Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
i386: hvf: Implement CPU kick
HVF doesn't have a CPU kick and without it it's not possible to perform an action on CPU thread until a VMEXIT happens. The kick is also needed for timely interrupt delivery. Existing implementation of CPU kick sends SIG_IPI (aka SIGUSR1) to vCPU thread, but it's different from what hv_vcpu_interrupt does. The latter one results in invocation of mp_cpus_kick() in XNU kernel [1]. mp_cpus_kick() sends an IPI through the host LAPIC to the HVF vCPU. And the kick interrupt leads to VM exit because "external-interrupt exiting” VM-execution control is enabled for HVF. hv_vcpu_interrupt() has no effect if it's delivered when vCPU is outside of a guest, therefore to avoid kick loss it's complemented with a SIG_IPI handler and zero VMX-preemption timer. If the kick happens outside of hv_vcpu_run(), the signal handler will re-queue the kick by setting exit_request. exit_request is cleared when the request is satisfied, i.e. when vCPU thread returns with EXCP_INTERRUPT. So we get the following scenarios time/location-wise for the kick: 1) vCPU thread is far away before hv_vcpu_run(), then exit_request is scheduled. As soon as vCPU thread approaches hv_vcpu_run(), the exit request is satisfied. 2) vCPU thread is about to enter the guest, then VMX-preemption timer is enabled to expedite immediate VM-exit. The VMX-preemption timer is then cleared in VM-exit handler, exit from vCPU thread is performed. 3) The guest is running, then hv_vcpu_run() is interrupted by hv_vcpu_interrupt() and vCPU thread quits. 4) vCPU thread has just made VM-exit, then exit_request is recorded and VMX-preemption timer is enabled but the exit request won't be satisfied until the next iteration of vCPU thread, no kick loss happens. 5) vCPU thread is far after hv_vcpu_run(), then exit_request is recorded and VMX-preemption timer is not enabled. The exit request will be satisfied on the next iteration of vCPU thread, like in 4). The kick is not lost. 6) If some external interrupt happens we can satisfy exit request and can clear VMX-preemption timer, i.e. kicks are coalesced with interrupts. 1. https://opensource.apple.com/source/xnu/xnu-6153.81.5/osfmk/i386/mp.c Cc: Cameron Esfahani <dirty@apple.com> Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
- Loading branch information
Showing
6 changed files
with
72 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters