kvm/vfio: detect assigned device via irqbypass manager
Subsystems (4)
Quoted 10 lines · On Sun, 12 Jul 2020 22:49:21 +0800 Zhu Lingshan <[email protected]> wrote:
We used to detect assigned device via VFIO manipulated device conters. This is less flexible consider VFIO is not the only interface for assigned device. vDPA devices has dedicated backed hardware as well. So this patch tries to detect the assigned device via irqbypass manager.
We will increase/decrease the assigned device counter in kvm/x86. Both vDPA and VFIO would go through this code path.
This code path only affect x86 for now.
No it doesn't, it only adds VFIO support to x86, but it removes it from architecture neutral code. Also a VFIO device does not necessarily make use of the irqbypass manager, this depends on platform support and
enablement of this feature. Therefore, NAK. Thanks,
Alex
Quoted 50 lines
Signed-off-by Zhu Lingshan <[email protected]>--- arch/x86/kvm/x86.c | 10 ++++++++-- virt/kvm/vfio.c | 2 -- 2 files changed, 8 insertions(+), 4 deletions(-)arch/x86/kvm/x86.c +8
-2@@ -10624,11 +10624,17 @@ int kvm_arch_irq_bypass_add_producer(struct irq_bypass_consumer *cons, {struct kvm_kernel_irqfd *irqfd = container_of(cons, struct kvm_kernel_irqfd, consumer); +int ret; irqfd->producer = prod; +kvm_arch_start_assignment (irqfd->kvm); + ret = kvm_x86_ops.update_pi_irte (irqfd->kvm, + prod->irq, irqfd->gsi,1 ); + +if (ret) +kvm_arch_end_assignment (irqfd->kvm); -return kvm_x86_ops.update_pi_irte (irqfd->kvm, - prod->irq, irqfd->gsi,1 ); +return ret; } void kvm_arch_irq_bypass_del_producer(struct irq_bypass_consumer *cons,virt/kvm/vfio.c +0
-2@@ -226,7 +226,6 @@ static int kvm_vfio_set_group(struct kvm_device *dev, long attr, u64 arg)list_add_tail (&kvg->node, &kv->group_list); kvg->vfio_group = vfio_group; -kvm_arch_start_assignment (dev->kvm);mutex_unlock (&kv->lock);@@ -254,7 +253,6 @@ static int kvm_vfio_set_group(struct kvm_device *dev, long attr, u64 arg)continue ;list_del (&kvg->node); -kvm_arch_end_assignment (dev->kvm);#ifdef CONFIG_SPAPR_TCE_IOMMU kvm_spapr_tce_release_vfio_group (dev->kvm, kvg->vfio_group);
Michael S. Tsirkin
maintainerQuoted 6 lines · Zhu Lingshan
We used to detect assigned device via VFIO manipulated device conters. This is less flexible consider VFIO is not the only interface for assigned device. vDPA devices has dedicated backed hardware as well. So this patch tries to detect the assigned device via irqbypass manager.
Quoted 6 lines
We will increase/decrease the assigned device counter in kvm/x86. Both vDPA and VFIO would go through this code path.
This code path only affect x86 for now.
Signed-off-by Zhu Lingshan <[email protected]>
I think it's best to leave VFIO alone. Add appropriate APIs for VDPA, worry about converting existing users later.
Quoted 51 lines
--- arch/x86/kvm/x86.c | 10 ++++++++-- virt/kvm/vfio.c | 2 -- 2 files changed, 8 insertions(+), 4 deletions(-)arch/x86/kvm/x86.c +8
-2@@ -10624,11 +10624,17 @@ int kvm_arch_irq_bypass_add_producer(struct irq_bypass_consumer *cons, {struct kvm_kernel_irqfd *irqfd = container_of(cons, struct kvm_kernel_irqfd, consumer); +int ret; irqfd->producer = prod; +kvm_arch_start_assignment (irqfd->kvm); + ret = kvm_x86_ops.update_pi_irte (irqfd->kvm, + prod->irq, irqfd->gsi,1 ); + +if (ret) +kvm_arch_end_assignment (irqfd->kvm); -return kvm_x86_ops.update_pi_irte (irqfd->kvm, - prod->irq, irqfd->gsi,1 ); +return ret; } void kvm_arch_irq_bypass_del_producer(struct irq_bypass_consumer *cons,virt/kvm/vfio.c +0
-2@@ -226,7 +226,6 @@ static int kvm_vfio_set_group(struct kvm_device *dev, long attr, u64 arg)list_add_tail (&kvg->node, &kv->group_list); kvg->vfio_group = vfio_group; -kvm_arch_start_assignment (dev->kvm);mutex_unlock (&kv->lock);@@ -254,7 +253,6 @@ static int kvm_vfio_set_group(struct kvm_device *dev, long attr, u64 arg)continue ;list_del (&kvg->node); -kvm_arch_end_assignment (dev->kvm);#ifdef CONFIG_SPAPR_TCE_IOMMU kvm_spapr_tce_release_vfio_group (dev->kvm, kvg->vfio_group);Signature · 1 line
1.8.3.1
Quoted 9 lines · Alex Williamson
Quoted 6 lines · On Sun, 12 Jul 2020 22:49:21 +0800 Zhu Lingshan <[email protected]> wrote:
We used to detect assigned device via VFIO manipulated device conters. This is less flexible consider VFIO is not the only interface for assigned device. vDPA devices has dedicated backed hardware as well. So this patch tries to detect the assigned device via irqbypass manager.
Quoted 6 lines
Quoted 4 lines
We will increase/decrease the assigned device counter in kvm/x86. Both vDPA and VFIO would go through this code path.
This code path only affect x86 for now.
No it doesn't, it only adds VFIO support to x86, but it removes it from architecture neutral code.
Do you mean we should introduce a kvm_irq_bypass_add_producer and do kvm_arch_start_assignment( ) there?
Quoted 3 lines
Also a VFIO device does not necessarily
make use of the irqbypass manager, this depends on platform support and enablement of this feature.
Yes, we should keep the VFIO part unchanged.
Thanks
Quoted 54 lines
Therefore, NAK. Thanks,
Alex
Quoted 50 lines
Signed-off-by Zhu Lingshan <[email protected]>--- arch/x86/kvm/x86.c | 10 ++++++++-- virt/kvm/vfio.c | 2 -- 2 files changed, 8 insertions(+), 4 deletions(-)arch/x86/kvm/x86.c +8
-2@@ -10624,11 +10624,17 @@ int kvm_arch_irq_bypass_add_producer(struct irq_bypass_consumer *cons, {struct kvm_kernel_irqfd *irqfd = container_of(cons, struct kvm_kernel_irqfd, consumer); +int ret; irqfd->producer = prod; +kvm_arch_start_assignment (irqfd->kvm); + ret = kvm_x86_ops.update_pi_irte (irqfd->kvm, + prod->irq, irqfd->gsi,1 ); + +if (ret) +kvm_arch_end_assignment (irqfd->kvm); -return kvm_x86_ops.update_pi_irte (irqfd->kvm, - prod->irq, irqfd->gsi,1 ); +return ret; } void kvm_arch_irq_bypass_del_producer(struct irq_bypass_consumer *cons,virt/kvm/vfio.c +0
-2@@ -226,7 +226,6 @@ static int kvm_vfio_set_group(struct kvm_device *dev, long attr, u64 arg)list_add_tail (&kvg->node, &kv->group_list); kvg->vfio_group = vfio_group; -kvm_arch_start_assignment (dev->kvm);mutex_unlock (&kv->lock);@@ -254,7 +253,6 @@ static int kvm_vfio_set_group(struct kvm_device *dev, long attr, u64 arg)continue ;list_del (&kvg->node); -kvm_arch_end_assignment (dev->kvm);#ifdef CONFIG_SPAPR_TCE_IOMMU kvm_spapr_tce_release_vfio_group (dev->kvm, kvg->vfio_group);
Quoted 10 lines · Michael S. Tsirkin
Quoted 9 lines · Zhu Lingshan
We used to detect assigned device via VFIO manipulated device conters. This is less flexible consider VFIO is not the only interface for assigned device. vDPA devices has dedicated backed hardware as well. So this patch tries to detect the assigned device via irqbypass manager.
We will increase/decrease the assigned device counter in kvm/x86. Both vDPA and VFIO would go through this code path.
Quoted 6 lines
Quoted 3 lines
This code path only affect x86 for now.
Signed-off-by Zhu Lingshan <[email protected]>I think it's best to leave VFIO alone. Add appropriate APIs for VDPA, worry about converting existing users later.
Just to make sure I understand, did you mean:
1) introduce another bridge for vDPA
or
2) only detect vDPA via bypass manager? (we can leave VFIO code as is, then the assigned device counter may increase/decrease twice if VFIO use irq bypass manager which should be no harm).
Thanks
Quoted 52 lines
Quoted 52 lines
--- arch/x86/kvm/x86.c | 10 ++++++++-- virt/kvm/vfio.c | 2 -- 2 files changed, 8 insertions(+), 4 deletions(-)arch/x86/kvm/x86.c +8
-2@@ -10624,11 +10624,17 @@ int kvm_arch_irq_bypass_add_producer(struct irq_bypass_consumer *cons, {struct kvm_kernel_irqfd *irqfd = container_of(cons, struct kvm_kernel_irqfd, consumer); +int ret; irqfd->producer = prod; +kvm_arch_start_assignment (irqfd->kvm); + ret = kvm_x86_ops.update_pi_irte (irqfd->kvm, + prod->irq, irqfd->gsi,1 ); + +if (ret) +kvm_arch_end_assignment (irqfd->kvm); -return kvm_x86_ops.update_pi_irte (irqfd->kvm, - prod->irq, irqfd->gsi,1 ); +return ret; } void kvm_arch_irq_bypass_del_producer(struct irq_bypass_consumer *cons,virt/kvm/vfio.c +0
-2@@ -226,7 +226,6 @@ static int kvm_vfio_set_group(struct kvm_device *dev, long attr, u64 arg)list_add_tail (&kvg->node, &kv->group_list); kvg->vfio_group = vfio_group; -kvm_arch_start_assignment (dev->kvm);mutex_unlock (&kv->lock);@@ -254,7 +253,6 @@ static int kvm_vfio_set_group(struct kvm_device *dev, long attr, u64 arg)continue ;list_del (&kvg->node); -kvm_arch_end_assignment (dev->kvm);#ifdef CONFIG_SPAPR_TCE_IOMMU kvm_spapr_tce_release_vfio_group (dev->kvm, kvg->vfio_group);Signature · 1 line
1.8.3.1
Re: [PATCH 3/7] vhost_vdpa: implement IRQ offloading functions in vhost_vdpa
In reply to a message not in the archiveQuoted 27 lines · Zhu Lingshan
This patch introduce a set of functions for setup/unsetup and update irq offloading respectively by register/unregister and re-register the
irq_bypass_producer.Signed-off-by Zhu Lingshan <[email protected]>--- drivers/vhost/vdpa.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+)drivers/vhost/vdpa.c +10
-0@@ -115,6 +115,63 @@ static irqreturn_t vhost_vdpa_config_cb(void *private)return IRQ_HANDLED ; } +static void vhost_vdpa_setup_vq_irq (struct vdpa_device *dev,int qid,int irq) +{ +struct vhost_vdpa *v =vdpa_get_drvdata (dev); +struct vhost_virtqueue *vq = &v->vqs[qid]; +int ret; + +vq_err (vq,"setup irq bypass for vq %d with irq = %d\n" , qid, irq); +spin_lock (&vq->call_ctx.ctx_lock); +if (!vq->call_ctx.ctx) +return ;
drivers/vhost/vdpa.c static irqreturn_t vhost_vdpa_config_cb(void *private) · line 137
Quoted 10 lines
drivers/vhost/vdpa.c +10
-0+ + vq->call_ctx.producer.token = vq->call_ctx.ctx; + vq->call_ctx.producer.irq = irq; + ret =irq_bypass_register_producer (&vq->call_ctx.producer); +spin_unlock (&vq->call_ctx.ctx_lock); + +if (unlikely (ret)) +vq_err (vq, +"irq bypass producer (token %p registration fails: %d\n" , + vq->call_ctx.producer.token, ret);
Not sure this deserves a vq_err(), irq will be relayed through eventfd if irq bypass manager can't work.
drivers/vhost/vdpa.c static irqreturn_t vhost_vdpa_config_cb(void *private) · line 149
Quoted 12 lines
drivers/vhost/vdpa.c +12
-0+} + +static void vhost_vdpa_unsetup_vq_irq (struct vdpa_device *dev,int qid) +{ +struct vhost_vdpa *v =vdpa_get_drvdata (dev); +struct vhost_virtqueue *vq = &v->vqs[qid]; + +spin_lock (&vq->call_ctx.ctx_lock); +irq_bypass_unregister_producer (&vq->call_ctx.producer); +spin_unlock (&vq->call_ctx.ctx_lock); + +vq_err (vq,"unsetup irq bypass for vq %d\n" , qid);
Why call vq_err() here?
drivers/vhost/vdpa.c static irqreturn_t vhost_vdpa_config_cb(void *private) · line 161
Quoted 12 lines
drivers/vhost/vdpa.c +12
-0+} + +static void vhost_vdpa_update_vq_irq (struct vhost_virtqueue *vq) +{ +struct eventfd_ctx *ctx; +void *token; + +spin_lock (&vq->call_ctx.ctx_lock); + ctx = vq->call_ctx.ctx; + token = vq->call_ctx.producer.token; +if (ctx == token) +return ;
Need do unlock here.
drivers/vhost/vdpa.c static irqreturn_t vhost_vdpa_config_cb(void *private) · line 172
Quoted 11 lines
drivers/vhost/vdpa.c +11
-0+ +if (!ctx && token) +irq_bypass_unregister_producer (&vq->call_ctx.producer); + +if (ctx && ctx != token) { +irq_bypass_unregister_producer (&vq->call_ctx.producer); + vq->call_ctx.producer.token = ctx; +irq_bypass_register_producer (&vq->call_ctx.producer); + } + +spin_unlock (&vq->call_ctx.ctx_lock);
This should be rare so I'd use simple codes just do unregister and register.
drivers/vhost/vdpa.c static long vhost_vdpa_set_config_call(struct vhost_vdpa *v, u32 __user *argp) · line 392
Quoted 10 lines
drivers/vhost/vdpa.c +3
-0+} +static void vhost_vdpa_reset (struct vhost_vdpa *v) {struct vdpa_device *vdpa = v->vdpa;@@ -332,6 +389,7 @@ static long vhost_vdpa_set_config_call(struct vhost_vdpa *v, u32 __user *argp)return 0 ; } +
Unnecessary change.
Quoted 21 lines
drivers/vhost/vdpa.c +10
-0static long vhost_vdpa_vring_ioctl (struct vhost_vdpa *v,unsigned int cmd,void __user *argp) {@@ -390,6 +448,16 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd, cb.private =NULL ; } ops->set_vq_cb (vdpa, idx, &cb); +#ifdef CONFIG_HAVE_KVM_IRQ_BYPASS +/* +* if it has a non-zero irq, means there is a +* previsouly registered irq_bypass_producer, +* we should update it when ctx (its token) +* changes. +*/ +if (vq->call_ctx.producer.irq) +vhost_vdpa_update_vq_irq (vq); +#endif break ;case VHOST_SET_VRING_NUM :
drivers/vhost/vdpa.c static int vhost_vdpa_open(struct inode *inode, struct file *filep) · line 812
Quoted 4 lines
drivers/vhost/vdpa.c +1
-0@@ -741,6 +809,7 @@ static int vhost_vdpa_open(struct inode *inode, struct file *filep) vqs[i] = &v->vqs[i]; vqs[i]->handle_kick = handle_vq_kick; } +
Unnecessary change.
Thanks
Quoted 3 lines
drivers/vhost/vdpa.c +0
-0vhost_dev_init (dev, vqs, nvqs,0 ,0 ,0 , false, vhost_vdpa_process_iotlb_msg);
Re: [PATCH 4/7] vDPA: implement IRQ offloading helpers in vDPA core
In reply to a message not in the archiveQuoted 10 lines · Zhu Lingshan
This commit implements IRQ offloading helpers in vDPA core by introducing two couple of functions:
vdpa_alloc_vq_irq()andvdpa_free_vq_irq(): request irq and free irq, will setup irq offloading ifirq_bypassis enabled.
vdpa_setup_irq()andvdpa_unsetup_irq(): supportive functions, will callvhost_vdpahelpers.Signed-off-by Zhu Lingshan <[email protected]>
This patch should go before patch 3.
Quoted 12 lines
--- drivers/vdpa/vdpa.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/vhost/Kconfig | 1 + drivers/vhost/vdpa.c | 2 ++ include/linux/vdpa.h | 11 +++++++++++ 4 files changed, 60 insertions(+)drivers/vdpa/vdpa.c +0
-0
drivers/vdpa/vdpa.c void vdpa_unregister_driver(struct vdpa_driver *drv) · line 170
Quoted 8 lines
drivers/vdpa/vdpa.c +5
-0@@ -163,6 +163,52 @@ void vdpa_unregister_driver(struct vdpa_driver *drv) }EXPORT_SYMBOL_GPL (vdpa_unregister_driver); +static void vdpa_setup_irq (struct vdpa_device *vdev,int qid,int irq) +{ +struct vdpa_driver *drv =drv_to_vdpa (vdev->dev.driver); + +#ifdef CONFIG_HAVE_KVM_IRQ_BYPASS
Let's don't do the check here. It's the responsibility of driver to decide what it should do.
Quoted 17 lines
drivers/vdpa/vdpa.c +17
-0+if (drv->setup_vq_irq) + drv->setup_vq_irq (vdev, qid, irq); +#endif +} + +static void vdpa_unsetup_irq (struct vdpa_device *vdev,int qid) +{ +struct vdpa_driver *drv =drv_to_vdpa (vdev->dev.driver); + +#ifdef CONFIG_HAVE_KVM_IRQ_BYPASS +if (drv->unsetup_vq_irq) + drv->unsetup_vq_irq (vdev, qid); +#endif +} + +int vdpa_alloc_vq_irq(struct device *dev, struct vdpa_device *vdev, + unsigned int irq, irq_handler_t handler,
drivers/vdpa/vdpa.c void vdpa_unregister_driver(struct vdpa_driver *drv) · line 197
Quoted 10 lines
drivers/vdpa/vdpa.c +10
-0+ unsigned long irqflags, const char *devname, void *dev_id, + int qid) +{ + int ret; + + ret =devm_request_irq (dev, irq, handler, irqflags, devname, dev_id); +if (ret) +dev_err (dev,"Failed to request irq for vq %d\n" , qid); +else +vdpa_setup_irq (vdev, qid, irq);
I'd like to squash the vdpa_setup_irq logic here.
drivers/vhost/Kconfig
Quoted 18 lines
drivers/vdpa/vdpa.c +14
-0+ +return ret; + +} +EXPORT_SYMBOL_GPL (vdpa_alloc_vq_irq); + +void vdpa_free_vq_irq (struct device *dev,struct vdpa_device *vdev,int irq, +int qid,void *dev_id) +{ +devm_free_irq (dev, irq, dev_id); +vdpa_unsetup_irq (vdev, qid); +} +EXPORT_SYMBOL_GPL (vdpa_free_vq_irq); +static int vdpa_init (void ) {return bus_register (&vdpa_bus);drivers/vhost/Kconfig +0
-0
Let squash the vhost patch into patch 3.
Quoted 29 lines
index d3688c6..587fbae 100644
drivers/vhost/Kconfig +1
-0@@ -65,6 +65,7 @@ config VHOST_VDPA tristate "Vhost driver for vDPA-based backend" depends on EVENTFD select VHOST + select IRQ_BYPASS_MANAGER depends on VDPA help This kernel module can be loaded in host kernel to acceleratedrivers/vhost/vdpa.c +2
-0@@ -1020,6 +1020,8 @@ static void vhost_vdpa_remove(struct vdpa_device *vdpa) }, .probe = vhost_vdpa_probe, .remove = vhost_vdpa_remove, + .setup_vq_irq = vhost_vdpa_setup_vq_irq, + .unsetup_vq_irq = vhost_vdpa_unsetup_vq_irq, };static int __init vhost_vdpa_init (void )include/linux/vdpa.h +0
-0
include/linux/vdpa.h struct vdpa_device *__vdpa_alloc_device(struct device *parent, · line 228
Quoted 9 lines
include/linux/vdpa.h +6
-0@@ -220,17 +220,28 @@ struct vdpa_device *__vdpa_alloc_device(struct device *parent,int vdpa_register_device (struct vdpa_device *vdev);void vdpa_unregister_device (struct vdpa_device *vdev); +int vdpa_alloc_vq_irq (struct device *dev,struct vdpa_device *vdev, +unsigned int irq,irq_handler_t handler, +unsigned long irqflags,const char *devname,void *dev_id, +int qid); +void vdpa_free_vq_irq (struct device *dev,struct vdpa_device *vdev,int irq, +int qid,void *dev_id);
You need to document the devres implications of those two helpers.
include/linux/vdpa.h struct vdpa_device *__vdpa_alloc_device(struct device *parent, · line 237
Quoted 9 lines
include/linux/vdpa.h +3
-0+/** * vdpa_driver - operations for a vDPA driver * @driver: underlying device driver * @probe: the function to call when a device is found. Returns 0 or -errno. * @remove: the function to call when a device is removed. +* @setup_vq_irq: setup irq bypass for a vhost_vdpa vq. +* @unsetup_vq_irq: unsetup irq bypass for a vhost_vdpa vq.
Though irq bypass is used by vhost-vdpa, it's not necessarily to be true in the future. So it's better not to mention irqbypass in the doc here.
Thanks
Quoted 10 lines
include/linux/vdpa.h +2
-0*/ struct vdpa_driver {struct device_driver driver;int (*probe)(struct vdpa_device *vdev);void (*remove)(struct vdpa_device *vdev); +void (*setup_vq_irq)(struct vdpa_device *vdev,int qid,int irq); +void (*unsetup_vq_irq)(struct vdpa_device *vdev,int qid); };#define vdpa_register_driver (drv) \
Re: [PATCH 5/7] virtio_vdpa: init IRQ offloading function pointers to NULL.
In reply to a message not in the archiveQuoted 14 lines · Zhu Lingshan
This commit initialize IRQ offloading function pointers in
virtio_vdpa_driverto NULL. Becasue irq offloading only focus on VMs forvhost_vdpa.Signed-off-by Zhu Lingshan <[email protected]>--- drivers/virtio/virtio_vdpa.c | 2 ++ 1 file changed, 2 insertions(+)drivers/virtio/virtio_vdpa.c +0
-0
drivers/virtio/virtio_vdpa.c static void virtio_vdpa_remove(struct vdpa_device *vdpa) · line 391
Quoted 6 lines
drivers/virtio/virtio_vdpa.c +2
-0@@ -386,6 +386,8 @@ static void virtio_vdpa_remove(struct vdpa_device *vdpa) }, .probe = virtio_vdpa_probe, .remove = virtio_vdpa_remove, + .setup_vq_irq = NULL, + .unsetup_vq_irq = NULL, };
Is this really needed consider the it's static?
Thanks
Quoted 2 lines
drivers/virtio/virtio_vdpa.c +0
-0module_vdpa_driver (virtio_vdpa_driver);
Re: [PATCH 6/7] ifcvf: replace irq_request/free with helpers in vDPA core.
In reply to a message not in the archiveQuoted 36 lines · Zhu Lingshan
This commit replaced irq_request/free() with helpers in vDPA core, so that it can request/free irq and setup irq offloading on order.
Signed-off-by Zhu Lingshan <[email protected]>--- drivers/vdpa/ifcvf/ifcvf_main.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)drivers/vdpa/ifcvf/ifcvf_main.c +3
-1@@ -47,11 +47,12 @@ static void ifcvf_free_irq(struct ifcvf_adapter *adapter, int queues) {struct pci_dev *pdev = adapter->pdev;struct ifcvf_hw *vf = &adapter->vf; +struct vdpa_device *vdpa = &adapter->vdpa;int i;for (i =0 ; i < queues; i++) -devm_free_irq (&pdev->dev, vf->vring[i].irq, &vf->vring[i]); +vdpa_free_vq_irq (&pdev->dev, vdpa, vf->vring[i].irq, i, &vf->vring[i]);ifcvf_free_irq_vectors (pdev); }@@ -60,6 +61,7 @@ static int ifcvf_request_irq(struct ifcvf_adapter *adapter) {struct pci_dev *pdev = adapter->pdev;struct ifcvf_hw *vf = &adapter->vf; +struct vdpa_device *vdpa = &adapter->vdpa;int vector, i, ret, irq; ret = pci_alloc_irq_vectors(pdev, IFCVF_MAX_INTR,
drivers/vdpa/ifcvf/ifcvf_main.c static int ifcvf_request_irq(struct ifcvf_adapter *adapter) · line 78
Quoted 4 lines
drivers/vdpa/ifcvf/ifcvf_main.c +1
-0@@ -73,6 +75,7 @@ static int ifcvf_request_irq(struct ifcvf_adapter *adapter) pci_name(pdev)); vector =0 ; irq =pci_irq_vector (pdev, vector); +/* config interrupt */
Unnecessary changes.
Thanks
Quoted 19 lines
drivers/vdpa/ifcvf/ifcvf_main.c +2
-4ret =devm_request_irq (&pdev->dev, irq, ifcvf_config_changed,0 , vf->config_msix_name, vf);@@ -82,13 +85,11 @@ static int ifcvf_request_irq(struct ifcvf_adapter *adapter) pci_name(pdev), i); vector = i +IFCVF_MSI_QUEUE_OFF ; irq =pci_irq_vector (pdev, vector); - ret =devm_request_irq (&pdev->dev, irq, + ret =vdpa_alloc_vq_irq (&pdev->dev, vdpa, irq, ifcvf_intr_handler,0 , vf->vring[i].msix_name, - &vf->vring[i]); + &vf->vring[i], i);if (ret) { -IFCVF_ERR (pdev, -"Failed to request irq for vq %d\n" , i);ifcvf_free_irq (adapter, i);return ret;
Michael S. Tsirkin
maintainerQuoted 25 lines · Jason Wang
Quoted 10 lines · Michael S. Tsirkin
Quoted 9 lines · Zhu Lingshan
We used to detect assigned device via VFIO manipulated device conters. This is less flexible consider VFIO is not the only interface for assigned device. vDPA devices has dedicated backed hardware as well. So this patch tries to detect the assigned device via irqbypass manager.
We will increase/decrease the assigned device counter in kvm/x86. Both vDPA and VFIO would go through this code path.
Quoted 6 lines
Quoted 3 lines
This code path only affect x86 for now.
Signed-off-by Zhu Lingshan <[email protected]>I think it's best to leave VFIO alone. Add appropriate APIs for VDPA, worry about converting existing users later.
Just to make sure I understand, did you mean:
1) introduce another bridge for vDPA
Quoted 7 lines
or
2) only detect vDPA via bypass manager? (we can leave VFIO code as is, then the assigned device counter may increase/decrease twice if VFIO use irq bypass manager which should be no harm).
Thanks
2 is probably easier to justify. 1 would depend on the specific bridge proposed.
Quoted 46 lines
Quoted 46 lines
Quoted 46 lines
--- arch/x86/kvm/x86.c | 10 ++++++++-- virt/kvm/vfio.c | 2 -- 2 files changed, 8 insertions(+), 4 deletions(-)arch/x86/kvm/x86.c +8
-2@@ -10624,11 +10624,17 @@ int kvm_arch_irq_bypass_add_producer(struct irq_bypass_consumer *cons, {struct kvm_kernel_irqfd *irqfd = container_of(cons, struct kvm_kernel_irqfd, consumer); +int ret; irqfd->producer = prod; +kvm_arch_start_assignment (irqfd->kvm); + ret = kvm_x86_ops.update_pi_irte (irqfd->kvm, + prod->irq, irqfd->gsi,1 ); + +if (ret) +kvm_arch_end_assignment (irqfd->kvm); -return kvm_x86_ops.update_pi_irte (irqfd->kvm, - prod->irq, irqfd->gsi,1 ); +return ret; } void kvm_arch_irq_bypass_del_producer(struct irq_bypass_consumer *cons,virt/kvm/vfio.c +0
-2@@ -226,7 +226,6 @@ static int kvm_vfio_set_group(struct kvm_device *dev, long attr, u64 arg)list_add_tail (&kvg->node, &kv->group_list); kvg->vfio_group = vfio_group; -kvm_arch_start_assignment (dev->kvm);mutex_unlock (&kv->lock);@@ -254,7 +253,6 @@ static int kvm_vfio_set_group(struct kvm_device *dev, long attr, u64 arg)continue ;list_del (&kvg->node); -kvm_arch_end_assignment (dev->kvm);#ifdef CONFIG_SPAPR_TCE_IOMMU kvm_spapr_tce_release_vfio_group (dev->kvm, kvg->vfio_group);Signature · 1 line
1.8.3.1
Michael S. Tsirkin
maintainerQuoted 39 lines · Lingshan
On 7/13/2020 6:52 PM, Michael S. Tsirkin wrote:
On Mon, Jul 13, 2020 at 04:13:35PM +0800, Jason Wang wrote:
On 2020/7/13 上午5:06, Michael S. Tsirkin wrote:
On Sun, Jul 12, 2020 at 10:49:21PM +0800, Zhu Lingshan wrote:
We used to detect assigned device via VFIO manipulated device conters. This is less flexible consider VFIO is not the only interface for assigned device. vDPA devices has dedicated backed hardware as well. So this patch tries to detect the assigned device via irqbypass manager.
We will increase/decrease the assigned device counter in kvm/x86. Both vDPA and VFIO would go through this code path.
This code path only affect x86 for now.
Signed-off-by Zhu Lingshan <[email protected]>I think it's best to leave VFIO alone. Add appropriate APIs for VDPA, worry about converting existing users later.
Just to make sure I understand, did you mean:
1) introduce another bridge for vDPA
or
2) only detect vDPA via bypass manager? (we can leave VFIO code as is, then the assigned device counter may increase/decrease twice if VFIO use irq bypass manager which should be no harm).
Thanks
Quoted 7 lines
2 is probably easier to justify. 1 would depend on the specific bridge proposed.
Thanks Michael, so we should just drop changes in vfio, just increase / decrease the counter in irq bypass manager. right?
Thanks
I don't see any issue with that.
Quoted 47 lines
---
arch/x86/kvm/x86.c | 10 ++++++++--
virt/kvm/vfio.c | 2 --
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 00c88c2..20c07d3 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -10624,11 +10624,17 @@ int kvm_arch_irq_bypass_add_producer(struct irq_bypass_consumer *cons,
{
struct kvm_kernel_irqfd *irqfd =
container_of(cons, struct kvm_kernel_irqfd, consumer);
+ int ret;
irqfd->producer = prod;
+ kvm_arch_start_assignment(irqfd->kvm);
+ ret = kvm_x86_ops.update_pi_irte(irqfd->kvm,
+ prod->irq, irqfd->gsi, 1);
+
+ if (ret)
+ kvm_arch_end_assignment(irqfd->kvm);
- return kvm_x86_ops.update_pi_irte(irqfd->kvm,
- prod->irq, irqfd->gsi, 1);
+ return ret;
}
void kvm_arch_irq_bypass_del_producer(struct irq_bypass_consumer *cons,
diff --git a/virt/kvm/vfio.c b/virt/kvm/vfio.c
index 8fcbc50..111da52 100644
--- a/virt/kvm/vfio.c
+++ b/virt/kvm/vfio.c
@@ -226,7 +226,6 @@ static int kvm_vfio_set_group(struct kvm_device *dev, long attr, u64 arg)
list_add_tail(&kvg->node, &kv->group_list);
kvg->vfio_group = vfio_group;
- kvm_arch_start_assignment(dev->kvm);
mutex_unlock(&kv->lock);
@@ -254,7 +253,6 @@ static int kvm_vfio_set_group(struct kvm_device *dev, long attr, u64 arg)
continue;
list_del(&kvg->node);
- kvm_arch_end_assignment(dev->kvm);
#ifdef CONFIG_SPAPR_TCE_IOMMU
kvm_spapr_tce_release_vfio_group(dev->kvm,
kvg->vfio_group);
--
1.8.3.1Re: [PATCH 6/7] ifcvf: replace irq_request/free with helpers in vDPA core.
In reply to a message not in the archiveQuoted 48 lines · Lingshan
Quoted 37 lines · Jason Wang
Quoted 35 lines · Zhu Lingshan
This commit replaced irq_request/free() with helpers in vDPA core, so that it can request/free irq and setup irq offloading on order.
Signed-off-by Zhu Lingshan <[email protected]>---
drivers/vdpa/ifcvf/ifcvf_main.c| 11 ++++++-----1 file changed, 6 insertions(+), 5 deletions(-)drivers/vdpa/ifcvf/ifcvf_main.c +3
-1@@ -47,11 +47,12 @@ static void ifcvf_free_irq(struct ifcvf_adapter *adapter, int queues) { struct pci_dev *pdev = adapter->pdev; struct ifcvf_hw *vf = &adapter->vf; + struct vdpa_device *vdpa = &adapter->vdpa; int i; for (i = 0; i < queues; i++) - devm_free_irq(&pdev->dev, vf->vring[i].irq, &vf->vring[i]); + vdpa_free_vq_irq(&pdev->dev, vdpa, vf->vring[i].irq, i, &vf->vring[i]); ifcvf_free_irq_vectors(pdev); }@@ -60,6 +61,7 @@ static int ifcvf_request_irq(struct ifcvf_adapter *adapter) { struct pci_dev *pdev = adapter->pdev; struct ifcvf_hw *vf = &adapter->vf; + struct vdpa_device *vdpa = &adapter->vdpa; int vector, i, ret, irq; ret = pci_alloc_irq_vectors(pdev, IFCVF_MAX_INTR,@@ -73,6 +75,7 @@ static int ifcvf_request_irq(struct ifcvf_adapterQuoted 8 lines
drivers/vdpa/ifcvf/ifcvf_main.c static int ifcvf_request_irq(struct ifcvf_adapter · line 79
Quoted 5 lines
drivers/vdpa/ifcvf/ifcvf_main.c +1
-0*adapter) pci_name(pdev)); vector = 0; irq = pci_irq_vector(pdev, vector); + /* config interrupt */Unnecessary changes.
Quoted 1 line
This is to show we did not setup this irq offloading for config interrupt, only setup irq offloading for data vq. But can remove this since we have
config_msix_namein code to show what it is
Btw, any reason for not making config interrupt work for irq offloading? I don't see any thing that blocks this.
Thanks
Quoted 2 lines
Thanks BR Zhu Lingshan
Quoted 1 line
Re: [PATCH 5/7] virtio_vdpa: init IRQ offloading function pointers to NULL.
In reply to a message not in the archiveQuoted 30 lines · Lingshan
Quoted 27 lines · Jason Wang
Quoted 14 lines · Zhu Lingshan
This commit initialize IRQ offloading function pointers in
virtio_vdpa_driverto NULL. Becasue irq offloading only focus on VMs forvhost_vdpa.Signed-off-by Zhu Lingshan <[email protected]>---
drivers/virtio/virtio_vdpa.c| 2 ++1 file changed, 2 insertions(+)drivers/virtio/virtio_vdpa.c +0
-0drivers/virtio/virtio_vdpa.c static void virtio_vdpa_remove(struct · line 392
Quoted 7 lines
drivers/virtio/virtio_vdpa.c +2
-0@@ -386,6 +386,8 @@ static void virtio_vdpa_remove(struct vdpa_device *vdpa) }, .probe = virtio_vdpa_probe, .remove = virtio_vdpa_remove, + .setup_vq_irq = NULL, + .unsetup_vq_irq = NULL, };Is this really needed consider the it's static?
Quoted 4 lines
Quoted 1 line
Thanks
This is for readability, to show they are NULL, so
virtio_vdpawould not go through irq forwarding / offloading.Does this make sense?
Probably not, please refer what is done by other subsystems.
Thanks
Quoted 8 lines
Thanks,
BR
Zhu LingshanQuoted 4 lines
Quoted 3 lines
drivers/virtio/virtio_vdpa.c +0
-0module_vdpa_driver (virtio_vdpa_driver);
Re: [PATCH 3/7] vhost_vdpa: implement IRQ offloading functions in vhost_vdpa
In reply to a message not in the archiveQuoted 101 lines · Lingshan
Quoted 36 lines · Jason Wang
Quoted 34 lines · Zhu Lingshan
This patch introduce a set of functions for setup/unsetup and update irq offloading respectively by register/unregister and re-register the
irq_bypass_producer.Signed-off-by Zhu Lingshan <[email protected]>---
drivers/vhost/vdpa.c| 69
++++++++++++++++++++++++++++++++++++++++++++++++++++1 file changed, 69 insertions(+)drivers/vhost/vdpa.c +14
-0@@ -115,6 +115,63 @@ static irqreturn_t vhost_vdpa_config_cb(void *private) return IRQ_HANDLED; } +static void vhost_vdpa_setup_vq_irq(struct vdpa_device *dev, int qid, int irq) +{ + struct vhost_vdpa *v = vdpa_get_drvdata(dev); + struct vhost_virtqueue *vq = &v->vqs[qid]; + int ret; + + vq_err(vq, "setup irq bypass for vq %d with irq = %d\n", qid, irq); + spin_lock(&vq->call_ctx.ctx_lock); + if (!vq->call_ctx.ctx) + return; + + vq->call_ctx.producer.token = vq->call_ctx.ctx; + vq->call_ctx.producer.irq = irq; + ret = irq_bypass_register_producer(&vq->call_ctx.producer); + spin_unlock(&vq->call_ctx.ctx_lock);Quoted 8 lines
drivers/vhost/vdpa.c static irqreturn_t vhost_vdpa_config_cb(void · line 138
Quoted 5 lines
drivers/vhost/vdpa.c +5
-0+ + if (unlikely(ret)) + vq_err(vq, + "irq bypass producer (token %p registration fails: %d\n", + vq->call_ctx.producer.token, ret);Not sure this deserves a
vq_err(), irq will be relayed through eventfd if irq bypass manager can't work.OK, I see
vq_err()willeventfd_signalerr_ctxthan just print a message, will remove allvq_err().Quoted 20 lines
Quoted 5 lines
drivers/vhost/vdpa.c +3
-0+} + +static void vhost_vdpa_unsetup_vq_irq(struct vdpa_device *dev, intdrivers/vhost/vdpa.c static irqreturn_t vhost_vdpa_config_cb(void · line 151
Quoted 10 lines
drivers/vhost/vdpa.c +9
-0qid) +{ + struct vhost_vdpa *v = vdpa_get_drvdata(dev); + struct vhost_virtqueue *vq = &v->vqs[qid]; + + spin_lock(&vq->call_ctx.ctx_lock); +irq_bypass_unregister_producer (&vq->call_ctx.producer); + spin_unlock(&vq->call_ctx.ctx_lock); + + vq_err(vq, "unsetup irq bypass for vq %d\n", qid);Why call
vq_err()here?Quoted 15 lines
drivers/vhost/vdpa.c static irqreturn_t vhost_vdpa_config_cb(void · line 163
Quoted 12 lines
drivers/vhost/vdpa.c +12
-0+} + +static void vhost_vdpa_update_vq_irq (struct vhost_virtqueue *vq) +{ + struct eventfd_ctx *ctx; + void *token; + + spin_lock(&vq->call_ctx.ctx_lock); + ctx = vq->call_ctx.ctx; + token = vq->call_ctx.producer.token; + if (ctx == token) + return;Need do unlock here.
sure!
Quoted 16 lines
drivers/vhost/vdpa.c static irqreturn_t vhost_vdpa_config_cb(void · line 174
Quoted 13 lines
drivers/vhost/vdpa.c +11
-0+ + if (!ctx && token) +irq_bypass_unregister_producer (&vq->call_ctx.producer); + + if (ctx && ctx != token) { +irq_bypass_unregister_producer (&vq->call_ctx.producer); + vq->call_ctx.producer.token = ctx; +irq_bypass_register_producer (&vq->call_ctx.producer); + } + + spin_unlock(&vq->call_ctx.ctx_lock);This should be rare so I'd use simple codes just do unregister and register.
Quoted 2 lines
do you mean remove "if (ctx && ctx != token)"? I think this could be useful, we should only update it when ctx!=NULL and ctx!= existing token.
I meant something like:
unregister();vq->call_ctx.producer.token = ctx;register();
Quoted 15 lines
Quoted 15 lines
drivers/vhost/vdpa.c static long vhost_vdpa_set_config_call(struct · line 392
Quoted 12 lines
drivers/vhost/vdpa.c +2
-0+} +static void
vhost_vdpa_reset(struct vhost_vdpa *v){
structvdpa_device*vdpa =v->vdpa;drivers/vhost/vdpa.c +1
-0@@ -332,6 +389,7 @@ static long vhost_vdpa_set_config_call(struct vhost_vdpa *v, u32 __user *argp) return 0; } +Unnecessary change.
Quoted 1 line
this new blank line is added because there is no blank line between functions, I will double check
The point is not mixing coding style fix with other fixes or enhancement.
Thanks
Quoted 39 lines
THanks, BR Zhu Lingshan
Quoted 38 lines
Quoted 23 lines
drivers/vhost/vdpa.c +10
-0static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd, void __user *argp) {@@ -390,6 +448,16 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd, cb.private = NULL; } ops->set_vq_cb(vdpa, idx, &cb); +#ifdef CONFIG_HAVE_KVM_IRQ_BYPASS + /* + * if it has a non-zero irq, means there is a + * previsouly registered irq_bypass_producer, + * we should update it when ctx (its token) + * changes. + */ + if (vq->call_ctx.producer.irq) + vhost_vdpa_update_vq_irq(vq); +#endif break;case
VHOST_SET_VRING_NUM:drivers/vhost/vdpa.c static int vhost_vdpa_open(struct inode *inode, · line 813
Quoted 5 lines
drivers/vhost/vdpa.c +1
-0@@ -741,6 +809,7 @@ static int vhost_vdpa_open(struct inode *inode, struct file *filep) vqs[i] = &v->vqs[i]; vqs[i]->handle_kick = handle_vq_kick; } +Unnecessary change.
Thanks
Quoted 2 lines
drivers/vhost/vdpa.c +0
-0vhost_dev_init(dev, vqs, nvqs, 0, 0, 0, false, vhost_vdpa_process_iotlb_msg);
Re: [PATCH 3/7] vhost_vdpa: implement IRQ offloading functions in vhost_vdpa
In reply to a message not in the archiveQuoted 115 lines · Lingshan
Quoted 103 lines · Jason Wang
Quoted 101 lines · Lingshan
Quoted 36 lines · Jason Wang
Quoted 34 lines · Zhu Lingshan
This patch introduce a set of functions for setup/unsetup and update irq offloading respectively by register/unregister and re-register the
irq_bypass_producer.Signed-off-by Zhu Lingshan <[email protected]>---
drivers/vhost/vdpa.c| 69
++++++++++++++++++++++++++++++++++++++++++++++++++++1 file changed, 69 insertions(+)drivers/vhost/vdpa.c +14
-0@@ -115,6 +115,63 @@ static irqreturn_t vhost_vdpa_config_cb(void *private) return IRQ_HANDLED; } +static void vhost_vdpa_setup_vq_irq(struct vdpa_device *dev, int qid, int irq) +{ + struct vhost_vdpa *v = vdpa_get_drvdata(dev); + struct vhost_virtqueue *vq = &v->vqs[qid]; + int ret; + + vq_err(vq, "setup irq bypass for vq %d with irq = %d\n", qid, irq); + spin_lock(&vq->call_ctx.ctx_lock); + if (!vq->call_ctx.ctx) + return; + + vq->call_ctx.producer.token = vq->call_ctx.ctx; + vq->call_ctx.producer.irq = irq; + ret = irq_bypass_register_producer(&vq->call_ctx.producer); + spin_unlock(&vq->call_ctx.ctx_lock);Quoted 8 lines
drivers/vhost/vdpa.c static irqreturn_t vhost_vdpa_config_cb(void · line 138
Quoted 5 lines
drivers/vhost/vdpa.c +5
-0+ + if (unlikely(ret)) + vq_err(vq, + "irq bypass producer (token %p registration fails: %d\n", + vq->call_ctx.producer.token, ret);Not sure this deserves a
vq_err(), irq will be relayed through eventfd if irq bypass manager can't work.OK, I see
vq_err()willeventfd_signalerr_ctxthan just print a message, will remove allvq_err().Quoted 20 lines
Quoted 5 lines
drivers/vhost/vdpa.c +3
-0+} + +static void vhost_vdpa_unsetup_vq_irq(struct vdpa_device *dev,drivers/vhost/vdpa.c static irqreturn_t vhost_vdpa_config_cb(void · line 151
Quoted 10 lines
drivers/vhost/vdpa.c +9
-0int qid) +{ + struct vhost_vdpa *v = vdpa_get_drvdata(dev); + struct vhost_virtqueue *vq = &v->vqs[qid]; + + spin_lock(&vq->call_ctx.ctx_lock); +irq_bypass_unregister_producer (&vq->call_ctx.producer); + spin_unlock(&vq->call_ctx.ctx_lock); + + vq_err(vq, "unsetup irq bypass for vq %d\n", qid);Why call
vq_err()here?Quoted 15 lines
drivers/vhost/vdpa.c static irqreturn_t vhost_vdpa_config_cb(void · line 163
Quoted 12 lines
drivers/vhost/vdpa.c +12
-0+} + +static void vhost_vdpa_update_vq_irq (struct vhost_virtqueue *vq) +{ + struct eventfd_ctx *ctx; + void *token; + + spin_lock(&vq->call_ctx.ctx_lock); + ctx = vq->call_ctx.ctx; + token = vq->call_ctx.producer.token; + if (ctx == token) + return;Need do unlock here.
sure!
Quoted 16 lines
drivers/vhost/vdpa.c static irqreturn_t vhost_vdpa_config_cb(void · line 174
Quoted 13 lines
drivers/vhost/vdpa.c +11
-0+ + if (!ctx && token) +irq_bypass_unregister_producer (&vq->call_ctx.producer); + + if (ctx && ctx != token) { +irq_bypass_unregister_producer (&vq->call_ctx.producer); + vq->call_ctx.producer.token = ctx; +irq_bypass_register_producer (&vq->call_ctx.producer); + } + + spin_unlock(&vq->call_ctx.ctx_lock);This should be rare so I'd use simple codes just do unregister and register.
Quoted 8 lines
Quoted 2 lines
do you mean remove "if (ctx && ctx != token)"? I think this could be useful, we should only update it when ctx!=NULL and ctx!= existing token.
I meant something like:
unregister();vq->call_ctx.producer.token= ctx;register();This is what we are doing now, or I must missed somethig:
Quoted 8 lines
if (ctx && ctx != token) { irq_bypass_unregister_producer(&vq->call_ctx.producer); vq->call_ctx.producer.token = ctx; irq_bypass_register_producer(&vq->call_ctx.producer);}
It just unregister and register.
I meant there's probably no need for the check and another check and unregister before. The whole function is as simple as I suggested above.
Thanks
Quoted 4 lines
Thanks,
BR
Zhu Lingshan
Re: [PATCH 3/7] vhost_vdpa: implement IRQ offloading functions in vhost_vdpa
In reply to a message not in the archiveQuoted 14 lines · Lingshan
Quoted 14 lines
Quoted 14 lines
Quoted 6 lines
I meant something like:
unregister();vq->call_ctx.producer.token= ctx;register();This is what we are doing now, or I must missed somethig:
if (ctx && ctx != token) {irq_bypass_unregister_producer(&vq->call_ctx.producer);vq->call_ctx.producer.token= ctx;irq_bypass_register_producer(&vq->call_ctx.producer);}
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
It just unregister and register.
I meant there's probably no need for the check and another check and unregister before. The whole function is as simple as I suggested above.
Thanks
IMHO we still need the checks, this function handles three cases:
(1)if the ctx == token, we do nothing. For this unregister and register can work, but waste of time.
But we have a more simple code and we don't care about the performance here since the operations is rare.
Quoted 1 line
(2)if token exists but ctx is NULL, this means user space issued an unbind, so we need to only unregister the producer.
Note that the register/unregister have a graceful check of whether or not there's a token.
Quoted 3 lines
(3)if ctx exists and ctx!=token, this means there is a new ctx, we need to update producer by unregister and register.
I think we can not simply handle all these cases by "unregister and register".
So it looks to me the functions are equivalent.
Thanks
Quoted 4 lines
Thanks,
BR
Zhu Lingshan
Michael S. Tsirkin
maintainerRe: [PATCH 6/7] ifcvf: replace irq_request/free with helpers in vDPA core.
In reply to Jason WangQuoted 56 lines · Jason Wang
Quoted 49 lines · Lingshan
Quoted 38 lines · Jason Wang
Quoted 36 lines · Zhu Lingshan
This commit replaced irq_request/free() with helpers in vDPA core, so that it can request/free irq and setup irq offloading on order.
Signed-off-by Zhu Lingshan <[email protected]>---
drivers/vdpa/ifcvf/ifcvf_main.c| 11 ++++++-----1 file changed, 6 insertions(+), 5 deletions(-)drivers/vdpa/ifcvf/ifcvf_main.c +3
-1@@ -47,11 +47,12 @@ static void ifcvf_free_irq(struct ifcvf_adapter *adapter, int queues) { struct pci_dev *pdev = adapter->pdev; struct ifcvf_hw *vf = &adapter->vf; + struct vdpa_device *vdpa = &adapter->vdpa; int i; for (i = 0; i < queues; i++) - devm_free_irq(&pdev->dev, vf->vring[i].irq, &vf->vring[i]); + vdpa_free_vq_irq(&pdev->dev, vdpa, vf->vring[i].irq, i, &vf->vring[i]); ifcvf_free_irq_vectors(pdev); }@@ -60,6 +61,7 @@ static int ifcvf_request_irq(struct ifcvf_adapter *adapter) { struct pci_dev *pdev = adapter->pdev; struct ifcvf_hw *vf = &adapter->vf; + struct vdpa_device *vdpa = &adapter->vdpa; int vector, i, ret, irq; ret = pci_alloc_irq_vectors(pdev, IFCVF_MAX_INTR,@@ -73,6 +75,7 @@ static int ifcvf_request_irq(structQuoted 8 lines
drivers/vdpa/ifcvf/ifcvf_main.c static int ifcvf_request_irq(struct · line 79
Quoted 5 lines
drivers/vdpa/ifcvf/ifcvf_main.c +1
-0ifcvf_adapter *adapter) pci_name(pdev)); vector = 0; irq = pci_irq_vector(pdev, vector); + /* config interrupt */Unnecessary changes.
Quoted 3 lines
This is to show we did not setup this irq offloading for config interrupt, only setup irq offloading for data vq. But can remove this since we have
config_msix_namein code to show what it is
Quoted 4 lines
Btw, any reason for not making config interrupt work for irq offloading? I don't see any thing that blocks this.
Thanks
Well config accesses all go through userspace right? Doing config interrupt directly would just be messy ...
Quoted 3 lines
Quoted 3 lines
Thanks BR Zhu Lingshan
Quoted 1 line
Re: [PATCH 6/7] ifcvf: replace irq_request/free with helpers in vDPA core.
Quoted 49 lines · Michael S. Tsirkin
Quoted 48 lines · Jason Wang
Quoted 47 lines · Lingshan
Quoted 35 lines · Jason Wang
Quoted 34 lines · Zhu Lingshan
This commit replaced irq_request/free() with helpers in vDPA core, so that it can request/free irq and setup irq offloading on order.
Signed-off-by Zhu Lingshan<[email protected]>--- drivers/vdpa/ifcvf/ifcvf_main.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)drivers/vdpa/ifcvf/ifcvf_main.c +3
-1@@ -47,11 +47,12 @@ static void ifcvf_free_irq(struct ifcvf_adapter *adapter, int queues) { struct pci_dev *pdev = adapter->pdev; struct ifcvf_hw *vf = &adapter->vf; + struct vdpa_device *vdpa = &adapter->vdpa; int i; for (i = 0; i < queues; i++) - devm_free_irq(&pdev->dev, vf->vring[i].irq, &vf->vring[i]); + vdpa_free_vq_irq(&pdev->dev, vdpa, vf->vring[i].irq, i, &vf->vring[i]); ifcvf_free_irq_vectors(pdev); }@@ -60,6 +61,7 @@ static int ifcvf_request_irq(struct ifcvf_adapter *adapter) { struct pci_dev *pdev = adapter->pdev; struct ifcvf_hw *vf = &adapter->vf; + struct vdpa_device *vdpa = &adapter->vdpa; int vector, i, ret, irq;Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_main.c static int ifcvf_request_irq(struct · line 79
Quoted 7 lines
drivers/vdpa/ifcvf/ifcvf_main.c +1
-0ret = pci_alloc_irq_vectors(pdev, IFCVF_MAX_INTR,@@ -73,6 +75,7 @@ static int ifcvf_request_irq(struct ifcvf_adapter *adapter) pci_name(pdev)); vector = 0; irq = pci_irq_vector(pdev, vector); + /* config interrupt */Unnecessary changes.
This is to show we did not setup this irq offloading for config interrupt, only setup irq offloading for data vq. But can remove this since we have
config_msix_namein code to show what it is
Quoted 6 lines
Quoted 4 lines
Btw, any reason for not making config interrupt work for irq offloading? I don't see any thing that blocks this.
Thanks
Well config accesses all go through userspace right? Doing config interrupt directly would just be messy ...
Right, so I think we need a better comment here.
Thanks
Quoted 2 lines
Re: [PATCH 3/7] vhost_vdpa: implement IRQ offloading functions in vhost_vdpa
In reply to Jason WangQuoted 35 lines · Jason Wang
Quoted 14 lines · Lingshan
Quoted 14 lines
Quoted 14 lines
Quoted 6 lines
I meant something like:
unregister();vq->call_ctx.producer.token= ctx;register();This is what we are doing now, or I must missed somethig:
if (ctx && ctx != token) {irq_bypass_unregister_producer(&vq->call_ctx.producer);vq->call_ctx.producer.token= ctx;irq_bypass_register_producer(&vq->call_ctx.producer);}
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
It just unregister and register.
I meant there's probably no need for the check and another check and unregister before. The whole function is as simple as I suggested above.
Thanks
IMHO we still need the checks, this function handles three cases:
(1)if the ctx == token, we do nothing. For this unregister and register can work, but waste of time.But we have a more simple code and we don't care about the performance here since the operations is rare.
Quoted 1 line
(2)if token exists but ctx is NULL, this means user space issued an unbind, so we need to only unregister the producer.
Note that the register/unregister have a graceful check of whether or not there's a token.
Quoted 8 lines
Quoted 3 lines
(3)if ctx exists and ctx!=token, this means there is a new ctx, we need to update producer by unregister and register.
I think we can not simply handle all these cases by "unregister and register".
So it looks to me the functions are equivalent.
Thanks
Sounds reasonable, thanks!
Quoted 7 lines
Quoted 6 lines
Thanks,
BR
Zhu Lingshan
Re: [PATCH 6/7] ifcvf: replace irq_request/free with helpers in vDPA core.
In reply to Jason WangQuoted 54 lines · Jason Wang
Quoted 52 lines · Michael S. Tsirkin
Quoted 51 lines · Jason Wang
Quoted 44 lines · Lingshan
Quoted 35 lines · Jason Wang
Quoted 34 lines · Zhu Lingshan
This commit replaced irq_request/free() with helpers in vDPA core, so that it can request/free irq and setup irq offloading on order.
Signed-off-by Zhu Lingshan<[email protected]>---
drivers/vdpa/ifcvf/ifcvf_main.c| 11 ++++++-----1 file changed, 6 insertions(+), 5 deletions(-)drivers/vdpa/ifcvf/ifcvf_main.c +3
-1@@ -47,11 +47,12 @@ static void ifcvf_free_irq(struct ifcvf_adapter *adapter, int queues) { struct pci_dev *pdev = adapter->pdev; struct ifcvf_hw *vf = &adapter->vf; + struct vdpa_device *vdpa = &adapter->vdpa; int i; for (i = 0; i < queues; i++) - devm_free_irq(&pdev->dev, vf->vring[i].irq, &vf->vring[i]); + vdpa_free_vq_irq(&pdev->dev, vdpa, vf->vring[i].irq, i, &vf->vring[i]); ifcvf_free_irq_vectors(pdev); }@@ -60,6 +61,7 @@ static int ifcvf_request_irq(struct ifcvf_adapter *adapter) { struct pci_dev *pdev = adapter->pdev; struct ifcvf_hw *vf = &adapter->vf; + struct vdpa_device *vdpa = &adapter->vdpa; int vector, i, ret, irq;Quoted 8 lines
drivers/vdpa/ifcvf/ifcvf_main.c static int ifcvf_request_irq(struct · line 79
Quoted 7 lines
drivers/vdpa/ifcvf/ifcvf_main.c +1
-0ret = pci_alloc_irq_vectors(pdev, IFCVF_MAX_INTR,@@ -73,6 +75,7 @@ static int ifcvf_request_irq(struct ifcvf_adapter *adapter) pci_name(pdev)); vector = 0; irq = pci_irq_vector(pdev, vector); + /* config interrupt */Unnecessary changes.
Quoted 3 lines
This is to show we did not setup this irq offloading for config interrupt, only setup irq offloading for data vq. But can remove this since we have
config_msix_namein code to show what it isBtw, any reason for not making config interrupt work for irq offloading? I don't see any thing that blocks this.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Thanks
Well config accesses all go through userspace right? Doing config interrupt directly would just be messy ...
Right, so I think we need a better comment here.
Thanks, will add a better comment than just "config interrupt".
Quoted 7 lines
Thanks
Quoted 2 lines