From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id B7A5B43E57 for ; Sat, 13 Apr 2024 14:55:37 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B158740294; Sat, 13 Apr 2024 14:55:37 +0200 (CEST) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2079.outbound.protection.outlook.com [40.107.237.79]) by mails.dpdk.org (Postfix) with ESMTP id 6BD2A400D6 for ; Sat, 13 Apr 2024 14:55:36 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RsVobjWMA1gie5okfnNQvi0Rwo1r9ycy9UvcTj3w3zcAuuNDDbhXGrle2HpF2Pfqlp+bV6Daiufb7WTGuV39YXdEash0iBzdbOqw7BBTILoobmc7+qFwi+qul/uxEcHLdghvMbaKCpUvwEM7TI8r4z6ooVwhesmr0y11dz0mNhWzrzltBFTybaDvtSeYUqK43OFTj5nTNIqVh4Ikq1x3vpQCYW/6Q51sp27ueVPPkvavWCV7HEcuuVCxN0rsxYz6asH/4cZwsv9yDaMpzb4i+rjJRd2eaCIDYlbksd+AFyAFWnTZFoaGPDQqfxiDb7qhdqN7cNdxKe5hWG/tM1qGZA== 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=bQwkSqKV+VrtAA2HPUQ0XH4Jn89dg4PLa27P4BT+nbc=; b=lieHza1qO+nW3R0h0fEKoBWIjenRcbXIq9V4a7ET/aVGK285w3mZDnPquyovGTKXFQJIb8211MTjh1NYxpp235JCGEpI3mDcbbFQJJW8MWOgTk9l2Uix36/Fq65yQprS4WEnvXpy6fEkrD4sBu6Z7CSWwWHzev1p3F6llWjSusDWj1ih7J+pYlI2Ipmf4Ubo2tYAGOHTlZh+9hSUpieaEOaS/B2+hFjZgVy/QgE6UkgOnASWv8VAeP083qCcj9yLd+UkFgxRFEz1W1JJWquCK9HGTuUvkAzhIlyZT3I0fFFb7FSAKG/1QGvX4FVrnXonYxKAVpFqFD+wB4wx/vIXuw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bQwkSqKV+VrtAA2HPUQ0XH4Jn89dg4PLa27P4BT+nbc=; b=TBTuNFwk55XqsMOpdObysTm+rEXn99IU/XDneNbREw1C822c+wA+7tM7W+6ljOOJntKZ8f6s1GifNZNrJba99s9alBCuMxjM7fnuYutfmfnbIl6b8oucHVphgY3ZOy9DQvKJN45Lzv/ccJWNppC/t4T4kiNclX7/aHjwu0RZPzXFyYt5jyNpsxW0TJd+Wuwlkif/sQZfMHSjnfR1CtGn4GSUFRThMAaneyFJwTlrAmPlfMEFqh/CDemdt8htmcoLNONOqC8InWel/uBTzWJMY1Ikktr6MZi1Nhe/7QuNvZW/u7ePMSQ9Wt+uYzI3zFYMSAZWg264Ta/jgI0gm3ia4g== Received: from SJ0PR03CA0044.namprd03.prod.outlook.com (2603:10b6:a03:33e::19) by DS7PR12MB6118.namprd12.prod.outlook.com (2603:10b6:8:9a::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.46; Sat, 13 Apr 2024 12:55:33 +0000 Received: from SJ1PEPF00001CDC.namprd05.prod.outlook.com (2603:10b6:a03:33e:cafe::ee) by SJ0PR03CA0044.outlook.office365.com (2603:10b6:a03:33e::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.26 via Frontend Transport; Sat, 13 Apr 2024 12:55:32 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by SJ1PEPF00001CDC.mail.protection.outlook.com (10.167.242.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.22 via Frontend Transport; Sat, 13 Apr 2024 12:55:32 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Sat, 13 Apr 2024 05:55:20 -0700 Received: from nvidia.com (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Sat, 13 Apr 2024 05:55:19 -0700 From: Xueming Li To: Dariusz Sosnowski CC: Suanming Mou , dpdk stable Subject: patch 'net/mlx5: fix VLAN handling in meter split' has been queued to stable release 23.11.1 Date: Sat, 13 Apr 2024 20:48:57 +0800 Message-ID: <20240413125005.725659-57-xuemingl@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240413125005.725659-1-xuemingl@nvidia.com> References: <20240305094757.439387-1-xuemingl@nvidia.com> <20240413125005.725659-1-xuemingl@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.126.230.35] X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00001CDC:EE_|DS7PR12MB6118:EE_ X-MS-Office365-Filtering-Correlation-Id: 9be430bd-7331-4a65-5a4c-08dc5bb90149 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QIxgvvrOcro2swhq5mcdOBNBCSWFNrqgwAl7eOSuBdjAO0uu5gT5l+3Mi1nYTfwf2n5Wk2NbI2zfib3Xw52BeDixIk0bik0dlCEv8/4hPAaQ47KcaKMCRzyjmYKSCWPCLExKwxUtcjM+kd1JR3KF3tCLBJjFuZNz5dVMeaDHXeT2jE5gxqe1O2f/kFs2Os9KerA3FekERPdYCJqGUF64fF7Fm/PaVncMj3SP00v7nSR9uLdMRocEglaoEF50N5KSY2JctfZ88VN2LzKFtIThE4e83k2xSn0KQrQhZ5e93FLitikorik/BhLxoYqNSVfc+WjeaYjj/sUGlpn1jvP68k2BrYgyqdXn7bx12IQMA0nFUB2PE2FmjN3PwN7hzN7D1ioYIV+QtqLDYHiggw3PLvqdPIoDwQ4B9S3lp4Wkv5t42jWe5n1VRDvfcmipHEaR5dZnDnOHgp5gGJ1F3hTdqSN9fZLb+ctAyTPx/+L7fTI7Ls9xPNApMWqcpZwgjXdcdPdz1G55NpvU06Y9Z1eCk/Oi2isZPtzdiHW0ydZtPvw21nAHQqVzkthfLUsiaxL5fBe1flHdMdhdaSK4QW0eLzM6T7NB14gzm9UuWU8Vi5RWBNXsj68TALhyAO6/LxMhNsik42QVvokGSwZ0ZFafgHgJ+dJmvR/3gu9eDIBI8VBeOnJr23A6/f4LIOO3BKIQEJQweTqU71C39HGkIp8UILwUppNC52vagEBdQ2A1owy1/F+PTvKcoBr4Jul+aNG7 X-Forefront-Antispam-Report: CIP:216.228.117.160; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge1.nvidia.com; CAT:NONE; SFS:(13230031)(1800799015)(376005)(36860700004)(82310400014); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Apr 2024 12:55:32.7960 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9be430bd-7331-4a65-5a4c-08dc5bb90149 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.160]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF00001CDC.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB6118 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Hi, FYI, your patch has been queued to stable release 23.11.1 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 04/15/24. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasing (ie: not only metadata diffs), please double check that the rebase was correctly done. Queued patches are on a temporary branch at: https://git.dpdk.org/dpdk-stable/log/?h=23.11-staging This queued commit can be viewed at: https://git.dpdk.org/dpdk-stable/commit/?h=23.11-staging&id=0198b11a1109696dff05344fde67fb7a4f7e26d7 Thanks. Xueming Li --- >From 0198b11a1109696dff05344fde67fb7a4f7e26d7 Mon Sep 17 00:00:00 2001 From: Dariusz Sosnowski Date: Tue, 27 Feb 2024 14:58:15 +0100 Subject: [PATCH] net/mlx5: fix VLAN handling in meter split Cc: Xueming Li [ upstream commit 5d2301a222d77e7bac3a085aa17f8ef7a3af7ffe ] On the attempt to create a flow rule with: - matching on REPRESENTED_PORT, - matching on outer VLAN tag, - matching on inner VLAN tag, - METER action, flow splitting mechanism for handling metering flows was causing memory corruption. It was assumed that suffix flow will have a single VLAN item (used for translation of OF_PUSH_VLAN/OF_SET_VLAN_VID actions), however during flow_meter_split_prep() 2 VLAN items were parsed. This caused the buffer overflow on allocated suffix flow item buffer. This patch fixes this overflow, by account for number of VLAN items in flow rule pattern when allocating items for suffix flow. Fixes: 50f576d657d7 ("net/mlx5: fix VLAN actions in meter") Signed-off-by: Dariusz Sosnowski Acked-by: Suanming Mou --- drivers/net/mlx5/mlx5_flow.c | 60 +++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index 3e31945f99..ee210549e7 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -5817,8 +5817,8 @@ flow_meter_split_prep(struct rte_eth_dev *dev, struct mlx5_rte_flow_item_tag *tag_item_spec; struct mlx5_rte_flow_item_tag *tag_item_mask; uint32_t tag_id = 0; - struct rte_flow_item *vlan_item_dst = NULL; - const struct rte_flow_item *vlan_item_src = NULL; + bool vlan_actions; + struct rte_flow_item *orig_sfx_items = sfx_items; const struct rte_flow_item *orig_items = items; struct rte_flow_action *hw_mtr_action; struct rte_flow_action *action_pre_head = NULL; @@ -5835,6 +5835,7 @@ flow_meter_split_prep(struct rte_eth_dev *dev, /* Prepare the suffix subflow items. */ tag_item = sfx_items++; + tag_item->type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_TAG; for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) { int item_type = items->type; @@ -5857,10 +5858,13 @@ flow_meter_split_prep(struct rte_eth_dev *dev, sfx_items++; break; case RTE_FLOW_ITEM_TYPE_VLAN: - /* Determine if copy vlan item below. */ - vlan_item_src = items; - vlan_item_dst = sfx_items++; - vlan_item_dst->type = RTE_FLOW_ITEM_TYPE_VOID; + /* + * Copy VLAN items in case VLAN actions are performed. + * If there are no VLAN actions, these items will be VOID. + */ + memcpy(sfx_items, items, sizeof(*sfx_items)); + sfx_items->type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_VLAN; + sfx_items++; break; default: break; @@ -5877,6 +5881,7 @@ flow_meter_split_prep(struct rte_eth_dev *dev, tag_action = actions_pre++; } /* Prepare the actions for prefix and suffix flow. */ + vlan_actions = false; for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) { struct rte_flow_action *action_cur = NULL; @@ -5907,16 +5912,7 @@ flow_meter_split_prep(struct rte_eth_dev *dev, break; case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN: case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID: - if (vlan_item_dst && vlan_item_src) { - memcpy(vlan_item_dst, vlan_item_src, - sizeof(*vlan_item_dst)); - /* - * Convert to internal match item, it is used - * for vlan push and set vid. - */ - vlan_item_dst->type = (enum rte_flow_item_type) - MLX5_RTE_FLOW_ITEM_TYPE_VLAN; - } + vlan_actions = true; break; case RTE_FLOW_ACTION_TYPE_COUNT: if (fm->def_policy) @@ -5931,6 +5927,14 @@ flow_meter_split_prep(struct rte_eth_dev *dev, actions_sfx++ : actions_pre++; memcpy(action_cur, actions, sizeof(struct rte_flow_action)); } + /* If there are no VLAN actions, convert VLAN items to VOID in suffix flow items. */ + if (!vlan_actions) { + struct rte_flow_item *it = orig_sfx_items; + + for (; it->type != RTE_FLOW_ITEM_TYPE_END; it++) + if (it->type == (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_VLAN) + it->type = RTE_FLOW_ITEM_TYPE_VOID; + } /* Add end action to the actions. */ actions_sfx->type = RTE_FLOW_ACTION_TYPE_END; if (priv->sh->meter_aso_en) { @@ -6020,8 +6024,6 @@ flow_meter_split_prep(struct rte_eth_dev *dev, tag_action->type = (enum rte_flow_action_type) MLX5_RTE_FLOW_ACTION_TYPE_TAG; tag_action->conf = set_tag; - tag_item->type = (enum rte_flow_item_type) - MLX5_RTE_FLOW_ITEM_TYPE_TAG; tag_item->spec = tag_item_spec; tag_item->last = NULL; tag_item->mask = tag_item_mask; @@ -6849,6 +6851,19 @@ flow_meter_create_drop_flow_with_org_pattern(struct rte_eth_dev *dev, &drop_split_info, error); } +static int +flow_count_vlan_items(const struct rte_flow_item items[]) +{ + int items_n = 0; + + for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) { + if (items->type == RTE_FLOW_ITEM_TYPE_VLAN || + items->type == (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_VLAN) + items_n++; + } + return items_n; +} + /** * The splitting for meter feature. * @@ -6904,6 +6919,7 @@ flow_create_split_meter(struct rte_eth_dev *dev, size_t act_size; size_t item_size; int actions_n = 0; + int vlan_items_n = 0; int ret = 0; if (priv->mtr_en) @@ -6963,9 +6979,11 @@ flow_create_split_meter(struct rte_eth_dev *dev, act_size = (sizeof(struct rte_flow_action) * (actions_n + METER_PREFIX_ACTION)) + sizeof(struct mlx5_rte_flow_action_set_tag); - /* Suffix items: tag, vlan, port id, end. */ -#define METER_SUFFIX_ITEM 4 - item_size = sizeof(struct rte_flow_item) * METER_SUFFIX_ITEM + + /* Flow can have multiple VLAN items. Account for them in suffix items. */ + vlan_items_n = flow_count_vlan_items(items); + /* Suffix items: tag, [vlans], port id, end. */ +#define METER_SUFFIX_ITEM 3 + item_size = sizeof(struct rte_flow_item) * (METER_SUFFIX_ITEM + vlan_items_n) + sizeof(struct mlx5_rte_flow_item_tag) * 2; sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size + item_size), 0, SOCKET_ID_ANY); -- 2.34.1 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2024-04-13 20:43:06.793788586 +0800 +++ 0057-net-mlx5-fix-VLAN-handling-in-meter-split.patch 2024-04-13 20:43:04.997753931 +0800 @@ -1 +1 @@ -From 5d2301a222d77e7bac3a085aa17f8ef7a3af7ffe Mon Sep 17 00:00:00 2001 +From 0198b11a1109696dff05344fde67fb7a4f7e26d7 Mon Sep 17 00:00:00 2001 @@ -4,0 +5,3 @@ +Cc: Xueming Li + +[ upstream commit 5d2301a222d77e7bac3a085aa17f8ef7a3af7ffe ] @@ -24 +26,0 @@ -Cc: stable@dpdk.org @@ -33 +35 @@ -index c7d70b8c7b..f8943a60be 100644 +index 3e31945f99..ee210549e7 100644 @@ -36 +38 @@ -@@ -5707,8 +5707,8 @@ flow_meter_split_prep(struct rte_eth_dev *dev, +@@ -5817,8 +5817,8 @@ flow_meter_split_prep(struct rte_eth_dev *dev, @@ -47 +49 @@ -@@ -5725,6 +5725,7 @@ flow_meter_split_prep(struct rte_eth_dev *dev, +@@ -5835,6 +5835,7 @@ flow_meter_split_prep(struct rte_eth_dev *dev, @@ -55 +57 @@ -@@ -5747,10 +5748,13 @@ flow_meter_split_prep(struct rte_eth_dev *dev, +@@ -5857,10 +5858,13 @@ flow_meter_split_prep(struct rte_eth_dev *dev, @@ -73 +75 @@ -@@ -5767,6 +5771,7 @@ flow_meter_split_prep(struct rte_eth_dev *dev, +@@ -5877,6 +5881,7 @@ flow_meter_split_prep(struct rte_eth_dev *dev, @@ -81 +83 @@ -@@ -5797,16 +5802,7 @@ flow_meter_split_prep(struct rte_eth_dev *dev, +@@ -5907,16 +5912,7 @@ flow_meter_split_prep(struct rte_eth_dev *dev, @@ -99 +101 @@ -@@ -5821,6 +5817,14 @@ flow_meter_split_prep(struct rte_eth_dev *dev, +@@ -5931,6 +5927,14 @@ flow_meter_split_prep(struct rte_eth_dev *dev, @@ -114 +116 @@ -@@ -5910,8 +5914,6 @@ flow_meter_split_prep(struct rte_eth_dev *dev, +@@ -6020,8 +6024,6 @@ flow_meter_split_prep(struct rte_eth_dev *dev, @@ -123 +125 @@ -@@ -6739,6 +6741,19 @@ flow_meter_create_drop_flow_with_org_pattern(struct rte_eth_dev *dev, +@@ -6849,6 +6851,19 @@ flow_meter_create_drop_flow_with_org_pattern(struct rte_eth_dev *dev, @@ -143 +145 @@ -@@ -6794,6 +6809,7 @@ flow_create_split_meter(struct rte_eth_dev *dev, +@@ -6904,6 +6919,7 @@ flow_create_split_meter(struct rte_eth_dev *dev, @@ -151 +153 @@ -@@ -6853,9 +6869,11 @@ flow_create_split_meter(struct rte_eth_dev *dev, +@@ -6963,9 +6979,11 @@ flow_create_split_meter(struct rte_eth_dev *dev,