From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1M9aJn-0004Dw-VX for qemu-devel@nongnu.org; Thu, 28 May 2009 03:46:28 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1M9aJi-0004CH-Lo for qemu-devel@nongnu.org; Thu, 28 May 2009 03:46:27 -0400 Received: from [199.232.76.173] (port=51276 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M9aJi-0004CE-Gh for qemu-devel@nongnu.org; Thu, 28 May 2009 03:46:22 -0400 Received: from mx20.gnu.org ([199.232.41.8]:4818) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1M9aJh-0003QR-Su for qemu-devel@nongnu.org; Thu, 28 May 2009 03:46:22 -0400 Received: from fmmailgate01.web.de ([217.72.192.221]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1M9aJg-0000rY-3G for qemu-devel@nongnu.org; Thu, 28 May 2009 03:46:20 -0400 Message-ID: <4A1E4145.4010304@web.de> Date: Thu, 28 May 2009 09:46:13 +0200 From: Jan Kiszka MIME-Version: 1.0 References: <4A184C2D.7060205@web.de> <4A1E3F29.6070009@codemonkey.ws> In-Reply-To: <4A1E3F29.6070009@codemonkey.ws> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig9E8771C9C2A61A77DAC3AA4E" Sender: jan.kiszka@web.de Subject: [Qemu-devel] Re: [PATCH 1/2] kvm: Rework VCPU synchronization List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: qemu-devel This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig9E8771C9C2A61A77DAC3AA4E Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable Anthony Liguori wrote: > Jan Kiszka wrote: >> During startup and after reset we have to synchronize user space to th= e >> in-kernel KVM state. Namely, we need to transfer the VCPU registers wh= en >> they change due to VCPU as well as APIC reset. >> >> This patch refactors the required hooks so that kvm_init_vcpu register= s >> its own per-VCPU reset handler and adds a cpu_synchronize_state to the= >> APIC reset. That way we no longer depend on the new reset order (and c= an >> drop this disliked interface again) and we can even drop a KVM hook in= >> main(). >> >> Signed-off-by: Jan Kiszka >> =20 >=20 >> diff --git a/kvm-all.c b/kvm-all.c >> index c89e3b1..1364982 100644 >> --- a/kvm-all.c >> +++ b/kvm-all.c >> @@ -143,6 +143,15 @@ static int kvm_set_user_memory_region(KVMState *s= , >> KVMSlot *slot) >> =20 >=20 > This patch (this line, in particular) is whitespace damaged. >=20 Sorry, fixed version below: ---------> During startup and after reset we have to synchronize user space to the in-kernel KVM state. Namely, we need to transfer the VCPU registers when they change due to VCPU as well as APIC reset. This patch refactors the required hooks so that kvm_init_vcpu registers its own per-VCPU reset handler and adds a cpu_synchronize_state to the APIC reset. That way we no longer depend on the new reset order (and can drop this disliked interface again) and we can even drop a KVM hook in main(). Signed-off-by: Jan Kiszka --- hw/apic.c | 3 +++ kvm-all.c | 36 +++++++++++++----------------------- kvm.h | 1 - vl.c | 11 ----------- 4 files changed, 16 insertions(+), 35 deletions(-) diff --git a/hw/apic.c b/hw/apic.c index 8c8b2de..10b8184 100644 --- a/hw/apic.c +++ b/hw/apic.c @@ -21,6 +21,7 @@ #include "pc.h" #include "qemu-timer.h" #include "host-utils.h" +#include "kvm.h" =20 //#define DEBUG_APIC =20 @@ -884,6 +885,8 @@ static void apic_reset(void *opaque) */ s->lvt[APIC_LVT_LINT0] =3D 0x700; } + + cpu_synchronize_state(s->cpu_env, 1); } =20 static CPUReadMemoryFunc *apic_mem_read[3] =3D { diff --git a/kvm-all.c b/kvm-all.c index c89e3b1..1364982 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -143,6 +143,15 @@ static int kvm_set_user_memory_region(KVMState *s, K= VMSlot *slot) return kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, &mem); } =20 +static void kvm_reset_vcpu(void *opaque) +{ + CPUState *env =3D opaque; + + if (kvm_arch_put_registers(env)) { + fprintf(stderr, "Fatal: kvm vcpu reset failed\n"); + abort(); + } +} =20 int kvm_init_vcpu(CPUState *env) { @@ -176,7 +185,10 @@ int kvm_init_vcpu(CPUState *env) } =20 ret =3D kvm_arch_init_vcpu(env); - + if (ret =3D=3D 0) { + qemu_register_reset(kvm_reset_vcpu, 0, env); + ret =3D kvm_arch_put_registers(env); + } err: return ret; } @@ -201,21 +213,6 @@ int kvm_get_mp_state(CPUState *env) return 0; } =20 -int kvm_sync_vcpus(void) -{ - CPUState *env; - - for (env =3D first_cpu; env !=3D NULL; env =3D env->next_cpu) { - int ret; - - ret =3D kvm_arch_put_registers(env); - if (ret) - return ret; - } - - return 0; -} - /* * dirty pages logging control */ @@ -397,11 +394,6 @@ int kvm_check_extension(KVMState *s, unsigned int ex= tension) return ret; } =20 -static void kvm_reset_vcpus(void *opaque) -{ - kvm_sync_vcpus(); -} - int kvm_init(int smp_cpus) { KVMState *s; @@ -488,8 +480,6 @@ int kvm_init(int smp_cpus) if (ret < 0) goto err; =20 - qemu_register_reset(kvm_reset_vcpus, INT_MAX, NULL); - kvm_state =3D s; =20 return 0; diff --git a/kvm.h b/kvm.h index 560aef3..96b4d72 100644 --- a/kvm.h +++ b/kvm.h @@ -32,7 +32,6 @@ struct kvm_run; int kvm_init(int smp_cpus); =20 int kvm_init_vcpu(CPUState *env); -int kvm_sync_vcpus(void); =20 int kvm_cpu_exec(CPUState *env); =20 diff --git a/vl.c b/vl.c index 090c83d..8b38fd1 100644 --- a/vl.c +++ b/vl.c @@ -5918,17 +5918,6 @@ int main(int argc, char **argv, char **envp) =20 current_machine =3D machine; =20 - /* Set KVM's vcpu state to qemu's initial CPUState. */ - if (kvm_enabled()) { - int ret; - - ret =3D kvm_sync_vcpus(); - if (ret < 0) { - fprintf(stderr, "failed to initialize vcpus\n"); - exit(1); - } - } - /* init USB devices */ if (usb_enabled) { for(i =3D 0; i < usb_devices_index; i++) { --------------enig9E8771C9C2A61A77DAC3AA4E Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iEYEARECAAYFAkoeQUoACgkQniDOoMHTA+l74wCghHl8Q+gP/94K/1YG8nrHtZUH u7IAnjbTAYnbDaLD390KnKnj+jP+Q7Bu =puiX -----END PGP SIGNATURE----- --------------enig9E8771C9C2A61A77DAC3AA4E--