Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 63d1142f authored by Eduardo Habkost's avatar Eduardo Habkost Committed by Avi Kivity
Browse files

KVM: SVM: move has_svm() code to asm/virtext.h



Use a trick to keep the printk()s on has_svm() working as before. gcc
will take care of not generating code for the 'msg' stuff when the
function is called with a NULL msg argument.

Signed-off-by: default avatarEduardo Habkost <ehabkost@redhat.com>
Signed-off-by: default avatarAvi Kivity <avi@redhat.com>
parent 6aa07a0d
Loading
Loading
Loading
Loading
+41 −0
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@
#include <asm/system.h>
#include <asm/system.h>


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


/*
/*
 * VMX functions:
 * VMX functions:
@@ -66,4 +67,44 @@ static inline void cpu_emergency_vmxoff(void)
		__cpu_emergency_vmxoff();
		__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 */
#endif /* _ASM_X86_VIRTEX_H */
+5 −14
Original line number Original line Diff line number Diff line
@@ -28,6 +28,8 @@


#include <asm/desc.h>
#include <asm/desc.h>


#include <asm/virtext.h>

#define __ex(x) __kvm_handle_fault_on_reboot(x)
#define __ex(x) __kvm_handle_fault_on_reboot(x)


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


static int has_svm(void)
static int has_svm(void)
{
{
	uint32_t eax, ebx, ecx, edx;
	const char *msg;

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


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