From 39464352911843c1ceac6eb17068b0907b171229 Mon Sep 17 00:00:00 2001 From: Zvonko Kaiser Date: Mon, 14 Apr 2025 20:49:27 +0000 Subject: [PATCH] gpu: Handle VFIO devices with DevicePlugin and CDI We can provide devices during cold-plug with CDI annotation on a Pod level and add per container device information wit the device plugin. Since the sandbox has already attached the VFIO device remove them from consideration and just apply the inner runtime CDI annotation. Signed-off-by: Zvonko Kaiser --- src/runtime/virtcontainers/container.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/runtime/virtcontainers/container.go b/src/runtime/virtcontainers/container.go index 536fbcff1..b736229f5 100644 --- a/src/runtime/virtcontainers/container.go +++ b/src/runtime/virtcontainers/container.go @@ -842,6 +842,20 @@ func (c *Container) createDevices(contConfig *ContainerConfig) error { coldPlugDevices := []config.DeviceInfo{} for i, vfio := range deviceInfos { + // If device is already attached during sandbox creation, e.g. + // with an CDI annotation, skip it in the container creation and + // only create the proper CDI annotation for the kata-agent + for _, dev := range config.PCIeDevicesPerPort["root-port"] { + if dev.HostPath == vfio.ContainerPath { + c.Logger().Warnf("device %s already attached to the sandbox, skipping", vfio.ContainerPath) + } + } + for _, dev := range config.PCIeDevicesPerPort["switch-port"] { + if dev.HostPath == vfio.ContainerPath { + c.Logger().Warnf("device %s already attached to the sandbox, skipping", vfio.ContainerPath) + } + } + // Only considering VFIO updates for Port and ColdPlug or // HotPlug updates isVFIODevice := deviceManager.IsVFIODevice(vfio.ContainerPath)