Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp1092182rdb; Fri, 20 Oct 2023 08:13:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEGJD+qaqs6EbTalai4iE2s9fb4XJZJGRoTv47Aq0tbahIXTQY0KM3sf4LfA3VGotqFLl5R X-Received: by 2002:a05:6a21:a593:b0:16b:74db:8fe1 with SMTP id gd19-20020a056a21a59300b0016b74db8fe1mr2491774pzc.29.1697814807537; Fri, 20 Oct 2023 08:13:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697814807; cv=none; d=google.com; s=arc-20160816; b=bAYxM26cuIki1Q8ahFd8vIVOZVaBDGX7otptzPcM8nGD3wHGzXiJSMl2WP+goZKMkp 6cAGATxyB58AzGH+cJZGmULJ3+7PiMPrQCeUxjhR1Pabe9QGkShB9QdK/aWoq2mOIGJo DiIGAXJEppRNx+pZAh8s5lxo0cb4qRZYxBxa++/u8bRGogBilK7ptU6ydSryFsczDsP/ xDRwm6wmnKzByqn4IL24GjyfRPZsI9g0WBXVYV1VYDwWQfCEMhQgpO3oYhqX0sMygCB6 4BWlDQY2fqK5/5buoekO7Qu0Xhnh8wapfA36oDDcTrr3/+UbnEKmnXxgEQIzUQOpLfXu aA2g== 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=iw6JvSvu16kdVfUPtZTMZ6dHhC4KaBhFUkCnK0C19pc=; fh=zgww269bCnQ8VQepSkUb3i3YdaPqj+fISfghODbGw6M=; b=Ya5Jy2c+4X68maz1e2wOtTFZ+O/7EtRDPGfjSzK5hkel1Ol4g3UfLM+uX0ZmtD7Wfm GWUtpw2qstVXIG7LrscPnDHDq3mRHsCqYoXTz+wRaktmgq2Czgaylicw9xCt19MhaCYz dfY7bmrKLOD2I4kcb/DQw1jT3hyvfI5ulNxvBYZJ5RKhj8EEgpJAurvBF8kKCAarIwlW p5bD5kdG8hym6x32nDHjdTFH7HNtpUa1g6OvkUW9QFEzOU4mCANq49ZCEjSHZ6ANXQy0 9+vbP1XR4lA77e4vAxK5mfvDDJj9PTgcC04H7qy2Mv4FrJbsuoMwpnUbS1+22mW335LX rGrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=M3wr1ALK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id x3-20020a170902ea8300b001c9ad30e4b8si1937633plb.320.2023.10.20.08.13.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 08:13:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=M3wr1ALK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id C202983FA177; Fri, 20 Oct 2023 08:13:23 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377661AbjJTPNL (ORCPT + 99 others); Fri, 20 Oct 2023 11:13:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377653AbjJTPNC (ORCPT ); Fri, 20 Oct 2023 11:13:02 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75FE9D6B for ; Fri, 20 Oct 2023 08:12:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697814780; x=1729350780; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MPIjCtbNsICrtwqXzYBNDwDeX3sLS3gFAi6SoZOpAO8=; b=M3wr1ALKLBSje8Ikwl/9PKg8FPHyHjLUkUIp+ZmoLiszw/O/SRRBChfL h15XxMovWnD04y2yg/laqcGtYe9Zb1jLuIR2LAl6aIYNsw6MdyrdA50G6 R2dqBQIHmAd5Z5Rj4etimVSYHVwLcwR9/Jo4oK3A1/n7uKtZjBlqBQKwT b8JAJwDUZ3GVa0VUi3L3nZbHvIWPog/fvzcz906FvyCQ8K5hUPNsulk7n EyyrWxVr3mHZxx7wNDr6mZY6gYJpJ/n6AaQjLfbovPHsBaC2BF4e4/hxB CuZqNDoVdFCpypQVLh3qdiHJkWoHjdMHWCYzALwNuPkjsFLvKhzlcyij4 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10869"; a="376893621" X-IronPort-AV: E=Sophos;i="6.03,239,1694761200"; d="scan'208";a="376893621" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2023 08:12:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10869"; a="761080250" X-IronPort-AV: E=Sophos;i="6.03,239,1694761200"; d="scan'208";a="761080250" Received: from dgutows1-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.249.39.237]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2023 08:12:48 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 10D5D10A296; Fri, 20 Oct 2023 18:12:45 +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" , Paolo Bonzini , Wanpeng Li , Vitaly Kuznetsov Subject: [PATCHv2 04/13] x86/kvm: Do not try to disable kvmclock if it was not enabled Date: Fri, 20 Oct 2023 18:12:33 +0300 Message-ID: <20231020151242.1814-5-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231020151242.1814-1-kirill.shutemov@linux.intel.com> References: <20231020151242.1814-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.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 (morse.vger.email [0.0.0.0]); Fri, 20 Oct 2023 08:13:24 -0700 (PDT) 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") Cc: Paolo Bonzini Cc: Wanpeng Li Cc: Vitaly Kuznetsov Cc: Sean Christopherson --- 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