Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1290834yba; Thu, 18 Apr 2019 19:29:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqys8WeJdPGvmZqJrY5eDV9iZwvKnASCnG6fjuLKUxLPSktfucstBMT/GZDsJFKDw0ScaAVw X-Received: by 2002:a63:170b:: with SMTP id x11mr1412281pgl.186.1555640971992; Thu, 18 Apr 2019 19:29:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555640971; cv=none; d=google.com; s=arc-20160816; b=DXUvXHCR1WJ+NJYgGUI3tiLqJt7KuNRkalwIqpBxnfeS0GMItMmoDvXyjqFU2IsuCK Od+n0/TH/sOKgE8Y9b2by36SG+l85nVMw4O1uLjZ/qu2qveebFTu7wfmjh/oYBYjidxB fh1Jxjz60aopxA7RsBuMHZSe9tIN6nEQHdsSoSMn+yAUjqJsEgke6wVd9QDJf1UYx2as OlHaRfZDuZiJ3yqwKP09j/1ZiI6KFrUdLzopvNaMgTl0SyK5qSiKAgmQ5jwoorkL5i3L bVNsFClWzXpmTIQKAR95NqPPMuNDdve5T7kubVSFXE/IArQEPmBWWuInEnRJjG2Lf9W2 Jabw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=Cr3jxz1llHpRFR08/4quUdfsbeEUnCJUuElH9qwxAjA=; b=aU6RPAhuQE9Of+jmbh7Q3zenawtZsKCOlCbbxioRzu4VPY7Wpp43XIXpdeovxTrFqy jc+WvLhG5tDCpFQ7p2ScP64YVp8s8auikfI0kbss2q75tZp4A/PSjULqOZtKPoED+t+A QTA30MQ02gk0NY7U53CHuEbDYV83iBRAxBt9005mIVE7s/4EgJspBP01rup2ARSo8IDT 3T6ydvxSH6ZNk+Tinw3C/7YHrqgeex2wWPQreYSzIBTjf3gdnp76gWCdGxMWkI9azQD6 dizeqxXAooLBMrfQRexwCKG4ky50OP4MRtI/k31I2+xNPM3SmLVcyWHIq8+rxVtHdDOM VLAw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h11si4117590plk.270.2019.04.18.19.29.16; Thu, 18 Apr 2019 19:29:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727190AbfDSC21 (ORCPT + 99 others); Thu, 18 Apr 2019 22:28:27 -0400 Received: from mga06.intel.com ([134.134.136.31]:5539 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726822AbfDSC21 (ORCPT ); Thu, 18 Apr 2019 22:28:27 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Apr 2019 19:28:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,368,1549958400"; d="scan'208";a="137051741" Received: from xy-skl-4s.sh.intel.com ([10.239.48.179]) by orsmga006.jf.intel.com with ESMTP; 18 Apr 2019 19:28:24 -0700 From: Xiaoyao Li To: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , kvm@vger.kernel.org Cc: Xiaoyao Li , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] kvm: x86: refine kvm_get_arch_capabilities() Date: Fri, 19 Apr 2019 10:16:24 +0800 Message-Id: <20190419021624.186106-1-xiaoyao.li@linux.intel.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 1. Using X86_FEATURE_ARCH_CAPABILITIES to enumerate the existence of MSR_IA32_ARCH_CAPABILITIES to avoid using rdmsrl_safe(). 2. Since kvm_get_arch_capabilities() is only used in this file, making it static. Signed-off-by: Xiaoyao Li --- arch/x86/include/asm/kvm_host.h | 1 - arch/x86/kvm/x86.c | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index a9d03af34030..d4ae67870764 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1526,7 +1526,6 @@ int kvm_pv_send_ipi(struct kvm *kvm, unsigned long ipi_bitmap_low, unsigned long ipi_bitmap_high, u32 min, unsigned long icr, int op_64_bit); -u64 kvm_get_arch_capabilities(void); void kvm_define_shared_msr(unsigned index, u32 msr); int kvm_set_shared_msr(unsigned index, u64 val, u64 mask); diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index a0d1fc80ac5a..ba8e269a8cd2 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -1205,11 +1205,12 @@ static u32 msr_based_features[] = { static unsigned int num_msr_based_features; -u64 kvm_get_arch_capabilities(void) +static u64 kvm_get_arch_capabilities(void) { - u64 data; + u64 data = 0; - rdmsrl_safe(MSR_IA32_ARCH_CAPABILITIES, &data); + if (boot_cpu_has(X86_FEATURE_ARCH_CAPABILITIES)) + rdmsrl(MSR_IA32_ARCH_CAPABILITIES, data); /* * If we're doing cache flushes (either "always" or "cond") @@ -1225,7 +1226,6 @@ u64 kvm_get_arch_capabilities(void) return data; } -EXPORT_SYMBOL_GPL(kvm_get_arch_capabilities); static int kvm_get_msr_feature(struct kvm_msr_entry *msr) { -- 2.19.1