From patchwork Tue Jun 2 02:08:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 1302016 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49bb7H1rfGz9sSn; Tue, 2 Jun 2020 12:08:43 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1jfwM3-0005Jc-9m; Tue, 02 Jun 2020 02:08:39 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jfwM0-0005Ha-OG for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:36 +0000 Received: from mail-qt1-f197.google.com ([209.85.160.197]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jfwM0-0001yZ-Aw for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:36 +0000 Received: by mail-qt1-f197.google.com with SMTP id h49so10089220qtk.10 for ; Mon, 01 Jun 2020 19:08:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mPP0+GEC7TyE8NH5W8GqE3o9YrbLM0l5xaPBNXVzPPk=; b=rg3vPZLa7w0AbjgASJRBiE+l437dSq1ClP/vB6/xDIBsnX8orEjiIgqY5Bt4y7RfA/ VXuLLEI4TP0b/s/51r7KCQ8mmifYiRMx2yRf7JMvweLn4LXHLJ+vpx7REGqS0LejLf8V QCcj6yy3MovoF+HakNOPuJ+sDdzVrCFFObPgd0WPSbgvCA0K2ZQ9OBUDgBuxGTmEBTh0 J0NBSGVjSvdyBAty/MKDcAvE7x8V1B963qaKnouRk5sylPSvop0vqxHqNm90hKHqJSr4 N6u5lVrydMfL5hcKMh4G45UHdqikj/94GeHLIt8AB+z2cdV0bj6yoRd0jM0LTnPmWiaD to8g== X-Gm-Message-State: AOAM532qZSfLoisuOhdiyo8NEUANG6DIvTeJKfr6/KjsCU0T2kysajA3 WBEZzzcsoYirwLPrWZcbwJ757xEKHffFHwafFxMkI162dB8lnJNuxUMqtJJRdPk12YDb6S+qZ8u +cxp8Q2uQzRRGXZsJBx/TICzhGqfDYP4wkewokbZ4 X-Received: by 2002:ad4:5222:: with SMTP id r2mr24024434qvq.82.1591063714921; Mon, 01 Jun 2020 19:08:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxwC2y96p38TC9g1Q4IktRU4Qloi1SyQtiLiSs4ThgVqVODgo+4PvQwdvy4X7j6rj0+EJgK5g== X-Received: by 2002:ad4:5222:: with SMTP id r2mr24024424qvq.82.1591063714587; Mon, 01 Jun 2020 19:08:34 -0700 (PDT) Received: from gallifrey.lan ([201.82.186.200]) by smtp.gmail.com with ESMTPSA id t13sm1138342qtc.77.2020.06.01.19.08.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jun 2020 19:08:33 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [focal:linux-azure][PATCH 07/21] hv_balloon: Add the support of hibernation Date: Mon, 1 Jun 2020 23:08:03 -0300 Message-Id: <20200602020817.236422-8-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200602020817.236422-1-marcelo.cerri@canonical.com> References: <20200602020817.236422-1-marcelo.cerri@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Dexuan Cui BugLink: http://bugs.launchpad.net/bugs/1880032 When hibernation is enabled, we must ignore the balloon up/down and hot-add requests from the host, if any. Signed-off-by: Dexuan Cui Acked-by: David Hildenbrand Signed-off-by: Sasha Levin (cherry picked from commit 25bd2b2f1f05347a4cd633138d0e4c2fd5788359) Signed-off-by: Marcelo Henrique Cerri --- drivers/hv/hv_balloon.c | 87 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 2 deletions(-) diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c index 930674117533..e75419391fa8 100644 --- a/drivers/hv/hv_balloon.c +++ b/drivers/hv/hv_balloon.c @@ -24,6 +24,8 @@ #include +#include + #define CREATE_TRACE_POINTS #include "hv_trace_balloon.h" @@ -457,6 +459,7 @@ struct hot_add_wrk { struct work_struct wrk; }; +static bool allow_hibernation; static bool hot_add = true; static bool do_hot_add; /* @@ -1053,8 +1056,12 @@ static void hot_add_req(struct work_struct *dummy) else resp.result = 0; - if (!do_hot_add || (resp.page_count == 0)) - pr_err("Memory hot add failed\n"); + if (!do_hot_add || resp.page_count == 0) { + if (!allow_hibernation) + pr_err("Memory hot add failed\n"); + else + pr_info("Ignore hot-add request!\n"); + } dm->state = DM_INITIALIZED; resp.hdr.trans_id = atomic_inc_return(&trans_id); @@ -1502,6 +1509,11 @@ static void balloon_onchannelcallback(void *context) break; case DM_BALLOON_REQUEST: + if (allow_hibernation) { + pr_info("Ignore balloon-up request!\n"); + break; + } + if (dm->state == DM_BALLOON_UP) pr_warn("Currently ballooning\n"); bal_msg = (struct dm_balloon *)recv_buffer; @@ -1511,6 +1523,11 @@ static void balloon_onchannelcallback(void *context) break; case DM_UNBALLOON_REQUEST: + if (allow_hibernation) { + pr_info("Ignore balloon-down request!\n"); + break; + } + dm->state = DM_BALLOON_DOWN; balloon_down(dm, (struct dm_unballoon_request *)recv_buffer); @@ -1616,6 +1633,11 @@ static int balloon_connect_vsp(struct hv_device *dev) cap_msg.hdr.size = sizeof(struct dm_capabilities); cap_msg.hdr.trans_id = atomic_inc_return(&trans_id); + /* + * When hibernation (i.e. virtual ACPI S4 state) is enabled, the host + * currently still requires the bits to be set, so we have to add code + * to fail the host's hot-add and balloon up/down requests, if any. + */ cap_msg.caps.cap_bits.balloon = 1; cap_msg.caps.cap_bits.hot_add = 1; @@ -1665,6 +1687,10 @@ static int balloon_probe(struct hv_device *dev, { int ret; + allow_hibernation = hv_is_hibernation_supported(); + if (allow_hibernation) + hot_add = false; + #ifdef CONFIG_MEMORY_HOTPLUG do_hot_add = hot_add; #else @@ -1704,6 +1730,8 @@ static int balloon_probe(struct hv_device *dev, return 0; probe_error: + dm_device.state = DM_INIT_ERROR; + dm_device.thread = NULL; vmbus_close(dev->channel); #ifdef CONFIG_MEMORY_HOTPLUG unregister_memory_notifier(&hv_memory_nb); @@ -1745,6 +1773,59 @@ static int balloon_remove(struct hv_device *dev) return 0; } +static int balloon_suspend(struct hv_device *hv_dev) +{ + struct hv_dynmem_device *dm = hv_get_drvdata(hv_dev); + + tasklet_disable(&hv_dev->channel->callback_event); + + cancel_work_sync(&dm->balloon_wrk.wrk); + cancel_work_sync(&dm->ha_wrk.wrk); + + if (dm->thread) { + kthread_stop(dm->thread); + dm->thread = NULL; + vmbus_close(hv_dev->channel); + } + + tasklet_enable(&hv_dev->channel->callback_event); + + return 0; + +} + +static int balloon_resume(struct hv_device *dev) +{ + int ret; + + dm_device.state = DM_INITIALIZING; + + ret = balloon_connect_vsp(dev); + + if (ret != 0) + goto out; + + dm_device.thread = + kthread_run(dm_thread_func, &dm_device, "hv_balloon"); + if (IS_ERR(dm_device.thread)) { + ret = PTR_ERR(dm_device.thread); + dm_device.thread = NULL; + goto close_channel; + } + + dm_device.state = DM_INITIALIZED; + return 0; +close_channel: + vmbus_close(dev->channel); +out: + dm_device.state = DM_INIT_ERROR; +#ifdef CONFIG_MEMORY_HOTPLUG + unregister_memory_notifier(&hv_memory_nb); + restore_online_page_callback(&hv_online_page); +#endif + return ret; +} + static const struct hv_vmbus_device_id id_table[] = { /* Dynamic Memory Class ID */ /* 525074DC-8985-46e2-8057-A307DC18A502 */ @@ -1759,6 +1840,8 @@ static struct hv_driver balloon_drv = { .id_table = id_table, .probe = balloon_probe, .remove = balloon_remove, + .suspend = balloon_suspend, + .resume = balloon_resume, .driver = { .probe_type = PROBE_PREFER_ASYNCHRONOUS, },