All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: Peter Zijlstra <peterz@infradead.org>
Cc: yabinc@google.com, acme@kernel.org,
	alexander.shishkin@linux.intel.com, jolsa@redhat.com,
	namhyung@kernel.org, mark.rutland@arm.com,
	linux-kernel@vger.kernel.org, Ingo Molnar <mingo@redhat.com>
Subject: Re: [PATCH 1/4] perf/ring_buffer: Fix exposing a temporarily decreased data_head.
Date: Fri, 17 May 2019 15:05:09 +0200	[thread overview]
Message-ID: <20190517130509.GA90824@gmail.com> (raw)
In-Reply-To: <20190517115418.224478157@infradead.org>


* Peter Zijlstra <peterz@infradead.org> wrote:

> In perf_output_put_handle(), an IRQ/NMI can happen in below location and
> write records to the same ring buffer:
> 	...
> 	local_dec_and_test(&rb->nest)
> 	...                          <-- an IRQ/NMI can happen here
> 	rb->user_page->data_head = head;
> 	...
> 
> In this case, a value A is written to data_head in the IRQ, then a value
> B is written to data_head after the IRQ. And A > B. As a result,
> data_head is temporarily decreased from A to B. And a reader may see
> data_head < data_tail if it read the buffer frequently enough, which
> creates unexpected behaviors.
> 
> This can be fixed by moving dec(&rb->nest) to after updating data_head,
> which prevents the IRQ/NMI above from updating data_head.
> 
> Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Jiri Olsa <jolsa@redhat.com>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> Fixes: ef60777c9abd ("perf: Optimize the perf_output() path by removing IRQ-disables")
> Signed-off-by: Yabin Cui <yabinc@google.com>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> Link: https://lkml.kernel.org/r/20190516184010.167903-1-yabinc@google.com

So these are missing a bunch of:

  From: Yabin Cui <yabinc@google.com>

lines, right?

Thanks,

	Ingo

  reply	other threads:[~2019-05-17 13:05 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-17 11:52 [PATCH 0/4] perf ring-buffer fixes Peter Zijlstra
2019-05-17 11:52 ` [PATCH 1/4] perf/ring_buffer: Fix exposing a temporarily decreased data_head Peter Zijlstra
2019-05-17 13:05   ` Ingo Molnar [this message]
2019-05-17 14:26     ` Peter Zijlstra
2019-05-24  7:01       ` Ingo Molnar
2019-05-24  8:08   ` [tip:perf/urgent] " tip-bot for Yabin Cui
2019-05-17 11:52 ` [PATCH 2/4] perf/ring_buffer: Add ordering to rb->nest increment Peter Zijlstra
2019-05-24  8:08   ` [tip:perf/urgent] " tip-bot for Peter Zijlstra
2019-05-17 11:52 ` [PATCH 3/4] perf/ring-buffer: Always use {READ,WRITE}_ONCE() for rb->user_page data Peter Zijlstra
2019-05-24  8:09   ` [tip:perf/urgent] " tip-bot for Peter Zijlstra
2019-05-17 11:52 ` [PATCH 4/4] perf/ring-buffer: Use regular variables for nesting Peter Zijlstra
2019-05-24  8:10   ` [tip:perf/urgent] " tip-bot for Peter Zijlstra

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=20190517130509.GA90824@gmail.com \
    --to=mingo@kernel.org \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=yabinc@google.com \
    --subject='Re: [PATCH 1/4] perf/ring_buffer: Fix exposing a temporarily decreased data_head.' \
    /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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.