Skip to content

Commit 21409b9

Browse files
committed
fix(vcpu): correct exit reason handling in vmexit trampoline
- Update vmexit_trampoline to properly save and restore exit reason - Modify Aarch64VCpu::run to return exit reason instead of dummy value - These changes ensure correct handling of VM exits and improve code clarity
1 parent f7ccb6d commit 21409b9

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/exception.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,14 @@ fn dispatch_irq() {
263263
#[no_mangle]
264264
unsafe extern "C" fn vmexit_trampoline() {
265265
core::arch::asm!(
266+
"mov x6, x0", // Save the exit reason.
266267
"bl {vcpu_running}", // Check if vcpu is running.
268+
"mov x7, x0", // Save the return value of vcpu_running.
269+
"mov x0, x6", // Restore the exit reason.
267270
// If vcpu_running returns true, jump to `return_run_guest`,
268271
// after that the control flow is handed back to Aarch64VCpu.run(),
269272
// simulating the normal return of the `run_guest` function.
270-
"cbnz x0, {return_run_guest}",
273+
"cbnz x7, {return_run_guest}",
271274
// If vcpu_running returns false, there is no active vcpu running,
272275
// jump to `dispatch_irq`.
273276
"bl {dispatch_irq}",

src/vcpu.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,14 @@ impl<H: AxVCpuHal> Aarch64VCpu<H> {
222222
options(nostack)
223223
);
224224

225-
// the dummy return value, the real return value is in x0 when `return_run_guest` returns
226-
0
225+
// Return value is the exit reason, the real return value is in x0 when `return_run_guest` returns
226+
let exit_reason: usize;
227+
core::arch::asm!(
228+
"mov {}, x0",
229+
out(reg) exit_reason,
230+
options(nostack)
231+
);
232+
exit_reason
227233
}
228234

229235
/// Restores guest system control registers.

0 commit comments

Comments
 (0)