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 2/3] vfio/pci: enable vector on dynamic MSI-X allocation
Date: Thu, 27 Jul 2023 11:25:03 -0600 [thread overview]
Message-ID: <20230727112503.4160f411.alex.williamson@redhat.com> (raw)
In-Reply-To: <20230727072410.135743-3-jing2.liu@intel.com>
On Thu, 27 Jul 2023 03:24:09 -0400
Jing Liu <jing2.liu@intel.com> wrote:
> The vector_use callback is used to enable vector that is unmasked in
> guest. The kernel used to only support static MSI-X allocation. When
> allocating a new interrupt using "static MSI-X allocation" kernels,
> Qemu first disables all previously allocated vectors and then
> re-allocates all including the new one. The nr_vectors of VFIOPCIDevice
> indicates that all vectors from 0 to nr_vectors are allocated (and may
> be enabled), which is used to to loop all the possibly used vectors
> When, e.g., disabling MSI-X interrupts.
>
> Extend the vector_use function to support dynamic MSI-X allocation when
> host supports the capability. Qemu therefore can individually allocate
> and enable a new interrupt without affecting others or causing interrupts
> lost during runtime.
>
> Utilize nr_vectors to calculate the upper bound of enabled vectors in
> dynamic MSI-X allocation mode since looping all msix_entries_nr is not
> efficient and unnecessary.
>
> Signed-off-by: Jing Liu <jing2.liu@intel.com>
> Tested-by: Reinette Chatre <reinette.chatre@intel.com>
> ---
> hw/vfio/pci.c | 40 +++++++++++++++++++++++++++-------------
> 1 file changed, 27 insertions(+), 13 deletions(-)
>
> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
> index 0c4ac0873d40..8c485636445c 100644
> --- a/hw/vfio/pci.c
> +++ b/hw/vfio/pci.c
> @@ -512,12 +512,20 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, unsigned int nr,
> }
>
> /*
> - * We don't want to have the host allocate all possible MSI vectors
> - * for a device if they're not in use, so we shutdown and incrementally
> - * increase them as needed.
> + * When dynamic allocation is not supported, we don't want to have the
> + * host allocate all possible MSI vectors for a device if they're not
> + * in use, so we shutdown and incrementally increase them as needed.
> + * And nr_vectors stands for the number of vectors being allocated.
"nr_vectors represents the total number of vectors allocated."
> + *
> + * When dynamic allocation is supported, let the host only allocate
> + * and enable a vector when it is in use in guest. nr_vectors stands
> + * for the upper bound of vectors being enabled (but not all of the
> + * ranges is allocated or enabled).
s/stands for/represents/
> */
> - if (vdev->nr_vectors < nr + 1) {
> + if ((vdev->msix->irq_info_flags & VFIO_IRQ_INFO_NORESIZE) &&
Testing vdev->msix->noresize would be cleaner.
> + (vdev->nr_vectors < nr + 1)) {
> vdev->nr_vectors = nr + 1;
> +
> if (!vdev->defer_kvm_irq_routing) {
> vfio_disable_irqindex(&vdev->vbasedev, VFIO_PCI_MSIX_IRQ_INDEX);
> ret = vfio_enable_vectors(vdev, true);
> @@ -529,16 +537,22 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, unsigned int nr,
> Error *err = NULL;
> int32_t fd;
>
> - if (vector->virq >= 0) {
> - fd = event_notifier_get_fd(&vector->kvm_interrupt);
> - } else {
> - fd = event_notifier_get_fd(&vector->interrupt);
> - }
> + if (!vdev->defer_kvm_irq_routing) {
> + if (vector->virq >= 0) {
> + fd = event_notifier_get_fd(&vector->kvm_interrupt);
> + } else {
> + fd = event_notifier_get_fd(&vector->interrupt);
> + }
>
> - if (vfio_set_irq_signaling(&vdev->vbasedev,
> - VFIO_PCI_MSIX_IRQ_INDEX, nr,
> - VFIO_IRQ_SET_ACTION_TRIGGER, fd, &err)) {
> - error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name);
> + if (vfio_set_irq_signaling(&vdev->vbasedev,
> + VFIO_PCI_MSIX_IRQ_INDEX, nr,
> + VFIO_IRQ_SET_ACTION_TRIGGER, fd, &err)) {
> + error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name);
> + }
> + }
> + /* Increase for dynamic allocation case. */
> + if (vdev->nr_vectors < nr + 1) {
> + vdev->nr_vectors = nr + 1;
> }
We now have two branches where the bulk of the code is skipped when
defer_kvm_irq_routing is enabled and doing effectively the same update
to nr_vectors otherwise. This suggests we should move the
defer_kvm_irq_routing test out and create a common place to update
nr_vectors. Thanks,
Alex
next prev parent reply other threads:[~2023-07-27 17:42 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 [this message]
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=20230727112503.4160f411.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).