Linux Documentation
 help / color / mirror / Atom feed
* [PATCH v2] docs/RCU: Bring smp_wmb() back
@ 2023-06-17 14:53 Alan Huang
  2023-06-17 17:23 ` Matthew Wilcox
  2023-06-20 22:33 ` Paul E. McKenney
  0 siblings, 2 replies; 7+ messages in thread
From: Alan Huang @ 2023-06-17 14:53 UTC (permalink / raw)
  To: paulmck; +Cc: joel, corbet, rcu, linux-doc, Alan Huang

There are two memory ordering required in the insertion algorithm,
we need to make sure obj->key is updated before obj->obj_node.next
and obj->refcnt, atomic_set_release is not enough to provide the
required memory barrier.

Signed-off-by: Alan Huang <mmpgouride@gmail.com>
---
 Documentation/RCU/rculist_nulls.rst | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/Documentation/RCU/rculist_nulls.rst b/Documentation/RCU/rculist_nulls.rst
index e06ed40bb6..77244adbdf 100644
--- a/Documentation/RCU/rculist_nulls.rst
+++ b/Documentation/RCU/rculist_nulls.rst
@@ -98,7 +98,7 @@ Quoting Corey Minyard::
 ----------------------
 
 We need to make sure a reader cannot read the new 'obj->obj_node.next' value
-and previous value of 'obj->key'. Otherwise, an item could be deleted
+and previous value of 'obj->key' at the same time. Otherwise, an item could be deleted
 from a chain, and inserted into another chain. If new chain was empty
 before the move, 'next' pointer is NULL, and lockless reader can not
 detect the fact that it missed following items in original chain.
@@ -112,7 +112,12 @@ detect the fact that it missed following items in original chain.
   obj = kmem_cache_alloc(...);
   lock_chain(); // typically a spin_lock()
   obj->key = key;
-  atomic_set_release(&obj->refcnt, 1); // key before refcnt
+  /*
+  * we need to make sure obj->key is updated before obj->obj_node.next
+  * and obj->refcnt
+  */
+  smp_wmb();
+  atomic_set(&obj->refcnt, 1);
   hlist_add_head_rcu(&obj->obj_node, list);
   unlock_chain(); // typically a spin_unlock()
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-06-21  1:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-17 14:53 [PATCH v2] docs/RCU: Bring smp_wmb() back Alan Huang
2023-06-17 17:23 ` Matthew Wilcox
2023-06-17 17:55   ` Alan Huang
2023-06-17 18:07     ` Matthew Wilcox
2023-06-17 18:21       ` Alan Huang
2023-06-20 22:33 ` Paul E. McKenney
2023-06-21  1:24   ` Alan Huang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox