On Thursday, 23 July 2026 03:17:12 CEST Stefano Stabellini wrote:
> On Wed, 22 Jul 2026, Christian Schoenebeck wrote:
[...]
> > > @@ -368,10 +375,18 @@ static void xen_9pfs_evtchn_event(void *opaque)
> > >
> > > static void xen_9pfs_disconnect(struct XenLegacyDevice *xendev)
> > > {
> > >
> > > Xen9pfsDev *xen_9pdev = container_of(xendev, Xen9pfsDev, xendev);
> > >
> > > + V9fsState *s = &xen_9pdev->state;
> > >
> > > int i;
> > >
> > > + if (!xen_9pdev->rings) {
>
> specifically this check is not sufficient are there can be cases where
> rings != NULL but transport is not set and v9fs_reset should not be
> called. For instance xen_be_map_grant_ref() returns NULL,
> xen_9pfs_connect() go out without calling v9fs_device_realize_common().
> s->transport == NULL and also s->fids == NULL but rings != NULL. Later
> v9fs_reset calls g_hash_table_get_values(s->fids)
>
> > > + return;
> > > + }
> > > +
> > >
> > > trace_xen_9pfs_disconnect(xendev->name);
> > >
> > > + v9fs_reset(s);
> > > + v9fs_device_unrealize_common(s);
> > > +
> > >
> > > for (i = 0; i < xen_9pdev->num_rings; i++) {
> > >
> > > if (xen_9pdev->rings[i].evtchndev != NULL) {
> > >
> > > qemu_set_fd_handler(qemu_xen_evtchn_fd(xen_9pdev->rings[i].evtchndev),
>
> See this below. If you agree and add the below to this patch you can add
> my Reviewed-by.
>
>
> diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
> index 3119f01117..fc01791830 100644
> --- a/hw/9pfs/9p.c
> +++ b/hw/9pfs/9p.c
> @@ -4530,6 +4530,7 @@ void v9fs_device_unrealize_common(V9fsState *s)
> qp_table_destroy(&s->qpp_table);
> qp_table_destroy(&s->qpf_table);
> g_free(s->ctx.fs_root);
> + s->transport = NULL;
> }
>
> typedef struct VirtfsCoResetData {
> diff --git a/hw/9pfs/xen-9p-backend.c b/hw/9pfs/xen-9p-backend.c
> index edb65a7afc..f0791f9e97 100644
> --- a/hw/9pfs/xen-9p-backend.c
> +++ b/hw/9pfs/xen-9p-backend.c
> @@ -384,8 +384,10 @@ static void xen_9pfs_disconnect(struct XenLegacyDevice
> *xendev)
>
> trace_xen_9pfs_disconnect(xendev->name);
>
> - v9fs_reset(s);
> - v9fs_device_unrealize_common(s);
> + if (s->transport) {
> + v9fs_reset(s);
> + v9fs_device_unrealize_common(s);
> + }
>
> for (i = 0; i < xen_9pdev->num_rings; i++) {
> if (xen_9pdev->rings[i].evtchndev != NULL) {
Agreed, these two changes makes sense. I'll formally send a v3 with these two
changes added now.
My plan is to send a PR with this and other fixes tomorrow already, as we're
getting very close to release.
Thanks Stefano!
/Christian