From: Tariq Toukan <tariqt@nvidia.com>
To: Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, <netdev@vger.kernel.org>,
Paolo Abeni <pabeni@redhat.com>
Cc: Bobby Eshleman <bobbyeshleman@meta.com>,
Carolina Jubran <cjubran@nvidia.com>,
Cosmin Ratiu <cratiu@nvidia.com>,
Daniel Borkmann <daniel@iogearbox.net>,
David Wei <dw@davidwei.uk>, Dragos Tatulea <dtatulea@nvidia.com>,
Erfan Sharafzadeh <erfansh@meta.com>,
Gal Pressman <gal@nvidia.com>,
Jacob Keller <Jacob.e.keller@intel.com>,
Kaifeng Wang <kaifengw@google.com>,
Leon Romanovsky <leon@kernel.org>,
open list <linux-kernel@vger.kernel.org>,
<linux-rdma@vger.kernel.org>, Mark Bloch <mbloch@nvidia.com>,
Matt Fleming <mfleming@cloudflare.com>,
Mina Almasry <almasrymina@google.com>,
Nikolay Aleksandrov <razor@blackwall.org>,
"Saeed Mahameed" <saeedm@nvidia.com>,
Simon Horman <horms@kernel.org>,
"Stanislav Fomichev" <sdf@fomichev.me>,
Stanislav Fomichev <sdf.kernel@gmail.com>,
"Tariq Toukan" <tariqt@nvidia.com>, William Tu <witu@nvidia.com>
Subject: [PATCH net-next V2 12/13] net/mlx5e: Disable data direct on data direct device unbind
Date: Tue, 10 Nov 2026 20:38:25 +0200 [thread overview]
Message-ID: <20261110183826.2927274-13-tariqt@nvidia.com> (raw)
In-Reply-To: <20261110183826.2927274-1-tariqt@nvidia.com>
From: Dragos Tatulea <dtatulea@nvidia.com>
To prevent invalid accesses after the data direct device is unbound,
stop the netdev and drop the providers using the unbound DMA device. To
prevent further use disable the private flag.
Also release the providers during suspend because the notifier
is disabled at that point and a data direct device unbind would
go unnoticed. This would result in dangling references to the
unbound DMA device.
FW reset, devlink reload and health recovery are not affected: they
unregister the netdev, which releases the memory providers and dmabuf
bindings.
Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com>
Reviewed-by: Cosmin Ratiu <cratiu@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
.../ethernet/mellanox/mlx5/core/data_direct.c | 4 +-
.../net/ethernet/mellanox/mlx5/core/en_main.c | 67 ++++++++++++++++++-
2 files changed, 68 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/data_direct.c b/drivers/net/ethernet/mellanox/mlx5/core/data_direct.c
index 7db94b8a5b79..246a03f44afd 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/data_direct.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/data_direct.c
@@ -198,9 +198,11 @@ static void mlx5_data_direct_bind(struct mlx5_data_direct_registration *reg,
static void
mlx5_data_direct_do_unbind(struct mlx5_data_direct_registration *reg)
{
+ struct mlx5_data_direct_dev *dev = reg->dd.dev;
+
WRITE_ONCE(reg->dd.dev, NULL);
blocking_notifier_call_chain(®->users, MLX5_DATA_DIRECT_UNBIND,
- NULL);
+ dev);
}
int mlx5_data_direct_init(struct mlx5_core_dev *mdev)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
index ebd41f24330d..63d91ef0dda8 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
@@ -6170,9 +6170,53 @@ static int mlx5e_data_direct_event(struct notifier_block *nb,
{
struct mlx5e_priv *priv = container_of(nb, struct mlx5e_priv,
data_direct_nb);
+ struct mlx5_data_direct_dev *dd_dev = data;
+ struct net_device *netdev = priv->netdev;
+ struct mlx5e_params new_params;
+ bool enabled, reopen;
+ int err;
+
+ if (action != MLX5_DATA_DIRECT_UNBIND)
+ return NOTIFY_DONE;
+
+ rtnl_lock();
+ netdev_lock(netdev);
+
+ mutex_lock(&priv->state_lock);
+ enabled = MLX5E_GET_PFLAG(&priv->channels.params,
+ MLX5E_PFLAG_DATA_DIRECT);
+ mutex_unlock(&priv->state_lock);
+ if (!enabled)
+ goto out;
+
+ reopen = netif_running(netdev);
+ netif_close(netdev);
+
+ err = netdev_unbind_dma_dev(netdev, dd_dev->device);
+ if (WARN_ON_ONCE(err)) {
+ netdev_err(netdev, "Failed to unbind dma device, won't reopen netdev, err=%d\n",
+ err);
+ goto out;
+ }
+
+ mutex_lock(&priv->state_lock);
+ new_params = priv->channels.params;
+ MLX5E_SET_PFLAG(&new_params, MLX5E_PFLAG_DATA_DIRECT, false);
+ mlx5e_safe_switch_params(priv, &new_params, NULL, NULL, false);
+ mutex_unlock(&priv->state_lock);
+
+ netdev_info(netdev, "data_direct device unbound, disabled data_direct\n");
- if (action == MLX5_DATA_DIRECT_UNBIND)
- mlx5_core_dbg(priv->mdev, "data direct device unbound\n");
+ if (reopen) {
+ err = netif_open(netdev, NULL);
+ if (err)
+ netdev_err(netdev, "Failed to reopen after data_direct unbind, err=%d\n",
+ err);
+ }
+
+out:
+ netdev_unlock(netdev);
+ rtnl_unlock();
return NOTIFY_OK;
}
@@ -6407,6 +6451,24 @@ static int mlx5e_nic_enable(struct mlx5e_priv *priv)
return err;
}
+static void mlx5e_data_direct_unbind_dev(struct mlx5e_priv *priv)
+{
+ struct mlx5_data_direct_dev *dd_dev;
+ bool enabled;
+
+ dd_dev = mlx5_data_direct_get_dev(priv->mdev->data_direct);
+ if (!dd_dev)
+ return;
+
+ mutex_lock(&priv->state_lock);
+ enabled = MLX5E_GET_PFLAG(&priv->channels.params,
+ MLX5E_PFLAG_DATA_DIRECT);
+ mutex_unlock(&priv->state_lock);
+ if (enabled)
+ WARN_ON_ONCE(netdev_unbind_dma_dev(priv->netdev,
+ dd_dev->device));
+}
+
static void mlx5e_nic_disable(struct mlx5e_priv *priv)
{
struct mlx5_core_dev *mdev = priv->mdev;
@@ -6424,6 +6486,7 @@ static void mlx5e_nic_disable(struct mlx5e_priv *priv)
mlx5e_close_trap(priv->en_trap);
priv->en_trap = NULL;
}
+ mlx5e_data_direct_unbind_dev(priv);
netdev_unlock(priv->netdev);
rtnl_unlock();
--
2.44.0
next prev parent reply other threads:[~2026-11-10 18:40 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 18:38 [PATCH net-next V2 00/13] net/mlx5e: Add netdev support for data direct Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 01/13] net/mlx5: Log the data direct to PF device mapping Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 02/13] net/mlx5: Detach auxiliary devices on attach failure during load Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 03/13] net/mlx5e: Register supported netdevs as data direct users Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 04/13] net/mlx5e: Pre-calculate UMR padding and entry size Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 05/13] net/mlx5e: Add data direct ethtool private flag Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 06/13] net/mlx5e: Add data direct RX infrastructure Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 07/13] net/mlx5e: SHAMPO, Use page_pool DMA sync helper for SKB frags Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 08/13] net/mlx5e: Add data direct TX infrastructure Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 09/13] net/mlx5e: Use the correct DMA dev when data_direct is enabled Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 10/13] net: devmem: add netdev_has_dmabuf_binding() helper Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 11/13] net: add netdev_unbind_dma_dev() helper Tariq Toukan
2026-11-10 18:38 ` Tariq Toukan [this message]
2026-11-10 18:38 ` [PATCH net-next V2 13/13] net/mlx5e: Enable the data direct netdev feature Tariq Toukan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261110183826.2927274-13-tariqt@nvidia.com \
--to=tariqt@nvidia.com \
--cc=Jacob.e.keller@intel.com \
--cc=almasrymina@google.com \
--cc=andrew+netdev@lunn.ch \
--cc=bobbyeshleman@meta.com \
--cc=cjubran@nvidia.com \
--cc=cratiu@nvidia.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=dtatulea@nvidia.com \
--cc=dw@davidwei.uk \
--cc=edumazet@kernel.org \
--cc=erfansh@meta.com \
--cc=gal@nvidia.com \
--cc=horms@kernel.org \
--cc=kaifengw@google.com \
--cc=kuba@kernel.org \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=mbloch@nvidia.com \
--cc=mfleming@cloudflare.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=razor@blackwall.org \
--cc=saeedm@nvidia.com \
--cc=sdf.kernel@gmail.com \
--cc=sdf@fomichev.me \
--cc=witu@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®