Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp588806pxa; Fri, 21 Aug 2020 15:29:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwk8pdgjwqsRNeutEna+tvGlbXTspVXBSSX5UTlnniXRGxBWb8EpchPR/cS8RJ5j+Nf1dyF X-Received: by 2002:a17:906:3993:: with SMTP id h19mr5272373eje.111.1598048952088; Fri, 21 Aug 2020 15:29:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598048952; cv=none; d=google.com; s=arc-20160816; b=Q6p6yp006BB5K4KOpMk+6U/gdjrFWsfj1vVTwXeu89AAxE8HpDT5cOBoFS6lsaPDbC iXMxl/XumfvXwXtMJItt4HMEIRvqwFZXasfv3wc8p6XPAUSl6/zZIo9NuebjqEvfIiR/ 949VKsjsszhxzf5Kt8bRxoC4vDfwVQgoORH4fBCb0ixHihANta9TwqdIGQ+nrN/dtMo7 g/wqciUATINYOOsLCqSUowTAvcjPxIEvNVnu2w4cZcJCBfxyyjMQGWORtcd+Lnb1f1XD CKnsXiDwV8aZ7s7olPf/7JR6V+e96h51kS/UlpWW7eNsiv4BWse/lEgukZdQGfclGWrK mUCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:to :from:date:dkim-signature; bh=P6c+ghbxBFW6FKLFXMggDpsPZB1htB1D5l7v91pDUP4=; b=E5vpM45JLGpS1OmOriBY0bWuh7uFrD2FvMbJVX1Lo3LLf6WzzmM06RzHujYuQVFOI3 2uJonmRd45Ihs6BZUofdVKHV8ZSnhspxIl+tyKraB9BWNhhm4+EsyOR3z7XpPsL2x1uX /+CF4Y7K5hSoMKJ9aGXvrWX9msEL9F9R9pGSozMB40tBuKfypEQ6xc0Yc50nqV0Wjvah CNk7cEdfi1N4ZObiHzZIJHWwNKp00LbNW+zj+UZeUpGB9g+MTAvfYTmDZfc5aNnwUOG2 p707hJuSXt+HQzpzMtWiV8UkSt8l1rDtsQ0n1BSS6ljRT05MXPmsiNjOHAAdpEeivGYr hdXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=Ig431mc8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cx1si1375308edb.4.2020.08.21.15.28.48; Fri, 21 Aug 2020 15:29:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=Ig431mc8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726904AbgHUW0C (ORCPT + 99 others); Fri, 21 Aug 2020 18:26:02 -0400 Received: from smtp-fw-2101.amazon.com ([72.21.196.25]:15381 "EHLO smtp-fw-2101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726761AbgHUW0A (ORCPT ); Fri, 21 Aug 2020 18:26:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1598048760; x=1629584760; h=date:from:to:subject:message-id:references:mime-version: in-reply-to; bh=P6c+ghbxBFW6FKLFXMggDpsPZB1htB1D5l7v91pDUP4=; b=Ig431mc8nkL7A2MVUhWBPacrSyQ+W4gVssi6yw6WUQTFR00KxbUYfSEJ bBNll5FaRaUMO5TOqXtvye6SAqBu2NJzWumWb3wuXT7f4N/u5fsF0D7J8 9/oh2CQz2KfRvXKiniguHk+6c2+s5QwCeTtQBUrgpZ5nyYMWhEFxrQ5ti c=; X-IronPort-AV: E=Sophos;i="5.76,338,1592870400"; d="scan'208";a="49215629" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-1a-7d76a15f.us-east-1.amazon.com) ([10.43.8.2]) by smtp-border-fw-out-2101.iad2.amazon.com with ESMTP; 21 Aug 2020 22:25:58 +0000 Received: from EX13MTAUEE002.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan3.iad.amazon.com [10.40.159.166]) by email-inbound-relay-1a-7d76a15f.us-east-1.amazon.com (Postfix) with ESMTPS id B7A6CA2891; Fri, 21 Aug 2020 22:25:50 +0000 (UTC) Received: from EX13D08UEE001.ant.amazon.com (10.43.62.126) by EX13MTAUEE002.ant.amazon.com (10.43.62.24) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 21 Aug 2020 22:25:50 +0000 Received: from EX13MTAUEE002.ant.amazon.com (10.43.62.24) by EX13D08UEE001.ant.amazon.com (10.43.62.126) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 21 Aug 2020 22:25:49 +0000 Received: from dev-dsk-anchalag-2a-9c2d1d96.us-west-2.amazon.com (172.22.96.68) by mail-relay.amazon.com (10.43.62.224) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Fri, 21 Aug 2020 22:25:49 +0000 Received: by dev-dsk-anchalag-2a-9c2d1d96.us-west-2.amazon.com (Postfix, from userid 4335130) id 6AD8840362; Fri, 21 Aug 2020 22:25:49 +0000 (UTC) Date: Fri, 21 Aug 2020 22:25:49 +0000 From: Anchal Agarwal To: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 01/11] xen/manage: keep track of the on-going suspend mode Message-ID: <9b970e12491107afda0c1d4a6f154b52d90346ac.1598042152.git.anchalag@amazon.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Munehisa Kamata Guest hibernation is different from xen suspend/resume/live migration. Xen save/restore does not use pm_ops as is needed by guest hibernation. Hibernation in guest follows ACPI path and is guest inititated , the hibernation image is saved within guest as compared to later modes which are xen toolstack assisted and image creation/storage is in control of hypervisor/host machine. To differentiate between Xen suspend and PM hibernation, keep track of the on-going suspend mode by mainly using a new API to keep track of SHUTDOWN_SUSPEND state. Introduce a simple function that keeps track of on-going suspend mode so that PM hibernation code can behave differently according to the current suspend mode. Since Xen suspend doesn't have corresponding PM event, its main logic is modfied to acquire pm_mutex. Though, accquirng pm_mutex is still right thing to do, we may see deadlock if PM hibernation is interrupted by Xen suspend. PM hibernation depends on xenwatch thread to process xenbus state transactions, but the thread will sleep to wait pm_mutex which is already held by PM hibernation context in the scenario. Xen shutdown code may need some changes to avoid the issue. [Anchal Agarwal: Changelog]: RFC v1->v2: Code refactoring v1->v2: Remove unused functions for PM SUSPEND/PM hibernation v2->v3: Added logic to use existing pm_notifier to detect for ARM and abort hibernation for ARM guests. Also removed different suspend_modes and simplified the code with using existing state variables for tracking Xen suspend. The notifier won't get registered for pvh dom0 either. Signed-off-by: Anchal Agarwal Signed-off-by: Munehisa Kamata --- drivers/xen/manage.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ include/xen/xen-ops.h | 1 + 2 files changed, 47 insertions(+) diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c index cd046684e0d1..d2a51c454c3e 100644 --- a/drivers/xen/manage.c +++ b/drivers/xen/manage.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -40,6 +41,11 @@ enum shutdown_state { /* Ignore multiple shutdown requests. */ static enum shutdown_state shutting_down = SHUTDOWN_INVALID; +bool is_xen_suspend(void) +{ + return shutting_down == SHUTDOWN_SUSPEND; +} + struct suspend_info { int cancelled; }; @@ -99,6 +105,8 @@ static void do_suspend(void) int err; struct suspend_info si; + lock_system_sleep(); + shutting_down = SHUTDOWN_SUSPEND; err = freeze_processes(); @@ -162,6 +170,8 @@ static void do_suspend(void) thaw_processes(); out: shutting_down = SHUTDOWN_INVALID; + + unlock_system_sleep(); } #endif /* CONFIG_HIBERNATE_CALLBACKS */ @@ -387,3 +397,39 @@ int xen_setup_shutdown_event(void) EXPORT_SYMBOL_GPL(xen_setup_shutdown_event); subsys_initcall(xen_setup_shutdown_event); + +static int xen_pm_notifier(struct notifier_block *notifier, + unsigned long pm_event, void *unused) +{ + int ret; + + switch (pm_event) { + case PM_SUSPEND_PREPARE: + case PM_HIBERNATION_PREPARE: + /* Guest hibernation is not supported for aarch64 currently*/ + if (IS_ENABLED(CONFIG_ARM64)) { + ret = NOTIFY_BAD; + break; + } + case PM_RESTORE_PREPARE: + case PM_POST_SUSPEND: + case PM_POST_HIBERNATION: + case PM_POST_RESTORE: + default: + ret = NOTIFY_OK; + } + return ret; +}; + +static struct notifier_block xen_pm_notifier_block = { + .notifier_call = xen_pm_notifier +}; + +static int xen_setup_pm_notifier(void) +{ + if (!xen_hvm_domain() || xen_initial_domain()) + return -ENODEV; + return register_pm_notifier(&xen_pm_notifier_block); +} + +subsys_initcall(xen_setup_pm_notifier); diff --git a/include/xen/xen-ops.h b/include/xen/xen-ops.h index 39a5580f8feb..e8b08734fab1 100644 --- a/include/xen/xen-ops.h +++ b/include/xen/xen-ops.h @@ -40,6 +40,7 @@ u64 xen_steal_clock(int cpu); int xen_setup_shutdown_event(void); +bool is_xen_suspend(void); extern unsigned long *xen_contiguous_bitmap; #if defined(CONFIG_XEN_PV) || defined(CONFIG_ARM) || defined(CONFIG_ARM64) -- 2.16.6