Skip to contentSkip to conversation

null_blk: prevent crash from bad home_node value

PATCH Applied John Pittman 2 participants 5 messages Apr 5, 2019 – Apr 6, 2019 Block layer

lore
Share & tools
lore
#0 lore raw

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
index 417a9f15c116..c7fb7a133c8d 100644
@@ -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
maintainer Applied
#1 lore raw
Quoted 5 lines · John Pittman

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.

Applied, thanks.

Signature · 1 line
Jens Axboe
#2 lore raw

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_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.

Applied, thanks.

--
Jens Axboe

maintainer
#3 lore raw
Quoted 43 lines · John Pittman

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:

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: 10

Fortunately, and also unexpectedly to me, I was able to fix the issue just by casting nr_online_nodes as 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
#4 lore raw

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_blk with no arguments, I got the invalid home_node value 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: 10

Fortunately, and also unexpectedly to me, I was able to fix the issue just by casting nr_online_nodes as 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