From patchwork Wed May 19 15:15:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Righi X-Patchwork-Id: 1480995 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 4Flbz34V0tz9sWl; Thu, 20 May 2021 01:15:27 +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 1ljNut-0001s3-5a; Wed, 19 May 2021 15:15:23 +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-0001qe-Lv for kernel-team@lists.ubuntu.com; Wed, 19 May 2021 15:15:20 +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 1ljNuq-0003nm-Ew for kernel-team@lists.ubuntu.com; Wed, 19 May 2021 15:15:20 +0000 Received: by mail-ed1-f70.google.com with SMTP id y17-20020a0564023591b02903886c26ada4so7885479edc.5 for ; Wed, 19 May 2021 08:15:20 -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=GC92v1JQXoPtJq3VFMogDIHk7VyC/mMb9xItaa6wApo=; b=mebQNmf3L3BMRu85H/zmeO6j0bqG5cPdcl8CdNtZYnK5oE0onAlfFz0RLt2NZpoOlD WUQOTF0h2NVUIvfjdIjmPwMFTTFKau0ZrH/O8/V+xcn5gl5QdFwfZLego5bWtHWV6J8/ KpjZdS/5a1u47kQDWbtwJ15iHBM/2N+xUybagwHUTiehwKatWyEGm1THoom+smOA/upB 4AKG7MP2+UD3OS2d+dGSKMkk4FdEQSvQ/y/qpiU1pU6ZdArRte8GV76jjzP3ZJyG2mSW SxqaQW8RBbixLRpFGLOQREcaYCGQtYD4vgg3XxbuwRYHsYZR1i/QXo458ZWinMxhJ6Cv N1dA== X-Gm-Message-State: AOAM530IahnXt3oMJStD1J2wajeFjrUizJjFLVYSyRCwjMmocOQTVG39 Dy1ao6k/m4oo00Qe5Yk6TGJYO0RQl8HxTRC9zDRbLJbJFS17bhrmNLuB5gL+m/PkLp+1sq1wTHL nBdsfQwwrGupXnrh1qPFxaHHF/53riQwZqyxvozuIQw== X-Received: by 2002:a17:906:5448:: with SMTP id d8mr13071527ejp.248.1621437320101; Wed, 19 May 2021 08:15:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwU/i0K7CuC9kdG/8pVjlUFi4mphhAnSiDvo9H0IBsU+TbRFFlXzuDNj5NFZBwIlvvDEKiHhA== X-Received: by 2002:a17:906:5448:: with SMTP id d8mr13071503ejp.248.1621437319838; 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.19 (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 v3 4/6] x86/kvm: Disable kvmclock on all CPUs on shutdown Date: Wed, 19 May 2021 17:15:11 +0200 Message-Id: <20210519151513.309935-5-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 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 (backported from 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 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