public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] module: Remove duplicate freeing of lockdep classes
@ 2026-01-07 12:22 Petr Pavlu
  2026-01-07 16:31 ` Aaron Tomlin
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Petr Pavlu @ 2026-01-07 12:22 UTC (permalink / raw)
  To: Luis Chamberlain, Petr Pavlu, Daniel Gomez, Sami Tolvanen
  Cc: Aaron Tomlin, Peter Zijlstra, Ingo Molnar, Will Deacon,
	Boqun Feng, Waiman Long, Song Liu, linux-modules, linux-kernel

In the error path of load_module(), under the free_module label, the
code calls lockdep_free_key_range() to release lock classes associated
with the MOD_DATA, MOD_RODATA and MOD_RO_AFTER_INIT module regions, and
subsequently invokes module_deallocate().

Since commit ac3b43283923 ("module: replace module_layout with
module_memory"), the module_deallocate() function calls free_mod_mem(),
which releases the lock classes as well and considers all module
regions.

Attempting to free these classes twice is unnecessary. Remove the
redundant code in load_module().

Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>
---
 kernel/module/main.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/kernel/module/main.c b/kernel/module/main.c
index 710ee30b3bea..bcd259505c8b 100644
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -3544,12 +3544,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
 	mutex_unlock(&module_mutex);
  free_module:
 	mod_stat_bump_invalid(info, flags);
-	/* Free lock-classes; relies on the preceding sync_rcu() */
-	for_class_mod_mem_type(type, core_data) {
-		lockdep_free_key_range(mod->mem[type].base,
-				       mod->mem[type].size);
-	}
-
 	module_memory_restore_rox(mod);
 	module_deallocate(mod, info);
  free_copy:

base-commit: 3609fa95fb0f2c1b099e69e56634edb8fc03f87c
-- 
2.52.0


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

* Re: [PATCH] module: Remove duplicate freeing of lockdep classes
  2026-01-07 12:22 [PATCH] module: Remove duplicate freeing of lockdep classes Petr Pavlu
@ 2026-01-07 16:31 ` Aaron Tomlin
  2026-01-12 16:43 ` Peter Zijlstra
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Aaron Tomlin @ 2026-01-07 16:31 UTC (permalink / raw)
  To: Petr Pavlu
  Cc: Luis Chamberlain, Daniel Gomez, Sami Tolvanen, Peter Zijlstra,
	Ingo Molnar, Will Deacon, Boqun Feng, Waiman Long, Song Liu,
	linux-modules, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1606 bytes --]

On Wed, Jan 07, 2026 at 01:22:57PM +0100, Petr Pavlu wrote:
> In the error path of load_module(), under the free_module label, the
> code calls lockdep_free_key_range() to release lock classes associated
> with the MOD_DATA, MOD_RODATA and MOD_RO_AFTER_INIT module regions, and
> subsequently invokes module_deallocate().
> 
> Since commit ac3b43283923 ("module: replace module_layout with
> module_memory"), the module_deallocate() function calls free_mod_mem(),
> which releases the lock classes as well and considers all module
> regions.
> 
> Attempting to free these classes twice is unnecessary. Remove the
> redundant code in load_module().
> 
> Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>
> ---
>  kernel/module/main.c | 6 ------
>  1 file changed, 6 deletions(-)
> 
> diff --git a/kernel/module/main.c b/kernel/module/main.c
> index 710ee30b3bea..bcd259505c8b 100644
> --- a/kernel/module/main.c
> +++ b/kernel/module/main.c
> @@ -3544,12 +3544,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
>  	mutex_unlock(&module_mutex);
>   free_module:
>  	mod_stat_bump_invalid(info, flags);
> -	/* Free lock-classes; relies on the preceding sync_rcu() */
> -	for_class_mod_mem_type(type, core_data) {
> -		lockdep_free_key_range(mod->mem[type].base,
> -				       mod->mem[type].size);
> -	}
> -
>  	module_memory_restore_rox(mod);
>  	module_deallocate(mod, info);
>   free_copy:
> 
> base-commit: 3609fa95fb0f2c1b099e69e56634edb8fc03f87c
> -- 
> 2.52.0
> 

Reviewed-by: Aaron Tomlin <atomlin@atomlin.com>

-- 
Aaron Tomlin

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH] module: Remove duplicate freeing of lockdep classes
  2026-01-07 12:22 [PATCH] module: Remove duplicate freeing of lockdep classes Petr Pavlu
  2026-01-07 16:31 ` Aaron Tomlin
@ 2026-01-12 16:43 ` Peter Zijlstra
  2026-01-12 17:57 ` Song Liu
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Peter Zijlstra @ 2026-01-12 16:43 UTC (permalink / raw)
  To: Petr Pavlu
  Cc: Luis Chamberlain, Daniel Gomez, Sami Tolvanen, Aaron Tomlin,
	Ingo Molnar, Will Deacon, Boqun Feng, Waiman Long, Song Liu,
	linux-modules, linux-kernel

On Wed, Jan 07, 2026 at 01:22:57PM +0100, Petr Pavlu wrote:
> In the error path of load_module(), under the free_module label, the
> code calls lockdep_free_key_range() to release lock classes associated
> with the MOD_DATA, MOD_RODATA and MOD_RO_AFTER_INIT module regions, and
> subsequently invokes module_deallocate().
> 
> Since commit ac3b43283923 ("module: replace module_layout with
> module_memory"), the module_deallocate() function calls free_mod_mem(),
> which releases the lock classes as well and considers all module
> regions.
> 
> Attempting to free these classes twice is unnecessary. Remove the
> redundant code in load_module().
> 
> Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>

Indeed,

Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>

> ---
>  kernel/module/main.c | 6 ------
>  1 file changed, 6 deletions(-)
> 
> diff --git a/kernel/module/main.c b/kernel/module/main.c
> index 710ee30b3bea..bcd259505c8b 100644
> --- a/kernel/module/main.c
> +++ b/kernel/module/main.c
> @@ -3544,12 +3544,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
>  	mutex_unlock(&module_mutex);
>   free_module:
>  	mod_stat_bump_invalid(info, flags);
> -	/* Free lock-classes; relies on the preceding sync_rcu() */
> -	for_class_mod_mem_type(type, core_data) {
> -		lockdep_free_key_range(mod->mem[type].base,
> -				       mod->mem[type].size);
> -	}
> -
>  	module_memory_restore_rox(mod);
>  	module_deallocate(mod, info);
>   free_copy:
> 
> base-commit: 3609fa95fb0f2c1b099e69e56634edb8fc03f87c
> -- 
> 2.52.0
> 

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

* Re: [PATCH] module: Remove duplicate freeing of lockdep classes
  2026-01-07 12:22 [PATCH] module: Remove duplicate freeing of lockdep classes Petr Pavlu
  2026-01-07 16:31 ` Aaron Tomlin
  2026-01-12 16:43 ` Peter Zijlstra
@ 2026-01-12 17:57 ` Song Liu
  2026-01-12 19:29 ` Aaron Tomlin
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Song Liu @ 2026-01-12 17:57 UTC (permalink / raw)
  To: Petr Pavlu
  Cc: Luis Chamberlain, Daniel Gomez, Sami Tolvanen, Aaron Tomlin,
	Peter Zijlstra, Ingo Molnar, Will Deacon, Boqun Feng, Waiman Long,
	linux-modules, linux-kernel

On Wed, Jan 7, 2026 at 4:24 AM Petr Pavlu <petr.pavlu@suse.com> wrote:
>
> In the error path of load_module(), under the free_module label, the
> code calls lockdep_free_key_range() to release lock classes associated
> with the MOD_DATA, MOD_RODATA and MOD_RO_AFTER_INIT module regions, and
> subsequently invokes module_deallocate().
>
> Since commit ac3b43283923 ("module: replace module_layout with
> module_memory"), the module_deallocate() function calls free_mod_mem(),
> which releases the lock classes as well and considers all module
> regions.
>
> Attempting to free these classes twice is unnecessary. Remove the
> redundant code in load_module().
>
> Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>

Acked-by: Song Liu <song@kernel.org>

Thanks for the fix!

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

* Re: [PATCH] module: Remove duplicate freeing of lockdep classes
  2026-01-07 12:22 [PATCH] module: Remove duplicate freeing of lockdep classes Petr Pavlu
                   ` (2 preceding siblings ...)
  2026-01-12 17:57 ` Song Liu
@ 2026-01-12 19:29 ` Aaron Tomlin
  2026-02-20 15:55 ` Daniel Gomez
  2026-02-24 18:34 ` Sami Tolvanen
  5 siblings, 0 replies; 7+ messages in thread
From: Aaron Tomlin @ 2026-01-12 19:29 UTC (permalink / raw)
  To: Petr Pavlu
  Cc: Luis Chamberlain, Daniel Gomez, Sami Tolvanen, Peter Zijlstra,
	Ingo Molnar, Will Deacon, Boqun Feng, Waiman Long, Song Liu,
	linux-modules, linux-kernel

On Wed, Jan 07, 2026 at 01:22:57PM +0100, Petr Pavlu wrote:
> In the error path of load_module(), under the free_module label, the
> code calls lockdep_free_key_range() to release lock classes associated
> with the MOD_DATA, MOD_RODATA and MOD_RO_AFTER_INIT module regions, and
> subsequently invokes module_deallocate().
> 
> Since commit ac3b43283923 ("module: replace module_layout with
> module_memory"), the module_deallocate() function calls free_mod_mem(),
> which releases the lock classes as well and considers all module
> regions.
> 
> Attempting to free these classes twice is unnecessary. Remove the
> redundant code in load_module().
> 
> Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>
> ---
>  kernel/module/main.c | 6 ------
>  1 file changed, 6 deletions(-)
> 
> diff --git a/kernel/module/main.c b/kernel/module/main.c
> index 710ee30b3bea..bcd259505c8b 100644
> --- a/kernel/module/main.c
> +++ b/kernel/module/main.c
> @@ -3544,12 +3544,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
>  	mutex_unlock(&module_mutex);
>   free_module:
>  	mod_stat_bump_invalid(info, flags);
> -	/* Free lock-classes; relies on the preceding sync_rcu() */
> -	for_class_mod_mem_type(type, core_data) {
> -		lockdep_free_key_range(mod->mem[type].base,
> -				       mod->mem[type].size);
> -	}
> -
>  	module_memory_restore_rox(mod);
>  	module_deallocate(mod, info);
>   free_copy:
> 
> base-commit: 3609fa95fb0f2c1b099e69e56634edb8fc03f87c
> -- 
> 2.52.0
> 

Thank you!

Reviewed-by: Aaron Tomlin <atomlin@atomlin.com>

-- 
Aaron Tomlin

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

* Re: [PATCH] module: Remove duplicate freeing of lockdep classes
  2026-01-07 12:22 [PATCH] module: Remove duplicate freeing of lockdep classes Petr Pavlu
                   ` (3 preceding siblings ...)
  2026-01-12 19:29 ` Aaron Tomlin
@ 2026-02-20 15:55 ` Daniel Gomez
  2026-02-24 18:34 ` Sami Tolvanen
  5 siblings, 0 replies; 7+ messages in thread
From: Daniel Gomez @ 2026-02-20 15:55 UTC (permalink / raw)
  To: Petr Pavlu
  Cc: Luis Chamberlain, Sami Tolvanen, Aaron Tomlin, Peter Zijlstra,
	Ingo Molnar, Will Deacon, Boqun Feng, Waiman Long, Song Liu,
	linux-modules, linux-kernel

On 2026-01-07 13:22, Petr Pavlu wrote:
> In the error path of load_module(), under the free_module label, the
> code calls lockdep_free_key_range() to release lock classes associated
> with the MOD_DATA, MOD_RODATA and MOD_RO_AFTER_INIT module regions, and
> subsequently invokes module_deallocate().
> 
> Since commit ac3b43283923 ("module: replace module_layout with
> module_memory"), the module_deallocate() function calls free_mod_mem(),
> which releases the lock classes as well and considers all module
> regions.
> 
> Attempting to free these classes twice is unnecessary. Remove the
> redundant code in load_module().

I'd even say module_deallocate() handles MOD_DATA properly (deferring
it to the last one) while the first loop was not taking that into
consideration.

> 
> Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>

Reviewed-by: Daniel Gomez <da.gomez@samsung.com>


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

* Re: [PATCH] module: Remove duplicate freeing of lockdep classes
  2026-01-07 12:22 [PATCH] module: Remove duplicate freeing of lockdep classes Petr Pavlu
                   ` (4 preceding siblings ...)
  2026-02-20 15:55 ` Daniel Gomez
@ 2026-02-24 18:34 ` Sami Tolvanen
  5 siblings, 0 replies; 7+ messages in thread
From: Sami Tolvanen @ 2026-02-24 18:34 UTC (permalink / raw)
  To: Luis Chamberlain, Daniel Gomez, Petr Pavlu
  Cc: Aaron Tomlin, Peter Zijlstra, Ingo Molnar, Will Deacon,
	Waiman Long, Song Liu, linux-modules, linux-kernel, Boqun Feng

On Wed, 07 Jan 2026 13:22:57 +0100, Petr Pavlu wrote:
> In the error path of load_module(), under the free_module label, the
> code calls lockdep_free_key_range() to release lock classes associated
> with the MOD_DATA, MOD_RODATA and MOD_RO_AFTER_INIT module regions, and
> subsequently invokes module_deallocate().
> 
> Since commit ac3b43283923 ("module: replace module_layout with
> module_memory"), the module_deallocate() function calls free_mod_mem(),
> which releases the lock classes as well and considers all module
> regions.
> 
> [...]

Applied to modules-next, thanks!

[1/1] module: Remove duplicate freeing of lockdep classes
      commit: a7b4bc094fbaa7dc7b7b91ae33549bbd7eefaac1

Best regards,

	Sami



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

end of thread, other threads:[~2026-02-24 18:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-07 12:22 [PATCH] module: Remove duplicate freeing of lockdep classes Petr Pavlu
2026-01-07 16:31 ` Aaron Tomlin
2026-01-12 16:43 ` Peter Zijlstra
2026-01-12 17:57 ` Song Liu
2026-01-12 19:29 ` Aaron Tomlin
2026-02-20 15:55 ` Daniel Gomez
2026-02-24 18:34 ` Sami Tolvanen

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