Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp2541696rdb; Wed, 15 Nov 2023 04:03:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IG1H/3nGH6e234mXEYh9lXaedoZa1isBHFdqWctAZHyIWFvLalJLF2CRV2bkcC+ptkGhJ/2 X-Received: by 2002:a05:6808:3c8a:b0:3af:e556:4602 with SMTP id gs10-20020a0568083c8a00b003afe5564602mr17677376oib.11.1700049792167; Wed, 15 Nov 2023 04:03:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700049792; cv=none; d=google.com; s=arc-20160816; b=uX8tQuvw9kADzvjOtlRc3Qb64bhaFz5EVBjX/6hkvYqX7T6ekcsgkAH7KuYZYz3/ky QqRRvx4mvO6IW/uf72PvkDU364WGKMu8LupqGBhOF7zjDX3GM86uE8KC1ZTc/0IMU9J6 Vm1mrGCxr7KDX+wWMYx0lqBkx5rpU9i8Vku8iBk8Pia6Owxy5qk16vQLTWI5NDww4k2i x+L9t5gnnQ0wGD8wX+Mp/Og1SL6DAX3AKBlQJmcQMWtVsW8O9oaj15krnsDKapO31REi CRKlLLbaPGPeSHJi3biAfSCAmtvhtn3bcs8/KTFt98Y3YWNh8Ee1gcNKvfpvmNrtCmg3 jNAw== 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=n9Qmvgl4wJELoVDkyi0p6dG6nNIJb3dXiVHxgEQLm1I=; fh=DZfoEASDdBEo72ANs+M8oJxyhETR9BcEIBN4aLsHYxI=; b=PhOe7N9vRdjOnxB7JNOpVWqQ1DWbhGsKIY4gARSbH+rdHGSlI05E0SCcgfQUaQYmYa 1fXXRl82QrvSfQw0twK9UMGCAfGYerR3CARErphZCH4mz6yRRpa5SM1ND3Ooy+pR3Hez 5fqgWF1H8fW+ABUejtCIAeMgBvodEJhKmHP4/KwUWG9DdGCD5/esZ1XwNZlIFPwucrqv HKGTzIbDb+WHKusqGJnUMaaLZi4N6nhgHiMb8IxXP+HqhQoifuHqFtwMNr2W6CmHithI Gwet6Br975FPXbhTcIbBfJezjNohmBMrzR3LMF38NGQm6SKxO8sKmixVCfJTEn/C8Qme A9iQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nB5qB0mH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id s186-20020a632cc3000000b005be3c09abf1si9721475pgs.397.2023.11.15.04.03.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 04:03:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nB5qB0mH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 6A66A8024B10; Wed, 15 Nov 2023 04:03:04 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234936AbjKOMBr (ORCPT + 99 others); Wed, 15 Nov 2023 07:01:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343745AbjKOMBb (ORCPT ); Wed, 15 Nov 2023 07:01:31 -0500 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 769D718F for ; Wed, 15 Nov 2023 04:01:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700049687; x=1731585687; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=baddqEIghmkFajP6rpIfXbNavqQAwsBb4c0/kd75gPA=; b=nB5qB0mHHuZk7APNFGFW6gTaBTNEQNqj6jcN1+ybMk/kN0f/bdh++ZT0 8J1Ku0PM7y9xb4yIIB629Frb2rSVeJ4v4VGsa121St9hBc07uIdnBAVj7 eiWe7FQuAOQweaSTSQIeS/zNIxe/W4uNHMkQy+nYQ9ypiZeXD0UmNiFEb 2nC23xCJPwA8jzQFUlusanbxxyP8F0CjWe2WrZgBU3bcu6lLMJtsnQb1E GIiFOP/S6ntPvHWMRPrnzH2S2QUzYM8/shDKjgDiz/gDiHtYknjik4ixt LxfWS5bI7qaqVH7MyqtB5g7NRMGZuq4zUSR+KTBGYXthoRyGYdSVLCOyx g==; X-IronPort-AV: E=McAfee;i="6600,9927,10894"; a="394780435" X-IronPort-AV: E=Sophos;i="6.03,304,1694761200"; d="scan'208";a="394780435" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Nov 2023 04:01:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.03,304,1694761200"; d="scan'208";a="13160244" Received: from mituomis-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.249.44.135]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Nov 2023 04:01:19 -0800 Received: by box.shutemov.name (Postfix, from userid 1000) id 657C910A151; Wed, 15 Nov 2023 15:01:12 +0300 (+03) From: "Kirill A. Shutemov" To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: "Rafael J. Wysocki" , Peter Zijlstra , Adrian Hunter , Kuppuswamy Sathyanarayanan , Elena Reshetova , Jun Nakajima , Rick Edgecombe , Tom Lendacky , "Kalra, Ashish" , Sean Christopherson , "Huang, Kai" , Baoquan He , kexec@lists.infradead.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" , Vitaly Kuznetsov , Paolo Bonzini , Wanpeng Li Subject: [PATCHv3 05/14] x86/kvm: Do not try to disable kvmclock if it was not enabled Date: Wed, 15 Nov 2023 15:00:35 +0300 Message-ID: <20231115120044.8034-6-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231115120044.8034-1-kirill.shutemov@linux.intel.com> References: <20231115120044.8034-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 15 Nov 2023 04:03:04 -0800 (PST) kvm_guest_cpu_offline() tries to disable kvmclock regardless if it is present in the VM. It leads to write to a MSR that doesn't exist on some configurations, namely in TDX guest: unchecked MSR access error: WRMSR to 0x12 (tried to write 0x0000000000000000) at rIP: 0xffffffff8110687c (kvmclock_disable+0x1c/0x30) kvmclock enabling is gated by CLOCKSOURCE and CLOCKSOURCE2 KVM paravirt features. Do not disable kvmclock if it was not enabled. Signed-off-by: Kirill A. Shutemov Fixes: c02027b5742b ("x86/kvm: Disable kvmclock on all CPUs on shutdown") Reviewed-by: Sean Christopherson Reviewed-by: Vitaly Kuznetsov Cc: Paolo Bonzini Cc: Wanpeng Li --- arch/x86/kernel/kvmclock.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c index fb8f52149be9..f2fff625576d 100644 --- a/arch/x86/kernel/kvmclock.c +++ b/arch/x86/kernel/kvmclock.c @@ -24,8 +24,8 @@ static int kvmclock __initdata = 1; static int kvmclock_vsyscall __initdata = 1; -static int msr_kvm_system_time __ro_after_init = MSR_KVM_SYSTEM_TIME; -static int msr_kvm_wall_clock __ro_after_init = MSR_KVM_WALL_CLOCK; +static int msr_kvm_system_time __ro_after_init; +static int msr_kvm_wall_clock __ro_after_init; static u64 kvm_sched_clock_offset __ro_after_init; static int __init parse_no_kvmclock(char *arg) @@ -195,7 +195,8 @@ static void kvm_setup_secondary_clock(void) void kvmclock_disable(void) { - native_write_msr(msr_kvm_system_time, 0, 0); + if (msr_kvm_system_time) + native_write_msr(msr_kvm_system_time, 0, 0); } static void __init kvmclock_init_mem(void) @@ -294,7 +295,10 @@ void __init kvmclock_init(void) if (kvm_para_has_feature(KVM_FEATURE_CLOCKSOURCE2)) { msr_kvm_system_time = MSR_KVM_SYSTEM_TIME_NEW; msr_kvm_wall_clock = MSR_KVM_WALL_CLOCK_NEW; - } else if (!kvm_para_has_feature(KVM_FEATURE_CLOCKSOURCE)) { + } else if (kvm_para_has_feature(KVM_FEATURE_CLOCKSOURCE)) { + msr_kvm_system_time = MSR_KVM_SYSTEM_TIME; + msr_kvm_wall_clock = MSR_KVM_WALL_CLOCK; + } else { return; } -- 2.41.0