public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net/mlx4: fix MAC table total count corruption in __mlx4_unregister_mac()
@ 2026-01-22 18:39 Kery Qi
  2026-01-27  3:47 ` Jakub Kicinski
  2026-01-27  6:26 ` Tariq Toukan
  0 siblings, 2 replies; 4+ messages in thread
From: Kery Qi @ 2026-01-22 18:39 UTC (permalink / raw)
  To: tariqt, andrew+netdev, davem, edumazet, kuba, pabeni
  Cc: jackm, ogerlitz, monis, netdev, linux-rdma, linux-kernel, Kery Qi

In __mlx4_unregister_mac(), when operating in mf_bonded mode
(SR-IOV with bonding), it appears that the code might be incorrectly
decrementing table->total instead of dup_table->total when cleaning
up the duplicate table entry.

If this is the case, it would cause the primary table's total counter
to be decremented twice (once for itself and once when it should
decrement the duplicate table), leading to counter corruption.
Over time, table->total could become negative, which would
break the "table->total == table->max" fullness check in
__mlx4_register_mac().

The registration path correctly increments both counters:
  ++table->total;
  if (dup) {
      ...
      ++dup_table->total;
  }

However, the unregistration path seems to have a typo:
  --table->total;
  if (dup) {
      ...
      --table->total; // Should this be --dup_table->total?

Fixes: 5f61385d2ebc2 ("net/mlx4_core: Keep VLAN/MAC tables mirrored in multifunc HA mode")
Signed-off-by: Kery Qi <qikeyu2017@gmail.com>
---
 drivers/net/ethernet/mellanox/mlx4/port.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/port.c b/drivers/net/ethernet/mellanox/mlx4/port.c
index e3d0b13c1610..6d0295c471da 100644
--- a/drivers/net/ethernet/mellanox/mlx4/port.c
+++ b/drivers/net/ethernet/mellanox/mlx4/port.c
@@ -410,7 +410,7 @@ void __mlx4_unregister_mac(struct mlx4_dev *dev, u8 port, u64 mac)
 		if (mlx4_set_port_mac_table(dev, dup_port, dup_table->entries))
 			mlx4_warn(dev, "Fail to set mac in duplicate port %d during unregister\n", dup_port);
 
-		--table->total;
+		--dup_table->total;
 	}
 out:
 	if (dup) {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] net/mlx4: fix MAC table total count corruption in __mlx4_unregister_mac()
  2026-01-22 18:39 [PATCH] net/mlx4: fix MAC table total count corruption in __mlx4_unregister_mac() Kery Qi
@ 2026-01-27  3:47 ` Jakub Kicinski
  2026-01-27  6:26 ` Tariq Toukan
  1 sibling, 0 replies; 4+ messages in thread
From: Jakub Kicinski @ 2026-01-27  3:47 UTC (permalink / raw)
  To: tariqt
  Cc: Kery Qi, andrew+netdev, davem, edumazet, pabeni, jackm, ogerlitz,
	monis, netdev, linux-rdma, linux-kernel

On Fri, 23 Jan 2026 02:39:07 +0800 Kery Qi wrote:
> In __mlx4_unregister_mac(), when operating in mf_bonded mode
> (SR-IOV with bonding), it appears that the code might be incorrectly
> decrementing table->total instead of dup_table->total when cleaning
> up the duplicate table entry.
> 
> If this is the case, it would cause the primary table's total counter
> to be decremented twice (once for itself and once when it should
> decrement the duplicate table), leading to counter corruption.
> Over time, table->total could become negative, which would
> break the "table->total == table->max" fullness check in
> __mlx4_register_mac().
> 
> The registration path correctly increments both counters:
>   ++table->total;
>   if (dup) {
>       ...
>       ++dup_table->total;
>   }
> 
> However, the unregistration path seems to have a typo:
>   --table->total;
>   if (dup) {
>       ...
>       --table->total; // Should this be --dup_table->total?

Looks legit, Tariq? Are you trying to find/dust off an mlx4 card? :)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net/mlx4: fix MAC table total count corruption in __mlx4_unregister_mac()
  2026-01-22 18:39 [PATCH] net/mlx4: fix MAC table total count corruption in __mlx4_unregister_mac() Kery Qi
  2026-01-27  3:47 ` Jakub Kicinski
@ 2026-01-27  6:26 ` Tariq Toukan
  2026-01-27 16:38   ` Jakub Kicinski
  1 sibling, 1 reply; 4+ messages in thread
From: Tariq Toukan @ 2026-01-27  6:26 UTC (permalink / raw)
  To: Kery Qi, tariqt, andrew+netdev, davem, edumazet, kuba, pabeni
  Cc: jackm, ogerlitz, monis, netdev, linux-rdma, linux-kernel



On 22/01/2026 20:39, Kery Qi wrote:
> In __mlx4_unregister_mac(), when operating in mf_bonded mode
> (SR-IOV with bonding), it appears that the code might be incorrectly
> decrementing table->total instead of dup_table->total when cleaning
> up the duplicate table entry.
> 
> If this is the case, it would cause the primary table's total counter
> to be decremented twice (once for itself and once when it should
> decrement the duplicate table), leading to counter corruption.
> Over time, table->total could become negative, which would
> break the "table->total == table->max" fullness check in
> __mlx4_register_mac().
> 
> The registration path correctly increments both counters:
>    ++table->total;
>    if (dup) {
>        ...
>        ++dup_table->total;
>    }
> 
> However, the unregistration path seems to have a typo:
>    --table->total;
>    if (dup) {
>        ...
>        --table->total; // Should this be --dup_table->total?
> 
> Fixes: 5f61385d2ebc2 ("net/mlx4_core: Keep VLAN/MAC tables mirrored in multifunc HA mode")
> Signed-off-by: Kery Qi <qikeyu2017@gmail.com>
> ---

Hi Kery,

1. Commit message is phrased as an RFC, with questions and uncertainty.
Please re-phrase.
2. Do you hit an actual failure here? What are the steps? What error do 
you see?

Other than that, code LGTM.

>   drivers/net/ethernet/mellanox/mlx4/port.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx4/port.c b/drivers/net/ethernet/mellanox/mlx4/port.c
> index e3d0b13c1610..6d0295c471da 100644
> --- a/drivers/net/ethernet/mellanox/mlx4/port.c
> +++ b/drivers/net/ethernet/mellanox/mlx4/port.c
> @@ -410,7 +410,7 @@ void __mlx4_unregister_mac(struct mlx4_dev *dev, u8 port, u64 mac)
>   		if (mlx4_set_port_mac_table(dev, dup_port, dup_table->entries))
>   			mlx4_warn(dev, "Fail to set mac in duplicate port %d during unregister\n", dup_port);
>   
> -		--table->total;
> +		--dup_table->total;
>   	}
>   out:
>   	if (dup) {


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net/mlx4: fix MAC table total count corruption in __mlx4_unregister_mac()
  2026-01-27  6:26 ` Tariq Toukan
@ 2026-01-27 16:38   ` Jakub Kicinski
  0 siblings, 0 replies; 4+ messages in thread
From: Jakub Kicinski @ 2026-01-27 16:38 UTC (permalink / raw)
  To: Tariq Toukan, Kery Qi
  Cc: tariqt, andrew+netdev, davem, edumazet, pabeni, jackm, ogerlitz,
	monis, netdev, linux-rdma, linux-kernel

On Tue, 27 Jan 2026 08:26:49 +0200 Tariq Toukan wrote:
> 1. Commit message is phrased as an RFC, with questions and uncertainty.
> Please re-phrase.
> 2. Do you hit an actual failure here? What are the steps? What error do 
> you see?

Alternatively, perhaps, seeing that Kery is sending patches to random
pieces of code - please add a paragraph explaining what kind of tool
you used to detect the issue, and stating that you haven't actually
hit it. Please note that disclosure that the issue has been found
by static analysis tool is _required_ in the kernel process.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-01-27 16:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-22 18:39 [PATCH] net/mlx4: fix MAC table total count corruption in __mlx4_unregister_mac() Kery Qi
2026-01-27  3:47 ` Jakub Kicinski
2026-01-27  6:26 ` Tariq Toukan
2026-01-27 16:38   ` Jakub Kicinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox