linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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 1/4] module: mm: Make module_alloc() generally available
Date: Fri, 8 Mar 2024 12:53:41 -0800	[thread overview]
Message-ID: <Zet61a2jTaSV1eF0@gmail.com> (raw)
In-Reply-To: <267d9173-2a0e-4006-a858-4e94aeff94df@csgroup.eu>

On Thursday 03/07 at 14:43 +0000, Christophe Leroy wrote:
> Hi Calvin,
> 
> 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 ]
> > 
> > Both BPF_JIT and KPROBES depend on CONFIG_MODULES, but only require
> > module_alloc() itself, which can be easily separated into a standalone
> > allocator for executable kernel memory.
> 
> Easily maybe, but not as easily as you think, see below.
> 
> > 
> > Thomas Gleixner sent a patch to do that for x86 as part of a larger
> > series a couple years ago:
> > 
> >      https://lore.kernel.org/all/20220716230953.442937066@linutronix.de/
> > 
> > I've simply extended that approach to the whole kernel.
> > 
> > Signed-off-by: Calvin Owens <jcalvinowens@gmail.com>
> > ---
> >   arch/Kconfig                     |   2 +-
> >   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 ++++++++++
> 
> Missing several powerpc changes to make it work. You must audit every 
> use of CONFIG_MODULES inside powerpc. Here are a few exemples:
> 
> Function get_patch_pfn() to enable text code patching.
> 
> arch/powerpc/Kconfig : 	select KASAN_VMALLOC			if KASAN && MODULES
> 
> arch/powerpc/include/asm/kasan.h:
> 
> #if defined(CONFIG_MODULES) && defined(CONFIG_PPC32)
> #define KASAN_KERN_START	ALIGN_DOWN(PAGE_OFFSET - SZ_256M, SZ_256M)
> #else
> #define KASAN_KERN_START	PAGE_OFFSET
> #endif
> 
> arch/powerpc/kernel/head_8xx.S and arch/powerpc/kernel/head_book3s_32.S: 
> InstructionTLBMiss interrupt handler must know that there is executable 
> kernel text outside kernel core.
> 
> Function is_module_segment() to identified segments used for module text 
> and set NX (NoExec) MMU flag on non-module segments.

Thanks Christophe, I'll fix that up.

I'm sure there are many other issues like this in the arch stuff here,
I'm going to run them all through QEMU to catch everything I can before
the next respin.

> >   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 +-
> >   kernel/module/Kconfig            |   1 +
> >   kernel/module/main.c             |  17 ----
> >   mm/Kconfig                       |   3 +
> >   mm/Makefile                      |   1 +
> >   mm/module_alloc.c                |  21 +++++
> >   mm/vmalloc.c                     |   2 +-
> >   42 files changed, 467 insertions(+), 402 deletions(-)
> 
> ...
> 
> > diff --git a/mm/Kconfig b/mm/Kconfig
> > index ffc3a2ba3a8c..92bfb5ae2e95 100644
> > --- a/mm/Kconfig
> > +++ b/mm/Kconfig
> > @@ -1261,6 +1261,9 @@ config LOCK_MM_AND_FIND_VMA
> >   config IOMMU_MM_DATA
> >          bool
> > 
> > +config MODULE_ALLOC
> > +       def_bool n
> > +
> 
> I'd call it something else than CONFIG_MODULE_ALLOC as you want to use 
> it when CONFIG_MODULE is not selected.
> 
> Something like CONFIG_EXECMEM_ALLOC or CONFIG_DYNAMIC_EXECMEM ?
> 
> 
> 
> Christophe

  reply	other threads:[~2024-03-08 20:53 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 [this message]
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

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=Zet61a2jTaSV1eF0@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).