qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] virtio: Add corresponding memory_listener_unregister to unrealize
@ 2021-01-22 20:08 Eugenio Pérez
  2021-01-22 20:17 ` Peter Xu
  2021-01-25  3:15 ` Jason Wang
  0 siblings, 2 replies; 6+ messages in thread
From: Eugenio Pérez @ 2021-01-22 20:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: Jason Wang, Peter Xu, Michael S. Tsirkin

Cannot destroy address spaces of IOMMU-aware virtio devices without it,
since they can contain memory listeners.

Fixes: c611c76417f ("virtio: add MemoryListener to cache ring translations")
Buglink: https://bugs.launchpad.net/qemu/+bug/1912846
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
 hw/virtio/virtio.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index b308026596..67efd2c301 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -3680,6 +3680,7 @@ static void virtio_device_unrealize(DeviceState *dev)
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
     VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(dev);
 
+    memory_listener_unregister(&vdev->listener);
     virtio_bus_device_unplugged(vdev);
 
     if (vdc->unrealize != NULL) {
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] virtio: Add corresponding memory_listener_unregister to unrealize
  2021-01-22 20:08 [PATCH] virtio: Add corresponding memory_listener_unregister to unrealize Eugenio Pérez
@ 2021-01-22 20:17 ` Peter Xu
  2021-01-25  3:15 ` Jason Wang
  1 sibling, 0 replies; 6+ messages in thread
From: Peter Xu @ 2021-01-22 20:17 UTC (permalink / raw)
  To: Eugenio Pérez
  Cc: Jason Wang, QEMU Stable, qemu-devel, Michael S. Tsirkin

On Fri, Jan 22, 2021 at 09:08:51PM +0100, Eugenio Pérez wrote:
> Cannot destroy address spaces of IOMMU-aware virtio devices without it,
> since they can contain memory listeners.
> 
> Fixes: c611c76417f ("virtio: add MemoryListener to cache ring translations")
> Buglink: https://bugs.launchpad.net/qemu/+bug/1912846
> Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
> ---
>  hw/virtio/virtio.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index b308026596..67efd2c301 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -3680,6 +3680,7 @@ static void virtio_device_unrealize(DeviceState *dev)
>      VirtIODevice *vdev = VIRTIO_DEVICE(dev);
>      VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(dev);
>  
> +    memory_listener_unregister(&vdev->listener);
>      virtio_bus_device_unplugged(vdev);
>  
>      if (vdc->unrealize != NULL) {
> -- 
> 2.27.0
> 

Reviewed-by: Peter Xu <peterx@redhat.com>

CC stable, assuming that's what we need too.

Thanks,

-- 
Peter Xu



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] virtio: Add corresponding memory_listener_unregister to unrealize
  2021-01-22 20:08 [PATCH] virtio: Add corresponding memory_listener_unregister to unrealize Eugenio Pérez
  2021-01-22 20:17 ` Peter Xu
@ 2021-01-25  3:15 ` Jason Wang
  2021-01-25 16:55   ` Eugenio Perez Martin
  1 sibling, 1 reply; 6+ messages in thread
From: Jason Wang @ 2021-01-25  3:15 UTC (permalink / raw)
  To: Eugenio Pérez, qemu-devel; +Cc: Peter Xu, Michael S. Tsirkin


On 2021/1/23 上午4:08, Eugenio Pérez wrote:
> Cannot destroy address spaces of IOMMU-aware virtio devices without it,
> since they can contain memory listeners.


It's better to explain why the one in finalize doesn't work here.

Thanks


>
> Fixes: c611c76417f ("virtio: add MemoryListener to cache ring translations")
> Buglink: https://bugs.launchpad.net/qemu/+bug/1912846
> Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
> ---
>   hw/virtio/virtio.c | 1 +
>   1 file changed, 1 insertion(+)
>
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index b308026596..67efd2c301 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -3680,6 +3680,7 @@ static void virtio_device_unrealize(DeviceState *dev)
>       VirtIODevice *vdev = VIRTIO_DEVICE(dev);
>       VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(dev);
>   
> +    memory_listener_unregister(&vdev->listener);
>       virtio_bus_device_unplugged(vdev);
>   
>       if (vdc->unrealize != NULL) {



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] virtio: Add corresponding memory_listener_unregister to unrealize
  2021-01-25  3:15 ` Jason Wang
@ 2021-01-25 16:55   ` Eugenio Perez Martin
  2021-01-25 17:18     ` Peter Xu
  0 siblings, 1 reply; 6+ messages in thread
From: Eugenio Perez Martin @ 2021-01-25 16:55 UTC (permalink / raw)
  To: Jason Wang; +Cc: qemu-level, Peter Xu, Michael S. Tsirkin

On Mon, Jan 25, 2021 at 4:15 AM Jason Wang <jasowang@redhat.com> wrote:
>
>
> On 2021/1/23 上午4:08, Eugenio Pérez wrote:
> > Cannot destroy address spaces of IOMMU-aware virtio devices without it,
> > since they can contain memory listeners.
>
>
> It's better to explain why the one in finalize doesn't work here.
>

Hi Jason! Good point. The other call is at virtio_device_instance_finalize.

Function virtio_device_instance_finalize is called after
address_space_destroy if we follow steps of buglink.

Address_space_destroy is called by
pci_qdev_unrealize/do_pci_unregister_device, after call to
virtio_device_unrealize. After that call,
virtio_device_instance_finalize is called through object_deinit,
freeing the bus.

Also, memory_listener_unregister can be called again because it checks
for listener->address_space != NULL at start, and sets it to NULL at
end.

In regular shutdown, nothing of this is called, so maybe we could
safely delete the call to memory_listener_unregister at
virtio_device_instance_finalize?

If not, should I send again the patch with a new commit message?

Thanks!

> Thanks
>
>
> >
> > Fixes: c611c76417f ("virtio: add MemoryListener to cache ring translations")
> > Buglink: https://bugs.launchpad.net/qemu/+bug/1912846
> > Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
> > ---
> >   hw/virtio/virtio.c | 1 +
> >   1 file changed, 1 insertion(+)
> >
> > diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> > index b308026596..67efd2c301 100644
> > --- a/hw/virtio/virtio.c
> > +++ b/hw/virtio/virtio.c
> > @@ -3680,6 +3680,7 @@ static void virtio_device_unrealize(DeviceState *dev)
> >       VirtIODevice *vdev = VIRTIO_DEVICE(dev);
> >       VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(dev);
> >
> > +    memory_listener_unregister(&vdev->listener);
> >       virtio_bus_device_unplugged(vdev);
> >
> >       if (vdc->unrealize != NULL) {
>



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] virtio: Add corresponding memory_listener_unregister to unrealize
  2021-01-25 16:55   ` Eugenio Perez Martin
@ 2021-01-25 17:18     ` Peter Xu
  2021-01-25 19:22       ` Eugenio Perez Martin
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Xu @ 2021-01-25 17:18 UTC (permalink / raw)
  To: Eugenio Perez Martin; +Cc: Jason Wang, qemu-level, Michael S. Tsirkin

On Mon, Jan 25, 2021 at 05:55:35PM +0100, Eugenio Perez Martin wrote:
> On Mon, Jan 25, 2021 at 4:15 AM Jason Wang <jasowang@redhat.com> wrote:
> >
> >
> > On 2021/1/23 上午4:08, Eugenio Pérez wrote:
> > > Cannot destroy address spaces of IOMMU-aware virtio devices without it,
> > > since they can contain memory listeners.
> >
> >
> > It's better to explain why the one in finalize doesn't work here.
> >
> 
> Hi Jason! Good point. The other call is at virtio_device_instance_finalize.
> 
> Function virtio_device_instance_finalize is called after
> address_space_destroy if we follow steps of buglink.
> 
> Address_space_destroy is called by
> pci_qdev_unrealize/do_pci_unregister_device, after call to
> virtio_device_unrealize. After that call,
> virtio_device_instance_finalize is called through object_deinit,
> freeing the bus.
> 
> Also, memory_listener_unregister can be called again because it checks
> for listener->address_space != NULL at start, and sets it to NULL at
> end.
> 
> In regular shutdown, nothing of this is called, so maybe we could
> safely delete the call to memory_listener_unregister at
> virtio_device_instance_finalize?

I didn't notice this; if so we'd better remove that call if it's destined to be
a noop after all.

> 
> If not, should I send again the patch with a new commit message?

Maybe attach the full backtrace too along with above?  The assertion itself
could be a very good explanation of what's happened.

Thanks,

-- 
Peter Xu



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] virtio: Add corresponding memory_listener_unregister to unrealize
  2021-01-25 17:18     ` Peter Xu
@ 2021-01-25 19:22       ` Eugenio Perez Martin
  0 siblings, 0 replies; 6+ messages in thread
From: Eugenio Perez Martin @ 2021-01-25 19:22 UTC (permalink / raw)
  To: Peter Xu; +Cc: Jason Wang, qemu-level, Michael S. Tsirkin

On Mon, Jan 25, 2021 at 6:18 PM Peter Xu <peterx@redhat.com> wrote:
>
> On Mon, Jan 25, 2021 at 05:55:35PM +0100, Eugenio Perez Martin wrote:
> > On Mon, Jan 25, 2021 at 4:15 AM Jason Wang <jasowang@redhat.com> wrote:
> > >
> > >
> > > On 2021/1/23 上午4:08, Eugenio Pérez wrote:
> > > > Cannot destroy address spaces of IOMMU-aware virtio devices without it,
> > > > since they can contain memory listeners.
> > >
> > >
> > > It's better to explain why the one in finalize doesn't work here.
> > >
> >
> > Hi Jason! Good point. The other call is at virtio_device_instance_finalize.
> >
> > Function virtio_device_instance_finalize is called after
> > address_space_destroy if we follow steps of buglink.
> >
> > Address_space_destroy is called by
> > pci_qdev_unrealize/do_pci_unregister_device, after call to
> > virtio_device_unrealize. After that call,
> > virtio_device_instance_finalize is called through object_deinit,
> > freeing the bus.
> >
> > Also, memory_listener_unregister can be called again because it checks
> > for listener->address_space != NULL at start, and sets it to NULL at
> > end.
> >
> > In regular shutdown, nothing of this is called, so maybe we could
> > safely delete the call to memory_listener_unregister at
> > virtio_device_instance_finalize?
>
> I didn't notice this; if so we'd better remove that call if it's destined to be
> a noop after all.
>
> >
> > If not, should I send again the patch with a new commit message?
>
> Maybe attach the full backtrace too along with above?  The assertion itself
> could be a very good explanation of what's happened.
>

I agree, sending v2.

Thanks!

> Thanks,
>
> --
> Peter Xu
>



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-01-25 19:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-22 20:08 [PATCH] virtio: Add corresponding memory_listener_unregister to unrealize Eugenio Pérez
2021-01-22 20:17 ` Peter Xu
2021-01-25  3:15 ` Jason Wang
2021-01-25 16:55   ` Eugenio Perez Martin
2021-01-25 17:18     ` Peter Xu
2021-01-25 19:22       ` Eugenio Perez Martin

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).