From: Calvin Owens <jcalvinowens@gmail.com>
To: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Luis Chamberlain <mcgrof@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Alexei Starovoitov <ast@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Naveen N Rao <naveen.n.rao@linux.ibm.com>,
Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>,
David S Miller <davem@davemloft.net>,
Thomas Gleixner <tglx@linutronix.de>,
"bpf@vger.kernel.org" <bpf@vger.kernel.org>,
"linux-modules@vger.kernel.org" <linux-modules@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [RFC][PATCH 2/4] bpf: Allow BPF_JIT with CONFIG_MODULES=n
Date: Fri, 8 Mar 2024 13:04:53 -0800 [thread overview]
Message-ID: <Zet9ddK2kaEuTrOW@gmail.com> (raw)
In-Reply-To: <a7ac9672-06d1-4f6a-b676-01c9868ea39c@csgroup.eu>
On Thursday 03/07 at 22:09 +0000, Christophe Leroy wrote:
>
>
> Le 06/03/2024 à 21:05, Calvin Owens a écrit :
> > [Vous ne recevez pas souvent de courriers de jcalvinowens@gmail.com. Découvrez pourquoi ceci est important à https://aka.ms/LearnAboutSenderIdentification ]
> >
> > No BPF code has to change, except in struct_ops (for module refs).
> >
> > This conflicts with bpf-next because of this (relevant) series:
> >
> > https://lore.kernel.org/all/20240119225005.668602-1-thinker.li@gmail.com/
> >
> > If something like this is merged down the road, it can go through
> > bpf-next at leisure once the module_alloc change is in: it's a one-way
> > dependency.
> >
> > Signed-off-by: Calvin Owens <jcalvinowens@gmail.com>
> > ---
> > kernel/bpf/Kconfig | 2 +-
> > kernel/bpf/bpf_struct_ops.c | 28 ++++++++++++++++++++++++----
> > 2 files changed, 25 insertions(+), 5 deletions(-)
> >
> > diff --git a/kernel/bpf/Kconfig b/kernel/bpf/Kconfig
> > index 6a906ff93006..77df483a8925 100644
> > --- a/kernel/bpf/Kconfig
> > +++ b/kernel/bpf/Kconfig
> > @@ -42,7 +42,7 @@ config BPF_JIT
> > bool "Enable BPF Just In Time compiler"
> > depends on BPF
> > depends on HAVE_CBPF_JIT || HAVE_EBPF_JIT
> > - depends on MODULES
> > + select MODULE_ALLOC
> > help
> > BPF programs are normally handled by a BPF interpreter. This option
> > allows the kernel to generate native code when a program is loaded
> > diff --git a/kernel/bpf/bpf_struct_ops.c b/kernel/bpf/bpf_struct_ops.c
> > index 02068bd0e4d9..fbf08a1bb00c 100644
> > --- a/kernel/bpf/bpf_struct_ops.c
> > +++ b/kernel/bpf/bpf_struct_ops.c
> > @@ -108,11 +108,30 @@ const struct bpf_prog_ops bpf_struct_ops_prog_ops = {
> > #endif
> > };
> >
> > +#if IS_ENABLED(CONFIG_MODULES)
>
> Can you avoid ifdefs as much as possible ?
Similar to the other one, this was just a misguided attempt to avoid
triggering -Wunused, I'll clean it up.
This particular patch will look very different when rebased on bpf-next.
> > static const struct btf_type *module_type;
> >
> > +static int bpf_struct_module_type_init(struct btf *btf)
> > +{
> > + s32 module_id;
>
> Could be:
>
> if (!IS_ENABLED(CONFIG_MODULES))
> return 0;
>
> > +
> > + module_id = btf_find_by_name_kind(btf, "module", BTF_KIND_STRUCT);
> > + if (module_id < 0)
> > + return 1;
> > +
> > + module_type = btf_type_by_id(btf, module_id);
> > + return 0;
> > +}
> > +#else
> > +static int bpf_struct_module_type_init(struct btf *btf)
> > +{
> > + return 0;
> > +}
> > +#endif
> > +
> > void bpf_struct_ops_init(struct btf *btf, struct bpf_verifier_log *log)
> > {
> > - s32 type_id, value_id, module_id;
> > + s32 type_id, value_id;
> > const struct btf_member *member;
> > struct bpf_struct_ops *st_ops;
> > const struct btf_type *t;
> > @@ -125,12 +144,10 @@ void bpf_struct_ops_init(struct btf *btf, struct bpf_verifier_log *log)
> > #include "bpf_struct_ops_types.h"
> > #undef BPF_STRUCT_OPS_TYPE
> >
> > - module_id = btf_find_by_name_kind(btf, "module", BTF_KIND_STRUCT);
> > - if (module_id < 0) {
> > + if (bpf_struct_module_type_init(btf)) {
> > pr_warn("Cannot find struct module in btf_vmlinux\n");
> > return;
> > }
> > - module_type = btf_type_by_id(btf, module_id);
> >
> > for (i = 0; i < ARRAY_SIZE(bpf_struct_ops); i++) {
> > st_ops = bpf_struct_ops[i];
> > @@ -433,12 +450,15 @@ static long bpf_struct_ops_map_update_elem(struct bpf_map *map, void *key,
> >
> > moff = __btf_member_bit_offset(t, member) / 8;
> > ptype = btf_type_resolve_ptr(btf_vmlinux, member->type, NULL);
> > +
> > +#if IS_ENABLED(CONFIG_MODULES)
>
> Can't see anything depending on CONFIG_MODULES here, can you instead do:
>
> if (IS_ENABLED(CONFIG_MODULES) && ptype == module_type) {
>
> > if (ptype == module_type) {
> > if (*(void **)(udata + moff))
> > goto reset_unlock;
> > *(void **)(kdata + moff) = BPF_MODULE_OWNER;
> > continue;
> > }
> > +#endif
> >
> > err = st_ops->init_member(t, member, kdata, udata);
> > if (err < 0)
> > --
> > 2.43.0
> >
> >
next prev parent reply other threads:[~2024-03-08 21:04 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-06 20:05 [RFC][PATCH 0/4] Make bpf_jit and kprobes work with CONFIG_MODULES=n Calvin Owens
2024-03-06 20:05 ` [RFC][PATCH 1/4] module: mm: Make module_alloc() generally available Calvin Owens
2024-03-07 14:43 ` Christophe Leroy
2024-03-08 20:53 ` Calvin Owens
2024-03-08 2:16 ` Masami Hiramatsu
2024-03-08 20:43 ` Calvin Owens
2024-03-06 20:05 ` [RFC][PATCH 2/4] bpf: Allow BPF_JIT with CONFIG_MODULES=n Calvin Owens
2024-03-07 22:09 ` Christophe Leroy
2024-03-08 21:04 ` Calvin Owens [this message]
2024-03-06 20:05 ` [RFC][PATCH 3/4] kprobes: Allow kprobes " Calvin Owens
2024-03-07 7:22 ` Mike Rapoport
2024-03-08 2:46 ` Masami Hiramatsu
2024-03-08 20:36 ` Calvin Owens
2024-03-07 22:16 ` Christophe Leroy
2024-03-08 21:02 ` Calvin Owens
2024-03-08 2:46 ` Masami Hiramatsu
2024-03-08 20:57 ` Calvin Owens
2024-03-06 20:05 ` [RFC][PATCH 4/4] selftests/bpf: Support testing the !MODULES case Calvin Owens
2024-03-06 21:34 ` [RFC][PATCH 0/4] Make bpf_jit and kprobes work with CONFIG_MODULES=n Luis Chamberlain
2024-03-06 23:23 ` Calvin Owens
2024-03-07 1:58 ` Song Liu
2024-03-08 2:50 ` Masami Hiramatsu
2024-03-08 2:55 ` Luis Chamberlain
2024-03-08 20:27 ` Calvin Owens
2024-03-07 7:13 ` Mike Rapoport
2024-03-08 2:45 ` Masami Hiramatsu
2024-03-25 22:46 ` Jarkko Sakkinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Zet9ddK2kaEuTrOW@gmail.com \
--to=jcalvinowens@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=andrii@kernel.org \
--cc=anil.s.keshavamurthy@intel.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=christophe.leroy@csgroup.eu \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-modules@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=mhiramat@kernel.org \
--cc=naveen.n.rao@linux.ibm.com \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).