Skip to contentSkip to conversation

mlxbf_gige: Fix kernel panic at shutdown

PATCH Superseded Asmaa Mnebhi 3 participants 6 messages Jun 2, 2023 – Jun 7, 2023

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mlxbf_gige: Fix kernel panic at shutdown

There is a race condition happening during shutdown due to pending napi transactions. Since mlxbf_gige_poll is still running, it tries to access a NULL pointer and as a result causes a kernel panic.
To fix this during shutdown, invoke mlxbf_gige_remove to disable and dequeue napi.

Fixes f92e1869d74e ("Add Mellanox BlueField Gigabit Ethernet driver")
---
 drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_main.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_main.c +1 -4
index 694de9513b9f..7017f14595db 100644
@@ -485,10 +485,7 @@ static int mlxbf_gige_remove(struct platform_device *pdev)
 
 static void mlxbf_gige_shutdown(struct platform_device *pdev)
 {
-	struct mlxbf_gige *priv = platform_get_drvdata(pdev);
-
-	writeq(0, priv->base + MLXBF_GIGE_INT_EN);
-	mlxbf_gige_clean_port(priv);
+	mlxbf_gige_remove(pdev);
 }
 
 static const struct acpi_device_id __maybe_unused mlxbf_gige_acpi_match[] = {
Signature · 1 line
2.30.1
maintainer
#1 lore raw
Quoted 7 lines · On Fri, 2 Jun 2023 14:24:43 -0400 Asmaa Mnebhi wrote:

There is a race condition happening during shutdown due to pending napi transactions. Since mlxbf_gige_poll is still running, it tries to access a NULL pointer and as a result causes a kernel panic.
To fix this during shutdown, invoke mlxbf_gige_remove to disable and dequeue napi.

Fixes f92e1869d74e ("Add Mellanox BlueField Gigabit Ethernet driver")

Judging by the Fixes tag the problem can happen on 6.4-rc5 already, right? So the tree in the [PATCH ] tag should have been net rather than net-next?

https://www.kernel.org/doc/html/next/process/maintainer-netdev.html#git-trees-and-patch-flow

No need to repost confirmation is enough.

maintainer
#3 lore raw
In reply to Asmaa Mnebhi
Quoted 17 lines · Asmaa Mnebhi

There is a race condition happening during shutdown due to pending napi transactions. Since mlxbf_gige_poll is still running, it tries to access a NULL pointer and as a result causes a kernel panic.
To fix this during shutdown, invoke mlxbf_gige_remove to disable and dequeue napi.

Fixes f92e1869d74e ("Add Mellanox BlueField Gigabit Ethernet driver")
---
 drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_main.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_main.c +0 -0
index 694de9513b9f..7017f14595db 100644
@@ -485,10 +485,7 @@ static int mlxbf_gige_remove(struct platform_device *pdev)
 

drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_main.c static int mlxbf_gige_remove(struct platform_device *pdev) · line 491

Quoted 10 lines
drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_main.c +1 -4
 static void mlxbf_gige_shutdown(struct platform_device *pdev)
 {
-	struct mlxbf_gige *priv = platform_get_drvdata(pdev);
-
-	writeq(0, priv->base + MLXBF_GIGE_INT_EN);
-	mlxbf_gige_clean_port(priv);
+	mlxbf_gige_remove(pdev);
 }
 
 static const struct acpi_device_id __maybe_unused mlxbf_gige_acpi_match[] = {

if the device goes through both shutdown() and remove(), the netdevice will go through unregister_netdevice() 2 times, which is wrong. Am I missing something relevant?

Thanks!

Paolo

maintainer
#4 lore raw
In reply to Paolo Abeni
Quoted 9 lines · On Tue, 06 Jun 2023 12:47:09 +0200 Paolo Abeni wrote:
Quoted 9 lines

static void mlxbf_gige_shutdown(struct platform_device *pdev) {

drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_main.c +1 -4
-	struct mlxbf_gige *priv = platform_get_drvdata(pdev);
-
-	writeq(0, priv->base + MLXBF_GIGE_INT_EN);
-	mlxbf_gige_clean_port(priv);
+	mlxbf_gige_remove(pdev);
 }
Quoted 5 lines
Quoted 1 line

static const struct acpi_device_id __maybe_unused mlxbf_gige_acpi_match[] = {

if the device goes through both shutdown() and remove(), the netdevice will go through unregister_netdevice() 2 times, which is wrong. Am I missing something relevant?

Good point, mlxbf_gige_remove() needs to check that the priv pointer is not NULL.

Signature · 1 line
pw-bot: cr
#5 lore raw
Quoted 15 lines
Quoted 8 lines
Quoted 8 lines

static void mlxbf_gige_shutdown(struct platform_device *pdev) {

drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_main.c +1 -4
-	struct mlxbf_gige *priv = platform_get_drvdata(pdev);
-
-	writeq(0, priv->base + MLXBF_GIGE_INT_EN);
-	mlxbf_gige_clean_port(priv);
+	mlxbf_gige_remove(pdev);
 }
Quoted 6 lines
Quoted 2 lines

static const struct acpi_device_id __maybe_unused
mlxbf_gige_acpi_match[] = {

if the device goes through both shutdown() and remove(), the netdevice will go through unregister_netdevice() 2 times, which is wrong. Am I missing something relevant?

Quoted 2 lines

Good point, mlxbf_gige_remove() needs to check that the priv pointer is not NULL.

Thank you all for your feedback. I will fix it shortly along with net-next -> net.