From patchwork Tue May 18 15:25:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Righi X-Patchwork-Id: 1480324 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 4Fl0FY4Yq3z9sXM; Wed, 19 May 2021 01:25:53 +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 1lj1bR-0001Ld-JQ; Tue, 18 May 2021 15:25:49 +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 1lj1bP-0001KZ-2Z for kernel-team@lists.ubuntu.com; Tue, 18 May 2021 15:25:47 +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 1lj1bO-0008BF-Qd for kernel-team@lists.ubuntu.com; Tue, 18 May 2021 15:25:46 +0000 Received: by mail-ej1-f70.google.com with SMTP id gt39-20020a1709072da7b02903a8f7736a08so2540032ejc.1 for ; Tue, 18 May 2021 08:25:46 -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=uME5h5fLmEEeNRh0rbd74ZP9belwkK0F2/GJbFKp7Pc=; b=JrjvsLORWWqxVOr5Xir8Ji8J2c4lL4vjPmattqbwdjKGb/pF2zkQ0s4UE9tz9upTMd rPlmOZbRG+1LrKrBvdx3YIUJja/mge3LmKZku3u+CbZZ8eCy4cRH4qalPd75u7vys4hb QaMsvUtVRdxmxp9uqIRzzjBIfaxrUoOyN9Q4DagomVOSYX490np1jMZYickwv4lfjFNK PumI9CTaw0msQtjimTS5F6PdpbTB4cfEMoLqFsnu6qxUnDcQRPAmyjGXTvJqaNM7zLMk 4SYNEkrEoGkVR9240SKK1wnJM749rFKbMFNV3x60/Evg7EBrLYGNFHEP8G033DQAYKOa l2Rg== X-Gm-Message-State: AOAM530RHLEdz52IgRdB0Z3Fzjd/lpIYE9FrS5jdeonm8CENMjzH6zB1 4phQi8sAEasCUWj9CbtQIzdzySyvzG2WZ/KKSPG0SSxMgtP26EJVSXXsFomdxQ9/i8kaU/wafqO HXlUxyAD48aZmMzy6sjTAbWlZ5OVaZTS6y3CIJjrhOQ== X-Received: by 2002:a50:fd17:: with SMTP id i23mr8014036eds.54.1621351546559; Tue, 18 May 2021 08:25:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwA6Vw9mnjcEQw14Jpete/rLZcmrCpqteN5BtbCX0FxEuQgq3tTblNgDjLFgq6CFupwAzGy9Q== X-Received: by 2002:a50:fd17:: with SMTP id i23mr8014008eds.54.1621351546310; Tue, 18 May 2021 08:25:46 -0700 (PDT) Received: from xps-13-7390.homenet.telecomitalia.it (host-79-19-135-103.retail.telecomitalia.it. [79.19.135.103]) by smtp.gmail.com with ESMTPSA id d11sm4969896ejr.58.2021.05.18.08.25.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 May 2021 08:25:46 -0700 (PDT) From: Andrea Righi To: kernel-team@lists.ubuntu.com Subject: [SRU][F/aws][PATCH v2 3/6] x86/kvm: Teardown PV features on boot CPU as well Date: Tue, 18 May 2021 17:25:35 +0200 Message-Id: <20210518152538.197174-4-andrea.righi@canonical.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210518152538.197174-1-andrea.righi@canonical.com> References: <20210518152538.197174-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 (backported from http://next.patchew.org/Linux/20210414123544.1060604-1-vkuznets@redhat.com/) 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