Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1287411
| From | Peter Zijlstra <peterz@infradead.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH 4/7] perf: Free aux pages in unmap path |
| Date | 2015-12-09 12:00 +0100 |
| Message-ID | <qDKDv-7j2-1@gated-at.bofh.it> (permalink) |
| References | <qBzsR-3Jm-3@gated-at.bofh.it> <qBzsS-3Jm-31@gated-at.bofh.it> <qC21T-5zk-75@gated-at.bofh.it> <qDJHu-6FW-53@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Wed, Dec 09, 2015 at 11:57:51AM +0200, Alexander Shishkin wrote:
> Peter Zijlstra <peterz@infradead.org> writes:
>
> > Yuck, nasty problem. Also, I think its broken. By not having
> > mmap_mutex around the whole thing, notably rb_free_aux(), you can race
> > against mmap().
> >
> > What seems possible now is that:
> >
> > mmap(aux); // rb->aux_mmap_count == 1
> > munmap(aux)
> > atomic_dec_and_mutex_lock(&rb->aux_mmap_count, &event->mmap_mutex); // == 0
> >
> > mutex_unlock(&event->mmap_mutex);
> >
> > mmap(aux)
> > if (rb_has_aux())
> > atomic_inc(&rb->aux_mmap_count); // == 1
> >
> > rb_free_aux(); // oops!!
>
> Wait, this isn't actually a problem, we can hold mmap_mutex over
> rb_free_aux(), as we actually already do in current code. My patch did
> it wrongly though, but there's really no reason to drop the mutex before
> rb_free_aux().
Well, you had to drop it because you wanted to acquire the ctx::mutex,
but if we drop that requirement, as we must per the other emails, then
this should indeed be possible.
> So if we just hold the mmap_mutex over rb_free_aux(), this won't
> happen, right?
Correct.
> How about something like this to stop the writers:
>
> static int __ring_buffer_output_stop(void *info)
> {
> struct ring_buffer *rb = info;
> struct perf_event *event;
>
> spin_lock(&rb->event_lock);
> list_for_each_entry_rcu(event, &rb->event_list, rb_entry) {
> if (event->state != PERF_EVENT_STATE_ACTIVE)
> continue;
>
> event->pmu->stop(event, PERF_EF_UPDATE);
> }
> spin_unlock(&rb->event_lock);
>
> return 0;
> }
>
> static void perf_event_output_stop(struct perf_event *event)
> {
> struct ring_buffer *rb = event->rb;
>
> lockdep_assert_held(&event->mmap_mutex);
>
> if (event->cpu == -1)
> perf_event_stop(event);
>
> cpu_function_call(event->cpu, __ring_buffer_output_stop, rb);
I'm not sure about the different semantics between event->cpu == -1 and
not, but yes, something along those likes.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 4/7] perf: Free aux pages in unmap path Alexander Shishkin <alexander.shishkin@linux.intel.com> - 2015-12-03 11:40 +0100
Re: [PATCH 4/7] perf: Free aux pages in unmap path Peter Zijlstra <peterz@infradead.org> - 2015-12-04 18:10 +0100
Re: [PATCH 4/7] perf: Free aux pages in unmap path Peter Zijlstra <peterz@infradead.org> - 2015-12-04 23:20 +0100
Re: [PATCH 4/7] perf: Free aux pages in unmap path Peter Zijlstra <peterz@infradead.org> - 2015-12-07 17:20 +0100
Re: [PATCH 4/7] perf: Free aux pages in unmap path Alexander Shishkin <alexander.shishkin@linux.intel.com> - 2015-12-09 11:00 +0100
Re: [PATCH 4/7] perf: Free aux pages in unmap path Peter Zijlstra <peterz@infradead.org> - 2015-12-09 12:00 +0100
Re: [PATCH 4/7] perf: Free aux pages in unmap path Alexander Shishkin <alexander.shishkin@linux.intel.com> - 2015-12-10 12:30 +0100
Re: [PATCH 4/7] perf: Free aux pages in unmap path Alexander Shishkin <alexander.shishkin@linux.intel.com> - 2015-12-10 14:10 +0100
csiph-web