mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-06 22:23:26 +00:00
agent: Rename VFIO handling to VFIO PCI handling
e.g., split_vfio_option is PCI-specific and should instead be named split_vfio_pci_option. This mutually affects the runtime, most notably how the labels are named for the agent. Signed-off-by: Jakob Naucke <jakob.naucke@ibm.com>
This commit is contained in:
parent
db89c88f4f
commit
4c527d00c7
@ -45,11 +45,11 @@ pub const DRIVER_NVDIMM_TYPE: &str = "nvdimm";
|
|||||||
pub const DRIVER_EPHEMERAL_TYPE: &str = "ephemeral";
|
pub const DRIVER_EPHEMERAL_TYPE: &str = "ephemeral";
|
||||||
pub const DRIVER_LOCAL_TYPE: &str = "local";
|
pub const DRIVER_LOCAL_TYPE: &str = "local";
|
||||||
pub const DRIVER_WATCHABLE_BIND_TYPE: &str = "watchable-bind";
|
pub const DRIVER_WATCHABLE_BIND_TYPE: &str = "watchable-bind";
|
||||||
// VFIO device to be bound to a guest kernel driver
|
// VFIO PCI device to be bound to a guest kernel driver
|
||||||
pub const DRIVER_VFIO_GK_TYPE: &str = "vfio-gk";
|
pub const DRIVER_VFIO_PCI_GK_TYPE: &str = "vfio-pci-gk";
|
||||||
// VFIO device to be bound to vfio-pci and made available inside the
|
// VFIO PCI device to be bound to vfio-pci and made available inside the
|
||||||
// container as a VFIO device node
|
// container as a VFIO device node
|
||||||
pub const DRIVER_VFIO_TYPE: &str = "vfio";
|
pub const DRIVER_VFIO_PCI_TYPE: &str = "vfio-pci";
|
||||||
pub const DRIVER_OVERLAYFS_TYPE: &str = "overlayfs";
|
pub const DRIVER_OVERLAYFS_TYPE: &str = "overlayfs";
|
||||||
pub const FS_TYPE_HUGETLB: &str = "hugetlbfs";
|
pub const FS_TYPE_HUGETLB: &str = "hugetlbfs";
|
||||||
|
|
||||||
@ -704,7 +704,7 @@ async fn virtio_nvdimm_device_handler(
|
|||||||
Ok(DevNumUpdate::from_vm_path(&device.vm_path)?.into())
|
Ok(DevNumUpdate::from_vm_path(&device.vm_path)?.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn split_vfio_option(opt: &str) -> Option<(&str, &str)> {
|
fn split_vfio_pci_option(opt: &str) -> Option<(&str, &str)> {
|
||||||
let mut tokens = opt.split('=');
|
let mut tokens = opt.split('=');
|
||||||
let hostbdf = tokens.next()?;
|
let hostbdf = tokens.next()?;
|
||||||
let path = tokens.next()?;
|
let path = tokens.next()?;
|
||||||
@ -719,14 +719,18 @@ fn split_vfio_option(opt: &str) -> Option<(&str, &str)> {
|
|||||||
// Each option should have the form "DDDD:BB:DD.F=<pcipath>"
|
// Each option should have the form "DDDD:BB:DD.F=<pcipath>"
|
||||||
// DDDD:BB:DD.F is the device's PCI address in the host
|
// DDDD:BB:DD.F is the device's PCI address in the host
|
||||||
// <pcipath> is a PCI path to the device in the guest (see pci.rs)
|
// <pcipath> is a PCI path to the device in the guest (see pci.rs)
|
||||||
async fn vfio_device_handler(device: &Device, sandbox: &Arc<Mutex<Sandbox>>) -> Result<SpecUpdate> {
|
#[instrument]
|
||||||
let vfio_in_guest = device.field_type != DRIVER_VFIO_GK_TYPE;
|
async fn vfio_pci_device_handler(
|
||||||
|
device: &Device,
|
||||||
|
sandbox: &Arc<Mutex<Sandbox>>,
|
||||||
|
) -> Result<SpecUpdate> {
|
||||||
|
let vfio_in_guest = device.field_type != DRIVER_VFIO_PCI_GK_TYPE;
|
||||||
let mut pci_fixups = Vec::<(pci::Address, pci::Address)>::new();
|
let mut pci_fixups = Vec::<(pci::Address, pci::Address)>::new();
|
||||||
let mut group = None;
|
let mut group = None;
|
||||||
|
|
||||||
for opt in device.options.iter() {
|
for opt in device.options.iter() {
|
||||||
let (host, pcipath) =
|
let (host, pcipath) =
|
||||||
split_vfio_option(opt).ok_or_else(|| anyhow!("Malformed VFIO option {:?}", opt))?;
|
split_vfio_pci_option(opt).ok_or_else(|| anyhow!("Malformed VFIO option {:?}", opt))?;
|
||||||
let host =
|
let host =
|
||||||
pci::Address::from_str(host).context("Bad host PCI address in VFIO option {:?}")?;
|
pci::Address::from_str(host).context("Bad host PCI address in VFIO option {:?}")?;
|
||||||
let pcipath = pci::Path::from_str(pcipath)?;
|
let pcipath = pci::Path::from_str(pcipath)?;
|
||||||
@ -833,7 +837,9 @@ async fn add_device(device: &Device, sandbox: &Arc<Mutex<Sandbox>>) -> Result<Sp
|
|||||||
DRIVER_MMIO_BLK_TYPE => virtiommio_blk_device_handler(device, sandbox).await,
|
DRIVER_MMIO_BLK_TYPE => virtiommio_blk_device_handler(device, sandbox).await,
|
||||||
DRIVER_NVDIMM_TYPE => virtio_nvdimm_device_handler(device, sandbox).await,
|
DRIVER_NVDIMM_TYPE => virtio_nvdimm_device_handler(device, sandbox).await,
|
||||||
DRIVER_SCSI_TYPE => virtio_scsi_device_handler(device, sandbox).await,
|
DRIVER_SCSI_TYPE => virtio_scsi_device_handler(device, sandbox).await,
|
||||||
DRIVER_VFIO_GK_TYPE | DRIVER_VFIO_TYPE => vfio_device_handler(device, sandbox).await,
|
DRIVER_VFIO_PCI_GK_TYPE | DRIVER_VFIO_PCI_TYPE => {
|
||||||
|
vfio_pci_device_handler(device, sandbox).await
|
||||||
|
}
|
||||||
_ => Err(anyhow!("Unknown device type {}", device.field_type)),
|
_ => Err(anyhow!("Unknown device type {}", device.field_type)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1492,13 +1498,13 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_split_vfio_option() {
|
fn test_split_vfio_pci_option() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
split_vfio_option("0000:01:00.0=02/01"),
|
split_vfio_pci_option("0000:01:00.0=02/01"),
|
||||||
Some(("0000:01:00.0", "02/01"))
|
Some(("0000:01:00.0", "02/01"))
|
||||||
);
|
);
|
||||||
assert_eq!(split_vfio_option("0000:01:00.0=02/01=rubbish"), None);
|
assert_eq!(split_vfio_pci_option("0000:01:00.0=02/01=rubbish"), None);
|
||||||
assert_eq!(split_vfio_option("0000:01:00.0"), None);
|
assert_eq!(split_vfio_pci_option("0000:01:00.0"), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -258,11 +258,11 @@ const (
|
|||||||
// VFIODeviceErrorType is the error type of VFIO device
|
// VFIODeviceErrorType is the error type of VFIO device
|
||||||
VFIODeviceErrorType VFIODeviceType = iota
|
VFIODeviceErrorType VFIODeviceType = iota
|
||||||
|
|
||||||
// VFIODeviceNormalType is a normal VFIO device type
|
// VFIOPCIDeviceNormalType is a normal VFIO PCI device type
|
||||||
VFIODeviceNormalType
|
VFIOPCIDeviceNormalType
|
||||||
|
|
||||||
// VFIODeviceMediatedType is a VFIO mediated device type
|
// VFIOPCIDeviceMediatedType is a VFIO PCI mediated device type
|
||||||
VFIODeviceMediatedType
|
VFIOPCIDeviceMediatedType
|
||||||
)
|
)
|
||||||
|
|
||||||
// VFIODev represents a VFIO drive used for hotplugging
|
// VFIODev represents a VFIO drive used for hotplugging
|
||||||
|
@ -94,12 +94,12 @@ func GetVFIODeviceType(deviceFileName string) config.VFIODeviceType {
|
|||||||
tokens := strings.Split(deviceFileName, ":")
|
tokens := strings.Split(deviceFileName, ":")
|
||||||
vfioDeviceType := config.VFIODeviceErrorType
|
vfioDeviceType := config.VFIODeviceErrorType
|
||||||
if len(tokens) == 3 {
|
if len(tokens) == 3 {
|
||||||
vfioDeviceType = config.VFIODeviceNormalType
|
vfioDeviceType = config.VFIOPCIDeviceNormalType
|
||||||
} else {
|
} else {
|
||||||
//For example, 83b8f4f2-509f-382f-3c1e-e6bfe0fa1001
|
//For example, 83b8f4f2-509f-382f-3c1e-e6bfe0fa1001
|
||||||
tokens = strings.Split(deviceFileName, "-")
|
tokens = strings.Split(deviceFileName, "-")
|
||||||
if len(tokens) == 5 {
|
if len(tokens) == 5 {
|
||||||
vfioDeviceType = config.VFIODeviceMediatedType
|
vfioDeviceType = config.VFIOPCIDeviceMediatedType
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return vfioDeviceType
|
return vfioDeviceType
|
||||||
|
@ -207,12 +207,12 @@ func getVFIODetails(deviceFileName, iommuDevicesPath string) (deviceBDF, deviceS
|
|||||||
vfioDeviceType = GetVFIODeviceType(deviceFileName)
|
vfioDeviceType = GetVFIODeviceType(deviceFileName)
|
||||||
|
|
||||||
switch vfioDeviceType {
|
switch vfioDeviceType {
|
||||||
case config.VFIODeviceNormalType:
|
case config.VFIOPCIDeviceNormalType:
|
||||||
// Get bdf of device eg. 0000:00:1c.0
|
// Get bdf of device eg. 0000:00:1c.0
|
||||||
deviceBDF = getBDF(deviceFileName)
|
deviceBDF = getBDF(deviceFileName)
|
||||||
// Get sysfs path used by cloud-hypervisor
|
// Get sysfs path used by cloud-hypervisor
|
||||||
deviceSysfsDev = filepath.Join(config.SysBusPciDevicesPath, deviceFileName)
|
deviceSysfsDev = filepath.Join(config.SysBusPciDevicesPath, deviceFileName)
|
||||||
case config.VFIODeviceMediatedType:
|
case config.VFIOPCIDeviceMediatedType:
|
||||||
// Get sysfsdev of device eg. /sys/devices/pci0000:00/0000:00:02.0/f79944e4-5a3d-11e8-99ce-479cbab002e4
|
// Get sysfsdev of device eg. /sys/devices/pci0000:00/0000:00:02.0/f79944e4-5a3d-11e8-99ce-479cbab002e4
|
||||||
sysfsDevStr := filepath.Join(iommuDevicesPath, deviceFileName)
|
sysfsDevStr := filepath.Join(iommuDevicesPath, deviceFileName)
|
||||||
deviceSysfsDev, err = getSysfsDev(sysfsDevStr)
|
deviceSysfsDev, err = getSysfsDev(sysfsDevStr)
|
||||||
|
@ -32,9 +32,9 @@ func TestGetVFIODetails(t *testing.T) {
|
|||||||
deviceBDF, deviceSysfsDev, vfioDeviceType, err := getVFIODetails(d.deviceStr, "")
|
deviceBDF, deviceSysfsDev, vfioDeviceType, err := getVFIODetails(d.deviceStr, "")
|
||||||
|
|
||||||
switch vfioDeviceType {
|
switch vfioDeviceType {
|
||||||
case config.VFIODeviceNormalType:
|
case config.VFIOPCIDeviceNormalType:
|
||||||
assert.Equal(t, d.expectedStr, deviceBDF)
|
assert.Equal(t, d.expectedStr, deviceBDF)
|
||||||
case config.VFIODeviceMediatedType:
|
case config.VFIOPCIDeviceMediatedType:
|
||||||
assert.Equal(t, d.expectedStr, deviceSysfsDev)
|
assert.Equal(t, d.expectedStr, deviceSysfsDev)
|
||||||
default:
|
default:
|
||||||
assert.NotNil(t, err)
|
assert.NotNil(t, err)
|
||||||
|
@ -1117,10 +1117,10 @@ func (k *kataAgent) appendVfioDevice(dev ContainerDevice, device api.Device, c *
|
|||||||
|
|
||||||
groupNum := filepath.Base(dev.ContainerPath)
|
groupNum := filepath.Base(dev.ContainerPath)
|
||||||
|
|
||||||
// Each /dev/vfio/NN device represents a VFIO group, which
|
// For VFIO-PCI, each /dev/vfio/NN device represents a VFIO group,
|
||||||
// could include several PCI devices. So we give group
|
// which could include several PCI devices. So we give group
|
||||||
// information in the main structure, then list each
|
// information in the main structure, then list each individual PCI
|
||||||
// individual PCI device in the Options array.
|
// device in the Options array.
|
||||||
//
|
//
|
||||||
// Each option is formatted as "DDDD:BB:DD.F=<pcipath>"
|
// Each option is formatted as "DDDD:BB:DD.F=<pcipath>"
|
||||||
// DDDD:BB:DD.F is the device's PCI address on the
|
// DDDD:BB:DD.F is the device's PCI address on the
|
||||||
@ -1128,9 +1128,9 @@ func (k *kataAgent) appendVfioDevice(dev ContainerDevice, device api.Device, c *
|
|||||||
// (see qomGetPciPath() for details).
|
// (see qomGetPciPath() for details).
|
||||||
kataDevice := &grpc.Device{
|
kataDevice := &grpc.Device{
|
||||||
ContainerPath: dev.ContainerPath,
|
ContainerPath: dev.ContainerPath,
|
||||||
Type: kataVfioDevType,
|
Type: kataVfioPciDevType,
|
||||||
Id: groupNum,
|
Id: groupNum,
|
||||||
Options: make([]string, len(devList)),
|
Options: nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
// We always pass the device information to the agent, since
|
// We always pass the device information to the agent, since
|
||||||
@ -1138,7 +1138,7 @@ func (k *kataAgent) appendVfioDevice(dev ContainerDevice, device api.Device, c *
|
|||||||
// on the vfio_mode, we need to use a different device type so
|
// on the vfio_mode, we need to use a different device type so
|
||||||
// the agent can handle it properly
|
// the agent can handle it properly
|
||||||
if c.sandbox.config.VfioMode == config.VFIOModeGuestKernel {
|
if c.sandbox.config.VfioMode == config.VFIOModeGuestKernel {
|
||||||
kataDevice.Type = kataVfioGuestKernelDevType
|
kataDevice.Type = kataVfioPciGuestKernelDevType
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, pciDev := range devList {
|
for i, pciDev := range devList {
|
||||||
|
@ -1743,9 +1743,9 @@ func (q *qemu) hotplugVFIODevice(ctx context.Context, device *config.VFIODev, op
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch device.Type {
|
switch device.Type {
|
||||||
case config.VFIODeviceNormalType:
|
case config.VFIOPCIDeviceNormalType:
|
||||||
err = q.qmpMonitorCh.qmp.ExecuteVFIODeviceAdd(q.qmpMonitorCh.ctx, devID, device.BDF, device.Bus, romFile)
|
err = q.qmpMonitorCh.qmp.ExecuteVFIODeviceAdd(q.qmpMonitorCh.ctx, devID, device.BDF, device.Bus, romFile)
|
||||||
case config.VFIODeviceMediatedType:
|
case config.VFIOPCIDeviceMediatedType:
|
||||||
if utils.IsAPVFIOMediatedDevice(device.SysfsDev) {
|
if utils.IsAPVFIOMediatedDevice(device.SysfsDev) {
|
||||||
err = q.qmpMonitorCh.qmp.ExecuteAPVFIOMediatedDeviceAdd(q.qmpMonitorCh.ctx, device.SysfsDev)
|
err = q.qmpMonitorCh.qmp.ExecuteAPVFIOMediatedDeviceAdd(q.qmpMonitorCh.ctx, device.SysfsDev)
|
||||||
} else {
|
} else {
|
||||||
@ -1767,9 +1767,9 @@ func (q *qemu) hotplugVFIODevice(ctx context.Context, device *config.VFIODev, op
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
switch device.Type {
|
switch device.Type {
|
||||||
case config.VFIODeviceNormalType:
|
case config.VFIOPCIDeviceNormalType:
|
||||||
err = q.qmpMonitorCh.qmp.ExecutePCIVFIODeviceAdd(q.qmpMonitorCh.ctx, devID, device.BDF, addr, bridge.ID, romFile)
|
err = q.qmpMonitorCh.qmp.ExecutePCIVFIODeviceAdd(q.qmpMonitorCh.ctx, devID, device.BDF, addr, bridge.ID, romFile)
|
||||||
case config.VFIODeviceMediatedType:
|
case config.VFIOPCIDeviceMediatedType:
|
||||||
if utils.IsAPVFIOMediatedDevice(device.SysfsDev) {
|
if utils.IsAPVFIOMediatedDevice(device.SysfsDev) {
|
||||||
err = q.qmpMonitorCh.qmp.ExecuteAPVFIOMediatedDeviceAdd(q.qmpMonitorCh.ctx, device.SysfsDev)
|
err = q.qmpMonitorCh.qmp.ExecuteAPVFIOMediatedDeviceAdd(q.qmpMonitorCh.ctx, device.SysfsDev)
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user