Re: deadlock in perf_ioctl

From: Peter Zijlstra
Date: Mon Nov 30 2015 - 06:56:23 EST


On Mon, Nov 30, 2015 at 10:20:49AM +0100, Dmitry Vyukov wrote:
> =============================================
> [ INFO: possible recursive locking detected ]
> 4.4.0-rc1+ #129 Not tainted
> ---------------------------------------------
> a.out/6283 is trying to acquire lock:
> (&ctx->lock){-.....}, at: [<ffffffff815072ce>]
> __perf_event_period+0x8e/0x4b0 kernel/events/core.c:4156
>
> but task is already holding lock:
> (&ctx->lock){-.....}, at: [< inline >] perf_event_period
> kernel/events/core.c:4212
> (&ctx->lock){-.....}, at: [< inline >] _perf_ioctl
> kernel/events/core.c:4266
> (&ctx->lock){-.....}, at: [<ffffffff8152331c>] perf_ioctl+0x7bc/0xcc0
> kernel/events/core.c:4320
>

Indeed so. I suppose the below should fix this, I'll go try in a bit.

---
Subject: perf: Fix PERF_EVENT_IOC_PERIOD deadlock

Dmitry reported a fairly silly recursive lock deadlock for
PERF_EVENT_IOC_PERIOD, fix this by explicitly doing the inactive part of
__perf_event_period() instead of calling that function.

Reported-by: Dmitry Vyukov <dvyukov@xxxxxxxxxx>
Fixes: c7999c6f3fed ("perf: Fix PERF_EVENT_IOC_PERIOD migration race")
Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
---
kernel/events/core.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 36babfd20648..a991e12e4d0d 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -4216,7 +4216,14 @@ static int perf_event_period(struct perf_event *event, u64 __user *arg)
goto retry;
}

- __perf_event_period(&pe);
+ if (event->attr.freq) {
+ event->attr.sample_freq = value;
+ } else {
+ event->attr.sample_period = value;
+ event->hw.sample_period = value;
+ }
+
+ local64_set(&event->hw.period_left, 0);
raw_spin_unlock_irq(&ctx->lock);

return 0;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/