#892

Guest reboot and power-off both exit 0, so callers can't tell them apart

Openwillieopened 1mo ago

A guest reboot and a guest power-off end the VM the same way: the process exits with 0.

A program running a long-lived guest (a desktop VM through krunkit, in my case) can't tell whether to start the VM again when the process exits, so after a guest reboot its user has to start it by hand.

Giving reset its own exit code by default would break libkrun's init. It ends every workload with reboot(RB_AUTOBOOT) (exec.rs#L107-L110), and reports the workload's exit code with an ioctl only when / is virtio-fs (exec.rs#L65-L76). With a block-device root, the vCPU's exit code becomes the process's, so a new default would turn those 0s into the new code.

Proposal: opt-in. krun_set_reset_exit_code(ctx_id, code) sets the process exit code for a guest reset; the default stays as it is. The exit code the guest sets through the ioctl still takes precedence. HVF, KVM and the i8042 path would all use it. krunkit would get a flag to pass it through.

Tested: macOS, v1.19.5, with a patch mapping SYSTEM_RESET to 32 (crosvm's VmReset): systemctl reboot in a Fedora guest exits 32, and systemctl poweroff exits 0.

Would this shape work? Or would you rather have something else, such as a callback, or a different default where no init is in use?

Activity

3
slp29d ago

Would this shape work? Or would you rather have something else, such as a callback, or a different default where no init is in use?

Sounds reasonable to me.

willie29d ago

Thanks! Since main is the 2.0 builder API, I'll add krun_vmm_builder_reset_exit_code(builder, code) there, and backport it to 1.19.x as krun_set_reset_exit_code(ctx_id, code) so krunkit can use it. Sound good?

willie13d ago

The patch I tested with, for reference: willie/libkrun@cbbca3a2 on v1.19.6. It's the quick version (HVF only, reset always exits 32), not the opt-in API proposed above.