nVMX: Test for EP4TA pointing at MMIO
Sean Christopherson
reviewercover nVMX: Test for EP4TA pointing at MMIO
Finally posting the testcase for the fix to back !visible roots with a dummy root[*]. The testcase is very simple: point EP4TA at MMIO (TPM base), do VM-Enter, and expect the VM to not die.
[*] https://lore.kernel.org/all/[email protected]
Sean Christopherson (3):
nVMX: Use helpers to check for WB memtype and 4-level EPT support
nVMX: Use setup_dummy_ept() to configure EPT for test_ept_eptp() test
nVMX: Add a testcase for running L2 with EP4TA that points at MMIO
x86/vmx_tests.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-)
base-commit: d4fba74a42d222d2cfdde65351fac3531a1d6f5c
Signature · 1 line
2.42.0.283.g2d96d420d3-goog
Sean Christopherson
reviewerPATCH 1/3 nVMX: Use helpers to check for WB memtype and 4-level EPT support
Use is_ept_memtype_supported() and is_4_level_ept_supported() to check for basic EPT support instead of open coding checks on ept_vpid.val.
Opportunstically add a report() failure if 4-level EPT isn't supported, as support for 4-level paging is mandatory in any sane configuration.
--- x86/vmx_tests.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
x86/vmx_tests.c +5 -2
@@ -1039,11 +1039,14 @@ static int __setup_ept(u64 hpa, bool enable_ad)printf ("\tEPT is not supported\n" );return 1 ; } -if (!(ept_vpid.val &EPT_CAP_WB )) { +if (!is_ept_memtype_supported (EPT_MEM_TYPE_WB )) {printf ("\tWB memtype for EPT walks not supported\n" );return 1 ; } -if (!(ept_vpid.val &EPT_CAP_PWL4 )) { + +if (!is_4_level_ept_supported ()) { +/* Support for 4-level EPT is mandatory. */ +report (false,"4-level EPT support check" );printf ("\tPWL4 is not supported\n" );return 1 ; }
Signature · 1 line
2.42.0.283.g2d96d420d3-goog
Sean Christopherson
reviewerPATCH 2/3 nVMX: Use setup_dummy_ept() to configure EPT for test_ept_eptp() test
In reply to Sean ChristophersonUse setup_dummy_ept() instead of open coding a rough equivalent in test_ept_eptp().
--- x86/vmx_tests.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-)
x86/vmx_tests.c +6 -17
@@ -4658,28 +4658,17 @@ static void test_ept_eptp(void)u32 primary_saved =vmcs_read (CPU_EXEC_CTRL0 );u32 secondary_saved =vmcs_read (CPU_EXEC_CTRL1 );u64 eptp_saved =vmcs_read (EPTP ); -u32 primary = primary_saved; -u32 secondary = secondary_saved; -u64 eptp = eptp_saved; +u32 secondary; +u64 eptp;u32 i, maxphysaddr;u64 j, resv_bits_mask =0 ; -if (!((ctrl_cpu_rev[0 ].clr &CPU_SECONDARY ) && - (ctrl_cpu_rev[1 ].clr &CPU_EPT ))) { -report_skip ("%s : \"CPU secondary\" and/or \"enable EPT\" exec control not supported" , __func__); -return ; - } - -/* Support for 4-level EPT is mandatory. */ report (is_4_level_ept_supported (),"4-level EPT support check" ); - primary |=CPU_SECONDARY ; -vmcs_write (CPU_EXEC_CTRL0 , primary); - secondary |=CPU_EPT ; -vmcs_write (CPU_EXEC_CTRL1 , secondary); - eptp = (eptp & ~EPTP_PG_WALK_LEN_MASK ) | - (3ul <<EPTP_PG_WALK_LEN_SHIFT ); -vmcs_write (EPTP , eptp); +setup_dummy_ept (); + + secondary =vmcs_read (CPU_EXEC_CTRL1 ); + eptp =vmcs_read (EPTP );for (i =0 ; i <8 ; i++) { eptp = (eptp & ~EPT_MEM_TYPE_MASK ) | i;
Signature · 1 line
2.42.0.283.g2d96d420d3-goog
Sean Christopherson
reviewerPATCH 3/3 nVMX: Add a testcase for running L2 with EP4TA that points at MMIO
In reply to Sean ChristophersonAdd a testcase in test_ept_eptp() to verify that KVM doesn't inject a triple fault (or any other unexpected "error") if L1 runs L2 with an EP4TA that points at MMIO memory. For a very, very long time, KVM synthesized a triple fault in response to a "legal-but-garbage" EP4TA _before_ completing emulation of nested VM-Enter, which is architectural wrong and triggered various warnings in KVM.
Use the TPM base address for the MMIO backing, as KVM doesn't emulate a TPM (in-kernel) and practically the address is guaranteed to be MMIO.
Drop the manual test for 4-level EPT support, as __setup_ept() performs said check/test.
--- x86/vmx_tests.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
x86/vmx_tests.c +6 -1
@@ -4663,7 +4663,12 @@ static void test_ept_eptp(void)u32 i, maxphysaddr;u64 j, resv_bits_mask =0 ; -report (is_4_level_ept_supported (),"4-level EPT support check" ); +if (__setup_ept (0xfed40000 , false)) { +report_skip ("%s : EPT not supported" , __func__); +return ; + } + +test_vmx_valid_controls ();setup_dummy_ept ();
Signature · 1 line
2.42.0.283.g2d96d420d3-goog
Quoted 4 lines · Sean Christopherson
Finally posting the testcase for the fix to back !visible roots with a dummy root[*]. The testcase is very simple: point EP4TA at MMIO (TPM base), do VM-Enter, and expect the VM to not die.
Quoted 8 lines
[*] https://lore.kernel.org/all/[email protected]
Sean Christopherson (3):
nVMX: Use helpers to check for WB memtype and 4-level EPT support
nVMX: Usesetup_dummy_ept()to configure EPT fortest_ept_eptp()test
nVMX: Add a testcase for running L2 with EP4TA that points at MMIO[...]
Applied to kvm-x86 next, thanks!
[1/3] nVMX: Use helpers to check for WB memtype and 4-level EPT support
https://github.com/kvm-x86/kvm-unit-tests/commit/ee7c8d4e630a [2/3] nVMX: Use setup_dummy_ept() to configure EPT for test_ept_eptp() test https://github.com/kvm-x86/kvm-unit-tests/commit/5676a8651066 [3/3] nVMX: Add a testcase for running L2 with EP4TA that points at MMIO https://github.com/kvm-x86/kvm-unit-tests/commit/e87078ea65b0