x86/entry: Entry/exception code rework, simple exceptions
Subsystems (6)
v4 cover x86/entry: Entry/exception code rework, simple exceptions
Folks,
This is the third part of the rework series. Part 2 can be found here:
https://lore.kernel.org/r/[email protected]
The series has a total of 138 patches and is split into 5 parts. The base for this 3rd series is:
git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git entry-v4-part-2
The full series with all parts applied is available here:
git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git entry-v4-part-5
The third part, i.e. this series is available from:
git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git entry-v4-part-3
This part contains the modifications for the simple exceptions and traps:
- Preparatory changes and simplifications moving especially tracing affected code out of ASM
- Distangle the unreadable idtentry maze on 64bit
- Provide C entry/exit functions which handle the transitions vs. RCU, context tracking and instrumentation.
- Provide a set of macros to define and declare exception and trap handlers
The macros generate:
- The prototypes for the relevant C, ASM and XEN/PV functions
- C wrappers for the actual handler code which contain all the necessary entry handling
- Automatic emission of the low level ASM entry code
- Converting the trivial exceptions over to the new scheme
The objtool check for the noinstr.text correctness is not yet added to the build machinery and has to be invoked manually for now:
objtool check -fal vmlinux.o
The checking only works for builtin code as objtool cannot do a combined analysis of vmlinux.o and a module.o
Thanks,
tglx
8<----------
arch/x86/entry/common.c | 90 +++++++ arch/x86/entry/entry_32.S | 188 ++++++--------- arch/x86/entry/entry_64.S | 436 +++++++++++++++++++---------------- arch/x86/include/asm/idtentry.h | 153 ++++++++++++ arch/x86/include/asm/special_insns.h | 14 - arch/x86/include/asm/trapnr.h | 31 ++ arch/x86/include/asm/traps.h | 76 ------ arch/x86/kernel/idt.c | 28 +- arch/x86/kernel/traps.c | 184 +++++++++----- arch/x86/mm/fault.c | 17 + arch/x86/xen/enlighten_pv.c | 33 +- arch/x86/xen/xen-asm_32.S | 2 arch/x86/xen/xen-asm_64.S | 28 +- include/linux/rcutiny.h | 1 include/linux/rcutree.h | 1 kernel/rcu/tree.c | 21 + 16 files changed, 808 insertions(+), 495 deletions(-)
PATCH v4 1/29 x86/traps: Mark fixup_bad_iret() noinstr
This is called from deep entry ASM in a situation where instrumentation will cause more harm than providing useful information.
--- arch/x86/kernel/traps.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
arch/x86/kernel/traps.c +9 -7
@@ -621,7 +621,7 @@ struct bad_iret_stack {struct pt_regs regs; }; -asmlinkage __visible notrace +asmlinkage __visible noinstrstruct bad_iret_stack *fixup_bad_iret (struct bad_iret_stack *s) {/*
@@ -632,19 +632,21 @@ struct bad_iret_stack *fixup_bad_iret(st* just below the IRET frame) and we want to pretend that the * exception came from the IRET target. */ -struct bad_iret_stack *new_stack = - (struct bad_iret_stack *)this_cpu_read (cpu_tss_rw.x86_tss.sp0) -1 ; +struct bad_iret_stack tmp, *new_stack = + (struct bad_iret_stack *)__this_cpu_read (cpu_tss_rw.x86_tss.sp0) -1 ; -/* Copy the IRET target to the new stack. */ -memmove (&new_stack->regs.ip, (void *)s->regs.sp,5 *8 ); +/* Copy the IRET target to the temporary storage. */ +memcpy (&tmp.regs.ip, (void *)s->regs.sp,5 *8 );/* Copy the remainder of the stack from the current stack. */ - memmove(new_stack, s, offsetof(struct bad_iret_stack, regs.ip)); + memcpy(&tmp, s, offsetof(struct bad_iret_stack, regs.ip)); + +/* Update the entry stack */ +memcpy (new_stack, &tmp,sizeof (tmp));BUG_ON (!user_mode (&new_stack->regs)); return new_stack; } -NOKPROBE_SYMBOL (fixup_bad_iret);#endif static bool is_sysenter_singlestep (struct pt_regs *regs)
Re: [patch V4 part 3 01/29] x86/traps: Mark fixup_bad_iret() noinstr
Quoted 4 lines · Thomas Gleixner
This is called from deep entry ASM in a situation where instrumentation will cause more harm than providing useful information.
Maybe add to changelog:
Switch from memmove() to memcpy() because memmove() can't be called from noinstr code.
Steven Rostedt
reviewerRe: [patch V4 part 3 01/29] x86/traps: Mark fixup_bad_iret() noinstr
Quoted 6 lines · On Fri, 8 May 2020 17:39:00 -0700 Andy Lutomirski <[email protected]> wrote:
Quoted 4 lines · Thomas Gleixner
This is called from deep entry ASM in a situation where instrumentation will cause more harm than providing useful information.
Quoted 6 lines
Acked-by Andy Lutomirski <[email protected]>Maybe add to changelog:
Switch from
memmove()tomemcpy()becausememmove()can't be called from noinstr code.
Yes please, because I was about to say that there was changes that didn't seem to fit the change log.
I would also add a comment in the code saying that we need the temp variable to use memcpy as memmove can't be used in noinstr code.
-- Steve
Mathieu Desnoyers
reviewerRe: [patch V4 part 3 01/29] x86/traps: Mark fixup_bad_iret() noinstr
Quoted 13 lines · ----- On May 12, 2020, at 9:51 PM, rostedt [email protected] wrote:
Quoted 10 lines · On Fri, 8 May 2020 17:39:00 -0700 Andy Lutomirski <[email protected]> wrote:
Quoted 4 lines · Thomas Gleixner
This is called from deep entry ASM in a situation where instrumentation will cause more harm than providing useful information.
Acked-by Andy Lutomirski <[email protected]>Maybe add to changelog:
Quoted 8 lines
Quoted 2 lines
Switch from
memmove()tomemcpy()becausememmove()can't be called from noinstr code.Yes please, because I was about to say that there was changes that didn't seem to fit the change log.
I would also add a comment in the code saying that we need the temp variable to use memcpy as memmove can't be used in noinstr code.
Looking at an updated version of the tree, I see the acked-by from Andy, but not comment about switching from memmove to memcpy.
Also, I notice a significant undocumented change in this patch: it changes a this_cpu_read() (which presumes preemption is enabled) to a __this_cpu_read().
So the 100$ question: is preemption enabled or not in fixup_bad_iret() ? And of course that change should be documented in the commit message.
Thanks,
Mathieu
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com
Re: [patch V4 part 3 01/29] x86/traps: Mark fixup_bad_iret() noinstr
Quoted 28 lines · Mathieu Desnoyers
Quoted 13 lines · ----- On May 12, 2020, at 9:51 PM, rostedt [email protected] wrote:
Quoted 13 lines
On Fri, 8 May 2020 17:39:00 -0700
Andy Lutomirski <[email protected]> wrote:Quoted 4 lines · Thomas Gleixner
This is called from deep entry ASM in a situation where instrumentation will cause more harm than providing useful information.
Acked-by Andy Lutomirski <[email protected]>Maybe add to changelog:
Quoted 8 lines
Quoted 2 lines
Switch from
memmove()tomemcpy()becausememmove()can't be called from noinstr code.Yes please, because I was about to say that there was changes that didn't seem to fit the change log.
I would also add a comment in the code saying that we need the temp variable to use memcpy as memmove can't be used in noinstr code.
Quoted 9 lines
Looking at an updated version of the tree, I see the acked-by from Andy, but not comment about switching from memmove to memcpy.
Also, I notice a significant undocumented change in this patch: it changes a
this_cpu_read()(which presumes preemption is enabled) to a__this_cpu_read().So the 100$ question: is preemption enabled or not in
fixup_bad_iret()? And of course that change should be documented in the commit message.
IRQs are off, and, if they were on, the lack of a warning from the percpu access would be the least of our concerns here.
Quoted 8 lines
Thanks,
Mathieu
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com
Re: [patch V4 part 3 01/29] x86/traps: Mark fixup_bad_iret() noinstr
In reply to Thomas GleixnerQuoted 4 lines · On Tue, 05 May 2020 15:43:55 +0200 Thomas Gleixner <[email protected]> wrote:
This is called from deep entry ASM in a situation where instrumentation will cause more harm than providing useful information.
Signed-off-by Thomas Gleixner <[email protected]>
Looks good to me.
Thank you,
Quoted 44 lines
--- arch/x86/kernel/traps.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)arch/x86/kernel/traps.c +9
-7@@ -621,7 +621,7 @@ struct bad_iret_stack {struct pt_regs regs; }; -asmlinkage __visible notrace +asmlinkage __visible noinstrstruct bad_iret_stack *fixup_bad_iret (struct bad_iret_stack *s) {/* @@ -632,19 +632,21 @@ struct bad_iret_stack *fixup_bad_iret(st* just below the IRET frame) and we want to pretend that the * exception came from the IRET target. */ -struct bad_iret_stack *new_stack = - (struct bad_iret_stack *)this_cpu_read (cpu_tss_rw.x86_tss.sp0) -1 ; +struct bad_iret_stack tmp, *new_stack = + (struct bad_iret_stack *)__this_cpu_read (cpu_tss_rw.x86_tss.sp0) -1 ; -/* Copy the IRET target to the new stack. */ -memmove (&new_stack->regs.ip, (void *)s->regs.sp,5 *8 ); +/* Copy the IRET target to the temporary storage. */ +memcpy (&tmp.regs.ip, (void *)s->regs.sp,5 *8 );/* Copy the remainder of the stack from the current stack. */ - memmove(new_stack, s, offsetof(struct bad_iret_stack, regs.ip)); + memcpy(&tmp, s, offsetof(struct bad_iret_stack, regs.ip)); + +/* Update the entry stack */ +memcpy (new_stack, &tmp,sizeof (tmp));BUG_ON (!user_mode (&new_stack->regs)); return new_stack; } -NOKPROBE_SYMBOL (fixup_bad_iret);#endif static bool is_sysenter_singlestep (struct pt_regs *regs)
Signature · 1 line
Masami Hiramatsu <[email protected]>
[tip: x86/entry] x86/traps: Mark fixup_bad_iret() noinstr
In reply to Thomas GleixnerThe following commit has been merged into the x86/entry branch of tip:
The following commit has been merged into the x86/entry branch of tip:
Commit-ID: 68a05c6247d2aa67f5ada1009ffd19758e5914ea Gitweb: https://git.kernel.org/tip/68a05c6247d2aa67f5ada1009ffd19758e5914ea Author: Thomas Gleixner <[email protected]> AuthorDate: Wed, 25 Mar 2020 19:53:38 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 19 May 2020 16:03:52 +02:00
x86/traps: Mark fixup_bad_iret() noinstr
This is called from deep entry ASM in a situation where instrumentation will cause more harm than providing useful information.
Switch from memmove() to memcpy() because memmove() can't be called from noinstr code.
--- arch/x86/kernel/traps.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
arch/x86/kernel/traps.c +9 -7
@@ -578,7 +578,7 @@ struct bad_iret_stack {struct pt_regs regs; }; -asmlinkage __visible notrace +asmlinkage __visible noinstrstruct bad_iret_stack *fixup_bad_iret (struct bad_iret_stack *s) {/*
@@ -589,19 +589,21 @@ struct bad_iret_stack *fixup_bad_iret(struct bad_iret_stack *s)* just below the IRET frame) and we want to pretend that the * exception came from the IRET target. */ -struct bad_iret_stack *new_stack = - (struct bad_iret_stack *)this_cpu_read (cpu_tss_rw.x86_tss.sp0) -1 ; +struct bad_iret_stack tmp, *new_stack = + (struct bad_iret_stack *)__this_cpu_read (cpu_tss_rw.x86_tss.sp0) -1 ; -/* Copy the IRET target to the new stack. */ -memmove (&new_stack->regs.ip, (void *)s->regs.sp,5 *8 ); +/* Copy the IRET target to the temporary storage. */ +memcpy (&tmp.regs.ip, (void *)s->regs.sp,5 *8 );/* Copy the remainder of the stack from the current stack. */ - memmove(new_stack, s, offsetof(struct bad_iret_stack, regs.ip)); + memcpy(&tmp, s, offsetof(struct bad_iret_stack, regs.ip)); + +/* Update the entry stack */ +memcpy (new_stack, &tmp,sizeof (tmp));BUG_ON (!user_mode (&new_stack->regs)); return new_stack; } -NOKPROBE_SYMBOL (fixup_bad_iret);#endif static bool is_sysenter_singlestep (struct pt_regs *regs)
PATCH v4 2/29 x86/traps: Mark sync_regs() noinstr
In reply to Thomas GleixnerReplace the notrace and NOKPROBE annotations with noinstr.
--- arch/x86/kernel/traps.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/x86/kernel/traps.c +1 -2
@@ -639,14 +639,13 @@ NOKPROBE_SYMBOL(do_int3);* to switch to the normal thread stack if the interrupted code was in * user mode. The actual stack switch is done in entry_64.S */ -asmlinkage __visible notrace struct pt_regs *sync_regs(struct pt_regs *eregs) +asmlinkage __visible noinstr struct pt_regs *sync_regs(struct pt_regs *eregs) {struct pt_regs *regs = (struct pt_regs *)this_cpu_read (cpu_current_top_of_stack) -1 ;if (regs != eregs) *regs = *eregs;return regs; } -NOKPROBE_SYMBOL (sync_regs);struct bad_iret_stack {void *error_entry_ret;
Re: [patch V4 part 3 02/29] x86/traps: Mark sync_regs() noinstr
Quoted 4 lines · Thomas Gleixner
Replace the notrace and NOKPROBE annotations with noinstr.
Signed-off-by Thomas Gleixner <[email protected]>
Re: [patch V4 part 3 02/29] x86/traps: Mark sync_regs() noinstr
In reply to Thomas GleixnerQuoted 3 lines · On Tue, 05 May 2020 15:43:56 +0200 Thomas Gleixner <[email protected]> wrote:
Replace the notrace and NOKPROBE annotations with noinstr.
Signed-off-by Thomas Gleixner <[email protected]>
Looks good to me.
Thanks!
Quoted 23 lines
--- arch/x86/kernel/traps.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)arch/x86/kernel/traps.c +1
-2@@ -639,14 +639,13 @@ NOKPROBE_SYMBOL(do_int3);* to switch to the normal thread stack if the interrupted code was in * user mode. The actual stack switch is done in entry_64.S */ -asmlinkage __visible notrace struct pt_regs *sync_regs(struct pt_regs *eregs) +asmlinkage __visible noinstr struct pt_regs *sync_regs(struct pt_regs *eregs) {struct pt_regs *regs = (struct pt_regs *)this_cpu_read (cpu_current_top_of_stack) -1 ;if (regs != eregs) *regs = *eregs;return regs; } -NOKPROBE_SYMBOL (sync_regs);struct bad_iret_stack {void *error_entry_ret;
Signature · 1 line
Masami Hiramatsu <[email protected]>
[tip: x86/entry] x86/traps: Mark sync_regs() noinstr
In reply to Thomas GleixnerThe following commit has been merged into the x86/entry branch of tip:
The following commit has been merged into the x86/entry branch of tip:
Commit-ID: 2c14e64ca887fe55ba958376ef1e2d08e810b5e3 Gitweb: https://git.kernel.org/tip/2c14e64ca887fe55ba958376ef1e2d08e810b5e3 Author: Thomas Gleixner <[email protected]> AuthorDate: Wed, 25 Mar 2020 23:47:51 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 19 May 2020 16:03:53 +02:00
x86/traps: Mark sync_regs() noinstr
Replace the notrace and NOKPROBE annotations with noinstr.
--- arch/x86/kernel/traps.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/x86/kernel/traps.c +1 -2
@@ -564,14 +564,13 @@ NOKPROBE_SYMBOL(do_int3);* to switch to the normal thread stack if the interrupted code was in * user mode. The actual stack switch is done in entry_64.S */ -asmlinkage __visible notrace struct pt_regs *sync_regs(struct pt_regs *eregs) +asmlinkage __visible noinstr struct pt_regs *sync_regs(struct pt_regs *eregs) {struct pt_regs *regs = (struct pt_regs *)this_cpu_read (cpu_current_top_of_stack) -1 ;if (regs != eregs) *regs = *eregs;return regs; } -NOKPROBE_SYMBOL (sync_regs);struct bad_iret_stack {void *error_entry_ret;
PATCH v4 3/29 x86/entry: Disable interrupts for native_load_gs_index() in C code
In reply to Thomas GleixnerThere is absolutely no point in doing this in ASM code. Move it to C.
--- arch/x86/entry/entry_64.S | 19 +++++++------------ arch/x86/include/asm/special_insns.h | 14 ++++++++++++-- 2 files changed, 19 insertions(+), 14 deletions(-)
arch/x86/entry/entry_64.S +7 -12
@@ -1036,27 +1036,22 @@ idtentry alignment_check do_alignment_c idtentry simd_coprocessor_error do_simd_coprocessor_error has_error_code=0 - /* - * Reload gs selector with exception handling - * edi: new selector - */ +/* + * Reload gs selector with exception handling + * edi: new selector + */ .pushsection .text, "ax" -SYM_FUNC_START(native_load_gs_index) +SYM_FUNC_START(asm_native_load_gs_index) FRAME_BEGIN - pushfq - DISABLE_INTERRUPTS(CLBR_ANY & ~CLBR_RDI) - TRACE_IRQS_OFF SWAPGS .Lgs_change: movl %edi, %gs 2: ALTERNATIVE "", "mfence", X86_BUG_SWAPGS_FENCE SWAPGS - TRACE_IRQS_FLAGS (%rsp) - popfq FRAME_END ret -SYM_FUNC_END(native_load_gs_index) -EXPORT_SYMBOL(native_load_gs_index) +SYM_FUNC_END(asm_native_load_gs_index) +EXPORT_SYMBOL(asm_native_load_gs_index) .popsection _ASM_EXTABLE(.Lgs_change, .Lbad_gs)
arch/x86/include/asm/special_insns.h +12 -2
@@ -7,6 +7,7 @@#include <asm/nops.h> #include <asm/processor-flags.h> +#include <linux/irqflags.h> #include <linux/jump_label.h> /*
@@ -129,7 +130,16 @@ static inline void native_wbinvd(void) asmvolatile ("wbinvd" : : :"memory" ); } -extern asmlinkage void native_load_gs_index(unsigned); +extern asmlinkage void asm_native_load_gs_index(unsigned int selector); + +static inline void native_load_gs_index (unsigned int selector) +{ +unsigned long flags; + +local_irq_save (flags); +asm_native_load_gs_index (selector); +local_irq_restore (flags); +}static inline unsigned long __read_cr4 (void ) {
@@ -186,7 +196,7 @@ static inline void wbinvd(void)#ifdef CONFIG_X86_64 -static inline void load_gs_index (unsigned selector) +static inline void load_gs_index (unsigned int selector) {native_load_gs_index (selector); }
Re: [patch V4 part 3 03/29] x86/entry: Disable interrupts for native_load_gs_index() in C code
Quoted 3 lines · Thomas Gleixner
There is absolutely no point in doing this in ASM code. Move it to C.
[tip: x86/entry] x86/entry: Disable interrupts for native_load_gs_index() in C code
In reply to Thomas GleixnerThe following commit has been merged into the x86/entry branch of tip:
The following commit has been merged into the x86/entry branch of tip:
Commit-ID: 800c8a1afb8e9d71ffb1ff54d6a2cf5c45dc50b5 Gitweb: https://git.kernel.org/tip/800c8a1afb8e9d71ffb1ff54d6a2cf5c45dc50b5 Author: Thomas Gleixner <[email protected]> AuthorDate: Wed, 04 Mar 2020 23:32:15 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 19 May 2020 16:03:53 +02:00
x86/entry: Disable interrupts for native_load_gs_index() in C code
There is absolutely no point in doing this in ASM code. Move it to C.
--- arch/x86/entry/entry_64.S | 11 +++-------- arch/x86/include/asm/special_insns.h | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 10 deletions(-)
arch/x86/entry/entry_64.S +3 -8
@@ -1041,22 +1041,17 @@ idtentry simd_coprocessor_error do_simd_coprocessor_error has_error_code=0 * * Is in entry.text as it shouldn't be instrumented. */ -SYM_FUNC_START(native_load_gs_index) +SYM_FUNC_START(asm_load_gs_index) FRAME_BEGIN - pushfq - DISABLE_INTERRUPTS(CLBR_ANY & ~CLBR_RDI) - TRACE_IRQS_OFF SWAPGS .Lgs_change: movl %edi, %gs 2: ALTERNATIVE "", "mfence", X86_BUG_SWAPGS_FENCE SWAPGS - TRACE_IRQS_FLAGS (%rsp) - popfq FRAME_END ret -SYM_FUNC_END(native_load_gs_index) -EXPORT_SYMBOL(native_load_gs_index) +SYM_FUNC_END(asm_load_gs_index) +EXPORT_SYMBOL(asm_load_gs_index) _ASM_EXTABLE(.Lgs_change, .Lbad_gs) .section .fixup, "ax"
arch/x86/include/asm/special_insns.h +12 -2
@@ -7,6 +7,7 @@#include <asm/nops.h> #include <asm/processor-flags.h> +#include <linux/irqflags.h> #include <linux/jump_label.h> /*
@@ -129,7 +130,16 @@ static inline void native_wbinvd(void) asmvolatile ("wbinvd" : : :"memory" ); } -extern asmlinkage void native_load_gs_index(unsigned); +extern asmlinkage void asm_load_gs_index(unsigned int selector); + +static inline void native_load_gs_index (unsigned int selector) +{ +unsigned long flags; + +local_irq_save (flags); +asm_load_gs_index (selector); +local_irq_restore (flags); +}static inline unsigned long __read_cr4 (void ) {
@@ -186,7 +196,7 @@ static inline void wbinvd(void)#ifdef CONFIG_X86_64 -static inline void load_gs_index (unsigned selector) +static inline void load_gs_index (unsigned int selector) {native_load_gs_index (selector); }
PATCH v4 4/29 x86/traps: Make interrupt enable/disable symmetric in C code
In reply to Thomas GleixnerTraps enable interrupts conditionally but rely on the ASM return code to disable them again. That results in redundant interrupt disable and trace calls.
Make the trap handlers disable interrupts before returning to avoid that, which allows simplification of the ASM entry code.
--- arch/x86/kernel/traps.c | 28 +++++++++++++++++++--------- arch/x86/mm/fault.c | 15 +++++++++++++-- 2 files changed, 32 insertions(+), 11 deletions(-)
arch/x86/kernel/traps.c +19 -9
@@ -201,6 +201,7 @@ static void do_error_trap(struct pt_regs NOTIFY_STOP) {cond_local_irq_enable (regs);do_trap (trapnr, signr, str, regs, error_code, sicode, addr); +cond_local_irq_disable (regs); } }
@@ -399,6 +400,8 @@ dotraplinkage void do_bounds(struct pt_rdie ("bounds" , regs, error_code);do_trap (X86_TRAP_BR ,SIGSEGV ,"bounds" , regs, error_code,0 ,NULL ); + +cond_local_irq_disable (regs); }enum kernel_gp_hint {
@@ -458,12 +461,13 @@ dotraplinkage void do_general_protectionif (static_cpu_has (X86_FEATURE_UMIP )) {if (user_mode (regs) &&fixup_umip_exception (regs)) -return ; + goto exit; }if (v8086_mode (regs)) {local_irq_enable ();handle_vm86_fault ((struct kernel_vm86_regs *) regs, error_code); +local_irq_disable ();return ; }
@@ -475,12 +479,11 @@ dotraplinkage void do_general_protectionshow_signal (tsk,SIGSEGV ,"" , desc, regs, error_code);force_sig (SIGSEGV ); - -return ; + goto exit; }if (fixup_exception (regs,X86_TRAP_GP , error_code,0 )) -return ; + goto exit; tsk->thread.error_code = error_code; tsk->thread.trap_nr =X86_TRAP_GP ;
@@ -492,11 +495,11 @@ dotraplinkage void do_general_protectionif (!preemptible () &&kprobe_running () &&kprobe_fault_handler (regs,X86_TRAP_GP )) -return ; + goto exit; ret =notify_die (DIE_GPF , desc, regs, error_code,X86_TRAP_GP ,SIGSEGV );if (ret ==NOTIFY_STOP ) -return ; + goto exit;if (error_code)snprintf (desc,sizeof (desc),"segment-related " GPFSTR );
@@ -518,6 +521,8 @@ dotraplinkage void do_general_protectiondie_addr (desc, regs, error_code, gp_addr); +exit: +cond_local_irq_disable (regs); }NOKPROBE_SYMBOL (do_general_protection);
@@ -775,7 +780,7 @@ static void math_error(struct pt_regs *rif (!user_mode (regs)) {if (fixup_exception (regs, trapnr, error_code,0 )) -return ; + goto exit; task->thread.error_code = error_code; task->thread.trap_nr = trapnr;
@@ -783,7 +788,7 @@ static void math_error(struct pt_regs *rif (notify_die (DIE_TRAP , str, regs, error_code, trapnr,SIGFPE ) !=NOTIFY_STOP )die (str, regs, error_code); -return ; + goto exit; }/*
@@ -797,10 +802,12 @@ static void math_error(struct pt_regs *r si_code =fpu__exception_code (fpu, trapnr);/* Retry when we get spurious exceptions: */ if (!si_code) -return ; + goto exit;force_sig_fault (SIGFPE , si_code, (void __user *)uprobe_get_trap_addr (regs)); +exit: +cond_local_irq_disable (regs); } dotraplinkage void do_coprocessor_error(struct pt_regs *regs, long error_code)
@@ -855,6 +862,8 @@ do_device_not_available(struct pt_regs * info.regs = regs;math_emulate (&info); + +cond_local_irq_disable (regs); return; }#endif
@@ -885,6 +894,7 @@ dotraplinkage void do_iret_error(structdo_trap (X86_TRAP_IRET ,SIGILL ,"iret exception" , regs, error_code, ILL_BADSTK, (void __user *)NULL); } +local_irq_disable (); }#endif
arch/x86/mm/fault.c +13 -2
@@ -927,6 +927,8 @@ static voidforce_sig_fault (SIGSEGV , si_code, (void __user *)address); +local_irq_disable (); +return ; }
@@ -1548,9 +1550,18 @@ do_page_fault(struct pt_regs *regs, unsireturn ;/* Was the fault on kernel-controlled part of the address space? */ -if (unlikely (fault_in_kernel_space (address))) +if (unlikely (fault_in_kernel_space (address))) {do_kern_addr_fault (regs, hw_error_code, address); -else + }else {do_user_addr_fault (regs, hw_error_code, address); +/* +* User address page fault handling might have reenabled +* interrupts. Fixing up all potential exit points of +* do_user_addr_fault() and its leaf functions is just not +* doable w/o creating an unholy mess or turning the code +* upside down. +*/ +local_irq_disable (); + } }NOKPROBE_SYMBOL (do_page_fault);
Re: [patch V4 part 3 04/29] x86/traps: Make interrupt enable/disable symmetric in C code
Quoted 7 lines · Thomas Gleixner
Traps enable interrupts conditionally but rely on the ASM return code to disable them again. That results in redundant interrupt disable and trace calls.
Make the trap handlers disable interrupts before returning to avoid that, which allows simplification of the ASM entry code.
Quoted 8 lines
Originally-by Peter Zijlstra <[email protected]>Signed-off-by Thomas Gleixner <[email protected]>--- arch/x86/kernel/traps.c | 28 +++++++++++++++++++--------- arch/x86/mm/fault.c | 15 +++++++++++++-- 2 files changed, 32 insertions(+), 11 deletions(-)
So this patch makes C trap handlers disable interrupts on return but there's no change to the ASM entry code, which will still (also) disable interrupts. I suppose this is cleaned up in a next patch. So it's worth mentioning that the "simplification of the ASM entry code" is not in this patch.
alex.
Re: [patch V4 part 3 04/29] x86/traps: Make interrupt enable/disable symmetric in C code
Quoted 17 lines · Alexandre Chartre
Quoted 7 lines · Thomas Gleixner
Traps enable interrupts conditionally but rely on the ASM return code to disable them again. That results in redundant interrupt disable and trace calls.
Make the trap handlers disable interrupts before returning to avoid that, which allows simplification of the ASM entry code.
Quoted 8 lines
Originally-by Peter Zijlstra <[email protected]>Signed-off-by Thomas Gleixner <[email protected]>--- arch/x86/kernel/traps.c | 28 +++++++++++++++++++--------- arch/x86/mm/fault.c | 15 +++++++++++++-- 2 files changed, 32 insertions(+), 11 deletions(-)
Quoted 4 lines
So this patch makes C trap handlers disable interrupts on return but there's no change to the ASM entry code, which will still (also) disable interrupts. I suppose this is cleaned up in a next patch. So it's worth mentioning that the "simplification of the ASM entry code" is not in this patch.
I thought that was expressed by:
Quoted 1 line
Quoted 1 line
which allows simplification of the ASM entry code.
but yeah it's ambigous. Will clarify.
Thanks,
tglx
Re: [patch V4 part 3 04/29] x86/traps: Make interrupt enable/disable symmetric in C code
In reply to Thomas GleixnerQuoted 7 lines · Thomas Gleixner
Traps enable interrupts conditionally but rely on the ASM return code to disable them again. That results in redundant interrupt disable and trace calls.
Make the trap handlers disable interrupts before returning to avoid that, which allows simplification of the ASM entry code.
And thanks! This has bothered me forever.
[tip: x86/entry] x86/traps: Make interrupt enable/disable symmetric in C code
In reply to Thomas GleixnerThe following commit has been merged into the x86/entry branch of tip:
The following commit has been merged into the x86/entry branch of tip:
Commit-ID: 1b208500418d351c476e173f2e4bebaaf0959ef0 Gitweb: https://git.kernel.org/tip/1b208500418d351c476e173f2e4bebaaf0959ef0 Author: Thomas Gleixner <[email protected]> AuthorDate: Wed, 23 Oct 2019 14:27:10 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 19 May 2020 16:03:54 +02:00
x86/traps: Make interrupt enable/disable symmetric in C code
Traps enable interrupts conditionally but rely on the ASM return code to disable them again. That results in redundant interrupt disable and trace calls.
Make the trap handlers disable interrupts before returning to avoid that, which allows simplification of the ASM entry code in follow up changes.
--- arch/x86/kernel/traps.c | 28 +++++++++++++++++++--------- arch/x86/mm/fault.c | 15 +++++++++++++-- 2 files changed, 32 insertions(+), 11 deletions(-)
arch/x86/kernel/traps.c +19 -9
@@ -201,6 +201,7 @@ static void do_error_trap(struct pt_regs *regs, long error_code, char *str, NOTIFY_STOP) {cond_local_irq_enable (regs);do_trap (trapnr, signr, str, regs, error_code, sicode, addr); +cond_local_irq_disable (regs); } }
@@ -397,6 +398,8 @@ dotraplinkage void do_bounds(struct pt_regs *regs, long error_code)die ("bounds" , regs, error_code);do_trap (X86_TRAP_BR ,SIGSEGV ,"bounds" , regs, error_code,0 ,NULL ); + +cond_local_irq_disable (regs); }enum kernel_gp_hint {
@@ -456,12 +459,13 @@ dotraplinkage void do_general_protection(struct pt_regs *regs, long error_code)if (static_cpu_has (X86_FEATURE_UMIP )) {if (user_mode (regs) &&fixup_umip_exception (regs)) -return ; + goto exit; }if (v8086_mode (regs)) {local_irq_enable ();handle_vm86_fault ((struct kernel_vm86_regs *) regs, error_code); +local_irq_disable ();return ; }
@@ -473,12 +477,11 @@ dotraplinkage void do_general_protection(struct pt_regs *regs, long error_code)show_signal (tsk,SIGSEGV ,"" , desc, regs, error_code);force_sig (SIGSEGV ); - -return ; + goto exit; }if (fixup_exception (regs,X86_TRAP_GP , error_code,0 )) -return ; + goto exit; tsk->thread.error_code = error_code; tsk->thread.trap_nr =X86_TRAP_GP ;
@@ -490,11 +493,11 @@ dotraplinkage void do_general_protection(struct pt_regs *regs, long error_code)if (!preemptible () &&kprobe_running () &&kprobe_fault_handler (regs,X86_TRAP_GP )) -return ; + goto exit; ret =notify_die (DIE_GPF , desc, regs, error_code,X86_TRAP_GP ,SIGSEGV );if (ret ==NOTIFY_STOP ) -return ; + goto exit;if (error_code)snprintf (desc,sizeof (desc),"segment-related " GPFSTR );
@@ -516,6 +519,8 @@ dotraplinkage void do_general_protection(struct pt_regs *regs, long error_code)die_addr (desc, regs, error_code, gp_addr); +exit: +cond_local_irq_disable (regs); }NOKPROBE_SYMBOL (do_general_protection);
@@ -773,7 +778,7 @@ static void math_error(struct pt_regs *regs, int error_code, int trapnr)if (!user_mode (regs)) {if (fixup_exception (regs, trapnr, error_code,0 )) -return ; + goto exit; task->thread.error_code = error_code; task->thread.trap_nr = trapnr;
@@ -781,7 +786,7 @@ static void math_error(struct pt_regs *regs, int error_code, int trapnr)if (notify_die (DIE_TRAP , str, regs, error_code, trapnr,SIGFPE ) !=NOTIFY_STOP )die (str, regs, error_code); -return ; + goto exit; }/*
@@ -795,10 +800,12 @@ static void math_error(struct pt_regs *regs, int error_code, int trapnr) si_code =fpu__exception_code (fpu, trapnr);/* Retry when we get spurious exceptions: */ if (!si_code) -return ; + goto exit;force_sig_fault (SIGFPE , si_code, (void __user *)uprobe_get_trap_addr (regs)); +exit: +cond_local_irq_disable (regs); } dotraplinkage void do_coprocessor_error(struct pt_regs *regs, long error_code)
@@ -853,6 +860,8 @@ do_device_not_available(struct pt_regs *regs, long error_code) info.regs = regs;math_emulate (&info); + +cond_local_irq_disable (regs); return; }#endif
@@ -883,6 +892,7 @@ dotraplinkage void do_iret_error(struct pt_regs *regs, long error_code)do_trap (X86_TRAP_IRET ,SIGILL ,"iret exception" , regs, error_code, ILL_BADSTK, (void __user *)NULL); } +local_irq_disable (); }#endif
arch/x86/mm/fault.c +13 -2
@@ -927,6 +927,8 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,force_sig_fault (SIGSEGV , si_code, (void __user *)address); +local_irq_disable (); +return ; }
@@ -1548,9 +1550,18 @@ do_page_fault(struct pt_regs *regs, unsigned long hw_error_code,return ;/* Was the fault on kernel-controlled part of the address space? */ -if (unlikely (fault_in_kernel_space (address))) +if (unlikely (fault_in_kernel_space (address))) {do_kern_addr_fault (regs, hw_error_code, address); -else + }else {do_user_addr_fault (regs, hw_error_code, address); +/* +* User address page fault handling might have reenabled +* interrupts. Fixing up all potential exit points of +* do_user_addr_fault() and its leaf functions is just not +* doable w/o creating an unholy mess or turning the code +* upside down. +*/ +local_irq_disable (); + } }NOKPROBE_SYMBOL (do_page_fault);
PATCH v4 5/29 x86/traps: Split trap numbers out in a seperate header
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
So they can be used in ASM code. For this it is also necessary to convert them to defines. Will be used for the rework of the entry code.
--- arch/x86/include/asm/trapnr.h | 31 +++++++++++++++++++++++++++++++ arch/x86/include/asm/traps.h | 26 +------------------------- 2 files changed, 32 insertions(+), 25 deletions(-)
arch/x86/include/asm/trapnr.h new file +31 -0
@@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_X86_TRAPNR_H +#define _ASM_X86_TRAPNR_H + +/* Interrupts/Exceptions */ + +#define X86_TRAP_DE 0/* Divide-by-zero */ +#define X86_TRAP_DB 1/* Debug */ +#define X86_TRAP_NMI 2/* Non-maskable Interrupt */ +#define X86_TRAP_BP 3/* Breakpoint */ +#define X86_TRAP_OF 4/* Overflow */ +#define X86_TRAP_BR 5/* Bound Range Exceeded */ +#define X86_TRAP_UD 6/* Invalid Opcode */ +#define X86_TRAP_NM 7/* Device Not Available */ +#define X86_TRAP_DF 8/* Double Fault */ +#define X86_TRAP_OLD_MF 9/* Coprocessor Segment Overrun */ +#define X86_TRAP_TS 10/* Invalid TSS */ +#define X86_TRAP_NP 11/* Segment Not Present */ +#define X86_TRAP_SS 12/* Stack Segment Fault */ +#define X86_TRAP_GP 13/* General Protection Fault */ +#define X86_TRAP_PF 14/* Page Fault */ +#define X86_TRAP_SPURIOUS 15/* Spurious Interrupt */ +#define X86_TRAP_MF 16/* x87 Floating-Point Exception */ +#define X86_TRAP_AC 17/* Alignment Check */ +#define X86_TRAP_MC 18/* Machine Check */ +#define X86_TRAP_XF 19/* SIMD Floating-Point Exception */ +#define X86_TRAP_VE 20/* Virtualization Exception */ +#define X86_TRAP_CP 21/* Control Protection Exception */ +#define X86_TRAP_IRET 32/* IRET Exception */ + +#endif
arch/x86/include/asm/traps.h +1 -25
@@ -7,6 +7,7 @@#include <asm/debugreg.h> #include <asm/siginfo.h> /* TRAP_TRACE, ... */ +#include <asm/trapnr.h> #define dotraplinkage __visible
@@ -127,31 +128,6 @@ void __noreturn handle_stack_overflow(co unsigned long fault_address);#endif -/* Interrupts/Exceptions */ -enum { -X86_TRAP_DE =0 ,/* 0, Divide-by-zero */ -X86_TRAP_DB ,/* 1, Debug */ -X86_TRAP_NMI ,/* 2, Non-maskable Interrupt */ -X86_TRAP_BP ,/* 3, Breakpoint */ -X86_TRAP_OF ,/* 4, Overflow */ -X86_TRAP_BR ,/* 5, Bound Range Exceeded */ -X86_TRAP_UD ,/* 6, Invalid Opcode */ -X86_TRAP_NM ,/* 7, Device Not Available */ -X86_TRAP_DF ,/* 8, Double Fault */ -X86_TRAP_OLD_MF ,/* 9, Coprocessor Segment Overrun */ -X86_TRAP_TS ,/* 10, Invalid TSS */ -X86_TRAP_NP ,/* 11, Segment Not Present */ -X86_TRAP_SS ,/* 12, Stack Segment Fault */ -X86_TRAP_GP ,/* 13, General Protection Fault */ -X86_TRAP_PF ,/* 14, Page Fault */ -X86_TRAP_SPURIOUS ,/* 15, Spurious Interrupt */ -X86_TRAP_MF ,/* 16, x87 Floating-Point Exception */ -X86_TRAP_AC ,/* 17, Alignment Check */ -X86_TRAP_MC ,/* 18, Machine Check */ -X86_TRAP_XF ,/* 19, SIMD Floating-Point Exception */ -X86_TRAP_IRET =32 ,/* 32, IRET Exception */ -}; -/* * Page fault error code bits: *
Re: [patch V4 part 3 05/29] x86/traps: Split trap numbers out in a seperate header
Quoted 5 lines · Thomas Gleixner
From: Thomas Gleixner <[email protected]>
So they can be used in ASM code. For this it is also necessary to convert them to defines. Will be used for the rework of the entry code.
Quoted 8 lines
Signed-off-by Thomas Gleixner <[email protected]>Reviewed-by Andy Lutomirski <[email protected]>Reviewed-by Alexandre Chartre <[email protected]>--- arch/x86/include/asm/trapnr.h | 31 +++++++++++++++++++++++++++++++ arch/x86/include/asm/traps.h | 26 +------------------------- 2 files changed, 32 insertions(+), 25 deletions(-)
typo in subject: "seperate"
alex.
[tip: x86/entry] x86/traps: Split trap numbers out in a separate header
In reply to Thomas GleixnerThe following commit has been merged into the x86/entry branch of tip:
The following commit has been merged into the x86/entry branch of tip:
Commit-ID: 9201e511e0f7184bebbd58e98d3d08fa13a34cac Gitweb: https://git.kernel.org/tip/9201e511e0f7184bebbd58e98d3d08fa13a34cac Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 25 Feb 2020 23:16:07 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 19 May 2020 16:03:54 +02:00
x86/traps: Split trap numbers out in a separate header
So they can be used in ASM code. For this it is also necessary to convert them to defines. Will be used for the rework of the entry code.
--- arch/x86/include/asm/trapnr.h | 31 +++++++++++++++++++++++++++++++ arch/x86/include/asm/traps.h | 26 +------------------------- 2 files changed, 32 insertions(+), 25 deletions(-) create mode 100644 arch/x86/include/asm/trapnr.h
arch/x86/include/asm/trapnr.h new file +31 -0
@@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_X86_TRAPNR_H +#define _ASM_X86_TRAPNR_H + +/* Interrupts/Exceptions */ + +#define X86_TRAP_DE 0/* Divide-by-zero */ +#define X86_TRAP_DB 1/* Debug */ +#define X86_TRAP_NMI 2/* Non-maskable Interrupt */ +#define X86_TRAP_BP 3/* Breakpoint */ +#define X86_TRAP_OF 4/* Overflow */ +#define X86_TRAP_BR 5/* Bound Range Exceeded */ +#define X86_TRAP_UD 6/* Invalid Opcode */ +#define X86_TRAP_NM 7/* Device Not Available */ +#define X86_TRAP_DF 8/* Double Fault */ +#define X86_TRAP_OLD_MF 9/* Coprocessor Segment Overrun */ +#define X86_TRAP_TS 10/* Invalid TSS */ +#define X86_TRAP_NP 11/* Segment Not Present */ +#define X86_TRAP_SS 12/* Stack Segment Fault */ +#define X86_TRAP_GP 13/* General Protection Fault */ +#define X86_TRAP_PF 14/* Page Fault */ +#define X86_TRAP_SPURIOUS 15/* Spurious Interrupt */ +#define X86_TRAP_MF 16/* x87 Floating-Point Exception */ +#define X86_TRAP_AC 17/* Alignment Check */ +#define X86_TRAP_MC 18/* Machine Check */ +#define X86_TRAP_XF 19/* SIMD Floating-Point Exception */ +#define X86_TRAP_VE 20/* Virtualization Exception */ +#define X86_TRAP_CP 21/* Control Protection Exception */ +#define X86_TRAP_IRET 32/* IRET Exception */ + +#endif
arch/x86/include/asm/traps.h +1 -25
@@ -7,6 +7,7 @@#include <asm/debugreg.h> #include <asm/siginfo.h> /* TRAP_TRACE, ... */ +#include <asm/trapnr.h> #define dotraplinkage __visible
@@ -122,31 +123,6 @@ void __noreturn handle_stack_overflow(const char *message, unsigned long fault_address);#endif -/* Interrupts/Exceptions */ -enum { -X86_TRAP_DE =0 ,/* 0, Divide-by-zero */ -X86_TRAP_DB ,/* 1, Debug */ -X86_TRAP_NMI ,/* 2, Non-maskable Interrupt */ -X86_TRAP_BP ,/* 3, Breakpoint */ -X86_TRAP_OF ,/* 4, Overflow */ -X86_TRAP_BR ,/* 5, Bound Range Exceeded */ -X86_TRAP_UD ,/* 6, Invalid Opcode */ -X86_TRAP_NM ,/* 7, Device Not Available */ -X86_TRAP_DF ,/* 8, Double Fault */ -X86_TRAP_OLD_MF ,/* 9, Coprocessor Segment Overrun */ -X86_TRAP_TS ,/* 10, Invalid TSS */ -X86_TRAP_NP ,/* 11, Segment Not Present */ -X86_TRAP_SS ,/* 12, Stack Segment Fault */ -X86_TRAP_GP ,/* 13, General Protection Fault */ -X86_TRAP_PF ,/* 14, Page Fault */ -X86_TRAP_SPURIOUS ,/* 15, Spurious Interrupt */ -X86_TRAP_MF ,/* 16, x87 Floating-Point Exception */ -X86_TRAP_AC ,/* 17, Alignment Check */ -X86_TRAP_MC ,/* 18, Machine Check */ -X86_TRAP_XF ,/* 19, SIMD Floating-Point Exception */ -X86_TRAP_IRET =32 ,/* 32, IRET Exception */ -}; -/* * Page fault error code bits: *
PATCH v4 6/29 x86/entry/64: Reorder idtentries
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
Move them all together so verifying the cleanup patches for binary equivalence will be easier.
--- arch/x86/entry/entry_64.S | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-)
arch/x86/entry/entry_64.S +17 -19
@@ -1021,20 +1021,36 @@ SYM_CODE_START(\sym) SYM_CODE_END(\sym) .endm + idtentry divide_error do_divide_error has_error_code=0 idtentry overflow do_overflow has_error_code=0 +idtentry int3 do_int3 has_error_code=0 create_gap=1 idtentry bounds do_bounds has_error_code=0 idtentry invalid_op do_invalid_op has_error_code=0 idtentry device_not_available do_device_not_available has_error_code=0 -idtentry double_fault do_double_fault has_error_code=1 paranoid=2 read_cr2=1 idtentry coprocessor_segment_overrun do_coprocessor_segment_overrun has_error_code=0 idtentry invalid_TSS do_invalid_TSS has_error_code=1 idtentry segment_not_present do_segment_not_present has_error_code=1 +idtentry stack_segment do_stack_segment has_error_code=1 +idtentry general_protection do_general_protection has_error_code=1 idtentry spurious_interrupt_bug do_spurious_interrupt_bug has_error_code=0 idtentry coprocessor_error do_coprocessor_error has_error_code=0 idtentry alignment_check do_alignment_check has_error_code=1 idtentry simd_coprocessor_error do_simd_coprocessor_error has_error_code=0 +idtentry page_fault do_page_fault has_error_code=1 read_cr2=1 + +#ifdef CONFIG_X86_MCE +idtentry machine_check do_mce has_error_code=0 paranoid=1 +#endif +idtentry debug do_debug has_error_code=0 paranoid=1 shift_ist=IST_INDEX_DB ist_offset=DB_STACK_OFFSET +idtentry double_fault do_double_fault has_error_code=1 paranoid=2 read_cr2=1 + +#ifdef CONFIG_XEN_PV +idtentry hypervisor_callback xen_do_hypervisor_callback has_error_code=0 +idtentry xennmi do_nmi has_error_code=0 +idtentry xendebug do_debug has_error_code=0 +#endif /* * Reload gs selector with exception handling
@@ -1085,8 +1101,6 @@ SYM_FUNC_END(do_softirq_own_stack) .popsection #ifdef CONFIG_XEN_PV -idtentry hypervisor_callback xen_do_hypervisor_callback has_error_code=0 - /* * A note on the "critical region" in our callback handler. * We want to avoid stacking callback handlers due to events occurring
@@ -1189,22 +1203,6 @@ apicinterrupt3 HYPERVISOR_CALLBACK_VECTO acrn_hv_callback_vector acrn_hv_vector_handler #endif -idtentry debug do_debug has_error_code=0 paranoid=1 shift_ist=IST_INDEX_DB ist_offset=DB_STACK_OFFSET -idtentry int3 do_int3 has_error_code=0 create_gap=1 -idtentry stack_segment do_stack_segment has_error_code=1 - -#ifdef CONFIG_XEN_PV -idtentry xennmi do_nmi has_error_code=0 -idtentry xendebug do_debug has_error_code=0 -#endif - -idtentry general_protection do_general_protection has_error_code=1 -idtentry page_fault do_page_fault has_error_code=1 read_cr2=1 - -#ifdef CONFIG_X86_MCE -idtentry machine_check do_mce has_error_code=0 paranoid=1 -#endif - /* * Save all registers in pt_regs, and switch gs if needed. * Use slow, but surefire "are we in kernel?" check.
[tip: x86/entry] x86/entry/64: Reorder idtentries
The following commit has been merged into the x86/entry branch of tip:
The following commit has been merged into the x86/entry branch of tip:
Commit-ID: 8996fcd630d11ff3fe6f3fbaee7b39b4a9dde4d0 Gitweb: https://git.kernel.org/tip/8996fcd630d11ff3fe6f3fbaee7b39b4a9dde4d0 Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 25 Feb 2020 23:16:09 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 19 May 2020 16:03:55 +02:00
x86/entry/64: Reorder idtentries
Move them all together so verifying the cleanup patches for binary equivalence will be easier.
--- arch/x86/entry/entry_64.S | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-)
arch/x86/entry/entry_64.S +17 -19
@@ -1020,20 +1020,36 @@ _ASM_NOKPROBE(\sym) SYM_CODE_END(\sym) .endm + idtentry divide_error do_divide_error has_error_code=0 idtentry overflow do_overflow has_error_code=0 +idtentry int3 do_int3 has_error_code=0 create_gap=1 idtentry bounds do_bounds has_error_code=0 idtentry invalid_op do_invalid_op has_error_code=0 idtentry device_not_available do_device_not_available has_error_code=0 -idtentry double_fault do_double_fault has_error_code=1 paranoid=2 read_cr2=1 idtentry coprocessor_segment_overrun do_coprocessor_segment_overrun has_error_code=0 idtentry invalid_TSS do_invalid_TSS has_error_code=1 idtentry segment_not_present do_segment_not_present has_error_code=1 +idtentry stack_segment do_stack_segment has_error_code=1 +idtentry general_protection do_general_protection has_error_code=1 idtentry spurious_interrupt_bug do_spurious_interrupt_bug has_error_code=0 idtentry coprocessor_error do_coprocessor_error has_error_code=0 idtentry alignment_check do_alignment_check has_error_code=1 idtentry simd_coprocessor_error do_simd_coprocessor_error has_error_code=0 +idtentry page_fault do_page_fault has_error_code=1 read_cr2=1 + +#ifdef CONFIG_X86_MCE +idtentry machine_check do_mce has_error_code=0 paranoid=1 +#endif +idtentry debug do_debug has_error_code=0 paranoid=1 shift_ist=IST_INDEX_DB ist_offset=DB_STACK_OFFSET +idtentry double_fault do_double_fault has_error_code=1 paranoid=2 read_cr2=1 + +#ifdef CONFIG_XEN_PV +idtentry hypervisor_callback xen_do_hypervisor_callback has_error_code=0 +idtentry xennmi do_nmi has_error_code=0 +idtentry xendebug do_debug has_error_code=0 +#endif /* * Reload gs selector with exception handling
@@ -1084,8 +1100,6 @@ SYM_FUNC_END(do_softirq_own_stack) .popsection #ifdef CONFIG_XEN_PV -idtentry hypervisor_callback xen_do_hypervisor_callback has_error_code=0 - /* * A note on the "critical region" in our callback handler. * We want to avoid stacking callback handlers due to events occurring
@@ -1188,22 +1202,6 @@ apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \ acrn_hv_callback_vector acrn_hv_vector_handler #endif -idtentry debug do_debug has_error_code=0 paranoid=1 shift_ist=IST_INDEX_DB ist_offset=DB_STACK_OFFSET -idtentry int3 do_int3 has_error_code=0 create_gap=1 -idtentry stack_segment do_stack_segment has_error_code=1 - -#ifdef CONFIG_XEN_PV -idtentry xennmi do_nmi has_error_code=0 -idtentry xendebug do_debug has_error_code=0 -#endif - -idtentry general_protection do_general_protection has_error_code=1 -idtentry page_fault do_page_fault has_error_code=1 read_cr2=1 - -#ifdef CONFIG_X86_MCE -idtentry machine_check do_mce has_error_code=0 paranoid=1 -#endif - /* * Save all registers in pt_regs, and switch gs if needed. * Use slow, but surefire "are we in kernel?" check.
PATCH v4 7/29 x86/entry: Distangle idtentry
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
idtentry is a completely unreadable maze. Split it into distinct idtentry variants which only contain the minimal code:
- idtentry for regular exceptions
- idtentry_mce_debug for #MCE and #DB
- idtentry_df for #DF
The generated binary code is equivalent.
--- arch/x86/entry/entry_64.S | 401 +++++++++++++++++++++++++--------------------- 1 file changed, 219 insertions(+), 182 deletions(-)
arch/x86/entry/entry_64.S +219 -182
@@ -37,6 +37,7 @@ #include <asm/pgtable_types.h> #include <asm/export.h> #include <asm/frame.h> +#include <asm/trapnr.h> #include <asm/nospec-branch.h> #include <linux/err.h>
@@ -494,6 +495,202 @@ SYM_CODE_END(spurious_entries_start) decl PER_CPU_VAR(irq_count) .endm +/** + * idtentry_body - Macro to emit code calling the C function + * @vector: Vector number + * @cfunc: C function to be called + * @has_error_code: Hardware pushed error code on stack + */ +.macro idtentry_body vector cfunc has_error_code:req + + call error_entry + UNWIND_HINT_REGS + + .if \vector == X86_TRAP_PF + /* + * Store CR2 early so subsequent faults cannot clobber it. Use R12 as + * intermediate storage as RDX can be clobbered in enter_from_user_mode(). + * GET_CR2_INTO can clobber RAX. + */ + GET_CR2_INTO(%r12); + .endif + + TRACE_IRQS_OFF + +#ifdef CONFIG_CONTEXT_TRACKING + testb $3, CS(%rsp) + jz .Lfrom_kernel_no_ctxt_tracking_\@ + CALL_enter_from_user_mode +.Lfrom_kernel_no_ctxt_tracking_\@: +#endif + + movq %rsp, %rdi /* pt_regs pointer into 1st argument*/ + + .if \has_error_code == 1 + movq ORIG_RAX(%rsp), %rsi /* get error code into 2nd argument*/ + movq $-1, ORIG_RAX(%rsp) /* no syscall to restart */ + .else + xorl %esi, %esi /* Clear the error code */ + .endif + + .if \vector == X86_TRAP_PF + movq %r12, %rdx /* Move CR2 into 3rd argument */ + .endif + + call \cfunc + + jmp error_exit +.endm + +/** + * idtentry - Macro to generate entry stubs for simple IDT entries + * @vector: Vector number + * @asmsym: ASM symbol for the entry point + * @cfunc: C function to be called + * @has_error_code: Hardware pushed error code on stack + * + * The macro emits code to set up the kernel context for straight forward + * and simple IDT entries. No IST stack, no paranoid entry checks. + */ +.macro idtentry vector asmsym cfunc has_error_code:req +SYM_CODE_START(\asmsym) + UNWIND_HINT_IRET_REGS offset=\has_error_code*8 + ASM_CLAC + + .if \has_error_code == 0 + pushq $-1 /* ORIG_RAX: no syscall to restart */ + .endif + + .if \vector == X86_TRAP_BP + /* + * If coming from kernel space, create a 6-word gap to allow the + * int3 handler to emulate a call instruction. + */ + testb $3, CS-ORIG_RAX(%rsp) + jnz .Lfrom_usermode_no_gap_\@ + .rept 6 + pushq 5*8(%rsp) + .endr + UNWIND_HINT_IRET_REGS offset=8 +.Lfrom_usermode_no_gap_\@: + .endif + + idtentry_body \vector \cfunc \has_error_code + +_ASM_NOKPROBE(\asmsym) +SYM_CODE_END(\asmsym) +.endm + +/* + * MCE and DB exceptions + */ +#define CPU_TSS_IST(x) PER_CPU_VAR(cpu_tss_rw) + (TSS_ist + (x) * 8) + +/** + * idtentry_mce_db - Macro to generate entry stubs for #MC and #DB + * @vector: Vector number + * @asmsym: ASM symbol for the entry point + * @cfunc: C function to be called + * + * The macro emits code to set up the kernel context for #MC and #DB + * + * If the entry comes from user space it uses the normal entry path + * including the return to user space work and preemption checks on + * exit. + * + * If hits in kernel mode then it needs to go through the paranoid + * entry as the exception can hit any random state. No preemption + * check on exit to keep the paranoid path simple. + * + * If the trap is #DB then the interrupt stack entry in the IST is + * moved to the second stack, so a potential recursion will have a + * fresh IST. + */ +.macro idtentry_mce_db vector asmsym cfunc +SYM_CODE_START(\asmsym) + UNWIND_HINT_IRET_REGS + ASM_CLAC + + pushq $-1 /* ORIG_RAX: no syscall to restart */ + + /* + * If the entry is from userspace, switch stacks and treat it as + * a normal entry. + */ + testb $3, CS-ORIG_RAX(%rsp) + jnz .Lfrom_usermode_switch_stack_\@ + + /* + * paranoid_entry returns SWAPGS flag for paranoid_exit in EBX. + * EBX == 0 -> SWAPGS, EBX == 1 -> no SWAPGS + */ + call paranoid_entry + + UNWIND_HINT_REGS + + .if \vector == X86_TRAP_DB + TRACE_IRQS_OFF_DEBUG + .else + TRACE_IRQS_OFF + .endif + + movq %rsp, %rdi /* pt_regs pointer */ + xorl %esi, %esi /* Clear the error code */ + + .if \vector == X86_TRAP_DB + subq $DB_STACK_OFFSET, CPU_TSS_IST(IST_INDEX_DB) + .endif + + call \cfunc + + .if \vector == X86_TRAP_DB + addq $DB_STACK_OFFSET, CPU_TSS_IST(IST_INDEX_DB) + .endif + + jmp paranoid_exit + + /* Switch to the regular task stack and use the noist entry point */ +.Lfrom_usermode_switch_stack_\@: + idtentry_body vector \cfunc, has_error_code=0 + +_ASM_NOKPROBE(\asmsym) +SYM_CODE_END(\asmsym) +.endm + +/* + * Double fault entry. Straight paranoid. No checks from which context + * this comes because for the espfix induced #DF this would do the wrong + * thing. + */ +.macro idtentry_df vector asmsym cfunc +SYM_CODE_START(\asmsym) + UNWIND_HINT_IRET_REGS offset=8 + ASM_CLAC + + /* + * paranoid_entry returns SWAPGS flag for paranoid_exit in EBX. + * EBX == 0 -> SWAPGS, EBX == 1 -> no SWAPGS + */ + call paranoid_entry + UNWIND_HINT_REGS + + /* Read CR2 early */ + GET_CR2_INTO(%r12); + + TRACE_IRQS_OFF + + movq %rsp, %rdi /* pt_regs pointer into first argument */ + movq ORIG_RAX(%rsp), %rsi /* get error code into 2nd argument*/ + movq $-1, ORIG_RAX(%rsp) /* no syscall to restart */ + movq %r12, %rdx /* Move CR2 into 3rd argument */ + call \cfunc + + jmp paranoid_exit + +_ASM_NOKPROBE(\asmsym) +SYM_CODE_END(\asmsym) +.endm + /* * Interrupt entry helper function. *
@@ -861,195 +1058,35 @@ apicinterrupt IRQ_WORK_VECTOR irq_work /* * Exception entry points. */ -#define CPU_TSS_IST(x) PER_CPU_VAR(cpu_tss_rw) + (TSS_ist + (x) * 8) - -.macro idtentry_part do_sym, has_error_code:req, read_cr2:req, paranoid:req, shift_ist=-1, ist_offset=0 - - .if \paranoid - call paranoid_entry - /* returned flag: ebx=0: need swapgs on exit, ebx=1: don't need it */ - .else - call error_entry - .endif - UNWIND_HINT_REGS - - .if \read_cr2 - /* - * Store CR2 early so subsequent faults cannot clobber it. Use R12 as - * intermediate storage as RDX can be clobbered in enter_from_user_mode(). - * GET_CR2_INTO can clobber RAX. - */ - GET_CR2_INTO(%r12); - .endif - - .if \shift_ist != -1 - TRACE_IRQS_OFF_DEBUG /* reload IDT in case of recursion */ - .else - TRACE_IRQS_OFF - .endif - -#ifdef CONFIG_CONTEXT_TRACKING - .if \paranoid == 0 - testb $3, CS(%rsp) - jz .Lfrom_kernel_no_context_tracking_\@ - CALL_enter_from_user_mode -.Lfrom_kernel_no_context_tracking_\@: - .endif -#endif - - movq %rsp, %rdi /* pt_regs pointer */ - - .if \has_error_code - movq ORIG_RAX(%rsp), %rsi /* get error code */ - movq $-1, ORIG_RAX(%rsp) /* no syscall to restart */ - .else - xorl %esi, %esi /* no error code */ - .endif - - .if \shift_ist != -1 - subq $\ist_offset, CPU_TSS_IST(\shift_ist) - .endif - - .if \read_cr2 - movq %r12, %rdx /* Move CR2 into 3rd argument */ - .endif - - call \do_sym - - .if \shift_ist != -1 - addq $\ist_offset, CPU_TSS_IST(\shift_ist) - .endif - - .if \paranoid - /* this procedure expect "no swapgs" flag in ebx */ - jmp paranoid_exit - .else - jmp error_exit - .endif - -.endm - -/** - * idtentry - Generate an IDT entry stub - * @sym: Name of the generated entry point - * @do_sym: C function to be called - * @has_error_code: True if this IDT vector has an error code on the stack - * @paranoid: non-zero means that this vector may be invoked from - * kernel mode with user GSBASE and/or user CR3. - * 2 is special -- see below. - * @shift_ist: Set to an IST index if entries from kernel mode should - * decrement the IST stack so that nested entries get a - * fresh stack. (This is for #DB, which has a nasty habit - * of recursing.) - * @create_gap: create a 6-word stack gap when coming from kernel mode. - * @read_cr2: load CR2 into the 3rd argument; done before calling any C code - * - * idtentry generates an IDT stub that sets up a usable kernel context, - * creates struct pt_regs, and calls @do_sym. The stub has the following - * special behaviors: - * - * On an entry from user mode, the stub switches from the trampoline or - * IST stack to the normal thread stack. On an exit to user mode, the - * normal exit-to-usermode path is invoked. - * - * On an exit to kernel mode, if @paranoid == 0, we check for preemption, - * whereas we omit the preemption check if @paranoid != 0. This is purely - * because the implementation is simpler this way. The kernel only needs - * to check for asynchronous kernel preemption when IRQ handlers return. - * - * If @paranoid == 0, then the stub will handle IRET faults by pretending - * that the fault came from user mode. It will handle gs_change faults by - * pretending that the fault happened with kernel GSBASE. Since this handling - * is omitted for @paranoid != 0, the #GP, #SS, and #NP stubs must have - * @paranoid == 0. This special handling will do the wrong thing for - * espfix-induced #DF on IRET, so #DF must not use @paranoid == 0. - * - * @paranoid == 2 is special: the stub will never switch stacks. This is for - * #DF: if the thread stack is somehow unusable, we'll still get a useful OOPS. - */ -.macro idtentry sym do_sym has_error_code:req paranoid=0 shift_ist=-1 ist_offset=0 create_gap=0 read_cr2=0 -SYM_CODE_START(\sym) - UNWIND_HINT_IRET_REGS offset=\has_error_code*8 - - /* Sanity check */ - .if \shift_ist != -1 && \paranoid != 1 - .error "using shift_ist requires paranoid=1" - .endif - - .if \create_gap && \paranoid - .error "using create_gap requires paranoid=0" - .endif - - ASM_CLAC - - .if \has_error_code == 0 - pushq $-1 /* ORIG_RAX: no syscall to restart */ - .endif - - .if \paranoid == 1 - testb $3, CS-ORIG_RAX(%rsp) /* If coming from userspace, switch stacks */ - jnz .Lfrom_usermode_switch_stack_\@ - .endif - - .if \create_gap == 1 - /* - * If coming from kernel space, create a 6-word gap to allow the - * int3 handler to emulate a call instruction. - */ - testb $3, CS-ORIG_RAX(%rsp) - jnz .Lfrom_usermode_no_gap_\@ - .rept 6 - pushq 5*8(%rsp) - .endr - UNWIND_HINT_IRET_REGS offset=8 -.Lfrom_usermode_no_gap_\@: - .endif - - idtentry_part \do_sym, \has_error_code, \read_cr2, \paranoid, \shift_ist, \ist_offset - - .if \paranoid == 1 - /* - * Entry from userspace. Switch stacks and treat it - * as a normal entry. This means that paranoid handlers - * run in real process context if user_mode(regs). - */ -.Lfrom_usermode_switch_stack_\@: - idtentry_part \do_sym, \has_error_code, \read_cr2, paranoid=0 - .endif - -_ASM_NOKPROBE(\sym) -SYM_CODE_END(\sym) -.endm - -idtentry divide_error do_divide_error has_error_code=0 -idtentry overflow do_overflow has_error_code=0 -idtentry int3 do_int3 has_error_code=0 create_gap=1 -idtentry bounds do_bounds has_error_code=0 -idtentry invalid_op do_invalid_op has_error_code=0 -idtentry device_not_available do_device_not_available has_error_code=0 -idtentry coprocessor_segment_overrun do_coprocessor_segment_overrun has_error_code=0 -idtentry invalid_TSS do_invalid_TSS has_error_code=1 -idtentry segment_not_present do_segment_not_present has_error_code=1 -idtentry stack_segment do_stack_segment has_error_code=1 -idtentry general_protection do_general_protection has_error_code=1 -idtentry spurious_interrupt_bug do_spurious_interrupt_bug has_error_code=0 -idtentry coprocessor_error do_coprocessor_error has_error_code=0 -idtentry alignment_check do_alignment_check has_error_code=1 -idtentry simd_coprocessor_error do_simd_coprocessor_error has_error_code=0 +idtentry X86_TRAP_DE divide_error do_divide_error has_error_code=0 +idtentry X86_TRAP_OF overflow do_overflow has_error_code=0 +idtentry X86_TRAP_BP int3 do_int3 has_error_code=0 +idtentry X86_TRAP_BR bounds do_bounds has_error_code=0 +idtentry X86_TRAP_UD invalid_op do_invalid_op has_error_code=0 +idtentry X86_TRAP_NM device_not_available do_device_not_available has_error_code=0 +idtentry X86_TRAP_OLD_MF coprocessor_segment_overrun do_coprocessor_segment_overrun has_error_code=0 +idtentry X86_TRAP_TS invalid_TSS do_invalid_TSS has_error_code=1 +idtentry X86_TRAP_NP segment_not_present do_segment_not_present has_error_code=1 +idtentry X86_TRAP_SS stack_segment do_stack_segment has_error_code=1 +idtentry X86_TRAP_GP general_protection do_general_protection has_error_code=1 +idtentry X86_TRAP_SPURIOUS spurious_interrupt_bug do_spurious_interrupt_bug has_error_code=0 +idtentry X86_TRAP_MF coprocessor_error do_coprocessor_error has_error_code=0 +idtentry X86_TRAP_AC alignment_check do_alignment_check has_error_code=1 +idtentry X86_TRAP_XF simd_coprocessor_error do_simd_coprocessor_error has_error_code=0 -idtentry page_fault do_page_fault has_error_code=1 read_cr2=1 +idtentry X86_TRAP_PF page_fault do_page_fault has_error_code=1 #ifdef CONFIG_X86_MCE -idtentry machine_check do_mce has_error_code=0 paranoid=1 +idtentry_mce_db X86_TRAP_MCE machine_check do_mce #endif -idtentry debug do_debug has_error_code=0 paranoid=1 shift_ist=IST_INDEX_DB ist_offset=DB_STACK_OFFSET -idtentry double_fault do_double_fault has_error_code=1 paranoid=2 read_cr2=1 +idtentry_mce_db X86_TRAP_DB debug do_debug +idtentry_df X86_TRAP_DF double_fault do_double_fault #ifdef CONFIG_XEN_PV -idtentry hypervisor_callback xen_do_hypervisor_callback has_error_code=0 -idtentry xennmi do_nmi has_error_code=0 -idtentry xendebug do_debug has_error_code=0 +idtentry 512 /* dummy */ hypervisor_callback xen_do_hypervisor_callback has_error_code=0 +idtentry X86_TRAP_NMI xennmi do_nmi has_error_code=0 +idtentry X86_TRAP_DB xendebug do_debug has_error_code=0 #endif /*
Re: [patch V4 part 3 07/29] x86/entry: Distangle idtentry
Quoted 11 lines · Thomas Gleixner
From: Thomas Gleixner <[email protected]>
idtentry is a completely unreadable maze. Split it into distinct idtentry variants which only contain the minimal code:
- idtentry for regular exceptions
-idtentry_mce_debugfor #MCE and #DB
-idtentry_dffor #DFThe generated binary code is equivalent.
[tip: x86/entry] x86/entry: Distangle idtentry
In reply to Thomas GleixnerThe following commit has been merged into the x86/entry branch of tip:
The following commit has been merged into the x86/entry branch of tip:
Commit-ID: 696ab9143a5fc25eaaedd589bc9939c58d626030 Gitweb: https://git.kernel.org/tip/696ab9143a5fc25eaaedd589bc9939c58d626030 Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 25 Feb 2020 23:16:10 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 19 May 2020 16:03:55 +02:00
x86/entry: Distangle idtentry
idtentry is a completely unreadable maze. Split it into distinct idtentry variants which only contain the minimal code:
- idtentry for regular exceptions
- idtentry_mce_debug for #MCE and #DB
- idtentry_df for #DF
The generated binary code is equivalent.
--- arch/x86/entry/entry_64.S | 403 ++++++++++++++++++++----------------- 1 file changed, 220 insertions(+), 183 deletions(-)
arch/x86/entry/entry_64.S +220 -183
@@ -37,6 +37,7 @@ #include <asm/pgtable_types.h> #include <asm/export.h> #include <asm/frame.h> +#include <asm/trapnr.h> #include <asm/nospec-branch.h> #include <linux/err.h>
@@ -493,6 +494,202 @@ SYM_CODE_END(spurious_entries_start) decl PER_CPU_VAR(irq_count) .endm +/** + * idtentry_body - Macro to emit code calling the C function + * @vector: Vector number + * @cfunc: C function to be called + * @has_error_code: Hardware pushed error code on stack + */ +.macro idtentry_body vector cfunc has_error_code:req + + call error_entry + UNWIND_HINT_REGS + + .if \vector == X86_TRAP_PF + /* + * Store CR2 early so subsequent faults cannot clobber it. Use R12 as + * intermediate storage as RDX can be clobbered in enter_from_user_mode(). + * GET_CR2_INTO can clobber RAX. + */ + GET_CR2_INTO(%r12); + .endif + + TRACE_IRQS_OFF + +#ifdef CONFIG_CONTEXT_TRACKING + testb $3, CS(%rsp) + jz .Lfrom_kernel_no_ctxt_tracking_\@ + CALL_enter_from_user_mode +.Lfrom_kernel_no_ctxt_tracking_\@: +#endif + + movq %rsp, %rdi /* pt_regs pointer into 1st argument*/ + + .if \has_error_code == 1 + movq ORIG_RAX(%rsp), %rsi /* get error code into 2nd argument*/ + movq $-1, ORIG_RAX(%rsp) /* no syscall to restart */ + .else + xorl %esi, %esi /* Clear the error code */ + .endif + + .if \vector == X86_TRAP_PF + movq %r12, %rdx /* Move CR2 into 3rd argument */ + .endif + + call \cfunc + + jmp error_exit +.endm + +/** + * idtentry - Macro to generate entry stubs for simple IDT entries + * @vector: Vector number + * @asmsym: ASM symbol for the entry point + * @cfunc: C function to be called + * @has_error_code: Hardware pushed error code on stack + * + * The macro emits code to set up the kernel context for straight forward + * and simple IDT entries. No IST stack, no paranoid entry checks. + */ +.macro idtentry vector asmsym cfunc has_error_code:req +SYM_CODE_START(\asmsym) + UNWIND_HINT_IRET_REGS offset=\has_error_code*8 + ASM_CLAC + + .if \has_error_code == 0 + pushq $-1 /* ORIG_RAX: no syscall to restart */ + .endif + + .if \vector == X86_TRAP_BP + /* + * If coming from kernel space, create a 6-word gap to allow the + * int3 handler to emulate a call instruction. + */ + testb $3, CS-ORIG_RAX(%rsp) + jnz .Lfrom_usermode_no_gap_\@ + .rept 6 + pushq 5*8(%rsp) + .endr + UNWIND_HINT_IRET_REGS offset=8 +.Lfrom_usermode_no_gap_\@: + .endif + + idtentry_body \vector \cfunc \has_error_code + +_ASM_NOKPROBE(\asmsym) +SYM_CODE_END(\asmsym) +.endm + +/* + * MCE and DB exceptions + */ +#define CPU_TSS_IST(x) PER_CPU_VAR(cpu_tss_rw) + (TSS_ist + (x) * 8) + +/** + * idtentry_mce_db - Macro to generate entry stubs for #MC and #DB + * @vector: Vector number + * @asmsym: ASM symbol for the entry point + * @cfunc: C function to be called + * + * The macro emits code to set up the kernel context for #MC and #DB + * + * If the entry comes from user space it uses the normal entry path + * including the return to user space work and preemption checks on + * exit. + * + * If hits in kernel mode then it needs to go through the paranoid + * entry as the exception can hit any random state. No preemption + * check on exit to keep the paranoid path simple. + * + * If the trap is #DB then the interrupt stack entry in the IST is + * moved to the second stack, so a potential recursion will have a + * fresh IST. + */ +.macro idtentry_mce_db vector asmsym cfunc +SYM_CODE_START(\asmsym) + UNWIND_HINT_IRET_REGS + ASM_CLAC + + pushq $-1 /* ORIG_RAX: no syscall to restart */ + + /* + * If the entry is from userspace, switch stacks and treat it as + * a normal entry. + */ + testb $3, CS-ORIG_RAX(%rsp) + jnz .Lfrom_usermode_switch_stack_\@ + + /* + * paranoid_entry returns SWAPGS flag for paranoid_exit in EBX. + * EBX == 0 -> SWAPGS, EBX == 1 -> no SWAPGS + */ + call paranoid_entry + + UNWIND_HINT_REGS + + .if \vector == X86_TRAP_DB + TRACE_IRQS_OFF_DEBUG + .else + TRACE_IRQS_OFF + .endif + + movq %rsp, %rdi /* pt_regs pointer */ + xorl %esi, %esi /* Clear the error code */ + + .if \vector == X86_TRAP_DB + subq $DB_STACK_OFFSET, CPU_TSS_IST(IST_INDEX_DB) + .endif + + call \cfunc + + .if \vector == X86_TRAP_DB + addq $DB_STACK_OFFSET, CPU_TSS_IST(IST_INDEX_DB) + .endif + + jmp paranoid_exit + + /* Switch to the regular task stack and use the noist entry point */ +.Lfrom_usermode_switch_stack_\@: + idtentry_body vector \cfunc, has_error_code=0 + +_ASM_NOKPROBE(\asmsym) +SYM_CODE_END(\asmsym) +.endm + +/* + * Double fault entry. Straight paranoid. No checks from which context + * this comes because for the espfix induced #DF this would do the wrong + * thing. + */ +.macro idtentry_df vector asmsym cfunc +SYM_CODE_START(\asmsym) + UNWIND_HINT_IRET_REGS offset=8 + ASM_CLAC + + /* + * paranoid_entry returns SWAPGS flag for paranoid_exit in EBX. + * EBX == 0 -> SWAPGS, EBX == 1 -> no SWAPGS + */ + call paranoid_entry + UNWIND_HINT_REGS + + /* Read CR2 early */ + GET_CR2_INTO(%r12); + + TRACE_IRQS_OFF + + movq %rsp, %rdi /* pt_regs pointer into first argument */ + movq ORIG_RAX(%rsp), %rsi /* get error code into 2nd argument*/ + movq $-1, ORIG_RAX(%rsp) /* no syscall to restart */ + movq %r12, %rdx /* Move CR2 into 3rd argument */ + call \cfunc + + jmp paranoid_exit + +_ASM_NOKPROBE(\asmsym) +SYM_CODE_END(\asmsym) +.endm + /* * Interrupt entry helper function. *
@@ -860,195 +1057,35 @@ apicinterrupt IRQ_WORK_VECTOR irq_work_interrupt smp_irq_work_interrupt /* * Exception entry points. */ -#define CPU_TSS_IST(x) PER_CPU_VAR(cpu_tss_rw) + (TSS_ist + (x) * 8) - -.macro idtentry_part do_sym, has_error_code:req, read_cr2:req, paranoid:req, shift_ist=-1, ist_offset=0 - - .if \paranoid - call paranoid_entry - /* returned flag: ebx=0: need swapgs on exit, ebx=1: don't need it */ - .else - call error_entry - .endif - UNWIND_HINT_REGS - - .if \read_cr2 - /* - * Store CR2 early so subsequent faults cannot clobber it. Use R12 as - * intermediate storage as RDX can be clobbered in enter_from_user_mode(). - * GET_CR2_INTO can clobber RAX. - */ - GET_CR2_INTO(%r12); - .endif - - .if \shift_ist != -1 - TRACE_IRQS_OFF_DEBUG /* reload IDT in case of recursion */ - .else - TRACE_IRQS_OFF - .endif - -#ifdef CONFIG_CONTEXT_TRACKING - .if \paranoid == 0 - testb $3, CS(%rsp) - jz .Lfrom_kernel_no_context_tracking_\@ - CALL_enter_from_user_mode -.Lfrom_kernel_no_context_tracking_\@: - .endif -#endif - - movq %rsp, %rdi /* pt_regs pointer */ - - .if \has_error_code - movq ORIG_RAX(%rsp), %rsi /* get error code */ - movq $-1, ORIG_RAX(%rsp) /* no syscall to restart */ - .else - xorl %esi, %esi /* no error code */ - .endif - - .if \shift_ist != -1 - subq $\ist_offset, CPU_TSS_IST(\shift_ist) - .endif - - .if \read_cr2 - movq %r12, %rdx /* Move CR2 into 3rd argument */ - .endif - - call \do_sym - - .if \shift_ist != -1 - addq $\ist_offset, CPU_TSS_IST(\shift_ist) - .endif - - .if \paranoid - /* this procedure expect "no swapgs" flag in ebx */ - jmp paranoid_exit - .else - jmp error_exit - .endif - -.endm - -/** - * idtentry - Generate an IDT entry stub - * @sym: Name of the generated entry point - * @do_sym: C function to be called - * @has_error_code: True if this IDT vector has an error code on the stack - * @paranoid: non-zero means that this vector may be invoked from - * kernel mode with user GSBASE and/or user CR3. - * 2 is special -- see below. - * @shift_ist: Set to an IST index if entries from kernel mode should - * decrement the IST stack so that nested entries get a - * fresh stack. (This is for #DB, which has a nasty habit - * of recursing.) - * @create_gap: create a 6-word stack gap when coming from kernel mode. - * @read_cr2: load CR2 into the 3rd argument; done before calling any C code - * - * idtentry generates an IDT stub that sets up a usable kernel context, - * creates struct pt_regs, and calls @do_sym. The stub has the following - * special behaviors: - * - * On an entry from user mode, the stub switches from the trampoline or - * IST stack to the normal thread stack. On an exit to user mode, the - * normal exit-to-usermode path is invoked. - * - * On an exit to kernel mode, if @paranoid == 0, we check for preemption, - * whereas we omit the preemption check if @paranoid != 0. This is purely - * because the implementation is simpler this way. The kernel only needs - * to check for asynchronous kernel preemption when IRQ handlers return. - * - * If @paranoid == 0, then the stub will handle IRET faults by pretending - * that the fault came from user mode. It will handle gs_change faults by - * pretending that the fault happened with kernel GSBASE. Since this handling - * is omitted for @paranoid != 0, the #GP, #SS, and #NP stubs must have - * @paranoid == 0. This special handling will do the wrong thing for - * espfix-induced #DF on IRET, so #DF must not use @paranoid == 0. - * - * @paranoid == 2 is special: the stub will never switch stacks. This is for - * #DF: if the thread stack is somehow unusable, we'll still get a useful OOPS. - */ -.macro idtentry sym do_sym has_error_code:req paranoid=0 shift_ist=-1 ist_offset=0 create_gap=0 read_cr2=0 -SYM_CODE_START(\sym) - UNWIND_HINT_IRET_REGS offset=\has_error_code*8 - - /* Sanity check */ - .if \shift_ist != -1 && \paranoid != 1 - .error "using shift_ist requires paranoid=1" - .endif - - .if \create_gap && \paranoid - .error "using create_gap requires paranoid=0" - .endif - - ASM_CLAC - - .if \has_error_code == 0 - pushq $-1 /* ORIG_RAX: no syscall to restart */ - .endif - - .if \paranoid == 1 - testb $3, CS-ORIG_RAX(%rsp) /* If coming from userspace, switch stacks */ - jnz .Lfrom_usermode_switch_stack_\@ - .endif - - .if \create_gap == 1 - /* - * If coming from kernel space, create a 6-word gap to allow the - * int3 handler to emulate a call instruction. - */ - testb $3, CS-ORIG_RAX(%rsp) - jnz .Lfrom_usermode_no_gap_\@ - .rept 6 - pushq 5*8(%rsp) - .endr - UNWIND_HINT_IRET_REGS offset=8 -.Lfrom_usermode_no_gap_\@: - .endif - - idtentry_part \do_sym, \has_error_code, \read_cr2, \paranoid, \shift_ist, \ist_offset - - .if \paranoid == 1 - /* - * Entry from userspace. Switch stacks and treat it - * as a normal entry. This means that paranoid handlers - * run in real process context if user_mode(regs). - */ -.Lfrom_usermode_switch_stack_\@: - idtentry_part \do_sym, \has_error_code, \read_cr2, paranoid=0 - .endif - -_ASM_NOKPROBE(\sym) -SYM_CODE_END(\sym) -.endm - -idtentry divide_error do_divide_error has_error_code=0 -idtentry overflow do_overflow has_error_code=0 -idtentry int3 do_int3 has_error_code=0 create_gap=1 -idtentry bounds do_bounds has_error_code=0 -idtentry invalid_op do_invalid_op has_error_code=0 -idtentry device_not_available do_device_not_available has_error_code=0 -idtentry coprocessor_segment_overrun do_coprocessor_segment_overrun has_error_code=0 -idtentry invalid_TSS do_invalid_TSS has_error_code=1 -idtentry segment_not_present do_segment_not_present has_error_code=1 -idtentry stack_segment do_stack_segment has_error_code=1 -idtentry general_protection do_general_protection has_error_code=1 -idtentry spurious_interrupt_bug do_spurious_interrupt_bug has_error_code=0 -idtentry coprocessor_error do_coprocessor_error has_error_code=0 -idtentry alignment_check do_alignment_check has_error_code=1 -idtentry simd_coprocessor_error do_simd_coprocessor_error has_error_code=0 - -idtentry page_fault do_page_fault has_error_code=1 read_cr2=1 +idtentry X86_TRAP_DE divide_error do_divide_error has_error_code=0 +idtentry X86_TRAP_OF overflow do_overflow has_error_code=0 +idtentry X86_TRAP_BP int3 do_int3 has_error_code=0 +idtentry X86_TRAP_BR bounds do_bounds has_error_code=0 +idtentry X86_TRAP_UD invalid_op do_invalid_op has_error_code=0 +idtentry X86_TRAP_NM device_not_available do_device_not_available has_error_code=0 +idtentry X86_TRAP_OLD_MF coprocessor_segment_overrun do_coprocessor_segment_overrun has_error_code=0 +idtentry X86_TRAP_TS invalid_TSS do_invalid_TSS has_error_code=1 +idtentry X86_TRAP_NP segment_not_present do_segment_not_present has_error_code=1 +idtentry X86_TRAP_SS stack_segment do_stack_segment has_error_code=1 +idtentry X86_TRAP_GP general_protection do_general_protection has_error_code=1 +idtentry X86_TRAP_SPURIOUS spurious_interrupt_bug do_spurious_interrupt_bug has_error_code=0 +idtentry X86_TRAP_MF coprocessor_error do_coprocessor_error has_error_code=0 +idtentry X86_TRAP_AC alignment_check do_alignment_check has_error_code=1 +idtentry X86_TRAP_XF simd_coprocessor_error do_simd_coprocessor_error has_error_code=0 + +idtentry X86_TRAP_PF page_fault do_page_fault has_error_code=1 #ifdef CONFIG_X86_MCE -idtentry machine_check do_mce has_error_code=0 paranoid=1 +idtentry_mce_db X86_TRAP_MCE machine_check do_mce #endif -idtentry debug do_debug has_error_code=0 paranoid=1 shift_ist=IST_INDEX_DB ist_offset=DB_STACK_OFFSET -idtentry double_fault do_double_fault has_error_code=1 paranoid=2 read_cr2=1 +idtentry_mce_db X86_TRAP_DB debug do_debug +idtentry_df X86_TRAP_DF double_fault do_double_fault #ifdef CONFIG_XEN_PV -idtentry hypervisor_callback xen_do_hypervisor_callback has_error_code=0 -idtentry xennmi do_nmi has_error_code=0 -idtentry xendebug do_debug has_error_code=0 +idtentry 512 /* dummy */ hypervisor_callback xen_do_hypervisor_callback has_error_code=0 +idtentry X86_TRAP_NMI xennmi do_nmi has_error_code=0 +idtentry X86_TRAP_DB xendebug do_debug has_error_code=0 #endif /*
PATCH v4 8/29 x86/entry/64: Provide sane error entry/exit
In reply to Thomas GleixnerFor gradual conversion provide a macro parameter and the required code which allows to handle instrumentation and interrupt flags tracking in C.
--- arch/x86/entry/entry_64.S | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-)
arch/x86/entry/entry_64.S +19 -3
@@ -500,8 +500,9 @@ SYM_CODE_END(spurious_entries_start) * @vector: Vector number * @cfunc: C function to be called * @has_error_code: Hardware pushed error code on stack + * @sane: Sane variant which handles irq tracing, context tracking in C */ -.macro idtentry_body vector cfunc has_error_code:req +.macro idtentry_body vector cfunc has_error_code:req sane=0 call error_entry UNWIND_HINT_REGS
@@ -515,6 +516,7 @@ SYM_CODE_END(spurious_entries_start) GET_CR2_INTO(%r12); .endif + .if \sane == 0 TRACE_IRQS_OFF #ifdef CONFIG_CONTEXT_TRACKING
@@ -523,6 +525,7 @@ SYM_CODE_END(spurious_entries_start) CALL_enter_from_user_mode .Lfrom_kernel_no_ctxt_tracking_\@: #endif + .endif movq %rsp, %rdi /* pt_regs pointer into 1st argument*/
@@ -539,7 +542,11 @@ SYM_CODE_END(spurious_entries_start) call \cfunc + .if \sane == 0 jmp error_exit + .else + jmp error_return + .endif .endm /**
@@ -548,11 +555,12 @@ SYM_CODE_END(spurious_entries_start) * @asmsym: ASM symbol for the entry point * @cfunc: C function to be called * @has_error_code: Hardware pushed error code on stack + * @sane: Sane variant which handles irq tracing, context tracking in C * * The macro emits code to set up the kernel context for straight forward * and simple IDT entries. No IST stack, no paranoid entry checks. */ -.macro idtentry vector asmsym cfunc has_error_code:req +.macro idtentry vector asmsym cfunc has_error_code:req sane=0 SYM_CODE_START(\asmsym) UNWIND_HINT_IRET_REGS offset=\has_error_code*8 ASM_CLAC
@@ -575,7 +583,7 @@ SYM_CODE_START(\asmsym) .Lfrom_usermode_no_gap_\@: .endif - idtentry_body \vector \cfunc \has_error_code + idtentry_body \vector \cfunc \has_error_code \sane _ASM_NOKPROBE(\asmsym) SYM_CODE_END(\asmsym)
@@ -1405,6 +1413,14 @@ SYM_CODE_START_LOCAL(error_exit) jmp .Lretint_user SYM_CODE_END(error_exit) +SYM_CODE_START_LOCAL(error_return) + UNWIND_HINT_REGS + DEBUG_ENTRY_ASSERT_IRQS_OFF + testb $3, CS(%rsp) + jz restore_regs_and_return_to_kernel + jmp swapgs_restore_regs_and_return_to_usermode +SYM_CODE_END(error_return) + /* * Runs on exception stack. Xen PV does not go through this path at all, * so we can use real assembly here.
Re: [patch V4 part 3 08/29] x86/entry/64: Provide sane error entry/exit
Quoted 3 lines · Thomas Gleixner
For gradual conversion provide a macro parameter and the required code which allows to handle instrumentation and interrupt flags tracking in C.
Steven Rostedt
reviewerRe: [patch V4 part 3 08/29] x86/entry/64: Provide sane error entry/exit
In reply to Thomas Gleixnerarch/x86/entry/entry_64.S SYM_CODE_END(spurious_entries_start) · line 520
Quoted 2 lines · On Tue, 05 May 2020 15:44:02 +0200 Thomas Gleixner <[email protected]> wrote:
arch/x86/entry/entry_64.S +1
-0+ .if \sane == 0 TRACE_IRQS_OFF
Are you implying that TRACE_IRQS_OFF is insane?
-- Steve
Re: [patch V4 part 3 08/29] x86/entry/64: Provide sane error entry/exit
Quoted 7 lines · Steven Rostedt
arch/x86/entry/entry_64.S SYM_CODE_END(spurious_entries_start) · line 520
Quoted 2 lines · On Tue, 05 May 2020 15:44:02 +0200 Thomas Gleixner <[email protected]> wrote:
arch/x86/entry/entry_64.S +1
-0+ .if \sane == 0 TRACE_IRQS_OFFAre you implying that
TRACE_IRQS_OFFis insane?
Very much so.
[tip: x86/entry] x86/entry/64: Provide sane error entry/exit
In reply to Thomas GleixnerThe following commit has been merged into the x86/entry branch of tip:
The following commit has been merged into the x86/entry branch of tip:
Commit-ID: 3660da2d124813bed342e25b39df0251cbe2ac4f Gitweb: https://git.kernel.org/tip/3660da2d124813bed342e25b39df0251cbe2ac4f Author: Thomas Gleixner <[email protected]> AuthorDate: Thu, 26 Mar 2020 16:56:20 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 19 May 2020 16:03:56 +02:00
x86/entry/64: Provide sane error entry/exit
For gradual conversion provide a macro parameter and the required code which allows to handle instrumentation and interrupt flags tracking in C.
--- arch/x86/entry/entry_64.S | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-)
arch/x86/entry/entry_64.S +19 -3
@@ -499,8 +499,9 @@ SYM_CODE_END(spurious_entries_start) * @vector: Vector number * @cfunc: C function to be called * @has_error_code: Hardware pushed error code on stack + * @sane: Sane variant which handles irq tracing, context tracking in C */ -.macro idtentry_body vector cfunc has_error_code:req +.macro idtentry_body vector cfunc has_error_code:req sane=0 call error_entry UNWIND_HINT_REGS
@@ -514,6 +515,7 @@ SYM_CODE_END(spurious_entries_start) GET_CR2_INTO(%r12); .endif + .if \sane == 0 TRACE_IRQS_OFF #ifdef CONFIG_CONTEXT_TRACKING
@@ -522,6 +524,7 @@ SYM_CODE_END(spurious_entries_start) CALL_enter_from_user_mode .Lfrom_kernel_no_ctxt_tracking_\@: #endif + .endif movq %rsp, %rdi /* pt_regs pointer into 1st argument*/
@@ -538,7 +541,11 @@ SYM_CODE_END(spurious_entries_start) call \cfunc + .if \sane == 0 jmp error_exit + .else + jmp error_return + .endif .endm /**
@@ -547,11 +554,12 @@ SYM_CODE_END(spurious_entries_start) * @asmsym: ASM symbol for the entry point * @cfunc: C function to be called * @has_error_code: Hardware pushed error code on stack + * @sane: Sane variant which handles irq tracing, context tracking in C * * The macro emits code to set up the kernel context for straight forward * and simple IDT entries. No IST stack, no paranoid entry checks. */ -.macro idtentry vector asmsym cfunc has_error_code:req +.macro idtentry vector asmsym cfunc has_error_code:req sane=0 SYM_CODE_START(\asmsym) UNWIND_HINT_IRET_REGS offset=\has_error_code*8 ASM_CLAC
@@ -574,7 +582,7 @@ SYM_CODE_START(\asmsym) .Lfrom_usermode_no_gap_\@: .endif - idtentry_body \vector \cfunc \has_error_code + idtentry_body \vector \cfunc \has_error_code \sane _ASM_NOKPROBE(\asmsym) SYM_CODE_END(\asmsym)
@@ -1403,6 +1411,14 @@ SYM_CODE_START_LOCAL(error_exit) jmp .Lretint_user SYM_CODE_END(error_exit) +SYM_CODE_START_LOCAL(error_return) + UNWIND_HINT_REGS + DEBUG_ENTRY_ASSERT_IRQS_OFF + testb $3, CS(%rsp) + jz restore_regs_and_return_to_kernel + jmp swapgs_restore_regs_and_return_to_usermode +SYM_CODE_END(error_return) + /* * Runs on exception stack. Xen PV does not go through this path at all, * so we can use real assembly here.
PATCH v4 9/29 x86/entry/32: Provide macro to emit IDT entry stubs
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
32 and 64 bit have unnecessary different ways to populate the exception entry code. Provide a idtentry macro which allows to consolidate all of that.
---
V3: Remove the INVD bug asm. Can be done in C (Brian)
--- arch/x86/entry/entry_32.S | 68 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+)
arch/x86/entry/entry_32.S +68 -0
@@ -44,6 +44,7 @@ #include <asm/asm.h> #include <asm/smap.h> #include <asm/frame.h> +#include <asm/trapnr.h> #include <asm/nospec-branch.h> #include "calling.h"
@@ -726,6 +727,31 @@ .Lend_\@: .endm + +/** + * idtentry - Macro to generate entry stubs for simple IDT entries + * @vector: Vector number + * @asmsym: ASM symbol for the entry point + * @cfunc: C function to be called + * @has_error_code: Hardware pushed error code on stack + * @sane: Compatibility flag with 64bit + */ +.macro idtentry vector asmsym cfunc has_error_code:req sane=0 +SYM_CODE_START(\asmsym) + ASM_CLAC + cld + + .if \has_error_code == 0 + pushl $0 /* Clear the error code */ + .endif + + /* Push the C-function address into the GS slot */ + pushl $\cfunc + /* Invoke the common exception entry */ + jmp handle_exception +SYM_CODE_END(\asmsym) +.endm + /* * %eax: prev task * %edx: next task
@@ -1517,6 +1543,48 @@ SYM_CODE_START_LOCAL_NOALIGN(common_exce jmp ret_from_exception SYM_CODE_END(common_exception) +SYM_CODE_START_LOCAL_NOALIGN(handle_exception) + /* the function address is in %gs's slot on the stack */ + SAVE_ALL switch_stacks=1 skip_gs=1 unwind_espfix=1 + ENCODE_FRAME_POINTER + + /* fixup %gs */ + GS_TO_REG %ecx + movl PT_GS(%esp), %edi # get the function address + REG_TO_PTGS %ecx + SET_KERNEL_GS %ecx + + /* fixup orig %eax */ + movl PT_ORIG_EAX(%esp), %edx # get the error code + movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart + + movl %esp, %eax # pt_regs pointer + CALL_NOSPEC edi + +#ifdef CONFIG_VM86 + movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS + movb PT_CS(%esp), %al + andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax +#else + /* + * We can be coming here from child spawned by kernel_thread(). + */ + movl PT_CS(%esp), %eax + andl $SEGMENT_RPL_MASK, %eax +#endif + cmpl $USER_RPL, %eax # returning to v8086 or userspace ? + jnb ret_to_user + + PARANOID_EXIT_TO_KERNEL_MODE + BUG_IF_WRONG_CR3 + RESTORE_REGS 4 + jmp .Lirq_return + +ret_to_user: + movl %esp, %eax + jmp restore_all_switch_stack +SYM_CODE_END(handle_exception) + SYM_CODE_START(debug) /* * Entry from sysenter is now handled in common_exception
Re: [patch V4 part 3 09/29] x86/entry/32: Provide macro to emit IDT entry stubs
Quoted 9 lines · Thomas Gleixner
From: Thomas Gleixner <[email protected]>
32 and 64 bit have unnecessary different ways to populate the exception entry code. Provide a idtentry macro which allows to consolidate all of that.
Signed-off-by Thomas Gleixner <[email protected]>Reviewed-by Alexandre Chartre <[email protected]>
arch/x86/entry/entry_32.S SYM_CODE_START_LOCAL_NOALIGN(common_exce · line 1555
Quoted 5 lines
arch/x86/entry/entry_32.S +5
-0+ /* fixup %gs */ + GS_TO_REG %ecx + movl PT_GS(%esp), %edi # get the function address + REG_TO_PTGS %ecx + SET_KERNEL_GS %ecx
This GS garbage remains an atrocity. Some day if I'm inspired to clean up 32-bit stuff, I'll decrapify it.
Mathieu Desnoyers
reviewerRe: [patch V4 part 3 09/29] x86/entry/32: Provide macro to emit IDT entry stubs
In reply to Thomas Gleixner----- On May 5, 2020, at 9:44 AM, Thomas Gleixner [email protected] wrote:
[...]
arch/x86/entry/entry_32.S line 742
Quoted 4 lines
+.macro idtentry vector asmsym cfunc has_error_code:req sane=0
arch/x86/entry/entry_32.S +3
-0+SYM_CODE_START(\asmsym) + ASM_CLAC + cld
Looking at the various interrupt and trap entry points for 32 and 64-bit x86, I notice a lack of consistency in use of the following instruction sequence at the asm entry point:
- ASM_CLAC,
- cld (clear direction flag).
Are they always needed, or only for interrupt handlers ?
Thanks,
Mathieu
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com
Andy Lutomirski
maintainerRe: [patch V4 part 3 09/29] x86/entry/32: Provide macro to emit IDT entry stubs
Quoted 10 lines · Mathieu Desnoyers
----- On May 5, 2020, at 9:44 AM, Thomas Gleixner [email protected] wrote:
[...]
arch/x86/entry/entry_32.S line 742
Quoted 4 lines
+.macro idtentry vector asmsym cfunc has_error_code:req sane=0
arch/x86/entry/entry_32.S +3
-0+SYM_CODE_START(\asmsym) + ASM_CLAC + cld
Quoted 8 lines
Looking at the various interrupt and trap entry points for 32 and 64-bit x86, I notice a lack of consistency in use of the following instruction sequence at the asm entry point:
-
ASM_CLAC,
- cld (clear direction flag).Are they always needed, or only for interrupt handlers ?
They're needed for all entries except SYSCALL, but they're hidden inside helpers in many cases.
Mathieu Desnoyers
reviewerRe: [patch V4 part 3 09/29] x86/entry/32: Provide macro to emit IDT entry stubs
Quoted 16 lines · ----- On May 14, 2020, at 12:31 AM, Andy Lutomirski [email protected] wrote:
Quoted 14 lines · Mathieu Desnoyers
----- On May 5, 2020, at 9:44 AM, Thomas Gleixner [email protected] wrote:
[...]
arch/x86/entry/entry_32.S line 742
Quoted 4 lines
+.macro idtentry vector asmsym cfunc has_error_code:req sane=0
arch/x86/entry/entry_32.S +3
-0+SYM_CODE_START(\asmsym) + ASM_CLAC + cldLooking at the various interrupt and trap entry points for 32 and 64-bit x86, I notice a lack of consistency in use of the following instruction sequence at the asm entry point:
Quoted 7 lines
Quoted 4 lines
-
ASM_CLAC,
- cld (clear direction flag).Are they always needed, or only for interrupt handlers ?
They're needed for all entries except SYSCALL, but they're hidden inside helpers in many cases.
Indeed, on x86-32 the macro SAVE_ALL contains cld. That architecture appears to be OK.
What I am concerned about is the idtentry, idtentry_mce_db, and idtentry_df macros introduced in entry_64.S by this series. Those are supposed to be technically equivalent to the prior code, which indeed has the ASM_CLAC but no "cld".
So maybe the cld happens to be hidden elsewhere, but I'm clearly missing it ? Or is it not needed for some reason ?
Thanks,
Mathieu
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com
Re: [patch V4 part 3 09/29] x86/entry/32: Provide macro to emit IDT entry stubs
Quoted 9 lines · Mathieu Desnoyers
Quoted 4 lines · ----- On May 14, 2020, at 12:31 AM, Andy Lutomirski [email protected] wrote:
On Wed, May 13, 2020 at 6:44 PM Mathieu Desnoyers <[email protected]> wrote:
They're needed for all entries except SYSCALL, but they're hidden inside helpers in many cases.Indeed, on x86-32 the macro
SAVE_ALLcontains cld. That architecture appears to be OK.
Quoted 7 lines
What I am concerned about is the idtentry,
idtentry_mce_db, andidtentry_dfmacros introduced inentry_64.Sby this series. Those are supposed to be technically equivalent to the prior code, which indeed has theASM_CLACbut no "cld".So maybe the cld happens to be hidden elsewhere, but I'm clearly missing it ? Or is it not needed for some reason ?
It's needed and it is there where it was forever in error_entry and paranoid_entry.
It probably makes sense to stick it right after the CLAC.
Thanks,
tglx
Mathieu Desnoyers
reviewerRe: [patch V4 part 3 09/29] x86/entry/32: Provide macro to emit IDT entry stubs
Quoted 15 lines · ----- Thomas Gleixner
Quoted 14 lines · Mathieu Desnoyers
Quoted 4 lines · ----- On May 14, 2020, at 12:31 AM, Andy Lutomirski [email protected] wrote:
On Wed, May 13, 2020 at 6:44 PM Mathieu Desnoyers <[email protected]> wrote:
They're needed for all entries except SYSCALL, but they're hidden inside helpers in many cases.Indeed, on x86-32 the macro
SAVE_ALLcontains cld. That architecture appears to be OK.What I am concerned about is the idtentry,
idtentry_mce_db, andidtentry_dfmacros introduced inentry_64.Sby this series. Those are supposed to be technically equivalent to the prior code, which indeed has theASM_CLACbut no "cld".
Quoted 5 lines
Quoted 2 lines
So maybe the cld happens to be hidden elsewhere, but I'm clearly missing it ? Or is it not needed for some reason ?
It's needed and it is there where it was forever in
error_entryandparanoid_entry.
Ok I simply missed it.
Quoted 2 lines
It probably makes sense to stick it right after the CLAC.
Indeed.
Thanks!
Mathieu
Quoted 6 lines
Thanks,
tglx
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com
[tip: x86/entry] x86/entry/32: Provide macro to emit IDT entry stubs
In reply to Thomas GleixnerThe following commit has been merged into the x86/entry branch of tip:
The following commit has been merged into the x86/entry branch of tip:
Commit-ID: e94587c501c82a3c9153217a97db11a81ed37f85 Gitweb: https://git.kernel.org/tip/e94587c501c82a3c9153217a97db11a81ed37f85 Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 25 Feb 2020 23:16:11 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 19 May 2020 16:03:56 +02:00
x86/entry/32: Provide macro to emit IDT entry stubs
32 and 64 bit have unnecessary different ways to populate the exception entry code. Provide a idtentry macro which allows to consolidate all of that.
--- arch/x86/entry/entry_32.S | 68 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+)
arch/x86/entry/entry_32.S +68 -0
@@ -44,6 +44,7 @@ #include <asm/asm.h> #include <asm/smap.h> #include <asm/frame.h> +#include <asm/trapnr.h> #include <asm/nospec-branch.h> #include "calling.h"
@@ -726,6 +727,31 @@ .Lend_\@: .endm + +/** + * idtentry - Macro to generate entry stubs for simple IDT entries + * @vector: Vector number + * @asmsym: ASM symbol for the entry point + * @cfunc: C function to be called + * @has_error_code: Hardware pushed error code on stack + * @sane: Compatibility flag with 64bit + */ +.macro idtentry vector asmsym cfunc has_error_code:req sane=0 +SYM_CODE_START(\asmsym) + ASM_CLAC + cld + + .if \has_error_code == 0 + pushl $0 /* Clear the error code */ + .endif + + /* Push the C-function address into the GS slot */ + pushl $\cfunc + /* Invoke the common exception entry */ + jmp handle_exception +SYM_CODE_END(\asmsym) +.endm + /* * %eax: prev task * %edx: next task
@@ -1517,6 +1543,48 @@ SYM_CODE_START_LOCAL_NOALIGN(common_exception) jmp ret_from_exception SYM_CODE_END(common_exception) +SYM_CODE_START_LOCAL_NOALIGN(handle_exception) + /* the function address is in %gs's slot on the stack */ + SAVE_ALL switch_stacks=1 skip_gs=1 unwind_espfix=1 + ENCODE_FRAME_POINTER + + /* fixup %gs */ + GS_TO_REG %ecx + movl PT_GS(%esp), %edi # get the function address + REG_TO_PTGS %ecx + SET_KERNEL_GS %ecx + + /* fixup orig %eax */ + movl PT_ORIG_EAX(%esp), %edx # get the error code + movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart + + movl %esp, %eax # pt_regs pointer + CALL_NOSPEC edi + +#ifdef CONFIG_VM86 + movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS + movb PT_CS(%esp), %al + andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax +#else + /* + * We can be coming here from child spawned by kernel_thread(). + */ + movl PT_CS(%esp), %eax + andl $SEGMENT_RPL_MASK, %eax +#endif + cmpl $USER_RPL, %eax # returning to v8086 or userspace ? + jnb ret_to_user + + PARANOID_EXIT_TO_KERNEL_MODE + BUG_IF_WRONG_CR3 + RESTORE_REGS 4 + jmp .Lirq_return + +ret_to_user: + movl %esp, %eax + jmp restore_all_switch_stack +SYM_CODE_END(handle_exception) + SYM_CODE_START(debug) /* * Entry from sysenter is now handled in common_exception
PATCH v4 10/29 x86/idtentry: Provide macros to define/declare IDT entry points
In reply to Thomas GleixnerProvide DECLARE/DEFINE_IDTENTRY() macros.
DEFINE_IDTENTRY() provides a wrapper which acts as the function definition. The exception handler body is just appended to it with curly brackets. The entry point is marked notrace/noprobe so that irq tracing and the enter_from_user_mode() can be moved into the C-entry point. As all C-entries use the same macro (or a later variant) the necessary entry handling can be implemented at one central place.
DECLARE_IDTENTRY() provides the function prototypes:
- The C entry point cfunc
- The ASM entry point asm_cfunc
- The XEN/PV entry point xen_asm_cfunc
They all follow the same naming convention.
When included from ASM code DECLARE_IDTENTRY() is a macro which emits the low level entry point in assembly by instantiating idtentry.
IDTENTRY is the simplest variant which just has a pt_regs argument. It's going to be used for all exceptions which have no error code.
---
V2: Add comments to explain the C vs. ASM variants
--- arch/x86/entry/entry_32.S | 6 +++ arch/x86/entry/entry_64.S | 6 +++ arch/x86/include/asm/idtentry.h | 67 ++++++++++++++++++++++++++++++++++++++++ arch/x86/include/asm/traps.h | 2 - 4 files changed, 80 insertions(+), 1 deletion(-)
arch/x86/entry/entry_32.S +6 -0
@@ -753,6 +753,12 @@ SYM_CODE_END(\asmsym) .endm /* + * Include the defines which emit the idt entries which are shared + * shared between 32 and 64 bit. + */ +#include <asm/idtentry.h> + +/* * %eax: prev task * %edx: next task */
arch/x86/entry/entry_64.S +6 -0
@@ -700,6 +700,12 @@ SYM_CODE_END(\asmsym) .endm /* + * Include the defines which emit the idt entries which are shared + * shared between 32 and 64 bit. + */ +#include <asm/idtentry.h> + +/* * Interrupt entry helper function. * * Entry runs with interrupts off. Stack layout at entry:
arch/x86/include/asm/idtentry.h new file +67 -0
67 lines not on this page · raw message
arch/x86/include/asm/traps.h +1 -1
@@ -6,8 +6,8 @@#include <linux/kprobes.h> #include <asm/debugreg.h> +#include <asm/idtentry.h> #include <asm/siginfo.h> /* TRAP_TRACE, ... */ -#include <asm/trapnr.h> #define dotraplinkage __visible
Re: [patch V4 part 3 10/29] x86/idtentry: Provide macros to define/declare IDT entry points
Quoted 2 lines · Thomas Gleixner
Provide DECLARE/DEFINE_IDTENTRY() macros.
except:
Quoted 5 lines
DEFINE_IDTENTRY()provides a wrapper which acts as the function definition. The exception handler body is just appended to it with curly brackets. The entry point is marked notrace/noprobe so that irq tracing and theenter_from_user_mode()can be moved into the C-entry point.
"noinstr", perhaps? I'm guessing you write this text before noinstr happened.
Also, would it perhaps make sense in the future to include the idtentry macro somehow (via inline asm or gcc options) so that DEFINE_IDTENTRY() could emit the stub instead of leaving it to DECLARE_IDTENTRY()? It might end up too messy in practice, I suppose. This is obviously not worth changing right now, but maybe down the road.
Re: [patch V4 part 3 10/29] x86/idtentry: Provide macros to define/declare IDT entry points
Quoted 9 lines · Andy Lutomirski
Quoted 2 lines · Thomas Gleixner
Provide DECLARE/DEFINE_IDTENTRY() macros.
Acked-by Andy Lutomirski <[email protected]>except:
Quoted 1 line
Quoted 7 lines
Quoted 4 lines
DEFINE_IDTENTRY()provides a wrapper which acts as the function definition. The exception handler body is just appended to it with curly brackets. The entry point is marked notrace/noprobe so that irq tracing and theenter_from_user_mode()can be moved into the C-entry point."noinstr", perhaps? I'm guessing you write this text before noinstr happened.
Yes.
Quoted 6 lines
Also, would it perhaps make sense in the future to include the idtentry macro somehow (via inline asm or gcc options) so that
DEFINE_IDTENTRY()could emit the stub instead of leaving it toDECLARE_IDTENTRY()? It might end up too messy in practice, I suppose. This is obviously not worth changing right now, but maybe down the road.
Maybe. Right now my entry/rcu/tracing induced brainmelt is far too advanced to try thinking about it :)
[tip: x86/entry] x86/idtentry: Provide macros to define/declare IDT entry points
In reply to Thomas GleixnerThe following commit has been merged into the x86/entry branch of tip:
The following commit has been merged into the x86/entry branch of tip:
Commit-ID: c5c3c71d132f6480c71bc91723d3d987abfdfaa3 Gitweb: https://git.kernel.org/tip/c5c3c71d132f6480c71bc91723d3d987abfdfaa3 Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 25 Feb 2020 23:16:12 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 19 May 2020 16:03:56 +02:00
x86/idtentry: Provide macros to define/declare IDT entry points
Provide DECLARE/DEFINE_IDTENTRY() macros.
DEFINE_IDTENTRY() provides a wrapper which acts as the function definition. The exception handler body is just appended to it with curly brackets. The entry point is marked noinstr so that irq tracing and the enter_from_user_mode() can be moved into the C-entry point. As all C-entries use the same macro (or a later variant) the necessary entry handling can be implemented at one central place.
DECLARE_IDTENTRY() provides the function prototypes:
- The C entry point cfunc
- The ASM entry point asm_cfunc
- The XEN/PV entry point xen_asm_cfunc
They all follow the same naming convention.
When included from ASM code DECLARE_IDTENTRY() is a macro which emits the low level entry point in assembly by instantiating idtentry.
IDTENTRY is the simplest variant which just has a pt_regs argument. It's going to be used for all exceptions which have no error code.
--- arch/x86/entry/entry_32.S | 6 +++- arch/x86/entry/entry_64.S | 6 +++- arch/x86/include/asm/idtentry.h | 67 ++++++++++++++++++++++++++++++++- arch/x86/include/asm/traps.h | 2 +- 4 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 arch/x86/include/asm/idtentry.h
arch/x86/entry/entry_32.S +6 -0
@@ -753,6 +753,12 @@ SYM_CODE_END(\asmsym) .endm /* + * Include the defines which emit the idt entries which are shared + * shared between 32 and 64 bit. + */ +#include <asm/idtentry.h> + +/* * %eax: prev task * %edx: next task */
arch/x86/entry/entry_64.S +6 -0
@@ -699,6 +699,12 @@ SYM_CODE_END(\asmsym) .endm /* + * Include the defines which emit the idt entries which are shared + * shared between 32 and 64 bit. + */ +#include <asm/idtentry.h> + +/* * Interrupt entry helper function. * * Entry runs with interrupts off. Stack layout at entry:
arch/x86/include/asm/idtentry.h new file +67 -0
67 lines not on this page · raw message
arch/x86/include/asm/traps.h +1 -1
@@ -6,8 +6,8 @@#include <linux/kprobes.h> #include <asm/debugreg.h> +#include <asm/idtentry.h> #include <asm/siginfo.h> /* TRAP_TRACE, ... */ -#include <asm/trapnr.h> #define dotraplinkage __visible
PATCH v4 11/29 rcu: Provide rcu_irq_exit_preempt()
In reply to Thomas GleixnerInterrupts and exceptions invoke rcu_irq_enter() on entry and need to invoke rcu_irq_exit() before they either return to the interrupted code or invoke the scheduler due to preemption.
The general assumption is that RCU idle code has to have preemption disabled so that a return from interrupt cannot schedule. So the return from interrupt code invokes rcu_irq_exit() and preempt_schedule_irq().
If there is any imbalance in the rcu_irq/nmi* invocations or RCU idle code had preemption enabled then this goes unnoticed until the CPU goes idle or some other RCU check is executed.
Provide rcu_irq_exit_preempt() which can be invoked from the interrupt/exception return code in case that preemption is enabled. It invokes rcu_irq_exit() and contains a few sanity checks in case that CONFIG_PROVE_RCU is enabled to catch such issues directly.
--- include/linux/rcutiny.h | 1 + include/linux/rcutree.h | 1 + kernel/rcu/tree.c | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+)
include/linux/rcutiny.h +1 -0
@@ -71,6 +71,7 @@ static inline void rcu_irq_enter(void) {static inline void rcu_irq_exit_irqson (void ) { }static inline void rcu_irq_enter_irqson (void ) { }static inline void rcu_irq_exit (void ) { } +static inline void rcu_irq_exit_preempt (void ) { }static inline void exit_rcu (void ) { }static inline bool rcu_preempt_need_deferred_qs (struct task_struct *t) {
include/linux/rcutree.h +1 -0
@@ -46,6 +46,7 @@ void rcu_idle_enter(void);void rcu_idle_exit (void );void rcu_irq_enter (void );void rcu_irq_exit (void ); +void rcu_irq_exit_preempt (void );void rcu_irq_enter_irqson (void );void rcu_irq_exit_irqson (void );
kernel/rcu/tree.c +21 -0
@@ -706,6 +706,27 @@ void noinstr rcu_irq_exit(void)rcu_nmi_exit (); } +/** +* rcu_irq_exit_preempt - Inform RCU that current CPU is exiting irq +* towards in kernel preemption +* +* Same as rcu_irq_exit() but has a sanity check that scheduling is safe +* from RCU point of view. Invoked from return from interrupt before kernel +* preemption. +*/ +void rcu_irq_exit_preempt (void ) +{ +lockdep_assert_irqs_disabled (); +rcu_nmi_exit (); + +RCU_LOCKDEP_WARN (__this_cpu_read (rcu_data.dynticks_nesting) <=0 , +"RCU dynticks_nesting counter underflow/zero!" ); +RCU_LOCKDEP_WARN (__this_cpu_read (rcu_data.dynticks_nmi_nesting) <=0 , +"RCU dynticks_nmi_nesting counter underflow/zero!" ); +RCU_LOCKDEP_WARN (rcu_dynticks_curr_cpu_in_eqs (), +"RCU in extended quiescent state!" ); +} +/* * Wrapper for rcu_irq_exit() where interrupts are enabled. *
Re: [patch V4 part 3 11/29] rcu: Provide rcu_irq_exit_preempt()
Quoted 12 lines · Thomas Gleixner
Interrupts and exceptions invoke
rcu_irq_enter()on entry and need to invokercu_irq_exit()before they either return to the interrupted code or invoke the scheduler due to preemption.The general assumption is that RCU idle code has to have preemption disabled so that a return from interrupt cannot schedule. So the return from interrupt code invokes
rcu_irq_exit()andpreempt_schedule_irq().If there is any imbalance in the rcu_irq/nmi* invocations or RCU idle code had preemption enabled then this goes unnoticed until the CPU goes idle or some other RCU check is executed.
Quoted 8 lines
Provide
rcu_irq_exit_preempt()which can be invoked from the interrupt/exception return code in case that preemption is enabled. It invokesrcu_irq_exit()and contains a few sanity checks in case thatCONFIG_PROVE_RCUis enabled to catch such issues directly.Signed-off-by Thomas Gleixner <[email protected]>Cc "Paul E. McKenney" <[email protected]>Cc Joel Fernandes <[email protected]>
The ->dynticks_nmi_nesting field is going away at some point, but there is always "git merge". ;-)
Quoted 57 lines
--- include/linux/rcutiny.h | 1 + include/linux/rcutree.h | 1 + kernel/rcu/tree.c | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+)include/linux/rcutiny.h +1
-0@@ -71,6 +71,7 @@ static inline void rcu_irq_enter(void) {static inline void rcu_irq_exit_irqson (void ) { }static inline void rcu_irq_enter_irqson (void ) { }static inline void rcu_irq_exit (void ) { } +static inline void rcu_irq_exit_preempt (void ) { }static inline void exit_rcu (void ) { }static inline bool rcu_preempt_need_deferred_qs (struct task_struct *t) {include/linux/rcutree.h +1
-0@@ -46,6 +46,7 @@ void rcu_idle_enter(void);void rcu_idle_exit (void );void rcu_irq_enter (void );void rcu_irq_exit (void ); +void rcu_irq_exit_preempt (void );void rcu_irq_enter_irqson (void );void rcu_irq_exit_irqson (void );kernel/rcu/tree.c +21
-0@@ -706,6 +706,27 @@ void noinstr rcu_irq_exit(void)rcu_nmi_exit (); } +/** +* rcu_irq_exit_preempt - Inform RCU that current CPU is exiting irq +* towards in kernel preemption +* +* Same as rcu_irq_exit() but has a sanity check that scheduling is safe +* from RCU point of view. Invoked from return from interrupt before kernel +* preemption. +*/ +void rcu_irq_exit_preempt (void ) +{ +lockdep_assert_irqs_disabled (); +rcu_nmi_exit (); + +RCU_LOCKDEP_WARN (__this_cpu_read (rcu_data.dynticks_nesting) <=0 , +"RCU dynticks_nesting counter underflow/zero!" ); +RCU_LOCKDEP_WARN (__this_cpu_read (rcu_data.dynticks_nmi_nesting) <=0 , +"RCU dynticks_nmi_nesting counter underflow/zero!" ); +RCU_LOCKDEP_WARN (rcu_dynticks_curr_cpu_in_eqs (), +"RCU in extended quiescent state!" ); +} +/* * Wrapper for rcu_irq_exit() where interrupts are enabled. *
Re: [patch V4 part 3 11/29] rcu: Provide rcu_irq_exit_preempt()
Quoted 18 lines · Paul E. McKenney
Quoted 17 lines · Thomas Gleixner
Interrupts and exceptions invoke
rcu_irq_enter()on entry and need to invokercu_irq_exit()before they either return to the interrupted code or invoke the scheduler due to preemption.The general assumption is that RCU idle code has to have preemption disabled so that a return from interrupt cannot schedule. So the return from interrupt code invokes
rcu_irq_exit()andpreempt_schedule_irq().If there is any imbalance in the rcu_irq/nmi* invocations or RCU idle code had preemption enabled then this goes unnoticed until the CPU goes idle or some other RCU check is executed.
Provide
rcu_irq_exit_preempt()which can be invoked from the interrupt/exception return code in case that preemption is enabled. It invokesrcu_irq_exit()and contains a few sanity checks in case thatCONFIG_PROVE_RCUis enabled to catch such issues directly.
Quoted 6 lines
Quoted 3 lines
Signed-off-by Thomas Gleixner <[email protected]>Cc "Paul E. McKenney" <[email protected]>Cc Joel Fernandes <[email protected]>The ->dynticks_nmi_nesting field is going away at some point, but there is always "git merge". ;-)
Yes. The logistics for merging all of this is going to be interesting :)
Paul E. McKenney
maintainerRe: [patch V4 part 3 11/29] rcu: Provide rcu_irq_exit_preempt()
Quoted 20 lines · Thomas Gleixner
Quoted 18 lines · Paul E. McKenney
Quoted 17 lines · Thomas Gleixner
Interrupts and exceptions invoke
rcu_irq_enter()on entry and need to invokercu_irq_exit()before they either return to the interrupted code or invoke the scheduler due to preemption.The general assumption is that RCU idle code has to have preemption disabled so that a return from interrupt cannot schedule. So the return from interrupt code invokes
rcu_irq_exit()andpreempt_schedule_irq().If there is any imbalance in the rcu_irq/nmi* invocations or RCU idle code had preemption enabled then this goes unnoticed until the CPU goes idle or some other RCU check is executed.
Provide
rcu_irq_exit_preempt()which can be invoked from the interrupt/exception return code in case that preemption is enabled. It invokesrcu_irq_exit()and contains a few sanity checks in case thatCONFIG_PROVE_RCUis enabled to catch such issues directly.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Signed-off-by Thomas Gleixner <[email protected]>Cc "Paul E. McKenney" <[email protected]>Cc Joel Fernandes <[email protected]>The ->dynticks_nmi_nesting field is going away at some point, but there is always "git merge". ;-)
Yes. The logistics for merging all of this is going to be interesting :)
;-) ;-) ;-)
Thanx, Paul
Mathieu Desnoyers
reviewerRe: [patch V4 part 3 11/29] rcu: Provide rcu_irq_exit_preempt()
In reply to Thomas Gleixner----- On May 5, 2020, at 9:44 AM, Thomas Gleixner [email protected] wrote:
[...]
Quoted 4 lines
+/**
+ *rcu_irq_exit_preempt- Inform RCU that current CPU is exiting irq
+ * towards in kernel preemption
Not sure what "towards in" means.
Thanks,
Mathieu
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com
Re: [patch V4 part 3 11/29] rcu: Provide rcu_irq_exit_preempt()
In reply to Thomas GleixnerHi Thomas,
On Tue, May 05, 2020 at 03:44:05PM +0200, Thomas Gleixner wrote:
Thank you for CC'ing me.
Quoted 8 lines
Interrupts and exceptions invoke
rcu_irq_enter()on entry and need to invokercu_irq_exit()before they either return to the interrupted code or invoke the scheduler due to preemption.The general assumption is that RCU idle code has to have preemption disabled so that a return from interrupt cannot schedule. So the return from interrupt code invokes
rcu_irq_exit()andpreempt_schedule_irq().
Quoted 8 lines
If there is any imbalance in the rcu_irq/nmi* invocations or RCU idle code had preemption enabled then this goes unnoticed until the CPU goes idle or some other RCU check is executed.
Provide
rcu_irq_exit_preempt()which can be invoked from the interrupt/exception return code in case that preemption is enabled. It invokesrcu_irq_exit()and contains a few sanity checks in case thatCONFIG_PROVE_RCUis enabled to catch such issues directly.
Could you let me know which patch or part in the multi-part series is using it?
Quoted 41 lines
Signed-off-by Thomas Gleixner <[email protected]>Cc "Paul E. McKenney" <[email protected]>Cc Joel Fernandes <[email protected]>--- include/linux/rcutiny.h | 1 + include/linux/rcutree.h | 1 + kernel/rcu/tree.c | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+)include/linux/rcutiny.h +1
-0@@ -71,6 +71,7 @@ static inline void rcu_irq_enter(void) {static inline void rcu_irq_exit_irqson (void ) { }static inline void rcu_irq_enter_irqson (void ) { }static inline void rcu_irq_exit (void ) { } +static inline void rcu_irq_exit_preempt (void ) { }static inline void exit_rcu (void ) { }static inline bool rcu_preempt_need_deferred_qs (struct task_struct *t) {include/linux/rcutree.h +1
-0@@ -46,6 +46,7 @@ void rcu_idle_enter(void);void rcu_idle_exit (void );void rcu_irq_enter (void );void rcu_irq_exit (void ); +void rcu_irq_exit_preempt (void );void rcu_irq_enter_irqson (void );void rcu_irq_exit_irqson (void );kernel/rcu/tree.c +5
-0@@ -706,6 +706,27 @@ void noinstr rcu_irq_exit(void)rcu_nmi_exit (); } +/** +* rcu_irq_exit_preempt - Inform RCU that current CPU is exiting irq +* towards in kernel preemption +* +* Same as rcu_irq_exit() but has a sanity check that scheduling is safe
kernel/rcu/tree.c void noinstr rcu_irq_exit(void) · line 723
Quoted 10 lines
kernel/rcu/tree.c +10
-0+* from RCU point of view. Invoked from return from interrupt before kernel +* preemption. +*/ +void rcu_irq_exit_preempt (void ) +{ +lockdep_assert_irqs_disabled (); +rcu_nmi_exit (); + +RCU_LOCKDEP_WARN (__this_cpu_read (rcu_data.dynticks_nesting) <=0 , +"RCU dynticks_nesting counter underflow/zero!" );
Makes sense.
kernel/rcu/tree.c void noinstr rcu_irq_exit(void) · line 725
Quoted 2 lines
kernel/rcu/tree.c +2
-0+RCU_LOCKDEP_WARN (__this_cpu_read (rcu_data.dynticks_nmi_nesting) <=0 , +"RCU dynticks_nmi_nesting counter underflow/zero!" );
This new function will be called only from the outer-most IRQ that interrupted kernel mode (process context). Right? If so, a better (more specific) check for the second RCU_LOCKDEP_WARN above is:
RCU_LOCKDEP_WARN(__this_cpu_read(rcu_data.dynticks_nmi_nesting) != DYNTICK_IRQ_NONIDLE,
"Bad RCU dynticks_nmi_nesting counter\n");
That will make sure, it is only called from outer-most rcu_irq_exit() and interrupting kernel mode.
Or, if [1] is merged, then we could just combine the checks into one check.
RCU_LOCKDEP_WARN(__this_cpu_read(rcu_data.dynticks_nesting) != 1, "Bad RCU dynticks_nmi_nesting counter\n");
kernel/rcu/tree.c void noinstr rcu_irq_exit(void) · line 727
Quoted 2 lines
kernel/rcu/tree.c +2
-0+RCU_LOCKDEP_WARN (rcu_dynticks_curr_cpu_in_eqs (), +"RCU in extended quiescent state!" );
Makes sense.
BTW, I wonder if a better place to do this "don't enter scheduler while RCU is not watching" is rcu_note_context_switch()...
thanks,
Quoted 6 lines
kernel/rcu/tree.c +2
-0+} +/* * Wrapper for rcu_irq_exit() where interrupts are enabled. *
Re: [patch V4 part 3 11/29] rcu: Provide rcu_irq_exit_preempt()
Quoted 18 lines · Joel Fernandes
Hi Thomas,
On Tue, May 05, 2020 at 03:44:05PM +0200, Thomas Gleixner wrote:
Thank you for CC'ing me.
Quoted 12 lines
Interrupts and exceptions invoke
rcu_irq_enter()on entry and need to invokercu_irq_exit()before they either return to the interrupted code or invoke the scheduler due to preemption.The general assumption is that RCU idle code has to have preemption disabled so that a return from interrupt cannot schedule. So the return from interrupt code invokes
rcu_irq_exit()andpreempt_schedule_irq().If there is any imbalance in the rcu_irq/nmi* invocations or RCU idle code had preemption enabled then this goes unnoticed until the CPU goes idle or some other RCU check is executed.
Quoted 6 lines
Quoted 4 lines
Provide
rcu_irq_exit_preempt()which can be invoked from the interrupt/exception return code in case that preemption is enabled. It invokesrcu_irq_exit()and contains a few sanity checks in case thatCONFIG_PROVE_RCUis enabled to catch such issues directly.Could you let me know which patch or part in the multi-part series is using it?
Ah I see its "x86/entry/common: Provide idtentry_enter/exit()" patch. I'll go read that tomorrow. Thanks!
- Joel
Re: [patch V4 part 3 11/29] rcu: Provide rcu_irq_exit_preempt()
In reply to Joel FernandesJoel,
Quoted 3 lines · Joel Fernandes
On Tue, May 05, 2020 at 03:44:05PM +0200, Thomas Gleixner wrote:
Could you let me know which patch or part in the multi-part series is using it?
You found it :)
Quoted 17 lines
kernel/rcu/tree.c void noinstr rcu_irq_exit(void) · line 723
Quoted 7 lines
kernel/rcu/tree.c +7
-0+void rcu_irq_exit_preempt (void ) +{ +lockdep_assert_irqs_disabled (); +rcu_nmi_exit (); + +RCU_LOCKDEP_WARN (__this_cpu_read (rcu_data.dynticks_nesting) <=0 , +"RCU dynticks_nesting counter underflow/zero!" );Makes sense.
kernel/rcu/tree.c void noinstr rcu_irq_exit(void) · line 725
Quoted 2 lines
kernel/rcu/tree.c +2
-0+RCU_LOCKDEP_WARN (__this_cpu_read (rcu_data.dynticks_nmi_nesting) <=0 , +"RCU dynticks_nmi_nesting counter underflow/zero!" );This new function will be called only from the outer-most IRQ that interrupted kernel mode (process context). Right? If so, a better (more specific) check for the second
RCU_LOCKDEP_WARNabove is:
Quoted 5 lines
RCU_LOCKDEP_WARN(__this_cpu_read(rcu_data.dynticks_nmi_nesting) !=
DYNTICK_IRQ_NONIDLE,"Bad RCU dynticks_nmi_nesting counter\n");That will make sure, it is only called from outer-most
rcu_irq_exit()and interrupting kernel mode.
Makes sense.
Quoted 11 lines
Or, if [1] is merged, then we could just combine the checks into one check.
RCU_LOCKDEP_WARN(__this_cpu_read(rcu_data.dynticks_nesting) != 1, "Bad RCU dynticks_nmi_nesting counter\n");kernel/rcu/tree.c void noinstr rcu_irq_exit(void) · line 727
Quoted 2 lines
kernel/rcu/tree.c +2
-0+RCU_LOCKDEP_WARN (rcu_dynticks_curr_cpu_in_eqs (), +"RCU in extended quiescent state!" );Makes sense.
BTW, I wonder if a better place to do this "don't enter scheduler while RCU is not watching" is
rcu_note_context_switch()...
I actually want to catch even the case where we don't schedule, i.e.
if (ret_to_kernel) {
if (interrupts_on_after_return((regs)) {
if (IS_ENABLED(CONFIG_PREEMPTION)) {
if (!preempt_count()) {
/* Preemption is possible ... */
rcu_irq_exit_preempt();
if (need_resched())
schedule_preempt_irq();that catches any exit where preemption is possible and RCU is not watching after rcu_irq_exit().
It does not matter whether need-resched is set here or not. Any interrupt/exception could set it.
Yes, I'm paranoid :)
Thanks,
tglx
Re: [patch V4 part 3 11/29] rcu: Provide rcu_irq_exit_preempt()
On Thu, May 14, 2020 at 04:43:31PM +0200, Thomas Gleixner wrote:
[...]
Quoted 23 lines
Quoted 11 lines
Or, if [1] is merged, then we could just combine the checks into one check.
RCU_LOCKDEP_WARN(__this_cpu_read(rcu_data.dynticks_nesting) != 1, "Bad RCU dynticks_nmi_nesting counter\n");kernel/rcu/tree.c void noinstr rcu_irq_exit(void) · line 727
Quoted 2 lines
kernel/rcu/tree.c +2
-0+RCU_LOCKDEP_WARN (rcu_dynticks_curr_cpu_in_eqs (), +"RCU in extended quiescent state!" );Makes sense.
BTW, I wonder if a better place to do this "don't enter scheduler while RCU is not watching" is
rcu_note_context_switch()...I actually want to catch even the case where we don't schedule, i.e.
if (ret_to_kernel) { if (interrupts_on_after_return((regs)) { if (IS_ENABLED(CONFIG_PREEMPTION)) { if (!preempt_count()) { /* Preemption is possible ... */ rcu_irq_exit_preempt(); if (need_resched()) schedule_preempt_irq();
Quoted 5 lines
that catches any exit where preemption is possible and RCU is not watching after
rcu_irq_exit().It does not matter whether need-resched is set here or not. Any interrupt/exception could set it.
Yes, your way of doing it is better. Let us do it this way then.
Thanks!
- Joel
[tip: core/rcu] rcu: Provide rcu_irq_exit_preempt()
In reply to Thomas GleixnerThe following commit has been merged into the core/rcu branch of tip:
The following commit has been merged into the core/rcu branch of tip:
Commit-ID: 8ae0ae6737ad449c8ae21e2bb01d9736f360a933 Gitweb: https://git.kernel.org/tip/8ae0ae6737ad449c8ae21e2bb01d9736f360a933 Author: Thomas Gleixner <[email protected]> AuthorDate: Sun, 03 May 2020 15:08:52 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 19 May 2020 15:51:21 +02:00
rcu: Provide rcu_irq_exit_preempt()
Interrupts and exceptions invoke rcu_irq_enter() on entry and need to invoke rcu_irq_exit() before they either return to the interrupted code or invoke the scheduler due to preemption.
The general assumption is that RCU idle code has to have preemption disabled so that a return from interrupt cannot schedule. So the return from interrupt code invokes rcu_irq_exit() and preempt_schedule_irq().
If there is any imbalance in the rcu_irq/nmi* invocations or RCU idle code had preemption enabled then this goes unnoticed until the CPU goes idle or some other RCU check is executed.
Provide rcu_irq_exit_preempt() which can be invoked from the interrupt/exception return code in case that preemption is enabled. It invokes rcu_irq_exit() and contains a few sanity checks in case that CONFIG_PROVE_RCU is enabled to catch such issues directly.
--- include/linux/rcutiny.h | 1 + include/linux/rcutree.h | 1 + kernel/rcu/tree.c | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+)
include/linux/rcutiny.h +1 -0
@@ -71,6 +71,7 @@ static inline void rcu_irq_enter(void) { }static inline void rcu_irq_exit_irqson (void ) { }static inline void rcu_irq_enter_irqson (void ) { }static inline void rcu_irq_exit (void ) { } +static inline void rcu_irq_exit_preempt (void ) { }static inline void exit_rcu (void ) { }static inline bool rcu_preempt_need_deferred_qs (struct task_struct *t) {
include/linux/rcutree.h +1 -0
@@ -47,6 +47,7 @@ void rcu_idle_enter(void);void rcu_idle_exit (void );void rcu_irq_enter (void );void rcu_irq_exit (void ); +void rcu_irq_exit_preempt (void );void rcu_irq_enter_irqson (void );void rcu_irq_exit_irqson (void );
kernel/rcu/tree.c +22 -0
@@ -743,6 +743,28 @@ void noinstr rcu_irq_exit(void)rcu_nmi_exit (); } +/** +* rcu_irq_exit_preempt - Inform RCU that current CPU is exiting irq +* towards in kernel preemption +* +* Same as rcu_irq_exit() but has a sanity check that scheduling is safe +* from RCU point of view. Invoked from return from interrupt before kernel +* preemption. +*/ +void rcu_irq_exit_preempt (void ) +{ +lockdep_assert_irqs_disabled (); +rcu_nmi_exit (); + +RCU_LOCKDEP_WARN (__this_cpu_read (rcu_data.dynticks_nesting) <=0 , +"RCU dynticks_nesting counter underflow/zero!" ); +RCU_LOCKDEP_WARN (__this_cpu_read (rcu_data.dynticks_nmi_nesting) != +DYNTICK_IRQ_NONIDLE , +"Bad RCU dynticks_nmi_nesting counter\n" ); +RCU_LOCKDEP_WARN (rcu_dynticks_curr_cpu_in_eqs (), +"RCU in extended quiescent state!" ); +} +/* * Wrapper for rcu_irq_exit() where interrupts are enabled. *
PATCH v4 12/29 x86/entry/common: Provide idtentry_enter/exit()
In reply to Thomas GleixnerProvide functions which handle the low level entry and exit similiar to enter/exit from user mode.
--- arch/x86/entry/common.c | 89 ++++++++++++++++++++++++++++++++++++++++ arch/x86/include/asm/idtentry.h | 3 + 2 files changed, 92 insertions(+)
arch/x86/entry/common.c +89 -0
@@ -510,3 +510,92 @@ SYSCALL_DEFINE0(ni_syscall) {return -ENOSYS ; } + +/** +* idtentry_enter - Handle state tracking on idtentry +* @regs: Pointer to pt_regs of interrupted context +* +* Invokes: +* - lockdep irqflag state tracking as low level ASM entry disabled +* interrupts. +* +* - Context tracking if the exception hit user mode. +* +* - RCU notification if the exception hit kernel mode +* +* - The hardirq tracer to keep the state consistent as low level ASM +* entry disabled interrupts. +*/ +void noinstr idtentry_enter(struct pt_regs *regs) +{ +if (user_mode (regs)) { +enter_from_user_mode (); + }else { +lockdep_hardirqs_off (CALLER_ADDR0 ); +rcu_irq_enter (); +instr_begin (); +trace_hardirqs_off_prepare (); +instr_end (); + } +} + +/** +* idtentry_exit - Common code to handle return from exceptions +* @regs: Pointer to pt_regs (exception entry regs) +* +* Depending on the return target (kernel/user) this runs the necessary +* preemption and work checks if possible and reguired and returns to +* the caller with interrupts disabled and no further work pending. +* +* This is the last action before returning to the low level ASM code which +* just needs to return to the appropriate context. +* +* Invoked by all exception/interrupt IDTENTRY handlers which are not +* returning through the paranoid exit path (all except NMI, #DF and the IST +* variants of #MC and #DB). +*/ +void noinstr idtentry_exit(struct pt_regs *regs) +{ +lockdep_assert_irqs_disabled (); + +/* Check whether this returns to user mode */ +if (user_mode (regs)) { +prepare_exit_to_usermode (regs); + }else if (regs->flags &X86_EFLAGS_IF ) { +/* Check kernel preemption, if enabled */ +if (IS_ENABLED (CONFIG_PREEMPTION )) { +/* +* This needs to be done very carefully. +* idtentry_enter() invoked rcu_irq_enter(). This +* needs to undone before scheduling. +* +* Preemption is disabled inside of RCU idle +* sections. When the task returns from +* preempt_schedule_irq(), RCU is still watching. +* +* rcu_irq_exit_preempt() has additional state +* checking if CONFIG_PROVE_RCU=y +*/ +if (!preempt_count ()) { +instr_begin (); +rcu_irq_exit_preempt (); +if (need_resched ()) +preempt_schedule_irq (); +/* Covers both tracing and lockdep */ +trace_hardirqs_on (); +instr_end (); +return ; + } + } +instr_begin (); +/* Tell the tracer that IRET will enable interrupts */ +trace_hardirqs_on_prepare (); +lockdep_hardirqs_on_prepare (CALLER_ADDR0 ); +instr_end (); +rcu_irq_exit (); +lockdep_hardirqs_on (CALLER_ADDR0 ); + }else { +/* IRQ flags state is correct already. Just tell RCU */ +rcu_irq_exit (); + } +}
arch/x86/include/asm/idtentry.h +3 -0
@@ -7,6 +7,9 @@#ifndef __ASSEMBLY__ +void idtentry_enter (struct pt_regs *regs); +void idtentry_exit (struct pt_regs *regs); +/** * DECLARE_IDTENTRY - Declare functions for simple IDT entry points * No error code pushed by hardware
Re: [patch V4 part 3 12/29] x86/entry/common: Provide idtentry_enter/exit()
Quoted 2 lines · Thomas Gleixner
Provide functions which handle the low level entry and exit similiar to enter/exit from user mode.
typo: "similiar"
Quoted 8 lines
Signed-off-by Thomas Gleixner <[email protected]>--- arch/x86/entry/common.c | 89 ++++++++++++++++++++++++++++++++++++++++ arch/x86/include/asm/idtentry.h | 3 + 2 files changed, 92 insertions(+)arch/x86/entry/common.c +0
-0
...
Quoted 6 lines
+/**
+ *idtentry_exit- Common code to handle return from exceptions
+ * @regs: Pointer topt_regs(exception entry regs)
+ *
+ * Depending on the return target (kernel/user) this runs the necessary
+ * preemption and work checks if possible and reguired and returns to
typo: "reguired"
alex.
Andy Lutomirski
maintainerRe: [patch V4 part 3 12/29] x86/entry/common: Provide idtentry_enter/exit()
In reply to Thomas GleixnerQuoted 10 lines · Thomas Gleixner
Provide functions which handle the low level entry and exit similiar to enter/exit from user mode.
arch/x86/entry/common.c +5
-0+ +/** +* idtentry_exit - Common code to handle return from exceptions +* @regs: Pointer to pt_regs (exception entry regs) +*
arch/x86/entry/common.c SYSCALL_DEFINE0(ni_syscall) · line 555
Quoted 10 lines
arch/x86/entry/common.c +10
-0+* Depending on the return target (kernel/user) this runs the necessary +* preemption and work checks if possible and reguired and returns to +* the caller with interrupts disabled and no further work pending. +* +* This is the last action before returning to the low level ASM code which +* just needs to return to the appropriate context. +* +* Invoked by all exception/interrupt IDTENTRY handlers which are not +* returning through the paranoid exit path (all except NMI, #DF and the IST +* variants of #MC and #DB).
The paranoid-exit bit is not really relevant. The important part is which stack we're on. See below.
arch/x86/entry/common.c SYSCALL_DEFINE0(ni_syscall) · line 559
Quoted 4 lines
+ */
arch/x86/entry/common.c +3
-0+void noinstr idtentry_exit(struct pt_regs *regs) +{ +lockdep_assert_irqs_disabled ();
How about:
#ifdef CONFIG_DEBUG_ENTRY
WARN_ON_ONCE(!on_thread_stack());
#endif
Quoted 14 lines
arch/x86/entry/common.c +14
-0+ +/* Check whether this returns to user mode */ +if (user_mode (regs)) { +prepare_exit_to_usermode (regs); + }else if (regs->flags &X86_EFLAGS_IF ) { +/* Check kernel preemption, if enabled */ +if (IS_ENABLED (CONFIG_PREEMPTION )) { +/* +* This needs to be done very carefully. +* idtentry_enter() invoked rcu_irq_enter(). This +* needs to undone before scheduling. +* +* Preemption is disabled inside of RCU idle +* sections. When the task returns from
arch/x86/entry/common.c SYSCALL_DEFINE0(ni_syscall) · line 583
Quoted 10 lines
arch/x86/entry/common.c +10
-0+* preempt_schedule_irq(), RCU is still watching. +* +* rcu_irq_exit_preempt() has additional state +* checking if CONFIG_PROVE_RCU=y +*/ +if (!preempt_count ()) { +instr_begin (); +rcu_irq_exit_preempt (); +if (need_resched ()) +preempt_schedule_irq ();
This is an excellent improvement. Thanks!
arch/x86/entry/common.c SYSCALL_DEFINE0(ni_syscall) · line 592
Quoted 9 lines
arch/x86/entry/common.c +9
-0+/* Covers both tracing and lockdep */ +trace_hardirqs_on (); +instr_end (); +return ; + } + } +instr_begin (); +/* Tell the tracer that IRET will enable interrupts */ +trace_hardirqs_on_prepare ();
Why is trace_hardirqs_on() okay above but not here? Is it that we know we weren't RCU-quiescent if we had preemption and IF on? But even this code path came from an IF-on context. I'm confused. Maybe some comments as to why this case seems to be ordered so differently from the !preempt_count() case would be helpful.
Quoted 22 lines
arch/x86/entry/common.c +9
-0+lockdep_hardirqs_on_prepare (CALLER_ADDR0 ); +instr_end (); +rcu_irq_exit (); +lockdep_hardirqs_on (CALLER_ADDR0 ); + }else { +/* IRQ flags state is correct already. Just tell RCU */ +rcu_irq_exit (); + } +}arch/x86/include/asm/idtentry.h +3
-0@@ -7,6 +7,9 @@#ifndef __ASSEMBLY__ +void idtentry_enter (struct pt_regs *regs); +void idtentry_exit (struct pt_regs *regs); +/** * DECLARE_IDTENTRY - Declare functions for simple IDT entry points * No error code pushed by hardware
PATCH v5 12/29 x86/entry/common: Provide idtentry_enter/exit()
Quoted 6 lines · Andy Lutomirski
Quoted 3 lines
+ * Invoked by all exception/interrupt IDTENTRY handlers which are not
+ * returning through the paranoid exit path (all except NMI, #DF and the IST
+ * variants of #MC and #DB).The paranoid-exit bit is not really relevant. The important part is which stack we're on. See below.
Right. I amended the comment to that effect.
Quoted 10 lines
Review
Quoted 4 lines
+ */
(quoted diff) +3
-0+void noinstr idtentry_exit(struct pt_regs *regs) +{ + lockdep_assert_irqs_disabled();How about:
#ifdef
CONFIG_DEBUG_ENTRY
WARN_ON_ONCE(!on_thread_stack());
#endif
Made this if (IS_ENABLED()) ..
Quoted 9 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ instr_begin(); + /* Tell the tracer that IRET will enable interrupts */ + trace_hardirqs_on_prepare();Why is
trace_hardirqs_on()okay above but not here? Is it that we know we weren't RCU-quiescent if we had preemption and IF on? But even this code path came from an IF-on context. I'm confused. Maybe some comments as to why this case seems to be ordered so differently from the !preempt_count() case would be helpful.
Added commentry. Updated patch below.
Thanks,
tglx
8<-----------------
Subject: x86/entry/common: Provide idtentry_enter/exit()
From: Thomas Gleixner <[email protected]>
Date: Thu, 26 Mar 2020 16:28:52 +0100
Provide functions which handle the low level entry and exit similar to enter/exit from user mode.
--- arch/x86/entry/common.c | 100 ++++++++++++++++++++++++++++++++++++++++ arch/x86/include/asm/idtentry.h | 3 + 2 files changed, 103 insertions(+)
arch/x86/entry/common.c +100 -0
@@ -510,3 +510,103 @@ SYSCALL_DEFINE0(ni_syscall) {return -ENOSYS ; } + +/** +* idtentry_enter - Handle state tracking on idtentry +* @regs: Pointer to pt_regs of interrupted context +* +* Invokes: +* - lockdep irqflag state tracking as low level ASM entry disabled +* interrupts. +* +* - Context tracking if the exception hit user mode. +* +* - RCU notification if the exception hit kernel mode +* +* - The hardirq tracer to keep the state consistent as low level ASM +* entry disabled interrupts. +*/ +void noinstr idtentry_enter(struct pt_regs *regs) +{ +if (user_mode (regs)) { +enter_from_user_mode (); + }else { +lockdep_hardirqs_off (CALLER_ADDR0 ); +rcu_irq_enter (); +instrumentation_begin (); +trace_hardirqs_off_prepare (); +instrumentation_end (); + } +} + +/** +* idtentry_exit - Common code to handle return from exceptions +* @regs: Pointer to pt_regs (exception entry regs) +* +* Depending on the return target (kernel/user) this runs the necessary +* preemption and work checks if possible and required and returns to +* the caller with interrupts disabled and no further work pending. +* +* This is the last action before returning to the low level ASM code which +* just needs to return to the appropriate context. +* +* Invoked by all exception/interrupt IDTENTRY handlers which are not +* returning through the paranoid exit path (all except NMI, #DF and the IST +* variants of #MC and #DB) and are therefore on the thread stack. +*/ +void noinstr idtentry_exit(struct pt_regs *regs) +{ +lockdep_assert_irqs_disabled (); + +if (IS_ENABLED (CONFIG_DEBUG_ENTRY )) +WARN_ON_ONCE (!on_thread_stack ()); + +/* Check whether this returns to user mode */ +if (user_mode (regs)) { +prepare_exit_to_usermode (regs); + }else if (regs->flags &X86_EFLAGS_IF ) { +/* Check kernel preemption, if enabled */ +if (IS_ENABLED (CONFIG_PREEMPTION )) { +/* +* This needs to be done very carefully. +* idtentry_enter() invoked rcu_irq_enter(). This +* needs to undone before scheduling. +* +* Preemption is disabled inside of RCU idle +* sections. When the task returns from +* preempt_schedule_irq(), RCU is still watching. +* +* rcu_irq_exit_preempt() has additional state +* checking if CONFIG_PROVE_RCU=y +*/ +if (!preempt_count ()) { +instrumentation_begin (); +rcu_irq_exit_preempt (); +if (need_resched ()) +preempt_schedule_irq (); +/* Covers both tracing and lockdep */ +trace_hardirqs_on (); +instrumentation_end (); +return ; + } + } +/* +* If preemption is disabled then this needs to be done +* carefully with respect to RCU. The exception might come +* from a RCU idle section in the idle task due to the fact +* that safe_halt() enables interrupts. So this needs the +* same ordering of lockdep/tracing and RCU as the return +* to user mode path. +*/ +instrumentation_begin (); +/* Tell the tracer that IRET will enable interrupts */ +trace_hardirqs_on_prepare (); +lockdep_hardirqs_on_prepare (CALLER_ADDR0 ); +instrumentation_end (); +rcu_irq_exit (); +lockdep_hardirqs_on (CALLER_ADDR0 ); + }else { +/* IRQ flags state is correct already. Just tell RCU */ +rcu_irq_exit (); + } +}
arch/x86/include/asm/idtentry.h +3 -0
@@ -7,6 +7,9 @@#ifndef __ASSEMBLY__ +void idtentry_enter (struct pt_regs *regs); +void idtentry_exit (struct pt_regs *regs); +/** * DECLARE_IDTENTRY - Declare functions for simple IDT entry points * No error code pushed by hardware
Andy Lutomirski
maintainerRe: [patch V5 part 3 12/29] x86/entry/common: Provide idtentry_enter/exit()
arch/x86/entry/common.c SYSCALL_DEFINE0(ni_syscall) · line 562
Quoted 13 lines · Thomas Gleixner
Quoted 4 lines · Andy Lutomirski
Quoted 3 lines
+ * Invoked by all exception/interrupt IDTENTRY handlers which are not
+ * returning through the paranoid exit path (all except NMI, #DF and the IST
+ * variants of #MC and #DB).arch/x86/entry/common.c +6
-0+void noinstr idtentry_exit(struct pt_regs *regs) +{ +lockdep_assert_irqs_disabled (); + +if (IS_ENABLED (CONFIG_DEBUG_ENTRY )) +WARN_ON_ONCE (!on_thread_stack ());
Whoops. After sleeping on this, this is obviously wrong. If this is something like a page fault, we can be on an IST or IRQ stack. Perhaps the actual condition should be:
WARN_ON_ONCE(!on_thread_stack() && (regs->flags & X86_FLAGS_IF) && preempt_count() == 0);
IOW, the actual condition we want is that, if the idtenter_entry/exit code might schedule or if a cond_local_irq_enable() path might schedule, we had better be on the correct stack.
Sorry for causing confusion.
Re: [patch V5 part 3 12/29] x86/entry/common: Provide idtentry_enter/exit()
Quoted 19 lines · Andy Lutomirski
arch/x86/entry/common.c SYSCALL_DEFINE0(ni_syscall) · line 562
Quoted 13 lines · Thomas Gleixner
Quoted 4 lines · Andy Lutomirski
Quoted 3 lines
+ * Invoked by all exception/interrupt IDTENTRY handlers which are not
+ * returning through the paranoid exit path (all except NMI, #DF and the IST
+ * variants of #MC and #DB).arch/x86/entry/common.c +6
-0+void noinstr idtentry_exit(struct pt_regs *regs) +{ +lockdep_assert_irqs_disabled (); + +if (IS_ENABLED (CONFIG_DEBUG_ENTRY )) +WARN_ON_ONCE (!on_thread_stack ());Whoops. After sleeping on this, this is obviously wrong. If this is something like a page fault, we can be on an IST or IRQ stack. Perhaps the actual condition should be:
Quoted 8 lines
WARN_ON_ONCE(!on_thread_stack() && (regs->flags & X86_FLAGS_IF) && preempt_count() == 0);IOW, the actual condition we want is that, if the idtenter_entry/exit code might schedule or if a
cond_local_irq_enable()path might schedule, we had better be on the correct stack.Sorry for causing confusion.
Nothing to be sorry about. I could have thought about it myself :) Let me try again.
PATCH v6 12/29 x86/entry/common: Provide idtentry_enter/exit()
Quoted 4 lines · Thomas Gleixner
Quoted 3 lines · Andy Lutomirski
WARN_ON_ONCE(!on_thread_stack() && (regs->flags & X86_FLAGS_IF) && preempt_count() == 0);
Quoted 8 lines
Quoted 5 lines
IOW, the actual condition we want is that, if the idtenter_entry/exit code might schedule or if a
cond_local_irq_enable()path might schedule, we had better be on the correct stack.Sorry for causing confusion.
Nothing to be sorry about. I could have thought about it myself :) Let me try again.
Move it into the actual preemption condition. Most natural place.
Thanks,
tglx
8<--------------------
Subject: x86/entry/common: Provide idtentry_enter/exit()
From: Thomas Gleixner <[email protected]>
Date: Thu, 26 Mar 2020 16:28:52 +0100
Provide functions which handle the low level entry and exit similar to enter/exit from user mode.
--- arch/x86/entry/common.c | 99 ++++++++++++++++++++++++++++++++++++++++ arch/x86/include/asm/idtentry.h | 3 + 2 files changed, 102 insertions(+)
arch/x86/entry/common.c +99 -0
@@ -510,3 +510,102 @@ SYSCALL_DEFINE0(ni_syscall) {return -ENOSYS ; } + +/** +* idtentry_enter - Handle state tracking on idtentry +* @regs: Pointer to pt_regs of interrupted context +* +* Invokes: +* - lockdep irqflag state tracking as low level ASM entry disabled +* interrupts. +* +* - Context tracking if the exception hit user mode. +* +* - RCU notification if the exception hit kernel mode +* +* - The hardirq tracer to keep the state consistent as low level ASM +* entry disabled interrupts. +*/ +void noinstr idtentry_enter(struct pt_regs *regs) +{ +if (user_mode (regs)) { +enter_from_user_mode (); + }else { +lockdep_hardirqs_off (CALLER_ADDR0 ); +rcu_irq_enter (); +instrumentation_begin (); +trace_hardirqs_off_prepare (); +instrumentation_end (); + } +} + +/** +* idtentry_exit - Common code to handle return from exceptions +* @regs: Pointer to pt_regs (exception entry regs) +* +* Depending on the return target (kernel/user) this runs the necessary +* preemption and work checks if possible and required and returns to +* the caller with interrupts disabled and no further work pending. +* +* This is the last action before returning to the low level ASM code which +* just needs to return to the appropriate context. +* +* Invoked by all exception/interrupt IDTENTRY handlers which are not +* returning through the paranoid exit path (all except NMI, #DF and the IST +* variants of #MC and #DB) and are therefore on the thread stack. +*/ +void noinstr idtentry_exit(struct pt_regs *regs) +{ +lockdep_assert_irqs_disabled (); + +/* Check whether this returns to user mode */ +if (user_mode (regs)) { +prepare_exit_to_usermode (regs); + }else if (regs->flags &X86_EFLAGS_IF ) { +/* Check kernel preemption, if enabled */ +if (IS_ENABLED (CONFIG_PREEMPTION )) { +/* +* This needs to be done very carefully. +* idtentry_enter() invoked rcu_irq_enter(). This +* needs to undone before scheduling. +* +* Preemption is disabled inside of RCU idle +* sections. When the task returns from +* preempt_schedule_irq(), RCU is still watching. +* +* rcu_irq_exit_preempt() has additional state +* checking if CONFIG_PROVE_RCU=y +*/ +if (!preempt_count ()) { +if (IS_ENABLED (CONFIG_DEBUG_ENTRY )) +WARN_ON_ONCE (!on_thread_stack ()); +instrumentation_begin (); +rcu_irq_exit_preempt (); +if (need_resched ()) +preempt_schedule_irq (); +/* Covers both tracing and lockdep */ +trace_hardirqs_on (); +instrumentation_end (); +return ; + } + } +/* +* If preemption is disabled then this needs to be done +* carefully with respect to RCU. The exception might come +* from a RCU idle section in the idle task due to the fact +* that safe_halt() enables interrupts. So this needs the +* same ordering of lockdep/tracing and RCU as the return +* to user mode path. +*/ +instrumentation_begin (); +/* Tell the tracer that IRET will enable interrupts */ +trace_hardirqs_on_prepare (); +lockdep_hardirqs_on_prepare (CALLER_ADDR0 ); +instrumentation_end (); +rcu_irq_exit (); +lockdep_hardirqs_on (CALLER_ADDR0 ); + }else { +/* IRQ flags state is correct already. Just tell RCU */ +rcu_irq_exit (); + } +}
arch/x86/include/asm/idtentry.h +3 -0
@@ -7,6 +7,9 @@#ifndef __ASSEMBLY__ +void idtentry_enter (struct pt_regs *regs); +void idtentry_exit (struct pt_regs *regs); +/** * DECLARE_IDTENTRY - Declare functions for simple IDT entry points * No error code pushed by hardware
Re: [patch V6 part 3 12/29] x86/entry/common: Provide idtentry_enter/exit()
Quoted 10 lines · Thomas Gleixner
Quoted 8 lines · Thomas Gleixner
Quoted 7 lines · Andy Lutomirski
WARN_ON_ONCE(!on_thread_stack() && (regs->flags & X86_FLAGS_IF) && preempt_count() == 0);IOW, the actual condition we want is that, if the idtenter_entry/exit code might schedule or if a
cond_local_irq_enable()path might schedule, we had better be on the correct stack.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Sorry for causing confusion.
Nothing to be sorry about. I could have thought about it myself :) Let me try again.
Move it into the actual preemption condition. Most natural place.
Nice! This way the logic is clear and the warning will fire even if no actual preemption occurs.
Mathieu Desnoyers
reviewerRe: [patch V4 part 3 12/29] x86/entry/common: Provide idtentry_enter/exit()
In reply to Thomas Gleixner----- On May 5, 2020, at 9:44 AM, Thomas Gleixner [email protected] wrote:
[...]
Quoted 7 lines
+ * Invokes:
+ * - lockdep irqflag state tracking as low level ASM entry disabled
+ * interrupts.
+ *
+ * - Context tracking if the exception hit user mode.
+ *
+ * - RCU notification if the exception hit kernel mode
Nit: missing "." at end of line.
arch/x86/entry/common.c SYSCALL_DEFINE0(ni_syscall) · line 570
Quoted 7 lines
+ *
+ * - The hardirq tracer to keep the state consistent as low level ASM
+ * entry disabled interrupts.arch/x86/entry/common.c +3
-0+* This needs to be done very carefully. +* idtentry_enter() invoked rcu_irq_enter(). This +* needs to undone before scheduling.
Nit: "to undone" -> "to be undone".
Thanks,
Mathieu
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com
[tip: x86/entry] x86/entry/common: Provide idtentry_enter/exit()
In reply to Thomas GleixnerThe following commit has been merged into the x86/entry branch of tip:
The following commit has been merged into the x86/entry branch of tip:
Commit-ID: eadb831607477ba774b3314bdc956331b41817d6 Gitweb: https://git.kernel.org/tip/eadb831607477ba774b3314bdc956331b41817d6 Author: Thomas Gleixner <[email protected]> AuthorDate: Thu, 26 Mar 2020 16:28:52 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 19 May 2020 16:03:57 +02:00
x86/entry/common: Provide idtentry_enter/exit()
Provide functions which handle the low level entry and exit similar to enter/exit from user mode.
--- arch/x86/entry/common.c | 99 +++++++++++++++++++++++++++++++- arch/x86/include/asm/idtentry.h | 3 +- 2 files changed, 102 insertions(+)
arch/x86/entry/common.c +99 -0
@@ -510,3 +510,102 @@ SYSCALL_DEFINE0(ni_syscall) {return -ENOSYS ; } + +/** +* idtentry_enter - Handle state tracking on idtentry +* @regs: Pointer to pt_regs of interrupted context +* +* Invokes: +* - lockdep irqflag state tracking as low level ASM entry disabled +* interrupts. +* +* - Context tracking if the exception hit user mode. +* +* - RCU notification if the exception hit kernel mode. +* +* - The hardirq tracer to keep the state consistent as low level ASM +* entry disabled interrupts. +*/ +void noinstr idtentry_enter(struct pt_regs *regs) +{ +if (user_mode (regs)) { +enter_from_user_mode (); + }else { +lockdep_hardirqs_off (CALLER_ADDR0 ); +rcu_irq_enter (); +instrumentation_begin (); +trace_hardirqs_off_prepare (); +instrumentation_end (); + } +} + +/** +* idtentry_exit - Common code to handle return from exceptions +* @regs: Pointer to pt_regs (exception entry regs) +* +* Depending on the return target (kernel/user) this runs the necessary +* preemption and work checks if possible and required and returns to +* the caller with interrupts disabled and no further work pending. +* +* This is the last action before returning to the low level ASM code which +* just needs to return to the appropriate context. +* +* Invoked by all exception/interrupt IDTENTRY handlers which are not +* returning through the paranoid exit path (all except NMI, #DF and the IST +* variants of #MC and #DB) and are therefore on the thread stack. +*/ +void noinstr idtentry_exit(struct pt_regs *regs) +{ +lockdep_assert_irqs_disabled (); + +/* Check whether this returns to user mode */ +if (user_mode (regs)) { +prepare_exit_to_usermode (regs); + }else if (regs->flags &X86_EFLAGS_IF ) { +/* Check kernel preemption, if enabled */ +if (IS_ENABLED (CONFIG_PREEMPTION )) { +/* +* This needs to be done very carefully. +* idtentry_enter() invoked rcu_irq_enter(). This +* needs to be undone before scheduling. +* +* Preemption is disabled inside of RCU idle +* sections. When the task returns from +* preempt_schedule_irq(), RCU is still watching. +* +* rcu_irq_exit_preempt() has additional state +* checking if CONFIG_PROVE_RCU=y +*/ +if (!preempt_count ()) { +if (IS_ENABLED (CONFIG_DEBUG_ENTRY )) +WARN_ON_ONCE (!on_thread_stack ()); +instrumentation_begin (); +rcu_irq_exit_preempt (); +if (need_resched ()) +preempt_schedule_irq (); +/* Covers both tracing and lockdep */ +trace_hardirqs_on (); +instrumentation_end (); +return ; + } + } +/* +* If preemption is disabled then this needs to be done +* carefully with respect to RCU. The exception might come +* from a RCU idle section in the idle task due to the fact +* that safe_halt() enables interrupts. So this needs the +* same ordering of lockdep/tracing and RCU as the return +* to user mode path. +*/ +instrumentation_begin (); +/* Tell the tracer that IRET will enable interrupts */ +trace_hardirqs_on_prepare (); +lockdep_hardirqs_on_prepare (CALLER_ADDR0 ); +instrumentation_end (); +rcu_irq_exit (); +lockdep_hardirqs_on (CALLER_ADDR0 ); + }else { +/* IRQ flags state is correct already. Just tell RCU */ +rcu_irq_exit (); + } +}
arch/x86/include/asm/idtentry.h +3 -0
@@ -7,6 +7,9 @@#ifndef __ASSEMBLY__ +void idtentry_enter (struct pt_regs *regs); +void idtentry_exit (struct pt_regs *regs); +/** * DECLARE_IDTENTRY - Declare functions for simple IDT entry points * No error code pushed by hardware
PATCH v4 13/29 x86/traps: Prepare for using DEFINE_IDTENTRY
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
Prepare for using IDTENTRY to define the C exception/trap entry points. It would be possible to glue this into the existing macro maze, but it's simpler and better to read at the end to just make them distinct. Provide a trivial inline helper to read the trap address.
The existing macros will be removed once all instances are converted.
--- arch/x86/kernel/traps.c | 5 +++++ 1 file changed, 5 insertions(+)
arch/x86/kernel/traps.c +5 -0
@@ -205,6 +205,11 @@ static void do_error_trap(struct pt_regs } } +static __always_inline void __user *error_get_trap_addr(struct pt_regs *regs) +{ +return (void __user *)uprobe_get_trap_addr (regs); +} +#define IP ((void __user *)uprobe_get_trap_addr(regs))#define DO_ERROR (trapnr, signr, sicode, addr, str, name) \ dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \
Andy Lutomirski
maintainerRe: [patch V4 part 3 13/29] x86/traps: Prepare for using DEFINE_IDTENTRY
Quoted 20 lines · Thomas Gleixner
From: Thomas Gleixner <[email protected]>
Prepare for using IDTENTRY to define the C exception/trap entry points. It would be possible to glue this into the existing macro maze, but it's simpler and better to read at the end to just make them distinct. Provide a trivial inline helper to read the trap address.
The existing macros will be removed once all instances are converted.
Signed-off-by Thomas Gleixner <[email protected]>Reviewed-by Alexandre Chartre <[email protected]>--- arch/x86/kernel/traps.c | 5 +++++ 1 file changed, 5 insertions(+)
arch/x86/kernel/traps.c static void do_error_trap(struct pt_regs · line 211
Quoted 7 lines
arch/x86/kernel/traps.c +4
-0@@ -205,6 +205,11 @@ static void do_error_trap(struct pt_regs } } +static __always_inline void __user *error_get_trap_addr(struct pt_regs *regs) +{ +return (void __user *)uprobe_get_trap_addr (regs); +}
My mind boggles. WTF is this?
Perhaps this should have a comment like:
/*
* Returns the address from which a user trap originated. This would
be the same as regs->ip,
* except for frhgnieawfn nvlrkvklsrvs and mfkealwf, and this lets the
thingummy pass a
* modified value to the signal frame, but only for #DE and #UD,
because #*!&@&#@.
*/
except with the blanks filled in.
After reading a bit of uprobe code, I assume this is a fixup for when we're running code that got moved out of line because it got replaced by a breakpoint. I'm still mystified by why it only seems to apply to #DE and #UD.
Re: [patch V4 part 3 13/29] x86/traps: Prepare for using DEFINE_IDTENTRY
Andy,
Quoted 8 lines · Andy Lutomirski
arch/x86/kernel/traps.c static void do_error_trap(struct pt_regs · line 211
Quoted 5 lines · Thomas Gleixner
arch/x86/kernel/traps.c +4
-0+static __always_inline void __user *error_get_trap_addr(struct pt_regs *regs) +{ +return (void __user *)uprobe_get_trap_addr (regs); +}My mind boggles. WTF is this?
That's an inline version of the same nonsense in that macro maze.
Quoted 9 lines
Perhaps this should have a comment like:
/*
* Returns the address from which a user trap originated. This would be the same asregs->ip,
* except for frhgnieawfn nvlrkvklsrvs and mfkealwf, and this lets the thingummy pass a
* modified value to the signal frame, but only for #DE and #UD, because #*!&@&#@. */except with the blanks filled in.
Hmm. Filling the blanks gives me:
/* **0Returns1the2address3from4which5a6user7trap8originated.90This1would...
That's not really more readable than yours :)
Quoted 4 lines
After reading a bit of uprobe code, I assume this is a fixup for when we're running code that got moved out of line because it got replaced by a breakpoint. I'm still mystified by why it only seems to apply to #DE and #UD.
man sigaction(2):
* SIGILL, SIGFPE, SIGSEGV, SIGBUS, and SIGTRAP fill in si_addr with the address of the fault. On some architectures, these signals also fill in the si_trapno field.
Posix spec says:
In addition, the following signal-specific information shall be available:
Signal Member Value
SIGILL void * si_addr Address of faulting instruction.
SIGFPE
SIGSEGV void * si_addr Address of faulting memory reference.
SIGBUS
For some implementations, the value of si_addr may be inaccurate.
In historic kernels si_addr was simply set to regs->ip and the uprobe muck changed that in commit b02ef20a9fba08 ("uprobes/x86: Fix the wrong ->si_addr when xol triggers a trap")
If the probed insn triggers a trap, ->si_addr = regs->ip is technically correct, but this is not what the signal handler wants; we need to pass the address of the probed insn, not the address of xol slot.
Now that I filled my own blanks, I think that I can come up with a halfways useful comment.
Thanks,
tglx
Peter Zijlstra
maintainerRe: [patch V4 part 3 13/29] x86/traps: Prepare for using DEFINE_IDTENTRY
Quoted 8 lines · Thomas Gleixner
Quoted 6 lines · Andy Lutomirski
/*
* Returns the address from which a user trap originated. This would be the same asregs->ip,
* except for frhgnieawfn nvlrkvklsrvs and mfkealwf, and this lets the thingummy pass a
* modified value to the signal frame, but only for #DE and #UD, because #*!&@&#@. */
Quoted 8 lines
Quoted 1 line
except with the blanks filled in.
Hmm. Filling the blanks gives me:
/* **0Returns1the2address3from4which5a6user7trap8originated.90This1would...
That's not really more readable than yours :)
ROFL -- You just made me spill my tea!
Re: [patch V4 part 3 13/29] x86/traps: Prepare for using DEFINE_IDTENTRY
In reply to Thomas GleixnerAndy,
Quoted 10 lines · Thomas Gleixner
In historic kernels
si_addrwas simply set toregs->ipand the uprobe muck changed that in commitb02ef20a9fba08("uprobes/x86: Fix the wrong ->si_addr when xol triggers a trap")If the probed insn triggers a trap, ->si_addr =
regs->ipis technically correct, but this is not what the signal handler wants; we need to pass the address of the probed insn, not the address of xol slot.Now that I filled my own blanks, I think that I can come up with a halfways useful comment.
That's what I came up with (delta patch)
Thanks,
tglx
8<---------------
arch/x86/kernel/traps.c +10 -0
@@ -205,6 +205,16 @@ static void do_error_trap(struct pt_regs } } +/* +* Posix requires to provide the address of the faulting instruction for +* SIGILL (#UD) and SIGFPE (#DE) in the si_addr member of siginfo_t. +* +* This address is usually regs->ip, but when an uprobe moved the code out +* of line then regs->ip points to the XOL code which would confuse +* anything which analyzes the fault address vs. the unmodified binary. If +* a trap happened in XOL code then uprobe maps regs->ip back to the +* original instruction address. +*/ static __always_inline void __user *error_get_trap_addr(struct pt_regs *regs) {return (void __user *)uprobe_get_trap_addr (regs);
[tip: x86/entry] x86/traps: Prepare for using DEFINE_IDTENTRY
In reply to Thomas GleixnerThe following commit has been merged into the x86/entry branch of tip:
The following commit has been merged into the x86/entry branch of tip:
Commit-ID: 54367ca6ef59d0e7599b02aca8dcc7ca4fd264bd Gitweb: https://git.kernel.org/tip/54367ca6ef59d0e7599b02aca8dcc7ca4fd264bd Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 25 Feb 2020 23:16:13 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 19 May 2020 16:03:57 +02:00
x86/traps: Prepare for using DEFINE_IDTENTRY
Prepare for using IDTENTRY to define the C exception/trap entry points. It would be possible to glue this into the existing macro maze, but it's simpler and better to read at the end to just make them distinct.
Provide a trivial inline helper to read the trap address and add a comment explaining the logic behind it.
The existing macros will be removed once all instances are converted.
--- arch/x86/kernel/traps.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
arch/x86/kernel/traps.c +15 -0
@@ -205,6 +205,21 @@ static void do_error_trap(struct pt_regs *regs, long error_code, char *str, } } +/* +* Posix requires to provide the address of the faulting instruction for +* SIGILL (#UD) and SIGFPE (#DE) in the si_addr member of siginfo_t. +* +* This address is usually regs->ip, but when an uprobe moved the code out +* of line then regs->ip points to the XOL code which would confuse +* anything which analyzes the fault address vs. the unmodified binary. If +* a trap happened in XOL code then uprobe maps regs->ip back to the +* original instruction address. +*/ +static __always_inline void __user *error_get_trap_addr(struct pt_regs *regs) +{ +return (void __user *)uprobe_get_trap_addr (regs); +} +#define IP ((void __user *)uprobe_get_trap_addr(regs))#define DO_ERROR (trapnr, signr, sicode, addr, str, name) \ dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \
PATCH v4 14/29 x86/entry: Convert Divide Error to IDTENTRY
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
Convert #DE to IDTENTRY:
- Implement the C entry point with DEFINE_IDTENTRY
- Emit the ASM stub with DECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
No functional change.
---
V2: Add comment to explain the DECLARE_IDTENTRY macro magic at the
actual usage site.
--- arch/x86/entry/entry_32.S | 7 ------- arch/x86/entry/entry_64.S | 1 - arch/x86/include/asm/idtentry.h | 12 ++++++++++++ arch/x86/include/asm/traps.h | 3 --- arch/x86/kernel/idt.c | 2 +- arch/x86/kernel/traps.c | 7 ++++++- arch/x86/xen/enlighten_pv.c | 7 ++++++- arch/x86/xen/xen-asm_64.S | 2 +- 8 files changed, 26 insertions(+), 15 deletions(-)
arch/x86/entry/entry_32.S +0 -7
@@ -1377,13 +1377,6 @@ SYM_CODE_START(alignment_check) jmp common_exception SYM_CODE_END(alignment_check) -SYM_CODE_START(divide_error) - ASM_CLAC - pushl $0 # no error code - pushl $do_divide_error - jmp common_exception -SYM_CODE_END(divide_error) - #ifdef CONFIG_X86_MCE SYM_CODE_START(machine_check) ASM_CLAC
arch/x86/entry/entry_64.S +0 -1
@@ -1073,7 +1073,6 @@ apicinterrupt IRQ_WORK_VECTOR irq_work * Exception entry points. */ -idtentry X86_TRAP_DE divide_error do_divide_error has_error_code=0 idtentry X86_TRAP_OF overflow do_overflow has_error_code=0 idtentry X86_TRAP_BP int3 do_int3 has_error_code=0 idtentry X86_TRAP_BR bounds do_bounds has_error_code=0
arch/x86/include/asm/idtentry.h +12 -0
@@ -67,4 +67,16 @@ static __always_inline void __##func(str#endif /* __ASSEMBLY__ */ +/* +* The actual entry points. Note that DECLARE_IDTENTRY*() serves two +* purposes: +* - provide the function declarations when included from C-Code +* - emit the ASM stubs when included from entry_32/64.S +* +* This avoids duplicate defines and ensures that everything is consistent. +*/ + +/* Simple exception entry points. No hardware error code */ +DECLARE_IDTENTRY (X86_TRAP_DE , exc_divide_error); +#endif
arch/x86/include/asm/traps.h +0 -3
@@ -11,7 +11,6 @@#define dotraplinkage __visible -asmlinkage void divide_error(void); asmlinkage void debug(void); asmlinkage void nmi(void); asmlinkage void int3(void);
@@ -38,7 +37,6 @@ asmlinkage void machine_check(void); asmlinkage void simd_coprocessor_error(void);#if defined(CONFIG_X86_64 ) && defined(CONFIG_XEN_PV ) -asmlinkage void xen_divide_error(void); asmlinkage void xen_xennmi(void); asmlinkage void xen_xendebug(void); asmlinkage void xen_int3(void);
@@ -62,7 +60,6 @@ asmlinkage void xen_machine_check(void); asmlinkage void xen_simd_coprocessor_error(void);#endif -dotraplinkage void do_divide_error(struct pt_regs *regs, long error_code); dotraplinkage void do_debug(struct pt_regs *regs, long error_code); dotraplinkage void do_nmi(struct pt_regs *regs, long error_code); dotraplinkage void do_int3(struct pt_regs *regs, long error_code);
arch/x86/kernel/idt.c +1 -1
@@ -70,7 +70,7 @@ static const __initconst struct idt_data* set up TSS. */ static const __initconst struct idt_data def_idts[] = { -INTG (X86_TRAP_DE , divide_error), +INTG (X86_TRAP_DE , asm_exc_divide_error),INTG (X86_TRAP_NMI , nmi),INTG (X86_TRAP_BR , bounds),INTG (X86_TRAP_UD , invalid_op),
arch/x86/kernel/traps.c +6 -1
@@ -210,6 +210,12 @@ static __always_inline void __user *erroreturn (void __user *)uprobe_get_trap_addr (regs); } +DEFINE_IDTENTRY (exc_divide_error) +{ +do_error_trap (regs,0 ,"divide_error" ,X86_TRAP_DE ,SIGFPE , +FPE_INTDIV ,error_get_trap_addr (regs)); +} +#define IP ((void __user *)uprobe_get_trap_addr(regs))#define DO_ERROR (trapnr, signr, sicode, addr, str, name) \ dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \
@@ -217,7 +223,6 @@ dotraplinkage void do_##name(struct pt_rdo_error_trap (regs, error_code, str, trapnr, signr, sicode, addr); \ } -DO_ERROR(X86_TRAP_DE, SIGFPE, FPE_INTDIV, IP, "divide error", divide_error) DO_ERROR(X86_TRAP_OF, SIGSEGV, 0, NULL, "overflow", overflow) DO_ERROR(X86_TRAP_UD, SIGILL, ILL_ILLOPN, IP, "invalid opcode", invalid_op)DO_ERROR (X86_TRAP_OLD_MF ,SIGFPE ,0 ,NULL ,"coprocessor segment overrun" , coprocessor_segment_overrun)
arch/x86/xen/enlighten_pv.c +6 -1
@@ -605,6 +605,11 @@ struct trap_array_entry {bool ist_okay; }; +#define TRAP_ENTRY (func, ist_ok) { \ + .orig = asm_##func, \ + .xen = xen_asm_##func, \ + .ist_okay = ist_ok } +static struct trap_array_entry trap_array[] = { { debug, xen_xendebug, true }, { double_fault, xen_double_fault, true },
@@ -618,7 +623,7 @@ static struct trap_array_entry trap_arra { entry_INT80_compat, xen_entry_INT80_compat, false }, #endif { page_fault, xen_page_fault, false }, - { divide_error, xen_divide_error, false }, + TRAP_ENTRY(exc_divide_error, false ), { bounds, xen_bounds, false }, { invalid_op, xen_invalid_op, false }, { device_not_available, xen_device_not_available, false },
arch/x86/xen/xen-asm_64.S +1 -1
@@ -28,7 +28,7 @@ SYM_CODE_END(xen_\name) _ASM_NOKPROBE(xen_\name) .endm -xen_pv_trap divide_error +xen_pv_trap asm_exc_divide_error xen_pv_trap debug xen_pv_trap xendebug xen_pv_trap int3
Re: [patch V4 part 3 14/29] x86/entry: Convert Divide Error to IDTENTRY
Quoted 12 lines · Thomas Gleixner
From: Thomas Gleixner <[email protected]>
Convert #DE to IDTENTRY:
- Implement the C entry point withDEFINE_IDTENTRY
- Emit the ASM stub withDECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV codeNo functional change.
[tip: x86/entry] x86/entry: Convert Divide Error to IDTENTRY
In reply to Thomas GleixnerThe following commit has been merged into the x86/entry branch of tip:
The following commit has been merged into the x86/entry branch of tip:
Commit-ID: 4b1250ee34e648302449214eb86235ce1d94ea17 Gitweb: https://git.kernel.org/tip/4b1250ee34e648302449214eb86235ce1d94ea17 Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 25 Feb 2020 23:16:14 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 19 May 2020 16:03:57 +02:00
x86/entry: Convert Divide Error to IDTENTRY
Convert #DE to IDTENTRY:
- Implement the C entry point with DEFINE_IDTENTRY
- Emit the ASM stub with DECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
No functional change.
--- arch/x86/entry/entry_32.S | 7 ------- arch/x86/entry/entry_64.S | 1 - arch/x86/include/asm/idtentry.h | 12 ++++++++++++ arch/x86/include/asm/traps.h | 3 --- arch/x86/kernel/idt.c | 2 +- arch/x86/kernel/traps.c | 7 ++++++- arch/x86/xen/enlighten_pv.c | 7 ++++++- arch/x86/xen/xen-asm_64.S | 2 +- 8 files changed, 26 insertions(+), 15 deletions(-)
arch/x86/entry/entry_32.S +0 -7
@@ -1377,13 +1377,6 @@ SYM_CODE_START(alignment_check) jmp common_exception SYM_CODE_END(alignment_check) -SYM_CODE_START(divide_error) - ASM_CLAC - pushl $0 # no error code - pushl $do_divide_error - jmp common_exception -SYM_CODE_END(divide_error) - #ifdef CONFIG_X86_MCE SYM_CODE_START(machine_check) ASM_CLAC
arch/x86/entry/entry_64.S +0 -1
@@ -1072,7 +1072,6 @@ apicinterrupt IRQ_WORK_VECTOR irq_work_interrupt smp_irq_work_interrupt * Exception entry points. */ -idtentry X86_TRAP_DE divide_error do_divide_error has_error_code=0 idtentry X86_TRAP_OF overflow do_overflow has_error_code=0 idtentry X86_TRAP_BP int3 do_int3 has_error_code=0 idtentry X86_TRAP_BR bounds do_bounds has_error_code=0
arch/x86/include/asm/idtentry.h +12 -0
@@ -67,4 +67,16 @@ static __always_inline void __##func(struct pt_regs *regs)#endif /* __ASSEMBLY__ */ +/* +* The actual entry points. Note that DECLARE_IDTENTRY*() serves two +* purposes: +* - provide the function declarations when included from C-Code +* - emit the ASM stubs when included from entry_32/64.S +* +* This avoids duplicate defines and ensures that everything is consistent. +*/ + +/* Simple exception entry points. No hardware error code */ +DECLARE_IDTENTRY (X86_TRAP_DE , exc_divide_error); +#endif
arch/x86/include/asm/traps.h +0 -3
@@ -11,7 +11,6 @@#define dotraplinkage __visible -asmlinkage void divide_error(void); asmlinkage void debug(void); asmlinkage void nmi(void); asmlinkage void int3(void);
@@ -38,7 +37,6 @@ asmlinkage void machine_check(void); asmlinkage void simd_coprocessor_error(void);#if defined(CONFIG_X86_64 ) && defined(CONFIG_XEN_PV ) -asmlinkage void xen_divide_error(void); asmlinkage void xen_xennmi(void); asmlinkage void xen_xendebug(void); asmlinkage void xen_int3(void);
@@ -62,7 +60,6 @@ asmlinkage void xen_machine_check(void); asmlinkage void xen_simd_coprocessor_error(void);#endif -dotraplinkage void do_divide_error(struct pt_regs *regs, long error_code); dotraplinkage void do_debug(struct pt_regs *regs, long error_code); dotraplinkage void do_nmi(struct pt_regs *regs, long error_code); dotraplinkage void do_int3(struct pt_regs *regs, long error_code);
arch/x86/kernel/idt.c +1 -1
@@ -73,7 +73,7 @@ static const __initconst struct idt_data early_idts[] = {* set up TSS. */ static const __initconst struct idt_data def_idts[] = { -INTG (X86_TRAP_DE , divide_error), +INTG (X86_TRAP_DE , asm_exc_divide_error),INTG (X86_TRAP_NMI , nmi),INTG (X86_TRAP_BR , bounds),INTG (X86_TRAP_UD , invalid_op),
arch/x86/kernel/traps.c +6 -1
@@ -220,6 +220,12 @@ static __always_inline void __user *error_get_trap_addr(struct pt_regs *regs)return (void __user *)uprobe_get_trap_addr (regs); } +DEFINE_IDTENTRY (exc_divide_error) +{ +do_error_trap (regs,0 ,"divide_error" ,X86_TRAP_DE ,SIGFPE , +FPE_INTDIV ,error_get_trap_addr (regs)); +} +#define IP ((void __user *)uprobe_get_trap_addr(regs))#define DO_ERROR (trapnr, signr, sicode, addr, str, name) \ dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \
@@ -227,7 +233,6 @@ dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \do_error_trap (regs, error_code, str, trapnr, signr, sicode, addr); \ } -DO_ERROR(X86_TRAP_DE, SIGFPE, FPE_INTDIV, IP, "divide error", divide_error) DO_ERROR(X86_TRAP_OF, SIGSEGV, 0, NULL, "overflow", overflow) DO_ERROR(X86_TRAP_UD, SIGILL, ILL_ILLOPN, IP, "invalid opcode", invalid_op)DO_ERROR (X86_TRAP_OLD_MF ,SIGFPE ,0 ,NULL ,"coprocessor segment overrun" , coprocessor_segment_overrun)
arch/x86/xen/enlighten_pv.c +6 -1
@@ -605,6 +605,11 @@ struct trap_array_entry {bool ist_okay; }; +#define TRAP_ENTRY (func, ist_ok) { \ + .orig = asm_##func, \ + .xen = xen_asm_##func, \ + .ist_okay = ist_ok } +static struct trap_array_entry trap_array[] = { { debug, xen_xendebug, true }, { double_fault, xen_double_fault, true },
@@ -618,7 +623,7 @@ static struct trap_array_entry trap_array[] = { { entry_INT80_compat, xen_entry_INT80_compat, false }, #endif { page_fault, xen_page_fault, false }, - { divide_error, xen_divide_error, false }, + TRAP_ENTRY(exc_divide_error, false ), { bounds, xen_bounds, false }, { invalid_op, xen_invalid_op, false }, { device_not_available, xen_device_not_available, false },
arch/x86/xen/xen-asm_64.S +1 -1
@@ -28,7 +28,7 @@ SYM_CODE_END(xen_\name) _ASM_NOKPROBE(xen_\name) .endm -xen_pv_trap divide_error +xen_pv_trap asm_exc_divide_error xen_pv_trap debug xen_pv_trap xendebug xen_pv_trap int3
Re: [tip: x86/entry] x86/entry: Convert Divide Error to IDTENTRY
arch/x86/kernel/traps.c static __always_inline void __user *error_get_trap_addr(struct pt_regs *regs) · line 227
Quoted 10 lines · On Tue, May 19, 2020 at 9:59 PM tip-bot2 for Thomas Gleixner…
The following commit has been merged into the x86/entry branch of tip:
arch/x86/kernel/traps.c +5
-1-DO_ERROR (X86_TRAP_DE ,SIGFPE ,FPE_INTDIV ,IP ,"divide error" , divide_error) +DEFINE_IDTENTRY (exc_divide_error) +{ +do_error_trap (regs,0 ,"divide_error" ,X86_TRAP_DE ,SIGFPE , +FPE_INTDIV ,error_get_trap_addr (regs)); +}
I suppose this is a copy-paste typo and was supposed to be "divide error", right?
Otherwise it changes how kernel oopses look like and breaks syzkaller crash parsing, and probably of every other kernel testing system that looks for kernel crashes.
syzkaller now says just the following for divide errors, without attribution to function/file/maintainers:
kernel panic: Fatal exception (3) FS: 0000000000000000(0000) GS:ffff8880ae500000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00000000004c9428 CR3: 0000000009e8d000 CR4: 00000000001506e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Kernel panic - not syncing: Fatal exception in interrupt
Kernel Offset: disabled
Rebooting in 86400 seconds..
I will fix it up in syzkaller. It is now required anyway since this new crash mode is in git history, so needed for bisection and testing of older releases.
It is not the first time kernel crash output changes intentionally/unintentionally breaking kernel testing.
But I wonder if LKDTM can be turned into actual executable tests that produce pass/fail and fix crash output for different oopses? Marco, you implemented some "output tests" for KCSAN. Can that be extended to other crash types? With some KUnit help? However, I am not sure about hard panics, they may not play well with unit-testing...
Re: [tip: x86/entry] x86/entry: Convert Divide Error to IDTENTRY
Quoted 6 lines · Dmitry Vyukov
Quoted 4 lines · On Tue, May 19, 2020 at 9:59 PM tip-bot2 for Thomas Gleixner…
The following commit has been merged into the x86/entry branch of tip:
-DO_ERROR(X86_TRAP_DE, SIGFPE,
FPE_INTDIV, IP, "divide error",divide_error)
Quoted 8 lines
arch/x86/kernel/traps.c static __always_inline void __user *error_get_trap_addr(struct pt_regs *regs) · line 227
Quoted 5 lines
arch/x86/kernel/traps.c +5
-0+DEFINE_IDTENTRY (exc_divide_error) +{ +do_error_trap (regs,0 ,"divide_error" ,X86_TRAP_DE ,SIGFPE , +FPE_INTDIV ,error_get_trap_addr (regs)); +}I suppose this is a copy-paste typo and was supposed to be "divide error", right?
Yeah. That was definitely unintentional.
[tip: x86/urgent] x86/traps: Fix #DE Oops message regression
In reply to Dmitry VyukovThe following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: 20802fef73a5a98b6e8ed1c0aeca82994d835b13 Gitweb: https://git.kernel.org/tip/20802fef73a5a98b6e8ed1c0aeca82994d835b13 Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 12 Oct 2020 15:11:47 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 12 Oct 2020 15:16:56 +02:00
x86/traps: Fix #DE Oops message regression
The conversion of #DE to the idtentry mechanism introduced a change in the Ooops message which confuses tools which parse crash information in dmesg.
Remove the underscore from 'divide_error' to restore previous behaviour.
--- arch/x86/kernel/traps.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/traps.c +1 -1
@@ -195,7 +195,7 @@ static __always_inline void __user *error_get_trap_addr(struct pt_regs *regs)DEFINE_IDTENTRY (exc_divide_error) { -do_error_trap (regs,0 ,"divide_error" ,X86_TRAP_DE ,SIGFPE , +do_error_trap (regs,0 ,"divide error" ,X86_TRAP_DE ,SIGFPE ,FPE_INTDIV ,error_get_trap_addr (regs)); }
Re: [tip: x86/entry] x86/entry: Convert Divide Error to IDTENTRY
In reply to Dmitry VyukovQuoted 36 lines · Dmitry Vyukov
arch/x86/kernel/traps.c static __always_inline void __user *error_get_trap_addr(struct pt_regs *regs) · line 227
Quoted 10 lines · On Tue, May 19, 2020 at 9:59 PM tip-bot2 for Thomas Gleixner…
The following commit has been merged into the x86/entry branch of tip:
arch/x86/kernel/traps.c +5
-1-DO_ERROR (X86_TRAP_DE ,SIGFPE ,FPE_INTDIV ,IP ,"divide error" , divide_error) +DEFINE_IDTENTRY (exc_divide_error) +{ +do_error_trap (regs,0 ,"divide_error" ,X86_TRAP_DE ,SIGFPE , +FPE_INTDIV ,error_get_trap_addr (regs)); +}I suppose this is a copy-paste typo and was supposed to be "divide error", right?
Otherwise it changes how kernel oopses look like and breaks syzkaller crash parsing, and probably of every other kernel testing system that looks for kernel crashes.syzkaller now says just the following for divide errors, without attribution to function/file/maintainers:
kernel panic: Fatal exception (3) FS: 0000000000000000(0000) GS:ffff8880ae500000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00000000004c9428 CR3: 0000000009e8d000 CR4: 00000000001506e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Kernel panic - not syncing: Fatal exception in interruptKernel Offset: disabled
Rebooting in 86400 seconds..I will fix it up in syzkaller. It is now required anyway since this new crash mode is in git history, so needed for bisection and testing of older releases.
Quoted 7 lines
It is not the first time kernel crash output changes intentionally/unintentionally breaking kernel testing.
But I wonder if LKDTM can be turned into actual executable tests that produce pass/fail and fix crash output for different oopses? Marco, you implemented some "output tests" for KCSAN. Can that be extended to other crash types? With some KUnit help? However, I am not sure about hard panics, they may not play well with unit-testing...
A lot of the behavioral tests in LKDTM end up triggering arch-specific logging. I decided to avoid trying to consolidate it in favor of actually getting the test coverage. :)
Signature · 1 line
Kees Cook
Re: [tip: x86/entry] x86/entry: Convert Divide Error to IDTENTRY
Quoted 46 lines · Kees Cook
Quoted 36 lines · Dmitry Vyukov
arch/x86/kernel/traps.c static __always_inline void __user *error_get_trap_addr(struct pt_regs *regs) · line 227
Quoted 10 lines · On Tue, May 19, 2020 at 9:59 PM tip-bot2 for Thomas Gleixner…
The following commit has been merged into the x86/entry branch of tip:
arch/x86/kernel/traps.c +5
-1-DO_ERROR (X86_TRAP_DE ,SIGFPE ,FPE_INTDIV ,IP ,"divide error" , divide_error) +DEFINE_IDTENTRY (exc_divide_error) +{ +do_error_trap (regs,0 ,"divide_error" ,X86_TRAP_DE ,SIGFPE , +FPE_INTDIV ,error_get_trap_addr (regs)); +}I suppose this is a copy-paste typo and was supposed to be "divide error", right?
Otherwise it changes how kernel oopses look like and breaks syzkaller crash parsing, and probably of every other kernel testing system that looks for kernel crashes.syzkaller now says just the following for divide errors, without attribution to function/file/maintainers:
kernel panic: Fatal exception (3) FS: 0000000000000000(0000) GS:ffff8880ae500000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00000000004c9428 CR3: 0000000009e8d000 CR4: 00000000001506e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Kernel panic - not syncing: Fatal exception in interruptKernel Offset: disabled
Rebooting in 86400 seconds..I will fix it up in syzkaller. It is now required anyway since this new crash mode is in git history, so needed for bisection and testing of older releases.
Quoted 7 lines
It is not the first time kernel crash output changes intentionally/unintentionally breaking kernel testing.
But I wonder if LKDTM can be turned into actual executable tests that produce pass/fail and fix crash output for different oopses? Marco, you implemented some "output tests" for KCSAN. Can that be extended to other crash types? With some KUnit help? However, I am not sure about hard panics, they may not play well with unit-testing...
Quoted 3 lines
A lot of the behavioral tests in LKDTM end up triggering arch-specific logging. I decided to avoid trying to consolidate it in favor of actually getting the test coverage. :)
What do you mean? Some of these tests would need to be arch-specific, yes. But I think this is mostly orthogonal to making them PASS/FAIL tests that can be used during testing.
FTR, syzkaller fix for crash format:
https://github.com/google/syzkaller/commit/c9f222e7b410a336e436f094e24f6465d1cfdc13
[tip: x86/urgent] x86/traps: Fix #DE Oops message regression
In reply to Dmitry VyukovThe following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: 5f1ec1fd32252af5130dac23b5542e8e66fe0bcb Gitweb: https://git.kernel.org/tip/5f1ec1fd32252af5130dac23b5542e8e66fe0bcb Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 12 Oct 2020 15:11:47 +02:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Tue, 13 Oct 2020 19:17:33 +02:00
x86/traps: Fix #DE Oops message regression
The conversion of #DE to the idtentry mechanism introduced a change in the Ooops message which confuses tools which parse crash information in dmesg.
Remove the underscore from 'divide_error' to restore previous behaviour.
--- arch/x86/kernel/traps.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/traps.c +1 -1
@@ -195,7 +195,7 @@ static __always_inline void __user *error_get_trap_addr(struct pt_regs *regs)DEFINE_IDTENTRY (exc_divide_error) { -do_error_trap (regs,0 ,"divide_error" ,X86_TRAP_DE ,SIGFPE , +do_error_trap (regs,0 ,"divide error" ,X86_TRAP_DE ,SIGFPE ,FPE_INTDIV ,error_get_trap_addr (regs)); }
PATCH v4 15/29 x86/entry: Convert Overflow exception to IDTENTRY
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
Convert #OF to IDTENTRY:
- Implement the C entry point with DEFINE_IDTENTRY
- Emit the ASM stub with DECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototyoes
No functional change.
--- arch/x86/entry/entry_32.S | 7 ------- arch/x86/entry/entry_64.S | 1 - arch/x86/include/asm/idtentry.h | 1 + arch/x86/include/asm/traps.h | 3 --- arch/x86/kernel/idt.c | 2 +- arch/x86/kernel/traps.c | 6 +++++- arch/x86/xen/enlighten_pv.c | 2 +- arch/x86/xen/xen-asm_64.S | 2 +- 8 files changed, 9 insertions(+), 15 deletions(-)
arch/x86/entry/entry_32.S +0 -7
@@ -1325,13 +1325,6 @@ SYM_CODE_START(native_iret) SYM_CODE_END(native_iret) #endif -SYM_CODE_START(overflow) - ASM_CLAC - pushl $0 - pushl $do_overflow - jmp common_exception -SYM_CODE_END(overflow) - SYM_CODE_START(bounds) ASM_CLAC pushl $0
arch/x86/entry/entry_64.S +0 -1
@@ -1073,7 +1073,6 @@ apicinterrupt IRQ_WORK_VECTOR irq_work * Exception entry points. */ -idtentry X86_TRAP_OF overflow do_overflow has_error_code=0 idtentry X86_TRAP_BP int3 do_int3 has_error_code=0 idtentry X86_TRAP_BR bounds do_bounds has_error_code=0 idtentry X86_TRAP_UD invalid_op do_invalid_op has_error_code=0
arch/x86/include/asm/idtentry.h +1 -0
@@ -78,5 +78,6 @@ static __always_inline void __##func(str/* Simple exception entry points. No hardware error code */ DECLARE_IDTENTRY (X86_TRAP_DE , exc_divide_error); +DECLARE_IDTENTRY (X86_TRAP_OF , exc_overflow);#endif
arch/x86/include/asm/traps.h +0 -3
@@ -14,7 +14,6 @@ asmlinkage void debug(void); asmlinkage void nmi(void); asmlinkage void int3(void); -asmlinkage void overflow(void); asmlinkage void bounds(void); asmlinkage void invalid_op(void); asmlinkage void device_not_available(void);
@@ -40,7 +39,6 @@ asmlinkage void simd_coprocessor_error(v asmlinkage void xen_xennmi(void); asmlinkage void xen_xendebug(void); asmlinkage void xen_int3(void); -asmlinkage void xen_overflow(void); asmlinkage void xen_bounds(void); asmlinkage void xen_invalid_op(void); asmlinkage void xen_device_not_available(void);
@@ -63,7 +61,6 @@ asmlinkage void xen_simd_coprocessor_err dotraplinkage void do_debug(struct pt_regs *regs, long error_code); dotraplinkage void do_nmi(struct pt_regs *regs, long error_code); dotraplinkage void do_int3(struct pt_regs *regs, long error_code); -dotraplinkage void do_overflow(struct pt_regs *regs, long error_code); dotraplinkage void do_bounds(struct pt_regs *regs, long error_code); dotraplinkage void do_invalid_op(struct pt_regs *regs, long error_code); dotraplinkage void do_device_not_available(struct pt_regs *regs, long error_code);
arch/x86/kernel/idt.c +1 -1
@@ -96,7 +96,7 @@ static const __initconst struct idt_data INTG(X86_TRAP_MC, &machine_check), #endif - SYSG(X86_TRAP_OF, overflow), + SYSG(X86_TRAP_OF, asm_exc_overflow),#if defined(CONFIG_IA32_EMULATION ) SYSG(IA32_SYSCALL_VECTOR, entry_INT80_compat),#elif defined(CONFIG_X86_32 )
arch/x86/kernel/traps.c +5 -1
@@ -216,6 +216,11 @@ DEFINE_IDTENTRY(exc_divide_error) FPE_INTDIV, error_get_trap_addr(regs)); } +DEFINE_IDTENTRY (exc_overflow) +{ +do_error_trap (regs,0 ,"overflow" ,X86_TRAP_OF ,SIGSEGV ,0 ,NULL ); +} +#define IP ((void __user *)uprobe_get_trap_addr(regs))#define DO_ERROR (trapnr, signr, sicode, addr, str, name) \ dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \
@@ -223,7 +228,6 @@ dotraplinkage void do_##name(struct pt_rdo_error_trap (regs, error_code, str, trapnr, signr, sicode, addr); \ } -DO_ERROR(X86_TRAP_OF, SIGSEGV, 0, NULL, "overflow", overflow) DO_ERROR(X86_TRAP_UD, SIGILL, ILL_ILLOPN, IP, "invalid opcode", invalid_op) DO_ERROR(X86_TRAP_OLD_MF, SIGFPE, 0, NULL, "coprocessor segment overrun", coprocessor_segment_overrun)DO_ERROR (X86_TRAP_TS ,SIGSEGV ,0 ,NULL ,"invalid TSS" , invalid_TSS)
arch/x86/xen/enlighten_pv.c +1 -1
@@ -618,7 +618,7 @@ static struct trap_array_entry trap_arra#endif { nmi, xen_xennmi, true }, { int3, xen_int3, false }, - { overflow, xen_overflow, false }, +TRAP_ENTRY (exc_overflow, false ), #ifdef CONFIG_IA32_EMULATION { entry_INT80_compat, xen_entry_INT80_compat, false }, #endif
arch/x86/xen/xen-asm_64.S +1 -1
@@ -33,7 +33,7 @@ xen_pv_trap debug xen_pv_trap xendebug xen_pv_trap int3 xen_pv_trap xennmi -xen_pv_trap overflow +xen_pv_trap asm_exc_overflow xen_pv_trap bounds xen_pv_trap invalid_op xen_pv_trap device_not_available
Re: [patch V4 part 3 15/29] x86/entry: Convert Overflow exception to IDTENTRY
Quoted 11 lines · Thomas Gleixner
From: Thomas Gleixner <[email protected]>
Convert #OF to IDTENTRY:
- Implement the C entry point withDEFINE_IDTENTRY
- Emit the ASM stub withDECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototyoes
Quoted 1 line
No functional change.
[tip: x86/entry] x86/entry: Convert Overflow exception to IDTENTRY
In reply to Thomas GleixnerThe following commit has been merged into the x86/entry branch of tip:
The following commit has been merged into the x86/entry branch of tip:
Commit-ID: 50455f27bae20453b4042423dc5ec1bee9ef89f5 Gitweb: https://git.kernel.org/tip/50455f27bae20453b4042423dc5ec1bee9ef89f5 Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 25 Feb 2020 23:16:15 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 19 May 2020 16:03:58 +02:00
x86/entry: Convert Overflow exception to IDTENTRY
Convert #OF to IDTENTRY:
- Implement the C entry point with DEFINE_IDTENTRY
- Emit the ASM stub with DECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototypes
No functional change.
--- arch/x86/entry/entry_32.S | 7 ------- arch/x86/entry/entry_64.S | 1 - arch/x86/include/asm/idtentry.h | 1 + arch/x86/include/asm/traps.h | 3 --- arch/x86/kernel/idt.c | 2 +- arch/x86/kernel/traps.c | 6 +++++- arch/x86/xen/enlighten_pv.c | 2 +- arch/x86/xen/xen-asm_64.S | 2 +- 8 files changed, 9 insertions(+), 15 deletions(-)
arch/x86/entry/entry_32.S +0 -7
@@ -1325,13 +1325,6 @@ SYM_CODE_START(native_iret) SYM_CODE_END(native_iret) #endif -SYM_CODE_START(overflow) - ASM_CLAC - pushl $0 - pushl $do_overflow - jmp common_exception -SYM_CODE_END(overflow) - SYM_CODE_START(bounds) ASM_CLAC pushl $0
arch/x86/entry/entry_64.S +0 -1
@@ -1072,7 +1072,6 @@ apicinterrupt IRQ_WORK_VECTOR irq_work_interrupt smp_irq_work_interrupt * Exception entry points. */ -idtentry X86_TRAP_OF overflow do_overflow has_error_code=0 idtentry X86_TRAP_BP int3 do_int3 has_error_code=0 idtentry X86_TRAP_BR bounds do_bounds has_error_code=0 idtentry X86_TRAP_UD invalid_op do_invalid_op has_error_code=0
arch/x86/include/asm/idtentry.h +1 -0
@@ -78,5 +78,6 @@ static __always_inline void __##func(struct pt_regs *regs)/* Simple exception entry points. No hardware error code */ DECLARE_IDTENTRY (X86_TRAP_DE , exc_divide_error); +DECLARE_IDTENTRY (X86_TRAP_OF , exc_overflow);#endif
arch/x86/include/asm/traps.h +0 -3
@@ -14,7 +14,6 @@ asmlinkage void debug(void); asmlinkage void nmi(void); asmlinkage void int3(void); -asmlinkage void overflow(void); asmlinkage void bounds(void); asmlinkage void invalid_op(void); asmlinkage void device_not_available(void);
@@ -40,7 +39,6 @@ asmlinkage void simd_coprocessor_error(void); asmlinkage void xen_xennmi(void); asmlinkage void xen_xendebug(void); asmlinkage void xen_int3(void); -asmlinkage void xen_overflow(void); asmlinkage void xen_bounds(void); asmlinkage void xen_invalid_op(void); asmlinkage void xen_device_not_available(void);
@@ -63,7 +61,6 @@ asmlinkage void xen_simd_coprocessor_error(void); dotraplinkage void do_debug(struct pt_regs *regs, long error_code); dotraplinkage void do_nmi(struct pt_regs *regs, long error_code); dotraplinkage void do_int3(struct pt_regs *regs, long error_code); -dotraplinkage void do_overflow(struct pt_regs *regs, long error_code); dotraplinkage void do_bounds(struct pt_regs *regs, long error_code); dotraplinkage void do_invalid_op(struct pt_regs *regs, long error_code); dotraplinkage void do_device_not_available(struct pt_regs *regs, long error_code);
arch/x86/kernel/idt.c +1 -1
@@ -99,7 +99,7 @@ static const __initconst struct idt_data def_idts[] = { INTG(X86_TRAP_MC, machine_check), #endif - SYSG(X86_TRAP_OF, overflow), + SYSG(X86_TRAP_OF, asm_exc_overflow),#if defined(CONFIG_IA32_EMULATION ) SYSG(IA32_SYSCALL_VECTOR, entry_INT80_compat),#elif defined(CONFIG_X86_32 )
arch/x86/kernel/traps.c +5 -1
@@ -226,6 +226,11 @@ DEFINE_IDTENTRY(exc_divide_error) FPE_INTDIV, error_get_trap_addr(regs)); } +DEFINE_IDTENTRY (exc_overflow) +{ +do_error_trap (regs,0 ,"overflow" ,X86_TRAP_OF ,SIGSEGV ,0 ,NULL ); +} +#define IP ((void __user *)uprobe_get_trap_addr(regs))#define DO_ERROR (trapnr, signr, sicode, addr, str, name) \ dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \
@@ -233,7 +238,6 @@ dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \do_error_trap (regs, error_code, str, trapnr, signr, sicode, addr); \ } -DO_ERROR(X86_TRAP_OF, SIGSEGV, 0, NULL, "overflow", overflow) DO_ERROR(X86_TRAP_UD, SIGILL, ILL_ILLOPN, IP, "invalid opcode", invalid_op) DO_ERROR(X86_TRAP_OLD_MF, SIGFPE, 0, NULL, "coprocessor segment overrun", coprocessor_segment_overrun)DO_ERROR (X86_TRAP_TS ,SIGSEGV ,0 ,NULL ,"invalid TSS" , invalid_TSS)
arch/x86/xen/enlighten_pv.c +1 -1
@@ -618,7 +618,7 @@ static struct trap_array_entry trap_array[] = {#endif { nmi, xen_xennmi, true }, { int3, xen_int3, false }, - { overflow, xen_overflow, false }, +TRAP_ENTRY (exc_overflow, false ), #ifdef CONFIG_IA32_EMULATION { entry_INT80_compat, xen_entry_INT80_compat, false }, #endif
arch/x86/xen/xen-asm_64.S +1 -1
@@ -33,7 +33,7 @@ xen_pv_trap debug xen_pv_trap xendebug xen_pv_trap int3 xen_pv_trap xennmi -xen_pv_trap overflow +xen_pv_trap asm_exc_overflow xen_pv_trap bounds xen_pv_trap invalid_op xen_pv_trap device_not_available
PATCH v4 16/29 x86/entry: Convert Bounds exception to IDTENTRY
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
Convert #BR to IDTENTRY:
- Implement the C entry point with DEFINE_IDTENTRY
- Emit the ASM stub with DECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototyoes
- Remove the RCU warning as the new entry macro ensures correctness
No functional change.
--- arch/x86/entry/entry_32.S | 7 ------- arch/x86/entry/entry_64.S | 1 - arch/x86/include/asm/idtentry.h | 1 + arch/x86/include/asm/traps.h | 3 --- arch/x86/kernel/idt.c | 2 +- arch/x86/kernel/traps.c | 9 ++++----- arch/x86/xen/enlighten_pv.c | 2 +- arch/x86/xen/xen-asm_64.S | 2 +- 8 files changed, 8 insertions(+), 19 deletions(-)
arch/x86/entry/entry_32.S +0 -7
@@ -1325,13 +1325,6 @@ SYM_CODE_START(native_iret) SYM_CODE_END(native_iret) #endif -SYM_CODE_START(bounds) - ASM_CLAC - pushl $0 - pushl $do_bounds - jmp common_exception -SYM_CODE_END(bounds) - SYM_CODE_START(invalid_op) ASM_CLAC pushl $0
arch/x86/entry/entry_64.S +0 -1
@@ -1074,7 +1074,6 @@ apicinterrupt IRQ_WORK_VECTOR irq_work */ idtentry X86_TRAP_BP int3 do_int3 has_error_code=0 -idtentry X86_TRAP_BR bounds do_bounds has_error_code=0 idtentry X86_TRAP_UD invalid_op do_invalid_op has_error_code=0 idtentry X86_TRAP_NM device_not_available do_device_not_available has_error_code=0 idtentry X86_TRAP_OLD_MF coprocessor_segment_overrun do_coprocessor_segment_overrun has_error_code=0
arch/x86/include/asm/idtentry.h +1 -0
@@ -79,5 +79,6 @@ static __always_inline void __##func(str/* Simple exception entry points. No hardware error code */ DECLARE_IDTENTRY (X86_TRAP_DE , exc_divide_error);DECLARE_IDTENTRY (X86_TRAP_OF , exc_overflow); +DECLARE_IDTENTRY (X86_TRAP_BR , exc_bounds);#endif
arch/x86/include/asm/traps.h +0 -3
@@ -14,7 +14,6 @@ asmlinkage void debug(void); asmlinkage void nmi(void); asmlinkage void int3(void); -asmlinkage void bounds(void); asmlinkage void invalid_op(void); asmlinkage void device_not_available(void);#ifdef CONFIG_X86_64
@@ -39,7 +38,6 @@ asmlinkage void simd_coprocessor_error(v asmlinkage void xen_xennmi(void); asmlinkage void xen_xendebug(void); asmlinkage void xen_int3(void); -asmlinkage void xen_bounds(void); asmlinkage void xen_invalid_op(void); asmlinkage void xen_device_not_available(void); asmlinkage void xen_double_fault(void);
@@ -61,7 +59,6 @@ asmlinkage void xen_simd_coprocessor_err dotraplinkage void do_debug(struct pt_regs *regs, long error_code); dotraplinkage void do_nmi(struct pt_regs *regs, long error_code); dotraplinkage void do_int3(struct pt_regs *regs, long error_code); -dotraplinkage void do_bounds(struct pt_regs *regs, long error_code); dotraplinkage void do_invalid_op(struct pt_regs *regs, long error_code); dotraplinkage void do_device_not_available(struct pt_regs *regs, long error_code);#if defined(CONFIG_X86_64 ) || defined(CONFIG_DOUBLEFAULT )
arch/x86/kernel/idt.c +1 -1
@@ -72,7 +72,7 @@ static const __initconst struct idt_datastatic const __initconst struct idt_data def_idts[] = {INTG (X86_TRAP_DE , asm_exc_divide_error),INTG (X86_TRAP_NMI , nmi), -INTG (X86_TRAP_BR , bounds), +INTG (X86_TRAP_BR , asm_exc_bounds),INTG (X86_TRAP_UD , invalid_op),INTG (X86_TRAP_NM , device_not_available),INTG (X86_TRAP_OLD_MF , coprocessor_segment_overrun),
arch/x86/kernel/traps.c +4 -5
@@ -402,18 +402,17 @@ dotraplinkage void do_double_fault(struc }#endif -dotraplinkage void do_bounds(struct pt_regs *regs, long error_code) +DEFINE_IDTENTRY (exc_bounds) { -RCU_LOCKDEP_WARN (!rcu_is_watching (),"entry code didn't wake RCU" ); -if (notify_die (DIE_TRAP ,"bounds" , regs, error_code, +if (notify_die (DIE_TRAP ,"bounds" , regs,0 ,X86_TRAP_BR ,SIGSEGV ) ==NOTIFY_STOP )return ;cond_local_irq_enable (regs);if (!user_mode (regs)) -die ("bounds" , regs, error_code); +die ("bounds" , regs,0 ); -do_trap (X86_TRAP_BR ,SIGSEGV ,"bounds" , regs, error_code,0 ,NULL ); +do_trap (X86_TRAP_BR ,SIGSEGV ,"bounds" , regs,0 ,0 ,NULL );cond_local_irq_disable (regs); }
arch/x86/xen/enlighten_pv.c +1 -1
@@ -624,7 +624,7 @@ static struct trap_array_entry trap_arra#endif { page_fault, xen_page_fault, false },TRAP_ENTRY (exc_divide_error, false ), - { bounds, xen_bounds, false }, +TRAP_ENTRY (exc_bounds, false ), { invalid_op, xen_invalid_op, false }, { device_not_available, xen_device_not_available, false }, { coprocessor_segment_overrun, xen_coprocessor_segment_overrun, false },
arch/x86/xen/xen-asm_64.S +1 -1
@@ -34,7 +34,7 @@ xen_pv_trap xendebug xen_pv_trap int3 xen_pv_trap xennmi xen_pv_trap asm_exc_overflow -xen_pv_trap bounds +xen_pv_trap asm_exc_bounds xen_pv_trap invalid_op xen_pv_trap device_not_available xen_pv_trap double_fault
Re: [patch V4 part 3 16/29] x86/entry: Convert Bounds exception to IDTENTRY
Quoted 10 lines · Thomas Gleixner
From: Thomas Gleixner <[email protected]>
Convert #BR to IDTENTRY:
- Implement the C entry point withDEFINE_IDTENTRY
- Emit the ASM stub withDECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototyoes
prototypoes?
[tip: x86/entry] x86/entry: Convert Bounds exception to IDTENTRY
In reply to Thomas GleixnerThe following commit has been merged into the x86/entry branch of tip:
The following commit has been merged into the x86/entry branch of tip:
Commit-ID: e98b41399cb15d8e52e266b53e32f1362f541daf Gitweb: https://git.kernel.org/tip/e98b41399cb15d8e52e266b53e32f1362f541daf Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 25 Feb 2020 23:16:17 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 19 May 2020 16:03:58 +02:00
x86/entry: Convert Bounds exception to IDTENTRY
Convert #BR to IDTENTRY:
- Implement the C entry point with DEFINE_IDTENTRY
- Emit the ASM stub with DECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototypes
- Remove the RCU warning as the new entry macro ensures correctness
No functional change.
--- arch/x86/entry/entry_32.S | 7 ------- arch/x86/entry/entry_64.S | 1 - arch/x86/include/asm/idtentry.h | 1 + arch/x86/include/asm/traps.h | 3 --- arch/x86/kernel/idt.c | 2 +- arch/x86/kernel/traps.c | 9 ++++----- arch/x86/xen/enlighten_pv.c | 2 +- arch/x86/xen/xen-asm_64.S | 2 +- 8 files changed, 8 insertions(+), 19 deletions(-)
arch/x86/entry/entry_32.S +0 -7
@@ -1325,13 +1325,6 @@ SYM_CODE_START(native_iret) SYM_CODE_END(native_iret) #endif -SYM_CODE_START(bounds) - ASM_CLAC - pushl $0 - pushl $do_bounds - jmp common_exception -SYM_CODE_END(bounds) - SYM_CODE_START(invalid_op) ASM_CLAC pushl $0
arch/x86/entry/entry_64.S +0 -1
@@ -1073,7 +1073,6 @@ apicinterrupt IRQ_WORK_VECTOR irq_work_interrupt smp_irq_work_interrupt */ idtentry X86_TRAP_BP int3 do_int3 has_error_code=0 -idtentry X86_TRAP_BR bounds do_bounds has_error_code=0 idtentry X86_TRAP_UD invalid_op do_invalid_op has_error_code=0 idtentry X86_TRAP_NM device_not_available do_device_not_available has_error_code=0 idtentry X86_TRAP_OLD_MF coprocessor_segment_overrun do_coprocessor_segment_overrun has_error_code=0
arch/x86/include/asm/idtentry.h +1 -0
@@ -79,5 +79,6 @@ static __always_inline void __##func(struct pt_regs *regs)/* Simple exception entry points. No hardware error code */ DECLARE_IDTENTRY (X86_TRAP_DE , exc_divide_error);DECLARE_IDTENTRY (X86_TRAP_OF , exc_overflow); +DECLARE_IDTENTRY (X86_TRAP_BR , exc_bounds);#endif
arch/x86/include/asm/traps.h +0 -3
@@ -14,7 +14,6 @@ asmlinkage void debug(void); asmlinkage void nmi(void); asmlinkage void int3(void); -asmlinkage void bounds(void); asmlinkage void invalid_op(void); asmlinkage void device_not_available(void);#ifdef CONFIG_X86_64
@@ -39,7 +38,6 @@ asmlinkage void simd_coprocessor_error(void); asmlinkage void xen_xennmi(void); asmlinkage void xen_xendebug(void); asmlinkage void xen_int3(void); -asmlinkage void xen_bounds(void); asmlinkage void xen_invalid_op(void); asmlinkage void xen_device_not_available(void); asmlinkage void xen_double_fault(void);
@@ -61,7 +59,6 @@ asmlinkage void xen_simd_coprocessor_error(void); dotraplinkage void do_debug(struct pt_regs *regs, long error_code); dotraplinkage void do_nmi(struct pt_regs *regs, long error_code); dotraplinkage void do_int3(struct pt_regs *regs, long error_code); -dotraplinkage void do_bounds(struct pt_regs *regs, long error_code); dotraplinkage void do_invalid_op(struct pt_regs *regs, long error_code); dotraplinkage void do_device_not_available(struct pt_regs *regs, long error_code); dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code, unsigned long cr2);
arch/x86/kernel/idt.c +1 -1
@@ -75,7 +75,7 @@ static const __initconst struct idt_data early_idts[] = {static const __initconst struct idt_data def_idts[] = {INTG (X86_TRAP_DE , asm_exc_divide_error),INTG (X86_TRAP_NMI , nmi), -INTG (X86_TRAP_BR , bounds), +INTG (X86_TRAP_BR , asm_exc_bounds),INTG (X86_TRAP_UD , invalid_op),INTG (X86_TRAP_NM , device_not_available),INTG (X86_TRAP_OLD_MF , coprocessor_segment_overrun),
arch/x86/kernel/traps.c +4 -5
@@ -410,18 +410,17 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code, unsignpanic ("Machine halted." ); } -dotraplinkage void do_bounds(struct pt_regs *regs, long error_code) +DEFINE_IDTENTRY (exc_bounds) { -RCU_LOCKDEP_WARN (!rcu_is_watching (),"entry code didn't wake RCU" ); -if (notify_die (DIE_TRAP ,"bounds" , regs, error_code, +if (notify_die (DIE_TRAP ,"bounds" , regs,0 ,X86_TRAP_BR ,SIGSEGV ) ==NOTIFY_STOP )return ;cond_local_irq_enable (regs);if (!user_mode (regs)) -die ("bounds" , regs, error_code); +die ("bounds" , regs,0 ); -do_trap (X86_TRAP_BR ,SIGSEGV ,"bounds" , regs, error_code,0 ,NULL ); +do_trap (X86_TRAP_BR ,SIGSEGV ,"bounds" , regs,0 ,0 ,NULL );cond_local_irq_disable (regs); }
arch/x86/xen/enlighten_pv.c +1 -1
@@ -624,7 +624,7 @@ static struct trap_array_entry trap_array[] = {#endif { page_fault, xen_page_fault, false },TRAP_ENTRY (exc_divide_error, false ), - { bounds, xen_bounds, false }, +TRAP_ENTRY (exc_bounds, false ), { invalid_op, xen_invalid_op, false }, { device_not_available, xen_device_not_available, false }, { coprocessor_segment_overrun, xen_coprocessor_segment_overrun, false },
arch/x86/xen/xen-asm_64.S +1 -1
@@ -34,7 +34,7 @@ xen_pv_trap xendebug xen_pv_trap int3 xen_pv_trap xennmi xen_pv_trap asm_exc_overflow -xen_pv_trap bounds +xen_pv_trap asm_exc_bounds xen_pv_trap invalid_op xen_pv_trap device_not_available xen_pv_trap double_fault
PATCH v4 17/29 x86/entry: Convert Invalid Opcode exception to IDTENTRY
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
Convert #UD to IDTENTRY:
- Implement the C entry point with DEFINE_IDTENTRY
- Emit the ASM stub with DECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Fixup the FOOF bug call in fault.c
- Remove the old prototyoes
No functional change.
---
V2: Fixup the FOOF bug call into invalid op
--- arch/x86/entry/entry_32.S | 7 ------- arch/x86/entry/entry_64.S | 1 - arch/x86/include/asm/idtentry.h | 1 + arch/x86/include/asm/traps.h | 8 +++++--- arch/x86/kernel/idt.c | 2 +- arch/x86/kernel/traps.c | 16 +++++++++++++++- arch/x86/mm/fault.c | 2 +- arch/x86/xen/enlighten_pv.c | 2 +- arch/x86/xen/xen-asm_64.S | 2 +- 9 files changed, 25 insertions(+), 16 deletions(-)
arch/x86/entry/entry_32.S +0 -7
@@ -1325,13 +1325,6 @@ SYM_CODE_START(native_iret) SYM_CODE_END(native_iret) #endif -SYM_CODE_START(invalid_op) - ASM_CLAC - pushl $0 - pushl $do_invalid_op - jmp common_exception -SYM_CODE_END(invalid_op) - SYM_CODE_START(coprocessor_segment_overrun) ASM_CLAC pushl $0
arch/x86/entry/entry_64.S +0 -1
@@ -1074,7 +1074,6 @@ apicinterrupt IRQ_WORK_VECTOR irq_work */ idtentry X86_TRAP_BP int3 do_int3 has_error_code=0 -idtentry X86_TRAP_UD invalid_op do_invalid_op has_error_code=0 idtentry X86_TRAP_NM device_not_available do_device_not_available has_error_code=0 idtentry X86_TRAP_OLD_MF coprocessor_segment_overrun do_coprocessor_segment_overrun has_error_code=0 idtentry X86_TRAP_TS invalid_TSS do_invalid_TSS has_error_code=1
arch/x86/include/asm/idtentry.h +1 -0
@@ -80,5 +80,6 @@ static __always_inline void __##func(strDECLARE_IDTENTRY (X86_TRAP_DE , exc_divide_error);DECLARE_IDTENTRY (X86_TRAP_OF , exc_overflow);DECLARE_IDTENTRY (X86_TRAP_BR , exc_bounds); +DECLARE_IDTENTRY (X86_TRAP_UD , exc_invalid_op);#endif
arch/x86/include/asm/traps.h +5 -3
@@ -14,7 +14,6 @@ asmlinkage void debug(void); asmlinkage void nmi(void); asmlinkage void int3(void); -asmlinkage void invalid_op(void); asmlinkage void device_not_available(void);#ifdef CONFIG_X86_64 asmlinkage void double_fault(void);
@@ -38,7 +37,6 @@ asmlinkage void simd_coprocessor_error(v asmlinkage void xen_xennmi(void); asmlinkage void xen_xendebug(void); asmlinkage void xen_int3(void); -asmlinkage void xen_invalid_op(void); asmlinkage void xen_device_not_available(void); asmlinkage void xen_double_fault(void); asmlinkage void xen_coprocessor_segment_overrun(void);
@@ -59,7 +57,6 @@ asmlinkage void xen_simd_coprocessor_err dotraplinkage void do_debug(struct pt_regs *regs, long error_code); dotraplinkage void do_nmi(struct pt_regs *regs, long error_code); dotraplinkage void do_int3(struct pt_regs *regs, long error_code); -dotraplinkage void do_invalid_op(struct pt_regs *regs, long error_code); dotraplinkage void do_device_not_available(struct pt_regs *regs, long error_code);#if defined(CONFIG_X86_64 ) || defined(CONFIG_DOUBLEFAULT ) dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code, unsigned long cr2);
@@ -86,6 +83,11 @@ struct bad_iret_stack *fixup_bad_iret(stvoid __init trap_init (void );#endif +#ifdef CONFIG_X86_F00F_BUG +/* For handling the FOOF bug */ +void handle_invalid_op (struct pt_regs *regs); +#endif +static inline int get_si_code (unsigned long condition) {if (condition &DR_STEP )
arch/x86/kernel/idt.c +1 -1
@@ -73,7 +73,7 @@ static const __initconst struct idt_dataINTG (X86_TRAP_DE , asm_exc_divide_error),INTG (X86_TRAP_NMI , nmi),INTG (X86_TRAP_BR , asm_exc_bounds), -INTG (X86_TRAP_UD , invalid_op), +INTG (X86_TRAP_UD , asm_exc_invalid_op),INTG (X86_TRAP_NM , device_not_available),INTG (X86_TRAP_OLD_MF , coprocessor_segment_overrun), INTG(X86_TRAP_TS, invalid_TSS),
arch/x86/kernel/traps.c +15 -1
@@ -221,6 +221,21 @@ DEFINE_IDTENTRY(exc_overflow)do_error_trap (regs,0 ,"overflow" ,X86_TRAP_OF ,SIGSEGV ,0 ,NULL ); } +#ifdef CONFIG_X86_F00F_BUG +void handle_invalid_op(struct pt_regs *regs) +#else +static inline void handle_invalid_op(struct pt_regs *regs) +#endif +{ +do_error_trap (regs,0 ,"invalid opcode" ,X86_TRAP_UD ,SIGILL , +ILL_ILLOPN ,error_get_trap_addr (regs)); +} + +DEFINE_IDTENTRY (exc_invalid_op) +{ +handle_invalid_op (regs); +} +#define IP ((void __user *)uprobe_get_trap_addr(regs))#define DO_ERROR (trapnr, signr, sicode, addr, str, name) \ dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \
@@ -228,7 +243,6 @@ dotraplinkage void do_##name(struct pt_rdo_error_trap (regs, error_code, str, trapnr, signr, sicode, addr); \ } -DO_ERROR(X86_TRAP_UD, SIGILL, ILL_ILLOPN, IP, "invalid opcode", invalid_op) DO_ERROR(X86_TRAP_OLD_MF, SIGFPE, 0, NULL, "coprocessor segment overrun", coprocessor_segment_overrun) DO_ERROR(X86_TRAP_TS, SIGSEGV, 0, NULL, "invalid TSS", invalid_TSS)DO_ERROR (X86_TRAP_NP ,SIGBUS ,0 ,NULL ,"segment not present" , segment_not_present)
arch/x86/mm/fault.c +1 -1
@@ -567,7 +567,7 @@ static int is_f00f_bug(struct pt_regs *r nr = (address - idt_descr.address) >>3 ;if (nr ==6 ) { -do_invalid_op (regs,0 ); +handle_invalid_op (regs);return 1 ; } }
arch/x86/xen/enlighten_pv.c +1 -1
@@ -625,7 +625,7 @@ static struct trap_array_entry trap_arra { page_fault, xen_page_fault, false },TRAP_ENTRY (exc_divide_error, false ),TRAP_ENTRY (exc_bounds, false ), - { invalid_op, xen_invalid_op, false }, +TRAP_ENTRY (exc_invalid_op, false ), { device_not_available, xen_device_not_available, false }, { coprocessor_segment_overrun, xen_coprocessor_segment_overrun, false }, { invalid_TSS, xen_invalid_TSS, false },
arch/x86/xen/xen-asm_64.S +1 -1
@@ -35,7 +35,7 @@ xen_pv_trap int3 xen_pv_trap xennmi xen_pv_trap asm_exc_overflow xen_pv_trap asm_exc_bounds -xen_pv_trap invalid_op +xen_pv_trap asm_exc_invalid_op xen_pv_trap device_not_available xen_pv_trap double_fault xen_pv_trap coprocessor_segment_overrun
Re: [patch V4 part 3 17/29] x86/entry: Convert Invalid Opcode exception to IDTENTRY
Quoted 12 lines · Thomas Gleixner
From: Thomas Gleixner <[email protected]>
Convert #UD to IDTENTRY:
- Implement the C entry point withDEFINE_IDTENTRY
- Emit the ASM stub withDECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Fixup the FOOF bug call infault.c
- Remove the old prototyoes
Quoted 1 line
No functional change.
I think there *is* a functional change:
arch/x86/mm/fault.c static int is_f00f_bug(struct pt_regs *r · line 570
Quoted 8 lines
arch/x86/mm/fault.c +1
-1@@ -567,7 +567,7 @@ static int is_f00f_bug(struct pt_regs *r nr = (address - idt_descr.address) >>3 ;if (nr ==6 ) { -do_invalid_op (regs,0 ); +handle_invalid_op (regs);
I suspect the old code was wrong and no one noticed because no one has a F00F-buggy machine any more.
So maybe document that you fixed up the F00F bug, too. Otherwise:
Re: [patch V4 part 3 17/29] x86/entry: Convert Invalid Opcode exception to IDTENTRY
Quoted 23 lines · Andy Lutomirski
Quoted 12 lines · Thomas Gleixner
From: Thomas Gleixner <[email protected]>
Convert #UD to IDTENTRY:
- Implement the C entry point withDEFINE_IDTENTRY
- Emit the ASM stub withDECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Fixup the FOOF bug call infault.c
- Remove the old prototyoesQuoted 1 line
No functional change.
I think there *is* a functional change:
Quoted 5 lines
arch/x86/mm/fault.c +0
-0@@ -567,7 +567,7 @@ static int is_f00f_bug(struct pt_regs *r nr = (address - idt_descr.address) >>3 ;
Quoted 6 lines
arch/x86/mm/fault.c static int is_f00f_bug(struct pt_regs *r · line 570
Quoted 3 lines
arch/x86/mm/fault.c +1
-1if (nr ==6 ) { -do_invalid_op (regs,0 ); +handle_invalid_op (regs);I suspect the old code was wrong and no one noticed because no one has a F00F-buggy machine any more.
I don't think so. It's really just the same thing. The old #UD C function was:
void do_invalid_op(struct pt_regs *regs, long error_code)
{
do_error_trap(regs, error_code, "invalid opcode", X86_TRAP_UD,
SIGILL, ILL_ILLOPN, (void __user *)uprobe_get_trap_addr(regs));
}after expanding the DO_ERROR() muck.
The new one does:
void handle_invalid_op(struct pt_regs *regs)
{
do_error_trap(regs, 0, "invalid opcode", X86_TRAP_UD, SIGILL,
ILL_ILLOPN, error_get_trap_addr(regs));
}which is exactly the same except for the error code being hardcoded to zero in handle_invalid_op() because #UD does not have one.
Quoted 1 line
So maybe document that you fixed up the F00F bug, too. Otherwise:
Not sure what to document :)
Thanks,
tglx
Re: [patch V4 part 3 17/29] x86/entry: Convert Invalid Opcode exception to IDTENTRY
Quoted 55 lines · Thomas Gleixner
Quoted 23 lines · Andy Lutomirski
Quoted 13 lines · Thomas Gleixner
From: Thomas Gleixner <[email protected]>
Convert #UD to IDTENTRY:
- Implement the C entry point withDEFINE_IDTENTRY
- Emit the ASM stub withDECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Fixup the FOOF bug call infault.c
- Remove the old prototyoesQuoted 1 line
No functional change.
I think there *is* a functional change:
Quoted 5 lines
arch/x86/mm/fault.c +0
-0@@ -567,7 +567,7 @@ static int is_f00f_bug(struct pt_regs *r nr = (address - idt_descr.address) >>3 ;Quoted 6 lines
arch/x86/mm/fault.c static int is_f00f_bug(struct pt_regs *r · line 570
Quoted 3 lines
arch/x86/mm/fault.c +1
-1if (nr ==6 ) { -do_invalid_op (regs,0 ); +handle_invalid_op (regs);I suspect the old code was wrong and no one noticed because no one has a F00F-buggy machine any more.
I don't think so. It's really just the same thing. The old #UD C function was:
void
do_invalid_op(struct pt_regs *regs, long error_code){
do_error_trap(regs,error_code, "invalid opcode",X86_TRAP_UD,SIGILL, ILL_ILLOPN, (void __user *)uprobe_get_trap_addr(regs)); }after expanding the
DO_ERROR()muck.The new one does:
void
handle_invalid_op(struct pt_regs *regs)
{
do_error_trap(regs, 0, "invalid opcode",X86_TRAP_UD, SIGILL,ILL_ILLOPN, error_get_trap_addr(regs)); }
Quoted 6 lines
which is exactly the same except for the error code being hardcoded to zero in
handle_invalid_op()because #UD does not have one.Quoted 1 line
So maybe document that you fixed up the F00F bug, too. Otherwise:
Not sure what to document :)
Duh, right, never mind. Here I was thinking the old C handlers did all the entry/exit work.
Quoted 4 lines
Thanks,
tglx
[tip: x86/entry] x86/entry: Convert Invalid Opcode exception to IDTENTRY
In reply to Thomas GleixnerThe following commit has been merged into the x86/entry branch of tip:
The following commit has been merged into the x86/entry branch of tip:
Commit-ID: a99471a459d4c89ff013363b06c6cb56fe4d7286 Gitweb: https://git.kernel.org/tip/a99471a459d4c89ff013363b06c6cb56fe4d7286 Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 25 Feb 2020 23:16:18 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 19 May 2020 16:03:59 +02:00
x86/entry: Convert Invalid Opcode exception to IDTENTRY
Convert #UD to IDTENTRY:
- Implement the C entry point with DEFINE_IDTENTRY
- Emit the ASM stub with DECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Fixup the FOOF bug call in fault.c
- Remove the old prototypes
No functional change.
--- arch/x86/entry/entry_32.S | 7 ------- arch/x86/entry/entry_64.S | 1 - arch/x86/include/asm/idtentry.h | 1 + arch/x86/include/asm/traps.h | 8 +++++--- arch/x86/kernel/idt.c | 2 +- arch/x86/kernel/traps.c | 16 +++++++++++++++- arch/x86/mm/fault.c | 2 +- arch/x86/xen/enlighten_pv.c | 2 +- arch/x86/xen/xen-asm_64.S | 2 +- 9 files changed, 25 insertions(+), 16 deletions(-)
arch/x86/entry/entry_32.S +0 -7
@@ -1325,13 +1325,6 @@ SYM_CODE_START(native_iret) SYM_CODE_END(native_iret) #endif -SYM_CODE_START(invalid_op) - ASM_CLAC - pushl $0 - pushl $do_invalid_op - jmp common_exception -SYM_CODE_END(invalid_op) - SYM_CODE_START(coprocessor_segment_overrun) ASM_CLAC pushl $0
arch/x86/entry/entry_64.S +0 -1
@@ -1073,7 +1073,6 @@ apicinterrupt IRQ_WORK_VECTOR irq_work_interrupt smp_irq_work_interrupt */ idtentry X86_TRAP_BP int3 do_int3 has_error_code=0 -idtentry X86_TRAP_UD invalid_op do_invalid_op has_error_code=0 idtentry X86_TRAP_NM device_not_available do_device_not_available has_error_code=0 idtentry X86_TRAP_OLD_MF coprocessor_segment_overrun do_coprocessor_segment_overrun has_error_code=0 idtentry X86_TRAP_TS invalid_TSS do_invalid_TSS has_error_code=1
arch/x86/include/asm/idtentry.h +1 -0
@@ -80,5 +80,6 @@ static __always_inline void __##func(struct pt_regs *regs)DECLARE_IDTENTRY (X86_TRAP_DE , exc_divide_error);DECLARE_IDTENTRY (X86_TRAP_OF , exc_overflow);DECLARE_IDTENTRY (X86_TRAP_BR , exc_bounds); +DECLARE_IDTENTRY (X86_TRAP_UD , exc_invalid_op);#endif
arch/x86/include/asm/traps.h +5 -3
@@ -14,7 +14,6 @@ asmlinkage void debug(void); asmlinkage void nmi(void); asmlinkage void int3(void); -asmlinkage void invalid_op(void); asmlinkage void device_not_available(void);#ifdef CONFIG_X86_64 asmlinkage void double_fault(void);
@@ -38,7 +37,6 @@ asmlinkage void simd_coprocessor_error(void); asmlinkage void xen_xennmi(void); asmlinkage void xen_xendebug(void); asmlinkage void xen_int3(void); -asmlinkage void xen_invalid_op(void); asmlinkage void xen_device_not_available(void); asmlinkage void xen_double_fault(void); asmlinkage void xen_coprocessor_segment_overrun(void);
@@ -59,7 +57,6 @@ asmlinkage void xen_simd_coprocessor_error(void); dotraplinkage void do_debug(struct pt_regs *regs, long error_code); dotraplinkage void do_nmi(struct pt_regs *regs, long error_code); dotraplinkage void do_int3(struct pt_regs *regs, long error_code); -dotraplinkage void do_invalid_op(struct pt_regs *regs, long error_code); dotraplinkage void do_device_not_available(struct pt_regs *regs, long error_code); dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code, unsigned long cr2); dotraplinkage void do_coprocessor_segment_overrun(struct pt_regs *regs, long error_code);
@@ -84,6 +81,11 @@ struct bad_iret_stack *fixup_bad_iret(struct bad_iret_stack *s);void __init trap_init (void );#endif +#ifdef CONFIG_X86_F00F_BUG +/* For handling the FOOF bug */ +void handle_invalid_op (struct pt_regs *regs); +#endif +static inline int get_si_code (unsigned long condition) {if (condition &DR_STEP )
arch/x86/kernel/idt.c +1 -1
@@ -76,7 +76,7 @@ static const __initconst struct idt_data def_idts[] = {INTG (X86_TRAP_DE , asm_exc_divide_error),INTG (X86_TRAP_NMI , nmi),INTG (X86_TRAP_BR , asm_exc_bounds), -INTG (X86_TRAP_UD , invalid_op), +INTG (X86_TRAP_UD , asm_exc_invalid_op),INTG (X86_TRAP_NM , device_not_available),INTG (X86_TRAP_OLD_MF , coprocessor_segment_overrun), INTG(X86_TRAP_TS, invalid_TSS),
arch/x86/kernel/traps.c +15 -1
@@ -231,6 +231,21 @@ DEFINE_IDTENTRY(exc_overflow)do_error_trap (regs,0 ,"overflow" ,X86_TRAP_OF ,SIGSEGV ,0 ,NULL ); } +#ifdef CONFIG_X86_F00F_BUG +void handle_invalid_op(struct pt_regs *regs) +#else +static inline void handle_invalid_op(struct pt_regs *regs) +#endif +{ +do_error_trap (regs,0 ,"invalid opcode" ,X86_TRAP_UD ,SIGILL , +ILL_ILLOPN ,error_get_trap_addr (regs)); +} + +DEFINE_IDTENTRY (exc_invalid_op) +{ +handle_invalid_op (regs); +} +#define IP ((void __user *)uprobe_get_trap_addr(regs))#define DO_ERROR (trapnr, signr, sicode, addr, str, name) \ dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \
@@ -238,7 +253,6 @@ dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \do_error_trap (regs, error_code, str, trapnr, signr, sicode, addr); \ } -DO_ERROR(X86_TRAP_UD, SIGILL, ILL_ILLOPN, IP, "invalid opcode", invalid_op) DO_ERROR(X86_TRAP_OLD_MF, SIGFPE, 0, NULL, "coprocessor segment overrun", coprocessor_segment_overrun) DO_ERROR(X86_TRAP_TS, SIGSEGV, 0, NULL, "invalid TSS", invalid_TSS)DO_ERROR (X86_TRAP_NP ,SIGBUS ,0 ,NULL ,"segment not present" , segment_not_present)
arch/x86/mm/fault.c +1 -1
@@ -567,7 +567,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address) nr = (address - idt_descr.address) >>3 ;if (nr ==6 ) { -do_invalid_op (regs,0 ); +handle_invalid_op (regs);return 1 ; } }
arch/x86/xen/enlighten_pv.c +1 -1
@@ -625,7 +625,7 @@ static struct trap_array_entry trap_array[] = { { page_fault, xen_page_fault, false },TRAP_ENTRY (exc_divide_error, false ),TRAP_ENTRY (exc_bounds, false ), - { invalid_op, xen_invalid_op, false }, +TRAP_ENTRY (exc_invalid_op, false ), { device_not_available, xen_device_not_available, false }, { coprocessor_segment_overrun, xen_coprocessor_segment_overrun, false }, { invalid_TSS, xen_invalid_TSS, false },
arch/x86/xen/xen-asm_64.S +1 -1
@@ -35,7 +35,7 @@ xen_pv_trap int3 xen_pv_trap xennmi xen_pv_trap asm_exc_overflow xen_pv_trap asm_exc_bounds -xen_pv_trap invalid_op +xen_pv_trap asm_exc_invalid_op xen_pv_trap device_not_available xen_pv_trap double_fault xen_pv_trap coprocessor_segment_overrun
PATCH v4 18/29 x86/entry: Convert Device not available exception to IDTENTRY
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
Convert #NM to IDTENTRY:
- Implement the C entry point with DEFINE_IDTENTRY
- Emit the ASM stub with DECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototyoes
- Remove the RCU warning as the new entry macro ensures correctness
No functional change.
--- arch/x86/entry/entry_32.S | 7 ------- arch/x86/entry/entry_64.S | 1 - arch/x86/include/asm/idtentry.h | 1 + arch/x86/include/asm/traps.h | 3 --- arch/x86/kernel/idt.c | 2 +- arch/x86/kernel/traps.c | 8 ++------ arch/x86/xen/enlighten_pv.c | 2 +- arch/x86/xen/xen-asm_64.S | 2 +- 8 files changed, 6 insertions(+), 20 deletions(-)
arch/x86/entry/entry_32.S +0 -7
@@ -1311,13 +1311,6 @@ SYM_CODE_START(simd_coprocessor_error) jmp common_exception SYM_CODE_END(simd_coprocessor_error) -SYM_CODE_START(device_not_available) - ASM_CLAC - pushl $0 - pushl $do_device_not_available - jmp common_exception -SYM_CODE_END(device_not_available) - #ifdef CONFIG_PARAVIRT SYM_CODE_START(native_iret) iret
arch/x86/entry/entry_64.S +0 -1
@@ -1074,7 +1074,6 @@ apicinterrupt IRQ_WORK_VECTOR irq_work */ idtentry X86_TRAP_BP int3 do_int3 has_error_code=0 -idtentry X86_TRAP_NM device_not_available do_device_not_available has_error_code=0 idtentry X86_TRAP_OLD_MF coprocessor_segment_overrun do_coprocessor_segment_overrun has_error_code=0 idtentry X86_TRAP_TS invalid_TSS do_invalid_TSS has_error_code=1 idtentry X86_TRAP_NP segment_not_present do_segment_not_present has_error_code=1
arch/x86/include/asm/idtentry.h +1 -0
@@ -81,5 +81,6 @@ DECLARE_IDTENTRY(X86_TRAP_DE, exc_dividDECLARE_IDTENTRY (X86_TRAP_OF , exc_overflow);DECLARE_IDTENTRY (X86_TRAP_BR , exc_bounds);DECLARE_IDTENTRY (X86_TRAP_UD , exc_invalid_op); +DECLARE_IDTENTRY (X86_TRAP_NM , exc_device_not_available);#endif
arch/x86/include/asm/traps.h +0 -3
@@ -14,7 +14,6 @@ asmlinkage void debug(void); asmlinkage void nmi(void); asmlinkage void int3(void); -asmlinkage void device_not_available(void);#ifdef CONFIG_X86_64 asmlinkage void double_fault(void);#endif
@@ -37,7 +36,6 @@ asmlinkage void simd_coprocessor_error(v asmlinkage void xen_xennmi(void); asmlinkage void xen_xendebug(void); asmlinkage void xen_int3(void); -asmlinkage void xen_device_not_available(void); asmlinkage void xen_double_fault(void); asmlinkage void xen_coprocessor_segment_overrun(void); asmlinkage void xen_invalid_TSS(void);
@@ -57,7 +55,6 @@ asmlinkage void xen_simd_coprocessor_err dotraplinkage void do_debug(struct pt_regs *regs, long error_code); dotraplinkage void do_nmi(struct pt_regs *regs, long error_code); dotraplinkage void do_int3(struct pt_regs *regs, long error_code); -dotraplinkage void do_device_not_available(struct pt_regs *regs, long error_code);#if defined(CONFIG_X86_64 ) || defined(CONFIG_DOUBLEFAULT ) dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code, unsigned long cr2);#endif
arch/x86/kernel/idt.c +1 -1
@@ -74,7 +74,7 @@ static const __initconst struct idt_dataINTG (X86_TRAP_NMI , nmi),INTG (X86_TRAP_BR , asm_exc_bounds),INTG (X86_TRAP_UD , asm_exc_invalid_op), -INTG (X86_TRAP_NM , device_not_available), +INTG (X86_TRAP_NM , asm_exc_device_not_available),INTG (X86_TRAP_OLD_MF , coprocessor_segment_overrun),INTG (X86_TRAP_TS , invalid_TSS), INTG(X86_TRAP_NP, segment_not_present),
arch/x86/kernel/traps.c +2 -6
@@ -874,13 +874,10 @@ do_spurious_interrupt_bug(struct pt_regs*/ } -dotraplinkage void -do_device_not_available (struct pt_regs *regs,long error_code) +DEFINE_IDTENTRY (exc_device_not_available) {unsigned long cr0 =read_cr0 (); -RCU_LOCKDEP_WARN (!rcu_is_watching (),"entry code didn't wake RCU" ); -#ifdef CONFIG_MATH_EMULATION if (!boot_cpu_has (X86_FEATURE_FPU ) && (cr0 &X86_CR0_EM )) {struct math_emu_info info = { };
@@ -905,10 +902,9 @@ do_device_not_available(struct pt_regs ** to kill the task than getting stuck in a never-ending * loop of #NM faults. */ -die ("unexpected #NM exception" , regs, error_code); +die ("unexpected #NM exception" , regs,0 ); } } -NOKPROBE_SYMBOL (do_device_not_available);#ifdef CONFIG_X86_32 dotraplinkage void do_iret_error(struct pt_regs *regs, long error_code)
arch/x86/xen/enlighten_pv.c +1 -1
@@ -626,7 +626,7 @@ static struct trap_array_entry trap_arraTRAP_ENTRY (exc_divide_error, false ),TRAP_ENTRY (exc_bounds, false ),TRAP_ENTRY (exc_invalid_op, false ), - { device_not_available, xen_device_not_available, false }, +TRAP_ENTRY (exc_device_not_available, false ), { coprocessor_segment_overrun, xen_coprocessor_segment_overrun, false }, { invalid_TSS, xen_invalid_TSS, false }, { segment_not_present, xen_segment_not_present, false },
arch/x86/xen/xen-asm_64.S +1 -1
@@ -36,7 +36,7 @@ xen_pv_trap xennmi xen_pv_trap asm_exc_overflow xen_pv_trap asm_exc_bounds xen_pv_trap asm_exc_invalid_op -xen_pv_trap device_not_available +xen_pv_trap asm_exc_device_not_available xen_pv_trap double_fault xen_pv_trap coprocessor_segment_overrun xen_pv_trap invalid_TSS
Re: [patch V4 part 3 18/29] x86/entry: Convert Device not available exception to IDTENTRY
Quoted 12 lines · Thomas Gleixner
From: Thomas Gleixner <[email protected]>
Convert #NM to IDTENTRY:
- Implement the C entry point withDEFINE_IDTENTRY
- Emit the ASM stub withDECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototyoes
- Remove the RCU warning as the new entry macro ensures correctness
Quoted 1 line
No functional change.
[tip: x86/entry] x86/entry: Convert Device not available exception to IDTENTRY
In reply to Thomas GleixnerThe following commit has been merged into the x86/entry branch of tip:
The following commit has been merged into the x86/entry branch of tip:
Commit-ID: 02974050e002189d08d76a7e1d0aa1af74957f01 Gitweb: https://git.kernel.org/tip/02974050e002189d08d76a7e1d0aa1af74957f01 Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 25 Feb 2020 23:16:19 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 19 May 2020 16:03:59 +02:00
x86/entry: Convert Device not available exception to IDTENTRY
Convert #NM to IDTENTRY:
- Implement the C entry point with DEFINE_IDTENTRY
- Emit the ASM stub with DECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototypes
- Remove the RCU warning as the new entry macro ensures correctness
No functional change.
--- arch/x86/entry/entry_32.S | 7 ------- arch/x86/entry/entry_64.S | 1 - arch/x86/include/asm/idtentry.h | 1 + arch/x86/include/asm/traps.h | 3 --- arch/x86/kernel/idt.c | 2 +- arch/x86/kernel/traps.c | 8 ++------ arch/x86/xen/enlighten_pv.c | 2 +- arch/x86/xen/xen-asm_64.S | 2 +- 8 files changed, 6 insertions(+), 20 deletions(-)
arch/x86/entry/entry_32.S +0 -7
@@ -1311,13 +1311,6 @@ SYM_CODE_START(simd_coprocessor_error) jmp common_exception SYM_CODE_END(simd_coprocessor_error) -SYM_CODE_START(device_not_available) - ASM_CLAC - pushl $0 - pushl $do_device_not_available - jmp common_exception -SYM_CODE_END(device_not_available) - #ifdef CONFIG_PARAVIRT SYM_CODE_START(native_iret) iret
arch/x86/entry/entry_64.S +0 -1
@@ -1073,7 +1073,6 @@ apicinterrupt IRQ_WORK_VECTOR irq_work_interrupt smp_irq_work_interrupt */ idtentry X86_TRAP_BP int3 do_int3 has_error_code=0 -idtentry X86_TRAP_NM device_not_available do_device_not_available has_error_code=0 idtentry X86_TRAP_OLD_MF coprocessor_segment_overrun do_coprocessor_segment_overrun has_error_code=0 idtentry X86_TRAP_TS invalid_TSS do_invalid_TSS has_error_code=1 idtentry X86_TRAP_NP segment_not_present do_segment_not_present has_error_code=1
arch/x86/include/asm/idtentry.h +1 -0
@@ -81,5 +81,6 @@ DECLARE_IDTENTRY(X86_TRAP_DE, exc_divide_error);DECLARE_IDTENTRY (X86_TRAP_OF , exc_overflow);DECLARE_IDTENTRY (X86_TRAP_BR , exc_bounds);DECLARE_IDTENTRY (X86_TRAP_UD , exc_invalid_op); +DECLARE_IDTENTRY (X86_TRAP_NM , exc_device_not_available);#endif
arch/x86/include/asm/traps.h +0 -3
@@ -14,7 +14,6 @@ asmlinkage void debug(void); asmlinkage void nmi(void); asmlinkage void int3(void); -asmlinkage void device_not_available(void);#ifdef CONFIG_X86_64 asmlinkage void double_fault(void);#endif
@@ -37,7 +36,6 @@ asmlinkage void simd_coprocessor_error(void); asmlinkage void xen_xennmi(void); asmlinkage void xen_xendebug(void); asmlinkage void xen_int3(void); -asmlinkage void xen_device_not_available(void); asmlinkage void xen_double_fault(void); asmlinkage void xen_coprocessor_segment_overrun(void); asmlinkage void xen_invalid_TSS(void);
@@ -57,7 +55,6 @@ asmlinkage void xen_simd_coprocessor_error(void); dotraplinkage void do_debug(struct pt_regs *regs, long error_code); dotraplinkage void do_nmi(struct pt_regs *regs, long error_code); dotraplinkage void do_int3(struct pt_regs *regs, long error_code); -dotraplinkage void do_device_not_available(struct pt_regs *regs, long error_code); dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code, unsigned long cr2); dotraplinkage void do_coprocessor_segment_overrun(struct pt_regs *regs, long error_code); dotraplinkage void do_invalid_TSS(struct pt_regs *regs, long error_code);
arch/x86/kernel/idt.c +1 -1
@@ -77,7 +77,7 @@ static const __initconst struct idt_data def_idts[] = {INTG (X86_TRAP_NMI , nmi),INTG (X86_TRAP_BR , asm_exc_bounds),INTG (X86_TRAP_UD , asm_exc_invalid_op), -INTG (X86_TRAP_NM , device_not_available), +INTG (X86_TRAP_NM , asm_exc_device_not_available),INTG (X86_TRAP_OLD_MF , coprocessor_segment_overrun),INTG (X86_TRAP_TS , invalid_TSS), INTG(X86_TRAP_NP, segment_not_present),
arch/x86/kernel/traps.c +2 -6
@@ -882,13 +882,10 @@ do_spurious_interrupt_bug(struct pt_regs *regs, long error_code)*/ } -dotraplinkage void -do_device_not_available (struct pt_regs *regs,long error_code) +DEFINE_IDTENTRY (exc_device_not_available) {unsigned long cr0 =read_cr0 (); -RCU_LOCKDEP_WARN (!rcu_is_watching (),"entry code didn't wake RCU" ); -#ifdef CONFIG_MATH_EMULATION if (!boot_cpu_has (X86_FEATURE_FPU ) && (cr0 &X86_CR0_EM )) {struct math_emu_info info = { };
@@ -913,10 +910,9 @@ do_device_not_available(struct pt_regs *regs, long error_code)* to kill the task than getting stuck in a never-ending * loop of #NM faults. */ -die ("unexpected #NM exception" , regs, error_code); +die ("unexpected #NM exception" , regs,0 ); } } -NOKPROBE_SYMBOL (do_device_not_available);#ifdef CONFIG_X86_32 dotraplinkage void do_iret_error(struct pt_regs *regs, long error_code)
arch/x86/xen/enlighten_pv.c +1 -1
@@ -626,7 +626,7 @@ static struct trap_array_entry trap_array[] = {TRAP_ENTRY (exc_divide_error, false ),TRAP_ENTRY (exc_bounds, false ),TRAP_ENTRY (exc_invalid_op, false ), - { device_not_available, xen_device_not_available, false }, +TRAP_ENTRY (exc_device_not_available, false ), { coprocessor_segment_overrun, xen_coprocessor_segment_overrun, false }, { invalid_TSS, xen_invalid_TSS, false }, { segment_not_present, xen_segment_not_present, false },
arch/x86/xen/xen-asm_64.S +1 -1
@@ -36,7 +36,7 @@ xen_pv_trap xennmi xen_pv_trap asm_exc_overflow xen_pv_trap asm_exc_bounds xen_pv_trap asm_exc_invalid_op -xen_pv_trap device_not_available +xen_pv_trap asm_exc_device_not_available xen_pv_trap double_fault xen_pv_trap coprocessor_segment_overrun xen_pv_trap invalid_TSS
PATCH v4 19/29 x86/entry: Convert Coprocessor segment overrun exception to IDTENTRY
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
Convert #OLD_MF to IDTENTRY:
- Implement the C entry point with DEFINE_IDTENTRY
- Emit the ASM stub with DECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototyoes
No functional change.
--- arch/x86/entry/entry_32.S | 7 ------- arch/x86/entry/entry_64.S | 1 - arch/x86/include/asm/idtentry.h | 1 + arch/x86/include/asm/traps.h | 3 --- arch/x86/kernel/idt.c | 2 +- arch/x86/kernel/traps.c | 7 ++++++- arch/x86/xen/enlighten_pv.c | 2 +- arch/x86/xen/xen-asm_64.S | 2 +- 8 files changed, 10 insertions(+), 15 deletions(-)
arch/x86/entry/entry_32.S +0 -7
@@ -1318,13 +1318,6 @@ SYM_CODE_START(native_iret) SYM_CODE_END(native_iret) #endif -SYM_CODE_START(coprocessor_segment_overrun) - ASM_CLAC - pushl $0 - pushl $do_coprocessor_segment_overrun - jmp common_exception -SYM_CODE_END(coprocessor_segment_overrun) - SYM_CODE_START(invalid_TSS) ASM_CLAC pushl $do_invalid_TSS
arch/x86/entry/entry_64.S +0 -1
@@ -1074,7 +1074,6 @@ apicinterrupt IRQ_WORK_VECTOR irq_work */ idtentry X86_TRAP_BP int3 do_int3 has_error_code=0 -idtentry X86_TRAP_OLD_MF coprocessor_segment_overrun do_coprocessor_segment_overrun has_error_code=0 idtentry X86_TRAP_TS invalid_TSS do_invalid_TSS has_error_code=1 idtentry X86_TRAP_NP segment_not_present do_segment_not_present has_error_code=1 idtentry X86_TRAP_SS stack_segment do_stack_segment has_error_code=1
arch/x86/include/asm/idtentry.h +1 -0
@@ -82,5 +82,6 @@ DECLARE_IDTENTRY(X86_TRAP_OF, exc_overfDECLARE_IDTENTRY (X86_TRAP_BR , exc_bounds);DECLARE_IDTENTRY (X86_TRAP_UD , exc_invalid_op);DECLARE_IDTENTRY (X86_TRAP_NM , exc_device_not_available); +DECLARE_IDTENTRY (X86_TRAP_OLD_MF , exc_coproc_segment_overrun);#endif
arch/x86/include/asm/traps.h +0 -3
@@ -17,7 +17,6 @@ asmlinkage void int3(void);#ifdef CONFIG_X86_64 asmlinkage void double_fault(void);#endif -asmlinkage void coprocessor_segment_overrun(void); asmlinkage void invalid_TSS(void); asmlinkage void segment_not_present(void); asmlinkage void stack_segment(void);
@@ -37,7 +36,6 @@ asmlinkage void xen_xennmi(void); asmlinkage void xen_xendebug(void); asmlinkage void xen_int3(void); asmlinkage void xen_double_fault(void); -asmlinkage void xen_coprocessor_segment_overrun(void); asmlinkage void xen_invalid_TSS(void); asmlinkage void xen_segment_not_present(void); asmlinkage void xen_stack_segment(void);
@@ -58,7 +56,6 @@ dotraplinkage void do_int3(struct pt_reg#if defined(CONFIG_X86_64 ) || defined(CONFIG_DOUBLEFAULT ) dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code, unsigned long cr2);#endif -dotraplinkage void do_coprocessor_segment_overrun(struct pt_regs *regs, long error_code); dotraplinkage void do_invalid_TSS(struct pt_regs *regs, long error_code); dotraplinkage void do_segment_not_present(struct pt_regs *regs, long error_code); dotraplinkage void do_stack_segment(struct pt_regs *regs, long error_code);
arch/x86/kernel/idt.c +1 -1
@@ -75,7 +75,7 @@ static const __initconst struct idt_dataINTG (X86_TRAP_BR , asm_exc_bounds),INTG (X86_TRAP_UD , asm_exc_invalid_op),INTG (X86_TRAP_NM , asm_exc_device_not_available), -INTG (X86_TRAP_OLD_MF , coprocessor_segment_overrun), +INTG (X86_TRAP_OLD_MF , asm_exc_coproc_segment_overrun),INTG (X86_TRAP_TS , invalid_TSS),INTG (X86_TRAP_NP , segment_not_present), INTG(X86_TRAP_SS, stack_segment),
arch/x86/kernel/traps.c +6 -1
@@ -236,6 +236,12 @@ DEFINE_IDTENTRY(exc_invalid_op)handle_invalid_op (regs); } +DEFINE_IDTENTRY (exc_coproc_segment_overrun) +{ +do_error_trap (regs,0 ,"coprocessor segment overrun" , +X86_TRAP_OLD_MF ,SIGFPE ,0 ,NULL ); +} +#define IP ((void __user *)uprobe_get_trap_addr(regs))#define DO_ERROR (trapnr, signr, sicode, addr, str, name) \ dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \
@@ -243,7 +249,6 @@ dotraplinkage void do_##name(struct pt_rdo_error_trap (regs, error_code, str, trapnr, signr, sicode, addr); \ } -DO_ERROR(X86_TRAP_OLD_MF, SIGFPE, 0, NULL, "coprocessor segment overrun", coprocessor_segment_overrun) DO_ERROR(X86_TRAP_TS, SIGSEGV, 0, NULL, "invalid TSS", invalid_TSS) DO_ERROR(X86_TRAP_NP, SIGBUS, 0, NULL, "segment not present", segment_not_present)DO_ERROR (X86_TRAP_SS ,SIGBUS ,0 ,NULL ,"stack segment" , stack_segment)
arch/x86/xen/enlighten_pv.c +1 -1
@@ -627,7 +627,7 @@ static struct trap_array_entry trap_arraTRAP_ENTRY (exc_bounds, false ),TRAP_ENTRY (exc_invalid_op, false ),TRAP_ENTRY (exc_device_not_available, false ), - { coprocessor_segment_overrun, xen_coprocessor_segment_overrun, false }, +TRAP_ENTRY (exc_coproc_segment_overrun, false ), { invalid_TSS, xen_invalid_TSS, false }, { segment_not_present, xen_segment_not_present, false }, { stack_segment, xen_stack_segment, false },
arch/x86/xen/xen-asm_64.S +1 -1
@@ -38,7 +38,7 @@ xen_pv_trap asm_exc_bounds xen_pv_trap asm_exc_invalid_op xen_pv_trap asm_exc_device_not_available xen_pv_trap double_fault -xen_pv_trap coprocessor_segment_overrun +xen_pv_trap asm_exc_coproc_segment_overrun xen_pv_trap invalid_TSS xen_pv_trap segment_not_present xen_pv_trap stack_segment
Re: [patch V4 part 3 19/29] x86/entry: Convert Coprocessor segment overrun exception to IDTENTRY
Quoted 11 lines · Thomas Gleixner
From: Thomas Gleixner <[email protected]>
Convert #OLD_MF to IDTENTRY:
- Implement the C entry point withDEFINE_IDTENTRY
- Emit the ASM stub withDECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototyoes
Quoted 1 line
No functional change.
PATCH v4 20/29 x86/entry: Provide IDTENTRY_ERRORCODE
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
Same as IDTENTRY but the C entry point has an error code argument.
--- arch/x86/include/asm/idtentry.h | 46 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
arch/x86/include/asm/idtentry.h +46 -0
@@ -57,6 +57,49 @@ static __always_inline void __##func(str \ static __always_inline void __##func(struct pt_regs *regs) +/** +* DECLARE_IDTENTRY_ERRORCODE - Declare functions for simple IDT entry points +* Error code pushed by hardware +* @vector: Vector number (ignored for C) +* @func: Function name of the entry point +* +* Declares three functions: +* - The ASM entry point: asm_##func +* - The XEN PV trap entry point: xen_##func (maybe unused) +* - The C handler called from the ASM entry point +* +* Same as DECLARE_IDTENTRY, but has an extra error_code argument for the +* C-handler. +*/ +#define DECLARE_IDTENTRY_ERRORCODE (vector, func) \ + asmlinkage void asm_##func(void); \ + asmlinkage void xen_asm_##func(void); \ + __visible void func(struct pt_regs *regs, unsigned long error_code) + +/** +* DEFINE_IDTENTRY_ERRORCODE - Emit code for simple IDT entry points +* Error code pushed by hardware +* @func: Function name of the entry point +* +* Same as DEFINE_IDTENTRY, but has an extra error_code argument +*/ +#define DEFINE_IDTENTRY_ERRORCODE (func) \ +static __always_inline void __##func(struct pt_regs *regs, \ + unsigned long error_code); \ + \ +__visible noinstr void func(struct pt_regs *regs, \ + unsigned long error_code) \ +{ \ + idtentry_enter(regs); \ + instr_begin(); \ + __##func (regs, error_code); \ + instr_end(); \ + idtentry_exit(regs); \ +} \ + \ +static __always_inline void __##func(struct pt_regs *regs, \ + unsigned long error_code) +#else /* !__ASSEMBLY__ */ /*
@@ -65,6 +108,9 @@ static __always_inline void __##func(str#define DECLARE_IDTENTRY (vector, func) \ idtentry vector asm_##func func has_error_code=0 sane=1 +#define DECLARE_IDTENTRY_ERRORCODE (vector, func) \ + idtentry vector asm_##func func has_error_code=1 sane=1 +#endif /* __ASSEMBLY__ */ /*
Re: [patch V4 part 3 20/29] x86/entry: Provide IDTENTRY_ERRORCODE
Quoted 5 lines · Thomas Gleixner
From: Thomas Gleixner <[email protected]>
Same as IDTENTRY but the C entry point has an error code argument.
[tip: x86/entry] x86/idtentry: Provide IDTENTRY_ERRORCODE
In reply to Thomas GleixnerThe following commit has been merged into the x86/entry branch of tip:
The following commit has been merged into the x86/entry branch of tip:
Commit-ID: c7fd4ec398dc3e23414da137637bf1182bfe0585 Gitweb: https://git.kernel.org/tip/c7fd4ec398dc3e23414da137637bf1182bfe0585 Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 25 Feb 2020 23:16:21 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 19 May 2020 16:04:00 +02:00
x86/idtentry: Provide IDTENTRY_ERRORCODE
Same as IDTENTRY but the C entry point has an error code argument.
--- arch/x86/include/asm/idtentry.h | 46 ++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+)
arch/x86/include/asm/idtentry.h +46 -0
@@ -57,6 +57,49 @@ __visible noinstr void func(struct pt_regs *regs) \ \ static __always_inline void __##func(struct pt_regs *regs) +/** +* DECLARE_IDTENTRY_ERRORCODE - Declare functions for simple IDT entry points +* Error code pushed by hardware +* @vector: Vector number (ignored for C) +* @func: Function name of the entry point +* +* Declares three functions: +* - The ASM entry point: asm_##func +* - The XEN PV trap entry point: xen_##func (maybe unused) +* - The C handler called from the ASM entry point +* +* Same as DECLARE_IDTENTRY, but has an extra error_code argument for the +* C-handler. +*/ +#define DECLARE_IDTENTRY_ERRORCODE (vector, func) \ + asmlinkage void asm_##func(void); \ + asmlinkage void xen_asm_##func(void); \ + __visible void func(struct pt_regs *regs, unsigned long error_code) + +/** +* DEFINE_IDTENTRY_ERRORCODE - Emit code for simple IDT entry points +* Error code pushed by hardware +* @func: Function name of the entry point +* +* Same as DEFINE_IDTENTRY, but has an extra error_code argument +*/ +#define DEFINE_IDTENTRY_ERRORCODE (func) \ +static __always_inline void __##func(struct pt_regs *regs, \ + unsigned long error_code); \ + \ +__visible noinstr void func(struct pt_regs *regs, \ + unsigned long error_code) \ +{ \ + idtentry_enter(regs); \ + instrumentation_begin(); \ + __##func (regs, error_code); \ + instrumentation_end(); \ + idtentry_exit(regs); \ +} \ + \ +static __always_inline void __##func(struct pt_regs *regs, \ + unsigned long error_code) +#else /* !__ASSEMBLY__ */ /*
@@ -65,6 +108,9 @@ static __always_inline void __##func(struct pt_regs *regs)#define DECLARE_IDTENTRY (vector, func) \ idtentry vector asm_##func func has_error_code=0 sane=1 +#define DECLARE_IDTENTRY_ERRORCODE (vector, func) \ + idtentry vector asm_##func func has_error_code=1 sane=1 +#endif /* __ASSEMBLY__ */ /*
PATCH v4 21/29 x86/entry: Convert Invalid TSS exception to IDTENTRY
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
Convert #TS to IDTENTRY_ERRORCODE:
- Implement the C entry point with DEFINE_IDTENTRY
- Emit the ASM stub with DECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototyoes
No functional change.
--- arch/x86/entry/entry_32.S | 6 ------ arch/x86/entry/entry_64.S | 1 - arch/x86/include/asm/idtentry.h | 3 +++ arch/x86/include/asm/traps.h | 3 --- arch/x86/kernel/idt.c | 2 +- arch/x86/kernel/traps.c | 7 ++++++- arch/x86/xen/enlighten_pv.c | 2 +- arch/x86/xen/xen-asm_64.S | 2 +- 8 files changed, 12 insertions(+), 14 deletions(-)
arch/x86/entry/entry_32.S +0 -6
@@ -1318,12 +1318,6 @@ SYM_CODE_START(native_iret) SYM_CODE_END(native_iret) #endif -SYM_CODE_START(invalid_TSS) - ASM_CLAC - pushl $do_invalid_TSS - jmp common_exception -SYM_CODE_END(invalid_TSS) - SYM_CODE_START(segment_not_present) ASM_CLAC pushl $do_segment_not_present
arch/x86/entry/entry_64.S +0 -1
@@ -1074,7 +1074,6 @@ apicinterrupt IRQ_WORK_VECTOR irq_work */ idtentry X86_TRAP_BP int3 do_int3 has_error_code=0 -idtentry X86_TRAP_TS invalid_TSS do_invalid_TSS has_error_code=1 idtentry X86_TRAP_NP segment_not_present do_segment_not_present has_error_code=1 idtentry X86_TRAP_SS stack_segment do_stack_segment has_error_code=1 idtentry X86_TRAP_GP general_protection do_general_protection has_error_code=1
arch/x86/include/asm/idtentry.h +3 -0
@@ -130,4 +130,7 @@ DECLARE_IDTENTRY(X86_TRAP_UD, exc_invalDECLARE_IDTENTRY (X86_TRAP_NM , exc_device_not_available);DECLARE_IDTENTRY (X86_TRAP_OLD_MF , exc_coproc_segment_overrun); +/* Simple exception entries with error code pushed by hardware */ +DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_TS , exc_invalid_tss); +#endif
arch/x86/include/asm/traps.h +0 -3
@@ -17,7 +17,6 @@ asmlinkage void int3(void);#ifdef CONFIG_X86_64 asmlinkage void double_fault(void);#endif -asmlinkage void invalid_TSS(void); asmlinkage void segment_not_present(void); asmlinkage void stack_segment(void); asmlinkage void general_protection(void);
@@ -36,7 +35,6 @@ asmlinkage void xen_xennmi(void); asmlinkage void xen_xendebug(void); asmlinkage void xen_int3(void); asmlinkage void xen_double_fault(void); -asmlinkage void xen_invalid_TSS(void); asmlinkage void xen_segment_not_present(void); asmlinkage void xen_stack_segment(void); asmlinkage void xen_general_protection(void);
@@ -56,7 +54,6 @@ dotraplinkage void do_int3(struct pt_reg#if defined(CONFIG_X86_64 ) || defined(CONFIG_DOUBLEFAULT ) dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code, unsigned long cr2);#endif -dotraplinkage void do_invalid_TSS(struct pt_regs *regs, long error_code); dotraplinkage void do_segment_not_present(struct pt_regs *regs, long error_code); dotraplinkage void do_stack_segment(struct pt_regs *regs, long error_code); dotraplinkage void do_general_protection(struct pt_regs *regs, long error_code);
arch/x86/kernel/idt.c +1 -1
@@ -76,7 +76,7 @@ static const __initconst struct idt_dataINTG (X86_TRAP_UD , asm_exc_invalid_op),INTG (X86_TRAP_NM , asm_exc_device_not_available),INTG (X86_TRAP_OLD_MF , asm_exc_coproc_segment_overrun), -INTG (X86_TRAP_TS , invalid_TSS), +INTG (X86_TRAP_TS , asm_exc_invalid_tss),INTG (X86_TRAP_NP , segment_not_present),INTG (X86_TRAP_SS , stack_segment), INTG(X86_TRAP_GP, general_protection),
arch/x86/kernel/traps.c +6 -1
@@ -242,6 +242,12 @@ DEFINE_IDTENTRY(exc_coproc_segment_overr X86_TRAP_OLD_MF, SIGFPE, 0, NULL); } +DEFINE_IDTENTRY_ERRORCODE (exc_invalid_tss) +{ +do_error_trap (regs, error_code,"invalid TSS" ,X86_TRAP_TS ,SIGSEGV , +0 ,NULL ); +} +#define IP ((void __user *)uprobe_get_trap_addr(regs))#define DO_ERROR (trapnr, signr, sicode, addr, str, name) \ dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \
@@ -249,7 +255,6 @@ dotraplinkage void do_##name(struct pt_rdo_error_trap (regs, error_code, str, trapnr, signr, sicode, addr); \ } -DO_ERROR(X86_TRAP_TS, SIGSEGV, 0, NULL, "invalid TSS", invalid_TSS) DO_ERROR(X86_TRAP_NP, SIGBUS, 0, NULL, "segment not present", segment_not_present) DO_ERROR(X86_TRAP_SS, SIGBUS, 0, NULL, "stack segment", stack_segment)#undef IP
arch/x86/xen/enlighten_pv.c +1 -1
@@ -628,7 +628,7 @@ static struct trap_array_entry trap_arraTRAP_ENTRY (exc_invalid_op, false ),TRAP_ENTRY (exc_device_not_available, false ),TRAP_ENTRY (exc_coproc_segment_overrun, false ), - { invalid_TSS, xen_invalid_TSS, false }, +TRAP_ENTRY (exc_invalid_tss, false ), { segment_not_present, xen_segment_not_present, false }, { stack_segment, xen_stack_segment, false }, { general_protection, xen_general_protection, false },
arch/x86/xen/xen-asm_64.S +1 -1
@@ -39,7 +39,7 @@ xen_pv_trap asm_exc_invalid_op xen_pv_trap asm_exc_device_not_available xen_pv_trap double_fault xen_pv_trap asm_exc_coproc_segment_overrun -xen_pv_trap invalid_TSS +xen_pv_trap asm_exc_invalid_tss xen_pv_trap segment_not_present xen_pv_trap stack_segment xen_pv_trap general_protection
Re: [patch V4 part 3 21/29] x86/entry: Convert Invalid TSS exception to IDTENTRY
Quoted 11 lines · Thomas Gleixner
From: Thomas Gleixner <[email protected]>
Convert #TS to
IDTENTRY_ERRORCODE:
- Implement the C entry point withDEFINE_IDTENTRY
- Emit the ASM stub withDECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototyoes
Quoted 1 line
No functional change.
I confess that I'm a bit mystified as to why we have all the machinery in place to send a signal if #TS happens. Whatever.
[tip: x86/entry] x86/entry: Convert Invalid TSS exception to IDTENTRY
In reply to Thomas GleixnerThe following commit has been merged into the x86/entry branch of tip:
The following commit has been merged into the x86/entry branch of tip:
Commit-ID: 87a9c4feaa8a5e219462c3e54fa6b39d9ccc03db Gitweb: https://git.kernel.org/tip/87a9c4feaa8a5e219462c3e54fa6b39d9ccc03db Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 25 Feb 2020 23:16:22 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 19 May 2020 16:04:00 +02:00
x86/entry: Convert Invalid TSS exception to IDTENTRY
Convert #TS to IDTENTRY_ERRORCODE:
- Implement the C entry point with DEFINE_IDTENTRY
- Emit the ASM stub with DECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototypes
No functional change.
--- arch/x86/entry/entry_32.S | 6 ------ arch/x86/entry/entry_64.S | 1 - arch/x86/include/asm/idtentry.h | 3 +++ arch/x86/include/asm/traps.h | 3 --- arch/x86/kernel/idt.c | 2 +- arch/x86/kernel/traps.c | 7 ++++++- arch/x86/xen/enlighten_pv.c | 2 +- arch/x86/xen/xen-asm_64.S | 2 +- 8 files changed, 12 insertions(+), 14 deletions(-)
arch/x86/entry/entry_32.S +0 -6
@@ -1318,12 +1318,6 @@ SYM_CODE_START(native_iret) SYM_CODE_END(native_iret) #endif -SYM_CODE_START(invalid_TSS) - ASM_CLAC - pushl $do_invalid_TSS - jmp common_exception -SYM_CODE_END(invalid_TSS) - SYM_CODE_START(segment_not_present) ASM_CLAC pushl $do_segment_not_present
arch/x86/entry/entry_64.S +0 -1
@@ -1073,7 +1073,6 @@ apicinterrupt IRQ_WORK_VECTOR irq_work_interrupt smp_irq_work_interrupt */ idtentry X86_TRAP_BP int3 do_int3 has_error_code=0 -idtentry X86_TRAP_TS invalid_TSS do_invalid_TSS has_error_code=1 idtentry X86_TRAP_NP segment_not_present do_segment_not_present has_error_code=1 idtentry X86_TRAP_SS stack_segment do_stack_segment has_error_code=1 idtentry X86_TRAP_GP general_protection do_general_protection has_error_code=1
arch/x86/include/asm/idtentry.h +3 -0
@@ -130,4 +130,7 @@ DECLARE_IDTENTRY(X86_TRAP_UD, exc_invalid_op);DECLARE_IDTENTRY (X86_TRAP_NM , exc_device_not_available);DECLARE_IDTENTRY (X86_TRAP_OLD_MF , exc_coproc_segment_overrun); +/* Simple exception entries with error code pushed by hardware */ +DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_TS , exc_invalid_tss); +#endif
arch/x86/include/asm/traps.h +0 -3
@@ -17,7 +17,6 @@ asmlinkage void int3(void);#ifdef CONFIG_X86_64 asmlinkage void double_fault(void);#endif -asmlinkage void invalid_TSS(void); asmlinkage void segment_not_present(void); asmlinkage void stack_segment(void); asmlinkage void general_protection(void);
@@ -36,7 +35,6 @@ asmlinkage void xen_xennmi(void); asmlinkage void xen_xendebug(void); asmlinkage void xen_int3(void); asmlinkage void xen_double_fault(void); -asmlinkage void xen_invalid_TSS(void); asmlinkage void xen_segment_not_present(void); asmlinkage void xen_stack_segment(void); asmlinkage void xen_general_protection(void);
@@ -54,7 +52,6 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code); dotraplinkage void do_nmi(struct pt_regs *regs, long error_code); dotraplinkage void do_int3(struct pt_regs *regs, long error_code); dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code, unsigned long cr2); -dotraplinkage void do_invalid_TSS(struct pt_regs *regs, long error_code); dotraplinkage void do_segment_not_present(struct pt_regs *regs, long error_code); dotraplinkage void do_stack_segment(struct pt_regs *regs, long error_code); dotraplinkage void do_general_protection(struct pt_regs *regs, long error_code);
arch/x86/kernel/idt.c +1 -1
@@ -79,7 +79,7 @@ static const __initconst struct idt_data def_idts[] = {INTG (X86_TRAP_UD , asm_exc_invalid_op),INTG (X86_TRAP_NM , asm_exc_device_not_available),INTG (X86_TRAP_OLD_MF , asm_exc_coproc_segment_overrun), -INTG (X86_TRAP_TS , invalid_TSS), +INTG (X86_TRAP_TS , asm_exc_invalid_tss),INTG (X86_TRAP_NP , segment_not_present),INTG (X86_TRAP_SS , stack_segment), INTG(X86_TRAP_GP, general_protection),
arch/x86/kernel/traps.c +6 -1
@@ -252,6 +252,12 @@ DEFINE_IDTENTRY(exc_coproc_segment_overrun) X86_TRAP_OLD_MF, SIGFPE, 0, NULL); } +DEFINE_IDTENTRY_ERRORCODE (exc_invalid_tss) +{ +do_error_trap (regs, error_code,"invalid TSS" ,X86_TRAP_TS ,SIGSEGV , +0 ,NULL ); +} +#define IP ((void __user *)uprobe_get_trap_addr(regs))#define DO_ERROR (trapnr, signr, sicode, addr, str, name) \ dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \
@@ -259,7 +265,6 @@ dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \do_error_trap (regs, error_code, str, trapnr, signr, sicode, addr); \ } -DO_ERROR(X86_TRAP_TS, SIGSEGV, 0, NULL, "invalid TSS", invalid_TSS) DO_ERROR(X86_TRAP_NP, SIGBUS, 0, NULL, "segment not present", segment_not_present) DO_ERROR(X86_TRAP_SS, SIGBUS, 0, NULL, "stack segment", stack_segment)#undef IP
arch/x86/xen/enlighten_pv.c +1 -1
@@ -628,7 +628,7 @@ static struct trap_array_entry trap_array[] = {TRAP_ENTRY (exc_invalid_op, false ),TRAP_ENTRY (exc_device_not_available, false ),TRAP_ENTRY (exc_coproc_segment_overrun, false ), - { invalid_TSS, xen_invalid_TSS, false }, +TRAP_ENTRY (exc_invalid_tss, false ), { segment_not_present, xen_segment_not_present, false }, { stack_segment, xen_stack_segment, false }, { general_protection, xen_general_protection, false },
arch/x86/xen/xen-asm_64.S +1 -1
@@ -39,7 +39,7 @@ xen_pv_trap asm_exc_invalid_op xen_pv_trap asm_exc_device_not_available xen_pv_trap double_fault xen_pv_trap asm_exc_coproc_segment_overrun -xen_pv_trap invalid_TSS +xen_pv_trap asm_exc_invalid_tss xen_pv_trap segment_not_present xen_pv_trap stack_segment xen_pv_trap general_protection
PATCH v4 22/29 x86/entry: Convert Segment not present exception to IDTENTRY
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
Convert #NP to IDTENTRY_ERRORCODE:
- Implement the C entry point with DEFINE_IDTENTRY
- Emit the ASM stub with DECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototyoes
No functional change.
--- arch/x86/entry/entry_32.S | 6 ------ arch/x86/entry/entry_64.S | 1 - arch/x86/include/asm/idtentry.h | 1 + arch/x86/include/asm/traps.h | 3 --- arch/x86/kernel/idt.c | 2 +- arch/x86/kernel/traps.c | 7 ++++++- arch/x86/xen/enlighten_pv.c | 2 +- arch/x86/xen/xen-asm_64.S | 2 +- 8 files changed, 10 insertions(+), 14 deletions(-)
arch/x86/entry/entry_32.S +0 -6
@@ -1318,12 +1318,6 @@ SYM_CODE_START(native_iret) SYM_CODE_END(native_iret) #endif -SYM_CODE_START(segment_not_present) - ASM_CLAC - pushl $do_segment_not_present - jmp common_exception -SYM_CODE_END(segment_not_present) - SYM_CODE_START(stack_segment) ASM_CLAC pushl $do_stack_segment
arch/x86/entry/entry_64.S +0 -1
@@ -1074,7 +1074,6 @@ apicinterrupt IRQ_WORK_VECTOR irq_work */ idtentry X86_TRAP_BP int3 do_int3 has_error_code=0 -idtentry X86_TRAP_NP segment_not_present do_segment_not_present has_error_code=1 idtentry X86_TRAP_SS stack_segment do_stack_segment has_error_code=1 idtentry X86_TRAP_GP general_protection do_general_protection has_error_code=1 idtentry X86_TRAP_SPURIOUS spurious_interrupt_bug do_spurious_interrupt_bug has_error_code=0
arch/x86/include/asm/idtentry.h +1 -0
@@ -132,5 +132,6 @@ DECLARE_IDTENTRY(X86_TRAP_OLD_MF, exc_co/* Simple exception entries with error code pushed by hardware */ DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_TS , exc_invalid_tss); +DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_NP , exc_segment_not_present);#endif
arch/x86/include/asm/traps.h +0 -3
@@ -17,7 +17,6 @@ asmlinkage void int3(void);#ifdef CONFIG_X86_64 asmlinkage void double_fault(void);#endif -asmlinkage void segment_not_present(void); asmlinkage void stack_segment(void); asmlinkage void general_protection(void); asmlinkage void page_fault(void);
@@ -35,7 +34,6 @@ asmlinkage void xen_xennmi(void); asmlinkage void xen_xendebug(void); asmlinkage void xen_int3(void); asmlinkage void xen_double_fault(void); -asmlinkage void xen_segment_not_present(void); asmlinkage void xen_stack_segment(void); asmlinkage void xen_general_protection(void); asmlinkage void xen_page_fault(void);
@@ -54,7 +52,6 @@ dotraplinkage void do_int3(struct pt_reg#if defined(CONFIG_X86_64 ) || defined(CONFIG_DOUBLEFAULT ) dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code, unsigned long cr2);#endif -dotraplinkage void do_segment_not_present(struct pt_regs *regs, long error_code); dotraplinkage void do_stack_segment(struct pt_regs *regs, long error_code); dotraplinkage void do_general_protection(struct pt_regs *regs, long error_code); dotraplinkage void do_page_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
arch/x86/kernel/idt.c +1 -1
@@ -77,7 +77,7 @@ static const __initconst struct idt_dataINTG (X86_TRAP_NM , asm_exc_device_not_available),INTG (X86_TRAP_OLD_MF , asm_exc_coproc_segment_overrun),INTG (X86_TRAP_TS , asm_exc_invalid_tss), -INTG (X86_TRAP_NP , segment_not_present), +INTG (X86_TRAP_NP , asm_exc_segment_not_present),INTG (X86_TRAP_SS , stack_segment),INTG (X86_TRAP_GP , general_protection), INTG(X86_TRAP_SPURIOUS, spurious_interrupt_bug),
arch/x86/kernel/traps.c +6 -1
@@ -248,6 +248,12 @@ DEFINE_IDTENTRY_ERRORCODE(exc_invalid_ts 0, NULL); } +DEFINE_IDTENTRY_ERRORCODE (exc_segment_not_present) +{ +do_error_trap (regs, error_code,"segment not present" ,X86_TRAP_NP , +SIGBUS ,0 ,NULL ); +} +#define IP ((void __user *)uprobe_get_trap_addr(regs))#define DO_ERROR (trapnr, signr, sicode, addr, str, name) \ dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \
@@ -255,7 +261,6 @@ dotraplinkage void do_##name(struct pt_rdo_error_trap (regs, error_code, str, trapnr, signr, sicode, addr); \ } -DO_ERROR(X86_TRAP_NP, SIGBUS, 0, NULL, "segment not present", segment_not_present) DO_ERROR(X86_TRAP_SS, SIGBUS, 0, NULL, "stack segment", stack_segment)#undef IP
arch/x86/xen/enlighten_pv.c +1 -1
@@ -629,7 +629,7 @@ static struct trap_array_entry trap_arraTRAP_ENTRY (exc_device_not_available, false ),TRAP_ENTRY (exc_coproc_segment_overrun, false ),TRAP_ENTRY (exc_invalid_tss, false ), - { segment_not_present, xen_segment_not_present, false }, +TRAP_ENTRY (exc_segment_not_present, false ), { stack_segment, xen_stack_segment, false }, { general_protection, xen_general_protection, false }, { spurious_interrupt_bug, xen_spurious_interrupt_bug, false },
arch/x86/xen/xen-asm_64.S +1 -1
@@ -40,7 +40,7 @@ xen_pv_trap asm_exc_device_not_available xen_pv_trap double_fault xen_pv_trap asm_exc_coproc_segment_overrun xen_pv_trap asm_exc_invalid_tss -xen_pv_trap segment_not_present +xen_pv_trap asm_exc_segment_not_present xen_pv_trap stack_segment xen_pv_trap general_protection xen_pv_trap page_fault
Re: [patch V4 part 3 22/29] x86/entry: Convert Segment not present exception to IDTENTRY
Quoted 11 lines · Thomas Gleixner
From: Thomas Gleixner <[email protected]>
Convert #NP to
IDTENTRY_ERRORCODE:
- Implement the C entry point withDEFINE_IDTENTRY
- Emit the ASM stub withDECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototyoes
Quoted 1 line
No functional change.
[tip: x86/entry] x86/entry: Convert Segment not present exception to IDTENTRY
In reply to Thomas GleixnerThe following commit has been merged into the x86/entry branch of tip:
The following commit has been merged into the x86/entry branch of tip:
Commit-ID: 403ad51200262306a08c9fa0b3120f51cce95445 Gitweb: https://git.kernel.org/tip/403ad51200262306a08c9fa0b3120f51cce95445 Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 25 Feb 2020 23:16:23 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 19 May 2020 16:04:01 +02:00
x86/entry: Convert Segment not present exception to IDTENTRY
Convert #NP to IDTENTRY_ERRORCODE:
- Implement the C entry point with DEFINE_IDTENTRY
- Emit the ASM stub with DECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototypes
No functional change.
--- arch/x86/entry/entry_32.S | 6 ------ arch/x86/entry/entry_64.S | 1 - arch/x86/include/asm/idtentry.h | 1 + arch/x86/include/asm/traps.h | 3 --- arch/x86/kernel/idt.c | 2 +- arch/x86/kernel/traps.c | 7 ++++++- arch/x86/xen/enlighten_pv.c | 2 +- arch/x86/xen/xen-asm_64.S | 2 +- 8 files changed, 10 insertions(+), 14 deletions(-)
arch/x86/entry/entry_32.S +0 -6
@@ -1318,12 +1318,6 @@ SYM_CODE_START(native_iret) SYM_CODE_END(native_iret) #endif -SYM_CODE_START(segment_not_present) - ASM_CLAC - pushl $do_segment_not_present - jmp common_exception -SYM_CODE_END(segment_not_present) - SYM_CODE_START(stack_segment) ASM_CLAC pushl $do_stack_segment
arch/x86/entry/entry_64.S +0 -1
@@ -1073,7 +1073,6 @@ apicinterrupt IRQ_WORK_VECTOR irq_work_interrupt smp_irq_work_interrupt */ idtentry X86_TRAP_BP int3 do_int3 has_error_code=0 -idtentry X86_TRAP_NP segment_not_present do_segment_not_present has_error_code=1 idtentry X86_TRAP_SS stack_segment do_stack_segment has_error_code=1 idtentry X86_TRAP_GP general_protection do_general_protection has_error_code=1 idtentry X86_TRAP_SPURIOUS spurious_interrupt_bug do_spurious_interrupt_bug has_error_code=0
arch/x86/include/asm/idtentry.h +1 -0
@@ -132,5 +132,6 @@ DECLARE_IDTENTRY(X86_TRAP_OLD_MF, exc_coproc_segment_overrun);/* Simple exception entries with error code pushed by hardware */ DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_TS , exc_invalid_tss); +DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_NP , exc_segment_not_present);#endif
arch/x86/include/asm/traps.h +0 -3
@@ -17,7 +17,6 @@ asmlinkage void int3(void);#ifdef CONFIG_X86_64 asmlinkage void double_fault(void);#endif -asmlinkage void segment_not_present(void); asmlinkage void stack_segment(void); asmlinkage void general_protection(void); asmlinkage void page_fault(void);
@@ -35,7 +34,6 @@ asmlinkage void xen_xennmi(void); asmlinkage void xen_xendebug(void); asmlinkage void xen_int3(void); asmlinkage void xen_double_fault(void); -asmlinkage void xen_segment_not_present(void); asmlinkage void xen_stack_segment(void); asmlinkage void xen_general_protection(void); asmlinkage void xen_page_fault(void);
@@ -52,7 +50,6 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code); dotraplinkage void do_nmi(struct pt_regs *regs, long error_code); dotraplinkage void do_int3(struct pt_regs *regs, long error_code); dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code, unsigned long cr2); -dotraplinkage void do_segment_not_present(struct pt_regs *regs, long error_code); dotraplinkage void do_stack_segment(struct pt_regs *regs, long error_code); dotraplinkage void do_general_protection(struct pt_regs *regs, long error_code); dotraplinkage void do_page_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
arch/x86/kernel/idt.c +1 -1
@@ -80,7 +80,7 @@ static const __initconst struct idt_data def_idts[] = {INTG (X86_TRAP_NM , asm_exc_device_not_available),INTG (X86_TRAP_OLD_MF , asm_exc_coproc_segment_overrun),INTG (X86_TRAP_TS , asm_exc_invalid_tss), -INTG (X86_TRAP_NP , segment_not_present), +INTG (X86_TRAP_NP , asm_exc_segment_not_present),INTG (X86_TRAP_SS , stack_segment),INTG (X86_TRAP_GP , general_protection), INTG(X86_TRAP_SPURIOUS, spurious_interrupt_bug),
arch/x86/kernel/traps.c +6 -1
@@ -258,6 +258,12 @@ DEFINE_IDTENTRY_ERRORCODE(exc_invalid_tss) 0, NULL); } +DEFINE_IDTENTRY_ERRORCODE (exc_segment_not_present) +{ +do_error_trap (regs, error_code,"segment not present" ,X86_TRAP_NP , +SIGBUS ,0 ,NULL ); +} +#define IP ((void __user *)uprobe_get_trap_addr(regs))#define DO_ERROR (trapnr, signr, sicode, addr, str, name) \ dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \
@@ -265,7 +271,6 @@ dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \do_error_trap (regs, error_code, str, trapnr, signr, sicode, addr); \ } -DO_ERROR(X86_TRAP_NP, SIGBUS, 0, NULL, "segment not present", segment_not_present) DO_ERROR(X86_TRAP_SS, SIGBUS, 0, NULL, "stack segment", stack_segment)#undef IP
arch/x86/xen/enlighten_pv.c +1 -1
@@ -629,7 +629,7 @@ static struct trap_array_entry trap_array[] = {TRAP_ENTRY (exc_device_not_available, false ),TRAP_ENTRY (exc_coproc_segment_overrun, false ),TRAP_ENTRY (exc_invalid_tss, false ), - { segment_not_present, xen_segment_not_present, false }, +TRAP_ENTRY (exc_segment_not_present, false ), { stack_segment, xen_stack_segment, false }, { general_protection, xen_general_protection, false }, { spurious_interrupt_bug, xen_spurious_interrupt_bug, false },
arch/x86/xen/xen-asm_64.S +1 -1
@@ -40,7 +40,7 @@ xen_pv_trap asm_exc_device_not_available xen_pv_trap double_fault xen_pv_trap asm_exc_coproc_segment_overrun xen_pv_trap asm_exc_invalid_tss -xen_pv_trap segment_not_present +xen_pv_trap asm_exc_segment_not_present xen_pv_trap stack_segment xen_pv_trap general_protection xen_pv_trap page_fault
PATCH v4 23/29 x86/entry: Convert Stack segment exception to IDTENTRY
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
Convert #SS to IDTENTRY_ERRORCODE:
- Implement the C entry point with DEFINE_IDTENTRY
- Emit the ASM stub with DECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototyoes
No functional change.
--- arch/x86/entry/entry_32.S | 6 ------ arch/x86/entry/entry_64.S | 1 - arch/x86/include/asm/idtentry.h | 1 + arch/x86/include/asm/traps.h | 3 --- arch/x86/kernel/idt.c | 2 +- arch/x86/kernel/traps.c | 12 ++++-------- arch/x86/xen/enlighten_pv.c | 2 +- arch/x86/xen/xen-asm_64.S | 2 +- 8 files changed, 8 insertions(+), 21 deletions(-)
arch/x86/entry/entry_32.S +0 -6
@@ -1318,12 +1318,6 @@ SYM_CODE_START(native_iret) SYM_CODE_END(native_iret) #endif -SYM_CODE_START(stack_segment) - ASM_CLAC - pushl $do_stack_segment - jmp common_exception -SYM_CODE_END(stack_segment) - SYM_CODE_START(alignment_check) ASM_CLAC pushl $do_alignment_check
arch/x86/entry/entry_64.S +0 -1
@@ -1074,7 +1074,6 @@ apicinterrupt IRQ_WORK_VECTOR irq_work */ idtentry X86_TRAP_BP int3 do_int3 has_error_code=0 -idtentry X86_TRAP_SS stack_segment do_stack_segment has_error_code=1 idtentry X86_TRAP_GP general_protection do_general_protection has_error_code=1 idtentry X86_TRAP_SPURIOUS spurious_interrupt_bug do_spurious_interrupt_bug has_error_code=0 idtentry X86_TRAP_MF coprocessor_error do_coprocessor_error has_error_code=0
arch/x86/include/asm/idtentry.h +1 -0
@@ -133,5 +133,6 @@ DECLARE_IDTENTRY(X86_TRAP_OLD_MF, exc_co/* Simple exception entries with error code pushed by hardware */ DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_TS , exc_invalid_tss);DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_NP , exc_segment_not_present); +DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_SS , exc_stack_segment);#endif
arch/x86/include/asm/traps.h +0 -3
@@ -17,7 +17,6 @@ asmlinkage void int3(void);#ifdef CONFIG_X86_64 asmlinkage void double_fault(void);#endif -asmlinkage void stack_segment(void); asmlinkage void general_protection(void); asmlinkage void page_fault(void); asmlinkage void async_page_fault(void);
@@ -34,7 +33,6 @@ asmlinkage void xen_xennmi(void); asmlinkage void xen_xendebug(void); asmlinkage void xen_int3(void); asmlinkage void xen_double_fault(void); -asmlinkage void xen_stack_segment(void); asmlinkage void xen_general_protection(void); asmlinkage void xen_page_fault(void); asmlinkage void xen_spurious_interrupt_bug(void);
@@ -52,7 +50,6 @@ dotraplinkage void do_int3(struct pt_reg#if defined(CONFIG_X86_64 ) || defined(CONFIG_DOUBLEFAULT ) dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code, unsigned long cr2);#endif -dotraplinkage void do_stack_segment(struct pt_regs *regs, long error_code); dotraplinkage void do_general_protection(struct pt_regs *regs, long error_code); dotraplinkage void do_page_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address); dotraplinkage void do_spurious_interrupt_bug(struct pt_regs *regs, long error_code);
arch/x86/kernel/idt.c +1 -1
@@ -78,7 +78,7 @@ static const __initconst struct idt_dataINTG (X86_TRAP_OLD_MF , asm_exc_coproc_segment_overrun),INTG (X86_TRAP_TS , asm_exc_invalid_tss),INTG (X86_TRAP_NP , asm_exc_segment_not_present), -INTG (X86_TRAP_SS , stack_segment), +INTG (X86_TRAP_SS , asm_exc_stack_segment),INTG (X86_TRAP_GP , general_protection),INTG (X86_TRAP_SPURIOUS , spurious_interrupt_bug), INTG(X86_TRAP_MF, coprocessor_error),
arch/x86/kernel/traps.c +4 -8
@@ -254,16 +254,12 @@ DEFINE_IDTENTRY_ERRORCODE(exc_segment_no SIGBUS, 0, NULL); } -#define IP ((void __user *)uprobe_get_trap_addr(regs)) -#define DO_ERROR (trapnr, signr, sicode, addr, str, name) \ -dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \ -{ \ - do_error_trap(regs, error_code, str, trapnr, signr, sicode, addr); \ +DEFINE_IDTENTRY_ERRORCODE (exc_stack_segment) +{ +do_error_trap (regs, error_code,"stack segment" ,X86_TRAP_SS ,SIGBUS , +0 ,NULL ); } -DO_ERROR(X86_TRAP_SS, SIGBUS, 0, NULL, "stack segment", stack_segment) -#undef IP - dotraplinkage void do_alignment_check(struct pt_regs *regs, long error_code) {char *str ="alignment check" ;
arch/x86/xen/enlighten_pv.c +1 -1
@@ -630,7 +630,7 @@ static struct trap_array_entry trap_arraTRAP_ENTRY (exc_coproc_segment_overrun, false ),TRAP_ENTRY (exc_invalid_tss, false ),TRAP_ENTRY (exc_segment_not_present, false ), - { stack_segment, xen_stack_segment, false }, +TRAP_ENTRY (exc_stack_segment, false ), { general_protection, xen_general_protection, false }, { spurious_interrupt_bug, xen_spurious_interrupt_bug, false }, { coprocessor_error, xen_coprocessor_error, false },
arch/x86/xen/xen-asm_64.S +1 -1
@@ -41,7 +41,7 @@ xen_pv_trap double_fault xen_pv_trap asm_exc_coproc_segment_overrun xen_pv_trap asm_exc_invalid_tss xen_pv_trap asm_exc_segment_not_present -xen_pv_trap stack_segment +xen_pv_trap asm_exc_stack_segment xen_pv_trap general_protection xen_pv_trap page_fault xen_pv_trap spurious_interrupt_bug
Re: [patch V4 part 3 23/29] x86/entry: Convert Stack segment exception to IDTENTRY
Quoted 11 lines · Thomas Gleixner
From: Thomas Gleixner <[email protected]>
Convert #SS to
IDTENTRY_ERRORCODE:
- Implement the C entry point withDEFINE_IDTENTRY
- Emit the ASM stub withDECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototyoes
Quoted 1 line
No functional change.
[tip: x86/entry] x86/entry: Convert Stack segment exception to IDTENTRY
In reply to Thomas GleixnerThe following commit has been merged into the x86/entry branch of tip:
The following commit has been merged into the x86/entry branch of tip:
Commit-ID: 24e4d217ea653837567c4763fa465d28d1422e63 Gitweb: https://git.kernel.org/tip/24e4d217ea653837567c4763fa465d28d1422e63 Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 25 Feb 2020 23:16:24 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 19 May 2020 16:04:01 +02:00
x86/entry: Convert Stack segment exception to IDTENTRY
Convert #SS to IDTENTRY_ERRORCODE:
- Implement the C entry point with DEFINE_IDTENTRY
- Emit the ASM stub with DECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototypes
No functional change.
--- arch/x86/entry/entry_32.S | 6 ------ arch/x86/entry/entry_64.S | 1 - arch/x86/include/asm/idtentry.h | 1 + arch/x86/include/asm/traps.h | 3 --- arch/x86/kernel/idt.c | 2 +- arch/x86/kernel/traps.c | 12 ++++-------- arch/x86/xen/enlighten_pv.c | 2 +- arch/x86/xen/xen-asm_64.S | 2 +- 8 files changed, 8 insertions(+), 21 deletions(-)
arch/x86/entry/entry_32.S +0 -6
@@ -1318,12 +1318,6 @@ SYM_CODE_START(native_iret) SYM_CODE_END(native_iret) #endif -SYM_CODE_START(stack_segment) - ASM_CLAC - pushl $do_stack_segment - jmp common_exception -SYM_CODE_END(stack_segment) - SYM_CODE_START(alignment_check) ASM_CLAC pushl $do_alignment_check
arch/x86/entry/entry_64.S +0 -1
@@ -1073,7 +1073,6 @@ apicinterrupt IRQ_WORK_VECTOR irq_work_interrupt smp_irq_work_interrupt */ idtentry X86_TRAP_BP int3 do_int3 has_error_code=0 -idtentry X86_TRAP_SS stack_segment do_stack_segment has_error_code=1 idtentry X86_TRAP_GP general_protection do_general_protection has_error_code=1 idtentry X86_TRAP_SPURIOUS spurious_interrupt_bug do_spurious_interrupt_bug has_error_code=0 idtentry X86_TRAP_MF coprocessor_error do_coprocessor_error has_error_code=0
arch/x86/include/asm/idtentry.h +1 -0
@@ -133,5 +133,6 @@ DECLARE_IDTENTRY(X86_TRAP_OLD_MF, exc_coproc_segment_overrun);/* Simple exception entries with error code pushed by hardware */ DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_TS , exc_invalid_tss);DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_NP , exc_segment_not_present); +DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_SS , exc_stack_segment);#endif
arch/x86/include/asm/traps.h +0 -3
@@ -17,7 +17,6 @@ asmlinkage void int3(void);#ifdef CONFIG_X86_64 asmlinkage void double_fault(void);#endif -asmlinkage void stack_segment(void); asmlinkage void general_protection(void); asmlinkage void page_fault(void); asmlinkage void async_page_fault(void);
@@ -34,7 +33,6 @@ asmlinkage void xen_xennmi(void); asmlinkage void xen_xendebug(void); asmlinkage void xen_int3(void); asmlinkage void xen_double_fault(void); -asmlinkage void xen_stack_segment(void); asmlinkage void xen_general_protection(void); asmlinkage void xen_page_fault(void); asmlinkage void xen_spurious_interrupt_bug(void);
@@ -50,7 +48,6 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code); dotraplinkage void do_nmi(struct pt_regs *regs, long error_code); dotraplinkage void do_int3(struct pt_regs *regs, long error_code); dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code, unsigned long cr2); -dotraplinkage void do_stack_segment(struct pt_regs *regs, long error_code); dotraplinkage void do_general_protection(struct pt_regs *regs, long error_code); dotraplinkage void do_page_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address); dotraplinkage void do_spurious_interrupt_bug(struct pt_regs *regs, long error_code);
arch/x86/kernel/idt.c +1 -1
@@ -81,7 +81,7 @@ static const __initconst struct idt_data def_idts[] = {INTG (X86_TRAP_OLD_MF , asm_exc_coproc_segment_overrun),INTG (X86_TRAP_TS , asm_exc_invalid_tss),INTG (X86_TRAP_NP , asm_exc_segment_not_present), -INTG (X86_TRAP_SS , stack_segment), +INTG (X86_TRAP_SS , asm_exc_stack_segment),INTG (X86_TRAP_GP , general_protection),INTG (X86_TRAP_SPURIOUS , spurious_interrupt_bug), INTG(X86_TRAP_MF, coprocessor_error),
arch/x86/kernel/traps.c +4 -8
@@ -264,16 +264,12 @@ DEFINE_IDTENTRY_ERRORCODE(exc_segment_not_present) SIGBUS, 0, NULL); } -#define IP ((void __user *)uprobe_get_trap_addr(regs)) -#define DO_ERROR (trapnr, signr, sicode, addr, str, name) \ -dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \ -{ \ - do_error_trap(regs, error_code, str, trapnr, signr, sicode, addr); \ +DEFINE_IDTENTRY_ERRORCODE (exc_stack_segment) +{ +do_error_trap (regs, error_code,"stack segment" ,X86_TRAP_SS ,SIGBUS , +0 ,NULL ); } -DO_ERROR(X86_TRAP_SS, SIGBUS, 0, NULL, "stack segment", stack_segment) -#undef IP - dotraplinkage void do_alignment_check(struct pt_regs *regs, long error_code) {char *str ="alignment check" ;
arch/x86/xen/enlighten_pv.c +1 -1
@@ -630,7 +630,7 @@ static struct trap_array_entry trap_array[] = {TRAP_ENTRY (exc_coproc_segment_overrun, false ),TRAP_ENTRY (exc_invalid_tss, false ),TRAP_ENTRY (exc_segment_not_present, false ), - { stack_segment, xen_stack_segment, false }, +TRAP_ENTRY (exc_stack_segment, false ), { general_protection, xen_general_protection, false }, { spurious_interrupt_bug, xen_spurious_interrupt_bug, false }, { coprocessor_error, xen_coprocessor_error, false },
arch/x86/xen/xen-asm_64.S +1 -1
@@ -41,7 +41,7 @@ xen_pv_trap double_fault xen_pv_trap asm_exc_coproc_segment_overrun xen_pv_trap asm_exc_invalid_tss xen_pv_trap asm_exc_segment_not_present -xen_pv_trap stack_segment +xen_pv_trap asm_exc_stack_segment xen_pv_trap general_protection xen_pv_trap page_fault xen_pv_trap spurious_interrupt_bug
PATCH v4 24/29 x86/entry: Convert General protection exception to IDTENTRY
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
Convert #GP to IDTENTRY_ERRORCODE:
- Implement the C entry point with DEFINE_IDTENTRY
- Emit the ASM stub with DECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototyoes
- Remove the RCU warning as the new entry macro ensures correctness
No functional change.
---
V3: Fixup simd on 32bit to exc_general_protection
--- arch/x86/entry/entry_32.S | 8 +------- arch/x86/entry/entry_64.S | 3 +-- arch/x86/include/asm/idtentry.h | 1 + arch/x86/include/asm/traps.h | 3 --- arch/x86/kernel/idt.c | 2 +- arch/x86/kernel/traps.c | 8 +++----- arch/x86/xen/enlighten_pv.c | 2 +- arch/x86/xen/xen-asm_64.S | 2 +- 8 files changed, 9 insertions(+), 20 deletions(-)
arch/x86/entry/entry_32.S +1 -7
@@ -1302,7 +1302,7 @@ SYM_CODE_START(simd_coprocessor_error) pushl $0 #ifdef CONFIG_X86_INVD_BUG /* AMD 486 bug: invd from userspace calls exception 19 instead of #GP */ - ALTERNATIVE "pushl $do_general_protection", \ + ALTERNATIVE "pushl $exc_general_protection", \ "pushl $do_simd_coprocessor_error", \ X86_FEATURE_XMM #else
@@ -1692,12 +1692,6 @@ SYM_CODE_START(int3) jmp common_exception SYM_CODE_END(int3) -SYM_CODE_START(general_protection) - ASM_CLAC - pushl $do_general_protection - jmp common_exception -SYM_CODE_END(general_protection) - .pushsection .text, "ax" SYM_CODE_START(rewind_stack_do_exit) /* Prevent any naive code from trying to unwind to our caller. */
arch/x86/entry/entry_64.S +1 -2
@@ -1074,7 +1074,6 @@ apicinterrupt IRQ_WORK_VECTOR irq_work */ idtentry X86_TRAP_BP int3 do_int3 has_error_code=0 -idtentry X86_TRAP_GP general_protection do_general_protection has_error_code=1 idtentry X86_TRAP_SPURIOUS spurious_interrupt_bug do_spurious_interrupt_bug has_error_code=0 idtentry X86_TRAP_MF coprocessor_error do_coprocessor_error has_error_code=0 idtentry X86_TRAP_AC alignment_check do_alignment_check has_error_code=1
@@ -1210,7 +1209,7 @@ SYM_CODE_START(xen_failsafe_callback) addq $0x30, %rsp pushq $0 /* RIP */ UNWIND_HINT_IRET_REGS offset=8 - jmp general_protection + jmp asm_exc_general_protection 1: /* Segment mismatch => Category 1 (Bad segment). Retry the IRET. */ movq (%rsp), %rcx movq 8(%rsp), %r11
arch/x86/include/asm/idtentry.h +1 -0
@@ -134,5 +134,6 @@ DECLARE_IDTENTRY(X86_TRAP_OLD_MF, exc_coDECLARE_IDTENTRY_ERRORCODE (X86_TRAP_TS , exc_invalid_tss);DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_NP , exc_segment_not_present);DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_SS , exc_stack_segment); +DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_GP , exc_general_protection);#endif
arch/x86/include/asm/traps.h +0 -3
@@ -17,7 +17,6 @@ asmlinkage void int3(void);#ifdef CONFIG_X86_64 asmlinkage void double_fault(void);#endif -asmlinkage void general_protection(void); asmlinkage void page_fault(void); asmlinkage void async_page_fault(void); asmlinkage void spurious_interrupt_bug(void);
@@ -33,7 +32,6 @@ asmlinkage void xen_xennmi(void); asmlinkage void xen_xendebug(void); asmlinkage void xen_int3(void); asmlinkage void xen_double_fault(void); -asmlinkage void xen_general_protection(void); asmlinkage void xen_page_fault(void); asmlinkage void xen_spurious_interrupt_bug(void); asmlinkage void xen_coprocessor_error(void);
@@ -50,7 +48,6 @@ dotraplinkage void do_int3(struct pt_reg#if defined(CONFIG_X86_64 ) || defined(CONFIG_DOUBLEFAULT ) dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code, unsigned long cr2);#endif -dotraplinkage void do_general_protection(struct pt_regs *regs, long error_code); dotraplinkage void do_page_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address); dotraplinkage void do_spurious_interrupt_bug(struct pt_regs *regs, long error_code); dotraplinkage void do_coprocessor_error(struct pt_regs *regs, long error_code);
arch/x86/kernel/idt.c +1 -1
@@ -79,7 +79,7 @@ static const __initconst struct idt_dataINTG (X86_TRAP_TS , asm_exc_invalid_tss),INTG (X86_TRAP_NP , asm_exc_segment_not_present),INTG (X86_TRAP_SS , asm_exc_stack_segment), -INTG (X86_TRAP_GP , general_protection), +INTG (X86_TRAP_GP , asm_exc_general_protection),INTG (X86_TRAP_SPURIOUS , spurious_interrupt_bug),INTG (X86_TRAP_MF , coprocessor_error), INTG(X86_TRAP_AC, alignment_check),
arch/x86/kernel/traps.c +3 -5
@@ -145,7 +145,7 @@ do_trap_no_signal(struct task_struct *ts* process no chance to handle the signal and notice the * kernel fault information, so that won't result in polluting * the information about previously queued, but not yet -* delivered, faults. See also do_general_protection below. +* delivered, faults. See also exc_general_protection below. */ tsk->thread.error_code = error_code; tsk->thread.trap_nr = trapnr;
@@ -366,7 +366,7 @@ dotraplinkage void do_double_fault(struc* which is what the stub expects, given that the faulting * RIP will be the IRET instruction. */ - regs->ip = (unsigned long )general_protection; + regs->ip = (unsigned long )asm_exc_general_protection; regs->sp = (unsigned long )&gpregs->orig_ax;return ;
@@ -486,7 +486,7 @@ static enum kernel_gp_hint get_kernel_gp#define GPFSTR "general protection fault" -dotraplinkage void do_general_protection(struct pt_regs *regs, long error_code) +DEFINE_IDTENTRY_ERRORCODE (exc_general_protection) {char desc[sizeof (GPFSTR ) +50 +2 *sizeof (unsigned long ) +1 ] =GPFSTR ;enum kernel_gp_hint hint =GP_NO_HINT ;
@@ -494,7 +494,6 @@ dotraplinkage void do_general_protectionunsigned long gp_addr;int ret; -RCU_LOCKDEP_WARN (!rcu_is_watching (),"entry code didn't wake RCU" );cond_local_irq_enable (regs);if (static_cpu_has (X86_FEATURE_UMIP )) {
@@ -562,7 +561,6 @@ dotraplinkage void do_general_protection exit:cond_local_irq_disable (regs); } -NOKPROBE_SYMBOL (do_general_protection); dotraplinkage void notrace do_int3(struct pt_regs *regs, long error_code) {
arch/x86/xen/enlighten_pv.c +1 -1
@@ -631,7 +631,7 @@ static struct trap_array_entry trap_arraTRAP_ENTRY (exc_invalid_tss, false ),TRAP_ENTRY (exc_segment_not_present, false ),TRAP_ENTRY (exc_stack_segment, false ), - { general_protection, xen_general_protection, false }, +TRAP_ENTRY (exc_general_protection, false ), { spurious_interrupt_bug, xen_spurious_interrupt_bug, false }, { coprocessor_error, xen_coprocessor_error, false }, { alignment_check, xen_alignment_check, false },
arch/x86/xen/xen-asm_64.S +1 -1
@@ -42,7 +42,7 @@ xen_pv_trap asm_exc_coproc_segment_overr xen_pv_trap asm_exc_invalid_tss xen_pv_trap asm_exc_segment_not_present xen_pv_trap asm_exc_stack_segment -xen_pv_trap general_protection +xen_pv_trap asm_exc_general_protection xen_pv_trap page_fault xen_pv_trap spurious_interrupt_bug xen_pv_trap coprocessor_error
Re: [patch V4 part 3 24/29] x86/entry: Convert General protection exception to IDTENTRY
Quoted 12 lines · Thomas Gleixner
From: Thomas Gleixner <[email protected]>
Convert #GP to
IDTENTRY_ERRORCODE:
- Implement the C entry point withDEFINE_IDTENTRY
- Emit the ASM stub withDECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototyoes
- Remove the RCU warning as the new entry macro ensures correctness
Quoted 1 line
No functional change.
[tip: x86/entry] x86/entry: Convert General protection exception to IDTENTRY
In reply to Thomas GleixnerThe following commit has been merged into the x86/entry branch of tip:
The following commit has been merged into the x86/entry branch of tip:
Commit-ID: d4271b8fccc0ebe87abe9a393ebfec972f5f6cb0 Gitweb: https://git.kernel.org/tip/d4271b8fccc0ebe87abe9a393ebfec972f5f6cb0 Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 25 Feb 2020 23:16:25 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 19 May 2020 16:04:02 +02:00
x86/entry: Convert General protection exception to IDTENTRY
Convert #GP to IDTENTRY_ERRORCODE:
- Implement the C entry point with DEFINE_IDTENTRY
- Emit the ASM stub with DECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototypes
- Remove the RCU warning as the new entry macro ensures correctness
No functional change.
--- arch/x86/entry/entry_32.S | 8 +------- arch/x86/entry/entry_64.S | 3 +-- arch/x86/include/asm/idtentry.h | 1 + arch/x86/include/asm/traps.h | 3 --- arch/x86/kernel/idt.c | 2 +- arch/x86/kernel/traps.c | 8 +++----- arch/x86/xen/enlighten_pv.c | 2 +- arch/x86/xen/xen-asm_64.S | 2 +- 8 files changed, 9 insertions(+), 20 deletions(-)
arch/x86/entry/entry_32.S +1 -7
@@ -1302,7 +1302,7 @@ SYM_CODE_START(simd_coprocessor_error) pushl $0 #ifdef CONFIG_X86_INVD_BUG /* AMD 486 bug: invd from userspace calls exception 19 instead of #GP */ - ALTERNATIVE "pushl $do_general_protection", \ + ALTERNATIVE "pushl $exc_general_protection", \ "pushl $do_simd_coprocessor_error", \ X86_FEATURE_XMM #else
@@ -1690,12 +1690,6 @@ SYM_CODE_START(int3) jmp common_exception SYM_CODE_END(int3) -SYM_CODE_START(general_protection) - ASM_CLAC - pushl $do_general_protection - jmp common_exception -SYM_CODE_END(general_protection) - .pushsection .text, "ax" SYM_CODE_START(rewind_stack_do_exit) /* Prevent any naive code from trying to unwind to our caller. */
arch/x86/entry/entry_64.S +1 -2
@@ -1073,7 +1073,6 @@ apicinterrupt IRQ_WORK_VECTOR irq_work_interrupt smp_irq_work_interrupt */ idtentry X86_TRAP_BP int3 do_int3 has_error_code=0 -idtentry X86_TRAP_GP general_protection do_general_protection has_error_code=1 idtentry X86_TRAP_SPURIOUS spurious_interrupt_bug do_spurious_interrupt_bug has_error_code=0 idtentry X86_TRAP_MF coprocessor_error do_coprocessor_error has_error_code=0 idtentry X86_TRAP_AC alignment_check do_alignment_check has_error_code=1
@@ -1209,7 +1208,7 @@ SYM_CODE_START(xen_failsafe_callback) addq $0x30, %rsp pushq $0 /* RIP */ UNWIND_HINT_IRET_REGS offset=8 - jmp general_protection + jmp asm_exc_general_protection 1: /* Segment mismatch => Category 1 (Bad segment). Retry the IRET. */ movq (%rsp), %rcx movq 8(%rsp), %r11
arch/x86/include/asm/idtentry.h +1 -0
@@ -134,5 +134,6 @@ DECLARE_IDTENTRY(X86_TRAP_OLD_MF, exc_coproc_segment_overrun);DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_TS , exc_invalid_tss);DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_NP , exc_segment_not_present);DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_SS , exc_stack_segment); +DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_GP , exc_general_protection);#endif
arch/x86/include/asm/traps.h +0 -3
@@ -17,7 +17,6 @@ asmlinkage void int3(void);#ifdef CONFIG_X86_64 asmlinkage void double_fault(void);#endif -asmlinkage void general_protection(void); asmlinkage void page_fault(void); asmlinkage void async_page_fault(void); asmlinkage void spurious_interrupt_bug(void);
@@ -33,7 +32,6 @@ asmlinkage void xen_xennmi(void); asmlinkage void xen_xendebug(void); asmlinkage void xen_int3(void); asmlinkage void xen_double_fault(void); -asmlinkage void xen_general_protection(void); asmlinkage void xen_page_fault(void); asmlinkage void xen_spurious_interrupt_bug(void); asmlinkage void xen_coprocessor_error(void);
@@ -48,7 +46,6 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code); dotraplinkage void do_nmi(struct pt_regs *regs, long error_code); dotraplinkage void do_int3(struct pt_regs *regs, long error_code); dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code, unsigned long cr2); -dotraplinkage void do_general_protection(struct pt_regs *regs, long error_code); dotraplinkage void do_page_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address); dotraplinkage void do_spurious_interrupt_bug(struct pt_regs *regs, long error_code); dotraplinkage void do_coprocessor_error(struct pt_regs *regs, long error_code);
arch/x86/kernel/idt.c +1 -1
@@ -82,7 +82,7 @@ static const __initconst struct idt_data def_idts[] = {INTG (X86_TRAP_TS , asm_exc_invalid_tss),INTG (X86_TRAP_NP , asm_exc_segment_not_present),INTG (X86_TRAP_SS , asm_exc_stack_segment), -INTG (X86_TRAP_GP , general_protection), +INTG (X86_TRAP_GP , asm_exc_general_protection),INTG (X86_TRAP_SPURIOUS , spurious_interrupt_bug),INTG (X86_TRAP_MF , coprocessor_error), INTG(X86_TRAP_AC, alignment_check),
arch/x86/kernel/traps.c +3 -5
@@ -145,7 +145,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,* process no chance to handle the signal and notice the * kernel fault information, so that won't result in polluting * the information about previously queued, but not yet -* delivered, faults. See also do_general_protection below. +* delivered, faults. See also exc_general_protection below. */ tsk->thread.error_code = error_code; tsk->thread.trap_nr = trapnr;
@@ -375,7 +375,7 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code, unsign* which is what the stub expects, given that the faulting * RIP will be the IRET instruction. */ - regs->ip = (unsigned long )general_protection; + regs->ip = (unsigned long )asm_exc_general_protection; regs->sp = (unsigned long )&gpregs->orig_ax;return ;
@@ -494,7 +494,7 @@ static enum kernel_gp_hint get_kernel_gp_address(struct pt_regs *regs,#define GPFSTR "general protection fault" -dotraplinkage void do_general_protection(struct pt_regs *regs, long error_code) +DEFINE_IDTENTRY_ERRORCODE (exc_general_protection) {char desc[sizeof (GPFSTR ) +50 +2 *sizeof (unsigned long ) +1 ] =GPFSTR ;enum kernel_gp_hint hint =GP_NO_HINT ;
@@ -502,7 +502,6 @@ dotraplinkage void do_general_protection(struct pt_regs *regs, long error_code)unsigned long gp_addr;int ret; -RCU_LOCKDEP_WARN (!rcu_is_watching (),"entry code didn't wake RCU" );cond_local_irq_enable (regs);if (static_cpu_has (X86_FEATURE_UMIP )) {
@@ -570,7 +569,6 @@ dotraplinkage void do_general_protection(struct pt_regs *regs, long error_code) exit:cond_local_irq_disable (regs); } -NOKPROBE_SYMBOL (do_general_protection); dotraplinkage void notrace do_int3(struct pt_regs *regs, long error_code) {
arch/x86/xen/enlighten_pv.c +1 -1
@@ -631,7 +631,7 @@ static struct trap_array_entry trap_array[] = {TRAP_ENTRY (exc_invalid_tss, false ),TRAP_ENTRY (exc_segment_not_present, false ),TRAP_ENTRY (exc_stack_segment, false ), - { general_protection, xen_general_protection, false }, +TRAP_ENTRY (exc_general_protection, false ), { spurious_interrupt_bug, xen_spurious_interrupt_bug, false }, { coprocessor_error, xen_coprocessor_error, false }, { alignment_check, xen_alignment_check, false },
arch/x86/xen/xen-asm_64.S +1 -1
@@ -42,7 +42,7 @@ xen_pv_trap asm_exc_coproc_segment_overrun xen_pv_trap asm_exc_invalid_tss xen_pv_trap asm_exc_segment_not_present xen_pv_trap asm_exc_stack_segment -xen_pv_trap general_protection +xen_pv_trap asm_exc_general_protection xen_pv_trap page_fault xen_pv_trap spurious_interrupt_bug xen_pv_trap coprocessor_error
PATCH v4 25/29 x86/entry: Convert Spurious interrupt bug exception to IDTENTRY
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
Convert #SPURIOUS to IDTENTRY_ERRORCODE:
- Implement the C entry point with DEFINE_IDTENTRY
- Emit the ASM stub with DECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototyoes
No functional change.
--- arch/x86/entry/entry_32.S | 7 ------- arch/x86/entry/entry_64.S | 1 - arch/x86/include/asm/idtentry.h | 1 + arch/x86/include/asm/traps.h | 3 --- arch/x86/kernel/idt.c | 2 +- arch/x86/kernel/traps.c | 3 +-- arch/x86/xen/enlighten_pv.c | 2 +- arch/x86/xen/xen-asm_64.S | 2 +- 8 files changed, 5 insertions(+), 16 deletions(-)
arch/x86/entry/entry_32.S +0 -7
@@ -1333,13 +1333,6 @@ SYM_CODE_START(machine_check) SYM_CODE_END(machine_check) #endif -SYM_CODE_START(spurious_interrupt_bug) - ASM_CLAC - pushl $0 - pushl $do_spurious_interrupt_bug - jmp common_exception -SYM_CODE_END(spurious_interrupt_bug) - #ifdef CONFIG_XEN_PV SYM_FUNC_START(xen_hypervisor_callback) /*
arch/x86/entry/entry_64.S +0 -1
@@ -1074,7 +1074,6 @@ apicinterrupt IRQ_WORK_VECTOR irq_work */ idtentry X86_TRAP_BP int3 do_int3 has_error_code=0 -idtentry X86_TRAP_SPURIOUS spurious_interrupt_bug do_spurious_interrupt_bug has_error_code=0 idtentry X86_TRAP_MF coprocessor_error do_coprocessor_error has_error_code=0 idtentry X86_TRAP_AC alignment_check do_alignment_check has_error_code=1 idtentry X86_TRAP_XF simd_coprocessor_error do_simd_coprocessor_error has_error_code=0
arch/x86/include/asm/idtentry.h +1 -0
@@ -129,6 +129,7 @@ DECLARE_IDTENTRY(X86_TRAP_BR, exc_boundDECLARE_IDTENTRY (X86_TRAP_UD , exc_invalid_op);DECLARE_IDTENTRY (X86_TRAP_NM , exc_device_not_available);DECLARE_IDTENTRY (X86_TRAP_OLD_MF , exc_coproc_segment_overrun); +DECLARE_IDTENTRY (X86_TRAP_SPURIOUS , exc_spurious_interrupt_bug);/* Simple exception entries with error code pushed by hardware */ DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_TS , exc_invalid_tss);
arch/x86/include/asm/traps.h +0 -3
@@ -19,7 +19,6 @@ asmlinkage void double_fault(void);#endif asmlinkage void page_fault(void); asmlinkage void async_page_fault(void); -asmlinkage void spurious_interrupt_bug(void); asmlinkage void coprocessor_error(void); asmlinkage void alignment_check(void);#ifdef CONFIG_X86_MCE
@@ -33,7 +32,6 @@ asmlinkage void xen_xendebug(void); asmlinkage void xen_int3(void); asmlinkage void xen_double_fault(void); asmlinkage void xen_page_fault(void); -asmlinkage void xen_spurious_interrupt_bug(void); asmlinkage void xen_coprocessor_error(void); asmlinkage void xen_alignment_check(void);#ifdef CONFIG_X86_MCE
@@ -49,7 +47,6 @@ dotraplinkage void do_int3(struct pt_reg dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code, unsigned long cr2);#endif dotraplinkage void do_page_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address); -dotraplinkage void do_spurious_interrupt_bug(struct pt_regs *regs, long error_code); dotraplinkage void do_coprocessor_error(struct pt_regs *regs, long error_code); dotraplinkage void do_alignment_check(struct pt_regs *regs, long error_code); dotraplinkage void do_simd_coprocessor_error(struct pt_regs *regs, long error_code);
arch/x86/kernel/idt.c +1 -1
@@ -80,7 +80,7 @@ static const __initconst struct idt_dataINTG (X86_TRAP_NP , asm_exc_segment_not_present),INTG (X86_TRAP_SS , asm_exc_stack_segment),INTG (X86_TRAP_GP , asm_exc_general_protection), -INTG (X86_TRAP_SPURIOUS , spurious_interrupt_bug), +INTG (X86_TRAP_SPURIOUS , asm_exc_spurious_interrupt_bug),INTG (X86_TRAP_MF , coprocessor_error),INTG (X86_TRAP_AC , alignment_check), INTG(X86_TRAP_XF, simd_coprocessor_error),
arch/x86/kernel/traps.c +1 -2
@@ -859,8 +859,7 @@ do_simd_coprocessor_error(struct pt_regsmath_error (regs, error_code,X86_TRAP_XF ); } -dotraplinkage void -do_spurious_interrupt_bug (struct pt_regs *regs,long error_code) +DEFINE_IDTENTRY (exc_spurious_interrupt_bug) {/* * This addresses a Pentium Pro Erratum:
arch/x86/xen/enlighten_pv.c +1 -1
@@ -632,7 +632,7 @@ static struct trap_array_entry trap_arraTRAP_ENTRY (exc_segment_not_present, false ),TRAP_ENTRY (exc_stack_segment, false ),TRAP_ENTRY (exc_general_protection, false ), - { spurious_interrupt_bug, xen_spurious_interrupt_bug, false }, +TRAP_ENTRY (exc_spurious_interrupt_bug, false ), { coprocessor_error, xen_coprocessor_error, false }, { alignment_check, xen_alignment_check, false }, { simd_coprocessor_error, xen_simd_coprocessor_error, false },
arch/x86/xen/xen-asm_64.S +1 -1
@@ -44,7 +44,7 @@ xen_pv_trap asm_exc_segment_not_present xen_pv_trap asm_exc_stack_segment xen_pv_trap asm_exc_general_protection xen_pv_trap page_fault -xen_pv_trap spurious_interrupt_bug +xen_pv_trap asm_exc_spurious_interrupt_bug xen_pv_trap coprocessor_error xen_pv_trap alignment_check #ifdef CONFIG_X86_MCE
Re: [patch V4 part 3 25/29] x86/entry: Convert Spurious interrupt bug exception to IDTENTRY
Quoted 11 lines · Thomas Gleixner
From: Thomas Gleixner <[email protected]>
Convert #SPURIOUS to
IDTENTRY_ERRORCODE:
- Implement the C entry point withDEFINE_IDTENTRY
- Emit the ASM stub withDECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototyoes
Quoted 1 line
No functional change.
[tip: x86/entry] x86/entry: Convert Spurious interrupt bug exception to IDTENTRY
In reply to Thomas GleixnerThe following commit has been merged into the x86/entry branch of tip:
The following commit has been merged into the x86/entry branch of tip:
Commit-ID: 8e82613acc64890cd95e02d0367f21ac005508bb Gitweb: https://git.kernel.org/tip/8e82613acc64890cd95e02d0367f21ac005508bb Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 25 Feb 2020 23:16:26 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 19 May 2020 16:04:02 +02:00
x86/entry: Convert Spurious interrupt bug exception to IDTENTRY
Convert #SPURIOUS to IDTENTRY_ERRORCODE:
- Implement the C entry point with DEFINE_IDTENTRY
- Emit the ASM stub with DECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototypes
No functional change.
--- arch/x86/entry/entry_32.S | 7 ------- arch/x86/entry/entry_64.S | 1 - arch/x86/include/asm/idtentry.h | 1 + arch/x86/include/asm/traps.h | 3 --- arch/x86/kernel/idt.c | 2 +- arch/x86/kernel/traps.c | 3 +-- arch/x86/xen/enlighten_pv.c | 2 +- arch/x86/xen/xen-asm_64.S | 2 +- 8 files changed, 5 insertions(+), 16 deletions(-)
arch/x86/entry/entry_32.S +0 -7
@@ -1333,13 +1333,6 @@ SYM_CODE_START(machine_check) SYM_CODE_END(machine_check) #endif -SYM_CODE_START(spurious_interrupt_bug) - ASM_CLAC - pushl $0 - pushl $do_spurious_interrupt_bug - jmp common_exception -SYM_CODE_END(spurious_interrupt_bug) - #ifdef CONFIG_XEN_PV SYM_FUNC_START(xen_hypervisor_callback) /*
arch/x86/entry/entry_64.S +0 -1
@@ -1073,7 +1073,6 @@ apicinterrupt IRQ_WORK_VECTOR irq_work_interrupt smp_irq_work_interrupt */ idtentry X86_TRAP_BP int3 do_int3 has_error_code=0 -idtentry X86_TRAP_SPURIOUS spurious_interrupt_bug do_spurious_interrupt_bug has_error_code=0 idtentry X86_TRAP_MF coprocessor_error do_coprocessor_error has_error_code=0 idtentry X86_TRAP_AC alignment_check do_alignment_check has_error_code=1 idtentry X86_TRAP_XF simd_coprocessor_error do_simd_coprocessor_error has_error_code=0
arch/x86/include/asm/idtentry.h +1 -0
@@ -129,6 +129,7 @@ DECLARE_IDTENTRY(X86_TRAP_BR, exc_bounds);DECLARE_IDTENTRY (X86_TRAP_UD , exc_invalid_op);DECLARE_IDTENTRY (X86_TRAP_NM , exc_device_not_available);DECLARE_IDTENTRY (X86_TRAP_OLD_MF , exc_coproc_segment_overrun); +DECLARE_IDTENTRY (X86_TRAP_SPURIOUS , exc_spurious_interrupt_bug);/* Simple exception entries with error code pushed by hardware */ DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_TS , exc_invalid_tss);
arch/x86/include/asm/traps.h +0 -3
@@ -19,7 +19,6 @@ asmlinkage void double_fault(void);#endif asmlinkage void page_fault(void); asmlinkage void async_page_fault(void); -asmlinkage void spurious_interrupt_bug(void); asmlinkage void coprocessor_error(void); asmlinkage void alignment_check(void);#ifdef CONFIG_X86_MCE
@@ -33,7 +32,6 @@ asmlinkage void xen_xendebug(void); asmlinkage void xen_int3(void); asmlinkage void xen_double_fault(void); asmlinkage void xen_page_fault(void); -asmlinkage void xen_spurious_interrupt_bug(void); asmlinkage void xen_coprocessor_error(void); asmlinkage void xen_alignment_check(void);#ifdef CONFIG_X86_MCE
@@ -47,7 +45,6 @@ dotraplinkage void do_nmi(struct pt_regs *regs, long error_code); dotraplinkage void do_int3(struct pt_regs *regs, long error_code); dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code, unsigned long cr2); dotraplinkage void do_page_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address); -dotraplinkage void do_spurious_interrupt_bug(struct pt_regs *regs, long error_code); dotraplinkage void do_coprocessor_error(struct pt_regs *regs, long error_code); dotraplinkage void do_alignment_check(struct pt_regs *regs, long error_code); dotraplinkage void do_simd_coprocessor_error(struct pt_regs *regs, long error_code);
arch/x86/kernel/idt.c +1 -1
@@ -83,7 +83,7 @@ static const __initconst struct idt_data def_idts[] = {INTG (X86_TRAP_NP , asm_exc_segment_not_present),INTG (X86_TRAP_SS , asm_exc_stack_segment),INTG (X86_TRAP_GP , asm_exc_general_protection), -INTG (X86_TRAP_SPURIOUS , spurious_interrupt_bug), +INTG (X86_TRAP_SPURIOUS , asm_exc_spurious_interrupt_bug),INTG (X86_TRAP_MF , coprocessor_error),INTG (X86_TRAP_AC , alignment_check), INTG(X86_TRAP_XF, simd_coprocessor_error),
arch/x86/kernel/traps.c +1 -2
@@ -867,8 +867,7 @@ do_simd_coprocessor_error(struct pt_regs *regs, long error_code)math_error (regs, error_code,X86_TRAP_XF ); } -dotraplinkage void -do_spurious_interrupt_bug (struct pt_regs *regs,long error_code) +DEFINE_IDTENTRY (exc_spurious_interrupt_bug) {/* * This addresses a Pentium Pro Erratum:
arch/x86/xen/enlighten_pv.c +1 -1
@@ -632,7 +632,7 @@ static struct trap_array_entry trap_array[] = {TRAP_ENTRY (exc_segment_not_present, false ),TRAP_ENTRY (exc_stack_segment, false ),TRAP_ENTRY (exc_general_protection, false ), - { spurious_interrupt_bug, xen_spurious_interrupt_bug, false }, +TRAP_ENTRY (exc_spurious_interrupt_bug, false ), { coprocessor_error, xen_coprocessor_error, false }, { alignment_check, xen_alignment_check, false }, { simd_coprocessor_error, xen_simd_coprocessor_error, false },
arch/x86/xen/xen-asm_64.S +1 -1
@@ -44,7 +44,7 @@ xen_pv_trap asm_exc_segment_not_present xen_pv_trap asm_exc_stack_segment xen_pv_trap asm_exc_general_protection xen_pv_trap page_fault -xen_pv_trap spurious_interrupt_bug +xen_pv_trap asm_exc_spurious_interrupt_bug xen_pv_trap coprocessor_error xen_pv_trap alignment_check #ifdef CONFIG_X86_MCE
PATCH v4 26/29 x86/entry: Convert Coprocessor error exception to IDTENTRY
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
Convert #MF to IDTENTRY_ERRORCODE:
- Implement the C entry point with DEFINE_IDTENTRY
- Emit the ASM stub with DECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototyoes
- Remove the RCU warning as the new entry macro ensures correctness
No functional change.
--- arch/x86/entry/entry_32.S | 7 ------- arch/x86/entry/entry_64.S | 1 - arch/x86/include/asm/idtentry.h | 1 + arch/x86/include/asm/traps.h | 3 --- arch/x86/kernel/idt.c | 2 +- arch/x86/kernel/traps.c | 5 ++--- arch/x86/xen/enlighten_pv.c | 2 +- arch/x86/xen/xen-asm_64.S | 2 +- 8 files changed, 6 insertions(+), 17 deletions(-)
arch/x86/entry/entry_32.S +0 -7
@@ -1290,13 +1290,6 @@ SYM_FUNC_END(name) /* The include is where all of the SMP etc. interrupts come from */ #include <asm/entry_arch.h> -SYM_CODE_START(coprocessor_error) - ASM_CLAC - pushl $0 - pushl $do_coprocessor_error - jmp common_exception -SYM_CODE_END(coprocessor_error) - SYM_CODE_START(simd_coprocessor_error) ASM_CLAC pushl $0
arch/x86/entry/entry_64.S +0 -1
@@ -1074,7 +1074,6 @@ apicinterrupt IRQ_WORK_VECTOR irq_work */ idtentry X86_TRAP_BP int3 do_int3 has_error_code=0 -idtentry X86_TRAP_MF coprocessor_error do_coprocessor_error has_error_code=0 idtentry X86_TRAP_AC alignment_check do_alignment_check has_error_code=1 idtentry X86_TRAP_XF simd_coprocessor_error do_simd_coprocessor_error has_error_code=0
arch/x86/include/asm/idtentry.h +1 -0
@@ -130,6 +130,7 @@ DECLARE_IDTENTRY(X86_TRAP_UD, exc_invalDECLARE_IDTENTRY (X86_TRAP_NM , exc_device_not_available);DECLARE_IDTENTRY (X86_TRAP_OLD_MF , exc_coproc_segment_overrun);DECLARE_IDTENTRY (X86_TRAP_SPURIOUS , exc_spurious_interrupt_bug); +DECLARE_IDTENTRY (X86_TRAP_MF , exc_coprocessor_error);/* Simple exception entries with error code pushed by hardware */ DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_TS , exc_invalid_tss);
arch/x86/include/asm/traps.h +0 -3
@@ -19,7 +19,6 @@ asmlinkage void double_fault(void);#endif asmlinkage void page_fault(void); asmlinkage void async_page_fault(void); -asmlinkage void coprocessor_error(void); asmlinkage void alignment_check(void);#ifdef CONFIG_X86_MCE asmlinkage void machine_check(void);
@@ -32,7 +31,6 @@ asmlinkage void xen_xendebug(void); asmlinkage void xen_int3(void); asmlinkage void xen_double_fault(void); asmlinkage void xen_page_fault(void); -asmlinkage void xen_coprocessor_error(void); asmlinkage void xen_alignment_check(void);#ifdef CONFIG_X86_MCE asmlinkage void xen_machine_check(void);
@@ -47,7 +45,6 @@ dotraplinkage void do_int3(struct pt_reg dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code, unsigned long cr2);#endif dotraplinkage void do_page_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address); -dotraplinkage void do_coprocessor_error(struct pt_regs *regs, long error_code); dotraplinkage void do_alignment_check(struct pt_regs *regs, long error_code); dotraplinkage void do_simd_coprocessor_error(struct pt_regs *regs, long error_code);#ifdef CONFIG_X86_32
arch/x86/kernel/idt.c +1 -1
@@ -81,7 +81,7 @@ static const __initconst struct idt_dataINTG (X86_TRAP_SS , asm_exc_stack_segment),INTG (X86_TRAP_GP , asm_exc_general_protection),INTG (X86_TRAP_SPURIOUS , asm_exc_spurious_interrupt_bug), -INTG (X86_TRAP_MF , coprocessor_error), +INTG (X86_TRAP_MF , asm_exc_coprocessor_error),INTG (X86_TRAP_AC , alignment_check), INTG(X86_TRAP_XF, simd_coprocessor_error),
arch/x86/kernel/traps.c +2 -3
@@ -846,10 +846,9 @@ static void math_error(struct pt_regs *rcond_local_irq_disable (regs); } -dotraplinkage void do_coprocessor_error(struct pt_regs *regs, long error_code) +DEFINE_IDTENTRY (exc_coprocessor_error) { -RCU_LOCKDEP_WARN (!rcu_is_watching (),"entry code didn't wake RCU" ); -math_error (regs, error_code,X86_TRAP_MF ); +math_error (regs,0 ,X86_TRAP_MF ); }dotraplinkage void
arch/x86/xen/enlighten_pv.c +1 -1
@@ -633,7 +633,7 @@ static struct trap_array_entry trap_arraTRAP_ENTRY (exc_stack_segment, false ),TRAP_ENTRY (exc_general_protection, false ),TRAP_ENTRY (exc_spurious_interrupt_bug, false ), - { coprocessor_error, xen_coprocessor_error, false }, +TRAP_ENTRY (exc_coprocessor_error, false ), { alignment_check, xen_alignment_check, false }, { simd_coprocessor_error, xen_simd_coprocessor_error, false }, };
arch/x86/xen/xen-asm_64.S +1 -1
@@ -45,7 +45,7 @@ xen_pv_trap asm_exc_stack_segment xen_pv_trap asm_exc_general_protection xen_pv_trap page_fault xen_pv_trap asm_exc_spurious_interrupt_bug -xen_pv_trap coprocessor_error +xen_pv_trap asm_exc_coprocessor_error xen_pv_trap alignment_check #ifdef CONFIG_X86_MCE xen_pv_trap machine_check
Re: [patch V4 part 3 26/29] x86/entry: Convert Coprocessor error exception to IDTENTRY
Quoted 12 lines · Thomas Gleixner
From: Thomas Gleixner <[email protected]>
Convert #MF to
IDTENTRY_ERRORCODE:
- Implement the C entry point withDEFINE_IDTENTRY
- Emit the ASM stub withDECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototyoes
- Remove the RCU warning as the new entry macro ensures correctness
Quoted 1 line
No functional change.
[tip: x86/entry] x86/entry: Convert Coprocessor error exception to IDTENTRY
In reply to Thomas GleixnerThe following commit has been merged into the x86/entry branch of tip:
The following commit has been merged into the x86/entry branch of tip:
Commit-ID: bad29a8306cb330d3c566c0183f5f6c6291a23c4 Gitweb: https://git.kernel.org/tip/bad29a8306cb330d3c566c0183f5f6c6291a23c4 Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 25 Feb 2020 23:16:27 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 19 May 2020 16:04:02 +02:00
x86/entry: Convert Coprocessor error exception to IDTENTRY
Convert #MF to IDTENTRY_ERRORCODE:
- Implement the C entry point with DEFINE_IDTENTRY
- Emit the ASM stub with DECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototypes
- Remove the RCU warning as the new entry macro ensures correctness
No functional change.
--- arch/x86/entry/entry_32.S | 7 ------- arch/x86/entry/entry_64.S | 1 - arch/x86/include/asm/idtentry.h | 1 + arch/x86/include/asm/traps.h | 3 --- arch/x86/kernel/idt.c | 2 +- arch/x86/kernel/traps.c | 5 ++--- arch/x86/xen/enlighten_pv.c | 2 +- arch/x86/xen/xen-asm_64.S | 2 +- 8 files changed, 6 insertions(+), 17 deletions(-)
arch/x86/entry/entry_32.S +0 -7
@@ -1290,13 +1290,6 @@ SYM_FUNC_END(name) /* The include is where all of the SMP etc. interrupts come from */ #include <asm/entry_arch.h> -SYM_CODE_START(coprocessor_error) - ASM_CLAC - pushl $0 - pushl $do_coprocessor_error - jmp common_exception -SYM_CODE_END(coprocessor_error) - SYM_CODE_START(simd_coprocessor_error) ASM_CLAC pushl $0
arch/x86/entry/entry_64.S +0 -1
@@ -1073,7 +1073,6 @@ apicinterrupt IRQ_WORK_VECTOR irq_work_interrupt smp_irq_work_interrupt */ idtentry X86_TRAP_BP int3 do_int3 has_error_code=0 -idtentry X86_TRAP_MF coprocessor_error do_coprocessor_error has_error_code=0 idtentry X86_TRAP_AC alignment_check do_alignment_check has_error_code=1 idtentry X86_TRAP_XF simd_coprocessor_error do_simd_coprocessor_error has_error_code=0
arch/x86/include/asm/idtentry.h +1 -0
@@ -130,6 +130,7 @@ DECLARE_IDTENTRY(X86_TRAP_UD, exc_invalid_op);DECLARE_IDTENTRY (X86_TRAP_NM , exc_device_not_available);DECLARE_IDTENTRY (X86_TRAP_OLD_MF , exc_coproc_segment_overrun);DECLARE_IDTENTRY (X86_TRAP_SPURIOUS , exc_spurious_interrupt_bug); +DECLARE_IDTENTRY (X86_TRAP_MF , exc_coprocessor_error);/* Simple exception entries with error code pushed by hardware */ DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_TS , exc_invalid_tss);
arch/x86/include/asm/traps.h +0 -3
@@ -19,7 +19,6 @@ asmlinkage void double_fault(void);#endif asmlinkage void page_fault(void); asmlinkage void async_page_fault(void); -asmlinkage void coprocessor_error(void); asmlinkage void alignment_check(void);#ifdef CONFIG_X86_MCE asmlinkage void machine_check(void);
@@ -32,7 +31,6 @@ asmlinkage void xen_xendebug(void); asmlinkage void xen_int3(void); asmlinkage void xen_double_fault(void); asmlinkage void xen_page_fault(void); -asmlinkage void xen_coprocessor_error(void); asmlinkage void xen_alignment_check(void);#ifdef CONFIG_X86_MCE asmlinkage void xen_machine_check(void);
@@ -45,7 +43,6 @@ dotraplinkage void do_nmi(struct pt_regs *regs, long error_code); dotraplinkage void do_int3(struct pt_regs *regs, long error_code); dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code, unsigned long cr2); dotraplinkage void do_page_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address); -dotraplinkage void do_coprocessor_error(struct pt_regs *regs, long error_code); dotraplinkage void do_alignment_check(struct pt_regs *regs, long error_code); dotraplinkage void do_simd_coprocessor_error(struct pt_regs *regs, long error_code);#ifdef CONFIG_X86_32
arch/x86/kernel/idt.c +1 -1
@@ -84,7 +84,7 @@ static const __initconst struct idt_data def_idts[] = {INTG (X86_TRAP_SS , asm_exc_stack_segment),INTG (X86_TRAP_GP , asm_exc_general_protection),INTG (X86_TRAP_SPURIOUS , asm_exc_spurious_interrupt_bug), -INTG (X86_TRAP_MF , coprocessor_error), +INTG (X86_TRAP_MF , asm_exc_coprocessor_error),INTG (X86_TRAP_AC , alignment_check), INTG(X86_TRAP_XF, simd_coprocessor_error),
arch/x86/kernel/traps.c +2 -3
@@ -854,10 +854,9 @@ exit:cond_local_irq_disable (regs); } -dotraplinkage void do_coprocessor_error(struct pt_regs *regs, long error_code) +DEFINE_IDTENTRY (exc_coprocessor_error) { -RCU_LOCKDEP_WARN (!rcu_is_watching (),"entry code didn't wake RCU" ); -math_error (regs, error_code,X86_TRAP_MF ); +math_error (regs,0 ,X86_TRAP_MF ); }dotraplinkage void
arch/x86/xen/enlighten_pv.c +1 -1
@@ -633,7 +633,7 @@ static struct trap_array_entry trap_array[] = {TRAP_ENTRY (exc_stack_segment, false ),TRAP_ENTRY (exc_general_protection, false ),TRAP_ENTRY (exc_spurious_interrupt_bug, false ), - { coprocessor_error, xen_coprocessor_error, false }, +TRAP_ENTRY (exc_coprocessor_error, false ), { alignment_check, xen_alignment_check, false }, { simd_coprocessor_error, xen_simd_coprocessor_error, false }, };
arch/x86/xen/xen-asm_64.S +1 -1
@@ -45,7 +45,7 @@ xen_pv_trap asm_exc_stack_segment xen_pv_trap asm_exc_general_protection xen_pv_trap page_fault xen_pv_trap asm_exc_spurious_interrupt_bug -xen_pv_trap coprocessor_error +xen_pv_trap asm_exc_coprocessor_error xen_pv_trap alignment_check #ifdef CONFIG_X86_MCE xen_pv_trap machine_check
[tip: x86/entry] x86/entry: Convert Coprocessor segment overrun exception to IDTENTRY
In reply to Thomas GleixnerThe following commit has been merged into the x86/entry branch of tip:
The following commit has been merged into the x86/entry branch of tip:
Commit-ID: 2c1a8d98ef858628327b260362258549c816cf18 Gitweb: https://git.kernel.org/tip/2c1a8d98ef858628327b260362258549c816cf18 Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 25 Feb 2020 23:16:20 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 19 May 2020 16:04:00 +02:00
x86/entry: Convert Coprocessor segment overrun exception to IDTENTRY
Convert #OLD_MF to IDTENTRY:
- Implement the C entry point with DEFINE_IDTENTRY
- Emit the ASM stub with DECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototypes
No functional change.
--- arch/x86/entry/entry_32.S | 7 ------- arch/x86/entry/entry_64.S | 1 - arch/x86/include/asm/idtentry.h | 1 + arch/x86/include/asm/traps.h | 3 --- arch/x86/kernel/idt.c | 2 +- arch/x86/kernel/traps.c | 7 ++++++- arch/x86/xen/enlighten_pv.c | 2 +- arch/x86/xen/xen-asm_64.S | 2 +- 8 files changed, 10 insertions(+), 15 deletions(-)
arch/x86/entry/entry_32.S +0 -7
@@ -1318,13 +1318,6 @@ SYM_CODE_START(native_iret) SYM_CODE_END(native_iret) #endif -SYM_CODE_START(coprocessor_segment_overrun) - ASM_CLAC - pushl $0 - pushl $do_coprocessor_segment_overrun - jmp common_exception -SYM_CODE_END(coprocessor_segment_overrun) - SYM_CODE_START(invalid_TSS) ASM_CLAC pushl $do_invalid_TSS
arch/x86/entry/entry_64.S +0 -1
@@ -1073,7 +1073,6 @@ apicinterrupt IRQ_WORK_VECTOR irq_work_interrupt smp_irq_work_interrupt */ idtentry X86_TRAP_BP int3 do_int3 has_error_code=0 -idtentry X86_TRAP_OLD_MF coprocessor_segment_overrun do_coprocessor_segment_overrun has_error_code=0 idtentry X86_TRAP_TS invalid_TSS do_invalid_TSS has_error_code=1 idtentry X86_TRAP_NP segment_not_present do_segment_not_present has_error_code=1 idtentry X86_TRAP_SS stack_segment do_stack_segment has_error_code=1
arch/x86/include/asm/idtentry.h +1 -0
@@ -82,5 +82,6 @@ DECLARE_IDTENTRY(X86_TRAP_OF, exc_overflow);DECLARE_IDTENTRY (X86_TRAP_BR , exc_bounds);DECLARE_IDTENTRY (X86_TRAP_UD , exc_invalid_op);DECLARE_IDTENTRY (X86_TRAP_NM , exc_device_not_available); +DECLARE_IDTENTRY (X86_TRAP_OLD_MF , exc_coproc_segment_overrun);#endif
arch/x86/include/asm/traps.h +0 -3
@@ -17,7 +17,6 @@ asmlinkage void int3(void);#ifdef CONFIG_X86_64 asmlinkage void double_fault(void);#endif -asmlinkage void coprocessor_segment_overrun(void); asmlinkage void invalid_TSS(void); asmlinkage void segment_not_present(void); asmlinkage void stack_segment(void);
@@ -37,7 +36,6 @@ asmlinkage void xen_xennmi(void); asmlinkage void xen_xendebug(void); asmlinkage void xen_int3(void); asmlinkage void xen_double_fault(void); -asmlinkage void xen_coprocessor_segment_overrun(void); asmlinkage void xen_invalid_TSS(void); asmlinkage void xen_segment_not_present(void); asmlinkage void xen_stack_segment(void);
@@ -56,7 +54,6 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code); dotraplinkage void do_nmi(struct pt_regs *regs, long error_code); dotraplinkage void do_int3(struct pt_regs *regs, long error_code); dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code, unsigned long cr2); -dotraplinkage void do_coprocessor_segment_overrun(struct pt_regs *regs, long error_code); dotraplinkage void do_invalid_TSS(struct pt_regs *regs, long error_code); dotraplinkage void do_segment_not_present(struct pt_regs *regs, long error_code); dotraplinkage void do_stack_segment(struct pt_regs *regs, long error_code);
arch/x86/kernel/idt.c +1 -1
@@ -78,7 +78,7 @@ static const __initconst struct idt_data def_idts[] = {INTG (X86_TRAP_BR , asm_exc_bounds),INTG (X86_TRAP_UD , asm_exc_invalid_op),INTG (X86_TRAP_NM , asm_exc_device_not_available), -INTG (X86_TRAP_OLD_MF , coprocessor_segment_overrun), +INTG (X86_TRAP_OLD_MF , asm_exc_coproc_segment_overrun),INTG (X86_TRAP_TS , invalid_TSS),INTG (X86_TRAP_NP , segment_not_present), INTG(X86_TRAP_SS, stack_segment),
arch/x86/kernel/traps.c +6 -1
@@ -246,6 +246,12 @@ DEFINE_IDTENTRY(exc_invalid_op)handle_invalid_op (regs); } +DEFINE_IDTENTRY (exc_coproc_segment_overrun) +{ +do_error_trap (regs,0 ,"coprocessor segment overrun" , +X86_TRAP_OLD_MF ,SIGFPE ,0 ,NULL ); +} +#define IP ((void __user *)uprobe_get_trap_addr(regs))#define DO_ERROR (trapnr, signr, sicode, addr, str, name) \ dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \
@@ -253,7 +259,6 @@ dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \do_error_trap (regs, error_code, str, trapnr, signr, sicode, addr); \ } -DO_ERROR(X86_TRAP_OLD_MF, SIGFPE, 0, NULL, "coprocessor segment overrun", coprocessor_segment_overrun) DO_ERROR(X86_TRAP_TS, SIGSEGV, 0, NULL, "invalid TSS", invalid_TSS) DO_ERROR(X86_TRAP_NP, SIGBUS, 0, NULL, "segment not present", segment_not_present)DO_ERROR (X86_TRAP_SS ,SIGBUS ,0 ,NULL ,"stack segment" , stack_segment)
arch/x86/xen/enlighten_pv.c +1 -1
@@ -627,7 +627,7 @@ static struct trap_array_entry trap_array[] = {TRAP_ENTRY (exc_bounds, false ),TRAP_ENTRY (exc_invalid_op, false ),TRAP_ENTRY (exc_device_not_available, false ), - { coprocessor_segment_overrun, xen_coprocessor_segment_overrun, false }, +TRAP_ENTRY (exc_coproc_segment_overrun, false ), { invalid_TSS, xen_invalid_TSS, false }, { segment_not_present, xen_segment_not_present, false }, { stack_segment, xen_stack_segment, false },
arch/x86/xen/xen-asm_64.S +1 -1
@@ -38,7 +38,7 @@ xen_pv_trap asm_exc_bounds xen_pv_trap asm_exc_invalid_op xen_pv_trap asm_exc_device_not_available xen_pv_trap double_fault -xen_pv_trap coprocessor_segment_overrun +xen_pv_trap asm_exc_coproc_segment_overrun xen_pv_trap invalid_TSS xen_pv_trap segment_not_present xen_pv_trap stack_segment
PATCH v4 27/29 x86/entry: Convert Alignment check exception to IDTENTRY
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
Convert #AC to IDTENTRY_ERRORCODE:
- Implement the C entry point with DEFINE_IDTENTRY
- Emit the ASM stub with DECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototyoes
- Remove the RCU warning as the new entry macro ensures correctness
No functional change.
--- arch/x86/entry/entry_32.S | 6 ------ arch/x86/entry/entry_64.S | 1 - arch/x86/include/asm/idtentry.h | 1 + arch/x86/include/asm/traps.h | 3 --- arch/x86/kernel/idt.c | 2 +- arch/x86/kernel/traps.c | 4 +--- arch/x86/xen/enlighten_pv.c | 2 +- arch/x86/xen/xen-asm_64.S | 2 +- 8 files changed, 5 insertions(+), 16 deletions(-)
arch/x86/entry/entry_32.S +0 -6
@@ -1311,12 +1311,6 @@ SYM_CODE_START(native_iret) SYM_CODE_END(native_iret) #endif -SYM_CODE_START(alignment_check) - ASM_CLAC - pushl $do_alignment_check - jmp common_exception -SYM_CODE_END(alignment_check) - #ifdef CONFIG_X86_MCE SYM_CODE_START(machine_check) ASM_CLAC
arch/x86/entry/entry_64.S +0 -1
@@ -1074,7 +1074,6 @@ apicinterrupt IRQ_WORK_VECTOR irq_work */ idtentry X86_TRAP_BP int3 do_int3 has_error_code=0 -idtentry X86_TRAP_AC alignment_check do_alignment_check has_error_code=1 idtentry X86_TRAP_XF simd_coprocessor_error do_simd_coprocessor_error has_error_code=0 idtentry X86_TRAP_PF page_fault do_page_fault has_error_code=1
arch/x86/include/asm/idtentry.h +1 -0
@@ -137,5 +137,6 @@ DECLARE_IDTENTRY_ERRORCODE(X86_TRAP_TS,DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_NP , exc_segment_not_present);DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_SS , exc_stack_segment);DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_GP , exc_general_protection); +DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_AC , exc_alignment_check);#endif
arch/x86/include/asm/traps.h +0 -3
@@ -19,7 +19,6 @@ asmlinkage void double_fault(void);#endif asmlinkage void page_fault(void); asmlinkage void async_page_fault(void); -asmlinkage void alignment_check(void);#ifdef CONFIG_X86_MCE asmlinkage void machine_check(void);#endif /* CONFIG_X86_MCE */
@@ -31,7 +30,6 @@ asmlinkage void xen_xendebug(void); asmlinkage void xen_int3(void); asmlinkage void xen_double_fault(void); asmlinkage void xen_page_fault(void); -asmlinkage void xen_alignment_check(void);#ifdef CONFIG_X86_MCE asmlinkage void xen_machine_check(void);#endif /* CONFIG_X86_MCE */
@@ -45,7 +43,6 @@ dotraplinkage void do_int3(struct pt_reg dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code, unsigned long cr2);#endif dotraplinkage void do_page_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address); -dotraplinkage void do_alignment_check(struct pt_regs *regs, long error_code); dotraplinkage void do_simd_coprocessor_error(struct pt_regs *regs, long error_code);#ifdef CONFIG_X86_32 dotraplinkage void do_iret_error(struct pt_regs *regs, long error_code);
arch/x86/kernel/idt.c +1 -1
@@ -82,7 +82,7 @@ static const __initconst struct idt_dataINTG (X86_TRAP_GP , asm_exc_general_protection),INTG (X86_TRAP_SPURIOUS , asm_exc_spurious_interrupt_bug),INTG (X86_TRAP_MF , asm_exc_coprocessor_error), -INTG (X86_TRAP_AC , alignment_check), +INTG (X86_TRAP_AC , asm_exc_alignment_check),INTG (X86_TRAP_XF , simd_coprocessor_error), #ifdef CONFIG_X86_32
arch/x86/kernel/traps.c +1 -3
@@ -260,12 +260,10 @@ DEFINE_IDTENTRY_ERRORCODE(exc_stack_segm 0, NULL); } -dotraplinkage void do_alignment_check(struct pt_regs *regs, long error_code) +DEFINE_IDTENTRY_ERRORCODE (exc_alignment_check) {char *str ="alignment check" ; -RCU_LOCKDEP_WARN (!rcu_is_watching (),"entry code didn't wake RCU" ); -if (notify_die (DIE_TRAP , str, regs, error_code,X86_TRAP_AC ,SIGBUS ) ==NOTIFY_STOP )return ;
arch/x86/xen/enlighten_pv.c +1 -1
@@ -634,7 +634,7 @@ static struct trap_array_entry trap_arraTRAP_ENTRY (exc_general_protection, false ),TRAP_ENTRY (exc_spurious_interrupt_bug, false ),TRAP_ENTRY (exc_coprocessor_error, false ), - { alignment_check, xen_alignment_check, false }, +TRAP_ENTRY (exc_alignment_check, false ), { simd_coprocessor_error, xen_simd_coprocessor_error, false }, };
arch/x86/xen/xen-asm_64.S +1 -1
@@ -46,7 +46,7 @@ xen_pv_trap asm_exc_general_protection xen_pv_trap page_fault xen_pv_trap asm_exc_spurious_interrupt_bug xen_pv_trap asm_exc_coprocessor_error -xen_pv_trap alignment_check +xen_pv_trap asm_exc_alignment_check #ifdef CONFIG_X86_MCE xen_pv_trap machine_check #endif /* CONFIG_X86_MCE */
Re: [patch V4 part 3 27/29] x86/entry: Convert Alignment check exception to IDTENTRY
Quoted 12 lines · Thomas Gleixner
From: Thomas Gleixner <[email protected]>
Convert #AC to
IDTENTRY_ERRORCODE:
- Implement the C entry point withDEFINE_IDTENTRY
- Emit the ASM stub withDECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototyoes
- Remove the RCU warning as the new entry macro ensures correctness
Quoted 1 line
No functional change.
[tip: x86/entry] x86/entry: Convert Alignment check exception to IDTENTRY
In reply to Thomas GleixnerThe following commit has been merged into the x86/entry branch of tip:
The following commit has been merged into the x86/entry branch of tip:
Commit-ID: ea28f3d0310506b97fdca160ea2e1e30e3bd4583 Gitweb: https://git.kernel.org/tip/ea28f3d0310506b97fdca160ea2e1e30e3bd4583 Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 25 Feb 2020 23:16:28 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 19 May 2020 16:04:03 +02:00
x86/entry: Convert Alignment check exception to IDTENTRY
Convert #AC to IDTENTRY_ERRORCODE:
- Implement the C entry point with DEFINE_IDTENTRY
- Emit the ASM stub with DECLARE_IDTENTRY
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototypes
- Remove the RCU warning as the new entry macro ensures correctness
No functional change.
--- arch/x86/entry/entry_32.S | 6 ------ arch/x86/entry/entry_64.S | 1 - arch/x86/include/asm/idtentry.h | 1 + arch/x86/include/asm/traps.h | 3 --- arch/x86/kernel/idt.c | 2 +- arch/x86/kernel/traps.c | 4 +--- arch/x86/xen/enlighten_pv.c | 2 +- arch/x86/xen/xen-asm_64.S | 2 +- 8 files changed, 5 insertions(+), 16 deletions(-)
arch/x86/entry/entry_32.S +0 -6
@@ -1311,12 +1311,6 @@ SYM_CODE_START(native_iret) SYM_CODE_END(native_iret) #endif -SYM_CODE_START(alignment_check) - ASM_CLAC - pushl $do_alignment_check - jmp common_exception -SYM_CODE_END(alignment_check) - #ifdef CONFIG_X86_MCE SYM_CODE_START(machine_check) ASM_CLAC
arch/x86/entry/entry_64.S +0 -1
@@ -1073,7 +1073,6 @@ apicinterrupt IRQ_WORK_VECTOR irq_work_interrupt smp_irq_work_interrupt */ idtentry X86_TRAP_BP int3 do_int3 has_error_code=0 -idtentry X86_TRAP_AC alignment_check do_alignment_check has_error_code=1 idtentry X86_TRAP_XF simd_coprocessor_error do_simd_coprocessor_error has_error_code=0 idtentry X86_TRAP_PF page_fault do_page_fault has_error_code=1
arch/x86/include/asm/idtentry.h +1 -0
@@ -137,5 +137,6 @@ DECLARE_IDTENTRY_ERRORCODE(X86_TRAP_TS, exc_invalid_tss);DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_NP , exc_segment_not_present);DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_SS , exc_stack_segment);DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_GP , exc_general_protection); +DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_AC , exc_alignment_check);#endif
arch/x86/include/asm/traps.h +0 -3
@@ -19,7 +19,6 @@ asmlinkage void double_fault(void);#endif asmlinkage void page_fault(void); asmlinkage void async_page_fault(void); -asmlinkage void alignment_check(void);#ifdef CONFIG_X86_MCE asmlinkage void machine_check(void);#endif /* CONFIG_X86_MCE */
@@ -31,7 +30,6 @@ asmlinkage void xen_xendebug(void); asmlinkage void xen_int3(void); asmlinkage void xen_double_fault(void); asmlinkage void xen_page_fault(void); -asmlinkage void xen_alignment_check(void);#ifdef CONFIG_X86_MCE asmlinkage void xen_machine_check(void);#endif /* CONFIG_X86_MCE */
@@ -43,7 +41,6 @@ dotraplinkage void do_nmi(struct pt_regs *regs, long error_code); dotraplinkage void do_int3(struct pt_regs *regs, long error_code); dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code, unsigned long cr2); dotraplinkage void do_page_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address); -dotraplinkage void do_alignment_check(struct pt_regs *regs, long error_code); dotraplinkage void do_simd_coprocessor_error(struct pt_regs *regs, long error_code);#ifdef CONFIG_X86_32 dotraplinkage void do_iret_error(struct pt_regs *regs, long error_code);
arch/x86/kernel/idt.c +1 -1
@@ -85,7 +85,7 @@ static const __initconst struct idt_data def_idts[] = {INTG (X86_TRAP_GP , asm_exc_general_protection),INTG (X86_TRAP_SPURIOUS , asm_exc_spurious_interrupt_bug),INTG (X86_TRAP_MF , asm_exc_coprocessor_error), -INTG (X86_TRAP_AC , alignment_check), +INTG (X86_TRAP_AC , asm_exc_alignment_check),INTG (X86_TRAP_XF , simd_coprocessor_error), #ifdef CONFIG_X86_32
arch/x86/kernel/traps.c +1 -3
@@ -270,12 +270,10 @@ DEFINE_IDTENTRY_ERRORCODE(exc_stack_segment) 0, NULL); } -dotraplinkage void do_alignment_check(struct pt_regs *regs, long error_code) +DEFINE_IDTENTRY_ERRORCODE (exc_alignment_check) {char *str ="alignment check" ; -RCU_LOCKDEP_WARN (!rcu_is_watching (),"entry code didn't wake RCU" ); -if (notify_die (DIE_TRAP , str, regs, error_code,X86_TRAP_AC ,SIGBUS ) ==NOTIFY_STOP )return ;
arch/x86/xen/enlighten_pv.c +1 -1
@@ -634,7 +634,7 @@ static struct trap_array_entry trap_array[] = {TRAP_ENTRY (exc_general_protection, false ),TRAP_ENTRY (exc_spurious_interrupt_bug, false ),TRAP_ENTRY (exc_coprocessor_error, false ), - { alignment_check, xen_alignment_check, false }, +TRAP_ENTRY (exc_alignment_check, false ), { simd_coprocessor_error, xen_simd_coprocessor_error, false }, };
arch/x86/xen/xen-asm_64.S +1 -1
@@ -46,7 +46,7 @@ xen_pv_trap asm_exc_general_protection xen_pv_trap page_fault xen_pv_trap asm_exc_spurious_interrupt_bug xen_pv_trap asm_exc_coprocessor_error -xen_pv_trap alignment_check +xen_pv_trap asm_exc_alignment_check #ifdef CONFIG_X86_MCE xen_pv_trap machine_check #endif /* CONFIG_X86_MCE */
PATCH v4 28/29 x86/entry: Convert SIMD coprocessor error exception to IDTENTRY
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
Convert #XF to IDTENTRY_ERRORCODE:
- Implement the C entry point with DEFINE_IDTENTRY
- Emit the ASM stub with DECLARE_IDTENTRY
- Handle INVD_BUG in C
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototyoes
- Remove the RCU warning as the new entry macro ensures correctness
No functional change.
---
V3: Move the INVD bug handling to C (Brian)
--- arch/x86/entry/entry_32.S | 14 -------------- arch/x86/entry/entry_64.S | 1 - arch/x86/include/asm/idtentry.h | 1 + arch/x86/include/asm/traps.h | 3 --- arch/x86/kernel/idt.c | 2 +- arch/x86/kernel/traps.c | 29 +++++++++++++++++------------ arch/x86/xen/enlighten_pv.c | 2 +- arch/x86/xen/xen-asm_64.S | 2 +- 8 files changed, 21 insertions(+), 33 deletions(-)
arch/x86/entry/entry_32.S +0 -14
@@ -1290,20 +1290,6 @@ SYM_FUNC_END(name) /* The include is where all of the SMP etc. interrupts come from */ #include <asm/entry_arch.h> -SYM_CODE_START(simd_coprocessor_error) - ASM_CLAC - pushl $0 -#ifdef CONFIG_X86_INVD_BUG - /* AMD 486 bug: invd from userspace calls exception 19 instead of #GP */ - ALTERNATIVE "pushl $exc_general_protection", \ - "pushl $do_simd_coprocessor_error", \ - X86_FEATURE_XMM -#else - pushl $do_simd_coprocessor_error -#endif - jmp common_exception -SYM_CODE_END(simd_coprocessor_error) - #ifdef CONFIG_PARAVIRT SYM_CODE_START(native_iret) iret
arch/x86/entry/entry_64.S +0 -1
@@ -1074,7 +1074,6 @@ apicinterrupt IRQ_WORK_VECTOR irq_work */ idtentry X86_TRAP_BP int3 do_int3 has_error_code=0 -idtentry X86_TRAP_XF simd_coprocessor_error do_simd_coprocessor_error has_error_code=0 idtentry X86_TRAP_PF page_fault do_page_fault has_error_code=1
arch/x86/include/asm/idtentry.h +1 -0
@@ -131,6 +131,7 @@ DECLARE_IDTENTRY(X86_TRAP_NM, exc_devicDECLARE_IDTENTRY (X86_TRAP_OLD_MF , exc_coproc_segment_overrun);DECLARE_IDTENTRY (X86_TRAP_SPURIOUS , exc_spurious_interrupt_bug);DECLARE_IDTENTRY (X86_TRAP_MF , exc_coprocessor_error); +DECLARE_IDTENTRY (X86_TRAP_XF , exc_simd_coprocessor_error);/* Simple exception entries with error code pushed by hardware */ DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_TS , exc_invalid_tss);
arch/x86/include/asm/traps.h +0 -3
@@ -22,7 +22,6 @@ asmlinkage void async_page_fault(void);#ifdef CONFIG_X86_MCE asmlinkage void machine_check(void);#endif /* CONFIG_X86_MCE */ -asmlinkage void simd_coprocessor_error(void);#if defined(CONFIG_X86_64 ) && defined(CONFIG_XEN_PV ) asmlinkage void xen_xennmi(void);
@@ -33,7 +32,6 @@ asmlinkage void xen_page_fault(void);#ifdef CONFIG_X86_MCE asmlinkage void xen_machine_check(void);#endif /* CONFIG_X86_MCE */ -asmlinkage void xen_simd_coprocessor_error(void);#endif dotraplinkage void do_debug(struct pt_regs *regs, long error_code);
@@ -43,7 +41,6 @@ dotraplinkage void do_int3(struct pt_reg dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code, unsigned long cr2);#endif dotraplinkage void do_page_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address); -dotraplinkage void do_simd_coprocessor_error(struct pt_regs *regs, long error_code);#ifdef CONFIG_X86_32 dotraplinkage void do_iret_error(struct pt_regs *regs, long error_code);#endif
arch/x86/kernel/idt.c +1 -1
@@ -83,7 +83,7 @@ static const __initconst struct idt_dataINTG (X86_TRAP_SPURIOUS , asm_exc_spurious_interrupt_bug),INTG (X86_TRAP_MF , asm_exc_coprocessor_error),INTG (X86_TRAP_AC , asm_exc_alignment_check), -INTG (X86_TRAP_XF , simd_coprocessor_error), +INTG (X86_TRAP_XF , asm_exc_simd_coprocessor_error), #ifdef CONFIG_X86_32 TSKG(X86_TRAP_DF, GDT_ENTRY_DOUBLEFAULT_TSS),
arch/x86/kernel/traps.c +17 -12
@@ -802,7 +802,7 @@ NOKPROBE_SYMBOL(do_debug);* the correct behaviour even in the presence of the asynchronous * IRQ13 behaviour */ -static void math_error (struct pt_regs *regs,int error_code,int trapnr) +static void math_error (struct pt_regs *regs,int trapnr) {struct task_struct *task = current;struct fpu *fpu = &task->thread.fpu;
@@ -813,15 +813,15 @@ static void math_error(struct pt_regs *rcond_local_irq_enable (regs);if (!user_mode (regs)) { -if (fixup_exception (regs, trapnr, error_code,0 )) +if (fixup_exception (regs, trapnr,0 ,0 )) goto exit; - task->thread.error_code = error_code; + task->thread.error_code =0 ; task->thread.trap_nr = trapnr; -if (notify_die (DIE_TRAP , str, regs, error_code, - trapnr,SIGFPE ) !=NOTIFY_STOP ) -die (str, regs, error_code); +if (notify_die (DIE_TRAP , str, regs,0 , trapnr, +SIGFPE ) !=NOTIFY_STOP ) +die (str, regs,0 ); goto exit; }
@@ -831,7 +831,7 @@ static void math_error(struct pt_regs *rfpu__save (fpu); task->thread.trap_nr = trapnr; - task->thread.error_code = error_code; + task->thread.error_code =0 ; si_code =fpu__exception_code (fpu, trapnr);/* Retry when we get spurious exceptions: */
@@ -846,14 +846,19 @@ static void math_error(struct pt_regs *rDEFINE_IDTENTRY (exc_coprocessor_error) { -math_error (regs,0 ,X86_TRAP_MF ); +math_error (regs,X86_TRAP_MF ); } -dotraplinkage void -do_simd_coprocessor_error (struct pt_regs *regs,long error_code) +DEFINE_IDTENTRY (exc_simd_coprocessor_error) { -RCU_LOCKDEP_WARN (!rcu_is_watching (),"entry code didn't wake RCU" ); -math_error (regs, error_code,X86_TRAP_XF ); +if (IS_ENABLED (CONFIG_X86_INVD_BUG )) { +/* AMD 486 bug: INVD in CPL 0 raises #XF instead of #GP */ +if (!static_cpu_has (X86_FEATURE_XMM )) { +__exc_general_protection (regs,0 ); +return ; + } + } +math_error (regs,X86_TRAP_XF ); }DEFINE_IDTENTRY (exc_spurious_interrupt_bug)
arch/x86/xen/enlighten_pv.c +1 -1
@@ -635,7 +635,7 @@ static struct trap_array_entry trap_arraTRAP_ENTRY (exc_spurious_interrupt_bug, false ),TRAP_ENTRY (exc_coprocessor_error, false ),TRAP_ENTRY (exc_alignment_check, false ), - { simd_coprocessor_error, xen_simd_coprocessor_error, false }, + TRAP_ENTRY(exc_simd_coprocessor_error, false ), };static bool __ref get_trap_addr (void **addr,unsigned int ist)
arch/x86/xen/xen-asm_64.S +1 -1
@@ -50,7 +50,7 @@ xen_pv_trap asm_exc_alignment_check #ifdef CONFIG_X86_MCE xen_pv_trap machine_check #endif /* CONFIG_X86_MCE */ -xen_pv_trap simd_coprocessor_error +xen_pv_trap asm_exc_simd_coprocessor_error #ifdef CONFIG_IA32_EMULATION xen_pv_trap entry_INT80_compat #endif
Re: [patch V4 part 3 28/29] x86/entry: Convert SIMD coprocessor error exception to IDTENTRY
Quoted 13 lines · Thomas Gleixner
From: Thomas Gleixner <[email protected]>
Convert #XF to
IDTENTRY_ERRORCODE:
- Implement the C entry point withDEFINE_IDTENTRY
- Emit the ASM stub withDECLARE_IDTENTRY
- HandleINVD_BUGin C
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototyoes
- Remove the RCU warning as the new entry macro ensures correctness
Quoted 1 line
No functional change.
[tip: x86/entry] x86/entry: Convert SIMD coprocessor error exception to IDTENTRY
In reply to Thomas GleixnerThe following commit has been merged into the x86/entry branch of tip:
The following commit has been merged into the x86/entry branch of tip:
Commit-ID: 03852142b159a78c77aa795ba6c6bd1f6273eab8 Gitweb: https://git.kernel.org/tip/03852142b159a78c77aa795ba6c6bd1f6273eab8 Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 25 Feb 2020 23:16:29 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 19 May 2020 16:04:03 +02:00
x86/entry: Convert SIMD coprocessor error exception to IDTENTRY
Convert #XF to IDTENTRY_ERRORCODE:
- Implement the C entry point with DEFINE_IDTENTRY
- Emit the ASM stub with DECLARE_IDTENTRY
- Handle INVD_BUG in C
- Remove the ASM idtentry in 64bit
- Remove the open coded ASM entry code in 32bit
- Fixup the XEN/PV code
- Remove the old prototypes
- Remove the RCU warning as the new entry macro ensures correctness
No functional change.
--- arch/x86/entry/entry_32.S | 14 -------------- arch/x86/entry/entry_64.S | 1 - arch/x86/include/asm/idtentry.h | 1 + arch/x86/include/asm/traps.h | 3 --- arch/x86/kernel/idt.c | 2 +- arch/x86/kernel/traps.c | 29 +++++++++++++++++------------ arch/x86/xen/enlighten_pv.c | 2 +- arch/x86/xen/xen-asm_64.S | 2 +- 8 files changed, 21 insertions(+), 33 deletions(-)
arch/x86/entry/entry_32.S +0 -14
@@ -1290,20 +1290,6 @@ SYM_FUNC_END(name) /* The include is where all of the SMP etc. interrupts come from */ #include <asm/entry_arch.h> -SYM_CODE_START(simd_coprocessor_error) - ASM_CLAC - pushl $0 -#ifdef CONFIG_X86_INVD_BUG - /* AMD 486 bug: invd from userspace calls exception 19 instead of #GP */ - ALTERNATIVE "pushl $exc_general_protection", \ - "pushl $do_simd_coprocessor_error", \ - X86_FEATURE_XMM -#else - pushl $do_simd_coprocessor_error -#endif - jmp common_exception -SYM_CODE_END(simd_coprocessor_error) - #ifdef CONFIG_PARAVIRT SYM_CODE_START(native_iret) iret
arch/x86/entry/entry_64.S +0 -1
@@ -1073,7 +1073,6 @@ apicinterrupt IRQ_WORK_VECTOR irq_work_interrupt smp_irq_work_interrupt */ idtentry X86_TRAP_BP int3 do_int3 has_error_code=0 -idtentry X86_TRAP_XF simd_coprocessor_error do_simd_coprocessor_error has_error_code=0 idtentry X86_TRAP_PF page_fault do_page_fault has_error_code=1
arch/x86/include/asm/idtentry.h +1 -0
@@ -131,6 +131,7 @@ DECLARE_IDTENTRY(X86_TRAP_NM, exc_device_not_available);DECLARE_IDTENTRY (X86_TRAP_OLD_MF , exc_coproc_segment_overrun);DECLARE_IDTENTRY (X86_TRAP_SPURIOUS , exc_spurious_interrupt_bug);DECLARE_IDTENTRY (X86_TRAP_MF , exc_coprocessor_error); +DECLARE_IDTENTRY (X86_TRAP_XF , exc_simd_coprocessor_error);/* Simple exception entries with error code pushed by hardware */ DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_TS , exc_invalid_tss);
arch/x86/include/asm/traps.h +0 -3
@@ -22,7 +22,6 @@ asmlinkage void async_page_fault(void);#ifdef CONFIG_X86_MCE asmlinkage void machine_check(void);#endif /* CONFIG_X86_MCE */ -asmlinkage void simd_coprocessor_error(void);#if defined(CONFIG_X86_64 ) && defined(CONFIG_XEN_PV ) asmlinkage void xen_xennmi(void);
@@ -33,7 +32,6 @@ asmlinkage void xen_page_fault(void);#ifdef CONFIG_X86_MCE asmlinkage void xen_machine_check(void);#endif /* CONFIG_X86_MCE */ -asmlinkage void xen_simd_coprocessor_error(void);#endif dotraplinkage void do_debug(struct pt_regs *regs, long error_code);
@@ -41,7 +39,6 @@ dotraplinkage void do_nmi(struct pt_regs *regs, long error_code); dotraplinkage void do_int3(struct pt_regs *regs, long error_code); dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code, unsigned long cr2); dotraplinkage void do_page_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address); -dotraplinkage void do_simd_coprocessor_error(struct pt_regs *regs, long error_code);#ifdef CONFIG_X86_32 dotraplinkage void do_iret_error(struct pt_regs *regs, long error_code);#endif
arch/x86/kernel/idt.c +1 -1
@@ -86,7 +86,7 @@ static const __initconst struct idt_data def_idts[] = {INTG (X86_TRAP_SPURIOUS , asm_exc_spurious_interrupt_bug),INTG (X86_TRAP_MF , asm_exc_coprocessor_error),INTG (X86_TRAP_AC , asm_exc_alignment_check), -INTG (X86_TRAP_XF , simd_coprocessor_error), +INTG (X86_TRAP_XF , asm_exc_simd_coprocessor_error), #ifdef CONFIG_X86_32 TSKG(X86_TRAP_DF, GDT_ENTRY_DOUBLEFAULT_TSS),
arch/x86/kernel/traps.c +17 -12
@@ -810,7 +810,7 @@ NOKPROBE_SYMBOL(do_debug);* the correct behaviour even in the presence of the asynchronous * IRQ13 behaviour */ -static void math_error (struct pt_regs *regs,int error_code,int trapnr) +static void math_error (struct pt_regs *regs,int trapnr) {struct task_struct *task = current;struct fpu *fpu = &task->thread.fpu;
@@ -821,15 +821,15 @@ static void math_error(struct pt_regs *regs, int error_code, int trapnr)cond_local_irq_enable (regs);if (!user_mode (regs)) { -if (fixup_exception (regs, trapnr, error_code,0 )) +if (fixup_exception (regs, trapnr,0 ,0 )) goto exit; - task->thread.error_code = error_code; + task->thread.error_code =0 ; task->thread.trap_nr = trapnr; -if (notify_die (DIE_TRAP , str, regs, error_code, - trapnr,SIGFPE ) !=NOTIFY_STOP ) -die (str, regs, error_code); +if (notify_die (DIE_TRAP , str, regs,0 , trapnr, +SIGFPE ) !=NOTIFY_STOP ) +die (str, regs,0 ); goto exit; }
@@ -839,7 +839,7 @@ static void math_error(struct pt_regs *regs, int error_code, int trapnr)fpu__save (fpu); task->thread.trap_nr = trapnr; - task->thread.error_code = error_code; + task->thread.error_code =0 ; si_code =fpu__exception_code (fpu, trapnr);/* Retry when we get spurious exceptions: */
@@ -854,14 +854,19 @@ exit:DEFINE_IDTENTRY (exc_coprocessor_error) { -math_error (regs,0 ,X86_TRAP_MF ); +math_error (regs,X86_TRAP_MF ); } -dotraplinkage void -do_simd_coprocessor_error (struct pt_regs *regs,long error_code) +DEFINE_IDTENTRY (exc_simd_coprocessor_error) { -RCU_LOCKDEP_WARN (!rcu_is_watching (),"entry code didn't wake RCU" ); -math_error (regs, error_code,X86_TRAP_XF ); +if (IS_ENABLED (CONFIG_X86_INVD_BUG )) { +/* AMD 486 bug: INVD in CPL 0 raises #XF instead of #GP */ +if (!static_cpu_has (X86_FEATURE_XMM )) { +__exc_general_protection (regs,0 ); +return ; + } + } +math_error (regs,X86_TRAP_XF ); }DEFINE_IDTENTRY (exc_spurious_interrupt_bug)
arch/x86/xen/enlighten_pv.c +1 -1
@@ -635,7 +635,7 @@ static struct trap_array_entry trap_array[] = {TRAP_ENTRY (exc_spurious_interrupt_bug, false ),TRAP_ENTRY (exc_coprocessor_error, false ),TRAP_ENTRY (exc_alignment_check, false ), - { simd_coprocessor_error, xen_simd_coprocessor_error, false }, + TRAP_ENTRY(exc_simd_coprocessor_error, false ), };static bool __ref get_trap_addr (void **addr,unsigned int ist)
arch/x86/xen/xen-asm_64.S +1 -1
@@ -50,7 +50,7 @@ xen_pv_trap asm_exc_alignment_check #ifdef CONFIG_X86_MCE xen_pv_trap machine_check #endif /* CONFIG_X86_MCE */ -xen_pv_trap simd_coprocessor_error +xen_pv_trap asm_exc_simd_coprocessor_error #ifdef CONFIG_IA32_EMULATION xen_pv_trap entry_INT80_compat #endif
PATCH v4 29/29 x86/entry/32: Convert IRET exception to IDTENTRY_SW
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
Convert the IRET exception handler to IDTENTRY_SW. This is slightly different than the conversions of hardware exceptions as the IRET exception is invoked via an exception table when IRET faults. So it just uses the IDTENTRY_SW mechanism for consistency. It does not emit ASM code as it does not fit the other idtentry exceptions.
- Implement the C entry point with DEFINE_IDTENTRY_SW() which maps to DEFINE_IDTENTRY()
- Fixup the XEN/PV code
- Remove the old prototyoes
- Remove the RCU warning as the new entry macro ensures correctness
No functional change.
--- arch/x86/entry/entry_32.S | 14 +++++++------- arch/x86/include/asm/idtentry.h | 10 ++++++++++ arch/x86/include/asm/traps.h | 3 --- arch/x86/kernel/traps.c | 8 +++----- arch/x86/xen/xen-asm_32.S | 2 +- 5 files changed, 21 insertions(+), 16 deletions(-)
arch/x86/entry/entry_32.S +7 -7
@@ -1147,9 +1147,9 @@ SYM_FUNC_START(entry_INT80_32) jmp .Lirq_return .section .fixup, "ax" -SYM_CODE_START(iret_exc) +SYM_CODE_START(asm_exc_iret_error) pushl $0 # no error code - pushl $do_iret_error + pushl $exc_iret_error #ifdef CONFIG_DEBUG_ENTRY /*
@@ -1163,10 +1163,10 @@ SYM_CODE_START(iret_exc) popl %eax #endif - jmp common_exception -SYM_CODE_END(iret_exc) + jmp handle_exception +SYM_CODE_END(asm_exc_iret_error) .previous - _ASM_EXTABLE(.Lirq_return, iret_exc) + _ASM_EXTABLE(.Lirq_return, asm_exc_iret_error) SYM_FUNC_END(entry_INT80_32) .macro FIXUP_ESPFIX_STACK
@@ -1293,7 +1293,7 @@ SYM_FUNC_END(name) #ifdef CONFIG_PARAVIRT SYM_CODE_START(native_iret) iret - _ASM_EXTABLE(native_iret, iret_exc) + _ASM_EXTABLE(native_iret, asm_exc_iret_error) SYM_CODE_END(native_iret) #endif
@@ -1358,7 +1358,7 @@ SYM_FUNC_START(xen_failsafe_callback) popl %eax lea 16(%esp), %esp jz 5f - jmp iret_exc + jmp asm_exc_iret_error 5: pushl $-1 /* orig_ax = -1 => not a system call */ SAVE_ALL ENCODE_FRAME_POINTER
arch/x86/include/asm/idtentry.h +10 -0
@@ -57,6 +57,10 @@ static __always_inline void __##func(str \ static __always_inline void __##func(struct pt_regs *regs) +/* Special case for 32bit IRET 'trap' */ +#define DECLARE_IDTENTRY_SW DECLARE_IDTENTRY +#define DEFINE_IDTENTRY_SW DEFINE_IDTENTRY +/** * DECLARE_IDTENTRY_ERRORCODE - Declare functions for simple IDT entry points * Error code pushed by hardware
@@ -111,6 +115,9 @@ static __always_inline void __##func(str#define DECLARE_IDTENTRY_ERRORCODE (vector, func) \ idtentry vector asm_##func func has_error_code=1 sane=1 +/* Special case for 32bit IRET 'trap'. Do not emit ASM code */ +#define DECLARE_IDTENTRY_SW (vector, func) +#endif /* __ASSEMBLY__ */ /*
@@ -133,6 +140,9 @@ DECLARE_IDTENTRY(X86_TRAP_SPURIOUS, exc_DECLARE_IDTENTRY (X86_TRAP_MF , exc_coprocessor_error);DECLARE_IDTENTRY (X86_TRAP_XF , exc_simd_coprocessor_error); +/* 32bit software IRET trap. Do not emit ASM code */ +DECLARE_IDTENTRY_SW (X86_TRAP_IRET , exc_iret_error); +/* Simple exception entries with error code pushed by hardware */ DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_TS , exc_invalid_tss);DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_NP , exc_segment_not_present);
arch/x86/include/asm/traps.h +0 -3
@@ -41,9 +41,6 @@ dotraplinkage void do_int3(struct pt_reg dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code, unsigned long cr2);#endif dotraplinkage void do_page_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address); -#ifdef CONFIG_X86_32 -dotraplinkage void do_iret_error(struct pt_regs *regs, long error_code); -#endif dotraplinkage void do_mce(struct pt_regs *regs, long error_code);#ifdef CONFIG_X86_64
arch/x86/kernel/traps.c +3 -5
@@ -917,14 +917,12 @@ DEFINE_IDTENTRY(exc_device_not_available }#ifdef CONFIG_X86_32 -dotraplinkage void do_iret_error(struct pt_regs *regs, long error_code) +DEFINE_IDTENTRY_SW (exc_iret_error) { -RCU_LOCKDEP_WARN (!rcu_is_watching (),"entry code didn't wake RCU" );local_irq_enable (); - -if (notify_die (DIE_TRAP ,"iret exception" , regs, error_code, +if (notify_die (DIE_TRAP ,"iret exception" , regs,0 ,X86_TRAP_IRET ,SIGILL ) !=NOTIFY_STOP ) { -do_trap (X86_TRAP_IRET ,SIGILL ,"iret exception" , regs, error_code, +do_trap (X86_TRAP_IRET ,SIGILL ,"iret exception" , regs,0 ,ILL_BADSTK , (void __user *)NULL ); }local_irq_disable ();
arch/x86/xen/xen-asm_32.S +1 -1
@@ -117,7 +117,7 @@ SYM_CODE_START(xen_iret) 1: iret xen_iret_end_crit: - _ASM_EXTABLE(1b, iret_exc) + _ASM_EXTABLE(1b, asm_exc_iret_error) hyper_iret: /* put this out of line since its very rarely used */
Re: [patch V4 part 3 29/29] x86/entry/32: Convert IRET exception to IDTENTRY_SW
Quoted 14 lines · Thomas Gleixner
From: Thomas Gleixner <[email protected]>
Convert the IRET exception handler to
IDTENTRY_SW. This is slightly different than the conversions of hardware exceptions as the IRET exception is invoked via an exception table when IRET faults. So it just uses theIDTENTRY_SWmechanism for consistency. It does not emit ASM code as it does not fit the other idtentry exceptions.- Implement the C entry point with
DEFINE_IDTENTRY_SW()which maps toDEFINE_IDTENTRY()
- Fixup the XEN/PV code
- Remove the old prototyoes
- Remove the RCU warning as the new entry macro ensures correctness
Quoted 4 lines
No functional change.
Signed-off-by Thomas Gleixner <[email protected]>
For all patches of part 3:
alex
Re: [patch V4 part 3 29/29] x86/entry/32: Convert IRET exception to IDTENTRY_SW
In reply to Thomas GleixnerQuoted 8 lines · Thomas Gleixner
From: Thomas Gleixner <[email protected]>
Convert the IRET exception handler to
IDTENTRY_SW. This is slightly different than the conversions of hardware exceptions as the IRET exception is invoked via an exception table when IRET faults. So it just uses theIDTENTRY_SWmechanism for consistency. It does not emit ASM code as it does not fit the other idtentry exceptions.
Blech. I should redo the 32-bit code to handle this the way the 64-bit code does and this can all be deleted. But, for now:
However, maybe rename asm_exc_iret_error to avoid confusion? It's not really an exception entry.
Re: [patch V4 part 3 29/29] x86/entry/32: Convert IRET exception to IDTENTRY_SW
Quoted 10 lines · Andy Lutomirski
Quoted 8 lines · Thomas Gleixner
From: Thomas Gleixner <[email protected]>
Convert the IRET exception handler to
IDTENTRY_SW. This is slightly different than the conversions of hardware exceptions as the IRET exception is invoked via an exception table when IRET faults. So it just uses theIDTENTRY_SWmechanism for consistency. It does not emit ASM code as it does not fit the other idtentry exceptions.
Quoted 7 lines
Blech. I should redo the 32-bit code to handle this the way the 64-bit code does and this can all be deleted. But, for now:
Acked-by Andy Lutomirski <[email protected]>However, maybe rename
asm_exc_iret_errorto avoid confusion? It's not really an exception entry.
True. Removed the 'exc_' from all instances.
[tip: x86/entry] x86/entry/32: Convert IRET exception to IDTENTRY_SW
In reply to Thomas GleixnerThe following commit has been merged into the x86/entry branch of tip:
The following commit has been merged into the x86/entry branch of tip:
Commit-ID: db300565d865092ee8a372a6bd15eb2764ec85ab Gitweb: https://git.kernel.org/tip/db300565d865092ee8a372a6bd15eb2764ec85ab Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 25 Feb 2020 23:16:30 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 19 May 2020 16:04:04 +02:00
x86/entry/32: Convert IRET exception to IDTENTRY_SW
Convert the IRET exception handler to IDTENTRY_SW. This is slightly different than the conversions of hardware exceptions as the IRET exception is invoked via an exception table when IRET faults. So it just uses the IDTENTRY_SW mechanism for consistency. It does not emit ASM code as it does not fit the other idtentry exceptions.
- Implement the C entry point with DEFINE_IDTENTRY_SW() which maps to DEFINE_IDTENTRY()
- Fixup the XEN/PV code
- Remove the old prototypes
- Remove the RCU warning as the new entry macro ensures correctness
No functional change.
--- arch/x86/entry/entry_32.S | 14 +++++++------- arch/x86/include/asm/idtentry.h | 10 ++++++++++ arch/x86/include/asm/traps.h | 3 --- arch/x86/kernel/traps.c | 8 +++----- arch/x86/xen/xen-asm_32.S | 2 +- 5 files changed, 21 insertions(+), 16 deletions(-)
arch/x86/entry/entry_32.S +7 -7
@@ -1147,9 +1147,9 @@ restore_all_kernel: jmp .Lirq_return .section .fixup, "ax" -SYM_CODE_START(iret_exc) +SYM_CODE_START(asm_iret_error) pushl $0 # no error code - pushl $do_iret_error + pushl $iret_error #ifdef CONFIG_DEBUG_ENTRY /*
@@ -1163,10 +1163,10 @@ SYM_CODE_START(iret_exc) popl %eax #endif - jmp common_exception -SYM_CODE_END(iret_exc) + jmp handle_exception +SYM_CODE_END(asm_iret_error) .previous - _ASM_EXTABLE(.Lirq_return, iret_exc) + _ASM_EXTABLE(.Lirq_return, asm_iret_error) SYM_FUNC_END(entry_INT80_32) .macro FIXUP_ESPFIX_STACK
@@ -1293,7 +1293,7 @@ SYM_FUNC_END(name) #ifdef CONFIG_PARAVIRT SYM_CODE_START(native_iret) iret - _ASM_EXTABLE(native_iret, iret_exc) + _ASM_EXTABLE(native_iret, asm_iret_error) SYM_CODE_END(native_iret) #endif
@@ -1358,7 +1358,7 @@ SYM_FUNC_START(xen_failsafe_callback) popl %eax lea 16(%esp), %esp jz 5f - jmp iret_exc + jmp asm_iret_error 5: pushl $-1 /* orig_ax = -1 => not a system call */ SAVE_ALL ENCODE_FRAME_POINTER
arch/x86/include/asm/idtentry.h +10 -0
@@ -57,6 +57,10 @@ __visible noinstr void func(struct pt_regs *regs) \ \ static __always_inline void __##func(struct pt_regs *regs) +/* Special case for 32bit IRET 'trap' */ +#define DECLARE_IDTENTRY_SW DECLARE_IDTENTRY +#define DEFINE_IDTENTRY_SW DEFINE_IDTENTRY +/** * DECLARE_IDTENTRY_ERRORCODE - Declare functions for simple IDT entry points * Error code pushed by hardware
@@ -111,6 +115,9 @@ static __always_inline void __##func(struct pt_regs *regs, \#define DECLARE_IDTENTRY_ERRORCODE (vector, func) \ idtentry vector asm_##func func has_error_code=1 sane=1 +/* Special case for 32bit IRET 'trap'. Do not emit ASM code */ +#define DECLARE_IDTENTRY_SW (vector, func) +#endif /* __ASSEMBLY__ */ /*
@@ -133,6 +140,9 @@ DECLARE_IDTENTRY(X86_TRAP_SPURIOUS, exc_spurious_interrupt_bug);DECLARE_IDTENTRY (X86_TRAP_MF , exc_coprocessor_error);DECLARE_IDTENTRY (X86_TRAP_XF , exc_simd_coprocessor_error); +/* 32bit software IRET trap. Do not emit ASM code */ +DECLARE_IDTENTRY_SW (X86_TRAP_IRET , iret_error); +/* Simple exception entries with error code pushed by hardware */ DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_TS , exc_invalid_tss);DECLARE_IDTENTRY_ERRORCODE (X86_TRAP_NP , exc_segment_not_present);
arch/x86/include/asm/traps.h +0 -3
@@ -39,9 +39,6 @@ dotraplinkage void do_nmi(struct pt_regs *regs, long error_code); dotraplinkage void do_int3(struct pt_regs *regs, long error_code); dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code, unsigned long cr2); dotraplinkage void do_page_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address); -#ifdef CONFIG_X86_32 -dotraplinkage void do_iret_error(struct pt_regs *regs, long error_code); -#endif dotraplinkage void do_mce(struct pt_regs *regs, long error_code);#ifdef CONFIG_X86_64
arch/x86/kernel/traps.c +3 -5
@@ -925,14 +925,12 @@ DEFINE_IDTENTRY(exc_device_not_available) }#ifdef CONFIG_X86_32 -dotraplinkage void do_iret_error(struct pt_regs *regs, long error_code) +DEFINE_IDTENTRY_SW (iret_error) { -RCU_LOCKDEP_WARN (!rcu_is_watching (),"entry code didn't wake RCU" );local_irq_enable (); - -if (notify_die (DIE_TRAP ,"iret exception" , regs, error_code, +if (notify_die (DIE_TRAP ,"iret exception" , regs,0 ,X86_TRAP_IRET ,SIGILL ) !=NOTIFY_STOP ) { -do_trap (X86_TRAP_IRET ,SIGILL ,"iret exception" , regs, error_code, +do_trap (X86_TRAP_IRET ,SIGILL ,"iret exception" , regs,0 ,ILL_BADSTK , (void __user *)NULL ); }local_irq_disable ();
arch/x86/xen/xen-asm_32.S +1 -1
@@ -117,7 +117,7 @@ iret_restore_end: 1: iret xen_iret_end_crit: - _ASM_EXTABLE(1b, iret_exc) + _ASM_EXTABLE(1b, asm_iret_error) hyper_iret: /* put this out of line since its very rarely used */