From: Christian Borntraeger Subject: Re: [PATCH] kvm-userspace: fix memslot assignment Date: Thu, 31 Jul 2008 16:57:06 +0200 Message-ID: <200807311657.06479.borntraeger@de.ibm.com> References: <200807251738.29171.borntraeger@de.ibm.com> <200807311453.56210.borntraeger@de.ibm.com> <4891B76B.5090009@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 mtagate5.uk.ibm.com ([195.212.29.138]:13888 "EHLO mtagate5.uk.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750898AbYGaO5R (ORCPT ); Thu, 31 Jul 2008 10:57:17 -0400 Received: from d06nrmr1407.portsmouth.uk.ibm.com (d06nrmr1407.portsmouth.uk.ibm.com [9.149.38.185]) by mtagate5.uk.ibm.com (8.13.8/8.13.8) with ESMTP id m6VEv7cB246166 for ; Thu, 31 Jul 2008 14:57:07 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 m6VEv7FQ3297410 for ; Thu, 31 Jul 2008 15:57:07 +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 m6VEv7k2029620 for ; Thu, 31 Jul 2008 15:57:07 +0100 In-Reply-To: <4891B76B.5090009@qumranet.com> Content-Disposition: inline Sender: kvm-owner@vger.kernel.org List-ID: 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 --- 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)