From patchwork Fri Dec 22 23:51:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 182816 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp1395020dyi; Fri, 22 Dec 2023 15:55:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IHo6Mv5OScoGPjay4G8EBHZYfd7jhjzbVhFIXg5V3muOp2FASD8Rq9wS9/E/nGk1BPZJOW1 X-Received: by 2002:a50:c31a:0:b0:553:165e:b213 with SMTP id a26-20020a50c31a000000b00553165eb213mr1271651edb.25.1703289350799; Fri, 22 Dec 2023 15:55:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703289350; cv=none; d=google.com; s=arc-20160816; b=B69dG2668AdDpLsYfrMR21VV/LIuIlYjZXyd357mqPp0iP/c1LWRKBs0F6o537AdYN wElTbhwczdt/EVOowVRgocsw5rk8w+NveRz8nxBf0Uw9JuTTuYwwIUBUAndCNqX9zM2c Pt+MVk2p8X1QzjFGxPhQUdcqnewjs4xHlGxXVIV/dunp2fpypA9hzPu75Loq+Vj8v8CH 9rlRN2JWcN7BKWGxiCUNxpz7HTwsegGdaV6km819ceccfgSevuvheiMI5e3okAW+7c4x wAx5ovUCUIPVsr+Fct62cnQyV9c45UBt9q6r0aZigZd0slYqQQr1y17Uq6Lyjgk9zztR uWEw== 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10138-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id e7-20020a50a687000000b00554107338f6si2104076edc.58.2023.12.22.15.55.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 15:55:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10138-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10138-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 42F4C1F23A92 for ; Fri, 22 Dec 2023 23:55:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B3DAD4C630; Fri, 22 Dec 2023 23:52:34 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786028334267834481 X-GMAIL-MSGID: 1786028334267834481 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; }