* [PATCH] vhost vdpa: fix the irq check for invoking irq_bypass_unregister_producer
@ 2021-02-22 9:13 Gautam Dawar
2021-02-23 4:42 ` Jason Wang
0 siblings, 1 reply; 3+ messages in thread
From: Gautam Dawar @ 2021-02-22 9:13 UTC (permalink / raw)
To: Jason Wang, mst, gdawar, hanand, martinh, virtualization
[-- Attachment #1.1: Type: text/plain, Size: 1240 bytes --]
When qemu with vhost-vdpa netdevice is run for the first time, it works
well.
But after the VM is powered off, the next qemu run causes kernel panic due
to
a NULL pointer dereference in irq_bypass_register_producer().
When the VM is powered off, vhost_vdpa_clean_irq() misses on calling
irq_bypass_unregister_producer() for irq 0 because of the existing check.
This leaves stale producer nodes, which are reset in
vhost_vring_call_reset()
when vhost_dev_init() is invoked during the second qemu run.
As the node member of struct irq_bypass_producer is also initialized
to zero, traversal on the producers list causes crash due to NULL pointer
dereference.
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=211711
Signed-off-by: Gautam Dawar <gdawar@xilinx.com>
diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
index 62a9bb0efc55..d1c3a33c6239 100644
--- a/drivers/vhost/vdpa.c
+++ b/drivers/vhost/vdpa.c
@@ -849,7 +849,7 @@ static void vhost_vdpa_clean_irq(struct vhost_vdpa *v)
for (i = 0; i < v->nvqs; i++) {
vq = &v->vqs[i];
- if (vq->call_ctx.producer.irq)
+ if (vq->call_ctx.producer.irq >= 0)
irq_bypass_unregister_producer(&vq->call_ctx.producer);
}
}
[-- Attachment #1.2: Type: text/html, Size: 1590 bytes --]
[-- Attachment #2: Type: text/plain, Size: 183 bytes --]
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] vhost vdpa: fix the irq check for invoking irq_bypass_unregister_producer
2021-02-22 9:13 [PATCH] vhost vdpa: fix the irq check for invoking irq_bypass_unregister_producer Gautam Dawar
@ 2021-02-23 4:42 ` Jason Wang
2021-02-23 10:02 ` Gautam Dawar
0 siblings, 1 reply; 3+ messages in thread
From: Jason Wang @ 2021-02-23 4:42 UTC (permalink / raw)
To: Gautam Dawar, mst, gdawar, hanand, martinh, virtualization
On 2021/2/22 下午5:13, Gautam Dawar wrote:
> When qemu with vhost-vdpa netdevice is run for the first time, it
> works well.
> But after the VM is powered off, the next qemu run causes kernel panic
> due to
> a NULL pointer dereference in irq_bypass_register_producer().
>
> When the VM is powered off, vhost_vdpa_clean_irq() misses on calling
> irq_bypass_unregister_producer() for irq 0 because of the existing check.
>
> This leaves stale producer nodes, which are reset in
> vhost_vring_call_reset()
> when vhost_dev_init() is invoked during the second qemu run.
>
> As the node member of struct irq_bypass_producer is also initialized
> to zero, traversal on the producers list causes crash due to NULL pointer
> dereference.
>
> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=211711
> Signed-off-by: Gautam Dawar <gdawar@xilinx.com <mailto:gdawar@xilinx.com>>
>
>
> diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
> index 62a9bb0efc55..d1c3a33c6239 100644
> --- a/drivers/vhost/vdpa.c
> +++ b/drivers/vhost/vdpa.c
> @@ -849,7 +849,7 @@ static void vhost_vdpa_clean_irq(struct vhost_vdpa *v)
>
> for (i = 0; i < v->nvqs; i++) {
> vq = &v->vqs[i];
> - if (vq->call_ctx.producer.irq)
> + if (vq->call_ctx.producer.irq >= 0)
> irq_bypass_unregister_producer(&vq->call_ctx.producer);
Since it's impossible to have an irq < 0 ( see
vhost_vdap_setup_vq_irq()), I think we can simply remove the check above.
Then we can call vhost_vdpa_unsetup_vq_irq() here to avoid temporary
variable like vq.
Thanks
> }
> }
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] vhost vdpa: fix the irq check for invoking irq_bypass_unregister_producer
2021-02-23 4:42 ` Jason Wang
@ 2021-02-23 10:02 ` Gautam Dawar
0 siblings, 0 replies; 3+ messages in thread
From: Gautam Dawar @ 2021-02-23 10:02 UTC (permalink / raw)
To: Jason Wang; +Cc: martinh, hanand, virtualization, gdawar, mst
[-- Attachment #1.1: Type: text/plain, Size: 1868 bytes --]
On Tue, 23 Feb 2021 at 10:13, Jason Wang <jasowang@redhat.com> wrote:
>
> On 2021/2/22 下午5:13, Gautam Dawar wrote:
> > When qemu with vhost-vdpa netdevice is run for the first time, it
> > works well.
> > But after the VM is powered off, the next qemu run causes kernel panic
> > due to
> > a NULL pointer dereference in irq_bypass_register_producer().
> >
> > When the VM is powered off, vhost_vdpa_clean_irq() misses on calling
> > irq_bypass_unregister_producer() for irq 0 because of the existing check.
> >
> > This leaves stale producer nodes, which are reset in
> > vhost_vring_call_reset()
> > when vhost_dev_init() is invoked during the second qemu run.
> >
> > As the node member of struct irq_bypass_producer is also initialized
> > to zero, traversal on the producers list causes crash due to NULL pointer
> > dereference.
> >
> > Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=211711
> > Signed-off-by: Gautam Dawar <gdawar@xilinx.com <mailto:gdawar@xilinx.com
> >>
> >
> >
> > diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
> > index 62a9bb0efc55..d1c3a33c6239 100644
> > --- a/drivers/vhost/vdpa.c
> > +++ b/drivers/vhost/vdpa.c
> > @@ -849,7 +849,7 @@ static void vhost_vdpa_clean_irq(struct vhost_vdpa
> *v)
> >
> > for (i = 0; i < v->nvqs; i++) {
> > vq = &v->vqs[i];
> > - if (vq->call_ctx.producer.irq)
> > + if (vq->call_ctx.producer.irq >= 0)
> > irq_bypass_unregister_producer(&vq->call_ctx.producer);
>
>
> Since it's impossible to have an irq < 0 ( see
> vhost_vdap_setup_vq_irq()), I think we can simply remove the check above.
>
> Then we can call vhost_vdpa_unsetup_vq_irq() here to avoid temporary
> variable like vq.
>
>
Done and submitted patch v2.
> Thanks
>
>
> > }
> > }
>
> Regards,
Gautam
[-- Attachment #1.2: Type: text/html, Size: 2843 bytes --]
[-- Attachment #2: Type: text/plain, Size: 183 bytes --]
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-02-23 10:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-22 9:13 [PATCH] vhost vdpa: fix the irq check for invoking irq_bypass_unregister_producer Gautam Dawar
2021-02-23 4:42 ` Jason Wang
2021-02-23 10:02 ` Gautam Dawar
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.