From patchwork Wed Oct 14 17:09:20 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glauber Costa X-Patchwork-Id: 35998 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 21359B7B68 for ; Thu, 15 Oct 2009 04:10:10 +1100 (EST) Received: from localhost ([127.0.0.1]:46736 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1My7MV-0004VC-HD for incoming@patchwork.ozlabs.org; Wed, 14 Oct 2009 13:10:07 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1My7Lt-0004SP-CO for qemu-devel@nongnu.org; Wed, 14 Oct 2009 13:09:29 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1My7Lo-0004GY-R0 for qemu-devel@nongnu.org; Wed, 14 Oct 2009 13:09:28 -0400 Received: from [199.232.76.173] (port=46628 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1My7Lo-0004GQ-BQ for qemu-devel@nongnu.org; Wed, 14 Oct 2009 13:09:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55958) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1My7Ln-0004P3-RP for qemu-devel@nongnu.org; Wed, 14 Oct 2009 13:09:24 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9EH9MaD006405; Wed, 14 Oct 2009 13:09:23 -0400 Received: from localhost.localdomain (vpn-12-132.rdu.redhat.com [10.11.12.132]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n9EH9KVQ002467; Wed, 14 Oct 2009 13:09:21 -0400 From: Glauber Costa To: qemu-devel@nongnu.org Date: Wed, 14 Oct 2009 14:09:20 -0300 Message-Id: <1255540160-19869-1-git-send-email-glommer@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: aliguori@us.ibm.com Subject: [Qemu-devel] [PATCH] test for lm capable kernel. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Don't save x86_64-specific msrs if our kernel does not support them. Code is already in qemu-kvm.git, but the test function is slightly different. It follows what the test for msr_start does. Signed-off-by: Glauber Costa --- target-i386/kvm.c | 37 +++++++++++++++++++++++++++---------- 1 files changed, 27 insertions(+), 10 deletions(-) diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 7010999..0e69b57 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -15,6 +15,7 @@ #include #include #include +#include #include @@ -266,6 +267,20 @@ static int kvm_has_msr_star(CPUState *env) return 0; } +static int lm_capable_kernel(void) +{ + static int lm_capable = -1; + struct utsname utsname; + + if (lm_capable != -1) { + return lm_capable; + } + + uname(&utsname); + lm_capable = (strcmp(utsname.machine, "x86_64") == 0); + return lm_capable; +} + int kvm_arch_init(KVMState *s, int smp_cpus) { int ret; @@ -478,11 +493,12 @@ static int kvm_put_msrs(CPUState *env) kvm_msr_entry_set(&msrs[n++], MSR_STAR, env->star); kvm_msr_entry_set(&msrs[n++], MSR_IA32_TSC, env->tsc); #ifdef TARGET_X86_64 - /* FIXME if lm capable */ - kvm_msr_entry_set(&msrs[n++], MSR_CSTAR, env->cstar); - kvm_msr_entry_set(&msrs[n++], MSR_KERNELGSBASE, env->kernelgsbase); - kvm_msr_entry_set(&msrs[n++], MSR_FMASK, env->fmask); - kvm_msr_entry_set(&msrs[n++], MSR_LSTAR, env->lstar); + if (lm_capable_kernel()) { + kvm_msr_entry_set(&msrs[n++], MSR_CSTAR, env->cstar); + kvm_msr_entry_set(&msrs[n++], MSR_KERNELGSBASE, env->kernelgsbase); + kvm_msr_entry_set(&msrs[n++], MSR_FMASK, env->fmask); + kvm_msr_entry_set(&msrs[n++], MSR_LSTAR, env->lstar); + } #endif msr_data.info.nmsrs = n; @@ -611,11 +627,12 @@ static int kvm_get_msrs(CPUState *env) msrs[n++].index = MSR_STAR; msrs[n++].index = MSR_IA32_TSC; #ifdef TARGET_X86_64 - /* FIXME lm_capable_kernel */ - msrs[n++].index = MSR_CSTAR; - msrs[n++].index = MSR_KERNELGSBASE; - msrs[n++].index = MSR_FMASK; - msrs[n++].index = MSR_LSTAR; + if (lm_capable_kernel()) { + msrs[n++].index = MSR_CSTAR; + msrs[n++].index = MSR_KERNELGSBASE; + msrs[n++].index = MSR_FMASK; + msrs[n++].index = MSR_LSTAR; + } #endif msr_data.info.nmsrs = n; ret = kvm_vcpu_ioctl(env, KVM_GET_MSRS, &msr_data);