Skip to content

Commit 3dbd895

Browse files
krystian-hebelrianquinn
authored andcommitted
Fix exiting on CR0 write for unrestricted guests (#883)
vcpu::set_eptp() didn't disable exiting on writes to CR0. On the first run (BSP) handlers were set as if there was no support for unrestricted guests. Default handler for CR0 writes called emulate_ia_32e_mode_switch(), which doesn't allow for switches between all modes. Signed-off-by: Krystian Hebel <[email protected]>
1 parent 363814b commit 3dbd895

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

bfvmm/src/hve/arch/intel_x64/vcpu.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -891,15 +891,33 @@ vcpu::disable_preemption_timer()
891891
void
892892
vcpu::set_eptp(ept::mmap &map)
893893
{
894+
using namespace ::intel_x64::vmcs;
895+
using namespace ::intel_x64::cr0;
896+
894897
m_ept_handler.set_eptp(&map);
895898
m_mmap = &map;
899+
900+
// Disable exiting on changes to CR0.PG and CR0.PE.
901+
//
902+
// They were enabled by vCPU constructor for systems not using unrestricted
903+
// guests. This led to different treatment of mode changes on BSP than APs,
904+
// and as a result to inability to use some modes on BSP (e.g. 32b mode
905+
// without PAE).
906+
cr0_guest_host_mask::set(cr0_guest_host_mask::get() & ~(paging::mask | protection_enable::mask));
907+
m_control_register_handler.enable_wrcr0_exiting(cr0_guest_host_mask::get());
896908
}
897909

898910
void
899911
vcpu::disable_ept()
900912
{
913+
using namespace ::intel_x64::vmcs;
914+
using namespace ::intel_x64::cr0;
915+
901916
m_ept_handler.set_eptp(nullptr);
902917
m_mmap = nullptr;
918+
919+
cr0_guest_host_mask::set(cr0_guest_host_mask::get() | (paging::mask | protection_enable::mask));
920+
m_control_register_handler.enable_wrcr0_exiting(cr0_guest_host_mask::get());
903921
}
904922

905923
//==========================================================================

0 commit comments

Comments
 (0)