Message ID | 00e3eea06f5dde61734a53af797b190692060aab.camel@linux.intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-11690-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp1092326dyb; Tue, 26 Dec 2023 12:54:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IEhaQoMB2ekfxPES2ArSvgAwvOQALEYTHfD2+krL4rLtBvhKv8MhEB2AI1U6hWx6CMKqkpL X-Received: by 2002:a05:6a20:12c8:b0:195:fd8e:5a9d with SMTP id v8-20020a056a2012c800b00195fd8e5a9dmr1226121pzg.73.1703624067833; Tue, 26 Dec 2023 12:54:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703624067; cv=none; d=google.com; s=arc-20160816; b=fctp0nVyVYSGcDC+BXdvpob7UErf7NRTb/N8E8eJz4SFO1wWisINo+mQS1MK6QQXMs l33ecqFyym47/U+nOZ9nvoRMi6N+nDrabtWC/vqtO243K+2WxRQ80As+oTmKsesGhpMw uLcqq+H9k1UjbvrB8TPBjiMlHB2Zd25jkKuCDQ4rsA7ol4GD/jmtmDMJEOu9fIGt9dQS 0w76q4NLrpsdQGCh8Ym1pN9GyuUQYLse1r6qNHN/2mUEs+z5fzO5ZXsk2Evgb+en4cjW bggOo0Rwj/UI00gZQW4FFboDwGgwO8ZLXayGE63hMYjzhWRvxdbGH5E9/Syrt22Ds9E9 vE9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:content-transfer-encoding:date:cc:to:from:subject :message-id:dkim-signature; bh=r3bX8jTF52dFOj43CDQJjUHpbslYjf0Ikd2l6ftwfk8=; fh=tqgbunYDRCfJtAZ+DHAxIDdAWYVHSFjHvMTOp69KwYg=; b=cWHLBjlvR5TmcnWHXy4oM6K3Wy0wOFQASA1vtvgOtlVO1bRhZl+G0TS3b213/OhLnE 9I7+ZYKVx5nqu3tWh0/B4RsN5pU9yQIrOR6qTvitH8XbBOBfJwC5M/PeNyIDOJRSyfEz uYzB1qg8iy2nxFDYncZXLW4Cro9hRQnmrsuSD58ETE7Jci8UUwe534a6U5wCF7cCBFDH iE6s1q+m8pH7zGBWULXalu1xgfDAovfo0AcpdL5zwQMwvEsCBVF4nieEoybJT59jukcs Im/gLOUM4pnrCyoYQR94KOO+hPFsOD6zzwED1eHJVrEN60NpSbGUV0g8AHQpyUnx364C /E4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=V7iy9utS; spf=pass (google.com: domain of linux-kernel+bounces-11690-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11690-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id o21-20020a17090aac1500b0028c46664d88si5078552pjq.82.2023.12.26.12.54.27 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Dec 2023 12:54:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-11690-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=V7iy9utS; spf=pass (google.com: domain of linux-kernel+bounces-11690-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11690-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 6E7FF282A2E for <ouuuleilei@gmail.com>; Tue, 26 Dec 2023 20:54:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F2CB21078E; Tue, 26 Dec 2023 20:54:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="V7iy9utS" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F9CAEAF2; Tue, 26 Dec 2023 20:54:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1703624049; x=1735160049; h=message-id:subject:from:to:cc:date: content-transfer-encoding:mime-version; bh=6vm3/1J8+0RlhGUApQzpmYZe5Ax8xA/w2zIHtPsoe6A=; b=V7iy9utSXW+GsdVQwa6V9UgsJ7Xpz27eOFY6cG3CDkhNly2XTc/xd3Zq gKM++pCtizEwYC1Z+5HoxcmcdFesucM3QUc0W8cj9k5oXQebEmYlq1SSy 5vuGWnjjZlquEEgbl9X5S6kGlenl0YCdu1oyGSLMr/S+8TWKIlwCqYORA to/5/ZhJaJgGqaCdC2g7i0XLq/NTMINjzppQZ2E6UP3HFpvOkD4lrq+br nuuyN3tq8LeI9KsfWdkwEyaYdNsALooC7UJ5NUpjaEjr1M3qQuyVn1Fby YAXAlQIWuUEQ5wEAzUJO/9Zv8cXbUpNYAF3f+s6ZxLlfc8yWmglK8gmvA w==; X-IronPort-AV: E=McAfee;i="6600,9927,10935"; a="399168939" X-IronPort-AV: E=Sophos;i="6.04,307,1695711600"; d="scan'208";a="399168939" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Dec 2023 12:54:08 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,307,1695711600"; d="scan'208";a="20102656" Received: from smorga5x-mobl.amr.corp.intel.com ([10.212.113.189]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Dec 2023 12:53:27 -0800 Message-ID: <00e3eea06f5dde61734a53af797b190692060aab.camel@linux.intel.com> Subject: [PATCH] crypto: iaa - Account for cpu-less numa nodes From: Tom Zanussi <tom.zanussi@linux.intel.com> To: herbert@gondor.apana.org.au, davem@davemloft.net, fenghua.yu@intel.com Cc: rex.zhang@intel.com, dave.jiang@intel.com, tony.luck@intel.com, linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, dmaengine@vger.kernel.org Date: Tue, 26 Dec 2023 14:53:26 -0600 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4-0ubuntu2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786379310777383829 X-GMAIL-MSGID: 1786379310777383829 |
Series |
crypto: iaa - Account for cpu-less numa nodes
|
|
Commit Message
Tom Zanussi
Dec. 26, 2023, 8:53 p.m. UTC
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>
---
drivers/crypto/intel/iaa/iaa_crypto_main.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
Comments
Hi-- On 12/26/23 12:53, Tom Zanussi wrote: > 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> > --- > drivers/crypto/intel/iaa/iaa_crypto_main.c | 14 +++++++++++--- > 1 file changed, 11 insertions(+), 3 deletions(-) > > diff --git a/drivers/crypto/intel/iaa/iaa_crypto_main.c b/drivers/crypto/intel/iaa/iaa_crypto_main.c > index 5093361b0107..782157a74043 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,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 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? > > if (crypto_has_comp("deflate-generic", 0, 0)) > deflate_generic_tfm = crypto_alloc_comp("deflate-generic", 0, 0);
Hi Randy, On Tue, 2023-12-26 at 13:09 -0800, Randy Dunlap wrote: > Hi-- > > On 12/26/23 12:53, Tom Zanussi wrote: > > 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> > > --- > > drivers/crypto/intel/iaa/iaa_crypto_main.c | 14 +++++++++++--- > > 1 file changed, 11 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/crypto/intel/iaa/iaa_crypto_main.c > > b/drivers/crypto/intel/iaa/iaa_crypto_main.c > > index 5093361b0107..782157a74043 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,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 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? > 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 > > > > if (crypto_has_comp("deflate-generic", 0, 0)) > > deflate_generic_tfm = crypto_alloc_comp("deflate- > > generic", 0, 0); >
On 12/26/23 14:04, Tom Zanussi wrote: > Hi Randy, > > On Tue, 2023-12-26 at 13:09 -0800, Randy Dunlap wrote: >> Hi-- >> >> On 12/26/23 12:53, Tom Zanussi wrote: >>> 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> >>> --- >>> drivers/crypto/intel/iaa/iaa_crypto_main.c | 14 +++++++++++--- >>> 1 file changed, 11 insertions(+), 3 deletions(-) >>> >>> diff --git a/drivers/crypto/intel/iaa/iaa_crypto_main.c >>> b/drivers/crypto/intel/iaa/iaa_crypto_main.c >>> index 5093361b0107..782157a74043 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,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 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? >> > > 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... I think it's OK as is then. and I hope that we never see the WARN_ON() up above. :) >>> >>> if (crypto_has_comp("deflate-generic", 0, 0)) >>> deflate_generic_tfm = crypto_alloc_comp("deflate- >>> generic", 0, 0); >> > Thanks.
On Tue, Dec 26, 2023 at 02:53:26PM -0600, Tom Zanussi wrote: > 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> > --- > drivers/crypto/intel/iaa/iaa_crypto_main.c | 14 +++++++++++--- > 1 file changed, 11 insertions(+), 3 deletions(-) Patch applied. Thanks.
diff --git a/drivers/crypto/intel/iaa/iaa_crypto_main.c b/drivers/crypto/intel/iaa/iaa_crypto_main.c index 5093361b0107..782157a74043 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,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);