Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions openhcl/sidecar/src/arch/x86_64/vp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ fn run_vp(globals: &mut VpGlobals, command_page: &mut CommandPage, cpu_status: &

let mut intercept = false;
while cpu_status.load(Relaxed) != CpuStatus::STOP.0 {
match run_vp_once(command_page) {
match run_vp_once(command_page, globals.register_page_mapped) {
Ok(true) => {
intercept = true;
break;
Expand All @@ -276,7 +276,7 @@ fn run_vp(globals: &mut VpGlobals, command_page: &mut CommandPage, cpu_status: &
.unwrap(); // PANIC: will not panic, since sizeof(RunVpResponse) is 1, whereas the buffer is statically declared as 16 bytes long.
}

fn run_vp_once(command_page: &mut CommandPage) -> Result<bool, ()> {
fn run_vp_once(command_page: &mut CommandPage, register_page_mapped: bool) -> Result<bool, ()> {
let cpu_context = &mut command_page.cpu_context;
// Write rax and rcx to the VP assist page.
//
Expand Down Expand Up @@ -329,6 +329,16 @@ fn run_vp_once(command_page: &mut CommandPage) -> Result<bool, ()> {
let intercept_message =
unsafe { &*addr_of!((*addr_space::assist_page()).intercept_message) };
command_page.intercept_message = *intercept_message;

// Sync guest GP/XMM from the register page; cpu_context
// values are stale (VTL2 round-tripped on re-entry).
if register_page_mapped {
// SAFETY: the register page is mapped and not concurrently modified.
let reg = unsafe { &*addr_space::register_page() };
let xmm = reg.xmm.as_bytes().as_chunks::<16>().0;
command_page.cpu_context.gps = reg.gp_registers;
Comment thread
emirceski marked this conversation as resolved.
Outdated
command_page.cpu_context.fx_state.xmm[..xmm.len()].copy_from_slice(xmm);
Comment thread
emirceski marked this conversation as resolved.
Outdated
}
Ok(true)
}
entry_reason => {
Expand Down
Loading