From: Liu Jian liujian56@huawei.com
hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8J90J
----------------------------------------------------
BPF_PROG_TYPE_CGROUP* bpf programs is associated with cgroup2. If cgroup2 is not mounted, the bpf program is associated with cgrp_dfl_root.cgrp by default.
Then we can use it like below: bpftool cgroup attach /sys/fs/cgroup/cpu sock_ops pinned /sys/fs/bpf/xxx
Signed-off-by: Liu Jian liujian56@huawei.com Signed-off-by: Zhengchao Shao shaozhengchao@huawei.com --- kernel/bpf/cgroup.c | 16 ++++++++++++++++ net/Kconfig | 5 +++++ 2 files changed, 21 insertions(+)
diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c index 03b3d4492980..bb8650d20442 100644 --- a/kernel/bpf/cgroup.c +++ b/kernel/bpf/cgroup.c @@ -1134,7 +1134,11 @@ int cgroup_bpf_prog_attach(const union bpf_attr *attr, struct cgroup *cgrp; int ret;
+#if IS_ENABLED(CONFIG_NETACC_BPF) + cgrp = cgroup_v1v2_get_from_fd(attr->target_fd); +#else cgrp = cgroup_get_from_fd(attr->target_fd); +#endif if (IS_ERR(cgrp)) return PTR_ERR(cgrp);
@@ -1162,7 +1166,11 @@ int cgroup_bpf_prog_detach(const union bpf_attr *attr, enum bpf_prog_type ptype) struct cgroup *cgrp; int ret;
+#if IS_ENABLED(CONFIG_NETACC_BPF) + cgrp = cgroup_v1v2_get_from_fd(attr->target_fd); +#else cgrp = cgroup_get_from_fd(attr->target_fd); +#endif if (IS_ERR(cgrp)) return PTR_ERR(cgrp);
@@ -1281,7 +1289,11 @@ int cgroup_bpf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) if (attr->link_create.flags) return -EINVAL;
+#if IS_ENABLED(CONFIG_NETACC_BPF) + cgrp = cgroup_v1v2_get_from_fd(attr->link_create.target_fd); +#else cgrp = cgroup_get_from_fd(attr->link_create.target_fd); +#endif if (IS_ERR(cgrp)) return PTR_ERR(cgrp);
@@ -1321,7 +1333,11 @@ int cgroup_bpf_prog_query(const union bpf_attr *attr, struct cgroup *cgrp; int ret;
+#if IS_ENABLED(CONFIG_NETACC_BPF) + cgrp = cgroup_v1v2_get_from_fd(attr->query.target_fd); +#else cgrp = cgroup_get_from_fd(attr->query.target_fd); +#endif if (IS_ERR(cgrp)) return PTR_ERR(cgrp);
diff --git a/net/Kconfig b/net/Kconfig index d532ec33f1fe..1becb9b1470b 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -508,4 +508,9 @@ config NETDEV_ADDR_LIST_TEST default KUNIT_ALL_TESTS depends on KUNIT
+config NETACC_BPF + bool "Network acceleration" + default y + help + Network acceleration in bpf. endif # if NET