Re: [tip:x86/mm] x86/asm: Remove __VIRTUAL_MASK_SHIFT==47 assert

From: Kirill A. Shutemov
Date: Wed Apr 05 2017 - 07:15:22 EST


On Tue, Apr 04, 2017 at 05:36:33PM +0200, Denys Vlasenko wrote:
> > diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
> > index 044d18e..f07b4ef 100644
> > --- a/arch/x86/entry/entry_64.S
> > +++ b/arch/x86/entry/entry_64.S
> > @@ -265,12 +265,9 @@ return_from_SYSCALL_64:
> > *
> > * If width of "canonical tail" ever becomes variable, this will need
> > * to be updated to remain correct on both old and new CPUs.
> > + *
> > + * Change top 16 bits to be the sign-extension of 47th bit
>
> The comment above stops being correct: it's not necessary 16 top bits
> we sign-extend now. With larger __VIRTUAL_MASK_SHIFT for 5-level translation,
> it will become 7 bits (if I do the math right).

Does the patch below look okay to you?

> > */
> > - .ifne __VIRTUAL_MASK_SHIFT - 47
> > - .error "virtual address width changed -- SYSRET checks need update"
> > - .endif
> > -
> > - /* Change top 16 bits to be the sign-extension of 47th bit */
> > shl $(64 - (__VIRTUAL_MASK_SHIFT+1)), %rcx
> > sar $(64 - (__VIRTUAL_MASK_SHIFT+1)), %rcx
>
> The bigger problem here would be the future boot-time choice of 4/5-level
> page tables: __VIRTUAL_MASK_SHIFT will need to depend on that choice,
> but in this location it is preferable to not use any variables
> (memory references).

Yeah. Will see what I will be able to come up with. Not sure yet.

-------------------8<----------------------