From patchwork Wed Aug 16 06:52:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 13354602 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2683FC04FDF for ; Wed, 16 Aug 2023 06:53:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234258AbjHPGwp (ORCPT ); Wed, 16 Aug 2023 02:52:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242207AbjHPGwi (ORCPT ); Wed, 16 Aug 2023 02:52:38 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7750B19A1 for ; Tue, 15 Aug 2023 23:52:37 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0E07563BD7 for ; Wed, 16 Aug 2023 06:52:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A724EC433C7; Wed, 16 Aug 2023 06:52:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692168756; bh=2AIWKp2sy/1XGCmuzq+BzxxsosNVLkqm9wiJBK2f824=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NXmpk9FHf7EZA3mi9USxU6WDzCuRwF2to9NXqyWAzJsb9WRaa7dO01/3UC+Wsf3zu ivKMSPJZs7cZEyz4r7XklvhO/BbZSUchaPrawzee71pwUmYeNa0Y2raSUOAooO2Skw ph+3YHjtz9vdf8BfuscQegL5IZju4YiF1e3eH79+dsLGuFZqgqHjO5TL03PJ3oXuGW /MH7uBj2vUf8VM7WS4LgN5eBUqp7USKqSNFd0RyK6W2Bs9JoI3lE0d5PVv8DhXN8wy IlR2ilZxHQecendin8FCkuUB9kzu4omxSzuQQ3nRR1PvOWAl00uJk6hWqutLgdwfjM KB+1BJztsMnrQ== From: Leon Romanovsky To: Jason Gunthorpe Cc: Mark Bloch , "David S. Miller" , Eric Dumazet , Jakub Kicinski , linux-rdma@vger.kernel.org, Mark Zhang , netdev@vger.kernel.org, Paolo Abeni , Saeed Mahameed Subject: [PATCH rdma-next 1/2] RDMA/mlx5: Get upper device only if device is lagged Date: Wed, 16 Aug 2023 09:52:23 +0300 Message-ID: <117b591f5e6e130aeccc871888084fb92fb43b5a.1692168533.git.leon@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Mark Bloch If the RDMA device isn't in LAG mode there is no need to try to get the upper device. Signed-off-by: Mark Bloch Signed-off-by: Leon Romanovsky --- drivers/infiniband/hw/mlx5/main.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c index f0b394ed7452..215d7b0add8f 100644 --- a/drivers/infiniband/hw/mlx5/main.c +++ b/drivers/infiniband/hw/mlx5/main.c @@ -195,12 +195,18 @@ static int mlx5_netdev_event(struct notifier_block *this, case NETDEV_CHANGE: case NETDEV_UP: case NETDEV_DOWN: { - struct net_device *lag_ndev = mlx5_lag_get_roce_netdev(mdev); struct net_device *upper = NULL; - if (lag_ndev) { - upper = netdev_master_upper_dev_get(lag_ndev); - dev_put(lag_ndev); + if (ibdev->lag_active) { + struct net_device *lag_ndev; + + lag_ndev = mlx5_lag_get_roce_netdev(mdev); + if (lag_ndev) { + upper = netdev_master_upper_dev_get(lag_ndev); + dev_put(lag_ndev); + } else { + goto done; + } } if (ibdev->is_rep) @@ -254,9 +260,11 @@ static struct net_device *mlx5_ib_get_netdev(struct ib_device *device, if (!mdev) return NULL; - ndev = mlx5_lag_get_roce_netdev(mdev); - if (ndev) - goto out; + if (ibdev->lag_active) { + ndev = mlx5_lag_get_roce_netdev(mdev); + if (ndev) + goto out; + } /* Ensure ndev does not disappear before we invoke dev_hold() */ From patchwork Wed Aug 16 06:52:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 13354601 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3FDBC41513 for ; Wed, 16 Aug 2023 06:53:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241085AbjHPGwo (ORCPT ); Wed, 16 Aug 2023 02:52:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242208AbjHPGwn (ORCPT ); Wed, 16 Aug 2023 02:52:43 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDAD719A1 for ; Tue, 15 Aug 2023 23:52:41 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6709564E24 for ; Wed, 16 Aug 2023 06:52:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48707C433C8; Wed, 16 Aug 2023 06:52:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692168760; bh=abWiWPKwcgaHPVQRZlXrDvbyWt7euJGqA6mcYi7jVrs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BFijh41P+NVInGCZcyfdxuBf//Px+ckUMXhH7J8rIx6rDJjNftufP8KaOabxNSxU7 dP0iw22bl4SxL/4LlTlrh8BWuvb8dC0VJk3ZwKIQOCDoRlYwppQ6Z/SR5bXYJUg/v8 3HOvfu4kCpElSjr2ExTJTzo1Mfeu3CXivpwRaYUdJYL62M/o5gxsfMNLFI7WbUJ9jD ZnhLPAx3krpbFIdN+A3AZ0Ime770idL/pEewkGzw4oZ0qWfCpsMhYNrSb15SFkan+W B87xC9OnaJT9Cak37It9O6F+iDgr83SjohhdPv9uwZCk71Kcd77S4H9zITqrlCJx++ MeHwUOkat4z+A== From: Leon Romanovsky To: Jason Gunthorpe Cc: Mark Bloch , Eric Dumazet , Jakub Kicinski , linux-rdma@vger.kernel.org, Mark Zhang , netdev@vger.kernel.org, Paolo Abeni , Saeed Mahameed Subject: [PATCH rdma-next 2/2] RDMA/mlx5: Send correct port events Date: Wed, 16 Aug 2023 09:52:24 +0300 Message-ID: <86a8473d0ccea1b66e59eb86457359be9005cfcb.1692168533.git.leon@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Mark Bloch When operating in switchdev mode and with an active LAG, the function mlx5_lag_get_roce_netdev() fails to return a valid net device as this function is designed specifically for RoCE LAGs. Consequently, this issue resulted in the driver sending incorrect event reports. To address this, a new API is introduced to properly obtain the net device. Additionally, some code logic is cleaned up during this modification. Signed-off-by: Mark Bloch Signed-off-by: Leon Romanovsky --- drivers/infiniband/hw/mlx5/main.c | 39 +++++++++++++++---- .../net/ethernet/mellanox/mlx5/core/lag/lag.c | 29 ++++++++++++++ include/linux/mlx5/driver.h | 2 + 3 files changed, 62 insertions(+), 8 deletions(-) diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c index 215d7b0add8f..8b98200bd94c 100644 --- a/drivers/infiniband/hw/mlx5/main.c +++ b/drivers/infiniband/hw/mlx5/main.c @@ -159,6 +159,29 @@ static struct mlx5_roce *mlx5_get_rep_roce(struct mlx5_ib_dev *dev, return NULL; } +static bool mlx5_netdev_send_event(struct mlx5_ib_dev *dev, + struct net_device *ndev, + struct net_device *upper, + struct mlx5_roce *roce) +{ + if (!dev->ib_active) + return false; + + /* Event is about our upper device */ + if (upper == ndev) + return true; + + /* RDMA device not in lag and not in switchdev */ + if (!dev->is_rep && !upper && ndev == roce->netdev) + return true; + + /* RDMA device in switchdev */ + if (dev->is_rep && ndev == roce->netdev) + return true; + + return false; +} + static int mlx5_netdev_event(struct notifier_block *this, unsigned long event, void *ptr) { @@ -200,7 +223,7 @@ static int mlx5_netdev_event(struct notifier_block *this, if (ibdev->lag_active) { struct net_device *lag_ndev; - lag_ndev = mlx5_lag_get_roce_netdev(mdev); + lag_ndev = mlx5_lag_get_netdev(mdev); if (lag_ndev) { upper = netdev_master_upper_dev_get(lag_ndev); dev_put(lag_ndev); @@ -209,13 +232,13 @@ static int mlx5_netdev_event(struct notifier_block *this, } } - if (ibdev->is_rep) + if (ibdev->is_rep) { roce = mlx5_get_rep_roce(ibdev, ndev, upper, &port_num); - if (!roce) - return NOTIFY_DONE; - if ((upper == ndev || - ((!upper || ibdev->is_rep) && ndev == roce->netdev)) && - ibdev->ib_active) { + if (!roce) + return NOTIFY_DONE; + } + + if (mlx5_netdev_send_event(ibdev, ndev, upper, roce)) { struct ib_event ibev = { }; enum ib_port_state port_state; @@ -260,7 +283,7 @@ static struct net_device *mlx5_ib_get_netdev(struct ib_device *device, if (!mdev) return NULL; - if (ibdev->lag_active) { + if (!ibdev->is_rep && ibdev->lag_active) { ndev = mlx5_lag_get_roce_netdev(mdev); if (ndev) goto out; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c index f0a074b2fcdf..83298e9addd3 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c @@ -1498,6 +1498,35 @@ struct net_device *mlx5_lag_get_roce_netdev(struct mlx5_core_dev *dev) } EXPORT_SYMBOL(mlx5_lag_get_roce_netdev); +struct net_device *mlx5_lag_get_netdev(struct mlx5_core_dev *dev) +{ + struct net_device *ndev = NULL; + struct mlx5_lag *ldev; + unsigned long flags; + int i; + + spin_lock_irqsave(&lag_lock, flags); + ldev = mlx5_lag_dev(dev); + + if (!(ldev && __mlx5_lag_is_active(ldev))) + goto unlock; + + for (i = 0; i < ldev->ports; i++) { + if (ldev->pf[i].dev == dev) { + ndev = ldev->pf[i].netdev; + break; + } + } + + if (ndev) + dev_hold(ndev); + +unlock: + spin_unlock_irqrestore(&lag_lock, flags); + return ndev; +} +EXPORT_SYMBOL(mlx5_lag_get_netdev); + u8 mlx5_lag_get_slave_port(struct mlx5_core_dev *dev, struct net_device *slave) { diff --git a/include/linux/mlx5/driver.h b/include/linux/mlx5/driver.h index 25d0528f9219..bc7e3a974f62 100644 --- a/include/linux/mlx5/driver.h +++ b/include/linux/mlx5/driver.h @@ -1160,6 +1160,8 @@ bool mlx5_lag_is_master(struct mlx5_core_dev *dev); bool mlx5_lag_is_shared_fdb(struct mlx5_core_dev *dev); bool mlx5_lag_is_mpesw(struct mlx5_core_dev *dev); struct net_device *mlx5_lag_get_roce_netdev(struct mlx5_core_dev *dev); + +struct net_device *mlx5_lag_get_netdev(struct mlx5_core_dev *dev); u8 mlx5_lag_get_slave_port(struct mlx5_core_dev *dev, struct net_device *slave); int mlx5_lag_query_cong_counters(struct mlx5_core_dev *dev,