From patchwork Tue Dec 5 00:45:01 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: 173616 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3133931vqy; Mon, 4 Dec 2023 16:46:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IFbW12BaaUfwFOGn4n2XxypwsaNq3hi9wls3rJueox0X47ufWoCxD7eMnFXi8m62Le0pyEY X-Received: by 2002:a17:902:a70a:b0:1d0:6ffd:cecb with SMTP id w10-20020a170902a70a00b001d06ffdcecbmr2401210plq.132.1701737201447; Mon, 04 Dec 2023 16:46:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701737201; cv=none; d=google.com; s=arc-20160816; b=szDYMRGqSIYqfoXfZjbV5gGcNRW/Mw5YhZ5jbbFIjqwVhAqPB1yKdRyGiior2lN0Co t2yXK0Bwbdb02W55M7SBCs8QiEZ/VSJROfML/hgLLeqsI49cz4Xgcb0fGNkpVM3d4nFM ScA3BbhoiOdpJMFUQz11x2Iv0Gd6IjM6fC5WN8QFTDcburVcY7WFis+M0cMKq5bsMM64 mv/FhQ12cvKsOngR/Lw4DPc+Nqk1Es70mkPDAqvJgu+SPC6cNtj+A6Hv9+2cAEBy5yEC /IWboIw5I8juxF4TXyj83qMBYUGJhYCyD8pOl3LuefDI27evXNY4d8Iv/AwzrtNg/RPK vEXQ== 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=n9Qmvgl4wJELoVDkyi0p6dG6nNIJb3dXiVHxgEQLm1I=; fh=DZfoEASDdBEo72ANs+M8oJxyhETR9BcEIBN4aLsHYxI=; b=j1VRJOqnTW/VkcjwXPr7FMVN9ylVD2NEeLQhaGPfVMQPfFMLSFuCwKGNkAjZgxei3v eMhViRw8wGA7KCJXKuj6VhTrf5QEJ2Xrwb19pslR/HwPLyLUDOhzLuK1mWsZbQbKRBEJ GVC9R91u/bMCQJwal68+G+mTF5RJjVxqykupqkBXy03aP6/+NB2yNFbX7n6/7bu+S6P7 xO6O6+ETwWFyIOS/UOJ5hr8pe/Zjih6r9LlRrmV/hmaGLoEOLqFIEGdLZLV33sEtO6rD G4Y3I9bX3Va/+7o8X3EKqM7gbPT5GBntk8l+9GUUDzbV2WSvdizDOUmTcfFOm3VYqhx+ PcPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=S51Jwrbm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id b6-20020a170903228600b001cfbb926859si8603719plh.387.2023.12.04.16.46.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 16:46:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=S51Jwrbm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id EDFDA80AC584; Mon, 4 Dec 2023 16:46:38 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376295AbjLEAqS (ORCPT + 99 others); Mon, 4 Dec 2023 19:46:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234796AbjLEApg (ORCPT ); Mon, 4 Dec 2023 19:45:36 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60750111 for ; Mon, 4 Dec 2023 16:45:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701737137; x=1733273137; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=baddqEIghmkFajP6rpIfXbNavqQAwsBb4c0/kd75gPA=; b=S51Jwrbm9HBMJT898lMSXTTGizZg3+O0FHUa5tSvjLuefJYsIuTACJbp Vjn0KH7yJ/TC5SLOn0KkUpBO8Xo+Azs2u4YohVt0kgw5jGF4ZfVQdNlJx 74kQLpaKYPykuErtNU1zVna6/7mbbbud5/PAU7oJon3/zZF/Uva1iU6D8 4mmDv2+zTUoYdpBweTcxhX1CcYhw5/4V6pQlDzYUEuBfs6H5H3drUyr2Y OD7yRhhJdj00iEiL88xFRQV4GTk75Eemka+jNeU4+u/lYP6XYxVG6PLvC CB5CHQrl/lyVUJB92t9hfnh2Pk7XaO6IpXNQbKW4FZy8ZZl8zmkzIicX9 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="392688725" X-IronPort-AV: E=Sophos;i="6.04,251,1695711600"; d="scan'208";a="392688725" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2023 16:45:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="944067951" X-IronPort-AV: E=Sophos;i="6.04,251,1695711600"; d="scan'208";a="944067951" Received: from abijaz-mobl2.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.61.240]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2023 16:45:30 -0800 Received: by box.shutemov.name (Postfix, from userid 1000) id 5C3E410A445; Tue, 5 Dec 2023 03:45:20 +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: [PATCHv4 05/14] x86/kvm: Do not try to disable kvmclock if it was not enabled Date: Tue, 5 Dec 2023 03:45:01 +0300 Message-ID: <20231205004510.27164-6-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231205004510.27164-1-kirill.shutemov@linux.intel.com> References: <20231205004510.27164-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Mon, 04 Dec 2023 16:46:39 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784400787919271101 X-GMAIL-MSGID: 1784400787919271101 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; }