From 0e8769d76a516f74981aeb055d5d22762f8be64e Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Sat, 9 Jul 2022 12:13:44 +0000 Subject: [PATCH] device_manager: assert passthrough_device has the correct type There is a lot of unsafe code in such a small function. Add an assert to help detect issues earlier. Signed-off-by: Wei Liu --- vmm/src/device_manager.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index bfc207cec..ff92d81be 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -2959,6 +2959,8 @@ impl DeviceManager { return vmm_sys_util::errno::errno_result().map_err(DeviceManagerError::DupFd); } + assert!(passthrough_device.as_any().is::()); + // SAFETY the raw fd conversion here is safe because: // 1. When running on KVM or MSHV, passthrough_device wraps around DeviceFd. // 2. The conversion here extracts the raw fd and then turns the raw fd into a DeviceFd