WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] RE: [PATCH] Fixing stack alignment in x86-64 Xen

To: "Andi Kleen" <ak@xxxxxx>
Subject: [Xen-devel] RE: [PATCH] Fixing stack alignment in x86-64 Xen
From: "Nakajima, Jun" <jun.nakajima@xxxxxxxxx>
Date: Wed, 18 May 2005 09:38:51 -0700
Cc: xen-devel@xxxxxxxxxxxxxxxxxxx
Delivery-date: Wed, 18 May 2005 16:38:27 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
Thread-index: AcVbxKJznFXQF3LmR/ar3F7tnICKpAAAHCcw
Thread-topic: [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

<Prev in Thread] Current Thread [Next in Thread>