From: Jon Kohler <jon@nutanix.com>
To: seanjc@google.com, pbonzini@redhat.com, kvm@vger.kernel.org
Cc: Jon Kohler <jon@nutanix.com>
Subject: [kvm-unit-tests PATCH 08/17] x86/vmx: switch to new vmx.h EPT access and dirty defs
Date: Tue, 16 Sep 2025 10:22:37 -0700 [thread overview]
Message-ID: <20250916172247.610021-9-jon@nutanix.com> (raw)
In-Reply-To: <20250916172247.610021-1-jon@nutanix.com>
Migrate to new vmx.h's EPT defs for access and dirty bits, which makes
it easier to grok from one code base to another.
No functional change intended.
Signed-off-by: Jon Kohler <jon@nutanix.com>
---
x86/vmx.c | 20 +++++++++++---------
x86/vmx.h | 3 ---
x86/vmx_tests.c | 43 ++++++++++++++++++++++++-------------------
3 files changed, 35 insertions(+), 31 deletions(-)
diff --git a/x86/vmx.c b/x86/vmx.c
index 6b7dca34..a3c6c60b 100644
--- a/x86/vmx.c
+++ b/x86/vmx.c
@@ -986,7 +986,7 @@ static void clear_ept_ad_pte(unsigned long *pml4, unsigned long guest_addr)
for (l = EPT_PAGE_LEVEL; ; --l) {
offset = (guest_addr >> EPT_LEVEL_SHIFT(l)) & EPT_PGDIR_MASK;
- pt[offset] &= ~(EPT_ACCESS_FLAG|EPT_DIRTY_FLAG);
+ pt[offset] &= ~(VMX_EPT_ACCESS_BIT | VMX_EPT_DIRTY_BIT);
pte = pt[offset];
if (l == 1 || (l < 4 && (pte & EPT_LARGE_PAGE)))
break;
@@ -1043,12 +1043,14 @@ void check_ept_ad(unsigned long *pml4, u64 guest_cr3,
}
if (!bad_pt_ad) {
- bad_pt_ad |= (ept_pte & (EPT_ACCESS_FLAG|EPT_DIRTY_FLAG)) != expected_pt_ad;
+ bad_pt_ad |=
+ (ept_pte & (VMX_EPT_ACCESS_BIT | VMX_EPT_DIRTY_BIT)) !=
+ expected_pt_ad;
if (bad_pt_ad)
report_fail("EPT - guest level %d page table A=%d/D=%d",
l,
- !!(expected_pt_ad & EPT_ACCESS_FLAG),
- !!(expected_pt_ad & EPT_DIRTY_FLAG));
+ !!(expected_pt_ad & VMX_EPT_ACCESS_BIT),
+ !!(expected_pt_ad & VMX_EPT_DIRTY_BIT));
}
pte = pt[offset];
@@ -1061,8 +1063,8 @@ void check_ept_ad(unsigned long *pml4, u64 guest_cr3,
if (!bad_pt_ad)
report_pass("EPT - guest page table structures A=%d/D=%d",
- !!(expected_pt_ad & EPT_ACCESS_FLAG),
- !!(expected_pt_ad & EPT_DIRTY_FLAG));
+ !!(expected_pt_ad & VMX_EPT_ACCESS_BIT),
+ !!(expected_pt_ad & VMX_EPT_DIRTY_BIT));
offset = (guest_addr >> EPT_LEVEL_SHIFT(l)) & EPT_PGDIR_MASK;
offset_in_page = guest_addr & ((1 << EPT_LEVEL_SHIFT(l)) - 1);
@@ -1072,10 +1074,10 @@ void check_ept_ad(unsigned long *pml4, u64 guest_cr3,
report_fail("EPT - guest physical address is not mapped");
return;
}
- report((ept_pte & (EPT_ACCESS_FLAG | EPT_DIRTY_FLAG)) == expected_gpa_ad,
+ report((ept_pte & (VMX_EPT_ACCESS_BIT | VMX_EPT_DIRTY_BIT)) == expected_gpa_ad,
"EPT - guest physical address A=%d/D=%d",
- !!(expected_gpa_ad & EPT_ACCESS_FLAG),
- !!(expected_gpa_ad & EPT_DIRTY_FLAG));
+ !!(expected_gpa_ad & VMX_EPT_ACCESS_BIT),
+ !!(expected_gpa_ad & VMX_EPT_DIRTY_BIT));
}
void set_ept_pte(unsigned long *pml4, unsigned long guest_addr,
diff --git a/x86/vmx.h b/x86/vmx.h
index 3f792d4a..65012e0e 100644
--- a/x86/vmx.h
+++ b/x86/vmx.h
@@ -570,7 +570,6 @@ enum Intr_type {
#define EPTP_PG_WALK_LEN_MASK 0x38ul
#define EPTP_RESERV_BITS_MASK 0x1ful
#define EPTP_RESERV_BITS_SHIFT 0x7ul
-#define EPTP_AD_FLAG (1ul << 6)
#define EPT_MEM_TYPE_UC 0ul
#define EPT_MEM_TYPE_WC 1ul
@@ -578,8 +577,6 @@ enum Intr_type {
#define EPT_MEM_TYPE_WP 5ul
#define EPT_MEM_TYPE_WB 6ul
-#define EPT_ACCESS_FLAG (1ul << 8)
-#define EPT_DIRTY_FLAG (1ul << 9)
#define EPT_LARGE_PAGE (1ul << 7)
#define EPT_MEM_TYPE_SHIFT 3ul
#define EPT_MEM_TYPE_MASK 0x7ul
diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index eda9e88a..f7ea411f 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -1066,7 +1066,7 @@ static int __setup_ept(u64 hpa, bool enable_ad)
eptp |= (3 << EPTP_PG_WALK_LEN_SHIFT);
eptp |= hpa;
if (enable_ad)
- eptp |= EPTP_AD_FLAG;
+ eptp |= VMX_EPTP_AD_ENABLE_BIT;
vmcs_write(EPTP, eptp);
vmcs_write(CPU_EXEC_CTRL0, vmcs_read(CPU_EXEC_CTRL0)| CPU_SECONDARY);
@@ -1141,19 +1141,19 @@ static int enable_unrestricted_guest(bool need_valid_ept)
static void ept_enable_ad_bits(void)
{
- eptp |= EPTP_AD_FLAG;
+ eptp |= VMX_EPTP_AD_ENABLE_BIT;
vmcs_write(EPTP, eptp);
}
static void ept_disable_ad_bits(void)
{
- eptp &= ~EPTP_AD_FLAG;
+ eptp &= ~VMX_EPTP_AD_ENABLE_BIT;
vmcs_write(EPTP, eptp);
}
static int ept_ad_enabled(void)
{
- return eptp & EPTP_AD_FLAG;
+ return eptp & VMX_EPTP_AD_ENABLE_BIT;
}
static void ept_enable_ad_bits_or_skip_test(void)
@@ -1350,12 +1350,15 @@ static int ept_exit_handler_common(union exit_reason exit_reason, bool have_ad)
case 0:
check_ept_ad(pml4, guest_cr3,
(unsigned long)data_page1,
- have_ad ? EPT_ACCESS_FLAG : 0,
- have_ad ? EPT_ACCESS_FLAG | EPT_DIRTY_FLAG : 0);
+ have_ad ? VMX_EPT_ACCESS_BIT : 0,
+ have_ad ? VMX_EPT_ACCESS_BIT |
+ VMX_EPT_DIRTY_BIT : 0);
check_ept_ad(pml4, guest_cr3,
(unsigned long)data_page2,
- have_ad ? EPT_ACCESS_FLAG | EPT_DIRTY_FLAG : 0,
- have_ad ? EPT_ACCESS_FLAG | EPT_DIRTY_FLAG : 0);
+ have_ad ? VMX_EPT_ACCESS_BIT |
+ VMX_EPT_DIRTY_BIT : 0,
+ have_ad ? VMX_EPT_ACCESS_BIT |
+ VMX_EPT_DIRTY_BIT : 0);
clear_ept_ad(pml4, guest_cr3, (unsigned long)data_page1);
clear_ept_ad(pml4, guest_cr3, (unsigned long)data_page2);
if (have_ad)
@@ -1451,7 +1454,8 @@ static int ept_exit_handler_common(union exit_reason exit_reason, bool have_ad)
switch(vmx_get_test_stage()) {
case 3:
check_ept_ad(pml4, guest_cr3, (unsigned long)data_page1, 0,
- have_ad ? EPT_ACCESS_FLAG | EPT_DIRTY_FLAG : 0);
+ have_ad ? VMX_EPT_ACCESS_BIT |
+ VMX_EPT_DIRTY_BIT : 0);
clear_ept_ad(pml4, guest_cr3, (unsigned long)data_page1);
if (exit_qual == (EPT_VIOLATION_ACC_WRITE |
EPT_VIOLATION_GVA_IS_VALID |
@@ -1463,7 +1467,8 @@ static int ept_exit_handler_common(union exit_reason exit_reason, bool have_ad)
break;
case 4:
check_ept_ad(pml4, guest_cr3, (unsigned long)data_page1, 0,
- have_ad ? EPT_ACCESS_FLAG | EPT_DIRTY_FLAG : 0);
+ have_ad ? VMX_EPT_ACCESS_BIT |
+ VMX_EPT_DIRTY_BIT : 0);
clear_ept_ad(pml4, guest_cr3, (unsigned long)data_page1);
if (exit_qual == (EPT_VIOLATION_ACC_READ |
(have_ad ? EPT_VIOLATION_ACC_WRITE : 0) |
@@ -2517,11 +2522,11 @@ static void ept_access_paddr(unsigned long ept_access, unsigned long pte_ad,
if (ept_ad_enabled()) {
for (i = EPT_PAGE_LEVEL; i > 0; i--) {
TEST_ASSERT(get_ept_pte(pml4, gpa, i, &epte));
- TEST_ASSERT(epte & EPT_ACCESS_FLAG);
+ TEST_ASSERT(epte & VMX_EPT_ACCESS_BIT);
if (i == 1)
- TEST_ASSERT(epte & EPT_DIRTY_FLAG);
+ TEST_ASSERT(epte & VMX_EPT_DIRTY_BIT);
else
- TEST_ASSERT_EQ(epte & EPT_DIRTY_FLAG, 0);
+ TEST_ASSERT_EQ(epte & VMX_EPT_DIRTY_BIT, 0);
}
}
@@ -4783,7 +4788,7 @@ static void test_eptp_ad_bit(u64 eptp, bool is_ctrl_valid)
{
vmcs_write(EPTP, eptp);
report_prefix_pushf("Enable-EPT enabled; EPT accessed and dirty flag %s",
- (eptp & EPTP_AD_FLAG) ? "1": "0");
+ (eptp & VMX_EPTP_AD_ENABLE_BIT) ? "1" : "0");
if (is_ctrl_valid)
test_vmx_valid_controls();
else
@@ -4872,20 +4877,20 @@ static void test_ept_eptp(void)
*/
if (ept_ad_bits_supported()) {
report_info("Processor supports accessed and dirty flag");
- eptp &= ~EPTP_AD_FLAG;
+ eptp &= ~VMX_EPTP_AD_ENABLE_BIT;
test_eptp_ad_bit(eptp, true);
- eptp |= EPTP_AD_FLAG;
+ eptp |= VMX_EPTP_AD_ENABLE_BIT;
test_eptp_ad_bit(eptp, true);
} else {
report_info("Processor does not supports accessed and dirty flag");
- eptp &= ~EPTP_AD_FLAG;
+ eptp &= ~VMX_EPTP_AD_ENABLE_BIT;
test_eptp_ad_bit(eptp, true);
- eptp |= EPTP_AD_FLAG;
+ eptp |= VMX_EPTP_AD_ENABLE_BIT;
test_eptp_ad_bit(eptp, false);
- eptp &= ~EPTP_AD_FLAG;
+ eptp &= ~VMX_EPTP_AD_ENABLE_BIT;
}
/*
--
2.43.0
next prev parent reply other threads:[~2025-09-16 16:44 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-16 17:22 [kvm-unit-tests PATCH 00/17] x86/vmx: align with Linux kernel VMX definitions Jon Kohler
2025-09-16 17:22 ` [kvm-unit-tests PATCH 01/17] lib: add linux vmx.h clone from 6.16 Jon Kohler
2025-09-16 17:22 ` [kvm-unit-tests PATCH 02/17] lib: add linux trapnr.h " Jon Kohler
2025-09-16 17:22 ` [kvm-unit-tests PATCH 03/17] lib: add vmxfeatures.h " Jon Kohler
2025-09-16 17:22 ` [kvm-unit-tests PATCH 04/17] lib: define __aligned() in compiler.h Jon Kohler
2025-09-16 17:22 ` [kvm-unit-tests PATCH 05/17] x86/vmx: basic integration for new vmx.h Jon Kohler
2025-09-16 17:22 ` [kvm-unit-tests PATCH 06/17] x86/vmx: switch to new vmx.h EPT violation defs Jon Kohler
2025-09-16 17:22 ` [kvm-unit-tests PATCH 07/17] x86/vmx: switch to new vmx.h EPT RWX defs Jon Kohler
2025-09-16 17:22 ` Jon Kohler [this message]
2025-09-16 17:22 ` [kvm-unit-tests PATCH 09/17] x86/vmx: switch to new vmx.h EPT capability and memory type defs Jon Kohler
2025-09-16 17:22 ` [kvm-unit-tests PATCH 10/17] x86/vmx: switch to new vmx.h primary processor-based VM-execution controls Jon Kohler
2025-09-16 17:22 ` [kvm-unit-tests PATCH 11/17] x86/vmx: switch to new vmx.h secondary execution control bit Jon Kohler
2025-09-16 17:22 ` [kvm-unit-tests PATCH 12/17] x86/vmx: switch to new vmx.h secondary execution controls Jon Kohler
2025-09-16 17:22 ` [kvm-unit-tests PATCH 13/17] x86/vmx: switch to new vmx.h pin based VM-execution controls Jon Kohler
2025-09-16 17:22 ` [kvm-unit-tests PATCH 14/17] x86/vmx: switch to new vmx.h exit controls Jon Kohler
2025-09-16 17:22 ` [kvm-unit-tests PATCH 15/17] x86/vmx: switch to new vmx.h entry controls Jon Kohler
2025-09-16 17:22 ` [kvm-unit-tests PATCH 16/17] x86/vmx: switch to new vmx.h interrupt defs Jon Kohler
2025-09-16 17:22 ` [kvm-unit-tests PATCH 17/17] x86/vmx: align exit reasons with Linux uapi Jon Kohler
2025-11-12 19:02 ` [kvm-unit-tests PATCH 00/17] x86/vmx: align with Linux kernel VMX definitions Sean Christopherson
2025-11-14 14:52 ` Jon Kohler
2025-11-17 17:41 ` Sean Christopherson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250916172247.610021-9-jon@nutanix.com \
--to=jon@nutanix.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.