Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4745666pxj; Wed, 9 Jun 2021 00:23:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhgARbYjZ5uCiAHtjgBrZT03pYUN+M/UFEP7bac9U6K/swAmQrAkkMjhitMkRRivgT1v1W X-Received: by 2002:a05:6402:1bd1:: with SMTP id ch17mr30212391edb.357.1623223400902; Wed, 09 Jun 2021 00:23:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623223400; cv=none; d=google.com; s=arc-20160816; b=bjGEX5siJWLg0OLusyVlDP1qcxeCo2Q9Cu9fH2kJLBke8zdlGWIcBfpms2Y6RF3BSk ANNmARvUr3DvColWiJNuXjOSsZPOrOqDoAADznztiJP7R/whQma4N65J2hn+kGguRZtI qp5i/ZqQh4EAcnkOjmUF/1HssNc/CMu/1dvcBhTvbuJaE0o9V7mn+ef6neYNvwiAcmRA AQfm4KSNotuhQ0IQQzi+wWR+tg9RfpMEc7NBFUATXZdBppGBMSa3OY4BTEuADbwAgnZV 1+mlfEpZEIXINlYZcavuooGuHx+lmXbDBrirZGrDTKychK8SaBfgTmra6EnbRLB1o/fN 8m1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+VkrhiCcfc2MR25JhSMs1MHs4T0bssaFNKhJ+BuoQoM=; b=vL25SCMjMqRyiR3p7WknpQpuQYMw6D82dqbjgRu4uGVxS527Kx9zUvdOkChGwAPn5e kjTnAypOIChA2tkrTyVnM+eB0aE/owEDoFd9gXj47aizyMScY8Nv7LL8hcDncw+U8XiH qjVjALf6aWwUdSuzkF3P0XGAD0bMSdow+UyGu0CPpTR8Hz/akReetHinXTfh4rqPDRW8 k7igE6ulp/EfCf7pQ1PoWujVwsZCI9QjYMJPkv4efAfvMCvuaVUghO1YsAjWU+94H0E7 fX/QsJI2QaAyTw9n0zyglv76FXBLfgaDi36rujEZsYvk2GjXkh3Xoc5TFaAxDm85R7Kt iqCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UrWnKmWg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cr15si2126131ejc.258.2021.06.09.00.22.56; Wed, 09 Jun 2021 00:23:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UrWnKmWg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236853AbhFHSzZ (ORCPT + 99 others); Tue, 8 Jun 2021 14:55:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:44020 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235678AbhFHSst (ORCPT ); Tue, 8 Jun 2021 14:48:49 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5CF0B61422; Tue, 8 Jun 2021 18:38:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623177517; bh=KKSmZjpDI7LtApuy8fqZ8f4a2GjbXSNjayEcZICjsVc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UrWnKmWgcX2FmhFYbn9IBw3WvILZHjMbQCfPXb3icmJgwRGcsWkW2+2i4f/hdnNVl MEeRXYTkwfZDKFOUV86keusWyOv8gYAFEbMZSVbXZHP/LQgyKwthrsBzt3ROK9aGBI 7vCBoxj7O8ECqrGppURqLyo3kQ0s1eiAND+4hjRs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Vitaly Kuznetsov , Paolo Bonzini , Andrea Righi , Krzysztof Kozlowski Subject: [PATCH 5.4 73/78] x86/kvm: Disable kvmclock on all CPUs on shutdown Date: Tue, 8 Jun 2021 20:27:42 +0200 Message-Id: <20210608175937.728926756@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175935.254388043@linuxfoundation.org> References: <20210608175935.254388043@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vitaly Kuznetsov commit c02027b5742b5aa804ef08a4a9db433295533046 upstream. 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 Signed-off-by: Andrea Righi Signed-off-by: Krzysztof Kozlowski Signed-off-by: Greg Kroah-Hartman --- 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(-) --- 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(unsign } #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); --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -436,6 +436,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) --- a/arch/x86/kernel/kvmclock.c +++ b/arch/x86/kernel/kvmclock.c @@ -214,11 +214,9 @@ static void kvm_crash_shutdown(struct pt } #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