vfio/pci: enable vector on dynamic MSI-X allocation
commitd9e6710d7d59c1f774bfb49f3b1c2b5ee06ed33e
authorJing Liu <jing2.liu@intel.com>
Tue, 26 Sep 2023 02:14:05 +0000 (25 22:14 -0400)
committerCédric Le Goater <clg@redhat.com>
Thu, 5 Oct 2023 20:04:51 +0000 (5 22:04 +0200)
treed1a664b2eb2db3dc4be50632a33dd8d901d712ec
parent45d85f6228117dbe01d3680f1ad834389f69012f
vfio/pci: enable vector on dynamic MSI-X allocation

The vector_use callback is used to enable vector that is unmasked in
guest. The kernel used to only support static MSI-X allocation. When
allocating a new interrupt using "static MSI-X allocation" kernels,
QEMU first disables all previously allocated vectors and then
re-allocates all including the new one. The nr_vectors of VFIOPCIDevice
indicates that all vectors from 0 to nr_vectors are allocated (and may
be enabled), which is used to loop all the possibly used vectors when
e.g., disabling MSI-X interrupts.

Extend the vector_use function to support dynamic MSI-X allocation when
host supports the capability. QEMU therefore can individually allocate
and enable a new interrupt without affecting others or causing interrupts
lost during runtime.

Utilize nr_vectors to calculate the upper bound of enabled vectors in
dynamic MSI-X allocation mode since looping all msix_entries_nr is not
efficient and unnecessary.

Signed-off-by: Jing Liu <jing2.liu@intel.com>
Tested-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Cédric Le Goater <clg@redhat.com>
hw/vfio/pci.c