Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp153774rdg; Tue, 10 Oct 2023 06:54:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHl0BTlXn7tmvlRFBSc90iixSic7vWwgnn43nvn/VRUcJSnFnMq/a7z3+wS+sGVCc4MxpxX X-Received: by 2002:a17:903:443:b0:1c9:b5a5:ebf7 with SMTP id iw3-20020a170903044300b001c9b5a5ebf7mr1287949plb.36.1696946067741; Tue, 10 Oct 2023 06:54:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696946067; cv=none; d=google.com; s=arc-20160816; b=BXVRyDKkNDfLE6MzqQPiGha1nMMEQMKaqka+kIV2Cjnfv9nqlkdOZkVcMJ9b8n5oDk l3hZeI0D6lZUb/0BPDNs3b8OXZml6TjwLHRM0caT+wXaMi5QP8VWeDaA7Jk9w6UjiAu7 qrb6nQ40pis73aVefD7IaE2nOY/uyoLWenNrK6gQ5Bjoq/tlXWAejTpArH6SsejE/+1R ZzLy8wQbp4eOcUs0TWCQlfZHJ31S5i1ZqEgaJogYMN5acDRqzphM7+ZmNjqyLb1FFKP8 jFbEr5ekOQ2S0HdA648qxbsz5LB5WIW1ss7fdmWyVRVD1MQ3XjQDzNsEBhSGRCVauCiI ZK1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=5g2tvgZI3H0xBsJNhQNwgiPVh5+5sjJT5w+2Eovgyyc=; fh=cMyFVT0sh6ZwVP2rvst5CQqRq6dUn/5tjJx0MsDQfWQ=; b=HcPFhER6/gbVhMKndE1Zoy3RmdoXLM5v1J+d0YQBYT/r6yexc+9kfj+3R605Kn5HpV LLbuZvKO1DriS+FRL/ssNrJRj8zd+eYRwQVjk7QJKjuqP3pjKzyLB07X5S00OTMjhI7C oSYafAGI1FZ5j40OYaGJtbCFID0IgISBgbvgC27lgSoPAVEP6XxkMs6omDTHW9qGIZuN gsNwUi7j1A3BkMVi/4kN90B9wWvfyV6DtG4Ke8zPSOo9sBDELjRj/2nakgxvYBIpUwOZ E1jbgzB0pHy6Lt/1iRjptm84DgxAYsUHw5UU/wtppKDWNXxMRl4eHfAgzff8isklNCtr dT5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=AHwEciX6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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. [23.128.96.31]) by mx.google.com with ESMTPS id w2-20020a170902c78200b001bbacfdad2fsi11284277pla.291.2023.10.10.06.54.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 06:54:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=AHwEciX6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 3C54B803EB86; Tue, 10 Oct 2023 06:54:25 -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 S232605AbjJJNyU (ORCPT + 99 others); Tue, 10 Oct 2023 09:54:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233479AbjJJNyL (ORCPT ); Tue, 10 Oct 2023 09:54:11 -0400 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6271B1700 for ; Tue, 10 Oct 2023 06:53:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696946008; x=1728482008; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=STfmPYVLdo6+qt87QB/G2RvqDg2ED/4+X+sOB+AaltU=; b=AHwEciX6d9KQBggrcmhYcKtJiTJGQ3X8dD7Fkx0GdCqYHQKsBA1zF0rw mHjusCAIlbqpRT0UhrKEyxos+nIS5q8iXRdTqJbL4nylSNychkvLPJU+U ATJqvMnb/2FR/HzkRXQ1r37C4J2u5c908vm84nSkEi52VFr+aaJTBnzgh lceLAl0Ta3yWK4n/ExZ91uqBtpjVb25EGOzkM8yGHpa9LRFZVbvi9mrpi diPsuibH+xY2aDZHJz2DvBUCIao9IgsaA4EbDrHIS8TNX9naGSdDgskpz t5rTCVjU4vMLXTwR05WIzUX7s108/RM9GRMdcXYmLD7AWQk5Y8Y4So5PJ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10859"; a="2990216" X-IronPort-AV: E=Sophos;i="6.03,212,1694761200"; d="scan'208";a="2990216" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Oct 2023 06:53:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10859"; a="747075063" X-IronPort-AV: E=Sophos;i="6.03,212,1694761200"; d="scan'208";a="747075063" Received: from patinira-mobl.amr.corp.intel.com (HELO [10.212.128.216]) ([10.212.128.216]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Oct 2023 06:53:27 -0700 Message-ID: Date: Tue, 10 Oct 2023 06:53:27 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 04/13] x86/kvm: Do not try to disable kvmclock if it was not enabled Content-Language: en-US To: "Kirill A. Shutemov" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: "Rafael J. Wysocki" , Peter Zijlstra , Adrian Hunter , Elena Reshetova , Jun Nakajima , Rick Edgecombe , Tom Lendacky , kexec@lists.infradead.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org References: <20231005131402.14611-1-kirill.shutemov@linux.intel.com> <20231005131402.14611-5-kirill.shutemov@linux.intel.com> From: Kuppuswamy Sathyanarayanan In-Reply-To: <20231005131402.14611-5-kirill.shutemov@linux.intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=2.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no 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]); Tue, 10 Oct 2023 06:54:25 -0700 (PDT) X-Spam-Level: ** On 10/5/2023 6:13 AM, Kirill A. Shutemov wrote: > 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 enumerated or disabled by user > from kernel command line. For the above warning, check for CLOCKSOURCE and CLOCKSOURCE2 feature is sufficient, right? Do we need to include user/command-line disable check here? > > Signed-off-by: Kirill A. Shutemov > Fixes: c02027b5742b ("x86/kvm: Disable kvmclock on all CPUs on shutdown") > --- > arch/x86/kernel/kvmclock.c | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c > index fb8f52149be9..cba2e732e53f 100644 > --- a/arch/x86/kernel/kvmclock.c > +++ b/arch/x86/kernel/kvmclock.c > @@ -22,7 +22,7 @@ > #include > #include > > -static int kvmclock __initdata = 1; > +static int kvmclock __ro_after_init = 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; > @@ -195,7 +195,12 @@ static void kvm_setup_secondary_clock(void) > > void kvmclock_disable(void) > { > - native_write_msr(msr_kvm_system_time, 0, 0); > + if (!kvm_para_available() || !kvmclock) > + return; > + > + if (kvm_para_has_feature(KVM_FEATURE_CLOCKSOURCE) || > + kvm_para_has_feature(KVM_FEATURE_CLOCKSOURCE2)) > + native_write_msr(msr_kvm_system_time, 0, 0); > } > > static void __init kvmclock_init_mem(void) -- Sathyanarayanan Kuppuswamy Linux Kernel Developer