From nobody Thu May 2 23:03:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass header.i=@amazon.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=amazon.com ARC-Seal: i=1; a=rsa-sha256; t=1593714143; cv=none; d=zohomail.com; s=zohoarc; b=dVFKLgSgXN9uwG2VQjfVebMeThNMFH1vuP4rP7mseX+TX1OQO3Yjuic3KotacfV2g+YFMDafwx21gw28s7IayKKATS+N4ErOASUfv13fnkGcUL+jd7p9hohNrRe/bZU/YNqlMPusWj+lXlHZBPxq4EDe4ugZ0yQx5unhTmA64JQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593714143; h=Content-Type:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uoroRGLFE2Atyc2JGE05NLscaVRKKsCZnOJvewnD1q4=; b=nUmW94mOoBmKSXsXW4IBhwMqFb0C+5NdUxJi1b0QY8xkS1YLWGAnGM+UTzdiiWDRNIEK9umr8BTHEd4Un/A0DW8G02lkuI+UDw75246TKXoxW0CR6yULlXWl3xfsp+E3cs1Sp25bkS7qxWOYz9pRj27afv9Cw4m6jN+l/pF5Dw8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@amazon.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1593714143396640.1211162810569; Thu, 2 Jul 2020 11:22:23 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jr3qN-000573-Il; Thu, 02 Jul 2020 18:21:55 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jr3qL-00056y-S2 for xen-devel@lists.xenproject.org; Thu, 02 Jul 2020 18:21:53 +0000 Received: from smtp-fw-33001.amazon.com (unknown [207.171.190.10]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e70d7dae-bc90-11ea-b7bb-bc764e2007e4; Thu, 02 Jul 2020 18:21:53 +0000 (UTC) Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2a-119b4f96.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 02 Jul 2020 18:21:50 +0000 Received: from EX13MTAUWA001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2a-119b4f96.us-west-2.amazon.com (Postfix) with ESMTPS id BA4BA1A102E; Thu, 2 Jul 2020 18:21:48 +0000 (UTC) Received: from EX13D10UWA003.ant.amazon.com (10.43.160.248) by EX13MTAUWA001.ant.amazon.com (10.43.160.58) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 2 Jul 2020 18:21:43 +0000 Received: from EX13MTAUWA001.ant.amazon.com (10.43.160.58) by EX13D10UWA003.ant.amazon.com (10.43.160.248) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 2 Jul 2020 18:21:36 +0000 Received: from dev-dsk-anchalag-2a-9c2d1d96.us-west-2.amazon.com (172.22.96.68) by mail-relay.amazon.com (10.43.160.118) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 2 Jul 2020 18:21:36 +0000 Received: by dev-dsk-anchalag-2a-9c2d1d96.us-west-2.amazon.com (Postfix, from userid 4335130) id 8A9B940844; Thu, 2 Jul 2020 18:21:36 +0000 (UTC) X-Inumbo-ID: e70d7dae-bc90-11ea-b7bb-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1593714113; x=1625250113; h=date:from:to:subject:message-id:references:mime-version: in-reply-to; bh=uoroRGLFE2Atyc2JGE05NLscaVRKKsCZnOJvewnD1q4=; b=cfr5zgdq7Ft7MAHGkskXajztclg+fGj0slKdLNLluKkmOzUYYOX4IKrl bw1lfhRIMBG25w5OTvBTvS251rg6SB4FWCEtW+LMqYDN0X/LRX8VQBbIN 9427OFi+ocY2nfg0RE0Au/6mkvxWbLXX5/mU41YNN32zRF6jgU642GuiK A=; IronPort-SDR: 2zEetQQdV5iJipJrTQmkyojCF1liNQ2rvC5FD4pMA/MiHYFXS2EHBC9fKUXHHRnbe8spyb4jXz T4wH3OzVpZxQ== X-IronPort-AV: E=Sophos;i="5.75,305,1589241600"; d="scan'208";a="55693041" Date: Thu, 2 Jul 2020 18:21:36 +0000 From: Anchal Agarwal To: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v2 01/11] xen/manage: keep track of the on-going suspend mode Message-ID: <20200702182136.GA3511@dev-dsk-anchalag-2a-9c2d1d96.us-west-2.amazon.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Precedence: Bulk X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: pass (identity @amazon.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 PM notifier. Introduce simple functions which help to know the on-going suspend mode so that other Xen-related 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 and set the current mode. Though, acquirng 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 Signed-off-by: Anchal Agarwal Signed-off-by: Munehisa Kamata --- drivers/xen/manage.c | 60 +++++++++++++++++++++++++++++++++++++++++++ include/xen/xen-ops.h | 1 + 2 files changed, 61 insertions(+) diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c index cd046684e0d1..69833fd6cfd1 100644 --- a/drivers/xen/manage.c +++ b/drivers/xen/manage.c @@ -14,6 +14,7 @@ #include #include #include +#include =20 #include #include @@ -40,6 +41,20 @@ enum shutdown_state { /* Ignore multiple shutdown requests. */ static enum shutdown_state shutting_down =3D SHUTDOWN_INVALID; =20 +enum suspend_modes { + NO_SUSPEND =3D 0, + XEN_SUSPEND, + PM_HIBERNATION, +}; + +/* Protected by pm_mutex */ +static enum suspend_modes suspend_mode =3D NO_SUSPEND; + +bool xen_is_xen_suspend(void) +{ + return suspend_mode =3D=3D XEN_SUSPEND; +} + struct suspend_info { int cancelled; }; @@ -99,6 +114,10 @@ static void do_suspend(void) int err; struct suspend_info si; =20 + lock_system_sleep(); + + suspend_mode =3D XEN_SUSPEND; + shutting_down =3D SHUTDOWN_SUSPEND; =20 err =3D freeze_processes(); @@ -162,6 +181,10 @@ static void do_suspend(void) thaw_processes(); out: shutting_down =3D SHUTDOWN_INVALID; + + suspend_mode =3D NO_SUSPEND; + + unlock_system_sleep(); } #endif /* CONFIG_HIBERNATE_CALLBACKS */ =20 @@ -387,3 +410,40 @@ int xen_setup_shutdown_event(void) EXPORT_SYMBOL_GPL(xen_setup_shutdown_event); =20 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: + case PM_HIBERNATION_PREPARE: + case PM_RESTORE_PREPARE: + suspend_mode =3D PM_HIBERNATION; + break; + case PM_POST_SUSPEND: + case PM_POST_RESTORE: + case PM_POST_HIBERNATION: + /* Set back to the default */ + suspend_mode =3D 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 =3D { + .notifier_call =3D 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); diff --git a/include/xen/xen-ops.h b/include/xen/xen-ops.h index 39a5580f8feb..2521d6a306cd 100644 --- a/include/xen/xen-ops.h +++ b/include/xen/xen-ops.h @@ -40,6 +40,7 @@ u64 xen_steal_clock(int cpu); =20 int xen_setup_shutdown_event(void); =20 +bool xen_is_xen_suspend(void); extern unsigned long *xen_contiguous_bitmap; =20 #if defined(CONFIG_XEN_PV) || defined(CONFIG_ARM) || defined(CONFIG_ARM64) --=20 2.20.1 From nobody Thu May 2 23:03:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass header.i=@amazon.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=amazon.com ARC-Seal: i=1; a=rsa-sha256; t=1593714375; cv=none; d=zohomail.com; s=zohoarc; b=dfAeU/2N0BM/+2L6aC4BsfIfhZLDZDgn40DWpi72iaJZ6xa6dFzbH5mgiFMeAARfpGLEpJMlhgMhQB45X9JiS4CDKjQPl9BdWG7NjyX+QErY9SRqW/K19oh6V7Hg/eOVjgvMZEaotnvFTZ6UrZFGJFI1b7XAciBBpG+Lt19PRwk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593714375; h=Content-Type:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jLJQ9NuVygNNRcAPap0ICuY1A6zLkRPc2aHxxOZMLNc=; b=D33w0Zhedv0TNvbhIdfOCPv4O8q38WKNz6Z3D8VdnGwn4TzK03fKrSMV3G66vnIjv/sj63n/yq4NHWXTlwHifk8RLgJahF0sFHdVDa1TLzW4bgavUVOxD56OioogwwhzPmkByl2AfCsWerIRj/pUn9JKcwwE7yxKSkOwVchi0j0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@amazon.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 159371437587414.336486284657667; Thu, 2 Jul 2020 11:26:15 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jr3uM-0006D3-5J; Thu, 02 Jul 2020 18:26:02 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jr3uK-0006Ct-Cd for xen-devel@lists.xenproject.org; Thu, 02 Jul 2020 18:26:00 +0000 Received: from smtp-fw-33001.amazon.com (unknown [207.171.190.10]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 79f99b48-bc91-11ea-b7bb-bc764e2007e4; Thu, 02 Jul 2020 18:25:59 +0000 (UTC) Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1a-16acd5e0.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 02 Jul 2020 18:25:57 +0000 Received: from EX13MTAUEB002.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1a-16acd5e0.us-east-1.amazon.com (Postfix) with ESMTPS id 2B3EAA1FEE; Thu, 2 Jul 2020 18:25:49 +0000 (UTC) Received: from EX13D08UEB002.ant.amazon.com (10.43.60.107) by EX13MTAUEB002.ant.amazon.com (10.43.60.12) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 2 Jul 2020 18:25:30 +0000 Received: from EX13MTAUEB002.ant.amazon.com (10.43.60.12) by EX13D08UEB002.ant.amazon.com (10.43.60.107) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 2 Jul 2020 18:25:30 +0000 Received: from dev-dsk-anchalag-2a-9c2d1d96.us-west-2.amazon.com (172.22.96.68) by mail-relay.amazon.com (10.43.60.234) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 2 Jul 2020 18:25:29 +0000 Received: by dev-dsk-anchalag-2a-9c2d1d96.us-west-2.amazon.com (Postfix, from userid 4335130) id E9DAC40844; Thu, 2 Jul 2020 18:25:29 +0000 (UTC) X-Inumbo-ID: 79f99b48-bc91-11ea-b7bb-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1593714360; x=1625250360; h=date:from:to:subject:message-id:references:mime-version: in-reply-to; bh=jLJQ9NuVygNNRcAPap0ICuY1A6zLkRPc2aHxxOZMLNc=; b=Bn04Gr3BvCal+J+zvGCbb48FgninblZOYSr/Qt1aYgQ5Nx5T/oQTfegb bK8rj3X+OpNHAPDrR1p7VC0yAegLkvWTtoEO5LIoWb+SMrs0Mxfw0oB5n tC5WGmyGyWE/Xk8fQhhzMauX7TQaiTlzzB8NRtUk/HPDwbOxjovpOsZQ4 w=; IronPort-SDR: 9K0UaovTj6pXWTvQUqHP8tf1CyImeNnAp5dgeU8Ek2iag7xWzdGj816eXt/y4qO4q0g3EatLKK YauVToN5kJOg== X-IronPort-AV: E=Sophos;i="5.75,305,1589241600"; d="scan'208";a="55693820" Date: Thu, 2 Jul 2020 18:25:29 +0000 From: Anchal Agarwal To: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v2 02/11] xenbus: add freeze/thaw/restore callbacks support Message-ID: <20200702182529.GA3908@dev-dsk-anchalag-2a-9c2d1d96.us-west-2.amazon.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Precedence: Bulk X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: pass (identity @amazon.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Munehisa Kamata Since commit b3e96c0c7562 ("xen: use freeze/restore/thaw PM events for suspend/resume/chkpt"), xenbus uses PMSG_FREEZE, PMSG_THAW and PMSG_RESTORE events for Xen suspend. However, they're actually assigned to xenbus_dev_suspend(), xenbus_dev_cancel() and xenbus_dev_resume() respectively, and only suspend and resume callbacks are supported at driver level. To support PM suspend and PM hibernation, modify the bus level PM callbacks to invoke not only device driver's suspend/resume but also freeze/thaw/restore. Note that we'll use freeze/restore callbacks even for PM suspend whereas suspend/resume callbacks are normally used in the case, becausae the existing xenbus device drivers already have suspend/resume callbacks specifically designed for Xen suspend. So we can allow the device drivers to keep the existing callbacks wihtout modification. [Anchal Agarwal: Changelog]: RFC v1->v2: Refactored the callbacks code v1->v2: Use dev_warn instead of pr_warn, naming/initialization conventions Signed-off-by: Agarwal Anchal Signed-off-by: Munehisa Kamata --- drivers/xen/xenbus/xenbus_probe.c | 96 ++++++++++++++++++++++++++----- include/xen/xenbus.h | 3 + 2 files changed, 84 insertions(+), 15 deletions(-) diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_= probe.c index 38725d97d909..715919aacd28 100644 --- a/drivers/xen/xenbus/xenbus_probe.c +++ b/drivers/xen/xenbus/xenbus_probe.c @@ -50,6 +50,7 @@ #include #include #include +#include =20 #include #include @@ -599,16 +600,33 @@ int xenbus_dev_suspend(struct device *dev) struct xenbus_driver *drv; struct xenbus_device *xdev =3D container_of(dev, struct xenbus_device, dev); + bool xen_suspend =3D xen_is_xen_suspend(); =20 DPRINTK("%s", xdev->nodename); =20 if (dev->driver =3D=3D NULL) return 0; drv =3D to_xenbus_driver(dev->driver); - if (drv->suspend) - err =3D drv->suspend(xdev); - if (err) - dev_warn(dev, "suspend failed: %i\n", err); + if (xen_suspend) { + if (drv->suspend) + err =3D drv->suspend(xdev); + } else { + if (drv->freeze) { + err =3D drv->freeze(xdev); + if (!err) { + free_otherend_watch(xdev); + free_otherend_details(xdev); + return 0; + } + } + } + + if (err) { + dev_warn(&xdev->dev, "%s %s failed: %d\n", xen_suspend ? + "suspend" : "freeze", xdev->nodename, err); + return err; + } + return 0; } EXPORT_SYMBOL_GPL(xenbus_dev_suspend); @@ -619,6 +637,7 @@ int xenbus_dev_resume(struct device *dev) struct xenbus_driver *drv; struct xenbus_device *xdev =3D container_of(dev, struct xenbus_device, dev); + bool xen_suspend =3D xen_is_xen_suspend(); =20 DPRINTK("%s", xdev->nodename); =20 @@ -627,23 +646,34 @@ int xenbus_dev_resume(struct device *dev) drv =3D to_xenbus_driver(dev->driver); err =3D talk_to_otherend(xdev); if (err) { - dev_warn(dev, "resume (talk_to_otherend) failed: %i\n", err); + dev_warn(&xdev->dev, "%s (talk_to_otherend) %s failed: %d\n", + xen_suspend ? "resume" : "restore", + xdev->nodename, err); return err; } =20 - xdev->state =3D XenbusStateInitialising; + if (xen_suspend) { + xdev->state =3D XenbusStateInitialising; + if (drv->resume) + err =3D drv->resume(xdev); + } else { + if (drv->restore) + err =3D drv->restore(xdev); + } =20 - if (drv->resume) { - err =3D drv->resume(xdev); - if (err) { - dev_warn(dev, "resume failed: %i\n", err); - return err; - } + if (err) { + dev_warn(&xdev->dev, "%s %s failed: %d\n", + xen_suspend ? "resume" : "restore", + xdev->nodename, err); + return err; } =20 err =3D watch_otherend(xdev); if (err) { - dev_warn(dev, "resume (watch_otherend) failed: %d\n", err); + dev_warn(&xdev->dev, "%s (watch_otherend) %s failed: %d.\n", + xen_suspend ? "resume" : "restore", + xdev->nodename, err); + return err; } =20 @@ -653,8 +683,44 @@ EXPORT_SYMBOL_GPL(xenbus_dev_resume); =20 int xenbus_dev_cancel(struct device *dev) { - /* Do nothing */ - DPRINTK("cancel"); + int err; + struct xenbus_driver *drv; + struct xenbus_device *xendev =3D to_xenbus_device(dev); + bool xen_suspend =3D xen_is_xen_suspend(); + + if (xen_suspend) { + /* Do nothing */ + DPRINTK("cancel"); + return 0; + } + + DPRINTK("%s", xendev->nodename); + + if (dev->driver =3D=3D NULL) + return 0; + drv =3D to_xenbus_driver(dev->driver); + err =3D talk_to_otherend(xendev); + if (err) { + dev_warn(&xendev->dev, "thaw (talk_to_otherend) %s failed: %d.\n", + xendev->nodename, err); + return err; + } + + if (drv->thaw) { + err =3D drv->thaw(xendev); + if (err) { + dev_warn(&xendev->dev, "thaw %s failed: %d\n", xendev->nodename, err); + return err; + } + } + + err =3D watch_otherend(xendev); + if (err) { + dev_warn(&xendev->dev, "thaw (watch_otherend) %s failed: %d.\n", + xendev->nodename, err); + return err; + } + return 0; } EXPORT_SYMBOL_GPL(xenbus_dev_cancel); diff --git a/include/xen/xenbus.h b/include/xen/xenbus.h index 5a8315e6d8a6..8da964763255 100644 --- a/include/xen/xenbus.h +++ b/include/xen/xenbus.h @@ -104,6 +104,9 @@ struct xenbus_driver { int (*remove)(struct xenbus_device *dev); int (*suspend)(struct xenbus_device *dev); int (*resume)(struct xenbus_device *dev); + int (*freeze)(struct xenbus_device *dev); + int (*thaw)(struct xenbus_device *dev); + int (*restore)(struct xenbus_device *dev); int (*uevent)(struct xenbus_device *, struct kobj_uevent_env *); struct device_driver driver; int (*read_otherend_details)(struct xenbus_device *dev); --=20 2.20.1 From nobody Thu May 2 23:03:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass header.i=@amazon.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=amazon.com ARC-Seal: i=1; a=rsa-sha256; t=1593714164; cv=none; d=zohomail.com; s=zohoarc; b=EFRwvZ1JOuhWky9WJEmf9MZ+yO2R9Ra4E7EFX/HLh4YnhMEWqD4F9+jq3JOCCBTQqv8zNviKTJ0F5/MO11fwbrg+NldkX4oC2OD/R+QrGUnc1yiVCfs0s9Y8zM8w3w0Mnbgr6bE7zaUm0/UBR4fOfSQNBN7hoTQXscpG5mE1GNE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593714164; h=Content-Type:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=L0wmgxX+Ovp8pu3YnIUM23eFCfp/nVBG2avgRDi4ITE=; b=E9w5vPbghDRf3LKqH8+I/JkasRWChzHP+Url+z/jeMRc+BGlkYh9wuWvIETnTOVqV4C20r8NyiOxpWKL3o9xd3fiyPdN8g6ff3HYCHsDXp4V+Su/VMjLWjWen5iZv6Ybjd5tC/pgEvdN42Y9yUo08A9d2ZgDPdipt6jeXGVx5O8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@amazon.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1593714164115927.5581350107968; Thu, 2 Jul 2020 11:22:44 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jr3qw-0005DE-8u; Thu, 02 Jul 2020 18:22:30 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jr3qu-0005Cv-S3 for xen-devel@lists.xenproject.org; Thu, 02 Jul 2020 18:22:28 +0000 Received: from smtp-fw-9102.amazon.com (unknown [207.171.184.29]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id fb2adb9d-bc90-11ea-8887-12813bfff9fa; Thu, 02 Jul 2020 18:22:28 +0000 (UTC) Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1e-17c49630.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 02 Jul 2020 18:22:26 +0000 Received: from EX13MTAUEB002.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan3.iad.amazon.com [10.40.159.166]) by email-inbound-relay-1e-17c49630.us-east-1.amazon.com (Postfix) with ESMTPS id C81B2A188E; Thu, 2 Jul 2020 18:22:18 +0000 (UTC) Received: from EX13D08UEB002.ant.amazon.com (10.43.60.107) by EX13MTAUEB002.ant.amazon.com (10.43.60.12) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 2 Jul 2020 18:21:52 +0000 Received: from EX13MTAUEA002.ant.amazon.com (10.43.61.77) by EX13D08UEB002.ant.amazon.com (10.43.60.107) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 2 Jul 2020 18:21:52 +0000 Received: from dev-dsk-anchalag-2a-9c2d1d96.us-west-2.amazon.com (172.22.96.68) by mail-relay.amazon.com (10.43.61.169) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 2 Jul 2020 18:21:52 +0000 Received: by dev-dsk-anchalag-2a-9c2d1d96.us-west-2.amazon.com (Postfix, from userid 4335130) id 05A9F40844; Thu, 2 Jul 2020 18:21:52 +0000 (UTC) X-Inumbo-ID: fb2adb9d-bc90-11ea-8887-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1593714148; x=1625250148; h=date:from:to:subject:message-id:references:mime-version: in-reply-to; bh=L0wmgxX+Ovp8pu3YnIUM23eFCfp/nVBG2avgRDi4ITE=; b=AYpFS4qf//QSf1DXaidpas5RaihxjrIv9aA3HVGT/6cvwO7Cqvzf0WDM KHGrE03l3CSOcVCMt8LLo2b3Vkpus5fGJjmvBfHBgHz+vwAYepQyb7wKK ekiYo9ootHWH/4CBY9Zmu8VbRsxEnZTIMeo2Re+BZu00KiSwLR4lpqXNo s=; IronPort-SDR: phoIWWm5EGmTpHtUjCgKWFQfuW7oI7r/z0P4Vuu21Tm6bBK93XjGosJHiCJSK1i+PGpOrR2b63 /Mq6kJcMc4Tg== X-IronPort-AV: E=Sophos;i="5.75,305,1589241600"; d="scan'208";a="56964556" Date: Thu, 2 Jul 2020 18:21:52 +0000 From: Anchal Agarwal To: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v2 03/11] x86/xen: Introduce new function to map HYPERVISOR_shared_info on Resume Message-ID: <3601db44e7c543016ca67327393d9ae37019e408.1593665947.git.anchalag@amazon.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Precedence: Bulk X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: pass (identity @amazon.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce a small function which re-uses shared page's PA allocated during guest initialization time in reserve_shared_info() and not allocate new page during resume flow. It also does the mapping of shared_info_page by calling xen_hvm_init_shared_info() to use the function. Changelog: v1->v2: Remove extra check for shared_info_pfn to be NULL Signed-off-by: Anchal Agarwal --- arch/x86/xen/enlighten_hvm.c | 6 ++++++ arch/x86/xen/xen-ops.h | 1 + 2 files changed, 7 insertions(+) diff --git a/arch/x86/xen/enlighten_hvm.c b/arch/x86/xen/enlighten_hvm.c index 3e89b0067ff0..d91099928746 100644 --- a/arch/x86/xen/enlighten_hvm.c +++ b/arch/x86/xen/enlighten_hvm.c @@ -28,6 +28,12 @@ =20 static unsigned long shared_info_pfn; =20 +void xen_hvm_map_shared_info(void) +{ + xen_hvm_init_shared_info(); + HYPERVISOR_shared_info =3D __va(PFN_PHYS(shared_info_pfn)); +} + void xen_hvm_init_shared_info(void) { struct xen_add_to_physmap xatp; diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h index 53b224fd6177..41e9e9120f2d 100644 --- a/arch/x86/xen/xen-ops.h +++ b/arch/x86/xen/xen-ops.h @@ -54,6 +54,7 @@ void xen_enable_sysenter(void); void xen_enable_syscall(void); void xen_vcpu_restore(void); =20 +void xen_hvm_map_shared_info(void); void xen_hvm_init_shared_info(void); void xen_unplug_emulated_devices(void); =20 --=20 2.20.1 From nobody Thu May 2 23:03:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass header.i=@amazon.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=amazon.com ARC-Seal: i=1; a=rsa-sha256; t=1593714167; cv=none; d=zohomail.com; s=zohoarc; b=Z4JzQ0M1C+ERyEz2kQKZVWJyizD9Rs25IMc9DyUPg4p8PPRAPSDPGJY06SwFHhvpPUDzrTQKAKmaUfhvDxsAMLl9gOe+0NTDA1W15mwPLE+Q8G+tbAIjc8zlSJrl5tgJLVJFqd58vNzYRLq0kblh+JX5gqfCioIkjhGD0bLKIQQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593714167; h=Content-Type:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=OCpSQw7b/4F/s9Kck7b/oFt4msmldkjBxvkPzpRtc18=; b=HMxlefJYPtofj9/5OrL+zshrEldQTyYDJKGYppRu+yO5FU9io4nls1RZ7+h42z32G2KLuAjVUboBIqK3IK7kgiVgF4yhp7blN6x0NIvG31xcuKsEBikpwPBBBO8LszN4umyX9qSOOv5YFxeO3qxs8HY9FjlsMmYyLrp1gpLytW0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@amazon.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1593714167708357.8661062538024; Thu, 2 Jul 2020 11:22:47 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jr3r1-0005Es-Gt; Thu, 02 Jul 2020 18:22:35 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jr3qz-0005Cv-QR for xen-devel@lists.xenproject.org; Thu, 02 Jul 2020 18:22:33 +0000 Received: from smtp-fw-33001.amazon.com (unknown [207.171.190.10]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id fcc79bac-bc90-11ea-8887-12813bfff9fa; Thu, 02 Jul 2020 18:22:29 +0000 (UTC) Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2c-579b7f5b.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 02 Jul 2020 18:22:29 +0000 Received: from EX13MTAUEE002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2c-579b7f5b.us-west-2.amazon.com (Postfix) with ESMTPS id 1F1CDA18CF; Thu, 2 Jul 2020 18:22:27 +0000 (UTC) Received: from EX13D08UEE003.ant.amazon.com (10.43.62.118) by EX13MTAUEE002.ant.amazon.com (10.43.62.24) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 2 Jul 2020 18:22:05 +0000 Received: from EX13MTAUEE002.ant.amazon.com (10.43.62.24) by EX13D08UEE003.ant.amazon.com (10.43.62.118) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 2 Jul 2020 18:22:05 +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; Thu, 2 Jul 2020 18:22:05 +0000 Received: by dev-dsk-anchalag-2a-9c2d1d96.us-west-2.amazon.com (Postfix, from userid 4335130) id 0A86C40844; Thu, 2 Jul 2020 18:22:05 +0000 (UTC) X-Inumbo-ID: fcc79bac-bc90-11ea-8887-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1593714150; x=1625250150; h=date:from:to:subject:message-id:references:mime-version: in-reply-to; bh=OCpSQw7b/4F/s9Kck7b/oFt4msmldkjBxvkPzpRtc18=; b=T1shpIRhhZv0QyTkTEcdlrYXncywj0xuufCwh4wLYGcToE6BTxNl8OLE Adgu/ugBCx2gL7JkPXAroAUGNNVrLM6k6xhtwyYM+LIgSHzePbHKzk7d7 +V6wCwFW6MX3lr6CLcoFk/w2PPzp80n0z8dZnppmVuWEJ74xuqbVfKvP9 c=; IronPort-SDR: vkg/Sg8L6s4rdxfrTdTR2arayeY3g64ZdS81u9rg8mgIf0I0him3TpE5PXpud66wIReuCHA0QC aagUD9PVAMEA== X-IronPort-AV: E=Sophos;i="5.75,305,1589241600"; d="scan'208";a="55693165" Date: Thu, 2 Jul 2020 18:22:05 +0000 From: Anchal Agarwal To: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v2 04/11] x86/xen: add system core suspend and resume callbacks Message-ID: <20200702182205.GA3531@dev-dsk-anchalag-2a-9c2d1d96.us-west-2.amazon.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Precedence: Bulk X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: pass (identity @amazon.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Munehisa Kamata Add Xen PVHVM specific system core callbacks for PM hibernation support. The callbacks suspend and resume Xen primitives like shared_info, pvclock and grant table. These syscore_ops are specifically for domU hibernation. xen_suspend() calls syscore_suspend() during Xen suspend operation however, during xen suspend lock_system_sleep() lock is taken and thus system cannot trigger hibernation. These system core callbacks will be called only from the hibernation context. [Anchal Agarwal: Changelog]: v1->v2: Edit commit message Fixed syscore_suspend() to call gnntab_suspend Removed suspend mode check in syscore_suspend()/ syscore_resume() Signed-off-by: Agarwal Anchal Signed-off-by: Munehisa Kamata --- arch/x86/xen/enlighten_hvm.c | 1 + arch/x86/xen/suspend.c | 47 ++++++++++++++++++++++++++++++++++++ include/xen/xen-ops.h | 2 ++ 3 files changed, 50 insertions(+) diff --git a/arch/x86/xen/enlighten_hvm.c b/arch/x86/xen/enlighten_hvm.c index d91099928746..bd6bf6eb2052 100644 --- a/arch/x86/xen/enlighten_hvm.c +++ b/arch/x86/xen/enlighten_hvm.c @@ -215,6 +215,7 @@ static void __init xen_hvm_guest_init(void) if (xen_feature(XENFEAT_hvm_callback_vector)) xen_have_vector_callback =3D 1; =20 + xen_setup_syscore_ops(); xen_hvm_smp_init(); WARN_ON(xen_cpuhp_setup(xen_cpu_up_prepare_hvm, xen_cpu_dead_hvm)); xen_unplug_emulated_devices(); diff --git a/arch/x86/xen/suspend.c b/arch/x86/xen/suspend.c index 1d83152c761b..e8c924e93fc5 100644 --- a/arch/x86/xen/suspend.c +++ b/arch/x86/xen/suspend.c @@ -2,17 +2,22 @@ #include #include #include +#include +#include =20 #include #include +#include #include #include +#include =20 #include #include #include #include #include +#include =20 #include "xen-ops.h" #include "mmu.h" @@ -82,3 +87,45 @@ void xen_arch_suspend(void) =20 on_each_cpu(xen_vcpu_notify_suspend, NULL, 1); } + +static int xen_syscore_suspend(void) +{ + struct xen_remove_from_physmap xrfp; + int ret; + + gnttab_suspend(); + + xrfp.domid =3D DOMID_SELF; + xrfp.gpfn =3D __pa(HYPERVISOR_shared_info) >> PAGE_SHIFT; + + ret =3D HYPERVISOR_memory_op(XENMEM_remove_from_physmap, &xrfp); + if (!ret) + HYPERVISOR_shared_info =3D &xen_dummy_shared_info; + + return ret; +} + +static void xen_syscore_resume(void) +{ + /* No need to setup vcpu_info as it's already moved off */ + xen_hvm_map_shared_info(); + + pvclock_resume(); + + gnttab_resume(); +} + +/* + * These callbacks will be called with interrupts disabled and when having= only + * one CPU online. + */ +static struct syscore_ops xen_hvm_syscore_ops =3D { + .suspend =3D xen_syscore_suspend, + .resume =3D xen_syscore_resume +}; + +void __init xen_setup_syscore_ops(void) +{ + if (xen_hvm_domain()) + register_syscore_ops(&xen_hvm_syscore_ops); +} diff --git a/include/xen/xen-ops.h b/include/xen/xen-ops.h index 2521d6a306cd..9fa8a4082d68 100644 --- a/include/xen/xen-ops.h +++ b/include/xen/xen-ops.h @@ -41,6 +41,8 @@ u64 xen_steal_clock(int cpu); int xen_setup_shutdown_event(void); =20 bool xen_is_xen_suspend(void); +void xen_setup_syscore_ops(void); + extern unsigned long *xen_contiguous_bitmap; =20 #if defined(CONFIG_XEN_PV) || defined(CONFIG_ARM) || defined(CONFIG_ARM64) --=20 2.20.1 From nobody Thu May 2 23:03:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass header.i=@amazon.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=amazon.com ARC-Seal: i=1; a=rsa-sha256; t=1593714183; cv=none; d=zohomail.com; s=zohoarc; b=ligVqISOJ9Slipz1MS6GUvSf0UpsgsIuyYMj/swWvh7SOUMP5CIauYwPQnO4CUC2H+EAw+vkkWy9od0zlQ5GdT+vkHznpk/2UBbahx0OugbnjL38h/CH9QBfpR08j5imRop44pSepl8jK7s+T1Pz7BGlbvo7qI5L7pF3t2OFSio= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593714183; h=Content-Type:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6WYhS9fhcjlT02XaftcCbDh+6PPkxfzixjjo5vFo6xY=; b=Ny3uEc+CnbliOVWt6z3NyUqJWRxk020e+yF6esyVSijwF56lZtrZvB/H+KLlNXuy3qPHE3P62wspNOT7QZxrtTg9fy4xp950uZCS8WbcoOIkVP5ok7wpK3gwtxwUNtMmTEJBn+kGAGHN8i6q+S4m/6HId2NcFmUn0jAaucrV+7k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@amazon.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1593714183431273.6293293568277; Thu, 2 Jul 2020 11:23:03 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jr3rC-0005IW-Pb; Thu, 02 Jul 2020 18:22:46 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jr3rA-0005I2-Vz for xen-devel@lists.xenproject.org; Thu, 02 Jul 2020 18:22:45 +0000 Received: from smtp-fw-6001.amazon.com (unknown [52.95.48.154]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 05db32a8-bc91-11ea-bb8b-bc764e2007e4; Thu, 02 Jul 2020 18:22:44 +0000 (UTC) Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-1e-97fdccfd.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 02 Jul 2020 18:22:44 +0000 Received: from EX13MTAUEB002.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan3.iad.amazon.com [10.40.159.166]) by email-inbound-relay-1e-97fdccfd.us-east-1.amazon.com (Postfix) with ESMTPS id 4673DA181E; Thu, 2 Jul 2020 18:22:42 +0000 (UTC) Received: from EX13D08UEB002.ant.amazon.com (10.43.60.107) by EX13MTAUEB002.ant.amazon.com (10.43.60.12) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 2 Jul 2020 18:22:17 +0000 Received: from EX13MTAUEA002.ant.amazon.com (10.43.61.77) by EX13D08UEB002.ant.amazon.com (10.43.60.107) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 2 Jul 2020 18:22:17 +0000 Received: from dev-dsk-anchalag-2a-9c2d1d96.us-west-2.amazon.com (172.22.96.68) by mail-relay.amazon.com (10.43.61.169) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 2 Jul 2020 18:22:17 +0000 Received: by dev-dsk-anchalag-2a-9c2d1d96.us-west-2.amazon.com (Postfix, from userid 4335130) id 2738540844; Thu, 2 Jul 2020 18:22:17 +0000 (UTC) X-Inumbo-ID: 05db32a8-bc91-11ea-bb8b-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1593714165; x=1625250165; h=date:from:to:subject:message-id:references:mime-version: in-reply-to; bh=6WYhS9fhcjlT02XaftcCbDh+6PPkxfzixjjo5vFo6xY=; b=lNWLO/Z15mnPjoTbYcBU7rtwPxvziCpLO4bQHU2RKBfECOyVnudfeRCU N663oWBDuc1CJsTVTug7SiToXyR5/V5djI/kyU70BTFiiVqD57gQOicJf Frw+MXRob8aCr8q6QYD1iUs/odSItdjpQ9jurql/yxlkE3Ng34rQxJoZa w=; IronPort-SDR: 6WL2v6GoZKshQ2w15CQNvN73wC/gCz8xAZ14lB2bb634i0tTkR52VltZYVndpTfW348uMqq0Op 8xCq/KYQWdeg== X-IronPort-AV: E=Sophos;i="5.75,305,1589241600"; d="scan'208";a="41164983" Date: Thu, 2 Jul 2020 18:22:17 +0000 From: Anchal Agarwal To: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v2 05/11] genirq: Shutdown irq chips in suspend/resume during hibernation Message-ID: <20200702182217.GA3577@dev-dsk-anchalag-2a-9c2d1d96.us-west-2.amazon.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Precedence: Bulk X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: pass (identity @amazon.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner Many legacy device drivers do not implement power management (PM) functions which means that interrupts requested by these drivers stay in active state when the kernel is hibernated. This does not matter on bare metal and on most hypervisors because the interrupt is restored on resume without any noticeable side effects as it stays connected to the same physical or virtual interrupt line. The XEN interrupt mechanism is different as it maintains a mapping between the Linux interrupt number and a XEN event channel. If the interrupt stays active on hibernation this mapping is preserved but there is unfortunately no guarantee that on resume the same event channels are reassigned to these devices. This can result in event channel conflicts which prevent the affected devices from being restored correctly. One way to solve this would be to add the necessary power management functions to all affected legacy device drivers, but that's a questionable effort which does not provide any benefits on non-XEN environments. The least intrusive and most efficient solution is to provide a mechanism which allows the core interrupt code to tear down these interrupts on hibernation and bring them back up again on resume. This allows the XEN event channel mechanism to assign an arbitrary event channel on resume without affecting the functionality of these devices. Fortunately all these device interrupts are handled by a dedicated XEN interrupt chip so the chip can be marked that all interrupts connected to it are handled this way. This is pretty much in line with the other interrupt chip specific quirks, e.g. IRQCHIP_MASK_ON_SUSPEND. Add a new quirk flag IRQCHIP_SHUTDOWN_ON_SUSPEND and add support for it the core interrupt suspend/resume paths. Changelog: RFCv2-RFCv3: Incorporated tglx@'s patch to work with xen code v1->v2: Corrected the author's name to tglx@ Signed-off-by: Anchal Agarwal Signed-off-by: Thomas Gleixner --- drivers/xen/events/events_base.c | 1 + include/linux/irq.h | 2 ++ kernel/irq/chip.c | 2 +- kernel/irq/internals.h | 1 + kernel/irq/pm.c | 31 ++++++++++++++++++++++--------- 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_b= ase.c index 140c7bf33a98..958dea2a4916 100644 --- a/drivers/xen/events/events_base.c +++ b/drivers/xen/events/events_base.c @@ -1611,6 +1611,7 @@ static struct irq_chip xen_pirq_chip __read_mostly = =3D { .irq_set_affinity =3D set_affinity_irq, =20 .irq_retrigger =3D retrigger_dynirq, + .flags =3D IRQCHIP_SHUTDOWN_ON_SUSPEND, }; =20 static struct irq_chip xen_percpu_chip __read_mostly =3D { diff --git a/include/linux/irq.h b/include/linux/irq.h index 8d5bc2c237d7..94cb8c994d06 100644 --- a/include/linux/irq.h +++ b/include/linux/irq.h @@ -542,6 +542,7 @@ struct irq_chip { * IRQCHIP_EOI_THREADED: Chip requires eoi() on unmask in threaded mode * IRQCHIP_SUPPORTS_LEVEL_MSI Chip can provide two doorbells for Level MSIs * IRQCHIP_SUPPORTS_NMI: Chip can deliver NMIs, only for root irqchips + * IRQCHIP_SHUTDOWN_ON_SUSPEND: Shutdown non wake irqs in the suspend path */ enum { IRQCHIP_SET_TYPE_MASKED =3D (1 << 0), @@ -553,6 +554,7 @@ enum { IRQCHIP_EOI_THREADED =3D (1 << 6), IRQCHIP_SUPPORTS_LEVEL_MSI =3D (1 << 7), IRQCHIP_SUPPORTS_NMI =3D (1 << 8), + IRQCHIP_SHUTDOWN_ON_SUSPEND =3D (1 << 9), }; =20 #include diff --git a/kernel/irq/chip.c b/kernel/irq/chip.c index 41e7e37a0928..fd59489ff14b 100644 --- a/kernel/irq/chip.c +++ b/kernel/irq/chip.c @@ -233,7 +233,7 @@ __irq_startup_managed(struct irq_desc *desc, struct cpu= mask *aff, bool force) } #endif =20 -static int __irq_startup(struct irq_desc *desc) +int __irq_startup(struct irq_desc *desc) { struct irq_data *d =3D irq_desc_get_irq_data(desc); int ret =3D 0; diff --git a/kernel/irq/internals.h b/kernel/irq/internals.h index 7db284b10ac9..b6fca5eacff7 100644 --- a/kernel/irq/internals.h +++ b/kernel/irq/internals.h @@ -80,6 +80,7 @@ extern void __enable_irq(struct irq_desc *desc); extern int irq_activate(struct irq_desc *desc); extern int irq_activate_and_startup(struct irq_desc *desc, bool resend); extern int irq_startup(struct irq_desc *desc, bool resend, bool force); +extern int __irq_startup(struct irq_desc *desc); =20 extern void irq_shutdown(struct irq_desc *desc); extern void irq_shutdown_and_deactivate(struct irq_desc *desc); diff --git a/kernel/irq/pm.c b/kernel/irq/pm.c index 8f557fa1f4fe..dc48a25f1756 100644 --- a/kernel/irq/pm.c +++ b/kernel/irq/pm.c @@ -85,16 +85,25 @@ static bool suspend_device_irq(struct irq_desc *desc) } =20 desc->istate |=3D IRQS_SUSPENDED; - __disable_irq(desc); - /* - * Hardware which has no wakeup source configuration facility - * requires that the non wakeup interrupts are masked at the - * chip level. The chip implementation indicates that with - * IRQCHIP_MASK_ON_SUSPEND. + * Some irq chips (e.g. XEN PIRQ) require a full shutdown on suspend + * as some of the legacy drivers(e.g. floppy) do nothing during the + * suspend path */ - if (irq_desc_get_chip(desc)->flags & IRQCHIP_MASK_ON_SUSPEND) - mask_irq(desc); + if (irq_desc_get_chip(desc)->flags & IRQCHIP_SHUTDOWN_ON_SUSPEND) { + irq_shutdown(desc); + } else { + __disable_irq(desc); + + /* + * Hardware which has no wakeup source configuration facility + * requires that the non wakeup interrupts are masked at the + * chip level. The chip implementation indicates that with + * IRQCHIP_MASK_ON_SUSPEND. + */ + if (irq_desc_get_chip(desc)->flags & IRQCHIP_MASK_ON_SUSPEND) + mask_irq(desc); + } return true; } =20 @@ -152,7 +161,11 @@ static void resume_irq(struct irq_desc *desc) irq_state_set_masked(desc); resume: desc->istate &=3D ~IRQS_SUSPENDED; - __enable_irq(desc); + + if (irq_desc_get_chip(desc)->flags & IRQCHIP_SHUTDOWN_ON_SUSPEND) + __irq_startup(desc); + else + __enable_irq(desc); } =20 static void resume_irqs(bool want_early) --=20 2.20.1 From nobody Thu May 2 23:03:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass header.i=@amazon.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=amazon.com ARC-Seal: i=1; a=rsa-sha256; t=1593714195; cv=none; d=zohomail.com; s=zohoarc; b=Vp5jA+781kS7JOVdqTRXaT5kSEhTjGCwQ5f10W8hVQDU83a2tGKHoMDbAqa08xUacsY07NcYpNlZCjPAvkPIMnE4B9ssWL4kN2RvMZ5WW5hv//3vORiJkxeSPtmf/iAOWw/PCJlXktR7yzYkHkPe6m3qDkhv/v2ytF5r5i94pT8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593714195; h=Content-Type:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=RVQKYtcRWwNWuZmUzS3zKOFxRzkR229MYD6OqjQdblg=; b=Cy9oea/eAdf/8w3hPLdntpiVLD0dCF4nZRNUUpxZ+N9Hg6uaPTTU2YrMHaDCXZrZaCPIe+sqFRzGhdF7vpGX+MLSMOkp2b/jh8YgGg77T8oA/z9G3ACqgddQaLjU1osx4lLchCk2KpELYYJypjIrfjGhyo1+MS6NGlOqUKopMEQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@amazon.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1593714195012620.0772454190491; Thu, 2 Jul 2020 11:23:15 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jr3rP-0005Oh-Ej; Thu, 02 Jul 2020 18:22:59 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jr3rN-0005Lf-Ow for xen-devel@lists.xenproject.org; Thu, 02 Jul 2020 18:22:57 +0000 Received: from smtp-fw-9102.amazon.com (unknown [207.171.184.29]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 0d5f7e8a-bc91-11ea-b7bb-bc764e2007e4; Thu, 02 Jul 2020 18:22:57 +0000 (UTC) Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1a-807d4a99.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 02 Jul 2020 18:22:54 +0000 Received: from EX13MTAUEB002.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1a-807d4a99.us-east-1.amazon.com (Postfix) with ESMTPS id 67EEAA2423; Thu, 2 Jul 2020 18:22:47 +0000 (UTC) Received: from EX13D08UEB002.ant.amazon.com (10.43.60.107) by EX13MTAUEB002.ant.amazon.com (10.43.60.12) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 2 Jul 2020 18:22:29 +0000 Received: from EX13MTAUEB002.ant.amazon.com (10.43.60.12) by EX13D08UEB002.ant.amazon.com (10.43.60.107) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 2 Jul 2020 18:22:29 +0000 Received: from dev-dsk-anchalag-2a-9c2d1d96.us-west-2.amazon.com (172.22.96.68) by mail-relay.amazon.com (10.43.60.234) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 2 Jul 2020 18:22:28 +0000 Received: by dev-dsk-anchalag-2a-9c2d1d96.us-west-2.amazon.com (Postfix, from userid 4335130) id B17DF40844; Thu, 2 Jul 2020 18:22:28 +0000 (UTC) X-Inumbo-ID: 0d5f7e8a-bc91-11ea-b7bb-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1593714177; x=1625250177; h=date:from:to:subject:message-id:references:mime-version: in-reply-to; bh=RVQKYtcRWwNWuZmUzS3zKOFxRzkR229MYD6OqjQdblg=; b=NdsRZ2snflyOIiQBbCjZKak10ZUwltWSELv0tuqOotP7kx2aMnxD4Jy7 CJzocvYTg6PMw3OWcQkAqQRIje778szTn3joTxV04qhael74DvVAjIYOd GSeHpsvLapQOYzov7dAkDzJY8s9TX3daU2RxWQg7VpDrDAzFnnzF5ugzW k=; IronPort-SDR: CD+xWM+1+cIX2syWOyjPqbem2nqHCuYhZtRY9gc6NlNk+D4GhT+VRWopNGaFDnmYCsyAzUKHdD NlhAuEexncvg== X-IronPort-AV: E=Sophos;i="5.75,305,1589241600"; d="scan'208";a="56964654" Date: Thu, 2 Jul 2020 18:22:28 +0000 From: Anchal Agarwal To: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v2 06/11] xen-blkfront: add callbacks for PM suspend and hibernation Message-ID: <20200702182228.GA3586@dev-dsk-anchalag-2a-9c2d1d96.us-west-2.amazon.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Precedence: Bulk X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: pass (identity @amazon.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Munehisa Kamata S4 power transisiton states are much different than xen suspend/resume. Former is visible to the guest and frontend drivers should be aware of the state transistions and should be able to take appropriate actions when needed. In transition to S4 we need to make sure that at least all the in-flight blkif requests get completed, since they probably contain bits of the guest's memory image and that's not going to get saved any other way. Hence, re-issuing of in-flight requests as in case of xen resume will not work here. This is in contrast to xen-suspend where we need to freeze with as little processing as possible to avoid dirtying RAM late in the migration cycle and we know that in-flight data can wait. Add freeze, thaw and restore callbacks for PM suspend and hibernation support. All frontend drivers that needs to use PM_HIBERNATION/PM_SUSPEND events, need to implement these xenbus_driver callbacks. The freeze handler stops block-layer queue and disconnect the frontend from the backend while freeing ring_info and associated resources. Before disconnecting from the backend, we need to prevent any new IO from being queued and wait for existing IO to complete. Freeze/unfreeze of the queues will guarantee that there are no requests in use on the shared ring. However, for sanity we should check state of the ring before disconnecting to make sure that there are no outstanding requests to be processed on the ring. The restore handler re-allocates ring_info, unquiesces and unfreezes the queue and re-connect to the backend, so that rest of the kernel can continue to use the block device transparently. Note:For older backends,if a backend doesn't have commit'12ea729645ace' xen/blkback: unmap all persistent grants when frontend gets disconnected, the frontend may see massive amount of grant table warning when freeing resources. [ 36.852659] deferring g.e. 0xf9 (pfn 0xffffffffffffffff) [ 36.855089] xen:grant_table: WARNING:e.g. 0x112 still in use! In this case, persistent grants would need to be disabled. [Anchal Agarwal: Changelog]: RFC v1->v2: Removed timeout per request before disconnect during blkfront freeze. Added queue freeze/quiesce to the blkfront_freeze Code cleanup RFC v2->v3: None RFC v3->v1: Code cleanup, Refractoring v1->v2: * remove err variable in blkfront_freeze * BugFix: error handling if rings are still busy after queue freeze/quiesce and returnign driver to connected state * add TODO if blkback fails to disconnect on freeze * Code formatting Signed-off-by: Anchal Agarwal Signed-off-by: Munehisa Kamata --- drivers/block/xen-blkfront.c | 122 +++++++++++++++++++++++++++++++++-- 1 file changed, 118 insertions(+), 4 deletions(-) diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index 3b889ea950c2..9e3ed1b9f509 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -48,6 +48,8 @@ #include #include #include +#include +#include =20 #include #include @@ -80,6 +82,8 @@ enum blkif_state { BLKIF_STATE_DISCONNECTED, BLKIF_STATE_CONNECTED, BLKIF_STATE_SUSPENDED, + BLKIF_STATE_FREEZING, + BLKIF_STATE_FROZEN, }; =20 struct grant { @@ -219,6 +223,7 @@ struct blkfront_info struct list_head requests; struct bio_list bio_list; struct list_head info_list; + struct completion wait_backend_disconnected; }; =20 static unsigned int nr_minors; @@ -1005,6 +1010,7 @@ static int xlvbd_init_blk_queue(struct gendisk *gd, u= 16 sector_size, info->sector_size =3D sector_size; info->physical_sector_size =3D physical_sector_size; blkif_set_queue_limits(info); + init_completion(&info->wait_backend_disconnected); =20 return 0; } @@ -1353,6 +1359,8 @@ static void blkif_free(struct blkfront_info *info, in= t suspend) unsigned int i; struct blkfront_ring_info *rinfo; =20 + if (info->connected =3D=3D BLKIF_STATE_FREEZING) + goto free_rings; /* Prevent new requests being issued until we fix things up. */ info->connected =3D suspend ? BLKIF_STATE_SUSPENDED : BLKIF_STATE_DISCONNECTED; @@ -1360,6 +1368,7 @@ static void blkif_free(struct blkfront_info *info, in= t suspend) if (info->rq) blk_mq_stop_hw_queues(info->rq); =20 +free_rings: for_each_rinfo(info, rinfo, i) blkif_free_ring(rinfo); =20 @@ -1563,8 +1572,10 @@ static irqreturn_t blkif_interrupt(int irq, void *de= v_id) struct blkfront_ring_info *rinfo =3D (struct blkfront_ring_info *)dev_id; struct blkfront_info *info =3D rinfo->dev_info; =20 - if (unlikely(info->connected !=3D BLKIF_STATE_CONNECTED)) + if (unlikely(info->connected !=3D BLKIF_STATE_CONNECTED && + info->connected !=3D BLKIF_STATE_FREEZING)) { return IRQ_HANDLED; + } =20 spin_lock_irqsave(&rinfo->ring_lock, flags); again: @@ -2026,6 +2037,7 @@ static int blkif_recover(struct blkfront_info *info) struct bio *bio; unsigned int segs; struct blkfront_ring_info *rinfo; + bool frozen =3D info->connected =3D=3D BLKIF_STATE_FROZEN; =20 blkfront_gather_backend_features(info); /* Reset limits changed by blk_mq_update_nr_hw_queues(). */ @@ -2048,6 +2060,9 @@ static int blkif_recover(struct blkfront_info *info) kick_pending_request_queues(rinfo); } =20 + if (frozen) + return 0; + list_for_each_entry_safe(req, n, &info->requests, queuelist) { /* Requeue pending requests (flush or discard) */ list_del_init(&req->queuelist); @@ -2364,6 +2379,7 @@ static void blkfront_connect(struct blkfront_info *in= fo) =20 return; case BLKIF_STATE_SUSPENDED: + case BLKIF_STATE_FROZEN: /* * If we are recovering from suspension, we need to wait * for the backend to announce it's features before @@ -2481,12 +2497,37 @@ static void blkback_changed(struct xenbus_device *d= ev, break; =20 case XenbusStateClosed: - if (dev->state =3D=3D XenbusStateClosed) + if (dev->state =3D=3D XenbusStateClosed) { + if (info->connected =3D=3D BLKIF_STATE_FREEZING) { + blkif_free(info, 0); + info->connected =3D BLKIF_STATE_FROZEN; + complete(&info->wait_backend_disconnected); + } break; + } + /* + * We receive backend's Closed again while thawing + * or restoring and it causes thawing or restoring to fail. + * During blkfront_restore, backend is still in Closed state + * and we receive backend as closed here while frontend's + * dev->state is set to XenBusStateInitialized. + * Ignore such unexpected state regardless of the backend's + * state. + */ + if (info->connected =3D=3D BLKIF_STATE_FROZEN) { + dev_dbg(&dev->dev, "Thawing/Restoring, ignore the backend's Closed stat= e: %s", + dev->nodename); + break; + } + /* fall through */ case XenbusStateClosing: - if (info) - blkfront_closing(info); + if (info) { + if (info->connected =3D=3D BLKIF_STATE_FREEZING) + xenbus_frontend_closed(dev); + else + blkfront_closing(info); + } break; } } @@ -2630,6 +2671,76 @@ static void blkif_release(struct gendisk *disk, fmod= e_t mode) mutex_unlock(&blkfront_mutex); } =20 +static int blkfront_freeze(struct xenbus_device *dev) +{ + unsigned int i; + struct blkfront_info *info =3D dev_get_drvdata(&dev->dev); + struct blkfront_ring_info *rinfo; + /* This would be reasonable timeout as used in xenbus_dev_shutdown() */ + unsigned int timeout =3D 5 * HZ; + unsigned long flags; + + info->connected =3D BLKIF_STATE_FREEZING; + + blk_mq_freeze_queue(info->rq); + blk_mq_quiesce_queue(info->rq); + + for_each_rinfo(info, rinfo, i) { + /* No more gnttab callback work. */ + gnttab_cancel_free_callback(&rinfo->callback); + /* Flush gnttab callback work. Must be done with no locks held. */ + flush_work(&rinfo->work); + } + + for_each_rinfo(info, rinfo, i) { + spin_lock_irqsave(&rinfo->ring_lock, flags); + if (RING_FULL(&rinfo->ring) || + RING_HAS_UNCONSUMED_RESPONSES(&rinfo->ring)) { + spin_unlock_irqrestore(&rinfo->ring_lock, flags); + xenbus_dev_error(dev, -EBUSY, "Hibernation Failed. The ring is still bu= sy"); + info->connected =3D BLKIF_STATE_CONNECTED; + blk_mq_unquiesce_queue(info->rq); + blk_mq_unfreeze_queue(info->rq); + return -EBUSY; + } + spin_unlock_irqrestore(&rinfo->ring_lock, flags); + } + /* Kick the backend to disconnect */ + xenbus_switch_state(dev, XenbusStateClosing); + + /* + * We don't want to move forward before the frontend is diconnected + * from the backend cleanly. + * TODO:Handle timeout by falling back to the normal + * disconnect path and just wait for the backend to close before + * reconnecting. Bring the system back to its original state by + * failing hibernation gracefully. + */ + timeout =3D wait_for_completion_timeout(&info->wait_backend_disconnected, + timeout); + if (!timeout) { + xenbus_dev_error(dev, -EBUSY, "Freezing timed out;" + "the device may become inconsistent state"); + return -EBUSY; + } + + return 0; +} + +static int blkfront_restore(struct xenbus_device *dev) +{ + struct blkfront_info *info =3D dev_get_drvdata(&dev->dev); + int err; + + err =3D talk_to_blkback(dev, info); + if (!err) { + blk_mq_update_nr_hw_queues(&info->tag_set, info->nr_rings); + blk_mq_unquiesce_queue(info->rq); + blk_mq_unfreeze_queue(info->rq); + } + return err; +} + static const struct block_device_operations xlvbd_block_fops =3D { .owner =3D THIS_MODULE, @@ -2653,6 +2764,9 @@ static struct xenbus_driver blkfront_driver =3D { .resume =3D blkfront_resume, .otherend_changed =3D blkback_changed, .is_ready =3D blkfront_is_ready, + .freeze =3D blkfront_freeze, + .thaw =3D blkfront_restore, + .restore =3D blkfront_restore }; =20 static void purge_persistent_grants(struct blkfront_info *info) --=20 2.20.1 From nobody Thu May 2 23:03:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass header.i=@amazon.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=amazon.com ARC-Seal: i=1; a=rsa-sha256; t=1593714187; cv=none; d=zohomail.com; s=zohoarc; b=ZNReYKEWjblE0hHKlDJkoX7rVV2jyUrVP6cD83sRdOKsfiGjSENxQ+GRqPC811cg4XgnwL4PZdI4yUf49BlRpna7B+2eI9V94nxjybiQ6djRZnvrNFSDzfefDGefimZh60RBUMlLCBSk5bT9J8OgyWLCGaTDz/6ssy2sbJXxL28= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593714187; h=Content-Type:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=06XpXsbm4nGxufy5odK5fTjKd20Tk+xFUtGFnfbSPzI=; b=aDb97eTYIUH+7aZ/TFDvef1WdRLKL1zh+/abruylB33HYhdZndytvJyWa5iehxCE299rVKEbNBPl4MsHAuRjgOjpquT9LhFprNStBHCMmR5asUfwDGAQXRf8I6ExZ0AIEEvVzh0Y2/YmIPs/5Oq0y+G4H//U8tghm48By/NXJuk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@amazon.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1593714187484632.5754570005817; Thu, 2 Jul 2020 11:23:07 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jr3rI-0005L0-5I; Thu, 02 Jul 2020 18:22:52 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jr3rH-0005Kj-Dl for xen-devel@lists.xenproject.org; Thu, 02 Jul 2020 18:22:51 +0000 Received: from smtp-fw-9101.amazon.com (unknown [207.171.184.25]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 09425372-bc91-11ea-8887-12813bfff9fa; Thu, 02 Jul 2020 18:22:50 +0000 (UTC) Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2a-90c42d1d.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP; 02 Jul 2020 18:22:47 +0000 Received: from EX13MTAUWB001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2a-90c42d1d.us-west-2.amazon.com (Postfix) with ESMTPS id EE3B7A20BE; Thu, 2 Jul 2020 18:22:45 +0000 (UTC) Received: from EX13D07UWB001.ant.amazon.com (10.43.161.238) by EX13MTAUWB001.ant.amazon.com (10.43.161.249) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 2 Jul 2020 18:22:40 +0000 Received: from EX13MTAUWB001.ant.amazon.com (10.43.161.207) by EX13D07UWB001.ant.amazon.com (10.43.161.238) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 2 Jul 2020 18:22:40 +0000 Received: from dev-dsk-anchalag-2a-9c2d1d96.us-west-2.amazon.com (172.22.96.68) by mail-relay.amazon.com (10.43.161.249) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 2 Jul 2020 18:22:40 +0000 Received: by dev-dsk-anchalag-2a-9c2d1d96.us-west-2.amazon.com (Postfix, from userid 4335130) id 4A9E540844; Thu, 2 Jul 2020 18:22:40 +0000 (UTC) X-Inumbo-ID: 09425372-bc91-11ea-8887-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1593714170; x=1625250170; h=date:from:to:subject:message-id:references:mime-version: in-reply-to; bh=06XpXsbm4nGxufy5odK5fTjKd20Tk+xFUtGFnfbSPzI=; b=VX/bvOfbKagtaL40wqHSFwR8yT7u2TXTQd6kmhKrJsSoSha4CWsNHzhj oEJPA73A3HWv+QmpHEeqRciLRdVsnXo6YktcfuKG/oFMbBAs3mX5UHVtP ufcwDNz1U4ct/G0XXzJCDnwl0NcHxuemYqHWPlUs7IDyzzeF4Ej6X5hjs k=; IronPort-SDR: 0gwnU9r137fbenaSVqPItFyNKfUucpkmlvUo+1SwnrFmuaEm55bBT1oVwuTzRuYtHWnEFiJ/b7 VGVubhW9JJLw== X-IronPort-AV: E=Sophos;i="5.75,305,1589241600"; d="scan'208";a="48737187" Date: Thu, 2 Jul 2020 18:22:40 +0000 From: Anchal Agarwal To: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v2 07/11] xen-netfront: add callbacks for PM suspend and hibernation Message-ID: <20200702182240.GA3596@dev-dsk-anchalag-2a-9c2d1d96.us-west-2.amazon.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Precedence: Bulk X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: pass (identity @amazon.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Munehisa Kamata Add freeze, thaw and restore callbacks for PM suspend and hibernation support. The freeze handler simply disconnects the frotnend from the backend and frees resources associated with queues after disabling the net_device from the system. The restore handler just changes the frontend state and let the xenbus handler to re-allocate the resources and re-connect to the backend. This can be performed transparently to the rest of the system. The handlers are used for both PM suspend and hibernation so that we can keep the existing suspend/resume callbacks for Xen suspend without modification. Freezing netfront devices is normally expected to finish within a few hundred milliseconds, but it can rarely take more than 5 seconds and hit the hard coded timeout, it would depend on backend state which may be congested and/or have complex configuration. While it's rare case, longer default timeout seems a bit more reasonable here to avoid hitting the timeout. Also, make it configurable via module parameter so that we can cover broader setups than what we know currently. [Anchal Agarwal: Changelog]: RFCv1->RFCv2: Variable name fix and checkpatch.pl fixes] Signed-off-by: Anchal Agarwal Signed-off-by: Munehisa Kamata --- drivers/net/xen-netfront.c | 98 +++++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-) diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c index 482c6c8b0fb7..65edcdd6e05f 100644 --- a/drivers/net/xen-netfront.c +++ b/drivers/net/xen-netfront.c @@ -43,6 +43,7 @@ #include #include #include +#include #include =20 #include @@ -56,6 +57,12 @@ #include #include =20 +enum netif_freeze_state { + NETIF_FREEZE_STATE_UNFROZEN, + NETIF_FREEZE_STATE_FREEZING, + NETIF_FREEZE_STATE_FROZEN, +}; + /* Module parameters */ #define MAX_QUEUES_DEFAULT 8 static unsigned int xennet_max_queues; @@ -63,6 +70,12 @@ module_param_named(max_queues, xennet_max_queues, uint, = 0644); MODULE_PARM_DESC(max_queues, "Maximum number of queues per virtual interface"); =20 +static unsigned int netfront_freeze_timeout_secs =3D 10; +module_param_named(freeze_timeout_secs, + netfront_freeze_timeout_secs, uint, 0644); +MODULE_PARM_DESC(freeze_timeout_secs, + "timeout when freezing netfront device in seconds"); + static const struct ethtool_ops xennet_ethtool_ops; =20 struct netfront_cb { @@ -160,6 +173,10 @@ struct netfront_info { struct netfront_stats __percpu *tx_stats; =20 atomic_t rx_gso_checksum_fixup; + + int freeze_state; + + struct completion wait_backend_disconnected; }; =20 struct netfront_rx_info { @@ -721,6 +738,21 @@ static int xennet_close(struct net_device *dev) return 0; } =20 +static int xennet_disable_interrupts(struct net_device *dev) +{ + struct netfront_info *np =3D netdev_priv(dev); + unsigned int num_queues =3D dev->real_num_tx_queues; + unsigned int queue_index; + struct netfront_queue *queue; + + for (queue_index =3D 0; queue_index < num_queues; ++queue_index) { + queue =3D &np->queues[queue_index]; + disable_irq(queue->tx_irq); + disable_irq(queue->rx_irq); + } + return 0; +} + static void xennet_move_rx_slot(struct netfront_queue *queue, struct sk_bu= ff *skb, grant_ref_t ref) { @@ -1301,6 +1333,8 @@ static struct net_device *xennet_create_dev(struct xe= nbus_device *dev) =20 np->queues =3D NULL; =20 + init_completion(&np->wait_backend_disconnected); + err =3D -ENOMEM; np->rx_stats =3D netdev_alloc_pcpu_stats(struct netfront_stats); if (np->rx_stats =3D=3D NULL) @@ -1794,6 +1828,50 @@ static int xennet_create_queues(struct netfront_info= *info, return 0; } =20 +static int netfront_freeze(struct xenbus_device *dev) +{ + struct netfront_info *info =3D dev_get_drvdata(&dev->dev); + unsigned long timeout =3D netfront_freeze_timeout_secs * HZ; + int err =3D 0; + + xennet_disable_interrupts(info->netdev); + + netif_device_detach(info->netdev); + + info->freeze_state =3D NETIF_FREEZE_STATE_FREEZING; + + /* Kick the backend to disconnect */ + xenbus_switch_state(dev, XenbusStateClosing); + + /* We don't want to move forward before the frontend is diconnected + * from the backend cleanly. + */ + timeout =3D wait_for_completion_timeout(&info->wait_backend_disconnected, + timeout); + if (!timeout) { + err =3D -EBUSY; + xenbus_dev_error(dev, err, "Freezing timed out;" + "the device may become inconsistent state"); + return err; + } + + /* Tear down queues */ + xennet_disconnect_backend(info); + xennet_destroy_queues(info); + + info->freeze_state =3D NETIF_FREEZE_STATE_FROZEN; + + return err; +} + +static int netfront_restore(struct xenbus_device *dev) +{ + /* Kick the backend to re-connect */ + xenbus_switch_state(dev, XenbusStateInitialising); + + return 0; +} + /* Common code used when first setting up, and when resuming. */ static int talk_to_netback(struct xenbus_device *dev, struct netfront_info *info) @@ -1999,6 +2077,8 @@ static int xennet_connect(struct net_device *dev) spin_unlock_bh(&queue->rx_lock); } =20 + np->freeze_state =3D NETIF_FREEZE_STATE_UNFROZEN; + return 0; } =20 @@ -2036,10 +2116,23 @@ static void netback_changed(struct xenbus_device *d= ev, break; =20 case XenbusStateClosed: - if (dev->state =3D=3D XenbusStateClosed) + if (dev->state =3D=3D XenbusStateClosed) { + /* dpm context is waiting for the backend */ + if (np->freeze_state =3D=3D NETIF_FREEZE_STATE_FREEZING) + complete(&np->wait_backend_disconnected); break; + } + /* Fall through - Missed the backend's CLOSING state. */ case XenbusStateClosing: + /* We may see unexpected Closed or Closing from the backend. + * Just ignore it not to prevent the frontend from being + * re-connected in the case of PM suspend or hibernation. + */ + if (np->freeze_state =3D=3D NETIF_FREEZE_STATE_FROZEN && + dev->state =3D=3D XenbusStateInitialising) { + break; + } xenbus_frontend_closed(dev); break; } @@ -2186,6 +2279,9 @@ static struct xenbus_driver netfront_driver =3D { .probe =3D netfront_probe, .remove =3D xennet_remove, .resume =3D netfront_resume, + .freeze =3D netfront_freeze, + .thaw =3D netfront_restore, + .restore =3D netfront_restore, .otherend_changed =3D netback_changed, }; =20 --=20 2.20.1 From nobody Thu May 2 23:03:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass header.i=@amazon.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=amazon.com ARC-Seal: i=1; a=rsa-sha256; t=1593714217; cv=none; d=zohomail.com; s=zohoarc; b=L8RMDx6L1+lhy5WjSPiEZqp6nW9+SPJjBdMu9g5sbYgF+wudgfDwYylDJ77ko11LptQV1/RiPJ69oTNTO+qM7BV5NODFxXCYbU4RXyKrxpUUQyvahkQoq+ppXRRPeLu6RCB/UvToVkvbRUbHu97M/C+GlSOQLjAbc26FU4Y9lqQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593714217; h=Content-Type:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=I7turOllMrL/CNEMBFGxOPTAV9RKwwcOD5Qzsp0RMCI=; b=YAXweJfujmxS5s2ymdH/2G7KRTTxE7BVONc72O37unZ07DpUZPYIZ5XtYoKOnVtZRaK/ExJgX3TTlODKgd72HjpQWWS2B08bJy5k/mkRTpcwCDzj2jrG4mQXzEiu4VtO1tDcB8Aef2GsZtsqAQLCjDxI87Lhfd31U1CbRGSPEAY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@amazon.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 15937142172341015.9744633114376; Thu, 2 Jul 2020 11:23:37 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jr3ro-0005Zm-On; Thu, 02 Jul 2020 18:23:24 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jr3rm-0005ZE-VZ for xen-devel@lists.xenproject.org; Thu, 02 Jul 2020 18:23:22 +0000 Received: from smtp-fw-6002.amazon.com (unknown [52.95.49.90]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 1caaf9c8-bc91-11ea-bca7-bc764e2007e4; Thu, 02 Jul 2020 18:23:22 +0000 (UTC) Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2c-4e7c8266.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6002.iad6.amazon.com with ESMTP; 02 Jul 2020 18:23:16 +0000 Received: from EX13MTAUEE002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2c-4e7c8266.us-west-2.amazon.com (Postfix) with ESMTPS id A0D51A2540; Thu, 2 Jul 2020 18:23:14 +0000 (UTC) Received: from EX13D08UEE002.ant.amazon.com (10.43.62.92) by EX13MTAUEE002.ant.amazon.com (10.43.62.24) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 2 Jul 2020 18:22:51 +0000 Received: from EX13MTAUEE002.ant.amazon.com (10.43.62.24) by EX13D08UEE002.ant.amazon.com (10.43.62.92) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 2 Jul 2020 18:22:51 +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; Thu, 2 Jul 2020 18:22:51 +0000 Received: by dev-dsk-anchalag-2a-9c2d1d96.us-west-2.amazon.com (Postfix, from userid 4335130) id 651F840844; Thu, 2 Jul 2020 18:22:51 +0000 (UTC) X-Inumbo-ID: 1caaf9c8-bc91-11ea-bca7-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1593714202; x=1625250202; h=date:from:to:subject:message-id:references:mime-version: in-reply-to; bh=I7turOllMrL/CNEMBFGxOPTAV9RKwwcOD5Qzsp0RMCI=; b=vCQNhmqEzpWBiFjhA17o+7y6jSRGt0hV8h93YfSdFmwmTL7uGwTB3li2 WqRsJOVaS5mmHL5FBKt/3PAjm2H7e/eklFheXYrlJwWuB1POXO7BXTWcE SUDV3yj1DX3w216jPDUzXevn+HCtxqoXZ6Tce287X5Fyln5TibTNer3eL E=; IronPort-SDR: gtZOu0dMiB3ehEJQSAxthJy8slH3FlYoulPxQjoZIUWyHzAH9qA9TfOTryU3wg6sLJrulv+kzq yxHeXV2LgO7A== X-IronPort-AV: E=Sophos;i="5.75,305,1589241600"; d="scan'208";a="39736466" Date: Thu, 2 Jul 2020 18:22:51 +0000 From: Anchal Agarwal To: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v2 08/11] x86/xen: save and restore steal clock during PM hibernation Message-ID: <20200702182251.GA3606@dev-dsk-anchalag-2a-9c2d1d96.us-west-2.amazon.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Precedence: Bulk X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: pass (identity @amazon.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Save/restore steal times in syscore suspend/resume during PM hibernation. Commit '5e25f5db6abb9: ("xen/time: do not decrease steal time after live migration on xen")' fixes xen guest steal time handling during migration. A similar issue is seen during PM hibernation. Currently, steal time accounting code in scheduler expects steal clock callback to provide monotonically increasing value. If the accounting code receives a smaller value than previous one, it uses a negative value to calculate steal time and results in incorrectly updated idle and steal time accounting. This breaks userspace tools which read /proc/stat. top - 08:05:35 up 2:12, 3 users, load average: 0.00, 0.07, 0.23 Tasks: 80 total, 1 running, 79 sleeping, 0 stopped, 0 zombie Cpu(s): 0.0%us, 0.0%sy, 0.0%ni,30100.0%id, 0.0%wa, 0.0%hi, 0.0%si,-125= 3874204672.0%st This can actually happen when a Xen PVHVM guest gets restored from hibernation, because such a restored guest is just a fresh domain from Xen perspective and the time information in runstate info starts over from scratch. Changelog: v1->v2: Removed patches that introduced new function calls for saving/resto= ring sched clock offset and using existing ones that are used during LM Signed-off-by: Anchal Agarwal --- arch/x86/xen/suspend.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/arch/x86/xen/suspend.c b/arch/x86/xen/suspend.c index e8c924e93fc5..10cd14326472 100644 --- a/arch/x86/xen/suspend.c +++ b/arch/x86/xen/suspend.c @@ -94,10 +94,9 @@ static int xen_syscore_suspend(void) int ret; =20 gnttab_suspend(); - + xen_manage_runstate_time(-1); xrfp.domid =3D DOMID_SELF; xrfp.gpfn =3D __pa(HYPERVISOR_shared_info) >> PAGE_SHIFT; - ret =3D HYPERVISOR_memory_op(XENMEM_remove_from_physmap, &xrfp); if (!ret) HYPERVISOR_shared_info =3D &xen_dummy_shared_info; @@ -111,7 +110,7 @@ static void xen_syscore_resume(void) xen_hvm_map_shared_info(); =20 pvclock_resume(); - + xen_manage_runstate_time(0); gnttab_resume(); } =20 --=20 2.20.1 From nobody Thu May 2 23:03:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass header.i=@amazon.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=amazon.com ARC-Seal: i=1; a=rsa-sha256; t=1593714223; cv=none; d=zohomail.com; s=zohoarc; b=g3Z7vIY0sSBZJtNI61QLAr2RBRP/89IZuC3sExIkLDNQ8bcec6APOPsJDUXwUeLdpLBEzIZaXtqzkMlzeYoRXmuroZgErP4oZLMnA7dykEINEdZB1NYtfHUyVhT/eAaIjKE2ZAnTKVSTgy9c8kaoAlXVLAApq1/SCcNm94HKcQY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593714223; h=Content-Type:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=H8un5fMu7aydEquICqxLlc2CreWzZQt/df8398cfX/c=; b=dFG5WtJ2y+Jqsq6snp2PVvfsGVHl8Tmxx/s9r9yYm6Nnf6b862oj8lHhnPQGiHrXqwcoM7iuiFKdi311twyivOvwQn4stuTh1mmF3ElSv+SLqxw/8cfxtOnBHFGWdnncRhO/k7VQ7BO2o5vkUqS+dYx5SkVNgFQAMEkvbtA2HmM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@amazon.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1593714223537832.0064051651837; Thu, 2 Jul 2020 11:23:43 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jr3rt-0005by-5Y; Thu, 02 Jul 2020 18:23:29 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jr3rs-0005bi-OH for xen-devel@lists.xenproject.org; Thu, 02 Jul 2020 18:23:28 +0000 Received: from smtp-fw-6002.amazon.com (unknown [52.95.49.90]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 1ff4c03c-bc91-11ea-8887-12813bfff9fa; Thu, 02 Jul 2020 18:23:28 +0000 (UTC) Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2c-c6afef2e.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6002.iad6.amazon.com with ESMTP; 02 Jul 2020 18:23:26 +0000 Received: from EX13MTAUWA001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2c-c6afef2e.us-west-2.amazon.com (Postfix) with ESMTPS id 93042A2655; Thu, 2 Jul 2020 18:23:24 +0000 (UTC) Received: from EX13D10UWA001.ant.amazon.com (10.43.160.216) by EX13MTAUWA001.ant.amazon.com (10.43.160.118) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 2 Jul 2020 18:23:12 +0000 Received: from EX13MTAUWA001.ant.amazon.com (10.43.160.58) by EX13D10UWA001.ant.amazon.com (10.43.160.216) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 2 Jul 2020 18:23:12 +0000 Received: from dev-dsk-anchalag-2a-9c2d1d96.us-west-2.amazon.com (172.22.96.68) by mail-relay.amazon.com (10.43.160.118) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 2 Jul 2020 18:23:12 +0000 Received: by dev-dsk-anchalag-2a-9c2d1d96.us-west-2.amazon.com (Postfix, from userid 4335130) id BB32E40844; Thu, 2 Jul 2020 18:23:12 +0000 (UTC) X-Inumbo-ID: 1ff4c03c-bc91-11ea-8887-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1593714208; x=1625250208; h=date:from:to:subject:message-id:references:mime-version: in-reply-to; bh=H8un5fMu7aydEquICqxLlc2CreWzZQt/df8398cfX/c=; b=EuA4j1Ay4fUzhF4NQf9kdvekUqHC2IfUmjhWyFdGQlbU2lauRr+EJ/n2 KABRzPs83MGZNiCxxkRZPPkPJSukvqM/8Vb5yJ158icsqMR7iUEs+XSgN CQVB3R2qlf/4G/PBYIWAcQwa+FfuGd7am6XGebcC+LqV02Kmz/7nPf+Pj 0=; IronPort-SDR: +nUVv9fjNo7jApSiBsxQulNLtThEWcq31zBbfQPBu6bZu2P9FKOrUT141gBiLH5vsliubVIDL4 w1fvvS1czfgA== X-IronPort-AV: E=Sophos;i="5.75,305,1589241600"; d="scan'208";a="39736489" Date: Thu, 2 Jul 2020 18:23:12 +0000 From: Anchal Agarwal To: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v2 09/11] xen: Introduce wrapper for save/restore sched clock offset Message-ID: <20200702182312.GA3699@dev-dsk-anchalag-2a-9c2d1d96.us-west-2.amazon.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Precedence: Bulk X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: pass (identity @amazon.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce wrappers for save/restore xen_sched_clock_offset to be used by PM hibernation code to avoid system instability during resume. Signed-off-by: Anchal Agarwal --- arch/x86/xen/time.c | 15 +++++++++++++-- arch/x86/xen/xen-ops.h | 2 ++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c index c8897aad13cd..676950eb0cb5 100644 --- a/arch/x86/xen/time.c +++ b/arch/x86/xen/time.c @@ -386,12 +386,23 @@ static const struct pv_time_ops xen_time_ops __initco= nst =3D { static struct pvclock_vsyscall_time_info *xen_clock __read_mostly; static u64 xen_clock_value_saved; =20 +/*This is needed to maintain a monotonic clock value during PM hibernation= */ +void xen_save_sched_clock_offset(void) +{ + xen_clock_value_saved =3D xen_clocksource_read() - xen_sched_clock_offset; +} + +void xen_restore_sched_clock_offset(void) +{ + xen_sched_clock_offset =3D xen_clocksource_read() - xen_clock_value_saved; +} + void xen_save_time_memory_area(void) { struct vcpu_register_time_memory_area t; int ret; =20 - xen_clock_value_saved =3D xen_clocksource_read() - xen_sched_clock_offset; + xen_save_sched_clock_offset(); =20 if (!xen_clock) return; @@ -434,7 +445,7 @@ void xen_restore_time_memory_area(void) out: /* Need pvclock_resume() before using xen_clocksource_read(). */ pvclock_resume(); - xen_sched_clock_offset =3D xen_clocksource_read() - xen_clock_value_saved; + xen_restore_sched_clock_offset(); } =20 static void xen_setup_vsyscall_time_info(void) diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h index 41e9e9120f2d..f4b78b19493b 100644 --- a/arch/x86/xen/xen-ops.h +++ b/arch/x86/xen/xen-ops.h @@ -70,6 +70,8 @@ void xen_save_time_memory_area(void); void xen_restore_time_memory_area(void); void xen_init_time_ops(void); void xen_hvm_init_time_ops(void); +void xen_save_sched_clock_offset(void); +void xen_restore_sched_clock_offset(void); =20 irqreturn_t xen_debug_interrupt(int irq, void *dev_id); =20 --=20 2.20.1 From nobody Thu May 2 23:03:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass header.i=@amazon.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=amazon.com ARC-Seal: i=1; a=rsa-sha256; t=1593714233; cv=none; d=zohomail.com; s=zohoarc; b=EAuwvOMyVj5l7qTgfYXAh6/N5Z/Gp7oAhwg0TydtgNZHfzrSFn0/YNy9eJN7gWYF7IkEqCxGRPz4mTCJ3pkItY4Upc55Ud2JHO9dNtVRrGbI25repPtg5ipRQnOTuLrTRA0RSjtF5lxRAuNz56xwo93ckYEwTVQxYk6WpFmUmnQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593714233; h=Content-Type:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=42TBP3y4PhPFoPiNAsOF6sq0ISwy0yvaTgprwGJN3gs=; b=W+XqXGarqynLFSK62vAuHLqQyhho1t5PwmScezcf/MB38MDJ2Js52ddbuoXx7/E9pjBe+Vf2+qP5stvLT+X1qeJRlikPSqj/hzN3e/mvdULa0fOSs5Ec4e5nPgg1cE30In9giHYaLf9HyQtbOAbtDdqwkqWxnAQ6eW4+e/vUhfs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@amazon.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1593714233759652.7265113627894; Thu, 2 Jul 2020 11:23:53 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jr3s3-0005hX-FE; Thu, 02 Jul 2020 18:23:39 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jr3s2-0005h0-AO for xen-devel@lists.xenproject.org; Thu, 02 Jul 2020 18:23:38 +0000 Received: from smtp-fw-33001.amazon.com (unknown [207.171.190.10]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2504ba33-bc91-11ea-8887-12813bfff9fa; Thu, 02 Jul 2020 18:23:37 +0000 (UTC) Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2a-d0be17ee.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 02 Jul 2020 18:23:37 +0000 Received: from EX13MTAUWB001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2a-d0be17ee.us-west-2.amazon.com (Postfix) with ESMTPS id 7E718A255A; Thu, 2 Jul 2020 18:23:35 +0000 (UTC) Received: from EX13D10UWB004.ant.amazon.com (10.43.161.121) by EX13MTAUWB001.ant.amazon.com (10.43.161.249) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 2 Jul 2020 18:23:28 +0000 Received: from EX13MTAUWB001.ant.amazon.com (10.43.161.207) by EX13D10UWB004.ant.amazon.com (10.43.161.121) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 2 Jul 2020 18:23:28 +0000 Received: from dev-dsk-anchalag-2a-9c2d1d96.us-west-2.amazon.com (172.22.96.68) by mail-relay.amazon.com (10.43.161.249) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 2 Jul 2020 18:23:28 +0000 Received: by dev-dsk-anchalag-2a-9c2d1d96.us-west-2.amazon.com (Postfix, from userid 4335130) id 8E2C940844; Thu, 2 Jul 2020 18:23:28 +0000 (UTC) X-Inumbo-ID: 2504ba33-bc91-11ea-8887-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1593714218; x=1625250218; h=date:from:to:subject:message-id:references:mime-version: in-reply-to; bh=42TBP3y4PhPFoPiNAsOF6sq0ISwy0yvaTgprwGJN3gs=; b=gqArI3DQHtn1L2MkSfq/YBuf/AiCtMbE6j8vOQleOTW18+umcSBh8b1X fWQhO2254GD1Yx+wItnv1LzeF5PkT5/7Pz/dUbzITx+cf6WwmgfyY7uEq pSpHMVd4YThvuOvnqu4Z1YCdOUZ6bg6zufvGvQt8bnFf/5zW5ht3pAjbX A=; IronPort-SDR: LmEWe+lBjje6IkAwKMPzWi2nEZ4tgqKNfXE84BMIprWb5gWec64tizT5QYDEjeSJ/XdZT9iLjF RRHpr+GD/3WQ== X-IronPort-AV: E=Sophos;i="5.75,305,1589241600"; d="scan'208";a="55693384" Date: Thu, 2 Jul 2020 18:23:28 +0000 From: Anchal Agarwal To: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v2 10/11] xen: Update sched clock offset to avoid system instability in hibernation Message-ID: <20200702182328.GA3751@dev-dsk-anchalag-2a-9c2d1d96.us-west-2.amazon.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Precedence: Bulk X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: pass (identity @amazon.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Save/restore xen_sched_clock_offset in syscore suspend/resume during PM hibernation. Commit '867cefb4cb1012: ("xen: Fix x86 sched_clock() interface for xen")' fixes xen guest time handling during migration. A similar issue is seen during PM hibernation when system runs CPU intensive workload. Post resume pvclock resets the value to 0 however, xen sched_clock_offset is never updated. System instability is seen during resume from hibernation when system is under heavy CPU load. Since xen_sched_clock_offset is not updated, system does not see the monotonic clock value and the scheduler would then think that heavy CPU hog tasks need more time in CPU, causing the system to freeze Signed-off-by: Anchal Agarwal --- arch/x86/xen/suspend.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/x86/xen/suspend.c b/arch/x86/xen/suspend.c index 10cd14326472..4d8b1d2390b9 100644 --- a/arch/x86/xen/suspend.c +++ b/arch/x86/xen/suspend.c @@ -95,6 +95,7 @@ static int xen_syscore_suspend(void) =20 gnttab_suspend(); xen_manage_runstate_time(-1); + xen_save_sched_clock_offset(); xrfp.domid =3D DOMID_SELF; xrfp.gpfn =3D __pa(HYPERVISOR_shared_info) >> PAGE_SHIFT; ret =3D HYPERVISOR_memory_op(XENMEM_remove_from_physmap, &xrfp); @@ -110,6 +111,12 @@ static void xen_syscore_resume(void) xen_hvm_map_shared_info(); =20 pvclock_resume(); + /* + * Restore xen_sched_clock_offset during resume to maintain + * monotonic clock value + */ + xen_restore_sched_clock_offset(); + xen_manage_runstate_time(0); gnttab_resume(); } --=20 2.20.1 From nobody Thu May 2 23:03:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass header.i=@amazon.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=amazon.com ARC-Seal: i=1; a=rsa-sha256; t=1593714259; cv=none; d=zohomail.com; s=zohoarc; b=guH9zWHQBgQzXJoDuzdAh2d+eEVe1KqX+6zE5zbYigSQ9MUrzHlz4vPtJdOp0ORjz+X6fwJiCq/TeXWClGvZOkKSjz+Sbx0OSFlYGNbDsqVfrx+vBsxGM3vknPwVqBNykRPiTfg1camC9e3AxWVtGmZ3dMSxMImFnJGMIQMA+rk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593714259; h=Content-Type:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8xWBYHNSqyc0rRCT8ma4wuwSS0bbWLxvstPp4v8IEIQ=; b=mr3fMrHTyZhv6+vzkmPZL42fR7unQqMv2IbUEalQ0cELrgEs6h4Wab+zJ0kZwFJAcwWrwiao47kgfNddZ+1lDVawCv+5VSp3AOEjnshmySb+tGqWtULHfIYB1ufUqLK+Onh6b+5gBXS0uIejo/QripMEMaDF4zydurAdT0f/9F4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@amazon.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 159371425960464.18853432224842; Thu, 2 Jul 2020 11:24:19 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jr3sT-0005sM-Op; Thu, 02 Jul 2020 18:24:05 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jr3sS-0005rq-Cv for xen-devel@lists.xenproject.org; Thu, 02 Jul 2020 18:24:04 +0000 Received: from smtp-fw-2101.amazon.com (unknown [72.21.196.25]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 34e09ed1-bc91-11ea-8887-12813bfff9fa; Thu, 02 Jul 2020 18:24:03 +0000 (UTC) Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-1a-715bee71.us-east-1.amazon.com) ([10.43.8.2]) by smtp-border-fw-out-2101.iad2.amazon.com with ESMTP; 02 Jul 2020 18:24:03 +0000 Received: from EX13MTAUWC001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1a-715bee71.us-east-1.amazon.com (Postfix) with ESMTPS id 23592A25CA; Thu, 2 Jul 2020 18:23:55 +0000 (UTC) Received: from EX13D05UWC001.ant.amazon.com (10.43.162.82) by EX13MTAUWC001.ant.amazon.com (10.43.162.135) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 2 Jul 2020 18:23:37 +0000 Received: from EX13MTAUWC001.ant.amazon.com (10.43.162.135) by EX13D05UWC001.ant.amazon.com (10.43.162.82) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 2 Jul 2020 18:23:37 +0000 Received: from dev-dsk-anchalag-2a-9c2d1d96.us-west-2.amazon.com (172.22.96.68) by mail-relay.amazon.com (10.43.162.232) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 2 Jul 2020 18:23:37 +0000 Received: by dev-dsk-anchalag-2a-9c2d1d96.us-west-2.amazon.com (Postfix, from userid 4335130) id 5F90C40844; Thu, 2 Jul 2020 18:23:37 +0000 (UTC) X-Inumbo-ID: 34e09ed1-bc91-11ea-8887-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1593714244; x=1625250244; h=date:from:to:subject:message-id:references:mime-version: in-reply-to; bh=8xWBYHNSqyc0rRCT8ma4wuwSS0bbWLxvstPp4v8IEIQ=; b=dKwhQogBiG38kRTV9cIxd2hom5FJS8v1BFqS6UlOfR57ptUdWzxE/iiV mTxaYJTeEdY9x/aImJn/3xuLNCyKdhwBR3jGW7U/JorU0bhdpGqCosQEg Ncys7NAKZfTYovy7dr2XjxoPh7UQpVSQhu/var/BACXMorIbV8yq9HCm8 8=; IronPort-SDR: sDAToUmcQVKVwVu9eMz0u6grcT4hSIwmjgpl1XIY45YPsfIMhKSq5/2gBLD4pbIvjcoFAEP58A Z+Jgig/wdQNw== X-IronPort-AV: E=Sophos;i="5.75,305,1589241600"; d="scan'208";a="39714105" Date: Thu, 2 Jul 2020 18:23:37 +0000 From: Anchal Agarwal To: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v2 11/11] PM / hibernate: update the resume offset on SNAPSHOT_SET_SWAP_AREA Message-ID: <20200702182337.GA3762@dev-dsk-anchalag-2a-9c2d1d96.us-west-2.amazon.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Precedence: Bulk X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: pass (identity @amazon.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Aleksei Besogonov The SNAPSHOT_SET_SWAP_AREA is supposed to be used to set the hibernation offset on a running kernel to enable hibernating to a swap file. However, it doesn't actually update the swsusp_resume_block variable. As a result, the hibernation fails at the last step (after all the data is written out) in the validation of the swap signature in mark_swapfiles(). Before this patch, the command line processing was the only place where swsusp_resume_block was set. [Anchal Agarwal: Changelog: Resolved patch conflict as code fragmented to snapshot_set_swap_area] Signed-off-by: Aleksei Besogonov Signed-off-by: Munehisa Kamata Signed-off-by: Anchal Agarwal --- kernel/power/user.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kernel/power/user.c b/kernel/power/user.c index d5eedc2baa2a..e1209cefc103 100644 --- a/kernel/power/user.c +++ b/kernel/power/user.c @@ -242,8 +242,12 @@ static int snapshot_set_swap_area(struct snapshot_data= *data, return -EINVAL; } data->swap =3D swap_type_of(swdev, offset, &bdev); - if (data->swap < 0) + if (data->swap < 0) { return -ENODEV; + } else { + swsusp_resume_device =3D swdev; + swsusp_resume_block =3D offset; + } =20 data->bd_inode =3D bdev->bd_inode; bdput(bdev); --=20 2.20.1