From patchwork Wed May 24 06:16:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Gao X-Patchwork-Id: 98316 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2636151vqo; Tue, 23 May 2023 23:35:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Cl/q54Vd7oLJjRh+2MNvw3qfsOvMAZ/1uWhdK/f78ehu5gDUUIyr7ndlM0vmMCJyYDd/l X-Received: by 2002:a17:903:41cf:b0:1ae:2e0e:dfcf with SMTP id u15-20020a17090341cf00b001ae2e0edfcfmr17804613ple.2.1684910121443; Tue, 23 May 2023 23:35:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684910121; cv=none; d=google.com; s=arc-20160816; b=RQJsRFl+uUEIooyxxX6iCXr/I6JJ7wt3Ioyi2Mm04SNmLZ1r/Awm7PHu2ZH3//ePEN ym5lPMYI3WE9CbCQkcxDffEOlZlae4Y5Jj+/0H84dWw/Rw/F5NfCJJ9osCsryMmy13Od RdF69WRU2to8J7yRpEGZIo+tWTPgXHNOnZuKiv8OvrcQEezEBPFROdUcnTRBrgyQ7WON XrXt/g7esnJ0CGyIwQuNkDDQnSM/vG8uizZnPvkL+DmM9/sDbH1NaLH7dcIG0CdKS5OM dcd+ZctBvslj+UidOgYQTti/6LY+ONcjr/MCivxyR/EtMpYnptIoXXwgHYT0naQ2xhW5 6KzA== 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=QtQu88ewSL4Lp13WZCgv+Q2J3MkYlTrbKphGl9LM7/Y=; b=f0ZpeGrphZDtyqYOx0tyux3AB4grOlpzQkUWzQzfUA3gT2oLSZCu4/cLrwaaV19iaa DswO7Rtw+7chfPVSNnGSvFyiaIq4eS3CimXtYKEQq2VAj6EquzVWyQqOS3zvr5s/XGE3 0MigyKb0HP0gX2hR7cxuK0Q9VV2wlHEo5ItSBgpFT+NoIg/U4gNnD/Q7yAmZQAZiNVjo DBoO5AaP3W6QH/Vg0ZNp9hUdpBe4gRJVK7T5tyPfVftZoJnRffLz54yFbnT3jqLDS1Ll xSuF2h5PBBAFEIHTgEXqk5Vpqpum9LETHaVBJX2pWDYISyabkKMKJmyo64GhfIrlsGWd tmFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=mWY+6Sbd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a9-20020a170902ecc900b001aaf8182cc7si6339399plh.425.2023.05.23.23.35.06; Tue, 23 May 2023 23:35:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=mWY+6Sbd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239693AbjEXGRR (ORCPT + 99 others); Wed, 24 May 2023 02:17:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239584AbjEXGRN (ORCPT ); Wed, 24 May 2023 02:17:13 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAC1B18B; Tue, 23 May 2023 23:17:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1684909027; x=1716445027; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NIz83zwBrx9rPoQnot0IXhX1IJvrd8Dsfj/8OSzuMes=; b=mWY+6Sbd4wV6GW2VUoMFH482Tw8hYRSYqynGjx48Rd3Lmz75Yq3Xtyuz k7UV9mcGux5A0CY+WtW7AZUUK96xztQStS1jpJNvN8E0gUvUXa7HiMiWP wAOcxnqZkNnEf62DhiVpuIoRjMP2KsXdPihm2WZa9rh4lvUSTxKiJhodA GiWfpF+KcMjVfFXa325uvNA/UGPpoDSEKr67YfCo/stVEafsBTJUtTAaG dYhIEN86XjekIUGDZMYpUiVWbv8u2mqDBXTkGy/K+MptRi6j6V7uEvl9g jgLyFg/eG/VVvo0dtipyY0e1DpU9cBtKlWsQPjgm3LhpBqK2A4pEsV9hN w==; X-IronPort-AV: E=McAfee;i="6600,9927,10719"; a="356695105" X-IronPort-AV: E=Sophos;i="6.00,188,1681196400"; d="scan'208";a="356695105" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 May 2023 23:17:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10719"; a="704212453" X-IronPort-AV: E=Sophos;i="6.00,188,1681196400"; d="scan'208";a="704212453" Received: from spr.sh.intel.com ([10.239.53.106]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 May 2023 23:17:01 -0700 From: Chao Gao To: kvm@vger.kernel.org, x86@kernel.org Cc: xiaoyao.li@intel.com, Chao Gao , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Sean Christopherson , Paolo Bonzini , Peter Zijlstra , Kim Phillips , Juergen Gross , Ashok Raj , Pawan Gupta , Alexandre Chartre , linux-kernel@vger.kernel.org Subject: [PATCH v2 3/3] x86/cpu, KVM: Use helper function to read MSR_IA32_ARCH_CAPABILITIES Date: Wed, 24 May 2023 14:16:33 +0800 Message-Id: <20230524061634.54141-4-chao.gao@intel.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230524061634.54141-1-chao.gao@intel.com> References: <20230524061634.54141-1-chao.gao@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766756315377165614?= X-GMAIL-MSGID: =?utf-8?q?1766756315377165614?= KVM open-codes x86_read_arch_cap_msr() in a few places. Eliminate them by exposing the helper function and using it directly. No functional change intended. Signed-off-by: Chao Gao Reviewed-by: Xiaoyao Li --- arch/x86/kernel/cpu/common.c | 1 + arch/x86/kvm/vmx/vmx.c | 19 +++++-------------- arch/x86/kvm/x86.c | 7 +------ 3 files changed, 7 insertions(+), 20 deletions(-) diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 80710a68ef7d..b34dd3f3e6c4 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1315,6 +1315,7 @@ u64 x86_read_arch_cap_msr(void) return ia32_cap; } +EXPORT_SYMBOL_GPL(x86_read_arch_cap_msr); static bool arch_cap_mmio_immune(u64 ia32_cap) { diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 8274ef5e89e5..3dec4a4f637e 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -255,14 +255,9 @@ static int vmx_setup_l1d_flush(enum vmx_l1d_flush_state l1tf) return 0; } - if (boot_cpu_has(X86_FEATURE_ARCH_CAPABILITIES)) { - u64 msr; - - rdmsrl(MSR_IA32_ARCH_CAPABILITIES, msr); - if (msr & ARCH_CAP_SKIP_VMENTRY_L1DFLUSH) { - l1tf_vmx_mitigation = VMENTER_L1D_FLUSH_NOT_REQUIRED; - return 0; - } + if (x86_read_arch_cap_msr() & ARCH_CAP_SKIP_VMENTRY_L1DFLUSH) { + l1tf_vmx_mitigation = VMENTER_L1D_FLUSH_NOT_REQUIRED; + return 0; } /* If set to auto use the default l1tf mitigation method */ @@ -394,13 +389,9 @@ static int vmentry_l1d_flush_get(char *s, const struct kernel_param *kp) static void vmx_setup_fb_clear_ctrl(void) { - u64 msr; - - if (boot_cpu_has(X86_FEATURE_ARCH_CAPABILITIES) && - !boot_cpu_has_bug(X86_BUG_MDS) && + if (!boot_cpu_has_bug(X86_BUG_MDS) && !boot_cpu_has_bug(X86_BUG_TAA)) { - rdmsrl(MSR_IA32_ARCH_CAPABILITIES, msr); - if (msr & ARCH_CAP_FB_CLEAR_CTRL) + if (x86_read_arch_cap_msr() & ARCH_CAP_FB_CLEAR_CTRL) vmx_fb_clear_ctrl_available = true; } } diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index f7838260c183..b1bdb84ac10f 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -1612,12 +1612,7 @@ static bool kvm_is_immutable_feature_msr(u32 msr) static u64 kvm_get_arch_capabilities(void) { - u64 data = 0; - - if (boot_cpu_has(X86_FEATURE_ARCH_CAPABILITIES)) { - rdmsrl(MSR_IA32_ARCH_CAPABILITIES, data); - data &= KVM_SUPPORTED_ARCH_CAP; - } + u64 data = x86_read_arch_cap_msr() & KVM_SUPPORTED_ARCH_CAP; /* * If nx_huge_pages is enabled, KVM's shadow paging will ensure that