Am Donnerstag, 31. Juli 2008 schrieb Avi Kivity:
> If we rename the helper, kvm_wants_special_memslot_0() (reversing the
> meaning), we can have non-x86 return 0, x86 with KVM_CAP_SET_TSS_ADDR
> return 0, and otherwise return 1. No ifdefs outside the helper this way.
Having two ifdefs is not going to be very pretty, but here is the latest
version:
ppc, ia64 and s390 can start with slot 0 and it is not a special slot.
On x86 slot 0 is special, if
* KVM_CAP_SET_TSS_ADDR is not available
or
* The ioctl VM_CAP_SET_TSS_ADDR returns <=0
Lets introduce a helper that checks if we need a special memslot.
Signed-off-by: Christian Borntraeger <[EMAIL PROTECTED]>
---
libkvm.c | 35 +++++++++++++++++++----------------
1 file changed, 19 insertions(+), 16 deletions(-)
Index: libkvm/libkvm.c
===================================================================
--- libkvm.orig/libkvm.c
+++ libkvm/libkvm.c
@@ -73,26 +73,29 @@ void init_slots(void)
slots[i].len = 0;
}
-int get_free_slot(kvm_context_t kvm)
+static int kvm_wants_special_memslot_0(kvm_context_t kvm)
{
- int i;
- int tss_ext;
-
-#if defined(KVM_CAP_SET_TSS_ADDR) && !defined(__s390__)
- tss_ext = ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR);
+#if !defined(__x86_64__) && !defined(__i386__)
+ return 0;
#else
- tss_ext = 0;
-#endif
-
/*
- * on older kernels where the set tss ioctl is not supprted we must save
- * slot 0 to hold the extended memory, as the vmx will use the last 3
- * pages of this slot.
+ * on older x86 kernels where the set tss ioctl is not supported we
+ * must save slot 0 to hold the extended memory, as the vmx will
+ * use the last 3 pages of this slot.
*/
- if (tss_ext > 0)
- i = 0;
- else
- i = 1;
+#if defined(KVM_CAP_SET_TSS_ADDR)
+ if (ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR) > 0)
+ return 0;
+#endif
+ return 1;
+#endif
+}
+
+int get_free_slot(kvm_context_t kvm)
+{
+ int i;
+
+ i = kvm_wants_special_memslot_0(kvm);
for (; i < KVM_MAX_NUM_MEM_REGIONS; ++i)
if (!slots[i].len)
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at http://vger.kernel.org/majordomo-info.html