From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Kiszka Subject: Re: [PATCH 1/4] kvm-unit-tests: VMX: Add test cases for PAT and EFER Date: Thu, 15 Aug 2013 10:09:15 +0200 Message-ID: <520C8CAB.4050301@web.de> References: <1376409368-7016-1-git-send-email-yzt356@gmail.com> <1376409368-7016-2-git-send-email-yzt356@gmail.com> <520C8088.6070607@web.de> <520C87E8.3050107@web.de> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="LwGwIl4FlUPGCR1tnR59gN6CVTB6SA3E7" Cc: kvm , Gleb Natapov , Paolo Bonzini To: Arthur Chunqi Li Return-path: Received: from mout.web.de ([212.227.15.3]:52390 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753673Ab3HOIJR (ORCPT ); Thu, 15 Aug 2013 04:09:17 -0400 Received: from mchn199C.mchp.siemens.de ([95.157.58.223]) by smtp.web.de (mrweb103) with ESMTPSA (Nemesis) id 0M3T5g-1W0bjH3RA0-00qy19 for ; Thu, 15 Aug 2013 10:09:16 +0200 In-Reply-To: Sender: kvm-owner@vger.kernel.org List-ID: This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --LwGwIl4FlUPGCR1tnR59gN6CVTB6SA3E7 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 2013-08-15 10:05, Arthur Chunqi Li wrote: > On Thu, Aug 15, 2013 at 3:48 PM, Jan Kiszka wrote: >> On 2013-08-15 09:41, Arthur Chunqi Li wrote: >>> On Thu, Aug 15, 2013 at 3:17 PM, Jan Kiszka wrote= : >>>> On 2013-08-13 17:56, Arthur Chunqi Li wrote: >>>>> Add test cases for ENT_LOAD_PAT, ENT_LOAD_EFER, EXI_LOAD_PAT, >>>>> EXI_SAVE_PAT, EXI_LOAD_EFER, EXI_SAVE_PAT flags in enter/exit >>>>> control fields. >>>>> >>>>> Signed-off-by: Arthur Chunqi Li >>>>> --- >>>>> x86/vmx.h | 7 +++ >>>>> x86/vmx_tests.c | 185 +++++++++++++++++++++++++++++++++++++++++++= ++++++++++++ >>>>> 2 files changed, 192 insertions(+) >>>>> >>>>> diff --git a/x86/vmx.h b/x86/vmx.h >>>>> index 28595d8..18961f1 100644 >>>>> --- a/x86/vmx.h >>>>> +++ b/x86/vmx.h >>>>> @@ -152,10 +152,12 @@ enum Encoding { >>>>> GUEST_DEBUGCTL =3D 0x2802ul, >>>>> GUEST_DEBUGCTL_HI =3D 0x2803ul, >>>>> GUEST_EFER =3D 0x2806ul, >>>>> + GUEST_PAT =3D 0x2804ul, >>>>> GUEST_PERF_GLOBAL_CTRL =3D 0x2808ul, >>>>> GUEST_PDPTE =3D 0x280aul, >>>>> >>>>> /* 64-Bit Host State */ >>>>> + HOST_PAT =3D 0x2c00ul, >>>>> HOST_EFER =3D 0x2c02ul, >>>>> HOST_PERF_GLOBAL_CTRL =3D 0x2c04ul, >>>>> >>>>> @@ -330,11 +332,15 @@ enum Ctrl_exi { >>>>> EXI_HOST_64 =3D 1UL << 9, >>>>> EXI_LOAD_PERF =3D 1UL << 12, >>>>> EXI_INTA =3D 1UL << 15, >>>>> + EXI_SAVE_PAT =3D 1UL << 18, >>>>> + EXI_LOAD_PAT =3D 1UL << 19, >>>>> + EXI_SAVE_EFER =3D 1UL << 20, >>>>> EXI_LOAD_EFER =3D 1UL << 21, >>>>> }; >>>>> >>>>> enum Ctrl_ent { >>>>> ENT_GUEST_64 =3D 1UL << 9, >>>>> + ENT_LOAD_PAT =3D 1UL << 14, >>>>> ENT_LOAD_EFER =3D 1UL << 15, >>>>> }; >>>>> >>>>> @@ -354,6 +360,7 @@ enum Ctrl0 { >>>>> CPU_NMI_WINDOW =3D 1ul << 22, >>>>> CPU_IO =3D 1ul << 24, >>>>> CPU_IO_BITMAP =3D 1ul << 25, >>>>> + CPU_MSR_BITMAP =3D 1ul << 28, >>>>> CPU_SECONDARY =3D 1ul << 31, >>>>> }; >>>>> >>>>> diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c >>>>> index c1b39f4..61b0cef 100644 >>>>> --- a/x86/vmx_tests.c >>>>> +++ b/x86/vmx_tests.c >>>>> @@ -1,4 +1,15 @@ >>>>> #include "vmx.h" >>>>> +#include "msr.h" >>>>> +#include "processor.h" >>>>> +#include "vm.h" >>>>> + >>>>> +u64 ia32_pat; >>>>> +u64 ia32_efer; >>>>> + >>>>> +static inline void vmcall() >>>>> +{ >>>>> + asm volatile("vmcall"); >>>>> +} >>>>> >>>>> void basic_init() >>>>> { >>>>> @@ -76,6 +87,176 @@ int vmenter_exit_handler() >>>>> return VMX_TEST_VMEXIT; >>>>> } >>>>> >>>>> +void msr_bmp_init() >>>>> +{ >>>>> + void *msr_bitmap; >>>>> + u32 ctrl_cpu0; >>>>> + >>>>> + msr_bitmap =3D alloc_page(); >>>>> + memset(msr_bitmap, 0x0, PAGE_SIZE); >>>>> + ctrl_cpu0 =3D vmcs_read(CPU_EXEC_CTRL0); >>>>> + ctrl_cpu0 |=3D CPU_MSR_BITMAP; >>>>> + vmcs_write(CPU_EXEC_CTRL0, ctrl_cpu0); >>>>> + vmcs_write(MSR_BITMAP, (u64)msr_bitmap); >>>>> +} >>>> >>>> Better safe this function for the test case where you actually stres= s >>>> the bitmap. >>> What do you mean by "safe"? >> >> I meant the other "save": This function serves no purpose here. Let's >> only introduce it when that changes, i.e. when you actually test the M= SR >> bitmap. > No, the function is meaningful here. We need directly access to MSRs > in guest and if msr bitmap is not set, any access to MSRs will cause > vmexit. Here we just let all rdmsr/wrmsr pass in guest. Ah, sorry. Forgot that the default is "trap", not "pass". Jan --LwGwIl4FlUPGCR1tnR59gN6CVTB6SA3E7 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/ iEYEARECAAYFAlIMjKsACgkQitSsb3rl5xRS1gCgrA1ju/80wuG/sOP1VmFRx/FE D0wAn2hPzBBUKdo/PcHYtcRzYXkMNkci =CJXW -----END PGP SIGNATURE----- --LwGwIl4FlUPGCR1tnR59gN6CVTB6SA3E7--