mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: linux-kernel@vger.kernel.org,
	Corey Ashford <cjashfor@linux.vnet.ibm.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Ingo Molnar <mingo@elte.hu>, Namhyung Kim <namhyung@kernel.org>,
	Paul Mackerras <paulus@samba.org>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: Re: [PATCHv4] perf: Fix vmalloc ring buffer pages handling
Date: Tue, 30 Apr 2013 17:36:53 +0200	[thread overview]
Message-ID: <20130430153653.GD12715@krava.brq.redhat.com> (raw)
In-Reply-To: <20130319143509.GA1128@krava.brq.redhat.com>

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 <jstancek@redhat.com>
> Original-patch-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
> Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
> Cc: Frederic Weisbecker <fweisbec@gmail.com>
> Cc: Ingo Molnar <mingo@elte.hu>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Cc: Paul Mackerras <paulus@samba.org>
> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
> Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
> Signed-off-by: Jiri Olsa <jolsa@redhat.com>
> ---
>  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
> 

  reply	other threads:[~2013-04-30 15:39 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-01 16:34 [PATCHv2] perf: Fix vmalloc ring buffer free function Jiri Olsa
2013-03-06 14:30 ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2013-03-06 15:20 ` [PATCHv2] " Frederic Weisbecker
2013-03-06 15:37   ` Jiri Olsa
2013-03-06 15:40     ` Frederic Weisbecker
2013-03-11  9:40 ` Peter Zijlstra
2013-03-11 11:21   ` Jiri Olsa
2013-03-11 12:15     ` Ingo Molnar
2013-03-11 16:26     ` Peter Zijlstra
2013-03-11 16:43       ` Jiri Olsa
2013-03-11 17:44         ` Peter Zijlstra
2013-03-11 18:02           ` Jiri Olsa
2013-03-12 10:05             ` [PATCHv3] " Jiri Olsa
2013-03-12 10:27               ` Peter Zijlstra
2013-03-12 10:53                 ` Jiri Olsa
2013-03-12 12:38                   ` Peter Zijlstra
2013-03-12 13:52                 ` Jiri Olsa
2013-03-12 15:26                   ` Peter Zijlstra
2013-03-12 15:36                     ` Jiri Olsa
2013-03-12 16:24                       ` Peter Zijlstra
2013-03-12 17:04                         ` Jiri Olsa
2013-03-13 11:15                           ` Jiri Olsa
2013-03-18 19:05                             ` Jiri Olsa
2013-03-19 11:46                               ` Peter Zijlstra
2013-03-19 14:35                                 ` [PATCHv4] perf: Fix vmalloc ring buffer pages handling Jiri Olsa
2013-04-30 15:36                                   ` Jiri Olsa [this message]
2013-05-01 10:34                                     ` Ingo Molnar
2013-05-02  7:54                                   ` [tip:perf/urgent] " tip-bot for Jiri Olsa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130430153653.GD12715@krava.brq.redhat.com \
    --to=jolsa@redhat.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=cjashfor@linux.vnet.ibm.com \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=namhyung@kernel.org \
    --cc=paulus@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome