Xen Test Framework
vmxon.c
Go to the documentation of this file.
1#include "test.h"
2
3/* vmxon region which shouldn't be latched in the hardware vmxon pointer. */
5
6/* vmxon region which gets latched in hardware. */
8
9/* Loaded VMCS, to recover VM Instruction Errors. */
11
17static void test_vmxon_novmxe(void)
18{
19 check(__func__, stub_vmxon(0), EXINFO_SYM(UD, 0));
20}
21
22/*
23 * Wrapper around stub_vmxon_user(), This stub should always fault for control
24 * or permission reasons, but pointing at a supervisor frame is useful to
25 * check that Xen doesn't dereference the instructions parameter.
26 */
27static unsigned long __user_text vmxon_in_user(void)
28{
30}
31
38{
40
41 check(__func__, ex, EXINFO_SYM(UD, 0));
42}
43
49static void test_vmxon_in_user(void)
50{
52
53 check(__func__, ex, EXINFO_SYM(GP, 0));
54}
55
62{
63 exinfo_t ex = stub_vmxon(1ULL << maxphysaddr);
64
65 check(__func__, ex, VMERR_INVALID);
66}
67
74{
76
77 check(__func__, ex, VMERR_INVALID);
78}
79
86{
89
90 check(__func__, ex, VMERR_INVALID);
91}
92
98static void test_vmxon_revid_bit31(void)
99{
102
103 check(__func__, ex, VMERR_INVALID);
104}
105
111static void test_vmxon_correct(void)
112{
115
116 check(__func__, ex, VMERR_SUCCESS);
117}
118
125{
128
129 check(__func__, ex, VMERR_INVALID);
130}
131
138{
141
142 check(__func__, ex, EXINFO_SYM(GP, 0));
143}
144
150static void test_vmxon_in_root_cpl0(void)
151{
154
155 check(__func__, ex, VMERR_VALID(VMERR_VMXON_IN_ROOT));
156}
157
163static void test_vmxon_in_root_user(void)
164{
167
168 check(__func__, ex, EXINFO_SYM(GP, 0));
169}
170
171void test_vmxon(void)
172{
173 unsigned long cr4 = read_cr4();
174 exinfo_t ex;
175
176 if ( cr4 & X86_CR4_VMXE )
177 write_cr4(cr4 &= ~X86_CR4_VMXE);
178
179 printk("Test: vmxon\n");
180
183
184 write_cr4(cr4 | X86_CR4_VMXE);
185
192
193 /* Test should now be operating in VMX Root mode. */
194
197
198 /* Load a real VMCS to recover VM Instruction Errors. */
200 ex = stub_vmptrld(_u(vmcs));
201 if ( ex )
202 return xtf_failure("Fail: unexpected vmptrld failure %08x\n", ex);
203
206}
207
208/*
209 * Local variables:
210 * mode: C
211 * c-file-style: "BSD"
212 * c-basic-offset: 4
213 * tab-width: 4
214 * indent-tabs-mode: nil
215 * End:
216 */
unsigned int maxphysaddr
Definition: setup.c:28
static unsigned long read_cr4(void)
Definition: lib.h:252
static void write_cr4(unsigned long cr4)
Definition: lib.h:285
#define __user_text
Definition: compiler.h:33
#define __page_aligned_bss
Definition: compiler.h:37
void printk(const char *fmt,...)
Definition: console.c:134
#define EXINFO_SYM(exc, ec)
Definition: exinfo.h:29
unsigned int exinfo_t
Packed exception and error code information.
Definition: exinfo.h:19
static unsigned long exec_user(unsigned long(*fn)(void))
Definition: lib.h:62
#define GP
#define _u(v)
Express an arbitrary value v as unsigned long.
Definition: numbers.h:53
#define PAGE_SIZE
Definition: page.h:11
#define X86_CR4_VMXE
Definition: processor.h:56
void xtf_failure(const char *fmt,...)
Report a test failure.
Definition: report.c:94
__UINT8_TYPE__ uint8_t
Definition: stdint.h:14
#define VMERR_INVALID
Definition: test.h:16
void check(const char *func, exinfo_t got, exinfo_t exp)
Compare an expectation against what really happenend, printing human-readable information in case of ...
Definition: util.c:37
uint32_t vmcs_revid
Hardware VMCS Revision ID.
Definition: util.c:53
exinfo_t stub_vmxon_user(uint64_t paddr)
Definition: util.c:129
#define VMERR_VALID(x)
Definition: test.h:17
#define VMERR_SUCCESS
Definition: test.h:15
exinfo_t stub_vmptrld(uint64_t paddr)
Definition: util.c:103
static void clear_vmcs(void *_vmcs, uint32_t rev)
Definition: test.h:33
exinfo_t stub_vmxon(uint64_t paddr)
Definition: util.c:77
static void test_vmxon_novmxe_in_user(void)
vmxon in CPL=3 outside of VMX operation
Definition: vmxon.c:37
static void test_vmxon_revid_bit31(void)
vmxon with VMCS revision ID[31] set
Definition: vmxon.c:98
void test_vmxon(void)
Definition: vmxon.c:171
static void test_vmxon_novmcs_in_root_user(void)
vmxon in VMX root w/ CPL = 3 and w/o current VMCS
Definition: vmxon.c:137
static void test_vmxon_novmcs_in_root_cpl0(void)
vmxon in VMX root w/ CPL = 0 and w/o current VMCS
Definition: vmxon.c:124
static void test_vmxon_in_root_cpl0(void)
vmxon in VMX root w/ CPL = 0 and w/ current VMCS
Definition: vmxon.c:150
static unsigned long vmxon_in_user(void)
Definition: vmxon.c:27
static void test_vmxon_novmxe(void)
vmxon with CR4.VMXE cleared
Definition: vmxon.c:17
static uint8_t vmcs[PAGE_SIZE]
Definition: vmxon.c:10
static uint8_t vmxon_region_unused[PAGE_SIZE]
Definition: vmxon.c:4
static void test_vmxon_overly_wide_paddr(void)
vmxon with a physical address that exceeds the maximum address width
Definition: vmxon.c:61
static void test_vmxon_unaligned_paddr(void)
vmxon with an unaligned physical address
Definition: vmxon.c:73
static void test_vmxon_in_user(void)
vmxon in CPL=3 in VMX operation
Definition: vmxon.c:49
static void test_vmxon_mismatched_revid(void)
vmxon with VMCS revision ID mismatched with MSR_IA32_VMX_BASIC
Definition: vmxon.c:85
static void test_vmxon_correct(void)
vmxon expected to succeed
Definition: vmxon.c:111
static void test_vmxon_in_root_user(void)
vmxon in VMX root w/ CPL = 3 and w/ current VMCS
Definition: vmxon.c:163
static uint8_t vmxon_region_real[PAGE_SIZE]
Definition: vmxon.c:7
#define VMERR_VMXON_IN_ROOT
Definition: x86-vmx.h:24