From patchwork Wed May 26 05:15:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Righi X-Patchwork-Id: 1483871 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 4FqfLG3MLGz9sWT; Wed, 26 May 2021 15:16:05 +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 1llltg-0001hC-UE; Wed, 26 May 2021 05:16:00 +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 1llltf-0001gY-W1 for kernel-team@lists.ubuntu.com; Wed, 26 May 2021 05:15:59 +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 1llltf-0004D0-Nl for kernel-team@lists.ubuntu.com; Wed, 26 May 2021 05:15:59 +0000 Received: by mail-ed1-f69.google.com with SMTP id x3-20020a50ba830000b029038caed0dd2eso18678521ede.7 for ; Tue, 25 May 2021 22:15:59 -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=H0642PfIAa7cyDD8OKUv04YPqH7qULLAc61bNuB6j3A=; b=tJDwe1zBZoCjaTtyZX/WIEWlYunjNsormbWWT43tQaZAxgeCdSvqzaj9YWAs8zITLQ XAZFF+4t3fUFC5JlPVQSkAxu35M6svpSC3DS/FCb5gz5t9z9k/EN1t3jpeZAnENmTPEi ZenvM2WRprQUJiMsEE59DrbLmTPOtAXEyKFdT6o5U1jFI1aC42gI0X63vGYvqArPx/v2 HsNWAQrmi7CI85e3f6YWJ8Ys5hXHExqVQ43tA4O/Yhv0HYcffD+3LuFrLqfgEMPpx3zW VH22rc0ajLWL998BS6TSmgVWxio19uDtIwtBhqp+406SpqQyT0Lk8FraWXSQ1xIcKOGS z1YA== X-Gm-Message-State: AOAM531VbOceaTdRk+3XLNQ+lcGBGV9fQbaYQFpRveC3KpMbfC1XMPXR mo0xiEhD3Y78vFzExIc9X3s52ZLgedBHJQYCX3FJ4bI91mZBlDWih0Z5jdOp1lzsBFZO6jjpZ2m l5xuMHcUaK8HFRHOxZgGMeU9M+Dvaux7tgLmLcXHXxQ== X-Received: by 2002:a05:6402:10c9:: with SMTP id p9mr6789746edu.370.1622006159480; Tue, 25 May 2021 22:15:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyX0ERu9MH+YhdIC0iP+eUkEIE7HaJ0YmeIkn0SLwuCBeI5lDHNO/cJlP9f2ez9Evd1e1cNUw== X-Received: by 2002:a05:6402:10c9:: with SMTP id p9mr6789723edu.370.1622006159162; Tue, 25 May 2021 22:15:59 -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 z4sm11704098edc.1.2021.05.25.22.15.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 May 2021 22:15:58 -0700 (PDT) From: Andrea Righi To: kernel-team@lists.ubuntu.com Subject: [SRU][F][PATCH v2 3/5] x86/kvm: Disable kvmclock on all CPUs on shutdown Date: Wed, 26 May 2021 07:15:45 +0200 Message-Id: <20210526051547.217632-4-andrea.righi@canonical.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210526051547.217632-1-andrea.righi@canonical.com> References: <20210526051547.217632-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 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 29082944956b..35cd7baf2ad7 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -434,6 +434,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