From: Hui Zhu <[email protected]> To support features like allowing overrides in cgroup hierarchies, we need a way to pass flags from userspace to the kernel when attaching a struct_ops.
Extend `bpf_struct_ops_link` to include a `flags` field. This field is populated from `attr->link_create.flags` during link creation. This will allow struct_ops implementations, such as the upcoming memory controller ops, to interpret these flags and modify their attachment behavior accordingly. Signed-off-by: Geliang Tang <[email protected]> Signed-off-by: Hui Zhu <[email protected]> --- include/linux/bpf.h | 1 + kernel/bpf/bpf_struct_ops.c | 1 + tools/include/uapi/linux/bpf.h | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 7c15bac782fc..b8fde3bf4b91 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -1886,6 +1886,7 @@ struct bpf_struct_ops_link { struct bpf_map __rcu *map; wait_queue_head_t wait_hup; u64 cgroup_id; + u32 flags; }; struct bpf_link_primer { diff --git a/kernel/bpf/bpf_struct_ops.c b/kernel/bpf/bpf_struct_ops.c index f575c5cd0dc8..18042751f1eb 100644 --- a/kernel/bpf/bpf_struct_ops.c +++ b/kernel/bpf/bpf_struct_ops.c @@ -1390,6 +1390,7 @@ int bpf_struct_ops_link_create(union bpf_attr *attr) cgroup_put(cgrp); } #endif /* CONFIG_CGROUPS */ + link->flags = attr->link_create.flags; err = bpf_link_prime(&link->link, &link_primer); if (err) diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index b816bc53d2e1..a58fdb4484a4 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -1184,7 +1184,7 @@ enum bpf_perf_event_type { BPF_PERF_EVENT_EVENT = 6, }; -/* cgroup-bpf attach flags used in BPF_PROG_ATTACH command +/* cgroup-bpf attach flags used in BPF_PROG_ATTACH and BPF_LINK_CREATE command * * NONE(default): No further bpf programs allowed in the subtree. * -- 2.43.0

