From patchwork Thu May 20 13:36:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Righi X-Patchwork-Id: 1481628 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 4Fm9kJ1mXfz9sWX; Thu, 20 May 2021 23:36:23 +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 1ljiqZ-0001cN-Vk; Thu, 20 May 2021 13:36:19 +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 1ljiqX-0001bK-RI for kernel-team@lists.ubuntu.com; Thu, 20 May 2021 13:36:17 +0000 Received: from mail-ej1-f71.google.com ([209.85.218.71]) by youngberry.canonical.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1ljiqX-0000LU-Ii for kernel-team@lists.ubuntu.com; Thu, 20 May 2021 13:36:17 +0000 Received: by mail-ej1-f71.google.com with SMTP id p25-20020a1709061419b0290378364a6464so5002778ejc.15 for ; Thu, 20 May 2021 06:36:17 -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=drGvjTbo2kCYG9vAw0ofeMkFYC60Cw7g9Ei4i+i4sY0=; b=QlKLAXzzFhD72ujEIzR8rwlsBRvCc9PsZFuY0mEJkHHfxYsJCtNfxj2ipwKzhv7U1e 0i0sbAAbHbsPOUbrH9qTV2tIfgQJ50sxPhb/k0tNamc7WRU7Zfjq3QN2ktDDl0uikoLD 12kvgDWxwfGABIpfGu35g5ABE8BGsmBahoFH+jr2a4WjEhvLOVRvHeJUTOWFEEgGMUgz IxLAAmmAGtxIIZyG7+tB025D8E9VPMRAQBdeQeeg9Ztigwl8Z/+8VQzsTEF5BwWW9UeV DUHnwMLgEB+FwaTuMTcyy0COIZf+VV2OtjQgMtJc05BjgDgZzNjOamJUy8j6mBpLl4Wf cJGQ== X-Gm-Message-State: AOAM531lBHpqUMG9ebOCvSaoAH7828orHwvefF8xMYBIkWpyRt7s1uH5 Zx0q2rtbzsWchgNwdpnP5kSRB26/CorKNWsclLLGVKffvlS7kXK6opIIBcnFvwD+ULiHTvVHUQP pRphqkOUGp3Dt/XUT3r/txT/zjgqyoV83ReAcshKicg== X-Received: by 2002:a17:906:17ca:: with SMTP id u10mr4699940eje.124.1621517777274; Thu, 20 May 2021 06:36:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFjZ4ySVrv/sR4yLi2AN8mKrtYTY/8B9WY/sQfvUDpxKi8fDOSA9XBFGbLF7lzTc27FeNpUQ== X-Received: by 2002:a17:906:17ca:: with SMTP id u10mr4699918eje.124.1621517777012; Thu, 20 May 2021 06:36:17 -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 gw6sm936959ejb.86.2021.05.20.06.36.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 May 2021 06:36:16 -0700 (PDT) From: Andrea Righi To: kernel-team@lists.ubuntu.com Subject: [SRU][F][PATCH 2/5] x86/kvm: Teardown PV features on boot CPU as well Date: Thu, 20 May 2021 15:36:08 +0200 Message-Id: <20210520133611.39540-3-andrea.righi@canonical.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520133611.39540-1-andrea.righi@canonical.com> References: <20210520133611.39540-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 8b79feffeca28c5459458fe78676b081e87c93a4) Signed-off-by: Andrea Righi --- arch/x86/kernel/kvm.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index ec7e4b9f50a5..7bf47e41bb46 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -558,17 +559,21 @@ static void kvm_guest_cpu_offline(void) static int kvm_cpu_online(unsigned int cpu) { - local_irq_disable(); + unsigned long flags; + + local_irq_save(flags); kvm_guest_cpu_init(); - local_irq_enable(); + local_irq_restore(flags); return 0; } static int kvm_cpu_down_prepare(unsigned int cpu) { - local_irq_disable(); + unsigned long flags; + + local_irq_save(flags); kvm_guest_cpu_offline(); - local_irq_enable(); + local_irq_restore(flags); return 0; } #endif @@ -606,6 +611,23 @@ static void kvm_flush_tlb_others(const struct cpumask *cpumask, native_flush_tlb_others(flushmask, info); } +static int kvm_suspend(void) +{ + kvm_guest_cpu_offline(); + + return 0; +} + +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 __init kvm_guest_init(void) { int i; @@ -649,6 +671,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