mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Julius Bairaktaris <julius@bairaktaris.de>
To: Andrew Lunn <andrew@lunn.ch>, Vladimir Oltean <olteanv@gmail.com>,
	netdev@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@kernel.org>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Willem de Bruijn" <willemb@google.com>,
	"Simon Horman" <horms@kernel.org>,
	"Alvin Šipraga" <alvin.sipraga@analog.com>,
	"Linus Walleij" <linusw@kernel.org>,
	"Florian Fainelli" <florian.fainelli@broadcom.com>,
	"Pawel Dembicki" <paweldembicki@gmail.com>,
	"Tobias Waldekranz" <tobias@waldekranz.com>,
	"Daniel Golle" <daniel@makrotopia.org>,
	"Russell King" <linux@armlinux.org.uk>,
	linux-kernel@vger.kernel.org
Subject: [PATCH net 3/6] net: dsa: tag_dsa: send a marked frame of an unbridged port from the CPU
Date: Sat, 28 Nov 2026 17:52:02 +0100	[thread overview]
Message-ID: <20261128165206.3248835-4-julius@bairaktaris.de> (raw)
In-Reply-To: <20261128165206.3248835-1-julius@bairaktaris.de>

dsa_xmit_ll() sends a frame with offload_fwd_mark as a FORWARD frame on
behalf of the port's bridge, with the bridge number taken from
dsa_port_bridge_num_get(). The port need not be in a bridge: a frame
received on a bridged port keeps the mark through a tc mirred redirect
or an nft netdev fwd to a standalone port of the same switch, and a
frame that the bridge marked can still be queued for a port that has
left the bridge. The bridge number is 0 then, and the frame goes out as
FORWARD from device dst->last_switch, port 0, instead of FROM_CPU to the
port. The function also reads dp->bridge twice, once for the number and
once for the device.

Read dp->bridge once, and send FORWARD only while the port is in a
bridge; otherwise the frame goes FROM_CPU to the port, as a frame
without the mark does.

Found by an LLM review (Claude), and reproduced in QEMU with dsa_loop.

Fixes: d82f8ab0d874 ("net: dsa: tag_dsa: offload the bridge forwarding process")
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
 net/dsa/tag_dsa.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/net/dsa/tag_dsa.c b/net/dsa/tag_dsa.c
index d5ffee35fbb..9a89508e451 100644
--- a/net/dsa/tag_dsa.c
+++ b/net/dsa/tag_dsa.c
@@ -130,13 +130,17 @@ static struct sk_buff *dsa_xmit_ll(struct sk_buff *skb, struct net_device *dev,
 				   u8 extra)
 {
 	struct dsa_port *dp = dsa_user_to_port(dev);
-	struct net_device *br_dev;
+	const struct dsa_bridge *bridge = READ_ONCE(dp->bridge);
+	struct net_device *br_dev = bridge ? bridge->dev : NULL;
 	u8 tag_dev, tag_port;
 	enum dsa_cmd cmd;
 	u8 *dsa_header;
 
-	if (skb->offload_fwd_mark) {
-		unsigned int bridge_num = dsa_port_bridge_num_get(dp);
+	/* A frame keeps offload_fwd_mark through a redirect to a standalone
+	 * port, and the port may have left its bridge since the bridge marked
+	 * the frame: only a bridged port forwards for its bridge.
+	 */
+	if (skb->offload_fwd_mark && bridge) {
 		struct dsa_switch_tree *dst = dp->ds->dst;
 
 		cmd = DSA_CMD_FORWARD;
@@ -145,7 +149,7 @@ static struct sk_buff *dsa_xmit_ll(struct sk_buff *skb, struct net_device *dev,
 		 * packets on behalf of a virtual switch device with an index
 		 * past the physical switches.
 		 */
-		tag_dev = dst->last_switch + bridge_num;
+		tag_dev = dst->last_switch + bridge->num;
 		tag_port = 0;
 	} else {
 		cmd = DSA_CMD_FROM_CPU;
@@ -153,8 +157,6 @@ static struct sk_buff *dsa_xmit_ll(struct sk_buff *skb, struct net_device *dev,
 		tag_port = dp->index;
 	}
 
-	br_dev = dsa_port_bridge_dev_get(dp);
-
 	/* If frame is already 802.1Q tagged, we can convert it to a DSA
 	 * tag (avoiding a memmove), but only if the port is standalone
 	 * (in which case we always send FROM_CPU) or if the port's
-- 
2.53.0


  parent reply	other threads:[~2026-11-28 16:52 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28 16:51 [PATCH net 0/6] net: dsa: offload_fwd_mark on unbridged ports, bridge numbers across switches Julius Bairaktaris
2026-11-28 16:52 ` [PATCH net 1/6] net: dsa: free struct dsa_bridge after an RCU grace period Julius Bairaktaris
2026-11-28 16:52 ` [PATCH net 2/6] net: dsa: tag_sja1105, tag_vsc73xx_8021q: read the bridge once in xmit Julius Bairaktaris
2026-12-06  3:54   ` willemb
2026-11-28 16:52 ` Julius Bairaktaris [this message]
2026-12-06  3:55   ` [PATCH net 3/6] net: dsa: tag_dsa: send a marked frame of an unbridged port from the CPU willemb
2026-11-28 16:52 ` [PATCH net 4/6] net: dsa: do not hand a switch a bridge number above its limit Julius Bairaktaris
2026-12-06  3:55   ` willemb
2026-11-28 16:52 ` [PATCH net 5/6] net: dsa: do not take a bridge number past the end of the bitmap Julius Bairaktaris
2026-11-28 16:52 ` [PATCH net 6/6] net: dsa: keep a bridge number while another tree uses it Julius Bairaktaris
2026-12-06  3:57   ` willemb
2026-12-06  3:54 ` [PATCH net 0/6] net: dsa: offload_fwd_mark on unbridged ports, bridge numbers across switches willemb
2026-12-06 10:06   ` Julius Bairaktaris

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261128165206.3248835-4-julius@bairaktaris.de \
    --to=julius@bairaktaris.de \
    --cc=alvin.sipraga@analog.com \
    --cc=andrew@lunn.ch \
    --cc=daniel@makrotopia.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=florian.fainelli@broadcom.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=paweldembicki@gmail.com \
    --cc=tobias@waldekranz.com \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®