Skip to contentSkip to conversation

perf/core: Fix lock inversion between perf,trace,cpuhp

tip:perf/urgent Peter Zijlstra 4 participants 4 messages Jan 24, 2018 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 22 lines · tip-bot for Peter Zijlstra
Commit-ID:  25695067c32e34047b5490436a90af507fda1c2e
Gitweb:     https://git.kernel.org/tip/25695067c32e34047b5490436a90af507fda1c2e
Author:     Peter Zijlstra <[email protected]>
AuthorDate: Tue, 9 Jan 2018 13:10:30 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 24 Jan 2018 10:07:23 +0100

perf/core: Fix lock inversion between perf,trace,cpuhp

Lockdep gifted us with noticing the following race:

        perf_trace_init()
          perf_trace_event_init()
            perf_trace_event_reg()
              tp_event->class->reg() := tracepoint_probe_register
                  trace_point_add_func()

          perf_event_init_cpu()

        perf_event_task_disable()
          mutex_lock(&current->perf_event_mutex)
Quoted 9 lines
        do_exit()
          task_work_run()
            __fput()
              perf_release()
                perf_event_release_kernel()
                  free_event()
                    _free_event()
                      event->destroy() := perf_trace_destroy

You seem to have lost part of the Changelog, mine looks like:

perf_trace_init()
#0 mutex_lock(&event_mutex)

          perf_trace_event_init()
            perf_trace_event_reg()
              tp_event->class->reg() := tracepoint_probe_register

#1 mutex_lock(&tracepoints_mutex)
trace_point_add_func()
#2 static_key_enable()

#2 do_cpu_up()
perf_event_init_cpu()
#3 mutex_lock(&pmus_lock)
#4 mutex_lock(&ctx->mutex)

        perf_event_task_disable()
          mutex_lock(&current->perf_event_mutex)

#4 ctx = perf_event_ctx_lock()
#5 perf_event_for_each_child()

        do_exit()
          task_work_run()
            __fput()
              perf_release()
                perf_event_release_kernel()
#4                mutex_lock(&ctx->mutex)
#5                mutex_lock(&event->child_mutex)
                  free_event()
                    _free_event()
                      event->destroy() := perf_trace_destroy

#0 mutex_lock(&event_mutex);

Which shows an actual deadlock.

#2 lore raw
Quoted 67 lines · Peter Zijlstra
Quoted 22 lines · tip-bot for Peter Zijlstra
Commit-ID:  25695067c32e34047b5490436a90af507fda1c2e
Gitweb:     https://git.kernel.org/tip/25695067c32e34047b5490436a90af507fda1c2e
Author:     Peter Zijlstra <[email protected]>
AuthorDate: Tue, 9 Jan 2018 13:10:30 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 24 Jan 2018 10:07:23 +0100

perf/core: Fix lock inversion between perf,trace,cpuhp

Lockdep gifted us with noticing the following race:

        perf_trace_init()
          perf_trace_event_init()
            perf_trace_event_reg()
              tp_event->class->reg() := tracepoint_probe_register
                  trace_point_add_func()

          perf_event_init_cpu()

        perf_event_task_disable()
          mutex_lock(&current->perf_event_mutex)
Quoted 9 lines
        do_exit()
          task_work_run()
            __fput()
              perf_release()
                perf_event_release_kernel()
                  free_event()
                    _free_event()
                      event->destroy() := perf_trace_destroy

You seem to have lost part of the Changelog, mine looks like:

perf_trace_init()
#0 mutex_lock(&event_mutex)

          perf_trace_event_init()
            perf_trace_event_reg()
              tp_event->class->reg() := tracepoint_probe_register

#1 mutex_lock(&tracepoints_mutex)
trace_point_add_func()
#2 static_key_enable()

#2 do_cpu_up()
perf_event_init_cpu()
#3 mutex_lock(&pmus_lock)
#4 mutex_lock(&ctx->mutex)

        perf_event_task_disable()
          mutex_lock(&current->perf_event_mutex)

#4 ctx = perf_event_ctx_lock()
#5 perf_event_for_each_child()

        do_exit()
          task_work_run()
            __fput()
              perf_release()
                perf_event_release_kernel()
#4                mutex_lock(&ctx->mutex)
#5                mutex_lock(&event->child_mutex)
                  free_event()
                    _free_event()
                      event->destroy() := perf_trace_destroy
Quoted 5 lines

#0 mutex_lock(&event_mutex);

Which shows an actual deadlock.

Oh, the '#' was probably interpreted as a comment when I applied it ...

Thanks,

Ingo

#3 lore raw
Quoted 2 lines · Ingo Molnar

Oh, the '#' was probably interpreted as a comment when I applied it ...

Indeed. That's a subtle gotcha when you cut-and-paste things into the editor when editing a commit message (including the "git rebase -i" or "git commit --amend" kind of editing).

If you just apply it as an email, the hash-marks at the beginning of lines are not seen as comments - it's literally just the editing part that uses them as comments.

I'm afraid this isn't really a git "bug". But it _is_ subtle and unlucky.

Note that only a hash-mark in the first column is seen as a comment (unlike, say, shell programming), so you can avoid it with spacing. If you quote code with #ifdef etc, indent it.

Maybe git should have used a different comment scheme, but I have to admit that I think this is the first time I've heard of this issue causing problems in practice. I'm sure it's triggered before, and nobody has noticed (or I wasn't on the cc).

So the '#' thing _normally_ works, but yes, it can cause issues.

Linus

#4 lore raw
Quoted 4 lines · On Wed, 24 Jan 2018 08:57:10 -0800 Linus Torvalds…

Maybe git should have used a different comment scheme, but I have to admit that I think this is the first time I've heard of this issue causing problems in practice. I'm sure it's triggered before, and nobody has noticed (or I wasn't on the cc).

It does happen a bit in practice. It's nailed me a few times. I just consider it as the way git works and didn't complain.

Quoted 2 lines

So the '#' thing _normally_ works, but yes, it can cause issues.

I just brought this up here:

http://lkml.kernel.org/r/[email protected]

And someone replied with a pointer to:

https://github.com/git/git/blob/master/Documentation/RelNotes/2.0.0.txt

suggesting

git config commit.cleanup scissors

Where git looks for:

# ------------------------ >8 ------------------------

and does not delete comments before it. But this could play havoc when doing squash though.

-- Steve