All of lore.kernel.org
 help / color / mirror / Atom feed
From: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-kernel@vger.kernel.org,
	linux-rt-users <linux-rt-users@vger.kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Carsten Emde <C.Emde@osadl.org>, John Kacur <jkacur@redhat.com>,
	Ingo Molnar <mingo@elte.hu>,
	Andrew Morton <akpm@linux-foundation.org>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Alexander van Heukelum <heukelum@fastmail.fm>,
	Andi Kleen <ak@linux.intel.com>, Oleg Nesterov <oleg@redhat.com>,
	Clark Williams <williams@redhat.com>,
	Luis Goncalves <lgoncalv@redhat.com>
Subject: Re: [PATCH RT 1/2 v3] x86: Do not disable preemption in int3 on 32bit
Date: Thu, 02 Feb 2012 11:24:55 +0900	[thread overview]
Message-ID: <4F29F3F7.5000802@hitachi.com> (raw)
In-Reply-To: <20120201210748.397671856@goodmis.org>

(2012/02/02 6:06), Steven Rostedt wrote:
> Preemption must be disabled before enabling interrupts in do_trap
> on x86_64 because the stack in use for int3 and debug is a per CPU
> stack set by th IST. But 32bit does not have an IST and the stack
> still belongs to the current task and there is no problem in scheduling
> out the task.
> 
> Keep preemption enabled on X86_32 when enabling interrupts for
> do_trap().
> 
> The name of the function is changed from preempt_conditional_sti/cli()
> to conditional_sti/cli_ist(), to annotate that this function is used
> when the stack is on the IST.
> 
> Signed-off-by: Steven Rostedt <rostedt@goodmis.org

Reviewed-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>

Thanks!

> 
> Index: linux-rt.git/arch/x86/kernel/traps.c
> ===================================================================
> --- linux-rt.git.orig/arch/x86/kernel/traps.c
> +++ linux-rt.git/arch/x86/kernel/traps.c
> @@ -87,9 +87,21 @@ static inline void conditional_sti(struc
>  		local_irq_enable();
>  }
>  
> -static inline void preempt_conditional_sti(struct pt_regs *regs)
> +static inline void conditional_sti_ist(struct pt_regs *regs)
>  {
> +#ifdef CONFIG_X86_64
> +	/*
> +	 * X86_64 uses a per CPU stack on the IST for certain traps
> +	 * like int3. The task can not be preempted when using one
> +	 * of these stacks, thus preemption must be disabled, otherwise
> +	 * the stack can be corrupted if the task is scheduled out,
> +	 * and another task comes in and uses this stack.
> +	 *
> +	 * On x86_32 the task keeps its own stack and it is OK if the
> +	 * task schedules out.
> +	 */
>  	inc_preempt_count();
> +#endif
>  	if (regs->flags & X86_EFLAGS_IF)
>  		local_irq_enable();
>  }
> @@ -100,11 +112,13 @@ static inline void conditional_cli(struc
>  		local_irq_disable();
>  }
>  
> -static inline void preempt_conditional_cli(struct pt_regs *regs)
> +static inline void conditional_cli_ist(struct pt_regs *regs)
>  {
>  	if (regs->flags & X86_EFLAGS_IF)
>  		local_irq_disable();
> +#ifdef CONFIG_X86_64
>  	dec_preempt_count();
> +#endif
>  }
>  
>  static void __kprobes
> @@ -222,9 +236,9 @@ dotraplinkage void do_stack_segment(stru
>  	if (notify_die(DIE_TRAP, "stack segment", regs, error_code,
>  			12, SIGBUS) == NOTIFY_STOP)
>  		return;
> -	preempt_conditional_sti(regs);
> +	conditional_sti_ist(regs);
>  	do_trap(12, SIGBUS, "stack segment", regs, error_code, NULL);
> -	preempt_conditional_cli(regs);
> +	conditional_cli_ist(regs);
>  }
>  
>  dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
> @@ -316,9 +330,9 @@ dotraplinkage void __kprobes do_int3(str
>  		return;
>  #endif
>  
> -	preempt_conditional_sti(regs);
> +	conditional_sti_ist(regs);
>  	do_trap(3, SIGTRAP, "int3", regs, error_code, NULL);
> -	preempt_conditional_cli(regs);
> +	conditional_cli_ist(regs);
>  }
>  
>  #ifdef CONFIG_X86_64
> @@ -412,12 +426,12 @@ dotraplinkage void __kprobes do_debug(st
>  		return;
>  
>  	/* It's safe to allow irq's after DR6 has been saved */
> -	preempt_conditional_sti(regs);
> +	conditional_sti_ist(regs);
>  
>  	if (regs->flags & X86_VM_MASK) {
>  		handle_vm86_trap((struct kernel_vm86_regs *) regs,
>  				error_code, 1);
> -		preempt_conditional_cli(regs);
> +		conditional_cli_ist(regs);
>  		return;
>  	}
>  
> @@ -436,7 +450,7 @@ dotraplinkage void __kprobes do_debug(st
>  	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);
> +	conditional_cli_ist(regs);
>  
>  	return;
>  }
> 


-- 
Masami HIRAMATSU
Software Platform Research Dept. Linux Technology Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: masami.hiramatsu.pt@hitachi.com

  reply	other threads:[~2012-02-02  2:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-01 21:06 [PATCH RT 0/2 v3] preempt-rt/x86: Handle sending signals from do_trap() by gdb Steven Rostedt
2012-02-01 21:06 ` [PATCH RT 1/2 v3] x86: Do not disable preemption in int3 on 32bit Steven Rostedt
2012-02-02  2:24   ` Masami Hiramatsu [this message]
2012-02-01 21:06 ` [PATCH RT 2/2 v3] preempt-rt/x86: Delay calling signals in int3 Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4F29F3F7.5000802@hitachi.com \
    --to=masami.hiramatsu.pt@hitachi.com \
    --cc=C.Emde@osadl.org \
    --cc=ak@linux.intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=heukelum@fastmail.fm \
    --cc=hpa@zytor.com \
    --cc=jkacur@redhat.com \
    --cc=lgoncalv@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=oleg@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=williams@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.