Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2622668lqz; Wed, 3 Apr 2024 03:57:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWb35FLtAyxhYg+c28r2l0MtirD/MIGR0UgWSHewL+O/DMyHvrxE7Al89EC4U7Jc6TzMxT9SjK8jNxlge/skZSo91Ro7A2vNkSR6o7D7Q== X-Google-Smtp-Source: AGHT+IEytDuLDbyOAUo1Fao0gLh3+9m655ETGGYygoYRxN00fPx/eVZLAAIsoCKBE8ZmeWzCOuUH X-Received: by 2002:a17:906:b889:b0:a4e:101e:8a97 with SMTP id hb9-20020a170906b88900b00a4e101e8a97mr1501549ejb.65.1712141861691; Wed, 03 Apr 2024 03:57:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712141861; cv=pass; d=google.com; s=arc-20160816; b=jqL/6FKucaJ3Nio9WlV6GLOZ10o3Fns0ihxk3AXqtmALphQZMpyD8uoZhOhHvbv2rx Nk5qh3jBeOpLI6/sc/IrG8BX1cClqzU0E0YHOkVGM/t/hUG6DnOD21dpN2BV7eN+uB30 z7cWrB6wHQsFxzUgz4HZ1c97RDnubfEpLrX7qpMxbyecpidz+4vJa/sN6ojAjFQn1vaW Oira54Ch/DTv2B5x0/jdA9cWw6odL1McjAQdf1V6AIaZSmkRhe2R3Iq/SyCLKGMpW/51 010g45+oxRLntg0WmlpoD2xFi72TQi7U7epco8EThEvKDAorSuspH89dMmoHEnaMdvjc PuTg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Msw6XT9KO7yx5p18PrVia4phRl71DU7zcjCvgmrHJ+k=; fh=GDm+8eQp7V81Z9z4E8penvPz7TmF9/QPXj63lx/UTN8=; b=DMWhOVIDxq/QLp7jOXgQzc6GUuV8dvaJIKWrGMRdffJXzEadi5KFCFek1gbdFo4Es6 kDFKrYKDjFI96QHijjCQ7P7qcLDHQOwrxp5GiACMs2B22OlVi6RA2RBPPHany12r/I0e r2VJVK0WJak0F4G8m44GqBN4z53to5lElvnQkZ9PDmoKm/lhZ2YzLYTBXrAa50r+VZdw LwpaM96bQY26Y24DBqrceSGlBJOfGIKxUTLUct+25N49K7E5aaSK2H5Fnix8fYbqgU5n tnC7wrJFMidxrMLNEZNDkmJ3q1whHWyfRpueVuexjBb4eJNN5LGroVzGbGVBa3zOni9f 5kwA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="NI/LdOUp"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-129577-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-129577-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id qf12-20020a1709077f0c00b00a517992cd36si105624ejc.745.2024.04.03.03.57.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 03:57:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-129577-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="NI/LdOUp"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-129577-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-129577-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id DB34A1F2D385 for ; Wed, 3 Apr 2024 10:40:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1B5B71411D6; Wed, 3 Apr 2024 10:38:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NI/LdOUp" 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 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-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: 8bit 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 >=1), source_port and switch_id will be set to zeroes by dsa_8021q_rcv(), which might be problematic. But by checking for vbid >= 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(struct net_device *conduit, } EXPORT_SYMBOL_GPL(dsa_tag_8021q_find_port_by_vbid); +/** + * 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-initialized + * 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; if (skb_vlan_tag_present(skb)) { @@ -513,11 +525,25 @@ void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id, vid = tci & VLAN_VID_MASK; - *source_port = dsa_8021q_rx_source_port(vid); - *switch_id = dsa_8021q_rx_switch_id(vid); + tmp_source_port = dsa_8021q_rx_source_port(vid); + tmp_switch_id = dsa_8021q_rx_switch_id(vid); + tmp_vbid = 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 == 0 && *source_port == -1) + *source_port = tmp_source_port; + if (tmp_vbid == 0 && *switch_id == -1) + *switch_id = tmp_switch_id; if (vbid) - *vbid = dsa_tag_8021q_rx_vbid(vid); + *vbid = tmp_vbid; skb->priority = (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 *skb, /* 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 = -1, tmp_switch_id = -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 == 0 && source_port == -1) - source_port = tmp_source_port; - if (vbid == 0 && switch_id == -1) - switch_id = tmp_switch_id; - } else if (source_port == -1 && switch_id == -1) { + if (sja1105_skb_has_tag_8021q(skb)) + sja1105_vlan_rcv(skb, &source_port, &switch_id, &vbid, &vid); + else if (source_port == -1 && switch_id == -1) /* Packets with no source information have no chance of * getting accepted, drop them straight away. */ return NULL; - } if (source_port != -1 && switch_id != -1) skb->dev = dsa_conduit_find_user(netdev, switch_id, source_port); -- 2.34.1