net: dev: Add API to check net_dev readiness
Subsystems (2)
PATCH 1/1 net: dev: Add API to check net_dev readiness
From: Ilia Lin <[email protected]>
Add an API that returns true, if the net_dev_init was already called, and the driver was initialized.
Some early drivers, that are initialized during the subsys_initcall may try accessing the net_dev or NAPI APIs before the net_dev_init, and will encounter a kernel bug. This API provides a way to handle this and manage by deferring or by other way.
--- include/linux/netdevice.h | 2 ++ net/core/dev.c | 17 +++++++++++++++++ 2 files changed, 19 insertions(+)
include/linux/netdevice.h +2 -0
@@ -2600,6 +2600,8 @@ enum netdev_cmd { };const char *netdev_cmd_to_name (enum netdev_cmd cmd); +bool is_net_dev_initialized (void ); +int register_netdevice_notifier (struct notifier_block *nb);int unregister_netdevice_notifier (struct notifier_block *nb);int register_netdevice_notifier_net (struct net *net,struct notifier_block *nb);
net/core/dev.c +17 -0
@@ -1793,6 +1793,23 @@ static void call_netdevice_unregister_net_notifiers(struct notifier_block *nb,static int dev_boot_phase =1 ;/** +* is_net_dev_initialized - check, whether the net_dev was +* initialized +* +* Returns true, if the net_dev_init was already called, and +* the driver is initialized. +* +* This is useful for early drivers trying to call net_dev and +* NAPI APIs +*/ + +bool is_net_dev_initialized (void ) +{ +return !(bool )dev_boot_phase; +} +EXPORT_SYMBOL (is_net_dev_initialized); + +/** * register_netdevice_notifier - register a network notifier block * @nb: notifier *
Quoted 9 lines · Ilia Lin
From: Ilia Lin <[email protected]>
Add an API that returns true, if the
net_dev_initwas already called, and the driver was initialized.Some early drivers, that are initialized during the
subsys_initcallmay try accessing thenet_devor NAPI APIs before thenet_dev_init, and will encounter a kernel bug. This API provides a way to handle this and manage by deferring or by other way.
Hi Ilia
You need to include a user of this new API.
I also have to wonder why a network device driver is being probed the subsys_initcall.
Andrew
David Miller
maintainerFrom: Andrew Lunn <[email protected]>
Date: Sun, 26 Jul 2020 21:45:28 +0200
Quoted 2 lines
I also have to wonder why a network device driver is being probed the
subsys_initcall.
This makes me wonder how this interface could even be useful. The only way to fix the problem is to change when the device is probed, which would mean changing which initcall it uses. So at run time, this information can't do much.
Hi Andrew and David,
Thank you for your comments!
The client driver is still work in progress, but it can be seen here:
https://source.codeaurora.org/quic/la/kernel/msm-4.19/tree/drivers/platform/msm/ipa/ipa_api.c#n3842
For HW performance reasons, it has to be in subsys_initcall.
Here is the register_netdev call:
https://source.codeaurora.org/quic/la/kernel/msm-4.19/tree/drivers/platform/msm/ipa/ipa_v3/rmnet_ipa.c#n2497
And it is going to be in the subsys_initcall as well.
Thanks,
Ilia
Quoted 11 lines · David Miller
From: Andrew Lunn <[email protected]>
Date: Sun, 26 Jul 2020 21:45:28 +0200Quoted 2 lines
I also have to wonder why a network device driver is being probed the
subsys_initcall.This makes me wonder how this interface could even be useful. The only way to fix the problem is to change when the device is probed, which would mean changing which initcall it uses. So at run time, this information can't do much.
Quoted 1 line · Ilia Lin
Hi Andrew and David,
Hi Ilia
Please don't top post.
Quoted 7 lines
Thank you for your comments!
The client driver is still work in progress, but it can be seen here:
https://source.codeaurora.org/quic/la/kernel/msm-4.19/tree/drivers/platform/msm/ipa/ipa_api.c#n3842For HW performance reasons, it has to be in
subsys_initcall.
Well, until the user of this new API is ready, we will not accept the patch.
You also need to explain "For HW performance reasons". Why is this driver special that it can do things which no over driver does?
And you should really be working on net-next, not this dead kernel version, if you want to get merged into mainline.
Network drivers do not belong is drivers/platform. There is also ready a drivers/net/ipa, so i assume you will move there.
Andrew
My comments inline.
Thanks,
Ilia Lin
Quoted 11 lines · Andrew Lunn
Quoted 1 line · Ilia Lin
Hi Andrew and David,
Hi Ilia
Please don't top post.
Quoted 3 lines
Thank you for your comments!
Quoted 7 lines
Quoted 4 lines
The client driver is still work in progress, but it can be seen here:
https://source.codeaurora.org/quic/la/kernel/msm-4.19/tree/drivers/platform/msm/ipa/ipa_api.c#n3842For HW performance reasons, it has to be in
subsys_initcall.Well, until the user of this new API is ready, we will not accept the patch.
OK, but once we submit the change in the driver, is it good to go?
Quoted 3 lines
You also need to explain "For HW performance reasons". Why is this driver special that it can do things which no over driver does?
There are very strict KPI requirements. E.g. automotive rear mirror must be online 3 sec since boot.
Quoted 3 lines
And you should really be working on net-next, not this dead kernel version, if you want to get merged into mainline.
Of course, the upstream submition will be done on the mainline. I just gave an example of an existing product driver.
Quoted 3 lines
Network drivers do not belong is
drivers/platform. There is also ready adrivers/net/ipa, so i assume you will move there.
Sure, the driver in the drivers/net/ipa is the one that will be updated in the future.
Quoted 2 lines
Andrew
Quoted 3 lines
Quoted 2 lines
Well, until the user of this new API is ready, we will not accept the patch.
OK, but once we submit the change in the driver, is it good to go?
No. You really do need to explain why it is needed, and why it is safe.
Quoted 4 lines
Quoted 2 lines
You also need to explain "For HW performance reasons". Why is this driver special that it can do things which no over driver does?
There are very strict KPI requirements. E.g. automotive rear mirror must be online 3 sec since boot.
Which does not explain why this driver is special. What you really should be thinking about is having the required drivers for this use case built in, and the rest as modules. Get your time critical parts running, and then load the rest of the driver moduless and kick off additional user space in a second phase.
You are breaking all sorts of assumptions by loading network drivers before the stack is ready. You need to expect all sorts of nasty bugs. If this was just in your vendor kernel, we would not care too much, it is your problem to solve. But by doing this in mainline, you are setting a precedent for others to do it as well. And then we really do need to care about the broken assumptions. I doubt we are ready to allow this.
Andrew
Hi Andrew and David,
Thank you for your comments!
The client driver is still work in progress, but it can be seen here:
https://source.codeaurora.org/quic/la/kernel/msm-4.19/tree/drivers/platform/msm/ipa/ipa_api.c#n3842
For HW performance reasons, it has to be in subsys_initcall.
Here is the register_netdev call:
https://source.codeaurora.org/quic/la/kernel/msm-4.19/tree/drivers/platform/msm/ipa/ipa_v3/rmnet_ipa.c#n2497
And it is going to be in the subsys_initcall as well.
Thanks,
Ilia
Quoted 11 lines · David Miller
From: Andrew Lunn <[email protected]>
Date: Sun, 26 Jul 2020 21:45:28 +0200Quoted 2 lines
I also have to wonder why a network device driver is being probed the
subsys_initcall.This makes me wonder how this interface could even be useful. The only way to fix the problem is to change when the device is probed, which would mean changing which initcall it uses. So at run time, this information can't do much.