From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Kiszka Subject: Re: [PATCH v5] KVM: nVMX: Improve I/O exit handling Date: Mon, 18 Feb 2013 11:02:38 +0100 Message-ID: <5121FC3E.80108@web.de> References: <20130211100721.GA11107@fermat.math.technion.ac.il> <5118C4F9.707@web.de> <5118D3B5.5010406@siemens.com> <20130214093257.GK9817@redhat.com> <511D30FF.10108@siemens.com> <5121CB15.10206@web.de> <20130218084446.GX9817@redhat.com> <5121EC02.30704@web.de> <20130218085701.GA13680@redhat.com> <5121F19A.5030506@web.de> <20130218093656.GZ9817@redhat.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="----enig2TQAOVQXMIKOBVVBMSMKO" Cc: Marcelo Tosatti , Nadav Har'El , kvm , Orit Wasserman To: Gleb Natapov Return-path: Received: from mout.web.de ([212.227.17.11]:49398 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755908Ab3BRKCx (ORCPT ); Mon, 18 Feb 2013 05:02:53 -0500 In-Reply-To: <20130218093656.GZ9817@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: This is an OpenPGP/MIME signed message (RFC 4880 and 3156) ------enig2TQAOVQXMIKOBVVBMSMKO Content-Type: text/plain; charset=windows-1255 Content-Transfer-Encoding: quoted-printable On 2013-02-18 10:36, Gleb Natapov wrote: > On Mon, Feb 18, 2013 at 10:17:14AM +0100, Jan Kiszka wrote: >> From: Jan Kiszka >> >> This prevents trapping L2 I/O exits if L1 has neither unconditional no= r >> bitmap-based exiting enabled. Furthermore, it implements I/O bitmap >> handling. We still exit unconditionally in case the CPU does not provi= de >> information for ins/outs. >> >> Signed-off-by: Jan Kiszka >> --- >> >> Changes in v5: >> - still exit unconditionally if CPU refuses to provide exit >> information on ins/outs >> >> arch/x86/kvm/vmx.c | 58 +++++++++++++++++++++++++++++++++++++++++++= +++++++- >> 1 files changed, 56 insertions(+), 2 deletions(-) >> >> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c >> index 6667042..ccc7c17 100644 >> --- a/arch/x86/kvm/vmx.c >> +++ b/arch/x86/kvm/vmx.c >> @@ -651,6 +651,7 @@ static struct vmcs_config { >> int size; >> int order; >> u32 revision_id; >> + u32 vmx_basic_high; >> u32 pin_based_exec_ctrl; >> u32 cpu_based_exec_ctrl; >> u32 cpu_based_2nd_exec_ctrl; >> @@ -752,6 +753,11 @@ static inline bool vm_need_tpr_shadow(struct kvm = *kvm) >> return (cpu_has_vmx_tpr_shadow()) && (irqchip_in_kernel(kvm)); >> } >> =20 >> +static inline bool cpu_has_stringio_exit_info(void) >> +{ >> + return vmcs_config.vmx_basic_high & (VMX_BASIC_INOUT >> 32); >> +} >> + >> static inline bool cpu_has_secondary_exec_ctrls(void) >> { >> return vmcs_config.cpu_based_exec_ctrl & >> @@ -2635,6 +2641,7 @@ static __init int setup_vmcs_config(struct vmcs_= config *vmcs_conf) >> vmcs_conf->size =3D vmx_msr_high & 0x1fff; >> vmcs_conf->order =3D get_order(vmcs_config.size); >> vmcs_conf->revision_id =3D vmx_msr_low; >> + vmcs_conf->vmx_basic_high =3D vmx_msr_high; >> =20 >> vmcs_conf->pin_based_exec_ctrl =3D _pin_based_exec_control; >> vmcs_conf->cpu_based_exec_ctrl =3D _cpu_based_exec_control; >> @@ -5908,6 +5915,54 @@ static int (*const kvm_vmx_exit_handlers[])(str= uct 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; >> + 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; >> + >> + /* TODO: for older CPUs, derive access width from instruction */ >> + if (!cpu_has_stringio_exit_info()) >> + return 1; >> + >=20 > Sigh, actually I am stupid :( The information that is not available > on older cpus is address size in "VM-exit instruction information", > not operand size on exit qualification, so your v4 is correct. Except > handling of port wrap around: >=20 > If the =93use I/O bitmaps=94 VM-execution control is 1, the instructi= on > causes a VM exit if it attempts to access an I/O port corresponding t= o a > bit set to 1 in the appropriate I/O bitmap (see Section 24.6.4). If a= n > I/O operation =93wraps around=94 the 16-bit I/O-port space (accesses > ports FFFFH and 0000H), the I/O instruction causes a VM exit (the > =93unconditional I/O exiting=94 VM-execution control is ignored if th= e > =93use I/O bitmaps=94 VM-execution control is 1). Ah, indeed. OK, let's see if this "simple" patch manages to reach two-digit revision numbers... Jan ------enig2TQAOVQXMIKOBVVBMSMKO 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/ iEYEARECAAYFAlEh/EEACgkQitSsb3rl5xTlAQCgt0egqEK5KUW6W8YyEwcxazWX OngAnRUXOEogln5384bFBDwfAYhe92Wo =5oGP -----END PGP SIGNATURE----- ------enig2TQAOVQXMIKOBVVBMSMKO--