2022-03-31 04:19:10

by Rei Yamamoto

[permalink] [raw]
Subject: [PATCH v4] irq: consider cpus on nodes are unbalanced

If cpus on a node are offline at boot time, there are
difference in the number of nodes between when building affinity
masks for present cpus and when building affinity masks for possible
cpus. This patch fixes a problem caused by the difference of the
number of nodes:

- The routine of "numvecs <= nodes" condition can overwrite bits of
masks for present cpus in building masks for possible cpus. Fix this
problem by making CPU bits, which is not target, not changing.

Signed-off-by: Rei Yamamoto <[email protected]>
Reviewed-by: Ming Lei <[email protected]>
---
kernel/irq/affinity.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/irq/affinity.c b/kernel/irq/affinity.c
index f7ff8919dc9b..d2d01565d2ec 100644
--- a/kernel/irq/affinity.c
+++ b/kernel/irq/affinity.c
@@ -269,8 +269,9 @@ static int __irq_build_affinity_masks(unsigned int startvec,
*/
if (numvecs <= nodes) {
for_each_node_mask(n, nodemsk) {
+ cpumask_and(nmsk, cpu_mask, node_to_cpumask[n]);
cpumask_or(&masks[curvec].mask, &masks[curvec].mask,
- node_to_cpumask[n]);
+ nmsk);
if (++curvec == last_affv)
curvec = firstvec;
}
--
2.27.0


Subject: [tip: irq/urgent] genirq/affinity: Consider that CPUs on nodes can be unbalanced

The following commit has been merged into the irq/urgent branch of tip:

Commit-ID: 08d835dff916bfe8f45acc7b92c7af6c4081c8a7
Gitweb: https://git.kernel.org/tip/08d835dff916bfe8f45acc7b92c7af6c4081c8a7
Author: Rei Yamamoto <[email protected]>
AuthorDate: Thu, 31 Mar 2022 09:33:09 +09:00
Committer: Thomas Gleixner <[email protected]>
CommitterDate: Mon, 11 Apr 2022 09:58:03 +02:00

genirq/affinity: Consider that CPUs on nodes can be unbalanced

If CPUs on a node are offline at boot time, the number of nodes is
different when building affinity masks for present cpus and when building
affinity masks for possible cpus. This causes the following problem:

In the case that the number of vectors is less than the number of nodes
there are cases where bits of masks for present cpus are overwritten when
building masks for possible cpus.

Fix this by excluding CPUs, which are not part of the current build mask
(present/possible).

[ tglx: Massaged changelog and added comment ]

Fixes: b82592199032 ("genirq/affinity: Spread IRQs to all available NUMA nodes")
Signed-off-by: Rei Yamamoto <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Reviewed-by: Ming Lei <[email protected]>
Cc: [email protected]
Link: https://lore.kernel.org/r/[email protected]
---
kernel/irq/affinity.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/irq/affinity.c b/kernel/irq/affinity.c
index f7ff891..fdf1704 100644
--- a/kernel/irq/affinity.c
+++ b/kernel/irq/affinity.c
@@ -269,8 +269,9 @@ static int __irq_build_affinity_masks(unsigned int startvec,
*/
if (numvecs <= nodes) {
for_each_node_mask(n, nodemsk) {
- cpumask_or(&masks[curvec].mask, &masks[curvec].mask,
- node_to_cpumask[n]);
+ /* Ensure that only CPUs which are in both masks are set */
+ cpumask_and(nmsk, cpu_mask, node_to_cpumask[n]);
+ cpumask_or(&masks[curvec].mask, &masks[curvec].mask, nmsk);
if (++curvec == last_affv)
curvec = firstvec;
}