From patchwork Wed May 26 05:19:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Righi X-Patchwork-Id: 1483883 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FqfQD1Hl4z9s1l; Wed, 26 May 2021 15:19:31 +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 1lllx1-0002Ux-OO; Wed, 26 May 2021 05:19:27 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1lllwt-0002PO-KT for kernel-team@lists.ubuntu.com; Wed, 26 May 2021 05:19:19 +0000 Received: from mail-ed1-f72.google.com ([209.85.208.72]) by youngberry.canonical.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1lllwt-0004SP-B8 for kernel-team@lists.ubuntu.com; Wed, 26 May 2021 05:19:19 +0000 Received: by mail-ed1-f72.google.com with SMTP id c15-20020a05640227cfb029038d710bf29cso12583866ede.16 for ; Tue, 25 May 2021 22:19:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=34Z4YJbdTzoUkU1Oj/+0m8YJ1H4Gim1rzOBOETzaTV4=; b=MqVEz09GOBQkSF9rJQkht5lhFDdTHlrz64LlD1AQVBFlNfyw248m77Q25rtn+gR3me csOrk1/40Gpm3IsdDCZP3wsPZGisKutGCbl8rfe8zobDfjw7r1A9oT5Xxqr0kryhbBFZ LnfY/3LxjdlkJCqvAAUbyy0NZHroUmg/nCls9O4sJw5k5KFzeQWDMAAJRuBw8AfYUEpb MOhN545yJqhNEmmzCJO6ckwaiWRfAMUh3n4SQvmbM7KXhdd4b2HBa57gKkHbcpDj6IFp t2WLV/XMf6Lx/lurXAjqB8BBY8Qxv8GsS4VAZrn3rsEZLEnkKDSRpfHLcspO8h6weRqK Pk1g== X-Gm-Message-State: AOAM531ZIzsSylbHw3s8tm4jSExfhnk8yeFRBkCTyCBSdJzMlnY0Qjap 8+q2JkUFrzGQD5XQ+liCujqyaoPHheWKWIT3hG8+ZW1BmBj94YQI9GbZ0j7lUc6cIIg1PsRcML8 Au/9FT8YEwlYFsUwIXi9imu0ct2i42UALZtyTDeCAxw== X-Received: by 2002:a17:906:40d1:: with SMTP id a17mr31943734ejk.43.1622006359009; Tue, 25 May 2021 22:19:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzm1x4GzSG3buLBH252okePRqbpftPA7nOIAePUpRi7YsVoe3xJi3Qr4Cj+hjLG/BfxylcOhA== X-Received: by 2002:a17:906:40d1:: with SMTP id a17mr31943720ejk.43.1622006358824; Tue, 25 May 2021 22:19:18 -0700 (PDT) Received: from xps-13-7390.homenet.telecomitalia.it (host-87-19-3-42.retail.telecomitalia.it. [87.19.3.42]) by smtp.gmail.com with ESMTPSA id t19sm12131888eds.4.2021.05.25.22.19.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 May 2021 22:19:18 -0700 (PDT) From: Andrea Righi To: kernel-team@lists.ubuntu.com Subject: [SRU][H][PATCH v2 2/5] x86/kvm: Teardown PV features on boot CPU as well Date: Wed, 26 May 2021 07:19:12 +0200 Message-Id: <20210526051915.218316-3-andrea.righi@canonical.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210526051915.218316-1-andrea.righi@canonical.com> References: <20210526051915.218316-1-andrea.righi@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: Vitaly Kuznetsov BugLink: https://bugs.launchpad.net/bugs/1920944 Various PV features (Async PF, PV EOI, steal time) work through memory shared with hypervisor and when we restore from hibernation we must properly teardown all these features to make sure hypervisor doesn't write to stale locations after we jump to the previously hibernated kernel (which can try to place anything there). For secondary CPUs the job is already done by kvm_cpu_down_prepare(), register syscore ops to do the same for boot CPU. Signed-off-by: Vitaly Kuznetsov Message-Id: <20210414123544.1060604-3-vkuznets@redhat.com> Signed-off-by: Paolo Bonzini (backported from commit 8b79feffeca28c5459458fe78676b081e87c93a4) Signed-off-by: Andrea Righi --- arch/x86/kernel/kvm.c | 57 +++++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index 2047e751e15f..d2448c1831e0 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -451,6 +452,25 @@ static void __init sev_map_percpu_data(void) } } +static void kvm_guest_cpu_offline(void) +{ + kvm_disable_steal_time(); + if (kvm_para_has_feature(KVM_FEATURE_PV_EOI)) + wrmsrl(MSR_KVM_PV_EOI_EN, 0); + kvm_pv_disable_apf(); + apf_task_wake_all(); +} + +static int kvm_cpu_online(unsigned int cpu) +{ + unsigned long flags; + + local_irq_save(flags); + kvm_guest_cpu_init(); + local_irq_restore(flags); + return 0; +} + static bool pv_tlb_flush_supported(void) { return (kvm_para_has_feature(KVM_FEATURE_PV_TLB_FLUSH) && @@ -587,31 +607,34 @@ static void __init kvm_smp_prepare_boot_cpu(void) kvm_spinlock_init(); } -static void kvm_guest_cpu_offline(void) +static int kvm_cpu_down_prepare(unsigned int cpu) { - kvm_disable_steal_time(); - if (kvm_para_has_feature(KVM_FEATURE_PV_EOI)) - wrmsrl(MSR_KVM_PV_EOI_EN, 0); - kvm_pv_disable_apf(); - apf_task_wake_all(); -} + unsigned long flags; -static int kvm_cpu_online(unsigned int cpu) -{ - local_irq_disable(); - kvm_guest_cpu_init(); - local_irq_enable(); + local_irq_save(flags); + kvm_guest_cpu_offline(); + local_irq_restore(flags); return 0; } -static int kvm_cpu_down_prepare(unsigned int cpu) +#endif + +static int kvm_suspend(void) { - local_irq_disable(); kvm_guest_cpu_offline(); - local_irq_enable(); + return 0; } -#endif + +static void kvm_resume(void) +{ + kvm_cpu_online(raw_smp_processor_id()); +} + +static struct syscore_ops kvm_syscore_ops = { + .suspend = kvm_suspend, + .resume = kvm_resume, +}; static void kvm_flush_tlb_others(const struct cpumask *cpumask, const struct flush_tlb_info *info) @@ -681,6 +704,8 @@ static void __init kvm_guest_init(void) kvm_guest_cpu_init(); #endif + register_syscore_ops(&kvm_syscore_ops); + /* * Hard lockup detection is enabled by default. Disable it, as guests * can get false positives too easily, for example if the host is