Skip to content

Commit c3d80ea

Browse files
committed
Merge branch 'bpf-next/master' into for-next
Signed-off-by: Andrii Nakryiko <[email protected]>
2 parents ce06b1f + 01ac89d commit c3d80ea

File tree

8 files changed

+40
-31
lines changed

8 files changed

+40
-31
lines changed

include/linux/bpf.h

+1
Original file line numberDiff line numberDiff line change
@@ -3215,6 +3215,7 @@ extern const struct bpf_func_proto bpf_sock_hash_update_proto;
32153215
extern const struct bpf_func_proto bpf_get_current_cgroup_id_proto;
32163216
extern const struct bpf_func_proto bpf_get_current_ancestor_cgroup_id_proto;
32173217
extern const struct bpf_func_proto bpf_get_cgroup_classid_curr_proto;
3218+
extern const struct bpf_func_proto bpf_current_task_under_cgroup_proto;
32183219
extern const struct bpf_func_proto bpf_msg_redirect_hash_proto;
32193220
extern const struct bpf_func_proto bpf_msg_redirect_map_proto;
32203221
extern const struct bpf_func_proto bpf_sk_redirect_hash_proto;

kernel/bpf/btf.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ enum btf_kfunc_hook {
212212
BTF_KFUNC_HOOK_TRACING,
213213
BTF_KFUNC_HOOK_SYSCALL,
214214
BTF_KFUNC_HOOK_FMODRET,
215-
BTF_KFUNC_HOOK_CGROUP_SKB,
215+
BTF_KFUNC_HOOK_CGROUP,
216216
BTF_KFUNC_HOOK_SCHED_ACT,
217217
BTF_KFUNC_HOOK_SK_SKB,
218218
BTF_KFUNC_HOOK_SOCKET_FILTER,
@@ -8302,8 +8302,12 @@ static int bpf_prog_type_to_kfunc_hook(enum bpf_prog_type prog_type)
83028302
case BPF_PROG_TYPE_SYSCALL:
83038303
return BTF_KFUNC_HOOK_SYSCALL;
83048304
case BPF_PROG_TYPE_CGROUP_SKB:
8305+
case BPF_PROG_TYPE_CGROUP_SOCK:
8306+
case BPF_PROG_TYPE_CGROUP_DEVICE:
83058307
case BPF_PROG_TYPE_CGROUP_SOCK_ADDR:
8306-
return BTF_KFUNC_HOOK_CGROUP_SKB;
8308+
case BPF_PROG_TYPE_CGROUP_SOCKOPT:
8309+
case BPF_PROG_TYPE_CGROUP_SYSCTL:
8310+
return BTF_KFUNC_HOOK_CGROUP;
83078311
case BPF_PROG_TYPE_SCHED_ACT:
83088312
return BTF_KFUNC_HOOK_SCHED_ACT;
83098313
case BPF_PROG_TYPE_SK_SKB:

kernel/bpf/cgroup.c

+2
Original file line numberDiff line numberDiff line change
@@ -2581,6 +2581,8 @@ cgroup_current_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
25812581
case BPF_FUNC_get_cgroup_classid:
25822582
return &bpf_get_cgroup_classid_curr_proto;
25832583
#endif
2584+
case BPF_FUNC_current_task_under_cgroup:
2585+
return &bpf_current_task_under_cgroup_proto;
25842586
default:
25852587
return NULL;
25862588
}

kernel/bpf/helpers.c

+24
Original file line numberDiff line numberDiff line change
@@ -2458,6 +2458,29 @@ __bpf_kfunc long bpf_task_under_cgroup(struct task_struct *task,
24582458
return ret;
24592459
}
24602460

2461+
BPF_CALL_2(bpf_current_task_under_cgroup, struct bpf_map *, map, u32, idx)
2462+
{
2463+
struct bpf_array *array = container_of(map, struct bpf_array, map);
2464+
struct cgroup *cgrp;
2465+
2466+
if (unlikely(idx >= array->map.max_entries))
2467+
return -E2BIG;
2468+
2469+
cgrp = READ_ONCE(array->ptrs[idx]);
2470+
if (unlikely(!cgrp))
2471+
return -EAGAIN;
2472+
2473+
return task_under_cgroup_hierarchy(current, cgrp);
2474+
}
2475+
2476+
const struct bpf_func_proto bpf_current_task_under_cgroup_proto = {
2477+
.func = bpf_current_task_under_cgroup,
2478+
.gpl_only = false,
2479+
.ret_type = RET_INTEGER,
2480+
.arg1_type = ARG_CONST_MAP_PTR,
2481+
.arg2_type = ARG_ANYTHING,
2482+
};
2483+
24612484
/**
24622485
* bpf_task_get_cgroup1 - Acquires the associated cgroup of a task within a
24632486
* specific cgroup1 hierarchy. The cgroup1 hierarchy is identified by its
@@ -3052,6 +3075,7 @@ static int __init kfunc_init(void)
30523075
ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_XDP, &generic_kfunc_set);
30533076
ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS, &generic_kfunc_set);
30543077
ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_SYSCALL, &generic_kfunc_set);
3078+
ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_CGROUP_SKB, &generic_kfunc_set);
30553079
ret = ret ?: register_btf_id_dtor_kfuncs(generic_dtors,
30563080
ARRAY_SIZE(generic_dtors),
30573081
THIS_MODULE);

kernel/trace/bpf_trace.c

+2-25
Original file line numberDiff line numberDiff line change
@@ -797,29 +797,6 @@ const struct bpf_func_proto bpf_task_pt_regs_proto = {
797797
.ret_btf_id = &bpf_task_pt_regs_ids[0],
798798
};
799799

800-
BPF_CALL_2(bpf_current_task_under_cgroup, struct bpf_map *, map, u32, idx)
801-
{
802-
struct bpf_array *array = container_of(map, struct bpf_array, map);
803-
struct cgroup *cgrp;
804-
805-
if (unlikely(idx >= array->map.max_entries))
806-
return -E2BIG;
807-
808-
cgrp = READ_ONCE(array->ptrs[idx]);
809-
if (unlikely(!cgrp))
810-
return -EAGAIN;
811-
812-
return task_under_cgroup_hierarchy(current, cgrp);
813-
}
814-
815-
static const struct bpf_func_proto bpf_current_task_under_cgroup_proto = {
816-
.func = bpf_current_task_under_cgroup,
817-
.gpl_only = false,
818-
.ret_type = RET_INTEGER,
819-
.arg1_type = ARG_CONST_MAP_PTR,
820-
.arg2_type = ARG_ANYTHING,
821-
};
822-
823800
struct send_signal_irq_work {
824801
struct irq_work irq_work;
825802
struct task_struct *task;
@@ -1480,8 +1457,6 @@ bpf_tracing_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
14801457
return &bpf_get_numa_node_id_proto;
14811458
case BPF_FUNC_perf_event_read:
14821459
return &bpf_perf_event_read_proto;
1483-
case BPF_FUNC_current_task_under_cgroup:
1484-
return &bpf_current_task_under_cgroup_proto;
14851460
case BPF_FUNC_get_prandom_u32:
14861461
return &bpf_get_prandom_u32_proto;
14871462
case BPF_FUNC_probe_write_user:
@@ -1510,6 +1485,8 @@ bpf_tracing_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
15101485
return &bpf_cgrp_storage_get_proto;
15111486
case BPF_FUNC_cgrp_storage_delete:
15121487
return &bpf_cgrp_storage_delete_proto;
1488+
case BPF_FUNC_current_task_under_cgroup:
1489+
return &bpf_current_task_under_cgroup_proto;
15131490
#endif
15141491
case BPF_FUNC_send_signal:
15151492
return &bpf_send_signal_proto;

tools/testing/selftests/bpf/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ progs/test_pkt_md_access.c-CFLAGS := -fno-strict-aliasing
5858
progs/test_sk_lookup.c-CFLAGS := -fno-strict-aliasing
5959
progs/timer_crash.c-CFLAGS := -fno-strict-aliasing
6060
progs/test_global_func9.c-CFLAGS := -fno-strict-aliasing
61+
progs/verifier_nocsr.c-CFLAGS := -fno-strict-aliasing
6162

6263
ifneq ($(LLVM),)
6364
# Silence some warnings when compiled with clang

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ __retval(33)
5858
SEC("tc")
5959
int tailcall_bpf2bpf_hierarchy_2(struct __sk_buff *skb)
6060
{
61-
volatile int ret = 0;
61+
int ret = 0;
6262

6363
subprog_tail0(skb);
6464
subprog_tail1(skb);
6565

66-
asm volatile (""::"r+"(ret));
66+
__sink(ret);
6767
return (count1 << 16) | count0;
6868
}
6969

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ __retval(33)
5151
SEC("tc")
5252
int tailcall_bpf2bpf_hierarchy_3(struct __sk_buff *skb)
5353
{
54-
volatile int ret = 0;
54+
int ret = 0;
5555

5656
bpf_tail_call_static(skb, &jmp_table0, 0);
5757

58-
asm volatile (""::"r+"(ret));
58+
__sink(ret);
5959
return ret;
6060
}
6161

0 commit comments

Comments
 (0)