drivers/base/node: Handle error properly in register_one_node()
Subsystems (2)
PATCH 1/1 drivers/base/node: Handle error properly in register_one_node()
If register_node() returns an error, it is not handled correctly. The function will proceed further and try to register CPUs under the node, which is not correct.
So, in this patch, if register_node() returns an error, we return immediately from the function.
---
This patch is based on the mm-unstable branch.
The issue has been present since the above commit, which is quite old. Should I add a Fixes: tag and backport it to all kernels that have this commit?
--- drivers/base/node.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/base/node.c +2 -0
@@ -885,6 +885,8 @@ int register_one_node(int nid) node_devices[nid] = node; error =register_node (node_devices[nid], nid); +if (error) +return error;/* link cpu under this node */ for_each_present_cpu (cpu) {
Signature · 1 line
2.47.1
Quoted 10 lines · Donet Tom
If
register_node()returns an error, it is not handled correctly. The function will proceed further and try to register CPUs under the node, which is not correct.So, in this patch, if
register_node()returns an error, we return immediately from the function.Signed-off-by Donet Tom <[email protected]>---
...
drivers/base/node.c int register_one_node(int nid) · line 889
Quoted 10 lines
drivers/base/node.c +2
-0@@ -885,6 +885,8 @@ int register_one_node(int nid) node_devices[nid] = node; error =register_node (node_devices[nid], nid); +if (error) +return error;
Ok, all current callers (based on mm-unstable) panic or BUG() if this fails, but powerpc, in init_phb_dynamic(), which keeps on going.
Unless it panics somewhere down the road as well.
So I think we need to:
node_devices[nid] = NULL
kfree(node)
?
Also, once Hannes fix lands, we might need that as well.
Anyway, I'd suggest you hold on until Hannes fix lands, so we can later rebase all your mem-hotplug on top of that [1].
[1] https://lore.kernel.org/linux-mm/[email protected]/T/#mbf392eb390b8053f96be50da3b40dfd9b62dd389
Signature · 2 lines
Oscar Salvador SUSE Labs
Quoted 26 lines · Oscar Salvador
Quoted 10 lines · Donet Tom
If
register_node()returns an error, it is not handled correctly. The function will proceed further and try to register CPUs under the node, which is not correct.So, in this patch, if
register_node()returns an error, we return immediately from the function.Signed-off-by Donet Tom <[email protected]>---
...
drivers/base/node.c int register_one_node(int nid) · line 889
Quoted 10 lines
drivers/base/node.c +2
-0@@ -885,6 +885,8 @@ int register_one_node(int nid) node_devices[nid] = node; error =register_node (node_devices[nid], nid); +if (error) +return error;Ok, all current callers (based on mm-unstable) panic or
BUG()if this fails, but powerpc, ininit_phb_dynamic(), which keeps on going.
Unless it panics somewhere down the road as well.
Quoted 6 lines
So I think we need to:
node_devices[nid] = NULL
kfree(node)?
Yes, I will add this too.
But one question: if register_node() fails, is it okay to continue, or should we panic?
What is the correct way to handle this?
Quoted 4 lines
Also, once Hannes fix lands, we might need that as well.
Anyway, I'd suggest you hold on until Hannes fix lands, so we can later rebase all your mem-hotplug on top of that [1].
Sure
Quoted 36 lines · Donet Tom
Quoted 26 lines · Oscar Salvador
Quoted 10 lines · Donet Tom
If
register_node()returns an error, it is not handled correctly. The function will proceed further and try to register CPUs under the node, which is not correct.So, in this patch, if
register_node()returns an error, we return immediately from the function.Signed-off-by Donet Tom <[email protected]>---
...
drivers/base/node.c int register_one_node(int nid) · line 889
Quoted 10 lines
drivers/base/node.c +2
-0@@ -885,6 +885,8 @@ int register_one_node(int nid) node_devices[nid] = node; error =register_node (node_devices[nid], nid); +if (error) +return error;Ok, all current callers (based on mm-unstable) panic or
BUG()if this fails, but powerpc, ininit_phb_dynamic(), which keeps on going.
Unless it panics somewhere down the road as well.Quoted 6 lines
So I think we need to:
node_devices[nid] = NULL
kfree(node)?
Quoted 6 lines
Yes, I will add this too.
But one question: if
register_node()fails, is it okay to continue, or should we panic?What is the correct way to handle this?
panic() or BUG() is not the answer :)
Try to recover ...
Signature · 3 lines
Cheers, David / dhildenb
Quoted 38 lines · David Hildenbrand
Quoted 37 lines · Donet Tom
Quoted 25 lines · Oscar Salvador
Quoted 10 lines · Donet Tom
If
register_node()returns an error, it is not handled correctly. The function will proceed further and try to register CPUs under the node, which is not correct.So, in this patch, if
register_node()returns an error, we return immediately from the function.Signed-off-by Donet Tom <[email protected]>---
...
drivers/base/node.c int register_one_node(int nid) · line 888
Quoted 9 lines
drivers/base/node.c +2
-0@@ -885,6 +885,8 @@ int register_one_node(int nid) node_devices[nid] = node; error = register_node(node_devices[nid], nid); + if (error) + return error;Ok, all current callers (based on mm-unstable) panic or
BUG()if this fails, but powerpc, ininit_phb_dynamic(), which keeps on going.
Unless it panics somewhere down the road as well.Quoted 6 lines
So I think we need to:
node_devices[nid] = NULL
kfree(node)?
Yes, I will add this too.
Quoted 8 lines
Quoted 4 lines
But one question: if
register_node()fails, is it okay to continue, or should we panic?What is the correct way to handle this?
panic()orBUG()is not the answer :)Try to recover ...
Got it, thank you very much, David.