Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2281700ybv; Fri, 14 Feb 2020 15:25:10 -0800 (PST) X-Google-Smtp-Source: APXvYqwIZKefnkdauQhSDClJCi6j3/v3/3KHSRSY64uLV8y86iMJ+SsB0WKJxRc2JI+N4hNSEzMJ X-Received: by 2002:a05:6830:1e37:: with SMTP id t23mr4294536otr.16.1581722710424; Fri, 14 Feb 2020 15:25:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581722710; cv=none; d=google.com; s=arc-20160816; b=hp6JRTGHUdAOeD+mNTWK1rFoQySj8sVPqiDBPLKEY4/UDXBQtO5HFl7kFOjQhq6PlM yuJEbTUfkn1C96X8T4g5bzU1cz3ROqj4D8ZwlJ21k/hlSaHXBsA5tSA7gWhvdbonYcE+ EFU/+vw2c+BvY/E7jnkfUryF5mehE6bAP+OyuqTsyiiJ4U57EuEfyf0Ksr8mu2P/ZIS+ KTVEhdPm2uXVzaC/Qu1hETmFdEGTe8pBEwlDs5B9anwyOpFfO7PLnnl/SlO66jizXU2Z 3ra+izyFk+nFpFC+xysxPq4z7Dk2om7Ym+yZk0wxBVf363kukhO4FXJemIffM313ODdF AlKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:to :from:date:ironport-sdr:dkim-signature; bh=O4TyplSL+UdPLY/NuUPDprwnMfLeEuUi3w9c5rcDMEE=; b=T2chogBcYU8p/uPeYSx2DVUhKyYr1mvFC1Ak+8rK/6fb860ONYuIEL75Cdbvu0RyYQ +h7yoovIs1yy+ANO9U1fP0YTuWyQFnZQ0MMNI2rFFqFPVBItAJrfPxdEQCLNd5gbjX/8 ad37KuVVXrHBqa/1UxInDMozTUe8ou/PXVwz/Dl++76EMQNB35ClZQcx/hXwYXg9vMuT /8UIYRNpotrM+CTgy9LMyQSBzfW3jWK4woGT05TGUCRCe2EvBCMx3PAQnc1AqLEV4IZ0 kmbIq/Tw3eW4tsAeaYJY2us7zZTLZ+rYimQ/A/zM5KSqA9eiaTIZm693gYaES/CzFkD1 RdJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=Mgk0Dq1O; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p19si3759667otk.251.2020.02.14.15.24.57; Fri, 14 Feb 2020 15:25:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=Mgk0Dq1O; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728176AbgBNXYt (ORCPT + 99 others); Fri, 14 Feb 2020 18:24:49 -0500 Received: from smtp-fw-33001.amazon.com ([207.171.190.10]:19684 "EHLO smtp-fw-33001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727649AbgBNXYs (ORCPT ); Fri, 14 Feb 2020 18:24:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1581722688; x=1613258688; h=date:from:to:subject:message-id:references:mime-version: in-reply-to; bh=O4TyplSL+UdPLY/NuUPDprwnMfLeEuUi3w9c5rcDMEE=; b=Mgk0Dq1O8Jq52EqeAClb4ctgTMPGRrN41Qi5hucpS+1YlNy3qcH83x7y bji9MIg3zxk+pxyD9APV8BvbcaPPUlj5F0DnuoYdWiAbiXGJR685fvpc/ jpt2mmteyKVUldijdhKZs7dGZhqKnlc/d5q2F/jPyNXH44EkXbKe1XUDB I=; IronPort-SDR: jucGW3i6+D+Zt1UnEu8igkzhVY7ZncQ6ZmzcjtF2QWs4I5Qu8TXOsW70zoTfaFnk99NzPxn2lB 9Cxg1E1dRtaQ== X-IronPort-AV: E=Sophos;i="5.70,442,1574121600"; d="scan'208";a="26558627" 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; 14 Feb 2020 23:24:45 +0000 Received: from EX13MTAUWB001.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 15478A2998; Fri, 14 Feb 2020 23:24:38 +0000 (UTC) Received: from EX13D05UWB003.ant.amazon.com (10.43.161.26) by EX13MTAUWB001.ant.amazon.com (10.43.161.207) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Fri, 14 Feb 2020 23:24:19 +0000 Received: from EX13MTAUWB001.ant.amazon.com (10.43.161.207) by EX13D05UWB003.ant.amazon.com (10.43.161.26) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Fri, 14 Feb 2020 23:24:18 +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.1367.3 via Frontend Transport; Fri, 14 Feb 2020 23:24:18 +0000 Received: by dev-dsk-anchalag-2a-9c2d1d96.us-west-2.amazon.com (Postfix, from userid 4335130) id DCDD44028E; Fri, 14 Feb 2020 23:24:18 +0000 (UTC) Date: Fri, 14 Feb 2020 23:24:18 +0000 From: Anchal Agarwal To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC PATCH v3 04/12] x86/xen: add system core suspend and resume callbacks Message-ID: <49b41926cf0d2b50a9632d425cd09257853ca73b.1581721799.git.anchalag@amazon.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Munehisa Kamata Add Xen PVHVM specific system core callbacks for PM suspend and hibernation support. The callbacks suspend and resume Xen primitives,like shared_info, pvclock and grant table. Note that Xen suspend can handle them in a different manner, but system core callbacks are called from the context. So if the callbacks are called from Xen suspend context, return immediately. Signed-off-by: Agarwal Anchal Signed-off-by: Munehisa Kamata --- arch/x86/xen/enlighten_hvm.c | 1 + arch/x86/xen/suspend.c | 53 ++++++++++++++++++++++++++++++++++++ include/xen/xen-ops.h | 3 ++ 3 files changed, 57 insertions(+) diff --git a/arch/x86/xen/enlighten_hvm.c b/arch/x86/xen/enlighten_hvm.c index 75b1ec7a0fcd..138e71786e03 100644 --- a/arch/x86/xen/enlighten_hvm.c +++ b/arch/x86/xen/enlighten_hvm.c @@ -204,6 +204,7 @@ static void __init xen_hvm_guest_init(void) if (xen_feature(XENFEAT_hvm_callback_vector)) xen_have_vector_callback = 1; + 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..784c4484100b 100644 --- a/arch/x86/xen/suspend.c +++ b/arch/x86/xen/suspend.c @@ -2,17 +2,22 @@ #include #include #include +#include +#include #include #include +#include #include #include +#include #include #include #include #include #include +#include #include "xen-ops.h" #include "mmu.h" @@ -82,3 +87,51 @@ void xen_arch_suspend(void) on_each_cpu(xen_vcpu_notify_suspend, NULL, 1); } + +static int xen_syscore_suspend(void) +{ + struct xen_remove_from_physmap xrfp; + int ret; + + /* Xen suspend does similar stuffs in its own logic */ + if (xen_suspend_mode_is_xen_suspend()) + return 0; + + xrfp.domid = DOMID_SELF; + xrfp.gpfn = __pa(HYPERVISOR_shared_info) >> PAGE_SHIFT; + + ret = HYPERVISOR_memory_op(XENMEM_remove_from_physmap, &xrfp); + if (!ret) + HYPERVISOR_shared_info = &xen_dummy_shared_info; + + return ret; +} + +static void xen_syscore_resume(void) +{ + /* Xen suspend does similar stuffs in its own logic */ + if (xen_suspend_mode_is_xen_suspend()) + return; + + /* 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 = { + .suspend = xen_syscore_suspend, + .resume = 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 6c36e161dfd1..3b3992b5b0c2 100644 --- a/include/xen/xen-ops.h +++ b/include/xen/xen-ops.h @@ -43,6 +43,9 @@ int xen_setup_shutdown_event(void); bool xen_suspend_mode_is_xen_suspend(void); bool xen_suspend_mode_is_pm_suspend(void); bool xen_suspend_mode_is_pm_hibernation(void); + +void xen_setup_syscore_ops(void); + extern unsigned long *xen_contiguous_bitmap; #if defined(CONFIG_XEN_PV) || defined(CONFIG_ARM) || defined(CONFIG_ARM64) -- 2.24.1.AMZN