lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240902183609.1683756-3-yury.norov@gmail.com>
Date: Mon,  2 Sep 2024 11:36:06 -0700
From: Yury Norov <yury.norov@...il.com>
To: linux-kernel@...r.kernel.org,
	Christophe JAILLET <christophe.jaillet@...adoo.fr>
Cc: Yury Norov <yury.norov@...il.com>,
	Chen Yu <yu.c.chen@...el.com>,
	Leonardo Bras <leobras@...hat.com>,
	Ingo Molnar <mingo@...hat.com>,
	Peter Zijlstra <peterz@...radead.org>,
	Juri Lelli <juri.lelli@...hat.com>,
	Vincent Guittot <vincent.guittot@...aro.org>,
	Dietmar Eggemann <dietmar.eggemann@....com>,
	Steven Rostedt <rostedt@...dmis.org>,
	Ben Segall <bsegall@...gle.com>,
	Mel Gorman <mgorman@...e.de>,
	Valentin Schneider <vschneid@...hat.com>
Subject: [PATCH v3 2/3] sched/topology: optimize topology_span_sane()

The function may call cpumask_equal with mi == mc, even though the CPUs are
different. In such case, cpumask_equal() would always return true, and we
can proceed to the next iteration immediately.

This happens when topologies re-use the same mask for many CPUs.
The detailed comment is provided by Valentin Schneider.

Reviewed-by: Valentin Schneider <vschneid@...hat.com>
Signed-off-by: Yury Norov <yury.norov@...il.com>
---
 kernel/sched/topology.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
index ffbe3a28d2d4..04a3b3d7b6f4 100644
--- a/kernel/sched/topology.c
+++ b/kernel/sched/topology.c
@@ -2370,6 +2370,19 @@ static bool topology_span_sane(struct sched_domain_topology_level *tl,
 	for_each_cpu_from(cpu, cpu_map) {
 		mi = tl->mask(cpu);
 
+		/*
+		 * Some topology levels (e.g. PKG in default_topology[])
+		 * have a sched_domain_mask_f implementation that reuses
+		 * the same mask for several CPUs (in PKG's case, one mask
+		 * for all CPUs in the same NUMA node).
+		 *
+		 * For such topology levels, repeating cpumask_equal()
+		 * checks is wasteful. Instead, we first check that the
+		 * tl->mask(i) pointers aren't the same.
+		 */
+		if (mi == mc)
+			continue;
+
 		/*
 		 * We should 'and' all those masks with 'cpu_map' to exactly
 		 * match the topology we're about to build, but that can only
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ