From: Peter Zijlstra <peterz@infradead.org>
To: Mark Rutland <mark.rutland@arm.com>
Cc: linux-kernel@vger.kernel.org, Ingo Molnar <mingo@redhat.com>,
Will Deacon <will.deacon@arm.com>
Subject: Re: [PATCH] perf/ring_buffer: ensure atomicity and order of updates
Date: Mon, 14 May 2018 13:28:15 +0200 [thread overview]
Message-ID: <20180514112815.GP12217@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20180514110532.kihs5ilrs67kvq7e@lakrids.cambridge.arm.com>
On Mon, May 14, 2018 at 12:05:33PM +0100, Mark Rutland wrote:
> On Fri, May 11, 2018 at 06:22:29PM +0200, Peter Zijlstra wrote:
> > 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.
>
> For the wrapped values, yes.
>
> I thought that the head and tail values were meant to be free-running,
> but I can't see where I got that idea from now that I've gone digging
> again.
They are indeed free running.
> > 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.
>
> Ah, that's a fair point. So it's just compat userspace that this is
> potentially borked for. ;)
Right.. #$$#@ compat. Hurmph.. not sure how to go about fixing that
there.
> > 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..
>
> It would be nice to guarantee that we don't lose 32-bit atomicity by
> virtue of {READ,WRITE}_ONCE() falling back to memcpy in this case, so
> maybe we should wrap this in some helpers.
Our __READ_ONCE_SIZE / __write_once_size include case 8 unconditionally.
So we'll always issue a volatile u64 load/store and let the compiler
figure out how to do that -- typically 2 load/stores I would imagine.
next prev parent reply other threads:[~2018-05-14 11:28 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-10 13:06 [PATCH] perf/ring_buffer: ensure atomicity and order of updates Mark Rutland
2018-05-11 1:19 ` kbuild test robot
2018-05-11 1:19 ` kbuild test robot
2018-05-11 10:59 ` Mark Rutland
2018-05-11 16:22 ` Peter Zijlstra
2018-05-14 11:05 ` Mark Rutland
2018-05-14 11:28 ` Peter Zijlstra [this message]
2018-05-14 15:02 ` Peter Zijlstra
2018-05-14 15:20 ` Mark Rutland
2018-05-14 15:24 ` Peter Zijlstra
2018-05-23 16:42 ` Will Deacon
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=20180514112815.GP12217@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=will.deacon@arm.com \
/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