From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Kiszka Subject: Re: [PATCH v3] KVM: nVMX: Improve I/O exit handling Date: Mon, 18 Feb 2013 07:32:53 +0100 Message-ID: <5121CB15.10206@web.de> References: <51180635.3060003@web.de> <20130211100721.GA11107@fermat.math.technion.ac.il> <5118C4F9.707@web.de> <5118D3B5.5010406@siemens.com> <20130214093257.GK9817@redhat.com> <511D30FF.10108@siemens.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="----enig2MFVRGVALPJJUGJMSBMWT" Cc: Nadav Har'El , kvm , Orit Wasserman To: Gleb Natapov , Marcelo Tosatti Return-path: Received: from mout.web.de ([212.227.15.3]:65374 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932084Ab3BRGdD (ORCPT ); Mon, 18 Feb 2013 01:33:03 -0500 In-Reply-To: <511D30FF.10108@siemens.com> Sender: kvm-owner@vger.kernel.org List-ID: This is an OpenPGP/MIME signed message (RFC 4880 and 3156) ------enig2MFVRGVALPJJUGJMSBMWT Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 2013-02-14 19:46, Jan Kiszka wrote: > This prevents trapping L2 I/O exits if L1 has neither unconditional nor= > bitmap-based exiting enabled. Furthermore, it implements basic I/O > bitmap handling. Repeated string accesses are still reported to L1 > unconditionally for now. >=20 > Signed-off-by: Jan Kiszka > --- >=20 > Changes in v3: > - trap unconditionally if bitmap access fails >=20 > arch/x86/kvm/vmx.c | 55 ++++++++++++++++++++++++++++++++++++++++++++= ++++++- > 1 files changed, 53 insertions(+), 2 deletions(-) >=20 > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > index 6667042..2633199 100644 > --- a/arch/x86/kvm/vmx.c > +++ b/arch/x86/kvm/vmx.c > @@ -5908,6 +5908,58 @@ static int (*const kvm_vmx_exit_handlers[])(stru= ct kvm_vcpu *vcpu) =3D { > static const int kvm_vmx_max_exit_handlers =3D > ARRAY_SIZE(kvm_vmx_exit_handlers); > =20 > +static bool nested_vmx_exit_handled_io(struct kvm_vcpu *vcpu, > + struct vmcs12 *vmcs12) > +{ > + unsigned long exit_qualification; > + gpa_t bitmap, last_bitmap; > + bool string, rep; > + u16 port; > + int size; > + u8 b; > + > + if (nested_cpu_has(vmcs12, CPU_BASED_UNCOND_IO_EXITING)) > + return 1; > + > + if (!nested_cpu_has(vmcs12, CPU_BASED_USE_IO_BITMAPS)) > + return 0; > + > + exit_qualification =3D vmcs_readl(EXIT_QUALIFICATION); > + > + string =3D exit_qualification & 16; > + rep =3D exit_qualification & 32; > + > + /* TODO: interpret instruction and check range against bitmap */ > + if (string && rep) > + return 1; Nonsense, rep ins/outs always works against the same port. We can simply drop this check and be done with the feature. I'll come up with v4. Jan > + > + port =3D exit_qualification >> 16; > + size =3D (exit_qualification & 7) + 1; > + > + last_bitmap =3D (gpa_t)-1; > + b =3D -1; > + > + while (size > 0) { > + if (port < 0x8000) > + bitmap =3D vmcs12->io_bitmap_a; > + else > + bitmap =3D vmcs12->io_bitmap_b; > + bitmap +=3D (port & 0x7fff) / 8; > + > + if (last_bitmap !=3D bitmap) > + if (kvm_read_guest(vcpu->kvm, bitmap, &b, 1)) > + return 1; > + if (b & (1 << (port & 7))) > + return 1; > + > + port++; > + size--; > + last_bitmap =3D bitmap; > + } > + > + return 0; > +} > + > /* > * Return 1 if we should exit from L2 to L1 to handle an MSR access ac= cess, > * rather than handle it ourselves in L0. I.e., check whether L1 expre= ssed > @@ -6097,8 +6149,7 @@ static bool nested_vmx_exit_handled(struct kvm_vc= pu *vcpu) > case EXIT_REASON_DR_ACCESS: > return nested_cpu_has(vmcs12, CPU_BASED_MOV_DR_EXITING); > case EXIT_REASON_IO_INSTRUCTION: > - /* TODO: support IO bitmaps */ > - return 1; > + return nested_vmx_exit_handled_io(vcpu, vmcs12); > case EXIT_REASON_MSR_READ: > case EXIT_REASON_MSR_WRITE: > return nested_vmx_exit_handled_msr(vcpu, vmcs12, exit_reason); >=20 ------enig2MFVRGVALPJJUGJMSBMWT 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.16 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iEYEARECAAYFAlEhyxkACgkQitSsb3rl5xR3EwCgmvjtkLssWbY0Y11TkttqgO3f piUAn0XI97zDNFQ8/IWmSbOHctsU08Hy =OkRj -----END PGP SIGNATURE----- ------enig2MFVRGVALPJJUGJMSBMWT--