Skip to contentSkip to conversation

kvm: x86: refine kvm_get_arch_capabilities()

PATCH Applied Xiaoyao Li 2 participants 3 messages Apr 19, 2019 – Jun 4, 2019

Subsystems (3)
lore
Share & tools
lore

Xiaoyao Li

author
#0 lore raw

PATCH 1/1 kvm: x86: refine kvm_get_arch_capabilities()

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.

---
 arch/x86/include/asm/kvm_host.h | 1 -
 arch/x86/kvm/x86.c              | 8 ++++----
 2 files changed, 4 insertions(+), 5 deletions(-)
arch/x86/include/asm/kvm_host.h +0 -1
index a9d03af34030..d4ae67870764 100644
@@ -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);
 
arch/x86/kvm/x86.c +4 -4
index a0d1fc80ac5a..ba8e269a8cd2 100644
@@ -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)
 {
Signature · 1 line
2.19.1
author
#1 lore raw

Ping.

Quoted 53 lines · Xiaoyao Li

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.

---
  arch/x86/include/asm/kvm_host.h | 1 -
  arch/x86/kvm/x86.c              | 8 ++++----
  2 files changed, 4 insertions(+), 5 deletions(-)
arch/x86/include/asm/kvm_host.h +0 -1
index a9d03af34030..d4ae67870764 100644
@@ -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);
 
arch/x86/kvm/x86.c +4 -4
index a0d1fc80ac5a..ba8e269a8cd2 100644
@@ -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)
  {
maintainer Applied
#2 lore raw
In reply to Xiaoyao Li
Quoted 46 lines · Xiaoyao Li

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.

---
 arch/x86/include/asm/kvm_host.h | 1 -
 arch/x86/kvm/x86.c              | 8 ++++----
 2 files changed, 4 insertions(+), 5 deletions(-)
arch/x86/include/asm/kvm_host.h +0 -1
index a9d03af34030..d4ae67870764 100644
@@ -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);
 
arch/x86/kvm/x86.c +4 -3
index a0d1fc80ac5a..ba8e269a8cd2 100644
@@ -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")

arch/x86/kvm/x86.c u64 kvm_get_arch_capabilities(void) · line 1231

Quoted 7 lines
arch/x86/kvm/x86.c +0 -1
@@ -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)
 {

Queued, thanks.

Paolo