Skip to content

Commit fa2ac65

Browse files
Paul Durrantjgross1
authored andcommitted
xen-blkback: prevent premature module unload
Objects allocated by xen_blkif_alloc come from the 'blkif_cache' kmem cache. This cache is destoyed when xen-blkif is unloaded so it is necessary to wait for the deferred free routine used for such objects to complete. This necessity was missed in commit 1485595 "xen-blkback: allow module to be cleanly unloaded". This patch fixes the problem by taking/releasing extra module references in xen_blkif_alloc/free() respectively. Signed-off-by: Paul Durrant <[email protected]> Reviewed-by: Roger Pau Monné <[email protected]> Signed-off-by: Juergen Gross <[email protected]>
1 parent 1485595 commit fa2ac65

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

drivers/block/xen-blkback/xenbus.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,15 @@ static struct xen_blkif *xen_blkif_alloc(domid_t domid)
171171
blkif->domid = domid;
172172
atomic_set(&blkif->refcnt, 1);
173173
init_completion(&blkif->drain_complete);
174+
175+
/*
176+
* Because freeing back to the cache may be deferred, it is not
177+
* safe to unload the module (and hence destroy the cache) until
178+
* this has completed. To prevent premature unloading, take an
179+
* extra module reference here and release only when the object
180+
* has been freed back to the cache.
181+
*/
182+
__module_get(THIS_MODULE);
174183
INIT_WORK(&blkif->free_work, xen_blkif_deferred_free);
175184

176185
return blkif;
@@ -320,6 +329,7 @@ static void xen_blkif_free(struct xen_blkif *blkif)
320329

321330
/* Make sure everything is drained before shutting down */
322331
kmem_cache_free(xen_blkif_cachep, blkif);
332+
module_put(THIS_MODULE);
323333
}
324334

325335
int __init xen_blkif_interface_init(void)

0 commit comments

Comments
 (0)