From patchwork Wed May 26 05:17:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Righi X-Patchwork-Id: 1483876 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 4FqfNP5ZhWz9s1l; Wed, 26 May 2021 15:17:57 +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 1lllvV-00026p-DE; Wed, 26 May 2021 05:17:53 +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 1lllvT-00025A-96 for kernel-team@lists.ubuntu.com; Wed, 26 May 2021 05:17:51 +0000 Received: from mail-ed1-f70.google.com ([209.85.208.70]) by youngberry.canonical.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1lllvT-0004Ng-1E for kernel-team@lists.ubuntu.com; Wed, 26 May 2021 05:17:51 +0000 Received: by mail-ed1-f70.google.com with SMTP id c21-20020a0564021015b029038c3f08ce5aso18769738edu.18 for ; Tue, 25 May 2021 22:17:51 -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=RDtaF0XulObDXaTH81Eo+oZvgVxGgr9fJViIuqZBWqc=; b=nFwKo0uhDJxzMqnNExhCXQTZSkh4f3GW2EivUcIXd++e9/4+7QJubfgWOmMIoBkaVM N0vOlXq/ZA5NswCwxhmRL93VVhZlF6RugxuGBTBABmHH1pg0hv7WXl1KLR3lixljufRT j49GCbjVPstfqM2XnSr+5MFzPZj0eb5qyfOI0JG/FC27DlHR5qGHB4bhpsfp2pZMHeGo Djb5n+007Vi8ToJNMwWURQMwWZRRESvFWpBn1pvZzgn4nu1CW/uKRFd8Mwp+zrIlHnkD Fb42QocTHPwX7ZJVIQr4M5JED3qrY+vgJ2pTYqXm2YCQax09SkWK95h8MwPZYDkkJ1TH duPw== X-Gm-Message-State: AOAM531fWYgCpUM4hxS2rADDFY0y2WSELdCGbSAQaRT09/FISEzyhjD+ sc2VyI/3LmGtntCkf5RM4VQgAEkVpdjUr/LkMln4WPP2FmFhY6uiAfPzL+Yyi90Z5nWBRpy2JKy M4v1uLgWtlJBz7Rlrrj2BGKzmdFlYmBCTZ2QxC4kLBQ== X-Received: by 2002:a05:6402:1052:: with SMTP id e18mr36646568edu.366.1622006270786; Tue, 25 May 2021 22:17:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqVdG9QV1RJxHjYZXPVxdYE7+qpmfXETqd7ieVUDukhB2yBo9cLkRKF8dprLNZvjZxdMPe+A== X-Received: by 2002:a05:6402:1052:: with SMTP id e18mr36646547edu.366.1622006270527; Tue, 25 May 2021 22:17:50 -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 bh3sm9783270ejb.19.2021.05.25.22.17.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 May 2021 22:17:50 -0700 (PDT) From: Andrea Righi To: kernel-team@lists.ubuntu.com Subject: [SRU][G][PATCH v2 3/5] x86/kvm: Disable kvmclock on all CPUs on shutdown Date: Wed, 26 May 2021 07:17:42 +0200 Message-Id: <20210526051744.218062-4-andrea.righi@canonical.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210526051744.218062-1-andrea.righi@canonical.com> References: <20210526051744.218062-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 Message-Id: <20210414123544.1060604-4-vkuznets@redhat.com> Signed-off-by: Paolo Bonzini (cherry picked from commit c02027b5742b5aa804ef08a4a9db433295533046) 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 49d3a9edb06f..43cc4a396bee 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 4dc69777417a..74d6c0e344ba 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -438,6 +438,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 5ee705b44560..327a0de01066 100644 --- a/arch/x86/kernel/kvmclock.c +++ b/arch/x86/kernel/kvmclock.c @@ -221,11 +221,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) @@ -352,7 +350,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