From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.218.44 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796422848; b=zRu3vMuCQWZprvNG4OJsiJ0wEgEPXJ+HBRh5cZ87HFbVnvpQuIemfv3xQzIdHO/K+Tk3 mKZtLGcuuCnO2xnyI4vp22dF/4DKSwSZdV7ZvC2UFk6KThAR86IZDW9Ao7Ip9seyQ8rH+ +feCubHpVISBq17B0Jne9v0JX0T+QqSgLG5UjnPfjulDxtZNNSReDT48QYFXYo+8JL774 7l5EDYr8vHl90PpBLTPwKygLBkoEbJvcJTnME9VloGhkXuazT+TYXCEFk263xuZ83azVp 54t+AS7Y3+xJJ0vwnepfeYjePb/KDciQbRWh3MhgIKRWNtZzUgVtPoloIT7y50PQ4Tw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796422848; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=VObpt7JMEVFAdu6WyZlUoxKQlSxct2AboEa9GCsLHEE=; b=wRaPBrvYK4tzzaVmcdKm8ls9Gby2Eui+KX3aBf+axaEbCuDTCFRmpjGlrIMry3quZbXK Igi998V4Wv7Cm+REY3RFxC6JffupwXNqqLYOQYP/OlOkjXYcHSGvF62rLs7SkSxHMcdC0 yibsIi0zFrdFuKrY5W0GK5bNlkTQ6Q2gjszXPMtr3SfghBZ9hXvGfNBVofbp+wrPl2eZw Gs8B0L+9hVOZ0F/veaLBqPqDYpob36K371tXukDDV2omklvr04T3kFEOvdGc43lv5eTIY 7nXaPfb+IOwzg+WVvpsziq2RD8Ru0aRw6fqxAY/tPmUyf2i32LTALS/f1lBsgHFWhpw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=bairaktaris.de; spf=pass smtp.mailfrom=bairaktaris.de; dkim=pass header.d=bairaktaris.de header.i=@bairaktaris.de header.a=rsa-sha256 header.s=google header.b=CiRzvMel; arc=none smtp.remote-ip=209.85.218.44 Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (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 92A64606A330 for ; Fri, 4 Dec 2026 22:20:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 92A64606A330 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bairaktaris.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bairaktaris.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bairaktaris.de header.i=@bairaktaris.de header.a=rsa-sha256 header.s=google header.b=CiRzvMel Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-c5127c7abd5so265854966b.3 for ; Fri, 04 Dec 2026 14:20:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bairaktaris.de; s=google; t=1796422846; x=1797027646; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=VObpt7JMEVFAdu6WyZlUoxKQlSxct2AboEa9GCsLHEE=; b=CiRzvMeleIcVVVhWqKBa2IzLRGXBfEMWFR6PtQ+VSXANftgNN993O3pF0cm7DQrTo7 2j4I/qdVEJvCD+98c3TLoKJQSayKYMbOdV85LaH6Smlmkp3fJGhdfeN9uGrVKq17d7t8 qIVicTP1bAhzv+PUvcisKSYfpQ0eyG4e70Tzrzameoit5nC0P6ZwZ0uLTjdme6W7g5f8 glFfGcc4l347gQ9dd8ry4Gqog2WYuJ7TRTbLF9BXvxaWV5SiMotfGOFmPvqA62gOnhxk k36V4Dunrej7oPbQxfRgrVU4LrlO9wIOED1Mo5yRaNC4L8MP0tkdmubOTword1Gw5bkS eCWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796422846; x=1797027646; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=VObpt7JMEVFAdu6WyZlUoxKQlSxct2AboEa9GCsLHEE=; b=ab7+E56VcsLmI2RrpeF6ju9AYCfcBcr/2Y9rDZT2jQq+zXLAEHnX5bpfA7CFI4TwzU i3UOi86ji6H2hi4S1RaBgl3lPM+PKT+Qv6xDAryXXC5M5XZpDEdsXqy+SfeJnwyZtOwn MTejqoqLCtzLlYhC/+UA7pbR+SfexOv6pRx9UDA3XpYDpEgbTcad4pMPbkeuS8/wpsyY SAfHhbxH6WIAAjzedo6NYIUID4qu9mtffE3zReMNGhDjcunxQ0FtN/JNBMGauPjuxAMt YQQHhNY64t/ekpRT9hKyRJkhj1Nt3H9ujlp5WUoDjdtjZnbxovZfQvG76RiMlZmEaDg5 SzJg== X-Gm-Message-State: APuU4Z/SfZy0J+9SUHRpko/P1xWdVD7PdPVA33qjnW1+cbH2Fd3/Xl7R Y6woPr9fsySi527fOCTdw/jgJUKyRB8ulrKc1n92MePwySW6F5f1MvaQMMLHdZtOSw== X-Gm-Gg: AZFdTZcwnc5XfIlIKbfPefJcB5RKeOMsdxJqp5Mg7JxlbhTZyM6uj1FQeFTokuOUE7e 6xdp8IhnRlMvTQ4FNXQ/TJJaqVRV9Ieo1ImbHfx+S7e4Ll2I3b4YIFcUHQNdiTl5cMiEBm3QDK0 qOZnuYR60pEhEG6Q+KkwblDT+PBx1nNK2tb6+F+wiNK/dhTdUtaHLcct13mgoK6LKv0aaD3kAK3 GyvEyb04rAEORDNvKAg8WyGqKSn7KhAUCBZhMFnmP3CN4ULHXGsDTMf6xH79LOgof2WadjpmF5a j2b7KXARQLLeS8Yjj1gmM4dvDMpf4J+a4RqTJhu0ClRTvpb9+NUFQZi1aKBN/NRbWG6wexgeTzt JyqSdO2JjfdmRePNcmhnSBZNlXYtX40mUpB8Dywj3e9xWk4GeBNxh5F6ZXaTfjyKE7ShqS2kPZx JxIfSqA+nEUlXf6D2X7u/68Ws+a5Q7IT4GIXdDWR511p/tOzoFxRsohR+W3IMLlD2xt4k2FLbT5 UEFqmdAnJ7QK17ZFDEHisKMOttt9jlKnbu/4Enz3sqwBpfoTqkA6GNza/gOCHWGe0+iX/3WdcV5 /Z47uPaOS3Erg2exPHLyJHWlxcQNWOvYyuTjBuVpJdRCwycpYyziRlwXXmgHWthfUIMBsIZmk42 MIDa5TerenZ/DyxgK/RELSPUBZ3G92QnZDwBq0owOfOFLBeWiVSpFKnVSDUMICbHj4f+VJlu2zW lWMg49nYI9fzPFhGw8efo7zPbbd0ebHD6UvS315w54E6Vd+WbtSCA8+SKPMsGS9HmmxW2zXOUyj hUEuqPPTvKxvueNDZT/wmS1BVD7gdC+an0RjPRs0pV6IwQxa3iZfbycIdgmXGAEh6xXz3x4QQPG KCZ1CdRGbORvxXcSRSgyKAgDbxMK5C8ZNsMoAMos0w== X-Received: by 2002:a17:907:3e1a:b0:c52:1b7a:5e57 with SMTP id a640c23a62f3a-c5262002a6cmr226346866b.4.1796422845966; Fri, 04 Dec 2026 14:20:45 -0800 (PST) Received: from Desktop.tail070c67.ts.net (pd9513dea.dip0.t-ipconnect.de. [217.81.61.234]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c525b3ffac1sm170779166b.52.2026.12.04.14.20.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 14:20:45 -0800 (PST) From: Julius Bairaktaris To: Andrew Lunn , Vladimir Oltean Cc: netdev@vger.kernel.org, bridge@lists.linux.dev, "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Simon Horman , Nikolay Aleksandrov , Ido Schimmel , =?UTF-8?q?Alvin=20=C5=A0ipraga?= , Florian Fainelli , Tobias Waldekranz , Linus Walleij , Pawel Dembicki Subject: [PATCH net v3 1/3] net: dsa: do not run queued FDB events after the port left the bridge Date: Fri, 4 Dec 2026 23:20:43 +0100 Message-ID: <20261204222045.214014-2-julius@bairaktaris.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261204222045.214014-1-julius@bairaktaris.de> References: <20261204222045.214014-1-julius@bairaktaris.de> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit FDB events reach DSA from the atomic switchdev notifier and are handled from dsa_owq. The work builds the dsa_db from dp->bridge, which dsa_port_bridge_destroy() clears and frees when the port leaves the bridge or fails to join it. When switchdev_bridge_port_offload() fails in the FDB replay of dsa_port_bridge_join(), because dsa_user_fdb_event() could not allocate its work item, the entries replayed before the failure are still queued. The rollback clears dp->bridge, and the queued work dereferences it: KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007] Workqueue: dsa_ordered dsa_user_switchdev_event_work RIP: 0010:dsa_port_bridge_host_fdb_add+0x141/0x5c0 A bridge leave has the same problem for an event that the notifier queues after dsa_port_pre_bridge_leave() flushed the workqueue: nothing orders the dp->bridge check in dsa_user_fdb_event() against the clear, and on a switch unbind the work can also run after dsa_user_destroy() freed the port's net_device. The notifier and the taggers read dp->bridge->dev and ->num without locks while the bridge is freed. Clear dp->bridge, wait with synchronize_net(), flush the workqueue, and only then drop the reference and free the bridge. Nothing in flight can take a reference meanwhile. The refcount is only raised in dsa_port_bridge_create(), on a bridge that dsa_tree_bridge_find() returned, and both run in the join path under RTNL, which dsa_port_bridge_destroy() holds too. The paths without RTNL only read dp->bridge, and all of them are RCU readers: the switchdev notifier is called under rcu_read_lock() by atomic_notifier_call_chain() and by the FDB replay, and the taggers run in the RCU sections of the transmit and receive paths. synchronize_net() waits for them. The work a notifier queued is on dsa_owq by then, and the flush waits for it. The cost is one expedited RCU grace period, under RTNL, each time a port leaves a bridge. The work reads dp->bridge once and drops the event when the port has left; the FDB helpers take the bridge from it. The join rollback destroys the bridge before it tells the switches that the port left, as dsa_port_bridge_leave() does, so a dropped event programs nothing after that. dsa_port_bridge_dev_get() and dsa_port_bridge_num_get() read the pointer once, and dsa_port_bridge_create() publishes it with smp_store_release(), so a reader that sees it also sees its fields. The other readers outside RTNL only test the pointer, with READ_ONCE(). Fixes: c26933639b54 ("net: dsa: request drivers to perform FDB isolation") Fixes: d3eed0e57d5d ("net: dsa: keep the bridge_dev and bridge_num as part of the same structure") Link: https://lore.kernel.org/all/179480421335.3136.15795220009190349154@kernel.org/ [1] Signed-off-by: Julius Bairaktaris --- The rollback oops was pointed out by the hosted Sashiko review of a DSA host FDB series [1]. In QEMU with KASAN, dsa_loop given FDB operations that take 15 ms, 40 static FDB entries to replay and the N-th allocation of "ip link set lan1 master br0" failing for N = 1 to 150, net oopses as above in 3 of 3 boots, and with this change in none of 4 boots. With the change, 2 to 5 host addresses per boot stay on the CPU port after those joins (5, 4, 5 and 2 more additions than deletions). They were added by replayed events that ran before the allocation failed: br_switchdev_port_offload() does not undo the part of the replay that succeeded, and this change does not alter that. v3: - The message says why no in-flight notification or tagger can take a reference to the bridge, and what the grace period costs, after Paolo Abeni's question on v1: https://lore.kernel.org/all/dfe749f5-83de-4802-bcff-7517ea6b7283@redhat.com/ - Code unchanged. Rebased on net e9d78fc6741a; the join sweep ran once more on it. v2: - The other readers of dp->bridge outside RTNL, dsa_port_to_bridge_port(), dsa_find_designated_bridge_port_by_vid(), dsa_default_offload_fwd_mark() and dsa_tag_8021q_find_port_by_vbid(), use READ_ONCE() (hosted Sashiko review of v1). - The comment in dsa_port_bridge_destroy() speaks of a tagger that read the bridge; a tagger that reads NULL is patch 3. v2: https://lore.kernel.org/all/20261128133503.3887987-2-julius@bairaktaris.de/ v1: https://lore.kernel.org/all/20261121185821.1471559-1-julius@bairaktaris.de/ include/net/dsa.h | 10 ++++++--- net/dsa/port.c | 50 ++++++++++++++++++++++++++++++--------------- net/dsa/port.h | 26 ++++++++++++----------- net/dsa/tag.h | 4 ++-- net/dsa/tag_8021q.c | 2 +- net/dsa/user.c | 25 ++++++++++++++++------- 6 files changed, 75 insertions(+), 42 deletions(-) diff --git a/include/net/dsa.h b/include/net/dsa.h index 5d12191b6f6f..47e2162f1d7d 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -758,7 +758,7 @@ static inline struct net_device *dsa_port_to_conduit(const struct dsa_port *dp) static inline struct net_device *dsa_port_to_bridge_port(const struct dsa_port *dp) { - if (!dp->bridge) + if (!READ_ONCE(dp->bridge)) return NULL; if (dp->lag) @@ -772,12 +772,16 @@ struct net_device *dsa_port_to_bridge_port(const struct dsa_port *dp) static inline struct net_device * dsa_port_bridge_dev_get(const struct dsa_port *dp) { - return dp->bridge ? dp->bridge->dev : NULL; + const struct dsa_bridge *bridge = READ_ONCE(dp->bridge); + + return bridge ? bridge->dev : NULL; } static inline unsigned int dsa_port_bridge_num_get(struct dsa_port *dp) { - return dp->bridge ? dp->bridge->num : 0; + const struct dsa_bridge *bridge = READ_ONCE(dp->bridge); + + return bridge ? bridge->num : 0; } static inline bool dsa_port_bridge_same(const struct dsa_port *a, diff --git a/net/dsa/port.c b/net/dsa/port.c index 1f5536c0dffc..e41d3639f0f9 100644 --- a/net/dsa/port.c +++ b/net/dsa/port.c @@ -427,7 +427,8 @@ static int dsa_port_bridge_create(struct dsa_port *dp, bridge = dsa_tree_bridge_find(ds->dst, br); if (bridge) { refcount_inc(&bridge->refcount); - dp->bridge = bridge; + /* Read without locks, see below */ + smp_store_release(&dp->bridge, bridge); return 0; } @@ -447,7 +448,8 @@ static int dsa_port_bridge_create(struct dsa_port *dp, return -EOPNOTSUPP; } - dp->bridge = bridge; + /* Read without locks from the switchdev notifiers and the taggers */ + smp_store_release(&dp->bridge, bridge); return 0; } @@ -457,7 +459,14 @@ static void dsa_port_bridge_destroy(struct dsa_port *dp, { struct dsa_bridge *bridge = dp->bridge; - dp->bridge = NULL; + WRITE_ONCE(dp->bridge, NULL); + + /* An FDB event from the atomic switchdev notifier that still sees the + * bridge can queue work for it, and a tagger that read it can still + * use it. Wait for them, then for the work they queued. + */ + synchronize_net(); + dsa_flush_workqueue(); if (!refcount_dec_and_test(&bridge->refcount)) return; @@ -528,7 +537,12 @@ int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br, &dsa_user_switchdev_blocking_notifier); dsa_flush_workqueue(); out_rollback_unbridge: + /* Drop the FDB events still queued from the replay before the + * switches are told that the port left + */ + dsa_port_bridge_destroy(dp, br); dsa_broadcast(DSA_NOTIFIER_BRIDGE_LEAVE, &info); + return err; out_rollback: dsa_port_bridge_destroy(dp, br); return err; @@ -973,8 +987,8 @@ int dsa_port_mtu_change(struct dsa_port *dp, int new_mtu) return dsa_port_notify(dp, DSA_NOTIFIER_MTU, &info); } -int dsa_port_fdb_add(struct dsa_port *dp, const unsigned char *addr, - u16 vid) +int dsa_port_fdb_add(struct dsa_port *dp, const struct dsa_bridge *bridge, + const unsigned char *addr, u16 vid) { struct dsa_notifier_fdb_info info = { .dp = dp, @@ -982,7 +996,7 @@ int dsa_port_fdb_add(struct dsa_port *dp, const unsigned char *addr, .vid = vid, .db = { .type = DSA_DB_BRIDGE, - .bridge = *dp->bridge, + .bridge = *bridge, }, }; @@ -996,8 +1010,8 @@ int dsa_port_fdb_add(struct dsa_port *dp, const unsigned char *addr, return dsa_port_notify(dp, DSA_NOTIFIER_FDB_ADD, &info); } -int dsa_port_fdb_del(struct dsa_port *dp, const unsigned char *addr, - u16 vid) +int dsa_port_fdb_del(struct dsa_port *dp, const struct dsa_bridge *bridge, + const unsigned char *addr, u16 vid) { struct dsa_notifier_fdb_info info = { .dp = dp, @@ -1005,7 +1019,7 @@ int dsa_port_fdb_del(struct dsa_port *dp, const unsigned char *addr, .vid = vid, .db = { .type = DSA_DB_BRIDGE, - .bridge = *dp->bridge, + .bridge = *bridge, }, }; @@ -1041,12 +1055,13 @@ int dsa_port_standalone_host_fdb_add(struct dsa_port *dp, } int dsa_port_bridge_host_fdb_add(struct dsa_port *dp, + const struct dsa_bridge *bridge, const unsigned char *addr, u16 vid) { struct net_device *conduit = dsa_port_to_conduit(dp); struct dsa_db db = { .type = DSA_DB_BRIDGE, - .bridge = *dp->bridge, + .bridge = *bridge, }; int err; @@ -1092,12 +1107,13 @@ int dsa_port_standalone_host_fdb_del(struct dsa_port *dp, } int dsa_port_bridge_host_fdb_del(struct dsa_port *dp, + const struct dsa_bridge *bridge, const unsigned char *addr, u16 vid) { struct net_device *conduit = dsa_port_to_conduit(dp); struct dsa_db db = { .type = DSA_DB_BRIDGE, - .bridge = *dp->bridge, + .bridge = *bridge, }; int err; @@ -1113,8 +1129,8 @@ int dsa_port_bridge_host_fdb_del(struct dsa_port *dp, return dsa_port_host_fdb_del(dp, addr, vid, db); } -int dsa_port_lag_fdb_add(struct dsa_port *dp, const unsigned char *addr, - u16 vid) +int dsa_port_lag_fdb_add(struct dsa_port *dp, const struct dsa_bridge *bridge, + const unsigned char *addr, u16 vid) { struct dsa_notifier_lag_fdb_info info = { .lag = dp->lag, @@ -1122,7 +1138,7 @@ int dsa_port_lag_fdb_add(struct dsa_port *dp, const unsigned char *addr, .vid = vid, .db = { .type = DSA_DB_BRIDGE, - .bridge = *dp->bridge, + .bridge = *bridge, }, }; @@ -1132,8 +1148,8 @@ int dsa_port_lag_fdb_add(struct dsa_port *dp, const unsigned char *addr, return dsa_port_notify(dp, DSA_NOTIFIER_LAG_FDB_ADD, &info); } -int dsa_port_lag_fdb_del(struct dsa_port *dp, const unsigned char *addr, - u16 vid) +int dsa_port_lag_fdb_del(struct dsa_port *dp, const struct dsa_bridge *bridge, + const unsigned char *addr, u16 vid) { struct dsa_notifier_lag_fdb_info info = { .lag = dp->lag, @@ -1141,7 +1157,7 @@ int dsa_port_lag_fdb_del(struct dsa_port *dp, const unsigned char *addr, .vid = vid, .db = { .type = DSA_DB_BRIDGE, - .bridge = *dp->bridge, + .bridge = *bridge, }, }; diff --git a/net/dsa/port.h b/net/dsa/port.h index 6bc3291573c0..e665baf7454a 100644 --- a/net/dsa/port.h +++ b/net/dsa/port.h @@ -46,22 +46,24 @@ int dsa_port_mst_enable(struct dsa_port *dp, bool on, int dsa_port_vlan_msti(struct dsa_port *dp, const struct switchdev_vlan_msti *msti); int dsa_port_mtu_change(struct dsa_port *dp, int new_mtu); -int dsa_port_fdb_add(struct dsa_port *dp, const unsigned char *addr, - u16 vid); -int dsa_port_fdb_del(struct dsa_port *dp, const unsigned char *addr, - u16 vid); +int dsa_port_fdb_add(struct dsa_port *dp, const struct dsa_bridge *bridge, + const unsigned char *addr, u16 vid); +int dsa_port_fdb_del(struct dsa_port *dp, const struct dsa_bridge *bridge, + const unsigned char *addr, u16 vid); int dsa_port_standalone_host_fdb_add(struct dsa_port *dp, const unsigned char *addr, u16 vid); int dsa_port_standalone_host_fdb_del(struct dsa_port *dp, const unsigned char *addr, u16 vid); -int dsa_port_bridge_host_fdb_add(struct dsa_port *dp, const unsigned char *addr, - u16 vid); -int dsa_port_bridge_host_fdb_del(struct dsa_port *dp, const unsigned char *addr, - u16 vid); -int dsa_port_lag_fdb_add(struct dsa_port *dp, const unsigned char *addr, - u16 vid); -int dsa_port_lag_fdb_del(struct dsa_port *dp, const unsigned char *addr, - u16 vid); +int dsa_port_bridge_host_fdb_add(struct dsa_port *dp, + const struct dsa_bridge *bridge, + const unsigned char *addr, u16 vid); +int dsa_port_bridge_host_fdb_del(struct dsa_port *dp, + const struct dsa_bridge *bridge, + const unsigned char *addr, u16 vid); +int dsa_port_lag_fdb_add(struct dsa_port *dp, const struct dsa_bridge *bridge, + const unsigned char *addr, u16 vid); +int dsa_port_lag_fdb_del(struct dsa_port *dp, const struct dsa_bridge *bridge, + const unsigned char *addr, u16 vid); int dsa_port_fdb_dump(struct dsa_port *dp, dsa_fdb_dump_cb_t *cb, void *data); int dsa_port_mdb_add(const struct dsa_port *dp, const struct switchdev_obj_port_mdb *mdb); diff --git a/net/dsa/tag.h b/net/dsa/tag.h index cf52283fe9df..0e1be1da4537 100644 --- a/net/dsa/tag.h +++ b/net/dsa/tag.h @@ -201,7 +201,7 @@ dsa_find_designated_bridge_port_by_vid(struct net_device *conduit, u16 vid) if (dp->type != DSA_PORT_TYPE_USER) continue; - if (!dp->bridge) + if (!READ_ONCE(dp->bridge)) continue; if (dp->stp_state != BR_STATE_LEARNING && @@ -238,7 +238,7 @@ static inline void dsa_default_offload_fwd_mark(struct sk_buff *skb) { struct dsa_port *dp = dsa_user_to_port(skb->dev); - skb->offload_fwd_mark = !!(dp->bridge); + skb->offload_fwd_mark = !!READ_ONCE(dp->bridge); } /* Helper for removing DSA header tags from packets in the RX path. diff --git a/net/dsa/tag_8021q.c b/net/dsa/tag_8021q.c index f91646e60246..de7e24f75505 100644 --- a/net/dsa/tag_8021q.c +++ b/net/dsa/tag_8021q.c @@ -482,7 +482,7 @@ dsa_tag_8021q_find_port_by_vbid(struct net_device *conduit, int vbid) return NULL; dsa_tree_for_each_user_port(dp, dst) { - if (!dp->bridge) + if (!READ_ONCE(dp->bridge)) continue; if (dp->stp_state != BR_STATE_LEARNING && diff --git a/net/dsa/user.c b/net/dsa/user.c index 041f9060c8ef..81f0d3901209 100644 --- a/net/dsa/user.c +++ b/net/dsa/user.c @@ -3646,6 +3646,7 @@ static void dsa_user_switchdev_event_work(struct work_struct *work) const unsigned char *addr = switchdev_work->addr; struct net_device *dev = switchdev_work->dev; u16 vid = switchdev_work->vid; + const struct dsa_bridge *bridge; struct dsa_switch *ds; struct dsa_port *dp; int err; @@ -3653,14 +3654,22 @@ static void dsa_user_switchdev_event_work(struct work_struct *work) dp = dsa_user_to_port(dev); ds = dp->ds; + /* Gone if the port left the bridge after the event was queued: + * dsa_port_bridge_destroy() clears it before it flushes the workqueue + */ + bridge = READ_ONCE(dp->bridge); + if (!bridge) + goto out; + switch (switchdev_work->event) { case SWITCHDEV_FDB_ADD_TO_DEVICE: if (switchdev_work->host_addr) - err = dsa_port_bridge_host_fdb_add(dp, addr, vid); + err = dsa_port_bridge_host_fdb_add(dp, bridge, addr, + vid); else if (dp->lag) - err = dsa_port_lag_fdb_add(dp, addr, vid); + err = dsa_port_lag_fdb_add(dp, bridge, addr, vid); else - err = dsa_port_fdb_add(dp, addr, vid); + err = dsa_port_fdb_add(dp, bridge, addr, vid); if (err) { dev_err(ds->dev, "port %d failed to add %pM vid %d to fdb: %d\n", @@ -3672,11 +3681,12 @@ static void dsa_user_switchdev_event_work(struct work_struct *work) case SWITCHDEV_FDB_DEL_TO_DEVICE: if (switchdev_work->host_addr) - err = dsa_port_bridge_host_fdb_del(dp, addr, vid); + err = dsa_port_bridge_host_fdb_del(dp, bridge, addr, + vid); else if (dp->lag) - err = dsa_port_lag_fdb_del(dp, addr, vid); + err = dsa_port_lag_fdb_del(dp, bridge, addr, vid); else - err = dsa_port_fdb_del(dp, addr, vid); + err = dsa_port_fdb_del(dp, bridge, addr, vid); if (err) { dev_err(ds->dev, "port %d failed to delete %pM vid %d from fdb: %d\n", @@ -3686,6 +3696,7 @@ static void dsa_user_switchdev_event_work(struct work_struct *work) break; } +out: kfree(switchdev_work); } @@ -3718,7 +3729,7 @@ static int dsa_user_fdb_event(struct net_device *dev, if (ctx && ctx != dp) return 0; - if (!dp->bridge) + if (!READ_ONCE(dp->bridge)) return 0; if (switchdev_fdb_is_dynamically_learned(fdb_info)) { -- 2.53.0