x86_64 debug_stack nested patch
PATCH 1/1 x86_64 debug_stack nested patch
hi,
In x86_64 platform, INT1 and INT3 trap stack is IST stack called DEBUG_STACK, when INT1/INT3 trap happens, system will switch to DEBUG_STACK by hardware. Current DEBUG_STACK size is 4K, when int1/int3 trap happens, kernel will minus current DEBUG_STACK IST value by 4k. But if int3/int1 trap is nested, it will destroy other vector's IST stack. This patch modifies this, it sets DEBUG_STACK size as 8K and allows two level of nested int1/int3 trap.
Kprobe DEBUG_STACK may be nested, because kprobe hanlder may be probed by other kprobes. This patch is against 2.6.17-rc3.
Thanks
bibo,mao
arch/x86_64/kernel/traps.c +7 -33
@@ -141,50 +141,24 @@ static unsigned long *in_exception_stack [DOUBLEFAULT_STACK - 1] = "#DF", [STACKFAULT_STACK - 1] = "#SS", [MCE_STACK - 1] = "#MC", -#if DEBUG_STKSZ > EXCEPTION_STKSZ - [N_EXCEPTION_STACKS ... N_EXCEPTION_STACKS + DEBUG_STKSZ / EXCEPTION_STKSZ - 2] = "#DB[?]" -#endif }; -unsigned k; +unsigned stack_size, end, k;for (k =0 ; k <N_EXCEPTION_STACKS ; k++) { -unsigned long end; - -switch (k +1 ) { -#if DEBUG_STKSZ >EXCEPTION_STKSZ -case DEBUG_STACK : - end =cpu_pda (cpu)->debugstack +DEBUG_STKSZ ; -break ; -#endif -default : - end =per_cpu (init_tss, cpu).ist[k]; -break ; - } + end =per_cpu (init_tss, cpu).ist[k];if (stack >= end)continue ; -if (stack >= end -EXCEPTION_STKSZ ) { +if (k == (DEBUG_STACK -1 )) + stack_size =DEBUG_STKSZ ; +else stack_size =EXCEPTION_STKSZ ; + +if (stack >= end - stack_size) {if (*usedp & (1U << k))break ; *usedp |=1U << k; *idp = ids[k];return (unsigned long *)end; } -#if DEBUG_STKSZ >EXCEPTION_STKSZ -if (k ==DEBUG_STACK -1 && stack >= end -DEBUG_STKSZ ) { -unsigned j =N_EXCEPTION_STACKS -1 ; - -do { - ++j; - end -=EXCEPTION_STKSZ ; - ids[j][4 ] ='1' + (j -N_EXCEPTION_STACKS ); - }while (stack < end -EXCEPTION_STKSZ ); -if (*usedp & (1U << j)) -break ; - *usedp |=1U << j; - *idp = ids[j]; -return (unsigned long *)end; - } -#endif }return NULL ; }
include/asm-x86_64/page.h +1 -1
@@ -20,7 +20,7 @@#define EXCEPTION_STACK_ORDER 0#define EXCEPTION_STKSZ (PAGE_SIZE << EXCEPTION_STACK_ORDER) -#define DEBUG_STACK_ORDER EXCEPTION_STACK_ORDER +#define DEBUG_STACK_ORDER 1#define DEBUG_STKSZ (PAGE_SIZE << DEBUG_STACK_ORDER)#define IRQSTACK_ORDER 2
Would you mind explaining why you
- needed to replace the handling of the DEBUG_STKSZ > EXCEPTION_STKSZ in in_exception_stack()?
- used a hard coded 1 instead of (EXCEPTION_STACK_ORDER + 1) for defining DEBUG_STACK_ORDER?
Thanks, Jan
Quoted 1 line
Quoted 1 line
Quoted 1 line
"bibo,mao" <[email protected]> 10.05.06 08:45 >>>
hi,
In x86_64 platform, INT1 and INT3 trap stack is IST stack called DEBUG_STACK, when INT1/INT3 trap happens, system will switch to DEBUG_STACK by hardware. Current DEBUG_STACK size is 4K, when int1/int3 trap happens, kernel will minus current DEBUG_STACK IST value by 4k. But if int3/int1 trap is nested, it will destroy other vector's IST stack. This patch modifies this, it sets DEBUG_STACK size as 8K and allows two level of nested int1/int3 trap.
Kprobe DEBUG_STACK may be nested, because kprobe hanlder may be probed by other kprobes. This patch is against 2.6.17-rc3.
Thanks
bibo,mao
ok, EXCEPTION_STACK_ORDER + 1 is better for me.in_exception_stack() function is to judge which IST stack by parameter stack value, if DEBUG_STKSZ value is set as 8K. The original function can not judge whether it is within DEBUG_STACK space.
Thanks
bibo,mao
Quoted 22 lines · Jan Beulich
Would you mind explaining why you
- needed to replace the handling of theDEBUG_STKSZ>EXCEPTION_STKSZinin_exception_stack()?
- used a hard coded 1 instead of (EXCEPTION_STACK_ORDER+ 1) for definingDEBUG_STACK_ORDER?Thanks, Jan
Quoted 1 line
Quoted 1 line
Quoted 1 line
"bibo,mao" <[email protected]> 10.05.06 08:45 >>>
hi,
Inx86_64platform, INT1 and INT3 trap stack is IST stack calledDEBUG_STACK, when INT1/INT3 trap happens, system will switch toDEBUG_STACKby hardware. CurrentDEBUG_STACKsize is 4K, when int1/int3 trap happens, kernel will minus currentDEBUG_STACKIST value by 4k. But if int3/int1 trap is nested, it will destroy other vector's IST stack. This patch modifies this, it setsDEBUG_STACKsize as 8K and allows two level of nested int1/int3 trap.
KprobeDEBUG_STACKmay be nested, because kprobe hanlder may be probed by other kprobes. This patch is against 2.6.17-rc3.Signed-off-by bibo, mao <[email protected]>Thanks
bibo,mao
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 3 lines
in_exception_stack()function is to judge which IST stack by parameter stack value, ifDEBUG_STKSZvalue is set as 8K. The original function can not judge whether it is withinDEBUG_STACKspace.
I rather think that the new code can't work properly. Since the pointer in the TSS gets decreased while the handler is running, using that value is not going to tell you the end of the stack, but you'd rather get the end of the stack the next (nested) invocation of the handler would use. Further, treating the entire DEBUG_STKSZ range as a single piece is wrong, too, because it is not being used as a contiguous stack (but rather as 2 stacks EXCEPTION_STKSZ in size); the new code shouldn't be able to properly deal with nested invocations because of this.
Jan
yes, I am wrong. And I will modify this. And then only need define DEBUG_STACK_ORDER as (EXCEPTION_STACK_ORDER + 1)
thanks
bibo,mao
Quoted 15 lines · Jan Beulich
Quoted 1 line
in_exception_stack()function is to judge which IST stack by parameter stack value, ifDEBUG_STKSZvalue is set as 8K. The original function can not judge whether it is withinDEBUG_STACKspace.I rather think that the new code can't work properly. Since the pointer in the TSS gets decreased while the handler is running, using that value is not going to tell you the end of the stack, but you'd rather get the end of the stack the next (nested) invocation of the handler would use. Further, treating the entire
DEBUG_STKSZrange as a single piece is wrong, too, because it is not being used as a contiguous stack (but rather as 2 stacksEXCEPTION_STKSZin size); the new code shouldn't be able to properly deal with nested invocations because of this.Jan
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 2 lines · bibo,mao
yes, I am wrong. And I will modify this. And then only need define
DEBUG_STACK_ORDERas (EXCEPTION_STACK_ORDER+ 1)
If the kprobes code really wants to nest (in my opinion it's a kprobes bug) you should reduce its stack to 2K or so. Don't want to waste space for stupid code like this.
-Andi