Re: [RFC 5/7] x86/asm: Rearrange struct cpu_tss to enlarge SYSENTER_stack and fix alignment

From: Dave Hansen
Date: Mon Nov 13 2017 - 14:19:34 EST


On 11/10/2017 08:05 PM, Andy Lutomirski wrote:
> struct tss_struct {
> /*
> + * Space for the temporary SYSENTER stack. Used for the entry
> + * trampoline as well. Size it such that tss_struct ends up
> + * as a multiple of PAGE_SIZE. This calculation assumes that
> + * io_bitmap is a multiple of PAGE_SIZE (8192 bytes) plus one
> + * long.
> + */
> + unsigned long SYSENTER_stack_canary;
> + unsigned long SYSENTER_stack[(PAGE_SIZE - sizeof(struct x86_hw_tss)) / sizeof(unsigned long) - 2];
> +
> + /*
> * The hardware state:
> */
> struct x86_hw_tss x86_tss;
> @@ -337,15 +347,9 @@ struct tss_struct {
> * be within the limit.
> */
> unsigned long io_bitmap[IO_BITMAP_LONGS + 1];
> -
> - /*
> - * Space for the temporary SYSENTER stack.
> - */
> - unsigned long SYSENTER_stack_canary;
> - unsigned long SYSENTER_stack[64];
> } ____cacheline_aligned;


If io_bitmap[] is already page-size-aligned, how does it help us to move
SYSENTER_stack[]?

It seems like it would be easier to just leave SYSENTER_stack[] where it
is, make it SYSENTER_stack[0], and just find somewhere else to choose
how much to bloat the tss_struct *allocation* instead of trying to make
sure that sizeof(tss_struct) matches the allocation.

That SYSENTER_stack[] size calculation is pretty hideous. :)