Hi,

This is labeled as RFC but it's more like a FYI to let people know and
comment beforehand. Shiva sent a 28 patch series last year that implements
hotplug/unplug support for PCI multifunction devices [1]. The design
motivation of his work was based in a RFC sent to this mailing list back
in 2016 [2].

I'll briefly summarize the goals and motivations here. What we have today
in Libvirt:

- no hotplug/unplug support for multifunction PCI devices

This is explained in details in [2]. When hotplugging a multifunction
device, QEMU will queue the hotplug operation of all non-zero functions and,
when function 0 is hotplugged, all functions are hotplugged together. This
is true for all archs that supports PCI multifunction devices in QEMU. For
unplug it varies: x86 will unplug all functions if any function is unplugged,
ppc64 needs to unplug each one.

Due to the nature of how Libvirt hotplug works now, hotplug of these devices
is not possible. All hotplugs are considered in an isolated manner. Even if
we hotplug each function in the proper order (i.e. leaving function 0 last),
Libvirt can assign different slots in the guest for each. Similar problems
happens with hot-unplug.

This feature aims to address these by creating a new <devices> element,
exclusive for multifunction devices, that aggregates all functions of a device
in a single operation. To handle this new element, the existing attach/detach
functions in the QEMU driver now handles multiple devices. Attaching/detaching
a single device is routed away from the specialized multifunction code to be
handled to the existing attach/detach code base.

- no support for partial assignment of functions

We can't make the assumption that the guest will always assign all devices
of a multifunction device. Some functions might be a security risk to expose
to a guest, or the device can behave differently depending on the amount
of functions assigned.

Even if the 'leftover' functions can't be used to anything else in the host,
the decision of full/partial assignment of functions should come from the
user, not us. We can't predict how any other hardware vendor will setup
its devices.

This patch series also handles this case.

------

The latest version of this feature, rebase to cdd362e0e7a (the current
master as I'm writing this), can be found at:

https://github.com/danielhb/libvirt/tree/multifunction-rc2

This is a work still ongoing that it's not ready for contribution yet
(first patches that changes the unit test code are breaking existing
tests). The feature itself is being stress tested using a Broadcom BCM5719
with 4 functions and it looks solid. I'll see if I can grab a x86 env
with a multifunction card to test it there too when I have the chance.


Thoughts/comments are welcome. Instead of dropping a 28+ patch set for
review, I'm planning into sending smaller chunks that makes senses
individually.



Thanks,


DHB

[1] https://www.redhat.com/archives/libvir-list/2018-March/msg00729.html
[2] https://www.redhat.com/archives/libvir-list/2016-April/msg01057.html