Skip to contentSkip to conversation

x86/kvm/svm: Simplify cpu_has_svm()

PATCH Applied Borislav Petkov 2 participants 2 messages May 9, 2016 – Jun 9, 2016

Subsystems (3)
lore
Share & tools
lore

Borislav Petkov

author maintainer
#0 lore raw

PATCH 1/1 x86/kvm/svm: Simplify cpu_has_svm()

From: Borislav Petkov <[email protected]>

Use already cached CPUID information instead of querying CPUID again.

No functionality change.

---
 arch/x86/include/asm/svm.h     | 1 -
 arch/x86/include/asm/virtext.h | 8 ++------
 2 files changed, 2 insertions(+), 7 deletions(-)
arch/x86/include/asm/svm.h +0 -1
index 6136d99f537b..41888f51f936 100644
@@ -185,7 +185,6 @@ struct __attribute__ ((__packed__)) vmcb {
 	struct vmcb_save_area save;
 };
 
-#define SVM_CPUID_FEATURE_SHIFT 2
 #define SVM_CPUID_FUNC 0x8000000a
 
 #define SVM_VM_CR_SVM_DISABLE 4
arch/x86/include/asm/virtext.h +2 -6
index cce9ee68e335..0116b2ee9e64 100644
@@ -83,23 +83,19 @@ static inline void cpu_emergency_vmxoff(void)
  */
 static inline int cpu_has_svm(const char **msg)
 {
-	uint32_t eax, ebx, ecx, edx;
-
 	if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD) {
 		if (msg)
 			*msg = "not amd";
 		return 0;
 	}
 
-	cpuid(0x80000000, &eax, &ebx, &ecx, &edx);
-	if (eax < SVM_CPUID_FUNC) {
+	if (boot_cpu_data.extended_cpuid_level < SVM_CPUID_FUNC) {
 		if (msg)
 			*msg = "can't execute cpuid_8000000a";
 		return 0;
 	}
 
-	cpuid(0x80000001, &eax, &ebx, &ecx, &edx);
-	if (!(ecx & (1 << SVM_CPUID_FEATURE_SHIFT))) {
+	if (!boot_cpu_has(X86_FEATURE_SVM)) {
 		if (msg)
 			*msg = "svm not available";
 		return 0;
Signature · 1 line
2.7.3
maintainer Applied
#1 lore raw
Quoted 48 lines · Borislav Petkov

From: Borislav Petkov <[email protected]>

Use already cached CPUID information instead of querying CPUID again.

No functionality change.

---
 arch/x86/include/asm/svm.h     | 1 -
 arch/x86/include/asm/virtext.h | 8 ++------
 2 files changed, 2 insertions(+), 7 deletions(-)
arch/x86/include/asm/svm.h +0 -1
index 6136d99f537b..41888f51f936 100644
@@ -185,7 +185,6 @@ struct __attribute__ ((__packed__)) vmcb {
 	struct vmcb_save_area save;
 };
 
-#define SVM_CPUID_FEATURE_SHIFT 2
 #define SVM_CPUID_FUNC 0x8000000a
 
 #define SVM_VM_CR_SVM_DISABLE 4
arch/x86/include/asm/virtext.h +1 -4
index cce9ee68e335..0116b2ee9e64 100644
@@ -83,23 +83,19 @@ static inline void cpu_emergency_vmxoff(void)
  */
 static inline int cpu_has_svm(const char **msg)
 {
-	uint32_t eax, ebx, ecx, edx;
-
 	if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD) {
 		if (msg)
 			*msg = "not amd";
 		return 0;
 	}
 
-	cpuid(0x80000000, &eax, &ebx, &ecx, &edx);
-	if (eax < SVM_CPUID_FUNC) {
+	if (boot_cpu_data.extended_cpuid_level < SVM_CPUID_FUNC) {
 		if (msg)

arch/x86/include/asm/virtext.h static inline void cpu_emergency_vmxoff(void) · line 101

Quoted 10 lines
arch/x86/include/asm/virtext.h +1 -2
 			*msg = "can't execute cpuid_8000000a";
 		return 0;
 	}
 
-	cpuid(0x80000001, &eax, &ebx, &ecx, &edx);
-	if (!(ecx & (1 << SVM_CPUID_FEATURE_SHIFT))) {
+	if (!boot_cpu_has(X86_FEATURE_SVM)) {
 		if (msg)
 			*msg = "svm not available";
 		return 0;

Queued, thanks.

Paolo