Skip to contentSkip to conversation

Functional: Add a UMIP test

PATCH In review Boqun Feng (Intel) 3 participants 3 messages Aug 15, 2017 x86

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 Functional: Add a UMIP test

Add a "umip" test for the User-Model Instruction Prevention. The test simply tries to run sgdt/sidt/sldt/str/smsw in guest user-mode with CR4_UMIP = 1.

---
v1 --> v2:
* add a new write_cr4_safe()
* use %pe for exception print
* refactor the code based on Andrew's guide and advice
v2 --> v3:
* add test_insns() to simplify test_main() logic
* make write_cr4_safe() return 0 for success.
* add UMIP activation test even if !cpu_has_umip

Test results:

* With UMIP patch:
** boot with hvm_fep: SUCCESS
** boot without hvm_fep: SKIP

* Without UMIP patch:
** boot with hvm_fep: SKIP
** boot without hvm_fep: SKIP

(illed implementation)
* With UMIP cpuid exposed but hvm_cr4_guest_valid_bits() didn't include X86_CR4_UMIP:
** boot with hvm_fep: FAILURE, due to "Fail: Unable to activate UMIP.." ** boot without hvm_fep: FAILURE, due to "Fail: Unable to activate UMIP.."

* With UMIP cpuid not exposed but hvm_cr4_guest_valid_bits() included X86_CR4_UMIP:
** boot with hvm_fep: FAILURE, due to "UMIP unsupported, but setting CR4 succeeded" ** boot without hvm_fep: FAILURE, due to "UMIP unsupported, but setting CR4 succeeded"

 arch/x86/include/arch/lib.h |  13 +++
 docs/all-tests.dox          |   2 +
 tests/umip/Makefile         |   9 ++
 tests/umip/main.c           | 214 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 238 insertions(+)
 create mode 100644 tests/umip/Makefile
 create mode 100644 tests/umip/main.c
arch/x86/include/arch/lib.h +13 -0
index f608af9996f0..82eb7da600c4 100644
@@ -340,6 +340,19 @@ static inline void write_cr4(unsigned long cr4)
     asm volatile ("mov %0, %%cr4" :: "r" (cr4));
 }
 
+static inline bool write_cr4_safe(unsigned long cr4)
+{
+    exinfo_t fault = 0;
+
+    asm volatile ("1: mov %1, %%cr4; 2:"
+                  _ASM_EXTABLE_HANDLER(1b, 2b, ex_record_fault_edi)
+                  : "+D" (fault)
+                  : "r" (cr4),
+                    "X" (ex_record_fault_edi));
+
+    return fault;
+}
+
 static inline void write_cr8(unsigned long cr8)
 {
     asm volatile ("mov %0, %%cr8" :: "r" (cr8));
docs/all-tests.dox +2 -0
index c1b163a926cb..ef011007cf68 100644
@@ -111,4 +111,6 @@ guest breakout.
 @section index-in-development In Development
 
 @subpage test-vvmx - Nested VT-x tests.
+
+@subpage test-umip - User-Mode Instruction Prevention
 */
tests/umip/Makefile new file +9 -0
new file mode 100644
index 000000000000..0248c8b247a0
@@ -0,0 +1,9 @@
+include $(ROOT)/build/common.mk
+
+NAME      := umip
+CATEGORY  := functional
+TEST-ENVS := hvm32 hvm64
+
+obj-perenv += main.o
+
+include $(ROOT)/build/gen.mk
tests/umip/main.c new file +214 -0

214 lines not on this page · raw message

Signature · 7 lines
2.13.3


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v3 1/1
#1 lore raw
Quoted 5 lines · Boqun Feng (Intel)

Add a "umip" test for the User-Model Instruction Prevention. The test simply tries to run sgdt/sidt/sldt/str/smsw in guest user-mode with CR4_UMIP = 1.

It turns out there were some tabs lurking, which I fixed up. I also tweaked the documentation a little.

This test will now find its way automatically into OSSTest.

Out of interest (and I can't recall if I've asked this yet; if so, sorry for being forgetful), which processor line is UMIP going to be available in?

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#2 lore raw
Quoted 8 lines · Andrew Cooper
Quoted 5 lines · Boqun Feng (Intel)

Add a "umip" test for the User-Model Instruction Prevention. The test simply tries to run sgdt/sidt/sldt/str/smsw in guest user-mode with CR4_UMIP = 1.

Quoted 7 lines

It turns out there were some tabs lurking, which I fixed up. I also tweaked the documentation a little.

This test will now find its way automatically into OSSTest.

Out of interest (and I can't recall if I've asked this yet; if so, sorry for being forgetful), which processor line is UMIP going to be available in?

I guess should be in icelake. :-)

Yu

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel