Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933040Ab3D3Pja (ORCPT ); Tue, 30 Apr 2013 11:39:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47599 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932934Ab3D3Pj1 (ORCPT ); Tue, 30 Apr 2013 11:39:27 -0400 Date: Tue, 30 Apr 2013 17:36:53 +0200 From: Jiri Olsa To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Corey Ashford , Frederic Weisbecker , Ingo Molnar , Namhyung Kim , Paul Mackerras , Arnaldo Carvalho de Melo Subject: Re: [PATCHv4] perf: Fix vmalloc ring buffer pages handling Message-ID: <20130430153653.GD12715@krava.brq.redhat.com> References: <1363084030.14933.23.camel@laptop> <20130312135219.GA32001@krava.brq.redhat.com> <1363101972.24558.3.camel@laptop> <20130312153609.GC32001@krava.brq.redhat.com> <1363105490.24558.12.camel@laptop> <20130312170416.GD32001@krava.brq.redhat.com> <20130313111557.GC1064@krava.brq.redhat.com> <20130318190548.GA18920@krava.brq.redhat.com> <1363693618.22553.33.camel@laptop> <20130319143509.GA1128@krava.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20130319143509.GA1128@krava.brq.redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3132 Lines: 100 On Tue, Mar 19, 2013 at 03:35:09PM +0100, Jiri Olsa wrote: > On Tue, Mar 19, 2013 at 12:46:58PM +0100, Peter Zijlstra wrote: > > > > > are you going to include that, or should I repost it? > > > > Ah, please repost (and prettify) it, I'm still very limited in the > > amount of work that I can do :/ > > > > ok, attached Ingo, Peter, could this be pulled in? thanks, jirka > > jirka > > --- > If we allocate perf ring buffer with the size of single (user) > page, we will get memory corruption when releasing itin rb_free_work > function (for CONFIG_PERF_USE_VMALLOC option). > > For single page sized ring buffer the page_order is -1 (because > nr_pages is 0). This needs to be recognized in the rb_free_work > function to release proper amount of pages. > > Adding data_page_nr function that returns number of allocated > data pages. Customizing the rest of the code to use it. > > Reported-by: Jan Stancek > Original-patch-by: Peter Zijlstra > Cc: Corey Ashford > Cc: Frederic Weisbecker > Cc: Ingo Molnar > Cc: Namhyung Kim > Cc: Paul Mackerras > Cc: Peter Zijlstra > Cc: Arnaldo Carvalho de Melo > Signed-off-by: Jiri Olsa > --- > kernel/events/ring_buffer.c | 14 ++++++++++---- > 1 file changed, 10 insertions(+), 4 deletions(-) > > diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c > index 23cb34f..27a1af4 100644 > --- a/kernel/events/ring_buffer.c > +++ b/kernel/events/ring_buffer.c > @@ -312,11 +312,16 @@ void rb_free(struct ring_buffer *rb) > } > > #else > +static int data_page_nr(struct ring_buffer *rb) > +{ > + return rb->nr_pages << page_order(rb); > +} > > struct page * > perf_mmap_to_page(struct ring_buffer *rb, unsigned long pgoff) > { > - if (pgoff > (1UL << page_order(rb))) > + /* The '>' counts in the user page. */ > + if (pgoff > data_page_nr(rb)) > return NULL; > > return vmalloc_to_page((void *)rb->user_page + pgoff * PAGE_SIZE); > @@ -336,10 +341,11 @@ static void rb_free_work(struct work_struct *work) > int i, nr; > > rb = container_of(work, struct ring_buffer, work); > - nr = 1 << page_order(rb); > + nr = data_page_nr(rb); > > base = rb->user_page; > - for (i = 0; i < nr + 1; i++) > + /* The '<=' counts in the user page. */ > + for (i = 0; i <= nr; i++) > perf_mmap_unmark_page(base + (i * PAGE_SIZE)); > > vfree(base); > @@ -373,7 +379,7 @@ struct ring_buffer *rb_alloc(int nr_pages, long watermark, int cpu, int flags) > rb->user_page = all_buf; > rb->data_pages[0] = all_buf + PAGE_SIZE; > rb->page_order = ilog2(nr_pages); > - rb->nr_pages = 1; > + rb->nr_pages = !!nr_pages; > > ring_buffer_init(rb, watermark, flags); > > -- > 1.7.11.7 > -- 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/