From patchwork Thu Jan 6 17:56:28 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 77763 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 66E7EB708B for ; Fri, 7 Jan 2011 05:20:51 +1100 (EST) Received: from localhost ([127.0.0.1]:53273 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PauS8-0004su-Bn for incoming@patchwork.ozlabs.org; Thu, 06 Jan 2011 13:20:48 -0500 Received: from [140.186.70.92] (port=32852 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PauBE-0003uU-NL for qemu-devel@nongnu.org; Thu, 06 Jan 2011 13:03:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PauBA-0006bF-Us for qemu-devel@nongnu.org; Thu, 06 Jan 2011 13:03:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39928) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PauBA-0006al-NQ for qemu-devel@nongnu.org; Thu, 06 Jan 2011 13:03:16 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id p06I3F6k025697 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 6 Jan 2011 13:03:16 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p06I3F0o031088; Thu, 6 Jan 2011 13:03:15 -0500 Received: from amt.cnet (vpn1-4-164.ams2.redhat.com [10.36.4.164]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p06I3DjZ019117; Thu, 6 Jan 2011 13:03:14 -0500 Received: from amt.cnet (localhost.localdomain [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 7B79768A253; Thu, 6 Jan 2011 15:58:51 -0200 (BRST) Received: (from marcelo@localhost) by amt.cnet (8.14.4/8.14.4/Submit) id p06HwlvT011384; Thu, 6 Jan 2011 15:58:47 -0200 From: Marcelo Tosatti To: Anthony Liguori Date: Thu, 6 Jan 2011 15:56:28 -0200 Message-Id: <259263cb7c98cf3d8c3a9812d550e4a0f9ac11d2.1294336601.git.mtosatti@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Jan Kiszka , Marcelo Tosatti , qemu-devel@nongnu.org, kvm@vger.kernel.org Subject: [Qemu-devel] [PATCH 22/35] kvm: x86: Refactor msr_star/hsave_pa setup and checks 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 From: Jan Kiszka Simplify kvm_has_msr_star/hsave_pa to booleans and push their one-time initialization into kvm_arch_init. Also handle potential errors of that setup procedure. Signed-off-by: Jan Kiszka Signed-off-by: Marcelo Tosatti --- target-i386/kvm.c | 47 +++++++++++++++++++---------------------------- 1 files changed, 19 insertions(+), 28 deletions(-) diff --git a/target-i386/kvm.c b/target-i386/kvm.c index e46b901..d8f26bf 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -54,6 +54,8 @@ #define BUS_MCEERR_AO 5 #endif +static bool has_msr_star; +static bool has_msr_hsave_pa; static int lm_capable_kernel; #ifdef KVM_CAP_EXT_CPUID @@ -459,13 +461,10 @@ void kvm_arch_reset_vcpu(CPUState *env) } } -int has_msr_star; -int has_msr_hsave_pa; - -static void kvm_supported_msrs(CPUState *env) +static int kvm_get_supported_msrs(KVMState *s) { static int kvm_supported_msrs; - int ret; + int ret = 0; /* first time */ if (kvm_supported_msrs == 0) { @@ -476,9 +475,9 @@ static void kvm_supported_msrs(CPUState *env) /* Obtain MSR list from KVM. These are the MSRs that we must * save/restore */ msr_list.nmsrs = 0; - ret = kvm_ioctl(env->kvm_state, KVM_GET_MSR_INDEX_LIST, &msr_list); + ret = kvm_ioctl(s, KVM_GET_MSR_INDEX_LIST, &msr_list); if (ret < 0 && ret != -E2BIG) { - return; + return ret; } /* Old kernel modules had a bug and could write beyond the provided memory. Allocate at least a safe amount of 1K. */ @@ -487,17 +486,17 @@ static void kvm_supported_msrs(CPUState *env) sizeof(msr_list.indices[0]))); kvm_msr_list->nmsrs = msr_list.nmsrs; - ret = kvm_ioctl(env->kvm_state, KVM_GET_MSR_INDEX_LIST, kvm_msr_list); + ret = kvm_ioctl(s, KVM_GET_MSR_INDEX_LIST, kvm_msr_list); if (ret >= 0) { int i; for (i = 0; i < kvm_msr_list->nmsrs; i++) { if (kvm_msr_list->indices[i] == MSR_STAR) { - has_msr_star = 1; + has_msr_star = true; continue; } if (kvm_msr_list->indices[i] == MSR_VM_HSAVE_PA) { - has_msr_hsave_pa = 1; + has_msr_hsave_pa = true; continue; } } @@ -506,19 +505,7 @@ static void kvm_supported_msrs(CPUState *env) free(kvm_msr_list); } - return; -} - -static int kvm_has_msr_hsave_pa(CPUState *env) -{ - kvm_supported_msrs(env); - return has_msr_hsave_pa; -} - -static int kvm_has_msr_star(CPUState *env) -{ - kvm_supported_msrs(env); - return has_msr_star; + return ret; } static int kvm_init_identity_map_page(KVMState *s) @@ -543,9 +530,13 @@ static int kvm_init_identity_map_page(KVMState *s) int kvm_arch_init(KVMState *s, int smp_cpus) { int ret; - struct utsname utsname; + ret = kvm_get_supported_msrs(s); + if (ret < 0) { + return ret; + } + uname(&utsname); lm_capable_kernel = strcmp(utsname.machine, "x86_64") == 0; @@ -830,10 +821,10 @@ static int kvm_put_msrs(CPUState *env, int level) kvm_msr_entry_set(&msrs[n++], MSR_IA32_SYSENTER_CS, env->sysenter_cs); kvm_msr_entry_set(&msrs[n++], MSR_IA32_SYSENTER_ESP, env->sysenter_esp); kvm_msr_entry_set(&msrs[n++], MSR_IA32_SYSENTER_EIP, env->sysenter_eip); - if (kvm_has_msr_star(env)) { + if (has_msr_star) { kvm_msr_entry_set(&msrs[n++], MSR_STAR, env->star); } - if (kvm_has_msr_hsave_pa(env)) { + if (has_msr_hsave_pa) { kvm_msr_entry_set(&msrs[n++], MSR_VM_HSAVE_PA, env->vm_hsave); } #ifdef TARGET_X86_64 @@ -1076,10 +1067,10 @@ static int kvm_get_msrs(CPUState *env) msrs[n++].index = MSR_IA32_SYSENTER_CS; msrs[n++].index = MSR_IA32_SYSENTER_ESP; msrs[n++].index = MSR_IA32_SYSENTER_EIP; - if (kvm_has_msr_star(env)) { + if (has_msr_star) { msrs[n++].index = MSR_STAR; } - if (kvm_has_msr_hsave_pa(env)) { + if (has_msr_hsave_pa) { msrs[n++].index = MSR_VM_HSAVE_PA; } msrs[n++].index = MSR_IA32_TSC;