Hi, I have a doubt on the Tss initialization. In the function cpu_init(),t->rsp0 = get_stack_bottom(). #define get_stack_bottom() \ ((unsigned long)&get_cpu_info()->guest_cpu_user_regs.es) But I can’t find where the guest_cpu_user_regs has been initialized. Anybody can help me? -Techie.lee _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Li, Xin B
2007-Aug-06 15:49 UTC
RE: [Xen-devel] About TSS initialization when Xen booting.
in __context_switch, there is a memcpy to do this job. -Xin ________________________________ From: xen-devel-bounces@lists.xensource.com [mailto:xen-devel-bounces@lists.xensource.com] On Behalf Of 李亚琼 Sent: Monday, August 06, 2007 8:46 PM To: xen-devel@lists.xensource.com Subject: [Xen-devel] About TSS initialization when Xen booting. Hi, I have a doubt on the Tss initialization. In the function cpu_init(),t->rsp0 = get_stack_bottom(). #define get_stack_bottom() \ ((unsigned long)&get_cpu_info()->guest_cpu_user_regs.es) But I can’t find where the guest_cpu_user_regs has been initialized. Anybody can help me? -Techie.lee _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Thanks, Xin! But __context_switch will be invoked only when system is scheduled. During the initialization, Xen invokes percpu_traps_init and cpu_init to initialize a physical cpu. In this two functions, tss will be assigned with a value from guest_cpu_user_regs. But till this time, __context_switch has never been invoked. In other words, idle_domain’s tss is assigned with a trivial value. After all, when Xen is in the idle domain, a stack switch will occur when a interrupt occurs. Is it correct? Another question is about percpu_traps_init whick code is following: void __init percpu_traps_init(void) { char *stack_bottom, *stack; . . . stack_bottom = (char *)get_stack_bottom(); stack = (char *)((unsigned long)stack_bottom & ~(STACK_SIZE - 1)); /* Double-fault handler has its own per-CPU 2kB stack. */ init_tss[cpu].ist[0] = (unsigned long)&stack[2048]; /* NMI handler has its own per-CPU 1kB stack. */ init_tss[cpu].ist[1] = (unsigned long)&stack[3072]; /* * Trampoline for SYSCALL entry from long mode. */ /* Skip the NMI and DF stacks. */ stack = &stack[3072]; wrmsr(MSR_LSTAR, (unsigned long)stack, ((unsigned long)stack>>32)); /* movq %rsp, saversp(%rip) */ stack[0] = 0x48; stack[1] = 0x89; stack[2] = 0x25; *(u32 *)&stack[3] = (stack_bottom - &stack[7]) - 16; . . . } The question is about the variables, “stack” and “stack_bottom”. At this moment, if guest_cpu_user_regs has not been initialized, “stack_bottom” will be zero when the cpu is the first physical cpu ( its stack is initialized with zero in file boot.S). And then “stack” will be zero, too. Is it correct? -Techie, lee 2007-8-7 _____ 发件人: Li, Xin B [mailto:xin.b.li@intel.com] 发送时间: 2007年8月6日 23:50 收件人: 李亚琼; xen-devel@lists.xensource.com 主题: RE: [Xen-devel] About TSS initialization when Xen booting. In __context_switch, there is a memcpy to do this job. -Xin _____ From: xen-devel-bounces@lists.xensource.com [mailto:xen-devel-bounces@lists. xensource.com] On Behalf Of 李亚琼 Sent: Monday, August 06, 2007 8:46 PM To: xen-devel@lists.xensource.com Subject: [Xen-devel] About TSS initialization when Xen booting. Hi, I have a doubt on the Tss initialization. In the function cpu_init(),t->rsp0 = get_stack_bottom(). #define get_stack_bottom() \ ((unsigned long)&get_cpu_info()->guest_cpu_user_regs.es) But I can’t find where the guest_cpu_user_regs has been initialized. Anybody can help me? -Techie.lee _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2007-Aug-07 06:52 UTC
Re: 答复: [Xen-devel] About TSS initialization when Xen booting.
On Tue, 2007-08-07 at 09:27 +0800, 李亚琼 wrote:> Thanks, Xin! > > But __context_switch will be invoked only when system is scheduled. > During the initialization, Xen invokes percpu_traps_init and cpu_init > to initialize a physical cpu. In this two functions, tss will be > assigned with a value from guest_cpu_user_regs. But till this time, > __context_switch has never been invoked. In other words, idle_domain’s > tss is assigned with a trivial value. After all, when Xen is in the > idle domain, a stack switch will occur when a interrupt occurs. Is it > correct?get_cpu_info returns a pointer into the stack. guest_cpu_user_regs is a member of the structure this pointer points to (but not a pointer itself). It has been arranged so that guest_cpu_user_regs overlaps the part of the stack where entry.S will save the guests registers (mainly in the SAVE_ALL macro). This should make sense because the TSS is being initialised with exactly the value you wish the stack to have when transitioning to ring0.> The question is about the variables, “stack” and “stack_bottom”. At > this moment, if guest_cpu_user_regs has not been initialized, > “stack_bottom” will be zero when the cpu is the first physical cpu > ( its stack is initialized with zero in file boot.S). And then “stack” > will be zero, too. Is it correct?Remember that guest_cpu_user_regs isn''t a pointer, it''s just a member of a struct so it''s address will currently be the address of that struct plus an offset. Ian. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Hi,Ian I know what you mean. But the problem is that guest_cpu_user_regs.es (the macro of get_frame_bottom() returns this value) is used to initialize the TSS when it has not been initialized. If TSS has not been initialized correctly, Xen can''t switch to the kernel stack of the current cpu when a interrupt or trap occurs. Tss initialization should correctly be initialized before a interrupt or trap occurs. But I can''t find where guest_cpu_user_regs.es is initialized before used to initialize TSS in function percpu_traps_init(). Hope your reply! -Techie.lee 2007-8-7 -----邮件原件----- 发件人: Ian Campbell [mailto:Ian.Campbell@XenSource.com] 发送时间: 2007年8月7日 14:53 收件人: 李亚琼 抄送: ''Li, Xin B''; 主题: Re: 答复: [Xen-devel] About TSSinitialization when Xen booting. On Tue, 2007-08-07 at 09:27 +0800, 李亚琼 wrote:> Thanks, Xin! > > But __context_switch will be invoked only when system is scheduled. > During the initialization, Xen invokes percpu_traps_init and cpu_init > to initialize a physical cpu. In this two functions, tss will be > assigned with a value from guest_cpu_user_regs. But till this time, > __context_switch has never been invoked. In other words, idle_domain’s > tss is assigned with a trivial value. After all, when Xen is in the > idle domain, a stack switch will occur when a interrupt occurs. Is it > correct?get_cpu_info returns a pointer into the stack. guest_cpu_user_regs is a member of the structure this pointer points to (but not a pointer itself). It has been arranged so that guest_cpu_user_regs overlaps the part of the stack where entry.S will save the guests registers (mainly in the SAVE_ALL macro). This should make sense because the TSS is being initialised with exactly the value you wish the stack to have when transitioning to ring0.> The question is about the variables, “stack” and “stack_bottom”. At > this moment, if guest_cpu_user_regs has not been initialized, > “stack_bottom” will be zero when the cpu is the first physical cpu > ( its stack is initialized with zero in file boot.S). And then “stack” > will be zero, too. Is it correct?Remember that guest_cpu_user_regs isn''t a pointer, it''s just a member of a struct so it''s address will currently be the address of that struct plus an offset. Ian. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2007-Aug-07 07:30 UTC
Re: 答复: 答复: [Xen-devel] About TSSinitialization when Xen booting.
On Tue, 2007-08-07 at 15:20 +0800, 李亚琼 wrote:> Hi,Ian > I know what you mean. But the problem is that guest_cpu_user_regs.es > (the macro of get_frame_bottom() returns this value) is used to initialize > the TSS when it has not been initialized.It''s the _address_ of guest_cpu_user_regs.es, isn''t it? ((unsigned long)&get_cpu_info()->guest_cpu_user_regs.es) ^> If TSS has not been initialized > correctly, Xen can''t switch to the kernel stack of the current cpu when a > interrupt or trap occurs. Tss initialization should correctly be initialized > before a interrupt or trap occurs. But I can''t find where > guest_cpu_user_regs.es is initialized before used to initialize TSS in > function percpu_traps_init().The TSS setup in percpu_traps_init() is for the double fault TSS. The regular TSS is setup in cpu_init using init_tss[cpu]. Ian. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel