From c5d43657707f08562b2af21e90a16574f74d24be Mon Sep 17 00:00:00 2001 From: "Li, Fei1" Date: Wed, 29 May 2019 22:19:43 +0800 Subject: [PATCH] hv: vmcs: don't trap when setting reserved bit in cr0/cr4 According to Chap 23.8 RESTRICTIONS ON VMX OPERATION, Vol 3, SDM: "Any attempt to set one of these bits to an unsupported value while in VMX operation (including VMX root operation) using any of the CLTS, LMSW, or MOV CR instructions causes a general-protection exception." So we don't need to trap them out then inject the GP in hypervisor. Tracked-On: #2561 Signed-off-by: Li, Fei1 Acked-by: Anthony Xu --- hypervisor/arch/x86/guest/virtual_cr.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hypervisor/arch/x86/guest/virtual_cr.c b/hypervisor/arch/x86/guest/virtual_cr.c index 2dbd7cd2a..a2f386a03 100644 --- a/hypervisor/arch/x86/guest/virtual_cr.c +++ b/hypervisor/arch/x86/guest/virtual_cr.c @@ -311,6 +311,7 @@ void init_cr0_cr4_host_mask(void) cr0_host_owned_bits = ~(fixed0 ^ fixed1); /* Add the bit hv wants to trap */ cr0_host_owned_bits |= CR0_TRAP_MASK; + cr0_host_owned_bits &= ~CR0_RESERVED_MASK; /* CR0 clear PE/PG from always on bits due to "unrestructed guest" feature */ cr0_always_on_mask = fixed0 & (~(CR0_PE | CR0_PG)); cr0_always_off_mask = ~fixed1; @@ -327,6 +328,7 @@ void init_cr0_cr4_host_mask(void) cr4_host_owned_bits = ~(fixed0 ^ fixed1); /* Add the bit hv wants to trap */ cr4_host_owned_bits |= CR4_TRAP_MASK; + cr4_host_owned_bits &= ~CR4_RESERVED_MASK; cr4_always_on_mask = fixed0; /* Record the bit fixed to 0 for CR4, including reserved bits */ cr4_always_off_mask = ~fixed1;