Skip to contentSkip to conversation

rcu/segcblist: Use WRITE_ONCE() for rclp->len decrement

PATCH In review Kaushlendra Kumar 3 participants 3 messages Sep 11, 2025 RCU

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 rcu/segcblist: Use WRITE_ONCE() for rclp->len decrement

Use WRITE_ONCE() for rclp->len decrement in rcu_cblist_dequeue() to maintain consistency with rcu_cblist_enqueue(), which already uses WRITE_ONCE() for rclp->len increment. It maintains consistent access patterns to the rclp->len field across both enqueue and dequeue operations.

---
Changes in v2:
- Revised justification to focus on code consistency rather than concurrent access claims.
- Revised commit message to use imperative mood throughout per kernel documentation guidelines (suggested by Markus Elfring).

 kernel/rcu/rcu_segcblist.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/rcu/rcu_segcblist.c +1 -1
index 1693ea22ef1b..e10b36e9de54 100644
@@ -71,7 +71,7 @@ struct rcu_head *rcu_cblist_dequeue(struct rcu_cblist *rclp)
 	rhp = rclp->head;
 	if (!rhp)
 		return NULL;
-	rclp->len--;
+	WRITE_ONCE(rclp->len, rclp->len - 1);
 	rclp->head = rhp->next;
 	if (!rclp->head)
 		rclp->tail = &rclp->head;
Signature · 1 line
2.34.1
maintainer
#2 lore raw
In reply to Kaushlendra Kumar
Quoted 6 lines · Kaushlendra Kumar

Use WRITE_ONCE() for rclp->len decrement in rcu_cblist_dequeue() to maintain consistency with rcu_cblist_enqueue(), which already uses WRITE_ONCE() for rclp->len increment. It maintains consistent access patterns to the rclp->len field across both enqueue and dequeue operations.

Again, why is this patch needed?

Please keep in mind that unmarked normal C-language loads and stores have value in that KCSAN can detect data races involving them. If we decorate all loads and stores with READ_ONCE() and WRITE_ONCE(), respectively, KCSAN is unable to detect buggy concurrent accesses.

Thanx, Paul

Quoted 26 lines

---
Changes in v2:
- Revised justification to focus on code consistency rather than concurrent access claims.
- Revised commit message to use imperative mood throughout per kernel documentation guidelines (suggested by Markus Elfring).

 kernel/rcu/rcu_segcblist.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/rcu/rcu_segcblist.c +1 -1
index 1693ea22ef1b..e10b36e9de54 100644
@@ -71,7 +71,7 @@ struct rcu_head *rcu_cblist_dequeue(struct rcu_cblist *rclp)
 	rhp = rclp->head;
 	if (!rhp)
 		return NULL;
-	rclp->len--;
+	WRITE_ONCE(rclp->len, rclp->len - 1);
 	rclp->head = rhp->next;
 	if (!rclp->head)
 		rclp->tail = &rclp->head;
Signature · 1 line
2.34.1