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 A2DAB45962 for ; Wed, 11 Sep 2024 18:06:17 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 998744325C; Wed, 11 Sep 2024 18:06:17 +0200 (CEST) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2066.outbound.protection.outlook.com [40.107.236.66]) by mails.dpdk.org (Postfix) with ESMTP id C04324029E; Wed, 11 Sep 2024 18:06:14 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=utQ8lKVAbDEJBrlTwdWrh3YRcCAKI+9u6zbe4JMnW3OtD//mUCNyLCfVPiwIju/9vU24+y5YInasbmwZP68cvGRe/YcOpQ2XGqXnFhnRvSZ3aLt8ukawC0unBM6W/LoiW7DvnsmgI8oqZHgTGmp89WlAMVO8mal5Z+mETnRNBgcliXIqs9pxUk6vsVkLKa9+7a+Q8/MqcQpGB5YElZxKAWD18B9NkDDcJvSu/T+8A8SjAGAWfFbFdh1Ooq8mUfuyrN16BJqksCldcwz+3oyOjOpmWEuX7cs9qJ9PxxfTwKFDW9/VesZEGgVZxMpULRAzE1DgsYGgq0GoGyXoR+omzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=Om94qSh5KjPCvYJlVWdyGfmtYpnq+GxiH4HKerrp1qE=; b=FZakHeQMzPamiA6Riy9BkM/jTM2iWtW55wZeTbatHvUz8ucROm4U+4e8/akoexmtzH2iC0ewWHLMiRpFsB8WnvArUXVJfpzeMCZn2z+Rdz0V+UMp/Odmf4M6jMocglTnXFGzLERvSkGHnV72+6/8QgVQFRM9DV5/E1iNZ7lJ3Dze5N6wQBwbFrEA7gEV+alPd3IJxeUhi0andUJbYNoE1iYCSWzVeWpRSLyUYsPXg8WZfVA3/jee21LYOF+hfwa+norClZuLVbwWgHsiBZq0FbysXadsY/6WQLMl8vPhsFlI/slyAbtOlYsLTxigDPXeDojrIdpPjJNYygoqyiQrQQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) 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=Om94qSh5KjPCvYJlVWdyGfmtYpnq+GxiH4HKerrp1qE=; b=oICyPF+pKlXxmRATdtb18CF/Hhs4e6WPWokvfXiTUsXwuvx1qeMkU2m3A/BldTVC3cnUT8SM3uQIRiIbesoyA7l3nL1GytuhA1xjaF12BFOaLPCF+glcZD630GkZFU7nySm11pHpUdt3Pp2oSPaZ3ndSE9yQEWDcQey6w0yUvxkZuJDjDkgvcf7C0luy3bX4z/MU7P7f8c2nYTlQxa3NbkqY9+lDbpnm2B+vKgV6oqe70WNVPhT1KsdBm6Ezska9YTc3+dSQmsWAaUjHVmrQ0/zLoy7ycjqzyNs8MBekqxlj0rNanmAXzeml3uZra9RWfnE+Hs9pQqeDnGcnnuXe/A== Received: from BYAPR06CA0031.namprd06.prod.outlook.com (2603:10b6:a03:d4::44) by PH7PR12MB6441.namprd12.prod.outlook.com (2603:10b6:510:1fb::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.24; Wed, 11 Sep 2024 16:06:06 +0000 Received: from SJ5PEPF000001D6.namprd05.prod.outlook.com (2603:10b6:a03:d4:cafe::f) by BYAPR06CA0031.outlook.office365.com (2603:10b6:a03:d4::44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.24 via Frontend Transport; Wed, 11 Sep 2024 16:06:04 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by SJ5PEPF000001D6.mail.protection.outlook.com (10.167.242.58) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Wed, 11 Sep 2024 16:06:04 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 11 Sep 2024 09:05:46 -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.1544.4; Wed, 11 Sep 2024 09:05:44 -0700 From: Viacheslav Ovsiienko To: CC: , , , , Subject: [PATCH 9/9] net/mlx5: fix flex item header length field translation Date: Wed, 11 Sep 2024 19:04:58 +0300 Message-ID: <20240911160458.524732-9-viacheslavo@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911160458.524732-1-viacheslavo@nvidia.com> References: <20240911160458.524732-1-viacheslavo@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.126.230.35] X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ5PEPF000001D6:EE_|PH7PR12MB6441:EE_ X-MS-Office365-Filtering-Correlation-Id: 4085a1ee-54d8-46bb-ad99-08dcd27ba397 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|1800799024|82310400026|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?x6BzFzLAuP07BfsPTgIPrhSjzoDXnwRzrIwArSHLZGWTyEGf1RQG36sv1h3a?= =?us-ascii?Q?m6Q3NVJgmO+5aKQ8xoFzWxScUo3yliC+jrfZaNNkik5DoBS0zc0eSJk8tOyL?= =?us-ascii?Q?Ae1Pc482caqr+XnfPPXLg2m2blUZZazCS36GQE2rtJZeSq9Y7ruixqxLnuk8?= =?us-ascii?Q?3i7KoM4nkmliIEjK1VEs7Qw+GlzTyH8DKC0vAjbJlByBfXIT/2eCobDj1tU7?= =?us-ascii?Q?PZ6qK61/f1tKOlLuZ0HWO+aQsGMlRUm/JWdDIfspm6tCAMEmxMXPZUOniTtf?= =?us-ascii?Q?9P6Epe0aZIk7GEdbiMV7sucjQbUPrfBZfeUDNmzoJ9aDVz/kDvuh2awX8l0V?= =?us-ascii?Q?jzsSP91LRy80ethNWEoDyQCT7rE2U7GyNME/7Xg1MPUgddkR3fKJW7VBgdRQ?= =?us-ascii?Q?KiyjXbL5P7KasYksIY16ZMrwt8powbqlsJriv97SIPnkNNsGjSN8Xcxexm/C?= =?us-ascii?Q?Tbf6PBLur4WK8KMO9UMEdMKhZW3xLAuRiEU8YSAzVBnGomAINwMfojwSKkjC?= =?us-ascii?Q?muFFbHGstN4OmKCcZOdXZX/KQC2ne5D4PDBAXOl/6dCb80rH9YY0dyuF/Uqw?= =?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-Antispam-Report: CIP:216.228.117.161; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge2.nvidia.com; CAT:NONE; SFS:(13230040)(36860700013)(1800799024)(82310400026)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2024 16:06:04.5954 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4085a1ee-54d8-46bb-ad99-08dcd27ba397 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.161]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SJ5PEPF000001D6.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6441 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 There are hardware imposed limitations on the header length field description for the mask and shift combinations in the FIELD_MODE_OFFSET mode. The patch updates: - parameter check for FIELD_MODE_OFFSET for the header length field - check whether length field crosses dword boundaries in header - correct mask extension to the hardware required width 6-bits - correct adjusting the mask left margin offset, preventing dword offset Fixes: b293e8e49d78 ("net/mlx5: translate flex item configuration") Cc: stable@dpdk.org Signed-off-by: Viacheslav Ovsiienko --- drivers/net/mlx5/mlx5_flow_flex.c | 120 ++++++++++++++++-------------- 1 file changed, 66 insertions(+), 54 deletions(-) diff --git a/drivers/net/mlx5/mlx5_flow_flex.c b/drivers/net/mlx5/mlx5_flow_flex.c index bf38643a23..afed16985a 100644 --- a/drivers/net/mlx5/mlx5_flow_flex.c +++ b/drivers/net/mlx5/mlx5_flow_flex.c @@ -449,12 +449,14 @@ mlx5_flex_release_index(struct rte_eth_dev *dev, * * shift mask * ------- --------------- - * 0 b111100 0x3C - * 1 b111110 0x3E - * 2 b111111 0x3F - * 3 b011111 0x1F - * 4 b001111 0x0F - * 5 b000111 0x07 + * 0 b11111100 0x3C + * 1 b01111110 0x3E + * 2 b00111111 0x3F + * 3 b00011111 0x1F + * 4 b00001111 0x0F + * 5 b00000111 0x07 + * 6 b00000011 0x03 + * 7 b00000001 0x01 */ static uint8_t mlx5_flex_hdr_len_mask(uint8_t shift, @@ -464,8 +466,7 @@ mlx5_flex_hdr_len_mask(uint8_t shift, int diff = shift - MLX5_PARSE_GRAPH_NODE_HDR_LEN_SHIFT_DWORD; base_mask = mlx5_hca_parse_graph_node_base_hdr_len_mask(attr); - return diff == 0 ? base_mask : - diff < 0 ? (base_mask << -diff) & base_mask : base_mask >> diff; + return diff < 0 ? base_mask << -diff : base_mask >> diff; } static int @@ -476,7 +477,6 @@ mlx5_flex_translate_length(struct mlx5_hca_flex_attr *attr, { const struct rte_flow_item_flex_field *field = &conf->next_header; struct mlx5_devx_graph_node_attr *node = &devx->devx_conf; - uint32_t len_width, mask; if (field->field_base % CHAR_BIT) return rte_flow_error_set @@ -504,7 +504,14 @@ mlx5_flex_translate_length(struct mlx5_hca_flex_attr *attr, "negative header length field base (FIXED)"); node->header_length_mode = MLX5_GRAPH_NODE_LEN_FIXED; break; - case FIELD_MODE_OFFSET: + case FIELD_MODE_OFFSET: { + uint32_t msb, lsb; + int32_t shift = field->offset_shift; + uint32_t offset = field->offset_base; + uint32_t mask = field->offset_mask; + uint32_t wmax = attr->header_length_mask_width + + MLX5_PARSE_GRAPH_NODE_HDR_LEN_SHIFT_DWORD; + if (!(attr->header_length_mode & RTE_BIT32(MLX5_GRAPH_NODE_LEN_FIELD))) return rte_flow_error_set @@ -514,47 +521,73 @@ mlx5_flex_translate_length(struct mlx5_hca_flex_attr *attr, return rte_flow_error_set (error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM, NULL, "field size is a must for offset mode"); - if (field->field_size + field->offset_base < attr->header_length_mask_width) + if ((offset ^ (field->field_size + offset)) >> 5) return rte_flow_error_set (error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM, NULL, - "field size plus offset_base is too small"); - node->header_length_mode = MLX5_GRAPH_NODE_LEN_FIELD; - if (field->offset_mask == 0 || - !rte_is_power_of_2(field->offset_mask + 1)) + "field crosses the 32-bit word boundary"); + /* Hardware counts in dwords, all shifts done by offset within mask */ + if (shift < 0 || (uint32_t)shift >= wmax) + return rte_flow_error_set + (error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM, NULL, + "header length field shift exceeds limits (OFFSET)"); + if (!mask) + return rte_flow_error_set + (error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM, NULL, + "zero length field offset mask (OFFSET)"); + msb = rte_fls_u32(mask) - 1; + lsb = rte_bsf32(mask); + if (!rte_is_power_of_2((mask >> lsb) + 1)) return rte_flow_error_set (error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM, NULL, - "invalid length field offset mask (OFFSET)"); - len_width = rte_fls_u32(field->offset_mask); - if (len_width > attr->header_length_mask_width) + "length field offset mask not contiguous (OFFSET)"); + if (msb >= field->field_size) return rte_flow_error_set (error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM, NULL, - "length field offset mask too wide (OFFSET)"); - mask = mlx5_flex_hdr_len_mask(field->offset_shift, attr); - if (mask < field->offset_mask) + "length field offset mask exceeds field size (OFFSET)"); + if (msb >= wmax) return rte_flow_error_set (error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM, NULL, - "length field shift too big (OFFSET)"); - node->header_length_field_mask = RTE_MIN(mask, - field->offset_mask); + "length field offset mask exceeds supported width (OFFSET)"); + if (mask & ~mlx5_flex_hdr_len_mask(shift, attr)) + return rte_flow_error_set + (error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM, NULL, + "mask and shift combination not supported (OFFSET)"); + msb++; + offset += field->field_size - msb; + if (msb < attr->header_length_mask_width) { + if (attr->header_length_mask_width - msb > offset) + return rte_flow_error_set + (error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM, NULL, + "field size plus offset_base is too small"); + offset += msb; + /* + * Here we can move to preceding dword. Hardware does + * cyclic left shift so we should avoid this and stay + * at current dword offset. + */ + offset = (offset & ~0x1Fu) | + ((offset - attr->header_length_mask_width) & 0x1F); + } + node->header_length_mode = MLX5_GRAPH_NODE_LEN_FIELD; + node->header_length_field_mask = mask; + node->header_length_field_shift = shift; + node->header_length_field_offset = offset; break; + } case FIELD_MODE_BITMASK: if (!(attr->header_length_mode & RTE_BIT32(MLX5_GRAPH_NODE_LEN_BITMASK))) return rte_flow_error_set (error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM, NULL, "unsupported header length field mode (BITMASK)"); - if (attr->header_length_mask_width < field->field_size) + if (field->offset_shift > 15 || field->offset_shift < 0) return rte_flow_error_set (error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM, NULL, - "header length field width exceeds limit"); + "header length field shift exceeds limit (BITMASK)"); node->header_length_mode = MLX5_GRAPH_NODE_LEN_BITMASK; - mask = mlx5_flex_hdr_len_mask(field->offset_shift, attr); - if (mask < field->offset_mask) - return rte_flow_error_set - (error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM, NULL, - "length field shift too big (BITMASK)"); - node->header_length_field_mask = RTE_MIN(mask, - field->offset_mask); + node->header_length_field_mask = field->offset_mask; + node->header_length_field_shift = field->offset_shift; + node->header_length_field_offset = field->offset_base; break; default: return rte_flow_error_set @@ -567,27 +600,6 @@ mlx5_flex_translate_length(struct mlx5_hca_flex_attr *attr, (error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM, NULL, "header length field base exceeds limit"); node->header_length_base_value = field->field_base / CHAR_BIT; - if (field->field_mode == FIELD_MODE_OFFSET || - field->field_mode == FIELD_MODE_BITMASK) { - if (field->offset_shift > 15 || field->offset_shift < 0) - return rte_flow_error_set - (error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM, NULL, - "header length field shift exceeds limit"); - node->header_length_field_shift = field->offset_shift; - node->header_length_field_offset = field->offset_base; - } - if (field->field_mode == FIELD_MODE_OFFSET) { - if (field->field_size > attr->header_length_mask_width) { - node->header_length_field_offset += - field->field_size - attr->header_length_mask_width; - } else if (field->field_size < attr->header_length_mask_width) { - node->header_length_field_offset -= - attr->header_length_mask_width - field->field_size; - node->header_length_field_mask = - RTE_MIN(node->header_length_field_mask, - (1u << field->field_size) - 1); - } - } return 0; } -- 2.34.1