qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: Cindy Lu <lulu@redhat.com>, mst@redhat.com, qemu-devel@nongnu.org
Subject: Re: [PATCH v8 9/9] virtio-pci: add support for configure interrupt
Date: Fri, 9 Jul 2021 14:03:10 +0800	[thread overview]
Message-ID: <5d8445fb-846d-5026-1985-cf5787dccfb0@redhat.com> (raw)
In-Reply-To: <20210706072030.32365-10-lulu@redhat.com>


在 2021/7/6 下午3:20, Cindy Lu 写道:
> Add support for configure interrupt, use kvm_irqfd_assign and set the
> gsi to kernel. When the configure notifier was eventfd_signal by host
> kernel, this will finally inject an msix interrupt to guest
>
> Signed-off-by: Cindy Lu <lulu@redhat.com>
> ---
>   hw/virtio/virtio-pci.c | 60 +++++++++++++++++++++++++++++++++++-------
>   1 file changed, 50 insertions(+), 10 deletions(-)
>
> diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
> index e43d5760ee..73b5ffd1b8 100644
> --- a/hw/virtio/virtio-pci.c
> +++ b/hw/virtio/virtio-pci.c
> @@ -717,7 +717,8 @@ static int virtio_pci_get_notifier(VirtIOPCIProxy *proxy, int queue_no,
>       VirtQueue *vq;
>   
>       if (queue_no == VIRTIO_CONFIG_IRQ_IDX) {
> -        return -1;
> +        *n = virtio_get_config_notifier(vdev);
> +        *vector = vdev->config_vector;


Is there a case that the vector is not vdev->config_vector? If not, we 
probably don't need this.


>       } else {
>           if (!virtio_queue_get_num(vdev, queue_no)) {
>               return -1;
> @@ -764,6 +765,10 @@ static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs)
>       return ret;
>   }
>   
> +static int kvm_virtio_pci_vector_config_use(VirtIOPCIProxy *proxy)
> +{
> +    return kvm_virtio_pci_vector_use_one(proxy, VIRTIO_CONFIG_IRQ_IDX);
> +}
>   
>   static void kvm_virtio_pci_vector_release_one(VirtIOPCIProxy *proxy,
>                           int queue_no)
> @@ -792,6 +797,30 @@ static void kvm_virtio_pci_vector_release(VirtIOPCIProxy *proxy, int nvqs)
>       }
>   }
>   
> +static void kvm_virtio_pci_vector_config_release(VirtIOPCIProxy *proxy)


"kvm_virtio_pci_config_vector_relase" please, consider we've already had:

kvm_virtio_pci_vq_vector_release().

Thanks


> +{
> +    kvm_virtio_pci_vector_release_one(proxy, VIRTIO_CONFIG_IRQ_IDX);
> +}



Blank line is needed.


> +static int virtio_pci_set_config_notifier(DeviceState *d, bool assign)
> +{
> +    VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
> +    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
> +    EventNotifier *notifier = virtio_get_config_notifier(vdev);
> +    int r = 0;
> +    if (assign) {
> +        r = event_notifier_init(notifier, 0);
> +        if (r < 0) {
> +            return r;
> +        }
> +        virtio_set_config_notifier_fd_handler(vdev, true, true);
> +        kvm_virtio_pci_vector_config_use(proxy);
> +    } else {
> +        virtio_set_config_notifier_fd_handler(vdev, false, true);
> +        kvm_virtio_pci_vector_config_release(proxy);
> +        event_notifier_cleanup(notifier);
> +    }


We check MSIX in virtio_pci_set_guest_notifier but not here, any reason 
for this?

And I think we need consider to reuse the code in 
virtio_pci_set_guest_notifier().


> +    return r;
> +}
>   static int virtio_pci_one_vector_unmask(VirtIOPCIProxy *proxy,
>                                          unsigned int queue_no,
>                                          unsigned int vector,
> @@ -873,7 +902,12 @@ static int virtio_pci_vector_unmask(PCIDevice *dev, unsigned vector,
>           }
>           vq = virtio_vector_next_queue(vq);
>       }
> -
> +    n = virtio_get_config_notifier(vdev);
> +    ret = virtio_pci_one_vector_unmask(proxy, VIRTIO_CONFIG_IRQ_IDX,
> +                        vector, msg, n);
> +    if (ret < 0) {
> +        goto undo;
> +    }
>       return 0;
>   
>   undo:
> @@ -909,6 +943,8 @@ static void virtio_pci_vector_mask(PCIDevice *dev, unsigned vector)
>           }
>           vq = virtio_vector_next_queue(vq);
>       }
> +    n = virtio_get_config_notifier(vdev);
> +    virtio_pci_one_vector_mask(proxy, VIRTIO_CONFIG_IRQ_IDX, vector, n);
>   }
>   
>   static void virtio_pci_vector_poll(PCIDevice *dev,
> @@ -921,19 +957,17 @@ static void virtio_pci_vector_poll(PCIDevice *dev,
>       int queue_no;
>       unsigned int vector;
>       EventNotifier *notifier;
> -    VirtQueue *vq;
> -
> -    for (queue_no = 0; queue_no < proxy->nvqs_with_notifiers; queue_no++) {
> -        if (!virtio_queue_get_num(vdev, queue_no)) {
> +    int ret;
> +    for (queue_no = VIRTIO_CONFIG_IRQ_IDX;
> +            queue_no < proxy->nvqs_with_notifiers; queue_no++) {
> +        ret = virtio_pci_get_notifier(proxy, queue_no, &notifier, &vector);
> +        if (ret < 0) {
>               break;
>           }
> -        vector = virtio_queue_vector(vdev, queue_no);
>           if (vector < vector_start || vector >= vector_end ||
>               !msix_is_masked(dev, vector)) {
>               continue;
>           }
> -        vq = virtio_get_queue(vdev, queue_no);
> -        notifier = virtio_queue_get_guest_notifier(vq);
>           if (k->guest_notifier_pending) {
>               if (k->guest_notifier_pending(vdev, queue_no)) {
>                   msix_set_pending(dev, vector);
> @@ -1002,6 +1036,7 @@ static int virtio_pci_set_guest_notifiers(DeviceState *d, int nvqs, bool assign)
>           msix_unset_vector_notifiers(&proxy->pci_dev);
>           if (proxy->vector_irqfd) {
>               kvm_virtio_pci_vector_release(proxy, nvqs);
> +            kvm_virtio_pci_vector_config_release(proxy);
>               g_free(proxy->vector_irqfd);
>               proxy->vector_irqfd = NULL;
>           }
> @@ -1029,6 +1064,10 @@ static int virtio_pci_set_guest_notifiers(DeviceState *d, int nvqs, bool assign)
>                   goto assign_error;
>               }
>           }
> +        r = virtio_pci_set_config_notifier(d, assign);
> +        if (r < 0) {
> +            goto config_error;
> +        }
>           r = msix_set_vector_notifiers(&proxy->pci_dev,
>                                         virtio_pci_vector_unmask,
>                                         virtio_pci_vector_mask,
> @@ -1045,7 +1084,8 @@ notifiers_error:
>           assert(assign);
>           kvm_virtio_pci_vector_release(proxy, nvqs);
>       }
> -
> +config_error:
> +    kvm_virtio_pci_vector_config_release(proxy);
>   assign_error:
>       /* We get here on assignment failure. Recover by undoing for VQs 0 .. n. */
>       assert(assign);



      reply	other threads:[~2021-07-09  6:04 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-06  7:20 [PATCH v8 0/9] vhost-vdpa: add support for configure interrupt Cindy Lu
2021-07-06  7:20 ` [PATCH v8 1/9] virtio: introduce macro IRTIO_CONFIG_IRQ_IDX Cindy Lu
2021-07-09  4:04   ` Jason Wang
2021-07-06  7:20 ` [PATCH v8 2/9] virtio-pci:decouple virtqueue from interrupt setting process Cindy Lu
2021-07-09  5:22   ` Jason Wang
2021-07-06  7:20 ` [PATCH v8 3/9] vhost: add new call back function for config interrupt Cindy Lu
2021-07-09  5:23   ` Jason Wang
2021-07-06  7:20 ` [PATCH v8 4/9] vhost-vdpa: add support for config interrupt call back Cindy Lu
2021-07-09  5:24   ` Jason Wang
2021-07-06  7:20 ` [PATCH v8 5/9] vhost-net:add support for configure interrupt Cindy Lu
2021-07-09  5:41   ` Jason Wang
2021-07-06  7:20 ` [PATCH v8 6/9] virtio-mmio: add " Cindy Lu
2021-07-09  5:43   ` Jason Wang
2021-07-06  7:20 ` [PATCH v8 7/9] virtio-pci: decouple notifier from interrupt process Cindy Lu
2021-07-09  5:53   ` Jason Wang
2021-07-06  7:20 ` [PATCH v8 8/9] virtio-pci:decouple the single vector from the " Cindy Lu
2021-07-09  5:54   ` Jason Wang
2021-07-06  7:20 ` [PATCH v8 9/9] virtio-pci: add support for configure interrupt Cindy Lu
2021-07-09  6:03   ` Jason Wang [this message]

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=5d8445fb-846d-5026-1985-cf5787dccfb0@redhat.com \
    --to=jasowang@redhat.com \
    --cc=lulu@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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).