[PATCH v5 1/2] kprobes: textmem API

Jarkko Sakkinen jarkko at kernel.org
Mon Mar 25 19:01:23 PDT 2024


On Tue Mar 26, 2024 at 3:31 AM EET, Jarkko Sakkinen wrote:
> > > +#endif /* _LINUX_EXECMEM_H */
> > > diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> > > index 9d9095e81792..87fd8c14a938 100644
> > > --- a/kernel/kprobes.c
> > > +++ b/kernel/kprobes.c
> > > @@ -44,6 +44,7 @@
> > >  #include <asm/cacheflush.h>
> > >  #include <asm/errno.h>
> > >  #include <linux/uaccess.h>
> > > +#include <linux/execmem.h>
> > >  
> > >  #define KPROBE_HASH_BITS 6
> > >  #define KPROBE_TABLE_SIZE (1 << KPROBE_HASH_BITS)
> > > @@ -113,17 +114,17 @@ enum kprobe_slot_state {
> > >  void __weak *alloc_insn_page(void)
> > >  {
> > >  	/*
> > > -	 * Use module_alloc() so this page is within +/- 2GB of where the
> > > +	 * Use alloc_execmem() so this page is within +/- 2GB of where the
> > >  	 * kernel image and loaded module images reside. This is required
> > >  	 * for most of the architectures.
> > >  	 * (e.g. x86-64 needs this to handle the %rip-relative fixups.)
> > >  	 */
> > > -	return module_alloc(PAGE_SIZE);
> > > +	return alloc_execmem(PAGE_SIZE, GFP_KERNEL);
> > >  }
> > >  
> > >  static void free_insn_page(void *page)
> > >  {
> > > -	module_memfree(page);
> > > +	free_execmem(page);
> > >  }
> > >  
> > >  struct kprobe_insn_cache kprobe_insn_slots = {
> > > @@ -1580,6 +1581,7 @@ static int check_kprobe_address_safe(struct kprobe *p,
> > >  		goto out;
> > >  	}
> > >  
> > > +#ifdef CONFIG_MODULES
> >
> > You don't need this block, because these APIs have dummy functions.
>
> Hmm... I'll verify this tomorrow.

It depends on having struct module available given "(*probed_mod)->state".

It is non-existent unless CONFIG_MODULES is set given how things are
flagged in include/linux/module.h.

BR, Jarkko



More information about the linux-riscv mailing list