Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 125236
b: refs/heads/master
c: 63d1142
h: refs/heads/master
v: v3
  • Loading branch information
Eduardo Habkost authored and Avi Kivity committed Dec 31, 2008
1 parent 7db2ad2 commit b6f43fa
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 15 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 6aa07a0d77f6aafbe69e4e8609ffaf2b7ee1b591
refs/heads/master: 63d1142f8f69e39468bc6079ab2239e902828134
41 changes: 41 additions & 0 deletions trunk/arch/x86/include/asm/virtext.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <asm/system.h>

#include <asm/vmx.h>
#include <asm/svm.h>

/*
* VMX functions:
Expand Down Expand Up @@ -66,4 +67,44 @@ static inline void cpu_emergency_vmxoff(void)
__cpu_emergency_vmxoff();
}




/*
* SVM functions:
*/

/** Check if the CPU has SVM support
*
* You can use the 'msg' arg to get a message describing the problem,
* if the function returns zero. Simply pass NULL if you are not interested
* on the messages; gcc should take care of not generating code for
* the messages on this case.
*/
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 (msg)
*msg = "can't execute cpuid_8000000a";
return 0;
}

cpuid(0x80000001, &eax, &ebx, &ecx, &edx);
if (!(ecx & (1 << SVM_CPUID_FEATURE_SHIFT))) {
if (msg)
*msg = "svm not available";
return 0;
}
return 1;
}

#endif /* _ASM_X86_VIRTEX_H */
19 changes: 5 additions & 14 deletions trunk/arch/x86/kvm/svm.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

#include <asm/desc.h>

#include <asm/virtext.h>

#define __ex(x) __kvm_handle_fault_on_reboot(x)

MODULE_AUTHOR("Qumranet");
Expand Down Expand Up @@ -245,24 +247,13 @@ static void skip_emulated_instruction(struct kvm_vcpu *vcpu)

static int has_svm(void)
{
uint32_t eax, ebx, ecx, edx;

if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD) {
printk(KERN_INFO "has_svm: not amd\n");
return 0;
}
const char *msg;

cpuid(0x80000000, &eax, &ebx, &ecx, &edx);
if (eax < SVM_CPUID_FUNC) {
printk(KERN_INFO "has_svm: can't execute cpuid_8000000a\n");
if (!cpu_has_svm(&msg)) {
printk(KERN_INFO "has_svn: %s\n", msg);
return 0;
}

cpuid(0x80000001, &eax, &ebx, &ecx, &edx);
if (!(ecx & (1 << SVM_CPUID_FEATURE_SHIFT))) {
printk(KERN_DEBUG "has_svm: svm not available\n");
return 0;
}
return 1;
}

Expand Down

0 comments on commit b6f43fa

Please sign in to comment.