Skip to content

Commit a5bdc36

Browse files
committed
Daniel Borkmann says: ==================== pull-request: bpf-next 2021-11-15 We've added 72 non-merge commits during the last 13 day(s) which contain a total of 171 files changed, 2728 insertions(+), 1143 deletions(-). The main changes are: 1) Add btf_type_tag attributes to bring kernel annotations like __user/__rcu to BTF such that BPF verifier will be able to detect misuse, from Yonghong Song. 2) Big batch of libbpf improvements including various fixes, future proofing APIs, and adding a unified, OPTS-based bpf_prog_load() low-level API, from Andrii Nakryiko. 3) Add ingress_ifindex to BPF_SK_LOOKUP program type for selectively applying the programmable socket lookup logic to packets from a given netdev, from Mark Pashmfouroush. 4) Remove the 128M upper JIT limit for BPF programs on arm64 and add selftest to ensure exception handling still works, from Russell King and Alan Maguire. 5) Add a new bpf_find_vma() helper for tracing to map an address to the backing file such as shared library, from Song Liu. 6) Batch of various misc fixes to bpftool, fixing a memory leak in BPF program dump, updating documentation and bash-completion among others, from Quentin Monnet. 7) Deprecate libbpf bpf_program__get_prog_info_linear() API and migrate its users as the API is heavily tailored around perf and is non-generic, from Dave Marchevsky. 8) Enable libbpf's strict mode by default in bpftool and add a --legacy option as an opt-out for more relaxed BPF program requirements, from Stanislav Fomichev. 9) Fix bpftool to use libbpf_get_error() to check for errors, from Hengqi Chen. * https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next: (72 commits) bpftool: Use libbpf_get_error() to check error bpftool: Fix mixed indentation in documentation bpftool: Update the lists of names for maps and prog-attach types bpftool: Fix indent in option lists in the documentation bpftool: Remove inclusion of utilities.mak from Makefiles bpftool: Fix memory leak in prog_dump() selftests/bpf: Fix a tautological-constant-out-of-range-compare compiler warning selftests/bpf: Fix an unused-but-set-variable compiler warning bpf: Introduce btf_tracing_ids bpf: Extend BTF_ID_LIST_GLOBAL with parameter for number of IDs bpftool: Enable libbpf's strict mode by default docs/bpf: Update documentation for BTF_KIND_TYPE_TAG support selftests/bpf: Clarify llvm dependency with btf_tag selftest selftests/bpf: Add a C test for btf_type_tag selftests/bpf: Rename progs/tag.c to progs/btf_decl_tag.c selftests/bpf: Test BTF_KIND_DECL_TAG for deduplication selftests/bpf: Add BTF_KIND_TYPE_TAG unit tests selftests/bpf: Test libbpf API function btf__add_type_tag() bpftool: Support BTF_KIND_TYPE_TAG libbpf: Support BTF_KIND_TYPE_TAG ... ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 2f6a470 + e504389 commit a5bdc36

File tree

160 files changed

+2354
-1110
lines changed

Some content is hidden

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

160 files changed

+2354
-1110
lines changed

Documentation/bpf/btf.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ sequentially and type id is assigned to each recognized type starting from id
8686
#define BTF_KIND_DATASEC 15 /* Section */
8787
#define BTF_KIND_FLOAT 16 /* Floating point */
8888
#define BTF_KIND_DECL_TAG 17 /* Decl Tag */
89+
#define BTF_KIND_TYPE_TAG 18 /* Type Tag */
8990

9091
Note that the type section encodes debug info, not just pure types.
9192
``BTF_KIND_FUNC`` is not a type, and it represents a defined subprogram.
@@ -107,7 +108,7 @@ Each type contains the following common data::
107108
* "size" tells the size of the type it is describing.
108109
*
109110
* "type" is used by PTR, TYPEDEF, VOLATILE, CONST, RESTRICT,
110-
* FUNC, FUNC_PROTO and DECL_TAG.
111+
* FUNC, FUNC_PROTO, DECL_TAG and TYPE_TAG.
111112
* "type" is a type_id referring to another type.
112113
*/
113114
union {
@@ -492,6 +493,16 @@ the attribute is applied to a ``struct``/``union`` member or
492493
a ``func`` argument, and ``btf_decl_tag.component_idx`` should be a
493494
valid index (starting from 0) pointing to a member or an argument.
494495

496+
2.2.17 BTF_KIND_TYPE_TAG
497+
~~~~~~~~~~~~~~~~~~~~~~~~
498+
499+
``struct btf_type`` encoding requirement:
500+
* ``name_off``: offset to a non-empty string
501+
* ``info.kind_flag``: 0
502+
* ``info.kind``: BTF_KIND_TYPE_TAG
503+
* ``info.vlen``: 0
504+
* ``type``: the type with ``btf_type_tag`` attribute
505+
495506
3. BTF Kernel API
496507
*****************
497508

arch/arm64/include/asm/extable.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,6 @@ do { \
3333
(b)->data = (tmp).data; \
3434
} while (0)
3535

36-
static inline bool in_bpf_jit(struct pt_regs *regs)
37-
{
38-
if (!IS_ENABLED(CONFIG_BPF_JIT))
39-
return false;
40-
41-
return regs->pc >= BPF_JIT_REGION_START &&
42-
regs->pc < BPF_JIT_REGION_END;
43-
}
44-
4536
#ifdef CONFIG_BPF_JIT
4637
bool ex_handler_bpf(const struct exception_table_entry *ex,
4738
struct pt_regs *regs);

arch/arm64/include/asm/memory.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,8 @@
4444
#define _PAGE_OFFSET(va) (-(UL(1) << (va)))
4545
#define PAGE_OFFSET (_PAGE_OFFSET(VA_BITS))
4646
#define KIMAGE_VADDR (MODULES_END)
47-
#define BPF_JIT_REGION_START (_PAGE_END(VA_BITS_MIN))
48-
#define BPF_JIT_REGION_SIZE (SZ_128M)
49-
#define BPF_JIT_REGION_END (BPF_JIT_REGION_START + BPF_JIT_REGION_SIZE)
5047
#define MODULES_END (MODULES_VADDR + MODULES_VSIZE)
51-
#define MODULES_VADDR (BPF_JIT_REGION_END)
48+
#define MODULES_VADDR (_PAGE_END(VA_BITS_MIN))
5249
#define MODULES_VSIZE (SZ_128M)
5350
#define VMEMMAP_START (-(UL(1) << (VA_BITS - VMEMMAP_SHIFT)))
5451
#define VMEMMAP_END (VMEMMAP_START + VMEMMAP_SIZE)

arch/arm64/kernel/traps.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ static struct break_hook bug_break_hook = {
994994
static int reserved_fault_handler(struct pt_regs *regs, unsigned int esr)
995995
{
996996
pr_err("%s generated an invalid instruction at %pS!\n",
997-
in_bpf_jit(regs) ? "BPF JIT" : "Kernel text patching",
997+
"Kernel text patching",
998998
(void *)instruction_pointer(regs));
999999

10001000
/* We cannot handle this */

arch/arm64/mm/ptdump.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ static struct addr_marker address_markers[] = {
4141
{ 0 /* KASAN_SHADOW_START */, "Kasan shadow start" },
4242
{ KASAN_SHADOW_END, "Kasan shadow end" },
4343
#endif
44-
{ BPF_JIT_REGION_START, "BPF start" },
45-
{ BPF_JIT_REGION_END, "BPF end" },
4644
{ MODULES_VADDR, "Modules start" },
4745
{ MODULES_END, "Modules end" },
4846
{ VMALLOC_START, "vmalloc() area" },

arch/arm64/net/bpf_jit_comp.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,15 +1141,12 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
11411141

11421142
u64 bpf_jit_alloc_exec_limit(void)
11431143
{
1144-
return BPF_JIT_REGION_SIZE;
1144+
return VMALLOC_END - VMALLOC_START;
11451145
}
11461146

11471147
void *bpf_jit_alloc_exec(unsigned long size)
11481148
{
1149-
return __vmalloc_node_range(size, PAGE_SIZE, BPF_JIT_REGION_START,
1150-
BPF_JIT_REGION_END, GFP_KERNEL,
1151-
PAGE_KERNEL, 0, NUMA_NO_NODE,
1152-
__builtin_return_address(0));
1149+
return vmalloc(size);
11531150
}
11541151

11551152
void bpf_jit_free_exec(void *addr)

include/linux/bpf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2163,6 +2163,7 @@ extern const struct bpf_func_proto bpf_btf_find_by_name_kind_proto;
21632163
extern const struct bpf_func_proto bpf_sk_setsockopt_proto;
21642164
extern const struct bpf_func_proto bpf_sk_getsockopt_proto;
21652165
extern const struct bpf_func_proto bpf_kallsyms_lookup_name_proto;
2166+
extern const struct bpf_func_proto bpf_find_vma_proto;
21662167

21672168
const struct bpf_func_proto *tracing_prog_func_proto(
21682169
enum bpf_func_id func_id, const struct bpf_prog *prog);

include/linux/btf_ids.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ asm( \
7373
__BTF_ID_LIST(name, local) \
7474
extern u32 name[];
7575

76-
#define BTF_ID_LIST_GLOBAL(name) \
76+
#define BTF_ID_LIST_GLOBAL(name, n) \
7777
__BTF_ID_LIST(name, globl)
7878

7979
/* The BTF_ID_LIST_SINGLE macro defines a BTF_ID_LIST with
@@ -83,7 +83,7 @@ __BTF_ID_LIST(name, globl)
8383
BTF_ID_LIST(name) \
8484
BTF_ID(prefix, typename)
8585
#define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) \
86-
BTF_ID_LIST_GLOBAL(name) \
86+
BTF_ID_LIST_GLOBAL(name, 1) \
8787
BTF_ID(prefix, typename)
8888

8989
/*
@@ -149,7 +149,7 @@ extern struct btf_id_set name;
149149
#define BTF_ID_LIST(name) static u32 name[5];
150150
#define BTF_ID(prefix, name)
151151
#define BTF_ID_UNUSED
152-
#define BTF_ID_LIST_GLOBAL(name) u32 name[1];
152+
#define BTF_ID_LIST_GLOBAL(name, n) u32 name[n];
153153
#define BTF_ID_LIST_SINGLE(name, prefix, typename) static u32 name[1];
154154
#define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) u32 name[1];
155155
#define BTF_SET_START(name) static struct btf_id_set name = { 0 };
@@ -189,6 +189,18 @@ MAX_BTF_SOCK_TYPE,
189189
extern u32 btf_sock_ids[];
190190
#endif
191191

192-
extern u32 btf_task_struct_ids[];
192+
#define BTF_TRACING_TYPE_xxx \
193+
BTF_TRACING_TYPE(BTF_TRACING_TYPE_TASK, task_struct) \
194+
BTF_TRACING_TYPE(BTF_TRACING_TYPE_FILE, file) \
195+
BTF_TRACING_TYPE(BTF_TRACING_TYPE_VMA, vm_area_struct)
196+
197+
enum {
198+
#define BTF_TRACING_TYPE(name, type) name,
199+
BTF_TRACING_TYPE_xxx
200+
#undef BTF_TRACING_TYPE
201+
MAX_BTF_TRACING_TYPE,
202+
};
203+
204+
extern u32 btf_tracing_ids[];
193205

194206
#endif

include/linux/filter.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,7 @@ struct bpf_sk_lookup_kern {
13741374
const struct in6_addr *daddr;
13751375
} v6;
13761376
struct sock *selected_sk;
1377+
u32 ingress_ifindex;
13771378
bool no_reuseport;
13781379
};
13791380

@@ -1436,7 +1437,7 @@ extern struct static_key_false bpf_sk_lookup_enabled;
14361437
static inline bool bpf_sk_lookup_run_v4(struct net *net, int protocol,
14371438
const __be32 saddr, const __be16 sport,
14381439
const __be32 daddr, const u16 dport,
1439-
struct sock **psk)
1440+
const int ifindex, struct sock **psk)
14401441
{
14411442
struct bpf_prog_array *run_array;
14421443
struct sock *selected_sk = NULL;
@@ -1452,6 +1453,7 @@ static inline bool bpf_sk_lookup_run_v4(struct net *net, int protocol,
14521453
.v4.daddr = daddr,
14531454
.sport = sport,
14541455
.dport = dport,
1456+
.ingress_ifindex = ifindex,
14551457
};
14561458
u32 act;
14571459

@@ -1474,7 +1476,7 @@ static inline bool bpf_sk_lookup_run_v6(struct net *net, int protocol,
14741476
const __be16 sport,
14751477
const struct in6_addr *daddr,
14761478
const u16 dport,
1477-
struct sock **psk)
1479+
const int ifindex, struct sock **psk)
14781480
{
14791481
struct bpf_prog_array *run_array;
14801482
struct sock *selected_sk = NULL;
@@ -1490,6 +1492,7 @@ static inline bool bpf_sk_lookup_run_v6(struct net *net, int protocol,
14901492
.v6.daddr = daddr,
14911493
.sport = sport,
14921494
.dport = dport,
1495+
.ingress_ifindex = ifindex,
14931496
};
14941497
u32 act;
14951498

include/uapi/linux/bpf.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4938,6 +4938,25 @@ union bpf_attr {
49384938
* **-ENOENT** if symbol is not found.
49394939
*
49404940
* **-EPERM** if caller does not have permission to obtain kernel address.
4941+
*
4942+
* long bpf_find_vma(struct task_struct *task, u64 addr, void *callback_fn, void *callback_ctx, u64 flags)
4943+
* Description
4944+
* Find vma of *task* that contains *addr*, call *callback_fn*
4945+
* function with *task*, *vma*, and *callback_ctx*.
4946+
* The *callback_fn* should be a static function and
4947+
* the *callback_ctx* should be a pointer to the stack.
4948+
* The *flags* is used to control certain aspects of the helper.
4949+
* Currently, the *flags* must be 0.
4950+
*
4951+
* The expected callback signature is
4952+
*
4953+
* long (\*callback_fn)(struct task_struct \*task, struct vm_area_struct \*vma, void \*callback_ctx);
4954+
*
4955+
* Return
4956+
* 0 on success.
4957+
* **-ENOENT** if *task->mm* is NULL, or no vma contains *addr*.
4958+
* **-EBUSY** if failed to try lock mmap_lock.
4959+
* **-EINVAL** for invalid **flags**.
49414960
*/
49424961
#define __BPF_FUNC_MAPPER(FN) \
49434962
FN(unspec), \
@@ -5120,6 +5139,7 @@ union bpf_attr {
51205139
FN(trace_vprintk), \
51215140
FN(skc_to_unix_sock), \
51225141
FN(kallsyms_lookup_name), \
5142+
FN(find_vma), \
51235143
/* */
51245144

51255145
/* integer value in 'imm' field of BPF_CALL instruction selects which helper
@@ -6296,6 +6316,7 @@ struct bpf_sk_lookup {
62966316
__u32 local_ip4; /* Network byte order */
62976317
__u32 local_ip6[4]; /* Network byte order */
62986318
__u32 local_port; /* Host byte order */
6319+
__u32 ingress_ifindex; /* The arriving interface. Determined by inet_iif. */
62996320
};
63006321

63016322
/*

0 commit comments

Comments
 (0)