Skip to content

Commit 2465bb8

Browse files
author
Alexei Starovoitov
committed
Merge branch 's390-bpf-add-s390-jit-support-for-timed-may_goto'
Ilya Leoshkevich says: ==================== s390/bpf: Add s390 JIT support for timed may_goto v1: https://lore.kernel.org/bpf/[email protected]/ v1 -> v2: Fix test_stream_errors (caught by CI). This series adds timed may_goto implementation to the s390x JIT. Patch 1 is the implementation itself, patches 2-5 are the associated test changes. ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
2 parents d0f27ff + 21bce56 commit 2465bb8

File tree

8 files changed

+81
-10
lines changed

8 files changed

+81
-10
lines changed

arch/s390/net/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
#
33
# Arch-specific network modules
44
#
5-
obj-$(CONFIG_BPF_JIT) += bpf_jit_comp.o
5+
obj-$(CONFIG_BPF_JIT) += bpf_jit_comp.o bpf_timed_may_goto.o
66
obj-$(CONFIG_HAVE_PNETID) += pnet.o

arch/s390/net/bpf_jit_comp.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,10 +1806,22 @@ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp,
18061806
}
18071807
}
18081808

1809-
/* brasl %r14,func */
1810-
EMIT6_PCREL_RILB_PTR(0xc0050000, REG_14, (void *)func);
1811-
/* lgr %b0,%r2: load return value into %b0 */
1812-
EMIT4(0xb9040000, BPF_REG_0, REG_2);
1809+
if ((void *)func == arch_bpf_timed_may_goto) {
1810+
/*
1811+
* arch_bpf_timed_may_goto() has a special ABI: the
1812+
* parameters are in BPF_REG_AX and BPF_REG_10; the
1813+
* return value is in BPF_REG_AX; and all GPRs except
1814+
* REG_W0, REG_W1, and BPF_REG_AX are callee-saved.
1815+
*/
1816+
1817+
/* brasl %r0,func */
1818+
EMIT6_PCREL_RILB_PTR(0xc0050000, REG_0, (void *)func);
1819+
} else {
1820+
/* brasl %r14,func */
1821+
EMIT6_PCREL_RILB_PTR(0xc0050000, REG_14, (void *)func);
1822+
/* lgr %b0,%r2: load return value into %b0 */
1823+
EMIT4(0xb9040000, BPF_REG_0, REG_2);
1824+
}
18131825

18141826
/*
18151827
* Copy the potentially updated tail call counter back.
@@ -2993,3 +3005,8 @@ void arch_bpf_stack_walk(bool (*consume_fn)(void *, u64, u64, u64),
29933005
prev_addr = addr;
29943006
}
29953007
}
3008+
3009+
bool bpf_jit_supports_timed_may_goto(void)
3010+
{
3011+
return true;
3012+
}

arch/s390/net/bpf_timed_may_goto.S

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
3+
#include <linux/export.h>
4+
#include <linux/linkage.h>
5+
#include <asm/asm-offsets.h>
6+
#include <asm/nospec-insn.h>
7+
8+
#define R2_OFF 0
9+
#define R5_OFF (R2_OFF + (5 - 2 + 1) * 8)
10+
#define R14_OFF (R5_OFF + 8)
11+
#define RETADDR_OFF (R14_OFF + 8)
12+
#define R15_OFF (RETADDR_OFF + 8)
13+
#define BACKCHAIN_OFF (R15_OFF + 8)
14+
#define FRAME_SIZE (BACKCHAIN_OFF + 8)
15+
#define FRAME_OFF (STACK_FRAME_OVERHEAD - FRAME_SIZE)
16+
#if (FRAME_OFF + BACKCHAIN_OFF) != __SF_BACKCHAIN
17+
#error Stack frame layout calculation is broken
18+
#endif
19+
20+
GEN_BR_THUNK %r1
21+
22+
SYM_FUNC_START(arch_bpf_timed_may_goto)
23+
/*
24+
* This function has a special ABI: the parameters are in %r12 and
25+
* %r13; the return value is in %r12; all GPRs except %r0, %r1, and
26+
* %r12 are callee-saved; and the return address is in %r0.
27+
*/
28+
stmg %r2,%r5,FRAME_OFF+R2_OFF(%r15)
29+
stg %r14,FRAME_OFF+R14_OFF(%r15)
30+
stg %r0,FRAME_OFF+RETADDR_OFF(%r15)
31+
stg %r15,FRAME_OFF+R15_OFF(%r15)
32+
lgr %r1,%r15
33+
lay %r15,-FRAME_SIZE(%r15)
34+
stg %r1,__SF_BACKCHAIN(%r15)
35+
36+
lay %r2,0(%r12,%r13)
37+
brasl %r14,bpf_check_timed_may_goto
38+
lgr %r12,%r2
39+
40+
lg %r15,FRAME_SIZE+FRAME_OFF+R15_OFF(%r15)
41+
lmg %r2,%r5,FRAME_OFF+R2_OFF(%r15)
42+
lg %r14,FRAME_OFF+R14_OFF(%r15)
43+
lg %r1,FRAME_OFF+RETADDR_OFF(%r15)
44+
BR_EX %r1
45+
SYM_FUNC_END(arch_bpf_timed_may_goto)

tools/testing/selftests/bpf/DENYLIST.s390x

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
# Alphabetical order
33
get_stack_raw_tp # user_stack corrupted user stack (no backchain userspace)
44
stacktrace_build_id # compare_map_keys stackid_hmap vs. stackmap err -2 errno 2 (?)
5-
verifier_iterating_callbacks

tools/testing/selftests/bpf/prog_tests/stream.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void test_stream_errors(void)
7777
ASSERT_OK(ret, "ret");
7878
ASSERT_OK(opts.retval, "retval");
7979

80-
#if !defined(__x86_64__)
80+
#if !defined(__x86_64__) && !defined(__s390x__)
8181
ASSERT_TRUE(1, "Timed may_goto unsupported, skip.");
8282
if (i == 0) {
8383
ret = bpf_prog_stream_read(prog_fd, 2, buf, sizeof(buf), &ropts);

tools/testing/selftests/bpf/progs/bpf_misc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
#define __arch_x86_64 __arch("X86_64")
137137
#define __arch_arm64 __arch("ARM64")
138138
#define __arch_riscv64 __arch("RISCV64")
139+
#define __arch_s390x __arch("s390x")
139140
#define __caps_unpriv(caps) __attribute__((btf_decl_tag("comment:test_caps_unpriv=" EXPAND_QUOTE(caps))))
140141
#define __load_if_JITed() __attribute__((btf_decl_tag("comment:load_mode=jited")))
141142
#define __load_if_no_JITed() __attribute__((btf_decl_tag("comment:load_mode=no_jited")))

tools/testing/selftests/bpf/progs/verifier_may_goto_1.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
SEC("raw_tp")
1010
__description("may_goto 0")
1111
__arch_x86_64
12+
__arch_s390x
1213
__xlated("0: r0 = 1")
1314
__xlated("1: exit")
1415
__success
@@ -27,6 +28,7 @@ __naked void may_goto_simple(void)
2728
SEC("raw_tp")
2829
__description("batch 2 of may_goto 0")
2930
__arch_x86_64
31+
__arch_s390x
3032
__xlated("0: r0 = 1")
3133
__xlated("1: exit")
3234
__success
@@ -47,6 +49,7 @@ __naked void may_goto_batch_0(void)
4749
SEC("raw_tp")
4850
__description("may_goto batch with offsets 2/1/0")
4951
__arch_x86_64
52+
__arch_s390x
5053
__xlated("0: r0 = 1")
5154
__xlated("1: exit")
5255
__success
@@ -69,8 +72,9 @@ __naked void may_goto_batch_1(void)
6972
}
7073

7174
SEC("raw_tp")
72-
__description("may_goto batch with offsets 2/0 - x86_64")
75+
__description("may_goto batch with offsets 2/0 - x86_64 and s390x")
7376
__arch_x86_64
77+
__arch_s390x
7478
__xlated("0: *(u64 *)(r10 -16) = 65535")
7579
__xlated("1: *(u64 *)(r10 -8) = 0")
7680
__xlated("2: r11 = *(u64 *)(r10 -16)")
@@ -84,7 +88,7 @@ __xlated("9: r0 = 1")
8488
__xlated("10: r0 = 2")
8589
__xlated("11: exit")
8690
__success
87-
__naked void may_goto_batch_2_x86_64(void)
91+
__naked void may_goto_batch_2_x86_64_s390x(void)
8892
{
8993
asm volatile (
9094
".8byte %[may_goto1];"

tools/testing/selftests/bpf/test_loader.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ enum arch {
374374
ARCH_X86_64 = 0x2,
375375
ARCH_ARM64 = 0x4,
376376
ARCH_RISCV64 = 0x8,
377+
ARCH_S390X = 0x10,
377378
};
378379

379380
static int get_current_arch(void)
@@ -384,6 +385,8 @@ static int get_current_arch(void)
384385
return ARCH_ARM64;
385386
#elif defined(__riscv) && __riscv_xlen == 64
386387
return ARCH_RISCV64;
388+
#elif defined(__s390x__)
389+
return ARCH_S390X;
387390
#endif
388391
return ARCH_UNKNOWN;
389392
}
@@ -565,8 +568,10 @@ static int parse_test_spec(struct test_loader *tester,
565568
arch = ARCH_ARM64;
566569
} else if (strcmp(val, "RISCV64") == 0) {
567570
arch = ARCH_RISCV64;
571+
} else if (strcmp(val, "s390x") == 0) {
572+
arch = ARCH_S390X;
568573
} else {
569-
PRINT_FAIL("bad arch spec: '%s'", val);
574+
PRINT_FAIL("bad arch spec: '%s'\n", val);
570575
err = -EINVAL;
571576
goto cleanup;
572577
}

0 commit comments

Comments
 (0)