public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] samples/hw_breakpoint: fix building without module unloading
@ 2023-07-25  8:25 Arnd Bergmann
  2023-07-25  9:38 ` Petr Mladek
  0 siblings, 1 reply; 3+ messages in thread
From: Arnd Bergmann @ 2023-07-25  8:25 UTC (permalink / raw)
  To: Luis Chamberlain
  Cc: Arnd Bergmann, Rong Tao, Petr Mladek, Masami Hiramatsu,
	Andrew Morton, Will Deacon, Quentin Perret, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

__symbol_put() is really meant as an internal helper and is not available
when module unloading is disabled, unlike the previously used symbol_put():

samples/hw_breakpoint/data_breakpoint.c: In function 'hw_break_module_exit':
samples/hw_breakpoint/data_breakpoint.c:73:9: error: implicit declaration of function '__symbol_put'; did you mean '__symbol_get'? [-Werror=implicit-function-declaration]

The hw_break_module_exit() function is not actually used when module
unloading is disabled, but it still causes the build failure for an
undefined identifier. Enclose this one call in an appropriate #ifdef to
clarify what the requirement is. Leaving out the entire exit function
would also work but feels less clar in this case.

Fixes: 910e230d5f1bb ("samples/hw_breakpoint: Fix kernel BUG 'invalid opcode: 0000'")
Fixes: d8a84d33a4954 ("samples/hw_breakpoint: drop use of kallsyms_lookup_name()")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 samples/hw_breakpoint/data_breakpoint.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/samples/hw_breakpoint/data_breakpoint.c b/samples/hw_breakpoint/data_breakpoint.c
index 9debd128b2ab8..b99322f188e59 100644
--- a/samples/hw_breakpoint/data_breakpoint.c
+++ b/samples/hw_breakpoint/data_breakpoint.c
@@ -70,7 +70,9 @@ static int __init hw_break_module_init(void)
 static void __exit hw_break_module_exit(void)
 {
 	unregister_wide_hw_breakpoint(sample_hbp);
+#ifdef CONFIG_MODULE_UNLOAD
 	__symbol_put(ksym_name);
+#endif
 	printk(KERN_INFO "HW Breakpoint for %s write uninstalled\n", ksym_name);
 }
 
-- 
2.39.2


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

* Re: [PATCH] samples/hw_breakpoint: fix building without module unloading
  2023-07-25  8:25 [PATCH] samples/hw_breakpoint: fix building without module unloading Arnd Bergmann
@ 2023-07-25  9:38 ` Petr Mladek
  2023-07-25 23:35   ` Luis Chamberlain
  0 siblings, 1 reply; 3+ messages in thread
From: Petr Mladek @ 2023-07-25  9:38 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Luis Chamberlain, Arnd Bergmann, Rong Tao, Masami Hiramatsu,
	Andrew Morton, Will Deacon, Quentin Perret, linux-kernel

On Tue 2023-07-25 10:25:36, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> __symbol_put() is really meant as an internal helper and is not available
> when module unloading is disabled, unlike the previously used symbol_put():

Ah, I have missed this.

> samples/hw_breakpoint/data_breakpoint.c: In function 'hw_break_module_exit':
> samples/hw_breakpoint/data_breakpoint.c:73:9: error: implicit declaration of function '__symbol_put'; did you mean '__symbol_get'? [-Werror=implicit-function-declaration]
> 
> The hw_break_module_exit() function is not actually used when module
> unloading is disabled, but it still causes the build failure for an
> undefined identifier. Enclose this one call in an appropriate #ifdef to
> clarify what the requirement is. Leaving out the entire exit function
> would also work but feels less clar in this case.

> --- a/samples/hw_breakpoint/data_breakpoint.c
> +++ b/samples/hw_breakpoint/data_breakpoint.c
> @@ -70,7 +70,9 @@ static int __init hw_break_module_init(void)
>  static void __exit hw_break_module_exit(void)
>  {
>  	unregister_wide_hw_breakpoint(sample_hbp);
> +#ifdef CONFIG_MODULE_UNLOAD
>  	__symbol_put(ksym_name);
> +#endif
>  	printk(KERN_INFO "HW Breakpoint for %s write uninstalled\n", ksym_name);
>  }

I see that both symbol_put() and symbol_put_addr() are defined
as noops twice:

   + when !defined(CONFIG_MODULE_UNLOAD)
   + when !defined(CONFIG_MODULES)

This patch is enough because samples/hw_breakpoint/data_breakpoint.c
could be built only as a module, so feel free to use:

Reviewed-by: Petr Mladek <pmladek@suse.com>

But even better solution would be to define symbol_put_name() as
a noop in both situations and use it.

Best Regards,
Petr

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

* Re: [PATCH] samples/hw_breakpoint: fix building without module unloading
  2023-07-25  9:38 ` Petr Mladek
@ 2023-07-25 23:35   ` Luis Chamberlain
  0 siblings, 0 replies; 3+ messages in thread
From: Luis Chamberlain @ 2023-07-25 23:35 UTC (permalink / raw)
  To: Petr Mladek
  Cc: Arnd Bergmann, Arnd Bergmann, Rong Tao, Masami Hiramatsu,
	Andrew Morton, Will Deacon, Quentin Perret, linux-kernel

On Tue, Jul 25, 2023 at 11:38:48AM +0200, Petr Mladek wrote:
> Reviewed-by: Petr Mladek <pmladek@suse.com>

Thanks, patch applied and pushed!

> But even better solution would be to define symbol_put_name() as
> a noop in both situations and use it.

Patch welcomed!

  Luis

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

end of thread, other threads:[~2023-07-25 23:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-25  8:25 [PATCH] samples/hw_breakpoint: fix building without module unloading Arnd Bergmann
2023-07-25  9:38 ` Petr Mladek
2023-07-25 23:35   ` Luis Chamberlain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox