From patchwork Wed May 26 05:17:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Righi X-Patchwork-Id: 1483875 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 4FqfNN2bpDz9sW7; Wed, 26 May 2021 15:17:56 +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 1lllvV-00026M-18; Wed, 26 May 2021 05:17:53 +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 1lllvS-000254-Ls for kernel-team@lists.ubuntu.com; Wed, 26 May 2021 05:17:50 +0000 Received: from mail-ej1-f72.google.com ([209.85.218.72]) by youngberry.canonical.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1lllvS-0004NW-DY for kernel-team@lists.ubuntu.com; Wed, 26 May 2021 05:17:50 +0000 Received: by mail-ej1-f72.google.com with SMTP id p5-20020a17090653c5b02903db1cfa514dso46347ejo.13 for ; Tue, 25 May 2021 22:17:50 -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=5shXqSq94BD7EbdsG7sg/d43dq5eHsrbGEBDcUivfTA=; b=YbtatMzA82fGja+eMcoTFNrbXN46mlMgNJs+BsoITFabAxWtxNT6ITn+Pkc56Hmoxd qBno+HsJZbLfgKqUD1IY3QgKCzEigJwyzBsVb8OWGh7XETBZTd096IcQDhN8DPuujkDs M9o3NYUQaLeA7XAlU4bBumo2mohgMgdVCnlWxh3FQWTL4DGOFATa/Kgn0l0498LgDoV2 dLg96RbmA8m2QADthems9G2WQ2VaDt7uYjxk1QlIRJWN3ttJap6Dxb0RR3qzkJvghUb8 mYNcpw8Myh1acHisOoYsOsSIgJ9DEBIy5Qg1uvazKy1HaxhU/lQJ/hiSSdusdQH7fWkQ tm4w== X-Gm-Message-State: AOAM531Llidy3jJevN3CN3ZFYRhkR8c7RU/CWnsvAYtwkxvRFUzFtRHR o0UTcP3g3BEaoc8CDpiQN8+dQ9bO+xRn+IkgYWt1i1+oSECiT569gxq/V1c0QATtP99Iuqgxs3z iSi17Rz4SmcU+lR4DlmtqmDI+F3I0UZHMhuz8clEUPw== X-Received: by 2002:a50:bf0f:: with SMTP id f15mr33805479edk.205.1622006270133; Tue, 25 May 2021 22:17:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLVs1Vn3OjDKUSMnRThL2JNA68djtNWTnmjorz0JYkle2dQMt7kRxEBlGxi7bfNC7eD3kaiQ== X-Received: by 2002:a50:bf0f:: with SMTP id f15mr33805460edk.205.1622006269913; Tue, 25 May 2021 22:17:49 -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 bh3sm9783270ejb.19.2021.05.25.22.17.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 May 2021 22:17:49 -0700 (PDT) From: Andrea Righi To: kernel-team@lists.ubuntu.com Subject: [SRU][G][PATCH v2 2/5] x86/kvm: Teardown PV features on boot CPU as well Date: Wed, 26 May 2021 07:17:41 +0200 Message-Id: <20210526051744.218062-3-andrea.righi@canonical.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210526051744.218062-1-andrea.righi@canonical.com> References: <20210526051744.218062-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 0fee42222a8f..4dc69777417a 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -430,6 +431,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) && @@ -571,31 +591,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) @@ -664,6 +687,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