From patchwork Wed May 19 15:15:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Righi X-Patchwork-Id: 1480996 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 4Flbz75lD3z9sW4; Thu, 20 May 2021 01:15: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 1ljNux-0001uy-Nj; Wed, 19 May 2021 15:15: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 1ljNuq-0001qQ-3h for kernel-team@lists.ubuntu.com; Wed, 19 May 2021 15:15:20 +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 1ljNup-0003nW-SC for kernel-team@lists.ubuntu.com; Wed, 19 May 2021 15:15:19 +0000 Received: by mail-ed1-f72.google.com with SMTP id ba15-20020a0564021acfb029038d3b33d7ffso5225396edb.23 for ; Wed, 19 May 2021 08:15: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=drGvjTbo2kCYG9vAw0ofeMkFYC60Cw7g9Ei4i+i4sY0=; b=sBNGjksxTxaZ1ycW1UODiEQvEpVE6bYSaU1PbsHa10Yp4KBCxjhfGs6E8HPPZcAuMd KOytcXwz0OvhSvj+DaBE6oE8a4/jIwScCvZYyeqzawvHQmRL2yMaW17yxq6FCg/6oi6b ytAC9uPGlqbxsoLIhZPDRzQ5BYZPdLNw+XqsAh7WlLia1HaCrV74mE+qSY7a8iS9JFeD G7kMsrjXYawtMyQah6LJW/d8683DoIqBoUqF5lryLApBs2VFlo8ZC1iEcfDFLDCbQSxl n9bbivKN30GStk2pmTW63DQ79sRqxDFZ9vQKo3mxB4iD+yLBhhCNM6dU5TItE8x/Ix0Y 6v6A== X-Gm-Message-State: AOAM530ygJmaS+bGg4LtulPnsUifqViURijrMu3rGS+4nBGcksGOrlEL /oykBWhDefVqv5uMOUaEgJsJsKiW5ri50FcCo7mJQg/1lnYcpk3GV1lj7pbvWUhLvYhB67uI8wd 3fqZ+vvGDna9KUvrpABXBYscJkTQQBbG2t8c/b96fwA== X-Received: by 2002:a17:906:1dc2:: with SMTP id v2mr3708216ejh.8.1621437319520; Wed, 19 May 2021 08:15:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtzSNzhNpK8rrVReAVG2dfBV5mfRBj8XWLXdaeMbzGHxaVt5CqnRKbUNofDqzr1vOpSvKHtg== X-Received: by 2002:a17:906:1dc2:: with SMTP id v2mr3708203ejh.8.1621437319278; Wed, 19 May 2021 08:15:19 -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 d17sm5624051ejp.90.2021.05.19.08.15.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 May 2021 08:15:19 -0700 (PDT) From: Andrea Righi To: kernel-team@lists.ubuntu.com Subject: [SRU][F/aws][PATCH 3/6] x86/kvm: Teardown PV features on boot CPU as well Date: Wed, 19 May 2021 17:15:10 +0200 Message-Id: <20210519151513.309935-4-andrea.righi@canonical.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210519151513.309935-1-andrea.righi@canonical.com> References: <20210519151513.309935-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