Re: [PATCH 2/5] nptl: Add rseq registration

From: Paul E. McKenney
Date: Mon Dec 06 2021 - 16:08:19 EST


On Mon, Dec 06, 2021 at 09:26:51PM +0100, Florian Weimer wrote:
> * Paul E. McKenney via Libc-alpha:
>
> >> The C memory model is broken and does not prevent out-of-thin-air
> >> values. As far as I know, this breaks single-copy atomicity. In
> >> practice, compilers will not exercise the latitude offered by the memory
> >> model. volatile does not ensure absence of data races.
> >
> > Within the confines of the standard, agreed, use of the volatile keyword
> > does not explicitly prevent data races.
> >
> > However, volatile accesses are (informally) defined to suffice for
> > device-driver memory accesses that communicate with devices, whether via
> > MMIO or DMA-style shared memory. The device-driver firmware is often
> > written in C or C++. So doesn't this informal device-driver guarantee
> > need to also do what is needed for userspace code that is communicating
> > with kernel code? If not, why not?
>
> The informal guarantee is probably good enough here, too. However, the
> actual accesses are behind macros, and those macros use either
> non-volatile plain reads or inline assembler (which use
> single-instruction naturally aligned reads).

Agreed, a non-volatile plain read is quite dangerous in this context.

Thanx, Paul