dlm: add rcu_barrier before destroy kmem cache
Alexander Aring
maintainerPATCH 1/1 dlm: add rcu_barrier before destroy kmem cache
In the case we trigger dlm_free_rsb() that does a call_rcu() and the responding kfree() of res_lvbptr and a kmem_cache_free() of the rsb pointer we need to wait until this pending operation is done before calling kmem_cache_destroy(). We doing that by using rcu_barrier() that waits until all pending call_rcu() are done. This avoids that kmem_cache_destroy() complains about active objects around that are not being freed yet by call_rcu().
There is currently more discussions about to make this behaviour better, see:
https://lore.kernel.org/netdev/[email protected]/
However this is only for call_rcu() if the callback calls kmem_cache_destroy() only to replace it by kfree_rcu() call which has currently some issue. This isn't our case because we also free the res_lvbptr if being set.
For our case, to avoid the above race rcu_barrier() should be used before calling kmem_cache_destroy() to be sure that there are no active objects around. This is exactly what net/batman-adv is also doing before calling their kmem_cache_destroy() in module unloading.
--- fs/dlm/memory.c | 2 ++ 1 file changed, 2 insertions(+)
fs/dlm/memory.c +2 -0
@@ -72,6 +72,8 @@ int __init dlm_memory_init(void)void dlm_memory_exit (void ) { +rcu_barrier (); +kmem_cache_destroy (writequeue_cache);kmem_cache_destroy (mhandle_cache);kmem_cache_destroy (msg_cache);
Signature · 1 line
2.43.0
Alexander Aring
maintainerHi,
Quoted 19 lines · Alexander Aring
In the case we trigger
dlm_free_rsb()that does acall_rcu()and the respondingkfree()ofres_lvbptrand akmem_cache_free()of the rsb pointer we need to wait until this pending operation is done before callingkmem_cache_destroy(). We doing that by usingrcu_barrier()that waits until all pendingcall_rcu()are done. This avoids thatkmem_cache_destroy()complains about active objects around that are not being freed yet bycall_rcu().There is currently more discussions about to make this behaviour better, see:
https://lore.kernel.org/netdev/[email protected]/
However this is only for
call_rcu()if the callback callskmem_cache_destroy()only to replace it bykfree_rcu()call which has currently some issue. This isn't our case because we also free theres_lvbptrif being set.
Quoted 6 lines
For our case, to avoid the above race
rcu_barrier()should be used before callingkmem_cache_destroy()to be sure that there are no active objects around. This is exactly whatnet/batman-advis also doing before calling theirkmem_cache_destroy()in module unloading.Signed-off-by Alexander Aring <[email protected]>
missing "Fixes" tag:
- Alex