[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v6 11/19] vfio-user: handle PCI config space accesses
From: |
Jagannathan Raman |
Subject: |
[PATCH v6 11/19] vfio-user: handle PCI config space accesses |
Date: |
Thu, 17 Feb 2022 02:48:58 -0500 |
Define and register handlers for PCI config space accesses
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
hw/remote/vfio-user-obj.c | 45 +++++++++++++++++++++++++++++++++++++++
hw/remote/trace-events | 2 ++
2 files changed, 47 insertions(+)
diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c
index 384ec4612d..4c4280d603 100644
--- a/hw/remote/vfio-user-obj.c
+++ b/hw/remote/vfio-user-obj.c
@@ -47,6 +47,7 @@
#include "qapi/qapi-events-misc.h"
#include "qemu/notify.h"
#include "qemu/thread.h"
+#include "qemu/main-loop.h"
#include "sysemu/sysemu.h"
#include "libvfio-user.h"
#include "hw/qdev-core.h"
@@ -217,6 +218,39 @@ retry_attach:
qemu_set_fd_handler(o->vfu_poll_fd, vfu_object_ctx_run, NULL, o);
}
+static ssize_t vfu_object_cfg_access(vfu_ctx_t *vfu_ctx, char * const buf,
+ size_t count, loff_t offset,
+ const bool is_write)
+{
+ VfuObject *o = vfu_get_private(vfu_ctx);
+ uint32_t pci_access_width = sizeof(uint32_t);
+ size_t bytes = count;
+ uint32_t val = 0;
+ char *ptr = buf;
+ int len;
+
+ while (bytes > 0) {
+ len = (bytes > pci_access_width) ? pci_access_width : bytes;
+ if (is_write) {
+ memcpy(&val, ptr, len);
+ pci_host_config_write_common(o->pci_dev, offset,
+ pci_config_size(o->pci_dev),
+ val, len);
+ trace_vfu_cfg_write(offset, val);
+ } else {
+ val = pci_host_config_read_common(o->pci_dev, offset,
+ pci_config_size(o->pci_dev),
len);
+ memcpy(ptr, &val, len);
+ trace_vfu_cfg_read(offset, val);
+ }
+ offset += len;
+ ptr += len;
+ bytes -= len;
+ }
+
+ return count;
+}
+
/*
* TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device'
* properties. It also depends on devices instantiated in QEMU. These
@@ -293,6 +327,17 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp)
TYPE_VFU_OBJECT, o->device);
qdev_add_unplug_blocker(DEVICE(o->pci_dev), o->unplug_blocker);
+ ret = vfu_setup_region(o->vfu_ctx, VFU_PCI_DEV_CFG_REGION_IDX,
+ pci_config_size(o->pci_dev), &vfu_object_cfg_access,
+ VFU_REGION_FLAG_RW | VFU_REGION_FLAG_ALWAYS_CB,
+ NULL, 0, -1, 0);
+ if (ret < 0) {
+ error_setg(errp,
+ "vfu: Failed to setup config space handlers for %s- %s",
+ o->device, strerror(errno));
+ goto fail;
+ }
+
ret = vfu_realize_ctx(o->vfu_ctx);
if (ret < 0) {
error_setg(errp, "vfu: Failed to realize device %s- %s",
diff --git a/hw/remote/trace-events b/hw/remote/trace-events
index 7da12f0d96..2ef7884346 100644
--- a/hw/remote/trace-events
+++ b/hw/remote/trace-events
@@ -5,3 +5,5 @@ mpqemu_recv_io_error(int cmd, int size, int nfds) "failed to
receive %d size %d,
# vfio-user-obj.c
vfu_prop(const char *prop, const char *val) "vfu: setting %s as %s"
+vfu_cfg_read(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u -> 0x%x"
+vfu_cfg_write(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u <- 0x%x"
--
2.20.1
- Re: [PATCH v6 01/19] configure, meson: override C compiler for cmake, (continued)
- Re: [PATCH v6 01/19] configure, meson: override C compiler for cmake, Paolo Bonzini, 2022/02/18
- Re: [PATCH v6 01/19] configure, meson: override C compiler for cmake, Jag Raman, 2022/02/18
- Re: [PATCH v6 01/19] configure, meson: override C compiler for cmake, Jag Raman, 2022/02/18
- Re: [PATCH v6 01/19] configure, meson: override C compiler for cmake, Paolo Bonzini, 2022/02/20
- Re: [PATCH v6 01/19] configure, meson: override C compiler for cmake, Paolo Bonzini, 2022/02/20
- Re: [PATCH v6 01/19] configure, meson: override C compiler for cmake, Jag Raman, 2022/02/22
- Re: [PATCH v6 01/19] configure, meson: override C compiler for cmake, Paolo Bonzini, 2022/02/24
- Re: [PATCH v6 01/19] configure, meson: override C compiler for cmake, Jag Raman, 2022/02/24
- Re: [PATCH v6 01/19] configure, meson: override C compiler for cmake, Paolo Bonzini, 2022/02/28
- Re: [PATCH v6 01/19] configure, meson: override C compiler for cmake, Jag Raman, 2022/02/28
[PATCH v6 11/19] vfio-user: handle PCI config space accesses,
Jagannathan Raman <=
[PATCH v6 13/19] vfio-user: handle DMA mappings, Jagannathan Raman, 2022/02/17
[PATCH v6 14/19] vfio-user: handle PCI BAR accesses, Jagannathan Raman, 2022/02/17
[PATCH v6 16/19] softmmu/vl: defer backend init, Jagannathan Raman, 2022/02/17
[PATCH v6 15/19] vfio-user: handle device interrupts, Jagannathan Raman, 2022/02/17
[PATCH v6 18/19] vfio-user: handle reset of remote device, Jagannathan Raman, 2022/02/17
[PATCH v6 19/19] vfio-user: avocado tests for vfio-user, Jagannathan Raman, 2022/02/17
[PATCH v6 17/19] vfio-user: register handlers to facilitate migration, Jagannathan Raman, 2022/02/17