From d4832b3b741a32e96fae25a04c6f1f8844326ca7 Mon Sep 17 00:00:00 2001 From: Zvonko Kaiser Date: Mon, 27 May 2024 14:12:39 +0000 Subject: [PATCH] vfio: Fix hotpunplug We need to remove the device from the tracking map, a container restart will increment the bus index and we will get out of root-ports and crash the machine. Signed-off-by: Zvonko Kaiser --- src/runtime/pkg/device/drivers/vfio.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/runtime/pkg/device/drivers/vfio.go b/src/runtime/pkg/device/drivers/vfio.go index dedaea4429..394edd5848 100644 --- a/src/runtime/pkg/device/drivers/vfio.go +++ b/src/runtime/pkg/device/drivers/vfio.go @@ -141,6 +141,16 @@ func (device *VFIODevice) Detach(ctx context.Context, devReceiver api.DeviceRece deviceLogger().WithError(err).Error("Failed to remove device") return err } + for _, vfio := range device.VfioDevs { + if vfio.IsPCIe { + for ix, dev := range config.PCIeDevicesPerPort[vfio.Port] { + if dev.BDF == vfio.BDF { + config.PCIeDevicesPerPort[vfio.Port] = append(config.PCIeDevicesPerPort[vfio.Port][:ix], config.PCIeDevicesPerPort[vfio.Port][ix+1:]...) + break + } + } + } + } deviceLogger().WithFields(logrus.Fields{ "device-group": device.DeviceInfo.HostPath,