Skip to contentSkip to conversation

net: bridge: annotate data-race in br_fdb_update()

PATCH In review Eric Dumazet 2 participants 5 messages Jan 6 – Jan 7

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: bridge: annotate data-race in br_fdb_update()

fdb->updated is read and written locklessly.

Add READ_ONCE()/WRITE_ONCE() annotations.

Fixes 31cbc39b6344 ("net: bridge: add option to allow activity notifications for any fdb entries")
Cc Nikolay Aleksandrov <[email protected]>
---
 net/bridge/br_fdb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/bridge/br_fdb.c +2 -2
index 58d22e2b85fc3551bd5aec9c20296ddfcecaa040..e7bd20f0e8d6b7b24aef43d7bed34adf171c34a8 100644
@@ -1002,8 +1002,8 @@ void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source,
 			unsigned long now = jiffies;
 			bool fdb_modified = false;
 
-			if (now != fdb->updated) {
-				fdb->updated = now;
+			if (now != READ_ONCE(fdb->updated)) {
+				WRITE_ONCE(fdb->updated, now);
 				fdb_modified = __fdb_mark_active(fdb);
 			}
 
Signature · 1 line
2.52.0.351.gbe84eed79e-goog
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 16 lines · Eric Dumazet

fdb->updated is read and written locklessly.

Add READ_ONCE()/WRITE_ONCE() annotations.

Fixes 31cbc39b6344 ("net: bridge: add option to allow activity notifications for any fdb entries")
Cc Nikolay Aleksandrov <[email protected]>
---
  net/bridge/br_fdb.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
net/bridge/br_fdb.c +0 -0
index 58d22e2b85fc3551bd5aec9c20296ddfcecaa040..e7bd20f0e8d6b7b24aef43d7bed34adf171c34a8 100644

net/bridge/br_fdb.c void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source, · line 1009

Quoted 10 lines
net/bridge/br_fdb.c +2 -2
@@ -1002,8 +1002,8 @@ void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source,
  			unsigned long now = jiffies;
  			bool fdb_modified = false;
 
-			if (now != fdb->updated) {
-				fdb->updated = now;
+			if (now != READ_ONCE(fdb->updated)) {
+				WRITE_ONCE(fdb->updated, now);
  				fdb_modified = __fdb_mark_active(fdb);
  			}
 

Thanks,

#2 lore raw
Quoted 28 lines · Nikolay Aleksandrov
Quoted 16 lines · Eric Dumazet

fdb->updated is read and written locklessly.

Add READ_ONCE()/WRITE_ONCE() annotations.

Fixes 31cbc39b6344 ("net: bridge: add option to allow activity notifications for any fdb entries")
Cc Nikolay Aleksandrov <[email protected]>

---
  net/bridge/br_fdb.c | 4 ++--

  1 file changed, 2 insertions(+), 2 deletions(-)
net/bridge/br_fdb.c +0 -0
index 58d22e2b85fc3551bd5aec9c20296ddfcecaa040..e7bd20f0e8d6b7b24aef43d7bed34adf171c34a8 100644

net/bridge/br_fdb.c void br_fdb_update(struct net_bridge *br, struct · line 1008

Quoted 9 lines
net/bridge/br_fdb.c +2 -2
@@ -1002,8 +1002,8 @@ void br_fdb_update(struct net_bridge *br, struct 
 net_bridge_port *source,
               unsigned long now = jiffies;
               bool fdb_modified = false;
-            if (now != fdb->updated) {
-                fdb->updated = now;
+            if (now != READ_ONCE(fdb->updated)) {
+                WRITE_ONCE(fdb->updated, now);
                   fdb_modified = __fdb_mark_active(fdb);
               }

Thanks,

Quoted 1 line

Actually on second thought, ->updated is used lockless in a few more places, e.g. br_fdb_fillbuf(), fdb_fill_info(), br_fdb_cleanup().

#3 lore raw
Quoted 31 lines · Nikolay Aleksandrov
Quoted 28 lines · Nikolay Aleksandrov
Quoted 16 lines · Eric Dumazet

fdb->updated is read and written locklessly.

Add READ_ONCE()/WRITE_ONCE() annotations.

Fixes 31cbc39b6344 ("net: bridge: add option to allow activity notifications for any fdb entries")
Cc Nikolay Aleksandrov <[email protected]>

---
  net/bridge/br_fdb.c | 4 ++--

  1 file changed, 2 insertions(+), 2 deletions(-)
net/bridge/br_fdb.c +0 -0
index 58d22e2b85fc3551bd5aec9c20296ddfcecaa040..e7bd20f0e8d6b7b24aef43d7bed34adf171c34a8 100644

net/bridge/br_fdb.c void br_fdb_update(struct net_bridge *br, · line 1008

Quoted 9 lines
net/bridge/br_fdb.c +2 -2
@@ -1002,8 +1002,8 @@ void br_fdb_update(struct net_bridge *br, 
 struct net_bridge_port *source,
               unsigned long now = jiffies;
               bool fdb_modified = false;
-            if (now != fdb->updated) {
-                fdb->updated = now;
+            if (now != READ_ONCE(fdb->updated)) {
+                WRITE_ONCE(fdb->updated, now);
                   fdb_modified = __fdb_mark_active(fdb);
               }

Thanks,

Quoted 1 line
Quoted 3 lines

Actually on second thought, ->updated is used lockless in a few more places, e.g. br_fdb_fillbuf(), fdb_fill_info(), br_fdb_cleanup().

I mean I see the subject, but since this patch will get backported perhaps we can annotate all instances in one go.

Cheers,
Nik

#4 lore raw
Quoted 35 lines · Nikolay Aleksandrov
Quoted 33 lines · Nikolay Aleksandrov
Quoted 31 lines · Nikolay Aleksandrov
Quoted 18 lines · Eric Dumazet

fdb->updated is read and written locklessly.

Add READ_ONCE()/WRITE_ONCE() annotations.

Fixes 31cbc39b6344 ("net: bridge: add option to allow activity

notifications for any fdb entries")

Cc Nikolay Aleksandrov <[email protected]>
---
  net/bridge/br_fdb.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
net/bridge/br_fdb.c +0 -0

index 58d22e2b85fc3551bd5aec9c20296ddfcecaa040..e7bd20f0e8d6b7b24aef43d7bed34adf171c34a8 100644

net/bridge/br_fdb.c void br_fdb_update(struct net_bridge *br, · line 1008

Quoted 9 lines
net/bridge/br_fdb.c +2 -2
@@ -1002,8 +1002,8 @@ void br_fdb_update(struct net_bridge *br,
 struct net_bridge_port *source,
              unsigned long now = jiffies;
              bool fdb_modified = false;
-            if (now != fdb->updated) {
-                fdb->updated = now;
+            if (now != READ_ONCE(fdb->updated)) {
+                WRITE_ONCE(fdb->updated, now);
                  fdb_modified = __fdb_mark_active(fdb);
              }

Thanks,

Quoted 6 lines
Quoted 3 lines

Actually on second thought, ->updated is used lockless in a few more places, e.g. br_fdb_fillbuf(), fdb_fill_info(), br_fdb_cleanup().

I mean I see the subject, but since this patch will get backported perhaps we can annotate all instances in one go.

Sure, I will send a V2, thanks.