kni: unregister an unregisterd net_device could cause a kernel crash
PATCH 1/1 kni: unregister an unregisterd net_device could cause a kernel crash
--- lib/librte_eal/linuxapp/kni/kni_misc.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
lib/librte_eal/linuxapp/kni/kni_misc.c +3 -1
@@ -361,7 +361,9 @@ kni_dev_remove(struct kni_dev *dev)igb_kni_remove (dev->pci_dev);if (dev->net_dev) { -unregister_netdev (dev->net_dev); +if (dev->netdev->reg_state ==NETREG_REGISTERED ){ +unregister_netdev (dev->net_dev); + }free_netdev (dev->net_dev); }
Signature · 1 line
1.7.1
Quoted 10 lines · On Fri, 9 Sep 2016 10:46:07 +0800 zhouyangchao <[email protected]> wrote:
Signed-off-by zhouyangchao <[email protected]>--- lib/librte_eal/linuxapp/kni/kni_misc.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)lib/librte_eal/linuxapp/kni/kni_misc.c +0
-0
lib/librte_eal/linuxapp/kni/kni_misc.c kni_dev_remove(struct kni_dev *dev) · line 364
Quoted 5 lines
lib/librte_eal/linuxapp/kni/kni_misc.c +1
-1@@ -361,7 +361,9 @@ kni_dev_remove(struct kni_dev *dev)igb_kni_remove (dev->pci_dev);if (dev->net_dev) { -unregister_netdev (dev->net_dev); +if (dev->netdev->reg_state ==NETREG_REGISTERED ){
----------------------------------------------------------------^ Incorrect whitespace. But then again the whole KNI driver fails completely when running kernel style check.
Quoted 10 lines · zhouyangchao
Signed-off-by zhouyangchao <[email protected]>--- lib/librte_eal/linuxapp/kni/kni_misc.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)lib/librte_eal/linuxapp/kni/kni_misc.c +0
-0
lib/librte_eal/linuxapp/kni/kni_misc.c kni_dev_remove(struct kni_dev *dev) · line 364
Quoted 5 lines
lib/librte_eal/linuxapp/kni/kni_misc.c +1
-1@@ -361,7 +361,9 @@ kni_dev_remove(struct kni_dev *dev)igb_kni_remove (dev->pci_dev);if (dev->net_dev) { -unregister_netdev (dev->net_dev); +if (dev->netdev->reg_state ==NETREG_REGISTERED ){
Although this will work, I believe we shouldn't know more about netdev internals unless we don't have to, and for this case we don't need to know it. More Linux internal knowledge means more ways to be broken in the future.
Also I am not sure if reg_state intended to be used by network drivers.
I am for first version of your patch, with missing free_netdev() added into rollback code.
pseudo code:net_dev = alloc_netdev()
...
ret = register_netdev()
if (ret)
kni_dev_remove()
free_netdev()
returnkni->net_dev = net_dev
OR if don't want to move where kni->net_dev assigned
net_dev = alloc_netdev()kni->net_dev = net_dev
...
ret = register_netdev()
if (ret)
kni->net_dev = NULL kni_dev_remove() free_netdev() return
Quoted 6 lines
lib/librte_eal/linuxapp/kni/kni_misc.c +2
-0+unregister_netdev (dev->net_dev); + }free_netdev (dev->net_dev); }
On 9/8/2016 5:44 PM, Stephen Hemminger wrote:
...
Quoted 3 lines
But then again the whole KNI driver fails completely when running kernel style check.
Yes, it generates lots of warnings.
I can fix them (excluding ethtool/*), that wouldn't take much time but how syntax only patches welcomed? Another concern is it trashes git blame.
Regards,
ferruh
2016-09-08 18:15, Ferruh Yigit:
Quoted 11 lines · Stephen Hemminger
...
Quoted 3 lines
But then again the whole KNI driver fails completely when running kernel style check.
Yes, it generates lots of warnings.
I can fix them (excluding ethtool/*), that wouldn't take much time but how syntax only patches welcomed? Another concern is it trashes git blame.
You ask a question and give the answer ;)
I think it depends just on the balance of the pros/cons - to be evaluated.
Quoted 18 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Thomas Monjalon
Sent: Friday, September 9, 2016 1:40 PM
To: Yigit, Ferruh <[email protected]>
Cc: Stephen Hemminger <[email protected]>; zhouyangchao <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [PATCH] kni: unregister an unregisterdnet_devicecould cause a kernel crash2016-09-08 18:15, Ferruh Yigit:
Quoted 8 lines · Stephen Hemminger
...
Quoted 3 lines
But then again the whole KNI driver fails completely when running kernel style check.
Quoted 7 lines
Quoted 3 lines
Yes, it generates lots of warnings.
I can fix them (excluding ethtool/*), that wouldn't take much time but how syntax only patches welcomed? Another concern is it trashes gitblame.
You ask a question and give the answer ;) I think it depends just on the balance of the pros/cons - to be evaluated.
Hi,
I think in general we would prefer to avoid any large scale code beautification since, as pointed out, it breaks the option to git blame.
However, in the case of the KNI code the main author in git is "Intel" so git blame doesn't tell you a lot. Also, Ferruh is the maintainer, has made most of the recent changes, and is actively maintaining/improving it. So I think if the syntax fix came from him it would be okay. At least it would allow us to apply the checkpatch checks.
John
2016-09-09 14:33, Mcnamara, John:
Quoted 15 lines
From: dev [mailto:[email protected]] On Behalf Of Thomas Monjalon
Quoted 14 lines
2016-09-08 18:15, Ferruh Yigit:
Quoted 11 lines · Stephen Hemminger
...
Quoted 3 lines
But then again the whole KNI driver fails completely when running kernel style check.
Yes, it generates lots of warnings.
I can fix them (excluding ethtool/*), that wouldn't take much time but how syntax only patches welcomed? Another concern is it trashes gitblame.
Quoted 8 lines
Quoted 2 lines
You ask a question and give the answer ;) I think it depends just on the balance of the pros/cons - to be evaluated.
Hi,
I think in general we would prefer to avoid any large scale code beautification since, as pointed out, it breaks the option to git blame.
However, in the case of the KNI code the main author in git is "Intel" so git blame doesn't tell you a lot. Also, Ferruh is the maintainer, has made most of the recent changes, and is actively maintaining/improving it. So I think if the syntax fix came from him it would be okay. At least it would allow us to apply the checkpatch checks.
Yes seems reasonnable
PATCH 1/1 kni: unregister an unregisterd net_device could cause a kernel crash
In reply to Ferruh Yigit--- lib/librte_eal/linuxapp/kni/kni_misc.c | 2 ++ 1 file changed, 2 insertions(+)
lib/librte_eal/linuxapp/kni/kni_misc.c +2 -0
@@ -545,7 +545,9 @@ kni_ioctl_create(struct net *net,if (ret) {KNI_ERR ("error %i registering device \"%s\"\n" , ret, dev_info.name); + kni->net_dev =NULL ;kni_dev_remove (kni); +free_netdev (net_dev);return -ENODEV ; }
Signature · 1 line
2.10.0
Quoted 2 lines · zhouyangchao
Signed-off-by zhouyangchao <[email protected]>---
There is a typo in the patch subject, I suggest:
kni: fix error rollback kernel crash
Thomas Monjalon
Applied2016-09-13 14:13, Ferruh Yigit:
Quoted 9 lines · zhouyangchao
Quoted 1 line
Signed-off-by zhouyangchao <[email protected]>There is a typo in the patch subject, I suggest:
kni: fix error rollback kernel crashFixes 9c61145ff6f9 ("kni: allow multiple threads")Acked-by Ferruh Yigit <[email protected]>
Applied, thanks