* [PATCH net-next 0/2] net/mlx5: Add controller number to SF and VF phys_port_name
@ 2026-11-25 21:20 Tariq Toukan
2026-11-25 21:20 ` [PATCH net-next 1/2] net/mlx5: SF, Pass pfnum through the SF hardware-table allocation path Tariq Toukan
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Tariq Toukan @ 2026-11-25 21:20 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni
Cc: Carolina Jubran, Chris Mi, Gal Pressman, Kees Cook,
Leon Romanovsky, linux-rdma, Mark Bloch, Moshe Shemesh,
Or Har-Toov, Parav Pandit, Saeed Mahameed, Shay Drori,
Tariq Toukan
Hi,
This series by Chris adds the controller number to the phys_port_name of
SF and VF representors on the non-master PCI link of a BlueField-4
Socket-Direct topology.
Today the controller number is omitted from phys_port_name when it is 0.
In a BlueField-4 Socket-Direct topology there are two PCI links under a
single eswitch, and they have duplicate function numbers (pf num) and
SF/VF numbers. As a result, SFs/VFs on the two links end up with the
same phys_port_name, for example pf0sf0 on both, and cannot be told
apart.
Patch 1 is a preparation patch. It passes a pfnum parameter through the
SF hardware-table allocation and free call chain, and stores it on
struct mlx5_sf. This is plumbing only: pfnum is not used for hwc
selection yet, and the controller/pfnum validation is unchanged.
Patch 2 gives the non-master PCI link its own controller number, read
from the MLX5_PCI_PF_TYPE_QUERY_PF entry of QUERY_ESW_FUNCTIONS as
host_number + 1, so that its SFs/VFs display the controller prefix.
Since the self PF and a satellite PF share the same controller number,
pfnum is used to locate the right hwc table. With this, the SF on the
second link is named c4pf0sf0 instead of pf0sf0. A user can create an SF
with the device controller number either specified or omitted, and any
other controller number is rejected.
Regards,
Tariq
Chris Mi (2):
net/mlx5: SF, Pass pfnum through the SF hardware-table allocation path
net/mlx5: Add controller number for SF and ECVF phys_port_name
.../mellanox/mlx5/core/esw/devlink_port.c | 24 ++--
.../net/ethernet/mellanox/mlx5/core/eswitch.c | 117 ++++++++++++++++--
.../net/ethernet/mellanox/mlx5/core/eswitch.h | 22 +++-
.../mellanox/mlx5/core/eswitch_offloads.c | 16 ++-
.../mellanox/mlx5/core/lag/shared_fdb.c | 58 +++++++++
.../ethernet/mellanox/mlx5/core/sf/devlink.c | 58 +++++++--
.../ethernet/mellanox/mlx5/core/sf/hw_table.c | 49 +++++---
.../net/ethernet/mellanox/mlx5/core/sf/priv.h | 12 +-
8 files changed, 295 insertions(+), 61 deletions(-)
base-commit: 612848d37e68b858e15815175f1c5e609e09d719
--
2.44.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH net-next 1/2] net/mlx5: SF, Pass pfnum through the SF hardware-table allocation path
2026-11-25 21:20 [PATCH net-next 0/2] net/mlx5: Add controller number to SF and VF phys_port_name Tariq Toukan
@ 2026-11-25 21:20 ` Tariq Toukan
2026-11-25 21:20 ` [PATCH net-next 2/2] net/mlx5: Add controller number for SF and ECVF phys_port_name Tariq Toukan
2026-11-26 21:21 ` [PATCH net-next 0/2] net/mlx5: Add controller number to SF and VF phys_port_name sashiko-bot
2 siblings, 0 replies; 6+ messages in thread
From: Tariq Toukan @ 2026-11-25 21:20 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni
Cc: Carolina Jubran, Chris Mi, Gal Pressman, Kees Cook,
Leon Romanovsky, linux-rdma, Mark Bloch, Moshe Shemesh,
Or Har-Toov, Parav Pandit, Saeed Mahameed, Shay Drori,
Tariq Toukan
From: Chris Mi <cmi@nvidia.com>
Add a pfnum parameter to the SF allocation/free call chain and store
it on struct mlx5_sf as pf_num, set alongside controller in
mlx5_sf_alloc(), so free/dealloc can resolve the same hwc table that
was used at allocation time.
This is plumbing only. pfnum isn't used for hwc selection yet, and
controller/pfnum validation is unchanged. It prepares the SF hw-table
code to distinguish SFs created on the self PF from SFs created on a
satellite PF sharing the same controller number, implemented in
"net/mlx5: Add controller number for SF and ECVF phys_port_name"
later in this series.
Signed-off-by: Chris Mi <cmi@nvidia.com>
Reviewed-by: Parav Pandit <parav@nvidia.com>
Reviewed-by: Shay Drori <shayd@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
.../mellanox/mlx5/core/esw/devlink_port.c | 20 ++++++----
.../net/ethernet/mellanox/mlx5/core/eswitch.c | 6 ++-
.../net/ethernet/mellanox/mlx5/core/eswitch.h | 14 ++++---
.../mellanox/mlx5/core/eswitch_offloads.c | 9 +++--
.../ethernet/mellanox/mlx5/core/sf/devlink.c | 31 ++++++++++-----
.../ethernet/mellanox/mlx5/core/sf/hw_table.c | 39 +++++++++++--------
.../net/ethernet/mellanox/mlx5/core/sf/priv.h | 12 ++++--
7 files changed, 82 insertions(+), 49 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c b/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c
index fdc960ea5331..8b46634203b3 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c
@@ -148,16 +148,16 @@ static const struct devlink_port_ops mlx5_esw_pf_vf_dl_port_ops = {
.port_fn_max_io_eqs_set = mlx5_devlink_port_fn_max_io_eqs_set,
};
-static void mlx5_esw_offloads_sf_devlink_port_attrs_set(struct mlx5_eswitch *esw,
- struct devlink_port *dl_port,
- u32 controller, u32 sfnum)
+static void
+mlx5_esw_offloads_sf_devlink_port_attrs_set(struct mlx5_eswitch *esw,
+ struct devlink_port *dl_port,
+ u32 controller, u32 pfnum,
+ u32 sfnum)
{
struct mlx5_core_dev *dev = esw->dev;
struct netdev_phys_item_id ppid = {};
u32 hpf_ctrl;
- u16 pfnum;
- pfnum = mlx5_esw_sf_controller_to_pfnum(dev, controller);
hpf_ctrl = mlx5_esw_get_hpf_host_number(dev) + 1;
mlx5_esw_get_port_parent_id(dev, &ppid);
memcpy(dl_port->attrs.switch_id.id, &ppid.id[0], ppid.id_len);
@@ -166,11 +166,15 @@ static void mlx5_esw_offloads_sf_devlink_port_attrs_set(struct mlx5_eswitch *esw
controller == hpf_ctrl);
}
-int mlx5_esw_offloads_sf_devlink_port_init(struct mlx5_eswitch *esw, struct mlx5_vport *vport,
+int mlx5_esw_offloads_sf_devlink_port_init(struct mlx5_eswitch *esw,
+ struct mlx5_vport *vport,
struct mlx5_devlink_port *dl_port,
- u32 controller, u32 sfnum)
+ u32 controller, u32 pfnum,
+ u32 sfnum)
{
- mlx5_esw_offloads_sf_devlink_port_attrs_set(esw, &dl_port->dl_port, controller, sfnum);
+ mlx5_esw_offloads_sf_devlink_port_attrs_set(esw, &dl_port->dl_port,
+ controller, pfnum,
+ sfnum);
vport->dl_port = dl_port;
mlx5_devlink_port_init(dl_port, vport);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
index 76f808e06a88..8c2c55ba5c35 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
@@ -1370,7 +1370,8 @@ static void mlx5_eswitch_unload_pf_vf_vport(struct mlx5_eswitch *esw, u16 vport_
int mlx5_eswitch_load_sf_vport(struct mlx5_eswitch *esw, u16 vport_num,
enum mlx5_eswitch_vport_event enabled_events,
- struct mlx5_devlink_port *dl_port, u32 controller, u32 sfnum)
+ struct mlx5_devlink_port *dl_port,
+ u32 controller, u32 pfnum, u32 sfnum)
{
struct mlx5_vport *vport;
int err;
@@ -1379,7 +1380,8 @@ int mlx5_eswitch_load_sf_vport(struct mlx5_eswitch *esw, u16 vport_num,
if (IS_ERR(vport))
return PTR_ERR(vport);
- err = mlx5_esw_offloads_init_sf_rep(esw, vport, dl_port, controller, sfnum);
+ err = mlx5_esw_offloads_init_sf_rep(esw, vport, dl_port, controller,
+ pfnum, sfnum);
if (err)
return err;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
index 48eb6acc1e87..463855240032 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
@@ -872,9 +872,10 @@ void mlx5_esw_set_spec_source_port(struct mlx5_eswitch *esw,
int mlx5_esw_offloads_init_pf_vf_rep(struct mlx5_eswitch *esw, struct mlx5_vport *vport);
void mlx5_esw_offloads_cleanup_pf_vf_rep(struct mlx5_eswitch *esw, struct mlx5_vport *vport);
-int mlx5_esw_offloads_init_sf_rep(struct mlx5_eswitch *esw, struct mlx5_vport *vport,
+int mlx5_esw_offloads_init_sf_rep(struct mlx5_eswitch *esw,
+ struct mlx5_vport *vport,
struct mlx5_devlink_port *dl_port,
- u32 controller, u32 sfnum);
+ u32 controller, u32 pfnum, u32 sfnum);
void mlx5_esw_offloads_cleanup_sf_rep(struct mlx5_eswitch *esw, struct mlx5_vport *vport);
int mlx5_esw_offloads_load_rep(struct mlx5_eswitch *esw, struct mlx5_vport *vport);
@@ -882,7 +883,8 @@ void mlx5_esw_offloads_unload_rep(struct mlx5_eswitch *esw, struct mlx5_vport *v
int mlx5_eswitch_load_sf_vport(struct mlx5_eswitch *esw, u16 vport_num,
enum mlx5_eswitch_vport_event enabled_events,
- struct mlx5_devlink_port *dl_port, u32 controller, u32 sfnum);
+ struct mlx5_devlink_port *dl_port,
+ u32 controller, u32 pfnum, u32 sfnum);
void mlx5_eswitch_unload_sf_vport(struct mlx5_eswitch *esw, u16 vport_num);
int mlx5_eswitch_load_vf_vports(struct mlx5_eswitch *esw, u16 num_vfs,
@@ -894,9 +896,11 @@ int mlx5_esw_offloads_pf_vf_devlink_port_init(struct mlx5_eswitch *esw,
void mlx5_esw_offloads_pf_vf_devlink_port_cleanup(struct mlx5_eswitch *esw,
struct mlx5_vport *vport);
-int mlx5_esw_offloads_sf_devlink_port_init(struct mlx5_eswitch *esw, struct mlx5_vport *vport,
+int mlx5_esw_offloads_sf_devlink_port_init(struct mlx5_eswitch *esw,
+ struct mlx5_vport *vport,
struct mlx5_devlink_port *dl_port,
- u32 controller, u32 sfnum);
+ u32 controller, u32 pfnum,
+ u32 sfnum);
void mlx5_esw_offloads_sf_devlink_port_cleanup(struct mlx5_eswitch *esw, struct mlx5_vport *vport);
int mlx5_esw_offloads_devlink_port_register(struct mlx5_eswitch *esw, struct mlx5_vport *vport);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
index 1323114ce7f9..3f182e6286d6 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
@@ -2915,11 +2915,14 @@ void mlx5_esw_offloads_cleanup_pf_vf_rep(struct mlx5_eswitch *esw, struct mlx5_v
mlx5_esw_offloads_pf_vf_devlink_port_cleanup(esw, vport);
}
-int mlx5_esw_offloads_init_sf_rep(struct mlx5_eswitch *esw, struct mlx5_vport *vport,
+int mlx5_esw_offloads_init_sf_rep(struct mlx5_eswitch *esw,
+ struct mlx5_vport *vport,
struct mlx5_devlink_port *dl_port,
- u32 controller, u32 sfnum)
+ u32 controller, u32 pfnum, u32 sfnum)
{
- return mlx5_esw_offloads_sf_devlink_port_init(esw, vport, dl_port, controller, sfnum);
+ return mlx5_esw_offloads_sf_devlink_port_init(esw, vport, dl_port,
+ controller, pfnum,
+ sfnum);
}
void mlx5_esw_offloads_cleanup_sf_rep(struct mlx5_eswitch *esw, struct mlx5_vport *vport)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c b/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c
index 4564d460416b..2002b7f376ee 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c
@@ -15,6 +15,7 @@ struct mlx5_sf {
struct mlx5_devlink_port dl_port;
unsigned int port_index;
u32 controller;
+ u32 pf_num;
u16 id;
u16 hw_fn_id;
u16 hw_state;
@@ -51,7 +52,8 @@ static void mlx5_sf_function_id_erase(struct mlx5_sf_table *table, struct mlx5_s
static struct mlx5_sf *
mlx5_sf_alloc(struct mlx5_sf_table *table, struct mlx5_eswitch *esw,
- u32 controller, u32 sfnum, struct netlink_ext_ack *extack)
+ u32 controller, u32 pfnum, u32 sfnum,
+ struct netlink_ext_ack *extack)
{
unsigned int dl_port_index;
struct mlx5_sf *sf;
@@ -64,7 +66,8 @@ mlx5_sf_alloc(struct mlx5_sf_table *table, struct mlx5_eswitch *esw,
return ERR_PTR(-EINVAL);
}
- id_err = mlx5_sf_hw_table_sf_alloc(table->dev, controller, sfnum);
+ id_err = mlx5_sf_hw_table_sf_alloc(table->dev, controller, pfnum,
+ sfnum);
if (id_err < 0) {
err = id_err;
goto id_err;
@@ -76,12 +79,13 @@ mlx5_sf_alloc(struct mlx5_sf_table *table, struct mlx5_eswitch *esw,
goto alloc_err;
}
sf->id = id_err;
- hw_fn_id = mlx5_sf_sw_to_hw_id(table->dev, controller, sf->id);
+ hw_fn_id = mlx5_sf_sw_to_hw_id(table->dev, controller, pfnum, sf->id);
dl_port_index = mlx5_esw_vport_to_devlink_port_index(table->dev, hw_fn_id);
sf->port_index = dl_port_index;
sf->hw_fn_id = hw_fn_id;
sf->hw_state = MLX5_VHCA_STATE_ALLOCATED;
sf->controller = controller;
+ sf->pf_num = pfnum;
err = mlx5_sf_function_id_insert(table, sf);
if (err)
@@ -92,7 +96,7 @@ mlx5_sf_alloc(struct mlx5_sf_table *table, struct mlx5_eswitch *esw,
insert_err:
kfree(sf);
alloc_err:
- mlx5_sf_hw_table_sf_free(table->dev, controller, id_err);
+ mlx5_sf_hw_table_sf_free(table->dev, controller, pfnum, id_err);
id_err:
if (err == -EEXIST)
NL_SET_ERR_MSG_MOD(extack, "SF already exist. Choose different sfnum");
@@ -101,7 +105,8 @@ mlx5_sf_alloc(struct mlx5_sf_table *table, struct mlx5_eswitch *esw,
static void mlx5_sf_free(struct mlx5_sf_table *table, struct mlx5_sf *sf)
{
- mlx5_sf_hw_table_sf_free(table->dev, sf->controller, sf->id);
+ mlx5_sf_hw_table_sf_free(table->dev, sf->controller, sf->pf_num,
+ sf->id);
trace_mlx5_sf_free(table->dev, sf->port_index, sf->controller, sf->hw_fn_id);
kfree(sf);
}
@@ -241,13 +246,17 @@ static int mlx5_sf_add(struct mlx5_core_dev *dev, struct mlx5_sf_table *table,
struct mlx5_sf *sf;
int err;
- sf = mlx5_sf_alloc(table, esw, new_attr->controller, new_attr->sfnum, extack);
+ sf = mlx5_sf_alloc(table, esw, new_attr->controller, new_attr->pfnum,
+ new_attr->sfnum, extack);
if (IS_ERR(sf))
return PTR_ERR(sf);
mlx5_esw_reps_block(esw);
- err = mlx5_eswitch_load_sf_vport(esw, sf->hw_fn_id, MLX5_VPORT_UC_ADDR_CHANGE,
- &sf->dl_port, new_attr->controller, new_attr->sfnum);
+ err = mlx5_eswitch_load_sf_vport(esw, sf->hw_fn_id,
+ MLX5_VPORT_UC_ADDR_CHANGE,
+ &sf->dl_port, new_attr->controller,
+ new_attr->pfnum,
+ new_attr->sfnum);
mlx5_esw_reps_unblock(esw);
if (err)
goto esw_err;
@@ -347,10 +356,12 @@ static void mlx5_sf_dealloc(struct mlx5_sf_table *table, struct mlx5_sf *sf)
* firmware gives confirmation that it is detached by the driver.
*/
mlx5_cmd_sf_disable_hca(table->dev, sf->hw_fn_id);
- mlx5_sf_hw_table_sf_deferred_free(table->dev, sf->controller, sf->id);
+ mlx5_sf_hw_table_sf_deferred_free(table->dev, sf->controller,
+ sf->pf_num, sf->id);
kfree(sf);
} else {
- mlx5_sf_hw_table_sf_deferred_free(table->dev, sf->controller, sf->id);
+ mlx5_sf_hw_table_sf_deferred_free(table->dev, sf->controller,
+ sf->pf_num, sf->id);
kfree(sf);
}
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c b/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c
index c36dbd7de877..d8d061683497 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c
@@ -37,7 +37,7 @@ struct mlx5_sf_hw_table {
};
static struct mlx5_sf_hwc_table *
-mlx5_sf_controller_to_hwc(struct mlx5_core_dev *dev, u32 controller)
+mlx5_sf_controller_to_hwc(struct mlx5_core_dev *dev, u32 controller, u32 pfnum)
{
struct mlx5_sf_hw_table *table = dev->priv.sf_hw_table;
int i;
@@ -50,11 +50,12 @@ mlx5_sf_controller_to_hwc(struct mlx5_core_dev *dev, u32 controller)
return &table->hwc[!!controller];
}
-u16 mlx5_sf_sw_to_hw_id(struct mlx5_core_dev *dev, u32 controller, u16 sw_id)
+u16 mlx5_sf_sw_to_hw_id(struct mlx5_core_dev *dev, u32 controller, u32 pfnum,
+ u16 sw_id)
{
struct mlx5_sf_hwc_table *hwc;
- hwc = mlx5_sf_controller_to_hwc(dev, controller);
+ hwc = mlx5_sf_controller_to_hwc(dev, controller, pfnum);
return hwc->start_fn_id + sw_id;
}
@@ -79,14 +80,14 @@ mlx5_sf_table_fn_to_hwc(struct mlx5_sf_hw_table *table, u16 fn_id)
static int mlx5_sf_hw_table_id_alloc(struct mlx5_core_dev *dev,
struct mlx5_sf_hw_table *table,
- u32 controller,
+ u32 controller, u32 pfnum,
u32 usr_sfnum)
{
struct mlx5_sf_hwc_table *hwc;
int free_idx = -1;
int i;
- hwc = mlx5_sf_controller_to_hwc(dev, controller);
+ hwc = mlx5_sf_controller_to_hwc(dev, controller, pfnum);
if (!hwc->sfs)
return -ENOSPC;
@@ -110,16 +111,17 @@ static int mlx5_sf_hw_table_id_alloc(struct mlx5_core_dev *dev,
static void mlx5_sf_hw_table_id_free(struct mlx5_core_dev *dev,
struct mlx5_sf_hw_table *table,
- u32 controller, int id)
+ u32 controller, u32 pfnum, int id)
{
struct mlx5_sf_hwc_table *hwc;
- hwc = mlx5_sf_controller_to_hwc(dev, controller);
+ hwc = mlx5_sf_controller_to_hwc(dev, controller, pfnum);
hwc->sfs[id].allocated = false;
hwc->sfs[id].pending_delete = false;
}
-int mlx5_sf_hw_table_sf_alloc(struct mlx5_core_dev *dev, u32 controller, u32 usr_sfnum)
+int mlx5_sf_hw_table_sf_alloc(struct mlx5_core_dev *dev, u32 controller,
+ u32 pfnum, u32 usr_sfnum)
{
struct mlx5_sf_hw_table *table = dev->priv.sf_hw_table;
u16 hw_fn_id;
@@ -130,13 +132,14 @@ int mlx5_sf_hw_table_sf_alloc(struct mlx5_core_dev *dev, u32 controller, u32 usr
return -EOPNOTSUPP;
mutex_lock(&table->table_lock);
- sw_id = mlx5_sf_hw_table_id_alloc(dev, table, controller, usr_sfnum);
+ sw_id = mlx5_sf_hw_table_id_alloc(dev, table, controller, pfnum,
+ usr_sfnum);
if (sw_id < 0) {
err = sw_id;
goto exist_err;
}
- hw_fn_id = mlx5_sf_sw_to_hw_id(dev, controller, sw_id);
+ hw_fn_id = mlx5_sf_sw_to_hw_id(dev, controller, pfnum, sw_id);
err = mlx5_cmd_alloc_sf(dev, hw_fn_id);
if (err)
goto err;
@@ -161,21 +164,22 @@ int mlx5_sf_hw_table_sf_alloc(struct mlx5_core_dev *dev, u32 controller, u32 usr
vhca_err:
mlx5_cmd_dealloc_sf(dev, hw_fn_id);
err:
- mlx5_sf_hw_table_id_free(dev, table, controller, sw_id);
+ mlx5_sf_hw_table_id_free(dev, table, controller, pfnum, sw_id);
exist_err:
mutex_unlock(&table->table_lock);
return err;
}
-void mlx5_sf_hw_table_sf_free(struct mlx5_core_dev *dev, u32 controller, u16 id)
+void mlx5_sf_hw_table_sf_free(struct mlx5_core_dev *dev, u32 controller,
+ u32 pfnum, u16 id)
{
struct mlx5_sf_hw_table *table = dev->priv.sf_hw_table;
u16 hw_fn_id;
mutex_lock(&table->table_lock);
- hw_fn_id = mlx5_sf_sw_to_hw_id(dev, controller, id);
+ hw_fn_id = mlx5_sf_sw_to_hw_id(dev, controller, pfnum, id);
mlx5_cmd_dealloc_sf(dev, hw_fn_id);
- mlx5_sf_hw_table_id_free(dev, table, controller, id);
+ mlx5_sf_hw_table_id_free(dev, table, controller, pfnum, id);
mutex_unlock(&table->table_lock);
}
@@ -188,7 +192,8 @@ static void mlx5_sf_hw_table_hwc_sf_free(struct mlx5_core_dev *dev,
trace_mlx5_sf_hwc_free(dev, hwc->start_fn_id + idx);
}
-void mlx5_sf_hw_table_sf_deferred_free(struct mlx5_core_dev *dev, u32 controller, u16 id)
+void mlx5_sf_hw_table_sf_deferred_free(struct mlx5_core_dev *dev,
+ u32 controller, u32 pfnum, u16 id)
{
struct mlx5_sf_hw_table *table = dev->priv.sf_hw_table;
u32 out[MLX5_ST_SZ_DW(query_vhca_state_out)] = {};
@@ -197,8 +202,8 @@ void mlx5_sf_hw_table_sf_deferred_free(struct mlx5_core_dev *dev, u32 controller
u8 state;
int err;
- hw_fn_id = mlx5_sf_sw_to_hw_id(dev, controller, id);
- hwc = mlx5_sf_controller_to_hwc(dev, controller);
+ hw_fn_id = mlx5_sf_sw_to_hw_id(dev, controller, pfnum, id);
+ hwc = mlx5_sf_controller_to_hwc(dev, controller, pfnum);
mutex_lock(&table->table_lock);
err = mlx5_cmd_query_vhca_state(dev, hw_fn_id, out, sizeof(out));
if (err)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sf/priv.h b/drivers/net/ethernet/mellanox/mlx5/core/sf/priv.h
index 7114f3fc335f..19fc3be82cd4 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/sf/priv.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/priv.h
@@ -12,11 +12,15 @@ int mlx5_cmd_dealloc_sf(struct mlx5_core_dev *dev, u16 function_id);
int mlx5_cmd_sf_enable_hca(struct mlx5_core_dev *dev, u16 func_id);
int mlx5_cmd_sf_disable_hca(struct mlx5_core_dev *dev, u16 func_id);
-u16 mlx5_sf_sw_to_hw_id(struct mlx5_core_dev *dev, u32 controller, u16 sw_id);
+u16 mlx5_sf_sw_to_hw_id(struct mlx5_core_dev *dev, u32 controller, u32 pfnum,
+ u16 sw_id);
-int mlx5_sf_hw_table_sf_alloc(struct mlx5_core_dev *dev, u32 controller, u32 usr_sfnum);
-void mlx5_sf_hw_table_sf_free(struct mlx5_core_dev *dev, u32 controller, u16 id);
-void mlx5_sf_hw_table_sf_deferred_free(struct mlx5_core_dev *dev, u32 controller, u16 id);
+int mlx5_sf_hw_table_sf_alloc(struct mlx5_core_dev *dev, u32 controller,
+ u32 pfnum, u32 usr_sfnum);
+void mlx5_sf_hw_table_sf_free(struct mlx5_core_dev *dev, u32 controller,
+ u32 pfnum, u16 id);
+void mlx5_sf_hw_table_sf_deferred_free(struct mlx5_core_dev *dev,
+ u32 controller, u32 pfnum, u16 id);
bool mlx5_sf_hw_table_supported(const struct mlx5_core_dev *dev);
#endif
--
2.44.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH net-next 2/2] net/mlx5: Add controller number for SF and ECVF phys_port_name
2026-11-25 21:20 [PATCH net-next 0/2] net/mlx5: Add controller number to SF and VF phys_port_name Tariq Toukan
2026-11-25 21:20 ` [PATCH net-next 1/2] net/mlx5: SF, Pass pfnum through the SF hardware-table allocation path Tariq Toukan
@ 2026-11-25 21:20 ` Tariq Toukan
2026-11-26 21:21 ` sashiko-bot
2026-11-26 22:10 ` netdev-bot+sashiko
2026-11-26 21:21 ` [PATCH net-next 0/2] net/mlx5: Add controller number to SF and VF phys_port_name sashiko-bot
2 siblings, 2 replies; 6+ messages in thread
From: Tariq Toukan @ 2026-11-25 21:20 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni
Cc: Carolina Jubran, Chris Mi, Gal Pressman, Kees Cook,
Leon Romanovsky, linux-rdma, Mark Bloch, Moshe Shemesh,
Or Har-Toov, Parav Pandit, Saeed Mahameed, Shay Drori,
Tariq Toukan
From: Chris Mi <cmi@nvidia.com>
phys_port_name for the SF/VF representors is derived from the
devlink port attributes such as controller number, function
number (pf num) and the SF/VF number itself. However, if SF/VF
controller number is 0, the controller number is not added to
the phys_port_name.
In a BlueField-4 Socket-Direct topology [1], there are two PCI
links. Under single eswitch, there are duplicate function number
(pf num) and SF/VF number. The result is they share the same
phys_port_name [2]. Hence, annotate the non-master PCI link
with its own controller number so its SFs/VFs can be uniquely
identified. This streamlines the design so that all PCI links
which are not on the eswitch PF get their own unique controller
number.
Use the MLX5_PCI_PF_TYPE_QUERY_PF entry from QUERY_ESW_FUNCTIONS
to read the host_number for each PCI link. Controller number is
host_number + 1. The non-master PCI link devices get a non-zero
phys_port_cnum so their SFs/VFs display the controller prefix.
Since self PF and satellite PF share the same controller number,
use pfnum to locate the right hwc table.
For example, if the device controller number is 4, user can create
an SF like this:
$ devlink port add pci/0006:01:00.0 flavour pcisf pfnum 0 sfnum 0
or
$ devlink port add pci/0006:01:00.0 flavour pcisf pfnum 0 sfnum 0
controller 4
But if user specifies other controller number, command fails.
[1]
PCI NET
0002:01:00.0 net-B21c1pf0,net-p0,net-B21pf0sf0
0006:01:00.0 net-B61c1pf1,net-p1,net-B61pf0sf0
0002:01:00.1 net-B21c2pf0
0006:01:00.1 net-B61c2pf1
[2]
Before this enhancement:
$ cat /sys/class/net/B21pf0sf0/phys_port_name
pf0sf0
$ cat /sys/class/net/B61pf0sf0/phys_port_name
pf0sf0
[3]
After this enhancement:
$ cat /sys/class/net/B21pf0sf0/phys_port_name
pf0sf0
$ cat /sys/class/net/B61c4pf0sf0/phys_port_name
c4pf0sf0
$ devlink port show
pci/0002:01:00.0/360450: type eth netdev B21pf0sf0 flavour pcisf
controller 0 pfnum 0 sfnum 0 external false splittable false
function:
hw_addr 00:00:00:00:00:00 state inactive opstate detached
pci/0006:01:00.0/491520: type eth netdev B61c4pf0sf0 flavour pcisf
controller 4 pfnum 0 sfnum 0 external false splittable false
function:
hw_addr 00:00:00:00:00:00 state inactive opstate detached
Signed-off-by: Chris Mi <cmi@nvidia.com>
Reviewed-by: Parav Pandit <parav@nvidia.com>
Reviewed-by: Shay Drori <shayd@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
.../mellanox/mlx5/core/esw/devlink_port.c | 4 +-
.../net/ethernet/mellanox/mlx5/core/eswitch.c | 111 ++++++++++++++++--
.../net/ethernet/mellanox/mlx5/core/eswitch.h | 8 +-
.../mellanox/mlx5/core/eswitch_offloads.c | 7 +-
.../mellanox/mlx5/core/lag/shared_fdb.c | 58 +++++++++
.../ethernet/mellanox/mlx5/core/sf/devlink.c | 31 ++++-
.../ethernet/mellanox/mlx5/core/sf/hw_table.c | 10 ++
7 files changed, 215 insertions(+), 14 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c b/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c
index 8b46634203b3..fa07a571c1b9 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c
@@ -83,7 +83,9 @@ static void mlx5_esw_offloads_pf_vf_devlink_port_attrs_set(struct mlx5_eswitch *
memcpy(dl_port->attrs.switch_id.id, ppid.id, ppid.id_len);
dl_port->attrs.switch_id.id_len = ppid.id_len;
- devlink_port_attrs_pci_vf_set(dl_port, 0, pfnum,
+ controller_num = mlx5_esw_get_self_pf_ctrl_num(esw);
+ pfnum = mlx5_esw_get_self_pf_pfnum(esw);
+ devlink_port_attrs_pci_vf_set(dl_port, controller_num, pfnum,
vport_num - base_vport, false);
} else if (mlx5_esw_is_spf_vport(esw, vport_num)) {
int spf_idx = mlx5_esw_spf_vport_to_idx(esw, vport_num);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
index 8c2c55ba5c35..09a29280c48e 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
@@ -2183,21 +2183,58 @@ u16 mlx5_esw_get_hpf_pf_num(struct mlx5_core_dev *dev)
return PCI_FUNC(dev->pdev->devfn);
}
-u16 mlx5_esw_sf_controller_to_pfnum(struct mlx5_core_dev *dev, u32 controller)
+u32 mlx5_esw_get_self_pf_ctrl_num(struct mlx5_eswitch *esw)
+{
+ struct mlx5_esw_functions *esw_funcs = &esw->esw_funcs;
+
+ return esw_funcs->phys_port_cnum;
+}
+
+u16 mlx5_esw_get_self_pf_pfnum(struct mlx5_eswitch *esw)
+{
+ struct mlx5_core_dev *dev = esw->dev;
+
+ if (mlx5_core_is_ecpf_esw_manager(dev) &&
+ MLX5_CAP_GEN(dev, query_host_net_function_v1))
+ return esw->esw_funcs.self_pf_pfnum;
+
+ return PCI_FUNC(dev->pdev->devfn);
+}
+
+bool mlx5_esw_sf_controller_to_pfnum_valid(struct mlx5_core_dev *dev,
+ u32 controller, u32 pfnum)
{
struct mlx5_eswitch *esw = dev->priv.eswitch;
struct mlx5_esw_functions *esw_funcs;
+ bool known_controller = false;
int i;
- if (!controller)
- return PCI_FUNC(dev->pdev->devfn);
+ if (!MLX5_CAP_GEN(dev, query_host_net_function_v1))
+ return pfnum == PCI_FUNC(dev->pdev->devfn);
esw_funcs = &esw->esw_funcs;
- for (i = 0; i < esw_funcs->num_spfs; i++)
- if (controller == esw_funcs->spfs[i].host_number + 1)
- return esw_funcs->spfs[i].pf_num;
+ if (!controller || controller == esw_funcs->controller_num) {
+ known_controller = true;
+ if (mlx5_esw_get_self_pf_pfnum(esw) == pfnum)
+ return true;
+ }
- return mlx5_esw_get_hpf_pf_num(dev);
+ for (i = 0; i < esw_funcs->num_spfs; i++) {
+ if (controller != esw_funcs->spfs[i].host_number + 1)
+ continue;
+ known_controller = true;
+ if (esw_funcs->spfs[i].pf_num == pfnum)
+ return true;
+ }
+
+ /* controller matched self pf or a satellite PF, but pfnum matched
+ * neither. It's invalid, do not continue on to check the external
+ * host PF.
+ */
+ if (known_controller)
+ return false;
+
+ return mlx5_esw_get_hpf_pf_num(dev) == pfnum;
}
bool mlx5_esw_has_spf_sfs(struct mlx5_core_dev *dev)
@@ -2264,6 +2301,61 @@ void mlx5_esw_vport_free(struct mlx5_eswitch *esw, struct mlx5_vport *vport)
kfree(vport);
}
+static void mlx5_esw_self_pf_cleanup(struct mlx5_eswitch *esw)
+{
+ struct mlx5_esw_functions *esw_funcs = &esw->esw_funcs;
+
+ esw_funcs->controller_num = 0;
+ esw_funcs->phys_port_cnum = 0;
+ esw_funcs->self_pf_pfnum = 0;
+}
+
+static int mlx5_esw_self_pf_init(struct mlx5_eswitch *esw)
+{
+ struct mlx5_esw_functions *esw_funcs = &esw->esw_funcs;
+ struct mlx5_core_dev *dev = esw->dev;
+ int num_entries;
+ const u8 *entry;
+ const u32 *out;
+ int i;
+
+ esw_funcs->self_pf_pfnum = PCI_FUNC(dev->pdev->devfn);
+
+ if (!MLX5_CAP_GEN(dev, query_host_net_function_v1))
+ return 0;
+
+ out = mlx5_esw_query_functions(dev);
+ if (IS_ERR(out))
+ return PTR_ERR(out);
+
+ num_entries = MLX5_GET(query_esw_functions_out, out, net_function_num);
+ if (!num_entries)
+ goto out_free;
+
+ entry = MLX5_ADDR_OF(query_esw_functions_out, out, net_function_params);
+ for (i = 0; i < num_entries; i++) {
+ int pf_type;
+
+ pf_type = MLX5_GET(network_function_params, entry, pci_pf_type);
+ if (pf_type != MLX5_PCI_PF_TYPE_QUERY_PF) {
+ entry += MLX5_UN_SZ_BYTES(net_function_params);
+ continue;
+ }
+
+ esw_funcs->controller_num =
+ MLX5_GET(network_function_params,
+ entry, host_number) + 1;
+ esw_funcs->self_pf_pfnum =
+ MLX5_GET(network_function_params,
+ entry, pci_device_function);
+ break;
+ }
+
+out_free:
+ kvfree(out);
+ return 0;
+}
+
static void mlx5_esw_spfs_cleanup(struct mlx5_eswitch *esw)
{
struct mlx5_esw_functions *esw_funcs = &esw->esw_funcs;
@@ -2371,6 +2463,7 @@ static void mlx5_esw_vports_cleanup(struct mlx5_eswitch *esw)
mlx5_esw_for_each_vport(esw, i, vport)
mlx5_esw_vport_free(esw, vport);
xa_destroy(&esw->vports);
+ mlx5_esw_self_pf_cleanup(esw);
}
static int mlx5_esw_vports_init(struct mlx5_eswitch *esw)
@@ -2381,6 +2474,10 @@ static int mlx5_esw_vports_init(struct mlx5_eswitch *esw)
int err;
int i;
+ err = mlx5_esw_self_pf_init(esw);
+ if (err)
+ return err;
+
xa_init(&esw->vports);
err = mlx5_esw_hpf_info_init(esw);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
index 463855240032..b6b8c35f0289 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
@@ -370,6 +370,9 @@ struct mlx5_esw_functions {
bool has_spf_sfs;
struct mlx5_esw_spf *spfs;
int num_spfs;
+ u32 controller_num;
+ u32 phys_port_cnum;
+ u32 self_pf_pfnum;
};
enum {
@@ -916,7 +919,10 @@ int mlx5_esw_spf_get_host_number(struct mlx5_core_dev *dev, int spf_idx,
u16 *host_number);
u16 mlx5_esw_get_hpf_host_number(struct mlx5_core_dev *dev);
u16 mlx5_esw_get_hpf_pf_num(struct mlx5_core_dev *dev);
-u16 mlx5_esw_sf_controller_to_pfnum(struct mlx5_core_dev *dev, u32 controller);
+u32 mlx5_esw_get_self_pf_ctrl_num(struct mlx5_eswitch *esw);
+u16 mlx5_esw_get_self_pf_pfnum(struct mlx5_eswitch *esw);
+bool mlx5_esw_sf_controller_to_pfnum_valid(struct mlx5_core_dev *dev,
+ u32 controller, u32 pfnum);
bool mlx5_esw_has_spf_sfs(struct mlx5_core_dev *dev);
int mlx5_esw_vport_vhca_id_map(struct mlx5_eswitch *esw,
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
index 3f182e6286d6..ff689b10635f 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
@@ -4141,6 +4141,12 @@ bool mlx5_esw_offloads_controller_valid(const struct mlx5_eswitch *esw, u32 cont
const struct mlx5_esw_functions *esw_funcs;
int i;
+ /* User specifies correct non-zero self PF controller number */
+ esw_funcs = &esw->esw_funcs;
+ if (esw_funcs->phys_port_cnum &&
+ controller == esw_funcs->phys_port_cnum)
+ return true;
+
/* Local controller is always valid */
if (controller == 0)
return true;
@@ -4152,7 +4158,6 @@ bool mlx5_esw_offloads_controller_valid(const struct mlx5_eswitch *esw, u32 cont
if (controller == mlx5_esw_get_hpf_host_number(esw->dev) + 1)
return true;
- esw_funcs = &esw->esw_funcs;
for (i = 0; i < esw_funcs->num_spfs; i++) {
if (controller == esw_funcs->spfs[i].host_number + 1)
return true;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c
index 404278a15ef7..fb96e9c3a5d8 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c
@@ -190,6 +190,44 @@ void mlx5_lag_destroy_single_fdb(struct mlx5_lag *ldev)
mlx5_lag_destroy_single_fdb_filter(ldev, MLX5_LAG_FILTER_ALL);
}
+static void mlx5_self_controller_set(struct mlx5_lag *ldev, u32 filter)
+{
+ struct mlx5_core_dev *dev, *master_dev = NULL;
+ struct mlx5_esw_functions *esw_funcs;
+ struct mlx5_eswitch *esw;
+ int i;
+
+ mlx5_lag_for_each(i, 0, ldev, filter) {
+ dev = mlx5_lag_fn(ldev, i)->dev;
+ esw = dev->priv.eswitch;
+ esw_funcs = &esw->esw_funcs;
+ if (!mlx5_lag_is_master(dev))
+ esw_funcs->phys_port_cnum = esw_funcs->controller_num;
+ else
+ master_dev = dev;
+ }
+
+ if (!master_dev)
+ return;
+
+ mlx5_lag_for_each(i, 0, ldev, filter) {
+ struct mlx5_esw_functions *master_esw_funcs;
+ u32 host_ctrl_num, master_host_ctrl_num;
+ struct mlx5_eswitch *master_esw;
+
+ dev = mlx5_lag_fn(ldev, i)->dev;
+ esw = dev->priv.eswitch;
+ esw_funcs = &esw->esw_funcs;
+ host_ctrl_num = esw_funcs->controller_num;
+
+ master_esw = master_dev->priv.eswitch;
+ master_esw_funcs = &master_esw->esw_funcs;
+ master_host_ctrl_num = master_esw_funcs->controller_num;
+ if (host_ctrl_num == master_host_ctrl_num)
+ esw_funcs->phys_port_cnum = 0;
+ }
+}
+
/**
* mlx5_lag_shared_fdb_create - Create shared FDB LAG
* @ldev: LAG device
@@ -257,6 +295,9 @@ int mlx5_lag_shared_fdb_create(struct mlx5_lag *ldev,
if (filter == MLX5_LAG_FILTER_PORTS || filter == MLX5_LAG_FILTER_ALL)
mlx5_lag_set_vports_agg_speed(ldev);
+
+ mlx5_self_controller_set(ldev, filter);
+
return 0;
err_rescan_drivers:
@@ -277,6 +318,21 @@ int mlx5_lag_shared_fdb_create(struct mlx5_lag *ldev,
return err;
}
+static void mlx5_self_controller_reset(struct mlx5_lag *ldev, u32 filter)
+{
+ struct mlx5_esw_functions *esw_funcs;
+ struct mlx5_core_dev *dev;
+ struct mlx5_eswitch *esw;
+ int i;
+
+ mlx5_lag_for_each(i, 0, ldev, filter) {
+ dev = mlx5_lag_fn(ldev, i)->dev;
+ esw = dev->priv.eswitch;
+ esw_funcs = &esw->esw_funcs;
+ esw_funcs->phys_port_cnum = 0;
+ }
+}
+
void mlx5_lag_shared_fdb_destroy(struct mlx5_lag *ldev, u32 group_id)
{
u32 filter = group_id ? group_id : MLX5_LAG_FILTER_ALL;
@@ -284,6 +340,8 @@ void mlx5_lag_shared_fdb_destroy(struct mlx5_lag *ldev, u32 group_id)
int err;
int i;
+ mlx5_self_controller_reset(ldev, filter);
+
mlx5_lag_remove_devices_filter(ldev, filter);
if (filter == MLX5_LAG_FILTER_PORTS || filter == MLX5_LAG_FILTER_ALL) {
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c b/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c
index 2002b7f376ee..c8aa1b0b9319 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c
@@ -237,6 +237,18 @@ int mlx5_devlink_sf_port_fn_state_set(struct devlink_port *dl_port,
return mlx5_sf_state_set(dev, table, sf, state, extack);
}
+static u32
+mlx5_sf_get_self_controller(struct mlx5_eswitch *esw,
+ const struct devlink_port_new_attrs *new_attr)
+{
+ struct mlx5_esw_functions *esw_funcs = &esw->esw_funcs;
+
+ if (!new_attr->controller_valid && esw_funcs->phys_port_cnum)
+ return esw_funcs->phys_port_cnum;
+
+ return new_attr->controller;
+}
+
static int mlx5_sf_add(struct mlx5_core_dev *dev, struct mlx5_sf_table *table,
const struct devlink_port_new_attrs *new_attr,
struct netlink_ext_ack *extack,
@@ -244,9 +256,11 @@ static int mlx5_sf_add(struct mlx5_core_dev *dev, struct mlx5_sf_table *table,
{
struct mlx5_eswitch *esw = dev->priv.eswitch;
struct mlx5_sf *sf;
+ u32 controller;
int err;
- sf = mlx5_sf_alloc(table, esw, new_attr->controller, new_attr->pfnum,
+ controller = mlx5_sf_get_self_controller(esw, new_attr);
+ sf = mlx5_sf_alloc(table, esw, controller, new_attr->pfnum,
new_attr->sfnum, extack);
if (IS_ERR(sf))
return PTR_ERR(sf);
@@ -254,7 +268,7 @@ static int mlx5_sf_add(struct mlx5_core_dev *dev, struct mlx5_sf_table *table,
mlx5_esw_reps_block(esw);
err = mlx5_eswitch_load_sf_vport(esw, sf->hw_fn_id,
MLX5_VPORT_UC_ADDR_CHANGE,
- &sf->dl_port, new_attr->controller,
+ &sf->dl_port, controller,
new_attr->pfnum,
new_attr->sfnum);
mlx5_esw_reps_unblock(esw);
@@ -274,6 +288,8 @@ static int
mlx5_sf_new_check_attr(struct mlx5_core_dev *dev, const struct devlink_port_new_attrs *new_attr,
struct netlink_ext_ack *extack)
{
+ struct mlx5_esw_functions *esw_funcs;
+ struct mlx5_eswitch *esw;
u32 controller;
if (new_attr->flavour != DEVLINK_PORT_FLAVOUR_PCI_SF) {
@@ -295,9 +311,16 @@ mlx5_sf_new_check_attr(struct mlx5_core_dev *dev, const struct devlink_port_new_
NL_SET_ERR_MSG_MOD(extack, "External controller is unsupported");
return -EOPNOTSUPP;
}
+ esw = dev->priv.eswitch;
+ esw_funcs = &esw->esw_funcs;
+ if (new_attr->controller_valid && !new_attr->controller &&
+ esw_funcs->phys_port_cnum) {
+ NL_SET_ERR_MSG_MOD(extack, "Invalid controller supplied");
+ return -EOPNOTSUPP;
+ }
controller = new_attr->controller_valid ? new_attr->controller : 0;
- if (new_attr->pfnum !=
- mlx5_esw_sf_controller_to_pfnum(dev, controller)) {
+ if (!mlx5_esw_sf_controller_to_pfnum_valid(dev, controller,
+ new_attr->pfnum)) {
NL_SET_ERR_MSG_MOD(extack, "Invalid pfnum supplied");
return -EOPNOTSUPP;
}
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c b/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c
index d8d061683497..b7e8a8d7cc64 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c
@@ -40,8 +40,18 @@ static struct mlx5_sf_hwc_table *
mlx5_sf_controller_to_hwc(struct mlx5_core_dev *dev, u32 controller, u32 pfnum)
{
struct mlx5_sf_hw_table *table = dev->priv.sf_hw_table;
+ struct mlx5_eswitch *esw = dev->priv.eswitch;
+ struct mlx5_esw_functions *esw_funcs;
int i;
+ /* If shared fdb is destroyed, phys_port_cnum is reset to 0.
+ * So use controller_num directly which is read from firmware.
+ */
+ esw_funcs = &esw->esw_funcs;
+ if (controller == esw_funcs->controller_num &&
+ pfnum == mlx5_esw_get_self_pf_pfnum(esw))
+ return &table->hwc[MLX5_SF_HWC_LOCAL];
+
for (i = MLX5_SF_HWC_FIRST_SPF; i < table->num_hwc; i++) {
if (table->hwc[i].controller == controller)
return &table->hwc[i];
--
2.44.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net-next 2/2] net/mlx5: Add controller number for SF and ECVF phys_port_name
2026-11-25 21:20 ` [PATCH net-next 2/2] net/mlx5: Add controller number for SF and ECVF phys_port_name Tariq Toukan
@ 2026-11-26 21:21 ` sashiko-bot
2026-11-26 22:10 ` netdev-bot+sashiko
1 sibling, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-26 21:21 UTC (permalink / raw)
To: Tariq Toukan; +Cc: linux-rdma
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] net/mlx5: local SF state reset in
mlx5_sf_table_esw_changed_event_handler()
- [Medium] net/mlx5: controller_num check in
mlx5_esw_sf_controller_to_pfnum_valid()
- [Medium] net/mlx5: ECVF attrs read phys_port_cnum before
mlx5_self_controller_set()
- [Medium] net/mlx5: unlocked phys_port_cnum race in
mlx5_devlink_sf_port_new()
- [Medium] net/mlx5: wrong master and reset in
mlx5_self_controller_set() for SD bond
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [High] net/mlx5: LAG, NULL pointer dereference in
mlx5_mpesw_restore_sd_fdb() [1]
--
commit 9a9846fea956014d36adcb9c4f97568dd6087252
Author: Chris Mi <cmi@nvidia.com>
net/mlx5: Add controller number for SF and ECVF phys_port_name
This commit assigns a controller number derived from QUERY_ESW_FUNCTIONS
to non-master PCI link devices in a shared-FDB topology so that their SF
and ECVF representors receive a unique controller prefix in
phys_port_name.
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c b/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c
> index 8b46634203b37..fa07a571c1b99 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c
> @@ -83,7 +83,9 @@ static void mlx5_esw_offloads_pf_vf_devlink_port_attrs_set(struct mlx5_eswitch *
>
> memcpy(dl_port->attrs.switch_id.id, ppid.id, ppid.id_len);
> dl_port->attrs.switch_id.id_len = ppid.id_len;
> - devlink_port_attrs_pci_vf_set(dl_port, 0, pfnum,
> + controller_num = mlx5_esw_get_self_pf_ctrl_num(esw);
> + pfnum = mlx5_esw_get_self_pf_pfnum(esw);
> + devlink_port_attrs_pci_vf_set(dl_port, controller_num, pfnum,
> vport_num - base_vport, false);
> } else if (mlx5_esw_is_spf_vport(esw, vport_num)) {
> int spf_idx = mlx5_esw_spf_vport_to_idx(esw, vport_num);
[Severity: Medium]
Isn't esw->esw_funcs.phys_port_cnum still 0 when ECVF devlink ports are
registered during eswitch mode transition?
In mlx5_devlink_eswitch_mode_set(), esw_offloads_start() loads and
registers existing ECVF vports before mlx5_sd_eswitch_mode_set() ->
mlx5_lag_shared_fdb_create() -> mlx5_self_controller_set() populates
phys_port_cnum. The same ordering happens if ECVFs are enabled on a
non-master PCI link before its peer PF enters switchdev mode: the ECVF
devlink ports snapshot controller_num = 0 and never get the c<N> prefix in
phys_port_name once shared FDB is created.
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
> index 8c2c55ba5c35e..09a29280c48e3 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
> @@ -2183,21 +2183,58 @@ u16 mlx5_esw_get_hpf_pf_num(struct mlx5_core_dev *dev)
> return PCI_FUNC(dev->pdev->devfn);
> }
>
> -u16 mlx5_esw_sf_controller_to_pfnum(struct mlx5_core_dev *dev, u32 controller)
> +u32 mlx5_esw_get_self_pf_ctrl_num(struct mlx5_eswitch *esw)
> +{
> + struct mlx5_esw_functions *esw_funcs = &esw->esw_funcs;
> +
> + return esw_funcs->phys_port_cnum;
> +}
> +
> +u16 mlx5_esw_get_self_pf_pfnum(struct mlx5_eswitch *esw)
> +{
> + struct mlx5_core_dev *dev = esw->dev;
> +
> + if (mlx5_core_is_ecpf_esw_manager(dev) &&
> + MLX5_CAP_GEN(dev, query_host_net_function_v1))
> + return esw->esw_funcs.self_pf_pfnum;
> +
> + return PCI_FUNC(dev->pdev->devfn);
> +}
> +
> +bool mlx5_esw_sf_controller_to_pfnum_valid(struct mlx5_core_dev *dev,
> + u32 controller, u32 pfnum)
> {
> struct mlx5_eswitch *esw = dev->priv.eswitch;
> struct mlx5_esw_functions *esw_funcs;
> + bool known_controller = false;
> int i;
>
> - if (!controller)
> - return PCI_FUNC(dev->pdev->devfn);
> + if (!MLX5_CAP_GEN(dev, query_host_net_function_v1))
> + return pfnum == PCI_FUNC(dev->pdev->devfn);
>
> esw_funcs = &esw->esw_funcs;
> - for (i = 0; i < esw_funcs->num_spfs; i++)
> - if (controller == esw_funcs->spfs[i].host_number + 1)
> - return esw_funcs->spfs[i].pf_num;
> + if (!controller || controller == esw_funcs->controller_num) {
> + known_controller = true;
> + if (mlx5_esw_get_self_pf_pfnum(esw) == pfnum)
> + return true;
> + }
[Severity: Medium]
Should this check controller == esw_funcs->phys_port_cnum instead of
esw_funcs->controller_num?
mlx5_esw_self_pf_init() sets esw_funcs->controller_num to host_number + 1
on all PFs, including the master PCI link where phys_port_cnum is 0.
When a satellite PF shares the same host_number as the master self PF,
mlx5_esw_offloads_controller_valid() also accepts that controller number
via its spfs[] loop and mlx5_sf_controller_to_hwc() maps it to
MLX5_SF_HWC_LOCAL. A user on the master PCI link can then create a local
self-PF SF with a non-zero controller number and a c<N> prefix even though
phys_port_cnum is 0.
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c
> index 404278a15ef73..fb96e9c3a5d84 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c
> @@ -190,6 +190,44 @@ void mlx5_lag_destroy_single_fdb(struct mlx5_lag *ldev)
> mlx5_lag_destroy_single_fdb_filter(ldev, MLX5_LAG_FILTER_ALL);
> }
>
> +static void mlx5_self_controller_set(struct mlx5_lag *ldev, u32 filter)
> +{
> + struct mlx5_core_dev *dev, *master_dev = NULL;
> + struct mlx5_esw_functions *esw_funcs;
> + struct mlx5_eswitch *esw;
> + int i;
> +
> + mlx5_lag_for_each(i, 0, ldev, filter) {
> + dev = mlx5_lag_fn(ldev, i)->dev;
> + esw = dev->priv.eswitch;
> + esw_funcs = &esw->esw_funcs;
> + if (!mlx5_lag_is_master(dev))
> + esw_funcs->phys_port_cnum = esw_funcs->controller_num;
> + else
> + master_dev = dev;
> + }
[Severity: Medium]
Does mlx5_lag_is_master(dev) pick the wrong master here when a bond is
created over a Socket-Direct device?
When per-group SD shared FDBs are active (fn->sd_fdb_active is true) and a
bond is created with filter == MLX5_LAG_FILTER_ALL, mlx5_lag_is_master()
queries mlx5_lag_get_filter(ldev, dev), which returns fn->group_id instead
of MLX5_LAG_FILTER_ALL. Every SD group's primary PF therefore returns
true from mlx5_lag_is_master(), overwriting master_dev with the last SD
group's primary PF and clearing phys_port_cnum to 0 on that group's
controller instead of on the overall LAG master dev0.
> @@ -257,6 +295,9 @@ int mlx5_lag_shared_fdb_create(struct mlx5_lag *ldev,
>
> if (filter == MLX5_LAG_FILTER_PORTS || filter == MLX5_LAG_FILTER_ALL)
> mlx5_lag_set_vports_agg_speed(ldev);
> +
> + mlx5_self_controller_set(ldev, filter);
> +
> return 0;
[Severity: High]
This problem wasn't introduced by this patch, but can
mlx5_lag_shared_fdb_create() trigger a NULL pointer dereference [1]
when called from mlx5_mpesw_restore_sd_fdb()?
If one port on a multi-port Socket-Direct device has been unbound
(clearing its fn->group_id to 0 in sd_lag_cleanup()) while another port
still has a non-zero group_id, mlx5_mpesw_restore_sd_fdb() iterates over
all functions and calls mlx5_lag_shared_fdb_create(ldev, NULL, 0, 0) for
the unbound port. A zero group_id sets filter to MLX5_LAG_FILTER_ALL and
calls mlx5_activate_lag(ldev, NULL, 0, true) ->
mlx5_infer_tx_affinity_mapping(), which dereferences the NULL tracker
pointer.
> @@ -277,6 +318,21 @@ int mlx5_lag_shared_fdb_create(struct mlx5_lag *ldev,
> return err;
> }
>
> +static void mlx5_self_controller_reset(struct mlx5_lag *ldev, u32 filter)
> +{
> + struct mlx5_esw_functions *esw_funcs;
> + struct mlx5_core_dev *dev;
> + struct mlx5_eswitch *esw;
> + int i;
> +
> + mlx5_lag_for_each(i, 0, ldev, filter) {
> + dev = mlx5_lag_fn(ldev, i)->dev;
> + esw = dev->priv.eswitch;
> + esw_funcs = &esw->esw_funcs;
> + esw_funcs->phys_port_cnum = 0;
> + }
> +}
> +
> void mlx5_lag_shared_fdb_destroy(struct mlx5_lag *ldev, u32 group_id)
> {
> u32 filter = group_id ? group_id : MLX5_LAG_FILTER_ALL;
> @@ -284,6 +340,8 @@ void mlx5_lag_shared_fdb_destroy(struct mlx5_lag *ldev, u32 group_id)
> int err;
> int i;
>
> + mlx5_self_controller_reset(ldev, filter);
> +
> mlx5_lag_remove_devices_filter(ldev, filter);
>
> if (filter == MLX5_LAG_FILTER_PORTS || filter == MLX5_LAG_FILTER_ALL) {
[Severity: Medium]
When a bond over a Socket-Direct device is destroyed with group_id == 0
(filter == MLX5_LAG_FILTER_ALL), doesn't mlx5_self_controller_reset() wipe
phys_port_cnum to 0 across all SD groups even though the per-group SD
shared FDBs remain active? In addition, if mlx5_deactivate_lag() fails
and returns early just below, phys_port_cnum has already been cleared to 0
while the shared-FDB LAG is still active.
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c b/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c
> index 2002b7f376ee6..c8aa1b0b9319d 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c
> @@ -237,6 +237,18 @@ int mlx5_devlink_sf_port_fn_state_set(struct devlink_port *dl_port,
> return mlx5_sf_state_set(dev, table, sf, state, extack);
> }
>
> +static u32
> +mlx5_sf_get_self_controller(struct mlx5_eswitch *esw,
> + const struct devlink_port_new_attrs *new_attr)
> +{
> + struct mlx5_esw_functions *esw_funcs = &esw->esw_funcs;
> +
> + if (!new_attr->controller_valid && esw_funcs->phys_port_cnum)
> + return esw_funcs->phys_port_cnum;
> +
> + return new_attr->controller;
> +}
> +
> static int mlx5_sf_add(struct mlx5_core_dev *dev, struct mlx5_sf_table *table,
> const struct devlink_port_new_attrs *new_attr,
> struct netlink_ext_ack *extack,
> @@ -244,9 +256,11 @@ static int mlx5_sf_add(struct mlx5_core_dev *dev, struct mlx5_sf_table *table,
> {
> struct mlx5_eswitch *esw = dev->priv.eswitch;
> struct mlx5_sf *sf;
> + u32 controller;
> int err;
>
> - sf = mlx5_sf_alloc(table, esw, new_attr->controller, new_attr->pfnum,
> + controller = mlx5_sf_get_self_controller(esw, new_attr);
> + sf = mlx5_sf_alloc(table, esw, controller, new_attr->pfnum,
> new_attr->sfnum, extack);
[Severity: Medium]
Does storing a non-zero controller in sf->controller for local SFs on a
non-master PCI link cause mlx5_sf_table_esw_changed_event_handler() to
corrupt their sf->hw_state when the external host PF is disabled?
When an ESW_FUNCTIONS_CHANGED event arrives with host_pf_info.pf_disabled
set, mlx5_sf_table_esw_changed_event_handler() only skips SFs with
!sf->controller:
drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c:mlx5_sf_table_esw_changed_event_handler() {
...
xa_for_each(&table->function_ids, index, sf) {
if (!sf->controller)
continue;
if (sf->hw_state == MLX5_VHCA_STATE_IN_USE)
sf->hw_state = MLX5_VHCA_STATE_ACTIVE;
else if (sf->hw_state == MLX5_VHCA_STATE_TEARDOWN_REQUEST)
sf->hw_state = MLX5_VHCA_STATE_ALLOCATED;
...
}
Because local self-PF SFs on the non-master PCI link now have a non-zero
sf->controller, a host PF reboot or driver unbind resets their
sf->hw_state. If a local SF is in MLX5_VHCA_STATE_TEARDOWN_REQUEST and is
then deleted via mlx5_sf_dealloc(), seeing MLX5_VHCA_STATE_ALLOCATED causes
it to call mlx5_sf_free() -> mlx5_cmd_dealloc_sf() immediately instead of
mlx5_sf_hw_table_sf_deferred_free() while the local SF driver is still
detaching.
[ ... ]
> @@ -295,9 +311,16 @@ mlx5_sf_new_check_attr(struct mlx5_core_dev *dev, const struct devlink_port_new_
> NL_SET_ERR_MSG_MOD(extack, "External controller is unsupported");
> return -EOPNOTSUPP;
> }
> + esw = dev->priv.eswitch;
> + esw_funcs = &esw->esw_funcs;
> + if (new_attr->controller_valid && !new_attr->controller &&
> + esw_funcs->phys_port_cnum) {
> + NL_SET_ERR_MSG_MOD(extack, "Invalid controller supplied");
> + return -EOPNOTSUPP;
> + }
[Severity: Medium]
Can concurrent shared-FDB creation or teardown race with
mlx5_devlink_sf_port_new() on esw_funcs->phys_port_cnum?
mlx5_self_controller_set() and mlx5_self_controller_reset() update
esw_funcs->phys_port_cnum on non-master PCI functions under ldev->lock
(from ldev->wq or a peer PF's mode change) without holding the non-master
function's devlink lock, while mlx5_devlink_sf_port_new() reads
phys_port_cnum three times without ldev->lock:
CPU0 (non-master devl_lock) CPU1 (ldev->lock)
mlx5_devlink_sf_port_new()
mlx5_sf_new_check_attr()
/* phys_port_cnum == 4 */
mlx5_sf_add()
mlx5_sf_get_self_controller()
controller = 4
mlx5_lag_shared_fdb_destroy()
mlx5_self_controller_reset()
esw_funcs->phys_port_cnum = 0
mlx5_sf_alloc(..., 4, ...)
mlx5_esw_offloads_controller_valid(esw, 4)
--> false (-EINVAL)
If the user omitted the controller attribute, the driver's own selected
controller number is rejected with -EINVAL; in the reverse direction, if
mlx5_self_controller_set() runs after mlx5_sf_new_check_attr() allows an
explicit controller 0, the SF is created with controller 0 while shared
FDB is active.
[1] https://sashiko.dev/#/bug/linux-8703abcc-6916-44c4-b3c7-fe51c61aab5f
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125212032.243064-1-tariqt@nvidia.com?part=2
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next 0/2] net/mlx5: Add controller number to SF and VF phys_port_name
2026-11-25 21:20 [PATCH net-next 0/2] net/mlx5: Add controller number to SF and VF phys_port_name Tariq Toukan
2026-11-25 21:20 ` [PATCH net-next 1/2] net/mlx5: SF, Pass pfnum through the SF hardware-table allocation path Tariq Toukan
2026-11-25 21:20 ` [PATCH net-next 2/2] net/mlx5: Add controller number for SF and ECVF phys_port_name Tariq Toukan
@ 2026-11-26 21:21 ` sashiko-bot
2 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-26 21:21 UTC (permalink / raw)
To: Tariq Toukan; +Cc: linux-rdma
Sashiko has finished reviewing this 2-patch series:
- Patch 1: no issues found.
- Patch 2 ("net/mlx5: Add controller number for SF and ECVF phys..."): 5
potential issues (5 Medium) and 1 related pre-existing bug
A detailed review has been sent as a separate reply to patch 2.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125212032.243064-1-tariqt@nvidia.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next 2/2] net/mlx5: Add controller number for SF and ECVF phys_port_name
2026-11-25 21:20 ` [PATCH net-next 2/2] net/mlx5: Add controller number for SF and ECVF phys_port_name Tariq Toukan
2026-11-26 21:21 ` sashiko-bot
@ 2026-11-26 22:10 ` netdev-bot+sashiko
1 sibling, 0 replies; 6+ messages in thread
From: netdev-bot+sashiko @ 2026-11-26 22:10 UTC (permalink / raw)
To: tariqt
Cc: andrew+netdev, davem, edumazet, kuba, netdev, pabeni, cjubran,
cmi, gal, kees+treewide, leon, linux-rdma, mbloch, moshe,
ohartoov, parav, saeedm, shayd
Thank you for your contribution! Sashiko AI review found 6 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 5 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The controller prefix only reaches devlink ports created while
the shared FDB is active, so phys_port_names can still collide.
- [Medium] The SF-add validators disagree on what the 'self controller'
is.
- [Medium] Local SFs on the non-master link now carry a non-zero
sf->controller (phys_port_cnum, via mlx5_sf_get_self_controller() ->…
- [Medium] Nothing serialises esw_funcs->phys_port_cnum between its
writers and the devlink SF port_new readers.
- [Medium] mlx5_esw_sf_controller_to_pfnum_valid() now accepts any
satellite PF whose (host_number+1, pf_num) matches the request.
- [Medium] The patch gives the self PF controller_num = QUERY_PF
host_number + 1.
--
net/mlx5: Add controller number for SF and ECVF phys_port_name
This commit gives the non-master PCI link in a BlueField-4 Socket-Direct
shared FDB a non-zero controller number (QUERY_PF host_number + 1). SFs
and EC VFs on that link then get a cN prefix in phys_port_name. It tracks
the self PF controller and pfnum in the eswitch, sets and resets
phys_port_cnum on shared FDB create and destroy, and updates SF
validation and hwc table selection.
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c b/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c
> index 8b46634203b37..fa07a571c1b99 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c
> @@ -83,7 +83,9 @@ static void mlx5_esw_offloads_pf_vf_devlink_port_attrs_set(struct mlx5_eswitch *
>
> memcpy(dl_port->attrs.switch_id.id, ppid.id, ppid.id_len);
> dl_port->attrs.switch_id.id_len = ppid.id_len;
> - devlink_port_attrs_pci_vf_set(dl_port, 0, pfnum,
> + controller_num = mlx5_esw_get_self_pf_ctrl_num(esw);
> + pfnum = mlx5_esw_get_self_pf_pfnum(esw);
> + devlink_port_attrs_pci_vf_set(dl_port, controller_num, pfnum,
> vport_num - base_vport, false);
[Severity: High]
Are these attrs ever refreshed after phys_port_cnum changes?
mlx5_esw_get_self_pf_ctrl_num() reads phys_port_cnum here only once, when
the EC VF vport is loaded. Only mlx5_self_controller_set() sets
phys_port_cnum, and it runs as the last step of
mlx5_lag_shared_fdb_create().
In the SD flow, mlx5_devlink_eswitch_mode_set() runs esw_offloads_start()
first:
esw_offloads_start()
mlx5_eswitch_enable_pf_vf_vports()
mlx5_eswitch_load_ec_vf_vports()
mlx5_eswitch_load_pf_vf_vport()
mlx5_esw_offloads_init_pf_vf_rep()
mlx5_esw_offloads_pf_vf_devlink_port_attrs_set()
Only after that does it run:
mlx5_sd_eswitch_mode_set()
mlx5_sd_activate_shared_fdb()
mlx5_lag_shared_fdb_create()
mlx5_self_controller_set()
The later rep reload paths (mlx5_eswitch_reload_reps_blocked() and the IB
rep reload) reuse the existing vport->dl_port, so the attrs keep
controller 0.
Would EC VFs that exist at switchdev entry still be named pf0vf0 and
collide with the master's ports? The same question applies to SFs added
through mlx5_sf_get_self_controller() before the shared FDB exists, which
would still be named pf0sf0.
In the other direction, mlx5_self_controller_reset() clears phys_port_cnum
on destroy. Ports that are already registered keep the cN prefix, while
new ones get none. Does phys_port_name then depend on the order of
operations?
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
> index 8c2c55ba5c35e..09a29280c48e3 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
[ ... ]
> +bool mlx5_esw_sf_controller_to_pfnum_valid(struct mlx5_core_dev *dev,
> + u32 controller, u32 pfnum)
> {
> struct mlx5_eswitch *esw = dev->priv.eswitch;
> struct mlx5_esw_functions *esw_funcs;
> + bool known_controller = false;
> int i;
>
> - if (!controller)
> - return PCI_FUNC(dev->pdev->devfn);
> + if (!MLX5_CAP_GEN(dev, query_host_net_function_v1))
> + return pfnum == PCI_FUNC(dev->pdev->devfn);
>
> esw_funcs = &esw->esw_funcs;
> - for (i = 0; i < esw_funcs->num_spfs; i++)
> - if (controller == esw_funcs->spfs[i].host_number + 1)
> - return esw_funcs->spfs[i].pf_num;
> + if (!controller || controller == esw_funcs->controller_num) {
> + known_controller = true;
> + if (mlx5_esw_get_self_pf_pfnum(esw) == pfnum)
> + return true;
> + }
[Severity: Medium]
Does this check agree with mlx5_esw_offloads_controller_valid()?
This function accepts controller_num with the self pfnum on every device,
whatever the LAG or master state. mlx5_sf_controller_to_hwc() also maps
(controller_num, self pfnum) to hwc[MLX5_SF_HWC_LOCAL] on any device.
mlx5_esw_offloads_controller_valid(), however, accepts the self controller
only when it equals a non-zero phys_port_cnum.
mlx5_sf_new_check_attr() rejects an explicit controller 0 when
phys_port_cnum is set. It has no matching rejection of an explicit
controller_num when phys_port_cnum is 0, which is the case on the master,
on a standalone device, or after mlx5_lag_shared_fdb_destroy().
On such a device, "devlink port add ... pfnum <self> controller
<controller_num>" passes mlx5_sf_new_check_attr() and this function. After
that, it either fails in mlx5_sf_alloc() with "Invalid controller number",
or it succeeds if an SPF shares that host_number.
In the success case, would a local SF taken from the LOCAL hwc be labelled
cNpfXsfY on the master?
The commit message says:
But if user specifies other controller number, command fails.
Does that still hold for this case?
The "Local controller is always valid" comment in
mlx5_esw_offloads_controller_valid() also looks stale now, because an
explicit controller 0 is rejected earlier when phys_port_cnum is set.
[ ... ]
> +static int mlx5_esw_self_pf_init(struct mlx5_eswitch *esw)
> +{
> + struct mlx5_esw_functions *esw_funcs = &esw->esw_funcs;
> + struct mlx5_core_dev *dev = esw->dev;
[ ... ]
> + entry = MLX5_ADDR_OF(query_esw_functions_out, out, net_function_params);
> + for (i = 0; i < num_entries; i++) {
> + int pf_type;
> +
> + pf_type = MLX5_GET(network_function_params, entry, pci_pf_type);
> + if (pf_type != MLX5_PCI_PF_TYPE_QUERY_PF) {
> + entry += MLX5_UN_SZ_BYTES(net_function_params);
> + continue;
> + }
> +
> + esw_funcs->controller_num =
> + MLX5_GET(network_function_params,
> + entry, host_number) + 1;
> + esw_funcs->self_pf_pfnum =
> + MLX5_GET(network_function_params,
> + entry, pci_device_function);
[Severity: Medium]
Is pci_device_function enough to tell the self PF apart from a satellite
PF?
The commit message says the self PF and the satellite PFs share a
controller number, so self_pf_pfnum is the only tie-breaker. Neither this
function nor mlx5_esw_spfs_init() records pci_bus from
network_function_params, and pci_device_function is only unique per bus.
Suppose a self PF and an SPF of the same host both report function 0 on
different buses, like 0002:01:00.0 and 0006:01:00.0 in the commit example.
mlx5_sf_controller_to_hwc() would then return hwc[MLX5_SF_HWC_LOCAL]
before it scans the SPF tables. mlx5_esw_sf_controller_to_pfnum_valid()
would also accept the request as a self PF SF before it checks the SPFs.
Would an SF requested on the SPF then be allocated from the self PF's
function ID range via mlx5_sf_sw_to_hw_id()? If so, the SPF's hwc table
could not be reached for that controller/pfnum pair.
[ ... ]
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c
> index 404278a15ef73..fb96e9c3a5d84 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c
> @@ -190,6 +190,44 @@ void mlx5_lag_destroy_single_fdb(struct mlx5_lag *ldev)
> mlx5_lag_destroy_single_fdb_filter(ldev, MLX5_LAG_FILTER_ALL);
> }
>
> +static void mlx5_self_controller_set(struct mlx5_lag *ldev, u32 filter)
> +{
> + struct mlx5_core_dev *dev, *master_dev = NULL;
> + struct mlx5_esw_functions *esw_funcs;
> + struct mlx5_eswitch *esw;
> + int i;
> +
> + mlx5_lag_for_each(i, 0, ldev, filter) {
> + dev = mlx5_lag_fn(ldev, i)->dev;
> + esw = dev->priv.eswitch;
> + esw_funcs = &esw->esw_funcs;
> + if (!mlx5_lag_is_master(dev))
> + esw_funcs->phys_port_cnum = esw_funcs->controller_num;
> + else
> + master_dev = dev;
> + }
> +
> + if (!master_dev)
> + return;
> +
> + mlx5_lag_for_each(i, 0, ldev, filter) {
[ ... ]
> + if (host_ctrl_num == master_host_ctrl_num)
> + esw_funcs->phys_port_cnum = 0;
> + }
> +}
[Severity: Medium]
What serializes phys_port_cnum against the devlink port_new path?
mlx5_self_controller_set() and mlx5_self_controller_reset() run under
ldev->lock, called from bond work or mlx5_sd_activate_shared_fdb(). They
write this field for every eswitch in the group, including peers whose
devlink lock isn't held.
mlx5_devlink_sf_port_new() holds only the PF devlink instance lock. It
reads phys_port_cnum three separate times:
mlx5_sf_new_check_attr()
mlx5_sf_add()
mlx5_sf_get_self_controller()
mlx5_sf_alloc()
mlx5_esw_offloads_controller_valid()
Suppose mlx5_sf_new_check_attr() sees 0 and accepts an explicit controller
0, and the shared FDB is then created with phys_port_cnum set to 4. Can
the SF be created as pf0sf0 and collide with the master?
In the reverse order, mlx5_sf_get_self_controller() returns 4 and a
concurrent destroy then resets the field. Can
mlx5_esw_offloads_controller_valid(4) then fail with a spurious "Invalid
controller number"?
This function also writes in two passes. It first sets controller_num on
every non-master, then zeroes the ones that match the master. Can a
concurrent reader see the transient non-zero value?
The EC VF read in mlx5_esw_get_self_pf_ctrl_num() is not synchronized
either.
[ ... ]
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c b/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c
> index 2002b7f376ee6..c8aa1b0b9319d 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c
> @@ -237,6 +237,18 @@ int mlx5_devlink_sf_port_fn_state_set(struct devlink_port *dl_port,
> return mlx5_sf_state_set(dev, table, sf, state, extack);
> }
>
> +static u32
> +mlx5_sf_get_self_controller(struct mlx5_eswitch *esw,
> + const struct devlink_port_new_attrs *new_attr)
> +{
> + struct mlx5_esw_functions *esw_funcs = &esw->esw_funcs;
> +
> + if (!new_attr->controller_valid && esw_funcs->phys_port_cnum)
> + return esw_funcs->phys_port_cnum;
> +
> + return new_attr->controller;
> +}
[Severity: Medium]
Local SFs on the non-master link now carry a non-zero sf->controller.
Existing code treats any non-zero controller as an external host SF. Does
that code handle these local SFs correctly?
When the external host PF is disabled, esw_vfs_changed_event_handler()
calls mlx5_sf_table_esw_changed_event_handler(). That handler only skips
SFs whose sf->controller is 0:
if (!sf->controller)
continue;
if (sf->hw_state == MLX5_VHCA_STATE_IN_USE)
sf->hw_state = MLX5_VHCA_STATE_ACTIVE;
else if (sf->hw_state == MLX5_VHCA_STATE_TEARDOWN_REQUEST)
sf->hw_state = MLX5_VHCA_STATE_ALLOCATED;
Take a deactivated local SF that gets rolled back from TEARDOWN_REQUEST to
ALLOCATED. A later port del goes through mlx5_sf_dealloc() ->
mlx5_sf_free() -> mlx5_sf_hw_table_sf_free() and skips
mlx5_sf_hw_table_sf_deferred_free().
Could the function ID then be reused while firmware still holds it, and
would opstate report the wrong value?
Also, mlx5_sf_hw_table_sf_alloc() arms vhca events under "if
(controller)", and its comment says that is for external controllers. Is
it intended to arm them for these local SFs too?
The same applies to SFs created on the master with an explicit
controller_num, as described above.
[ ... ]
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c b/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c
> index d8d0616834978..b7e8a8d7cc646 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c
> @@ -40,8 +40,18 @@ static struct mlx5_sf_hwc_table *
> mlx5_sf_controller_to_hwc(struct mlx5_core_dev *dev, u32 controller, u32 pfnum)
> {
> struct mlx5_sf_hw_table *table = dev->priv.sf_hw_table;
> + struct mlx5_eswitch *esw = dev->priv.eswitch;
> + struct mlx5_esw_functions *esw_funcs;
> int i;
>
> + /* If shared fdb is destroyed, phys_port_cnum is reset to 0.
> + * So use controller_num directly which is read from firmware.
> + */
> + esw_funcs = &esw->esw_funcs;
> + if (controller == esw_funcs->controller_num &&
> + pfnum == mlx5_esw_get_self_pf_pfnum(esw))
> + return &table->hwc[MLX5_SF_HWC_LOCAL];
> +
> for (i = MLX5_SF_HWC_FIRST_SPF; i < table->num_hwc; i++) {
> if (table->hwc[i].controller == controller)
> return &table->hwc[i];
[Severity: Medium]
mlx5_esw_sf_controller_to_pfnum_valid() now accepts any SPF whose
host_number + 1 and pf_num both match. This loop, however, still picks
the SPF hwc by controller alone.
Suppose two SPFs on one eswitch share a host_number. Could a request for
the second SPF's pfnum pass validation and then be allocated from the
first SPF's hwc range? Both mlx5_sf_hw_table_id_alloc() and
mlx5_sf_sw_to_hw_id() take the first match, while the devlink port would
report the second pfnum.
Before this patch, mlx5_esw_sf_controller_to_pfnum() returned only the
first matching SPF's pf_num, so validation and hwc selection agreed.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125212032.243064-1-tariqt%40nvidia.com
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-26 22:10 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 21:20 [PATCH net-next 0/2] net/mlx5: Add controller number to SF and VF phys_port_name Tariq Toukan
2026-11-25 21:20 ` [PATCH net-next 1/2] net/mlx5: SF, Pass pfnum through the SF hardware-table allocation path Tariq Toukan
2026-11-25 21:20 ` [PATCH net-next 2/2] net/mlx5: Add controller number for SF and ECVF phys_port_name Tariq Toukan
2026-11-26 21:21 ` sashiko-bot
2026-11-26 22:10 ` netdev-bot+sashiko
2026-11-26 21:21 ` [PATCH net-next 0/2] net/mlx5: Add controller number to SF and VF phys_port_name sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox