[kvm-unit-tests PATCH v3 17/27] svm: correctly skip if NPT not supported

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Fail SVM setup when NPT is not supported

Signed-off-by: Maxim Levitsky <mlevitsk@xxxxxxxxxx>
---
 lib/x86/svm_lib.c | 16 ++++++++++------
 lib/x86/svm_lib.h |  2 +-
 x86/svm.c         |  3 ++-
 3 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/lib/x86/svm_lib.c b/lib/x86/svm_lib.c
index cb80f08f..c7194909 100644
--- a/lib/x86/svm_lib.c
+++ b/lib/x86/svm_lib.c
@@ -77,11 +77,18 @@ static void setup_npt(void)
 	__setup_mmu_range(pml4e, 0, size, X86_MMU_MAP_USER);
 }
 
-void setup_svm(void)
+bool setup_svm(void)
 {
-	void *hsave = alloc_page();
+	void *hsave;
 	int i;
 
+	if (!npt_supported()) {
+		printf("NPT not detected - skipping SVM initialization\n");
+		return false;
+	}
+
+	hsave = alloc_page();
+
 	wrmsr(MSR_VM_HSAVE_PA, virt_to_phys(hsave));
 	wrmsr(MSR_EFER, rdmsr(MSR_EFER) | EFER_SVME);
 
@@ -89,14 +96,10 @@ void setup_svm(void)
 
 	msr_bitmap = (void *) ALIGN((ulong)msr_bitmap_area, PAGE_SIZE);
 
-	if (!npt_supported())
-		return;
 
 	for (i = 1; i < cpu_count(); i++)
 		on_cpu(i, (void *)set_additional_vcpu_msr, (void *)rdmsr(MSR_EFER));
 
-	printf("NPT detected - running all tests with NPT enabled\n");
-
 	/*
 	 * Nested paging supported - Build a nested page table
 	 * Build the page-table bottom-up and map everything with 4k
@@ -104,4 +107,5 @@ void setup_svm(void)
 	 */
 
 	setup_npt();
+	return true;
 }
diff --git a/lib/x86/svm_lib.h b/lib/x86/svm_lib.h
index b491eee6..f603ff93 100644
--- a/lib/x86/svm_lib.h
+++ b/lib/x86/svm_lib.h
@@ -49,7 +49,7 @@ static inline void clgi(void)
 	asm volatile ("clgi");
 }
 
-void setup_svm(void);
+bool setup_svm(void);
 
 u64 *npt_get_pte(u64 address);
 u64 *npt_get_pde(u64 address);
diff --git a/x86/svm.c b/x86/svm.c
index 9edf5500..cf246c37 100644
--- a/x86/svm.c
+++ b/x86/svm.c
@@ -264,7 +264,8 @@ int run_svm_tests(int ac, char **av, struct svm_test *svm_tests)
 		return report_summary();
 	}
 
-	setup_svm();
+	if (!setup_svm())
+		return 0;
 
 	vmcb = alloc_page();
 
-- 
2.34.3




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux