Re: [PATCH] xen-blkback: allow module to be cleanly unloaded

From: Jan Beulich
Date: Fri Nov 29 2019 - 06:56:09 EST


On 29.11.2019 12:31, Paul Durrant wrote:
> --- a/drivers/block/xen-blkback/xenbus.c
> +++ b/drivers/block/xen-blkback/xenbus.c
> @@ -173,6 +173,8 @@ static struct xen_blkif *xen_blkif_alloc(domid_t domid)
> init_completion(&blkif->drain_complete);
> INIT_WORK(&blkif->free_work, xen_blkif_deferred_free);
>
> + __module_get(THIS_MODULE);
> +
> return blkif;
> }
>
> @@ -320,6 +322,8 @@ static void xen_blkif_free(struct xen_blkif *blkif)
>
> /* Make sure everything is drained before shutting down */
> kmem_cache_free(xen_blkif_cachep, blkif);
> +
> + module_put(THIS_MODULE);
> }

I realize there are various example of this in the tree, but
isn't this a flawed approach? __module_get() (nor even
try_module_get()) will prevent an unload attempt ahead of it
getting invoked, while execution is already in this module's
.text section. I think the xenbus driver should do this
before calling ->probe(), in case of its failure, and after
a successful call to ->remove().

Jan