From: Christian Borntraeger Subject: Re: [PATCH] kvm-userspace: fix memslot assignment Date: Thu, 31 Jul 2008 14:53:56 +0200 Message-ID: <200807311453.56210.borntraeger@de.ibm.com> References: <200807251738.29171.borntraeger@de.ibm.com> <200807311001.07426.borntraeger@de.ibm.com> <4891A0DD.5000503@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 , Izik Eidus To: Avi Kivity Return-path: Received: from mtagate6.uk.ibm.com ([195.212.29.139]:40500 "EHLO mtagate6.uk.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752045AbYGaMyu (ORCPT ); Thu, 31 Jul 2008 08:54:50 -0400 Received: from d06nrmr1407.portsmouth.uk.ibm.com (d06nrmr1407.portsmouth.uk.ibm.com [9.149.38.185]) by mtagate6.uk.ibm.com (8.13.8/8.13.8) with ESMTP id m6VCrvHr656242 for ; Thu, 31 Jul 2008 12:53:57 GMT Received: from d06av03.portsmouth.uk.ibm.com (d06av03.portsmouth.uk.ibm.com [9.149.37.213]) by d06nrmr1407.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v9.0) with ESMTP id m6VCrvHS3981328 for ; Thu, 31 Jul 2008 13:53:57 +0100 Received: from d06av03.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av03.portsmouth.uk.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id m6VCrub5012676 for ; Thu, 31 Jul 2008 13:53:57 +0100 In-Reply-To: <4891A0DD.5000503@qumranet.com> Content-Disposition: inline Sender: kvm-owner@vger.kernel.org List-ID: Am Donnerstag, 31. Juli 2008 schrieb Avi Kivity: > > +#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) > > > > Should be <= here? yes. But with the wrapper you suggest below its again >. > > > + i++; > > +#else > > + i++; > > +#endif > > +#endif > > > > Suggest a helper, kvm_supports_set_tss_addr(), to reduce further > braindamage. Something like that? But then I get the following warning on non-x86: libkvm.c:77: warning: 'kvm_supports_set_tss_addr' defined but not used Should I mask the wrapper with config x86 as well? --- libkvm.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) Index: libkvm/libkvm.c =================================================================== --- libkvm.orig/libkvm.c +++ libkvm/libkvm.c @@ -73,27 +73,29 @@ void init_slots(void) slots[i].len = 0; } +static int kvm_supports_set_tss_addr(kvm_context_t kvm) +{ +#if defined(KVM_CAP_SET_TSS_ADDR) + if (ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR) > 0) + return 1; +#endif + return 0; +} + 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 /* - * 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__) + i = !kvm_supports_set_tss_addr(kvm); +#else + i = 0; +#endif for (; i < KVM_MAX_NUM_MEM_REGIONS; ++i) if (!slots[i].len) return i;