[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251017112504.GE3245006@noisy.programming.kicks-ass.net>
Date: Fri, 17 Oct 2025 13:25:04 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: Andrew Cooper <andrew.cooper@...rix.com>
Cc: Thomas Gleixner <tglx@...utronix.de>,
LKML <linux-kernel@...r.kernel.org>,
Christophe Leroy <christophe.leroy@...roup.eu>,
Mathieu Desnoyers <mathieu.desnoyers@...icios.com>,
Andrew Cooper <andrew.cooper3@...rix.com>,
Linus Torvalds <torvalds@...ux-foundation.org>,
kernel test robot <lkp@...el.com>,
Russell King <linux@...linux.org.uk>,
linux-arm-kernel@...ts.infradead.org, x86@...nel.org,
Madhavan Srinivasan <maddy@...ux.ibm.com>,
Michael Ellerman <mpe@...erman.id.au>,
Nicholas Piggin <npiggin@...il.com>, linuxppc-dev@...ts.ozlabs.org,
Paul Walmsley <pjw@...nel.org>, Palmer Dabbelt <palmer@...belt.com>,
linux-riscv@...ts.infradead.org, Heiko Carstens <hca@...ux.ibm.com>,
Christian Borntraeger <borntraeger@...ux.ibm.com>,
Sven Schnelle <svens@...ux.ibm.com>, linux-s390@...r.kernel.org,
Julia Lawall <Julia.Lawall@...ia.fr>,
Nicolas Palix <nicolas.palix@...g.fr>,
Darren Hart <dvhart@...radead.org>,
Davidlohr Bueso <dave@...olabs.net>,
André Almeida <andrealmeid@...lia.com>,
Alexander Viro <viro@...iv.linux.org.uk>,
Christian Brauner <brauner@...nel.org>, Jan Kara <jack@...e.cz>,
linux-fsdevel@...r.kernel.org
Subject: Re: [patch V3 07/12] uaccess: Provide scoped masked user access
regions
On Fri, Oct 17, 2025 at 12:08:24PM +0100, Andrew Cooper wrote:
> On 17/10/2025 11:09 am, Thomas Gleixner wrote:
> > --- a/include/linux/uaccess.h
> > +++ b/include/linux/uaccess.h
> > +#define __scoped_masked_user_access(_mode, _uptr, _size, _elbl) \
> > +for (bool ____stop = false; !____stop; ____stop = true) \
> > + for (typeof((_uptr)) _tmpptr = __scoped_user_access_begin(_mode, _uptr, _size, _elbl); \
> > + !____stop; ____stop = true) \
> > + for (CLASS(masked_user_##_mode##_access, scope) (_tmpptr); !____stop; \
> > + ____stop = true) \
> > + /* Force modified pointer usage within the scope */ \
> > + for (const typeof((_uptr)) _uptr = _tmpptr; !____stop; ____stop = true) \
> > + if (1)
> > +
>
> Truly a thing of beauty. At least the end user experience is nice.
>
> One thing to be aware of is that:
>
> scoped_masked_user_rw_access(ptr, efault) {
> unsafe_get_user(rval, &ptr->rval, efault);
> unsafe_put_user(wval, &ptr->wval, efault);
> } else {
> // unreachable
> }
>
> will compile. Instead, I think you want the final line of the macro to
> be "if (0) {} else" to prevent this.
>
>
> While we're on the subject, can we find some C standards people to lobby.
>
> C2Y has a proposal to introduce "if (int foo =" syntax to generalise the
> for() loop special case. Can we please see about fixing the restriction
> of only allowing a single type per loop? This example could be a
> single loop if it weren't for that restriction.
So elsewhere, Linus suggested to use a struct to get around that. See
for example this lovely thing:
https://git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git/commit/?h=locking/core&id=1bc5d8cefd0d9768dc03c83140dd54c552bea470
Powered by blists - more mailing lists