Commit f441716d authored by Krish Sadhukhan's avatar Krish Sadhukhan Committed by Paolo Bonzini
Browse files

nVMX: Test vmentry of unrestricted (PG=0/PE=1) nested guest

According to section "UNRESTRICTED GUESTS" in SDM vol 3c, if the
"unrestricted guest" secondary VM-execution control is set, guests can run
in unpaged protected mode or in real mode. This patch tests vmentry of an
unrestricted guest in unpaged protected mode.

Signed-off-by: default avatarJim Mattson <>
Signed-off-by: default avatarKrish Sadhukhan <>
Message-Id: <>
Signed-off-by: default avatarPaolo Bonzini <>
parent 7820ac52
......@@ -1699,7 +1699,7 @@ static void test_vmx_caps(void)
/* This function can only be called in guest */
static void __attribute__((__used__)) hypercall(u32 hypercall_no)
void __attribute__((__used__)) hypercall(u32 hypercall_no)
u64 val = 0;
val = (hypercall_no & HYPERCALL_MASK) | HYPERCALL_BIT;
......@@ -895,6 +895,7 @@ bool ept_ad_bits_supported(void);
void __enter_guest(u8 abort_flag, struct vmentry_result *result);
void enter_guest(void);
void enter_guest_with_bad_controls(void);
void hypercall(u32 hypercall_no);
typedef void (*test_guest_func)(void);
typedef void (*test_teardown_func)(void *data);
......@@ -8229,6 +8229,53 @@ static void vmx_guest_state_area_test(void)
extern void unrestricted_guest_main(void);
asm (".code32\n"
"mov $1, %edi\n"
"call hypercall\n"
static void setup_unrestricted_guest(void)
vmcs_write(GUEST_CR0, vmcs_read(GUEST_CR0) & ~(X86_CR0_PG));
vmcs_write(ENT_CONTROLS, vmcs_read(ENT_CONTROLS) & ~ENT_GUEST_64);
vmcs_write(GUEST_EFER, vmcs_read(GUEST_EFER) & ~EFER_LMA);
vmcs_write(GUEST_RIP, virt_to_phys(unrestricted_guest_main));
static void unsetup_unrestricted_guest(void)
vmcs_write(GUEST_CR0, vmcs_read(GUEST_CR0) | X86_CR0_PG);
vmcs_write(ENT_CONTROLS, vmcs_read(ENT_CONTROLS) | ENT_GUEST_64);
vmcs_write(GUEST_EFER, vmcs_read(GUEST_EFER) | EFER_LMA);
vmcs_write(GUEST_RIP, (u64) phys_to_virt(vmcs_read(GUEST_RIP)));
vmcs_write(GUEST_RSP, (u64) phys_to_virt(vmcs_read(GUEST_RSP)));
* If "unrestricted guest" secondary VM-execution control is set, guests
* can run in unpaged protected mode.
static void vmentry_unrestricted_guest_test(void)
if (setup_ept(false))
test_skip("EPT not supported");
vmcs_write(CPU_EXEC_CTRL1, vmcs_read(CPU_EXEC_CTRL1) | CPU_URG);
test_guest_state("Unrestricted guest test", false, CPU_URG, "CPU_URG");
* Let the guest finish execution as a regular guest
vmcs_write(CPU_EXEC_CTRL1, vmcs_read(CPU_EXEC_CTRL1) & ~CPU_URG);
static bool valid_vmcs_for_vmentry(void)
struct vmcs *current_vmcs = NULL;
......@@ -10434,6 +10481,7 @@ struct vmx_test vmx_tests[] = {
/* APICv tests */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment