mlx5 updates 2023-10-27
Subsystems (5)
From: Saeed Mahameed <[email protected]>
This series provides few cleanups to mlx5 prior to merge window. For more information please see tag log below.
Please pull and let me know if there is any problem.
Thanks,
Saeed.
The following changes since commit d96e48a3d55db7ee62e607ad2d89eee1a8585028:
tools: ynl: introduce option to process unknown attributes or types (2023-10-27 14:54:31 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/saeed/linux.git tags/mlx5-updates-2023-10-27
for you to fetch changes up to 284e9944eafab558b9da5f34782288bff8752ddd:
net/mlx5e: Access array with enum values instead of magic numbers (2023-10-27 15:05:29 -0700)
----------------------------------------------------------------
mlx5-updates-2023-10-27
Few mlx5 pending cleanups.
----------------------------------------------------------------
Amir Tzin (1):
net/mlx5e: Some cleanup in mlx5e_tc_stats_matchall()
Gal Pressman (1):
net/mlx5e: Access array with enum values instead of magic numbers
Justin Stitt (1):
net/mlx5: simplify mlx5_set_driver_version string assignments
Kees Cook (2):
net/mlx5: Annotate struct mlx5_fc_bulk with __counted_by net/mlx5: Annotate struct mlx5_flow_handle with __counted_by
Moshe Shemesh (2):
net/mlx5: print change on SW reset semaphore returns busy net/mlx5: Allow sync reset flow when BF MGT interface device is present
Rahul Rameshbabu (3):
net/mlx5: Increase size of irq name buffer
net/mlx5e: Check return value of snprintf writing to fw_version buffer net/mlx5e: Check return value of snprintf writing to fw_version buffer for representors
Saeed Mahameed (1):
net/mlx5e: Reduce the size of icosq_str
.../net/ethernet/mellanox/mlx5/core/diag/crdump.c | 5 +++- .../net/ethernet/mellanox/mlx5/core/en/rep/tc.c | 14 ++++++++++ .../ethernet/mellanox/mlx5/core/en/reporter_rx.c | 4 +-- .../ethernet/mellanox/mlx5/core/en/tc/act/pedit.c | 3 +- .../net/ethernet/mellanox/mlx5/core/en_ethtool.c | 13 ++++++--- drivers/net/ethernet/mellanox/mlx5/core/en_rep.c | 12 +++++--- drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 24 +++------------- drivers/net/ethernet/mellanox/mlx5/core/en_tc.h | 2 -- drivers/net/ethernet/mellanox/mlx5/core/fs_core.h | 2 +- .../net/ethernet/mellanox/mlx5/core/fs_counters.c | 2 +- drivers/net/ethernet/mellanox/mlx5/core/fw_reset.c | 32 +++++++++++++++++++--- drivers/net/ethernet/mellanox/mlx5/core/main.c | 20 ++------------ drivers/net/ethernet/mellanox/mlx5/core/pci_irq.c | 6 ++-- drivers/net/ethernet/mellanox/mlx5/core/pci_irq.h | 3 ++ 14 files changed, 82 insertions(+), 60 deletions(-)
PATCH 1/11 net/mlx5: Increase size of irq name buffer
From: Rahul Rameshbabu <[email protected]>
Without increased buffer size, will trigger -Wformat-truncation with W=1 for the snprintf operation writing to the buffer.
drivers/net/ethernet/mellanox/mlx5/core/pci_irq.c: In function 'mlx5_irq_alloc':
drivers/net/ethernet/mellanox/mlx5/core/pci_irq.c:296:7: error: '@pci:' directive output may be truncated writing 5 bytes into a region of size between 1 and 32 [-Werror=format-truncation=]
296 | "%s@pci:%s", name, pci_name(dev->pdev));
| ^~~~~
drivers/net/ethernet/mellanox/mlx5/core/pci_irq.c:295:2: note: 'snprintf' output 6 or more bytes (assuming 37) into a destination of size 32
295 | snprintf(irq->name, MLX5_MAX_IRQ_NAME,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
296 | "%s@pci:%s", name, pci_name(dev->pdev));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--- drivers/net/ethernet/mellanox/mlx5/core/pci_irq.c | 6 +++--- drivers/net/ethernet/mellanox/mlx5/core/pci_irq.h | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/pci_irq.c +3 -3
@@ -28,7 +28,7 @@struct mlx5_irq {struct atomic_notifier_head nh;cpumask_var_t mask; -char name[MLX5_MAX_IRQ_NAME ]; +char name[MLX5_MAX_IRQ_FORMATTED_NAME ];struct mlx5_irq_pool *pool;int refcount;struct msi_map map;
@@ -292,8 +292,8 @@ struct mlx5_irq *mlx5_irq_alloc(struct mlx5_irq_pool *pool, int i,else irq_sf_set_name (pool, name, i);ATOMIC_INIT_NOTIFIER_HEAD (&irq->nh); -snprintf (irq->name,MLX5_MAX_IRQ_NAME , -"%s@pci:%s" , name,pci_name (dev->pdev)); +snprintf (irq->name,MLX5_MAX_IRQ_FORMATTED_NAME , +MLX5_IRQ_NAME_FORMAT_STR , name,pci_name (dev->pdev)); err =request_irq (irq->map.virq, irq_int_handler,0 , irq->name, &irq->nh);if (err) {
drivers/net/ethernet/mellanox/mlx5/core/pci_irq.h +3 -0
@@ -7,6 +7,9 @@#include <linux/mlx5/driver.h> #define MLX5_MAX_IRQ_NAME (32) +#define MLX5_IRQ_NAME_FORMAT_STR ("%s@pci:%s") +#define MLX5_MAX_IRQ_FORMATTED_NAME \ + (MLX5_MAX_IRQ_NAME + sizeof(MLX5_IRQ_NAME_FORMAT_STR))/* max irq_index is 2047, so four chars */ #define MLX5_MAX_IRQ_IDX_CHARS (4)#define MLX5_EQ_REFS_PER_IRQ (2)
Signature · 1 line
2.41.0
PATCH 2/11 net/mlx5e: Reduce the size of icosq_str
In reply to Saeed MahameedFrom: Saeed Mahameed <[email protected]>
icosq_str size is unnecessarily too long, and it causes a build warning -Wformat-truncation with W=1. Looking closely, It doesn't need to be 255B, hence this patch reduces the size to 32B which should be more than enough to host the string: "ICOSQ: 0x%x, ".
While here, add a missing space in the formatted string.
This fixes the following build warning:
$ KCFLAGS='-Wall -Werror' $ make O=/tmp/kbuild/linux W=1 -s -j12 drivers/net/ethernet/mellanox/mlx5/core/
drivers/net/ethernet/mellanox/mlx5/core/en/reporter_rx.c: In function 'mlx5e_reporter_rx_timeout':drivers/net/ethernet/mellanox/mlx5/core/en/reporter_rx.c:718:56:
error: ', CQ: 0x' directive output may be truncated writing 8 bytes into a region of size between 0 and 255 [-Werror=format-truncation=]
718 | "RX timeout on channel: %d, %sRQ: 0x%x, CQ: 0x%x",
| ^~~~~~~~drivers/net/ethernet/mellanox/mlx5/core/en/reporter_rx.c:717:9: note: 'snprintf' output between 43 and 322 bytes into a destination of size 288
717 | snprintf(err_str, sizeof(err_str),
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
718 | "RX timeout on channel: %d, %sRQ: 0x%x, CQ: 0x%x",
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
719 | rq->ix, icosq_str, rq->rqn, rq->cq.mcq.cqn);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--- drivers/net/ethernet/mellanox/mlx5/core/en/reporter_rx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/reporter_rx.c +2 -2
@@ -492,11 +492,11 @@ static int mlx5e_rx_reporter_dump(struct devlink_health_reporter *reporter,void mlx5e_reporter_rx_timeout (struct mlx5e_rq *rq) { -char icosq_str[MLX5E_REPORTER_PER_Q_MAX_LEN ] = {};char err_str[MLX5E_REPORTER_PER_Q_MAX_LEN ];struct mlx5e_icosq *icosq = rq->icosq;struct mlx5e_priv *priv = rq->priv;struct mlx5e_err_ctx err_ctx = {}; +char icosq_str[32 ] = {}; err_ctx.ctx = rq; err_ctx.recover = mlx5e_rx_reporter_timeout_recover;
@@ -505,7 +505,7 @@ void mlx5e_reporter_rx_timeout(struct mlx5e_rq *rq)if (icosq)snprintf (icosq_str,sizeof (icosq_str),"ICOSQ: 0x%x, " , icosq->sqn);snprintf (err_str,sizeof (err_str), -"RX timeout on channel: %d, %sRQ: 0x%x, CQ: 0x%x" , +"RX timeout on channel: %d, %s RQ: 0x%x, CQ: 0x%x" , rq->ix, icosq_str, rq->rqn, rq->cq.mcq.cqn);mlx5e_health_report (priv, priv->rx_reporter, err_str, &err_ctx);
Signature · 1 line
2.41.0
PATCH 3/11 net/mlx5e: Check return value of snprintf writing to fw_version buffer
In reply to Saeed MahameedFrom: Rahul Rameshbabu <[email protected]>
Treat the operation as an error case when the return value is equivalent to the size of the name buffer. Failed to write null terminator to the name buffer, making the string malformed and should not be used. Provide a string with only the firmware version when forming the string with the board id fails.
Without check, will trigger -Wformat-truncation with W=1.
drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c: In function 'mlx5e_ethtool_get_drvinfo':
drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c:49:31: warning: '%.16s' directive output may be truncated writing up to 16 bytes into a region of size between 13 and 22 [-Wformat-truncation=]
49 | "%d.%d.%04d (%.16s)",
| ^~~~~
drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c:48:9: note: 'snprintf' output between 12 and 37 bytes into a destination of size 32
48 | snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
49 | "%d.%d.%04d (%.16s)",
| ~~~~~~~~~~~~~~~~~~~~~
50 | fw_rev_maj(mdev), fw_rev_min(mdev), fw_rev_sub(mdev),
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
51 | mdev->board_id);
| ~~~~~~~~~~~~~~~--- .../net/ethernet/mellanox/mlx5/core/en_ethtool.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c +9 -4
@@ -43,12 +43,17 @@ void mlx5e_ethtool_get_drvinfo(struct mlx5e_priv *priv, struct ethtool_drvinfo *drvinfo) {struct mlx5_core_dev *mdev = priv->mdev; +int count;strscpy (drvinfo->driver,KBUILD_MODNAME ,sizeof (drvinfo->driver)); -snprintf (drvinfo->fw_version,sizeof (drvinfo->fw_version), -"%d.%d.%04d (%.16s)" , -fw_rev_maj (mdev),fw_rev_min (mdev),fw_rev_sub (mdev), - mdev->board_id); + count =snprintf (drvinfo->fw_version,sizeof (drvinfo->fw_version), +"%d.%d.%04d (%.16s)" ,fw_rev_maj (mdev), +fw_rev_min (mdev),fw_rev_sub (mdev), mdev->board_id); +if (count ==sizeof (drvinfo->fw_version)) +snprintf (drvinfo->fw_version,sizeof (drvinfo->fw_version), +"%d.%d.%04d" ,fw_rev_maj (mdev), +fw_rev_min (mdev),fw_rev_sub (mdev)); +strscpy (drvinfo->bus_info,dev_name (mdev->device),sizeof (drvinfo->bus_info)); }
Signature · 1 line
2.41.0
PATCH 4/11 net/mlx5e: Check return value of snprintf writing to fw_version buffer for representors
In reply to Saeed MahameedFrom: Rahul Rameshbabu <[email protected]>
Treat the operation as an error case when the return value is equivalent to the size of the name buffer. Failed to write null terminator to the name buffer, making the string malformed and should not be used. Provide a string with only the firmware version when forming the string with the board id fails. This logic for representors is identical to normal flow with ethtool.
Without check, will trigger -Wformat-truncation with W=1.
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c: In function 'mlx5e_rep_get_drvinfo':
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c:78:31: warning: '%.16s' directive output may be truncated writing up to 16 bytes into a region of size between 13 and 22 [-Wformat-truncation=]
78 | "%d.%d.%04d (%.16s)",
| ^~~~~
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c:77:9: note: 'snprintf' output between 12 and 37 bytes into a destination of size 32
77 | snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
78 | "%d.%d.%04d (%.16s)",
| ~~~~~~~~~~~~~~~~~~~~~
79 | fw_rev_maj(mdev), fw_rev_min(mdev),
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
80 | fw_rev_sub(mdev), mdev->board_id);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--- drivers/net/ethernet/mellanox/mlx5/core/en_rep.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c +8 -4
@@ -71,13 +71,17 @@ static void mlx5e_rep_get_drvinfo(struct net_device *dev, {struct mlx5e_priv *priv =netdev_priv (dev);struct mlx5_core_dev *mdev = priv->mdev; +int count;strscpy (drvinfo->driver, mlx5e_rep_driver_name,sizeof (drvinfo->driver)); -snprintf (drvinfo->fw_version,sizeof (drvinfo->fw_version), -"%d.%d.%04d (%.16s)" , -fw_rev_maj (mdev),fw_rev_min (mdev), -fw_rev_sub (mdev), mdev->board_id); + count =snprintf (drvinfo->fw_version,sizeof (drvinfo->fw_version), +"%d.%d.%04d (%.16s)" ,fw_rev_maj (mdev), +fw_rev_min (mdev),fw_rev_sub (mdev), mdev->board_id); +if (count ==sizeof (drvinfo->fw_version)) +snprintf (drvinfo->fw_version,sizeof (drvinfo->fw_version), +"%d.%d.%04d" ,fw_rev_maj (mdev), +fw_rev_min (mdev),fw_rev_sub (mdev)); }static const struct counter_desc sw_rep_stats_desc[] = {
Signature · 1 line
2.41.0
PATCH 5/11 net/mlx5: print change on SW reset semaphore returns busy
In reply to Saeed MahameedFrom: Moshe Shemesh <[email protected]>
While collecting crdump as part of fw_fatal health reporter dump the PF may fail to lock the SW reset semaphore. Change the print to indicate if it was due to another PF locked the semaphore already and so trying to lock the semaphore returned -EBUSY.
--- drivers/net/ethernet/mellanox/mlx5/core/diag/crdump.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/diag/crdump.c +4 -1
@@ -55,7 +55,10 @@ int mlx5_crdump_collect(struct mlx5_core_dev *dev, u32 *cr_data) ret =mlx5_vsc_sem_set_space (dev,MLX5_SEMAPHORE_SW_RESET ,MLX5_VSC_LOCK );if (ret) { -mlx5_core_warn (dev,"Failed to lock SW reset semaphore\n" ); +if (ret == -EBUSY ) +mlx5_core_info (dev,"SW reset semaphore is already in use\n" ); +else +mlx5_core_warn (dev,"Failed to lock SW reset semaphore\n" ); goto unlock_gw; }
Signature · 1 line
2.41.0
PATCH 6/11 net/mlx5: Allow sync reset flow when BF MGT interface device is present
In reply to Saeed MahameedFrom: Moshe Shemesh <[email protected]>
In sync reset flow, PF is checking that only devices of same device ID as itself present on the PCIe bridge, otherwise it will NACK the reset. Since the PCIe bridge connection to NIC card has to be 1 to 1, this is valid.
However, the BlueField device may also expose another sub-device to the PCI called management interface, which only provides an ethernet channel between the host and the smart NIC.
Allow sync reset flow also when management interface sub-device present when checking devices on the PCIe bridge.
--- .../ethernet/mellanox/mlx5/core/fw_reset.c | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/fw_reset.c +28 -4
@@ -325,6 +325,25 @@ static void mlx5_fw_live_patch_event(struct work_struct *work)mlx5_core_err (dev,"Failed to reload FW tracer\n" ); } +static const struct pci_device_id mgt_ifc_device_ids[] = { + {PCI_VDEVICE (MELLANOX ,0xc2d2 ) },/* BlueField1 MGT interface device ID */ + {PCI_VDEVICE (MELLANOX ,0xc2d3 ) },/* BlueField2 MGT interface device ID */ + {PCI_VDEVICE (MELLANOX ,0xc2d4 ) },/* BlueField3-Lx MGT interface device ID */ + {PCI_VDEVICE (MELLANOX ,0xc2d5 ) },/* BlueField3 MGT interface device ID */ + {PCI_VDEVICE (MELLANOX ,0xc2d6 ) },/* BlueField4 MGT interface device ID */ +}; + +static bool mlx5_is_mgt_ifc_pci_device (struct mlx5_core_dev *dev,u16 dev_id) +{ +int i; + +for (i =0 ; i <ARRAY_SIZE (mgt_ifc_device_ids); ++i) +if (mgt_ifc_device_ids[i].device == dev_id) +return true; + +return false; +} +static int mlx5_check_dev_ids (struct mlx5_core_dev *dev,u16 dev_id) {struct pci_bus *bridge_bus = dev->pdev->bus;
@@ -339,10 +358,15 @@ static int mlx5_check_dev_ids(struct mlx5_core_dev *dev, u16 dev_id) err =pci_read_config_word (sdev,PCI_DEVICE_ID , &sdev_id);if (err)return pcibios_err_to_errno (err); -if (sdev_id != dev_id) { -mlx5_core_warn (dev,"unrecognized dev_id (0x%x)\n" , sdev_id); -return -EPERM ; - } + +if (sdev_id == dev_id) +continue ; + +if (mlx5_is_mgt_ifc_pci_device (dev, sdev_id)) +continue ; + +mlx5_core_warn (dev,"unrecognized dev_id (0x%x)\n" , sdev_id); +return -EPERM ; }return 0 ; }
Signature · 1 line
2.41.0
PATCH 7/11 net/mlx5e: Some cleanup in mlx5e_tc_stats_matchall()
In reply to Saeed MahameedFrom: Amir Tzin <[email protected]>
Function mlx5e_tc_stats_matchall() is only called from one file:drivers/net/ethernet/mellanox/mlx5/core/en/rep/tc.c
Move it there and make it static as exposing it is unnecessary. Also variable cur_stats is redundant. Remove it and avoid superfluous copy.
This patch does not change functionality.
--- .../net/ethernet/mellanox/mlx5/core/en/rep/tc.c | 14 ++++++++++++++ drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 16 ---------------- drivers/net/ethernet/mellanox/mlx5/core/en_tc.h | 2 -- 3 files changed, 14 insertions(+), 18 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/rep/tc.c +14 -0
@@ -147,6 +147,20 @@ mlx5e_rep_setup_tc_cls_flower(struct mlx5e_priv *priv, } } +static void mlx5e_tc_stats_matchall (struct mlx5e_priv *priv, +struct tc_cls_matchall_offload *ma) +{ +struct mlx5e_rep_priv *rpriv = priv->ppriv; +u64 dbytes; +u64 dpkts; + + dpkts = priv->stats.rep_stats.vport_rx_packets - rpriv->prev_vf_vport_stats.rx_packets; + dbytes = priv->stats.rep_stats.vport_rx_bytes - rpriv->prev_vf_vport_stats.rx_bytes; +mlx5e_stats_copy_rep_stats (&rpriv->prev_vf_vport_stats, &priv->stats.rep_stats); +flow_stats_update (&ma->stats, dbytes, dpkts,0 , jiffies, +FLOW_ACTION_HW_STATS_DELAYED ); +} +static int mlx5e_rep_setup_tc_cls_matchall (struct mlx5e_priv *priv,struct tc_cls_matchall_offload *ma)
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +0 -16
@@ -5007,22 +5007,6 @@ int mlx5e_tc_delete_matchall(struct mlx5e_priv *priv,return apply_police_params (priv,0 , extack); } -void mlx5e_tc_stats_matchall (struct mlx5e_priv *priv, -struct tc_cls_matchall_offload *ma) -{ -struct mlx5e_rep_priv *rpriv = priv->ppriv; -struct rtnl_link_stats64 cur_stats; -u64 dbytes; -u64 dpkts; - -mlx5e_stats_copy_rep_stats (&cur_stats, &priv->stats.rep_stats); - dpkts = cur_stats.rx_packets - rpriv->prev_vf_vport_stats.rx_packets; - dbytes = cur_stats.rx_bytes - rpriv->prev_vf_vport_stats.rx_bytes; - rpriv->prev_vf_vport_stats = cur_stats; -flow_stats_update (&ma->stats, dbytes, dpkts,0 , jiffies, -FLOW_ACTION_HW_STATS_DELAYED ); -} -static void mlx5e_tc_hairpin_update_dead_peer (struct mlx5e_priv *priv,struct mlx5e_priv *peer_priv) {
drivers/net/ethernet/mellanox/mlx5/core/en_tc.h +0 -2
@@ -203,8 +203,6 @@ int mlx5e_tc_configure_matchall(struct mlx5e_priv *priv, struct tc_cls_matchall_offload *f);int mlx5e_tc_delete_matchall (struct mlx5e_priv *priv,struct tc_cls_matchall_offload *f); -void mlx5e_tc_stats_matchall (struct mlx5e_priv *priv, -struct tc_cls_matchall_offload *ma);struct mlx5e_encap_entry ; void mlx5e_tc_encap_flows_add(struct mlx5e_priv *priv,
Signature · 1 line
2.41.0
PATCH 8/11 net/mlx5: Annotate struct mlx5_fc_bulk with __counted_by
In reply to Saeed MahameedFrom: Kees Cook <[email protected]>
Prepare for the coming implementation by GCC and Clang of the __counted_by attribute. Flexible array members annotated with __counted_by can have their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions).
As found with Coccinelle[1], add __counted_by for struct mlx5_fc_bulk.
--- drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c +1 -1
@@ -539,7 +539,7 @@ struct mlx5_fc_bulk {u32 base_id;int bulk_len;unsigned long *bitmask; -struct mlx5_fc fcs[]; + struct mlx5_fc fcs[] __counted_by(bulk_len); }; static void mlx5_fc_init(struct mlx5_fc *counter, struct mlx5_fc_bulk *bulk,
Signature · 1 line
2.41.0
PATCH 9/11 net/mlx5: Annotate struct mlx5_flow_handle with __counted_by
In reply to Saeed MahameedFrom: Kees Cook <[email protected]>
Prepare for the coming implementation by GCC and Clang of the __counted_by attribute. Flexible array members annotated with __counted_by can have their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions).
As found with Coccinelle[1], add __counted_by for struct mlx5_flow_handle.
--- drivers/net/ethernet/mellanox/mlx5/core/fs_core.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/fs_core.h +1 -1
@@ -181,7 +181,7 @@ struct mlx5_flow_rule {struct mlx5_flow_handle {int num_rules; -struct mlx5_flow_rule *rule[]; + struct mlx5_flow_rule *rule[] __counted_by(num_rules); };/* Type of children is mlx5_flow_group */
Signature · 1 line
2.41.0
PATCH 10/11 net/mlx5: simplify mlx5_set_driver_version string assignments
In reply to Saeed MahameedFrom: Justin Stitt <[email protected]>
In total, just assigning this version string takes:
(1) strncpy()'s
(5) strlen()'s
(3) strncat()'s
(1) snprintf()'s
(4) max_t()'s
Moreover, strncpy is deprecated [1] and strncat really shouldn't be used either [2]. With this in mind, let's simply use a single snprintf.
--- .../net/ethernet/mellanox/mlx5/core/main.c | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/main.c +3 -17
@@ -219,7 +219,6 @@ static void mlx5_set_driver_version(struct mlx5_core_dev *dev)int driver_ver_sz =MLX5_FLD_SZ_BYTES (set_driver_version_in, driver_version);u8 in[MLX5_ST_SZ_BYTES (set_driver_version_in)] = {}; -int remaining_size = driver_ver_sz;char *string;if (!MLX5_CAP_GEN (dev, driver_version))
@@ -227,22 +226,9 @@ static void mlx5_set_driver_version(struct mlx5_core_dev *dev) string =MLX5_ADDR_OF (set_driver_version_in, in, driver_version); -strncpy (string,"Linux" , remaining_size); - - remaining_size =max_t (int,0 , driver_ver_sz -strlen (string)); -strncat (string,"," , remaining_size); - - remaining_size =max_t (int,0 , driver_ver_sz -strlen (string)); -strncat (string,KBUILD_MODNAME , remaining_size); - - remaining_size =max_t (int,0 , driver_ver_sz -strlen (string)); -strncat (string,"," , remaining_size); - - remaining_size =max_t (int,0 , driver_ver_sz -strlen (string)); - -snprintf (string +strlen (string), remaining_size,"%u.%u.%u" , -LINUX_VERSION_MAJOR ,LINUX_VERSION_PATCHLEVEL , -LINUX_VERSION_SUBLEVEL ); +snprintf (string, driver_ver_sz,"Linux,%s,%u.%u.%u" , +KBUILD_MODNAME ,LINUX_VERSION_MAJOR , +LINUX_VERSION_PATCHLEVEL ,LINUX_VERSION_SUBLEVEL );/*Send the command*/ MLX5_SET(set_driver_version_in, in, opcode,
Signature · 1 line
2.41.0
PATCH 11/11 net/mlx5e: Access array with enum values instead of magic numbers
In reply to Saeed MahameedFrom: Gal Pressman <[email protected]>
Access the headers array using pedit_cmd enum values, and don't assume anything about their values.
--- drivers/net/ethernet/mellanox/mlx5/core/en/tc/act/pedit.c | 3 ++- drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/tc/act/pedit.c +2 -1
@@ -48,7 +48,8 @@ mlx5e_tc_act_pedit_parse_action(struct mlx5e_priv *priv,struct pedit_headers_action *hdrs, struct netlink_ext_ack *extack) { - u8 cmd = (act->id == FLOW_ACTION_MANGLE) ? 0 : 1; + u8 cmd = (act->id == FLOW_ACTION_MANGLE) ? TCA_PEDIT_KEY_EX_CMD_SET : +TCA_PEDIT_KEY_EX_CMD_ADD ;u8 htype = act->mangle.htype;int err = -EOPNOTSUPP ;u32 mask, val, offset;
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +4 -4
@@ -3195,10 +3195,10 @@ static int offload_pedit_fields(struct mlx5e_priv *priv, headers_c =mlx5e_get_match_headers_criteria (*action_flags, &parse_attr->spec); headers_v =mlx5e_get_match_headers_value (*action_flags, &parse_attr->spec); - set_masks = &hdrs[0 ].masks; - add_masks = &hdrs[1 ].masks; - set_vals = &hdrs[0 ].vals; - add_vals = &hdrs[1 ].vals; + set_masks = &hdrs[TCA_PEDIT_KEY_EX_CMD_SET ].masks; + add_masks = &hdrs[TCA_PEDIT_KEY_EX_CMD_ADD ].masks; + set_vals = &hdrs[TCA_PEDIT_KEY_EX_CMD_SET ].vals; + add_vals = &hdrs[TCA_PEDIT_KEY_EX_CMD_ADD ].vals;for (i =0 ; i <ARRAY_SIZE (fields); i++) {bool skip;
Signature · 1 line
2.41.0
Jakub Kicinski
maintainerQuoted 2 lines · On Fri, 27 Oct 2023 15:19:55 -0700 Saeed Mahameed wrote:
This series provides few cleanups to mlx5 prior to merge window. For more information please see tag log below.
## Form letter - net-next-closed
The merge window for v6.7 has begun and we have already posted our pull request. Therefore net-next is closed for new drivers, features, code refactoring and optimizations. We are currently accepting bug fixes only.
Please repost when net-next reopens after Nov 12th.
RFC patches sent for review only are obviously welcome at any time.
See: https://www.kernel.org/doc/html/next/process/maintainer-netdev.html#development-cycle
Signature · 1 line
pw-bot: defer