From: Christian Borntraeger Subject: Re: [PATCH] kvm-userspace: fix memslot assignment Date: Thu, 31 Jul 2008 10:01:07 +0200 Message-ID: <200807311001.07426.borntraeger@de.ibm.com> References: <200807251738.29171.borntraeger@de.ibm.com> <200807281855.04681.borntraeger@de.ibm.com> <488F18B9.1010700@qumranet.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Cc: kvm , Carsten Otte , Olaf Schnapper , Christian Ehrhardt To: Avi Kivity Return-path: Received: from mtagate1.de.ibm.com ([195.212.29.150]:36041 "EHLO mtagate1.de.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750812AbYGaIB1 (ORCPT ); Thu, 31 Jul 2008 04:01:27 -0400 Received: from d12nrmr1607.megacenter.de.ibm.com (d12nrmr1607.megacenter.de.ibm.com [9.149.167.49]) by mtagate1.de.ibm.com (8.13.8/8.13.8) with ESMTP id m6V818vX081136 for ; Thu, 31 Jul 2008 08:01:08 GMT Received: from d12av03.megacenter.de.ibm.com (d12av03.megacenter.de.ibm.com [9.149.165.213]) by d12nrmr1607.megacenter.de.ibm.com (8.13.8/8.13.8/NCO v9.0) with ESMTP id m6V8189Q4034664 for ; Thu, 31 Jul 2008 10:01:08 +0200 Received: from d12av03.megacenter.de.ibm.com (loopback [127.0.0.1]) by d12av03.megacenter.de.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id m6V817CE001672 for ; Thu, 31 Jul 2008 10:01:08 +0200 In-Reply-To: <488F18B9.1010700@qumranet.com> Content-Disposition: inline Sender: kvm-owner@vger.kernel.org List-ID: Am Dienstag, 29. Juli 2008 schrieb Avi Kivity: > They all start with 0 AFAIK (kvm also starts with 0, it just wants it to > be a special slot). Now my brain hurts.... Ok, so I read this as: 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 Since my opteron box died recently I cannot test that on x86 at the moment. What do you think about the following patch Signed-off-by: Christian Borntraeger --- libkvm/libkvm.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) Index: kvm-userspace/libkvm/libkvm.c =================================================================== --- kvm-userspace.orig/libkvm/libkvm.c +++ kvm-userspace/libkvm/libkvm.c @@ -75,25 +75,21 @@ void init_slots(void) int get_free_slot(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); -#else - tss_ext = 0; -#endif + int i = 0; /* - * 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(__x86_64__) || defined(__i386__) +#if defined(KVM_CAP_SET_TSS_ADDR) + if (ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR) > 0) + i++; +#else + i++; +#endif +#endif for (; i < KVM_MAX_NUM_MEM_REGIONS; ++i) if (!slots[i].len) return i;