From patchwork Wed Aug 17 08:51:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerald Yang X-Patchwork-Id: 1667151 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=VvAUz7g5; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4M71x13M0Xz1ygg for ; Wed, 17 Aug 2022 18:52:21 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1oOEmY-0000SU-HY; Wed, 17 Aug 2022 08:52:10 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1oOEmT-0000Mx-8X for kernel-team@lists.ubuntu.com; Wed, 17 Aug 2022 08:52:05 +0000 Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id F17333FB94 for ; Wed, 17 Aug 2022 08:52:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1660726325; bh=MTKOvl9iShw/Xcwg0ZJO5QiRkozHYPDiS/He5/uBwt0=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VvAUz7g5EksxjBkn1XUmRFX48V9pM64lx5iN1gJnDdCA3X1r6q82qfEP0RH80atkp pR2HgIBc9fD0zDf45q9S7iHQ6is3/N7cYqELuHZo/SAlHq01qWB11T56jyNSU7IlRP Tbaubq0w0obr8bH9/awS7aht363YGY9NoKaOWuGKl3jJaQgf36qQsoaeTCUjFnhyMA 0s6XO8GtIQDbxSSPWE5sqcs7cYTxeNgQ7h+ls1CFlMNsrk3aQI3rpk1ky7YMVRCgHd MwX6VbRq60n+wRs/XnLtaxU1R5R81ows6KtKxiNCc4MGzPUjQtVs073tZARTm3xkFH 5/wTN7X7DNaVA== Received: by mail-pg1-f197.google.com with SMTP id z32-20020a631920000000b0042903cb8dfcso3320510pgl.5 for ; Wed, 17 Aug 2022 01:52:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc; bh=MTKOvl9iShw/Xcwg0ZJO5QiRkozHYPDiS/He5/uBwt0=; b=O5uSxe0ayEhzRxP/knpKLhjiPrtI+tXu8W2aq1swMUiOdIafbwTVt46LrcDDdw51fo QHw6SOY8elwTDGYYuHHT+YfdaIB9/ipb69VU4LDCyf9Ul2y71i2eyeZS3IoTfFUQlph4 FD20MZfLzqVnu15kS4V0KnvhgIX+UtbuXfJlqDPwraJBXZEIreWFzB2Qz9JevbzgrDag q6CnksZolbUGQMX34WAUhTdeBpngdCP4dvs8Wug4kViicwhElIxdqlZLMV8JJSfNHAfS 5ksFyoS2wT1/m2wZPlO/z0wtHGEdG1cdJyXgVJAQTZhoQSAMWJhFVfHhoK+RFMg9Twm2 4fgg== X-Gm-Message-State: ACgBeo2WoiCcPk++aStH3E2cvOBfFuvogKXgcBsUKObAV+hGWxgx1LfA 3T5umA5F7cW277L04KAuhk9sRdrf+SRCNPlTFJ5+vwEYxidC/K58J73pN0RsurkM0e/QkaZsvfs 5Wo3pzMrVj/ygPel+y/Z6y58IZ/Vy9BsHKK3ptkllnA== X-Received: by 2002:a62:1c81:0:b0:52f:ccb5:9de1 with SMTP id c123-20020a621c81000000b0052fccb59de1mr24785985pfc.45.1660726323428; Wed, 17 Aug 2022 01:52:03 -0700 (PDT) X-Google-Smtp-Source: AA6agR76FsJlz6xj2AS5a5wrw3fNY1tRzDmvbDWEIOVhGpjDrUhm7yA9lgXVU0NJW7A1KS99M0elIg== X-Received: by 2002:a62:1c81:0:b0:52f:ccb5:9de1 with SMTP id c123-20020a621c81000000b0052fccb59de1mr24785972pfc.45.1660726323079; Wed, 17 Aug 2022 01:52:03 -0700 (PDT) Received: from localhost.localdomain (220-135-31-21.hinet-ip.hinet.net. [220.135.31.21]) by smtp.gmail.com with ESMTPSA id s90-20020a17090a69e300b001f522180d46sm1001033pjj.8.2022.08.17.01.52.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Aug 2022 01:52:02 -0700 (PDT) From: Gerald Yang To: kernel-team@lists.ubuntu.com Subject: [SRU][kinetic/linux-aws][PATCH 05/20] UBUNTU: SAUCE: x86/xen: add system core suspend and resume callbacks Date: Wed, 17 Aug 2022 16:51:33 +0800 Message-Id: <20220817085150.2078055-8-gerald.yang@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220817085150.2078055-1-gerald.yang@canonical.com> References: <20220817085150.2078055-1-gerald.yang@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Munehisa Kamata BugLink: https://bugs.launchpad.net/bugs/1968062 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: Munehisa Kamata Signed-off-by: Anchal Agarwal Reviewed-by: Munehisa Kamata Reviewed-by: Eduardo Valentin CR: https://cr.amazon.com/r/8273204/ (cherry picked from commit bcb1b39880df2f69ec45652a88367861f96de60c amazon-5.15.y/mainline) Signed-off-by: Gerald Yang Signed-off-by: Matthew Ruffell --- arch/x86/xen/enlighten_hvm.c | 1 + arch/x86/xen/suspend.c | 53 ++++++++++++++++++++++++++++++++++++ include/xen/xen-ops.h | 2 ++ 3 files changed, 56 insertions(+) diff --git a/arch/x86/xen/enlighten_hvm.c b/arch/x86/xen/enlighten_hvm.c index 0d6c38c767aa..ebe29d6834f6 100644 --- a/arch/x86/xen/enlighten_hvm.c +++ b/arch/x86/xen/enlighten_hvm.c @@ -221,6 +221,7 @@ static void __init xen_hvm_guest_init(void) if (!no_vector_callback && 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 d37328f2af0f..59bc4417385e 100644 --- a/include/xen/xen-ops.h +++ b/include/xen/xen-ops.h @@ -44,6 +44,8 @@ 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)