Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp1117435rdb; Fri, 22 Dec 2023 15:56:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IE5rpjlTZI+2B6oCTInFB2ApnzP0CqJ+PWYUfGt40PVm1opZcP/h02dcCBkmbxggyM0lAul X-Received: by 2002:a17:902:f687:b0:1d4:18c2:b15a with SMTP id l7-20020a170902f68700b001d418c2b15amr2141900plg.51.1703289407125; Fri, 22 Dec 2023 15:56:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703289407; cv=none; d=google.com; s=arc-20160816; b=A6LlDj8hz5XRxdU/KNNvSLPZbKb38TaHYqQtGvyxJCmbq8wYYyNxeAJ/NI/FLflOSW zDy6GIlj8DJpsrc0z1VEAX/1tQe/+sfCLKe1XvgBQ4grHxG56untNkleVkxXWigqAFUx vcOdkdlAfM18Kw7EzgdsXL4Ocr19Y+JMCO+2iek3Gyx4mXRbYSIw/iNddlBxtr9c+54u jVg80jZfltaJF+8HP/ETFlehmDseQXJd68njz3lCxzRxd9xbdX5vf2K/xF0eFAvdMn4/ WyJt78Eq1UmCFJYiqFz8TOaLmh2r4buLtWHQJY0rObz0Y68EjQ0jQfPSo8BIB12+RB19 dP4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=n9Qmvgl4wJELoVDkyi0p6dG6nNIJb3dXiVHxgEQLm1I=; fh=DZfoEASDdBEo72ANs+M8oJxyhETR9BcEIBN4aLsHYxI=; b=fT/W+a2BXwT/3BY7SkJxWAAYFkvnnSQrJpQSYlQoFTOylxMzxsqrIXG4S6buKdOTZ0 +G2AIa/4ZUamGEjQzUqWw2hA6f6+rVrAfkCOeEoxdXyez0T7k18RHV4sCrIVoN354VAA LCo9nUwdF8gp06WHgT2OaovOl5fiqwGIJ0K9THBY91OFQezYuvvmVOc4yu3/6SogwjjU DNPhPxpy24NbW6/i865TUN4PHli2tmS24J/wgxwFl2UB+6/zD90+XCpk4Kyu29C9/39D DSIUoYR/BK4aAfhYT3UhPcrPhgelA+ZRZFM/WxowC/vJNxeOjVKvXXQ715Nq+lAXBfvS y2DQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WvvP83FV; spf=pass (google.com: domain of linux-kernel+bounces-10138-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10138-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id f6-20020a17090274c600b001cfbf5c045bsi3019383plt.458.2023.12.22.15.56.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 15:56:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10138-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WvvP83FV; spf=pass (google.com: domain of linux-kernel+bounces-10138-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10138-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id A900FB2411D for ; Fri, 22 Dec 2023 23:54:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CF0114B5C5; Fri, 22 Dec 2023 23:52:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="WvvP83FV" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B428939FCF for ; Fri, 22 Dec 2023 23:52:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1703289150; x=1734825150; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=baddqEIghmkFajP6rpIfXbNavqQAwsBb4c0/kd75gPA=; b=WvvP83FVCGF8+E/4L+Ug5+oWBK3o6AcE/Qd8PEs9qx2LRsrPcx/WU4hN wwbRxS/nhQDBxzgrXmxKMqGrxT1JYMCXq8+DooqVIuNXLSNeEMdftwHwp 8kbZwGzPGg2btMEESmwA8vHuJ9/HofnzYxdr3gNyCulCozPQJ8KdwdJ01 4xz8p74IzH0p7AWUi+BCW5pWfN6mUyjrFawl5Dp1HJ6IHI4L6ZdwZ3ek2 yWZNq0emLk0PumUSUznLLlkL6Q6ZKU4JugMamnVGO4mgj6GpC3Qy4QdtI IrW8ofZfrlh0wuHfHxeoDMA7Qet/yi6x4SiEXdOGJNEJM0dpxmS33uxCS g==; X-IronPort-AV: E=McAfee;i="6600,9927,10932"; a="3414377" X-IronPort-AV: E=Sophos;i="6.04,297,1695711600"; d="scan'208";a="3414377" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2023 15:52:28 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10932"; a="726961497" X-IronPort-AV: E=Sophos;i="6.04,297,1695711600"; d="scan'208";a="726961497" Received: from jeroenke-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.249.35.180]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2023 15:52:21 -0800 Received: by box.shutemov.name (Postfix, from userid 1000) id 0DB1E10A47A; Sat, 23 Dec 2023 02:52: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: [PATCHv5 05/16] x86/kvm: Do not try to disable kvmclock if it was not enabled Date: Sat, 23 Dec 2023 02:51:57 +0300 Message-ID: <20231222235209.32143-6-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231222235209.32143-1-kirill.shutemov@linux.intel.com> References: <20231222235209.32143-1-kirill.shutemov@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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