public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] crypto: iaa - Account for cpu-less numa nodes
@ 2023-12-27 20:28 Tom Zanussi
  0 siblings, 0 replies; only message in thread
From: Tom Zanussi @ 2023-12-27 20:28 UTC (permalink / raw)
  To: herbert, davem, fenghua.yu
  Cc: rex.zhang, dave.jiang, tony.luck, rdunlap, linux-kernel,
	linux-crypto, dmaengine

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 <rex.zhang@intel.com>
Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
---
 v2: In iaa_crypto_init_module(), if nr_nodes is 0, print an error message and return.

 drivers/crypto/intel/iaa/iaa_crypto_main.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/intel/iaa/iaa_crypto_main.c b/drivers/crypto/intel/iaa/iaa_crypto_main.c
index 5093361b0107..4ebf1950568a 100644
--- a/drivers/crypto/intel/iaa/iaa_crypto_main.c
+++ b/drivers/crypto/intel/iaa/iaa_crypto_main.c
@@ -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,9 +2100,15 @@ 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();
+	for_each_node_with_cpus(node)
+		nr_nodes++;
+	if (!nr_nodes) {
+		pr_err("IAA couldn't find any nodes with cpus\n");
+		return -ENODEV;
+	}
 	nr_cpus_per_node = nr_cpus / nr_nodes;
 
 	if (crypto_has_comp("deflate-generic", 0, 0))
-- 
2.34.1



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-12-27 20:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-27 20:28 [PATCH v2] crypto: iaa - Account for cpu-less numa nodes Tom Zanussi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox