bpf: remove the cgroup -> bpf header dependecy
Subsystems (27)
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.
Sending as an RFC because:
- bpf-link.h or bpf_link.h ?
- we probably want the header include fixes to go via bpf first
Jakub Kicinski (6):
treewide: add missing includes masked by cgroup -> bpf dependency
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
block/fops.c | 1 + drivers/gpu/drm/drm_gem_shmem_helper.c | 1 + drivers/gpu/drm/i915/gt/intel_gtt.c | 1 + drivers/gpu/drm/i915/i915_request.c | 1 + drivers/gpu/drm/lima/lima_device.c | 1 + drivers/gpu/drm/msm/msm_gem_shrinker.c | 1 + drivers/gpu/drm/ttm/ttm_tt.c | 1 + .../net/ethernet/huawei/hinic/hinic_sriov.c | 1 + .../ethernet/marvell/octeontx2/nic/otx2_ptp.c | 2 ++ drivers/pci/controller/dwc/pci-exynos.c | 1 + drivers/pci/controller/dwc/pcie-qcom-ep.c | 1 + drivers/usb/cdns3/host.c | 1 + 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 ++------------- include/linux/device/driver.h | 1 + include/linux/filter.h | 2 +- kernel/bpf/bpf_iter.c | 1 + kernel/bpf/helpers.c | 1 + kernel/bpf/local_storage.c | 1 + kernel/bpf/syscall.c | 1 + mm/damon/vaddr.c | 1 + mm/memory_hotplug.c | 1 + mm/swap_slots.c | 1 + net/core/dev.c | 1 + 27 files changed, 81 insertions(+), 28 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
maintainerRFC 1/6 treewide: add missing includes masked by cgroup -> bpf dependency
cgroup.h (therefore swap.h, therefore half of the universe) includes bpf.h which in turn includes module.h and slab.h. Since we're about to get rid of that dependency we need to clean things up.
--- block/fops.c | 1 + drivers/gpu/drm/drm_gem_shmem_helper.c | 1 + drivers/gpu/drm/i915/gt/intel_gtt.c | 1 + drivers/gpu/drm/i915/i915_request.c | 1 + drivers/gpu/drm/lima/lima_device.c | 1 + drivers/gpu/drm/msm/msm_gem_shrinker.c | 1 + drivers/gpu/drm/ttm/ttm_tt.c | 1 + drivers/net/ethernet/huawei/hinic/hinic_sriov.c | 1 + drivers/net/ethernet/marvell/octeontx2/nic/otx2_ptp.c | 2 ++ drivers/pci/controller/dwc/pci-exynos.c | 1 + drivers/pci/controller/dwc/pcie-qcom-ep.c | 1 + drivers/usb/cdns3/host.c | 1 + include/linux/device/driver.h | 1 + include/linux/filter.h | 2 +- mm/damon/vaddr.c | 1 + mm/memory_hotplug.c | 1 + mm/swap_slots.c | 1 + 17 files changed, 18 insertions(+), 1 deletion(-)
block/fops.c +1 -0
@@ -15,6 +15,7 @@#include <linux/falloc.h> #include <linux/suspend.h> #include <linux/fs.h> +#include <linux/module.h> #include "blk.h" static inline struct inode *bdev_file_inode (struct file *file)
drivers/gpu/drm/drm_gem_shmem_helper.c +1 -0
@@ -9,6 +9,7 @@#include <linux/shmem_fs.h> #include <linux/slab.h> #include <linux/vmalloc.h> +#include <linux/module.h> #ifdef CONFIG_X86 #include <asm/set_memory.h>
drivers/gpu/drm/i915/gt/intel_gtt.c +1 -0
@@ -6,6 +6,7 @@#include <linux/slab.h> /* fault-inject.h is not standalone! */ #include <linux/fault-inject.h> +#include <linux/sched/mm.h> #include "gem/i915_gem_lmem.h" #include "i915_trace.h"
drivers/gpu/drm/i915/i915_request.c +1 -0
@@ -29,6 +29,7 @@#include <linux/sched.h> #include <linux/sched/clock.h> #include <linux/sched/signal.h> +#include <linux/sched/mm.h> #include "gem/i915_gem_context.h" #include "gt/intel_breadcrumbs.h"
drivers/gpu/drm/lima/lima_device.c +1 -0
@@ -4,6 +4,7 @@#include <linux/regulator/consumer.h> #include <linux/reset.h> #include <linux/clk.h> +#include <linux/slab.h> #include <linux/dma-mapping.h> #include <linux/platform_device.h>
drivers/gpu/drm/msm/msm_gem_shrinker.c +1 -0
@@ -5,6 +5,7 @@*/ #include <linux/vmalloc.h> +#include <linux/sched/mm.h> #include "msm_drv.h" #include "msm_gem.h"
drivers/gpu/drm/ttm/ttm_tt.c +1 -0
@@ -34,6 +34,7 @@#include <linux/sched.h> #include <linux/shmem_fs.h> #include <linux/file.h> +#include <linux/module.h> #include <drm/drm_cache.h> #include <drm/ttm/ttm_bo_driver.h>
drivers/net/ethernet/huawei/hinic/hinic_sriov.c +1 -0
@@ -8,6 +8,7 @@#include <linux/interrupt.h> #include <linux/etherdevice.h> #include <linux/netdevice.h> +#include <linux/module.h> #include "hinic_hw_dev.h" #include "hinic_dev.h"
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ptp.c +2 -0
@@ -5,6 +5,8 @@* */ +#include <linux/module.h> +#include "otx2_common.h" #include "otx2_ptp.h"
drivers/pci/controller/dwc/pci-exynos.c +1 -0
@@ -19,6 +19,7 @@#include <linux/platform_device.h> #include <linux/phy/phy.h> #include <linux/regulator/consumer.h> +#include <linux/module.h> #include "pcie-designware.h"
drivers/pci/controller/dwc/pcie-qcom-ep.c +1 -0
@@ -18,6 +18,7 @@#include <linux/pm_domain.h> #include <linux/regmap.h> #include <linux/reset.h> +#include <linux/module.h> #include "pcie-designware.h"
drivers/usb/cdns3/host.c +1 -0
@@ -10,6 +10,7 @@*/ #include <linux/platform_device.h> +#include <linux/slab.h> #include "core.h" #include "drd.h" #include "host-export.h"
include/linux/device/driver.h +1 -0
@@ -18,6 +18,7 @@#include <linux/klist.h> #include <linux/pm.h> #include <linux/device/bus.h> +#include <linux/module.h> /** * enum probe_type - device driver probe type to try
include/linux/filter.h +1 -1
@@ -6,6 +6,7 @@#define __LINUX_FILTER_H__#include <linux/atomic.h> +#include <linux/bpf.h> #include <linux/refcount.h> #include <linux/compat.h> #include <linux/skbuff.h>
@@ -26,7 +27,6 @@#include <asm/byteorder.h> #include <uapi/linux/filter.h> -#include <uapi/linux/bpf.h> struct sk_buff ;struct sock ;
mm/damon/vaddr.c +1 -0
@@ -13,6 +13,7 @@#include <linux/mmu_notifier.h> #include <linux/page_idle.h> #include <linux/pagewalk.h> +#include <linux/sched/mm.h> #include "prmtv-common.h"
mm/memory_hotplug.c +1 -0
@@ -35,6 +35,7 @@#include <linux/memblock.h> #include <linux/compaction.h> #include <linux/rmap.h> +#include <linux/module.h> #include <asm/tlbflush.h>
mm/swap_slots.c +1 -0
@@ -30,6 +30,7 @@#include <linux/swap_slots.h> #include <linux/cpu.h> #include <linux/cpumask.h> +#include <linux/slab.h> #include <linux/vmalloc.h> #include <linux/mutex.h> #include <linux/mm.h>
Signature · 1 line
2.31.1
Jakub Kicinski
maintainerRFC 2/6 bpf: add header for enum bpf_cgroup_storage_type
In reply to Jakub Kicinskienum 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
maintainerRFC 3/6 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
maintainerRFC 4/6 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 ;
@@ -945,15 +946,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
maintainerRFC 5/6 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.
--- 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
maintainerRFC 6/6 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