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 B951545C20 for ; Thu, 31 Oct 2024 13:45:18 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B291F40264; Thu, 31 Oct 2024 13:45:18 +0100 (CET) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2077.outbound.protection.outlook.com [40.107.236.77]) by mails.dpdk.org (Postfix) with ESMTP id EC45143575 for ; Thu, 31 Oct 2024 13:45:17 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WaDi7JLL9wXDOiYVxH7oTL421ccOgnSDkF4ZcAI2Nin30xLv3+uSDymBBvzQT+eU3y48vJa5moPblVLlBFc+fyooYL/4ZW5s4g4KWlLss5Upyu5qNhBJXpmKV7qali5fCWB1X1OMTaX7epsKBePIlLZzabKW8eEfl9PViY3tPFyOg0cawG3P4YaAxzpLruRxbkCF5lWaZ054zITVW1K89iMuDOdSulbtWhZUHj2h1si0Ooe5u4FKnKVOWkyiFPnRFBJCd8RMue9fzOyePdO2maR0ca3TXP95hI/4vQEm6pz06Kk3DvhHLvzMdhmqL1eU1yzNY30xVZ6v1mAcZr+nWw== 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=bVqm7D4cbUrTJtrkep2E1KUIRdz42X3Mh+vIeR3TMfY=; b=H3mPYBPJJrffGCiUqarVL0D3IpcMdkonUHmdaPek9G2uuX9hlnUn2GLh84vEl7KdFGuJRxQuWKOtJ3BLYHrrZRFOzbFXpElQTg+RkE94Ub+PfI4xIgB3CbBb2v/Tq58LhZF/Rn8dezFeGsUliQ/IxeivHqf+KpswdFk9zEwde0f8SHJSifqwpgA/1/AphuiaYTv527wekB39MrslU1x8Ka5WAp/Xv84sC7cqgffnLFQW/9SqkpPZmqSojIA0559CUrxSBnaXfvbD4+7AH2OiWh+CJsDrm3GR92hmfqu2yHpak9VcPg4r0oRz5RvRLN2JuAL/wZivuyQhB460QpIJ/g== 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=bVqm7D4cbUrTJtrkep2E1KUIRdz42X3Mh+vIeR3TMfY=; b=ebNRjOmxCBC9QSbyyCVsa9HzRu+W3IOaachmSOm5U4s1zGUgn+oH1qfL+3U3jRYwq8Fj/c6e8lFy2Joj/EMimykCvkolQESaLFjGmo6WNYksh7WBMPxdHDXN5aJHkbf5YgnQnyMHeU1d5+mRRS0iJJ6HHothmm4Yc5vgdXAQ+V7CkYQmzl9nW0DAy/ZmctlWrF4ahlvt5LPyXemyiw4QKAkZe83BWTLjSewK+rSTIAzlW9Al5MmR7igo35P7DBcUcqLpf29lC2bW3OAN1/V2qrRrJ0rU/sTS/d8OgV/76B+uGIuL74lEQR5/3VmkApnadEWSiIf2iisPJnT5QxLe3Q== Received: from MW4PR03CA0326.namprd03.prod.outlook.com (2603:10b6:303:dd::31) by IA1PR12MB8554.namprd12.prod.outlook.com (2603:10b6:208:450::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.24; Thu, 31 Oct 2024 12:45:10 +0000 Received: from SJ5PEPF00000209.namprd05.prod.outlook.com (2603:10b6:303:dd:cafe::7b) by MW4PR03CA0326.outlook.office365.com (2603:10b6:303:dd::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.26 via Frontend Transport; Thu, 31 Oct 2024 12:45:09 +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 SJ5PEPF00000209.mail.protection.outlook.com (10.167.244.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.16 via Frontend Transport; Thu, 31 Oct 2024 12:45:09 +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; Thu, 31 Oct 2024 05:44:54 -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; Thu, 31 Oct 2024 05:44:53 -0700 From: Viacheslav Ovsiienko To: CC: , Dariusz Sosnowski Subject: [PATCH 22.11 2/3] net/mlx5: fix non full word sample fields in flex item Date: Thu, 31 Oct 2024 14:44:33 +0200 Message-ID: <20241031124434.1751097-2-viacheslavo@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241031124434.1751097-1-viacheslavo@nvidia.com> References: <20241031124434.1751097-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: 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: SJ5PEPF00000209:EE_|IA1PR12MB8554:EE_ X-MS-Office365-Filtering-Correlation-Id: 9f78c089-d315-47dd-a257-08dcf9a9dab5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|1800799024|376014|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?BWqN/rv855hIjCYytK/tTyU0NA+42Pm9FlrlLfExEdgvlaLfBuzOA2rKOE8F?= =?us-ascii?Q?L3f2GvZn/SS0zOTziIjfv8Iyx3Lz7zySMdKegdwlplAZjLITYPFOPFxPAOxJ?= =?us-ascii?Q?j7ugvomYNSlP8rYwurRTY+B+ZkEfwiz8eIPez4ykCwr6MRklWbvgHVRoAi6m?= =?us-ascii?Q?IqcbSAaIOfKTmiYQMvDwbA/GBqr4SV+hpP5DnEbNBAmeci+QuUmPzXy2PfWQ?= =?us-ascii?Q?lj3UURg5zDzGybz811d6GojFCGhEFudYvAM1pUzmqP3ej9ZFLDTTN77J4Jfp?= =?us-ascii?Q?b5i01JLrw4D4Pdrqnh+y+qwc4HZoaCzn6UTL6+uEhKIhHrkN0P2hmUybWT4Y?= =?us-ascii?Q?I9eZWufDNUS49XtFnWUKETqXc5ML9qvd4zwMRJRCZVznKLIQfYTWO6+LTX/S?= =?us-ascii?Q?0LnH4plG6U3EDakxArwzbymbhUKBkNUtzVTnfmduh+XDJkonKx7BmSMHprbk?= =?us-ascii?Q?lQmMp382pVUt1sWokLpK4IrDX+Iveti4MqyLziwmRG57m++oF3oBDBa9P8E5?= =?us-ascii?Q?XsWjMbBVv2DvkjP99EaqKxk3tIBqYuG1UdFHRCLwRO2rJDXGagpzGw0M9Stc?= =?us-ascii?Q?8iTxKlGcCzjoZsNh6BpCcOfC7FntJ8w+FLBbA9045YQ5NDurQ1nXYZVh4vZR?= =?us-ascii?Q?UHmc5VS3cYoZFBbQDpL1vs4GljEd4+i+HpLEdzE4zZ/Pbr+KLIyi29raYblS?= =?us-ascii?Q?6SbLXJoJ2calJ6SM6ih3LLqY876OpftLbv16QuqhgvfM0ofBv0rrkP60N41G?= =?us-ascii?Q?JnjJT8eiylTnEdTvfYMmf+jEDxTIwb5EevA8ir0X/ox7UfLXbzsG+NhBIM0W?= =?us-ascii?Q?edMXQR7dtDBh4aNQDj8CvNkIkERI7XsWd/nq4TMCo6CnsoMg6GhFPu3DR3ja?= =?us-ascii?Q?LH8PGleRpqYC5nvdGX6N+peerwfFWGRXaNfqOzcQwYgygfqdPo+AnIos12bv?= =?us-ascii?Q?vGAbACzbB2acUedkSqfA+6Z10cK8+pRXrEWBI26EBnBOeYHiisXb0z/PUN3X?= =?us-ascii?Q?cAuuBv8mL9X5/4ZGry/WvQW+OEB+tgOIfmwGGAX/3n0/PH86gzPShzcLXBBK?= =?us-ascii?Q?/KZnLaFukLJQmxqFiPV5LjM1KCqYGhqFnUpCO91Umm99OrqM+mPcUgQUHNo2?= =?us-ascii?Q?AnwIpzwo2XOCuwUb5b9IBNDzsaE/6vIYzqDH6S+yim0zg5Y4v6edNjiZZHfy?= =?us-ascii?Q?k8Tom0bnp75keZAkGiyM0b1yy37H+K98SQbNjwY+gFKlrv0vrzIc9tASQC9a?= =?us-ascii?Q?tEWcC3jTH8g8IoC27Qrk5eH325LQ2VlTbiivXRcRWFHSLdeSweo9XIBFrooS?= =?us-ascii?Q?r7jj7UsuuHa2gwA8D5Cg1dd1TeR3NJUcYEaEcggjLDk78ibhYOovqYfgyCj5?= =?us-ascii?Q?XMq6/9sCu3f7Zq5ymCls7wh3smQbzHvIy2gefrMWELEsqy8YkQ=3D=3D?= X-Forefront-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)(376014)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2024 12:45:09.2643 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9f78c089-d315-47dd-a257-08dcf9a9dab5 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: SJ5PEPF00000209.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8554 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 [ upstream commit 97e19f0762e5235d6914845a59823d4ea36925bb ] If the sample field in flex item did not cover the entire 32-bit word (width was not verified 32 bits) or was not aligned on the byte boundary the match on this sample in flows happened to be ignored or wrongly missed. The field mask "def" was build in wrong endianness, and non-byte aligned shifts were wrongly performed for the pattern masks and values. Fixes: 6dac7d7ff2bf ("net/mlx5: translate flex item pattern into matcher") Cc: stable@dpdk.org Signed-off-by: Viacheslav Ovsiienko Acked-by: Dariusz Sosnowski --- drivers/net/mlx5/mlx5_flow_flex.c | 32 ++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/drivers/net/mlx5/mlx5_flow_flex.c b/drivers/net/mlx5/mlx5_flow_flex.c index b63441b199..e4321941a6 100644 --- a/drivers/net/mlx5/mlx5_flow_flex.c +++ b/drivers/net/mlx5/mlx5_flow_flex.c @@ -118,28 +118,32 @@ mlx5_flex_get_bitfield(const struct rte_flow_item_flex *item, uint32_t pos, uint32_t width, uint32_t shift) { const uint8_t *ptr = item->pattern + pos / CHAR_BIT; - uint32_t val, vbits; + uint32_t val, vbits, skip = pos % CHAR_BIT; /* Proceed the bitfield start byte. */ MLX5_ASSERT(width <= sizeof(uint32_t) * CHAR_BIT && width); MLX5_ASSERT(width + shift <= sizeof(uint32_t) * CHAR_BIT); if (item->length <= pos / CHAR_BIT) return 0; - val = *ptr++ >> (pos % CHAR_BIT); + /* Bits are enumerated in byte in network order: 01234567 */ + val = *ptr++; vbits = CHAR_BIT - pos % CHAR_BIT; - pos = (pos + vbits) / CHAR_BIT; + pos = RTE_ALIGN_CEIL(pos, CHAR_BIT) / CHAR_BIT; vbits = RTE_MIN(vbits, width); - val &= RTE_BIT32(vbits) - 1; + /* Load bytes to cover the field width, checking pattern boundary */ while (vbits < width && pos < item->length) { uint32_t part = RTE_MIN(width - vbits, (uint32_t)CHAR_BIT); uint32_t tmp = *ptr++; - pos++; - tmp &= RTE_BIT32(part) - 1; - val |= tmp << vbits; + val |= tmp << RTE_ALIGN_CEIL(vbits, CHAR_BIT); vbits += part; + pos++; } - return rte_bswap32(val <<= shift); + val = rte_cpu_to_be_32(val); + val <<= skip; + val >>= shift; + val &= (RTE_BIT64(width) - 1) << (sizeof(uint32_t) * CHAR_BIT - shift - width); + return val; } #define SET_FP_MATCH_SAMPLE_ID(x, def, msk, val, sid) \ @@ -235,19 +239,21 @@ mlx5_flex_flow_translate_item(struct rte_eth_dev *dev, mask = item->mask; tp = (struct mlx5_flex_item *)spec->handle; MLX5_ASSERT(mlx5_flex_index(dev->data->dev_private, tp) >= 0); - for (i = 0; i < tp->mapnum; i++) { + for (i = 0; i < tp->mapnum && pos < (spec->length * CHAR_BIT); i++) { struct mlx5_flex_pattern_field *map = tp->map + i; uint32_t id = map->reg_id; - uint32_t def = (RTE_BIT64(map->width) - 1) << map->shift; - uint32_t val, msk; + uint32_t val, msk, def; /* Skip placeholders for DUMMY fields. */ if (id == MLX5_INVALID_SAMPLE_REG_ID) { pos += map->width; continue; } + def = (uint32_t)(RTE_BIT64(map->width) - 1); + def <<= (sizeof(uint32_t) * CHAR_BIT - map->shift - map->width); val = mlx5_flex_get_bitfield(spec, pos, map->width, map->shift); - msk = mlx5_flex_get_bitfield(mask, pos, map->width, map->shift); + msk = pos < (mask->length * CHAR_BIT) ? + mlx5_flex_get_bitfield(mask, pos, map->width, map->shift) : def; MLX5_ASSERT(map->width); MLX5_ASSERT(id < tp->devx_fp->num_samples); if (tp->tunnel_mode == FLEX_TUNNEL_MODE_MULTI && is_inner) { @@ -258,7 +264,7 @@ mlx5_flex_flow_translate_item(struct rte_eth_dev *dev, id += num_samples; } mlx5_flex_set_match_sample(misc4_m, misc4_v, - def, msk & def, val & msk & def, + def, msk, val & msk, tp->devx_fp->sample_ids[id], id); pos += map->width; } -- 2.34.1