mlx5 misc fixes 2024-10-15
Tariq Toukan
maintainercover mlx5 misc fixes 2024-10-15
Hi,
This patchset provides misc bug fixes from the team to the mlx5 core and Eth drivers.
Series generated against:
commit 174714f0e505 ("selftests: drivers: net: fix name not defined")
Thanks,
Tariq.
Cosmin Ratiu (4):
net/mlx5: HWS, don't destroy more bwc queue locks than allocated net/mlx5: HWS, use lock classes for bwc locks net/mlx5: Unregister notifier on eswitch init failure net/mlx5e: Don't call cleanup on profile rollback failure
Maher Sanalla (1):
net/mlx5: Check for invalid vector index on EQ creation
Shay Drory (1):
net/mlx5: Fix command bitmask initialization
Yevgeny Kliteynik (2):
net/mlx5: HWS, removed wrong access to a number of rules variable net/mlx5: HWS, fixed double free in error flow of definer layout
drivers/net/ethernet/mellanox/mlx5/core/cmd.c | 8 +++++-- .../net/ethernet/mellanox/mlx5/core/en_main.c | 4 +++- drivers/net/ethernet/mellanox/mlx5/core/eq.c | 6 +++++ .../net/ethernet/mellanox/mlx5/core/eswitch.c | 5 +++-- .../mlx5/core/steering/hws/mlx5hws_bwc.c | 4 +--- .../mlx5/core/steering/hws/mlx5hws_context.h | 1 + .../mlx5/core/steering/hws/mlx5hws_definer.c | 4 ++-- .../mlx5/core/steering/hws/mlx5hws_send.c | 22 ++++++++++++++++--- 8 files changed, 41 insertions(+), 13 deletions(-)
Signature · 1 line
2.44.0
Tariq Toukan
maintainerPATCH 1/8 net/mlx5: HWS, removed wrong access to a number of rules variable
From: Yevgeny Kliteynik <[email protected]>
Removed wrong access to the num_of_rules field of the matcher. This is a usual u32 variable, but the access was as if it was atomic.
This fixes the following CI warnings:
mlx5hws_bwc.c:708:17: warning: large atomic operation may incur significant performance penalty; the access size (4 bytes) exceeds the max lock-free size (0 bytes) [-Watomic-alignment]
--- .../ethernet/mellanox/mlx5/core/steering/hws/mlx5hws_bwc.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/mlx5hws_bwc.c +1 -3
@@ -691,7 +691,6 @@ static int hws_bwc_matcher_move(struct mlx5hws_bwc_matcher *bwc_matcher)static int hws_bwc_matcher_rehash_size (struct mlx5hws_bwc_matcher *bwc_matcher) { -u32 num_of_rules;int ret;/* If the current matcher size is already at its max size, we can't
@@ -705,8 +704,7 @@ hws_bwc_matcher_rehash_size(struct mlx5hws_bwc_matcher *bwc_matcher)* Need to check again if we really need rehash. * If the reason for rehash was size, but not any more - skip rehash. */ - num_of_rules =__atomic_load_n (&bwc_matcher->num_of_rules, __ATOMIC_RELAXED); -if (!hws_bwc_matcher_rehash_size_needed (bwc_matcher, num_of_rules)) +if (!hws_bwc_matcher_rehash_size_needed (bwc_matcher, bwc_matcher->num_of_rules))return 0 ;/* Now we're done all the checking - do the rehash:
Signature · 1 line
2.44.0
Tariq Toukan
maintainerPATCH 2/8 net/mlx5: HWS, fixed double free in error flow of definer layout
In reply to Tariq ToukanFrom: Yevgeny Kliteynik <[email protected]>
Fix error flow bug that could lead to double free of a buffer during a failure to calculate a suitable definer layout.
--- .../mellanox/mlx5/core/steering/hws/mlx5hws_definer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/mlx5hws_definer.c +2 -2
@@ -1925,7 +1925,7 @@ mlx5hws_definer_calc_layout(struct mlx5hws_context *ctx, ret =hws_definer_conv_match_params_to_hl (ctx, mt, match_hl);if (ret) {mlx5hws_err (ctx,"Failed to convert items to header layout\n" ); - goto free_fc; + goto free_match_hl; }/* Find the match definer layout for header layout match union */
@@ -1946,7 +1946,7 @@ mlx5hws_definer_calc_layout(struct mlx5hws_context *ctx, free_fc:kfree (mt->fc); - +free_match_hl:kfree (match_hl);return ret; }
Signature · 1 line
2.44.0
Tariq Toukan
maintainerPATCH 3/8 net/mlx5: HWS, don't destroy more bwc queue locks than allocated
In reply to Tariq ToukanFrom: Cosmin Ratiu <[email protected]>
hws_send_queues_bwc_locks_destroy destroyed more queue locks than allocated, leading to memory corruption (occasionally) and warnings such as DEBUG_LOCKS_WARN_ON(mutex_is_locked(lock)) in __mutex_destroy because sometimes, the 'mutex' being destroyed was random memory. The severity of this problem is proportional to the number of queues configured because the code overreaches beyond the end of the bwc_send_queue_locks array by 2x its length.
Fix that by using the correct number of bwc queues.
--- .../net/ethernet/mellanox/mlx5/core/steering/hws/mlx5hws_send.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/mlx5hws_send.c +1 -1
@@ -941,7 +941,7 @@ static void __hws_send_queues_close(struct mlx5hws_context *ctx, u16 queues)static void hws_send_queues_bwc_locks_destroy (struct mlx5hws_context *ctx) { -int bwc_queues = ctx->queues -1 ; +int bwc_queues =mlx5hws_bwc_queues (ctx);int i;if (!mlx5hws_context_bwc_supported (ctx))
Signature · 1 line
2.44.0
Tariq Toukan
maintainerPATCH 4/8 net/mlx5: HWS, use lock classes for bwc locks
In reply to Tariq ToukanFrom: Cosmin Ratiu <[email protected]>
The HWS BWC API uses one lock per queue and usually acquires one of them, except when doing changes which require locking all queues in order. Naturally, lockdep isn't too happy about acquiring the same lock class multiple times, so inform it that each queue lock is a different class to avoid false positives.
--- .../mlx5/core/steering/hws/mlx5hws_context.h | 1 + .../mlx5/core/steering/hws/mlx5hws_send.c | 20 +++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/mlx5hws_context.h +1 -0
@@ -46,6 +46,7 @@ struct mlx5hws_context {struct mlx5hws_send_engine *send_queue;size_t queues;struct mutex *bwc_send_queue_locks;/* protect BWC queues */ +struct lock_class_key *bwc_lock_class_keys;struct list_head tbl_list;struct mlx5hws_context_debug_info debug_info;struct xarray peer_ctx_xa;
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/mlx5hws_send.c +18 -2
@@ -947,8 +947,12 @@ static void hws_send_queues_bwc_locks_destroy(struct mlx5hws_context *ctx)if (!mlx5hws_context_bwc_supported (ctx))return ; -for (i =0 ; i < bwc_queues; i++) +for (i =0 ; i < bwc_queues; i++) {mutex_destroy (&ctx->bwc_send_queue_locks[i]); +lockdep_unregister_key (ctx->bwc_lock_class_keys + i); + } + +kfree (ctx->bwc_lock_class_keys);kfree (ctx->bwc_send_queue_locks); }
@@ -977,10 +981,22 @@ static int hws_bwc_send_queues_init(struct mlx5hws_context *ctx)if (!ctx->bwc_send_queue_locks)return -ENOMEM ; -for (i =0 ; i < bwc_queues; i++) + ctx->bwc_lock_class_keys =kcalloc (bwc_queues, +sizeof (*ctx->bwc_lock_class_keys), +GFP_KERNEL ); +if (!ctx->bwc_lock_class_keys) + goto err_lock_class_keys; + +for (i =0 ; i < bwc_queues; i++) {mutex_init (&ctx->bwc_send_queue_locks[i]); +lockdep_register_key (ctx->bwc_lock_class_keys + i); + }return 0 ; + +err_lock_class_keys: +kfree (ctx->bwc_send_queue_locks); +return -ENOMEM ; } int mlx5hws_send_queues_open(struct mlx5hws_context *ctx,
Signature · 1 line
2.44.0
Tariq Toukan
maintainerPATCH 5/8 net/mlx5: Check for invalid vector index on EQ creation
In reply to Tariq ToukanFrom: Maher Sanalla <[email protected]>
Currently, mlx5 driver does not enforce vector index to be lower than the maximum number of supported completion vectors when requesting a new completion EQ. Thus, mlx5_comp_eqn_get() fails when trying to acquire an IRQ with an improper vector index.
To prevent the case above, enforce that vector index value is valid and lower than maximum in mlx5_comp_eqn_get() before handling the request.
--- drivers/net/ethernet/mellanox/mlx5/core/eq.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/eq.c +6 -0
@@ -1061,6 +1061,12 @@ int mlx5_comp_eqn_get(struct mlx5_core_dev *dev, u16 vecidx, int *eqn)struct mlx5_eq_comp *eq;int ret =0 ; +if (vecidx >= table->max_comp_eqs) { +mlx5_core_dbg (dev,"Requested vector index %u should be less than %u" , + vecidx, table->max_comp_eqs); +return -EINVAL ; + } +mutex_lock (&table->comp_lock); eq =xa_load (&table->comp_eqs, vecidx);if (eq) {
Signature · 1 line
2.44.0
Tariq Toukan
maintainerPATCH 6/8 net/mlx5: Fix command bitmask initialization
In reply to Tariq ToukanFrom: Shay Drory <[email protected]>
Command bitmask have a dedicated bit for MANAGE_PAGES command, this bit isn't Initialize during command bitmask Initialization, only during MANAGE_PAGES.
In addition, mlx5_cmd_trigger_completions() is trying to trigger completion for MANAGE_PAGES command as well.
Hence, in case health error occurred before any MANAGE_PAGES command have been invoke (for example, during mlx5_enable_hca()), mlx5_cmd_trigger_completions() will try to trigger completion for MANAGE_PAGES command, which will result in null-ptr-deref error.[1]
Fix it by Initialize command bitmask correctly.
While at it, re-write the code for better understanding.
[1]
BUG: KASAN: null-ptr-deref in mlx5_cmd_trigger_completions+0x1db/0x600 [mlx5_core] Write of size 4 at addr 0000000000000214 by task kworker/u96:2/12078 CPU: 10 PID: 12078 Comm: kworker/u96:2 Not tainted 6.9.0-rc2_for_upstream_debug_2024_04_07_19_01 #1 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.13.0-0-gf21b5a4aeb02-prebuilt.qemu.org 04/01/2014 Workqueue: mlx5_health0000:08:00.0 mlx5_fw_fatal_reporter_err_work [mlx5_core] Call Trace: <TASK> dump_stack_lvl+0x7e/0xc0 kasan_report+0xb9/0xf0 kasan_check_range+0xec/0x190 mlx5_cmd_trigger_completions+0x1db/0x600 [mlx5_core] mlx5_cmd_flush+0x94/0x240 [mlx5_core] enter_error_state+0x6c/0xd0 [mlx5_core] mlx5_fw_fatal_reporter_err_work+0xf3/0x480 [mlx5_core] process_one_work+0x787/0x1490 ? lockdep_hardirqs_on_prepare+0x400/0x400 ? pwq_dec_nr_in_flight+0xda0/0xda0 ? assign_work+0x168/0x240 worker_thread+0x586/0xd30 ? rescuer_thread+0xae0/0xae0 kthread+0x2df/0x3b0 ? kthread_complete_and_exit+0x20/0x20 ret_from_fork+0x2d/0x70 ? kthread_complete_and_exit+0x20/0x20 ret_from_fork_asm+0x11/0x20 </TASK>
--- drivers/net/ethernet/mellanox/mlx5/core/cmd.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/cmd.c +6 -2
@@ -1765,6 +1765,10 @@ static void mlx5_cmd_comp_handler(struct mlx5_core_dev *dev, u64 vec, bool force } } +#define MLX5_MAX_MANAGE_PAGES_CMD_ENT 1 +#define MLX5_CMD_MASK ((1UL << (cmd->vars.max_reg_cmds + \ + MLX5_MAX_MANAGE_PAGES_CMD_ENT)) - 1) +static void mlx5_cmd_trigger_completions (struct mlx5_core_dev *dev) {struct mlx5_cmd *cmd = &dev->cmd;
@@ -1776,7 +1780,7 @@ static void mlx5_cmd_trigger_completions(struct mlx5_core_dev *dev)/* wait for pending handlers to complete */ mlx5_eq_synchronize_cmd_irq (dev);spin_lock_irqsave (&dev->cmd.alloc_lock, flags); - vector = ~dev->cmd.vars.bitmask & ((1ul << (1 << dev->cmd.vars.log_sz)) -1 ); + vector = ~dev->cmd.vars.bitmask &MLX5_CMD_MASK ;if (!vector) goto no_trig;
@@ -2361,7 +2365,7 @@ int mlx5_cmd_enable(struct mlx5_core_dev *dev) cmd->state =MLX5_CMDIF_STATE_DOWN ; cmd->vars.max_reg_cmds = (1 << cmd->vars.log_sz) -1 ; - cmd->vars.bitmask = (1UL << cmd->vars.max_reg_cmds) -1 ; + cmd->vars.bitmask =MLX5_CMD_MASK ;sema_init (&cmd->vars.sem, cmd->vars.max_reg_cmds);sema_init (&cmd->vars.pages_sem,1 );
Signature · 1 line
2.44.0
Tariq Toukan
maintainerPATCH 7/8 net/mlx5: Unregister notifier on eswitch init failure
In reply to Tariq ToukanFrom: Cosmin Ratiu <[email protected]>
It otherwise remains registered and a subsequent attempt at eswitch enabling might trigger warnings of the sort:
[ 682.589148] ------------[ cut here ]------------ [ 682.590204] notifier callback eswitch_vport_event [mlx5_core] already registered [ 682.590256] WARNING: CPU: 13 PID: 2660 at kernel/notifier.c:31 notifier_chain_register+0x3e/0x90 [...snipped] [ 682.610052] Call Trace: [ 682.610369] <TASK> [ 682.610663] ? __warn+0x7c/0x110 [ 682.611050] ? notifier_chain_register+0x3e/0x90 [ 682.611556] ? report_bug+0x148/0x170 [ 682.611977] ? handle_bug+0x36/0x70 [ 682.612384] ? exc_invalid_op+0x13/0x60 [ 682.612817] ? asm_exc_invalid_op+0x16/0x20 [ 682.613284] ? notifier_chain_register+0x3e/0x90 [ 682.613789] atomic_notifier_chain_register+0x25/0x40 [ 682.614322] mlx5_eswitch_enable_locked+0x1d4/0x3b0 [mlx5_core] [ 682.614965] mlx5_eswitch_enable+0xc9/0x100 [mlx5_core] [ 682.615551] mlx5_device_enable_sriov+0x25/0x340 [mlx5_core] [ 682.616170] mlx5_core_sriov_configure+0x50/0x170 [mlx5_core] [ 682.616789] sriov_numvfs_store+0xb0/0x1b0 [ 682.617248] kernfs_fop_write_iter+0x117/0x1a0 [ 682.617734] vfs_write+0x231/0x3f0 [ 682.618138] ksys_write+0x63/0xe0 [ 682.618536] do_syscall_64+0x4c/0x100 [ 682.618958] entry_SYSCALL_64_after_hwframe+0x4b/0x53
--- drivers/net/ethernet/mellanox/mlx5/core/eswitch.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
Hi,
Patch is expected to conflict with net-next. Resolution is trivial, by taking the net-next version.
Thanks,
Tariq
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +3 -2
@@ -1489,7 +1489,7 @@ int mlx5_eswitch_enable_locked(struct mlx5_eswitch *esw, int num_vfs) }if (err) - goto abort; + goto err_esw_enable; esw->fdb_table.flags |=MLX5_ESW_FDB_CREATED ;
@@ -1503,7 +1503,8 @@ int mlx5_eswitch_enable_locked(struct mlx5_eswitch *esw, int num_vfs)return 0 ; -abort: +err_esw_enable: +mlx5_eq_notifier_unregister (esw->dev, &esw->nb);mlx5_esw_acls_ns_cleanup (esw);return err; }
Signature · 1 line
2.44.0
Tariq Toukan
maintainerPATCH 8/8 net/mlx5e: Don't call cleanup on profile rollback failure
In reply to Tariq ToukanFrom: Cosmin Ratiu <[email protected]>
When profile rollback fails in mlx5e_netdev_change_profile, the netdev profile var is left set to NULL. Avoid a crash when unloading the driver by not calling profile->cleanup in such a case.
This was encountered while testing, with the original trigger that the wq rescuer thread creation got interrupted (presumably due to Ctrl+C-ing modprobe), which gets converted to ENOMEM (-12) by mlx5e_priv_init, the profile rollback also fails for the same reason (signal still active) so the profile is left as NULL, leading to a crash later in _mlx5e_remove.
[ 732.473932] mlx5_core 0000:08:00.1: E-Switch: Unload vfs: mode(OFFLOADS), nvfs(2), necvfs(0), active vports(2) [ 734.525513] workqueue: Failed to create a rescuer kthread for wq "mlx5e": -EINTR [ 734.557372] mlx5_core 0000:08:00.1: mlx5e_netdev_init_profile:6235:(pid 6086): mlx5e_priv_init failed, err=-12 [ 734.559187] mlx5_core 0000:08:00.1 eth3: mlx5e_netdev_change_profile: new profile init failed, -12 [ 734.560153] workqueue: Failed to create a rescuer kthread for wq "mlx5e": -EINTR [ 734.589378] mlx5_core 0000:08:00.1: mlx5e_netdev_init_profile:6235:(pid 6086): mlx5e_priv_init failed, err=-12 [ 734.591136] mlx5_core 0000:08:00.1 eth3: mlx5e_netdev_change_profile: failed to rollback to orig profile, -12 [ 745.537492] BUG: kernel NULL pointer dereference, address: 0000000000000008 [ 745.538222] #PF: supervisor read access in kernel mode <snipped> [ 745.551290] Call Trace: [ 745.551590] <TASK> [ 745.551866] ? __die+0x20/0x60 [ 745.552218] ? page_fault_oops+0x150/0x400 [ 745.555307] ? exc_page_fault+0x79/0x240 [ 745.555729] ? asm_exc_page_fault+0x22/0x30 [ 745.556166] ? mlx5e_remove+0x6b/0xb0 [mlx5_core] [ 745.556698] auxiliary_bus_remove+0x18/0x30 [ 745.557134] device_release_driver_internal+0x1df/0x240 [ 745.557654] bus_remove_device+0xd7/0x140 [ 745.558075] device_del+0x15b/0x3c0 [ 745.558456] mlx5_rescan_drivers_locked.part.0+0xb1/0x2f0 [mlx5_core] [ 745.559112] mlx5_unregister_device+0x34/0x50 [mlx5_core] [ 745.559686] mlx5_uninit_one+0x46/0xf0 [mlx5_core] [ 745.560203] remove_one+0x4e/0xd0 [mlx5_core] [ 745.560694] pci_device_remove+0x39/0xa0 [ 745.561112] device_release_driver_internal+0x1df/0x240 [ 745.561631] driver_detach+0x47/0x90 [ 745.562022] bus_remove_driver+0x84/0x100 [ 745.562444] pci_unregister_driver+0x3b/0x90 [ 745.562890] mlx5_cleanup+0xc/0x1b [mlx5_core] [ 745.563415] __x64_sys_delete_module+0x14d/0x2f0 [ 745.563886] ? kmem_cache_free+0x1b0/0x460 [ 745.564313] ? lockdep_hardirqs_on_prepare+0xe2/0x190 [ 745.564825] do_syscall_64+0x6d/0x140 [ 745.565223] entry_SYSCALL_64_after_hwframe+0x4b/0x53 [ 745.565725] RIP: 0033:0x7f1579b1288b
--- drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +3 -1
@@ -6509,7 +6509,9 @@ static void _mlx5e_remove(struct auxiliary_device *adev)mlx5e_dcbnl_delete_app (priv);unregister_netdev (priv->netdev);_mlx5e_suspend (adev, false); - priv->profile->cleanup (priv); +/* Avoid cleanup if profile rollback failed. */ +if (priv->profile) + priv->profile->cleanup (priv);mlx5e_destroy_netdev (priv);mlx5e_devlink_port_unregister (mlx5e_dev);mlx5e_destroy_devlink (mlx5e_dev);
Signature · 1 line
2.44.0
This series was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:
Quoted 9 lines · On Tue, 15 Oct 2024 12:32:00 +0300 you wrote:
Hi,
This patchset provides misc bug fixes from the team to the mlx5 core and Eth drivers.
Series generated against:
commit174714f0e505("selftests: drivers: net: fix name not defined")[...]
Here is the summary with links:
- [net,1/8] net/mlx5: HWS, removed wrong access to a number of rules variable
https://git.kernel.org/netdev/net/c/65b4eb9f3d1e - [net,2/8] net/mlx5: HWS, fixed double free in error flow of definer layout https://git.kernel.org/netdev/net/c/5aa2184e2908 - [net,3/8] net/mlx5: HWS, don't destroy more bwc queue locks than allocated https://git.kernel.org/netdev/net/c/45bcbd49224a - [net,4/8] net/mlx5: HWS, use lock classes for bwc locks https://git.kernel.org/netdev/net/c/9addffa34359 - [net,5/8] net/mlx5: Check for invalid vector index on EQ creation https://git.kernel.org/netdev/net/c/d4f25be27e3e - [net,6/8] net/mlx5: Fix command bitmask initialization https://git.kernel.org/netdev/net/c/d62b14045c65 - [net,7/8] net/mlx5: Unregister notifier on eswitch init failure https://git.kernel.org/netdev/net/c/1da9cfd6c41c - [net,8/8] net/mlx5e: Don't call cleanup on profile rollback failure https://git.kernel.org/netdev/net/c/4dbc1d1a9f39
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html