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 2C937A00C3; Fri, 13 May 2022 09:33:51 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 722474284B; Fri, 13 May 2022 09:33:40 +0200 (CEST) Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2077.outbound.protection.outlook.com [40.107.220.77]) by mails.dpdk.org (Postfix) with ESMTP id 511584283C for ; Fri, 13 May 2022 09:33:37 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jWOSnUpi5b1qdZj+UoQJTqDmQlU4rv34YEl8ZI1Z9hya6Mg1AgCY/e1DJ8qKYvRPpGe6YKIQ56lndiMe75+ABgQogv7T+mJ1uBofU91zkOJlrvXyABEqZba101GnO7kP7UHHNngUMTLbeZ24deJPxIHkORBCscfFWA6CjTX3S7SgALp2OXq9a5jsdp5s4G1VtPOAGcvqzHPJGSuPVNUKLYuqVhHQaqfSUNnSmAw+O5LW4CDzVZJowWxBcCnT320PoBTxypdlaTWbls6NYSLQUJCxN2BroC2uA3200LcyRb1syW3LgMUciki7wpJYx5D1x9P32eKQBex9kCqt/vj+nw== 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=2BCM+FKN890cbwMpyVS2u8DVHvm4CXJvqLG7raSZsm0=; b=daHHGwuqc400e8qtZ8rGoEXgpj1oZq1KnRWIYJdlmwxg8SYXFAK3wYqH4D7h0w5BrlpSXefFSnnj4euDPhSs/yMtHnZKrXK3U55Fd/wAJ32aKEQZeRhGdXtptAS9h/Hwlh1DFFw+xzLSYTNp8XSz8iLi5SZI2K9KVvLguQqQkI1IARMTZHy7PhlHEuA/2d77ucW41A5/Mi6HueN9XKhhDRBJpC2ksP16EUTUhroPvuhUrisac7Pd7fpUhlEQ7kI/VF0fi7yiacMQUCu/s8H3oQDakdJbn1LVRds3IPzTdkvQdsp62jezyenJJbDAU3qk1OX7PydrwHUEqrFPhPnRHQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.236) 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 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=2BCM+FKN890cbwMpyVS2u8DVHvm4CXJvqLG7raSZsm0=; b=KjWk1I1+BbBBqDHnSv6yBvH7pD3/dbkHp7XhYYL4cmYKVGSxGERt2CvuJAQILiaW3KSawX5Nb3p4rdI753IrIlITdAxO9u5QWMcTxiL1Fa7UYJ5gKoI1q37gI51ifZDapFnC8evfgGvXvob4DNCvZnPfiuzFyItk2A8lVPoSSAztQQTwsvGYVHfxwjl+iCDAV+YVh+0B8oZ58NWNxus6xqRvhPR9mmZxSknbqu4mXbd3rgeQV+S+hYjV9r4ekrM1ULkGh0BBJzVs1oVgBn05vyMbjhPMfq6uStaqiRoxBn+wWQK+xHA9yz4mwm7rJ/OAc/A4pVfQecEQPaXy6BnTtA== Received: from MW4PR03CA0210.namprd03.prod.outlook.com (2603:10b6:303:b8::35) by BYAPR12MB3493.namprd12.prod.outlook.com (2603:10b6:a03:dd::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5227.21; Fri, 13 May 2022 07:33:34 +0000 Received: from CO1NAM11FT057.eop-nam11.prod.protection.outlook.com (2603:10b6:303:b8:cafe::d) by MW4PR03CA0210.outlook.office365.com (2603:10b6:303:b8::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5227.23 via Frontend Transport; Fri, 13 May 2022 07:33:33 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.236) 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 12.22.5.236 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.236; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.236) by CO1NAM11FT057.mail.protection.outlook.com (10.13.174.205) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5250.13 via Frontend Transport; Fri, 13 May 2022 07:33:33 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL109.nvidia.com (10.27.9.19) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Fri, 13 May 2022 07:33:33 +0000 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.22; Fri, 13 May 2022 00:33:30 -0700 From: Shun Hao To: , , CC: , Subject: [PATCH v1 3/4] net/mlx5: support yellow meter action for hierarchy tag rule Date: Fri, 13 May 2022 10:33:07 +0300 Message-ID: <20220513073308.10762-4-shunh@nvidia.com> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20220513073308.10762-1-shunh@nvidia.com> References: <20220513073308.10762-1-shunh@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-Office365-Filtering-Correlation-Id: 6b73fc3c-dd12-43f2-bc8e-08da34b2e294 X-MS-TrafficTypeDiagnostic: BYAPR12MB3493:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IBo5LIzLmqy5siD3fUSfq/31o/1U6Y7wjPlEOvNluXFjgbmaeoHpyjeRud46XIFaV1jpNCq0YdIRoEpO1IwofG+yJbBYXQP75Z14kfzFRlwHJ3rssFeizJ5WEMr+e6QCVnE3Pl0JtZRvMw5fuN5eZVWIGEFsEoGZrctBbCucJKnwm2jNkcytog2bAUnTviifIT+JxD0TeBCenz33IqCKJcBl6XsWG9XN9SRElYvx6b7E9/xyDMEMo6acWz6VlltXy0S9+637wbQ8PY20N8jxDTDrYQ5wYivvIfLJy9Eg5BvOaNigVflDGuqu4KZWQnjeKESKRTXeIgcgu2Cq4mf7m+euJ7X5IiEH5svU3ubooc2cs/UErmrQhgZ6YY9PAUoeEFT9tbvZvC0fcKnCBiDH3002RniprgkyovYjrKsJFw5hoeXr3EKKZe6xKYyk3lg2US0TzhjF47tdBc3bhvQ+fK8uBoywdehIZEC2fHuvQob5HlypfS43f59sY5A24Zgk5KLWgPxgLaly0tGuu7/LXu2TXf+OUX4Ow6B1xAFvyZ7KyEbTw0Ol+xRPSut62PSVLpWQ72qM8aNWlYEx+BMTVDk0JkJlT8xSsmjryHyM2mZF4gUkGJ6ysMH1R/UjOriATCNSQQy9bCS6y7n73abnbg+z5otNYCGa+sE0hPut2uY1G79uXDbwobv1q6dnbQQybC5vmTza+trEO7q887vnrQ== X-Forefront-Antispam-Report: CIP:12.22.5.236; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230001)(4636009)(40470700004)(46966006)(36840700001)(2616005)(55016003)(508600001)(1076003)(81166007)(316002)(86362001)(36860700001)(83380400001)(36756003)(107886003)(5660300002)(16526019)(186003)(8936002)(2906002)(336012)(426003)(82310400005)(70586007)(47076005)(8676002)(70206006)(4326008)(30864003)(110136005)(6636002)(54906003)(7696005)(6666004)(356005)(26005)(6286002)(40460700003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 May 2022 07:33:33.5318 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6b73fc3c-dd12-43f2-bc8e-08da34b2e294 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.236]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT057.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB3493 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 When a hierarchy meter is shared by other ports, it's needed to iterate all meter policies in hierarchy to create tag rules, to set packet with next meter ID, which will be used by related meter drop count. This patch adds the tag rule for yellow support in hierarchy, so both green/yellow policy flows can set the correct meter ID. Signed-off-by: Shun Hao Acked-by: Matan Azard --- drivers/net/mlx5/mlx5_flow_dv.c | 270 +++++++++++++++++++++----------- 1 file changed, 175 insertions(+), 95 deletions(-) diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c index ee7a32acc8..287095cceb 100644 --- a/drivers/net/mlx5/mlx5_flow_dv.c +++ b/drivers/net/mlx5/mlx5_flow_dv.c @@ -17293,6 +17293,68 @@ flow_dv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev, return NULL; } +/** + * Check if need to create hierarchy tag rule. + * + * @param[in] priv + * Pointer to mlx5_priv. + * @param[in] mtr_policy + * Pointer to current meter policy. + * @param[in] src_port + * The src port this extra rule should use. + * @param[out] next_fm + * Pointer to next meter in hierarchy. + * @param[out] skip + * Indicate if skip the tag rule creation. + * @param[out] error + * Perform verbose error reporting if not NULL. + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +static int +mlx5_meter_hierarchy_skip_tag_rule(struct mlx5_priv *priv, + struct mlx5_flow_meter_policy *mtr_policy, + int32_t src_port, + struct mlx5_flow_meter_info **next_fm, + bool *skip, + struct rte_flow_error *error) +{ + struct mlx5_flow_meter_sub_policy *sub_policy; + struct mlx5_sub_policy_color_rule *color_rule; + uint32_t domain = MLX5_MTR_DOMAIN_TRANSFER; + int ret = 0; + int i; + + *next_fm = NULL; + *skip = false; + rte_spinlock_lock(&mtr_policy->sl); + if (!mtr_policy->is_hierarchy) + goto exit; + *next_fm = mlx5_flow_meter_hierarchy_next_meter(priv, mtr_policy, NULL); + if (!*next_fm) { + ret = rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION, + NULL, "Failed to find next meter in hierarchy."); + goto exit; + } + if (!(*next_fm)->drop_cnt) { + *skip = true; + goto exit; + } + sub_policy = mtr_policy->sub_policys[domain][0]; + for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) { + if (mtr_policy->act_cnt[i].fate_action != MLX5_FLOW_FATE_MTR) + continue; + TAILQ_FOREACH(color_rule, &sub_policy->color_rules[i], next_port) + if (color_rule->src_port == src_port) { + *skip = true; + goto exit; + } + } +exit: + rte_spinlock_unlock(&mtr_policy->sl); + return ret; +} + /** * Create the sub policy tag rule for all meters in hierarchy. * @@ -17336,111 +17398,129 @@ flow_dv_meter_hierarchy_rule_create(struct rte_eth_dev *dev, .reserved = 0, }; uint32_t domain = MLX5_MTR_DOMAIN_TRANSFER; - int i; + struct { + struct mlx5_flow_meter_policy *fm_policy; + struct mlx5_flow_meter_info *next_fm; + struct mlx5_sub_policy_color_rule *tag_rule[MLX5_MTR_RTE_COLORS]; + } fm_info[MLX5_MTR_CHAIN_MAX_NUM] = { {0} }; + uint32_t fm_cnt = 0; + uint32_t i, j; - mtr_policy = mlx5_flow_meter_policy_find(dev, fm->policy_id, NULL); - MLX5_ASSERT(mtr_policy); - if (!mtr_policy->is_hierarchy) - return 0; - next_fm = mlx5_flow_meter_find(priv, - mtr_policy->act_cnt[RTE_COLOR_GREEN].next_mtr_id, NULL); - if (!next_fm) { - return rte_flow_error_set(error, EINVAL, - RTE_FLOW_ERROR_TYPE_ACTION, NULL, - "Failed to find next meter in hierarchy."); - } - if (!next_fm->drop_cnt) - goto exit; color_reg_c_idx = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, error); - sub_policy = mtr_policy->sub_policys[domain][0]; - for (i = 0; i < RTE_COLORS; i++) { - bool rule_exist = false; - struct mlx5_meter_policy_action_container *act_cnt; + /* Get all fms who need to create the tag color rule. */ + do { + bool skip = false; - if (i >= RTE_COLOR_YELLOW) - break; - TAILQ_FOREACH(color_rule, - &sub_policy->color_rules[i], next_port) - if (color_rule->src_port == src_port) { - rule_exist = true; - break; - } - if (rule_exist) - continue; - color_rule = mlx5_malloc(MLX5_MEM_ZERO, - sizeof(struct mlx5_sub_policy_color_rule), - 0, SOCKET_ID_ANY); - if (!color_rule) - return rte_flow_error_set(error, ENOMEM, - RTE_FLOW_ERROR_TYPE_ACTION, - NULL, "No memory to create tag color rule."); - color_rule->src_port = src_port; - attr.priority = i; - next_policy = mlx5_flow_meter_policy_find(dev, - next_fm->policy_id, NULL); - MLX5_ASSERT(next_policy); - next_sub_policy = next_policy->sub_policys[domain][0]; - tbl_data = container_of(next_sub_policy->tbl_rsc, - struct mlx5_flow_tbl_data_entry, tbl); - act_cnt = &mtr_policy->act_cnt[i]; - if (mtr_first) { - acts.dv_actions[0] = next_fm->meter_action_g; - acts.dv_actions[1] = act_cnt->modify_hdr->action; - } else { - acts.dv_actions[0] = act_cnt->modify_hdr->action; - acts.dv_actions[1] = next_fm->meter_action_g; - } - acts.dv_actions[2] = tbl_data->jump.action; - acts.actions_n = 3; - if (mlx5_flow_meter_attach(priv, next_fm, &attr, error)) { - next_fm = NULL; - goto err_exit; - } - if (__flow_dv_create_policy_matcher(dev, color_reg_c_idx, - MLX5_MTR_POLICY_MATCHER_PRIO, sub_policy, - &attr, true, item, - &color_rule->matcher, error)) { - rte_flow_error_set(error, errno, - RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, - "Failed to create hierarchy meter matcher."); + mtr_policy = mlx5_flow_meter_policy_find(dev, fm->policy_id, NULL); + MLX5_ASSERT(mtr_policy); + if (mlx5_meter_hierarchy_skip_tag_rule(priv, mtr_policy, src_port, + &next_fm, &skip, error)) goto err_exit; + if (next_fm && !skip) { + fm_info[fm_cnt].fm_policy = mtr_policy; + fm_info[fm_cnt].next_fm = next_fm; + if (++fm_cnt >= MLX5_MTR_CHAIN_MAX_NUM) { + rte_flow_error_set(error, errno, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, + "Exceed max meter number in hierarchy."); + goto err_exit; + } } - if (__flow_dv_create_policy_flow(dev, color_reg_c_idx, - (enum rte_color)i, - color_rule->matcher->matcher_object, - acts.actions_n, acts.dv_actions, - true, item, - &color_rule->rule, &attr)) { - rte_flow_error_set(error, errno, - RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, - "Failed to create hierarchy meter rule."); - goto err_exit; + fm = next_fm; + } while (fm); + /* Create tag color rules for all needed fms. */ + for (i = 0; i < fm_cnt; i++) { + void *mtr_action; + + mtr_policy = fm_info[i].fm_policy; + rte_spinlock_lock(&mtr_policy->sl); + sub_policy = mtr_policy->sub_policys[domain][0]; + for (j = 0; j < MLX5_MTR_RTE_COLORS; j++) { + if (mtr_policy->act_cnt[j].fate_action != MLX5_FLOW_FATE_MTR) + continue; + color_rule = mlx5_malloc(MLX5_MEM_ZERO, + sizeof(struct mlx5_sub_policy_color_rule), + 0, SOCKET_ID_ANY); + if (!color_rule) { + rte_spinlock_unlock(&mtr_policy->sl); + rte_flow_error_set(error, ENOMEM, + RTE_FLOW_ERROR_TYPE_ACTION, NULL, + "No memory to create tag color rule."); + goto err_exit; + } + color_rule->src_port = src_port; + next_fm = fm_info[i].next_fm; + if (mlx5_flow_meter_attach(priv, next_fm, &attr, error)) { + mlx5_free(color_rule); + rte_spinlock_unlock(&mtr_policy->sl); + goto err_exit; + } + fm_info[i].tag_rule[j] = color_rule; + TAILQ_INSERT_TAIL(&sub_policy->color_rules[j], color_rule, next_port); + /* Prepare to create color rule. */ + mtr_action = (next_fm->color_aware && j == RTE_COLOR_YELLOW) ? + next_fm->meter_action_y : + next_fm->meter_action_g; + next_policy = mlx5_flow_meter_policy_find(dev, next_fm->policy_id, NULL); + MLX5_ASSERT(next_policy); + next_sub_policy = next_policy->sub_policys[domain][0]; + tbl_data = container_of(next_sub_policy->tbl_rsc, + struct mlx5_flow_tbl_data_entry, tbl); + if (mtr_first) { + acts.dv_actions[0] = mtr_action; + acts.dv_actions[1] = mtr_policy->act_cnt[j].modify_hdr->action; + } else { + acts.dv_actions[0] = mtr_policy->act_cnt[j].modify_hdr->action; + acts.dv_actions[1] = mtr_action; + } + acts.dv_actions[2] = tbl_data->jump.action; + acts.actions_n = 3; + if (__flow_dv_create_policy_matcher(dev, color_reg_c_idx, + MLX5_MTR_POLICY_MATCHER_PRIO, sub_policy, + &attr, true, item, &color_rule->matcher, error)) { + rte_spinlock_unlock(&mtr_policy->sl); + rte_flow_error_set(error, errno, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, + "Failed to create hierarchy meter matcher."); + goto err_exit; + } + if (__flow_dv_create_policy_flow(dev, color_reg_c_idx, (enum rte_color)j, + color_rule->matcher->matcher_object, + acts.actions_n, acts.dv_actions, + true, item, &color_rule->rule, &attr)) { + rte_spinlock_unlock(&mtr_policy->sl); + rte_flow_error_set(error, errno, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, + "Failed to create hierarchy meter rule."); + goto err_exit; + } } - TAILQ_INSERT_TAIL(&sub_policy->color_rules[i], - color_rule, next_port); + rte_spinlock_unlock(&mtr_policy->sl); } -exit: - /** - * Recursive call to iterate all meters in hierarchy and - * create needed rules. - */ - return flow_dv_meter_hierarchy_rule_create(dev, next_fm, - src_port, item, error); + return 0; err_exit: - if (color_rule) { - if (color_rule->rule) - mlx5_flow_os_destroy_flow(color_rule->rule); - if (color_rule->matcher) { - struct mlx5_flow_tbl_data_entry *tbl = - container_of(color_rule->matcher->tbl, - typeof(*tbl), tbl); - mlx5_list_unregister(tbl->matchers, - &color_rule->matcher->entry); + for (i = 0; i < fm_cnt; i++) { + mtr_policy = fm_info[i].fm_policy; + rte_spinlock_lock(&mtr_policy->sl); + sub_policy = mtr_policy->sub_policys[domain][0]; + for (j = 0; j < MLX5_MTR_RTE_COLORS; j++) { + color_rule = fm_info[i].tag_rule[j]; + if (!color_rule) + continue; + if (color_rule->rule) + mlx5_flow_os_destroy_flow(color_rule->rule); + if (color_rule->matcher) { + struct mlx5_flow_tbl_data_entry *tbl = + container_of(color_rule->matcher->tbl, typeof(*tbl), tbl); + mlx5_list_unregister(tbl->matchers, &color_rule->matcher->entry); + } + if (fm_info[i].next_fm) + mlx5_flow_meter_detach(priv, fm_info[i].next_fm); + TAILQ_REMOVE(&sub_policy->color_rules[j], color_rule, next_port); + mlx5_free(color_rule); } - mlx5_free(color_rule); + rte_spinlock_unlock(&mtr_policy->sl); } - if (next_fm) - mlx5_flow_meter_detach(priv, next_fm); return -rte_errno; } -- 2.20.0