crypto: iaa - Account for cpu-less numa nodes
Subsystems (3)
PATCH 1/1 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.
--- drivers/crypto/intel/iaa/iaa_crypto_main.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/crypto/intel/iaa/iaa_crypto_main.c +11 -3
@@ -1017,12 +1017,17 @@ static void rebalance_wq_table(void)return ; } -for_each_online_node (node) { +for_each_node_with_cpus (node) { node_cpus =cpumask_of_node (node);for (cpu =0 ; cpu < nr_cpus_per_node; cpu++) {int node_cpu =cpumask_nth (cpu, node_cpus); +if (WARN_ON (node_cpu >= nr_cpu_ids)) { +pr_debug ("node_cpu %d doesn't exist!\n" , node_cpu); +return ; + } +if ((cpu % cpus_per_iaa) ==0 ) iaa++;
@@ -2095,10 +2100,13 @@ static struct idxd_device_driver iaa_crypto_driver = {static int __init iaa_crypto_init_module (void ) {int ret =0 ; +int node; nr_cpus =num_online_cpus (); - nr_nodes =num_online_nodes (); - nr_cpus_per_node = nr_cpus / nr_nodes; +for_each_node_with_cpus (node) + nr_nodes++; +if (nr_nodes) + nr_cpus_per_node = nr_cpus / nr_nodes;if (crypto_has_comp ("deflate-generic" ,0 ,0 )) deflate_generic_tfm =crypto_alloc_comp ("deflate-generic" ,0 ,0 );
Signature · 1 line
2.34.1
Hi--
Quoted 43 lines · Tom Zanussi
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]>--- drivers/crypto/intel/iaa/iaa_crypto_main.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)drivers/crypto/intel/iaa/iaa_crypto_main.c +6
-1@@ -1017,12 +1017,17 @@ static void rebalance_wq_table(void)return ; } -for_each_online_node (node) { +for_each_node_with_cpus (node) { node_cpus =cpumask_of_node (node);for (cpu =0 ; cpu < nr_cpus_per_node; cpu++) {int node_cpu =cpumask_nth (cpu, node_cpus); +if (WARN_ON (node_cpu >= nr_cpu_ids)) { +pr_debug ("node_cpu %d doesn't exist!\n" , node_cpu); +return ; + } +if ((cpu % cpus_per_iaa) ==0 ) iaa++;@@ -2095,10 +2100,13 @@ static struct idxd_device_driver iaa_crypto_driver = {static int __init iaa_crypto_init_module (void ) {
drivers/crypto/intel/iaa/iaa_crypto_main.c static struct idxd_device_driver iaa_crypto_driver = { · line 2109
Quoted 10 lines
drivers/crypto/intel/iaa/iaa_crypto_main.c +5
-2int ret =0 ; +int node; nr_cpus =num_online_cpus (); - nr_nodes =num_online_nodes (); - nr_cpus_per_node = nr_cpus / nr_nodes; +for_each_node_with_cpus (node) + nr_nodes++; +if (nr_nodes) + nr_cpus_per_node = nr_cpus / nr_nodes;
If nr_nodes == 0, nr_cpus_per_node is not initialized here. Is it initialized somewhere else, or just not used if nr_nodes is 0?
Quoted 3 lines
drivers/crypto/intel/iaa/iaa_crypto_main.c +0
-0if (crypto_has_comp ("deflate-generic" ,0 ,0 )) deflate_generic_tfm =crypto_alloc_comp ("deflate-generic" ,0 ,0 );
Signature · 1 line
#Randy
Hi Randy,
Quoted 57 lines · Randy Dunlap
Hi--
Quoted 54 lines · Tom Zanussi
In some configurations e.g. systems with CXL, a numa node can have 0
cpus andcpumask_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]>---
drivers/crypto/intel/iaa/iaa_crypto_main.c | 14 +++++++++++---1 file changed, 11 insertions(+), 3 deletions(-)drivers/crypto/intel/iaa/iaa_crypto_main.c +0
-0@@ -1017,12 +1017,17 @@ static void rebalance_wq_table(void) return; }
- for_each_online_node(node) {
+ for_each_node_with_cpus(node) {
node_cpus =cpumask_of_node(node);
for (cpu = 0; cpu <nr_cpus_per_node; cpu++) { intnode_cpu=cpumask_nth(cpu, node_cpus);
+ if (WARN_ON(node_cpu >= nr_cpu_ids)) { + pr_debug("node_cpu %d doesn't exist!\n",node_cpu);
+ return;
+ }
+
if ((cpu %cpus_per_iaa) == 0) iaa++;drivers/crypto/intel/iaa/iaa_crypto_main.c +1
-0@@ -2095,10 +2100,13 @@ static struct idxd_device_driver iaa_crypto_driver = { static int __init iaa_crypto_init_module(void) { int ret = 0; + int node;
nr_cpus =num_online_cpus();
- nr_nodes =num_online_nodes();
Quoted 9 lines
Quoted 5 lines
- nr_cpus_per_node =
nr_cpus/nr_nodes; + for_each_node_with_cpus(node)
+ nr_nodes++;
+ if (nr_nodes)
+ nr_cpus_per_node =nr_cpus/nr_nodes;If
nr_nodes== 0,nr_cpus_per_nodeis not initialized here. Is it initialized somewhere else, or just not used ifnr_nodesis 0?
nr_cpus_per_node is initialized to 0 elsewhere (as a static global).
It seems to me nr_nodes should always be at least 1. From my testing with !CONFIG_NUMA, nr_nodes is set to 1 in that case; not sure how you can get actually get nr_nodes == 0 if you have any cpus working. The check is there to avoid dividing by 0 but maybe the right thing to is BUG_ON(!nr_nodes) and return an error, and remove that check...
Thanks,
Tom
Quoted 5 lines
Quoted 4 lines
if (crypto_has_comp("deflate-generic", 0, 0))deflate_generic_tfm=crypto_alloc_comp("deflate- generic", 0, 0);
Signature · 1 line
Tom Zanussi <[email protected]>
Quoted 70 lines · Tom Zanussi
Hi Randy,
Quoted 57 lines · Randy Dunlap
Hi--
Quoted 54 lines · Tom Zanussi
In some configurations e.g. systems with CXL, a numa node can have 0
cpus andcpumask_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]>---
drivers/crypto/intel/iaa/iaa_crypto_main.c | 14 +++++++++++---1 file changed, 11 insertions(+), 3 deletions(-)drivers/crypto/intel/iaa/iaa_crypto_main.c +0
-0@@ -1017,12 +1017,17 @@ static void rebalance_wq_table(void) return; }
- for_each_online_node(node) {
+ for_each_node_with_cpus(node) {
node_cpus =cpumask_of_node(node);
for (cpu = 0; cpu <nr_cpus_per_node; cpu++) { intnode_cpu=cpumask_nth(cpu, node_cpus);
+ if (WARN_ON(node_cpu >= nr_cpu_ids)) { + pr_debug("node_cpu %d doesn't exist!\n",node_cpu);
+ return;
+ }
+
if ((cpu %cpus_per_iaa) == 0) iaa++;drivers/crypto/intel/iaa/iaa_crypto_main.c +1
-0@@ -2095,10 +2100,13 @@ static struct idxd_device_driver iaa_crypto_driver = { static int __init iaa_crypto_init_module(void) { int ret = 0; + int node;
nr_cpus =num_online_cpus();
- nr_nodes =num_online_nodes();Quoted 9 lines
Quoted 5 lines
- nr_cpus_per_node =
nr_cpus/nr_nodes; + for_each_node_with_cpus(node)
+ nr_nodes++;
+ if (nr_nodes)
+ nr_cpus_per_node =nr_cpus/nr_nodes;If
nr_nodes== 0,nr_cpus_per_nodeis not initialized here. Is it initialized somewhere else, or just not used ifnr_nodesis 0?
Quoted 7 lines
nr_cpus_per_nodeis initialized to 0 elsewhere (as a static global).It seems to me
nr_nodesshould always be at least 1. From my testing with !CONFIG_NUMA,nr_nodesis set to 1 in that case; not sure how you can get actually getnr_nodes== 0 if you have any cpus working. The check is there to avoid dividing by 0 but maybe the right thing to isBUG_ON(!nr_nodes)and return an error, and remove that check...
I think it's OK as is then.
and I hope that we never see the WARN_ON() up above. :)
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
if (crypto_has_comp("deflate-generic", 0, 0))deflate_generic_tfm=crypto_alloc_comp("deflate- generic", 0, 0);
Thanks.
Signature · 1 line
#Randy
Herbert Xu
maintainerQuoted 8 lines · Tom Zanussi
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.
Quoted 8 lines
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]>--- drivers/crypto/intel/iaa/iaa_crypto_main.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
Patch applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt