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 v1 2/4] virtio-pci:add support for configure interrupt
Date: Thu, 14 Jan 2021 12:43:18 +0800	[thread overview]
Message-ID: <592aa41f-120f-9bb4-0226-2fc0799b244a@redhat.com> (raw)
In-Reply-To: <20210113154540.24981-3-lulu@redhat.com>


On 2021/1/13 下午11:45, Cindy Lu wrote:
> 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         | 93 ++++++++++++++++++++++++++++++++++
>   include/hw/virtio/virtio-bus.h |  2 +
>   2 files changed, 95 insertions(+)
>
> diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
> index 36524a5728..f8053e1fab 100644
> --- a/hw/virtio/virtio-pci.c
> +++ b/hw/virtio/virtio-pci.c
> @@ -762,6 +762,98 @@ undo:
>       return ret;
>   }
>   
> + static int kvm_virtio_pci_config_irqfd_use(VirtIOPCIProxy *proxy,
> +                                 unsigned int vector)
> +{
> +    VirtIOIRQFD *irqfd = &proxy->vector_irqfd[vector];
> +    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
> +    EventNotifier *n = virtio_queue_get_config_notifier(vdev);
> +    assert(irqfd);
> +    return kvm_irqchip_add_irqfd_notifier_gsi(kvm_state, n, NULL, irqfd->virq);
> +}
> +
> +static void kvm_virtio_pci_config_irqfd_release(VirtIOPCIProxy *proxy,
> +                                      unsigned int vector)
> +{
> +    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
> +    EventNotifier *n = virtio_queue_get_config_notifier(vdev);
> +    VirtIOIRQFD *irqfd = &proxy->vector_irqfd[vector];
> +    assert(irqfd);
> +    kvm_irqchip_remove_irqfd_notifier_gsi(kvm_state, n, irqfd->virq);
> +    return;
> +}
> +static int kvm_virtio_pci_config_vector_use(VirtIOPCIProxy *proxy,
> +                                        unsigned int vector)
> +{
> +    VirtIOIRQFD *irqfd = &proxy->vector_irqfd[vector];
> +    int ret;
> +
> +    if (irqfd->users == 0) {
> +        ret = kvm_irqchip_add_msi_route(kvm_state, vector, &proxy->pci_dev);
> +        if (ret < 0) {
> +            return ret;
> +        }
> +        irqfd->virq = ret;
> +    }
> +    irqfd->users++;
> +
> +    return 0;
> +}


Any reason that we can't resue kvm_virtio_pci_vq_vector_use()? Note that 
at MSIX level there's no difference if it belongs to vq or config.


> +static int kvm_virtio_pci_vector_config_use(VirtIOPCIProxy *proxy)
> +{
> +
> +    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
> +    unsigned int vector;
> +    int ret;
> +    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
> +
> +    vector = vdev->config_vector ;
> +    ret = kvm_virtio_pci_config_vector_use(proxy, vector);
> +    if (ret < 0) {
> +        goto undo;
> +    }
> +    ret = kvm_virtio_pci_config_irqfd_use(proxy,  vector);
> +    if (ret < 0) {
> +        goto undo;
> +    }
> +    return 0;
> +undo:
> +    kvm_virtio_pci_config_irqfd_release(proxy, vector);
> +    return ret;
> +}
> +static void kvm_virtio_pci_vector_config_release(VirtIOPCIProxy *proxy)
> +{
> +    PCIDevice *dev = &proxy->pci_dev;
> +    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
> +    unsigned int vector;
> +    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
> +    vector = vdev->config_vector ;
> +    if (vector >= msix_nr_vectors_allocated(dev)) {
> +        return;
> +    }
> +    kvm_virtio_pci_config_irqfd_release(proxy, vector);
> +    kvm_virtio_pci_vq_vector_release(proxy, vector);
> +}
> +
> +static int virtio_pci_set_guest_config_notifier(DeviceState *d,  bool assign,
> +                                         bool with_irqfd)
> +{
> +    VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
> +    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
> +    EventNotifier *notifier = virtio_queue_get_config_notifier(vdev);
> +    int r = 0;
> +    if (assign) {
> +        r = event_notifier_init(notifier, 1);
> +        virtio_set_config_notifier_fd_handler(vdev, true, with_irqfd);
> +        kvm_virtio_pci_vector_config_use(proxy);
> +    } else {
> +        virtio_set_config_notifier_fd_handler(vdev, false, with_irqfd);
> +        kvm_virtio_pci_vector_config_release(proxy);
> +        event_notifier_cleanup(notifier);
> +    }
> +    return r;
> +}


Any way to re-use virtio_pci_set_guest_notifier() here?

Thanks


> +
>   static void kvm_virtio_pci_vector_release(VirtIOPCIProxy *proxy, int nvqs)
>   {
>       PCIDevice *dev = &proxy->pci_dev;
> @@ -2137,6 +2229,7 @@ static void virtio_pci_bus_class_init(ObjectClass *klass, void *data)
>       k->ioeventfd_assign = virtio_pci_ioeventfd_assign;
>       k->get_dma_as = virtio_pci_get_dma_as;
>       k->queue_enabled = virtio_pci_queue_enabled;
> +    k->set_config_notifiers = virtio_pci_set_guest_config_notifier;
>   }
>   
>   static const TypeInfo virtio_pci_bus_info = {
> diff --git a/include/hw/virtio/virtio-bus.h b/include/hw/virtio/virtio-bus.h
> index ef8abe49c5..dae81ee414 100644
> --- a/include/hw/virtio/virtio-bus.h
> +++ b/include/hw/virtio/virtio-bus.h
> @@ -93,6 +93,8 @@ struct VirtioBusClass {
>        */
>       bool has_variable_vring_alignment;
>       AddressSpace *(*get_dma_as)(DeviceState *d);
> +    int (*set_config_notifiers)(DeviceState *d, bool assign, bool with_irqfd);
> +
>   };
>   
>   struct VirtioBusState {



  reply	other threads:[~2021-01-14  4:44 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-13 15:45 [PATCH v1 0/4] vhost-vdpa: add support for configure interrupt Cindy Lu
2021-01-13 15:45 ` [PATCH v1 1/4] virtio:add support in " Cindy Lu
2021-01-14  4:33   ` Jason Wang
2021-01-14  5:57     ` Cindy Lu
2021-01-13 15:45 ` [PATCH v1 2/4] virtio-pci:add support for " Cindy Lu
2021-01-14  4:43   ` Jason Wang [this message]
2021-01-14  6:08     ` Cindy Lu
2021-01-13 15:45 ` [PATCH v1 3/4] vhost_net:enable configure interrupt when vhost_net start Cindy Lu
2021-01-13 15:45 ` [PATCH v1 4/4] vhost-vdpa:add callback function for configure interrupt Cindy Lu
2021-01-13 16:17   ` Michael S. Tsirkin
2021-01-14  6:15     ` Cindy Lu
2021-01-14  4:46   ` Jason Wang
2021-01-14  6:11     ` Cindy Lu
2021-01-14  4:35 ` [PATCH v1 0/4] vhost-vdpa: add support " Jason Wang
2021-01-14  6:14   ` Cindy Lu

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=592aa41f-120f-9bb4-0226-2fc0799b244a@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).