From: Nadav Amit Subject: Re: [PATCH v2] kvm: x86: emulate monitor and mwait instructions as nop Date: Wed, 4 Jun 2014 22:12:39 +0300 Message-ID: <9767B286-A7EB-4BED-B500-589E62D0433E@gmail.com> References: <20140507205210.GA30030@ERROL.INI.CMU.EDU> <20140602192530.GC1653@ERROL.INI.CMU.EDU> <538D92BC.4060203@redhat.com> <20140604143941.GF1653@ERROL.INI.CMU.EDU> <538F30BD.5000501@suse.de> <538F4A7C.7070202@redhat.com> Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.2\)) Content-Type: multipart/signed; boundary="Apple-Mail=_7324C0A4-7374-4C92-9307-7C6D2FED47E0"; protocol="application/pgp-signature"; micalg=pgp-sha512 Cc: Alexander Graf , "Gabriel L. Somlo" , kvm@vger.kernel.org, mst@redhat.com, Borislav Petkov To: Paolo Bonzini Return-path: Received: from mail-we0-f169.google.com ([74.125.82.169]:34832 "EHLO mail-we0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750780AbaFDTMr (ORCPT ); Wed, 4 Jun 2014 15:12:47 -0400 Received: by mail-we0-f169.google.com with SMTP id u56so9153848wes.28 for ; Wed, 04 Jun 2014 12:12:46 -0700 (PDT) In-Reply-To: <538F4A7C.7070202@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: --Apple-Mail=_7324C0A4-7374-4C92-9307-7C6D2FED47E0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=windows-1252 On Jun 4, 2014, at 7:34 PM, Paolo Bonzini wrote: > Il 04/06/2014 16:44, Alexander Graf ha scritto: >>=20 >>=20 >>> Obviously, if you really like the current behavior better you can >>> always reject whatever patch I'll come up with, but I'd like to at >>> least try and see what it would look like :) >>=20 >> I think it's perfectly fine to leave mwait always implemented as NOP = - >> it's valid behavior. >>=20 >> As for the CPUID exposure, that should be a pure QEMU thing. If >> overriding CPUID bits the kernel mask tells us doesn't work today, we >> should just make it possible :). >=20 > That should be the purpose of KVM_GET_EMULATED_CPUID, so MWAIT could = be added in __do_cpuid_ent_emulated. However, the corresponding QEMU = patches were never included. Borislav, can you refresh them? Regardless to the whole discussion of what the guest is informed about, = I think it might be better to implement mwait and monitor correctly = according to the spec and let the instructions to be fully emulated. Both mwait and monitor may encounter exceptions (#GP, #PF, regardless of = #UD), so this behaviour should be correct. If you want me, I=92ll send my version which looks something like: static int em_monitor(struct x86_emulate_ctxt *ctxt) { int rc; struct segmented_address addr; u64 rcx =3D reg_read(ctxt, VCPU_REGS_RCX); u64 rax =3D reg_read(ctxt, VCPU_REGS_RAX); u8 byte; rc =3D check_mwait_supported(ctxt); if (rc !=3D X86EMUL_CONTINUE) return rc; if (ctxt->mode !=3D X86EMUL_MODE_PROT64) rcx =3D (u32)rcx; if (rcx !=3D 0) return emulate_gp(ctxt, 0); addr.seg =3D seg_override(ctxt); addr.ea =3D ctxt->ad_bytes =3D=3D 8 ? rax : (u32)rax; rc =3D segmented_read(ctxt, addr, &byte, 1); if (rc !=3D X86EMUL_CONTINUE) return rc; return X86EMUL_CONTINUE; } static int em_mwait(struct x86_emulate_ctxt *ctxt) { u64 rcx =3D reg_read(ctxt, VCPU_REGS_RCX); int rc =3D check_mwait_supported(ctxt); if (rc !=3D X86EMUL_CONTINUE) return rc; if (ctxt->mode !=3D X86EMUL_MODE_PROT64) rcx =3D (u32)rcx; if ((rcx & ~(u64)1) !=3D 0) return emulate_gp(ctxt, 0); if (rcx & 1) { /* Interrupt as break event */ u32 ebx, ecx, edx, eax; eax =3D 5; ecx =3D 0; ctxt->ops->get_cpuid(ctxt, &eax, &ebx, &ecx, &edx); if (!(ecx & 1)) return emulate_gp(ctxt, 0); } return X86EMUL_CONTINUE; } --Apple-Mail=_7324C0A4-7374-4C92-9307-7C6D2FED47E0 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP using GPGMail -----BEGIN PGP SIGNATURE----- Comment: GPGTools - http://gpgtools.org iQEcBAEBCgAGBQJTj2+nAAoJEHlOP0Zr1lTYz4IH/i1/K4h+ZF+W9bEEpYDgUQ+m oSYoHU+IVA/7/+8XVNzm+16LL6m9rkz/wB6egEEzs5O2xhaH7wXh2vkmOdgKnOzy 4l3e+6GJm/IB4G7aYtB9DJfF/lUs4TbLtUxPAfSwjHZx/6YbljKSzsVeW41GwShP U0zUuTmOua59ntP7BuGteqCPwSSV5s1euzBdKv6tjB7t/U0HJQEPAA577CwmBjc9 rgu41FOHxzfCXKGSJemCpqdtFh6jm5zPWKsYjENmtjCK5T2mlQFbiN6vBfNP2QIN pApgXkCkFyliUkjzbGplScvYJ7s6iGKLu2ncQSr15l2QTqBn8+sFmlZ6EhRfCIw= =7qQJ -----END PGP SIGNATURE----- --Apple-Mail=_7324C0A4-7374-4C92-9307-7C6D2FED47E0--