Re: [PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe

2015-08-22 Thread Ingo Molnar
* Andy Lutomirski wrote: > On Wed, Aug 5, 2015 at 11:27 AM, Steven Rostedt wrote: > > On Wed, 5 Aug 2015 11:24:54 -0700 > > Andy Lutomirski wrote: > > > >> On Wed, Aug 5, 2015 at 1:59 AM, Ingo Molnar wrote: > >> > > >> > * Andy Lutomirski wrote: > >> > > >> >> ---

Re: [PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe

2015-08-22 Thread Ingo Molnar
* Andy Lutomirski l...@amacapital.net wrote: On Wed, Aug 5, 2015 at 11:27 AM, Steven Rostedt rost...@goodmis.org wrote: On Wed, 5 Aug 2015 11:24:54 -0700 Andy Lutomirski l...@amacapital.net wrote: On Wed, Aug 5, 2015 at 1:59 AM, Ingo Molnar mi...@kernel.org wrote: * Andy

Re: [PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe

2015-08-05 Thread Andy Lutomirski
On Wed, Aug 5, 2015 at 11:27 AM, Steven Rostedt wrote: > On Wed, 5 Aug 2015 11:24:54 -0700 > Andy Lutomirski wrote: > >> On Wed, Aug 5, 2015 at 1:59 AM, Ingo Molnar wrote: >> > >> > * Andy Lutomirski wrote: >> > >> >> --- a/arch/x86/kernel/process_64.c >> >> +++ b/arch/x86/kernel/process_64.c

Re: [PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe

2015-08-05 Thread Steven Rostedt
On Wed, 5 Aug 2015 11:24:54 -0700 Andy Lutomirski wrote: > On Wed, Aug 5, 2015 at 1:59 AM, Ingo Molnar wrote: > > > > * Andy Lutomirski wrote: > > > >> --- a/arch/x86/kernel/process_64.c > >> +++ b/arch/x86/kernel/process_64.c > >> @@ -280,6 +280,10 @@ __switch_to(struct task_struct *prev_p,

Re: [PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe

2015-08-05 Thread Andy Lutomirski
On Wed, Aug 5, 2015 at 1:59 AM, Ingo Molnar wrote: > > * Andy Lutomirski wrote: > >> --- a/arch/x86/kernel/process_64.c >> +++ b/arch/x86/kernel/process_64.c >> @@ -280,6 +280,10 @@ __switch_to(struct task_struct *prev_p, struct >> task_struct *next_p) >> unsigned fsindex, gsindex; >>

Re: [PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe

2015-08-05 Thread Ingo Molnar
* Andy Lutomirski wrote: > --- a/arch/x86/kernel/process_64.c > +++ b/arch/x86/kernel/process_64.c > @@ -280,6 +280,10 @@ __switch_to(struct task_struct *prev_p, struct > task_struct *next_p) > unsigned fsindex, gsindex; > fpu_switch_t fpu_switch; > > +#ifdef CONFIG_DEBUG_ENTRY >

Re: [PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe

2015-08-05 Thread Ingo Molnar
* Andy Lutomirski l...@kernel.org wrote: --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -280,6 +280,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p) unsigned fsindex, gsindex; fpu_switch_t fpu_switch; +#ifdef

Re: [PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe

2015-08-05 Thread Andy Lutomirski
On Wed, Aug 5, 2015 at 1:59 AM, Ingo Molnar mi...@kernel.org wrote: * Andy Lutomirski l...@kernel.org wrote: --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -280,6 +280,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p) unsigned

Re: [PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe

2015-08-05 Thread Steven Rostedt
On Wed, 5 Aug 2015 11:24:54 -0700 Andy Lutomirski l...@amacapital.net wrote: On Wed, Aug 5, 2015 at 1:59 AM, Ingo Molnar mi...@kernel.org wrote: * Andy Lutomirski l...@kernel.org wrote: --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -280,6 +280,10 @@

Re: [PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe

2015-08-05 Thread Andy Lutomirski
On Wed, Aug 5, 2015 at 11:27 AM, Steven Rostedt rost...@goodmis.org wrote: On Wed, 5 Aug 2015 11:24:54 -0700 Andy Lutomirski l...@amacapital.net wrote: On Wed, Aug 5, 2015 at 1:59 AM, Ingo Molnar mi...@kernel.org wrote: * Andy Lutomirski l...@kernel.org wrote: ---

Re: [PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe

2015-07-25 Thread Linus Torvalds
On Sat, Jul 25, 2015 at 10:59 AM, Andy Lutomirski wrote: > > What if we added something like: > > if (regs->ip == ret_after_sti && !user_mode(regs) && (regs->flags & > X86_EFLAGS_IF)) { > regs->ip--; > regs->flags &= ~X86_EFLAGS_IF; > } > > to do_nmi, do_machine_check, and do_debug (the

Re: [PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe

2015-07-25 Thread Andy Lutomirski
On Sat, Jul 25, 2015 at 10:56 AM, Linus Torvalds wrote: > On Fri, Jul 24, 2015 at 9:59 PM, Andy Lutomirski wrote: >> >> And people will give me five new heads if I ignore Linus and do RET >> even with IF=1, saving 300 cycles? > > So I'm still nervous about that "sti; ret" when we're back on the

Re: [PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe

2015-07-25 Thread Linus Torvalds
On Fri, Jul 24, 2015 at 9:59 PM, Andy Lutomirski wrote: > > And people will give me five new heads if I ignore Linus and do RET > even with IF=1, saving 300 cycles? So I'm still nervous about that "sti; ret" when we're back on the original kernel stack that took the original fault or interrupt.

Re: [PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe

2015-07-25 Thread Borislav Petkov
On Fri, Jul 24, 2015 at 09:59:16PM -0700, Andy Lutomirski wrote: > And people will give me five new heads if I ignore Linus and do RET > even with IF=1, saving 300 cycles? As long as you don't make it too complex and corner-casy, I'll give you hats for those heads. -- Regards/Gruss, Boris.

Re: [PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe

2015-07-25 Thread Borislav Petkov
On Fri, Jul 24, 2015 at 09:59:16PM -0700, Andy Lutomirski wrote: And people will give me five new heads if I ignore Linus and do RET even with IF=1, saving 300 cycles? As long as you don't make it too complex and corner-casy, I'll give you hats for those heads. -- Regards/Gruss, Boris.

Re: [PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe

2015-07-25 Thread Andy Lutomirski
On Sat, Jul 25, 2015 at 10:56 AM, Linus Torvalds torva...@linux-foundation.org wrote: On Fri, Jul 24, 2015 at 9:59 PM, Andy Lutomirski l...@amacapital.net wrote: And people will give me five new heads if I ignore Linus and do RET even with IF=1, saving 300 cycles? So I'm still nervous about

Re: [PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe

2015-07-25 Thread Linus Torvalds
On Fri, Jul 24, 2015 at 9:59 PM, Andy Lutomirski l...@amacapital.net wrote: And people will give me five new heads if I ignore Linus and do RET even with IF=1, saving 300 cycles? So I'm still nervous about that sti; ret when we're back on the original kernel stack that took the original fault

Re: [PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe

2015-07-25 Thread Linus Torvalds
On Sat, Jul 25, 2015 at 10:59 AM, Andy Lutomirski l...@amacapital.net wrote: What if we added something like: if (regs-ip == ret_after_sti !user_mode(regs) (regs-flags X86_EFLAGS_IF)) { regs-ip--; regs-flags = ~X86_EFLAGS_IF; } to do_nmi, do_machine_check, and do_debug (the latter

Re: [PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe

2015-07-24 Thread Andy Lutomirski
On Fri, Jul 24, 2015 at 9:32 PM, Borislav Petkov wrote: > On Fri, Jul 24, 2015 at 09:28:47PM -0700, Andy Lutomirski wrote: >> Yeah, I'm going to submit v2 with the simple approach. I admit I'm >> rather fond of xadd as a way to switch rsp and set a flag at the same >> time, though :) > > I know

Re: [PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe

2015-07-24 Thread Borislav Petkov
On Fri, Jul 24, 2015 at 09:28:47PM -0700, Andy Lutomirski wrote: > Yeah, I'm going to submit v2 with the simple approach. I admit I'm > rather fond of xadd as a way to switch rsp and set a flag at the same > time, though :) I know you are. But people will rip your head out if you added 60

Re: [PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe

2015-07-24 Thread Andy Lutomirski
On Fri, Jul 24, 2015 at 9:16 PM, Borislav Petkov wrote: > On Fri, Jul 24, 2015 at 11:02:51AM -0700, Andy Lutomirski wrote: >> So really the only difference between this simple approach (which is >> more or less what we do now) and my fancy approach is that a kernel >> instruction breakpoint will

Re: [PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe

2015-07-24 Thread Borislav Petkov
On Fri, Jul 24, 2015 at 11:02:51AM -0700, Andy Lutomirski wrote: > So really the only difference between this simple approach (which is > more or less what we do now) and my fancy approach is that a kernel > instruction breakpoint will cause do_debug to run on the initial stack > instead of the

Re: [PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe

2015-07-24 Thread Andy Lutomirski
On Fri, Jul 24, 2015 at 3:25 AM, Borislav Petkov wrote: > On Thu, Jul 23, 2015 at 11:08:39PM -0700, Andy Lutomirski wrote: >> To be obviously safe against any local exception, we want a single >> instruction that will change %rsp and some in-memory flag at the same >> time. There aren't a whole

Re: [PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe

2015-07-24 Thread Borislav Petkov
On Thu, Jul 23, 2015 at 11:08:39PM -0700, Andy Lutomirski wrote: > To be obviously safe against any local exception, we want a single > instruction that will change %rsp and some in-memory flag at the same > time. There aren't a whole lot of candidates. Cmpxchg isn't useful > (cmpxchg with a

Re: [PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe

2015-07-24 Thread Andy Lutomirski
On Thu, Jul 23, 2015 at 3:37 PM, Andy Lutomirski wrote: > This will allow IRQ stacks to nest inside NMIs or similar entries > that can happen during IRQ stack setup or teardown. > > The Xen code here has a confusing comment. > > Signed-off-by: Andy Lutomirski > --- > arch/x86/entry/entry_64.S

Re: [PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe

2015-07-24 Thread Andy Lutomirski
On Thu, Jul 23, 2015 at 3:37 PM, Andy Lutomirski l...@kernel.org wrote: This will allow IRQ stacks to nest inside NMIs or similar entries that can happen during IRQ stack setup or teardown. The Xen code here has a confusing comment. Signed-off-by: Andy Lutomirski l...@kernel.org ---

Re: [PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe

2015-07-24 Thread Borislav Petkov
On Thu, Jul 23, 2015 at 11:08:39PM -0700, Andy Lutomirski wrote: To be obviously safe against any local exception, we want a single instruction that will change %rsp and some in-memory flag at the same time. There aren't a whole lot of candidates. Cmpxchg isn't useful (cmpxchg with a memory

Re: [PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe

2015-07-24 Thread Andy Lutomirski
On Fri, Jul 24, 2015 at 3:25 AM, Borislav Petkov b...@alien8.de wrote: On Thu, Jul 23, 2015 at 11:08:39PM -0700, Andy Lutomirski wrote: To be obviously safe against any local exception, we want a single instruction that will change %rsp and some in-memory flag at the same time. There aren't a

Re: [PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe

2015-07-24 Thread Borislav Petkov
On Fri, Jul 24, 2015 at 11:02:51AM -0700, Andy Lutomirski wrote: So really the only difference between this simple approach (which is more or less what we do now) and my fancy approach is that a kernel instruction breakpoint will cause do_debug to run on the initial stack instead of the IRQ

Re: [PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe

2015-07-24 Thread Andy Lutomirski
On Fri, Jul 24, 2015 at 9:16 PM, Borislav Petkov b...@alien8.de wrote: On Fri, Jul 24, 2015 at 11:02:51AM -0700, Andy Lutomirski wrote: So really the only difference between this simple approach (which is more or less what we do now) and my fancy approach is that a kernel instruction

Re: [PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe

2015-07-24 Thread Borislav Petkov
On Fri, Jul 24, 2015 at 09:28:47PM -0700, Andy Lutomirski wrote: Yeah, I'm going to submit v2 with the simple approach. I admit I'm rather fond of xadd as a way to switch rsp and set a flag at the same time, though :) I know you are. But people will rip your head out if you added 60 cycles

Re: [PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe

2015-07-24 Thread Andy Lutomirski
On Fri, Jul 24, 2015 at 9:32 PM, Borislav Petkov b...@alien8.de wrote: On Fri, Jul 24, 2015 at 09:28:47PM -0700, Andy Lutomirski wrote: Yeah, I'm going to submit v2 with the simple approach. I admit I'm rather fond of xadd as a way to switch rsp and set a flag at the same time, though :) I

[PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe

2015-07-23 Thread Andy Lutomirski
This will allow IRQ stacks to nest inside NMIs or similar entries that can happen during IRQ stack setup or teardown. The Xen code here has a confusing comment. Signed-off-by: Andy Lutomirski --- arch/x86/entry/entry_64.S| 72 ++--

[PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe

2015-07-23 Thread Andy Lutomirski
This will allow IRQ stacks to nest inside NMIs or similar entries that can happen during IRQ stack setup or teardown. The Xen code here has a confusing comment. Signed-off-by: Andy Lutomirski l...@kernel.org --- arch/x86/entry/entry_64.S| 72 ++--