bpf: remove the cgroup -> bpf header dependecy
Subsystems (4)
Jakub Kicinski
maintainercover bpf: remove the cgroup -> bpf header dependecy
Changes to bpf.h tend to clog up our build systems. The netdev/bpf build bot does incremental builds to save time (reusing the build directory to only rebuild changed objects).
This is the rough breakdown of how many objects needs to be rebuilt based on file touched:
kernel.h 40633 bpf.h 17881 bpf-cgroup.h 17875 skbuff.h 10696 bpf-netns.h 7604 netdevice.h 7452 filter.h 5003 tcp.h 4048 sock.h 4959
As the stats show touching bpf.h is _very_ expensive. Recent 20+ patch series from Jirka took 10 hours to build patch-by-patch on a 72 CPU VM.
Bulk of the objects get rebuilt because MM includes cgroup headers. Luckily bpf-cgroup.h does not fundamentally depend on bpf.h so we can break that dependency and reduce the number of objects.
With the patches applied touching bpf.h causes 5019 objects to be rebuilt (17881 / 5019 = 3.56x). That's pretty much down to filter.h plus noise.
Jakub Kicinski (5):
bpf: add header for enum bpf_cgroup_storage_type
bpf: create a header for cgroup_storage_type()
bpf: create a header for struct bpf_link
bpf: remove the cgroup -> bpf header dependecy
bpf: push down the bpf-link include
include/linux/bpf-cgroup-storage.h | 17 +++++++++++++++++ include/linux/bpf-cgroup-types.h | 13 +++++++++++++ include/linux/bpf-cgroup.h | 13 +++---------- include/linux/bpf-link.h | 23 +++++++++++++++++++++++ include/linux/bpf.h | 19 ++----------------- kernel/bpf/bpf_iter.c | 1 + kernel/bpf/helpers.c | 1 + kernel/bpf/local_storage.c | 1 + kernel/bpf/syscall.c | 1 + net/core/dev.c | 1 + 10 files changed, 63 insertions(+), 27 deletions(-) create mode 100644 include/linux/bpf-cgroup-storage.h create mode 100644 include/linux/bpf-cgroup-types.h create mode 100644 include/linux/bpf-link.h
Signature · 1 line
2.31.1
Jakub Kicinski
maintainerPATCH 1/5 bpf: add header for enum bpf_cgroup_storage_type
enum bpf_cgroup_storage_type is needed both in bpf.h and bpf-cgroup.h. Since we want to break the cgroup -> bpf dependency we need to place it in its own header.
--- include/linux/bpf-cgroup-types.h | 13 +++++++++++++ include/linux/bpf.h | 9 +-------- 2 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 include/linux/bpf-cgroup-types.h
include/linux/bpf-cgroup-types.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _BPF_CGROUP_TYPES_H +#define _BPF_CGROUP_TYPES_H + +enum bpf_cgroup_storage_type { +BPF_CGROUP_STORAGE_SHARED , +BPF_CGROUP_STORAGE_PERCPU , + __BPF_CGROUP_STORAGE_MAX +}; + +#define MAX_BPF_CGROUP_STORAGE_TYPE __BPF_CGROUP_STORAGE_MAX + +#endif
include/linux/bpf.h +1 -8
@@ -22,6 +22,7 @@#include <linux/sched/mm.h> #include <linux/slab.h> #include <linux/percpu-refcount.h> +#include <linux/bpf-cgroup-types.h> #include <linux/bpfptr.h> struct bpf_verifier_env ;
@@ -550,14 +551,6 @@ struct bpf_prog_offload {u32 jited_len; }; -enum bpf_cgroup_storage_type { -BPF_CGROUP_STORAGE_SHARED , -BPF_CGROUP_STORAGE_PERCPU , - __BPF_CGROUP_STORAGE_MAX -}; - -#define MAX_BPF_CGROUP_STORAGE_TYPE __BPF_CGROUP_STORAGE_MAX -/* The longest tracepoint has 12 args. * See include/trace/bpf_probe.h */
Signature · 1 line
2.31.1
Jakub Kicinski
maintainerPATCH 4/5 bpf: remove the cgroup -> bpf header dependecy
In reply to Jakub KicinskiNow that the stage has been set and actors are in place remove the header dependency between cgroup and bpf.h.
This reduces the incremental build size of x86 allmodconfig after bpf.h was touched from ~17k objects rebuilt to ~5k objects. bpf.h is 2.2kLoC and is modified relatively often.
--- include/linux/bpf-cgroup.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
include/linux/bpf-cgroup.h +3 -1
@@ -2,7 +2,8 @@#ifndef _BPF_CGROUP_H#define _BPF_CGROUP_H -#include <linux/bpf.h> +#include <linux/bpf-cgroup-types.h> +#include <linux/bpf-link.h> #include <linux/errno.h> #include <linux/jump_label.h> #include <linux/percpu.h>
@@ -16,6 +17,7 @@ struct cgroup;struct sk_buff ;struct bpf_map ;struct bpf_prog ; +struct bpf_prog_aux ;struct bpf_sock_ops_kern ;struct bpf_cgroup_storage ;struct ctl_table ;
Signature · 1 line
2.31.1
Jakub Kicinski
maintainerPATCH 2/5 bpf: create a header for cgroup_storage_type()
In reply to Jakub Kicinskicgroup_storage_type() is a static inline which needs to deference bpf_map. Move it to its own header so that we don't need to pull in bpf.h. It only has a couple of callers.
--- include/linux/bpf-cgroup-storage.h | 17 +++++++++++++++++ include/linux/bpf-cgroup.h | 9 --------- kernel/bpf/helpers.c | 1 + kernel/bpf/local_storage.c | 1 + 4 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 include/linux/bpf-cgroup-storage.h
include/linux/bpf-cgroup-storage.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _BPF_CGROUP_STORAGE_H +#define _BPF_CGROUP_STORAGE_H + +#include <linux/bpf.h> +#include <linux/bpf-cgroup.h> + +static inline enum bpf_cgroup_storage_type cgroup_storage_type ( +struct bpf_map *map) +{ +if (map->map_type ==BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE ) +return BPF_CGROUP_STORAGE_PERCPU ; + +return BPF_CGROUP_STORAGE_SHARED ; +} + +#endif
include/linux/bpf-cgroup.h +0 -9
@@ -194,15 +194,6 @@ int __cgroup_bpf_run_filter_getsockopt_kern(struct sock *sk, int level, int optname, void *optval, int *optlen, int retval); -static inline enum bpf_cgroup_storage_type cgroup_storage_type ( -struct bpf_map *map) -{ -if (map->map_type ==BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE ) -return BPF_CGROUP_STORAGE_PERCPU ; - -return BPF_CGROUP_STORAGE_SHARED ; -} -struct bpf_cgroup_storage *cgroup_storage_lookup (struct bpf_cgroup_storage_map *map,void *key,bool locked);
kernel/bpf/helpers.c +1 -0
@@ -2,6 +2,7 @@/* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com */ #include <linux/bpf.h> +#include <linux/bpf-cgroup-storage.h> #include <linux/rcupdate.h> #include <linux/random.h> #include <linux/smp.h>
kernel/bpf/local_storage.c +1 -0
@@ -1,5 +1,6 @@//SPDX-License-Identifier: GPL-2.0 #include <linux/bpf-cgroup.h> +#include <linux/bpf-cgroup-storage.h> #include <linux/bpf.h> #include <linux/bpf_local_storage.h> #include <linux/btf.h>
Signature · 1 line
2.31.1
Jakub Kicinski
maintainerPATCH 3/5 bpf: create a header for struct bpf_link
In reply to Jakub Kicinskistruct bpf_link needs to be embedded by cgroups.
Put it in its own header.
--- include/linux/bpf-link.h | 23 +++++++++++++++++++++++ include/linux/bpf.h | 10 +--------- 2 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 include/linux/bpf-link.h
include/linux/bpf-link.h new file +23 -0
@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com +*/ +#ifndef _LINUX_BPF_MIN_H +#define _LINUX_BPF_MIN_H 1 + +#include <uapi/linux/bpf.h> + +#include <linux/workqueue.h> + +struct bpf_prog ; +struct bpf_link_ops ; + +struct bpf_link { +atomic64_t refcnt; +u32 id; +enum bpf_link_type type; +const struct bpf_link_ops *ops; +struct bpf_prog *prog; +struct work_struct work; +}; + +#endif
include/linux/bpf.h +1 -9
@@ -23,6 +23,7 @@#include <linux/slab.h> #include <linux/percpu-refcount.h> #include <linux/bpf-cgroup-types.h> +#include <linux/bpf-link.h> #include <linux/bpfptr.h> struct bpf_verifier_env ;
@@ -946,15 +947,6 @@ struct bpf_array_aux {struct work_struct work; }; -struct bpf_link { -atomic64_t refcnt; -u32 id; -enum bpf_link_type type; -const struct bpf_link_ops *ops; -struct bpf_prog *prog; -struct work_struct work; -}; -struct bpf_link_ops {void (*release)(struct bpf_link *link);void (*dealloc)(struct bpf_link *link);
Signature · 1 line
2.31.1
Jakub Kicinski
maintainerPATCH 5/5 bpf: push down the bpf-link include
In reply to Jakub KicinskiTurns out bpf_link is not dereferenced or embedded much. Since we have separated it out to its own header why not drop the include from bpf.h completely...
--- include/linux/bpf.h | 2 +- kernel/bpf/bpf_iter.c | 1 + kernel/bpf/syscall.c | 1 + net/core/dev.c | 1 + 4 files changed, 4 insertions(+), 1 deletion(-)
include/linux/bpf.h +1 -1
@@ -23,12 +23,12 @@#include <linux/slab.h> #include <linux/percpu-refcount.h> #include <linux/bpf-cgroup-types.h> -#include <linux/bpf-link.h> #include <linux/bpfptr.h> struct bpf_verifier_env ;struct bpf_verifier_log ;struct perf_event ; +struct bpf_link ;struct bpf_prog ;struct bpf_prog_aux ;struct bpf_map ;
kernel/bpf/bpf_iter.c +1 -0
@@ -5,6 +5,7 @@#include <linux/anon_inodes.h> #include <linux/filter.h> #include <linux/bpf.h> +#include <linux/bpf-link.h> struct bpf_iter_target_info {struct list_head list;
kernel/bpf/syscall.c +1 -0
@@ -5,6 +5,7 @@#include <linux/bpf_trace.h> #include <linux/bpf_lirc.h> #include <linux/bpf_verifier.h> +#include <linux/bpf-link.h> #include <linux/btf.h> #include <linux/syscalls.h> #include <linux/slab.h>
net/core/dev.c +1 -0
@@ -93,6 +93,7 @@#include <linux/skbuff.h> #include <linux/kthread.h> #include <linux/bpf.h> +#include <linux/bpf-link.h> #include <linux/bpf_trace.h> #include <net/net_namespace.h> #include <net/sock.h>
Signature · 1 line
2.31.1
Re: [PATCH bpf-next 3/5] bpf: create a header for struct bpf_link
In reply to Jakub KicinskiQuoted 17 lines · Jakub Kicinski
struct
bpf_linkneeds to be embedded by cgroups.
Put it in its own header.Signed-off-by Jakub Kicinski <[email protected]>--- include/linux/bpf-link.h | 23 +++++++++++++++++++++++ include/linux/bpf.h | 10 +--------- 2 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 include/linux/bpf-link.hinclude/linux/bpf-link.h new file +0
-0
include/linux/bpf-link.h line 5
Quoted 5 lines
include/linux/bpf-link.h new file +5
-0@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com +*/ +#ifndef _LINUX_BPF_MIN_H +#define _LINUX_BPF_MIN_H 1
MIN_H ?
My understanding that patch 4 is the key.
I think the bpf-link.h bpf-cgroup-types.h and bpf-cgroup-storage.h are too specific. We don't do a header file per type. Maybe combine them all into one bpf-cgroup-types.h ? That will still achieve the separation of cgroup from linux/bpf.h
Jakub Kicinski
maintainerRe: [PATCH bpf-next 3/5] bpf: create a header for struct bpf_link
Quoted 12 lines · On Mon, 13 Dec 2021 21:15:06 -0800 Alexei Starovoitov wrote:
Quoted 11 lines · Jakub Kicinski
struct
bpf_linkneeds to be embedded by cgroups.
Put it in its own header.Signed-off-by Jakub Kicinski <[email protected]>--- include/linux/bpf-link.h | 23 +++++++++++++++++++++++ include/linux/bpf.h | 10 +--------- 2 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 include/linux/bpf-link.h
Quoted 13 lines
include/linux/bpf-link.h line 5
Quoted 11 lines
include/linux/bpf-link.h new file +5
-0@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com +*/ +#ifndef _LINUX_BPF_MIN_H +#define _LINUX_BPF_MIN_H 1
MIN_H?
Used to stand for "minimal", forgot to rename after I changed course.
Quoted 5 lines
My understanding that patch 4 is the key.
I think thebpf-link.hbpf-cgroup-types.handbpf-cgroup-storage.hare too specific. We don't do a header file per type. Maybe combine them all into onebpf-cgroup-types.h? That will still achieve the separation of cgroup fromlinux/bpf.h
Jakub Kicinski
maintainerRe: [PATCH bpf-next 3/5] bpf: create a header for struct bpf_link
Quoted 5 lines · On Tue, 14 Dec 2021 07:04:35 -0800 Jakub Kicinski wrote:
Quoted 5 lines
My understanding that patch 4 is the key.
I think thebpf-link.hbpf-cgroup-types.handbpf-cgroup-storage.hare too specific. We don't do a header file per type. Maybe combine them all into onebpf-cgroup-types.h? That will still achieve the separation of cgroup fromlinux/bpf.h
The dependency tree is
bpf-link.h bpf-cgroup-types.h
^ ^
| /
bpf.h bpf-cgroup.h
^ ^
| |
| | bpf-cgroup-storage.h
I can't merge bpf-cgroup-storage.h with the rest, it'd be a loop. Should I leave that one be separate? Any other ideas?
Jakub Kicinski
maintainerRe: [PATCH bpf-next 3/5] bpf: create a header for struct bpf_link
Quoted 11 lines · On Tue, 14 Dec 2021 07:18:50 -0800 Jakub Kicinski wrote:
The dependency tree is
bpf-link.hbpf-cgroup-types.h
^ ^
| /
bpf.hbpf-cgroup.h^ ^ | | | |
bpf-cgroup-storage.h
bpf-cgroup-types.h bpf-link.h
^ ^ ^
| | /
bpf.h bpf-cgroup.h
^ ^
| |
| | bpf-cgroup-storage.h
To be exact, bpf.h include cgroup-types, but not bpf-link, doesn't change the question below, tho.
Quoted 2 lines
I can't merge
bpf-cgroup-storage.hwith the rest, it'd be a loop. Should I leave that one be separate? Any other ideas?
kernel test robot
build botI love your patch! Yet something to improve:
Hi Jakub,
I love your patch! Yet something to improve:
[auto build test ERROR on bpf-next/master]
url: https://github.com/0day-ci/linux/commits/Jakub-Kicinski/bpf-remove-the-cgroup-bpf-header-dependecy/20211214-074344 base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master config: s390-randconfig-r023-20211213 (https://download.01.org/0day-ci/archive/20211215/202112150326.PHRPQfmk-lkp(a)intel.com/config) compiler: s390-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/517f95dd6d9264e4104cfc35eecdd5c1287738ae
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Jakub-Kicinski/bpf-remove-the-cgroup-bpf-header-dependecy/20211214-074344 git checkout 517f95dd6d9264e4104cfc35eecdd5c1287738ae
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=s390 SHELL=/bin/bash
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
arch/s390/mm/hugetlbpage.c: In function 'hugetlb_get_unmapped_area':
>> arch/s390/mm/hugetlbpage.c:352:16: error: implicit declaration of function 'check_asce_limit'; did you mean 'check_data_rlimit'? [-Werror=implicit-function-declaration]
352 | return check_asce_limit(mm, addr, len);
| ^~~~~~~~~~~~~~~~
| check_data_rlimitcc1: some warnings being treated as errors
vim +352 arch/s390/mm/hugetlbpage.c
5f490a520bcb393 Gerald Schaefer 2020-01-16 315
5f490a520bcb393 Gerald Schaefer 2020-01-16 316 unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
5f490a520bcb393 Gerald Schaefer 2020-01-16 317 unsigned long len, unsigned long pgoff, unsigned long flags)
5f490a520bcb393 Gerald Schaefer 2020-01-16 318 {
5f490a520bcb393 Gerald Schaefer 2020-01-16 319 struct hstate *h = hstate_file(file);
5f490a520bcb393 Gerald Schaefer 2020-01-16 320 struct mm_struct *mm = current->mm;
5f490a520bcb393 Gerald Schaefer 2020-01-16 321 struct vm_area_struct *vma;
5f490a520bcb393 Gerald Schaefer 2020-01-16 322
5f490a520bcb393 Gerald Schaefer 2020-01-16 323 if (len & ~huge_page_mask(h))
5f490a520bcb393 Gerald Schaefer 2020-01-16 324 return -EINVAL;
5f490a520bcb393 Gerald Schaefer 2020-01-16 325 if (len > TASK_SIZE - mmap_min_addr)
5f490a520bcb393 Gerald Schaefer 2020-01-16 326 return -ENOMEM;
5f490a520bcb393 Gerald Schaefer 2020-01-16 327
5f490a520bcb393 Gerald Schaefer 2020-01-16 328 if (flags & MAP_FIXED) {
5f490a520bcb393 Gerald Schaefer 2020-01-16 329 if (prepare_hugepage_range(file, addr, len))
5f490a520bcb393 Gerald Schaefer 2020-01-16 330 return -EINVAL;
5f490a520bcb393 Gerald Schaefer 2020-01-16 331 goto check_asce_limit;
5f490a520bcb393 Gerald Schaefer 2020-01-16 332 }
5f490a520bcb393 Gerald Schaefer 2020-01-16 333
5f490a520bcb393 Gerald Schaefer 2020-01-16 334 if (addr) {
5f490a520bcb393 Gerald Schaefer 2020-01-16 335 addr = ALIGN(addr, huge_page_size(h));
5f490a520bcb393 Gerald Schaefer 2020-01-16 336 vma = find_vma(mm, addr);
5f490a520bcb393 Gerald Schaefer 2020-01-16 337 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
5f490a520bcb393 Gerald Schaefer 2020-01-16 338 (!vma || addr + len <= vm_start_gap(vma)))
5f490a520bcb393 Gerald Schaefer 2020-01-16 339 goto check_asce_limit;
5f490a520bcb393 Gerald Schaefer 2020-01-16 340 }
5f490a520bcb393 Gerald Schaefer 2020-01-16 341
5f490a520bcb393 Gerald Schaefer 2020-01-16 342 if (mm->get_unmapped_area == arch_get_unmapped_area)
5f490a520bcb393 Gerald Schaefer 2020-01-16 343 addr = hugetlb_get_unmapped_area_bottomup(file, addr, len,
5f490a520bcb393 Gerald Schaefer 2020-01-16 344 pgoff, flags);
5f490a520bcb393 Gerald Schaefer 2020-01-16 345 else
5f490a520bcb393 Gerald Schaefer 2020-01-16 346 addr = hugetlb_get_unmapped_area_topdown(file, addr, len,
5f490a520bcb393 Gerald Schaefer 2020-01-16 347 pgoff, flags);
712fa5f294f377e Alexander Gordeev 2020-03-23 348 if (offset_in_page(addr))
5f490a520bcb393 Gerald Schaefer 2020-01-16 349 return addr;
5f490a520bcb393 Gerald Schaefer 2020-01-16 350
5f490a520bcb393 Gerald Schaefer 2020-01-16 351 check_asce_limit:712fa5f294f377e Alexander Gordeev 2020-03-23 @352 return check_asce_limit(mm, addr, len);
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org