Re: [RFC][PATCH v2 4/5] x86/uaccess: Implement unsafe_try_cmpxchg_user()

From: Peter Zijlstra
Date: Thu Jan 27 2022 - 04:56:39 EST


On Thu, Jan 27, 2022 at 06:36:19AM +0000, Sean Christopherson wrote:
> On Thu, Jan 27, 2022, Sean Christopherson wrote:
> > Doh, I should have specified that KVM needs 8-byte CMPXCHG on 32-bit kernels due
> > to using it to atomically update guest PAE PTEs and LTR descriptors (yay).
> >
> > Also, KVM's use case isn't a tight loop, how gross would it be to add a slightly
> > less unsafe version that does __uaccess_begin_nospec()? KVM pre-checks the address
> > way ahead of time, so the access_ok() check can be omitted. Alternatively, KVM
> > could add its own macro, but that seems a little silly. E.g. somethign like this,
> > though I don't think this is correct
>
> *sigh*
>
> Finally realized I forgot to add back the page offset after converting from guest
> page frame to host virtual address. Anyways, this is what I ended up with, will
> test more tomorrow.

Looks about right :-) (famous last words etc..)