vfio-user: forward MSI-X PBA BAR accesses to server

For vfio-user, the server holds the pending IRQ state; set up an I/O
region for the MSI-X PBA so we can ask the server for this state on a
PBA read.

Originally-by: John Johnson <john.g.johnson@oracle.com>
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: John Levon <john.levon@nutanix.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Link: https://lore.kernel.org/qemu-devel/20250625193012.2316242-11-john.levon@nutanix.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
This commit is contained in:
John Levon 2025-06-25 20:30:02 +01:00 committed by Cédric Le Goater
parent ca1add1696
commit 777e45c7b9
2 changed files with 65 additions and 0 deletions

View file

@ -24,6 +24,62 @@ struct VFIOUserPCIDevice {
bool send_queued; /* all sends are queued */
};
/*
* The server maintains the device's pending interrupts,
* via its MSIX table and PBA, so we treat these accesses
* like PCI config space and forward them.
*/
static uint64_t vfio_user_pba_read(void *opaque, hwaddr addr,
unsigned size)
{
VFIOPCIDevice *vdev = opaque;
VFIORegion *region = &vdev->bars[vdev->msix->pba_bar].region;
uint64_t data;
/* server copy is what matters */
data = vfio_region_read(region, addr + vdev->msix->pba_offset, size);
return data;
}
static void vfio_user_pba_write(void *opaque, hwaddr addr,
uint64_t data, unsigned size)
{
/* dropped */
}
static const MemoryRegionOps vfio_user_pba_ops = {
.read = vfio_user_pba_read,
.write = vfio_user_pba_write,
.endianness = DEVICE_LITTLE_ENDIAN,
};
static void vfio_user_msix_setup(VFIOPCIDevice *vdev)
{
MemoryRegion *vfio_reg, *msix_reg, *pba_reg;
pba_reg = g_new0(MemoryRegion, 1);
vdev->msix->pba_region = pba_reg;
vfio_reg = vdev->bars[vdev->msix->pba_bar].mr;
msix_reg = &vdev->pdev.msix_pba_mmio;
memory_region_init_io(pba_reg, OBJECT(vdev), &vfio_user_pba_ops, vdev,
"VFIO MSIX PBA", int128_get64(msix_reg->size));
memory_region_add_subregion_overlap(vfio_reg, vdev->msix->pba_offset,
pba_reg, 1);
}
static void vfio_user_msix_teardown(VFIOPCIDevice *vdev)
{
MemoryRegion *mr, *sub;
mr = vdev->bars[vdev->msix->pba_bar].mr;
sub = vdev->msix->pba_region;
memory_region_del_subregion(mr, sub);
g_free(vdev->msix->pba_region);
vdev->msix->pba_region = NULL;
}
/*
* Incoming request message callback.
*
@ -144,6 +200,10 @@ static void vfio_user_pci_realize(PCIDevice *pdev, Error **errp)
goto out_teardown;
}
if (vdev->msix != NULL) {
vfio_user_msix_setup(vdev);
}
if (!vfio_pci_interrupt_setup(vdev, errp)) {
goto out_teardown;
}
@ -192,6 +252,10 @@ static void vfio_user_instance_finalize(Object *obj)
VFIOPCIDevice *vdev = VFIO_PCI_BASE(obj);
VFIODevice *vbasedev = &vdev->vbasedev;
if (vdev->msix != NULL) {
vfio_user_msix_teardown(vdev);
}
vfio_pci_put_device(vdev);
if (vbasedev->proxy != NULL) {

View file

@ -116,6 +116,7 @@ typedef struct VFIOMSIXInfo {
uint32_t pba_offset;
unsigned long *pending;
bool noresize;
MemoryRegion *pba_region;
} VFIOMSIXInfo;
/*