From: Alex Williamson <alex.williamson@redhat.com>
To: Jing Liu <jing2.liu@intel.com>
Cc: qemu-devel@nongnu.org, clg@redhat.com, pbonzini@redhat.com,
kevin.tian@intel.com, reinette.chatre@intel.com
Subject: Re: [PATCH RFC v1 3/3] vfio/pci: dynamic MSI-X allocation in interrupt restoring
Date: Thu, 27 Jul 2023 11:24:47 -0600 [thread overview]
Message-ID: <20230727112447.4f9e5bc8.alex.williamson@redhat.com> (raw)
In-Reply-To: <20230727072410.135743-4-jing2.liu@intel.com>
On Thu, 27 Jul 2023 03:24:10 -0400
Jing Liu <jing2.liu@intel.com> wrote:
> 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 ioctl().
>
> When dynamic MSI-X allocation is supported, we only want the guest
> unmasked vectors being allocated and enabled. Therefore, Qemu can first
> set vector 0 to enable MSI-X and after that, all the vectors can be
> allocated in need.
>
> Signed-off-by: Jing Liu <jing2.liu@intel.com>
> ---
> hw/vfio/pci.c | 32 ++++++++++++++++++++++++++++++++
> 1 file changed, 32 insertions(+)
>
> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
> index 8c485636445c..43ffacd5b36a 100644
> --- a/hw/vfio/pci.c
> +++ b/hw/vfio/pci.c
> @@ -375,6 +375,38 @@ 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 being allocated on host.
s/being/to be/
> + *
> + * To keep allocation as needed, first setup vector 0 with an invalid
> + * fd to make MSI-X enabled, then enable vectors by setting all so that
> + * kernel allocates and enables interrupts only when enabled in guest.
> + */
> + if (msix && !(vdev->msix->irq_info_flags & VFIO_IRQ_INFO_NORESIZE)) {
!vdev->msix->noresize again seems cleaner.
> + argsz = sizeof(*irq_set) + sizeof(*fds);
> +
> + irq_set = g_malloc0(argsz);
> + irq_set->argsz = argsz;
> + irq_set->flags = VFIO_IRQ_SET_DATA_EVENTFD |
> + VFIO_IRQ_SET_ACTION_TRIGGER;
> + irq_set->index = msix ? VFIO_PCI_MSIX_IRQ_INDEX :
> + VFIO_PCI_MSI_IRQ_INDEX;
Why are we testing msix again within a branch that requires msix?
> + irq_set->start = 0;
> + irq_set->count = 1;
> + fds = (int32_t *)&irq_set->data;
> + fds[0] = -1;
> +
> + ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_SET_IRQS, irq_set);
> +
> + g_free(irq_set);
> +
> + if (ret) {
> + return ret;
> + }
> + }
So your goal here is simply to get the kernel to call vfio_msi_enable()
with nvec = 1 to get MSI-X enabled on the device, which then allows the
kernel to use the dynamic expansion when we call SET_IRQS again with a
potentially sparse set of eventfds to vector mappings. This seems very
similar to the nr_vectors == 0 branch of vfio_msix_enable() where it
uses a do_use and release call to accomplish getting MSI-X enabled. We
should consolidate, probably by pulling this out into a function since
it seems cleaner to use the fd = -1 trick than to setup userspace
triggering and immediately release. Thanks,
Alex
> +
> argsz = sizeof(*irq_set) + (vdev->nr_vectors * sizeof(*fds));
>
> irq_set = g_malloc0(argsz);
next prev parent reply other threads:[~2023-07-27 17:28 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 ` [PATCH RFC v1 1/3] vfio/pci: detect the support of " Jing Liu
2023-07-27 16:58 ` 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 [this message]
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=20230727112447.4f9e5bc8.alex.williamson@redhat.com \
--to=alex.williamson@redhat.com \
--cc=clg@redhat.com \
--cc=jing2.liu@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).