netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: airoha: Move net_devs registration in a dedicated routine
@ 2025-12-14  9:30 Lorenzo Bianconi
  2025-12-15 14:11 ` Simon Horman
  0 siblings, 1 reply; 4+ messages in thread
From: Lorenzo Bianconi @ 2025-12-14  9:30 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Lorenzo Bianconi
  Cc: linux-arm-kernel, linux-mediatek, netdev

Since airoha_probe() is not executed under rtnl lock, there is small race
where a given device is configured by user-space while the remaining ones
are not completely loaded from the dts yet. This condition will allow a
hw device misconfiguration since there are some conditions (e.g. GDM2 check
in airoha_dev_init()) that require all device are properly loaded from the
device tree. Fix the issue moving net_devices registration at the end of
the airoha_probe routine.

Fixes: 9cd451d414f6e ("net: airoha: Add loopback support for GDM2")
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/net/ethernet/airoha/airoha_eth.c | 39 +++++++++++++++++++++-----------
 1 file changed, 26 insertions(+), 13 deletions(-)

diff --git a/drivers/net/ethernet/airoha/airoha_eth.c b/drivers/net/ethernet/airoha/airoha_eth.c
index 75893c90a0a17c528c27fc0e986de194e7736637..315d97036ac1d611cc786020cbf2c6df810995a9 100644
--- a/drivers/net/ethernet/airoha/airoha_eth.c
+++ b/drivers/net/ethernet/airoha/airoha_eth.c
@@ -2924,19 +2924,26 @@ static int airoha_alloc_gdm_port(struct airoha_eth *eth,
 	port->id = id;
 	eth->ports[p] = port;
 
-	err = airoha_metadata_dst_alloc(port);
-	if (err)
-		return err;
+	return airoha_metadata_dst_alloc(port);
+}
 
-	err = register_netdev(dev);
-	if (err)
-		goto free_metadata_dst;
+static int airoha_register_gdm_devices(struct airoha_eth *eth)
+{
+	int i;
 
-	return 0;
+	for (i = 0; i < ARRAY_SIZE(eth->ports); i++) {
+		struct airoha_gdm_port *port = eth->ports[i];
+		int err;
 
-free_metadata_dst:
-	airoha_metadata_dst_free(port);
-	return err;
+		if (!port)
+			continue;
+
+		err = register_netdev(port->dev);
+		if (err)
+			return err;
+	}
+
+	return 0;
 }
 
 static int airoha_probe(struct platform_device *pdev)
@@ -3027,6 +3034,10 @@ static int airoha_probe(struct platform_device *pdev)
 		}
 	}
 
+	err = airoha_register_gdm_devices(eth);
+	if (err)
+		goto error_napi_stop;
+
 	return 0;
 
 error_napi_stop:
@@ -3040,10 +3051,12 @@ static int airoha_probe(struct platform_device *pdev)
 	for (i = 0; i < ARRAY_SIZE(eth->ports); i++) {
 		struct airoha_gdm_port *port = eth->ports[i];
 
-		if (port && port->dev->reg_state == NETREG_REGISTERED) {
+		if (!port)
+			continue;
+
+		if (port->dev->reg_state == NETREG_REGISTERED)
 			unregister_netdev(port->dev);
-			airoha_metadata_dst_free(port);
-		}
+		airoha_metadata_dst_free(port);
 	}
 	free_netdev(eth->napi_dev);
 	platform_set_drvdata(pdev, NULL);

---
base-commit: 8f7aa3d3c7323f4ca2768a9e74ebbe359c4f8f88
change-id: 20251214-airoha-fix-dev-registration-c3a114d58416

Best regards,
-- 
Lorenzo Bianconi <lorenzo@kernel.org>


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

* Re: [PATCH net] net: airoha: Move net_devs registration in a dedicated routine
  2025-12-14  9:30 [PATCH net] net: airoha: Move net_devs registration in a dedicated routine Lorenzo Bianconi
@ 2025-12-15 14:11 ` Simon Horman
  2025-12-15 14:33   ` Lorenzo Bianconi
  0 siblings, 1 reply; 4+ messages in thread
From: Simon Horman @ 2025-12-15 14:11 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, linux-arm-kernel, linux-mediatek, netdev

On Sun, Dec 14, 2025 at 10:30:07AM +0100, Lorenzo Bianconi wrote:
> Since airoha_probe() is not executed under rtnl lock, there is small race
> where a given device is configured by user-space while the remaining ones
> are not completely loaded from the dts yet. This condition will allow a
> hw device misconfiguration since there are some conditions (e.g. GDM2 check
> in airoha_dev_init()) that require all device are properly loaded from the
> device tree. Fix the issue moving net_devices registration at the end of
> the airoha_probe routine.
> 
> Fixes: 9cd451d414f6e ("net: airoha: Add loopback support for GDM2")
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>

Hi Lorenzo,

As a fix this patch looks good to me.

Reviewed-by: Simon Horman <horms@kernel.org>

But I am somewhat surprised that the netdev isn't unregistered earlier
both in airoha_remove() and the unwind ladder of airoha_probe().

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

* Re: [PATCH net] net: airoha: Move net_devs registration in a dedicated routine
  2025-12-15 14:11 ` Simon Horman
@ 2025-12-15 14:33   ` Lorenzo Bianconi
  2025-12-15 14:39     ` Simon Horman
  0 siblings, 1 reply; 4+ messages in thread
From: Lorenzo Bianconi @ 2025-12-15 14:33 UTC (permalink / raw)
  To: Simon Horman
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, linux-arm-kernel, linux-mediatek, netdev

[-- Attachment #1: Type: text/plain, Size: 1264 bytes --]

> On Sun, Dec 14, 2025 at 10:30:07AM +0100, Lorenzo Bianconi wrote:
> > Since airoha_probe() is not executed under rtnl lock, there is small race
> > where a given device is configured by user-space while the remaining ones
> > are not completely loaded from the dts yet. This condition will allow a
> > hw device misconfiguration since there are some conditions (e.g. GDM2 check
> > in airoha_dev_init()) that require all device are properly loaded from the
> > device tree. Fix the issue moving net_devices registration at the end of
> > the airoha_probe routine.
> > 
> > Fixes: 9cd451d414f6e ("net: airoha: Add loopback support for GDM2")
> > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> 
> Hi Lorenzo,
> 
> As a fix this patch looks good to me.
> 
> Reviewed-by: Simon Horman <horms@kernel.org>

Hi Simon,

thx for the review.

> 
> But I am somewhat surprised that the netdev isn't unregistered earlier
> both in airoha_remove() and the unwind ladder of airoha_probe().

do you mean moving unregister_netdev() before
airoha_qdma_stop_napi()/airoha_hw_cleanup()? I was thinking about it to be
honest :)
Since it is not related to this fix, I will post a patch as soon as net-next is
open again.

Regards,
Lorenzo


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

* Re: [PATCH net] net: airoha: Move net_devs registration in a dedicated routine
  2025-12-15 14:33   ` Lorenzo Bianconi
@ 2025-12-15 14:39     ` Simon Horman
  0 siblings, 0 replies; 4+ messages in thread
From: Simon Horman @ 2025-12-15 14:39 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, linux-arm-kernel, linux-mediatek, netdev

On Mon, Dec 15, 2025 at 03:33:01PM +0100, Lorenzo Bianconi wrote:
> > On Sun, Dec 14, 2025 at 10:30:07AM +0100, Lorenzo Bianconi wrote:
> > > Since airoha_probe() is not executed under rtnl lock, there is small race
> > > where a given device is configured by user-space while the remaining ones
> > > are not completely loaded from the dts yet. This condition will allow a
> > > hw device misconfiguration since there are some conditions (e.g. GDM2 check
> > > in airoha_dev_init()) that require all device are properly loaded from the
> > > device tree. Fix the issue moving net_devices registration at the end of
> > > the airoha_probe routine.
> > > 
> > > Fixes: 9cd451d414f6e ("net: airoha: Add loopback support for GDM2")
> > > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> > 
> > Hi Lorenzo,
> > 
> > As a fix this patch looks good to me.
> > 
> > Reviewed-by: Simon Horman <horms@kernel.org>
> 
> Hi Simon,
> 
> thx for the review.
> 
> > 
> > But I am somewhat surprised that the netdev isn't unregistered earlier
> > both in airoha_remove() and the unwind ladder of airoha_probe().
> 
> do you mean moving unregister_netdev() before
> airoha_qdma_stop_napi()/airoha_hw_cleanup()? I was thinking about it to be
> honest :)
> Since it is not related to this fix, I will post a patch as soon as net-next is
> open again.

Yes, that is what I was thinking.
And I agree that this is net-next material unrelated to this fix.

While you are there, I would look at making the unwind ladder
in probe follow the same pattern as remove, if possible.
I think that might mean moving airoha_ppe_deinit().

But perhaps you already thought of that too.
Or there is some good reason not to do so.



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

end of thread, other threads:[~2025-12-15 14:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-14  9:30 [PATCH net] net: airoha: Move net_devs registration in a dedicated routine Lorenzo Bianconi
2025-12-15 14:11 ` Simon Horman
2025-12-15 14:33   ` Lorenzo Bianconi
2025-12-15 14:39     ` Simon Horman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).