From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756752AbbLDWR3 (ORCPT ); Fri, 4 Dec 2015 17:17:29 -0500 Received: from casper.infradead.org ([85.118.1.10]:39898 "EHLO casper.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751341AbbLDWR2 (ORCPT ); Fri, 4 Dec 2015 17:17:28 -0500 Date: Fri, 4 Dec 2015 23:17:23 +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: <20151204221723.GR11639@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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20151204170206.GI17308@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 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. > if (!atomic_dec_and_mutex_lock(&aux->mmap_count, &event->mmap_mutex) { > /* we now hold both ctx::mutex and event::mmap_mutex */ > rb->aux = NULL; > ring_buffer_put(rb); /* aux had a reference */ > _perf_event_stop(event); > ring_buffer_put_aux(aux); /* should be last */ > mutex_unlock(&event->mmap_mutex); > } > mutex_unlock(&ctx->mutex); > } > >