linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH v5 11/15] arch: make execmem setup available regardless of CONFIG_MODULES
       [not found] ` <20240422094436.3625171-12-rppt@kernel.org>
@ 2024-04-22 12:11   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-04-22 12:11 UTC (permalink / raw)
  To: Mike Rapoport, linux-kernel
  Cc: Mark Rutland, x86, Sam Ravnborg, Peter Zijlstra, Catalin Marinas,
	Song Liu, Donald Dutile, sparclinux, linux-riscv, Nadav Amit,
	linux-arch, linux-s390, Helge Deller, Huacai Chen, Russell King,
	linux-trace-kernel, Alexandre Ghiti, Will Deacon, Heiko Carstens,
	Steven Rostedt, loongarch, Björn Töpel,
	Thomas Gleixner, bpf, linux-arm-kernel, Thomas Bogendoerfer,
	linux-parisc, linux-mm, netdev, Kent Overstreet, linux-mips,
	Dinh Nguyen, Luis Chamberlain, Eric Chanudet, Palmer Dabbelt,
	Masami Hiramatsu, Andrew Morton, Rick Edgecombe, linuxppc-dev,
	David S. Miller, linux-modules

On 22/4/24 11:44, Mike Rapoport wrote:
> From: "Mike Rapoport (IBM)" <rppt@kernel.org>
> 
> execmem does not depend on modules, on the contrary modules use
> execmem.
> 
> To make execmem available when CONFIG_MODULES=n, for instance for
> kprobes, split execmem_params initialization out from
> arch/*/kernel/module.c and compile it when CONFIG_EXECMEM=y
> 
> Signed-off-by: Mike Rapoport (IBM) <rppt@kernel.org>
> ---
>   arch/arm/kernel/module.c       |  43 ----------
>   arch/arm/mm/init.c             |  45 +++++++++++
>   arch/arm64/kernel/module.c     | 140 ---------------------------------
>   arch/arm64/mm/init.c           | 140 +++++++++++++++++++++++++++++++++
>   arch/loongarch/kernel/module.c |  19 -----
>   arch/loongarch/mm/init.c       |  21 +++++
>   arch/mips/kernel/module.c      |  22 ------
>   arch/mips/mm/init.c            |  23 ++++++
>   arch/nios2/kernel/module.c     |  20 -----
>   arch/nios2/mm/init.c           |  21 +++++
>   arch/parisc/kernel/module.c    |  20 -----
>   arch/parisc/mm/init.c          |  23 +++++-
>   arch/powerpc/kernel/module.c   |  63 ---------------
>   arch/powerpc/mm/mem.c          |  64 +++++++++++++++
>   arch/riscv/kernel/module.c     |  44 -----------
>   arch/riscv/mm/init.c           |  45 +++++++++++
>   arch/s390/kernel/module.c      |  27 -------
>   arch/s390/mm/init.c            |  30 +++++++
>   arch/sparc/kernel/module.c     |  19 -----
>   arch/sparc/mm/Makefile         |   2 +
>   arch/sparc/mm/execmem.c        |  21 +++++
>   arch/x86/kernel/module.c       |  27 -------
>   arch/x86/mm/init.c             |  29 +++++++
>   23 files changed, 463 insertions(+), 445 deletions(-)
>   create mode 100644 arch/sparc/mm/execmem.c

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>


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

* Re: [PATCH v5 14/15] kprobes: remove dependency on CONFIG_MODULES
       [not found] ` <20240422094436.3625171-15-rppt@kernel.org>
@ 2024-04-22 14:11   ` Masami Hiramatsu
  0 siblings, 0 replies; 3+ messages in thread
From: Masami Hiramatsu @ 2024-04-22 14:11 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: Mark Rutland, x86, Sam Ravnborg, Peter Zijlstra, Catalin Marinas,
	Russell King, Song Liu, Donald Dutile, sparclinux, linux-riscv,
	Nadav Amit, linux-arch, linux-s390, Helge Deller, Huacai Chen,
	Luis Chamberlain, linux-mips, linux-trace-kernel,
	Alexandre Ghiti, Will Deacon, Heiko Carstens, Steven Rostedt,
	loongarch, Thomas Gleixner, bpf, linux-arm-kernel,
	Thomas Bogendoerfer, linux-parisc, linux-mm, netdev,
	Kent Over street, linux-kernel, Dinh Nguyen,
	Björn Töpel, Eric Chanudet, Palmer Dabbelt,
	Masami Hiramatsu, Andrew Morton, Rick Edgecombe, linuxppc-dev,
	David S. Miller, linux-modules

On Mon, 22 Apr 2024 12:44:35 +0300
Mike Rapoport <rppt@kernel.org> wrote:

> From: "Mike Rapoport (IBM)" <rppt@kernel.org>
> 
> kprobes depended on CONFIG_MODULES because it has to allocate memory for
> code.
> 
> Since code allocations are now implemented with execmem, kprobes can be
> enabled in non-modular kernels.
> 
> Add #ifdef CONFIG_MODULE guards for the code dealing with kprobes inside
> modules, make CONFIG_KPROBES select CONFIG_EXECMEM and drop the
> dependency of CONFIG_KPROBES on CONFIG_MODULES.

Looks good to me.

Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Thank you!

> 
> Signed-off-by: Mike Rapoport (IBM) <rppt@kernel.org>
> ---
>  arch/Kconfig                |  2 +-
>  include/linux/module.h      |  9 ++++++
>  kernel/kprobes.c            | 55 +++++++++++++++++++++++--------------
>  kernel/trace/trace_kprobe.c | 20 +++++++++++++-
>  4 files changed, 63 insertions(+), 23 deletions(-)
> 
> diff --git a/arch/Kconfig b/arch/Kconfig
> index 7006f71f0110..a48ce6a488b3 100644
> --- a/arch/Kconfig
> +++ b/arch/Kconfig
> @@ -52,9 +52,9 @@ config GENERIC_ENTRY
>  
>  config KPROBES
>  	bool "Kprobes"
> -	depends on MODULES
>  	depends on HAVE_KPROBES
>  	select KALLSYMS
> +	select EXECMEM
>  	select TASKS_RCU if PREEMPTION
>  	help
>  	  Kprobes allows you to trap at almost any kernel address and
> diff --git a/include/linux/module.h b/include/linux/module.h
> index 1153b0d99a80..ffa1c603163c 100644
> --- a/include/linux/module.h
> +++ b/include/linux/module.h
> @@ -605,6 +605,11 @@ static inline bool module_is_live(struct module *mod)
>  	return mod->state != MODULE_STATE_GOING;
>  }
>  
> +static inline bool module_is_coming(struct module *mod)
> +{
> +        return mod->state == MODULE_STATE_COMING;
> +}
> +
>  struct module *__module_text_address(unsigned long addr);
>  struct module *__module_address(unsigned long addr);
>  bool is_module_address(unsigned long addr);
> @@ -857,6 +862,10 @@ void *dereference_module_function_descriptor(struct module *mod, void *ptr)
>  	return ptr;
>  }
>  
> +static inline bool module_is_coming(struct module *mod)
> +{
> +	return false;
> +}
>  #endif /* CONFIG_MODULES */
>  
>  #ifdef CONFIG_SYSFS
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index ddd7cdc16edf..ca2c6cbd42d2 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -1588,7 +1588,7 @@ static int check_kprobe_address_safe(struct kprobe *p,
>  	}
>  
>  	/* Get module refcount and reject __init functions for loaded modules. */
> -	if (*probed_mod) {
> +	if (IS_ENABLED(CONFIG_MODULES) && *probed_mod) {
>  		/*
>  		 * We must hold a refcount of the probed module while updating
>  		 * its code to prohibit unexpected unloading.
> @@ -1603,12 +1603,13 @@ static int check_kprobe_address_safe(struct kprobe *p,
>  		 * kprobes in there.
>  		 */
>  		if (within_module_init((unsigned long)p->addr, *probed_mod) &&
> -		    (*probed_mod)->state != MODULE_STATE_COMING) {
> +		    !module_is_coming(*probed_mod)) {
>  			module_put(*probed_mod);
>  			*probed_mod = NULL;
>  			ret = -ENOENT;
>  		}
>  	}
> +
>  out:
>  	preempt_enable();
>  	jump_label_unlock();
> @@ -2488,24 +2489,6 @@ int kprobe_add_area_blacklist(unsigned long start, unsigned long end)
>  	return 0;
>  }
>  
> -/* Remove all symbols in given area from kprobe blacklist */
> -static void kprobe_remove_area_blacklist(unsigned long start, unsigned long end)
> -{
> -	struct kprobe_blacklist_entry *ent, *n;
> -
> -	list_for_each_entry_safe(ent, n, &kprobe_blacklist, list) {
> -		if (ent->start_addr < start || ent->start_addr >= end)
> -			continue;
> -		list_del(&ent->list);
> -		kfree(ent);
> -	}
> -}
> -
> -static void kprobe_remove_ksym_blacklist(unsigned long entry)
> -{
> -	kprobe_remove_area_blacklist(entry, entry + 1);
> -}
> -
>  int __weak arch_kprobe_get_kallsym(unsigned int *symnum, unsigned long *value,
>  				   char *type, char *sym)
>  {
> @@ -2570,6 +2553,25 @@ static int __init populate_kprobe_blacklist(unsigned long *start,
>  	return ret ? : arch_populate_kprobe_blacklist();
>  }
>  
> +#ifdef CONFIG_MODULES
> +/* Remove all symbols in given area from kprobe blacklist */
> +static void kprobe_remove_area_blacklist(unsigned long start, unsigned long end)
> +{
> +	struct kprobe_blacklist_entry *ent, *n;
> +
> +	list_for_each_entry_safe(ent, n, &kprobe_blacklist, list) {
> +		if (ent->start_addr < start || ent->start_addr >= end)
> +			continue;
> +		list_del(&ent->list);
> +		kfree(ent);
> +	}
> +}
> +
> +static void kprobe_remove_ksym_blacklist(unsigned long entry)
> +{
> +	kprobe_remove_area_blacklist(entry, entry + 1);
> +}
> +
>  static void add_module_kprobe_blacklist(struct module *mod)
>  {
>  	unsigned long start, end;
> @@ -2672,6 +2674,17 @@ static struct notifier_block kprobe_module_nb = {
>  	.priority = 0
>  };
>  
> +static int kprobe_register_module_notifier(void)
> +{
> +	return register_module_notifier(&kprobe_module_nb);
> +}
> +#else
> +static int kprobe_register_module_notifier(void)
> +{
> +	return 0;
> +}
> +#endif /* CONFIG_MODULES */
> +
>  void kprobe_free_init_mem(void)
>  {
>  	void *start = (void *)(&__init_begin);
> @@ -2731,7 +2744,7 @@ static int __init init_kprobes(void)
>  	if (!err)
>  		err = register_die_notifier(&kprobe_exceptions_nb);
>  	if (!err)
> -		err = register_module_notifier(&kprobe_module_nb);
> +		err = kprobe_register_module_notifier();
>  
>  	kprobes_initialized = (err == 0);
>  	kprobe_sysctls_init();
> diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
> index 14099cc17fc9..2cb2a3951b4f 100644
> --- a/kernel/trace/trace_kprobe.c
> +++ b/kernel/trace/trace_kprobe.c
> @@ -111,6 +111,7 @@ static nokprobe_inline bool trace_kprobe_within_module(struct trace_kprobe *tk,
>  	return strncmp(module_name(mod), name, len) == 0 && name[len] == ':';
>  }
>  
> +#ifdef CONFIG_MODULES
>  static nokprobe_inline bool trace_kprobe_module_exist(struct trace_kprobe *tk)
>  {
>  	char *p;
> @@ -129,6 +130,12 @@ static nokprobe_inline bool trace_kprobe_module_exist(struct trace_kprobe *tk)
>  
>  	return ret;
>  }
> +#else
> +static inline bool trace_kprobe_module_exist(struct trace_kprobe *tk)
> +{
> +	return false;
> +}
> +#endif
>  
>  static bool trace_kprobe_is_busy(struct dyn_event *ev)
>  {
> @@ -670,6 +677,7 @@ static int register_trace_kprobe(struct trace_kprobe *tk)
>  	return ret;
>  }
>  
> +#ifdef CONFIG_MODULES
>  /* Module notifier call back, checking event on the module */
>  static int trace_kprobe_module_callback(struct notifier_block *nb,
>  				       unsigned long val, void *data)
> @@ -704,6 +712,16 @@ static struct notifier_block trace_kprobe_module_nb = {
>  	.notifier_call = trace_kprobe_module_callback,
>  	.priority = 1	/* Invoked after kprobe module callback */
>  };
> +static int trace_kprobe_register_module_notifier(void)
> +{
> +	return register_module_notifier(&trace_kprobe_module_nb);
> +}
> +#else
> +static int trace_kprobe_register_module_notifier(void)
> +{
> +	return 0;
> +}
> +#endif /* CONFIG_MODULES */
>  
>  static int count_symbols(void *data, unsigned long unused)
>  {
> @@ -1933,7 +1951,7 @@ static __init int init_kprobe_trace_early(void)
>  	if (ret)
>  		return ret;
>  
> -	if (register_module_notifier(&trace_kprobe_module_nb))
> +	if (trace_kprobe_register_module_notifier())
>  		return -EINVAL;
>  
>  	return 0;
> -- 
> 2.43.0
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

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

* Re: [PATCH v5 04/15] sparc: simplify module_alloc()
       [not found] ` <20240422094436.3625171-5-rppt@kernel.org>
@ 2024-04-23 16:41   ` Sam Ravnborg
  0 siblings, 0 replies; 3+ messages in thread
From: Sam Ravnborg @ 2024-04-23 16:41 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: Mark Rutland, x86, Peter Zijlstra, Catalin Marinas, Russell King,
	Song Liu, Donald Dutile, sparclinux, linux-riscv, Nadav Amit,
	linux-arch, linux-s390, Helge Deller, Huacai Chen,
	Luis Chamberlain, linux-mips, linux-trace-kernel,
	Alexandre Ghiti, Will Deacon, Heiko Carstens, Steven Rostedt,
	loongarch, Thomas Gleixner, bpf, linux-arm-kernel,
	Thomas Bogendoerfer, linux-parisc, linux-mm, netdev,
	Kent Overstreet, linux-kernel, Dinh Nguyen,
	Björn Töpel, Eric Chanudet, Palmer Dabbelt,
	Masami Hiramatsu, Andrew Morton, Rick Edgecombe, linuxppc-dev,
	David S. Miller, linux-modules

Hi Mike,
On Mon, Apr 22, 2024 at 12:44:25PM +0300, Mike Rapoport wrote:
> From: "Mike Rapoport (IBM)" <rppt@kernel.org>
> 
> Define MODULES_VADDR and MODULES_END as VMALLOC_START and VMALLOC_END
> for 32-bit and reduce module_alloc() to
> 
> 	__vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, ...)
> 
> as with the new defines the allocations becames identical for both 32
> and 64 bits.
> 
> While on it, drop unsed include of <linux/jump_label.h>
> 
> Suggested-by: Sam Ravnborg <sam@ravnborg.org>
> Signed-off-by: Mike Rapoport (IBM) <rppt@kernel.org>

Looks good.
Reviewed-by: Sam Ravnborg <sam@ravnborg.org>

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

end of thread, other threads:[~2024-04-23 16:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20240422094436.3625171-1-rppt@kernel.org>
     [not found] ` <20240422094436.3625171-12-rppt@kernel.org>
2024-04-22 12:11   ` [PATCH v5 11/15] arch: make execmem setup available regardless of CONFIG_MODULES Philippe Mathieu-Daudé
     [not found] ` <20240422094436.3625171-15-rppt@kernel.org>
2024-04-22 14:11   ` [PATCH v5 14/15] kprobes: remove dependency on CONFIG_MODULES Masami Hiramatsu
     [not found] ` <20240422094436.3625171-5-rppt@kernel.org>
2024-04-23 16:41   ` [PATCH v5 04/15] sparc: simplify module_alloc() Sam Ravnborg

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