Skip to content

Commit 819771c

Browse files
mrutland-armwilldeacon
authored andcommitted
arm64: extable: consolidate definitions
In subsequent patches we'll alter the structure and usage of struct exception_table_entry. For inline assembly, we create these using the `_ASM_EXTABLE()` CPP macro defined in <asm/uaccess.h>, and for plain assembly code we use the `_asm_extable()` GAS macro defined in <asm/assembler.h>, which are largely identical save for different escaping and stringification requirements. This patch moves the common definitions to a new <asm/asm-extable.h> header, so that it's easier to keep the two in-sync, and to remove the implication that these are only used for uaccess helpers (as e.g. load_unaligned_zeropad() is only used on kernel memory, and depends upon `_ASM_EXTABLE()`. At the same time, a few minor modifications are made for clarity and in preparation for subsequent patches: * The structure creation is factored out into an `__ASM_EXTABLE_RAW()` macro. This will make it easier to support different fixup variants in subsequent patches without needing to update all users of `_ASM_EXTABLE()`, and makes it easier to see tha the CPP and GAS variants of the macros are structurally identical. For the CPP macro, the stringification of fields is left to the wrapper macro, `_ASM_EXTABLE()`, as in subsequent patches it will be necessary to stringify fields in wrapper macros to safely concatenate strings which cannot be token-pasted together in CPP. * The fields of the structure are created separately on their own lines. This will make it easier to add/remove/modify individual fields clearly. * Additional parentheses are added around the use of macro arguments in field definitions to avoid any potential problems with evaluation due to operator precedence, and to make errors upon misuse clearer. * USER() is moved into <asm/asm-uaccess.h>, as it is not required by all assembly code, and is already refered to by comments in that file. There should be no functional change as a result of this patch. Signed-off-by: Mark Rutland <[email protected]> Reviewed-by: Ard Biesheuvel <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: James Morse <[email protected]> Cc: Robin Murphy <[email protected]> Cc: Will Deacon <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 286fba6 commit 819771c

File tree

5 files changed

+58
-35
lines changed

5 files changed

+58
-35
lines changed

arch/arm64/include/asm/asm-extable.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
#ifndef __ASM_ASM_EXTABLE_H
3+
#define __ASM_ASM_EXTABLE_H
4+
5+
#ifdef __ASSEMBLY__
6+
7+
#define __ASM_EXTABLE_RAW(insn, fixup) \
8+
.pushsection __ex_table, "a"; \
9+
.align 3; \
10+
.long ((insn) - .); \
11+
.long ((fixup) - .); \
12+
.popsection;
13+
14+
/*
15+
* Create an exception table entry for `insn`, which will branch to `fixup`
16+
* when an unhandled fault is taken.
17+
*/
18+
.macro _asm_extable, insn, fixup
19+
__ASM_EXTABLE_RAW(\insn, \fixup)
20+
.endm
21+
22+
/*
23+
* Create an exception table entry for `insn` if `fixup` is provided. Otherwise
24+
* do nothing.
25+
*/
26+
.macro _cond_extable, insn, fixup
27+
.ifnc \fixup,
28+
_asm_extable \insn, \fixup
29+
.endif
30+
.endm
31+
32+
#else /* __ASSEMBLY__ */
33+
34+
#include <linux/stringify.h>
35+
36+
#define __ASM_EXTABLE_RAW(insn, fixup) \
37+
".pushsection __ex_table, \"a\"\n" \
38+
".align 3\n" \
39+
".long ((" insn ") - .)\n" \
40+
".long ((" fixup ") - .)\n" \
41+
".popsection\n"
42+
43+
#define _ASM_EXTABLE(insn, fixup) \
44+
__ASM_EXTABLE_RAW(#insn, #fixup)
45+
46+
#endif /* __ASSEMBLY__ */
47+
48+
#endif /* __ASM_ASM_EXTABLE_H */

arch/arm64/include/asm/asm-uaccess.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
#define __ASM_ASM_UACCESS_H
44

55
#include <asm/alternative-macros.h>
6+
#include <asm/asm-extable.h>
7+
#include <asm/assembler.h>
68
#include <asm/kernel-pgtable.h>
79
#include <asm/mmu.h>
810
#include <asm/sysreg.h>
9-
#include <asm/assembler.h>
1011

1112
/*
1213
* User access enabling/disabling macros.
@@ -58,6 +59,10 @@ alternative_else_nop_endif
5859
.endm
5960
#endif
6061

62+
#define USER(l, x...) \
63+
9999: x; \
64+
_asm_extable 9999b, l
65+
6166
/*
6267
* Generate the assembly for LDTR/STTR with exception table entries.
6368
* This is complicated as there is no post-increment or pair versions of the

arch/arm64/include/asm/assembler.h

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414

1515
#include <asm-generic/export.h>
1616

17-
#include <asm/asm-offsets.h>
1817
#include <asm/alternative.h>
1918
#include <asm/asm-bug.h>
19+
#include <asm/asm-extable.h>
20+
#include <asm/asm-offsets.h>
2021
#include <asm/cpufeature.h>
2122
#include <asm/cputype.h>
2223
#include <asm/debug-monitors.h>
@@ -129,32 +130,6 @@ alternative_endif
129130
.endr
130131
.endm
131132

132-
/*
133-
* Create an exception table entry for `insn`, which will branch to `fixup`
134-
* when an unhandled fault is taken.
135-
*/
136-
.macro _asm_extable, insn, fixup
137-
.pushsection __ex_table, "a"
138-
.align 3
139-
.long (\insn - .), (\fixup - .)
140-
.popsection
141-
.endm
142-
143-
/*
144-
* Create an exception table entry for `insn` if `fixup` is provided. Otherwise
145-
* do nothing.
146-
*/
147-
.macro _cond_extable, insn, fixup
148-
.ifnc \fixup,
149-
_asm_extable \insn, \fixup
150-
.endif
151-
.endm
152-
153-
154-
#define USER(l, x...) \
155-
9999: x; \
156-
_asm_extable 9999b, l
157-
158133
/*
159134
* Register aliases.
160135
*/

arch/arm64/include/asm/uaccess.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/kasan-checks.h>
1919
#include <linux/string.h>
2020

21+
#include <asm/asm-extable.h>
2122
#include <asm/cpufeature.h>
2223
#include <asm/mmu.h>
2324
#include <asm/mte.h>
@@ -70,12 +71,6 @@ static inline unsigned long __range_ok(const void __user *addr, unsigned long si
7071

7172
#define access_ok(addr, size) __range_ok(addr, size)
7273

73-
#define _ASM_EXTABLE(from, to) \
74-
" .pushsection __ex_table, \"a\"\n" \
75-
" .align 3\n" \
76-
" .long (" #from " - .), (" #to " - .)\n" \
77-
" .popsection\n"
78-
7974
/*
8075
* User access enabling/disabling.
8176
*/

arch/arm64/lib/clear_user.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
#include <linux/linkage.h>
7-
#include <asm/assembler.h>
7+
#include <asm/asm-uaccess.h>
88

99
.text
1010

0 commit comments

Comments
 (0)