Skip to content

Commit

Permalink
Fix exiting on CR0 write for unrestricted guests (#883)
Browse files Browse the repository at this point in the history
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 <krystian.hebel@3mdeb.com>
  • Loading branch information
krystian-hebel authored and rianquinn committed Jan 10, 2020
1 parent 363814b commit 3dbd895
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions bfvmm/src/hve/arch/intel_x64/vcpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -891,15 +891,33 @@ vcpu::disable_preemption_timer()
void
vcpu::set_eptp(ept::mmap &map)
{
using namespace ::intel_x64::vmcs;
using namespace ::intel_x64::cr0;

m_ept_handler.set_eptp(&map);
m_mmap = &map;

// Disable exiting on changes to CR0.PG and CR0.PE.
//
// They were enabled by vCPU constructor for systems not using unrestricted
// guests. This led to different treatment of mode changes on BSP than APs,
// and as a result to inability to use some modes on BSP (e.g. 32b mode
// without PAE).
cr0_guest_host_mask::set(cr0_guest_host_mask::get() & ~(paging::mask | protection_enable::mask));
m_control_register_handler.enable_wrcr0_exiting(cr0_guest_host_mask::get());
}

void
vcpu::disable_ept()
{
using namespace ::intel_x64::vmcs;
using namespace ::intel_x64::cr0;

m_ept_handler.set_eptp(nullptr);
m_mmap = nullptr;

cr0_guest_host_mask::set(cr0_guest_host_mask::get() | (paging::mask | protection_enable::mask));
m_control_register_handler.enable_wrcr0_exiting(cr0_guest_host_mask::get());
}

//==========================================================================
Expand Down

0 comments on commit 3dbd895

Please sign in to comment.