[PATCH 4/5 v4] nSVM: Test addresses of MSR and IO permissions maps

Krish Sadhukhan
2021-03-24T18:39:34Z

According to section "Canonicalization and Consistency Checks" in APM vol 2,
the following guest state is illegal:

"The MSR or IOIO intercept tables extend to a physical address that
is greater than or equal to the maximum supported physical address."

Signed-off-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>
---
x86/svm_tests.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)

diff --git a/x86/svm_tests.c b/x86/svm_tests.c
index 29a0b59..70442d2 100644
--- a/x86/svm_tests.c
+++ b/x86/svm_tests.c
@@ -2304,6 +2304,33 @@ static void test_dr(void)
vmcb->save.dr7 = dr_saved;
}

+/*
+ * If the MSR or IOIO intercept table extends to a physical address that
+ * is greater than or equal to the maximum supported physical address, the
+ * guest state is illegal.
+ *
+ * [ APM vol 2]
+ */
+static void test_msrpm_iopm_bitmap_addrs(void)
+{
+ u64 addr_spill_beyond_ram =
+ (u64)(((u64)1 << cpuid_maxphyaddr()) - 4096);
+
+ /* MSR bitmap address */
+ vmcb->control.intercept |= 1ULL << INTERCEPT_MSR_PROT;
+ vmcb->control.msrpm_base_pa = addr_spill_beyond_ram;
+ report(svm_vmrun() == SVM_EXIT_ERR, "Test MSRPM address: %lx",
+ addr_spill_beyond_ram);
+ vmcb->control.intercept &= ~(1ULL << INTERCEPT_MSR_PROT);
+
+ /* MSR bitmap address */
+ vmcb->control.intercept |= 1ULL << INTERCEPT_IOIO_PROT;
+ vmcb->control.msrpm_base_pa = addr_spill_beyond_ram;
+ report(svm_vmrun() == SVM_EXIT_ERR, "Test IOPM address: %lx",
+ addr_spill_beyond_ram);
+ vmcb->control.intercept &= ~(1ULL << INTERCEPT_IOIO_PROT);
+}
+
static void svm_guest_state_test(void)
{
test_set_guest(basic_guest_main);
@@ -2313,6 +2340,7 @@ static void svm_guest_state_test(void)
test_cr3();
test_cr4();
test_dr();
+ test_msrpm_iopm_bitmap_addrs();
}

--
2.27.0