Skip to contentSkip to conversation

About UMIP unit test.

PATCH In review Yu Zhang 3 participants 9 messages Mar 2, 2017 Xen hypervisor interface

lore
Share & tools
lore

Yu Zhang

author
#0 lore raw

Hi Jan,

Previously I saw your UMIP patches merged in xen, and we'd like to
try some unit test here in Intel. And I wonder do you have any unit test code for this feature, or any suggestions? :)

Thanks
Yu

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

#1 lore raw
Quoted 5 lines · Yu Zhang

Hi Jan,

Previously I saw your UMIP patches merged in xen, and we'd like to
try some unit test here in Intel. And I wonder do you have any unit test code for this feature, or any suggestions? :)

There is support in the x86 emulator to handle UMIP correctly in the case that it is found set in CR4. However, the logic to emulate UMIP on non-UMIP-capable hardware has not been merged yet.

As for unit tests, if you use
http://xenbits.xen.org/gitweb/?p=xtf.git;a=blob;f=tests/cpuid-faulting/main.c;hb=HEAD
as an example, making a unit test should hopefully be trivial.

General docs can be found here http://xenbits.xen.org/docs/xtf/ and 'd be happy to answer any other questions you have on XTF, should you choose to use it.

~Andrew

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

#2 lore raw

cover UMIP test case

In reply to Yu Zhang

I wrote this long time ago before UMIP was merged.

Yu, since you asked, I might as well post it for your reference on how to do it with XTF.

This series is not yet tested in any way.

Wei Liu (2):
x86: add UMIP feature bit
Add UMIP test

 include/arch/x86/processor.h         |   1 +
 include/xen/arch-x86/cpufeatureset.h |   1 +
 tests/umip/Makefile                  |   9 ++++
 tests/umip/main.c                    | 102 +++++++++++++++++++++++++++++++++++
 4 files changed, 113 insertions(+)
 create mode 100644 tests/umip/Makefile
 create mode 100644 tests/umip/main.c
Signature · 7 lines
2.11.0


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

PATCH 1/2 x86: add UMIP feature bit

Strangely there was already one cpu_has_umip defined, so there is no need for one in this patch.

---
 include/arch/x86/processor.h         | 1 +
 include/xen/arch-x86/cpufeatureset.h | 1 +
 2 files changed, 2 insertions(+)
include/arch/x86/processor.h +1 -0
index 0106954..e2a2cbb 100644
@@ -52,6 +52,7 @@
 #define X86_CR4_PCE             0x00000100  /* Performance counters at ipl 3  */
 #define X86_CR4_OSFXSR          0x00000200  /* Fast FPU save and restore      */
 #define X86_CR4_OSXMMEXCPT      0x00000400  /* Unmasked SSE exceptions        */
+#define X86_CR4_UMIP            0x00000800  /* UMIP                           */
 #define X86_CR4_VMXE            0x00002000  /* VMX                            */
 #define X86_CR4_SMXE            0x00004000  /* SMX                            */
 #define X86_CR4_FSGSBASE        0x00010000  /* {rd,wr}{fs,gs}base             */
include/xen/arch-x86/cpufeatureset.h +1 -0
index 905e8e8..f66a4ab 100644
@@ -144,6 +144,7 @@
 
 /* Intel-defined CPU features, CPUID level 0x00000007:0.ecx, word 6 */
 #define X86_FEATURE_PREFETCHWT1   (6*32+ 0) /* PREFETCHWT1 instruction */
+#define X86_FEATURE_UMIP          (6*32+ 2) /* User-Mode Instruction Prevention */
 #define X86_FEATURE_PKU           (6*32+ 3) /* Protection Keys for Userspace */
 #define X86_FEATURE_OSPKE         (6*32+ 4) /* OS Protection Keys Enable */
 
Signature · 7 lines
2.11.0


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

PATCH 2/2 Add UMIP test

In reply to Wei Liu
---
 tests/umip/Makefile |   9 +++++
 tests/umip/main.c   | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 111 insertions(+)
 create mode 100644 tests/umip/Makefile
 create mode 100644 tests/umip/main.c
tests/umip/Makefile new file +9 -0
new file mode 100644
index 0000000..a74016c
@@ -0,0 +1,9 @@
+include $(ROOT)/build/common.mk
+
+NAME      := umip
+CATEGORY  := functional
+TEST-ENVS := hvm32
+
+obj-perenv += main.o
+
+include $(ROOT)/build/gen.mk
tests/umip/main.c new file +102 -0

102 lines not on this page · raw message

Signature · 7 lines
2.11.0


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

Re: [DO NOT APPLY PATCH XTF 0/2] UMIP test case

In reply to Wei Liu
Quoted 6 lines · Wei Liu

I wrote this long time ago before UMIP was merged.

Yu, since you asked, I might as well post it for your reference on how to do it with XTF.

This series is not yet tested in any way.

Unfortunately, you execute all of the sensitive instructions in kernel mode, where they wouldn't fault even with UMIP active.

For full testing of a feature like this, the test should include a check that the ability to modify CR4.UMIP depends strictly on the visibility of the feature, that uses in the kernel still continue to work, even when active, and that behaviour returns back to normal after the feature has been deactivated.

The first patch however, is fine to go in.

~Andrew

(I am also going to pretend I didn't see those macros :) )

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

#6 lore raw

Re: [DO NOT APPLY PATCH XTF 0/2] UMIP test case

Quoted 8 lines · Andrew Cooper
Quoted 6 lines · Wei Liu

I wrote this long time ago before UMIP was merged.

Yu, since you asked, I might as well post it for your reference on how to do it with XTF.

This series is not yet tested in any way.

Quoted 9 lines

Unfortunately, you execute all of the sensitive instructions in kernel mode, where they wouldn't fault even with UMIP active.

For full testing of a feature like this, the test should include a check that the ability to modify CR4.UMIP depends strictly on the visibility of the feature, that uses in the kernel still continue to work, even when active, and that behaviour returns back to normal after the feature has been deactivated.

I'm pretty sure there are bugs. :-)

Quoted 1 line

The first patch however, is fine to go in.

Feel free to pick it up in your next batch.

Quoted 4 lines

~Andrew

(I am also going to pretend I didn't see those macros :) )

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

author
#7 lore raw

Re: [DO NOT APPLY PATCH XTF 0/2] UMIP test case

In reply to Andrew Cooper

Wah. Thank you, Andrew & Wei. :-)

Quoted 7 lines · Andrew Cooper
Quoted 6 lines · Wei Liu

I wrote this long time ago before UMIP was merged.

Yu, since you asked, I might as well post it for your reference on how to do it with XTF.

This series is not yet tested in any way.

Quoted 8 lines

Unfortunately, you execute all of the sensitive instructions in kernel mode, where they wouldn't fault even with UMIP active.

For full testing of a feature like this, the test should include a check that the ability to modify CR4.UMIP depends strictly on the visibility of the feature, that uses in the kernel still continue to work, even when active, and that behaviour returns back to normal after the feature has been deactivated.

So, before cr4 is written, a cpuid is needed first in the test code, right?

But besides the emulation of cpuid and cr4, my understanding is that hypervisor need to inject a GP fault if an instruction causes a VM exit, right? This should be different than the normal GP fault inside a VM, and how do we test this code path?

Our QA and I may need to have a study of the XTF, and may probably seek for your help in the future. :-) Anyway, thanks a lot!

Yu

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

#8 lore raw

Re: [DO NOT APPLY PATCH XTF 0/2] UMIP test case

Quoted 14 lines · Yu Zhang

Wah. Thank you, Andrew & Wei. :-)

Quoted 11 lines · Andrew Cooper
Quoted 7 lines · Wei Liu

I wrote this long time ago before UMIP was merged.

Yu, since you asked, I might as well post it for your reference on how to
do it with XTF.

This series is not yet tested in any way.

Unfortunately, you execute all of the sensitive instructions in kernel mode, where they wouldn't fault even with UMIP active.

Quoted 8 lines
Quoted 5 lines

For full testing of a feature like this, the test should include a check that the ability to modify CR4.UMIP depends strictly on the visibility of the feature, that uses in the kernel still continue to work, even when active, and that behaviour returns back to normal after the feature has been deactivated.

So, before cr4 is written, a cpuid is needed first in the test code, right?

Yes, but that is performed automatically by the framework for convenience. The predicate cpu_has_umip will work fine for your test.

Quoted 5 lines

But besides the emulation of cpuid and cr4, my understanding is that hypervisor need to inject a GP fault if an instruction causes a VM exit, right? This should be different than the normal GP fault inside a VM, and how do we test this code path?

Using the Force Emulation Prefix. This breaks out to the hypervisor and runs the instruction through the emulator. You should test both that the native instructions behave as expected, and that once forced, the instructions also behave sensibly.

The FEP test is to cover alternative cases with would require emulation normally (e.g. memory operand hitting an MMIO region, or the page marked NX in EPT because of VM instrospection being active).

Quoted 4 lines

Our QA and I may need to have a study of the XTF, and may probably seek for your help in the future. :-)
Anyway, thanks a lot!

Haozhong (CC'd) has previously used XTF for a load of nested-virt testing, if you'd like an alternative opinion, (although I do hope you find XTF easy to use and useful).

~Andrew

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