From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755643AbbLGQQ2 (ORCPT ); Mon, 7 Dec 2015 11:16:28 -0500 Received: from bombadil.infradead.org ([198.137.202.9]:54035 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932409AbbLGQQY (ORCPT ); Mon, 7 Dec 2015 11:16:24 -0500 Date: Mon, 7 Dec 2015 17:16:19 +0100 From: Peter Zijlstra To: Alexander Shishkin Cc: Ingo Molnar , linux-kernel@vger.kernel.org, vince@deater.net, eranian@google.com, johannes@sipsolutions.net, Arnaldo Carvalho de Melo Subject: Re: [PATCH 4/7] perf: Free aux pages in unmap path Message-ID: <20151207161619.GB6373@twins.programming.kicks-ass.net> References: <1449138762-15194-1-git-send-email-alexander.shishkin@linux.intel.com> <1449138762-15194-5-git-send-email-alexander.shishkin@linux.intel.com> <20151204170206.GI17308@twins.programming.kicks-ass.net> <20151204221723.GR11639@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20151204221723.GR11639@twins.programming.kicks-ass.net> User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 04, 2015 at 11:17:23PM +0100, Peter Zijlstra wrote: > On Fri, Dec 04, 2015 at 06:02:06PM +0100, Peter Zijlstra wrote: > > The only solution I've come up with is: > > > > struct rb_aux *aux = rb->aux; > > > > if (aux && vma->vm_pgoff == aux->pgoff) { > > ctx = perf_event_ctx_lock(event); > > Can't do this at all, see the comment in put_event(). perf_read_group() > accesses user memory (and hence causes faults, which in turn take > mmap_sem) while holding ctx::mutex. > > So neither this, not what you proposed can work. > > Will need moar thinking. So we could try and see if we can get this working: static int __perf_event_stop(void *info) { struct perf_event *event = info; /* IRQs disabled, cannot get scheduled away */ if (event->oncpu == smp_processor_id()) { event->pmu->stop(event); return 0; } return -EAGAIN; } perf_event_stop(struct perf_event *event) { for (;;) { if (READ_ONCE(event->state) != PERF_EVENT_STATE_ACTIVE) break; smp_rmb(); /* if we see ACTIVE, ->oncpu must be set */ if (!cpu_function_call(READ_ONCE(event->oncpu), __perf_event_stop, event)) break; } } That probably wants some WRITE_ONCE() and maybe some memory barriers in event_sched_in() as well, like: WRITE_ONCE(event->oncpu, smp_processor_id()); smp_wmb(); WRITE_ONCE(event->state, PERF_EVENT_STATE_ACTIVE);