[patch V3 07/12] uaccess: Provide scoped masked user access regions
Andrew Cooper
andrew.cooper at citrix.com
Fri Oct 17 22:29:13 AEDT 2025
On 17/10/2025 12:21 pm, Thomas Gleixner wrote:
> On Fri, Oct 17 2025 at 12:08, 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.
> Duh. yes. But I can just remove the 'if (1)' completely. That's a
> leftover from some earlier iteration of this.
Oh, of course. That works too.
>
>> 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.
> That'd be nice. But we can't have nice things, can we?
Well, the worst they can say is no :)
~Andrew
More information about the Linuxppc-dev
mailing list