mirror of https://gitee.com/openkylin/libvirt.git
Introducing new address type='unassigned' for PCI hostdevs
This patch introduces a new PCI hostdev address type called 'unassigned'. This new type gives users the option to add PCI hostdevs to the domain XML in an 'unassigned' state, meaning that the device exists in the domain, is managed by Libvirt like any regular PCI hostdev, but the guest does not have access to it. This adds extra options for managing PCI device binding inside Libvirt, for example, making all the managed PCI hostdevs declared in the domain XML to be detached from the host and bind to the chosen driver and, at the same time, allowing just a subset of these devices to be usable by the guest. Next patch will use this new address type in the QEMU driver to avoid adding unassigned devices to the QEMU launch command line. Reviewed-by: Cole Robinson <crobinso@redhat.com> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
parent
94f6e2f9fc
commit
96999404cb
|
@ -5502,6 +5502,11 @@
|
|||
</attribute>
|
||||
<ref name="dimmaddress"/>
|
||||
</group>
|
||||
<group>
|
||||
<attribute name="type">
|
||||
<value>unassigned</value>
|
||||
</attribute>
|
||||
</group>
|
||||
</choice>
|
||||
</element>
|
||||
</define>
|
||||
|
|
|
@ -45,6 +45,7 @@ VIR_ENUM_IMPL(virDomainDeviceAddress,
|
|||
"virtio-mmio",
|
||||
"isa",
|
||||
"dimm",
|
||||
"unassigned",
|
||||
);
|
||||
|
||||
static int
|
||||
|
@ -120,6 +121,7 @@ virDomainDeviceInfoAddressIsEqual(const virDomainDeviceInfo *a,
|
|||
/* address types below don't have any specific data */
|
||||
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO:
|
||||
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390:
|
||||
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGNED:
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI:
|
||||
|
|
|
@ -45,6 +45,7 @@ typedef enum {
|
|||
VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO,
|
||||
VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA,
|
||||
VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM,
|
||||
VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGNED,
|
||||
|
||||
VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST
|
||||
} virDomainDeviceAddressType;
|
||||
|
|
|
@ -6352,9 +6352,11 @@ virDomainHostdevDefValidate(const virDomainHostdevDef *hostdev)
|
|||
switch ((virDomainHostdevSubsysType) hostdev->source.subsys.type) {
|
||||
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
|
||||
if (hostdev->info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
|
||||
hostdev->info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGNED &&
|
||||
hostdev->info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("PCI host devices must use 'pci' address type"));
|
||||
_("PCI host devices must use 'pci' or "
|
||||
"'unassigned' address type"));
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
|
@ -7371,6 +7373,7 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
|
|||
|
||||
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390:
|
||||
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE:
|
||||
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGNED:
|
||||
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST:
|
||||
break;
|
||||
}
|
||||
|
@ -7571,6 +7574,7 @@ virDomainDeviceAddressParseXML(xmlNodePtr address,
|
|||
break;
|
||||
|
||||
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE:
|
||||
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGNED:
|
||||
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST:
|
||||
break;
|
||||
}
|
||||
|
@ -21951,6 +21955,7 @@ virDomainDeviceInfoCheckABIStability(virDomainDeviceInfoPtr src,
|
|||
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW:
|
||||
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO:
|
||||
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE:
|
||||
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGNED:
|
||||
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -459,6 +459,7 @@ qemuBuildVirtioDevStr(virBufferPtr buf,
|
|||
return -1;
|
||||
|
||||
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE:
|
||||
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGNED:
|
||||
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST:
|
||||
default:
|
||||
virReportEnumRangeError(virDomainDeviceAddressType, info->type);
|
||||
|
|
|
@ -8305,6 +8305,7 @@ qemuDomainDeviceDefValidateAddress(const virDomainDeviceDef *dev,
|
|||
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO:
|
||||
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA:
|
||||
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM:
|
||||
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGNED:
|
||||
/* No validation for these address types yet */
|
||||
break;
|
||||
|
||||
|
|
|
@ -2313,6 +2313,11 @@ qemuDomainAssignDevicePCISlots(virDomainDefPtr def,
|
|||
continue;
|
||||
}
|
||||
|
||||
/* do not reserve address for info->type='unassigned' */
|
||||
if (def->hostdevs[i]->info->type ==
|
||||
VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGNED)
|
||||
continue;
|
||||
|
||||
if (qemuDomainPCIAddressReserveNextAddr(addrs,
|
||||
def->hostdevs[i]->info) < 0)
|
||||
goto error;
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
<domain type='kvm'>
|
||||
<name>delete</name>
|
||||
<uuid>583a8e8e-f0ce-4f53-89ab-092862148b25</uuid>
|
||||
<memory unit='KiB'>262144</memory>
|
||||
<vcpu placement='static'>4</vcpu>
|
||||
<os>
|
||||
<type arch='x86_64' machine='pc'>hvm</type>
|
||||
</os>
|
||||
<devices>
|
||||
<emulator>/usr/bin/qemu-system-x86_64</emulator>
|
||||
<controller type='usb' index='0'/>
|
||||
<controller type='ide' index='0'/>
|
||||
<controller type='pci' index='0' model='pci-root'/>
|
||||
<input type='mouse' bus='ps2'/>
|
||||
<input type='keyboard' bus='ps2'/>
|
||||
<hostdev mode='subsystem' type='pci' managed='yes'>
|
||||
<driver name='vfio'/>
|
||||
<source>
|
||||
<address domain='0x0005' bus='0x90' slot='0x01' function='0x0'/>
|
||||
</source>
|
||||
</hostdev>
|
||||
<hostdev mode='subsystem' type='pci' managed='yes'>
|
||||
<driver name='vfio'/>
|
||||
<source>
|
||||
<address domain='0x0005' bus='0x90' slot='0x01' function='0x1'/>
|
||||
</source>
|
||||
<address type='unassigned'/>
|
||||
</hostdev>
|
||||
<hostdev mode='subsystem' type='pci' managed='yes'>
|
||||
<driver name='vfio'/>
|
||||
<source>
|
||||
<address domain='0x0005' bus='0x90' slot='0x01' function='0x2'/>
|
||||
</source>
|
||||
</hostdev>
|
||||
<hostdev mode='subsystem' type='pci' managed='yes'>
|
||||
<driver name='vfio'/>
|
||||
<source>
|
||||
<address domain='0x0005' bus='0x90' slot='0x01' function='0x3'/>
|
||||
</source>
|
||||
</hostdev>
|
||||
</devices>
|
||||
</domain>
|
|
@ -0,0 +1,58 @@
|
|||
<domain type='kvm'>
|
||||
<name>delete</name>
|
||||
<uuid>583a8e8e-f0ce-4f53-89ab-092862148b25</uuid>
|
||||
<memory unit='KiB'>262144</memory>
|
||||
<currentMemory unit='KiB'>262144</currentMemory>
|
||||
<vcpu placement='static'>4</vcpu>
|
||||
<os>
|
||||
<type arch='x86_64' machine='pc'>hvm</type>
|
||||
<boot dev='hd'/>
|
||||
</os>
|
||||
<clock offset='utc'/>
|
||||
<on_poweroff>destroy</on_poweroff>
|
||||
<on_reboot>restart</on_reboot>
|
||||
<on_crash>destroy</on_crash>
|
||||
<devices>
|
||||
<emulator>/usr/bin/qemu-system-x86_64</emulator>
|
||||
<controller type='usb' index='0'>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
|
||||
</controller>
|
||||
<controller type='ide' index='0'>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
|
||||
</controller>
|
||||
<controller type='pci' index='0' model='pci-root'/>
|
||||
<input type='mouse' bus='ps2'/>
|
||||
<input type='keyboard' bus='ps2'/>
|
||||
<hostdev mode='subsystem' type='pci' managed='yes'>
|
||||
<driver name='vfio'/>
|
||||
<source>
|
||||
<address domain='0x0005' bus='0x90' slot='0x01' function='0x0'/>
|
||||
</source>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
|
||||
</hostdev>
|
||||
<hostdev mode='subsystem' type='pci' managed='yes'>
|
||||
<driver name='vfio'/>
|
||||
<source>
|
||||
<address domain='0x0005' bus='0x90' slot='0x01' function='0x1'/>
|
||||
</source>
|
||||
<address type='unassigned'/>
|
||||
</hostdev>
|
||||
<hostdev mode='subsystem' type='pci' managed='yes'>
|
||||
<driver name='vfio'/>
|
||||
<source>
|
||||
<address domain='0x0005' bus='0x90' slot='0x01' function='0x2'/>
|
||||
</source>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
|
||||
</hostdev>
|
||||
<hostdev mode='subsystem' type='pci' managed='yes'>
|
||||
<driver name='vfio'/>
|
||||
<source>
|
||||
<address domain='0x0005' bus='0x90' slot='0x01' function='0x3'/>
|
||||
</source>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
|
||||
</hostdev>
|
||||
<memballoon model='virtio'>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
|
||||
</memballoon>
|
||||
</devices>
|
||||
</domain>
|
|
@ -491,6 +491,7 @@ mymain(void)
|
|||
|
||||
DO_TEST("hostdev-usb-address", NONE);
|
||||
DO_TEST("hostdev-pci-address", NONE);
|
||||
DO_TEST("hostdev-pci-address-unassigned", QEMU_CAPS_DEVICE_VFIO_PCI);
|
||||
DO_TEST("hostdev-pci-multifunction", QEMU_CAPS_DEVICE_VFIO_PCI);
|
||||
DO_TEST("hostdev-vfio", QEMU_CAPS_DEVICE_VFIO_PCI);
|
||||
DO_TEST("hostdev-vfio-zpci",
|
||||
|
|
Loading…
Reference in New Issue