qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jing Liu <jing2.liu@intel.com>
To: qemu-devel@nongnu.org
Cc: alex.williamson@redhat.com, clg@redhat.com, pbonzini@redhat.com,
	kevin.tian@intel.com, reinette.chatre@intel.com,
	jing2.liu@intel.com
Subject: [PATCH RFC v1 1/3] vfio/pci: detect the support of dynamic MSI-X allocation
Date: Thu, 27 Jul 2023 03:24:08 -0400	[thread overview]
Message-ID: <20230727072410.135743-2-jing2.liu@intel.com> (raw)
In-Reply-To: <20230727072410.135743-1-jing2.liu@intel.com>

From: Reinette Chatre <reinette.chatre@intel.com>

Kernel provides the guidance of dynamic MSI-X allocation support of
passthrough device, by clearing the VFIO_IRQ_INFO_NORESIZE flag to
guide user space.

Fetch and store the flags from host for later use to determine if
specific flags are set.

Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Jing Liu <jing2.liu@intel.com>
---
 hw/vfio/pci.c        | 12 ++++++++++++
 hw/vfio/pci.h        |  1 +
 hw/vfio/trace-events |  2 ++
 3 files changed, 15 insertions(+)

diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index a205c6b1130f..0c4ac0873d40 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -1572,6 +1572,7 @@ static void vfio_msix_early_setup(VFIOPCIDevice *vdev, Error **errp)
 
 static int vfio_msix_setup(VFIOPCIDevice *vdev, int pos, Error **errp)
 {
+    struct vfio_irq_info irq_info = { .argsz = sizeof(irq_info) };
     int ret;
     Error *err = NULL;
 
@@ -1624,6 +1625,17 @@ static int vfio_msix_setup(VFIOPCIDevice *vdev, int pos, Error **errp)
         memory_region_set_enabled(&vdev->pdev.msix_table_mmio, false);
     }
 
+    irq_info.index = VFIO_PCI_MSIX_IRQ_INDEX;
+    ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_GET_IRQ_INFO, &irq_info);
+    if (ret) {
+        /* This can fail for an old kernel or legacy PCI dev */
+        trace_vfio_msix_setup_get_irq_info_failure(strerror(errno));
+    } else {
+        vdev->msix->irq_info_flags = irq_info.flags;
+    }
+    trace_vfio_msix_setup_irq_info_flags(vdev->vbasedev.name,
+                                         vdev->msix->irq_info_flags);
+
     return 0;
 }
 
diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h
index a2771b9ff3cc..ad34ec56d0ae 100644
--- a/hw/vfio/pci.h
+++ b/hw/vfio/pci.h
@@ -113,6 +113,7 @@ typedef struct VFIOMSIXInfo {
     uint32_t table_offset;
     uint32_t pba_offset;
     unsigned long *pending;
+    uint32_t irq_info_flags;
 } VFIOMSIXInfo;
 
 #define TYPE_VFIO_PCI "vfio-pci"
diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events
index ee7509e68e4f..7d4a398f044d 100644
--- a/hw/vfio/trace-events
+++ b/hw/vfio/trace-events
@@ -28,6 +28,8 @@ vfio_pci_read_config(const char *name, int addr, int len, int val) " (%s, @0x%x,
 vfio_pci_write_config(const char *name, int addr, int val, int len) " (%s, @0x%x, 0x%x, len=0x%x)"
 vfio_msi_setup(const char *name, int pos) "%s PCI MSI CAP @0x%x"
 vfio_msix_early_setup(const char *name, int pos, int table_bar, int offset, int entries) "%s PCI MSI-X CAP @0x%x, BAR %d, offset 0x%x, entries %d"
+vfio_msix_setup_get_irq_info_failure(const char *errstr) "VFIO_DEVICE_GET_IRQ_INFO failure: %s"
+vfio_msix_setup_irq_info_flags(const char *name, uint32_t flags) " (%s) MSI-X irq info flags 0x%x"
 vfio_check_pcie_flr(const char *name) "%s Supports FLR via PCIe cap"
 vfio_check_pm_reset(const char *name) "%s Supports PM reset"
 vfio_check_af_flr(const char *name) "%s Supports FLR via AF cap"
-- 
2.27.0



  reply	other threads:[~2023-07-27 14:06 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-27  7:24 [PATCH RFC v1 0/3] Support dynamic MSI-X allocation Jing Liu
2023-07-27  7:24 ` Jing Liu [this message]
2023-07-27 16:58   ` [PATCH RFC v1 1/3] vfio/pci: detect the support of " Cédric Le Goater
2023-07-28  8:34     ` Liu, Jing2
2023-07-28  8:43       ` Cédric Le Goater
2023-07-31  3:57         ` Liu, Jing2
2023-07-31  7:25           ` Cédric Le Goater
2023-07-31  8:40             ` Liu, Jing2
2023-07-27 17:24   ` Alex Williamson
2023-07-28  8:09     ` Liu, Jing2
2023-07-28  8:27       ` Cédric Le Goater
2023-07-28 15:41         ` Alex Williamson
2023-07-28 15:51           ` Cédric Le Goater
2023-07-31  3:51           ` Liu, Jing2
2023-07-27  7:24 ` [PATCH RFC v1 2/3] vfio/pci: enable vector on " Jing Liu
2023-07-27 17:07   ` Cédric Le Goater
2023-07-27 17:25   ` Alex Williamson
2023-07-31  7:17     ` Liu, Jing2
2023-07-27  7:24 ` [PATCH RFC v1 3/3] vfio/pci: dynamic MSI-X allocation in interrupt restoring Jing Liu
2023-07-27 17:24   ` Alex Williamson
2023-08-01  7:45     ` Liu, Jing2

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=20230727072410.135743-2-jing2.liu@intel.com \
    --to=jing2.liu@intel.com \
    --cc=alex.williamson@redhat.com \
    --cc=clg@redhat.com \
    --cc=kevin.tian@intel.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=reinette.chatre@intel.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).