From nobody Mon Feb 9 09:40:25 2026 Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 335CB146D5E; Wed, 3 Apr 2024 10:38:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712140698; cv=none; b=Pzs4L4X7rY8C0EJKnTodr+ggCM760lx7IwVjLfjM3A84fT+Zs2aqyLliGwevTKJN/eIwDS1zBvsCbxDF4oTWg/7TiWQ8kMuws77VCSrahNAS+OFmYCQKTPU3L0AjOHtc7jWzlg5Cl+/yEZCql31OZ1uX2ofritwGL4gLMM3WUqU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712140698; c=relaxed/simple; bh=GZjXmqsxTl886s48CtB/uBgr4u+1gG1/6bdKIonGezg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rpBmvaH1jbBFwJmS4xvr0UbuVxkQxlQXRq6urwAEtMhjB+eZSM7P6kbNc8iE+cUCXmQaaN5gVygmEkL2jcP/Bcmk48RrZgiFTsIl80fAkIERJrt8YxbZ1tBeX0/SHp5fvuiOBBhpiFJuL62pjkZE+t9+sP0om3OVaUQocIUmDNU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NI/LdOUp; arc=none smtp.client-ip=209.85.218.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NI/LdOUp" Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-a4a387ff7acso753948366b.2; Wed, 03 Apr 2024 03:38:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712140694; x=1712745494; 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; bh=Msw6XT9KO7yx5p18PrVia4phRl71DU7zcjCvgmrHJ+k=; b=NI/LdOUpCYDTyMoM4bGhRn9HHQGLeEwzKitVWmV+BLyXxjfq9HKG+VCwdX8qodEjup 9YDD37yU7Lwp+2WsNoze1i4nziu65gtYcJLinufeDuTEiV+s4Cu4rdWcCikJ9BXU4hyH ivCxPZbcDqbE6siEhoBatHkybYhPjvq9i6aFmLo2zz8mXBEdUZIILnLxRnv68zB1S30d k0cVmvWEh4Obaoo1NXiDa9rz53ZRc4KJY1Ubt9QPo1GoJcHvFR75d1cOhfmnQ+iv90q8 CIu0ZaxsQUWYj3xUZxfk3vOT9SaZ+3hjvBdWYpMPNYPJfqk6kzq3rEqKvlWxdx0CMUoB GsnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712140694; x=1712745494; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Msw6XT9KO7yx5p18PrVia4phRl71DU7zcjCvgmrHJ+k=; b=bVaiYH5uEE/2fDWuHeuXCWIG9zv3vHex92F99DxBKArbXb0A77kRDysWJosTq3gxf+ WxloVfg5AxzKPp/1XfBC8x679Ef8Z7BLEKxMT5mcskNgWMKswnAiBbPOC+CWZKmSFIxI tKAQxL72Km237C+te+WfvUhn/PcIK0qb1K9SVGid4qHFLkE9szRy2ZU5p8+dpXa9SXEk 5zpqfDUmoXEK20T8hP0BWi17uD/iZDt3l3Jflvd/ljWo83nZuoOZNoKHxqg1CXb27l2l 0xW07EP9IdIz2cT459/uSSjDQkECxU+rspl+B5245ziS2/LA3HoCYF73a3m1EyjrY2UV jYGQ== X-Forwarded-Encrypted: i=1; AJvYcCXwMh+YG7QXhlQopEIxUFJogropdmAK6bbfQNblYkNjt+2pjjLwCjAonRkYvub08YRNMD6iLj0Ls4mR2+sMCTEMUXE5OoJAEL3t3qnK X-Gm-Message-State: AOJu0YxqDHaKAuqro/5Rk1kftljFFiTIGShjHPjuFinqsSJK1/tz5d5v CN/0Axb3QF6iiPVjG2s/dcR/3/MGKoXh71+0qczvXh4kKUyIRUtgJUxokm8lhSE= X-Google-Smtp-Source: AGHT+IHWqya/PqeDmwRmotS0YDYDb/yYj0rY27pQLSyCl7ZKXU+UZUlVImdTPzmhSBwJB0tWtkigdQ== X-Received: by 2002:a17:906:1c4b:b0:a44:1fcf:9b97 with SMTP id l11-20020a1709061c4b00b00a441fcf9b97mr1531020ejg.24.1712140694239; Wed, 03 Apr 2024 03:38:14 -0700 (PDT) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id xd2-20020a170907078200b00a4e2e16805bsm6858169ejb.11.2024.04.03.03.38.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 03:38:13 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Linus Walleij , Simon Horman , Vladimir Oltean , Pawel Dembicki , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next v8 08/16] net: dsa: tag_sja1105: absorb logic for not overwriting precise info into dsa_8021q_rcv() Date: Wed, 3 Apr 2024 12:37:24 +0200 Message-Id: <20240403103734.3033398-9-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240403103734.3033398-1-paweldembicki@gmail.com> References: <20240403103734.3033398-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Vladimir Oltean In both sja1105_rcv() and sja1110_rcv(), we may have precise source port information coming from parallel hardware mechanisms, in addition to the tag_8021q header. Only sja1105_rcv() has extra logic to not overwrite that precise info with what's present in the VLAN tag. This is because sja1110_rcv() gets by, by having a reversed set of checks when assigning skb->dev. When the source port is imprecise (vbid >=3D1), source_port and switch_id will be set to zeroes by dsa_8021q_rcv(), which might be problematic. But by checking for vbid >=3D 1 first, sja1110_rcv() fends that off. We would like to make more code common between sja1105_rcv() and sja1110_rcv(), and for that, we need to make sure that sja1110_rcv() also goes through the precise source port preservation logic. Signed-off-by: Vladimir Oltean Signed-off-by: Pawel Dembicki --- v8, v7, v6: - resend only v5: - add missing SoB v4: - introduced patch net/dsa/tag_8021q.c | 32 +++++++++++++++++++++++++++++--- net/dsa/tag_sja1105.c | 23 +++-------------------- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/net/dsa/tag_8021q.c b/net/dsa/tag_8021q.c index 71b26ae6db39..3cb0293793a5 100644 --- a/net/dsa/tag_8021q.c +++ b/net/dsa/tag_8021q.c @@ -497,9 +497,21 @@ struct net_device *dsa_tag_8021q_find_port_by_vbid(str= uct net_device *conduit, } EXPORT_SYMBOL_GPL(dsa_tag_8021q_find_port_by_vbid); =20 +/** + * dsa_8021q_rcv - Decode source information from tag_8021q header + * @skb: RX socket buffer + * @source_port: pointer to storage for precise source port information. + * If this is known already from outside tag_8021q, the pre-initialized + * value is preserved. If not known, pass -1. + * @switch_id: similar to source_port. + * @vbid: pointer to storage for imprecise bridge ID. Must be pre-initiali= zed + * with -1. If a positive value is returned, the source_port and switch_id + * are invalid. + */ void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id, int *vbid) { + int tmp_source_port, tmp_switch_id, tmp_vbid; u16 vid, tci; =20 if (skb_vlan_tag_present(skb)) { @@ -513,11 +525,25 @@ void dsa_8021q_rcv(struct sk_buff *skb, int *source_p= ort, int *switch_id, =20 vid =3D tci & VLAN_VID_MASK; =20 - *source_port =3D dsa_8021q_rx_source_port(vid); - *switch_id =3D dsa_8021q_rx_switch_id(vid); + tmp_source_port =3D dsa_8021q_rx_source_port(vid); + tmp_switch_id =3D dsa_8021q_rx_switch_id(vid); + tmp_vbid =3D dsa_tag_8021q_rx_vbid(vid); + + /* Precise source port information is unknown when receiving from a + * VLAN-unaware bridging domain, and tmp_source_port and tmp_switch_id + * are zeroes in this case. + * + * Preserve the source information from hardware-specific mechanisms, + * if available. This allows us to not overwrite a valid source port + * and switch ID with less precise values. + */ + if (tmp_vbid =3D=3D 0 && *source_port =3D=3D -1) + *source_port =3D tmp_source_port; + if (tmp_vbid =3D=3D 0 && *switch_id =3D=3D -1) + *switch_id =3D tmp_switch_id; =20 if (vbid) - *vbid =3D dsa_tag_8021q_rx_vbid(vid); + *vbid =3D tmp_vbid; =20 skb->priority =3D (tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT; } diff --git a/net/dsa/tag_sja1105.c b/net/dsa/tag_sja1105.c index 1aba1d05c27a..48886d4b7e3e 100644 --- a/net/dsa/tag_sja1105.c +++ b/net/dsa/tag_sja1105.c @@ -524,30 +524,13 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *sk= b, /* Normal data plane traffic and link-local frames are tagged with * a tag_8021q VLAN which we have to strip */ - if (sja1105_skb_has_tag_8021q(skb)) { - int tmp_source_port =3D -1, tmp_switch_id =3D -1; - - sja1105_vlan_rcv(skb, &tmp_source_port, &tmp_switch_id, &vbid, - &vid); - /* Preserve the source information from the INCL_SRCPT option, - * if available. This allows us to not overwrite a valid source - * port and switch ID with zeroes when receiving link-local - * frames from a VLAN-unaware bridged port (non-zero vbid) or a - * VLAN-aware bridged port (non-zero vid). Furthermore, the - * tag_8021q source port information is only of trust when the - * vbid is 0 (precise port). Otherwise, tmp_source_port and - * tmp_switch_id will be zeroes. - */ - if (vbid =3D=3D 0 && source_port =3D=3D -1) - source_port =3D tmp_source_port; - if (vbid =3D=3D 0 && switch_id =3D=3D -1) - switch_id =3D tmp_switch_id; - } else if (source_port =3D=3D -1 && switch_id =3D=3D -1) { + if (sja1105_skb_has_tag_8021q(skb)) + sja1105_vlan_rcv(skb, &source_port, &switch_id, &vbid, &vid); + else if (source_port =3D=3D -1 && switch_id =3D=3D -1) /* Packets with no source information have no chance of * getting accepted, drop them straight away. */ return NULL; - } =20 if (source_port !=3D -1 && switch_id !=3D -1) skb->dev =3D dsa_conduit_find_user(netdev, switch_id, source_port); --=20 2.34.1