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 32987A0353; Tue, 1 Mar 2022 13:16:11 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EA392426F9; Tue, 1 Mar 2022 13:16:04 +0100 (CET) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2086.outbound.protection.outlook.com [40.107.94.86]) by mails.dpdk.org (Postfix) with ESMTP id 510AA426EA; Tue, 1 Mar 2022 13:16:01 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PyhQq9cmYYi2BALimRQyIigkPPRgY4Sr2ipIxPTPsnVFGsn++lHixtwW5hy+E/2wgq+aFadBDPETlWcPra054vn/fL7zlfODyTacRaZD1jFFMZ7p3Jg9y+fnN9S4t8InONZPmvEi8UckWzF0g8AI4fFb9mM9iFkl7kPi1Udzv2mm47H2bryEBD9fwPUSAyU9oxCvpXuy/Ef8KNTaBTVd9/PL3Lu22VXzTs4IUP/x2HRj/Iou9ev9suOf5T7T9zekWuuT9u+jPVya3YEoHRO1szM+wyI8HgiMd8BqyVGK7DQbZAEYZxkP3J6t0A45xiwGM0VyGHQ3t/KyQuXVLUi1ZA== 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=G5sM/U/w3J13V0Np8NxPhWgM/pTyXqRUs6zbZC5j6qk=; b=mQDU1MiQhfzkeMojyr0uWwNk3bniJqSNbA+uxIo+x2U+iYb3UC1FMAYYyDoKlVw/V1WSgvAKdyUjiHQqyP3RqGj7IlD4hlHSPhLp6AiFlAkdtMFWM6JfM+1aKdsnga/hkBbdhFRppkGU4KsRE+cFjMF/kW6iBiAL1OgXnncaObQ2wfoD9IG0PPtvcAe/DKe57Mpq7k5dYSiOgJqW1SZ/yfIdvjd9+6ndPSmsUehbe4plA50KFEGbrmr2fJLWkuuj9EW5uPmSUyM+56r208XQZR+pL/7eaSOSx4BMfSZYK/nTCtP7v8NXaiNPncxWIXsVZSt3X6kkQosNnZMxkjMJPQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.235) 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=G5sM/U/w3J13V0Np8NxPhWgM/pTyXqRUs6zbZC5j6qk=; b=lRP+wD7Ck7bcOf2WIrF+9Lhk0DNJu0umbj+/GRavVu0m8rQT2Kby1B7pyGtiiSg/GvLbVMpWw9xNL56rKGPnmGQ0CQ1gqsdDuzyKlobnBIhYwLEQJh5CZOUElmcLUBBWvcfwUWBrrQJivAS65pI9tbkbIkyuKPt+XFc3U1D9pSIXnsk7m5EA5xQu/oVo+WwSqeecl0gCYfUowaINU1uDZnlk32o2RcMQU2ybbCDKR8wiQFXcsqJH9Pw92pkV+6U5pO5dKJJFPTAJMHbnP/Tfgj6cdLkaZpQL0QW5NchQHZ8C49r6kRa85vjRC+2pGykhRLh8KWnFRY3WYt1UHQorAA== Received: from MWHPR15CA0061.namprd15.prod.outlook.com (2603:10b6:301:4c::23) by DS7PR12MB5957.namprd12.prod.outlook.com (2603:10b6:8:7c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.13; Tue, 1 Mar 2022 12:15:59 +0000 Received: from CO1NAM11FT035.eop-nam11.prod.protection.outlook.com (2603:10b6:301:4c:cafe::c0) by MWHPR15CA0061.outlook.office365.com (2603:10b6:301:4c::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.13 via Frontend Transport; Tue, 1 Mar 2022 12:15:59 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.235) 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.235 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.235; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.235) by CO1NAM11FT035.mail.protection.outlook.com (10.13.175.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5017.22 via Frontend Transport; Tue, 1 Mar 2022 12:15:58 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Tue, 1 Mar 2022 12:15:58 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.9; Tue, 1 Mar 2022 04:15:56 -0800 Received: from nvidia.com (10.127.8.11) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.9 via Frontend Transport; Tue, 1 Mar 2022 04:15:55 -0800 From: Dmitry Kozlyuk To: CC: , Viacheslav Ovsiienko , "Matan Azrad" Subject: [PATCH v2 2/3] net/mlx5: fix link status change detection Date: Tue, 1 Mar 2022 14:15:13 +0200 Message-ID: <20220301121514.41497-3-dkozlyuk@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220301121514.41497-1-dkozlyuk@nvidia.com> References: <20220223164333.3834590-1-dkozlyuk@nvidia.com> <20220301121514.41497-1-dkozlyuk@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 40705087-2d3d-406d-275d-08d9fb7d3eb7 X-MS-TrafficTypeDiagnostic: DS7PR12MB5957: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: ooXUx0nMeQ1opjWCVrJjIda4+8x8Ju9Sv6PTl1lH6zDTj7cMSKQi1Gv5jEbKhIBa++j4oHKoKm8sWmcnaSIZrreN13gZYdpdNvdUerJr0H7BpyTBRKYmTMj1suGmwBlQeZJl9kfp1j3b/gy6d5tVx7muWjc9NPf/LBVGKxcw/BNRbQXl6P231p8FDZgnlcdlV9ox3CQLnTPOFBhM/QSQ2FAb0bqwArXquYcBbcrLZ2UOjos+yKqE5T5jze1zcrtPV9Sr3s3wsXzjNqFdRqKP3FnD0MNx3ITlVRqcH0Mt7JBWVUBkMFAyyKq2cOyRtwiB6Lx17xh6Kx0FF5j7YxqwukOaxF9hv/TM9GI8uGMl8HZwtFDYyy/lFU6DyW+MYLiBfts74JH88IVlYWzo8UnmAYY4e2tdWeZ/dLr0pvINmGigy0owLfXq+a80VuzWyAiwFkl3tn4rIVYJvdxzZZNzckWucloeOJYJifJ0sP3yLWIQ3lJLa94HiMICkd29xR1DXA3Mg0H77gBFq9TjgTggesKKx0G30BkdKl16mg0nBfM2jBb7F8HxqiEeIp3WsB/4hDBexHsTweV17vzotwlme0lacyFsXdZGZ0vTTDdlndg13+I6mOH8acEHkqqPYOaXfiVnBqjktewCe9otXmeAPCFHv9zB8HQExqOdnh3+9sEAsX7LmkkNl1ZZABAs3dqX00AhKbnUbyh+7Xprn9GJpw== X-Forefront-Antispam-Report: CIP:12.22.5.235; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(40470700004)(46966006)(40460700003)(8936002)(36860700001)(2906002)(47076005)(6666004)(6286002)(7696005)(82310400004)(83380400001)(426003)(336012)(1076003)(2616005)(186003)(508600001)(26005)(107886003)(86362001)(6916009)(450100002)(316002)(81166007)(356005)(54906003)(5660300002)(8676002)(70586007)(55016003)(70206006)(4326008)(36756003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2022 12:15:58.9903 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 40705087-2d3d-406d-275d-08d9fb7d3eb7 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.235]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT035.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB5957 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 Sometimes net/mlx5 devices did not detect link status change to "up". Each shared device was monitoring IBV_EVENT_PORT_{ACTIVE,ERR} and queried the link status upon receiving the event. IBV_EVENT_PORT_ACTIVE is delivered when the logical link status (UP flag) is set, but the physical link status (RUNNING flag) may be down at that time, in which case the new link status would be erroneously considered down. IBV interface is insufficient for the task. Monitor interface events using Netlink. Fixes: 198a3c339a8f ("mlx5: handle link status interrupts") Cc: stable@dpdk.org Signed-off-by: Dmitry Kozlyuk Reviewed-by: Viacheslav Ovsiienko --- Coverity complains about unchecked rte_intr_fd/type_set() return values. That would be useless, because rte_intr_handle is in a known state. drivers/net/mlx5/linux/mlx5_ethdev_os.c | 63 ++++++++++++++++++++----- drivers/net/mlx5/linux/mlx5_os.c | 55 +++++++++++++++++++++ drivers/net/mlx5/mlx5.c | 1 + drivers/net/mlx5/mlx5.h | 3 ++ drivers/net/mlx5/mlx5_trigger.c | 12 ++++- 5 files changed, 120 insertions(+), 14 deletions(-) diff --git a/drivers/net/mlx5/linux/mlx5_ethdev_os.c b/drivers/net/mlx5/linux/mlx5_ethdev_os.c index c19825ee52..8fe73f1adb 100644 --- a/drivers/net/mlx5/linux/mlx5_ethdev_os.c +++ b/drivers/net/mlx5/linux/mlx5_ethdev_os.c @@ -38,6 +38,7 @@ #include #include #include +#include #include "mlx5.h" #include "mlx5_rxtx.h" @@ -760,6 +761,56 @@ mlx5_dev_interrupt_device_fatal(struct mlx5_dev_ctx_shared *sh) } } +static void +mlx5_dev_interrupt_nl_cb(struct nlmsghdr *hdr, void *cb_arg) +{ + struct mlx5_dev_ctx_shared *sh = cb_arg; + uint32_t i; + uint32_t if_index; + + if (mlx5_nl_parse_link_status_update(hdr, &if_index) < 0) + return; + for (i = 0; i < sh->max_port; i++) { + struct mlx5_dev_shared_port *port = &sh->port[i]; + struct rte_eth_dev *dev; + struct mlx5_priv *priv; + + if (port->nl_ih_port_id >= RTE_MAX_ETHPORTS) + continue; + dev = &rte_eth_devices[port->nl_ih_port_id]; + /* Probing may initiate an LSC before configuration is done. */ + if (dev->data->dev_configured && + !dev->data->dev_conf.intr_conf.lsc) + break; + priv = dev->data->dev_private; + if (priv->if_index == if_index) { + /* Block logical LSC events. */ + uint16_t prev_status = dev->data->dev_link.link_status; + + if (mlx5_link_update(dev, 0) < 0) + DRV_LOG(ERR, "Failed to update link status: %s", + rte_strerror(rte_errno)); + else if (prev_status != dev->data->dev_link.link_status) + rte_eth_dev_callback_process + (dev, RTE_ETH_EVENT_INTR_LSC, NULL); + break; + } + } +} + +void +mlx5_dev_interrupt_handler_nl(void *arg) +{ + struct mlx5_dev_ctx_shared *sh = arg; + int nlsk_fd = rte_intr_fd_get(sh->intr_handle_nl); + + if (nlsk_fd < 0) + return; + if (mlx5_nl_read_events(nlsk_fd, mlx5_dev_interrupt_nl_cb, sh) < 0) + DRV_LOG(ERR, "Failed to process Netlink events: %s", + rte_strerror(rte_errno)); +} + /** * Handle shared asynchronous events the NIC (removal event * and link status change). Supports multiport IB device. @@ -823,18 +874,6 @@ mlx5_dev_interrupt_handler(void *cb_arg) tmp = sh->port[tmp - 1].ih_port_id; dev = &rte_eth_devices[tmp]; MLX5_ASSERT(dev); - if ((event.event_type == IBV_EVENT_PORT_ACTIVE || - event.event_type == IBV_EVENT_PORT_ERR) && - dev->data->dev_conf.intr_conf.lsc) { - mlx5_glue->ack_async_event(&event); - if (mlx5_link_update(dev, 0) == -EAGAIN) { - usleep(0); - continue; - } - rte_eth_dev_callback_process - (dev, RTE_ETH_EVENT_INTR_LSC, NULL); - continue; - } DRV_LOG(DEBUG, "port %u cannot handle an unknown event (type %d)", dev->data->port_id, event.event_type); diff --git a/drivers/net/mlx5/linux/mlx5_os.c b/drivers/net/mlx5/linux/mlx5_os.c index 17e7144cc9..29a4890d14 100644 --- a/drivers/net/mlx5/linux/mlx5_os.c +++ b/drivers/net/mlx5/linux/mlx5_os.c @@ -2495,6 +2495,40 @@ mlx5_os_net_cleanup(void) mlx5_pmd_socket_uninit(); } +static int +mlx5_os_dev_shared_handler_install_lsc(struct mlx5_dev_ctx_shared *sh) +{ + int nlsk_fd, flags, ret; + + nlsk_fd = mlx5_nl_init(NETLINK_ROUTE, RTMGRP_LINK); + if (nlsk_fd < 0) { + DRV_LOG(ERR, "Failed to create a socket for Netlink events: %s", + rte_strerror(rte_errno)); + return -1; + } + flags = fcntl(nlsk_fd, F_GETFL); + ret = fcntl(nlsk_fd, F_SETFL, flags | O_NONBLOCK); + if (ret != 0) { + DRV_LOG(ERR, "Failed to make Netlink event socket non-blocking: %s", + strerror(errno)); + rte_errno = errno; + goto error; + } + rte_intr_type_set(sh->intr_handle_nl, RTE_INTR_HANDLE_EXT); + rte_intr_fd_set(sh->intr_handle_nl, nlsk_fd); + if (rte_intr_callback_register(sh->intr_handle_nl, + mlx5_dev_interrupt_handler_nl, + sh) != 0) { + DRV_LOG(ERR, "Failed to register Netlink events interrupt"); + rte_intr_fd_set(sh->intr_handle_nl, -1); + goto error; + } + return 0; +error: + close(nlsk_fd); + return -1; +} + /** * Install shared asynchronous device events handler. * This function is implemented to support event sharing @@ -2532,6 +2566,18 @@ mlx5_os_dev_shared_handler_install(struct mlx5_dev_ctx_shared *sh) rte_intr_fd_set(sh->intr_handle, -1); } } + sh->intr_handle_nl = rte_intr_instance_alloc + (RTE_INTR_INSTANCE_F_SHARED); + if (sh->intr_handle_nl == NULL) { + DRV_LOG(ERR, "Fail to allocate intr_handle"); + rte_errno = ENOMEM; + return; + } + rte_intr_fd_set(sh->intr_handle_nl, -1); + if (mlx5_os_dev_shared_handler_install_lsc(sh) < 0) { + DRV_LOG(INFO, "Fail to install the shared Netlink event handler."); + rte_intr_fd_set(sh->intr_handle_nl, -1); + } if (sh->cdev->config.devx) { #ifdef HAVE_IBV_DEVX_ASYNC sh->intr_handle_devx = @@ -2579,10 +2625,19 @@ mlx5_os_dev_shared_handler_install(struct mlx5_dev_ctx_shared *sh) void mlx5_os_dev_shared_handler_uninstall(struct mlx5_dev_ctx_shared *sh) { + int nlsk_fd; + if (rte_intr_fd_get(sh->intr_handle) >= 0) mlx5_intr_callback_unregister(sh->intr_handle, mlx5_dev_interrupt_handler, sh); rte_intr_instance_free(sh->intr_handle); + nlsk_fd = rte_intr_fd_get(sh->intr_handle_nl); + if (nlsk_fd >= 0) { + mlx5_intr_callback_unregister + (sh->intr_handle_nl, mlx5_dev_interrupt_handler_nl, sh); + close(nlsk_fd); + } + rte_intr_instance_free(sh->intr_handle_nl); #ifdef HAVE_IBV_DEVX_ASYNC if (rte_intr_fd_get(sh->intr_handle_devx) >= 0) rte_intr_callback_unregister(sh->intr_handle_devx, diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index 74841caaf9..09cd1367db 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -1457,6 +1457,7 @@ mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn, for (i = 0; i < sh->max_port; i++) { sh->port[i].ih_port_id = RTE_MAX_ETHPORTS; sh->port[i].devx_ih_port_id = RTE_MAX_ETHPORTS; + sh->port[i].nl_ih_port_id = RTE_MAX_ETHPORTS; } if (sh->cdev->config.devx) { sh->td = mlx5_devx_cmd_create_td(sh->cdev->ctx); diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index 9a4aff97cb..0f0045a2b5 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -637,6 +637,7 @@ struct mlx5_age_info { struct mlx5_dev_shared_port { uint32_t ih_port_id; uint32_t devx_ih_port_id; + uint32_t nl_ih_port_id; /* * Interrupt handler port_id. Used by shared interrupt * handler to find the corresponding rte_eth device @@ -1239,6 +1240,7 @@ struct mlx5_dev_ctx_shared { /* Shared interrupt handler section. */ struct rte_intr_handle *intr_handle; /* Interrupt handler for device. */ struct rte_intr_handle *intr_handle_devx; /* DEVX interrupt handler. */ + struct rte_intr_handle *intr_handle_nl; /* Netlink interrupt handler. */ void *devx_comp; /* DEVX async comp obj. */ struct mlx5_devx_obj *tis[16]; /* TIS object. */ struct mlx5_devx_obj *td; /* Transport domain. */ @@ -1666,6 +1668,7 @@ int mlx5_dev_set_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf); void mlx5_dev_interrupt_handler(void *arg); void mlx5_dev_interrupt_handler_devx(void *arg); +void mlx5_dev_interrupt_handler_nl(void *arg); int mlx5_set_link_down(struct rte_eth_dev *dev); int mlx5_set_link_up(struct rte_eth_dev *dev); int mlx5_is_removed(struct rte_eth_dev *dev); diff --git a/drivers/net/mlx5/mlx5_trigger.c b/drivers/net/mlx5/mlx5_trigger.c index fe8b42c414..c68b32cf14 100644 --- a/drivers/net/mlx5/mlx5_trigger.c +++ b/drivers/net/mlx5/mlx5_trigger.c @@ -1207,11 +1207,18 @@ mlx5_dev_start(struct rte_eth_dev *dev) priv->sh->port[priv->dev_port - 1].ih_port_id = (uint32_t)dev->data->port_id; } else { - DRV_LOG(INFO, "port %u starts without LSC and RMV interrupts.", + DRV_LOG(INFO, "port %u starts without RMV interrupts.", dev->data->port_id); - dev->data->dev_conf.intr_conf.lsc = 0; dev->data->dev_conf.intr_conf.rmv = 0; } + if (rte_intr_fd_get(priv->sh->intr_handle_nl) >= 0) { + priv->sh->port[priv->dev_port - 1].nl_ih_port_id = + (uint32_t)dev->data->port_id; + } else { + DRV_LOG(INFO, "port %u starts without LSC interrupts.", + dev->data->port_id); + dev->data->dev_conf.intr_conf.lsc = 0; + } if (rte_intr_fd_get(priv->sh->intr_handle_devx) >= 0) priv->sh->port[priv->dev_port - 1].devx_ih_port_id = (uint32_t)dev->data->port_id; @@ -1263,6 +1270,7 @@ mlx5_dev_stop(struct rte_eth_dev *dev) mlx5_rx_intr_vec_disable(dev); priv->sh->port[priv->dev_port - 1].ih_port_id = RTE_MAX_ETHPORTS; priv->sh->port[priv->dev_port - 1].devx_ih_port_id = RTE_MAX_ETHPORTS; + priv->sh->port[priv->dev_port - 1].nl_ih_port_id = RTE_MAX_ETHPORTS; mlx5_txq_stop(dev); mlx5_rxq_stop(dev); if (priv->obj_ops.lb_dummy_queue_release) -- 2.25.1