Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bpf: Remove attach_type in bpf_cgroup_link

Use attach_type in bpf_link, and remove it in bpf_cgroup_link.

Signed-off-by: Tao Chen <chen.dylane@linux.dev>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/bpf/20250710032038.888700-3-chen.dylane@linux.dev

authored by

Tao Chen and committed by
Andrii Nakryiko
9b8d543d b725441f

+6 -8
-1
include/linux/bpf-cgroup.h
··· 103 103 struct bpf_cgroup_link { 104 104 struct bpf_link link; 105 105 struct cgroup *cgroup; 106 - enum bpf_attach_type type; 107 106 }; 108 107 109 108 struct bpf_prog_list {
+6 -7
kernel/bpf/cgroup.c
··· 984 984 struct hlist_head *progs; 985 985 bool found = false; 986 986 987 - atype = bpf_cgroup_atype_find(link->type, new_prog->aux->attach_btf_id); 987 + atype = bpf_cgroup_atype_find(link->link.attach_type, new_prog->aux->attach_btf_id); 988 988 if (atype < 0) 989 989 return -EINVAL; 990 990 ··· 1396 1396 } 1397 1397 1398 1398 WARN_ON(__cgroup_bpf_detach(cg_link->cgroup, NULL, cg_link, 1399 - cg_link->type, 0)); 1400 - if (cg_link->type == BPF_LSM_CGROUP) 1399 + link->attach_type, 0)); 1400 + if (link->attach_type == BPF_LSM_CGROUP) 1401 1401 bpf_trampoline_unlink_cgroup_shim(cg_link->link.prog); 1402 1402 1403 1403 cg = cg_link->cgroup; ··· 1439 1439 "cgroup_id:\t%llu\n" 1440 1440 "attach_type:\t%d\n", 1441 1441 cg_id, 1442 - cg_link->type); 1442 + link->attach_type); 1443 1443 } 1444 1444 1445 1445 static int bpf_cgroup_link_fill_link_info(const struct bpf_link *link, ··· 1455 1455 cgroup_unlock(); 1456 1456 1457 1457 info->cgroup.cgroup_id = cg_id; 1458 - info->cgroup.attach_type = cg_link->type; 1458 + info->cgroup.attach_type = link->attach_type; 1459 1459 return 0; 1460 1460 } 1461 1461 ··· 1497 1497 bpf_link_init(&link->link, BPF_LINK_TYPE_CGROUP, &bpf_cgroup_link_lops, 1498 1498 prog, attr->link_create.attach_type); 1499 1499 link->cgroup = cgrp; 1500 - link->type = attr->link_create.attach_type; 1501 1500 1502 1501 err = bpf_link_prime(&link->link, &link_primer); 1503 1502 if (err) { ··· 1505 1506 } 1506 1507 1507 1508 err = cgroup_bpf_attach(cgrp, NULL, NULL, link, 1508 - link->type, BPF_F_ALLOW_MULTI | attr->link_create.flags, 1509 + link->link.attach_type, BPF_F_ALLOW_MULTI | attr->link_create.flags, 1509 1510 attr->link_create.cgroup.relative_fd, 1510 1511 attr->link_create.cgroup.expected_revision); 1511 1512 if (err) {