public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 net] net: bridge: annotate data-races around fdb->{updated,used}
@ 2026-01-07  8:32 Eric Dumazet
  2026-01-07  9:00 ` Nikolay Aleksandrov
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Dumazet @ 2026-01-07  8:32 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski, Paolo Abeni
  Cc: Simon Horman, netdev, eric.dumazet, Eric Dumazet,
	Nikolay Aleksandrov

fdb->updated and fdb->used are read and written locklessly.

Add READ_ONCE()/WRITE_ONCE() annotations.

Fixes: 31cbc39b6344 ("net: bridge: add option to allow activity notifications for any fdb entries")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Nikolay Aleksandrov <razor@blackwall.org>
---
v2: annotate all problematic fdb->updated and fdb->used reads/writes.
v1: https://lore.kernel.org/netdev/CANn89iL8-e_jphcg49eX=zdWrOeuA-AJDL0qhsTrApA4YnOFEg@mail.gmail.com/T/#mf99b76469697813939abe745f42ace3e201ef6f4

 net/bridge/br_fdb.c | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c
index 58d22e2b85fc3551bd5aec9c20296ddfcecaa040..0501ffcb8a3ddb21a19254915564b4000b6b6911 100644
--- a/net/bridge/br_fdb.c
+++ b/net/bridge/br_fdb.c
@@ -70,7 +70,7 @@ static inline int has_expired(const struct net_bridge *br,
 {
 	return !test_bit(BR_FDB_STATIC, &fdb->flags) &&
 	       !test_bit(BR_FDB_ADDED_BY_EXT_LEARN, &fdb->flags) &&
-	       time_before_eq(fdb->updated + hold_time(br), jiffies);
+	       time_before_eq(READ_ONCE(fdb->updated) + hold_time(br), jiffies);
 }
 
 static int fdb_to_nud(const struct net_bridge *br,
@@ -126,9 +126,9 @@ static int fdb_fill_info(struct sk_buff *skb, const struct net_bridge *br,
 	if (nla_put_u32(skb, NDA_FLAGS_EXT, ext_flags))
 		goto nla_put_failure;
 
-	ci.ndm_used	 = jiffies_to_clock_t(now - fdb->used);
+	ci.ndm_used	 = jiffies_to_clock_t(now - READ_ONCE(fdb->used));
 	ci.ndm_confirmed = 0;
-	ci.ndm_updated	 = jiffies_to_clock_t(now - fdb->updated);
+	ci.ndm_updated	 = jiffies_to_clock_t(now - READ_ONCE(fdb->updated));
 	ci.ndm_refcnt	 = 0;
 	if (nla_put(skb, NDA_CACHEINFO, sizeof(ci), &ci))
 		goto nla_put_failure;
@@ -551,7 +551,7 @@ void br_fdb_cleanup(struct work_struct *work)
 	 */
 	rcu_read_lock();
 	hlist_for_each_entry_rcu(f, &br->fdb_list, fdb_node) {
-		unsigned long this_timer = f->updated + delay;
+		unsigned long this_timer = READ_ONCE(f->updated) + delay;
 
 		if (test_bit(BR_FDB_STATIC, &f->flags) ||
 		    test_bit(BR_FDB_ADDED_BY_EXT_LEARN, &f->flags)) {
@@ -924,6 +924,7 @@ int br_fdb_fillbuf(struct net_bridge *br, void *buf,
 {
 	struct net_bridge_fdb_entry *f;
 	struct __fdb_entry *fe = buf;
+	unsigned long delta;
 	int num = 0;
 
 	memset(buf, 0, maxnum*sizeof(struct __fdb_entry));
@@ -953,8 +954,11 @@ int br_fdb_fillbuf(struct net_bridge *br, void *buf,
 		fe->port_hi = f->dst->port_no >> 8;
 
 		fe->is_local = test_bit(BR_FDB_LOCAL, &f->flags);
-		if (!test_bit(BR_FDB_STATIC, &f->flags))
-			fe->ageing_timer_value = jiffies_delta_to_clock_t(jiffies - f->updated);
+		if (!test_bit(BR_FDB_STATIC, &f->flags)) {
+			delta = jiffies - READ_ONCE(f->updated);
+			fe->ageing_timer_value =
+				jiffies_delta_to_clock_t(delta);
+		}
 		++fe;
 		++num;
 	}
@@ -1002,8 +1006,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);
 			}
 
@@ -1242,10 +1246,10 @@ static int fdb_add_entry(struct net_bridge *br, struct net_bridge_port *source,
 	if (fdb_handle_notify(fdb, notify))
 		modified = true;
 
-	fdb->used = jiffies;
+	WRITE_ONCE(fdb->used, jiffies);
 	if (modified) {
 		if (refresh)
-			fdb->updated = jiffies;
+			WRITE_ONCE(fdb->updated, jiffies);
 		fdb_notify(br, fdb, RTM_NEWNEIGH, true);
 	}
 
@@ -1556,7 +1560,7 @@ int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p,
 			goto err_unlock;
 		}
 
-		fdb->updated = jiffies;
+		WRITE_ONCE(fdb->updated, jiffies);
 
 		if (READ_ONCE(fdb->dst) != p) {
 			WRITE_ONCE(fdb->dst, p);
@@ -1565,7 +1569,7 @@ int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p,
 
 		if (test_and_set_bit(BR_FDB_ADDED_BY_EXT_LEARN, &fdb->flags)) {
 			/* Refresh entry */
-			fdb->used = jiffies;
+			WRITE_ONCE(fdb->used, jiffies);
 		} else {
 			modified = true;
 		}
-- 
2.52.0.351.gbe84eed79e-goog


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

* Re: [PATCH v2 net] net: bridge: annotate data-races around fdb->{updated,used}
  2026-01-07  8:32 [PATCH v2 net] net: bridge: annotate data-races around fdb->{updated,used} Eric Dumazet
@ 2026-01-07  9:00 ` Nikolay Aleksandrov
  2026-01-07 10:43   ` Nikolay Aleksandrov
  0 siblings, 1 reply; 4+ messages in thread
From: Nikolay Aleksandrov @ 2026-01-07  9:00 UTC (permalink / raw)
  To: Eric Dumazet, David S . Miller, Jakub Kicinski, Paolo Abeni
  Cc: Simon Horman, netdev, eric.dumazet, Ido Schimmel

On 07/01/2026 10:32, Eric Dumazet wrote:
> fdb->updated and fdb->used are read and written locklessly.
> 
> Add READ_ONCE()/WRITE_ONCE() annotations.
> 
> Fixes: 31cbc39b6344 ("net: bridge: add option to allow activity notifications for any fdb entries")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Nikolay Aleksandrov <razor@blackwall.org>
> ---
> v2: annotate all problematic fdb->updated and fdb->used reads/writes.
> v1: https://lore.kernel.org/netdev/CANn89iL8-e_jphcg49eX=zdWrOeuA-AJDL0qhsTrApA4YnOFEg@mail.gmail.com/T/#mf99b76469697813939abe745f42ace3e201ef6f4
> 
>   net/bridge/br_fdb.c | 28 ++++++++++++++++------------
>   1 file changed, 16 insertions(+), 12 deletions(-)
> 

+CC Ido

Oh you took care of ->used as well, even better. Thanks!
Acked-by: Nikolay Aleksandrov <razor@blackwall.org>


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

* Re: [PATCH v2 net] net: bridge: annotate data-races around fdb->{updated,used}
  2026-01-07  9:00 ` Nikolay Aleksandrov
@ 2026-01-07 10:43   ` Nikolay Aleksandrov
  2026-01-07 10:46     ` Eric Dumazet
  0 siblings, 1 reply; 4+ messages in thread
From: Nikolay Aleksandrov @ 2026-01-07 10:43 UTC (permalink / raw)
  To: Eric Dumazet, David S . Miller, Jakub Kicinski, Paolo Abeni
  Cc: Simon Horman, netdev, eric.dumazet, Ido Schimmel

On 07/01/2026 11:00, Nikolay Aleksandrov wrote:
> On 07/01/2026 10:32, Eric Dumazet wrote:
>> fdb->updated and fdb->used are read and written locklessly.
>>
>> Add READ_ONCE()/WRITE_ONCE() annotations.
>>
>> Fixes: 31cbc39b6344 ("net: bridge: add option to allow activity 
>> notifications for any fdb entries")
>> Signed-off-by: Eric Dumazet <edumazet@google.com>
>> Cc: Nikolay Aleksandrov <razor@blackwall.org>
>> ---
>> v2: annotate all problematic fdb->updated and fdb->used reads/writes.
>> v1: https://lore.kernel.org/netdev/CANn89iL8-e_jphcg49eX=zdWrOeuA- 
>> AJDL0qhsTrApA4YnOFEg@mail.gmail.com/T/ 
>> #mf99b76469697813939abe745f42ace3e201ef6f4
>>
>>   net/bridge/br_fdb.c | 28 ++++++++++++++++------------
>>   1 file changed, 16 insertions(+), 12 deletions(-)
>>
> 
> +CC Ido
> 
> Oh you took care of ->used as well, even better. Thanks!
> Acked-by: Nikolay Aleksandrov <razor@blackwall.org>
> 

Sorry, I forgot about br_input.c: br_handle_frame_finish()
use of ->used:
...
                 if (now != dst->used)
                         dst->used = now;
...

That will need annotations as well.

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

* Re: [PATCH v2 net] net: bridge: annotate data-races around fdb->{updated,used}
  2026-01-07 10:43   ` Nikolay Aleksandrov
@ 2026-01-07 10:46     ` Eric Dumazet
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Dumazet @ 2026-01-07 10:46 UTC (permalink / raw)
  To: Nikolay Aleksandrov
  Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
	netdev, eric.dumazet, Ido Schimmel

On Wed, Jan 7, 2026 at 11:43 AM Nikolay Aleksandrov <razor@blackwall.org> wrote:
>
> On 07/01/2026 11:00, Nikolay Aleksandrov wrote:
> > On 07/01/2026 10:32, Eric Dumazet wrote:
> >> fdb->updated and fdb->used are read and written locklessly.
> >>
> >> Add READ_ONCE()/WRITE_ONCE() annotations.
> >>
> >> Fixes: 31cbc39b6344 ("net: bridge: add option to allow activity
> >> notifications for any fdb entries")
> >> Signed-off-by: Eric Dumazet <edumazet@google.com>
> >> Cc: Nikolay Aleksandrov <razor@blackwall.org>
> >> ---
> >> v2: annotate all problematic fdb->updated and fdb->used reads/writes.
> >> v1: https://lore.kernel.org/netdev/CANn89iL8-e_jphcg49eX=zdWrOeuA-
> >> AJDL0qhsTrApA4YnOFEg@mail.gmail.com/T/
> >> #mf99b76469697813939abe745f42ace3e201ef6f4
> >>
> >>   net/bridge/br_fdb.c | 28 ++++++++++++++++------------
> >>   1 file changed, 16 insertions(+), 12 deletions(-)
> >>
> >
> > +CC Ido
> >
> > Oh you took care of ->used as well, even better. Thanks!
> > Acked-by: Nikolay Aleksandrov <razor@blackwall.org>
> >
>
> Sorry, I forgot about br_input.c: br_handle_frame_finish()
> use of ->used:
> ...
>                  if (now != dst->used)
>                          dst->used = now;
> ...
>
> That will need annotations as well.

No worries, I will add this in V3 tomorrow.

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

end of thread, other threads:[~2026-01-07 10:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-07  8:32 [PATCH v2 net] net: bridge: annotate data-races around fdb->{updated,used} Eric Dumazet
2026-01-07  9:00 ` Nikolay Aleksandrov
2026-01-07 10:43   ` Nikolay Aleksandrov
2026-01-07 10:46     ` Eric Dumazet

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