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 764DF43A51; Fri, 2 Feb 2024 16:07:21 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9AFAC42E8A; Fri, 2 Feb 2024 16:07:05 +0100 (CET) Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2062.outbound.protection.outlook.com [40.107.243.62]) by mails.dpdk.org (Postfix) with ESMTP id 5242442E77 for ; Fri, 2 Feb 2024 16:07:03 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XbmeoI8ZcxBIITcyvuhkdb7au50tLnc57NkoeSV+KeimdX3Ae0Zs3UBBSJcJetU0cL0+oUzRq9UNNeOtQtvj2oH6yIGoK97ArsBTZWtvvFviXAVC+L8Hx/D4HxlBrMSThB9UF7Xc7Gv1lAMLF+JBHzKlecDzwrjOoe1GEPFZBq6wIMeYGyKt/hOD4j2Kuv+4KsR6la2bSJSv0Ffe+MpZa916zZD70QwgSAyVBbw9lsBME9AfpqzGlQEVAKDTRX/9WofY9QXL0OQcxl/xIpKy63+Ym5fovRFQE1ImKqskzTz8n/gxbqhlAjrPDjK/7doo5HHta6BvWfjp/nUzXIyMNA== 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=KQSgTQoKbSIqn4np3cYW7yyc0XueXZZvQgPkaLlJ9H4=; b=WyP6JoEiIk6it3tCJr7zJnV++TWlaP+qHZ3rxa72WUeyxYivoTrp6rv0DzftSMQvw6TvpC2XKQVUTEqMOk7tdbHiqOt1SAQs79M25yYfDEPK87dzwzzf+74aVjX4jtDK0bDY/L4Le/jeCav7FsKMt/TU2MrP45FX1P7qlgeZGFgeT5np5MCAJYGV1rqGk/wt8jMLSHDSHANErkZKnCdJmP0g8TkY19hYjQT1fanHSKPQGOlpNeF0egAPP86nGEpaZGK30LCyM3pqvEYX24icNpcru5IJTVwbyaYaBfrZ3FywDZdnub/5UIJNY8a+ytEm/ulEvoEff4mX5ZPMhMBlfw== 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=KQSgTQoKbSIqn4np3cYW7yyc0XueXZZvQgPkaLlJ9H4=; b=bxS7CHGQ2JKe4Xkiq8pHNbRzguspu49vIUDoZEGKLZ+dy+1Lrzkz/LK0GiaQy588ClPE7Qn8YuIcmMHWg9xyF7LJD4vTC2Y8Dn6p5A5p5K5SD9KOO878W3ATWrkr12CdQIp9jOc8+XEUReX5aJhEowMMvEUabhEh0uNjMWdAdJM/fTvVYXkYhmwUBlcaouepoRef14UQvgu3bq5FxbrIy7mwTbkqv+hmQhW4cX2CyTARyDJTz304cwi3KDvOVXXCKbyOrycp4epPD4QwdVgdS2cgCvQ8Xt4ltLL6PvGfW8MRbCO0AQJrwoyv1D+Z1NENreYaSoXNVbMnoyWITU/VyQ== Received: from CYXPR03CA0040.namprd03.prod.outlook.com (2603:10b6:930:d2::18) by CYXPR12MB9320.namprd12.prod.outlook.com (2603:10b6:930:e6::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.11; Fri, 2 Feb 2024 15:07:01 +0000 Received: from CY4PEPF0000E9D0.namprd03.prod.outlook.com (2603:10b6:930:d2:cafe::78) by CYXPR03CA0040.outlook.office365.com (2603:10b6:930:d2::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.29 via Frontend Transport; Fri, 2 Feb 2024 15:07:01 +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 CY4PEPF0000E9D0.mail.protection.outlook.com (10.167.241.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.19 via Frontend Transport; Fri, 2 Feb 2024 15:07:00 +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.986.41; Fri, 2 Feb 2024 07:06:42 -0800 Received: from nvidia.com (10.126.231.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.986.41; Fri, 2 Feb 2024 07:06:40 -0800 From: Gregory Etelson To: CC: , , Dariusz Sosnowski , Viacheslav Ovsiienko , "Ori Kam" , Suanming Mou , Matan Azrad Subject: [PATCH 2/2] net/mlx5: improve pattern template validation Date: Fri, 2 Feb 2024 17:06:17 +0200 Message-ID: <20240202150617.328603-3-getelson@nvidia.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240202150617.328603-1-getelson@nvidia.com> References: <20240202150617.328603-1-getelson@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.126.231.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: CY4PEPF0000E9D0:EE_|CYXPR12MB9320:EE_ X-MS-Office365-Filtering-Correlation-Id: 928f39f5-1fa9-444b-8489-08dc24009b9d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xw9ebVM6HnTsJkNLDj2d0L/8xeXGhQwLJ4HgSTnZXngOPHAwW2pAl7tY3ubD608dVwN332VU3YQcd9AwPD17qcVgobexGBdOBYhCbkwOr7M8QeI2YhWArW2XvOU419AjM1SIoOBdcsYterYvLnhf23RZEBtLWv3SJq41y76XWe9JCqSYkIIjOiUnTABV16EsaM88Jbocj+AtesCH0joYpp4Fw/iHG81I3FDIBL1TwYfYRzaroeTDQos+YDN79Z9GDNGSw22/Mz37uw8rXBI8NUEpV4g7MhA6d1oTX/syi4Mzv0yJ/uE2Mb62IKIKoBHKiG7ESjGirMFM3tyjor/1Gy0TUcfLzy3TR7xIAq0fWdfW3ha98FhbtQb9Nl8dQ61I4XJJNJUudpgO8XCbW9NFt1Do9A759QbXztVzkFGWMTATkOdCVEJTXu7YyZPxdDHl3b5z/0D0rWNr+bUY4VWFKqeE6wEFAbASeX6pFhYXIeudWEmdqC2yiD2DMTu0UPW6pIRT81qN4yxcaXiMurmLH79llGhO5rYJFixtRNfHIhMwlJj/fX0IaYQwIqe2oHSQNAnPg4swl2LRmcdgN9oODo2WZ5qr+HZOomefpehGiWU085S6o6cSp4W+qHs+prwrz0KSuqzL26W/KlxB89THo2bAG9vO4R4pdDazG4gJsMf9lpqM6AfyHi2tge+3DSj4Scf/khi37ogO1zwM3Gis7tpOIr/gAa210OC1ORy0Siruvu1oFQe6JFSQw1jAPAnt 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:(13230031)(4636009)(136003)(376002)(346002)(396003)(39860400002)(230922051799003)(1800799012)(64100799003)(451199024)(82310400011)(186009)(40470700004)(36840700001)(46966006)(55016003)(40480700001)(40460700003)(83380400001)(356005)(86362001)(36756003)(16526019)(41300700001)(426003)(6666004)(1076003)(36860700001)(26005)(107886003)(47076005)(6286002)(336012)(2616005)(7696005)(2906002)(478600001)(82740400003)(316002)(70206006)(6916009)(70586007)(54906003)(7636003)(8676002)(4326008)(5660300002)(8936002); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Feb 2024 15:07:00.6971 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 928f39f5-1fa9-444b-8489-08dc24009b9d 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: CY4PEPF0000E9D0.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYXPR12MB9320 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Current PMD implementation validates pattern templates that will always be rejected during table template creation. The patch adds basic HWS verifications to pattern validation to ensure that the pattern can be used in table template. PMD updates `rte_errno` if pattern template validation failed: E2BIG - pattern too big for PMD ENOTSUP - pattern not supported by PMD ENOMEM - PMD allocation failure Signed-off-by: Gregory Etelson --- drivers/net/mlx5/mlx5.h | 1 + drivers/net/mlx5/mlx5_flow_hw.c | 121 ++++++++++++++++++++++++++++++-- 2 files changed, 117 insertions(+), 5 deletions(-) diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index f2e2e04429..e98db91888 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -1965,6 +1965,7 @@ struct mlx5_priv { struct mlx5_aso_mtr_pool *hws_mpool; /* HW steering's Meter pool. */ struct mlx5_flow_hw_ctrl_rx *hw_ctrl_rx; /**< HW steering templates used to create control flow rules. */ + struct rte_flow_actions_template *action_template_drop[MLX5DR_TABLE_TYPE_MAX]; #endif struct rte_eth_dev *shared_host; /* Host device for HW steering. */ uint16_t shared_refcnt; /* HW steering host reference counter. */ diff --git a/drivers/net/mlx5/mlx5_flow_hw.c b/drivers/net/mlx5/mlx5_flow_hw.c index da873ae2e2..443aa5fcf0 100644 --- a/drivers/net/mlx5/mlx5_flow_hw.c +++ b/drivers/net/mlx5/mlx5_flow_hw.c @@ -6840,6 +6840,46 @@ flow_hw_pattern_has_sq_match(const struct rte_flow_item *items) return false; } +static int +pattern_template_validate(struct rte_eth_dev *dev, + struct rte_flow_pattern_template *pt[], uint32_t pt_num) +{ + uint32_t group = 0; + struct rte_flow_error error; + struct rte_flow_template_table_attr tbl_attr = { + .nb_flows = 64, + .insertion_type = RTE_FLOW_TABLE_INSERTION_TYPE_PATTERN, + .hash_func = RTE_FLOW_TABLE_HASH_FUNC_DEFAULT, + .flow_attr = { + .ingress = pt[0]->attr.ingress, + .egress = pt[0]->attr.egress, + .transfer = pt[0]->attr.transfer + } + }; + struct mlx5_priv *priv = dev->data->dev_private; + struct rte_flow_actions_template *action_template; + + if (pt[0]->attr.ingress) + action_template = priv->action_template_drop[MLX5DR_TABLE_TYPE_NIC_RX]; + else if (pt[0]->attr.egress) + action_template = priv->action_template_drop[MLX5DR_TABLE_TYPE_NIC_TX]; + else if (pt[0]->attr.transfer) + action_template = priv->action_template_drop[MLX5DR_TABLE_TYPE_FDB]; + else + return EINVAL; + do { + struct rte_flow_template_table *tmpl_tbl; + + tbl_attr.flow_attr.group = group; + tmpl_tbl = flow_hw_template_table_create(dev, &tbl_attr, pt, pt_num, + &action_template, 1, NULL); + if (!tmpl_tbl) + return rte_errno; + flow_hw_table_destroy(dev, tmpl_tbl, &error); + } while (++group <= 1); + return 0; +} + /** * Create flow item template. * @@ -6975,8 +7015,19 @@ flow_hw_pattern_template_create(struct rte_eth_dev *dev, } } __atomic_fetch_add(&it->refcnt, 1, __ATOMIC_RELAXED); + rte_errno = pattern_template_validate(dev, &it, 1); + if (rte_errno) + goto error; LIST_INSERT_HEAD(&priv->flow_hw_itt, it, next); return it; +error: + flow_hw_flex_item_release(dev, &it->flex_item); + claim_zero(mlx5dr_match_template_destroy(it->mt)); + mlx5_free(it); + rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, + "Failed to create pattern template"); + return NULL; + } /** @@ -9184,6 +9235,66 @@ flow_hw_compare_config(const struct mlx5_flow_hw_attr *hw_attr, return true; } +/* + * No need to explicitly release drop action templates on port stop. + * Drop action templates release with other action templates during + * mlx5_dev_close -> flow_hw_resource_release -> flow_hw_actions_template_destroy + */ +static void +action_template_drop_release(struct rte_eth_dev *dev) +{ + int i; + struct mlx5_priv *priv = dev->data->dev_private; + + for (i = 0; i < MLX5DR_TABLE_TYPE_MAX; i++) { + if (!priv->action_template_drop[i]) + continue; + flow_hw_actions_template_destroy(dev, + priv->action_template_drop[i], + NULL); + } +} + +static int +action_template_drop_init(struct rte_eth_dev *dev, + struct rte_flow_error *error) +{ + const struct rte_flow_action drop[2] = { + [0] = { .type = RTE_FLOW_ACTION_TYPE_DROP }, + [1] = { .type = RTE_FLOW_ACTION_TYPE_END }, + }; + const struct rte_flow_action *actions = drop; + const struct rte_flow_action *masks = drop; + const struct rte_flow_actions_template_attr attr[MLX5DR_TABLE_TYPE_MAX] = { + [MLX5DR_TABLE_TYPE_NIC_RX] = { .ingress = 1 }, + [MLX5DR_TABLE_TYPE_NIC_TX] = { .egress = 1 }, + [MLX5DR_TABLE_TYPE_FDB] = { .transfer = 1 } + }; + struct mlx5_priv *priv = dev->data->dev_private; + + priv->action_template_drop[MLX5DR_TABLE_TYPE_NIC_RX] = + flow_hw_actions_template_create(dev, + &attr[MLX5DR_TABLE_TYPE_NIC_RX], + actions, masks, error); + if (!priv->action_template_drop[MLX5DR_TABLE_TYPE_NIC_RX]) + return -1; + priv->action_template_drop[MLX5DR_TABLE_TYPE_NIC_TX] = + flow_hw_actions_template_create(dev, + &attr[MLX5DR_TABLE_TYPE_NIC_TX], + actions, masks, error); + if (!priv->action_template_drop[MLX5DR_TABLE_TYPE_NIC_TX]) + return -1; + if (priv->sh->config.dv_esw_en && priv->master) { + priv->action_template_drop[MLX5DR_TABLE_TYPE_FDB] = + flow_hw_actions_template_create(dev, + &attr[MLX5DR_TABLE_TYPE_FDB], + actions, masks, error); + if (!priv->action_template_drop[MLX5DR_TABLE_TYPE_FDB]) + return -1; + } + return 0; +} + /** * Configure port HWS resources. * @@ -9426,6 +9537,9 @@ flow_hw_configure(struct rte_eth_dev *dev, rte_spinlock_init(&priv->hw_ctrl_lock); LIST_INIT(&priv->hw_ctrl_flows); LIST_INIT(&priv->hw_ext_ctrl_flows); + ret = action_template_drop_init(dev, error); + if (ret) + goto err; ret = flow_hw_create_ctrl_rx_tables(dev); if (ret) { rte_flow_error_set(error, -ret, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, @@ -9559,6 +9673,7 @@ flow_hw_configure(struct rte_eth_dev *dev, mlx5_hws_cnt_pool_destroy(priv->sh, priv->hws_cpool); priv->hws_cpool = NULL; } + action_template_drop_release(dev); mlx5_flow_quota_destroy(dev); flow_hw_destroy_send_to_kernel_action(priv); flow_hw_free_vport_actions(priv); @@ -9612,7 +9727,6 @@ flow_hw_resource_release(struct rte_eth_dev *dev) struct rte_flow_template_table *tbl; struct rte_flow_pattern_template *it; struct rte_flow_actions_template *at; - struct mlx5_flow_group *grp; uint32_t i; if (!priv->dr_ctx) @@ -9621,10 +9735,7 @@ flow_hw_resource_release(struct rte_eth_dev *dev) flow_hw_flush_all_ctrl_flows(dev); flow_hw_cleanup_tx_repr_tagging(dev); flow_hw_cleanup_ctrl_rx_tables(dev); - while (!LIST_EMPTY(&priv->flow_hw_grp)) { - grp = LIST_FIRST(&priv->flow_hw_grp); - flow_hw_group_unset_miss_group(dev, grp, NULL); - } + action_template_drop_release(dev); while (!LIST_EMPTY(&priv->flow_hw_tbl_ongo)) { tbl = LIST_FIRST(&priv->flow_hw_tbl_ongo); flow_hw_table_destroy(dev, tbl, NULL); -- 2.39.2