null_blk: prevent crash from bad home_node value
PATCH 1/1 null_blk: prevent crash from bad home_node value
At module load, if the selected home_node value is greater than the available numa nodes, the system will crash in __alloc_pages_nodemask() due to a bad paging request. Prevent this user error crash by detecting the bad value, logging an error, and setting g_home_node back to the default of NUMA_NO_NODE.
--- drivers/block/null_blk_main.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/block/null_blk_main.c +5 -0
@@ -1748,6 +1748,11 @@ static int __init null_init(void)return -EINVAL ; } +if (g_home_node >= nr_online_nodes) { +pr_err ("null_blk: invalid home_node value\n" ); + g_home_node =NUMA_NO_NODE ; + } +if (g_queue_mode ==NULL_Q_RQ ) {pr_err ("null_blk: legacy IO path no longer available\n" );return -EINVAL ;
Signature · 1 line
2.17.2
Quoted 5 lines · John Pittman
At module load, if the selected
home_nodevalue is greater than the available numa nodes, the system will crash in__alloc_pages_nodemask()due to a bad paging request. Prevent this user error crash by detecting the bad value, logging an error, and settingg_home_nodeback to the default ofNUMA_NO_NODE.
Applied, thanks.
Signature · 1 line
Jens Axboe
Hi Jens, I got some unexpected results with this patch this morning. When loading null_blk with no arguments, I got the invalid home_node value error message. I did some debug and found that the values seemed fine:
+ pr_err("g_home_node is %d", g_home_node);
+ pr_err("nr_online_nodes is %d", nr_online_nodes);
+ pr_err("NUMA_NO_NODE is %d", NUMA_NO_NODE);+
+ if (g_home_node >= nr_online_nodes) {
+ pr_err("null_blk: invalid home_node value\n");
+ g_home_node = NUMA_NO_NODE;
+ }
+
if (g_queue_mode == NULL_Q_RQ) {
pr_err("null_blk: legacy IO path no longer available\n");
return -EINVAL;[root@localhost linux]# modprobe null_blk
[ 296.336473] g_home_node is -1 [ 296.336474] nr_online_nodes is 1 [ 296.336514] NUMA_NO_NODE is -1 [ 296.336558] null_blk: invalid home_node value [ 296.338825] null: module loaded
[root@localhost linux]# numactl --hardware
available: 1 nodes (0)
node 0 cpus: 0 1 2 3
node 0 size: 828 MB
node 0 free: 451 MB
node distances:
node 0
0: 10
Fortunately, and also unexpectedly to me, I was able to fix the issue just by casting nr_online_nodes as an int.
+ if (g_home_node >= (int)nr_online_nodes) {
+ pr_err("null_blk: invalid home_node value\n");
+ g_home_node = NUMA_NO_NODE;
+ }
+
Would you like me to send in a v2 for this?
Thanks.
Quoted 13 lines · Jens Axboe
Quoted 5 lines · John Pittman
At module load, if the selected
home_nodevalue is greater than the available numa nodes, the system will crash in__alloc_pages_nodemask()due to a bad paging request. Prevent this user error crash by detecting the bad value, logging an error, and settingg_home_nodeback to the default ofNUMA_NO_NODE.Applied, thanks.
--
Jens Axboe
Jens Axboe
maintainerQuoted 43 lines · John Pittman
Hi Jens, I got some unexpected results with this patch this morning. When loading
null_blkwith no arguments, I got the invalidhome_nodevalue error message. I did some debug and found that the values seemed fine:drivers/block/null_blk_main.c +9
-0+pr_err ("g_home_node is %d" , g_home_node); +pr_err ("nr_online_nodes is %d" , nr_online_nodes); +pr_err ("NUMA_NO_NODE is %d" ,NUMA_NO_NODE ); + +if (g_home_node >= nr_online_nodes) { +pr_err ("null_blk: invalid home_node value\n" ); + g_home_node =NUMA_NO_NODE ; + } +if (g_queue_mode ==NULL_Q_RQ ) {pr_err ("null_blk: legacy IO path no longer available\n" );return -EINVAL ;[root@localhost linux]# modprobe
null_blk[ 296.336473] g_home_node is -1 [ 296.336474] nr_online_nodes is 1 [ 296.336514] NUMA_NO_NODE is -1 [ 296.336558] null_blk: invalid home_node value [ 296.338825] null: module loaded[root@localhost linux]# numactl --hardware
available: 1 nodes (0)
node 0 cpus: 0 1 2 3
node 0 size: 828 MB
node 0 free: 451 MB
node distances:
node 0
0: 10Fortunately, and also unexpectedly to me, I was able to fix the issue just by casting
nr_online_nodesas an int.drivers/block/null_blk_main.c +5
-0+if (g_home_node >= (int )nr_online_nodes) { +pr_err ("null_blk: invalid home_node value\n" ); + g_home_node =NUMA_NO_NODE ; + } +
Quoted 1 line
Would you like me to send in a v2 for this?
Well, I already added it... I'll just edit it. But I think we should make it:
if (g_home_node != NUMA_NO_NODE && g_home_node >= nr_online_nodes)
instead.
Signature · 1 line
Jens Axboe
Yep, yours works better. :) Thanks a lot Jens.
Quoted 57 lines · Jens Axboe
Quoted 43 lines · John Pittman
Hi Jens, I got some unexpected results with this patch this morning. When loading
null_blkwith no arguments, I got the invalidhome_nodevalue error message. I did some debug and found that the values seemed fine:drivers/block/null_blk_main.c +9
-0+pr_err ("g_home_node is %d" , g_home_node); +pr_err ("nr_online_nodes is %d" , nr_online_nodes); +pr_err ("NUMA_NO_NODE is %d" ,NUMA_NO_NODE ); + +if (g_home_node >= nr_online_nodes) { +pr_err ("null_blk: invalid home_node value\n" ); + g_home_node =NUMA_NO_NODE ; + } +if (g_queue_mode ==NULL_Q_RQ ) {pr_err ("null_blk: legacy IO path no longer available\n" );return -EINVAL ;[root@localhost linux]# modprobe
null_blk[ 296.336473] g_home_node is -1 [ 296.336474] nr_online_nodes is 1 [ 296.336514] NUMA_NO_NODE is -1 [ 296.336558] null_blk: invalid home_node value [ 296.338825] null: module loaded[root@localhost linux]# numactl --hardware
available: 1 nodes (0)
node 0 cpus: 0 1 2 3
node 0 size: 828 MB
node 0 free: 451 MB
node distances:
node 0
0: 10Fortunately, and also unexpectedly to me, I was able to fix the issue just by casting
nr_online_nodesas an int.drivers/block/null_blk_main.c +5
-0+if (g_home_node >= (int )nr_online_nodes) { +pr_err ("null_blk: invalid home_node value\n" ); + g_home_node =NUMA_NO_NODE ; + } +Quoted 1 line
Would you like me to send in a v2 for this?
Well, I already added it... I'll just edit it. But I think we should make it:
if (
g_home_node!=NUMA_NO_NODE&&g_home_node>=nr_online_nodes)instead.
--
Jens Axboe