From patchwork Tue May 18 15:25:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Righi X-Patchwork-Id: 1480325 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 4Fl0FZ1TKKz9sWW; 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-0001M1-QR; 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-0001Kj-L3 for kernel-team@lists.ubuntu.com; Tue, 18 May 2021 15:25:47 +0000 Received: from mail-ed1-f69.google.com ([209.85.208.69]) by youngberry.canonical.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1lj1bP-0008BO-DC for kernel-team@lists.ubuntu.com; Tue, 18 May 2021 15:25:47 +0000 Received: by mail-ed1-f69.google.com with SMTP id d4-20020aa7ce040000b029038d1d0524d0so5219435edv.3 for ; Tue, 18 May 2021 08:25:47 -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=BzueH+XcoM42yx48+LSLr1skrS5c9FeJvugdy8ZrT1M=; b=iYkv/cC22oyJKc4SqQuBIGW5+6FNKW0I0Au+SZv9J9jjr5y4Y3v03k15EIYk+ZaPSx TEOnMzw9zoNuuMQQLsO3QR0EYrX3ajnpCDtuUaTz5tDVbqPMfgUVOM2IkfBjayCj1/zp M7s9zCZ0ps4kuIVuna0+u45oLvqGFa7WUnV5LztOGWpoyqb1acGQsYxZ4ivE2/JmEKkQ eSY0XJqGLoqSGnIAP8Do0Xm358d7x1/yDa4a3g7n7EItH/O1UBg2sylz2FkPaSfY0Z4L GXAdgdeMi4fwN/wGNCl71LKjdnvzjdLiDSHhUNp8LxE8sIqaA1tvjK3zjToQy8li0W/L 4yoQ== X-Gm-Message-State: AOAM5319vaKhcTl649lT4vZ8LQAiVoYyatTh8M2WZ089tqMR1nmS4h/2 UUs0k9jgEQTz8gAT0Ul7dYWuN2Zl9x6Kx/ZquLYBS9Te+INJiqih11n6AxHLzBpkNIEJzvGs7Iv +Rxjk1RmaQa6kfHJmv4bNIkK1uc5Jb8boYEdsEaVgwg== X-Received: by 2002:a50:fd81:: with SMTP id o1mr7589858edt.107.1621351547120; Tue, 18 May 2021 08:25:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxzR3wEeo7vvHEizkrJhI9K+0OEzglOrTum4WfCy59OxWcyocbHruY9XCWvxSsMSdAuqNwjVA== X-Received: by 2002:a50:fd81:: with SMTP id o1mr7589832edt.107.1621351546849; 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.46 (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 4/6] x86/kvm: Disable kvmclock on all CPUs on shutdown Date: Tue, 18 May 2021 17:25:36 +0200 Message-Id: <20210518152538.197174-5-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 Currenly, we disable kvmclock from machine_shutdown() hook and this only happens for boot CPU. We need to disable it for all CPUs to guard against memory corruption e.g. on restore from hibernate. Note, writing '0' to kvmclock MSR doesn't clear memory location, it just prevents hypervisor from updating the location so for the short while after write and while CPU is still alive, the clock remains usable and correct so we don't need to switch to some other clocksource. 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/include/asm/kvm_para.h | 4 ++-- arch/x86/kernel/kvm.c | 1 + arch/x86/kernel/kvmclock.c | 5 +---- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/kvm_para.h b/arch/x86/include/asm/kvm_para.h index 9b4df6eaa11a..a617fd360023 100644 --- a/arch/x86/include/asm/kvm_para.h +++ b/arch/x86/include/asm/kvm_para.h @@ -6,8 +6,6 @@ #include #include -extern void kvmclock_init(void); - #ifdef CONFIG_KVM_GUEST bool kvm_check_and_clear_guest_paused(void); #else @@ -85,6 +83,8 @@ static inline long kvm_hypercall4(unsigned int nr, unsigned long p1, } #ifdef CONFIG_KVM_GUEST +void kvmclock_init(void); +void kvmclock_disable(void); bool kvm_para_available(void); unsigned int kvm_arch_para_features(void); unsigned int kvm_arch_para_hints(void); diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index 7bf47e41bb46..1d6e64a32278 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -555,6 +555,7 @@ static void kvm_guest_cpu_offline(void) wrmsrl(MSR_KVM_PV_EOI_EN, 0); kvm_pv_disable_apf(); apf_task_wake_all(); + kvmclock_disable(); } static int kvm_cpu_online(unsigned int cpu) diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c index 904494b924c1..bd3962953f78 100644 --- a/arch/x86/kernel/kvmclock.c +++ b/arch/x86/kernel/kvmclock.c @@ -214,11 +214,9 @@ static void kvm_crash_shutdown(struct pt_regs *regs) } #endif -static void kvm_shutdown(void) +void kvmclock_disable(void) { native_write_msr(msr_kvm_system_time, 0, 0); - kvm_disable_steal_time(); - native_machine_shutdown(); } static void __init kvmclock_init_mem(void) @@ -346,7 +344,6 @@ void __init kvmclock_init(void) #endif x86_platform.save_sched_clock_state = kvm_save_sched_clock_state; x86_platform.restore_sched_clock_state = kvm_restore_sched_clock_state; - machine_ops.shutdown = kvm_shutdown; #ifdef CONFIG_KEXEC_CORE machine_ops.crash_shutdown = kvm_crash_shutdown; #endif