From patchwork Fri Jul 2 09:14:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shun Hao X-Patchwork-Id: 95211 X-Patchwork-Delegate: rasland@nvidia.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6D895A0A0C; Fri, 2 Jul 2021 11:15:39 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3C7C44139B; Fri, 2 Jul 2021 11:15:26 +0200 (CEST) Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2050.outbound.protection.outlook.com [40.107.243.50]) by mails.dpdk.org (Postfix) with ESMTP id 6391C4138A; Fri, 2 Jul 2021 11:15:24 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bOL3gv23UQL3QYFg8LN+/FAWT3qRP4fmnMPdkw5FOlBkjrypHS5rSua1l4KSUR4g3Z4s8z55Oep8QLXc+kl6dNenA7/65Y8Q1V681/3drqJl8Axjg18RqIcFiBtHeVMZMPkQ4ZIK4j0XD/vOsIq2l9Iyyg8nX0y1OdtOa3VkIM54/ZHxpCM29UVyS7jv9SHLcwpkRc3dWJg4ZrW7MMqiK82F7Ugs3h7UJY4n/4uj1L1wYREVmMUA4GlQ5QaFg3CXmoNUlYrP9xpTYHDUup+p70Jq5SeeOWhyGEUZyiuoiNqlc3ayQYh3ct5v11g+1A/w0y/ghUXvgaJWMub8BO4rsA== 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-SenderADCheck; bh=hp+UwPaJMdZKQRRWKjyBgDoon+C/Kv4oxX8vgaCg7Ng=; b=F+R/a9EkKg0j2fTLTRPgnAe7zncJUOa6HFD5jBw7tu6AI7L1yUdwv9Ldf/S4LlxzriDidAgCV7IRG4Pujhui+RzgUXoYWbcPSUGVwF3na374vzOa0Yw+FbkpuS6Tpje2jDE1cFX8pHAH1CP0WfrWqHCpNDcVVW/rLt3UQeqke2LP0b9cb9R5Tx+TxPzLRx5KCEYfyBP+tiFfsNoB/hxlsKUMwPv9VHumhIWZBrl56tzj4N8O0MtZXRtL/Qa8gi6xSSOaFEelPkC5cfh1f+UquhbrnSEnW5YNQIoXtXmZLk60G/1hU0bCy/uiCLOamNpL+iOtFLxlY6ccrfSyyJtu1w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none 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=hp+UwPaJMdZKQRRWKjyBgDoon+C/Kv4oxX8vgaCg7Ng=; b=MgOQn5QnT5rWiCVnB/bbu7n64tFLiTIVo98ghbH3rsLkEZnZEVUux3ChL71k7lwRfW/zKKSC7LJvUzbLENlHLjk/ZbSmEpuYAz9QZ3lYldCZwbnvB5RMYjoER3SCHAz4ge2c8xr136Zkd67Bcu1m2zAiV+RciNq29Yun20R6x2FrUXj/VceUgLghvUn1lUpYCL+CazZOaL6DvWjZgDXlzciHqdLPXFGQ8rL6lJiSdBwiXMxnL4520W7wTiNYSj5B3SqgpbKspkoQoCj16X478nXiZ8xnQPDIgtSErdX1JV0aWFGObNgh5wkt35IkW5jOurUBKxbI9Ecs7nHbLmyHdA== Received: from DS7PR03CA0086.namprd03.prod.outlook.com (2603:10b6:5:3bb::31) by MW3PR12MB4506.namprd12.prod.outlook.com (2603:10b6:303:53::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4264.19; Fri, 2 Jul 2021 09:15:22 +0000 Received: from DM6NAM11FT041.eop-nam11.prod.protection.outlook.com (2603:10b6:5:3bb:cafe::2) by DS7PR03CA0086.outlook.office365.com (2603:10b6:5:3bb::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.23 via Frontend Transport; Fri, 2 Jul 2021 09:15:22 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; dpdk.org; dkim=none (message not signed) header.d=none;dpdk.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by DM6NAM11FT041.mail.protection.outlook.com (10.13.172.98) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4287.22 via Frontend Transport; Fri, 2 Jul 2021 09:15:22 +0000 Received: from nvidia.com (172.20.187.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 2 Jul 2021 09:15:18 +0000 From: Shun Hao To: , , , , Li Zhang CC: , , , , Date: Fri, 2 Jul 2021 12:14:46 +0300 Message-ID: <20210702091446.24635-5-shunh@nvidia.com> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20210702091446.24635-1-shunh@nvidia.com> References: <20210702091446.24635-1-shunh@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [172.20.187.6] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 320da707-e5a1-4c5b-8e15-08d93d39ebcc X-MS-TrafficTypeDiagnostic: MW3PR12MB4506: X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Kia1Q9VKycAQV/i5BAa3jqcwZ4+EodeF1ZNPfJAZfPuI6ZXt8GEerAJnEtZanHJjlwdx4jRci/J67e83xmFOy96g9UTa+7q/CttumBWMc1/iRLzevvFy89PS4e2x9Xd/eItv96jHJgLoNJwX1kitnWIC8OJymRYnG3DE22VwN3WdcgsCMl4ar3OfI57KHZ5vx5Vd9mUjqHeq5RpZQdFn6Dq9wEbtrogOtwkBUa1M1NIeV2p5kpCHYe4m1zz+d6/U7sWu+PKQTweyFqbcMp8isWnRIIYFrvSrgOu2hjlHPXDqMofP79huU/4i9MXnJQS1Q0fuium8TpICqukl5iQzQIz9VLPmvo5AgsHBFw7whb4mbzCT6ytHiEsg8Sqtz7lpi63leEV+x4N/llf5tNUhAl8B7zfI+WONd25/fj0NLpLevd+Ta+6wMvfqrUnPWO479QR2PhR4V3fNpLnjUv1RotRDgNqnfXm1p6x5BAEirRV43NFo6TTeqDZ6j6SNFBMmg7SLlmTF/KcHZOMbN65YRxdKWgaW29jIEJ1Gfcp+imjfl2pAJ2T4GxG84/KtOiw7BBmB56/Nm2DdVdyVimY4qhrzNT085fHIyoLkcxtEFr0RhWwi0RY95KvUEkCxUWqIVZ+SgQ2QwTNOFvn8Kjq2GuoPZEzPH/boUUzkQAvhqmlWwH4JJe3lLrKTEtSt4zwgGhq7uHksAV93ZKxJby/BZA== X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(39860400002)(396003)(376002)(136003)(346002)(36840700001)(46966006)(426003)(336012)(82310400003)(4326008)(478600001)(54906003)(110136005)(7696005)(36906005)(70586007)(26005)(36756003)(6666004)(316002)(8676002)(70206006)(2616005)(16526019)(7636003)(1076003)(86362001)(5660300002)(82740400003)(186003)(83380400001)(2906002)(6636002)(6286002)(47076005)(356005)(55016002)(8936002)(36860700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jul 2021 09:15:22.6898 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 320da707-e5a1-4c5b-8e15-08d93d39ebcc X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT041.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR12MB4506 Subject: [dpdk-dev] [PATCH v1 4/4] net/mlx5: fix meter policy flow match item 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 Sender: "dev" Currently when creating meter policy, a src port_id match item will always be added in switch domain. So if one meter is used by another port, it will not work correctly. This issue is solved: 1. If policy fate action is port_id, add the src port_id match item, and the meter cannot be shared by another port. 2. If policy fate action isn't port_id, don't add the src port_id match, meter can be shared by another port. This fix enables one meter being shared by different ports. User can create a meter flow using a port_id match item to make this meter shared by other port. Fixes: afb4aa4f122 ("net/mlx5: support meter policy operations") Cc: stable@dpdk.org Signed-off-by: Shun Hao Acked-by: Matan Azrad --- doc/guides/nics/mlx5.rst | 8 +++++ drivers/net/mlx5/mlx5.h | 2 ++ drivers/net/mlx5/mlx5_flow_dv.c | 58 ++++++++++++++++++++++++++++----- 3 files changed, 59 insertions(+), 9 deletions(-) diff --git a/doc/guides/nics/mlx5.rst b/doc/guides/nics/mlx5.rst index eb44a070b1..57e7d17b87 100644 --- a/doc/guides/nics/mlx5.rst +++ b/doc/guides/nics/mlx5.rst @@ -1912,3 +1912,11 @@ all flows with assistance of external tools. .. code-block:: console mlx_steering_dump.py -f -flowptr + +How to share a meter between ports in the same switch domain +------------------------------------------------------------ + +This section demonstrates how to use the shared meter. A meter M can be created +on port X and to be shared with a port Y on the same switch domain by the next way: + + flow create X ingress transfer pattern eth / port_id id is Y / end actions meter mtr_id M / end diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index 6eae7b6fd7..0f4b239142 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -682,6 +682,8 @@ struct mlx5_meter_policy_action_container { /* Flow meter policy parameter structure. */ struct mlx5_flow_meter_policy { + struct rte_eth_dev *dev; + /* The port dev on which policy is created. */ uint32_t is_rss:1; /* Is RSS policy table. */ uint32_t ingress:1; diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c index a04a3c2bb8..75ef6216ac 100644 --- a/drivers/net/mlx5/mlx5_flow_dv.c +++ b/drivers/net/mlx5/mlx5_flow_dv.c @@ -5031,6 +5031,8 @@ flow_dv_modify_hdr_action_max(struct rte_eth_dev *dev __rte_unused, * Pointer to the meter action. * @param[in] attr * Attributes of flow that includes this action. + * @param[in] port_id_item + * Pointer to item indicating port id. * @param[out] error * Pointer to error structure. * @@ -5042,6 +5044,7 @@ mlx5_flow_validate_action_meter(struct rte_eth_dev *dev, uint64_t action_flags, const struct rte_flow_action *action, const struct rte_flow_attr *attr, + const struct rte_flow_item *port_id_item, bool *def_policy, struct rte_flow_error *error) { @@ -5112,6 +5115,37 @@ mlx5_flow_validate_action_meter(struct rte_eth_dev *dev, "Flow attributes domain " "have a conflict with current " "meter domain attributes"); + if (attr->transfer && mtr_policy->dev) { + /** + * When policy has fate action of port_id, + * the flow should have the same src port as policy. + */ + struct mlx5_priv *policy_port_priv = + mtr_policy->dev->data->dev_private; + int32_t flow_src_port = priv->representor_id; + + if (port_id_item) { + const struct rte_flow_item_port_id *spec = + port_id_item->spec; + struct mlx5_priv *port_priv = + mlx5_port_to_eswitch_info(spec->id, + false); + if (!port_priv) + return rte_flow_error_set(error, + rte_errno, + RTE_FLOW_ERROR_TYPE_ITEM_SPEC, + spec, + "Failed to get port info."); + flow_src_port = port_priv->representor_id; + } + if (flow_src_port != policy_port_priv->representor_id) + return rte_flow_error_set(error, + rte_errno, + RTE_FLOW_ERROR_TYPE_ITEM_SPEC, + NULL, + "Flow and meter policy " + "have different src port."); + } *def_policy = false; } return 0; @@ -6685,6 +6719,7 @@ flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr, }; const struct rte_eth_hairpin_conf *conf; const struct rte_flow_item *rule_items = items; + const struct rte_flow_item *port_id_item = NULL; bool def_policy = false; if (items == NULL) @@ -6726,6 +6761,7 @@ flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr, if (ret < 0) return ret; last_item = MLX5_FLOW_ITEM_PORT_ID; + port_id_item = items; break; case RTE_FLOW_ITEM_TYPE_ETH: ret = mlx5_flow_validate_item_eth(items, item_flags, @@ -7463,6 +7499,7 @@ flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr, ret = mlx5_flow_validate_action_meter(dev, action_flags, actions, attr, + port_id_item, &def_policy, error); if (ret < 0) @@ -15348,7 +15385,7 @@ __flow_dv_create_policy_flow(struct rte_eth_dev *dev, uint32_t color_reg_c_idx, enum rte_color color, void *matcher_object, int actions_n, void *actions, - bool is_default_policy, void **rule, + bool match_src_port, void **rule, const struct rte_flow_attr *attr) { int ret; @@ -15362,7 +15399,7 @@ __flow_dv_create_policy_flow(struct rte_eth_dev *dev, }; struct mlx5_priv *priv = dev->data->dev_private; - if (!is_default_policy && (priv->representor || priv->master)) { + if (match_src_port && (priv->representor || priv->master)) { if (flow_dv_translate_item_port_id(dev, matcher.buf, value.buf, NULL, attr)) { DRV_LOG(ERR, @@ -15389,7 +15426,7 @@ __flow_dv_create_policy_matcher(struct rte_eth_dev *dev, uint16_t priority, struct mlx5_flow_meter_sub_policy *sub_policy, const struct rte_flow_attr *attr, - bool is_default_policy, + bool match_src_port, struct rte_flow_error *error) { struct mlx5_cache_entry *entry; @@ -15413,7 +15450,7 @@ __flow_dv_create_policy_matcher(struct rte_eth_dev *dev, struct mlx5_priv *priv = dev->data->dev_private; uint32_t color_mask = (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1; - if (!is_default_policy && (priv->representor || priv->master)) { + if (match_src_port && (priv->representor || priv->master)) { if (flow_dv_translate_item_port_id(dev, matcher.mask.buf, value.buf, NULL, attr)) { DRV_LOG(ERR, @@ -15458,7 +15495,7 @@ __flow_dv_create_policy_matcher(struct rte_eth_dev *dev, static int __flow_dv_create_domain_policy_rules(struct rte_eth_dev *dev, struct mlx5_flow_meter_sub_policy *sub_policy, - uint8_t egress, uint8_t transfer, bool is_default_policy, + uint8_t egress, uint8_t transfer, bool match_src_port, struct mlx5_meter_policy_acts acts[RTE_COLORS]) { struct rte_flow_error flow_err; @@ -15497,7 +15534,7 @@ __flow_dv_create_domain_policy_rules(struct rte_eth_dev *dev, /* Create matchers for Color. */ if (__flow_dv_create_policy_matcher(dev, color_reg_c_idx, i, sub_policy, - &attr, is_default_policy, &flow_err)) + &attr, match_src_port, &flow_err)) return -1; } /* Create flow, matching color. */ @@ -15507,7 +15544,7 @@ __flow_dv_create_domain_policy_rules(struct rte_eth_dev *dev, sub_policy->color_matcher[i]->matcher_object, acts[i].actions_n, acts[i].dv_actions, - is_default_policy, + match_src_port, &sub_policy->color_rule[i], &attr)) return -1; @@ -15527,6 +15564,7 @@ __flow_dv_create_policy_acts_rules(struct rte_eth_dev *dev, struct mlx5_flow_dv_port_id_action_resource *port_action; struct mlx5_hrxq *hrxq; uint8_t egress, transfer; + bool match_src_port = false; int i; for (i = 0; i < RTE_COLORS; i++) { @@ -15571,6 +15609,8 @@ __flow_dv_create_policy_acts_rules(struct rte_eth_dev *dev, acts[i].dv_actions[acts[i].actions_n] = port_action->action; acts[i].actions_n++; + mtr_policy->dev = dev; + match_src_port = true; break; case MLX5_FLOW_FATE_DROP: case MLX5_FLOW_FATE_JUMP: @@ -15601,7 +15641,7 @@ __flow_dv_create_policy_acts_rules(struct rte_eth_dev *dev, egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0; transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0; if (__flow_dv_create_domain_policy_rules(dev, sub_policy, - egress, transfer, false, acts)) { + egress, transfer, match_src_port, acts)) { DRV_LOG(ERR, "Failed to create policy rules per domain."); return -1; @@ -15709,7 +15749,7 @@ __flow_dv_create_domain_def_policy(struct rte_eth_dev *dev, uint32_t domain) /* Create default policy rules. */ ret = __flow_dv_create_domain_policy_rules(dev, &def_policy->sub_policy, - egress, transfer, true, acts); + egress, transfer, false, acts); if (ret) { DRV_LOG(ERR, "Failed to create " "default policy rules.");