From patchwork Tue Sep 7 12:30:53 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: john cooper X-Patchwork-Id: 64006 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 25BEAB6F06 for ; Tue, 7 Sep 2010 22:36:35 +1000 (EST) Received: from localhost ([127.0.0.1]:46585 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OsxPb-0006BE-V7 for incoming@patchwork.ozlabs.org; Tue, 07 Sep 2010 08:36:32 -0400 Received: from [140.186.70.92] (port=42528 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OsxLB-0004Bg-NR for qemu-devel@nongnu.org; Tue, 07 Sep 2010 08:32:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OsxL9-0004Eg-7E for qemu-devel@nongnu.org; Tue, 07 Sep 2010 08:31:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34440) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OsxL8-0004EY-US for qemu-devel@nongnu.org; Tue, 07 Sep 2010 08:31:55 -0400 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 o87CVs5Q001803 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 7 Sep 2010 08:31:54 -0400 Received: from anvil.naka.net (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o87CVnFK008551; Tue, 7 Sep 2010 08:31:51 -0400 Message-ID: <4C86307D.9030408@redhat.com> Date: Tue, 07 Sep 2010 08:30:53 -0400 From: john cooper User-Agent: Thunderbird 2.0.0.9 (X11/20071115) MIME-Version: 1.0 To: qemu-devel@nongnu.org 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: john cooper Subject: [Qemu-devel] [PATCH 2/4] cpu model corrections/updates: add kvm_early_init_vcpu() 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 Allow an optional qemu_early_init_vcpu() such that kvm_arch_get_supported_cpuid() can be used from cpu_x86_register(). Without this minimal setup kvm_arch_get_supported_cpuid() gags kvm_ioctl() via passing a NULL initialized KVMState *. Signed-off-by: john cooper diff --git a/cpus.c b/cpus.c index b09f5e3..82a33b4 100644 --- a/cpus.c +++ b/cpus.c @@ -252,6 +252,14 @@ void qemu_main_loop_start(void) { } +void qemu_early_init_vcpu(void *_env) +{ + CPUState *env = _env; + + if (kvm_enabled()) + kvm_early_init_vcpu(env); +} + void qemu_init_vcpu(void *_env) { CPUState *env = _env; diff --git a/kvm-all.c b/kvm-all.c index 58b0404..9d89d35 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -170,25 +170,48 @@ int kvm_pit_in_kernel(void) } -int kvm_init_vcpu(CPUState *env) +/* env->kvm_state is needed early by kvm_check_extension() + * break it out so it may be setup early where needed + */ +int kvm_early_init_vcpu(CPUState *env) { KVMState *s = kvm_state; - long mmap_size; int ret; - DPRINTF("kvm_init_vcpu\n"); + DPRINTF("kvm_early_init_vcpu\n"); + + if (env->kvm_state) { /* already setup */ + return 0; + } ret = kvm_vm_ioctl(s, KVM_CREATE_VCPU, env->cpu_index); if (ret < 0) { DPRINTF("kvm_create_vcpu failed\n"); - goto err; } + else { + env->kvm_fd = ret; + env->kvm_state = s; + } + return ret; +} - env->kvm_fd = ret; - env->kvm_state = s; +int kvm_init_vcpu(CPUState *env) +{ + KVMState *s; + long mmap_size; + int ret; + + DPRINTF("kvm_init_vcpu\n"); + + ret = kvm_early_init_vcpu(env); + if (ret < 0) { + goto err; + } + s = env->kvm_state; mmap_size = kvm_ioctl(s, KVM_GET_VCPU_MMAP_SIZE, 0); if (mmap_size < 0) { + ret = mmap_size; DPRINTF("KVM_GET_VCPU_MMAP_SIZE failed\n"); goto err; } diff --git a/kvm.h b/kvm.h index 50b6c01..420c815 100644 --- a/kvm.h +++ b/kvm.h @@ -44,6 +44,7 @@ int kvm_has_xsave(void); int kvm_has_xcrs(void); #ifdef NEED_CPU_H +int kvm_early_init_vcpu(CPUState *env); int kvm_init_vcpu(CPUState *env); int kvm_cpu_exec(CPUState *env); diff --git a/qemu-common.h b/qemu-common.h index dfd3dc0..2453778 100644 --- a/qemu-common.h +++ b/qemu-common.h @@ -263,8 +263,10 @@ struct qemu_work_item { }; #ifdef CONFIG_USER_ONLY +#define qemu_early_init_vcpu(env) do { } while (0) #define qemu_init_vcpu(env) do { } while (0) #else +void qemu_early_init_vcpu(void *env); void qemu_init_vcpu(void *env); #endif diff --git a/target-i386/helper.c b/target-i386/helper.c index e134340..b3c0b42 100644 --- a/target-i386/helper.c +++ b/target-i386/helper.c @@ -1133,6 +1133,7 @@ CPUX86State *cpu_x86_init(const char *cpu_model) cpu_set_debug_excp_handler(breakpoint_handler); #endif } + qemu_early_init_vcpu(env); if (cpu_x86_register(env, cpu_model) < 0) { cpu_x86_close(env); return NULL;