From: "Cédric Le Goater" <clg@redhat.com>
To: John Levon <john.levon@nutanix.com>, qemu-devel@nongnu.org
Cc: "Jason Herne" <jjherne@linux.ibm.com>,
"Thanos Makatos" <thanos.makatos@nutanix.com>,
"Halil Pasic" <pasic@linux.ibm.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Eric Farman" <farman@linux.ibm.com>,
"Tony Krowiak" <akrowiak@linux.ibm.com>,
"Thomas Huth" <thuth@redhat.com>,
qemu-s390x@nongnu.org, "Matthew Rosato" <mjrosato@linux.ibm.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Stefano Garzarella" <sgarzare@redhat.com>,
"Alex Williamson" <alex.williamson@redhat.com>,
"David Hildenbrand" <david@redhat.com>,
"Peter Xu" <peterx@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Jagannathan Raman" <jag.raman@oracle.com>,
"John Johnson" <john.g.johnson@oracle.com>,
"Elena Ufimtseva" <elena.ufimtseva@oracle.com>
Subject: Re: [PATCH v8 08/28] vfio: add region cache
Date: Thu, 3 Apr 2025 17:46:03 +0200 [thread overview]
Message-ID: <d0f99d52-4d8d-4b1e-9e83-ec39b5357a44@redhat.com> (raw)
In-Reply-To: <20250219144858.266455-9-john.levon@nutanix.com>
On 2/19/25 15:48, John Levon wrote:
> From: Jagannathan Raman <jag.raman@oracle.com>
>
> Instead of requesting region information on demand with
> VFIO_DEVICE_GET_REGION_INFO, maintain a cache: this will become
> necessary for performance for vfio-user, where this call becomes a
> message over the control socket, so is of higher overhead than the
> traditional path.
>
> 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>
> ---
> hw/vfio/ccw.c | 5 -----
> hw/vfio/common.c | 12 ++++++++++++
> hw/vfio/container.c | 10 ++++++++++
> hw/vfio/helpers.c | 21 ++++++++++++++++-----
> hw/vfio/igd.c | 8 ++++----
> hw/vfio/pci.c | 8 ++++----
> include/hw/vfio/vfio-common.h | 1 +
> 7 files changed, 47 insertions(+), 18 deletions(-)
>
> diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
> index 67bc137f9b..22378d50bc 100644
> --- a/hw/vfio/ccw.c
> +++ b/hw/vfio/ccw.c
> @@ -510,7 +510,6 @@ static bool vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
>
> vcdev->io_region_offset = info->offset;
> vcdev->io_region = g_malloc0(info->size);
> - g_free(info);
>
> /* check for the optional async command region */
> ret = vfio_get_dev_region_info(vdev, VFIO_REGION_TYPE_CCW,
> @@ -523,7 +522,6 @@ static bool vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
> }
> vcdev->async_cmd_region_offset = info->offset;
> vcdev->async_cmd_region = g_malloc0(info->size);
> - g_free(info);
> }
>
> ret = vfio_get_dev_region_info(vdev, VFIO_REGION_TYPE_CCW,
> @@ -536,7 +534,6 @@ static bool vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
> }
> vcdev->schib_region_offset = info->offset;
> vcdev->schib_region = g_malloc(info->size);
> - g_free(info);
> }
>
> ret = vfio_get_dev_region_info(vdev, VFIO_REGION_TYPE_CCW,
> @@ -550,7 +547,6 @@ static bool vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
> }
> vcdev->crw_region_offset = info->offset;
> vcdev->crw_region = g_malloc(info->size);
> - g_free(info);
> }
>
> return true;
> @@ -560,7 +556,6 @@ out_err:
> g_free(vcdev->schib_region);
> g_free(vcdev->async_cmd_region);
> g_free(vcdev->io_region);
> - g_free(info);
> return false;
> }
>
> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
> index 4434e0a0a2..1866b3d3c5 100644
> --- a/hw/vfio/common.c
> +++ b/hw/vfio/common.c
> @@ -1569,6 +1569,16 @@ retry:
> return info;
> }
>
> +static void vfio_get_all_regions(VFIODevice *vbasedev)
> +{
> + struct vfio_region_info *info;
> + int i;
> +
> + for (i = 0; i < vbasedev->num_regions; i++) {
> + vfio_get_region_info(vbasedev, i, &info);
> + }
> +}
> +
> void vfio_prepare_device(VFIODevice *vbasedev, VFIOContainerBase *bcontainer,
> VFIOGroup *group, struct vfio_device_info *info)
> {
> @@ -1586,6 +1596,8 @@ void vfio_prepare_device(VFIODevice *vbasedev, VFIOContainerBase *bcontainer,
> }
>
> QLIST_INSERT_HEAD(&vfio_device_list, vbasedev, global_next);
> +
> + vfio_get_all_regions(vbasedev);
> }
>
> bool vfio_attach_device_by_iommu_type(const char *iommu_type, char *name,
> diff --git a/hw/vfio/container.c b/hw/vfio/container.c
> index 37a3befbc5..36cd245c92 100644
> --- a/hw/vfio/container.c
> +++ b/hw/vfio/container.c
> @@ -886,6 +886,16 @@ static bool vfio_get_device(VFIOGroup *group, const char *name,
>
> static void vfio_put_base_device(VFIODevice *vbasedev)
> {
> + if (vbasedev->regions != NULL) {
> + int i;
> +
> + for (i = 0; i < vbasedev->num_regions; i++) {
> + g_free(vbasedev->regions[i]);
> + }
> + g_free(vbasedev->regions);
> + vbasedev->regions = NULL;
> + }
> +
> if (!vbasedev->group) {
> return;
> }
> diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c
> index 4b255d4f3a..3c923d23b9 100644
> --- a/hw/vfio/helpers.c
> +++ b/hw/vfio/helpers.c
> @@ -345,7 +345,7 @@ static int vfio_setup_region_sparse_mmaps(VFIORegion *region,
> int vfio_region_setup(Object *obj, VFIODevice *vbasedev, VFIORegion *region,
> int index, const char *name)
> {
> - g_autofree struct vfio_region_info *info = NULL;
> + struct vfio_region_info *info = NULL;
> int ret;
>
> ret = vfio_get_region_info(vbasedev, index, &info);
> @@ -562,6 +562,17 @@ int vfio_get_region_info(VFIODevice *vbasedev, int index,
> {
> size_t argsz = sizeof(struct vfio_region_info);
>
> + /* create region cache */
> + if (vbasedev->regions == NULL) {
> + vbasedev->regions = g_new0(struct vfio_region_info *,
> + vbasedev->num_regions);
> + }
> + /* check cache */
> + if (vbasedev->regions[index] != NULL) {
> + *info = vbasedev->regions[index];
> + return 0;
> + }
> +
why not populate vbasedev->regions[index] in vfio_get_all_regions() ?
Thanks,
C.
> *info = g_malloc0(argsz);
>
> (*info)->index = index;
> @@ -581,6 +592,9 @@ retry:
> goto retry;
> }
>
> + /* fill cache */
> + vbasedev->regions[index] = *info;
> +
> return 0;
> }
>
> @@ -599,7 +613,6 @@ int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type,
>
> hdr = vfio_get_region_info_cap(*info, VFIO_REGION_INFO_CAP_TYPE);
> if (!hdr) {
> - g_free(*info);
> continue;
> }
>
> @@ -611,8 +624,6 @@ int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type,
> if (cap_type->type == type && cap_type->subtype == subtype) {
> return 0;
> }
> -
> - g_free(*info);
> }
>
> *info = NULL;
> @@ -621,7 +632,7 @@ int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type,
>
> bool vfio_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_type)
> {
> - g_autofree struct vfio_region_info *info = NULL;
> + struct vfio_region_info *info = NULL;
> bool ret = false;
>
> if (!vfio_get_region_info(vbasedev, region, &info)) {
> diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c
> index b1a237edd6..b5425ba9c0 100644
> --- a/hw/vfio/igd.c
> +++ b/hw/vfio/igd.c
> @@ -490,10 +490,10 @@ void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr)
>
> void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
> {
> - g_autofree struct vfio_region_info *rom = NULL;
> - g_autofree struct vfio_region_info *opregion = NULL;
> - g_autofree struct vfio_region_info *host = NULL;
> - g_autofree struct vfio_region_info *lpc = NULL;
> + struct vfio_region_info *rom = NULL;
> + struct vfio_region_info *opregion = NULL;
> + struct vfio_region_info *host = NULL;
> + struct vfio_region_info *lpc = NULL;
> VFIOQuirk *quirk;
> VFIOIGDQuirk *igd;
> PCIDevice *lpc_bridge;
> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
> index 83fe329474..a4f99fc5e0 100644
> --- a/hw/vfio/pci.c
> +++ b/hw/vfio/pci.c
> @@ -879,7 +879,7 @@ static void vfio_update_msi(VFIOPCIDevice *vdev)
>
> static void vfio_pci_load_rom(VFIOPCIDevice *vdev)
> {
> - g_autofree struct vfio_region_info *reg_info = NULL;
> + struct vfio_region_info *reg_info = NULL;
> uint64_t size;
> off_t off = 0;
> ssize_t bytes;
> @@ -2665,7 +2665,7 @@ static VFIODeviceOps vfio_pci_ops = {
> bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp)
> {
> VFIODevice *vbasedev = &vdev->vbasedev;
> - g_autofree struct vfio_region_info *reg_info = NULL;
> + struct vfio_region_info *reg_info = NULL;
> int ret;
>
> ret = vfio_get_region_info(vbasedev, VFIO_PCI_VGA_REGION_INDEX, ®_info);
> @@ -2730,7 +2730,7 @@ bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp)
> static bool vfio_populate_device(VFIOPCIDevice *vdev, Error **errp)
> {
> VFIODevice *vbasedev = &vdev->vbasedev;
> - g_autofree struct vfio_region_info *reg_info = NULL;
> + struct vfio_region_info *reg_info = NULL;
> struct vfio_irq_info irq_info = { .argsz = sizeof(irq_info) };
> int i, ret = -1;
>
> @@ -3177,7 +3177,7 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
>
> if (!vdev->igd_opregion &&
> vdev->features & VFIO_FEATURE_ENABLE_IGD_OPREGION) {
> - g_autofree struct vfio_region_info *opregion = NULL;
> + struct vfio_region_info *opregion = NULL;
>
> if (vdev->pdev.qdev.hotplugged) {
> error_setg(errp,
> diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
> index ae3ecbd9f6..304030e71d 100644
> --- a/include/hw/vfio/vfio-common.h
> +++ b/include/hw/vfio/vfio-common.h
> @@ -151,6 +151,7 @@ typedef struct VFIODevice {
> IOMMUFDBackend *iommufd;
> VFIOIOASHwpt *hwpt;
> QLIST_ENTRY(VFIODevice) hwpt_next;
> + struct vfio_region_info **regions;
> } VFIODevice;
>
> struct VFIODeviceOps {
next prev parent reply other threads:[~2025-04-03 15:46 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-19 14:48 [PATCH v8 00/28] vfio-user client John Levon
2025-02-19 14:48 ` [PATCH v8 01/28] vfio/container: pass MemoryRegion to DMA operations John Levon
2025-04-02 16:44 ` Cédric Le Goater
2025-02-19 14:48 ` [PATCH v8 02/28] vfio/container: pass listener_begin/commit callbacks John Levon
2025-04-02 12:30 ` Cédric Le Goater
2025-02-19 14:48 ` [PATCH v8 03/28] vfio/container: support VFIO_DMA_UNMAP_FLAG_ALL John Levon
2025-04-02 16:49 ` Cédric Le Goater
2025-04-03 9:45 ` John Levon
2025-04-04 15:43 ` Cédric Le Goater
2025-02-19 14:48 ` [PATCH v8 04/28] vfio: add vfio_attach_device_by_iommu_type() John Levon
2025-04-02 16:52 ` Cédric Le Goater
2025-02-19 14:48 ` [PATCH v8 05/28] vfio: add vfio_prepare_device() John Levon
2025-04-03 9:19 ` Cédric Le Goater
2025-04-03 9:34 ` John Levon
2025-04-04 15:41 ` Cédric Le Goater
2025-04-04 15:45 ` John Levon
2025-02-19 14:48 ` [PATCH v8 06/28] vfio: refactor out vfio_interrupt_setup() John Levon
2025-04-03 9:23 ` Cédric Le Goater
2025-04-03 9:38 ` John Levon
2025-02-19 14:48 ` [PATCH v8 07/28] vfio: refactor out vfio_pci_config_setup() John Levon
2025-04-03 9:30 ` Cédric Le Goater
2025-02-19 14:48 ` [PATCH v8 08/28] vfio: add region cache John Levon
2025-04-03 15:46 ` Cédric Le Goater [this message]
2025-04-03 16:00 ` John Levon
2025-04-04 16:57 ` Cédric Le Goater
2025-04-04 17:18 ` John Levon
2025-04-08 13:48 ` John Levon
2025-02-19 14:48 ` [PATCH v8 09/28] vfio: split out VFIOKernelPCIDevice John Levon
2025-04-03 17:13 ` Cédric Le Goater
2025-04-03 18:08 ` John Levon
2025-04-04 12:49 ` Cédric Le Goater
2025-04-04 14:21 ` John Levon
2025-04-04 14:48 ` Cédric Le Goater
2025-04-04 15:44 ` John Levon
2025-02-19 14:48 ` [PATCH v8 10/28] vfio: add device IO ops vector John Levon
2025-04-04 14:36 ` Cédric Le Goater
2025-04-04 15:53 ` John Levon
2025-02-19 14:48 ` [PATCH v8 11/28] vfio-user: introduce vfio-user protocol specification John Levon
2025-02-19 14:48 ` [PATCH v8 12/28] vfio-user: add vfio-user class and container John Levon
2025-02-19 14:48 ` [PATCH v8 13/28] vfio-user: connect vfio proxy to remote server John Levon
2025-02-19 14:48 ` [PATCH v8 14/28] vfio-user: implement message receive infrastructure John Levon
2025-02-19 14:48 ` [PATCH v8 15/28] vfio-user: implement message send infrastructure John Levon
2025-02-19 14:48 ` [PATCH v8 16/28] vfio-user: implement VFIO_USER_DEVICE_GET_INFO John Levon
2025-02-19 14:48 ` [PATCH v8 17/28] vfio-user: implement VFIO_USER_DEVICE_GET_REGION_INFO John Levon
2025-02-19 14:48 ` [PATCH v8 18/28] vfio-user: implement VFIO_USER_REGION_READ/WRITE John Levon
2025-02-19 14:48 ` [PATCH v8 19/28] vfio-user: set up PCI in vfio_user_pci_realize() John Levon
2025-02-19 14:48 ` [PATCH v8 20/28] vfio-user: implement VFIO_USER_DEVICE_GET/SET_IRQ* John Levon
2025-02-19 14:48 ` [PATCH v8 21/28] vfio-user: forward MSI-X PBA BAR accesses to server John Levon
2025-02-19 14:48 ` [PATCH v8 22/28] vfio-user: set up container access to the proxy John Levon
2025-02-19 14:48 ` [PATCH v8 23/28] vfio-user: implement VFIO_USER_DEVICE_RESET John Levon
2025-02-19 14:48 ` [PATCH v8 24/28] vfio-user: implement VFIO_USER_DMA_MAP/UNMAP John Levon
2025-02-19 14:48 ` [PATCH v8 25/28] vfio-user: implement VFIO_USER_DMA_READ/WRITE John Levon
2025-02-19 14:48 ` [PATCH v8 26/28] vfio-user: add 'no-direct-dma' option John Levon
2025-02-19 14:48 ` [PATCH v8 27/28] vfio-user: add 'x-msg-timeout' option John Levon
2025-02-19 14:48 ` [PATCH v8 28/28] vfio-user: add coalesced posted writes John Levon
2025-02-28 17:09 ` [PATCH v8 00/28] vfio-user client Jag Raman
2025-03-03 11:19 ` John Levon
2025-03-03 15:39 ` Jag Raman
2025-03-14 14:25 ` Cédric Le Goater
2025-03-14 14:48 ` Steven Sistare
2025-03-18 10:00 ` Cédric Le Goater
2025-03-14 15:13 ` John Levon
2025-03-18 10:02 ` Cédric Le Goater
2025-04-04 17:21 ` Cédric Le Goater
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=d0f99d52-4d8d-4b1e-9e83-ec39b5357a44@redhat.com \
--to=clg@redhat.com \
--cc=akrowiak@linux.ibm.com \
--cc=alex.williamson@redhat.com \
--cc=berrange@redhat.com \
--cc=david@redhat.com \
--cc=elena.ufimtseva@oracle.com \
--cc=farman@linux.ibm.com \
--cc=jag.raman@oracle.com \
--cc=jjherne@linux.ibm.com \
--cc=john.g.johnson@oracle.com \
--cc=john.levon@nutanix.com \
--cc=marcandre.lureau@redhat.com \
--cc=mjrosato@linux.ibm.com \
--cc=mst@redhat.com \
--cc=pasic@linux.ibm.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=sgarzare@redhat.com \
--cc=thanos.makatos@nutanix.com \
--cc=thuth@redhat.com \
/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).