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]
Date:   Thu, 10 Dec 2020 15:12:25 +0530
From:   Viresh Kumar <viresh.kumar@...aro.org>
To:     Ionela Voinescu <ionela.voinescu@....com>,
        Catalin Marinas <catalin.marinas@....com>,
        Will Deacon <will@...nel.org>
Cc:     Viresh Kumar <viresh.kumar@...aro.org>,
        Vincent Guittot <vincent.guittot@...aro.org>,
        linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org
Subject: [PATCH] arm64: topology: Avoid the static_branch_{enable|disable} dance

Avoid the static_branch_enable() and static_branch_disable() dance by
redoing the code in a different way. We will be fully invariant here
only if amu_fie_cpus is set with all present CPUs, use that instead of
yet another call to topology_scale_freq_invariant().

This also avoids running rest of the routine if we enabled the static
branch, followed by a disable.

Also make the first call to topology_scale_freq_invariant() just when we
need it, instead of at the top of the routine. This makes it further
clear on why we need it, i.e. just around enabling AMUs use here.

Signed-off-by: Viresh Kumar <viresh.kumar@...aro.org>
---
 arch/arm64/kernel/topology.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c
index 7f7d8de325b6..6dedc6ee91cf 100644
--- a/arch/arm64/kernel/topology.c
+++ b/arch/arm64/kernel/topology.c
@@ -221,7 +221,7 @@ static DEFINE_STATIC_KEY_FALSE(amu_fie_key);
 
 static int __init init_amu_fie(void)
 {
-	bool invariance_status = topology_scale_freq_invariant();
+	bool invariance_status;
 	cpumask_var_t valid_cpus;
 	int ret = 0;
 	int cpu;
@@ -255,18 +255,15 @@ static int __init init_amu_fie(void)
 	    cpumask_equal(valid_cpus, cpu_present_mask))
 		cpumask_copy(amu_fie_cpus, cpu_present_mask);
 
-	if (!cpumask_empty(amu_fie_cpus)) {
-		pr_info("CPUs[%*pbl]: counters will be used for FIE.",
-			cpumask_pr_args(amu_fie_cpus));
-		static_branch_enable(&amu_fie_key);
-	}
+	/* Disallow partial use of counters for frequency invariance */
+	if (!cpumask_equal(amu_fie_cpus, cpu_present_mask))
+		goto free_valid_mask;
 
-	/*
-	 * If the system is not fully invariant after AMU init, disable
-	 * partial use of counters for frequency invariance.
-	 */
-	if (!topology_scale_freq_invariant())
-		static_branch_disable(&amu_fie_key);
+	pr_info("CPUs[%*pbl]: counters will be used for FIE.",
+		cpumask_pr_args(amu_fie_cpus));
+
+	invariance_status = topology_scale_freq_invariant();
+	static_branch_enable(&amu_fie_key);
 
 	/*
 	 * Task scheduler behavior depends on frequency invariance support,
-- 
2.25.0.rc1.19.g042ed3e048af

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ