Repository navigation
kexec: refuse to unload a multikernel instance that is running - #57
Conversation
|
Thanks, the bug is real: the unload path has never looked at the instance state (only The
Could you respin with the ACTIVE check on unload and the parked check on the multikernel load path instead? Also, the second sentence of the code comment is hard to follow without the commit message. |
KEXEC_FILE_UNLOAD frees a multikernel image without looking at its instance. For a running instance, kimage_free_multikernel() returns the image's segments, which hold the running kernel, to the instance pool, drops its IPI ring and moves it back to READY. The next load into that instance then copies a new image over the kernel that is still executing there, and the host has no way left to halt it. Return -EBUSY from unload while the instance is ACTIVE. A halt settles the instance to LOADED before its CPUs reach the park loop, so a CPU can still run in the segments after a halt too. Handing them back to the pool is harmless by itself; the damage is the next load copying into them. Check that the instance's CPUs are parked on the multikernel load path, as a reload of the instance already does, rather than on unload, so an instance with a CPU that never parked can still be unloaded and its teardown reaches the leak path in mk_instance_free_memory(). Fixes: b6e539f ("kexec: Integrate multikernel support with kexec_file_load()") Signed-off-by: Utkarsh Maurya <projects.utkarshMaurya@gmail.com>
d4de6da to
d966b1d
Compare
|
Respun on current master: the ACTIVE check stays on unload, the parked check moved to the multikernel load path, before the new image is allocated from the instance pool, and the comment is rewritten. The load check still runs under the kexec lock, but Tested on RISC-V QEMU with a test-only knob making |
KEXEC_FILE_UNLOADfrees a multikernel image without looking at its instance. For a running instance,kimage_free_multikernel()hands the segments that hold the running kernel back to the instance pool, drops its IPI ring and moves it to READY. The next load then copies a new image over the kernel still executing there, and the host can no longer halt it.-EBUSYwhile the instance is ACTIVE.mk_instance_confirm_parked(), the check a reload already makes). It sits before the new image is allocated from the instance pool, so an instance with a CPU that never parked can still be unloaded, and its teardown reaches the leak path inmk_instance_free_memory().Tested: RISC-V QEMU virt (aia=aplic-imsic, OpenSBI v1.8.1) on master 2017469, with a test-only knob making
mk_instance_confirm_parked()report a CPU as not parked:Spawn, graceful and forced halt, and re-spawn also pass; dmesg clean with lockdep. Builds: x86_64 clang W=1 with MULTIKERNEL=y and =n, no new warnings; checkpatch --strict clean.