Skip to contentSkip to conversation

Move nNPT test cases to a seperate file

PATCH Superseded Manali Shukla 3 participants 7 messages Feb 28, 2022 – Mar 10, 2022 KVM

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover Move nNPT test cases to a seperate file

Commit 916635a813e975600335c6c47250881b7a328971
(nSVM: Add test for NPT reserved bit and #NPF error code behavior) clears PT_USER_MASK for all svm testcases. Any tests that requires usermode access will fail after this commit.

If __setup_vm() is changed to setup_vm(), KUT will build tests with PT_USER_MASK set on all PTEs. It is a better idea to move nNPT tests to their own file so that tests don't need to fiddle with page tables midway.

The quick approach to do this would be to turn the current main into a small helper, without calling __setup_vm() from helper.

There are three patches in this patch series
1) Turned current main into helper function minus setup_vm()
2) Moved all nNPT test cases from svm_tests.c to svm_npt.c
3) Change __setup_vm to setup_vm() on svm_tests.c

Manali Shukla (3):
x86: nSVM: Move common functionality of the main() to helper
run_svm_tests
x86: nSVM: Move all nNPT test cases from svm_tests.c to a seperate
file.
x86: nSVM: Allow nSVM tests run with PT_USER_MASK enabled

 x86/Makefile.common |   2 +
 x86/Makefile.x86_64 |   2 +
 x86/svm.c           |   6 +-
 x86/svm.h           |   1 +
 x86/svm_npt.c       | 386 ++++++++++++++++++++++++++++++++++++++++++++
 x86/svm_tests.c     | 369 +-----------------------------------------
 6 files changed, 398 insertions(+), 368 deletions(-)
 create mode 100644 x86/svm_npt.c
Signature · 1 line
2.30.2
#1 lore raw

PATCH 1/3 x86: nSVM: Move common functionality of the main() to helper run_svm_tests

nSVM tests are "incompatible" with usermode due to __setup_vm() call in main function.

If __setup_vm() is replaced with setup_vm() in main function, KUT will build the test with PT_USER_MASK set on all PTEs.

nNPT tests will be moved to their own file so that the tests don't need to fiddle with page tables midway through.

The quick and dirty approach would be to turn the current main() into a small helper, minus its call to __setup_vm() and call the helper function run_svm_tests() from main() function.

No functional change intended.

---
 x86/svm.c | 14 +++++++++-----
 x86/svm.h |  1 +
 2 files changed, 10 insertions(+), 5 deletions(-)
x86/svm.c +9 -5
index 3f94b2a..e93e780 100644
@@ -406,17 +406,13 @@ test_wanted(const char *name, char *filters[], int filter_count)
         }
 }
 
-int main(int ac, char **av)
+int run_svm_tests(int ac, char **av)
 {
-	/* Omit PT_USER_MASK to allow tested host.CR4.SMEP=1. */
-	pteval_t opt_mask = 0;
 	int i = 0;
 
 	ac--;
 	av++;
 
-	__setup_vm(&opt_mask);
-
 	if (!this_cpu_has(X86_FEATURE_SVM)) {
 		printf("SVM not availble\n");
 		return report_summary();
@@ -453,3 +449,11 @@ int main(int ac, char **av)
 
 	return report_summary();
 }
+
+int main(int ac, char **av)
+{
+    pteval_t opt_mask = 0;
+
+    __setup_vm(&opt_mask);
+    return run_svm_tests(ac, av);
+}
x86/svm.h +1 -0
index f74b13a..9ab3aa5 100644
@@ -398,6 +398,7 @@ struct regs {
 
 typedef void (*test_guest_func)(struct svm_test *);
 
+int run_svm_tests(int ac, char **av);
 u64 *npt_get_pte(u64 address);
 u64 *npt_get_pde(u64 address);
 u64 *npt_get_pdpe(void);
Signature · 1 line
2.30.2
#2 lore raw

PATCH 2/3 x86: nSVM: Move all nNPT test cases from svm_tests.c to a seperate file.

In reply to Manali Shukla

nNPT test cases are moved to a seperate file svm_npt.c so that they can be run independently with PTE_USER_MASK disabled.

Rest of the test cases can be run with PTE_USER_MASK enabled.

No functional change intended.

---
 x86/Makefile.common |   2 +
 x86/Makefile.x86_64 |   2 +
 x86/svm.c           |   8 -
 x86/svm_npt.c       | 386 ++++++++++++++++++++++++++++++++++++++++++++
 x86/svm_tests.c     | 372 ++----------------------------------------
 5 files changed, 399 insertions(+), 371 deletions(-)
 create mode 100644 x86/svm_npt.c
x86/Makefile.common +2 -0
index ff02d98..202986b 100644
@@ -107,6 +107,8 @@ $(TEST_DIR)/access_test.$(bin): $(TEST_DIR)/access.o
 
 $(TEST_DIR)/vmx.$(bin): $(TEST_DIR)/access.o
 
+$(TEST_DIR)/svm_npt.$(bin): $(TEST_DIR)/svm.o
+
 $(TEST_DIR)/kvmclock_test.$(bin): $(TEST_DIR)/kvmclock.o
 
 $(TEST_DIR)/hyperv_synic.$(bin): $(TEST_DIR)/hyperv.o
x86/Makefile.x86_64 +2 -0
index a3cb75a..ba7c378 100644
@@ -42,6 +42,7 @@ endif
 ifneq ($(TARGET_EFI),y)
 tests += $(TEST_DIR)/access_test.$(exe)
 tests += $(TEST_DIR)/svm.$(exe)
+tests += $(TEST_DIR)/svm_npt.$(exe)
 tests += $(TEST_DIR)/vmx.$(exe)
 endif
 
@@ -55,3 +56,4 @@ $(TEST_DIR)/hyperv_clock.$(bin): $(TEST_DIR)/hyperv_clock.o
 
 $(TEST_DIR)/vmx.$(bin): $(TEST_DIR)/vmx_tests.o
 $(TEST_DIR)/svm.$(bin): $(TEST_DIR)/svm_tests.o
+$(TEST_DIR)/svm_npt.$(bin): $(TEST_DIR)/svm_npt.o
x86/svm.c +0 -8
index e93e780..d0d523a 100644
@@ -449,11 +449,3 @@ int run_svm_tests(int ac, char **av)
 
 	return report_summary();
 }
-
-int main(int ac, char **av)
-{
-    pteval_t opt_mask = 0;
-
-    __setup_vm(&opt_mask);
-    return run_svm_tests(ac, av);
-}
x86/svm_npt.c new file +386 -0

386 lines not on this page · raw message

x86/svm_tests.c +9 -363

414 lines not on this page · raw message

Signature · 1 line
2.30.2
#3 lore raw

PATCH 3/3 x86: nSVM: Allow nSVM tests run with PT_USER_MASK enabled

In reply to Manali Shukla

Commit 916635a813e975600335c6c47250881b7a328971
(nSVM: Add test for NPT reserved bit and #NPF error code behavior) clears PT_USER_MASK for all svm testcases. Any tests that requires usermode access will fail after this commit.

Above mentioned commit did changes in main() due to which other nSVM tests became "incompatible" with usermode

Solution to this problem would be to set PT_USER_MASK on all PTEs. So that KUT will build other tests with PT_USER_MASK set on all PTEs.

---
 x86/svm_tests.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
x86/svm_tests.c +1 -4
index 41980d9..fce466e 100644
@@ -10,7 +10,6 @@
 #include "isr.h"
 #include "apic.h"
 #include "delay.h"
-#include "vmalloc.h"
 
 #define SVM_EXIT_MAX_DR_INTERCEPT 0x3f
 
@@ -2736,9 +2735,7 @@ static void svm_nm_test(void)
 
 int main(int ac, char **av)
 {
-    pteval_t opt_mask = 0;
-
-    __setup_vm(&opt_mask);
+    setup_vm();
     return run_svm_tests(ac, av);
 }
 
Signature · 1 line
2.30.2
#4 lore raw
In reply to Manali Shukla
Quoted 25 lines · Manali Shukla

Commit 916635a813e975600335c6c47250881b7a328971
(nSVM: Add test for NPT reserved bit and #NPF error code behavior) clears PT_USER_MASK for all svm testcases. Any tests that requires usermode access will fail after this commit.

If __setup_vm() is changed to setup_vm(), KUT will build tests with PT_USER_MASK set on all PTEs. It is a better idea to move nNPT tests to their own file so that tests don't need to fiddle with page tables midway.

The quick approach to do this would be to turn the current main into a small helper, without calling __setup_vm() from helper.

There are three patches in this patch series
1) Turned current main into helper function minus setup_vm()
2) Moved all nNPT test cases from svm_tests.c to svm_npt.c
3) Change __setup_vm to setup_vm() on svm_tests.c

Manali Shukla (3):
x86: nSVM: Move common functionality of the main() to helper
run_svm_tests
x86: nSVM: Move all nNPT test cases from svm_tests.c to a seperate
file.
x86: nSVM: Allow nSVM tests run with PT_USER_MASK enabled

Quoted 9 lines
 x86/Makefile.common |   2 +
 x86/Makefile.x86_64 |   2 +
 x86/svm.c           |   6 +-
 x86/svm.h           |   1 +
 x86/svm_npt.c       | 386 ++++++++++++++++++++++++++++++++++++++++++++
 x86/svm_tests.c     | 369 +-----------------------------------------
 6 files changed, 398 insertions(+), 368 deletions(-)
 create mode 100644 x86/svm_npt.c

A gentle reminder for review

Thanks
Manali

maintainer
#5 lore raw
In reply to Manali Shukla
Quoted 10 lines · Manali Shukla

Commit 916635a813e975600335c6c47250881b7a328971
(nSVM: Add test for NPT reserved bit and #NPF error code behavior) clears PT_USER_MASK for all svm testcases. Any tests that requires usermode access will fail after this commit.

If __setup_vm() is changed to setup_vm(), KUT will build tests with PT_USER_MASK set on all PTEs. It is a better idea to move nNPT tests to their own file so that tests don't need to fiddle with page tables midway.

Quoted 7 lines

The quick approach to do this would be to turn the current main into a small helper, without calling __setup_vm() from helper.

There are three patches in this patch series
1) Turned current main into helper function minus setup_vm()
2) Moved all nNPT test cases from svm_tests.c to svm_npt.c
3) Change __setup_vm to setup_vm() on svm_tests.c

What ideas do you have for SVM tests that require usermode access in the test (not in the guest)?

Paolo

#6 lore raw
Quoted 14 lines · Paolo Bonzini
Quoted 13 lines · Manali Shukla

Commit 916635a813e975600335c6c47250881b7a328971
(nSVM: Add test for NPT reserved bit and #NPF error code behavior) clears PT_USER_MASK for all svm testcases. Any tests that requires usermode access will fail after this commit.

If __setup_vm() is changed to setup_vm(), KUT will build tests with PT_USER_MASK set on all PTEs. It is a better idea to move nNPT tests to  their own file so that tests don't need to fiddle with page tables midway.

The quick approach to do this would be to turn the current main into a small helper, without calling __setup_vm() from helper.

Quoted 9 lines
Quoted 4 lines

There are three patches in this patch series
1) Turned current main into helper function minus setup_vm()
2) Moved all nNPT test cases from svm_tests.c to svm_npt.c
3) Change __setup_vm to setup_vm() on svm_tests.c

What ideas do you have for SVM tests that require usermode access in the test (not in the guest)?

Paolo

I have tried running the user mode function from L1 guest, with setup_vm(), this seems to be working fine.

But I am not very clear about your ask for svm tests which require usermode access in the test (not in the guest).
Can you please elaborate on it if possible?
Are there any sample tests you are referring to which I can check out.

Thank you
Manali