Bits 62:59 are ignored if memory protection keys are disabled via the PKE CR4 bit. Verify that accesses are allowed when these bits are set while memory protection keys are disabled. Bits 52:58 are available so test that those are ignored as well. Signed-off-by: Kevin Cheng --- x86/svm_npt.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/x86/svm_npt.c b/x86/svm_npt.c index 5d70fd69a0c35..ab744d41824f8 100644 --- a/x86/svm_npt.c +++ b/x86/svm_npt.c @@ -372,6 +372,35 @@ static void npt_rwx_test(void) npt_access_test_cleanup(); } +static void npt_ignored_bit(int bit) +{ + /* Set the bit. */ + npt_access_allowed(0, 1ul << bit, OP_READ); + npt_access_allowed(0, 1ul << bit, OP_WRITE); + npt_access_allowed(0, 1ul << bit, OP_EXEC); + + /* Clear the bit. */ + npt_access_allowed(1ul << bit, 0, OP_READ); + npt_access_allowed(1ul << bit, 0, OP_WRITE); + npt_access_allowed(1ul << bit, 0, OP_EXEC); +} + +static void npt_ignored_bits_test(void) +{ + ulong saved_cr4 = read_cr4(); + + /* Setup must be called first because it saves the original cr4 state */ + npt_access_test_setup(); + + write_cr4(saved_cr4 & ~X86_CR4_PKE); + + for (int i = 52; i <= 62; i++) + npt_ignored_bit(i); + + write_cr4(saved_cr4); + npt_access_test_cleanup(); +} + static void npt_rw_pfwalk_prepare(struct svm_test *test) { @@ -831,6 +860,7 @@ static struct svm_test npt_tests[] = { NPT_V2_TEST(npt_ro_test), NPT_V2_TEST(npt_rw_test), NPT_V2_TEST(npt_rwx_test), + NPT_V2_TEST(npt_ignored_bits_test), { NULL, NULL, NULL, NULL, NULL, NULL, NULL } }; -- 2.52.0.322.g1dd061c0dc-goog