Newer userspace may run on an older kernel. Therefore we need a way to
check the capabilities of the kernel so that we can downgrade userspace
dynamically if necessary
Signed-off-by: Gregory Haskins <[EMAIL PROTECTED]>
---
qemu/qemu-kvm.c | 27 +++++++++++++++++++++++++++
user/kvmctl.c | 14 ++++++++++++++
user/kvmctl.h | 8 ++++++++
3 files changed, 49 insertions(+), 0 deletions(-)
diff --git a/qemu/qemu-kvm.c b/qemu/qemu-kvm.c
index 1192fbb..d13c967 100644
--- a/qemu/qemu-kvm.c
+++ b/qemu/qemu-kvm.c
@@ -709,6 +709,33 @@ int kvm_qemu_init()
int kvm_qemu_create_context(void)
{
int i;
+ struct kvm_extensions ext;
+
+ if (kvm_check_extension(kvm_context, &ext) < 0) {
+ kvm_qemu_destroy();
+ return -1;
+ }
+
+ if (!ext.lapic && kvm_apic.level) {
+ /*
+ * Opps... the kernel doesnt support apic-emulation even though
+ * the userspace is currently configured to enable it. If this was
+ * just simply because of our defaults, silently disable the feature
+ * and continue.
+ */
+ if (!kvm_apic.user_specified)
+ kvm_apic.level = 0;
+ else {
+ /*
+ * Otherwise, its a fatal error that the user must correct
+ */
+
+ /* FIXME: Should we also log this officially */
+ printf("FATAL: kernel does not support -kvm_apic = %d setting",
+ kvm_apic.level);
+ exit(-1);
+ }
+ }
if (kvm_create(kvm_context, phys_ram_size, kvm_apic.level,
(void**)&phys_ram_base) < 0) {
diff --git a/user/kvmctl.c b/user/kvmctl.c
index 70f9626..596c9cc 100644
--- a/user/kvmctl.c
+++ b/user/kvmctl.c
@@ -1076,3 +1076,17 @@ int kvm_set_signal_mask(kvm_context_t kvm, int vcpu,
const sigset_t *sigset)
free(sigmask);
return r;
}
+
+int kvm_check_extension(kvm_context_t kvm, struct kvm_extensions *ext)
+{
+ memset(ext, 0, sizeof(*ext));
+
+ int r = ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_APIC_MSG);
+ if (r < 0)
+ return r;
+
+ if (r)
+ ext->lapic = 1;
+
+ return 0;
+}
diff --git a/user/kvmctl.h b/user/kvmctl.h
index 9aab269..3a7726c 100644
--- a/user/kvmctl.h
+++ b/user/kvmctl.h
@@ -426,4 +426,12 @@ int kvm_dirty_pages_log_enable_all(kvm_context_t kvm);
*/
int kvm_dirty_pages_log_reset(kvm_context_t kvm);
+struct kvm_extensions
+{
+ int lapic; /* Today we only have one. Add more here as they come up */
+};
+
+int kvm_check_extension(kvm_context_t kvm, struct kvm_extensions *ext);
+
+
#endif
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
kvm-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel