Skip to contentSkip to conversation

net/mlx5e: kTLS, Fix missing error unwind when enabling RX offload

PATCH In review Xuanqiang Luo 4 participants 8 messages Oct 26 – Nov 6

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/mlx5e: kTLS, Fix missing error unwind when enabling RX offload

From: Xuanqiang Luo <[email protected]>

Since commit abed42f9cd80 ("net/mlx5e: Conditionally create async ICOSQ"), the async ICOSQ is only created when an XDP program is attached or priv->ktls_rx_was_enabled is set. When TLS RX offload is enabled for the first time, mlx5e_ktls_set_feature_rx() sets the flag and reopens the channels so that they get the queue, but it ignores the return value of mlx5e_safe_reopen_channels().

If the reopen fails, mlx5e_safe_switch_params() keeps the old channels, which have no async ICOSQ, while NETIF_F_HW_TLS_RX is still reported as enabled. The next offloaded RX connection then dereferences the NULL c->async_icosq in post_rx_param_wqes(). Enabling the feature again does not help, as the flag is already set and the reopen is skipped.

Propagate the error, clear the flag and destroy the accel TCP flow tables again, so that the feature stays disabled and the next attempt retries the reopen.

Fixes abed42f9cd80 ("net/mlx5e: Conditionally create async ICOSQ")

---
Found by code inspection while backporting commit abed42f9cd80 to a downstream kernel. I do not have a crypto-enabled ConnectX NIC, so the failure has not been reproduced and the fix is only compile-tested.

The crash itself is the one described in the changelog of abed42f9cd80 ("async ICOSQ allocation is not triggered, causing a NULL pointer crash"). This patch only covers the case where the reopen that should create the queue fails. ktls.c is also the only caller that ignores the return value of mlx5e_safe_reopen_channels(); the callers in health.c and reporter_tx.c check it.

 drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c +5 -1
index 337201f128958..3cc1213c2f682 100644
@@ -139,7 +139,11 @@ int mlx5e_ktls_set_feature_rx(struct net_device *netdev, bool enable)
 		err = mlx5e_accel_fs_tcp_create(priv->fs);
 		if (!err && !priv->ktls_rx_was_enabled) {
 			priv->ktls_rx_was_enabled = true;
-			mlx5e_safe_reopen_channels(priv);
+			err = mlx5e_safe_reopen_channels(priv);
+			if (err) {
+				priv->ktls_rx_was_enabled = false;
+				mlx5e_accel_fs_tcp_destroy(priv->fs);
+			}
 		}
 	} else {
 		mlx5e_accel_fs_tcp_destroy(priv->fs);
Signature · 1 line
2.43.0
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 15 lines

From: Xuanqiang Luo <[email protected]>

Since commit abed42f9cd80 ("net/mlx5e: Conditionally create async ICOSQ"), the async ICOSQ is only created when an XDP program is attached or priv->ktls_rx_was_enabled is set. When TLS RX offload is enabled for the first time, mlx5e_ktls_set_feature_rx() sets the flag and reopens the channels so that they get the queue, but it ignores the return value of mlx5e_safe_reopen_channels().

If the reopen fails, mlx5e_safe_switch_params() keeps the old channels, which have no async ICOSQ, while NETIF_F_HW_TLS_RX is still reported as enabled. The next offloaded RX connection then dereferences the NULL c->async_icosq in post_rx_param_wqes(). Enabling the feature again does not help, as the flag is already set and the reopen is skipped.

Quoted 6 lines

Propagate the error, clear the flag and destroy the accel TCP flow tables again, so that the feature stays disabled and the next attempt retries the reopen.

Fixes abed42f9cd80 ("net/mlx5e: Conditionally create async ICOSQ")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
reviewer Reviewed-by on v1 1/1
#2 lore raw
In reply to Xuanqiang Luo
Quoted 33 lines · Xuanqiang Luo

From: Xuanqiang Luo <[email protected]>

Since commit abed42f9cd80 ("net/mlx5e: Conditionally create async ICOSQ"), the async ICOSQ is only created when an XDP program is attached or priv->ktls_rx_was_enabled is set. When TLS RX offload is enabled for the first time, mlx5e_ktls_set_feature_rx() sets the flag and reopens the channels so that they get the queue, but it ignores the return value of mlx5e_safe_reopen_channels().

If the reopen fails, mlx5e_safe_switch_params() keeps the old channels, which have no async ICOSQ, while NETIF_F_HW_TLS_RX is still reported as enabled. The next offloaded RX connection then dereferences the NULL c->async_icosq in post_rx_param_wqes(). Enabling the feature again does not help, as the flag is already set and the reopen is skipped.

Propagate the error, clear the flag and destroy the accel TCP flow tables again, so that the feature stays disabled and the next attempt retries the reopen.

Fixes abed42f9cd80 ("net/mlx5e: Conditionally create async ICOSQ")

---
Found by code inspection while backporting commit abed42f9cd80 to a downstream kernel. I do not have a crypto-enabled ConnectX NIC, so the failure has not been reproduced and the fix is only compile-tested.

The crash itself is the one described in the changelog of abed42f9cd80 ("async ICOSQ allocation is not triggered, causing a NULL pointer crash"). This patch only covers the case where the reopen that should create the queue fails. ktls.c is also the only caller that ignores the return value of mlx5e_safe_reopen_channels(); the callers in health.c and reporter_tx.c check it.

Quoted 2 lines
 drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

I agree that a minimal approach to addressing this problem is appropriate for net.

However, I do think the logic of this function is becoming somewhat convoluted and would benefit from:

1. Handling error paths in conditionals while leaving the main thread of execution unconditional.

2. Use goto for unwind.

This is approach is complicated by the function needing to handle the enable condition. But at any rate, maybe a follow-up patch do do something like this would be worthwhile?

drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c +13 -10
index 3cc1213c2f68..0f5dcd1b822e 100644
@@ -137,19 +137,22 @@ int mlx5e_ktls_set_feature_rx(struct net_device *netdev, bool enable)
 	mutex_lock(&priv->state_lock);
 	if (enable) {
 		err = mlx5e_accel_fs_tcp_create(priv->fs);
-		if (!err && !priv->ktls_rx_was_enabled) {
-			priv->ktls_rx_was_enabled = true;
-			err = mlx5e_safe_reopen_channels(priv);
-			if (err) {
-				priv->ktls_rx_was_enabled = false;
-				mlx5e_accel_fs_tcp_destroy(priv->fs);
-			}
+		if (err || priv->ktls_rx_was_enabled)
+			goto out_unlock;
+
+		priv->ktls_rx_was_enabled = true;
+		err = mlx5e_safe_reopen_channels(priv);
+		if (err) {
+			priv->ktls_rx_was_enabled = false;
+			enable = false;
 		}
-	} else {
-		mlx5e_accel_fs_tcp_destroy(priv->fs);
 	}
-	mutex_unlock(&priv->state_lock);
 
+	if (!enable)
+		mlx5e_accel_fs_tcp_destroy(priv->fs);
+
+out_unlock:
+	mutex_unlock(&priv->state_lock);
 	return err;
 }
 

...

#3 lore raw
Quoted 34 lines · On 2026/10/29 at 21:40 Simon Horman wrote:
Quoted 33 lines · Xuanqiang Luo

From: Xuanqiang Luo <[email protected]>

Since commit abed42f9cd80 ("net/mlx5e: Conditionally create async ICOSQ"), the async ICOSQ is only created when an XDP program is attached or priv->ktls_rx_was_enabled is set. When TLS RX offload is enabled for the first time, mlx5e_ktls_set_feature_rx() sets the flag and reopens the channels so that they get the queue, but it ignores the return value of mlx5e_safe_reopen_channels().

If the reopen fails, mlx5e_safe_switch_params() keeps the old channels, which have no async ICOSQ, while NETIF_F_HW_TLS_RX is still reported as enabled. The next offloaded RX connection then dereferences the NULL c->async_icosq in post_rx_param_wqes(). Enabling the feature again does not help, as the flag is already set and the reopen is skipped.

Propagate the error, clear the flag and destroy the accel TCP flow tables again, so that the feature stays disabled and the next attempt retries the reopen.

Fixes abed42f9cd80 ("net/mlx5e: Conditionally create async ICOSQ")

---
Found by code inspection while backporting commit abed42f9cd80 to a downstream kernel. I do not have a crypto-enabled ConnectX NIC, so the failure has not been reproduced and the fix is only compile-tested.

The crash itself is the one described in the changelog of abed42f9cd80 ("async ICOSQ allocation is not triggered, causing a NULL pointer crash"). This patch only covers the case where the reopen that should create the queue fails. ktls.c is also the only caller that ignores the return value of mlx5e_safe_reopen_channels(); the callers in health.c and reporter_tx.c check it.

Quoted 7 lines
Quoted 2 lines
  drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)

I agree that a minimal approach to addressing this problem is appropriate for net.

Thanks for the review!

Quoted 40 lines

However, I do think the logic of this function is becoming somewhat convoluted and would benefit from:

1. Handling error paths in conditionals while leaving the main thread of execution unconditional.

2. Use goto for unwind.

This is approach is complicated by the function needing to handle the enable condition. But at any rate, maybe a follow-up patch do do something like this would be worthwhile?

drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c +8 -9
index 3cc1213c2f68..0f5dcd1b822e 100644
@@ -137,19 +137,22 @@ int mlx5e_ktls_set_feature_rx(struct net_device *netdev, bool enable)
  	mutex_lock(&priv->state_lock);
  	if (enable) {
  		err = mlx5e_accel_fs_tcp_create(priv->fs);
-		if (!err && !priv->ktls_rx_was_enabled) {
-			priv->ktls_rx_was_enabled = true;
-			err = mlx5e_safe_reopen_channels(priv);
-			if (err) {
-				priv->ktls_rx_was_enabled = false;
-				mlx5e_accel_fs_tcp_destroy(priv->fs);
-			}
+		if (err || priv->ktls_rx_was_enabled)
+			goto out_unlock;
+
+		priv->ktls_rx_was_enabled = true;
+		err = mlx5e_safe_reopen_channels(priv);
+		if (err) {
+			priv->ktls_rx_was_enabled = false;
+			enable = false;
  		}
-	} else {
-		mlx5e_accel_fs_tcp_destroy(priv->fs);
  	}

drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c int mlx5e_ktls_set_feature_rx(struct net_device *netdev, bool enable) · line 158

Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c +5 -1
-	mutex_unlock(&priv->state_lock);
 
+	if (!enable)
+		mlx5e_accel_fs_tcp_destroy(priv->fs);
+
+out_unlock:
+	mutex_unlock(&priv->state_lock);
  	return err;
  }
 

Thanks for the suggestion. Agreed, the nesting is getting hard to follow. I'll send a cleanup along these lines to net-next once this fix has made it there.

Thanks,
Xuanqiang

reviewer
#4 lore raw
Quoted 88 lines · Xuanqiang Luo
Quoted 34 lines · On 2026/10/29 at 21:40 Simon Horman wrote:
Quoted 33 lines · Xuanqiang Luo

From: Xuanqiang Luo <[email protected]>

Since commit abed42f9cd80 ("net/mlx5e: Conditionally create async ICOSQ"), the async ICOSQ is only created when an XDP program is attached or priv->ktls_rx_was_enabled is set. When TLS RX offload is enabled for the first time, mlx5e_ktls_set_feature_rx() sets the flag and reopens the channels so that they get the queue, but it ignores the return value of mlx5e_safe_reopen_channels().

If the reopen fails, mlx5e_safe_switch_params() keeps the old channels, which have no async ICOSQ, while NETIF_F_HW_TLS_RX is still reported as enabled. The next offloaded RX connection then dereferences the NULL c->async_icosq in post_rx_param_wqes(). Enabling the feature again does not help, as the flag is already set and the reopen is skipped.

Propagate the error, clear the flag and destroy the accel TCP flow tables again, so that the feature stays disabled and the next attempt retries the reopen.

Fixes abed42f9cd80 ("net/mlx5e: Conditionally create async ICOSQ")

---
Found by code inspection while backporting commit abed42f9cd80 to a downstream kernel. I do not have a crypto-enabled ConnectX NIC, so the failure has not been reproduced and the fix is only compile-tested.

The crash itself is the one described in the changelog of abed42f9cd80 ("async ICOSQ allocation is not triggered, causing a NULL pointer crash"). This patch only covers the case where the reopen that should create the queue fails. ktls.c is also the only caller that ignores the return value of mlx5e_safe_reopen_channels(); the callers in health.c and reporter_tx.c check it.

Quoted 7 lines
Quoted 2 lines
  drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)

I agree that a minimal approach to addressing this problem is appropriate for net.

Thanks for the review!

Quoted 43 lines

However, I do think the logic of this function is becoming somewhat convoluted and would benefit from:

1. Handling error paths in conditionals while leaving the main thread of execution unconditional.

2. Use goto for unwind.

This is approach is complicated by the function needing to handle the enable condition. But at any rate, maybe a follow-up patch do do something like this would be worthwhile?

drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c +10 -10
index 3cc1213c2f68..0f5dcd1b822e 100644
@@ -137,19 +137,22 @@ int mlx5e_ktls_set_feature_rx(struct net_device *netdev, bool enable)
  	mutex_lock(&priv->state_lock);
  	if (enable) {
  		err = mlx5e_accel_fs_tcp_create(priv->fs);
-		if (!err && !priv->ktls_rx_was_enabled) {
-			priv->ktls_rx_was_enabled = true;
-			err = mlx5e_safe_reopen_channels(priv);
-			if (err) {
-				priv->ktls_rx_was_enabled = false;
-				mlx5e_accel_fs_tcp_destroy(priv->fs);
-			}
+		if (err || priv->ktls_rx_was_enabled)
+			goto out_unlock;
+
+		priv->ktls_rx_was_enabled = true;
+		err = mlx5e_safe_reopen_channels(priv);
+		if (err) {
+			priv->ktls_rx_was_enabled = false;
+			enable = false;
  		}
-	} else {
-		mlx5e_accel_fs_tcp_destroy(priv->fs);
  	}
-	mutex_unlock(&priv->state_lock);
+	if (!enable)
+		mlx5e_accel_fs_tcp_destroy(priv->fs);
Quoted 8 lines

drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c int mlx5e_ktls_set_feature_rx(struct net_device *netdev, bool enable) · line 157

Quoted 5 lines
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c +3 -0
+
+out_unlock:
+	mutex_unlock(&priv->state_lock);
  	return err;
  }

Thanks for the suggestion. Agreed, the nesting is getting hard to follow. I'll send a cleanup along these lines to net-next once this fix has made it there.

Likewise, thanks.

Just to be clear, the patch I provided informally in my previous email is compile tested only.

maintainer Reviewed-by
#5 lore raw
In reply to Simon Horman
Quoted 34 lines · Simon Horman
Quoted 33 lines · Xuanqiang Luo

From: Xuanqiang Luo <[email protected]>

Since commit abed42f9cd80 ("net/mlx5e: Conditionally create async ICOSQ"), the async ICOSQ is only created when an XDP program is attached or priv->ktls_rx_was_enabled is set. When TLS RX offload is enabled for the first time, mlx5e_ktls_set_feature_rx() sets the flag and reopens the channels so that they get the queue, but it ignores the return value of mlx5e_safe_reopen_channels().

If the reopen fails, mlx5e_safe_switch_params() keeps the old channels, which have no async ICOSQ, while NETIF_F_HW_TLS_RX is still reported as enabled. The next offloaded RX connection then dereferences the NULL c->async_icosq in post_rx_param_wqes(). Enabling the feature again does not help, as the flag is already set and the reopen is skipped.

Propagate the error, clear the flag and destroy the accel TCP flow tables again, so that the feature stays disabled and the next attempt retries the reopen.

Fixes abed42f9cd80 ("net/mlx5e: Conditionally create async ICOSQ")

---
Found by code inspection while backporting commit abed42f9cd80 to a downstream kernel. I do not have a crypto-enabled ConnectX NIC, so the failure has not been reproduced and the fix is only compile-tested.

The crash itself is the one described in the changelog of abed42f9cd80 ("async ICOSQ allocation is not triggered, causing a NULL pointer crash"). This patch only covers the case where the reopen that should create the queue fails. ktls.c is also the only caller that ignores the return value of mlx5e_safe_reopen_channels(); the callers in health.c and reporter_tx.c check it.

Quoted 6 lines
Quoted 2 lines
  drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)

I agree that a minimal approach to addressing this problem is appropriate for net.

Quoted 5 lines

However, I do think the logic of this function is becoming somewhat convoluted and would benefit from:

Quoted 9 lines

1. Handling error paths in conditionals while leaving the main thread of execution unconditional.

2. Use goto for unwind.

This is approach is complicated by the function needing to handle the enable condition. But at any rate, maybe a follow-up patch do do something like this would be worthwhile?

Agree.

Quoted 29 lines
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c +8 -10
index 3cc1213c2f68..0f5dcd1b822e 100644
@@ -137,19 +137,22 @@ int mlx5e_ktls_set_feature_rx(struct net_device *netdev, bool enable)
  	mutex_lock(&priv->state_lock);
  	if (enable) {
  		err = mlx5e_accel_fs_tcp_create(priv->fs);
-		if (!err && !priv->ktls_rx_was_enabled) {
-			priv->ktls_rx_was_enabled = true;
-			err = mlx5e_safe_reopen_channels(priv);
-			if (err) {
-				priv->ktls_rx_was_enabled = false;
-				mlx5e_accel_fs_tcp_destroy(priv->fs);
-			}
+		if (err || priv->ktls_rx_was_enabled)
+			goto out_unlock;
+
+		priv->ktls_rx_was_enabled = true;
+		err = mlx5e_safe_reopen_channels(priv);
+		if (err) {
+			priv->ktls_rx_was_enabled = false;
+			enable = false;
  		}
-	} else {
-		mlx5e_accel_fs_tcp_destroy(priv->fs);
  	}
-	mutex_unlock(&priv->state_lock);
 

drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c int mlx5e_ktls_set_feature_rx(struct net_device *netdev, bool enable)

Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c +5 -0
+	if (!enable)
+		mlx5e_accel_fs_tcp_destroy(priv->fs);
+
+out_unlock:
+	mutex_unlock(&priv->state_lock);
  	return err;
  }
 
 
...

Makes sense.

maintainer
#6 lore raw
Quoted 101 lines · Tariq Toukan
Quoted 34 lines · Simon Horman
Quoted 33 lines · Xuanqiang Luo

From: Xuanqiang Luo <[email protected]>

Since commit abed42f9cd80 ("net/mlx5e: Conditionally create async ICOSQ"), the async ICOSQ is only created when an XDP program is attached or priv->ktls_rx_was_enabled is set. When TLS RX offload is enabled for the first time, mlx5e_ktls_set_feature_rx() sets the flag and reopens the channels so that they get the queue, but it ignores the return value of mlx5e_safe_reopen_channels().

If the reopen fails, mlx5e_safe_switch_params() keeps the old channels, which have no async ICOSQ, while NETIF_F_HW_TLS_RX is still reported as enabled. The next offloaded RX connection then dereferences the NULL c->async_icosq in post_rx_param_wqes(). Enabling the feature again does not help, as the flag is already set and the reopen is skipped.

Propagate the error, clear the flag and destroy the accel TCP flow tables again, so that the feature stays disabled and the next attempt retries the reopen.

Fixes abed42f9cd80 ("net/mlx5e: Conditionally create async ICOSQ")

---
Found by code inspection while backporting commit abed42f9cd80 to a downstream kernel. I do not have a crypto-enabled ConnectX NIC, so the failure has not been reproduced and the fix is only compile-tested.

The crash itself is the one described in the changelog of abed42f9cd80 ("async ICOSQ allocation is not triggered, causing a NULL pointer crash"). This patch only covers the case where the reopen that should create the queue fails. ktls.c is also the only caller that ignores the return value of mlx5e_safe_reopen_channels(); the callers in health.c and reporter_tx.c check it.

Quoted 6 lines
Quoted 2 lines

  drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c | 6 +++++-

  1 file changed, 5 insertions(+), 1 deletion(-)

I agree that a minimal approach to addressing this problem is appropriate for net.

Quoted 5 lines

However, I do think the logic of this function is becoming somewhat convoluted and would benefit from:

Quoted 9 lines

1. Handling error paths in conditionals while leaving the main thread of execution unconditional.

2. Use goto for unwind.

This is approach is complicated by the function needing to handle the enable condition. But at any rate, maybe a follow-up patch do do something like this would be worthwhile?

Agree.

Quoted 37 lines
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c +13 -10
index 3cc1213c2f68..0f5dcd1b822e 100644
@@ -137,19 +137,22 @@ int mlx5e_ktls_set_feature_rx(struct net_device 
 *netdev, bool enable)
       mutex_lock(&priv->state_lock);
       if (enable) {
           err = mlx5e_accel_fs_tcp_create(priv->fs);
-        if (!err && !priv->ktls_rx_was_enabled) {
-            priv->ktls_rx_was_enabled = true;
-            err = mlx5e_safe_reopen_channels(priv);
-            if (err) {
-                priv->ktls_rx_was_enabled = false;
-                mlx5e_accel_fs_tcp_destroy(priv->fs);
-            }
+        if (err || priv->ktls_rx_was_enabled)
+            goto out_unlock;
+
+        priv->ktls_rx_was_enabled = true;
+        err = mlx5e_safe_reopen_channels(priv);
+        if (err) {
+            priv->ktls_rx_was_enabled = false;
+            enable = false;
           }
-    } else {
-        mlx5e_accel_fs_tcp_destroy(priv->fs);
       }
-    mutex_unlock(&priv->state_lock);
+    if (!enable)
+        mlx5e_accel_fs_tcp_destroy(priv->fs);
+
+out_unlock:
+    mutex_unlock(&priv->state_lock);
       return err;
   }
 
Quoted 3 lines
Quoted 1 line

...

Makes sense.

Seems that we need a resend here.
Let me know if you want me to do that.

#7 lore raw

Hi Tariq,

Quoted 3 lines · On 2026/11/6 at 01:49 Tariq Toukan wrote:

Seems that we need a resend here.
Let me know if you want me to do that.

Yes, please go ahead and resend it. I saw the patch is marked "Awaiting Upstream" in patchwork, so I understand it needs to go through the mlx5 tree. Thanks for taking care of it!

I'll send the follow-up cleanup to net-next once the fix has landed.

Thanks,
Xuanqiang