]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
sunrpc/cache: improve RCU safety in cache_list walking.
authorNeilBrown <neil@brown.name>
Sat, 18 Oct 2025 00:11:23 +0000 (11:11 +1100)
committerChuck Lever <chuck.lever@oracle.com>
Mon, 30 Mar 2026 01:25:09 +0000 (21:25 -0400)
commit7b546bd89975cfbd60d4b86f2d1a3b6be5f9e558
treedc2ccfb10318fbde9f603c7fb90fed3e916b3f21
parent322ecd01bf8ad7e0da21e174679aff1759e68b2c
sunrpc/cache: improve RCU safety in cache_list walking.

1/ consistently use hlist_add_head_rcu() when adding to
  the cachelist to reflect the fact that it can be concurrently
  walked using RCU.  In fact hlist_add_head() has all the needed
  barriers so this is no safety issue, primarily a clarity issue.

2/ call cache_get() *before* adding the list with hlist_add_head_rcu().
  It is generally safest to inc the refcount before publishing a
  reference.  In this case it doesn't have any behavioural effect
  as code which does an RCU walk does not depend on precision of
  the refcount, and it will always be at least one.  But it looks
  more correct to use this order.

3/ avoid possible races between NULL tests and hlist_entry_safe()
   calls.  It is possible that a test will find that .next or .head
   is not NULL, but hlist_entry_safe() will find that it is NULL.
   This can lead to incorrect behaviour with the list-walk terminating
   early.
   It is safest to always call hlist_entry_safe() and test the result.

   Also simplify the *ppos calculation by simply assigning the hash
   shifted 32, rather than masking out low bits and incrementing high
   bits.

Signed-off-by: NeilBrown <neil@brown.name>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
net/sunrpc/cache.c