On 5/1/20 11:28 AM, Linus Torvalds wrote: > Plus on x86 you can't reasonably even have different code sequences > for that case, because CLAC/STAC don't have a "enable users read > accesses" vs "write accesses" case. It's an all-or-nothing "enable > user faults". > > We _used_ to have a difference on x86, back when we did the whole "fs > segment points to user space". Protection keys might give us _some_ of this back. If we're doing a copy_from_user(), we could (logically) do: stac() save_pkru() pkru |= ~0x55555555 ... do userspace read restore_pkru() clac() That *should* generate a fault if we try to write to userspace in there because PKRU affects all user *addresses* (PTEs with _PAGE_USER set) not user-mode *accesses*. Properly stashing the value off and context switching it correctly would be fun, but probably not impossible to pull off. You actually wouldn't even technically need to restore PKRU in this path. It would just need to be restored before the thread runs userspace or hits a copy_to_user() equivalent. I can't imagine this would all be worth the trouble, but there are crazier people out there than me.