All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jarkko Sakkinen" <jarkko@kernel.org>
To: "Calvin Owens" <jcalvinowens@gmail.com>,
	"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>
Cc: <bpf@vger.kernel.org>, <linux-modules@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [RFC][PATCH 0/4] Make bpf_jit and kprobes work with CONFIG_MODULES=n
Date: Tue, 26 Mar 2024 00:46:14 +0200	[thread overview]
Message-ID: <D0372IKSFG0T.B9NV4SYAWPJ2@kernel.org> (raw)
In-Reply-To: <cover.1709676663.git.jcalvinowens@gmail.com>

On Wed Mar 6, 2024 at 10:05 PM EET, Calvin Owens wrote:
> Hello all,
>
> This patchset makes it possible to use bpftrace with kprobes on kernels
> built without loadable module support.
>
> On a Raspberry Pi 4b, this saves about 700KB of memory where BPF is
> needed but loadable module support is not. These two kernels had
> identical configurations, except CONFIG_MODULE was off in the second:
>
>    - Linux version 6.8.0-rc7
>    - Memory: 3330672K/4050944K available (16576K kernel code, 2390K rwdata,
>    - 12364K rodata, 5632K init, 675K bss, 195984K reserved, 524288K cma-reserved)
>    + Linux version 6.8.0-rc7-00003-g2af01251ca21
>    + Memory: 3331400K/4050944K available (16512K kernel code, 2384K rwdata,
>    + 11728K rodata, 5632K init, 673K bss, 195256K reserved, 524288K cma-reserved)
>
> I don't intend to present an exhaustive list of !MODULES usecases, since
> I'm sure there are many I'm not aware of. Performance is a common one,
> the primary justification being that static text is mapped on hugepages
> and module text is not. Security is another, since rootkits are much
> harder to implement without modules.
>
> The first patch is the interesting one: it moves module_alloc() into its
> own file with its own Kconfig option, so it can be utilized even when
> loadable module support is disabled. I got the idea from an unmerged
> patch from a few years ago I found on lkml (see [1/4] for details). I
> think this also has value in its own right, since I suspect there are
> potential users beyond bpf, hopefully we will hear from some.
>
> Patches 2-3 are proofs of concept to demonstrate the first patch is
> sufficient to achieve my goal (full ebpf functionality without modules).
>
> Patch 4 adds a new "-n" argument to vmtest.sh to run the BPF selftests
> without modules, so the prior three patches can be rigorously tested.
>
> If something like the first patch were to eventually be merged, the rest
> could go through the normal bpf-next process as I clean them up: I've
> only based them on Linus' tree and combined them into a series here to
> introduce the idea.
>
> If you prefer to fetch the patches via git:
>
>   [1/4] https://github.com/jcalvinowens/linux.git work/module-alloc
>  +[2/4]+[3/4] https://github.com/jcalvinowens/linux.git work/nomodule-bpf
>  +[4/4] https://github.com/jcalvinowens/linux.git testing/nomodule-bpf-ci
>
> In addition to the automated BPF selftests, I've lightly tested this on
> my laptop (x86_64), a Raspberry Pi 4b (arm64), and a Raspberry Pi Zero W
> (arm). The other architectures have only been compile tested.
>
> I didn't want to spam all the arch maintainers with what I expect will
> be a discussion mostly about modules and bpf, so I've left them off this
> first submission. I will be sure to add them on future submissions of
> the first patch. Of course, feedback on the arch bits is welcome here.
>
> In addition to feedback on the patches themselves, I'm interested in
> hearing from anybody else who might find this functionality useful.
>
> Thanks,
> Calvin
>
>
> Calvin Owens (4):
>   module: mm: Make module_alloc() generally available
>   bpf: Allow BPF_JIT with CONFIG_MODULES=n
>   kprobes: Allow kprobes with CONFIG_MODULES=n
>   selftests/bpf: Support testing the !MODULES case
>
>  arch/Kconfig                                  |   4 +-
>  arch/arm/kernel/module.c                      |  35 -----
>  arch/arm/mm/Makefile                          |   2 +
>  arch/arm/mm/module_alloc.c                    |  40 ++++++
>  arch/arm64/kernel/module.c                    | 127 -----------------
>  arch/arm64/mm/Makefile                        |   1 +
>  arch/arm64/mm/module_alloc.c                  | 130 ++++++++++++++++++
>  arch/loongarch/kernel/module.c                |   6 -
>  arch/loongarch/mm/Makefile                    |   2 +
>  arch/loongarch/mm/module_alloc.c              |  10 ++
>  arch/mips/kernel/module.c                     |  10 --
>  arch/mips/mm/Makefile                         |   2 +
>  arch/mips/mm/module_alloc.c                   |  13 ++
>  arch/nios2/kernel/module.c                    |  20 ---
>  arch/nios2/mm/Makefile                        |   2 +
>  arch/nios2/mm/module_alloc.c                  |  22 +++
>  arch/parisc/kernel/module.c                   |  12 --
>  arch/parisc/mm/Makefile                       |   1 +
>  arch/parisc/mm/module_alloc.c                 |  15 ++
>  arch/powerpc/kernel/module.c                  |  36 -----
>  arch/powerpc/mm/Makefile                      |   1 +
>  arch/powerpc/mm/module_alloc.c                |  41 ++++++
>  arch/riscv/kernel/module.c                    |  11 --
>  arch/riscv/mm/Makefile                        |   1 +
>  arch/riscv/mm/module_alloc.c                  |  17 +++
>  arch/s390/kernel/module.c                     |  37 -----
>  arch/s390/mm/Makefile                         |   1 +
>  arch/s390/mm/module_alloc.c                   |  42 ++++++
>  arch/sparc/kernel/module.c                    |  31 -----
>  arch/sparc/mm/Makefile                        |   2 +
>  arch/sparc/mm/module_alloc.c                  |  31 +++++
>  arch/x86/kernel/ftrace.c                      |   2 +-
>  arch/x86/kernel/module.c                      |  56 --------
>  arch/x86/mm/Makefile                          |   2 +
>  arch/x86/mm/module_alloc.c                    |  59 ++++++++
>  fs/proc/kcore.c                               |   2 +-
>  include/trace/events/bpf_testmod.h            |   1 +
>  kernel/bpf/Kconfig                            |  11 +-
>  kernel/bpf/Makefile                           |   2 +
>  kernel/bpf/bpf_struct_ops.c                   |  28 +++-
>  kernel/bpf/bpf_testmod/Makefile               |   1 +
>  kernel/bpf/bpf_testmod/bpf_testmod.c          |   1 +
>  kernel/bpf/bpf_testmod/bpf_testmod.h          |   1 +
>  kernel/bpf/bpf_testmod/bpf_testmod_kfunc.h    |   1 +
>  kernel/kprobes.c                              |  22 +++
>  kernel/module/Kconfig                         |   1 +
>  kernel/module/main.c                          |  17 ---
>  kernel/trace/trace_kprobe.c                   |  11 ++
>  mm/Kconfig                                    |   3 +
>  mm/Makefile                                   |   1 +
>  mm/module_alloc.c                             |  21 +++
>  mm/vmalloc.c                                  |   2 +-
>  net/bpf/test_run.c                            |   2 +
>  tools/testing/selftests/bpf/Makefile          |  28 ++--
>  .../selftests/bpf/bpf_testmod/Makefile        |   2 +-
>  .../bpf/bpf_testmod/bpf_testmod-events.h      |   6 +
>  .../selftests/bpf/bpf_testmod/bpf_testmod.c   |   4 +
>  .../bpf/bpf_testmod/bpf_testmod_kfunc.h       |   2 +
>  tools/testing/selftests/bpf/config            |   5 -
>  tools/testing/selftests/bpf/config.mods       |   5 +
>  tools/testing/selftests/bpf/config.nomods     |   1 +
>  .../selftests/bpf/progs/btf_type_tag_percpu.c |   2 +
>  .../selftests/bpf/progs/btf_type_tag_user.c   |   2 +
>  tools/testing/selftests/bpf/progs/core_kern.c |   2 +
>  .../selftests/bpf/progs/iters_testmod_seq.c   |   2 +
>  .../bpf/progs/test_core_reloc_module.c        |   2 +
>  .../selftests/bpf/progs/test_ldsx_insn.c      |   2 +
>  .../selftests/bpf/progs/test_module_attach.c  |   3 +
>  .../selftests/bpf/progs/tracing_struct.c      |   2 +
>  tools/testing/selftests/bpf/testing_helpers.c |  14 ++
>  tools/testing/selftests/bpf/vmtest.sh         |  24 +++-
>  71 files changed, 636 insertions(+), 424 deletions(-)
>  create mode 100644 arch/arm/mm/module_alloc.c
>  create mode 100644 arch/arm64/mm/module_alloc.c
>  create mode 100644 arch/loongarch/mm/module_alloc.c
>  create mode 100644 arch/mips/mm/module_alloc.c
>  create mode 100644 arch/nios2/mm/module_alloc.c
>  create mode 100644 arch/parisc/mm/module_alloc.c
>  create mode 100644 arch/powerpc/mm/module_alloc.c
>  create mode 100644 arch/riscv/mm/module_alloc.c
>  create mode 100644 arch/s390/mm/module_alloc.c
>  create mode 100644 arch/sparc/mm/module_alloc.c
>  create mode 100644 arch/x86/mm/module_alloc.c
>  create mode 120000 include/trace/events/bpf_testmod.h
>  create mode 100644 kernel/bpf/bpf_testmod/Makefile
>  create mode 120000 kernel/bpf/bpf_testmod/bpf_testmod.c
>  create mode 120000 kernel/bpf/bpf_testmod/bpf_testmod.h
>  create mode 120000 kernel/bpf/bpf_testmod/bpf_testmod_kfunc.h
>  create mode 100644 mm/module_alloc.c
>  create mode 100644 tools/testing/selftests/bpf/config.mods
>  create mode 100644 tools/testing/selftests/bpf/config.nomods

I think with eBPF focus in the patch set should be only on arch's
that you use regulary, i.e. repeating same mistake I did couple of
years ago:

https://lore.kernel.org/all/20220608000014.3054333-1-jarkko@profian.com/

I don't see my patch set conflict with this work, and it adds needed
shenanigans to realize eBPF patches. I refined the shenanigans to match
Masami's suggestions:

https://lore.kernel.org/all/20240325215502.660-1-jarkko@kernel.org/

And it this requires properly working kprobes anyway.

BR, Jarkko

      parent reply	other threads:[~2024-03-25 22:46 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
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 [this message]

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=D0372IKSFG0T.B9NV4SYAWPJ2@kernel.org \
    --to=jarkko@kernel.org \
    --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=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=jcalvinowens@gmail.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.