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: <Y85yadQes4fSwCZm@hirez.programming.kicks-ass.net>
Date:   Mon, 23 Jan 2023 12:41:29 +0100
From:   Peter Zijlstra <peterz@...radead.org>
To:     Tetsuo Handa <penguin-kernel@...ove.sakura.ne.jp>
Cc:     Ingo Molnar <mingo@...hat.com>,
        Arnaldo Carvalho de Melo <acme@...nel.org>,
        Mark Rutland <mark.rutland@....com>,
        Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
        Jiri Olsa <jolsa@...nel.org>,
        Namhyung Kim <namhyung@...nel.org>,
        linux-perf-users@...r.kernel.org,
        LKML <linux-kernel@...r.kernel.org>
Subject: Re: [perf] lockdep warning between cpu_add_remove_lock and
 &dev->mutex.

On Mon, Jan 23, 2023 at 07:39:24PM +0900, Tetsuo Handa wrote:
> Hello.
> 
> I tried to apply below patch, and hit lockdep warning during boot.
> Can you break this dependency?

  cpu_add_remove_lock
    cpu_hotplug_lock
      pmus_lock
        dev->mutex		(pmu_dev_alloc)

vs

  dev->mutex
    cpu_add_remove_lock		(pci_device_probe)


Possibly something like this might do -- I'm not entirely sure it's
fully correct, needs a bit of auditing.

---
diff --git a/kernel/events/core.c b/kernel/events/core.c
index eacc3702654d..d6b2265a9982 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -13570,9 +13570,9 @@ static void perf_event_exit_cpu_context(int cpu)
 {
 	struct perf_cpu_context *cpuctx;
 	struct perf_event_context *ctx;
+	int idx = srcu_read_lock(&pmus_srcu);
 
 	// XXX simplify cpuctx->online
-	mutex_lock(&pmus_lock);
 	cpuctx = per_cpu_ptr(&perf_cpu_context, cpu);
 	ctx = &cpuctx->ctx;
 
@@ -13581,7 +13581,7 @@ static void perf_event_exit_cpu_context(int cpu)
 	cpuctx->online = 0;
 	mutex_unlock(&ctx->mutex);
 	cpumask_clear_cpu(cpu, perf_online_mask);
-	mutex_unlock(&pmus_lock);
+	srcu_read_unlock(&pmus_srcu, idx);
 }
 #else
 
@@ -13593,10 +13594,11 @@ int perf_event_init_cpu(unsigned int cpu)
 {
 	struct perf_cpu_context *cpuctx;
 	struct perf_event_context *ctx;
+	int idx;
 
 	perf_swevent_init_cpu(cpu);
 
-	mutex_lock(&pmus_lock);
+	idx = srcu_read_lock(&pmus_srcu);
 	cpumask_set_cpu(cpu, perf_online_mask);
 	cpuctx = per_cpu_ptr(&perf_cpu_context, cpu);
 	ctx = &cpuctx->ctx;
@@ -13604,7 +13606,7 @@ int perf_event_init_cpu(unsigned int cpu)
 	mutex_lock(&ctx->mutex);
 	cpuctx->online = 1;
 	mutex_unlock(&ctx->mutex);
-	mutex_unlock(&pmus_lock);
+	srcu_read_unlock(&pmus_srcu, idx);
 
 	return 0;
 }

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ