Skip to contentSkip to conversation

rcu_dereference() called when not under rcu_read_lock().

Drbd-dev David Butterfield 2 participants 2 messages Jul 8, 2019 DRBD driver

lore
Share & tools
lore
#0 lore raw

It seems that in general rcu_dereference() is expected to be called under rcu_read_lock().

I've observed that it is sometimes called without rcu_read_lock() -- for example the two call stacks below that traverse the idr list. Is something else protecting such that the rcu_read_lock() is unnecessary in some cases?

idr_get_next() calls rcu_dereference(), but is called not under rcu_read_lock()

 [02]   0x5e9eeb  rwlock_assert_readlocked usermode_lib.h:1016 (discriminator 5)
 [03]   0x5fa816  idr_get_next idr.c:602
 [04]   0x5684b7  adm_new_connection drbd_nl.c:3774
 [05]   0x569643  drbd_adm_new_peer drbd_nl.c:4070

idr_find() calls rcu_dereference(), but is called not under rcu_read_lock()

 [02]   0x5e9eeb  rwlock_assert_readlocked usermode_lib.h:1016 (discriminator 5)
 [03]   0x5fa582  idr_find idr.c:507
 [04]   0x536970  minor_to_device drbd_int.h:1418
 [05]   0x546625  drbd_create_device drbd_main.c:3709
 [06]   0x570b85  drbd_adm_new_minor drbd_nl.c:5858
#1 lore raw
Quoted 2 lines · David Butterfield

It seems that in general rcu_dereference() is expected to be called under rcu_read_lock().

[…]

Quoted 3 lines
[04]   0x5684b7  adm_new_connection drbd_nl.c:3774
[05]   0x569643  drbd_adm_new_peer drbd_nl.c:4070

[…]

Quoted 3 lines
[05]   0x546625  drbd_create_device drbd_main.c:3709
[06]   0x570b85  drbd_adm_new_minor drbd_nl.c:5858

We’ll check, but I believe I remember those to be either initializers (no readers and writers yet) or updaters. The code probably does an rcu_assign_pointer() and then possibly a deallocation after synchronize_rcu(). The updaters are normally serialized with mutex locks (e.g. the resource’s conf_update), so they don’t race with each other.

br,
Robert