Skip to contentSkip to conversation

x86: ipipe: Fix trap hooking for userspace routes

PATCH In review Jan Kiszka 4 participants 8 messages Oct 10, 2018 – Oct 29, 2018

Subsystems (2)
lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 1/1 x86: ipipe: Fix trap hooking for userspace routes

Also hook into the trap path when the exception was taken over userspace code.

Fixes e6b81a0ce7fb (x86: ipipe: route traps to co-kernel)

---

Makes sense? I'm not feeling 100% safe yet /wrt paranoid and the userspace path. Should we handle this identically to the kernel path or not?

Eventually this should be merged into the original patch, at least on next major rebase.

 arch/x86/entry/entry_64.S | 80 +++++++++++++++++++++++++++--------------------
 1 file changed, 46 insertions(+), 34 deletions(-)
arch/x86/entry/entry_64.S +46 -34
index f6fe849d66ed..42e31d1fddc6 100644
@@ -904,6 +904,46 @@ ENTRY(switch_to_thread_stack)
 	ret
 END(switch_to_thread_stack)
 
+.macro ipipe_idtentry_prologue paranoid=0 trapnr=-1 skip_label=-invalid-
+#ifdef CONFIG_IPIPE
+	movq	EFLAGS(%rsp), %r14		/* regs->flags */
+	movq	%rsp, %rdi			/* pt_regs pointer */
+	movl	$\trapnr, %esi			/* trap number */
+	subq	$8, %rsp
+	movq	%rsp, %rdx			/* &flags */
+	call	__ipipe_trap_prologue
+	popq	%r13
+	mov	%rax, %r12			/* save propagation status */
+	.if \paranoid == 0			/* paranoid may not skip handler */
+	testl	%eax, %eax
+	jg	\skip_label			/* skip regular handler if > 0 */
+	.endif
+#endif
+.endm
+
+.macro ipipe_idtentry_epilogue paranoid=0 skip_label=-invalid-
+#ifdef CONFIG_IPIPE
+	testl	%r12d, %r12d
+	jnz	1000f
+	movq	%rsp, %rdi			/* pt_regs pointer */
+	movq	%r13, %rsi			/* &flags from prologue */
+	movq	%r14, %rdx			/* original regs->flags before fixup */
+	call	__ipipe_trap_epilogue
+1000:
+	.if \paranoid == 0			/* paranoid implies normal epilogue */
+	testl	%r12d, %r12d
+	jz	1001f
+\skip_label:
+	UNWIND_HINT_REGS
+	DISABLE_INTERRUPTS(CLBR_ANY)
+	testl	%ebx, %ebx	/* %ebx: return to kernel mode */
+	jnz	retint_kernel_early
+	jmp	retint_user_early
+	.endif
+1001:
+#endif
+.endm
+
 .macro idtentry sym do_sym has_error_code:req paranoid=0 shift_ist=-1 trapnr=-1
 ENTRY(\sym)
 	UNWIND_HINT_IRET_REGS offset=\has_error_code*8
@@ -940,20 +980,7 @@ ENTRY(\sym)
 	.endif
 	.endif
 
-#ifdef CONFIG_IPIPE
-	movq	EFLAGS(%rsp), %r14		/* regs->flags */
-	movq	%rsp, %rdi			/* pt_regs pointer */
-	movl	$\trapnr, %esi			/* trap number */
-	subq	$8, %rsp
-	movq	%rsp, %rdx			/* &flags */
-	call	__ipipe_trap_prologue
-	popq	%r13
-	mov	%rax, %r12			/* save propagation status */
-	.if \paranoid == 0			/* paranoid may not skip handler */
-	testl	%eax, %eax
-	jg	98f				/* skip regular handler if > 0 */
-	.endif
-#endif
+	ipipe_idtentry_prologue paranoid=\paranoid trapnr=\trapnr skip_label=kernel_skip_\@
 
 	movq	%rsp, %rdi			/* pt_regs pointer */
 
@@ -970,26 +997,7 @@ ENTRY(\sym)
 
 	call	\do_sym
 
-#ifdef CONFIG_IPIPE
-	testl	%r12d, %r12d
-	jnz	97f
-	movq	%rsp, %rdi			/* pt_regs pointer */
-	movq	%r13, %rsi			/* &flags from prologue */
-	movq	%r14, %rdx			/* original regs->flags before fixup */
-	call	__ipipe_trap_epilogue
-97:
-	.if \paranoid == 0			/* paranoid implies normal epilogue */
-	testl	%r12d, %r12d
-	jz	99f
-98:
-	UNWIND_HINT_REGS
-	DISABLE_INTERRUPTS(CLBR_ANY)
-	testl	%ebx, %ebx	/* %ebx: return to kernel mode */
-	jnz	retint_kernel_early
-	jmp	retint_user_early
-	.endif
-99:
-#endif
+	ipipe_idtentry_epilogue paranoid=\paranoid skip_label=kernel_skip_\@
 
 	.if \shift_ist != -1
 	addq	$EXCEPTION_STKSZ, CPU_TSS_IST(\shift_ist)
@@ -1011,6 +1019,8 @@ ENTRY(\sym)
 .Lfrom_usermode_switch_stack_\@:
 	call	error_entry
 
+	ipipe_idtentry_prologue paranoid=\paranoid trapnr=\trapnr skip_label=user_skip_\@
+
 	movq	%rsp, %rdi			/* pt_regs pointer */
 
 	.if \has_error_code
@@ -1022,6 +1032,8 @@ ENTRY(\sym)
 
 	call	\do_sym
 
+	ipipe_idtentry_epilogue paranoid=\paranoid skip_label=user_skip_\@
+
 	jmp	error_exit
 	.endif
 END(\sym)
Signature · 1 line
2.16.4
#1 lore raw

Until this bug is properly sorted out, would it be a good idea to revert e6b81a0ce7fb86cf1f1db9f80b982c9b5f95c4c1 and 20db5ea2eee38b123c9641003fe55c895a1fd514 for the time being? The assembly code worked fine the way it was before. At least I never had any issues with it.

Alec

author
#2 lore raw
Quoted 1 line · Alec Ari

Until this bug is properly sorted out, would it be a good idea to revert e6b81a0ce7fb86cf1f1db9f80b982c9b5f95c4c1 and 20db5ea2eee38b123c9641003fe55c895a1fd514 for the time being? The assembly code worked fine the way it was before. At least I never had any issues with it.

Those two commits install fundamental features of the I-pipe patch set, you can't reasonably run Xenomai without them. E.g., hell will break loose if a Xenomai thread triggers a memory-mapped file access fault during startup while it happened to be in RT mode. And debugging will not work either.

The proposed fix may not yet be optimal, but it is apparently sufficient.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux
#3 lore raw
Quoted 2 lines

Those two commits install fundamental features of the I-pipe patch set, you can't reasonably run Xenomai without them.

The 3.18.20-x86-9 patch for example works just fine, and the only function I see that's related to e6b81a0ce7fb86cf1f1db9f80b982c9b5f95c4c1in that patch is __ipipe_trap_prologue.

I only took a quick glance at any of this so don't mind me, but all those trapnrs weren't added to entry_64.S previously, and there wasn't massive breakage everywhere.

Assembly isn't my thing so my best bet is to just use whatever worked before, but if the fix is sufficient, then never mind. :)

Alec

#4 lore raw
In reply to Jan Kiszka
Quoted 11 lines · Jan Kiszka

Also hook into the trap path when the exception was taken over userspace code.

Fixes e6b81a0ce7fb (x86: ipipe: route traps to co-kernel)

---

Makes sense? I'm not feeling 100% safe yet /wrt paranoid and the userspace path. Should we handle this identically to the kernel path or not?

It looks ok to me. We should always branch to error_exit in the paranoid case for the user path, never taking the fast path out. This is particularly important for handling debug traps properly.

Signature · 1 line
Philippe.
#5 lore raw
In reply to Jan Kiszka

Hey,

looks like this one is for the #PF from the sigdebug smokey test. With this patch applied i do not see the crash anymore, but the test gets stuck.
Did it work for you, or did i get the context wrong?

Henning

Am Wed, 10 Oct 2018 13:05:28 +0200
schrieb Jan Kiszka <[email protected]>:

Quoted 159 lines

Also hook into the trap path when the exception was taken over userspace code.

Fixes e6b81a0ce7fb (x86: ipipe: route traps to co-kernel)

---

Makes sense? I'm not feeling 100% safe yet /wrt paranoid and the userspace path. Should we handle this identically to the kernel path or not?

Eventually this should be merged into the original patch, at least on next major rebase.

 arch/x86/entry/entry_64.S | 80

+++++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 34 deletions(-)

arch/x86/entry/entry_64.S +1 -0
index f6fe849d66ed..42e31d1fddc6 100644
@@ -904,6 +904,46 @@ ENTRY(switch_to_thread_stack)
 	ret
 END(switch_to_thread_stack)
 
+.macro ipipe_idtentry_prologue paranoid=0 trapnr=-1

skip_label=-invalid- +#ifdef CONFIG_IPIPE

arch/x86/entry/entry_64.S +1 -0
+	movq	EFLAGS(%rsp), %r14		/* regs->flags

*/

arch/x86/entry/entry_64.S +1 -0
+	movq	%rsp, %rdi			/* pt_regs

pointer */

arch/x86/entry/entry_64.S +1 -0
+	movl	$\trapnr, %esi			/* trap

number */

arch/x86/entry/entry_64.S +5 -0
+	subq	$8, %rsp
+	movq	%rsp, %rdx			/* &flags */
+	call	__ipipe_trap_prologue
+	popq	%r13
+	mov	%rax, %r12			/* save

propagation status */

arch/x86/entry/entry_64.S +1 -0
+	.if \paranoid == 0			/* paranoid may

not skip handler */

arch/x86/entry/entry_64.S +2 -0
+	testl	%eax, %eax
+	jg	\skip_label			/* skip regular

handler if > 0 */

arch/x86/entry/entry_64.S +9 -0
+	.endif
+#endif
+.endm
+
+.macro ipipe_idtentry_epilogue paranoid=0 skip_label=-invalid-
+#ifdef CONFIG_IPIPE
+	testl	%r12d, %r12d
+	jnz	1000f
+	movq	%rsp, %rdi			/* pt_regs

pointer */

arch/x86/entry/entry_64.S +1 -0
+	movq	%r13, %rsi			/* &flags from

prologue */

arch/x86/entry/entry_64.S +1 -0
+	movq	%r14, %rdx			/* original

regs->flags before fixup */

arch/x86/entry/entry_64.S +3 -0
+	call	__ipipe_trap_epilogue
+1000:
+	.if \paranoid == 0			/* paranoid

implies normal epilogue */

arch/x86/entry/entry_64.S +6 -0
+	testl	%r12d, %r12d
+	jz	1001f
+\skip_label:
+	UNWIND_HINT_REGS
+	DISABLE_INTERRUPTS(CLBR_ANY)
+	testl	%ebx, %ebx	/* %ebx: return to kernel

mode */

arch/x86/entry/entry_64.S +7 -0
+	jnz	retint_kernel_early
+	jmp	retint_user_early
+	.endif
+1001:
+#endif
+.endm
+
 .macro idtentry sym do_sym has_error_code:req paranoid=0

shift_ist=-1 trapnr=-1 ENTRY(\sym)

arch/x86/entry/entry_64.S +0 -3
 	UNWIND_HINT_IRET_REGS offset=\has_error_code*8
@@ -940,20 +980,7 @@ ENTRY(\sym)
 	.endif
 	.endif
 
-#ifdef CONFIG_IPIPE
-	movq	EFLAGS(%rsp), %r14		/* regs->flags
 */
-	movq	%rsp, %rdi			/* pt_regs

pointer */

arch/x86/entry/entry_64.S +0 -1
-	movl	$\trapnr, %esi			/* trap

number */

arch/x86/entry/entry_64.S +0 -5
-	subq	$8, %rsp
-	movq	%rsp, %rdx			/* &flags */
-	call	__ipipe_trap_prologue
-	popq	%r13
-	mov	%rax, %r12			/* save

propagation status */

arch/x86/entry/entry_64.S +0 -1
-	.if \paranoid == 0			/* paranoid may

not skip handler */

arch/x86/entry/entry_64.S +0 -2
-	testl	%eax, %eax
-	jg	98f				/* skip regular

handler if > 0 */

arch/x86/entry/entry_64.S +1 -2
-	.endif
-#endif
+	ipipe_idtentry_prologue paranoid=\paranoid trapnr=\trapnr

skip_label=kernel_skip_\@
movq %rsp, %rdi /* pt_regs
pointer */

arch/x86/entry/entry_64.S +0 -4
@@ -970,26 +997,7 @@ ENTRY(\sym)
 
 	call	\do_sym
 
-#ifdef CONFIG_IPIPE
-	testl	%r12d, %r12d
-	jnz	97f
-	movq	%rsp, %rdi			/* pt_regs

pointer */

arch/x86/entry/entry_64.S +0 -1
-	movq	%r13, %rsi			/* &flags from

prologue */

arch/x86/entry/entry_64.S +0 -1
-	movq	%r14, %rdx			/* original

regs->flags before fixup */

arch/x86/entry/entry_64.S +0 -3
-	call	__ipipe_trap_epilogue
-97:
-	.if \paranoid == 0			/* paranoid

implies normal epilogue */

arch/x86/entry/entry_64.S +0 -6
-	testl	%r12d, %r12d
-	jz	99f
-98:
-	UNWIND_HINT_REGS
-	DISABLE_INTERRUPTS(CLBR_ANY)
-	testl	%ebx, %ebx	/* %ebx: return to kernel

mode */

arch/x86/entry/entry_64.S +1 -5
-	jnz	retint_kernel_early
-	jmp	retint_user_early
-	.endif
-99:
-#endif
+	ipipe_idtentry_epilogue paranoid=\paranoid

skip_label=kernel_skip_\@

arch/x86/entry/entry_64.S +1 -0
 	.if \shift_ist != -1
 	addq	$EXCEPTION_STKSZ, CPU_TSS_IST(\shift_ist)
@@ -1011,6 +1019,8 @@ ENTRY(\sym)
 .Lfrom_usermode_switch_stack_\@:
 	call	error_entry
 
+	ipipe_idtentry_prologue paranoid=\paranoid trapnr=\trapnr

skip_label=user_skip_\@ +
movq %rsp, %rdi /* pt_regs
pointer */

arch/x86/entry/entry_64.S +1 -0
 	.if \has_error_code
@@ -1022,6 +1032,8 @@ ENTRY(\sym)
 
 	call	\do_sym
 
+	ipipe_idtentry_epilogue paranoid=\paranoid

skip_label=user_skip_\@ +

arch/x86/entry/entry_64.S +0 -0
 	jmp	error_exit
 	.endif
 END(\sym)
author
#6 lore raw
Quoted 6 lines · Henning Schild

Hey,

looks like this one is for the #PF from the sigdebug smokey test. With this patch applied i do not see the crash anymore, but the test gets stuck.
Did it work for you, or did i get the context wrong?

Yes, this solved the issue for me, and I was able to finish the test. But that might be related to configuration variations (I think I sent my configuration earlier to the list).

Jan

Quoted 166 lines

Henning

Am Wed, 10 Oct 2018 13:05:28 +0200
schrieb Jan Kiszka <[email protected]>:

Quoted 159 lines

Also hook into the trap path when the exception was taken over userspace code.

Fixes e6b81a0ce7fb (x86: ipipe: route traps to co-kernel)

---

Makes sense? I'm not feeling 100% safe yet /wrt paranoid and the userspace path. Should we handle this identically to the kernel path or not?

Eventually this should be merged into the original patch, at least on next major rebase.

  arch/x86/entry/entry_64.S | 80

+++++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 34 deletions(-)

arch/x86/entry/entry_64.S +1 -0
index f6fe849d66ed..42e31d1fddc6 100644
@@ -904,6 +904,46 @@ ENTRY(switch_to_thread_stack)
  	ret
  END(switch_to_thread_stack)
 
+.macro ipipe_idtentry_prologue paranoid=0 trapnr=-1

skip_label=-invalid- +#ifdef CONFIG_IPIPE

arch/x86/entry/entry_64.S +1 -0
+	movq	EFLAGS(%rsp), %r14		/* regs->flags

*/

arch/x86/entry/entry_64.S +1 -0
+	movq	%rsp, %rdi			/* pt_regs

pointer */

arch/x86/entry/entry_64.S +1 -0
+	movl	$\trapnr, %esi			/* trap

number */

arch/x86/entry/entry_64.S +5 -0
+	subq	$8, %rsp
+	movq	%rsp, %rdx			/* &flags */
+	call	__ipipe_trap_prologue
+	popq	%r13
+	mov	%rax, %r12			/* save

propagation status */

arch/x86/entry/entry_64.S +1 -0
+	.if \paranoid == 0			/* paranoid may

not skip handler */

arch/x86/entry/entry_64.S +2 -0
+	testl	%eax, %eax
+	jg	\skip_label			/* skip regular

handler if > 0 */

arch/x86/entry/entry_64.S +9 -0
+	.endif
+#endif
+.endm
+
+.macro ipipe_idtentry_epilogue paranoid=0 skip_label=-invalid-
+#ifdef CONFIG_IPIPE
+	testl	%r12d, %r12d
+	jnz	1000f
+	movq	%rsp, %rdi			/* pt_regs

pointer */

arch/x86/entry/entry_64.S +1 -0
+	movq	%r13, %rsi			/* &flags from

prologue */

arch/x86/entry/entry_64.S +1 -0
+	movq	%r14, %rdx			/* original

regs->flags before fixup */

arch/x86/entry/entry_64.S +3 -0
+	call	__ipipe_trap_epilogue
+1000:
+	.if \paranoid == 0			/* paranoid

implies normal epilogue */

arch/x86/entry/entry_64.S +6 -0
+	testl	%r12d, %r12d
+	jz	1001f
+\skip_label:
+	UNWIND_HINT_REGS
+	DISABLE_INTERRUPTS(CLBR_ANY)
+	testl	%ebx, %ebx	/* %ebx: return to kernel

mode */

arch/x86/entry/entry_64.S +7 -0
+	jnz	retint_kernel_early
+	jmp	retint_user_early
+	.endif
+1001:
+#endif
+.endm
+
  .macro idtentry sym do_sym has_error_code:req paranoid=0

shift_ist=-1 trapnr=-1 ENTRY(\sym)
UNWIND_HINT_IRET_REGS offset=\has_error_code*8

arch/x86/entry/entry_64.S +0 -3
@@ -940,20 +980,7 @@ ENTRY(\sym)
  	.endif
  	.endif
 
-#ifdef CONFIG_IPIPE
-	movq	EFLAGS(%rsp), %r14		/* regs->flags
 */
-	movq	%rsp, %rdi			/* pt_regs

pointer */

arch/x86/entry/entry_64.S +0 -1
-	movl	$\trapnr, %esi			/* trap

number */

arch/x86/entry/entry_64.S +0 -5
-	subq	$8, %rsp
-	movq	%rsp, %rdx			/* &flags */
-	call	__ipipe_trap_prologue
-	popq	%r13
-	mov	%rax, %r12			/* save

propagation status */

arch/x86/entry/entry_64.S +0 -1
-	.if \paranoid == 0			/* paranoid may

not skip handler */

arch/x86/entry/entry_64.S +0 -2
-	testl	%eax, %eax
-	jg	98f				/* skip regular

handler if > 0 */

arch/x86/entry/entry_64.S +1 -2
-	.endif
-#endif
+	ipipe_idtentry_prologue paranoid=\paranoid trapnr=\trapnr

skip_label=kernel_skip_\@
movq %rsp, %rdi /* pt_regs
pointer */

arch/x86/entry/entry_64.S +0 -4
@@ -970,26 +997,7 @@ ENTRY(\sym)
 
  	call	\do_sym
 
-#ifdef CONFIG_IPIPE
-	testl	%r12d, %r12d
-	jnz	97f
-	movq	%rsp, %rdi			/* pt_regs

pointer */

arch/x86/entry/entry_64.S +0 -1
-	movq	%r13, %rsi			/* &flags from

prologue */

arch/x86/entry/entry_64.S +0 -1
-	movq	%r14, %rdx			/* original

regs->flags before fixup */

arch/x86/entry/entry_64.S +0 -3
-	call	__ipipe_trap_epilogue
-97:
-	.if \paranoid == 0			/* paranoid

implies normal epilogue */

arch/x86/entry/entry_64.S +0 -6
-	testl	%r12d, %r12d
-	jz	99f
-98:
-	UNWIND_HINT_REGS
-	DISABLE_INTERRUPTS(CLBR_ANY)
-	testl	%ebx, %ebx	/* %ebx: return to kernel

mode */

arch/x86/entry/entry_64.S +1 -5
-	jnz	retint_kernel_early
-	jmp	retint_user_early
-	.endif
-99:
-#endif
+	ipipe_idtentry_epilogue paranoid=\paranoid

skip_label=kernel_skip_\@
.if \shift_ist != -1
addq $EXCEPTION_STKSZ, CPU_TSS_IST(\shift_ist)

arch/x86/entry/entry_64.S +1 -0
@@ -1011,6 +1019,8 @@ ENTRY(\sym)
  .Lfrom_usermode_switch_stack_\@:
  	call	error_entry
 
+	ipipe_idtentry_prologue paranoid=\paranoid trapnr=\trapnr

skip_label=user_skip_\@ +
movq %rsp, %rdi /* pt_regs
pointer */
.if \has_error_code

arch/x86/entry/entry_64.S +1 -0
@@ -1022,6 +1032,8 @@ ENTRY(\sym)
 
  	call	\do_sym
 
+	ipipe_idtentry_epilogue paranoid=\paranoid

skip_label=user_skip_\@ +
jmp error_exit
.endif
END(\sym)

Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux
#7 lore raw

Am Fri, 26 Oct 2018 14:32:36 +0100
schrieb Jan Kiszka <[email protected]>:

Quoted 11 lines · Henning Schild
Quoted 6 lines

Hey,

looks like this one is for the #PF from the sigdebug smokey test. With this patch applied i do not see the crash anymore, but the test gets stuck.
Did it work for you, or did i get the context wrong?

Yes, this solved the issue for me, and I was able to finish the test. But that might be related to configuration variations (I think I sent my configuration earlier to the list).

I was still using a modified copy of the test, looks like it works just fine. I guess we can release if we are ok with not supporting x86_32 for now ... or for the future.

Henning

Quoted 169 lines

Jan

Quoted 166 lines

Henning

Am Wed, 10 Oct 2018 13:05:28 +0200
schrieb Jan Kiszka <[email protected]>:

Quoted 159 lines

Also hook into the trap path when the exception was taken over userspace code.

Fixes e6b81a0ce7fb (x86: ipipe: route traps to co-kernel)

---

Makes sense? I'm not feeling 100% safe yet /wrt paranoid and the userspace path. Should we handle this identically to the kernel path or not?

Eventually this should be merged into the original patch, at least on next major rebase.

  arch/x86/entry/entry_64.S | 80

+++++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 34 deletions(-)

arch/x86/entry/entry_64.S +1 -0
index f6fe849d66ed..42e31d1fddc6 100644
@@ -904,6 +904,46 @@ ENTRY(switch_to_thread_stack)
  	ret
  END(switch_to_thread_stack)
 
+.macro ipipe_idtentry_prologue paranoid=0 trapnr=-1

skip_label=-invalid- +#ifdef CONFIG_IPIPE

arch/x86/entry/entry_64.S +1 -0
+	movq	EFLAGS(%rsp), %r14		/*

regs->flags */

arch/x86/entry/entry_64.S +1 -0
+	movq	%rsp, %rdi			/* pt_regs

pointer */

arch/x86/entry/entry_64.S +1 -0
+	movl	$\trapnr, %esi			/* trap

number */

arch/x86/entry/entry_64.S +5 -0
+	subq	$8, %rsp
+	movq	%rsp, %rdx			/* &flags */
+	call	__ipipe_trap_prologue
+	popq	%r13
+	mov	%rax, %r12			/* save

propagation status */

arch/x86/entry/entry_64.S +1 -0
+	.if \paranoid == 0			/* paranoid may

not skip handler */

arch/x86/entry/entry_64.S +2 -0
+	testl	%eax, %eax
+	jg	\skip_label			/* skip

regular handler if > 0 */

arch/x86/entry/entry_64.S +9 -0
+	.endif
+#endif
+.endm
+
+.macro ipipe_idtentry_epilogue paranoid=0 skip_label=-invalid-
+#ifdef CONFIG_IPIPE
+	testl	%r12d, %r12d
+	jnz	1000f
+	movq	%rsp, %rdi			/* pt_regs

pointer */

arch/x86/entry/entry_64.S +1 -0
+	movq	%r13, %rsi			/* &flags

from prologue */

arch/x86/entry/entry_64.S +1 -0
+	movq	%r14, %rdx			/* original

regs->flags before fixup */

arch/x86/entry/entry_64.S +3 -0
+	call	__ipipe_trap_epilogue
+1000:
+	.if \paranoid == 0			/* paranoid

implies normal epilogue */

arch/x86/entry/entry_64.S +6 -0
+	testl	%r12d, %r12d
+	jz	1001f
+\skip_label:
+	UNWIND_HINT_REGS
+	DISABLE_INTERRUPTS(CLBR_ANY)
+	testl	%ebx, %ebx	/* %ebx: return to kernel

mode */

arch/x86/entry/entry_64.S +7 -0
+	jnz	retint_kernel_early
+	jmp	retint_user_early
+	.endif
+1001:
+#endif
+.endm
+
  .macro idtentry sym do_sym has_error_code:req paranoid=0

shift_ist=-1 trapnr=-1 ENTRY(\sym)
UNWIND_HINT_IRET_REGS offset=\has_error_code*8

arch/x86/entry/entry_64.S +0 -2
@@ -940,20 +980,7 @@ ENTRY(\sym)
  	.endif
  	.endif
 
-#ifdef CONFIG_IPIPE
-	movq	EFLAGS(%rsp), %r14		/*

regs->flags */

arch/x86/entry/entry_64.S +0 -1
-	movq	%rsp, %rdi			/* pt_regs

pointer */

arch/x86/entry/entry_64.S +0 -1
-	movl	$\trapnr, %esi			/* trap

number */

arch/x86/entry/entry_64.S +0 -5
-	subq	$8, %rsp
-	movq	%rsp, %rdx			/* &flags */
-	call	__ipipe_trap_prologue
-	popq	%r13
-	mov	%rax, %r12			/* save

propagation status */

arch/x86/entry/entry_64.S +0 -1
-	.if \paranoid == 0			/* paranoid may

not skip handler */

arch/x86/entry/entry_64.S +0 -2
-	testl	%eax, %eax
-	jg	98f				/* skip

regular handler if > 0 */

arch/x86/entry/entry_64.S +1 -2
-	.endif
-#endif
+	ipipe_idtentry_prologue paranoid=\paranoid trapnr=\trapnr

skip_label=kernel_skip_\@
movq %rsp, %rdi /* pt_regs
pointer */

arch/x86/entry/entry_64.S +0 -4
@@ -970,26 +997,7 @@ ENTRY(\sym)
 
  	call	\do_sym
 
-#ifdef CONFIG_IPIPE
-	testl	%r12d, %r12d
-	jnz	97f
-	movq	%rsp, %rdi			/* pt_regs

pointer */

arch/x86/entry/entry_64.S +0 -1
-	movq	%r13, %rsi			/* &flags

from prologue */

arch/x86/entry/entry_64.S +0 -1
-	movq	%r14, %rdx			/* original

regs->flags before fixup */

arch/x86/entry/entry_64.S +0 -3
-	call	__ipipe_trap_epilogue
-97:
-	.if \paranoid == 0			/* paranoid

implies normal epilogue */

arch/x86/entry/entry_64.S +0 -6
-	testl	%r12d, %r12d
-	jz	99f
-98:
-	UNWIND_HINT_REGS
-	DISABLE_INTERRUPTS(CLBR_ANY)
-	testl	%ebx, %ebx	/* %ebx: return to kernel

mode */

arch/x86/entry/entry_64.S +1 -5
-	jnz	retint_kernel_early
-	jmp	retint_user_early
-	.endif
-99:
-#endif
+	ipipe_idtentry_epilogue paranoid=\paranoid

skip_label=kernel_skip_\@
.if \shift_ist != -1
addq $EXCEPTION_STKSZ, CPU_TSS_IST(\shift_ist)

arch/x86/entry/entry_64.S +1 -0
@@ -1011,6 +1019,8 @@ ENTRY(\sym)
  .Lfrom_usermode_switch_stack_\@:
  	call	error_entry
 
+	ipipe_idtentry_prologue paranoid=\paranoid trapnr=\trapnr

skip_label=user_skip_\@ +
movq %rsp, %rdi /* pt_regs
pointer */
.if \has_error_code

arch/x86/entry/entry_64.S +1 -0
@@ -1022,6 +1032,8 @@ ENTRY(\sym)
 
  	call	\do_sym
 
+	ipipe_idtentry_epilogue paranoid=\paranoid

skip_label=user_skip_\@ +
jmp error_exit
.endif
END(\sym)