Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp435250rdb; Fri, 6 Oct 2023 07:51:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IERWezs8iGt6ISowFRgfPmbpLS9qFcqFtNtI3pyGqduYAjgE8h/+abZ4imXz+Z4w587i0YL X-Received: by 2002:a05:6a20:32aa:b0:15e:10e:2cc3 with SMTP id g42-20020a056a2032aa00b0015e010e2cc3mr6533432pzd.60.1696603898628; Fri, 06 Oct 2023 07:51:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696603898; cv=none; d=google.com; s=arc-20160816; b=tO69cn8bROosH4Fg6lwrhgIu/AK1pEPbRKKyJWtb3zx7jdVXBAdoYSUNLFBYLdsiEW bzeuNXx0RA0VmY7lNk8rUMCe1lmtUa/jTO484wwEh7qEmu+yeSAkBSUjq0fxw4ZAzfoL ULm5M+P66W3RYpIgP2eiz92uRR5ieTC6cL9mcfdS3qVIkv14vM2TqgTq2ODaNagFCulb 1AXZK+WVeC6Si4ycbXQ5LE7UxjG0Ri4N2rWNcU/C7if8vdUxoXrYiBACMMYw7j1McSmE pltKS9lIvKMxtgPUl0DH1HZIeuahix7RzxIjwVMy8n/D/ZTlqnN4Vwq+rzpCfjvn1GY6 VcJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=9XRfKnrVotbBn0F9i40ZiAJEqDygnWV4LgggRhYw0+Q=; fh=35n87z0TGxSDC//toPqTtyGclylST45uwwbO4u0F0ZQ=; b=dIv5LYFqBGzobrBKOariWrRG0C17W3gH1SgTvafcTdVL3aXphSsMaOHNHy2g95Pigf pvddvJVyjctikPKKfSNSTfCo+TBVt9p1UVAS5GaTc2eHCFWKfNNNQ40+5iPWh5744zf/ 5TJYPktp2bTGLEvgmHuj7Qmg16mbYL1Q94YsVjgvbOYl4t7XbZcGbghbaVqn5JKTMB+v 13NL8ei3jCrvP3Az5fgStwCeHBF0WVrp6nHdWj40EYayb/LYBoSyB5cH0cpr7bA0avoz HTjSwdJRduO/I6olv6kuIcMe6HuwStWNvRKuoVu10O7uyJfWo5NqPBOty/zi/c7BfWGH QB/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dkBtcnRy; 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 19-20020a631753000000b0057777451a91si3865008pgx.581.2023.10.06.07.51.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 07:51:38 -0700 (PDT) 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=dkBtcnRy; 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 752FD80784DC; Fri, 6 Oct 2023 07:50:36 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232655AbjJFOu1 (ORCPT + 99 others); Fri, 6 Oct 2023 10:50:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232596AbjJFOuZ (ORCPT ); Fri, 6 Oct 2023 10:50:25 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6AC3A6 for ; Fri, 6 Oct 2023 07:50:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696603824; x=1728139824; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=W/51r4qVWeOrP4iJgr+qcAMJuEyFjcjduXqKxwHzQXk=; b=dkBtcnRypc7QSXw5FRBmtgV/OEHYQgytM/ms7aXsuAm9DLiorHiY0Eo4 sCAHqUVhGEdlooACGmTMyAGDA/bSEcasW+BaF/QkJVY++0NAt64y24xh4 1H1y4iK5qXXT4WaqwqmmIZRCmHyLULfwx/1mrHFh8Lh3ihoJKIifiEMif IZ30qNISK7wUQIOdeIictw8tpHjJ1QmtzVMwDqRtc23VMaoky9SzYBsOW 06vb04WP7QlhfW2L114BTnYSKXE4TP2So+FXEV4FjjdnVQWoSXaEvHQ9G cENkbdSZvLOPyLRwjhUPfnITWMN3UxYN8pk0NZWY3jYJtTPinptWydKj3 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10855"; a="374108526" X-IronPort-AV: E=Sophos;i="6.03,204,1694761200"; d="scan'208";a="374108526" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Oct 2023 07:50:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10855"; a="781680129" X-IronPort-AV: E=Sophos;i="6.03,204,1694761200"; d="scan'208";a="781680129" Received: from kvsudesh-mobl1.gar.corp.intel.com (HELO box.shutemov.name) ([10.251.222.76]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Oct 2023 07:50:19 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 236CC10A172; Fri, 6 Oct 2023 17:50:17 +0300 (+03) Date: Fri, 6 Oct 2023 17:50:17 +0300 From: "Kirill A. Shutemov" To: Sean Christopherson Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "Rafael J. Wysocki" , Peter Zijlstra , Adrian Hunter , Kuppuswamy Sathyanarayanan , Elena Reshetova , Jun Nakajima , Rick Edgecombe , Tom Lendacky , kexec@lists.infradead.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, Paolo Bonzini Subject: Re: [PATCH 04/13] x86/kvm: Do not try to disable kvmclock if it was not enabled Message-ID: <20231006145017.26q2quuiup2emodp@box.shutemov.name> References: <20231005131402.14611-1-kirill.shutemov@linux.intel.com> <20231005131402.14611-5-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 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]); Fri, 06 Oct 2023 07:50:36 -0700 (PDT) X-Spam-Level: ** On Fri, Oct 06, 2023 at 07:36:54AM -0700, Sean Christopherson wrote: > +Paolo > > Please use get_maintainers... Will do, sorry. > On Thu, Oct 05, 2023, 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. > > > > 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); > > Rather than recheck everything and preserve kvmclock, what about leaving the MSR > indices '0' by default and then disable msr_kvm_system_time iff it's non-zero. > That way the disable path won't become stale if the conditions for enabling > kvmclock change. Okay, works for me too. -- Kiryl Shutsemau / Kirill A. Shutemov