Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp5817481imm; Tue, 12 Jun 2018 13:57:40 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKVjTpWYgniuu+kmUrfMdt2zPw7ZPKOPaJr0lU3IOz27jtJ30Y5JjDxg+MSlOeR6pTmQam0 X-Received: by 2002:a63:7255:: with SMTP id c21-v6mr1591696pgn.99.1528837060251; Tue, 12 Jun 2018 13:57:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528837060; cv=none; d=google.com; s=arc-20160816; b=zOoNdXhIXQj9zQn8fT8hA8XPzTEsQSoxbGOY/FRAlRlH4w3SWQdBwb/gVJEW1aa20V iar3qcQWjssTQnS0/o4aL3zcTRx45dI5jJDVHynlDch4dKdrjthsGpKrHfpB7RlwgIcK Cbmy4Nt1WTAqYKIMfA8Mlx9p2UtNRVVxpvQiEDa5q/HcztIy5x1B5/79xPqbX9t7gBNx VEfwPX7MoDR15a7iOmG7pvxw+TL/k2DKvYMmA78Km99Zk2bRgfQXRI3SvduTw4IeyE2C SLFaCuOnT1qmK4hASKldW5g1t74Gb94Nl2iQoHkz2J3ZCMvyZTU6dahB1rmUcKC+TbAE jxgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=NpIAFvQ6O9nnG5WOiv9Pr/VSUltr4pf4KmI8tMYXerk=; b=REodCYm7/H4z4Ok6gttTZz5pgtqGSeGSkjBVrZGL4qb7K4MS83BzWXNKVbFMzVygkd WzMW4PUfnlekDo2XIKhe74lHOxIcA2P5WwOlKER0p3JtX4kMIVBVkJ7LLefYTmg88njz znP4vTq9YgnZAQpVz9E+IBvbSlJEcktfPQKEenPaVWTZ/j+llYbkiZJal3PbLsfoh4g+ bo/Ldz/VC5+se2y/UOLRKXT+lDMKQJC9KGgcUwKovp2RIIQwHcgds2afC4PH65NulO8V ULZS9B738iI0YYl/YjQ459SPYwpGrof01x9N0SY7vsvZ+SHJakZ0E2mZlQPVV7W4G7pF RfVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=OKizW0Rw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id o15-v6si796060pgv.580.2018.06.12.13.57.25; Tue, 12 Jun 2018 13:57:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=OKizW0Rw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S934314AbeFLU4k (ORCPT + 99 others); Tue, 12 Jun 2018 16:56:40 -0400 Received: from smtp-fw-2101.amazon.com ([72.21.196.25]:31566 "EHLO smtp-fw-2101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933693AbeFLU4f (ORCPT ); Tue, 12 Jun 2018 16:56:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1528836995; x=1560372995; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=NpIAFvQ6O9nnG5WOiv9Pr/VSUltr4pf4KmI8tMYXerk=; b=OKizW0RwKKKLT13YiQIQKPszfkVX0m337+iyXGbVB6qdiPdkrX4JDVY0 Uh121Gge6B+RW4FuaU3DacNm7RsElkYUxlu6ULmnqvKnh84CdtGKNRgEU Dc/JvKtCRHyZlgmfDBm3Xfwgjk+fIYWNQbkyiLrt84rSJAsMznfp27aLM o=; X-IronPort-AV: E=Sophos;i="5.51,216,1526342400"; d="scan'208";a="682679273" Received: from iad6-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-2b-c7131dcf.us-west-2.amazon.com) ([10.124.125.2]) by smtp-border-fw-out-2101.iad2.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 12 Jun 2018 20:56:32 +0000 Received: from EX13MTAUWB001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan3.pdx.amazon.com [10.236.137.198]) by email-inbound-relay-2b-c7131dcf.us-west-2.amazon.com (8.14.7/8.14.7) with ESMTP id w5CKuT1H117272 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Tue, 12 Jun 2018 20:56:29 GMT Received: from EX13D05UWB004.ant.amazon.com (10.43.161.208) by EX13MTAUWB001.ant.amazon.com (10.43.161.207) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 12 Jun 2018 20:56:26 +0000 Received: from EX13MTAUWB001.ant.amazon.com (10.43.161.207) by EX13D05UWB004.ant.amazon.com (10.43.161.208) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 12 Jun 2018 20:56:26 +0000 Received: from localhost (10.25.15.63) by mail-relay.amazon.com (10.43.161.249) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Tue, 12 Jun 2018 20:56:26 +0000 From: Anchal Agarwal To: , , , CC: , , , , , , , , , , , , , , , , , Subject: [RFC PATCH 01/12] xen/manage: keep track of the on-going suspend mode Date: Tue, 12 Jun 2018 20:56:08 +0000 Message-ID: <20180612205619.28156-2-anchalag@amazon.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180612205619.28156-1-anchalag@amazon.com> References: <20180612205619.28156-1-anchalag@amazon.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Munehisa Kamata To differentiate between Xen suspend, PM suspend and PM hibernation, keep track of the on-going suspend mode by mainly using a new PM notifier. Since Xen suspend doesn't have corresponding PM event, its main logic is modfied to acquire pm_mutex and set the current mode. Note that we may see deadlock if PM suspend/hibernation is interrupted by Xen suspend. PM suspend/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 suspend/hibernation context in the scenario. Though, acquirng pm_mutex is still right thing to do, and we would need to modify Xen shutdown code to avoid the issue. This will be fixed by a separate patch. Signed-off-by: Munehisa Kamata Signed-off-by: Anchal Agarwal Reviewed-by: Sebastian Biemueller Reviewed-by: Munehisa Kamata Reviewed-by: Eduardo Valentin --- drivers/xen/manage.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c index 8835065..8f9ea87 100644 --- a/drivers/xen/manage.c +++ b/drivers/xen/manage.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -39,6 +40,16 @@ enum shutdown_state { /* Ignore multiple shutdown requests. */ static enum shutdown_state shutting_down = SHUTDOWN_INVALID; +enum suspend_modes { + NO_SUSPEND = 0, + XEN_SUSPEND, + PM_SUSPEND, + PM_HIBERNATION, +}; + +/* Protected by pm_mutex */ +static enum suspend_modes suspend_mode = NO_SUSPEND; + struct suspend_info { int cancelled; }; @@ -98,6 +109,10 @@ static void do_suspend(void) int err; struct suspend_info si; + lock_system_sleep(); + + suspend_mode = XEN_SUSPEND; + shutting_down = SHUTDOWN_SUSPEND; err = freeze_processes(); @@ -161,6 +176,10 @@ static void do_suspend(void) thaw_processes(); out: shutting_down = SHUTDOWN_INVALID; + + suspend_mode = NO_SUSPEND; + + unlock_system_sleep(); } #endif /* CONFIG_HIBERNATE_CALLBACKS */ @@ -372,3 +391,42 @@ 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) +{ + switch (pm_event) { + case PM_SUSPEND_PREPARE: + suspend_mode = PM_SUSPEND; + break; + case PM_HIBERNATION_PREPARE: + case PM_RESTORE_PREPARE: + suspend_mode = PM_HIBERNATION; + break; + case PM_POST_SUSPEND: + case PM_POST_RESTORE: + case PM_POST_HIBERNATION: + /* Set back to the default */ + suspend_mode = NO_SUSPEND; + break; + default: + pr_warn("Receive unknown PM event 0x%lx\n", pm_event); + return -EINVAL; + } + + return 0; +}; + +static struct notifier_block xen_pm_notifier_block = { + .notifier_call = xen_pm_notifier +}; + +static int xen_setup_pm_notifier(void) +{ + if (!xen_hvm_domain()) + return -ENODEV; + + return register_pm_notifier(&xen_pm_notifier_block); +} + +subsys_initcall(xen_setup_pm_notifier); -- 2.7.4