[PATCH] Don't disable preemption in exception handlers without IST

From: Andi Kleen
Date: Sat Oct 27 2007 - 06:39:33 EST



Some of the exception handlers that run on an IST in a normal kernel
still disable preemption. This causes might_sleep warning when sending signals
for debugging in PREEMPT-RT because sending signals can take a lock.
Since the ISTs are disabled now for those don't disable the preemption.

This completes the remove IST patch I sent some time ago and fixes
another case where using gdb caused warnings.

Also it will likely improve latency a little bit.

Signed-off-by: Andi Kleen <ak@xxxxxxx>


Thomas, I think this patch is worth adding, unless you have a better
work around.


-- Steve



>
> Forward-ported from v2.6.33.9-rt31 to v3.2-rc2-rt3
> Signed-off-by: John Kacur <jkacur@xxxxxxxxxx>
> ---
> arch/x86/kernel/traps.c | 24 +++++++++++++-----------
> 1 files changed, 13 insertions(+), 11 deletions(-)
>
> diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
> index a8e3eb8..3654390 100644
> --- a/arch/x86/kernel/traps.c
> +++ b/arch/x86/kernel/traps.c
> @@ -87,9 +87,10 @@ static inline void conditional_sti(struct pt_regs *regs)
> local_irq_enable();
> }
>
> -static inline void preempt_conditional_sti(struct pt_regs *regs)
> +static inline void preempt_conditional_sti(struct pt_regs *regs, int stack)
> {
> - inc_preempt_count();
> + if (stack)
> + inc_preempt_count();
> if (regs->flags & X86_EFLAGS_IF)
> local_irq_enable();
> }
> @@ -100,11 +101,12 @@ static inline void conditional_cli(struct pt_regs *regs)
> local_irq_disable();
> }
>
> -static inline void preempt_conditional_cli(struct pt_regs *regs)
> +static inline void preempt_conditional_cli(struct pt_regs *regs, int stack)
> {
> if (regs->flags & X86_EFLAGS_IF)
> local_irq_disable();
> - dec_preempt_count();
> + if (stack)
> + dec_preempt_count();
> }
>
> static void __kprobes
> @@ -222,9 +224,9 @@ dotraplinkage void do_stack_segment(struct pt_regs *regs, long error_code)
> if (notify_die(DIE_TRAP, "stack segment", regs, error_code,
> 12, SIGBUS) == NOTIFY_STOP)
> return;
> - preempt_conditional_sti(regs);
> + preempt_conditional_sti(regs, STACKFAULT_STACK);
> do_trap(12, SIGBUS, "stack segment", regs, error_code, NULL);
> - preempt_conditional_cli(regs);
> + preempt_conditional_cli(regs, STACKFAULT_STACK);
> }
>
> dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
> @@ -316,9 +318,9 @@ dotraplinkage void __kprobes do_int3(struct pt_regs *regs, long error_code)
> return;
> #endif
>
> - preempt_conditional_sti(regs);
> + preempt_conditional_sti(regs, DEBUG_STACK);
> do_trap(3, SIGTRAP, "int3", regs, error_code, NULL);
> - preempt_conditional_cli(regs);
> + preempt_conditional_cli(regs, DEBUG_STACK);
> }
>
> #ifdef CONFIG_X86_64
> @@ -412,12 +414,12 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
> return;
>
> /* It's safe to allow irq's after DR6 has been saved */
> - preempt_conditional_sti(regs);
> + preempt_conditional_sti(regs, DEBUG_STACK);
>
> if (regs->flags & X86_VM_MASK) {
> handle_vm86_trap((struct kernel_vm86_regs *) regs,
> error_code, 1);
> - preempt_conditional_cli(regs);
> + preempt_conditional_cli(regs, DEBUG_STACK);
> return;
> }
>
> @@ -436,7 +438,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
> si_code = get_si_code(tsk->thread.debugreg6);
> if (tsk->thread.debugreg6 & (DR_STEP | DR_TRAP_BITS) || user_icebp)
> send_sigtrap(tsk, regs, error_code, si_code);
> - preempt_conditional_cli(regs);
> + preempt_conditional_cli(regs, DEBUG_STACK);
>
> return;
> }


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/