From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Kiszka Subject: Re: [PATCH 2/5] KVM: Make locked operations truly atomic Date: Wed, 17 Mar 2010 08:45:41 +0100 Message-ID: <4BA088A5.6000201@web.de> References: <1268654397-6650-1-git-send-email-avi@redhat.com> <1268654397-6650-3-git-send-email-avi@redhat.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigF621C4897B82BA04A335DEAB" Cc: Marcelo Tosatti , kvm@vger.kernel.org To: Avi Kivity Return-path: Received: from fmmailgate02.web.de ([217.72.192.227]:54592 "EHLO fmmailgate02.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752203Ab0CQHp7 (ORCPT ); Wed, 17 Mar 2010 03:45:59 -0400 In-Reply-To: <1268654397-6650-3-git-send-email-avi@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigF621C4897B82BA04A335DEAB Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable Avi Kivity wrote: > Once upon a time, locked operations were emulated while holding the mmu= mutex. > Since mmu pages were write protected, it was safe to emulate the writes= in > a non-atomic manner, since there could be no other writer, either in th= e > guest or in the kernel. >=20 > These days emulation takes place without holding the mmu spinlock, so t= he > write could be preempted by an unshadowing event, which exposes the pag= e > to writes by the guest. This may cause corruption of guest page tables= =2E >=20 > Fix by using an atomic cmpxchg for these operations. >=20 > Signed-off-by: Avi Kivity > --- > arch/x86/kvm/x86.c | 69 ++++++++++++++++++++++++++++++++++++--------= -------- > 1 files changed, 48 insertions(+), 21 deletions(-) >=20 > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 9d02cc7..d724a52 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -3299,41 +3299,68 @@ int emulator_write_emulated(unsigned long addr,= > } > EXPORT_SYMBOL_GPL(emulator_write_emulated); > =20 > +#define CMPXCHG_TYPE(t, ptr, old, new) \ > + (cmpxchg((t *)(ptr), *(t *)(old), *(t *)(new)) =3D=3D *(t *)(old)) > + > +#ifdef CONFIG_X86_64 > +# define CMPXCHG64(ptr, old, new) CMPXCHG_TYPE(u64, ptr, old, new) > +#else > +# define CMPXCHG64(ptr, old, new) \ > + (cmpxchg64((u64 *)(ptr), *(u64 *)(old), *(u *)(new)) =3D=3D *(u64 *)(= old)) ^^^^^^ This should cause the 32-bit build breakage I see with the current next branch. Jan --------------enigF621C4897B82BA04A335DEAB 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 iEYEARECAAYFAkugiLAACgkQitSsb3rl5xR9EgCdEbJxG/3mQrnM8h7MofV3H5E6 7I8AoKZCkHjesuYDX/iV8SMbCJfzAakJ =pih8 -----END PGP SIGNATURE----- --------------enigF621C4897B82BA04A335DEAB--