From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 07C7F432E9;
	Thu,  9 Nov 2023 19:02:15 +0100 (CET)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 5858340DF5;
	Thu,  9 Nov 2023 19:02:14 +0100 (CET)
Received: from NAM10-MW2-obe.outbound.protection.outlook.com
 (mail-mw2nam10on2043.outbound.protection.outlook.com [40.107.94.43])
 by mails.dpdk.org (Postfix) with ESMTP id 1EF3C4021E;
 Thu,  9 Nov 2023 19:02:12 +0100 (CET)
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
 b=KK+d39OeM0FRVB8P72amAAUl6vKF39lWum2JCQF6V73BKOLtfjA2ovXOgEdtjd0XKHo4s9g1bV4AvZFoTD9M3d6Y/6L+R7IlDvLXbDmVXtsINTR1SN0dNL/WAxGNvYta/O6GyICDl7tNmpLM4tssWvXO0VhTT4JHgmJR7mXZqyRGrhzHW4kbaSx8csdePtEFCFPZ52hTvfm7uBuzCIjbcuTQ5uTQ9/IqkDyV1DJKgTIlwAutVpoIyUYZOljU/YQuaX0+92Cp2ZSZrO66d/Ffd+OOINDjw4n7jPlpX04sVxga529Grzws81SAFjjNdav/Npppmwar4Z4oMRSGUS1l/A==
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=G/WgS1x4SdnoCpkLNOGDCvZXORP3scWiXakvBPl5LLY=;
 b=b9PPzv0xXayTehQM7eWgT7TTqSKbSV8Y+jJLO1oyw0098YI/oKQibHlcZZG6WMRIVrwTkOyBtkiqefbUtt/GS/CqaU3VDLKTyBWWYGFKAe+58yOK+tzQjNSrOvM710pc5T6nclHeTpiS2Cm3zUfngN5TTUz3StG3VQVY904n7YJshZoYv6SyWOFbz6RlIKYG4ICPoRhQzqB2At99EL1hiWXnFQBY6TiecI0pvJFyXjWcJ+qLuj8XSPIqlDQZVcjQDk5Vsg8sZw/Il/Wwrs3wy1pzGymPqMoI2umRdOluSiJsdClTBuwZ79C7g52QoX/smCoVauhraR+6+XsgFKPNHg==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is
 216.228.117.160) 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=G/WgS1x4SdnoCpkLNOGDCvZXORP3scWiXakvBPl5LLY=;
 b=GWnRHm9sfu2CMSQzFfo+T6eKxlDItp6P0k2onjVGa7Z/lzIEB+jiwqDyOky5hkzmFtDPoFFnwLLoVbaXOyf5XmZxi47ECPeNVs4OKMBxQgvVbQ/dU4Ppb9zTYkPFX9rnxC78Y9q1VpqJz0KBWRxCIpl0oF4pBkXXw1anwYT3W4lNry61hfrYzMZKiiMt/b0w1IG++A5P8TiDULrnszI3MTWdy0A7e2o/mgGnnFreE1aSF5VQxKdnNZ5AE5OFAim+Y8H9d7sbOkY61YcYHbL6zOode+LiBjweVEYWKN5460nrdn1ttVs89mWWO1OdBpBb7IqRQ361Wz+xgwdsZwacRg==
Received: from PR3P189CA0063.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::8) by
 PH0PR12MB5605.namprd12.prod.outlook.com (2603:10b6:510:129::14) with
 Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.25; Thu, 9 Nov
 2023 18:02:07 +0000
Received: from SN1PEPF000252A4.namprd05.prod.outlook.com
 (2603:10a6:102:b4:cafe::d0) by PR3P189CA0063.outlook.office365.com
 (2603:10a6:102:b4::8) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6977.18 via Frontend
 Transport; Thu, 9 Nov 2023 18:02:06 +0000
X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160)
 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.160 as permitted sender) receiver=protection.outlook.com;
 client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C
Received: from mail.nvidia.com (216.228.117.160) by
 SN1PEPF000252A4.mail.protection.outlook.com (10.167.242.11) with Microsoft
 SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.20.6977.16 via Frontend Transport; Thu, 9 Nov 2023 18:02:04 +0000
Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com
 (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Thu, 9 Nov 2023
 10:01:35 -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; Thu, 9 Nov 2023
 10:01:33 -0800
From: Dariusz Sosnowski <dsosnowski@nvidia.com>
To: Matan Azrad <matan@nvidia.com>, Viacheslav Ovsiienko
 <viacheslavo@nvidia.com>, Ori Kam <orika@nvidia.com>, Suanming Mou
 <suanmingm@nvidia.com>, Bing Zhao <bingz@nvidia.com>
CC: <dev@dpdk.org>, Raslan Darawsheh <rasland@nvidia.com>, <stable@dpdk.org>
Subject: [PATCH] net/mlx5: fix unbind of incorrect hairpin queue
Date: Thu, 9 Nov 2023 20:01:09 +0200
Message-ID: <20231109180109.3185537-1-dsosnowski@nvidia.com>
X-Mailer: git-send-email 2.25.1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [10.126.231.35]
X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To
 rnnvmail201.nvidia.com (10.129.68.8)
X-EOPAttributedMessage: 0
X-MS-PublicTrafficType: Email
X-MS-TrafficTypeDiagnostic: SN1PEPF000252A4:EE_|PH0PR12MB5605:EE_
X-MS-Office365-Filtering-Correlation-Id: 932c076b-95bd-47d6-c7bc-08dbe14dfb7c
X-MS-Exchange-SenderADCheck: 1
X-MS-Exchange-AntiSpam-Relay: 0
X-Microsoft-Antispam: BCL:0;
X-Microsoft-Antispam-Message-Info: 1DGj94fUPFVEY1PxzM7dq0te1M0Qs/+5xN53VHhNoO8WBmtz1utgeA2rCDzQRnDenSxLECBn1ZaaKLjRBVbyfUkMBug0QxwH30LtkxyRJ7vXhCUoERa+3JC177yWeMJr76zclFf27TDUuq46Pmyw4Rfzu+Wv4xV4iE1LgnFjzGdi30rxUpGdCAauEVJw+opxAEwe+3jt3f5npR4OURf6nF5CxtYwfmad+Qxzss94QeEZyaYZiyE5ekjABHD8QpmUTicUUpxi2LxGosqzdmQsW6aVKGtExq/U+xe0t4tOHtnf5TpDTszxXm8PMt2V4KdLpwuYA05mNVkNBTIKTuNEFeSiMwGBI/wrVJjb2GrodmlnibtuucYk9qYivr8cDA4bZo/uaabYntTXXGQU8KQvRJkRzN+gOxPr/a4LXkbNFxUHFmCTAwEtDAdUD8Wf9czz69ufPvPTD6cWNvS/Ec7YEySozxqYkyUitBTA73ijDNVri4oZ34lDoBfljToq6qwD4duz3N3srMoV/Ev9dCIgR5jg7a56aETpnuUl4JGrmk5C4cfw/XcIaq4PWosNcCOU6rYeREghDOjgyCIvUYGA1dU1giXcorxA/0QDMdxvOxeoQ/UTt8BLvQtG/V/iXtIH3GqEOK8lLfghih6J3WBYilALA0325RKDJVKtF6bliQcIK8MNBV0yQNo3UMid2GJUiPAMbUiG4OfDbciC64l2MqG/X5vu7svIz04jAT4CdaYZ8S4BlopsonRJtCbwWODw
X-Forefront-Antispam-Report: CIP:216.228.117.160; CTRY:US; LANG:en; SCL:1; SRV:;
 IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge1.nvidia.com; CAT:NONE;
 SFS:(13230031)(4636009)(136003)(376002)(346002)(396003)(39860400002)(230922051799003)(451199024)(186009)(82310400011)(64100799003)(1800799009)(40470700004)(46966006)(36840700001)(356005)(110136005)(82740400003)(54906003)(55016003)(40480700001)(86362001)(41300700001)(2906002)(40460700003)(5660300002)(6636002)(316002)(8936002)(70206006)(450100002)(4326008)(36756003)(70586007)(83380400001)(47076005)(478600001)(36860700001)(336012)(7696005)(1076003)(8676002)(6286002)(26005)(7636003)(16526019)(2616005)(426003)(6666004);
 DIR:OUT; SFP:1101; 
X-OriginatorOrg: Nvidia.com
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Nov 2023 18:02:04.9641 (UTC)
X-MS-Exchange-CrossTenant-Network-Message-Id: 932c076b-95bd-47d6-c7bc-08dbe14dfb7c
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.160];
 Helo=[mail.nvidia.com]
X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF000252A4.namprd05.prod.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Anonymous
X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem
X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB5605
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

Let's take an application with the following configuration:

- It uses 2 ports.
- Each port has 3 Rx queues and 3 Tx queues.
- On each port, Rx queues have a following purposes:
  - Rx queue 0 - SW queue,
  - Rx queue 1 - hairpin queue, bound to Tx queue on the same port,
  - Rx queue 2 - hairpin queue, bound to Tx queue on another port.
- On each port, Tx queues have a following purposes:
  - Tx queue 0 - SW queue,
  - Tx queue 1 - hairpin queue, bound to Rx queue on the same port,
  - Tx queue 2 - hairpin queue, bound to Rx queue on another port.
- Application configured all of the hairpin queues for manual binding.

After ports are configured and queues are set up,
if the application does the following API call sequence:

1. rte_eth_dev_start(port_id=0)
2. rte_eth_hairpin_bind(tx_port=0, rx_port=0)
3. rte_eth_hairpin_bind(tx_port=0, rx_port=1)

mlx5 PMD fails to modify SQ and logs this error:

  mlx5_common: mlx5_devx_cmds.c:2079: mlx5_devx_cmd_modify_sq():
    Failed to modify SQ using DevX

This error was caused by an incorrect unbind operation taken during
error handling inside call (3).

(3) fails, because port 1 (Rx side of the hairpin) was not started.
As a result of this failure, PMD goes into error handling, where all
previously bound hairpin queues are unbound.
This is incorrect, since this error handling procedure
in rte_eth_hairpin_bind() implementation assumes that
all hairpin queues are bound to the same rx_port, which is not the case.
The following sequence of function calls appears:

- rte_eth_hairpin_queue_peer_unbind(rx_port=**1**, rx_queue=1, 0),
- mlx5_hairpin_queue_peer_unbind(dev=**port 0**, tx_queue=1, 1).

Which violates the hairpin queue destroy flow, by unbinding Tx queue 1
on port 0, before unbinding Rx queue 1 on port 1.

This patch fixes that behavior, by filtering Tx queues on which error
handling is done to only affect:

- hairpin queues (it also reduces unnecessary debug log messages),
- hairpin queues connected to the rx_port which is currently processed.

Fixes: 37cd4501e873 ("net/mlx5: support two ports hairpin mode")
Cc: bingz@nvidia.com
Cc: stable@dpdk.org

Signed-off-by: Dariusz Sosnowski <dsosnowski@nvidia.com>
Acked-by: Viacheslav Ovsiienko <viacheslavo@nvidia.com>
---
 drivers/net/mlx5/mlx5_trigger.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/net/mlx5/mlx5_trigger.c b/drivers/net/mlx5/mlx5_trigger.c
index 88dc271a21..329fa7da3e 100644
--- a/drivers/net/mlx5/mlx5_trigger.c
+++ b/drivers/net/mlx5/mlx5_trigger.c
@@ -845,6 +845,11 @@ mlx5_hairpin_bind_single_port(struct rte_eth_dev *dev, uint16_t rx_port)
 		txq_ctrl = mlx5_txq_get(dev, i);
 		if (txq_ctrl == NULL)
 			continue;
+		if (!txq_ctrl->is_hairpin ||
+		    txq_ctrl->hairpin_conf.peers[0].port != rx_port) {
+			mlx5_txq_release(dev, i);
+			continue;
+		}
 		rx_queue = txq_ctrl->hairpin_conf.peers[0].queue;
 		rte_eth_hairpin_queue_peer_unbind(rx_port, rx_queue, 0);
 		mlx5_hairpin_queue_peer_unbind(dev, i, 1);
-- 
2.25.1