From: John Johnson <john.g.johnson@oracle.com>
To: qemu-devel@nongnu.org
Subject: [RFC v5 14/23] vfio-user: forward msix BAR accesses to server
Date: Thu, 5 May 2022 10:19:57 -0700 [thread overview]
Message-ID: <a95d08805d112e1d04a77d1eb0b7cade27683e5c.1651709440.git.john.g.johnson@oracle.com> (raw)
In-Reply-To: <cover.1651709440.git.john.g.johnson@oracle.com>
Server holds device current device pending state
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
---
hw/vfio/pci.h | 1 +
hw/vfio/pci.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 113 insertions(+)
diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h
index 643ff75..a4eb5b9 100644
--- a/hw/vfio/pci.h
+++ b/hw/vfio/pci.h
@@ -112,6 +112,7 @@ typedef struct VFIOMSIXInfo {
uint32_t table_offset;
uint32_t pba_offset;
unsigned long *pending;
+ MemoryRegion *msix_regions;
} VFIOMSIXInfo;
/*
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index 1be6683..bc70968 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -3426,6 +3426,111 @@ type_init(register_vfio_pci_dev_type)
* vfio-user routines.
*/
+/*
+ * The server maintains the device's pending interrupts,
+ * via its MSIX table and PBA, so we treat these acceses
+ * like PCI config space and forward them.
+ */
+static uint64_t vfio_user_table_read(void *opaque, hwaddr addr,
+ unsigned size)
+{
+ VFIOPCIDevice *vdev = opaque;
+ uint64_t data;
+
+ /* server doesn't change these, so local copy is good */
+ memory_region_dispatch_read(&vdev->pdev.msix_table_mmio, addr,
+ &data, size_memop(size) | MO_LE,
+ MEMTXATTRS_UNSPECIFIED);
+ return data;
+}
+
+static void vfio_user_table_write(void *opaque, hwaddr addr,
+ uint64_t data, unsigned size)
+{
+ VFIOPCIDevice *vdev = opaque;
+ VFIORegion *region = &vdev->bars[vdev->msix->table_bar].region;
+
+ /* forward, then perform locally */
+ vfio_region_write(region, addr + vdev->msix->table_offset, data, size);
+ memory_region_dispatch_write(&vdev->pdev.msix_table_mmio, addr,
+ data, size_memop(size) | MO_LE,
+ MEMTXATTRS_UNSPECIFIED);
+}
+
+static const MemoryRegionOps vfio_user_table_ops = {
+ .read = vfio_user_table_read,
+ .write = vfio_user_table_write,
+ .endianness = DEVICE_LITTLE_ENDIAN,
+};
+
+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, *new_reg;
+
+ vdev->msix->msix_regions = g_new0(MemoryRegion, 2);
+
+ vfio_reg = vdev->bars[vdev->msix->table_bar].mr;
+ msix_reg = &vdev->pdev.msix_table_mmio;
+ new_reg = &vdev->msix->msix_regions[0];
+ memory_region_init_io(new_reg, OBJECT(vdev), &vfio_user_table_ops, vdev,
+ "VFIO MSIX table", int128_get64(msix_reg->size));
+ memory_region_add_subregion_overlap(vfio_reg, vdev->msix->table_offset,
+ new_reg, 1);
+
+ vfio_reg = vdev->bars[vdev->msix->pba_bar].mr;
+ msix_reg = &vdev->pdev.msix_pba_mmio;
+ new_reg = &vdev->msix->msix_regions[1];
+ memory_region_init_io(new_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,
+ new_reg, 1);
+}
+
+static void vfio_user_msix_teardown(VFIOPCIDevice *vdev)
+{
+ MemoryRegion *mr, *sub;
+
+ mr = vdev->bars[vdev->msix->table_bar].mr;
+ sub = &vdev->msix->msix_regions[0];
+ memory_region_del_subregion(mr, sub);
+
+ mr = vdev->bars[vdev->msix->pba_bar].mr;
+ sub = &vdev->msix->msix_regions[1];
+ memory_region_del_subregion(mr, sub);
+
+ g_free(vdev->msix->msix_regions);
+ vdev->msix->msix_regions = NULL;
+}
+
+/*
+ * Incoming request message callback.
+ *
+ * Runs off main loop, so BQL held.
+ */
static void vfio_user_pci_process_req(void *opaque, VFIOUserMsg *msg)
{
@@ -3548,6 +3653,9 @@ static void vfio_user_pci_realize(PCIDevice *pdev, Error **errp)
if (ret) {
goto out_teardown;
}
+ if (vdev->msix != NULL) {
+ vfio_user_msix_setup(vdev);
+ }
ret = vfio_interrupt_setup(vdev, errp);
if (ret) {
@@ -3569,6 +3677,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_put_device(vdev);
if (vbasedev->proxy != NULL) {
--
1.8.3.1
next prev parent reply other threads:[~2022-05-05 17:35 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1651709440.git.john.g.johnson@oracle.com>
2022-05-05 17:19 ` [RFC v5 01/23] vfio-user: introduce vfio-user protocol specification John Johnson
2022-05-05 17:19 ` [RFC v5 02/23] vfio-user: add VFIO base abstract class John Johnson
2022-05-05 17:19 ` [RFC v5 03/23] vfio-user: add container IO ops vector John Johnson
2022-05-05 17:19 ` [RFC v5 04/23] vfio-user: add region cache John Johnson
2022-05-05 17:19 ` [RFC v5 05/23] vfio-user: add device IO ops vector John Johnson
2022-05-05 17:19 ` [RFC v5 06/23] vfio-user: Define type vfio_user_pci_dev_info John Johnson
2022-05-05 17:19 ` [RFC v5 07/23] vfio-user: connect vfio proxy to remote server John Johnson
2022-05-05 17:19 ` [RFC v5 08/23] vfio-user: define socket receive functions John Johnson
2022-05-05 17:19 ` [RFC v5 09/23] vfio-user: define socket send functions John Johnson
2022-05-05 17:19 ` [RFC v5 10/23] vfio-user: get device info John Johnson
2022-05-05 17:19 ` [RFC v5 11/23] vfio-user: get region info John Johnson
2022-05-05 17:19 ` [RFC v5 12/23] vfio-user: region read/write John Johnson
2022-05-05 17:19 ` [RFC v5 13/23] vfio-user: pci_user_realize PCI setup John Johnson
2022-05-05 17:19 ` John Johnson [this message]
2022-05-05 17:19 ` [RFC v5 15/23] vfio-user: get and set IRQs John Johnson
2022-05-05 17:19 ` [RFC v5 16/23] vfio-user: proxy container connect/disconnect John Johnson
2022-05-05 17:20 ` [RFC v5 17/23] vfio-user: dma map/unmap operations John Johnson
2022-05-05 17:20 ` [RFC v5 18/23] vfio-user: secure DMA support John Johnson
2022-05-05 17:20 ` [RFC v5 19/23] vfio-user: dma read/write operations John Johnson
2022-05-05 17:20 ` [RFC v5 20/23] vfio-user: pci reset John Johnson
2022-05-05 17:20 ` [RFC v5 21/23] vfio-user: add 'x-msg-timeout' option that specifies msg wait times John Johnson
2022-05-05 17:20 ` [RFC v5 22/23] vfio-user: add tracing to send/recv paths John Johnson
2022-05-05 17:20 ` [RFC v5 23/23] vfio-user: add dirty_bitmap stub until it support migration John Johnson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a95d08805d112e1d04a77d1eb0b7cade27683e5c.1651709440.git.john.g.johnson@oracle.com \
--to=john.g.johnson@oracle.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).