[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20180511162229.GK12217@hirez.programming.kicks-ass.net>
Date: Fri, 11 May 2018 18:22:29 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: Mark Rutland <mark.rutland@....com>
Cc: linux-kernel@...r.kernel.org, Ingo Molnar <mingo@...hat.com>,
Will Deacon <will.deacon@....com>
Subject: Re: [PATCH] perf/ring_buffer: ensure atomicity and order of updates
On Fri, May 11, 2018 at 11:59:32AM +0100, Mark Rutland wrote:
> READ_ONCE() and WRITE_ONCE() "helpfully" make a silent fallback to a
> memcpy in this case, so we're broken today, regardless of this change.
>
> I suspect that in practice we get single-copy-atomicity for the 32-bit
> halves, and sessions likely produce less than 4GiB of ringbuffer data,
> so failures would be rare.
This should not be a problem because of the 32bit adress space limit,
which would necessarily limit us to the low word.
Also note that in perf_output_put_handle(), where we write ->data_head,
the store is from an 'unsigned long'. So on 32bit that will result in a
zero high word. Similarly, in __perf_output_begin() we read ->data_tail
into an unsigned long, which will discard the high word.
So userspace should always read (head) a zero high word, irrespective of
a split store (2x32bit), and the kernel will disregard the high word on
reading (tail), irrespective of what userspace put there.
This is all a bit subtle, and could probably use a comment, but it ought
to work..
Powered by blists - more mailing lists