Skip to content

Commit b891063

Browse files
tzanussiherbertx
authored andcommitted
crypto: iaa - Account for cpu-less numa nodes
In some configurations e.g. systems with CXL, a numa node can have 0 cpus and cpumask_nth() will return a cpu value that doesn't exist, which will result in an attempt to add an entry to the wq table at a bad index. To fix this, when iterating the cpus for a node, skip any node that doesn't have cpus. Also, as a precaution, add a warning and bail if cpumask_nth() returns a nonexistent cpu. Reported-by: Zhang, Rex <[email protected]> Signed-off-by: Tom Zanussi <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 744e188 commit b891063

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

drivers/crypto/intel/iaa/iaa_crypto_main.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,12 +1017,17 @@ static void rebalance_wq_table(void)
10171017
return;
10181018
}
10191019

1020-
for_each_online_node(node) {
1020+
for_each_node_with_cpus(node) {
10211021
node_cpus = cpumask_of_node(node);
10221022

10231023
for (cpu = 0; cpu < nr_cpus_per_node; cpu++) {
10241024
int node_cpu = cpumask_nth(cpu, node_cpus);
10251025

1026+
if (WARN_ON(node_cpu >= nr_cpu_ids)) {
1027+
pr_debug("node_cpu %d doesn't exist!\n", node_cpu);
1028+
return;
1029+
}
1030+
10261031
if ((cpu % cpus_per_iaa) == 0)
10271032
iaa++;
10281033

@@ -2095,9 +2100,15 @@ static struct idxd_device_driver iaa_crypto_driver = {
20952100
static int __init iaa_crypto_init_module(void)
20962101
{
20972102
int ret = 0;
2103+
int node;
20982104

20992105
nr_cpus = num_online_cpus();
2100-
nr_nodes = num_online_nodes();
2106+
for_each_node_with_cpus(node)
2107+
nr_nodes++;
2108+
if (!nr_nodes) {
2109+
pr_err("IAA couldn't find any nodes with cpus\n");
2110+
return -ENODEV;
2111+
}
21012112
nr_cpus_per_node = nr_cpus / nr_nodes;
21022113

21032114
if (crypto_has_comp("deflate-generic", 0, 0))

0 commit comments

Comments
 (0)