Skip to content

Commit 34ba23b

Browse files
committed
Daniel Borkmann says: ==================== pull-request: bpf-next 2022-04-09 We've added 63 non-merge commits during the last 9 day(s) which contain a total of 68 files changed, 4852 insertions(+), 619 deletions(-). The main changes are: 1) Add libbpf support for USDT (User Statically-Defined Tracing) probes. USDTs are an abstraction built on top of uprobes, critical for tracing and BPF, and widely used in production applications, from Andrii Nakryiko. 2) While Andrii was adding support for x86{-64}-specific logic of parsing USDT argument specification, Ilya followed-up with USDT support for s390 architecture, from Ilya Leoshkevich. 3) Support name-based attaching for uprobe BPF programs in libbpf. The format supported is `u[ret]probe/binary_path:[raw_offset|function[+offset]]`, e.g. attaching to libc malloc can be done in BPF via SEC("uprobe/libc.so.6:malloc") now, from Alan Maguire. 4) Various load/store optimizations for the arm64 JIT to shrink the image size by using arm64 str/ldr immediate instructions. Also enable pointer authentication to verify return address for JITed code, from Xu Kuohai. 5) BPF verifier fixes for write access checks to helper functions, e.g. rd-only memory from bpf_*_cpu_ptr() must not be passed to helpers that write into passed buffers, from Kumar Kartikeya Dwivedi. 6) Fix overly excessive stack map allocation for its base map structure and buckets which slipped-in from cleanups during the rlimit accounting removal back then, from Yuntao Wang. 7) Extend the unstable CT lookup helpers for XDP and tc/BPF to report netfilter connection tracking tuple direction, from Lorenzo Bianconi. 8) Improve bpftool dump to show BPF program/link type names, Milan Landaverde. 9) Minor cleanups all over the place from various others. * https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next: (63 commits) bpf: Fix excessive memory allocation in stack_map_alloc() selftests/bpf: Fix return value checks in perf_event_stackmap test selftests/bpf: Add CO-RE relos into linked_funcs selftests libbpf: Use weak hidden modifier for USDT BPF-side API functions libbpf: Don't error out on CO-RE relos for overriden weak subprogs samples, bpf: Move routes monitor in xdp_router_ipv4 in a dedicated thread libbpf: Allow WEAK and GLOBAL bindings during BTF fixup libbpf: Use strlcpy() in path resolution fallback logic libbpf: Add s390-specific USDT arg spec parsing logic libbpf: Make BPF-side of USDT support work on big-endian machines libbpf: Minor style improvements in USDT code libbpf: Fix use #ifdef instead of #if to avoid compiler warning libbpf: Potential NULL dereference in usdt_manager_attach_usdt() selftests/bpf: Uprobe tests should verify param/return values libbpf: Improve string parsing for uprobe auto-attach libbpf: Improve library identification for uprobe binary path resolution selftests/bpf: Test for writes to map key from BPF helpers selftests/bpf: Test passing rdonly mem to global func bpf: Reject writes for PTR_TO_MAP_KEY in check_helper_mem_access bpf: Check PTR_TO_MEM | MEM_RDONLY in check_helper_mem_access ... ==================== Link: https://lore.kernel.org/r/20220408231741.19116-1-daniel@iogearbox.net Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents bd4a269 + b450431 commit 34ba23b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+4852
-619
lines changed

arch/arm64/include/asm/insn.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ enum aarch64_insn_size_type {
201201
enum aarch64_insn_ldst_type {
202202
AARCH64_INSN_LDST_LOAD_REG_OFFSET,
203203
AARCH64_INSN_LDST_STORE_REG_OFFSET,
204+
AARCH64_INSN_LDST_LOAD_IMM_OFFSET,
205+
AARCH64_INSN_LDST_STORE_IMM_OFFSET,
204206
AARCH64_INSN_LDST_LOAD_PAIR_PRE_INDEX,
205207
AARCH64_INSN_LDST_STORE_PAIR_PRE_INDEX,
206208
AARCH64_INSN_LDST_LOAD_PAIR_POST_INDEX,
@@ -335,13 +337,15 @@ __AARCH64_INSN_FUNCS(load_pre, 0x3FE00C00, 0x38400C00)
335337
__AARCH64_INSN_FUNCS(store_post, 0x3FE00C00, 0x38000400)
336338
__AARCH64_INSN_FUNCS(load_post, 0x3FE00C00, 0x38400400)
337339
__AARCH64_INSN_FUNCS(str_reg, 0x3FE0EC00, 0x38206800)
340+
__AARCH64_INSN_FUNCS(str_imm, 0x3FC00000, 0x39000000)
338341
__AARCH64_INSN_FUNCS(ldadd, 0x3F20FC00, 0x38200000)
339342
__AARCH64_INSN_FUNCS(ldclr, 0x3F20FC00, 0x38201000)
340343
__AARCH64_INSN_FUNCS(ldeor, 0x3F20FC00, 0x38202000)
341344
__AARCH64_INSN_FUNCS(ldset, 0x3F20FC00, 0x38203000)
342345
__AARCH64_INSN_FUNCS(swp, 0x3F20FC00, 0x38208000)
343346
__AARCH64_INSN_FUNCS(cas, 0x3FA07C00, 0x08A07C00)
344347
__AARCH64_INSN_FUNCS(ldr_reg, 0x3FE0EC00, 0x38606800)
348+
__AARCH64_INSN_FUNCS(ldr_imm, 0x3FC00000, 0x39400000)
345349
__AARCH64_INSN_FUNCS(ldr_lit, 0xBF000000, 0x18000000)
346350
__AARCH64_INSN_FUNCS(ldrsw_lit, 0xFF000000, 0x98000000)
347351
__AARCH64_INSN_FUNCS(exclusive, 0x3F800000, 0x08000000)
@@ -501,6 +505,11 @@ u32 aarch64_insn_gen_load_store_reg(enum aarch64_insn_register reg,
501505
enum aarch64_insn_register offset,
502506
enum aarch64_insn_size_type size,
503507
enum aarch64_insn_ldst_type type);
508+
u32 aarch64_insn_gen_load_store_imm(enum aarch64_insn_register reg,
509+
enum aarch64_insn_register base,
510+
unsigned int imm,
511+
enum aarch64_insn_size_type size,
512+
enum aarch64_insn_ldst_type type);
504513
u32 aarch64_insn_gen_load_store_pair(enum aarch64_insn_register reg1,
505514
enum aarch64_insn_register reg2,
506515
enum aarch64_insn_register base,

arch/arm64/lib/insn.c

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -299,29 +299,24 @@ static u32 aarch64_insn_encode_register(enum aarch64_insn_register_type type,
299299
return insn;
300300
}
301301

302+
static const u32 aarch64_insn_ldst_size[] = {
303+
[AARCH64_INSN_SIZE_8] = 0,
304+
[AARCH64_INSN_SIZE_16] = 1,
305+
[AARCH64_INSN_SIZE_32] = 2,
306+
[AARCH64_INSN_SIZE_64] = 3,
307+
};
308+
302309
static u32 aarch64_insn_encode_ldst_size(enum aarch64_insn_size_type type,
303310
u32 insn)
304311
{
305312
u32 size;
306313

307-
switch (type) {
308-
case AARCH64_INSN_SIZE_8:
309-
size = 0;
310-
break;
311-
case AARCH64_INSN_SIZE_16:
312-
size = 1;
313-
break;
314-
case AARCH64_INSN_SIZE_32:
315-
size = 2;
316-
break;
317-
case AARCH64_INSN_SIZE_64:
318-
size = 3;
319-
break;
320-
default:
314+
if (type < AARCH64_INSN_SIZE_8 || type > AARCH64_INSN_SIZE_64) {
321315
pr_err("%s: unknown size encoding %d\n", __func__, type);
322316
return AARCH64_BREAK_FAULT;
323317
}
324318

319+
size = aarch64_insn_ldst_size[type];
325320
insn &= ~GENMASK(31, 30);
326321
insn |= size << 30;
327322

@@ -504,6 +499,50 @@ u32 aarch64_insn_gen_load_store_reg(enum aarch64_insn_register reg,
504499
offset);
505500
}
506501

502+
u32 aarch64_insn_gen_load_store_imm(enum aarch64_insn_register reg,
503+
enum aarch64_insn_register base,
504+
unsigned int imm,
505+
enum aarch64_insn_size_type size,
506+
enum aarch64_insn_ldst_type type)
507+
{
508+
u32 insn;
509+
u32 shift;
510+
511+
if (size < AARCH64_INSN_SIZE_8 || size > AARCH64_INSN_SIZE_64) {
512+
pr_err("%s: unknown size encoding %d\n", __func__, type);
513+
return AARCH64_BREAK_FAULT;
514+
}
515+
516+
shift = aarch64_insn_ldst_size[size];
517+
if (imm & ~(BIT(12 + shift) - BIT(shift))) {
518+
pr_err("%s: invalid imm: %d\n", __func__, imm);
519+
return AARCH64_BREAK_FAULT;
520+
}
521+
522+
imm >>= shift;
523+
524+
switch (type) {
525+
case AARCH64_INSN_LDST_LOAD_IMM_OFFSET:
526+
insn = aarch64_insn_get_ldr_imm_value();
527+
break;
528+
case AARCH64_INSN_LDST_STORE_IMM_OFFSET:
529+
insn = aarch64_insn_get_str_imm_value();
530+
break;
531+
default:
532+
pr_err("%s: unknown load/store encoding %d\n", __func__, type);
533+
return AARCH64_BREAK_FAULT;
534+
}
535+
536+
insn = aarch64_insn_encode_ldst_size(size, insn);
537+
538+
insn = aarch64_insn_encode_register(AARCH64_INSN_REGTYPE_RT, insn, reg);
539+
540+
insn = aarch64_insn_encode_register(AARCH64_INSN_REGTYPE_RN, insn,
541+
base);
542+
543+
return aarch64_insn_encode_immediate(AARCH64_INSN_IMM_12, insn, imm);
544+
}
545+
507546
u32 aarch64_insn_gen_load_store_pair(enum aarch64_insn_register reg1,
508547
enum aarch64_insn_register reg2,
509548
enum aarch64_insn_register base,

arch/arm64/net/bpf_jit.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,20 @@
6666
#define A64_STR64(Xt, Xn, Xm) A64_LS_REG(Xt, Xn, Xm, 64, STORE)
6767
#define A64_LDR64(Xt, Xn, Xm) A64_LS_REG(Xt, Xn, Xm, 64, LOAD)
6868

69+
/* Load/store register (immediate offset) */
70+
#define A64_LS_IMM(Rt, Rn, imm, size, type) \
71+
aarch64_insn_gen_load_store_imm(Rt, Rn, imm, \
72+
AARCH64_INSN_SIZE_##size, \
73+
AARCH64_INSN_LDST_##type##_IMM_OFFSET)
74+
#define A64_STRBI(Wt, Xn, imm) A64_LS_IMM(Wt, Xn, imm, 8, STORE)
75+
#define A64_LDRBI(Wt, Xn, imm) A64_LS_IMM(Wt, Xn, imm, 8, LOAD)
76+
#define A64_STRHI(Wt, Xn, imm) A64_LS_IMM(Wt, Xn, imm, 16, STORE)
77+
#define A64_LDRHI(Wt, Xn, imm) A64_LS_IMM(Wt, Xn, imm, 16, LOAD)
78+
#define A64_STR32I(Wt, Xn, imm) A64_LS_IMM(Wt, Xn, imm, 32, STORE)
79+
#define A64_LDR32I(Wt, Xn, imm) A64_LS_IMM(Wt, Xn, imm, 32, LOAD)
80+
#define A64_STR64I(Xt, Xn, imm) A64_LS_IMM(Xt, Xn, imm, 64, STORE)
81+
#define A64_LDR64I(Xt, Xn, imm) A64_LS_IMM(Xt, Xn, imm, 64, LOAD)
82+
6983
/* Load/store register pair */
7084
#define A64_LS_PAIR(Rt, Rt2, Rn, offset, ls, type) \
7185
aarch64_insn_gen_load_store_pair(Rt, Rt2, Rn, offset, \
@@ -249,6 +263,9 @@
249263
/* HINTs */
250264
#define A64_HINT(x) aarch64_insn_gen_hint(x)
251265

266+
#define A64_PACIASP A64_HINT(AARCH64_INSN_HINT_PACIASP)
267+
#define A64_AUTIASP A64_HINT(AARCH64_INSN_HINT_AUTIASP)
268+
252269
/* BTI */
253270
#define A64_BTI_C A64_HINT(AARCH64_INSN_HINT_BTIC)
254271
#define A64_BTI_J A64_HINT(AARCH64_INSN_HINT_BTIJ)

0 commit comments

Comments
 (0)