Subject: RE: [PATCH v3 2/6] x86/uaccess: Avoid barrier_nospec() in 64-bit __get_user()

From: David Laight <[email-masked]>
Date: Fri, 8 Nov 2024 17:12:53 +0000

From: Josh Poimboeuf
> Sent: 29 October 2024 03:28
> 
> On Mon, Oct 28, 2024 at 06:56:15PM -0700, Josh Poimboeuf wrote:
> > The barrier_nospec() in 64-bit __get_user() is slow.  Instead use
> > pointer masking to force the user pointer to all 1's if a previous
> > access_ok() mispredicted true for an invalid address.
> 
> Linus pointed out that __get_user() may be used by some code to access
> both kernel and user space and in fact I found one such usage in
> vc_read_mem()....
> 
> So I self-NAK this patch for now.
> 
> Still, it would be great if patch 1 could get merged as that gives a
> significant performance boost.

I'm a bit late to the party and still a week behind :-(

But I've wondered if access_ok() ought to be implemented using an
'asm goto with output' - much like get_user().

Then the use would be:
	masked_address = access_ok(maybe_bad_address, size, jump_label);
with later user accesses using the masked_address.

Once you've done that __get_user() doesn't need to contain address masking.

Given that clac/stac iare so slow should there are be something that
combines stac with access_ok() bracketed with a 'user_access_end'
or an actual fault.

I've sure there is code (maybe reading iovec[] or in sys_poll())
that wants to do multiple get/put_user in a short loop rather that
calling copy_to/from_user().

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)