bnxt_re: Rely on Kconfig to keep module dependency
Subsystems (2)
PATCH 1/1 bnxt_re: Rely on Kconfig to keep module dependency
From: Leon Romanovsky <[email protected]>
Instead of manually messing with parent driver module reference counting, rely on "depends on" keyword to ensure that proper probe/remove chain is performed.
--- drivers/infiniband/hw/bnxt_re/Kconfig | 4 +--- drivers/infiniband/hw/bnxt_re/main.c | 20 +++++--------------- 2 files changed, 6 insertions(+), 18 deletions(-)
drivers/infiniband/hw/bnxt_re/Kconfig +1 -3
@@ -2,9 +2,7 @@ config INFINIBAND_BNXT_RE tristate "Broadcom Netxtreme HCA support" depends on 64BIT - depends on ETHERNET && NETDEVICES && PCI && INET && DCB - select NET_VENDOR_BROADCOM - select BNXT + depends on ETHERNET && NETDEVICES && PCI && INET && DCB && BNXT help This driver supports Broadcom NetXtreme-E 10/25/40/50 gigabit RoCE HCAs. To compile this driver as a module, choose M here:
drivers/infiniband/hw/bnxt_re/main.c +5 -15
@@ -561,13 +561,6 @@ static struct bnxt_re_dev *bnxt_re_from_netdev(struct net_device *netdev) return container_of(ibdev, struct bnxt_re_dev, ibdev); } -static void bnxt_re_dev_unprobe (struct net_device *netdev, -struct bnxt_en_dev *en_dev) -{ -dev_put (netdev); -module_put (en_dev->pdev->driver->driver.owner); -} -static struct bnxt_en_dev *bnxt_re_dev_probe (struct net_device *netdev) {struct bnxt *bp =netdev_priv (netdev);
@@ -593,10 +586,6 @@ static struct bnxt_en_dev *bnxt_re_dev_probe(struct net_device *netdev)return ERR_PTR (-ENODEV ); } -/* Bump net device reference count */ -if (!try_module_get (pdev->driver->driver.owner)) -return ERR_PTR (-ENODEV ); -dev_hold (netdev);return en_dev;
@@ -1523,13 +1512,14 @@ static int bnxt_re_dev_init(struct bnxt_re_dev *rdev, u8 wqe_mode)static void bnxt_re_dev_unreg (struct bnxt_re_dev *rdev) { -struct bnxt_en_dev *en_dev = rdev->en_dev;struct net_device *netdev = rdev->netdev;bnxt_re_dev_remove (rdev); -if (netdev) -bnxt_re_dev_unprobe (netdev, en_dev); +if (!netdev) +return ; + +dev_put (netdev); }static int bnxt_re_dev_reg (struct bnxt_re_dev **rdev,struct net_device *netdev)
@@ -1551,7 +1541,7 @@ static int bnxt_re_dev_reg(struct bnxt_re_dev **rdev, struct net_device *netdev) *rdev =bnxt_re_dev_add (netdev, en_dev);if (!*rdev) { rc = -ENOMEM ; -bnxt_re_dev_unprobe (netdev, en_dev); +dev_put (netdev); goto exit; } exit:
Signature · 1 line
2.30.2
Jason Gunthorpe
maintainerQuoted 5 lines · Leon Romanovsky
From: Leon Romanovsky <[email protected]>
Instead of manually messing with parent driver module reference counting, rely on "depends on" keyword to ensure that proper probe/remove chain is performed.
?? kconfig doesn't impact module ordering.
To have a proper remove chain there should be a symbol reference from bnxt_re to whatever the other module is
Quoted 9 lines
Signed-off-by Leon Romanovsky <[email protected]>drivers/infiniband/hw/bnxt_re/Kconfig | 4 +--- drivers/infiniband/hw/bnxt_re/main.c | 20 +++++--------------- 2 files changed, 6 insertions(+), 18 deletions(-)drivers/infiniband/hw/bnxt_re/Kconfig +1
-0+++ b/drivers/infiniband/hw/bnxt_re/Kconfig
drivers/infiniband/hw/bnxt_re/Kconfig line 5
Quoted 7 lines
drivers/infiniband/hw/bnxt_re/Kconfig +1
-3@@ -2,9 +2,7 @@ config INFINIBAND_BNXT_RE tristate "Broadcom Netxtreme HCA support" depends on 64BIT - depends on ETHERNET && NETDEVICES && PCI && INET && DCB - select NET_VENDOR_BROADCOM - select BNXT + depends on ETHERNET && NETDEVICES && PCI && INET && DCB && BNXT
Though this is correct, BNXT is a 'tristate' so it should be referenced with depends on select.
drivers/infiniband/hw/bnxt_re/main.c static struct bnxt_re_dev *bnxt_re_from_netdev(struct net_device *netdev) · line 569
Quoted 13 lines
drivers/infiniband/hw/bnxt_re/main.c +1
-6+++ b/drivers/infiniband/hw/bnxt_re/main.c@@ -561,13 +561,6 @@ static struct bnxt_re_dev *bnxt_re_from_netdev(struct net_device *netdev) return container_of(ibdev, struct bnxt_re_dev, ibdev); } -static void bnxt_re_dev_unprobe (struct net_device *netdev, -struct bnxt_en_dev *en_dev) -{ -dev_put (netdev); -module_put (en_dev->pdev->driver->driver.owner); -}
And you are right to be wondering WTF is this
Jason
Quoted 8 lines · Jason Gunthorpe
Quoted 5 lines · Leon Romanovsky
From: Leon Romanovsky <[email protected]>
Instead of manually messing with parent driver module reference counting, rely on "depends on" keyword to ensure that proper probe/remove chain is performed.
?? kconfig doesn't impact module ordering.
Yeah, I was fast with the typing.
Quoted 3 lines
To have a proper remove chain there should be a symbol reference from
bnxt_reto whatever the other module is
Right, they have probe_ulp() calls or something.
Quoted 38 lines
Quoted 10 lines
Signed-off-by Leon Romanovsky <[email protected]>drivers/infiniband/hw/bnxt_re/Kconfig | 4 +--- drivers/infiniband/hw/bnxt_re/main.c | 20 +++++--------------- 2 files changed, 6 insertions(+), 18 deletions(-)drivers/infiniband/hw/bnxt_re/Kconfig +1
-0+++ b/drivers/infiniband/hw/bnxt_re/Kconfigdrivers/infiniband/hw/bnxt_re/Kconfig line 5
Quoted 7 lines
drivers/infiniband/hw/bnxt_re/Kconfig +1
-3@@ -2,9 +2,7 @@ config INFINIBAND_BNXT_RE tristate "Broadcom Netxtreme HCA support" depends on 64BIT - depends on ETHERNET && NETDEVICES && PCI && INET && DCB - select NET_VENDOR_BROADCOM - select BNXT + depends on ETHERNET && NETDEVICES && PCI && INET && DCB && BNXTThough this is correct, BNXT is a 'tristate' so it should be referenced with depends on select.
drivers/infiniband/hw/bnxt_re/main.c static struct bnxt_re_dev *bnxt_re_from_netdev(struct net_device *netdev) · line 569
Quoted 13 lines
drivers/infiniband/hw/bnxt_re/main.c +1
-6+++ b/drivers/infiniband/hw/bnxt_re/main.c@@ -561,13 +561,6 @@ static struct bnxt_re_dev *bnxt_re_from_netdev(struct net_device *netdev) return container_of(ibdev, struct bnxt_re_dev, ibdev); } -static void bnxt_re_dev_unprobe (struct net_device *netdev, -struct bnxt_en_dev *en_dev) -{ -dev_put (netdev); -module_put (en_dev->pdev->driver->driver.owner); -}And you are right to be wondering WTF is this
Jason
Quoted 11 lines · Leon Romanovsky
Quoted 8 lines · Jason Gunthorpe
Quoted 5 lines · Leon Romanovsky
From: Leon Romanovsky <[email protected]>
Instead of manually messing with parent driver module reference counting, rely on "depends on" keyword to ensure that proper probe/remove chain is performed.
?? kconfig doesn't impact module ordering.
Quoted 46 lines
Yeah, I was fast with the typing.
Quoted 3 lines
To have a proper remove chain there should be a symbol reference from
bnxt_reto whatever the other module isRight, they have
probe_ulp()calls or something.Quoted 38 lines
Quoted 10 lines
Signed-off-by Leon Romanovsky <[email protected]>drivers/infiniband/hw/bnxt_re/Kconfig | 4 +--- drivers/infiniband/hw/bnxt_re/main.c | 20 +++++--------------- 2 files changed, 6 insertions(+), 18 deletions(-)drivers/infiniband/hw/bnxt_re/Kconfig +1
-0+++ b/drivers/infiniband/hw/bnxt_re/Kconfigdrivers/infiniband/hw/bnxt_re/Kconfig line 5
Quoted 7 lines
drivers/infiniband/hw/bnxt_re/Kconfig +1
-3@@ -2,9 +2,7 @@ config INFINIBAND_BNXT_RE tristate "Broadcom Netxtreme HCA support" depends on 64BIT - depends on ETHERNET && NETDEVICES && PCI && INET && DCB - select NET_VENDOR_BROADCOM - select BNXT + depends on ETHERNET && NETDEVICES && PCI && INET && DCB && BNXTThough this is correct, BNXT is a 'tristate' so it should be referenced with depends on select.
drivers/infiniband/hw/bnxt_re/main.c static struct bnxt_re_dev *bnxt_re_from_netdev(struct net_device *netdev) · line 569
Quoted 13 lines
drivers/infiniband/hw/bnxt_re/main.c +1
-6+++ b/drivers/infiniband/hw/bnxt_re/main.c@@ -561,13 +561,6 @@ static struct bnxt_re_dev *bnxt_re_from_netdev(struct net_device *netdev) return container_of(ibdev, struct bnxt_re_dev, ibdev); } -static void bnxt_re_dev_unprobe (struct net_device *netdev, -struct bnxt_en_dev *en_dev) -{ -dev_put (netdev); -module_put (en_dev->pdev->driver->driver.owner); -}And you are right to be wondering WTF is this
Jason
Hi Leon and Jason,
Still trying to understand but what's the big idea here may be I can help.
Signature · 2 lines
-Regards Devesh
Jason Gunthorpe
maintainerQuoted 10 lines · Devesh Sharma
Quoted 8 lines
Quoted 8 lines
drivers/infiniband/hw/bnxt_re/main.c static struct bnxt_re_dev *bnxt_re_from_netdev(struct net_device *netdev) · line 569
Quoted 6 lines
drivers/infiniband/hw/bnxt_re/main.c +0
-6-static void bnxt_re_dev_unprobe (struct net_device *netdev, -struct bnxt_en_dev *en_dev) -{ -dev_put (netdev); -module_put (en_dev->pdev->driver->driver.owner); -}And you are right to be wondering WTF is this
Still trying to understand but what's the big idea here may be I can help.
A driver should not have module put things like the above
It should not be accessing ->driver without holding the device_lock()
Basically it is all nonsense coding, Leon suggests to delete it and he is probably right.
Can you explain what it thinks it is doing?
Jason
Quoted 14 lines · Jason Gunthorpe
Quoted 10 lines · Devesh Sharma
Quoted 8 lines
Quoted 8 lines
drivers/infiniband/hw/bnxt_re/main.c static struct bnxt_re_dev *bnxt_re_from_netdev(struct net_device *netdev) · line 569
Quoted 6 lines
drivers/infiniband/hw/bnxt_re/main.c +0
-6-static void bnxt_re_dev_unprobe (struct net_device *netdev, -struct bnxt_en_dev *en_dev) -{ -dev_put (netdev); -module_put (en_dev->pdev->driver->driver.owner); -}And you are right to be wondering WTF is this
Still trying to understand but what's the big idea here may be I can help.
Quoted 8 lines
A driver should not have module put things like the above
It should not be accessing ->driver without holding the
device_lock()Basically it is all nonsense coding, Leon suggests to delete it and he is probably right.
Can you explain what it thinks it is doing?
That F'ed up code is trying to prevent a situation where someone tries to remove the bnxt_en driver while bnxt_re driver is using it. All because bnxt_re driver is at the mercy of bnxt_en drive and there is not symbole dependence, Do you suggest anything to prevent that unload of bnxt_en other than doing this jargon. I did not follow how DEPENDS_ON would prevent things.
Quoted 2 lines
Jason
Signature · 2 lines
-Regards Devesh
Jason Gunthorpe
maintainerQuoted 22 lines · Devesh Sharma
Quoted 21 lines · Jason Gunthorpe
Quoted 10 lines · Devesh Sharma
Quoted 8 lines
Quoted 8 lines
drivers/infiniband/hw/bnxt_re/main.c static struct bnxt_re_dev *bnxt_re_from_netdev(struct net_device *netdev) · line 569
Quoted 6 lines
drivers/infiniband/hw/bnxt_re/main.c +0
-6-static void bnxt_re_dev_unprobe (struct net_device *netdev, -struct bnxt_en_dev *en_dev) -{ -dev_put (netdev); -module_put (en_dev->pdev->driver->driver.owner); -}And you are right to be wondering WTF is this
Still trying to understand but what's the big idea here may be I can help.
A driver should not have module put things like the above
It should not be accessing ->driver without holding the
device_lock()Basically it is all nonsense coding, Leon suggests to delete it and he is probably right.
Quoted 6 lines
Quoted 1 line
Can you explain what it thinks it is doing?
That F'ed up code is trying to prevent a situation where someone tries to remove the
bnxt_endriver whilebnxt_redriver is using it. All becausebnxt_redriver is at the mercy ofbnxt_endrive and there is not symbole dependence, Do you suggest anything to prevent that unload ofbnxt_enother than doing this jargon.
Well, the module put says nothing about the validity of the 'struct bnxt' and related it extracted from the netdev - you should have a mechanism that prevents that from going invalid which in turn will ensure the function pointers you want to touch are still valid too. (as the struct containing function pointers must become invalid before the module unloads)
Probably the netdev refcount does that already but I always forget the exact point during unregister that it waits on that...
As far as strict module dependencies go, replace the pointless brp->ulp_probe function pointer with an actual call to bnxt_ulp_probe() and you get the same effect as the module_get.
Jason
Quoted 37 lines · Jason Gunthorpe
Quoted 22 lines · Devesh Sharma
Quoted 21 lines · Jason Gunthorpe
Quoted 10 lines · Devesh Sharma
Quoted 8 lines
Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +0
-6-static void bnxt_re_dev_unprobe(struct net_device *netdev, - struct bnxt_en_dev *en_dev) -{ - dev_put(netdev); - module_put(en_dev->pdev->driver->driver.owner); -}And you are right to be wondering WTF is this
Still trying to understand but what's the big idea here may be I can help.
A driver should not have module put things like the above
It should not be accessing ->driver without holding the
device_lock()Basically it is all nonsense coding, Leon suggests to delete it and he is probably right.
Quoted 6 lines
Quoted 1 line
Can you explain what it thinks it is doing?
That F'ed up code is trying to prevent a situation where someone tries to remove the
bnxt_endriver whilebnxt_redriver is using it. All becausebnxt_redriver is at the mercy ofbnxt_endrive and there is not symbole dependence, Do you suggest anything to prevent that unload ofbnxt_enother than doing this jargon.Well, the module put says nothing about the validity of the 'struct bnxt' and related it extracted from the netdev - you should have a mechanism that prevents that from going invalid which in turn will ensure the function pointers you want to touch are still valid too. (as the struct containing function pointers must become invalid before the module unloads)
Quoted 6 lines
Probably the netdev refcount does that already but I always forget the exact point during unregister that it waits on that...
As far as strict module dependencies go, replace the pointless
brp->ulp_probefunction pointer with an actual call tobnxt_ulp_probe()and you get the same effect as themodule_get.
Yeah, I'll update it.
Thanks
Quoted 2 lines
Jason
Quoted 42 lines · Leon Romanovsky
Quoted 40 lines · Jason Gunthorpe
Quoted 22 lines · Devesh Sharma
Quoted 21 lines · Jason Gunthorpe
Quoted 10 lines · Devesh Sharma
Quoted 8 lines
Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +0
-6-static void bnxt_re_dev_unprobe(struct net_device *netdev, - struct bnxt_en_dev *en_dev) -{ - dev_put(netdev); - module_put(en_dev->pdev->driver->driver.owner); -}And you are right to be wondering WTF is this
Still trying to understand but what's the big idea here may be I can help.
A driver should not have module put things like the above
It should not be accessing ->driver without holding the
device_lock()Basically it is all nonsense coding, Leon suggests to delete it and he is probably right.
Quoted 6 lines
Quoted 1 line
Can you explain what it thinks it is doing?
That F'ed up code is trying to prevent a situation where someone tries to remove the
bnxt_endriver whilebnxt_redriver is using it. All becausebnxt_redriver is at the mercy ofbnxt_endrive and there is not symbole dependence, Do you suggest anything to prevent that unload ofbnxt_enother than doing this jargon.Well, the module put says nothing about the validity of the 'struct bnxt' and related it extracted from the netdev - you should have a mechanism that prevents that from going invalid which in turn will ensure the function pointers you want to touch are still valid too. (as the struct containing function pointers must become invalid before the module unloads)
Probably the netdev refcount does that already but I always forget the exact point during unregister that it waits on that...
Quoted 8 lines
Quoted 3 lines
As far as strict module dependencies go, replace the pointless
brp->ulp_probefunction pointer with an actual call tobnxt_ulp_probe()and you get the same effect as themodule_get.Yeah, I'll update it.
Thanks
Yes, making it an exported symbol will help. It needs radical changes in the driver load/unload path. Let me as well take this feedback to my internal team .
Quoted 2 lines
Quoted 2 lines
Jason
Signature · 2 lines
-Regards Devesh