Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.227 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796319851; b=o5dYMl90JeqftXgZRAbgYK+6qL1rWduslKdiZ7uUgXhgBTNnumAyxg0AUmwtNHk8kR0A fAVIXfE1PBnw0OApOYPuWQRvDhzq005kgZLH511gtpMlm8J7qzIi68PiFjC5iqNmuFrXS DGq2gq4N19j49SlMLqJHF66ECHKi0b1lKls/q/eSdee5hlG8xztpziQcK59rXP7jgacOY vN2ZQ+/O6/W4sDLGa3fkUkU1BCHgWLPeUAPuMua8zpKs42lhF2CTqP5ej5JHSPRigECGr 5cQz/VzWHDfa2evzTmsidpG/DttEFGNQ34niTRb3n7QoRvhb3ubrssPgXtOd9o0wLjQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796319851; h=DMARC-Filter:Received:X-Google-DKIM-Signature:X-Gm-Message-State: X-Gm-Gg:X-Received:Received:X-Relaying-Domain:X-CFilter-Loop:Received: DKIM-Signature:X-Received:X-Received:Received:Message-ID:Date: MIME-Version:User-Agent:Subject:To:Cc:References:Content-Language: From:Autocrypt:In-Reply-To:Content-Type:Content-Transfer-Encoding: X-DetectorID-Processed; bh=0a/uyZF48Jp6vZ7Xo+tB72ABs+gMsJDV8yflmgCbg9c=; b=iBXOX9XLNivOfmWdAHs5wNbj2mf+BLUgpt2tpCyE3gR7b4RtMb9DBSLPJaMQywB1VY/t 80f2e1cdusF3hM/Y8Z6o+6OPouuAlkkTcg+ujVzFgtkD7xMnn3caGSpJn5NAiQcJeCUK+ 8OpsidPM2IfCvLZfX0N3bNyLwzEuxj1QzL/mTAOY45PxXViWZziKjb8/G9Hf/mIV8CJ0Y z+hPh5l5gKocfOI3lYyVw/4KjLfb+UlCxqb6AUC2pCe2+z6jiaglHBgw9RdBz88eaqoGW /8pM5ksxSErqN4hmXE8hJ2pP9wsGu0afDv720LrGTZ2mXXjL9wcIl1GJ3EygtqBCdyA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=broadcom.com; spf=fail smtp.mailfrom=broadcom.com; dkim=pass header.d=broadcom.com header.i=@broadcom.com header.a=rsa-sha256 header.s=google header.b=diiYE3Ti; arc=none smtp.remote-ip=74.125.82.227 Received: from mail-dy1-f227.google.com (mail-dy1-f227.google.com [74.125.82.227]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5FA06606A32D for ; Thu, 3 Dec 2026 17:44:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5FA06606A32D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.a=rsa-sha256 header.s=google header.b=diiYE3Ti Received: by mail-dy1-f227.google.com with SMTP id 5a478bee46e88-386c336eab8so1489141eec.0 for ; Thu, 03 Dec 2026 09:44:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796319850; x=1796924650; h=content-transfer-encoding:content-type:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to:content-type; bh=0a/uyZF48Jp6vZ7Xo+tB72ABs+gMsJDV8yflmgCbg9c=; b=1nkub7C8u456WXlCgLbhIYdTcTYKy3WuopdptR/8UuEOcHT5NMFBqJLDdqEJYefSRt pM8/dy4RPj5afGC0XHMKjYm1x007Aas9s4AifieiRpbi9iHSO6N4EIIDb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with SMTP id 5a478bee46e88-38742cf7cfdmr2619520eec.5.1796319850100; Thu, 03 Dec 2026 09:44:10 -0800 (PST) Received: from smtp-us-east1-p01-i01-si01.dlp.protect.broadcom.com (address-144-49-247-123.dlp.protect.broadcom.com. [144.49.247.123]) by smtp-relay.gmail.com with ESMTPS id 5a478bee46e88-385617ecc68sm7077785eec.0.2026.12.03.09.44.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 Dec 2026 09:44:10 -0800 (PST) X-Relaying-Domain: broadcom.com X-CFilter-Loop: Reflected Received: by mail-ua1-f70.google.com with SMTP id a1e0cc1a2514c-990c957f129so1157379241.1 for ; Thu, 03 Dec 2026 09:44:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1796319849; x=1796924649; darn=lists.linux.dev; h=content-transfer-encoding:content-type:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=0a/uyZF48Jp6vZ7Xo+tB72ABs+gMsJDV8yflmgCbg9c=; b=diiYE3TigrYJvHo66+TIpCSf97tYLUmOdeAXZUFLsH3bBNz6bhDqwCY8cNy6FWrtz1 XMJyPogLBXGMT8EGZFPzq8mR2KsPsmCyHDqo915sKq04Vj16f4oPNHSDMW7M3XOBOZbw g0skwCcwju+X85HgtgHUJpQj7JZP2OnL2TXTQ= X-Received: by 2002:a05:6102:2c0b:b0:7ba:b5ea:c4b8 with SMTP id ada2fe7eead31-7dad662093dmr1931431137.1.1796319848733; Thu, 03 Dec 2026 09:44:08 -0800 (PST) X-Received: by 2002:a05:6102:2c0b:b0:7ba:b5ea:c4b8 with SMTP id ada2fe7eead31-7dad662093dmr1931409137.1.1796319848142; Thu, 03 Dec 2026 09:44:08 -0800 (PST) Received: from [10.67.48.245] ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-7d6e8265e55sm45204680137.11.2026.12.03.09.44.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 03 Dec 2026 09:44:07 -0800 (PST) Message-ID: <874e664d-1ff3-4ec6-b7d2-2027c92683b5@broadcom.com> Date: Thu, 3 Dec 2026 09:44:04 -0800 X-Mailing-List: bridge@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net-next v2 3/6] net: flow_offload: allow drivers to validate and invalidate cached paths To: Nikolay Aleksandrov , netdev@vger.kernel.org Cc: bridge@lists.linux.dev, coreteam@netfilter.org, davem@davemloft.net, edumazet@kernel.org, fw@strlen.de, horms@kernel.org, idosch@nvidia.com, kuba@kernel.org, netfilter-devel@vger.kernel.org, pabeni@redhat.com, pablo@netfilter.org, phil@nwl.cc, willemb@google.com References: <20261201182227.3990791-1-florian.fainelli@broadcom.com> <20261201182227.3990791-4-florian.fainelli@broadcom.com> <5419219c-f8f0-47b6-86ef-403691400eec@blackwall.org> Content-Language: en-US, fr-FR From: Florian Fainelli Autocrypt: addr=florian.fainelli@broadcom.com; keydata= xsBNBFPAG8ABCAC3EO02urEwipgbUNJ1r6oI2Vr/+uE389lSEShN2PmL3MVnzhViSAtrYxeT M0Txqn1tOWoIc4QUl6Ggqf5KP6FoRkCrgMMTnUAINsINYXK+3OLe7HjP10h2jDRX4Ajs4Ghs JrZOBru6rH0YrgAhr6O5gG7NE1jhly+EsOa2MpwOiXO4DE/YKZGuVe6Bh87WqmILs9KvnNrQ PcycQnYKTVpqE95d4M824M5cuRB6D1GrYovCsjA9uxo22kPdOoQRAu5gBBn3AdtALFyQj9DQ KQuc39/i/Kt6XLZ/RsBc6qLs+p+JnEuPJngTSfWvzGjpx0nkwCMi4yBb+xk7Hki4kEslABEB AAHNMEZsb3JpYW4gRmFpbmVsbGkgPGZsb3JpYW4uZmFpbmVsbGlAYnJvYWRjb20u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AQgABgUCU8AbwQAKCRCTYAaomC8PVQ0VCACWk3n+ obFABEp5Rg6Qvspi9kWXcwCcfZV41OIYWhXMoc57ssjCand5noZi8bKg0bxw4qsg+9cNgZ3P N/DFWcNKcAT3Z2/4fTnJqdJS//YcEhlr8uGs+ZWFcqAPbteFCM4dGDRruo69IrHfyyQGx16s CcFlrN8vD066RKevFepb/ml7eYEdN5SRALyEdQMKeCSf3mectdoECEqdF/MWpfWIYQ1hEfdm C2Kztm+h3Nkt9ZQLqc3wsPJZmbD9T0c9Rphfypgw/SfTf2/CHoYVkKqwUIzI59itl5Lze+R5 wDByhWHx2Ud2R7SudmT9XK1e0x7W7a5z11Q6vrzuED5nQvkhAAoJEIExtcQpvGagugcIAJd5 EYe6KM6Y6RvI6TvHp+QgbU5dxvjqSiSvam0Ms3QrLidCtantcGT2Wz/2PlbZqkoJxMQc40rb fXa4xQSvJYj0GWpadrDJUvUu3LEsunDCxdWrmbmwGRKqZraV2oG7YEddmDqOe0Xm/NxeSobc MIlnaE6V0U8f5zNHB7Y46yJjjYT/Ds1TJo3pvwevDWPvv6rdBeV07D9s43frUS6xYd1uFxHC 7dZYWJjZmyUf5evr1W1gCgwLXG0PEi9n3qmz1lelQ8lSocmvxBKtMbX/OKhAfuP/iIwnTsww 95A2SaPiQZA51NywV8OFgsN0ITl2PlZ4Tp9hHERDe6nQCsNI/Us= In-Reply-To: <5419219c-f8f0-47b6-86ef-403691400eec@blackwall.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-DetectorID-Processed: b00c1d49-9d2e-4205-b15f-d015386d3d5e On 12/2/26 01:33, Nikolay Aleksandrov wrote: > On 01/12/2026 20:22, Florian Fainelli wrote: >> A classifier can lack the mark, DSCP and output-interface context used >> to select its forwarding path. Provide optional owner validation and >> invalidation callbacks so an accelerator can validate the actual cached >> routes and Ethernet peers instead of treating a partial FIB lookup as >> proof that a software path is stale. >> >> Retain direct-path dst references for validating hardware consumers. >> Mark references held only for that purpose so packet lookup and GC keep >> their existing route-validation policy. Validate without creating a >> neighbour, and report missing or unsupported context as unavailable. For >> untagged bridge paths, resolve the bridge neighbour through the FDB and >> compare the physical transmit port. Return the reverse cached peer MAC >> when requested, so ingress guards use the owner's authoritative peer. >> Allow the bridge STP accessor under either RTNL or RCU for flow workers. >> >> Notify forwarding caches before FDB movement or deletion and after >> publication, including administrative dynamic entries hidden from >> switchdev. Track a generation per network namespace for flows traversing >> a bridge, sampled before path construction. Reject stale construction, >> packet lookup, GC and hardware admission. This also retires software- >> only and hardware-capacity fallback owners after a client moves, without >> walking flowtables while bridge learning holds its locks. Non-bridge >> flows keep their existing semantics. >> >> Invalidation marks the owning connection for teardown. Owners retain the >> cookie through an RCU grace period after DESTROY; drivers stop calling >> back when their rules are destroyed. Conntrack ownership remains held >> until asynchronous deletion has completed. >> >> Signed-off-by: Florian Fainelli >> --- >> Changes in v2: >>    - Validate the owner's cached route and neighbour without allocating >>      entries; missing context is unavailable validation rather than >> proof of >>      a stale software path. >>    - Resolve untagged bridge neighbours through the FDB and return the >>      authoritative reverse peer MAC for ingress guards. Permit the bridge >>      STP accessor under RCU as well as RTNL. >>    - Notify forwarding caches around FDB mutation and publication. >> Track a >>      per-network-namespace generation for bridge paths so software- >> only and >>      capacity-fallback owners also retire on moves, deletion and aging. >>      Preserve non-bridge cache semantics. >> >>   include/net/flow_offload.h            |  14 +++ >>   include/net/netevent.h                |   1 + >>   include/net/netfilter/nf_flow_table.h |  13 ++- >>   include/net/netns/flow_table.h        |   3 + >>   net/bridge/br_fdb.c                   |  26 ++++- >>   net/bridge/br_stp.c                   |   7 +- >>   net/netfilter/nf_flow_table_core.c    |  57 ++++++++++- >>   net/netfilter/nf_flow_table_offload.c | 139 ++++++++++++++++++++++++++ >>   net/netfilter/nf_flow_table_path.c    |   8 ++ >>   net/netfilter/nft_flow_offload.c      |   6 +- >>   10 files changed, 257 insertions(+), 17 deletions(-) >> > > > In general I'm not a fan of sprinkling a new notification around the > bridge, > I've left a few comments and a potential alternative that is more > contained, but > at the very least if a new notification mechanism is at all needed > (which I'm yet > not convinced of) I think the scope should be per-bridge instead of > netns-global. Agreed. I've taken the per-flow GC approach you suggested and removed the new notification mechanism entirely in the next iteration. > As it stands any FDB change in the netns (learning, aging) invalidates > all bridged flows, including software only flowtables. Yes, that was unnecessarily broad. The revised implementation checks each flow's cached bridge destination and retires it when that path becomes stale. Changes involving another MAC or another bridge leave the flow cached. > > More below. > >> diff --git a/include/net/flow_offload.h b/include/net/flow_offload.h >> index 70a02ee143080..ab5c0677debb4 100644 >> --- a/include/net/flow_offload.h >> +++ b/include/net/flow_offload.h >> @@ -697,6 +697,20 @@ struct flow_cls_offload { >>       bool use_act_stats; >>       unsigned long cookie; >>       struct flow_rule *rule; >> +    /* Optional owner notification when a rule no longer represents >> the path. >> +     * Call under RCU; the owner retains the cookie and callback until a >> +     * grace period after DESTROY. Drivers must stop new calls at >> DESTROY. >> +     * The callback must not sleep or call back into the offload driver. >> +     */ >> +    void (*invalidate)(unsigned long cookie); >> +    /* Optional cached-path validation, called under RCU during REPLACE. >> +     * Return 0 for a valid path, -ESTALE for a demonstrably stale path, >> +     * or -EOPNOTSUPP when validation is unavailable. Do not sleep or >> +     * call back into the driver. The callback does not invalidate >> its owner. >> +     * If ingress_mac is non-NULL, also return the peer MAC from the >> cached >> +     * reverse Ethernet path, or -EOPNOTSUPP if it is unavailable. >> +     */ >> +    int (*validate)(unsigned long cookie, u8 *ingress_mac); >>       struct flow_stats stats; >>       u32 classid; >>   }; >> diff --git a/include/net/netevent.h b/include/net/netevent.h >> index 1be3757a8b7f0..68258accc9eab 100644 >> --- a/include/net/netevent.h >> +++ b/include/net/netevent.h >> @@ -30,6 +30,7 @@ enum netevent_notif_type { >>       NETEVENT_IPV4_MPATH_HASH_UPDATE, /* arg is struct net ptr */ >>       NETEVENT_IPV6_MPATH_HASH_UPDATE, /* arg is struct net ptr */ >>       NETEVENT_IPV4_FWD_UPDATE_PRIORITY_UPDATE, /* arg is struct net >> ptr */ >> +    NETEVENT_BRIDGE_FDB_UPDATE, /* arg is the bridge net_device ptr */ >>   }; > > The netevent chain is global and shared by all event types so each fdb > change now walks every registered netevent listener (mlx5 representors, > mlxsw, cxgb4, rdma cm and so on) from the learning path in softirq and > under br->hash_lock. The event carries no information about the entry, > so it is only usable as a gen bump for this one consumer. I've removed NETEVENT_BRIDGE_FDB_UPDATE and all its call sites. There is no longer a notifier-chain traversal from bridge learning, publication or deletion. br_fdb.c and the netevent header are unchanged from the base. > > Could the bridge keep the generation itself or could the flowtable > revalidate the bridge hop per flow instead of adding a global event? Yes, the flowtable now revalidates the bridge hop per flow. Software bridge caches retain validation-only route references, allowing the check to use their cached bridge destination MAC and physical egress. This also covers software-only and hardware-capacity fallback owners without introducing bridge generation state. > > nf_flow_offload_bridge_path added later in this patch already resolves > the current FDB port through dev_fill_forward_path under RCU and > compares it with tuple->out.ifidx. Could that same per flow check be run > from nf_flow_offload_gc_step for NF_FLOW_BRIDGE flows? That would only > retire the flows whose entry actually moved or disappeared, needs no > bridge changes and the staleness window would be the GC interval which > hardware flows already have with this patch. That's the approach I've implemented. GC reuses the bridge-path resolver under RCU and compares the current path against the cached egress and router MAC. Construction and pending hardware admission also recheck the path; packet lookup does not acquire a new FDB check. The recovery follows GC and queued hardware deletion, and full owner release can require a further GC pass. I've documented that asynchronous window. On BCM53012 the measured full owner release took approximately 903 ms for a software-cache move and 1440 ms for a hardware-to-software move. > > > In case the event stays could it at least be gated by a static key that the > flowtable enables only while a flowtable exists so systems without > flowtables do not pay for it? The event is gone, so no static key is needed and systems without flowtables incur no new bridge-learning overhead. > >>   int register_netevent_notifier(struct notifier_block *nb); >> diff --git a/include/net/netfilter/nf_flow_table.h b/include/net/ >> netfilter/nf_flow_table.h >> index 5b22d31cb1407..c9dcd9bc8d3d3 100644 >> --- a/include/net/netfilter/nf_flow_table.h >> +++ b/include/net/netfilter/nf_flow_table.h >> @@ -154,7 +154,8 @@ struct flow_offload_tuple { >>                       encap_num:2, >>                       needs_gso_segment:1, >>                       tun_num:2, >> -                    in_vlan_ingress:2; >> +                    in_vlan_ingress:2, >> +                    dst_validation_only:1; >>       u16                mtu; >>       u32                dst_cookie; >>       struct dst_entry        *dst_cache; >> @@ -190,6 +191,7 @@ enum nf_flow_flags { >>       NF_FLOW_HW_DEAD, >>       NF_FLOW_HW_BIDIRECTIONAL, >>       NF_FLOW_HW_ESTABLISHED, >> +    NF_FLOW_BRIDGE, >>   }; >>   enum flow_offload_type { >> @@ -203,6 +205,7 @@ struct flow_offload { >>       unsigned long                flags; >>       u16                    type; >>       u32                    timeout; >> +    u32                    bridge_genid; >>       struct rcu_head                rcu_head; >>   }; >> @@ -210,6 +213,7 @@ struct flow_offload { >>   #define nf_flowtable_time_stamp    (u32)jiffies >>   unsigned long flow_offload_get_timeout(struct flow_offload *flow); >> +bool nf_flow_bridge_stale(const struct flow_offload *flow); >>   static inline __s32 nf_flow_timeout_delta(unsigned int timeout) >>   { >> @@ -217,6 +221,8 @@ static inline __s32 nf_flow_timeout_delta(unsigned >> int timeout) >>   } >>   struct nf_flow_route { >> +    u32 bridge_genid; >> +    bool uses_bridge; >>       struct { >>           struct dst_entry        *dst; >>           struct { >> @@ -305,7 +311,7 @@ nf_flow_table_offload_del_cb(struct nf_flowtable >> *flow_table, >>   } >>   void flow_offload_route_init(struct flow_offload *flow, >> -                 struct nf_flow_route *route); >> +                 struct nf_flow_route *route, bool keep_dst); >>   int flow_offload_add(struct nf_flowtable *flow_table, struct >> flow_offload *flow); >>   void flow_offload_refresh(struct nf_flowtable *flow_table, >> @@ -313,7 +319,8 @@ void flow_offload_refresh(struct nf_flowtable >> *flow_table, >>   static inline bool nf_flow_dst_check(struct flow_offload_tuple *tuple) >>   { >> -    if (!tuple->dst_cache) >> +    /* A driver-only reference must not change direct-path/GC >> semantics. */ >> +    if (!tuple->dst_cache || tuple->dst_validation_only) >>           return true; >>       return dst_check(tuple->dst_cache, tuple->dst_cookie); >> diff --git a/include/net/netns/flow_table.h b/include/net/netns/ >> flow_table.h >> index 1c5fc657e2675..b286b23116ac1 100644 >> --- a/include/net/netns/flow_table.h >> +++ b/include/net/netns/flow_table.h >> @@ -2,6 +2,8 @@ >>   #ifndef __NETNS_FLOW_TABLE_H >>   #define __NETNS_FLOW_TABLE_H >> +#include >> + >>   struct nf_flow_table_stat { >>       unsigned int count_wq_add; >>       unsigned int count_wq_del; >> @@ -10,5 +12,6 @@ struct nf_flow_table_stat { >>   struct netns_ft { >>       struct nf_flow_table_stat __percpu *stat; >> +    atomic_t bridge_genid; >>   }; >>   #endif >> diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c >> index b601245ad9239..922c34fdfecd4 100644 >> --- a/net/bridge/br_fdb.c >> +++ b/net/bridge/br_fdb.c >> @@ -20,6 +20,7 @@ >>   #include >>   #include >>   #include >> +#include >>   #include >>   #include >>   #include "br_private.h" >> @@ -174,6 +175,15 @@ static inline size_t fdb_nlmsg_size(void) >>           + nla_total_size(sizeof(u8)); /* NFEA_ACTIVITY_NOTIFY */ >>   } >> +/* Forwarding caches must also observe FDB changes which are >> intentionally >> + * hidden from switchdev, such as software-only administrative entries. >> + * Notify before changing an existing destination and after publication. >> + */ >> +static void fdb_notify_cache(struct net_bridge *br) >> +{ >> +    call_netevent_notifiers(NETEVENT_BRIDGE_FDB_UPDATE, br->dev); >> +} >> + >>   static void fdb_notify(struct net_bridge *br, >>                  const struct net_bridge_fdb_entry *fdb, int type, >>                  bool swdev_notify) >> @@ -182,6 +192,7 @@ static void fdb_notify(struct net_bridge *br, >>       struct sk_buff *skb; >>       int err = -ENOBUFS; >> +    fdb_notify_cache(br); >>       if (swdev_notify) >>           br_switchdev_fdb_notify(br, fdb, type); >> @@ -315,6 +326,7 @@ static void fdb_del_hw_addr(struct net_bridge *br, >> const unsigned char *addr) >>   static void fdb_delete(struct net_bridge *br, struct >> net_bridge_fdb_entry *f, >>                  bool swdev_notify) >>   { >> +    fdb_notify_cache(br); >>       trace_fdb_delete(br, f, br_fdb_dst_port(f)); > > fdb_delete already ends with fdb_notify(br, f, RTM_DELNEIGH), > which now also calls fdb_notify_cache so each deletion bumps the > generation twice. > >>       if (test_bit(BR_FDB_STATIC, &f->flags)) >> @@ -350,8 +362,10 @@ static void fdb_delete_local(struct net_bridge *br, >>           vg = nbp_vlan_group(op); >>           if (op != p && ether_addr_equal(op->dev->dev_addr, addr) && >>               (!vid || br_vlan_find(vg, vid))) { >> +            fdb_notify_cache(br); >>               br_fdb_dst_write(f, br_port_to_dst(op)); >>               clear_bit(BR_FDB_ADDED_BY_USER, &f->flags); >> +            fdb_notify_cache(br); >>               return; >>           } >>       } >> @@ -361,8 +375,10 @@ static void fdb_delete_local(struct net_bridge *br, >>       /* Maybe bridge device has same hw addr? */ >>       if (p && ether_addr_equal(br->dev->dev_addr, addr) && >>           (!vid || (v && br_vlan_should_use(v)))) { >> +        fdb_notify_cache(br); >>           br_fdb_dst_write(f, br_port_to_dst(NULL)); >>           clear_bit(BR_FDB_ADDED_BY_USER, &f->flags); >> +        fdb_notify_cache(br); >>           return; >>       } >> @@ -409,6 +425,7 @@ static struct net_bridge_fdb_entry >> *fdb_create(struct net_bridge *br, >>           return NULL; >>       memcpy(fdb->key.addr.addr, addr, ETH_ALEN); >> +    fdb_notify_cache(br); >>       br_fdb_dst_write(fdb, dst); > > The entry isn't published yet at this point so nothing can have > resolved a path through it. Is this notification needed at all? > All callers of fdb_create follow it with fdb_notify which bumps > the generation again. > >>       fdb->key.vlan_id = vid; >>       fdb->flags = flags; >> @@ -1030,6 +1047,7 @@ static void __fdb_update(struct net_bridge *br, >>                 !test_bit(BR_FDB_STICKY, &fdb->flags)))) { >>           if (source != old_port) { >>               br_switchdev_fdb_notify(br, fdb, RTM_DELNEIGH); >> +            fdb_notify_cache(br); >>               br_fdb_dst_write(fdb, dst); >>               fdb_modified = true; >>               /* take over HW learned entry */ >> @@ -1194,7 +1212,7 @@ static bool fdb_handle_notify(struct >> net_bridge_fdb_entry *fdb, u8 notify) >>       return modified; >>   } >> -static bool fdb_update_dst(struct net_bridge_fdb_entry *fdb, >> +static bool fdb_update_dst(struct net_bridge *br, struct >> net_bridge_fdb_entry *fdb, >>                  struct net_bridge_dst old_dst, >>                  struct net_bridge_dst dst) >>   { >> @@ -1205,7 +1223,7 @@ static bool fdb_update_dst(struct >> net_bridge_fdb_entry *fdb, >>           br_fdb_dst_replace(fdb, old_dst, dst); >>           return false; >>       } >> - >> +    fdb_notify_cache(br); >>       br_fdb_dst_write(fdb, dst); >>       return true; >>   } >> @@ -1263,7 +1281,7 @@ static int fdb_add_entry(struct net_bridge *br, >> struct net_bridge_dst dst, >>               return -EEXIST; >>           old_dst = br_fdb_dst_read(fdb); >> -        modified = fdb_update_dst(fdb, old_dst, dst); >> +        modified = fdb_update_dst(br, fdb, old_dst, dst); >>           set_bit(BR_FDB_ADDED_BY_USER, &fdb->flags); >>           if (test_and_clear_bit(BR_FDB_DYNAMIC_LEARNED, &fdb->flags)) >> @@ -1644,7 +1662,7 @@ int br_fdb_external_learn_add(struct net_bridge >> *br, struct net_bridge_port *p, >>           WRITE_ONCE(fdb->updated, jiffies); >> -        modified = fdb_update_dst(fdb, old_dst, dst); >> +        modified = fdb_update_dst(br, fdb, old_dst, dst); >>           if (test_and_set_bit(BR_FDB_ADDED_BY_EXT_LEARN, &fdb->flags)) { >>               /* Refresh entry */ >> diff --git a/net/bridge/br_stp.c b/net/bridge/br_stp.c >> index c7e7e924f1557..5717bf33c2667 100644 >> --- a/net/bridge/br_stp.c >> +++ b/net/bridge/br_stp.c >> @@ -70,17 +70,16 @@ void br_set_state(struct net_bridge_port *p, >> unsigned int state) >>       } >>   } >> +/* Caller holds RTNL or RCU. */ >>   u8 br_port_get_stp_state(const struct net_device *dev) >>   { >>       struct net_bridge_port *p; >> -    ASSERT_RTNL(); >> - >> -    p = br_port_get_rtnl(dev); >> +    p = br_port_get_rtnl_rcu(dev); >>       if (!p) >>           return BR_STATE_DISABLED; >> -    return p->state; >> +    return READ_ONCE(p->state); >>   } > > Nothing in this patch calls br_port_get_stp_state under rcu. Could > this go into the patch that adds the RCU user, or a separate bridge > patch? I've moved the accessor change into a separate bridge preparation patch immediately before the FA driver patch that introduces its RCU caller. > > Also br_set_state still writes the state with a plain store instead of > WRITE_ONCE. Fixed. br_set_state() now uses WRITE_ONCE(), paired with the accessor's READ_ONCE(). > > > The patch changes the bridge, netevent, the flow_offload API and the > netfilter > flowtable at once. Could it be split so the bridge and netevent parts > can be > reviewed on their own? I've split the original patch into three: the generic cached-owner validation/invalidation API, per-flow bridge cache revalidation with focused tests, and the standalone bridge STP accessor preparation. There is no netevent change remaining. Thank you! pw-bot: cr -- Florian