* [kvm-unit-tests PATCH 1/2] x86: nSVM: Use PT_* macro for NPT tests
@ 2025-06-03 4:47 Eiichi Tsukata
2025-06-03 4:47 ` [kvm-unit-tests PATCH 2/2] x86: nSVM: Use PFERR_* " Eiichi Tsukata
0 siblings, 1 reply; 2+ messages in thread
From: Eiichi Tsukata @ 2025-06-03 4:47 UTC (permalink / raw)
To: kvm; +Cc: Eiichi Tsukata
No functional change intended.
Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
---
x86/svm_npt.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/x86/svm_npt.c b/x86/svm_npt.c
index b791f1ac..09c33783 100644
--- a/x86/svm_npt.c
+++ b/x86/svm_npt.c
@@ -16,7 +16,7 @@ static void npt_np_prepare(struct svm_test *test)
scratch_page = alloc_page();
pte = npt_get_pte((u64) scratch_page);
- *pte &= ~1ULL;
+ *pte &= ~PT_PRESENT_MASK;
}
static void npt_np_test(struct svm_test *test)
@@ -28,7 +28,7 @@ static bool npt_np_check(struct svm_test *test)
{
u64 *pte = npt_get_pte((u64) scratch_page);
- *pte |= 1ULL;
+ *pte |= PT_PRESENT_MASK;
return (vmcb->control.exit_code == SVM_EXIT_NPF)
&& (vmcb->control.exit_info_1 == 0x100000004ULL);
@@ -68,7 +68,7 @@ static void npt_us_prepare(struct svm_test *test)
scratch_page = alloc_page();
pte = npt_get_pte((u64) scratch_page);
- *pte &= ~(1ULL << 2);
+ *pte &= ~PT_USER_MASK;
}
static void npt_us_test(struct svm_test *test)
@@ -80,7 +80,7 @@ static bool npt_us_check(struct svm_test *test)
{
u64 *pte = npt_get_pte((u64) scratch_page);
- *pte |= (1ULL << 2);
+ *pte |= PT_USER_MASK;
return (vmcb->control.exit_code == SVM_EXIT_NPF)
&& (vmcb->control.exit_info_1 == 0x100000005ULL);
@@ -93,7 +93,7 @@ static void npt_rw_prepare(struct svm_test *test)
pte = npt_get_pte(0x80000);
- *pte &= ~(1ULL << 1);
+ *pte &= ~PT_WRITABLE_MASK;
}
static void npt_rw_test(struct svm_test *test)
@@ -107,7 +107,7 @@ static bool npt_rw_check(struct svm_test *test)
{
u64 *pte = npt_get_pte(0x80000);
- *pte |= (1ULL << 1);
+ *pte |= PT_WRITABLE_MASK;
return (vmcb->control.exit_code == SVM_EXIT_NPF)
&& (vmcb->control.exit_info_1 == 0x100000007ULL);
@@ -120,14 +120,14 @@ static void npt_rw_pfwalk_prepare(struct svm_test *test)
pte = npt_get_pte(read_cr3());
- *pte &= ~(1ULL << 1);
+ *pte &= ~PT_WRITABLE_MASK;
}
static bool npt_rw_pfwalk_check(struct svm_test *test)
{
u64 *pte = npt_get_pte(read_cr3());
- *pte |= (1ULL << 1);
+ *pte |= PT_WRITABLE_MASK;
return (vmcb->control.exit_code == SVM_EXIT_NPF)
&& (vmcb->control.exit_info_1 == 0x200000007ULL)
@@ -164,7 +164,7 @@ static void npt_rw_l1mmio_prepare(struct svm_test *test)
pte = npt_get_pte(0xfee00080);
- *pte &= ~(1ULL << 1);
+ *pte &= ~PT_WRITABLE_MASK;
}
static void npt_rw_l1mmio_test(struct svm_test *test)
@@ -178,7 +178,7 @@ static bool npt_rw_l1mmio_check(struct svm_test *test)
{
u64 *pte = npt_get_pte(0xfee00080);
- *pte |= (1ULL << 1);
+ *pte |= PT_WRITABLE_MASK;
return (vmcb->control.exit_code == SVM_EXIT_NPF)
&& (vmcb->control.exit_info_1 == 0x100000007ULL);
--
2.49.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [kvm-unit-tests PATCH 2/2] x86: nSVM: Use PFERR_* macro for NPT tests
2025-06-03 4:47 [kvm-unit-tests PATCH 1/2] x86: nSVM: Use PT_* macro for NPT tests Eiichi Tsukata
@ 2025-06-03 4:47 ` Eiichi Tsukata
0 siblings, 0 replies; 2+ messages in thread
From: Eiichi Tsukata @ 2025-06-03 4:47 UTC (permalink / raw)
To: kvm; +Cc: Eiichi Tsukata
No functional change intended.
Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
---
lib/x86/vm.h | 9 +++++++++
x86/access.c | 7 -------
x86/svm_npt.c | 23 +++++++++++++++--------
3 files changed, 24 insertions(+), 15 deletions(-)
diff --git a/lib/x86/vm.h b/lib/x86/vm.h
index cf39787a..49c0a557 100644
--- a/lib/x86/vm.h
+++ b/lib/x86/vm.h
@@ -7,6 +7,15 @@
#include "asm/io.h"
#include "asm/bitops.h"
+#define PFERR_PRESENT_MASK BIT(0)
+#define PFERR_WRITE_MASK BIT(1)
+#define PFERR_USER_MASK BIT(2)
+#define PFERR_RESERVED_MASK BIT(3)
+#define PFERR_FETCH_MASK BIT(4)
+#define PFERR_PK_MASK BIT(5)
+#define PFERR_GUEST_FINAL_MASK BIT_ULL(32)
+#define PFERR_GUEST_PAGE_MASK BIT_ULL(33)
+
void setup_5level_page_table(void);
struct pte_search {
diff --git a/x86/access.c b/x86/access.c
index f90a72d6..842be4d0 100644
--- a/x86/access.c
+++ b/x86/access.c
@@ -17,13 +17,6 @@ static int invalid_mask;
#define PT_BASE_ADDR_MASK ((pt_element_t)((((pt_element_t)1 << 36) - 1) & PAGE_MASK))
#define PT_PSE_BASE_ADDR_MASK (PT_BASE_ADDR_MASK & ~(1ull << 21))
-#define PFERR_PRESENT_MASK (1U << 0)
-#define PFERR_WRITE_MASK (1U << 1)
-#define PFERR_USER_MASK (1U << 2)
-#define PFERR_RESERVED_MASK (1U << 3)
-#define PFERR_FETCH_MASK (1U << 4)
-#define PFERR_PK_MASK (1U << 5)
-
#define MSR_EFER 0xc0000080
#define EFER_NX_MASK (1ull << 11)
diff --git a/x86/svm_npt.c b/x86/svm_npt.c
index 09c33783..53494107 100644
--- a/x86/svm_npt.c
+++ b/x86/svm_npt.c
@@ -31,7 +31,7 @@ static bool npt_np_check(struct svm_test *test)
*pte |= PT_PRESENT_MASK;
return (vmcb->control.exit_code == SVM_EXIT_NPF)
- && (vmcb->control.exit_info_1 == 0x100000004ULL);
+ && (vmcb->control.exit_info_1 == (PFERR_USER_MASK | PFERR_GUEST_FINAL_MASK));
}
static void npt_nx_prepare(struct svm_test *test)
@@ -58,7 +58,8 @@ static bool npt_nx_check(struct svm_test *test)
*pte &= ~PT64_NX_MASK;
return (vmcb->control.exit_code == SVM_EXIT_NPF)
- && (vmcb->control.exit_info_1 == 0x100000015ULL);
+ && (vmcb->control.exit_info_1 ==
+ (PFERR_PRESENT_MASK | PFERR_USER_MASK | PFERR_FETCH_MASK | PFERR_GUEST_FINAL_MASK));
}
static void npt_us_prepare(struct svm_test *test)
@@ -83,7 +84,8 @@ static bool npt_us_check(struct svm_test *test)
*pte |= PT_USER_MASK;
return (vmcb->control.exit_code == SVM_EXIT_NPF)
- && (vmcb->control.exit_info_1 == 0x100000005ULL);
+ && (vmcb->control.exit_info_1 ==
+ (PFERR_PRESENT_MASK | PFERR_USER_MASK | PFERR_GUEST_FINAL_MASK));
}
static void npt_rw_prepare(struct svm_test *test)
@@ -110,7 +112,8 @@ static bool npt_rw_check(struct svm_test *test)
*pte |= PT_WRITABLE_MASK;
return (vmcb->control.exit_code == SVM_EXIT_NPF)
- && (vmcb->control.exit_info_1 == 0x100000007ULL);
+ && (vmcb->control.exit_info_1 ==
+ (PFERR_PRESENT_MASK | PFERR_WRITE_MASK | PFERR_USER_MASK | PFERR_GUEST_FINAL_MASK));
}
static void npt_rw_pfwalk_prepare(struct svm_test *test)
@@ -130,7 +133,8 @@ static bool npt_rw_pfwalk_check(struct svm_test *test)
*pte |= PT_WRITABLE_MASK;
return (vmcb->control.exit_code == SVM_EXIT_NPF)
- && (vmcb->control.exit_info_1 == 0x200000007ULL)
+ && (vmcb->control.exit_info_1 ==
+ (PFERR_PRESENT_MASK | PFERR_WRITE_MASK | PFERR_USER_MASK | PFERR_GUEST_PAGE_MASK))
&& (vmcb->control.exit_info_2 == read_cr3());
}
@@ -181,7 +185,8 @@ static bool npt_rw_l1mmio_check(struct svm_test *test)
*pte |= PT_WRITABLE_MASK;
return (vmcb->control.exit_code == SVM_EXIT_NPF)
- && (vmcb->control.exit_info_1 == 0x100000007ULL);
+ && (vmcb->control.exit_info_1 ==
+ (PFERR_PRESENT_MASK | PFERR_WRITE_MASK | PFERR_USER_MASK | PFERR_GUEST_FINAL_MASK));
}
static void basic_guest_main(struct svm_test *test)
@@ -214,10 +219,12 @@ static void __svm_npt_rsvd_bits_test(u64 * pxe, u64 rsvd_bits, u64 efer,
* The guest's page tables will blow up on a bad PDPE/PML4E,
* before starting the final walk of the guest page.
*/
- pfec = 0x20000000full;
+ pfec = (PFERR_PRESENT_MASK | PFERR_WRITE_MASK | PFERR_USER_MASK |
+ PFERR_RESERVED_MASK | PFERR_GUEST_PAGE_MASK);
} else {
/* RSVD #NPF on final walk of guest page. */
- pfec = 0x10000000dULL;
+ pfec = (PFERR_PRESENT_MASK | PFERR_USER_MASK |
+ PFERR_RESERVED_MASK | PFERR_GUEST_FINAL_MASK);
/* PFEC.FETCH=1 if NX=1 *or* SMEP=1. */
if ((cr4 & X86_CR4_SMEP) || (efer & EFER_NX))
--
2.49.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-06-03 5:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-03 4:47 [kvm-unit-tests PATCH 1/2] x86: nSVM: Use PT_* macro for NPT tests Eiichi Tsukata
2025-06-03 4:47 ` [kvm-unit-tests PATCH 2/2] x86: nSVM: Use PFERR_* " Eiichi Tsukata
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).