On Fri, May 17, 2019 at 03:05:09PM +0200, Ingo Molnar wrote:
> 
> * Peter Zijlstra <[email protected]> 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 <[email protected]>
> > Cc: Ingo Molnar <[email protected]>
> > Cc: Jiri Olsa <[email protected]>
> > Cc: Namhyung Kim <[email protected]>
> > Cc: Alexander Shishkin <[email protected]>
> > Fixes: ef60777c9abd ("perf: Optimize the perf_output() path by removing 
> > IRQ-disables")
> > Signed-off-by: Yabin Cui <[email protected]>
> > Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
> > Link: https://lkml.kernel.org/r/[email protected]
> 
> So these are missing a bunch of:
> 
>   From: Yabin Cui <[email protected]>
> 
> lines, right?
> 

The first. certainly, the rest, while inspired by his patch, is more
complete than what he did.

Reply via email to