mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] rcu/segcblist: Use WRITE_ONCE() for rclp->len decrement
@ 2025-09-11 16:26 Kaushlendra Kumar
  2025-09-11 18:18 ` Davidlohr Bueso
  2025-09-11 19:41 ` Paul E. McKenney
  0 siblings, 2 replies; 3+ messages in thread
From: Kaushlendra Kumar @ 2025-09-11 16:26 UTC (permalink / raw)
  To: dave, paulmck, josh, frederic, neeraj.upadhyay, rostedt
  Cc: linux-kernel, rcu, 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.

Signed-off-by: Kaushlendra Kumar <kaushlendra.kumar@intel.com>
---
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(-)

diff --git a/kernel/rcu/rcu_segcblist.c b/kernel/rcu/rcu_segcblist.c
index 1693ea22ef1b..e10b36e9de54 100644
--- a/kernel/rcu/rcu_segcblist.c
+++ b/kernel/rcu/rcu_segcblist.c
@@ -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;
-- 
2.34.1


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

* Re: [PATCH v2] rcu/segcblist: Use WRITE_ONCE() for rclp->len decrement
  2025-09-11 16:26 [PATCH v2] rcu/segcblist: Use WRITE_ONCE() for rclp->len decrement Kaushlendra Kumar
@ 2025-09-11 18:18 ` Davidlohr Bueso
  2025-09-11 19:41 ` Paul E. McKenney
  1 sibling, 0 replies; 3+ messages in thread
From: Davidlohr Bueso @ 2025-09-11 18:18 UTC (permalink / raw)
  To: Kaushlendra Kumar
  Cc: paulmck, josh, frederic, neeraj.upadhyay, rostedt, linux-kernel, rcu

On Thu, 11 Sep 2025, Kaushlendra Kumar wrote:

>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.
>
>Signed-off-by: Kaushlendra Kumar <kaushlendra.kumar@intel.com>

Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>

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

* Re: [PATCH v2] rcu/segcblist: Use WRITE_ONCE() for rclp->len decrement
  2025-09-11 16:26 [PATCH v2] rcu/segcblist: Use WRITE_ONCE() for rclp->len decrement Kaushlendra Kumar
  2025-09-11 18:18 ` Davidlohr Bueso
@ 2025-09-11 19:41 ` Paul E. McKenney
  1 sibling, 0 replies; 3+ messages in thread
From: Paul E. McKenney @ 2025-09-11 19:41 UTC (permalink / raw)
  To: Kaushlendra Kumar
  Cc: dave, josh, frederic, neeraj.upadhyay, rostedt, linux-kernel, rcu

On Thu, Sep 11, 2025 at 09:56:41PM +0530, Kaushlendra Kumar wrote:
> 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.
> 
> Signed-off-by: Kaushlendra Kumar <kaushlendra.kumar@intel.com>

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

> ---
> 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(-)
> 
> diff --git a/kernel/rcu/rcu_segcblist.c b/kernel/rcu/rcu_segcblist.c
> index 1693ea22ef1b..e10b36e9de54 100644
> --- a/kernel/rcu/rcu_segcblist.c
> +++ b/kernel/rcu/rcu_segcblist.c
> @@ -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;
> -- 
> 2.34.1
> 

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

end of thread, other threads:[~2025-09-11 19:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-11 16:26 [PATCH v2] rcu/segcblist: Use WRITE_ONCE() for rclp->len decrement Kaushlendra Kumar
2025-09-11 18:18 ` Davidlohr Bueso
2025-09-11 19:41 ` Paul E. McKenney

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

all inboxes | Powered by JetHome®