Skip to content

Commit aa93e2a

Browse files
author
Peter Zijlstra
committed
x86/entry_32: Remove .fixup usage
Where possible, push the .fixup into code, at the tail of functions. This is hard for macros since they're used in multiple functions, therefore introduce a new extable handler to pop zeros. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Josh Poimboeuf <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 16e617d commit aa93e2a

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

arch/x86/entry/entry_32.S

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -270,17 +270,9 @@
270270
3: popl %fs
271271
addl $(4 + \pop), %esp /* pop the unused "gs" slot */
272272
IRET_FRAME
273-
.pushsection .fixup, "ax"
274-
4: movl $0, (%esp)
275-
jmp 1b
276-
5: movl $0, (%esp)
277-
jmp 2b
278-
6: movl $0, (%esp)
279-
jmp 3b
280-
.popsection
281-
_ASM_EXTABLE(1b, 4b)
282-
_ASM_EXTABLE(2b, 5b)
283-
_ASM_EXTABLE(3b, 6b)
273+
_ASM_EXTABLE_TYPE(1b, 1b, EX_TYPE_POP_ZERO)
274+
_ASM_EXTABLE_TYPE(2b, 2b, EX_TYPE_POP_ZERO)
275+
_ASM_EXTABLE_TYPE(3b, 3b, EX_TYPE_POP_ZERO)
284276
.endm
285277

286278
.macro RESTORE_ALL_NMI cr3_reg:req pop=0
@@ -925,10 +917,8 @@ SYM_FUNC_START(entry_SYSENTER_32)
925917
sti
926918
sysexit
927919

928-
.pushsection .fixup, "ax"
929-
2: movl $0, PT_FS(%esp)
930-
jmp 1b
931-
.popsection
920+
2: movl $0, PT_FS(%esp)
921+
jmp 1b
932922
_ASM_EXTABLE(1b, 2b)
933923

934924
.Lsysenter_fix_flags:
@@ -996,8 +986,7 @@ restore_all_switch_stack:
996986
*/
997987
iret
998988

999-
.section .fixup, "ax"
1000-
SYM_CODE_START(asm_iret_error)
989+
.Lasm_iret_error:
1001990
pushl $0 # no error code
1002991
pushl $iret_error
1003992

@@ -1014,9 +1003,8 @@ SYM_CODE_START(asm_iret_error)
10141003
#endif
10151004

10161005
jmp handle_exception
1017-
SYM_CODE_END(asm_iret_error)
1018-
.previous
1019-
_ASM_EXTABLE(.Lirq_return, asm_iret_error)
1006+
1007+
_ASM_EXTABLE(.Lirq_return, .Lasm_iret_error)
10201008
SYM_FUNC_END(entry_INT80_32)
10211009

10221010
.macro FIXUP_ESPFIX_STACK

arch/x86/include/asm/extable_fixup_types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@
1919
#define EX_TYPE_DEFAULT_MCE_SAFE 12
2020
#define EX_TYPE_FAULT_MCE_SAFE 13
2121

22+
#define EX_TYPE_POP_ZERO 14
23+
2224
#endif

arch/x86/mm/extable.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,18 @@ static bool ex_handler_clear_fs(const struct exception_table_entry *fixup,
9999
return ex_handler_default(fixup, regs);
100100
}
101101

102+
static bool ex_handler_pop_zero(const struct exception_table_entry *fixup,
103+
struct pt_regs *regs)
104+
{
105+
/*
106+
* Typically used for when "pop %seg" traps, in which case we'll clear
107+
* the stack slot and re-try the instruction, which will then succeed
108+
* to pop zero.
109+
*/
110+
*((unsigned long *)regs->sp) = 0;
111+
return ex_handler_default(fixup, regs);
112+
}
113+
102114
int ex_get_fixup_type(unsigned long ip)
103115
{
104116
const struct exception_table_entry *e = search_exception_tables(ip);
@@ -156,6 +168,8 @@ int fixup_exception(struct pt_regs *regs, int trapnr, unsigned long error_code,
156168
case EX_TYPE_WRMSR_IN_MCE:
157169
ex_handler_msr_mce(regs, true);
158170
break;
171+
case EX_TYPE_POP_ZERO:
172+
return ex_handler_pop_zero(e, regs);
159173
}
160174
BUG();
161175
}

0 commit comments

Comments
 (0)