From: Eduardo Habkost <ehabkost@redhat.com>
To: Avi Kivity <avi@redhat.com>, Ingo Molnar <mingo@elte.hu>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>,
Simon Horman <horms@verge.net.au>, Andrew Morton <akpm@osdl.org>,
Vivek Goyal <vgoyal@redhat.com>, Haren Myneni <hbabu@us.ibm.com>,
Andrey Borzenkov <arvidjaar@mail.ru>,
mingo@redhat.com, "Rafael J. Wysocki" <rjw@sisk.pl>,
Zachary Amsden <zach@vmware.com>,
kexec@lists.infradead.org, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org,
Eduardo Habkost <ehabkost@redhat.com>
Subject: [PATCH 07/11] kvm: svm: move has_svm() code to asm/virtext.h
Date: Thu, 13 Nov 2008 15:43:47 -0200 [thread overview]
Message-ID: <1226598231-18311-8-git-send-email-ehabkost@redhat.com> (raw)
In-Reply-To: <1226598231-18311-1-git-send-email-ehabkost@redhat.com>
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: Eduardo Habkost <ehabkost@redhat.com>
---
arch/x86/include/asm/virtext.h | 33 +++++++++++++++++++++++++++++++++
arch/x86/kvm/svm.c | 19 +++++--------------
2 files changed, 38 insertions(+), 14 deletions(-)
diff --git a/arch/x86/include/asm/virtext.h b/arch/x86/include/asm/virtext.h
index f6adf9d..e900015 100644
--- a/arch/x86/include/asm/virtext.h
+++ b/arch/x86/include/asm/virtext.h
@@ -95,4 +95,37 @@ static inline void cpu_emergency_vmxoff(void)
#define SVM_VM_CR_SVM_DISABLE 4
+/** 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 */
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 9c4ce65..64241f5 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -28,6 +28,8 @@
#include <asm/desc.h>
+#include <asm/virtext.h>
+
#define __ex(x) __kvm_handle_fault_on_reboot(x)
MODULE_AUTHOR("Qumranet");
@@ -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;
}
--
1.5.5.GIT
next prev parent reply other threads:[~2008-11-13 17:45 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-13 17:43 [PATCH 00/11] x86: disable virt on kdump and emergency_restart (v3) Eduardo Habkost
2008-11-13 17:43 ` [PATCH 01/11] kvm: vmx: move cpu_has_kvm_support() to an inline on asm/virtext.h Eduardo Habkost
2008-11-13 17:43 ` [PATCH 02/11] kvm: vmx: move ASM_VMX_* definitions to asm/virtext.h Eduardo Habkost
2008-11-13 17:43 ` [PATCH 03/11] x86: asm/virtext.h: add cpu_vmxoff() inline function Eduardo Habkost
2008-11-13 17:43 ` [PATCH 04/11] kvm: vmx: extract kvm_cpu_vmxoff() from hardware_disable() Eduardo Habkost
2008-11-13 17:43 ` [PATCH 05/11] x86: cpu_emergency_vmxoff() function Eduardo Habkost
2008-11-13 17:43 ` [PATCH 06/11] kvm: svm: move some SVM_* #defines to asm/virtext.h Eduardo Habkost
2008-11-13 17:43 ` Eduardo Habkost [this message]
2008-11-13 17:43 ` [PATCH 08/11] kvm: svm: move svm_hardware_disable() code " Eduardo Habkost
2008-11-13 17:43 ` [PATCH 09/11] x86: asm/virtext.h: create cpu_emergency_svm_disable() Eduardo Habkost
2008-11-13 17:43 ` [PATCH 10/11] kdump: forcibly disable VMX and SVM on machine_crash_shutdown() Eduardo Habkost
2008-11-13 17:43 ` [PATCH 11/11] x86: disable VMX on all CPUs on reboot Eduardo Habkost
[not found] ` <1226598231-18311-1-git-send-email-ehabkost-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2008-11-16 7:57 ` [PATCH 00/11] x86: disable virt on kdump and emergency_restart (v3) Avi Kivity
[not found] ` <491FD283.60402-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2008-11-17 15:04 ` Eduardo Habkost
2008-11-17 15:12 ` Avi Kivity
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1226598231-18311-8-git-send-email-ehabkost@redhat.com \
--to=ehabkost@redhat.com \
--cc=akpm@osdl.org \
--cc=arvidjaar@mail.ru \
--cc=avi@redhat.com \
--cc=ebiederm@xmission.com \
--cc=hbabu@us.ibm.com \
--cc=horms@verge.net.au \
--cc=kexec@lists.infradead.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=mingo@redhat.com \
--cc=rjw@sisk.pl \
--cc=vgoyal@redhat.com \
--cc=zach@vmware.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox