From 3cde974af0b08f29587778e8c11b5f1da505e758 Mon Sep 17 00:00:00 2001 From: Haiwei Li Date: Mon, 13 Dec 2021 15:42:00 +0800 Subject: [PATCH] devices: vfio: Fix vfio device initialization missing 'group.add_device_num()' This fixes a bug introduced by [1] when removing vfio device and 'device_num' is zero. A panic occured when unplug a vfio device: [ERROR:src/panic_hook.rs:90] thread 'crosvm_vcpu4' panicked at 'attempt to subtract with overflow', devices/src/vfio.rs:462:9 The variable group.device_num is 0 when subtract. And when initalizes a vfio device from hot-plugging workflow, 'group.add_device_num()' is missing. BUG=b:185084350 TEST=hotplug in and out a vfio-pci device in guest repeatedly [1]: https://chromium.googlesource.com/chromiumos/platform/crosvm/+/7b80554473eb05394d1de9561c51354a3155220c Change-Id: I9a039cd15e9f9414a4a0501c64da13be76e59c1b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3365212 Reviewed-by: Xiong Y Zhang Reviewed-by: Daniel Verkamp Tested-by: kokoro Commit-Queue: Daniel Verkamp --- devices/src/vfio.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/devices/src/vfio.rs b/devices/src/vfio.rs index c034c1d315..f5500e5f9f 100644 --- a/devices/src/vfio.rs +++ b/devices/src/vfio.rs @@ -603,6 +603,7 @@ impl VfioDevice { let name = String::from(name_str); let dev = group.lock().get_device(&name)?; let regions = Self::get_regions(&dev)?; + group.lock().add_device_num(); let group_descriptor = group.lock().as_raw_descriptor(); Ok(VfioDevice {