Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp35772pxb; Wed, 14 Apr 2021 08:51:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+1yr0pMmQa7j9/3ssU5jXZ7yqZJfmSWvwnVkI/GT5j5ZuL+N67hZa+A5tu+9jjP7N5Rlu X-Received: by 2002:a17:907:70d3:: with SMTP id yk19mr8455724ejb.108.1618415510009; Wed, 14 Apr 2021 08:51:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618415510; cv=none; d=google.com; s=arc-20160816; b=CbzZOC2jaYpBzpCYslFIglof8UPo7V4d9I+kpHfysP457eZKCqTp3BFWyM4QhHkv3q tsGqJ4Z6a2KNg0nMhLwpYlKjY+C9lJLpG1HdoNSKULsgHPp59dQeFRBpyw6x10N4xKxF OE58w8dCrERIaxC3okdUmWVWgayLkwjaaAMzp6ry89YLt0qOIcQo0etzSObnGaqrnaru kLA444KaeI3WR680rzuXNeEPco1OForLBKaRueh4K1O2SkDvPHpHSoP42TBGrtTqBqmP N5ynsTQZK2m8atxH5ySaBnLb8P27a/+kEri0H1PF3c/Y99EOgyrF1sfmItHkIvP4DhvZ qyyQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kzRNcf2H+R/8jYv3at6gchWQAIBG4ynOM3knOxKhlMA=; b=tZmU9qQS2YjSh8zf/UspNRJm6to11ukfvpyFhN6aiGI/tRj9pJ/Z/wE2IgxJ6Zynfn 6gEAOBjqvtdb9aBLuCPf+vioLMGWRUWrKVs6Kscimdlab3hmIaOXPF6WCnG2dEaKxQzX aFRVrnQu8CC90PfBMWqjynvPoEndWAJtOBq42J2mEp6f0e822yKZdLCut/vA33/GviYL QXQbNU6wcIgVIixI9vv2gTRjwusZVDrN1NWcpJ1iJxtJa930TmieFMpjxAM3x0yI59Eu ykAxgkCkl4kWbLkRjEup9oacXZkbf5W+b2hFqZQkbkcMqLfJpQjVQ49xfd9PQixEzFnO AITg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Y+0lkMQM; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o6si14629679edi.18.2021.04.14.08.51.08; Wed, 14 Apr 2021 08:51:49 -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=@redhat.com header.s=mimecast20190719 header.b=Y+0lkMQM; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233427AbhDNMgi (ORCPT + 99 others); Wed, 14 Apr 2021 08:36:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:25428 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350967AbhDNMgV (ORCPT ); Wed, 14 Apr 2021 08:36:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618403760; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kzRNcf2H+R/8jYv3at6gchWQAIBG4ynOM3knOxKhlMA=; b=Y+0lkMQMOJo+wFsVFo8gZnjP6SHGnh819k1WVVf+lAEnrTSKzSUK3qf5U1iubvWOq0lndN BNdQjB/A8p8JRvEj65RkSwgKsFjiOJE1IDtDtsTUUGsAp7jIejmCdhD0gDPBySFk3nIrqV 7p5G1/59ipfIN36dawA5e2iNqvxIim0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-266-VSzLgA_QMeGZNpNG0DIRVg-1; Wed, 14 Apr 2021 08:35:58 -0400 X-MC-Unique: VSzLgA_QMeGZNpNG0DIRVg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7CCABA6862; Wed, 14 Apr 2021 12:35:57 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.196.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id AFF815D9CC; Wed, 14 Apr 2021 12:35:54 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini Cc: Sean Christopherson , Wanpeng Li , Jim Mattson , x86@kernel.org, Lenny Szubowicz , Mohamed Aboubakr , Xiaoyi Chen , linux-kernel@vger.kernel.org Subject: [PATCH 3/5] x86/kvm: Disable kvmclock on all CPUs on shutdown Date: Wed, 14 Apr 2021 14:35:42 +0200 Message-Id: <20210414123544.1060604-4-vkuznets@redhat.com> In-Reply-To: <20210414123544.1060604-1-vkuznets@redhat.com> References: <20210414123544.1060604-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 338119852512..9c56e0defd45 100644 --- a/arch/x86/include/asm/kvm_para.h +++ b/arch/x86/include/asm/kvm_para.h @@ -7,8 +7,6 @@ #include #include -extern void kvmclock_init(void); - #ifdef CONFIG_KVM_GUEST bool kvm_check_and_clear_guest_paused(void); #else @@ -86,6 +84,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 6b16a9bb4ecd..df00d44f7424 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -595,6 +595,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 1fc0962c89c0..cf869de98eec 100644 --- a/arch/x86/kernel/kvmclock.c +++ b/arch/x86/kernel/kvmclock.c @@ -220,11 +220,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) @@ -351,7 +349,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 -- 2.30.2