mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] list: Remove unnecessary WRITE_ONCE()
@ 2023-06-19  9:03 Alan Huang
  2023-06-19 11:02 ` Eric Dumazet
  2023-06-21 12:12 ` Alan Huang
  0 siblings, 2 replies; 4+ messages in thread
From: Alan Huang @ 2023-06-19  9:03 UTC (permalink / raw)
  To: paulmck; +Cc: edumazet, linux-kernel, Alan Huang

Commit c54a2744497d("list: Add hlist_unhashed_lockless()") added
various WRITE_ONCE() to pair with the READ_ONCE() in
hlist_unhashed_lockless(), but there is no need to protect
->next with WRITE_ONCE(). Therefore, this commit removes those
unnecessary WRITE_ONCE().

Signed-off-by: Alan Huang <mmpgouride@gmail.com>
---
 include/linux/list.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/linux/list.h b/include/linux/list.h
index f10344dbad..ac366958ea 100644
--- a/include/linux/list.h
+++ b/include/linux/list.h
@@ -940,7 +940,7 @@ static inline void hlist_del_init(struct hlist_node *n)
 static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
 {
 	struct hlist_node *first = h->first;
-	WRITE_ONCE(n->next, first);
+	n->next = first;
 	if (first)
 		WRITE_ONCE(first->pprev, &n->next);
 	WRITE_ONCE(h->first, n);
@@ -956,7 +956,7 @@ static inline void hlist_add_before(struct hlist_node *n,
 				    struct hlist_node *next)
 {
 	WRITE_ONCE(n->pprev, next->pprev);
-	WRITE_ONCE(n->next, next);
+	n->next = next;
 	WRITE_ONCE(next->pprev, &n->next);
 	WRITE_ONCE(*(n->pprev), n);
 }
@@ -969,8 +969,8 @@ static inline void hlist_add_before(struct hlist_node *n,
 static inline void hlist_add_behind(struct hlist_node *n,
 				    struct hlist_node *prev)
 {
-	WRITE_ONCE(n->next, prev->next);
-	WRITE_ONCE(prev->next, n);
+	n->next = prev->next;
+	prev->next = n;
 	WRITE_ONCE(n->pprev, &prev->next);
 
 	if (n->next)
-- 
2.34.1


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

* Re: [PATCH] list: Remove unnecessary WRITE_ONCE()
  2023-06-19  9:03 [PATCH] list: Remove unnecessary WRITE_ONCE() Alan Huang
@ 2023-06-19 11:02 ` Eric Dumazet
  2023-06-19 11:39   ` Alan Huang
  2023-06-21 12:12 ` Alan Huang
  1 sibling, 1 reply; 4+ messages in thread
From: Eric Dumazet @ 2023-06-19 11:02 UTC (permalink / raw)
  To: Alan Huang; +Cc: paulmck, linux-kernel

On Mon, Jun 19, 2023 at 11:03 AM Alan Huang <mmpgouride@gmail.com> wrote:
>
> Commit c54a2744497d("list: Add hlist_unhashed_lockless()") added
> various WRITE_ONCE() to pair with the READ_ONCE() in
> hlist_unhashed_lockless(), but there is no need to protect
> ->next with WRITE_ONCE(). Therefore, this commit removes those
> unnecessary WRITE_ONCE().

Why are they unnecessary ?
They seem just fine to me.
Please elaborate.

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

* Re: [PATCH] list: Remove unnecessary WRITE_ONCE()
  2023-06-19 11:02 ` Eric Dumazet
@ 2023-06-19 11:39   ` Alan Huang
  0 siblings, 0 replies; 4+ messages in thread
From: Alan Huang @ 2023-06-19 11:39 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: paulmck, linux-kernel


> 2023年6月19日 19:02,Eric Dumazet <edumazet@google.com> 写道:
> 
> On Mon, Jun 19, 2023 at 11:03 AM Alan Huang <mmpgouride@gmail.com> wrote:
>> 
>> Commit c54a2744497d("list: Add hlist_unhashed_lockless()") added
>> various WRITE_ONCE() to pair with the READ_ONCE() in
>> hlist_unhashed_lockless(), but there is no need to protect
>> ->next with WRITE_ONCE(). Therefore, this commit removes those
>> unnecessary WRITE_ONCE().
> 
> Why are they unnecessary ?

There is no reader locklessly read ->next.

These functions are protected by something like spin_lock, only the thread running 
the function can access ->next.

> They seem just fine to me.
> Please elaborate.


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

* Re: [PATCH] list: Remove unnecessary WRITE_ONCE()
  2023-06-19  9:03 [PATCH] list: Remove unnecessary WRITE_ONCE() Alan Huang
  2023-06-19 11:02 ` Eric Dumazet
@ 2023-06-21 12:12 ` Alan Huang
  1 sibling, 0 replies; 4+ messages in thread
From: Alan Huang @ 2023-06-21 12:12 UTC (permalink / raw)
  To: paulmck; +Cc: Eric Dumazet, linux-kernel

Hi Paul,

Looks like you missed this one?

Thanks,
Alan

> 2023年6月19日 17:03,Alan Huang <mmpgouride@gmail.com> 写道:
> 
> Commit c54a2744497d("list: Add hlist_unhashed_lockless()") added
> various WRITE_ONCE() to pair with the READ_ONCE() in
> hlist_unhashed_lockless(), but there is no need to protect
> ->next with WRITE_ONCE(). Therefore, this commit removes those
> unnecessary WRITE_ONCE().
> 
> Signed-off-by: Alan Huang <mmpgouride@gmail.com>
> ---
> include/linux/list.h | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/include/linux/list.h b/include/linux/list.h
> index f10344dbad..ac366958ea 100644
> --- a/include/linux/list.h
> +++ b/include/linux/list.h
> @@ -940,7 +940,7 @@ static inline void hlist_del_init(struct hlist_node *n)
> static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
> {
> struct hlist_node *first = h->first;
> - WRITE_ONCE(n->next, first);
> + n->next = first;
> if (first)
> WRITE_ONCE(first->pprev, &n->next);
> WRITE_ONCE(h->first, n);
> @@ -956,7 +956,7 @@ static inline void hlist_add_before(struct hlist_node *n,
>    struct hlist_node *next)
> {
> WRITE_ONCE(n->pprev, next->pprev);
> - WRITE_ONCE(n->next, next);
> + n->next = next;
> WRITE_ONCE(next->pprev, &n->next);
> WRITE_ONCE(*(n->pprev), n);
> }
> @@ -969,8 +969,8 @@ static inline void hlist_add_before(struct hlist_node *n,
> static inline void hlist_add_behind(struct hlist_node *n,
>    struct hlist_node *prev)
> {
> - WRITE_ONCE(n->next, prev->next);
> - WRITE_ONCE(prev->next, n);
> + n->next = prev->next;
> + prev->next = n;
> WRITE_ONCE(n->pprev, &prev->next);
> 
> if (n->next)
> -- 
> 2.34.1
> 


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

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

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-19  9:03 [PATCH] list: Remove unnecessary WRITE_ONCE() Alan Huang
2023-06-19 11:02 ` Eric Dumazet
2023-06-19 11:39   ` Alan Huang
2023-06-21 12:12 ` Alan Huang

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®