Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hvf: ensure vcpus run in the right thread #242

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions src/hvf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,14 @@ impl HvfVcpu<'_> {
return Err(Error::VcpuCreate);
}

// We write vcpuid to Aff1 as otherwise it won't match the redistributor ID
// when using HVF in-kernel GICv3.
let ret =
unsafe { hv_vcpu_set_sys_reg(vcpuid, hv_sys_reg_t_HV_SYS_REG_MPIDR_EL1, vcpuid << 8) };
if ret != HV_SUCCESS {
return Err(Error::VcpuCreate);
}

let vcpu_exit: &hv_vcpu_exit_t = unsafe { vcpu_exit_ptr.as_mut().unwrap() };

Ok(Self {
Expand Down
12 changes: 6 additions & 6 deletions src/vmm/src/macos/vstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,7 @@ impl Vcpu {
self.init_thread_local_data()
.expect("Cannot cleanly initialize vcpu TLS.");

init_tls_sender
.send(true)
.expect("Cannot notify vcpu TLS initialization.");

self.run();
self.run(init_tls_sender);
})
.map_err(Error::VcpuSpawn)?;

Expand Down Expand Up @@ -462,10 +458,14 @@ impl Vcpu {
}

/// Main loop of the vCPU thread.
pub fn run(&mut self) {
pub fn run(&mut self, init_tls_sender: Sender<bool>) {
let mut hvf_vcpu = HvfVcpu::new().expect("Can't create HVF vCPU");
let hvf_vcpuid = hvf_vcpu.id();

init_tls_sender
.send(true)
.expect("Cannot notify vcpu TLS initialization.");

let (wfe_sender, wfe_receiver) = unbounded();
self.vcpu_list.register(hvf_vcpuid, wfe_sender);
self.intc.lock().unwrap().add_vcpu();
Expand Down
Loading