bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next v3 0/3] bpf: remove the cgroup -> bpf header dependecy
@ 2021-12-15  6:19 Jakub Kicinski
  2021-12-15  6:19 ` [PATCH bpf-next v3 1/3] add includes masked by cgroup -> bpf dependency Jakub Kicinski
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jakub Kicinski @ 2021-12-15  6:19 UTC (permalink / raw)
  To: daniel, ast, andrii; +Cc: bpf, Jakub Kicinski

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.

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.

v2:
Try to make the new headers wider in scope. Collapse bpf-link and
bpf-cgroup-types into one header, which may serve as "BPF kernel
API" header in the future if needed. Rename bpf-cgroup-storage.h
to bpf-inlines.h.

Add a fix for the s390 build issue.

v3:
Merge bpf-includes.h into bpf.h.
Remember to git format-patch after fixing build issues.

Jakub Kicinski (3):
  add includes masked by cgroup -> bpf dependency
  bpf: add header for enum bpf_cgroup_storage_type and bpf_link
  bpf: remove the cgroup -> bpf header dependecy

 arch/s390/mm/hugetlbpage.c       |  1 +
 include/linux/bpf-cgroup-types.h | 29 +++++++++++++++++++++++++++++
 include/linux/bpf-cgroup.h       | 12 ++----------
 include/linux/bpf.h              | 27 ++++++++++-----------------
 4 files changed, 42 insertions(+), 27 deletions(-)
 create mode 100644 include/linux/bpf-cgroup-types.h

-- 
2.31.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH bpf-next v3 1/3] add includes masked by cgroup -> bpf dependency
  2021-12-15  6:19 [PATCH bpf-next v3 0/3] bpf: remove the cgroup -> bpf header dependecy Jakub Kicinski
@ 2021-12-15  6:19 ` Jakub Kicinski
  2021-12-15  6:19 ` [PATCH bpf-next v3 2/3] bpf: add header for enum bpf_cgroup_storage_type and bpf_link Jakub Kicinski
  2021-12-15  6:19 ` [PATCH bpf-next v3 3/3] bpf: remove the cgroup -> bpf header dependecy Jakub Kicinski
  2 siblings, 0 replies; 4+ messages in thread
From: Jakub Kicinski @ 2021-12-15  6:19 UTC (permalink / raw)
  To: daniel, ast, andrii
  Cc: bpf, Jakub Kicinski, hca, gor, borntraeger, agordeev, akpm,
	peterx, linux-s390

cgroup pulls in BPF which pulls in a lot of includes.
We're about to break that chain so fix those who were
depending on it.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
CC: hca@linux.ibm.com
CC: gor@linux.ibm.com
CC: borntraeger@linux.ibm.com
CC: agordeev@linux.ibm.com
CC: akpm@linux-foundation.org
CC: peterx@redhat.com
CC: linux-s390@vger.kernel.org
---
 arch/s390/mm/hugetlbpage.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/s390/mm/hugetlbpage.c b/arch/s390/mm/hugetlbpage.c
index da36d13ffc16..082793d497ec 100644
--- a/arch/s390/mm/hugetlbpage.c
+++ b/arch/s390/mm/hugetlbpage.c
@@ -9,6 +9,7 @@
 #define KMSG_COMPONENT "hugetlb"
 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
 
+#include <asm/pgalloc.h>
 #include <linux/mm.h>
 #include <linux/hugetlb.h>
 #include <linux/mman.h>
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH bpf-next v3 2/3] bpf: add header for enum bpf_cgroup_storage_type and bpf_link
  2021-12-15  6:19 [PATCH bpf-next v3 0/3] bpf: remove the cgroup -> bpf header dependecy Jakub Kicinski
  2021-12-15  6:19 ` [PATCH bpf-next v3 1/3] add includes masked by cgroup -> bpf dependency Jakub Kicinski
@ 2021-12-15  6:19 ` Jakub Kicinski
  2021-12-15  6:19 ` [PATCH bpf-next v3 3/3] bpf: remove the cgroup -> bpf header dependecy Jakub Kicinski
  2 siblings, 0 replies; 4+ messages in thread
From: Jakub Kicinski @ 2021-12-15  6:19 UTC (permalink / raw)
  To: daniel, ast, andrii; +Cc: bpf, Jakub Kicinski

enum bpf_cgroup_storage_type and struct bpf_link are 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.

We can transform this header into some form of "kernel API"
header for BPF if more places want to include a lightweight
version of bpf.h. I'm calling it bpf-cgroup-types.h for now
mostly because naming is hard...

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 include/linux/bpf-cgroup-types.h | 29 +++++++++++++++++++++++++++++
 include/linux/bpf.h              | 18 +-----------------
 2 files changed, 30 insertions(+), 17 deletions(-)
 create mode 100644 include/linux/bpf-cgroup-types.h

diff --git a/include/linux/bpf-cgroup-types.h b/include/linux/bpf-cgroup-types.h
new file mode 100644
index 000000000000..c916fd3f4a0f
--- /dev/null
+++ b/include/linux/bpf-cgroup-types.h
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _BPF_CGROUP_TYPES_H
+#define _BPF_CGROUP_TYPES_H
+
+#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;
+};
+
+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
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 965fffaf0308..1e16243623fe 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -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
  */
@@ -958,15 +951,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);
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH bpf-next v3 3/3] bpf: remove the cgroup -> bpf header dependecy
  2021-12-15  6:19 [PATCH bpf-next v3 0/3] bpf: remove the cgroup -> bpf header dependecy Jakub Kicinski
  2021-12-15  6:19 ` [PATCH bpf-next v3 1/3] add includes masked by cgroup -> bpf dependency Jakub Kicinski
  2021-12-15  6:19 ` [PATCH bpf-next v3 2/3] bpf: add header for enum bpf_cgroup_storage_type and bpf_link Jakub Kicinski
@ 2021-12-15  6:19 ` Jakub Kicinski
  2 siblings, 0 replies; 4+ messages in thread
From: Jakub Kicinski @ 2021-12-15  6:19 UTC (permalink / raw)
  To: daniel, ast, andrii; +Cc: bpf, Jakub Kicinski

Remove the dependency from cgroup.h to 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.

cgroup_storage_type() needs to be moved to bpf.h because
it dereferences struct bpf_map.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 include/linux/bpf-cgroup.h | 12 ++----------
 include/linux/bpf.h        |  9 +++++++++
 2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/include/linux/bpf-cgroup.h b/include/linux/bpf-cgroup.h
index 11820a430d6c..d966b3dc7666 100644
--- a/include/linux/bpf-cgroup.h
+++ b/include/linux/bpf-cgroup.h
@@ -2,7 +2,7 @@
 #ifndef _BPF_CGROUP_H
 #define _BPF_CGROUP_H
 
-#include <linux/bpf.h>
+#include <linux/bpf-cgroup-types.h>
 #include <linux/errno.h>
 #include <linux/jump_label.h>
 #include <linux/percpu.h>
@@ -16,6 +16,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;
@@ -194,15 +195,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);
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 1e16243623fe..8ea70c26acb5 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -288,6 +288,15 @@ static inline bool bpf_map_support_seq_show(const struct bpf_map *map)
 		map->ops->map_seq_show_elem;
 }
 
+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;
+}
+
 int map_check_no_btf(const struct bpf_map *map,
 		     const struct btf *btf,
 		     const struct btf_type *key_type,
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-12-15  6:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-15  6:19 [PATCH bpf-next v3 0/3] bpf: remove the cgroup -> bpf header dependecy Jakub Kicinski
2021-12-15  6:19 ` [PATCH bpf-next v3 1/3] add includes masked by cgroup -> bpf dependency Jakub Kicinski
2021-12-15  6:19 ` [PATCH bpf-next v3 2/3] bpf: add header for enum bpf_cgroup_storage_type and bpf_link Jakub Kicinski
2021-12-15  6:19 ` [PATCH bpf-next v3 3/3] bpf: remove the cgroup -> bpf header dependecy Jakub Kicinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).