Linux Documentation
 help / color / mirror / Atom feed
From: Shay Drori <shayd@nvidia.com>
To: Stefan Metzmacher <metze@samba.org>, <netdev@vger.kernel.org>
Cc: Saeed Mahameed <saeedm@nvidia.com>,
	Leon Romanovsky <leon@kernel.org>,
	Tariq Toukan <tariqt@nvidia.com>, Mark Bloch <mbloch@nvidia.com>,
	<linux-rdma@vger.kernel.org>, Jiri Pirko <jiri@resnulli.us>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	"Jakub Kicinski" <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
	Willem de Bruijn <willemb@google.com>,
	Jonathan Corbet <corbet@lwn.net>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Randy Dunlap <rdunlap@infradead.org>,
	Andrew Lunn <andrew+netdev@lunn.ch>, <linux-doc@vger.kernel.org>
Subject: Re: [PATCH net-next 2/3] net/mlx5: support the enable_rdma devlink param in runtime cmode
Date: Thu, 3 Dec 2026 16:37:29 +0200	[thread overview]
Message-ID: <313d066f-b375-4b21-ac30-bfd26bf602d8@nvidia.com> (raw)
In-Reply-To: <1541f82d368a2a364c6acf1fc1334c2a5307d8a3.1796076486.git.metze@samba.org>


On 01/12/2026 0:09, Stefan Metzmacher wrote:
> External email: Use caution opening links or attachments
> 
> 
> The enable_rdma devlink param controls whether the RDMA auxiliary
> device (mlx5_ib) is instantiated for a function, but only in
> driverinit cmode. Changing it requires a devlink reload, which also
> unregisters the netdev, so its addresses, routes and other
> configuration are lost.
> 
> Add the runtime cmode, which unplugs or plugs only the RDMA auxiliary
> device of the function and leaves the netdev alone:
> 
>    devlink dev param set pci/0000:03:00.0 name enable_rdma \
>            value false cmode runtime
> 
> This has the same effect as unloading mlx5_ib, but only for this
> function, i.e. port. For an Ethernet port the RoCE state of the NIC
> vport is disabled again, so RoCEv2 packets reach the netdev and e.g.
> rxe can be used on it. It also works for a port in InfiniBand mode.


This isn't the case here. The RDMA function is an auxiliary device,
and its driver can already be unbound per function via sysfs, leaving
the netdev alone:

   echo mlx5_core.rdma.0 > /sys/bus/auxiliary/drivers/mlx5_ib.rdma/unbind

is there some special reason to add a devlink runtime knob that
duplicates auxiliary driver core bind/unbind?

Thanks
Shay

> 
> Enabling it at runtime requires it to be enabled in driverinit cmode,
> and a reload resets it to the driverinit value. The state is kept in
> the new dev->priv.rdma_runtime_disabled, which mlx5_devlink_reload_up()
> resets. The runtime cmode is refused in switchdev or multiport mode,
> where the RDMA device isn't the plain one of this function, and while
> LAG is active. A RoCE LAG activated later isn't affected by it.
> 
> Cc: Saeed Mahameed <saeedm@nvidia.com>
> Cc: Leon Romanovsky <leon@kernel.org>
> Cc: Tariq Toukan <tariqt@nvidia.com>
> Cc: Mark Bloch <mbloch@nvidia.com>
> Cc: netdev@vger.kernel.org
> Cc: linux-rdma@vger.kernel.org
> Cc: Jiri Pirko <jiri@resnulli.us>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@kernel.org>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: Simon Horman <horms@kernel.org>
> Cc: Willem de Bruijn <willemb@google.com>
> Cc: Jonathan Corbet <corbet@lwn.net>
> Cc: Shuah Khan <skhan@linuxfoundation.org>
> Cc: Randy Dunlap <rdunlap@infradead.org>
> Cc: Andrew Lunn <andrew+netdev@lunn.ch>
> Cc: linux-doc@vger.kernel.org
> Signed-off-by: Stefan Metzmacher <metze@samba.org>
> ---
>   Documentation/networking/devlink/mlx5.rst     | 11 +++
>   drivers/net/ethernet/mellanox/mlx5/core/dev.c | 10 ++-
>   .../net/ethernet/mellanox/mlx5/core/devlink.c | 70 ++++++++++++++++++-
>   .../ethernet/mellanox/mlx5/core/mlx5_core.h   |  1 +
>   include/linux/mlx5/driver.h                   |  2 +
>   5 files changed, 91 insertions(+), 3 deletions(-)
> 
> diff --git a/Documentation/networking/devlink/mlx5.rst b/Documentation/networking/devlink/mlx5.rst
> index 9421c89951a0..382383d05b64 100644
> --- a/Documentation/networking/devlink/mlx5.rst
> +++ b/Documentation/networking/devlink/mlx5.rst
> @@ -23,6 +23,17 @@ Parameters
>          device support for RoCE capability. Otherwise, the control occurs in the
>          driver stack. When RoCE is disabled at the driver level, only raw
>          ethernet QPs are supported.
> +   * - ``enable_rdma``
> +     - driverinit, runtime
> +     - Boolean
> +     - Controls whether the RDMA auxiliary device (mlx5_ib) is instantiated
> +       for the function. In runtime mode it is unplugged or plugged again
> +       without reloading the function, so the netdev and its configuration
> +       stay. Enabling it in runtime mode requires it to be enabled in
> +       driverinit mode, and a reload resets the runtime mode to the
> +       driverinit value. Not supported in switchdev or multiport mode or
> +       while LAG is active. A RoCE LAG activated later is not affected by
> +       the runtime value of its functions.
>      * - ``io_eq_size``
>        - driverinit
>        - The range is between 64 and 4096.
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/dev.c b/drivers/net/ethernet/mellanox/mlx5/core/dev.c
> index df2e3ad01819..a9aa12dabb70 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/dev.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/dev.c
> @@ -193,7 +193,7 @@ bool mlx5_rdma_supported(struct mlx5_core_dev *dev)
>          return true;
>   }
> 
> -static bool is_ib_enabled(struct mlx5_core_dev *dev)
> +bool mlx5_rdma_driverinit_enabled(struct mlx5_core_dev *dev)
>   {
>          union devlink_param_value val;
>          int err;
> @@ -204,6 +204,14 @@ static bool is_ib_enabled(struct mlx5_core_dev *dev)
>          return err ? false : val.vbool;
>   }
> 
> +static bool is_ib_enabled(struct mlx5_core_dev *dev)
> +{
> +       if (dev->priv.rdma_runtime_disabled)
> +               return false;
> +
> +       return mlx5_rdma_driverinit_enabled(dev);
> +}
> +
>   static bool is_dpll_supported(struct mlx5_core_dev *dev)
>   {
>          if (!IS_ENABLED(CONFIG_MLX5_DPLL))
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/devlink.c b/drivers/net/ethernet/mellanox/mlx5/core/devlink.c
> index 30a97e48dda7..94bab50cf22c 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/devlink.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/devlink.c
> @@ -250,6 +250,8 @@ static int mlx5_devlink_reload_up(struct devlink *devlink, enum devlink_reload_a
>          *actions_performed = BIT(action);
>          switch (action) {
>          case DEVLINK_RELOAD_ACTION_DRIVER_REINIT:
> +               /* a reload resets enable_rdma to its driverinit value */
> +               dev->priv.rdma_runtime_disabled = false;
>                  if (mlx5_dev_is_lightweight(dev)) {
>                          mlx5_fw_reporters_create(dev);
>                          return mlx5_init_one_devl_locked(dev);
> @@ -261,6 +263,7 @@ static int mlx5_devlink_reload_up(struct devlink *devlink, enum devlink_reload_a
>                          break;
>                  /* On fw_activate action, also driver is reloaded and reinit performed */
>                  *actions_performed |= BIT(DEVLINK_RELOAD_ACTION_DRIVER_REINIT);
> +               dev->priv.rdma_runtime_disabled = false;
>                  ret = mlx5_load_one_devl_locked(dev, true);
>                  if (ret)
>                          return ret;
> @@ -793,9 +796,72 @@ static int mlx5_devlink_enable_rdma_validate(struct devlink *devlink, u32 id,
>          return 0;
>   }
> 
> +static int mlx5_devlink_enable_rdma_get(struct devlink *devlink, u32 id,
> +                                       struct devlink_param_gset_ctx *ctx,
> +                                       struct netlink_ext_ack *extack)
> +{
> +       struct mlx5_core_dev *dev = devlink_priv(devlink);
> +
> +       ctx->val.vbool = mlx5_rdma_driverinit_enabled(dev) &&
> +                        !dev->priv.rdma_runtime_disabled;
> +
> +       return 0;
> +}
> +
> +/*
> + * In runtime cmode the RDMA auxiliary device of this function is
> + * unplugged or plugged again, without reloading the function, so the
> + * netdev and its configuration stay. Unplugging it has the same effect
> + * as unloading mlx5_ib for this function only, e.g. the RoCE state of
> + * the NIC vport is disabled, so RoCEv2 packets reach the netdev.
> + *
> + * A reload resets it to the value of the driverinit cmode, see
> + * mlx5_devlink_reload_up().
> + */
> +static int mlx5_devlink_enable_rdma_set(struct devlink *devlink, u32 id,
> +                                       struct devlink_param_gset_ctx *ctx,
> +                                       struct netlink_ext_ack *extack)
> +{
> +       struct mlx5_core_dev *dev = devlink_priv(devlink);
> +       bool disable = !ctx->val.vbool;
> +       int err;
> +
> +       if (!disable && !mlx5_rdma_driverinit_enabled(dev)) {
> +               NL_SET_ERR_MSG_MOD(extack,
> +                                  "RDMA is disabled in driverinit cmode, enable it there and reload");
> +               return -EOPNOTSUPP;
> +       }
> +
> +       if (dev->priv.rdma_runtime_disabled == disable)
> +               return 0;
> +       if (!mlx5_rdma_supported(dev)) {
> +               NL_SET_ERR_MSG_MOD(extack,
> +                                  "RDMA can't be changed at runtime in switchdev or multiport mode");
> +               return -EOPNOTSUPP;
> +       }
> +       if (mlx5_lag_is_active(dev)) {
> +               NL_SET_ERR_MSG_MOD(extack, "RDMA can't be changed at runtime while LAG is active");
> +               return -EBUSY;
> +       }
> +
> +       mlx5_devcom_comp_lock(dev->priv.hca_devcom_comp);
> +       dev->priv.rdma_runtime_disabled = disable;
> +       err = mlx5_rescan_drivers_locked(dev);
> +       if (err && !disable) {
> +               dev->priv.rdma_runtime_disabled = true;
> +               mlx5_rescan_drivers_locked(dev);
> +       }
> +       mlx5_devcom_comp_unlock(dev->priv.hca_devcom_comp);
> +
> +       return err;
> +}
> +
>   static const struct devlink_param mlx5_devlink_rdma_params[] = {
> -       DEVLINK_PARAM_GENERIC(ENABLE_RDMA, BIT(DEVLINK_PARAM_CMODE_DRIVERINIT),
> -                             NULL, NULL, mlx5_devlink_enable_rdma_validate),
> +       DEVLINK_PARAM_GENERIC(ENABLE_RDMA, BIT(DEVLINK_PARAM_CMODE_DRIVERINIT) |
> +                             BIT(DEVLINK_PARAM_CMODE_RUNTIME),
> +                             mlx5_devlink_enable_rdma_get,
> +                             mlx5_devlink_enable_rdma_set,
> +                             mlx5_devlink_enable_rdma_validate),
>   };
> 
>   static int mlx5_devlink_rdma_params_register(struct devlink *devlink)
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h b/drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h
> index d84d0424d04e..08bb86d649a9 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h
> @@ -473,6 +473,7 @@ static inline u32 mlx5_sriov_get_vf_total_msix(struct pci_dev *pdev)
> 
>   bool mlx5_eth_supported(struct mlx5_core_dev *dev);
>   bool mlx5_rdma_supported(struct mlx5_core_dev *dev);
> +bool mlx5_rdma_driverinit_enabled(struct mlx5_core_dev *dev);
>   bool mlx5_vnet_supported(struct mlx5_core_dev *dev);
>   bool mlx5_same_hw_devs(struct mlx5_core_dev *dev, struct mlx5_core_dev *peer_dev);
>   int mlx5_cmd_allow_other_vhca_access(struct mlx5_core_dev *dev,
> diff --git a/include/linux/mlx5/driver.h b/include/linux/mlx5/driver.h
> index b6efc01a8e36..b62d519eba8c 100644
> --- a/include/linux/mlx5/driver.h
> +++ b/include/linux/mlx5/driver.h
> @@ -615,6 +615,8 @@ struct mlx5_priv {
>          struct mlx5_core_sriov  sriov;
>          struct mlx5_lag         *lag;
>          u32                     flags;
> +       /* RDMA disabled via devlink enable_rdma in runtime cmode */
> +       bool                    rdma_runtime_disabled;
>          struct mlx5_devcom_dev  *devc;
>          struct mlx5_devcom_comp_dev *hca_devcom_comp;
>          struct mlx5_fw_reset    *fw_reset;
> --
> 2.43.0
> 
> 


  reply	other threads:[~2026-12-03 14:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 22:09 [PATCH net-next 0/3] devlink: support the enable_rdma param in runtime cmode for cxgb4, mlx5 and ice Stefan Metzmacher
2026-11-30 22:09 ` [PATCH net-next 1/3] cxgb4: support the enable_rdma devlink param in runtime cmode Stefan Metzmacher
2026-11-30 22:09 ` [PATCH net-next 2/3] net/mlx5: " Stefan Metzmacher
2026-12-03 14:37   ` Shay Drori [this message]
2026-11-30 22:10 ` [PATCH net-next 3/3] ice: " Stefan Metzmacher
2026-12-01 13:36   ` Przemek Kitszel

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=313d066f-b375-4b21-ac30-bfd26bf602d8@nvidia.com \
    --to=shayd@nvidia.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=mbloch@nvidia.com \
    --cc=metze@samba.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rdunlap@infradead.org \
    --cc=saeedm@nvidia.com \
    --cc=skhan@linuxfoundation.org \
    --cc=tariqt@nvidia.com \
    --cc=willemb@google.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