bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next v2 0/4] bpf: remove the cgroup -> bpf header dependecy
@ 2021-12-15  2:31 Jakub Kicinski
  2021-12-15  2:31 ` [PATCH bpf-next v2 1/4] bpf: add header for enum bpf_cgroup_storage_type and bpf_link Jakub Kicinski
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Jakub Kicinski @ 2021-12-15  2:31 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.

Jakub Kicinski (4):
  bpf: add header for enum bpf_cgroup_storage_type and bpf_link
  bpf: create a header for inline helpers
  add includes masked by cgroup -> bpf dependency
  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       | 13 +++----------
 include/linux/bpf-inlines.h      | 17 +++++++++++++++++
 include/linux/bpf.h              | 18 +-----------------
 kernel/bpf/helpers.c             |  1 +
 kernel/bpf/local_storage.c       |  1 +
 7 files changed, 53 insertions(+), 27 deletions(-)
 create mode 100644 include/linux/bpf-cgroup-types.h
 create mode 100644 include/linux/bpf-inlines.h

-- 
2.31.1


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

* [PATCH bpf-next v2 1/4] bpf: add header for enum bpf_cgroup_storage_type and bpf_link
  2021-12-15  2:31 [PATCH bpf-next v2 0/4] bpf: remove the cgroup -> bpf header dependecy Jakub Kicinski
@ 2021-12-15  2:31 ` Jakub Kicinski
  2021-12-15  2:31 ` [PATCH bpf-next v2 2/4] bpf: create a header for inline helpers Jakub Kicinski
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Jakub Kicinski @ 2021-12-15  2:31 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] 7+ messages in thread

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

static inlines are notorious for creating inter-header dependencies.
Create a dedicated header where we can place include-heavy inlines
for bpf.

Put cgroup_storage_type() there. It needs to deference bpf_map and
access cgroup types thus creating a dependency between cgroup and
bpf.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 include/linux/bpf-cgroup.h  |  9 ---------
 include/linux/bpf-inlines.h | 17 +++++++++++++++++
 kernel/bpf/helpers.c        |  1 +
 kernel/bpf/local_storage.c  |  1 +
 4 files changed, 19 insertions(+), 9 deletions(-)
 create mode 100644 include/linux/bpf-inlines.h

diff --git a/include/linux/bpf-cgroup.h b/include/linux/bpf-cgroup.h
index 11820a430d6c..12474516e0be 100644
--- a/include/linux/bpf-cgroup.h
+++ b/include/linux/bpf-cgroup.h
@@ -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);
diff --git a/include/linux/bpf-inlines.h b/include/linux/bpf-inlines.h
new file mode 100644
index 000000000000..73d8429d22f1
--- /dev/null
+++ b/include/linux/bpf-inlines.h
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _BPF_INLINES_H
+#define _BPF_INLINES_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
diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
index 8babae03d30a..d33216287b4d 100644
--- a/kernel/bpf/helpers.c
+++ b/kernel/bpf/helpers.c
@@ -2,6 +2,7 @@
 /* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
  */
 #include <linux/bpf.h>
+#include <linux/bpf-inlines.h>
 #include <linux/rcupdate.h>
 #include <linux/random.h>
 #include <linux/smp.h>
diff --git a/kernel/bpf/local_storage.c b/kernel/bpf/local_storage.c
index 035e9e3a7132..bc8cfe03a37e 100644
--- a/kernel/bpf/local_storage.c
+++ b/kernel/bpf/local_storage.c
@@ -1,5 +1,6 @@
 //SPDX-License-Identifier: GPL-2.0
 #include <linux/bpf-cgroup.h>
+#include <linux/bpf-inlines.h>
 #include <linux/bpf.h>
 #include <linux/bpf_local_storage.h>
 #include <linux/btf.h>
-- 
2.31.1


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

* [PATCH bpf-next v2 3/4] add includes masked by cgroup -> bpf dependency
  2021-12-15  2:31 [PATCH bpf-next v2 0/4] bpf: remove the cgroup -> bpf header dependecy Jakub Kicinski
  2021-12-15  2:31 ` [PATCH bpf-next v2 1/4] bpf: add header for enum bpf_cgroup_storage_type and bpf_link Jakub Kicinski
  2021-12-15  2:31 ` [PATCH bpf-next v2 2/4] bpf: create a header for inline helpers Jakub Kicinski
@ 2021-12-15  2:31 ` Jakub Kicinski
  2021-12-15  2:31 ` [PATCH bpf-next v2 4/4] bpf: remove the cgroup -> bpf header dependecy Jakub Kicinski
  3 siblings, 0 replies; 7+ messages in thread
From: Jakub Kicinski @ 2021-12-15  2:31 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] 7+ messages in thread

* [PATCH bpf-next v2 4/4] bpf: remove the cgroup -> bpf header dependecy
  2021-12-15  2:31 [PATCH bpf-next v2 0/4] bpf: remove the cgroup -> bpf header dependecy Jakub Kicinski
                   ` (2 preceding siblings ...)
  2021-12-15  2:31 ` [PATCH bpf-next v2 3/4] add includes masked by cgroup -> bpf dependency Jakub Kicinski
@ 2021-12-15  2:31 ` Jakub Kicinski
  2021-12-15  5:15   ` Alexei Starovoitov
  3 siblings, 1 reply; 7+ messages in thread
From: Jakub Kicinski @ 2021-12-15  2:31 UTC (permalink / raw)
  To: daniel, ast, andrii; +Cc: bpf, Jakub Kicinski

Now 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.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 include/linux/bpf-cgroup.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/linux/bpf-cgroup.h b/include/linux/bpf-cgroup.h
index 12474516e0be..4c932d47e7f2 100644
--- a/include/linux/bpf-cgroup.h
+++ b/include/linux/bpf-cgroup.h
@@ -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;
-- 
2.31.1


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

* Re: [PATCH bpf-next v2 4/4] bpf: remove the cgroup -> bpf header dependecy
  2021-12-15  2:31 ` [PATCH bpf-next v2 4/4] bpf: remove the cgroup -> bpf header dependecy Jakub Kicinski
@ 2021-12-15  5:15   ` Alexei Starovoitov
  2021-12-15  5:54     ` Jakub Kicinski
  0 siblings, 1 reply; 7+ messages in thread
From: Alexei Starovoitov @ 2021-12-15  5:15 UTC (permalink / raw)
  To: Jakub Kicinski; +Cc: Daniel Borkmann, Alexei Starovoitov, Andrii Nakryiko, bpf

On Tue, Dec 14, 2021 at 6:31 PM Jakub Kicinski <kuba@kernel.org> wrote:
>
> Now 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.
>
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> ---
>  include/linux/bpf-cgroup.h | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/bpf-cgroup.h b/include/linux/bpf-cgroup.h
> index 12474516e0be..4c932d47e7f2 100644
> --- a/include/linux/bpf-cgroup.h
> +++ b/include/linux/bpf-cgroup.h
> @@ -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>

Borked rebase with stale header I guess ?

Could you try just patch 1 with bpf-cgroup-types.h
and do s/bpf.h/bpf-cgroup-types.h/ here in bpf-cgroup.h
as patch 2
while moving cgroup_storage_type() function to bpf.h ?
Patch 1 will add +#include <linux/bpf-cgroup-types.h>
to linux/bpf.h,
so cgroup_storage_type() will have everything it needs there.

I could be still missing something.

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

* Re: [PATCH bpf-next v2 4/4] bpf: remove the cgroup -> bpf header dependecy
  2021-12-15  5:15   ` Alexei Starovoitov
@ 2021-12-15  5:54     ` Jakub Kicinski
  0 siblings, 0 replies; 7+ messages in thread
From: Jakub Kicinski @ 2021-12-15  5:54 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: Daniel Borkmann, Alexei Starovoitov, Andrii Nakryiko, bpf

On Tue, 14 Dec 2021 21:15:15 -0800 Alexei Starovoitov wrote:
> On Tue, Dec 14, 2021 at 6:31 PM Jakub Kicinski <kuba@kernel.org> wrote:
> > Now 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.

> >  #ifndef _BPF_CGROUP_H
> >  #define _BPF_CGROUP_H
> >
> > -#include <linux/bpf.h>
> > +#include <linux/bpf-cgroup-types.h>
> > +#include <linux/bpf-link.h>  
> 
> Borked rebase with stale header I guess ?
> 
> Could you try just patch 1 with bpf-cgroup-types.h
> and do s/bpf.h/bpf-cgroup-types.h/ here in bpf-cgroup.h
> as patch 2
> while moving cgroup_storage_type() function to bpf.h ?
> Patch 1 will add +#include <linux/bpf-cgroup-types.h>
> to linux/bpf.h,
> so cgroup_storage_type() will have everything it needs there.
> 
> I could be still missing something.

Right, I must misremembered the reasoning, move to bpf.h should work
just fine.

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

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

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-15  2:31 [PATCH bpf-next v2 0/4] bpf: remove the cgroup -> bpf header dependecy Jakub Kicinski
2021-12-15  2:31 ` [PATCH bpf-next v2 1/4] bpf: add header for enum bpf_cgroup_storage_type and bpf_link Jakub Kicinski
2021-12-15  2:31 ` [PATCH bpf-next v2 2/4] bpf: create a header for inline helpers Jakub Kicinski
2021-12-15  2:31 ` [PATCH bpf-next v2 3/4] add includes masked by cgroup -> bpf dependency Jakub Kicinski
2021-12-15  2:31 ` [PATCH bpf-next v2 4/4] bpf: remove the cgroup -> bpf header dependecy Jakub Kicinski
2021-12-15  5:15   ` Alexei Starovoitov
2021-12-15  5:54     ` 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).