x86: vmx: Mask undefined bits in exit qualifications
PATCH 1/1 x86: vmx: Mask undefined bits in exit qualifications
From: Nadav Amit <[email protected]>
On EPT violation, the exit qualifications may have some undefined bits.
Bit 6 is undefined if "mode-based execute control" is 0.
Bits 9-11 are undefined unless the processor supports advanced VM-exit information for EPT violations.
Right now on KVM these bits are always undefined inside the VM (i.e., in an emulated VM-exit). Mask these bits to avoid potential false indication of failures.
--- x86/vmx.h | 20 ++++++++++++-------- x86/vmx_tests.c | 4 ++++ 2 files changed, 16 insertions(+), 8 deletions(-)
x86/vmx.h +12 -8
@@ -603,16 +603,20 @@ enum vm_instruction_error_number {#define EPT_ADDR_MASK GENMASK_ULL(51, 12)#define PAGE_MASK_2M (~(PAGE_SIZE_2M-1)) -#define EPT_VLT_RD 1 -#define EPT_VLT_WR (1 << 1) -#define EPT_VLT_FETCH (1 << 2) -#define EPT_VLT_PERM_RD (1 << 3) -#define EPT_VLT_PERM_WR (1 << 4) -#define EPT_VLT_PERM_EX (1 << 5) +#define EPT_VLT_RD (1ull << 0) +#define EPT_VLT_WR (1ull << 1) +#define EPT_VLT_FETCH (1ull << 2) +#define EPT_VLT_PERM_RD (1ull << 3) +#define EPT_VLT_PERM_WR (1ull << 4) +#define EPT_VLT_PERM_EX (1ull << 5) +#define EPT_VLT_PERM_USER_EX (1ull << 6)#define EPT_VLT_PERMS (EPT_VLT_PERM_RD | EPT_VLT_PERM_WR | \ EPT_VLT_PERM_EX) -#define EPT_VLT_LADDR_VLD (1 << 7) -#define EPT_VLT_PADDR (1 << 8) +#define EPT_VLT_LADDR_VLD (1ull << 7) +#define EPT_VLT_PADDR (1ull << 8) +#define EPT_VLT_GUEST_USER (1ull << 9) +#define EPT_VLT_GUEST_WR (1ull << 10) +#define EPT_VLT_GUEST_EX (1ull << 11)#define MAGIC_VAL_1 0x12345678ul#define MAGIC_VAL_2 0x87654321ul
x86/vmx_tests.c +4 -0
@@ -2365,6 +2365,10 @@ static void do_ept_violation(bool leaf, enum ept_access_op op, qual =vmcs_read (EXI_QUALIFICATION ); +/* Mask undefined bits (which may later be defined in certain cases). */ + qual &= ~(EPT_VLT_GUEST_USER |EPT_VLT_GUEST_WR |EPT_VLT_GUEST_EX | +EPT_VLT_PERM_USER_EX ); +diagnose_ept_violation_qual (expected_qual, qual);TEST_EXPECT_EQ (expected_qual, qual);
Signature · 1 line
2.17.1
Quoted 71 lines · On May 3, 2019, at 10:49 AM, [email protected] wrote:
From: Nadav Amit <[email protected]>
On EPT violation, the exit qualifications may have some undefined bits.
Bit 6 is undefined if "mode-based execute control" is 0.
Bits 9-11 are undefined unless the processor supports advanced VM-exit information for EPT violations.
Right now on KVM these bits are always undefined inside the VM (i.e., in an emulated VM-exit). Mask these bits to avoid potential false indication of failures.
Signed-off-by Nadav Amit <[email protected]>---
x86/vmx.h| 20 ++++++++++++--------x86/vmx_tests.c| 4 ++++2 files changed, 16 insertions(+), 8 deletions(-)x86/vmx.h +12
-8@@ -603,16 +603,20 @@ enum vm_instruction_error_number {#define EPT_ADDR_MASK GENMASK_ULL(51, 12)#define PAGE_MASK_2M (~(PAGE_SIZE_2M-1)) -#define EPT_VLT_RD 1 -#define EPT_VLT_WR (1 << 1) -#define EPT_VLT_FETCH (1 << 2) -#define EPT_VLT_PERM_RD (1 << 3) -#define EPT_VLT_PERM_WR (1 << 4) -#define EPT_VLT_PERM_EX (1 << 5) +#define EPT_VLT_RD (1ull << 0) +#define EPT_VLT_WR (1ull << 1) +#define EPT_VLT_FETCH (1ull << 2) +#define EPT_VLT_PERM_RD (1ull << 3) +#define EPT_VLT_PERM_WR (1ull << 4) +#define EPT_VLT_PERM_EX (1ull << 5) +#define EPT_VLT_PERM_USER_EX (1ull << 6)#define EPT_VLT_PERMS (EPT_VLT_PERM_RD | EPT_VLT_PERM_WR | \ EPT_VLT_PERM_EX) -#define EPT_VLT_LADDR_VLD (1 << 7) -#define EPT_VLT_PADDR (1 << 8) +#define EPT_VLT_LADDR_VLD (1ull << 7) +#define EPT_VLT_PADDR (1ull << 8) +#define EPT_VLT_GUEST_USER (1ull << 9) +#define EPT_VLT_GUEST_WR (1ull << 10) +#define EPT_VLT_GUEST_EX (1ull << 11)#define MAGIC_VAL_1 0x12345678ul#define MAGIC_VAL_2 0x87654321ulx86/vmx_tests.c +4
-0@@ -2365,6 +2365,10 @@ static void do_ept_violation(bool leaf, enum ept_access_op op, qual =vmcs_read (EXI_QUALIFICATION ); +/* Mask undefined bits (which may later be defined in certain cases). */ + qual &= ~(EPT_VLT_GUEST_USER |EPT_VLT_GUEST_WR |EPT_VLT_GUEST_EX | +EPT_VLT_PERM_USER_EX ); +diagnose_ept_violation_qual (expected_qual, qual);TEST_EXPECT_EQ (expected_qual, qual);Signature · 1 line
2.17.1
Ping.
Quoted 42 lines · Nadav Amit
Quoted 42 lines · On May 3, 2019, at 10:49 AM, [email protected] wrote:
From: Nadav Amit <[email protected]>
On EPT violation, the exit qualifications may have some undefined bits.
Bit 6 is undefined if "mode-based execute control" is 0.
Bits 9-11 are undefined unless the processor supports advanced VM-exit information for EPT violations.
Right now on KVM these bits are always undefined inside the VM (i.e., in an emulated VM-exit). Mask these bits to avoid potential false indication of failures.
Signed-off-by Nadav Amit <[email protected]>---
x86/vmx.h| 20 ++++++++++++--------x86/vmx_tests.c| 4 ++++2 files changed, 16 insertions(+), 8 deletions(-)x86/vmx.h +7
-6@@ -603,16 +603,20 @@ enum vm_instruction_error_number {#define EPT_ADDR_MASK GENMASK_ULL(51, 12)#define PAGE_MASK_2M (~(PAGE_SIZE_2M-1)) -#define EPT_VLT_RD 1 -#define EPT_VLT_WR (1 << 1) -#define EPT_VLT_FETCH (1 << 2) -#define EPT_VLT_PERM_RD (1 << 3) -#define EPT_VLT_PERM_WR (1 << 4) -#define EPT_VLT_PERM_EX (1 << 5) +#define EPT_VLT_RD (1ull << 0) +#define EPT_VLT_WR (1ull << 1) +#define EPT_VLT_FETCH (1ull << 2) +#define EPT_VLT_PERM_RD (1ull << 3) +#define EPT_VLT_PERM_WR (1ull << 4) +#define EPT_VLT_PERM_EX (1ull << 5) +#define EPT_VLT_PERM_USER_EX (1ull << 6)
Quoted 8 lines
x86/vmx.h enum vm_instruction_error_number { · line 618
Quoted 8 lines
x86/vmx.h +4
-2#define EPT_VLT_PERMS (EPT_VLT_PERM_RD | EPT_VLT_PERM_WR | \ EPT_VLT_PERM_EX) -#define EPT_VLT_LADDR_VLD (1 << 7) -#define EPT_VLT_PADDR (1 << 8) +#define EPT_VLT_LADDR_VLD (1ull << 7) +#define EPT_VLT_PADDR (1ull << 8) +#define EPT_VLT_GUEST_USER (1ull << 9) +#define EPT_VLT_GUEST_WR (1ull << 10)
This one should be named EPT_VLT_GUEST_RW, assuming you are naming them according to the 1-setting of the bits.
Quoted 10 lines
Quoted 10 lines
x86/vmx.h +1
-0+#define EPT_VLT_GUEST_EX (1ull << 11)#define MAGIC_VAL_1 0x12345678ul#define MAGIC_VAL_2 0x87654321ulx86/vmx_tests.c +0
-0@@ -2365,6 +2365,10 @@ static void do_ept_violation(bool leaf, enum ept_access_op op,
Quoted 6 lines
x86/vmx_tests.c static void do_ept_violation(bool leaf, enum ept_access_op op, · line 2371
Quoted 6 lines
x86/vmx_tests.c +4
-0qual =vmcs_read (EXI_QUALIFICATION ); +/* Mask undefined bits (which may later be defined in certain cases). */ + qual &= ~(EPT_VLT_GUEST_USER |EPT_VLT_GUEST_WR |EPT_VLT_GUEST_EX | +EPT_VLT_PERM_USER_EX ); +
The "DIAGNOSE" macro doesn't check any of these bits, so this masking seems redundant.
Also, don't we need to check for the relevant conditions before masking the bits ? For example, EPT_VLT_PERM_USER_EX is dependent on "mode-based execute control" VM-execution control" and the other ones depend on bit 7 and 8 of the Exit Qualification field.
Quoted 7 lines
Quoted 5 lines
x86/vmx_tests.c +0
-0diagnose_ept_violation_qual (expected_qual, qual);TEST_EXPECT_EQ (expected_qual, qual);Signature · 1 line
2.17.1Ping.
Quoted 50 lines · Krish Sadhukhan
Quoted 45 lines · Nadav Amit
Quoted 45 lines · On May 3, 2019, at 10:49 AM, [email protected] wrote:
From: Nadav Amit <[email protected]>
On EPT violation, the exit qualifications may have some undefined bits.
Bit 6 is undefined if "mode-based execute control" is 0.
Bits 9-11 are undefined unless the processor supports advanced VM-exit information for EPT violations.
Right now on KVM these bits are always undefined inside the VM (i.e., in an emulated VM-exit). Mask these bits to avoid potential false indication of failures.
Signed-off-by Nadav Amit <[email protected]>---
x86/vmx.h| 20 ++++++++++++--------x86/vmx_tests.c| 4 ++++2 files changed, 16 insertions(+), 8 deletions(-)x86/vmx.h +7
-7@@ -603,16 +603,20 @@ enum vm_instruction_error_number {#define EPT_ADDR_MASK GENMASK_ULL(51, 12)#define PAGE_MASK_2M (~(PAGE_SIZE_2M-1)) -#define EPT_VLT_RD 1 -#define EPT_VLT_WR (1 << 1) -#define EPT_VLT_FETCH (1 << 2) -#define EPT_VLT_PERM_RD (1 << 3) -#define EPT_VLT_PERM_WR (1 << 4) -#define EPT_VLT_PERM_EX (1 << 5) +#define EPT_VLT_RD (1ull << 0) +#define EPT_VLT_WR (1ull << 1) +#define EPT_VLT_FETCH (1ull << 2) +#define EPT_VLT_PERM_RD (1ull << 3) +#define EPT_VLT_PERM_WR (1ull << 4) +#define EPT_VLT_PERM_EX (1ull << 5) +#define EPT_VLT_PERM_USER_EX (1ull << 6)#define EPT_VLT_PERMS (EPT_VLT_PERM_RD | EPT_VLT_PERM_WR | \ EPT_VLT_PERM_EX) -#define EPT_VLT_LADDR_VLD (1 << 7)
Quoted 8 lines
Quoted 5 lines
x86/vmx.h enum vm_instruction_error_number { · line 618
Quoted 5 lines
x86/vmx.h +4
-1-#define EPT_VLT_PADDR (1 << 8) +#define EPT_VLT_LADDR_VLD (1ull << 7) +#define EPT_VLT_PADDR (1ull << 8) +#define EPT_VLT_GUEST_USER (1ull << 9) +#define EPT_VLT_GUEST_WR (1ull << 10)This one should be named
EPT_VLT_GUEST_RW, assuming you are naming them according to the 1-setting of the bits.
Whatever you wish (unless someone else has different preference).
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
x86/vmx.h +1
-0+#define EPT_VLT_GUEST_EX (1ull << 11)#define MAGIC_VAL_1 0x12345678ul#define MAGIC_VAL_2 0x87654321ulx86/vmx_tests.c +0
-0@@ -2365,6 +2365,10 @@ static void do_ept_violation(bool leaf, enum ept_access_op op, qual =vmcs_read (EXI_QUALIFICATION );
Quoted 7 lines
Quoted 4 lines
x86/vmx_tests.c static void do_ept_violation(bool leaf, enum ept_access_op op, · line 2371
Quoted 4 lines
x86/vmx_tests.c +4
-0+/* Mask undefined bits (which may later be defined in certain cases). */ + qual &= ~(EPT_VLT_GUEST_USER |EPT_VLT_GUEST_WR |EPT_VLT_GUEST_EX | +EPT_VLT_PERM_USER_EX ); +The "DIAGNOSE" macro doesn't check any of these bits, so this masking seems redundant.
The DIAGNOSE macro is not the one who causes errors. It’s the:
TEST_EXPECT_EQ(expected_qual, qual);
That comes right after the call to diagnose_ept_violation_qual().
Quoted 5 lines
Also, don't we need to check for the relevant conditions before masking the bits ? For example,
EPT_VLT_PERM_USER_EXis dependent on "mode-based execute control" VM-execution control" and the other ones depend on bit 7 and 8 of the Exit Qualification field.
The tests right now do not “emulate” these bits, so the expected qualification would never have EPT_VLT_PERM_USER_EX (for instance) set. Once someone implements tests for these bits, he would need to change the masking.
Krish Sadhukhan
Reviewed-byQuoted 77 lines · Nadav Amit
Quoted 49 lines · Krish Sadhukhan
Quoted 44 lines · Nadav Amit
Quoted 44 lines · On May 3, 2019, at 10:49 AM, [email protected] wrote:
From: Nadav Amit <[email protected]>
On EPT violation, the exit qualifications may have some undefined bits.
Bit 6 is undefined if "mode-based execute control" is 0.
Bits 9-11 are undefined unless the processor supports advanced VM-exit information for EPT violations.
Right now on KVM these bits are always undefined inside the VM (i.e., in an emulated VM-exit). Mask these bits to avoid potential false indication of failures.
Signed-off-by Nadav Amit <[email protected]>---
x86/vmx.h| 20 ++++++++++++--------x86/vmx_tests.c| 4 ++++2 files changed, 16 insertions(+), 8 deletions(-)x86/vmx.h +7
-6@@ -603,16 +603,20 @@ enum vm_instruction_error_number {#define EPT_ADDR_MASK GENMASK_ULL(51, 12)#define PAGE_MASK_2M (~(PAGE_SIZE_2M-1)) -#define EPT_VLT_RD 1 -#define EPT_VLT_WR (1 << 1) -#define EPT_VLT_FETCH (1 << 2) -#define EPT_VLT_PERM_RD (1 << 3) -#define EPT_VLT_PERM_WR (1 << 4) -#define EPT_VLT_PERM_EX (1 << 5) +#define EPT_VLT_RD (1ull << 0) +#define EPT_VLT_WR (1ull << 1) +#define EPT_VLT_FETCH (1ull << 2) +#define EPT_VLT_PERM_RD (1ull << 3) +#define EPT_VLT_PERM_WR (1ull << 4) +#define EPT_VLT_PERM_EX (1ull << 5) +#define EPT_VLT_PERM_USER_EX (1ull << 6)#define EPT_VLT_PERMS (EPT_VLT_PERM_RD | EPT_VLT_PERM_WR | \ EPT_VLT_PERM_EX)Quoted 8 lines
Quoted 6 lines
x86/vmx.h enum vm_instruction_error_number { · line 618
Quoted 6 lines
x86/vmx.h +4
-2-#define EPT_VLT_LADDR_VLD (1 << 7) -#define EPT_VLT_PADDR (1 << 8) +#define EPT_VLT_LADDR_VLD (1ull << 7) +#define EPT_VLT_PADDR (1ull << 8) +#define EPT_VLT_GUEST_USER (1ull << 9) +#define EPT_VLT_GUEST_WR (1ull << 10)This one should be named
EPT_VLT_GUEST_RW, assuming you are naming them according to the 1-setting of the bits.Whatever you wish (unless someone else has different preference).
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
x86/vmx.h +1
-0+#define EPT_VLT_GUEST_EX (1ull << 11)#define MAGIC_VAL_1 0x12345678ul#define MAGIC_VAL_2 0x87654321ulx86/vmx_tests.c +0
-0@@ -2365,6 +2365,10 @@ static void do_ept_violation(bool leaf, enum ept_access_op op,Quoted 8 lines
Quoted 6 lines
x86/vmx_tests.c static void do_ept_violation(bool leaf, enum ept_access_op op, · line 2371
Quoted 6 lines
x86/vmx_tests.c +4
-0qual =vmcs_read (EXI_QUALIFICATION ); +/* Mask undefined bits (which may later be defined in certain cases). */ + qual &= ~(EPT_VLT_GUEST_USER |EPT_VLT_GUEST_WR |EPT_VLT_GUEST_EX | +EPT_VLT_PERM_USER_EX ); +The "DIAGNOSE" macro doesn't check any of these bits, so this masking seems redundant.
Quoted 5 lines
The DIAGNOSE macro is not the one who causes errors. It’s the:
TEST_EXPECT_EQ(expected_qual, qual);That comes right after the call to
diagnose_ept_violation_qual().
Sorry, I missed that !
Quoted 10 lines
Quoted 5 lines
Also, don't we need to check for the relevant conditions before masking the bits ? For example,
EPT_VLT_PERM_USER_EXis dependent on "mode-based execute control" VM-execution control" and the other ones depend on bit 7 and 8 of the Exit Qualification field.The tests right now do not “emulate” these bits, so the expected qualification would never have
EPT_VLT_PERM_USER_EX(for instance) set. Once someone implements tests for these bits, he would need to change the masking.
Paolo Bonzini
maintainerQuoted 48 lines · Krish Sadhukhan
Quoted 45 lines · Nadav Amit
Quoted 45 lines · On May 3, 2019, at 10:49 AM, [email protected] wrote:
From: Nadav Amit <[email protected]>
On EPT violation, the exit qualifications may have some undefined bits.
Bit 6 is undefined if "mode-based execute control" is 0.
Bits 9-11 are undefined unless the processor supports advanced VM-exit information for EPT violations.
Right now on KVM these bits are always undefined inside the VM (i.e., in an emulated VM-exit). Mask these bits to avoid potential false indication of failures.
Signed-off-by Nadav Amit <[email protected]>---
x86/vmx.h | 20 ++++++++++++--------x86/vmx_tests.c| 4 ++++2 files changed, 16 insertions(+), 8 deletions(-)x86/vmx.h +7
-7@@ -603,16 +603,20 @@ enum vm_instruction_error_number {#define EPT_ADDR_MASK GENMASK_ULL(51, 12)#define PAGE_MASK_2M (~(PAGE_SIZE_2M-1)) -#define EPT_VLT_RD 1 -#define EPT_VLT_WR (1 << 1) -#define EPT_VLT_FETCH (1 << 2) -#define EPT_VLT_PERM_RD (1 << 3) -#define EPT_VLT_PERM_WR (1 << 4) -#define EPT_VLT_PERM_EX (1 << 5) +#define EPT_VLT_RD (1ull << 0) +#define EPT_VLT_WR (1ull << 1) +#define EPT_VLT_FETCH (1ull << 2) +#define EPT_VLT_PERM_RD (1ull << 3) +#define EPT_VLT_PERM_WR (1ull << 4) +#define EPT_VLT_PERM_EX (1ull << 5) +#define EPT_VLT_PERM_USER_EX (1ull << 6)#define EPT_VLT_PERMS (EPT_VLT_PERM_RD | EPT_VLT_PERM_WR | \ EPT_VLT_PERM_EX) -#define EPT_VLT_LADDR_VLD (1 << 7)
Quoted 8 lines
Quoted 5 lines
x86/vmx.h enum vm_instruction_error_number { · line 618
Quoted 5 lines
x86/vmx.h +4
-1-#define EPT_VLT_PADDR (1 << 8) +#define EPT_VLT_LADDR_VLD (1ull << 7) +#define EPT_VLT_PADDR (1ull << 8) +#define EPT_VLT_GUEST_USER (1ull << 9) +#define EPT_VLT_GUEST_WR (1ull << 10)This one should be named EPT_VLT_GUEST_RW, assuming you are naming them according to the 1-setting of the bits.
Applied with this change, thanks.
Paolo