cloud-hypervisor/virtio-devices/src
Alyssa Ross 287887c99c vmm: fix console IO safety
Rebooting a VM fails with the following error when debug assertions
are enabled:

	fatal runtime error: IO Safety violation: owned file descriptor already closed

This happens because FromRawFd::from_raw_fd is used on RawFds stored
in ConsoleInfo every time a VM begins to boot, so the second
time (after a reboot, or if the first attempt to boot via the API
failed), the fd will be closed.  Until this assertion is hit, the code
is operating on either closed file descriptors, or new file
descriptors for something completely different.  If debug assertions
are disabled, it will just continue doing this with unpredictable
results.

To fix this, and prevent the problem reocurring, ownership of the
console file descriptors needs to be properly tracked, using Rust's
type system, so this commit refactors the console code to do that.
The file descriptors are now passed around with reference counts, so
they won't be closed prematurely.  The obvious way to do this would be
to just have each member of ConsoleInfo be an Arc<File>, but we need
to accomodate that serial console file descriptors can also be
sockets.  We can't just store an OwnedFd and convert it when it's
used, because we only get a reference from the Arc, so we need to
store the descriptors as their concrete types in an enum.  Since this
basically duplicates the ConsoleOutputMode enum from the config, the
ConsoleOutputMode enum is now not used past constructing the
ConsoleInfo.

So that ownership can be represented consistently, the debug console's
tty mode now uses its own stdout descriptor.

I'm still using .try_clone().unwrap() (i.e. dup()) to clone file
descriptors for Endpoint::FilePair and Endpoint::TtyPair, because I
assume there's a reason for them not just to hold a single file
descriptor.

I've also retained the existing behaviour of having serial manager
ignore the tty file descriptor passed to it (which is stdout), and
instead using stdin.  It looks a lot weirder now, because it has to
explicitly indicate it's ignoring the fd with an underscore binding.

Fixes: 52eebaf6 ("vmm: refactor DeviceManager to use console_info")
Signed-off-by: Alyssa Ross <hi@alyssa.is>
2024-09-25 22:34:43 +00:00
..
transport vm-virtio: Gain access to virtqueue before accessing them 2024-09-04 17:33:37 +00:00
vhost_user virtio-devices: vhost_user: Remove unused backend support from virtio-fs 2024-09-25 19:41:35 +01:00
vsock misc: Fix various warnings from clippy 0.1.82 2024-09-07 09:40:20 +00:00
balloon.rs misc: Migrate away from versionize 2024-04-22 17:10:55 +00:00
block.rs virtio-devices: block: Reduce notification latency when rate limited 2024-08-31 20:54:13 +00:00
console.rs vmm: fix console IO safety 2024-09-25 22:34:43 +00:00
device.rs misc: Fix various warnings from clippy 0.1.82 2024-09-07 09:40:20 +00:00
epoll_helper.rs virtio-devices: modify or provide safety comments 2022-11-18 12:50:01 +00:00
iommu.rs virtio-devices: iommu: use inspect_err instead of map_err 2024-07-23 21:07:17 +00:00
lib.rs misc: Fix various warnings from clippy 0.1.82 2024-09-07 09:40:20 +00:00
mem.rs vmm: memory_manager: Fix bound checks for memory hotplug 2024-09-19 18:02:20 +00:00
net.rs misc: Migrate away from versionize 2024-04-22 17:10:55 +00:00
pmem.rs misc: Migrate away from versionize 2024-04-22 17:10:55 +00:00
rng.rs misc: Migrate away from versionize 2024-04-22 17:10:55 +00:00
seccomp_filters.rs virtio-devices: Fix seccomp rules for SevSnp 2024-09-11 08:41:17 +00:00
thread_helper.rs virtio-devices: Shutdown VMM upon worker thread errors 2022-08-16 11:45:44 +01:00
vdpa.rs virtio-devices: vdpa: Don't restore on paused state 2024-06-15 07:32:58 +00:00
watchdog.rs misc: Migrate away from versionize 2024-04-22 17:10:55 +00:00