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, jing2.liu@linux.intel.com
Subject: [PATCH v1 4/4] vfio/pci: enable MSI-X in interrupt restoring on dynamic allocation
Date: Tue, 22 Aug 2023 03:29:27 -0400 [thread overview]
Message-ID: <20230822072927.224803-5-jing2.liu@intel.com> (raw)
In-Reply-To: <20230822072927.224803-1-jing2.liu@intel.com>
During migration restoring, vfio_enable_vectors() is called to restore
enabling MSI-X interrupts for assigned devices. It sets the range from
0 to nr_vectors to kernel to enable MSI-X and the vectors unmasked in
guest. During the MSI-X enabling, all the vectors within the range are
allocated according to the VFIO_DEVICE_SET_IRQS ioctl.
When dynamic MSI-X allocation is supported, we only want the guest
unmasked vectors being allocated and enabled. Use vector 0 with an
invalid fd to get MSI-X enabled, after that, all the vectors can be
allocated in need.
Signed-off-by: Jing Liu <jing2.liu@intel.com>
---
Changes since RFC v1:
- Revise the comments. (Alex)
- Call the new helper function in previous patch to enable MSI-X. (Alex)
---
hw/vfio/pci.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index e24c21241a0c..3c37d036e727 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -408,6 +408,23 @@ static int vfio_enable_vectors(VFIOPCIDevice *vdev, bool msix)
int ret = 0, i, argsz;
int32_t *fds;
+ /*
+ * If dynamic MSI-X allocation is supported, the vectors to be allocated
+ * and enabled can be scattered. Before kernel enabling MSI-X, setting
+ * nr_vectors causes all these vectors to be allocated on host.
+ *
+ * To keep allocation as needed, use vector 0 with an invalid fd to get
+ * MSI-X enabled first, then set vectors with a potentially sparse set of
+ * eventfds to enable interrupts only when enabled in guest.
+ */
+ if (msix && !vdev->msix->noresize) {
+ ret = vfio_enable_msix_no_vec(vdev);
+
+ if (ret) {
+ return ret;
+ }
+ }
+
argsz = sizeof(*irq_set) + (vdev->nr_vectors * sizeof(*fds));
irq_set = g_malloc0(argsz);
--
2.27.0
next prev parent reply other threads:[~2023-08-22 7:31 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-22 7:29 [PATCH v1 0/4] Support dynamic MSI-X allocation Jing Liu
2023-08-22 7:29 ` [PATCH v1 1/4] vfio/pci: detect the support of " Jing Liu
2023-08-29 13:33 ` Cédric Le Goater
2023-08-30 7:21 ` Liu, Jing2
2023-08-22 7:29 ` [PATCH v1 2/4] vfio/pci: enable vector on " Jing Liu
2023-08-22 7:29 ` [PATCH v1 3/4] vfio/pci: use an invalid fd to enable MSI-X Jing Liu
2023-08-29 14:04 ` Cédric Le Goater
2023-08-30 10:03 ` Liu, Jing2
2023-08-30 10:48 ` Igor Mammedov
2023-09-04 7:37 ` Liu, Jing2
2023-08-22 7:29 ` Jing Liu [this message]
2023-09-15 7:40 ` [PATCH v1 0/4] Support dynamic MSI-X allocation Liu, Jing2
2023-09-15 7:42 ` Cédric Le Goater
2023-09-15 8:03 ` 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=20230822072927.224803-5-jing2.liu@intel.com \
--to=jing2.liu@intel.com \
--cc=alex.williamson@redhat.com \
--cc=clg@redhat.com \
--cc=jing2.liu@linux.intel.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).