|
|
|
|
|
|
|
|
|
|
xen-devel
[Xen-devel] RE: [PATCH] Fixing stack alignment in x86-64 Xen
Andi Kleen wrote:
>> I think the right thing is to get rsp0 in TSS on a 16-byte boundary
>> by getting get_stack_bottom() and get_cpu_user_regs() see the correct
>> stack. That will fix the reset_stack_and_jump() as well. It's
>> basically what my patch does.
>
> This means you cannot disable the 16 byte stack alignment in gcc.
> Probably does not matter too much today (I guess Xen is not that
> bad a stack pig), but in the far future it might come in useful.
> Also it would generate smaller code.
>
> -Andi
I don't think that's correct. If you look at how they calculate the
stack pointer, fortunately they depend only on STACK_RESERVED and the
magic number 48 (see below). It does not matter if gcc used 16 byte
stack alignment or not because the current RSP will be rounded down to
the 8KB boundary when calculate the stack pointer.
#define STACK_RESERVED \
(sizeof(struct cpu_user_regs) + sizeof(struct domain *))
static inline struct cpu_user_regs *get_cpu_user_regs(void)
{
struct cpu_user_regs *cpu_user_regs;
__asm__( "andq %%rsp,%0; addq %2,%0"
: "=r" (cpu_user_regs)
: "0" (~(STACK_SIZE-1)), "i" (STACK_SIZE-STACK_RESERVED) );
return cpu_user_regs;
}
/*
* Get the bottom-of-stack, as stored in the per-CPU TSS. This is
actually
* 48 bytes before the real bottom of the stack to allow space for:
* domain pointer, padding, DS, ES, FS, GS. The padding is required to
* have the stack pointer 16-byte aligned.
*/
static inline unsigned long get_stack_bottom(void)
{
unsigned long p;
__asm__( "andq %%rsp,%0; addq %2,%0"
: "=r" (p)
: "0" (~(STACK_SIZE-1)), "i" (STACK_SIZE-48) );
return p;
}
Jun
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|
|
|
|
|