Skip to content

Commit 3d66718

Browse files
hcahcaVasily Gorbik
authored andcommitted
s390/extable: convert to relative table with data
Follow arm64, riscv, and x86 and change extable layout to common "relative table with data". This allows to get rid of s390 specific code in sorttable.c. The main difference to before is that extable entries do not contain a relative function pointer anymore. Instead data and type fields are added. The type field is used to indicate which exception handler needs to be called, while the data field is currently unused. Acked-by: Alexander Gordeev <agordeev@linux.ibm.com> Signed-off-by: Heiko Carstens <hca@linux.ibm.com> Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
1 parent 46fee16 commit 3d66718

5 files changed

Lines changed: 46 additions & 74 deletions

File tree

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,22 @@
55
#include <linux/stringify.h>
66
#include <asm/asm-const.h>
77

8-
#define __EX_TABLE(_section, _fault, _target) \
8+
#define EX_TYPE_NONE 0
9+
#define EX_TYPE_FIXUP 1
10+
#define EX_TYPE_BPF 2
11+
12+
#define __EX_TABLE(_section, _fault, _target, _type) \
913
stringify_in_c(.section _section,"a";) \
10-
stringify_in_c(.align 8;) \
14+
stringify_in_c(.align 4;) \
1115
stringify_in_c(.long (_fault) - .;) \
1216
stringify_in_c(.long (_target) - .;) \
13-
stringify_in_c(.quad 0;) \
17+
stringify_in_c(.short (_type);) \
18+
stringify_in_c(.short 0;) \
1419
stringify_in_c(.previous)
1520

1621
#define EX_TABLE(_fault, _target) \
17-
__EX_TABLE(__ex_table, _fault, _target)
22+
__EX_TABLE(__ex_table, _fault, _target, EX_TYPE_FIXUP)
1823
#define EX_TABLE_AMODE31(_fault, _target) \
19-
__EX_TABLE(.amode31.ex_table, _fault, _target)
24+
__EX_TABLE(.amode31.ex_table, _fault, _target, EX_TYPE_FIXUP)
2025

2126
#endif /* __ASM_EXTABLE_H */

arch/s390/include/asm/extable.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
struct exception_table_entry
2626
{
2727
int insn, fixup;
28-
long handler;
28+
short type, data;
2929
};
3030

3131
extern struct exception_table_entry *__start_amode31_ex_table;
@@ -38,17 +38,6 @@ static inline unsigned long extable_fixup(const struct exception_table_entry *x)
3838
return (unsigned long)&x->fixup + x->fixup;
3939
}
4040

41-
typedef bool (*ex_handler_t)(const struct exception_table_entry *,
42-
struct pt_regs *);
43-
44-
static inline ex_handler_t
45-
ex_fixup_handler(const struct exception_table_entry *x)
46-
{
47-
if (likely(!x->handler))
48-
return NULL;
49-
return (ex_handler_t)((unsigned long)&x->handler + x->handler);
50-
}
51-
5241
#define ARCH_HAS_RELATIVE_EXTABLE
5342

5443
static inline void swap_ex_entry_fixup(struct exception_table_entry *a,
@@ -58,15 +47,26 @@ static inline void swap_ex_entry_fixup(struct exception_table_entry *a,
5847
{
5948
a->fixup = b->fixup + delta;
6049
b->fixup = tmp.fixup - delta;
61-
a->handler = b->handler;
62-
if (a->handler)
63-
a->handler += delta;
64-
b->handler = tmp.handler;
65-
if (b->handler)
66-
b->handler -= delta;
50+
a->type = b->type;
51+
b->type = tmp.type;
52+
a->data = b->data;
53+
b->data = tmp.data;
6754
}
6855
#define swap_ex_entry_fixup swap_ex_entry_fixup
6956

57+
#ifdef CONFIG_BPF_JIT
58+
59+
bool ex_handler_bpf(const struct exception_table_entry *ex, struct pt_regs *regs);
60+
61+
#else /* !CONFIG_BPF_JIT */
62+
63+
static inline bool ex_handler_bpf(const struct exception_table_entry *ex, struct pt_regs *regs)
64+
{
65+
return false;
66+
}
67+
68+
#endif /* CONFIG_BPF_JIT */
69+
7070
bool fixup_exception(struct pt_regs *regs);
7171

7272
#endif

arch/s390/mm/extable.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// SPDX-License-Identifier: GPL-2.0
22

33
#include <linux/extable.h>
4+
#include <linux/panic.h>
5+
#include <asm/asm-extable.h>
46
#include <asm/extable.h>
57

68
const struct exception_table_entry *s390_search_extables(unsigned long addr)
@@ -15,17 +17,24 @@ const struct exception_table_entry *s390_search_extables(unsigned long addr)
1517
return search_extable(__start_amode31_ex_table, num, addr);
1618
}
1719

20+
static bool ex_handler_fixup(const struct exception_table_entry *ex, struct pt_regs *regs)
21+
{
22+
regs->psw.addr = extable_fixup(ex);
23+
return true;
24+
}
25+
1826
bool fixup_exception(struct pt_regs *regs)
1927
{
2028
const struct exception_table_entry *ex;
21-
ex_handler_t handler;
2229

2330
ex = s390_search_extables(instruction_pointer(regs));
2431
if (!ex)
2532
return false;
26-
handler = ex_fixup_handler(ex);
27-
if (unlikely(handler))
28-
return handler(ex, regs);
29-
regs->psw.addr = extable_fixup(ex);
30-
return true;
33+
switch (ex->type) {
34+
case EX_TYPE_FIXUP:
35+
return ex_handler_fixup(ex, regs);
36+
case EX_TYPE_BPF:
37+
return ex_handler_bpf(ex, regs);
38+
}
39+
panic("invalid exception table entry");
3140
}

arch/s390/net/bpf_jit_comp.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -622,8 +622,7 @@ static int get_probe_mem_regno(const u8 *insn)
622622
return insn[1] >> 4;
623623
}
624624

625-
static bool ex_handler_bpf(const struct exception_table_entry *x,
626-
struct pt_regs *regs)
625+
bool ex_handler_bpf(const struct exception_table_entry *x, struct pt_regs *regs)
627626
{
628627
int regno;
629628
u8 *insn;
@@ -678,7 +677,7 @@ static int bpf_jit_probe_mem(struct bpf_jit *jit, struct bpf_prog *fp,
678677
/* JIT bug - landing pad and extable must be close. */
679678
return -1;
680679
ex->fixup = delta;
681-
ex->handler = (u8 *)ex_handler_bpf - (u8 *)&ex->handler;
680+
ex->type = EX_TYPE_BPF;
682681
jit->excnt++;
683682
}
684683
return 0;

scripts/sorttable.c

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -261,45 +261,6 @@ static void sort_relative_table_with_data(char *extab_image, int image_size)
261261
}
262262
}
263263

264-
static void s390_sort_relative_table(char *extab_image, int image_size)
265-
{
266-
int i;
267-
268-
for (i = 0; i < image_size; i += 16) {
269-
char *loc = extab_image + i;
270-
uint64_t handler;
271-
272-
w(r((uint32_t *)loc) + i, (uint32_t *)loc);
273-
w(r((uint32_t *)(loc + 4)) + (i + 4), (uint32_t *)(loc + 4));
274-
/*
275-
* 0 is a special self-relative handler value, which means that
276-
* handler should be ignored. It is safe, because it means that
277-
* handler field points to itself, which should never happen.
278-
* When creating extable-relative values, keep it as 0, since
279-
* this should never occur either: it would mean that handler
280-
* field points to the first extable entry.
281-
*/
282-
handler = r8((uint64_t *)(loc + 8));
283-
if (handler)
284-
handler += i + 8;
285-
w8(handler, (uint64_t *)(loc + 8));
286-
}
287-
288-
qsort(extab_image, image_size / 16, 16, compare_relative_table);
289-
290-
for (i = 0; i < image_size; i += 16) {
291-
char *loc = extab_image + i;
292-
uint64_t handler;
293-
294-
w(r((uint32_t *)loc) - i, (uint32_t *)loc);
295-
w(r((uint32_t *)(loc + 4)) - (i + 4), (uint32_t *)(loc + 4));
296-
handler = r8((uint64_t *)(loc + 8));
297-
if (handler)
298-
handler -= i + 8;
299-
w8(handler, (uint64_t *)(loc + 8));
300-
}
301-
}
302-
303264
static int do_file(char const *const fname, void *addr)
304265
{
305266
int rc = -1;
@@ -340,12 +301,10 @@ static int do_file(char const *const fname, void *addr)
340301
case EM_386:
341302
case EM_AARCH64:
342303
case EM_RISCV:
304+
case EM_S390:
343305
case EM_X86_64:
344306
custom_sort = sort_relative_table_with_data;
345307
break;
346-
case EM_S390:
347-
custom_sort = s390_sort_relative_table;
348-
break;
349308
case EM_PARISC:
350309
case EM_PPC:
351310
case EM_PPC64:

0 commit comments

Comments
 (0)