From patchwork Thu Apr 20 22:56:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13219272 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C81EFC7618E for ; Thu, 20 Apr 2023 22:57:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233393AbjDTW5C (ORCPT ); Thu, 20 Apr 2023 18:57:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233255AbjDTW4d (ORCPT ); Thu, 20 Apr 2023 18:56:33 -0400 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on060f.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0e::60f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D02966A5A; Thu, 20 Apr 2023 15:56:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iMNZ1gHo6LeDZhpNB4WdqqUzuD8VWWARBJTCZUXKDBom2HxpaRHYae1+QU1hEl6IeCqY67loHHfTLxlpA9lAfmvtxQ5ZkRXJ4Dvq7InU+IxDfO9/TB403KLwIfzf4eyPhXJ9y/g8Y9uw6ZmBKqXJ7oDDNbOOBJItJYKVYIXevpIrievRHipQAFuETDKKv6AZrxNynAqVMc/oOke7GiHwsnGyi6w+axhVSvoAibZ5efdmD1k+UbV/2dqkF8Ry2AFSZid9o5u+CDRPbpUNCdPtGeJKC5SnBvdHRv/B0W32XlhlSjHulKTfosaqZiO0fsKQHE9HwdBdTV/WxBdRbIMB+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=T/hd14NTERXsZeFZUPsIg4Ww7+KoT2dotGnFbCxnoxU=; b=dMH+GgAV3hXL7C/iLnj58r30I2SgiQTxb6jsYlbcWMzybInT81qHrnMR+SiZM4vKZMJPIbFwxuPDkl4MO6ywnWIOD3Q+H+bqXYgAhWZnxjnXYaiTQnI5edJ5CAr0Ru5Smjtt6CrKTfb7bt1C9CW1cXvVNhdK3SxdrzeuUUI7b3OwMOSaFKd6ofupMbhcFqTwNA1rRAuiZjcp9zq6DOHhzNL5ZTTQe5psdZ1TNfC2fmXBrrtqu9POipnmmbBsp8AWimRMxq/nMN7Ihp6JlLxgBwfcx3i/0BMwLqTycSbYf3DOqWz8vensPbXruhP+qLeDtCK6LgjZsHf64k3jT5ltOQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=T/hd14NTERXsZeFZUPsIg4Ww7+KoT2dotGnFbCxnoxU=; b=Z9WIsiwmtPltj7/B7TpuUqEnTlGA0lhQcAmenhXLQ08tTHxex4zFaUVSXmxHK4SvkCbmmEAwgTQCuoEb3vx4bA2ltwI+1X4LO/M3Q/J8+zS2LP0n697GE/t2AyidQ4L/4BsZU7r39FsHiAeMHsnqlLoSmbDEpE0oALcH7/mnPXU= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) by DB9PR04MB9497.eurprd04.prod.outlook.com (2603:10a6:10:361::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.22; Thu, 20 Apr 2023 22:56:19 +0000 Received: from AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::245a:9272:b30a:a21c]) by AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::245a:9272:b30a:a21c%3]) with mapi id 15.20.6319.022; Thu, 20 Apr 2023 22:56:18 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Florian Fainelli , linux-kernel@vger.kernel.org, Simon Horman Subject: [PATCH v2 net-next 9/9] net: dsa: tag_ocelot: call only the relevant portion of __skb_vlan_pop() on TX Date: Fri, 21 Apr 2023 01:56:01 +0300 Message-Id: <20230420225601.2358327-10-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230420225601.2358327-1-vladimir.oltean@nxp.com> References: <20230420225601.2358327-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM0PR03CA0088.eurprd03.prod.outlook.com (2603:10a6:208:69::29) To AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB6452:EE_|DB9PR04MB9497:EE_ X-MS-Office365-Filtering-Correlation-Id: f34c1c0f-2259-4237-7218-08db41f27404 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: i84X2GnrtaOzIzSyMCm9ITpGRTa0pn2wYZTuUIOtd5IXP4Tm7zacvydznkKE/SYiZWWsiVeLbyor8mqMWctgPzH5VdYy+TZ9lrEMS7yr9buYUWITJishiuC7nKSOJvosi4eeROg1vmhSfU0zOBSJCb9Wn+SQYDJoRxwEB+9MhAze0Lmm2KogtbeavZEs1AMZ2d5dhHiFEztAKga/m11AxwEfqQk17IMaMI++jdHQ78/Szmrup3XJyg26VqSX6A3jBr04zjRWvHcfYubSuxdZK4XX4s1sUAjAnhrpZnJksP48nhY4rK/5sQeU2ECKfh6XH0+4LYCyh6M9EWYnngchKvUrLSbfUL3p9Zf9uyC1qJesjHoe+IE53VtAEPpToHZubiUdUNLtpw3mRFsVFrB7q0spIvIlF/zIwtp0az5v9aSaaRIYtXT5SByRu7D43pdhLVPYrj0bwCQUKDRvj21derb15Sv/PkRLtp/h/ByqavGITVy3lcW5c3liwEf2tNzSMZUF2Hklym0a9W26AFbY11bd6NuaRw1nX/yVnroybhpKiT883DSPlihBPFKaYD14bHHVfZNNrVSzmN/eA5z8TDPdU/SKpe6axbYMwYi2rIQZI6WM2BVQr4g+Tmant8mo X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB6452.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(346002)(39860400002)(376002)(366004)(396003)(136003)(451199021)(83380400001)(86362001)(2616005)(6506007)(1076003)(26005)(6512007)(36756003)(52116002)(478600001)(6486002)(54906003)(6666004)(4326008)(66476007)(66946007)(66556008)(41300700001)(316002)(8936002)(8676002)(38100700002)(6916009)(186003)(44832011)(2906002)(5660300002)(38350700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 0s4dBz43+w+hVcPizI+mtqftpe3fvThvs8Y8zUwKN+a1hm7qbsK6OOliQi4Fjhm3JQNPt9n8z7Zc2G7dzuHaf5lW2IizWHhzNxBVeS6Z40vGjArNkAg2+XiPuPKAejK22fg+a1hmZSHMJQOoeR0Gr9MPGB00tl/kBcBVehcynVyG+0ByzXAL+LuYmdkqB8i295dBRVauJYn9DqKj0mx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oJs0sFmj4gHpGuKyEIGayJM+6Io65Xt+d5gugUjuBGpqkrgCAjmB5DLqgl6mLm6XmIAlxxG42qDNoiVpSw+NiEBKzCcwB91SvuuZmg/4Ak7e7jtIeTboNtFnJ/35TiNnK8UJguyHHZEXXsUIGDvV8wXbqzG953fGiWoi0hLDCV2vUCSu2sjkBfLUKgb6SQlE8Cc7Oa3Zw1xN2wtO70Dj8yQtzzxrgHO3M/aVEukWBxVbtcCzTw98Y9OlwICKLa2CKyDHaUMGmR6pKqARBeHrL8TZV2tBjS9KRyLTxLweDpcBJ4zTSEbxdWPkUP2BVAVhkaEt/OstwQS1V+EQ== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: f34c1c0f-2259-4237-7218-08db41f27404 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB6452.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2023 22:56:18.9062 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 0LaxCqmuqKDqeL4beTUtoKQ9xqCu9DcDNigRvbjBXkZXi+Vi+q+XgC9lZy+w/LKrj3RXsUxmyGwaR/SDu4yezg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB9497 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org ocelot_xmit_get_vlan_info() calls __skb_vlan_pop() as the most appropriate helper I could find which strips away a VLAN header. That's all I need it to do, but __skb_vlan_pop() has more logic, which will become incompatible with the future revert of commit 6d1ccff62780 ("net: reset mac header in dev_start_xmit()"). Namely, it performs a sanity check on skb_mac_header(), which will stop being set after the above revert, so it will return an error instead of removing the VLAN tag. ocelot_xmit_get_vlan_info() gets called in 2 circumstances: (1) the port is under a VLAN-aware bridge and the bridge sends VLAN-tagged packets (2) the port is under a VLAN-aware bridge and somebody else (an 8021q upper) sends VLAN-tagged packets (using a VID that isn't in the bridge vlan tables) In case (1), there is actually no bug to defend against, because br_dev_xmit() calls skb_reset_mac_header() and things continue to work. However, in case (2), illustrated using the commands below, it can be seen that our intervention is needed, since __skb_vlan_pop() complains: $ ip link add br0 type bridge vlan_filtering 1 && ip link set br0 up $ ip link set $eth master br0 && ip link set $eth up $ ip link add link $eth name $eth.100 type vlan id 100 && ip link set $eth.100 up $ ip addr add 192.168.100.1/24 dev $eth.100 I could fend off the checks in __skb_vlan_pop() with some skb_mac_header_was_set() calls, but seeing how few callers of __skb_vlan_pop() there are from TX paths, that seems rather unproductive. As an alternative solution, extract the bare minimum logic to strip a VLAN header, and move it to a new helper named vlan_remove_tag(), close to the definition of vlan_insert_tag(). Document it appropriately and make ocelot_xmit_get_vlan_info() call this smaller helper instead. Seeing that it doesn't appear illegal to test skb->protocol in the TX path, I guess it would be a good for vlan_remove_tag() to also absorb the vlan_set_encap_proto() function call. Signed-off-by: Vladimir Oltean Reviewed-by: Simon Horman Reviewed-by: Florian Fainelli Reviewed-by: Eric Dumazet --- include/linux/if_vlan.h | 21 +++++++++++++++++++++ net/core/skbuff.c | 8 +------- net/dsa/tag_ocelot.c | 2 +- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/include/linux/if_vlan.h b/include/linux/if_vlan.h index 3698f2b391cd..0f40f379d75c 100644 --- a/include/linux/if_vlan.h +++ b/include/linux/if_vlan.h @@ -685,6 +685,27 @@ static inline void vlan_set_encap_proto(struct sk_buff *skb, skb->protocol = htons(ETH_P_802_2); } +/** + * vlan_remove_tag - remove outer VLAN tag from payload + * @skb: skbuff to remove tag from + * @vlan_tci: buffer to store value + * + * Expects the skb to contain a VLAN tag in the payload, and to have skb->data + * pointing at the MAC header. + * + * Returns a new pointer to skb->data, or NULL on failure to pull. + */ +static inline void *vlan_remove_tag(struct sk_buff *skb, u16 *vlan_tci) +{ + struct vlan_hdr *vhdr = (struct vlan_hdr *)(skb->data + ETH_HLEN); + + *vlan_tci = ntohs(vhdr->h_vlan_TCI); + + memmove(skb->data + VLAN_HLEN, skb->data, 2 * ETH_ALEN); + vlan_set_encap_proto(skb, vhdr); + return __skb_pull(skb, VLAN_HLEN); +} + /** * skb_vlan_tagged - check if skb is vlan tagged. * @skb: skbuff to query diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 768f9d04911f..3fbf32897b8d 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -5943,7 +5943,6 @@ EXPORT_SYMBOL(skb_ensure_writable); */ int __skb_vlan_pop(struct sk_buff *skb, u16 *vlan_tci) { - struct vlan_hdr *vhdr; int offset = skb->data - skb_mac_header(skb); int err; @@ -5959,13 +5958,8 @@ int __skb_vlan_pop(struct sk_buff *skb, u16 *vlan_tci) skb_postpull_rcsum(skb, skb->data + (2 * ETH_ALEN), VLAN_HLEN); - vhdr = (struct vlan_hdr *)(skb->data + ETH_HLEN); - *vlan_tci = ntohs(vhdr->h_vlan_TCI); - - memmove(skb->data + VLAN_HLEN, skb->data, 2 * ETH_ALEN); - __skb_pull(skb, VLAN_HLEN); + vlan_remove_tag(skb, vlan_tci); - vlan_set_encap_proto(skb, vhdr); skb->mac_header += VLAN_HLEN; if (skb_network_offset(skb) < ETH_HLEN) diff --git a/net/dsa/tag_ocelot.c b/net/dsa/tag_ocelot.c index 73ee09de1a3a..20bf7074d5a6 100644 --- a/net/dsa/tag_ocelot.c +++ b/net/dsa/tag_ocelot.c @@ -30,7 +30,7 @@ static void ocelot_xmit_get_vlan_info(struct sk_buff *skb, struct dsa_port *dp, br_vlan_get_proto(br, &proto); if (ntohs(hdr->h_vlan_proto) == proto) { - __skb_vlan_pop(skb, &tci); + vlan_remove_tag(skb, &tci); *vlan_tci = tci; } else { rcu_read_lock();