mirror of
				https://github.com/kata-containers/kata-containers.git
				synced 2025-10-31 01:13:02 +00:00 
			
		
		
		
	device: support vfio cold plug
Depending on ColdPlug flag, cold or hot plug vfio devices. The VFIO device won't be hot removed when such flag is false Signed-off-by: Julio Montes <julio.montes@intel.com>
This commit is contained in:
		| @@ -98,10 +98,20 @@ func (device *VFIODevice) Attach(devReceiver api.DeviceReceiver) (retErr error) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	// hotplug a VFIO device is actually hotplugging a group of iommu devices | ||||
| 	if err := devReceiver.HotplugAddDevice(device, config.DeviceVFIO); err != nil { | ||||
| 		deviceLogger().WithError(err).Error("Failed to add device") | ||||
| 		return err | ||||
| 	coldPlug := device.DeviceInfo.ColdPlug | ||||
| 	deviceLogger().WithField("cold-plug", coldPlug).Info("Attaching VFIO device") | ||||
|  | ||||
| 	if coldPlug { | ||||
| 		if err := devReceiver.AppendDevice(device); err != nil { | ||||
| 			deviceLogger().WithError(err).Error("Failed to append device") | ||||
| 			return err | ||||
| 		} | ||||
| 	} else { | ||||
| 		// hotplug a VFIO device is actually hotplugging a group of iommu devices | ||||
| 		if err := devReceiver.HotplugAddDevice(device, config.DeviceVFIO); err != nil { | ||||
| 			deviceLogger().WithError(err).Error("Failed to add device") | ||||
| 			return err | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	deviceLogger().WithFields(logrus.Fields{ | ||||
| @@ -128,6 +138,15 @@ func (device *VFIODevice) Detach(devReceiver api.DeviceReceiver) (retErr error) | ||||
| 		} | ||||
| 	}() | ||||
|  | ||||
| 	if device.GenericDevice.DeviceInfo.ColdPlug { | ||||
| 		// nothing to detach, device was cold plugged | ||||
| 		deviceLogger().WithFields(logrus.Fields{ | ||||
| 			"device-group": device.DeviceInfo.HostPath, | ||||
| 			"device-type":  "vfio-passthrough", | ||||
| 		}).Info("Nothing to detach. VFIO device was cold plugged") | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	// hotplug a VFIO device is actually hotplugging a group of iommu devices | ||||
| 	if err := devReceiver.HotplugRemoveDevice(device, config.DeviceVFIO); err != nil { | ||||
| 		deviceLogger().WithError(err).Error("Failed to remove device") | ||||
|   | ||||
| @@ -1713,7 +1713,16 @@ func (s *Sandbox) AppendDevice(device api.Device) error { | ||||
| 	switch device.DeviceType() { | ||||
| 	case config.VhostUserSCSI, config.VhostUserNet, config.VhostUserBlk, config.VhostUserFS: | ||||
| 		return s.hypervisor.addDevice(device.GetDeviceInfo().(*config.VhostUserDeviceAttrs), vhostuserDev) | ||||
| 	case config.DeviceVFIO: | ||||
| 		vfioDevs := device.GetDeviceInfo().([]*config.VFIODev) | ||||
| 		for _, d := range vfioDevs { | ||||
| 			return s.hypervisor.addDevice(*d, vfioDev) | ||||
| 		} | ||||
| 	default: | ||||
| 		s.Logger().WithField("device-type", device.DeviceType()). | ||||
| 			Warn("Could not append device: unsupported device type") | ||||
| 	} | ||||
|  | ||||
| 	return fmt.Errorf("unsupported device type") | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user