History

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 14855954f636 "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.

Paul Durrant committed 6 years ago

Commit fa2ac651 parent 14855951 file · +10 −0Browse files

Unified · Split

drivers/block/xen-blkback/xenbus.c+10−0
@@ -171,6 +171,15 @@ static struct xen_blkif *xen_blkif_alloc(domid_t domid) · 170 unmodified lines
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) · 143 unmodified lines
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)