From patchwork Thu May 20 13:41:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Righi X-Patchwork-Id: 1481646 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 4Fm9rP3DGrz9sj5; Thu, 20 May 2021 23:41:41 +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 1ljivg-0002Yp-Uu; Thu, 20 May 2021 13:41:36 +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 1ljive-0002Xj-TI for kernel-team@lists.ubuntu.com; Thu, 20 May 2021 13:41:34 +0000 Received: from mail-ej1-f70.google.com ([209.85.218.70]) by youngberry.canonical.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1ljive-0000s9-KF for kernel-team@lists.ubuntu.com; Thu, 20 May 2021 13:41:34 +0000 Received: by mail-ej1-f70.google.com with SMTP id 16-20020a1709063010b029037417ca2d43so5024511ejz.5 for ; Thu, 20 May 2021 06:41:34 -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=TzkWuiuoSDk6Cpyg01VGhgr4fWi8PguXY1aqoIxxemw=; b=Tlkec4Z3Q5WDAvMHa1kRVoTPazYmCUFM709V/PFqFsuP3FC+OBPJ8L/fXQGs9YDJjg 9+mt6a7RDxfQwXh6vC0W0iEhyEp4a0k1xD1dU2uN0KuNpnq2/jB++i+g+5+zTRX9xzsm fQ+ihPMv2nb03+jLoT7QTJZkXdIvsFQ/KnxjcUW8s4JqjELiMCn1SqFzjanhzwuzbKrB 93eAPqvWx/U1hT57MModeli0GyWyCkzz112FtIflpVONHKndjmU1VAwfMBA+s72o83/J 0k9AO0gGjxMFHOGDlQr3zmFBONBjuYLaAyYci99Z4myv34pninMNBuasQi2ULenZ37R9 rSzw== X-Gm-Message-State: AOAM5311Ixcn5F2BfuMaAdvf81EUwLQr8qbZSVxlgb6EC52I1t+wKlqL /BXAuC8G0qCxeUaYQlVqWMuFQG/ZarhZuyOtprfQBV98a+KtjZO6Wx1KJJ7pzfVj0+zpB6l9VY8 uREKkc+XttolPzBauP4xx1yqjaGKzDB8ZrTMItQC6Uw== X-Received: by 2002:a17:906:a245:: with SMTP id bi5mr4983289ejb.316.1621518094319; Thu, 20 May 2021 06:41:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5IHBVkyv3HYhfaumS+RgFCTM+GuX7O+yDuOyJ0LBoeciUHwPQ7vNqUPCNLpHuJ94ehXKhAg== X-Received: by 2002:a17:906:a245:: with SMTP id bi5mr4983275ejb.316.1621518094077; Thu, 20 May 2021 06:41:34 -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 l6sm1417576ejc.92.2021.05.20.06.41.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 May 2021 06:41:33 -0700 (PDT) From: Andrea Righi To: kernel-team@lists.ubuntu.com Subject: [SRU][H][PATCH 2/5] x86/kvm: Teardown PV features on boot CPU as well Date: Thu, 20 May 2021 15:41:27 +0200 Message-Id: <20210520134130.40105-3-andrea.righi@canonical.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520134130.40105-1-andrea.righi@canonical.com> References: <20210520134130.40105-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 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