Skip to contentSkip to conversation

powerpc32/modules: Reserve a PLT entry for ftrace_regs_caller

PATCH Applied Bradley Morgan 5 participants 8 messages Sep 23 – Nov 18 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc32/modules: Reserve a PLT entry for ftrace_regs_caller

Commit 7dfbfb87c243 ("powerpc/ftrace: Activate HAVE_DYNAMIC_FTRACE_WITH_REGS on PPC32") made count_relocs() undercount the PLT entries the loader
consumes: module_finalize_ftrace() now creates two trampolines (mod->arch.tramp for ftrace_caller() and mod->arch.tramp_regs for ftrace_regs_caller()), while count_relocs() reserves only one entry for ftrace.

So the core .plt ends up one ppc_plt_entry (16 bytes) short. The walk in do_plt_call() scans for a free slot with
"while (entry->jump[0])" and has no bound check, so once the last reserved slot is used up, the walk steps past the end of the section and patch_instruction() writes the 4-instruction trampoline into whatever module memory follows the .plt.

Count the second entry, mirroring what module_64.c does for the same pair of stubs.

---
 arch/powerpc/kernel/module_32.c | 3 +++
 1 file changed, 3 insertions(+)
arch/powerpc/kernel/module_32.c +3 -0
index f930e3395a7f..61152deffc55 100644
@@ -41,6 +41,9 @@ static unsigned int count_relocs(const Elf32_Rela *rela, unsigned int num)
 
 #ifdef CONFIG_DYNAMIC_FTRACE
 	_count_relocs++;	/* add one for ftrace_caller */
+#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
+	_count_relocs++;	/* add one for ftrace_regs_caller */
+#endif
 #endif
 	return _count_relocs;
 }
Signature · 1 line
2.53.0
reviewer Reviewed-by on v1 1/1
#1 lore raw

Le 23/09/2026 à 19:56, Bradley Morgan a écrit :

Quoted 15 lines

Commit 7dfbfb87c243 ("powerpc/ftrace: Activate HAVE_DYNAMIC_FTRACE_WITH_REGS on PPC32") made count_relocs() undercount the PLT entries the loader
consumes: module_finalize_ftrace() now creates two trampolines (mod->arch.tramp for ftrace_caller() and mod->arch.tramp_regs for ftrace_regs_caller()), while count_relocs() reserves only one entry for ftrace.

So the core .plt ends up one ppc_plt_entry (16 bytes) short. The walk in do_plt_call() scans for a free slot with
"while (entry->jump[0])" and has no bound check, so once the last reserved slot is used up, the walk steps past the end of the section and patch_instruction() writes the 4-instruction trampoline into whatever module memory follows the .plt.

Quoted 4 lines

Count the second entry, mirroring what module_64.c does for the same pair of stubs.

I would have had a preference for something similar to commit c12cfe9dee07 ("powerpc/module_64: Convert #ifdef to IS_ENABLED()")

Nevertheless,

Quoted 18 lines
---
  arch/powerpc/kernel/module_32.c | 3 +++
  1 file changed, 3 insertions(+)
arch/powerpc/kernel/module_32.c +3 -0
index f930e3395a7f..61152deffc55 100644
@@ -41,6 +41,9 @@ static unsigned int count_relocs(const Elf32_Rela *rela, unsigned int num)
 
  #ifdef CONFIG_DYNAMIC_FTRACE
  	_count_relocs++;	/* add one for ftrace_caller */
+#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
+	_count_relocs++;	/* add one for ftrace_regs_caller */
+#endif
  #endif
  	return _count_relocs;
  }
#2 lore raw
Quoted 21 lines · Christophe Leroy (CS GROUP)

Le 23/09/2026 à 19:56, Bradley Morgan a écrit :

Quoted 18 lines

Commit 7dfbfb87c243 ("powerpc/ftrace: Activate HAVE_DYNAMIC_FTRACE_WITH_REGS on PPC32") made count_relocs() undercount the PLT entries the loader
consumes: module_finalize_ftrace() now creates two trampolines (mod->arch.tramp for ftrace_caller() and mod->arch.tramp_regs for ftrace_regs_caller()), while count_relocs() reserves only one entry for ftrace.

So the core .plt ends up one ppc_plt_entry (16 bytes) short. The walk in do_plt_call() scans for a free slot with
"while (entry->jump[0])" and has no bound check, so once the last reserved slot is used up, the walk steps past the end of the section and patch_instruction() writes the 4-instruction trampoline into whatever module memory follows the .plt.

Count the second entry, mirroring what module_64.c does for the same pair of stubs.

Quoted 8 lines
Quoted 1 line

I would have had a preference for something similar to commit c12cfe9dee07 ("powerpc/module_64: Convert #ifdef to IS_ENABLED()")

Nevertheless,

Thx, now the good question will be, who merges?

Quoted 14 lines

Review

Quoted 8 lines


---
  arch/powerpc/kernel/module_32.c | 3 +++
  1 file changed, 3 insertions(+)
(quoted diff) +0 -0

b/arch/powerpc/kernel/module_32.c

arch/powerpc/kernel/module_32.c static unsigned int count_relocs(const Elf32_Rela

Quoted 4 lines

index f930e3395a7f..61152deffc55 100644

arch/powerpc/kernel/module_32.c +0 -0
@@ -41,6 +41,9 @@ static unsigned int count_relocs(const Elf32_Rela

*rela, unsigned int num)

Quoted 9 lines

arch/powerpc/kernel/module_32.c static unsigned int count_relocs(const Elf32_Rela *rela, unsigned int num) · line 49

Quoted 8 lines
arch/powerpc/kernel/module_32.c +3 -0
    #ifdef CONFIG_DYNAMIC_FTRACE
  	_count_relocs++;	/* add one for ftrace_caller */
+#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
+	_count_relocs++;	/* add one for ftrace_regs_caller */
+#endif
  #endif
  	return _count_relocs;
  }

--- Thanks!

#3 lore raw
In reply to Bradley Morgan
Quoted 15 lines · Bradley Morgan

Commit 7dfbfb87c243 ("powerpc/ftrace: Activate HAVE_DYNAMIC_FTRACE_WITH_REGS on PPC32") made count_relocs() undercount the PLT entries the loader
consumes: module_finalize_ftrace() now creates two trampolines (mod->arch.tramp for ftrace_caller() and mod->arch.tramp_regs for ftrace_regs_caller()), while count_relocs() reserves only one entry for ftrace.

So the core .plt ends up one ppc_plt_entry (16 bytes) short. The walk in do_plt_call() scans for a free slot with
"while (entry->jump[0])" and has no bound check, so once the last reserved slot is used up, the walk steps past the end of the section and patch_instruction() writes the 4-instruction trampoline into whatever module memory follows the .plt.

Quoted 8 lines

Count the second entry, mirroring what module_64.c does for the same pair of stubs.

---
 arch/powerpc/kernel/module_32.c | 3 +++
 1 file changed, 3 insertions(+)

Do we also need fixes and stable tag here?

Fixes 7dfbfb87c243 ("powerpc/ftrace: Activate HAVE_DYNAMIC_FTRACE_WITH_REGS on PPC32")

-ritesh

#4 lore raw
Quoted 26 lines · Ritesh Harjani
Quoted 15 lines · Bradley Morgan

Commit 7dfbfb87c243 ("powerpc/ftrace: Activate HAVE_DYNAMIC_FTRACE_WITH_REGS on PPC32") made count_relocs() undercount the PLT entries the loader
consumes: module_finalize_ftrace() now creates two trampolines (mod->arch.tramp for ftrace_caller() and mod->arch.tramp_regs for ftrace_regs_caller()), while count_relocs() reserves only one entry for ftrace.

So the core .plt ends up one ppc_plt_entry (16 bytes) short. The walk in do_plt_call() scans for a free slot with
"while (entry->jump[0])" and has no bound check, so once the last reserved slot is used up, the walk steps past the end of the section and patch_instruction() writes the 4-instruction trampoline into whatever module memory follows the .plt.

Quoted 8 lines

Count the second entry, mirroring what module_64.c does for the same pair of stubs.

---
 arch/powerpc/kernel/module_32.c | 3 +++
 1 file changed, 3 insertions(+)
Quoted 4 lines

Do we also need fixes and stable tag here?

Fixes 7dfbfb87c243 ("powerpc/ftrace: Activate HAVE_DYNAMIC_FTRACE_WITH_REGS on PPC32")

Hmm.. could the merger add that? If anyone merges.. :(

Quoted 4 lines

-ritesh

--- Thanks!

#5 lore raw
Quoted 27 lines · Bradley Morgan
Quoted 25 lines · Ritesh Harjani
Quoted 23 lines · Bradley Morgan

Commit 7dfbfb87c243 ("powerpc/ftrace: Activate HAVE_DYNAMIC_FTRACE_WITH_REGS on PPC32") made count_relocs() undercount the PLT entries the loader
consumes: module_finalize_ftrace() now creates two trampolines (mod->arch.tramp for ftrace_caller() and mod->arch.tramp_regs for ftrace_regs_caller()), while count_relocs() reserves only one entry for ftrace.

So the core .plt ends up one ppc_plt_entry (16 bytes) short. The walk in do_plt_call() scans for a free slot with
"while (entry->jump[0])" and has no bound check, so once the last reserved slot is used up, the walk steps past the end of the section and patch_instruction() writes the 4-instruction trampoline into whatever module memory follows the .plt.

Count the second entry, mirroring what module_64.c does for the same pair of stubs.

---
  arch/powerpc/kernel/module_32.c | 3 +++
  1 file changed, 3 insertions(+)
Quoted 5 lines
Quoted 4 lines

Do we also need fixes and stable tag here?

Fixes 7dfbfb87c243 ("powerpc/ftrace: Activate HAVE_DYNAMIC_FTRACE_WITH_REGS on PPC32")

Hmm.. could the merger add that? If anyone merges.. :(

planned to be part of my fixes PR and will add it. Thanks for the fix.

Maddy

Quoted 4 lines
Quoted 3 lines

-ritesh

--- Thanks!

#6 lore raw
Quoted 29 lines · Madhavan Srinivasan
Quoted 27 lines · Bradley Morgan
Quoted 25 lines · Ritesh Harjani
Quoted 23 lines · Bradley Morgan

Commit 7dfbfb87c243 ("powerpc/ftrace: Activate HAVE_DYNAMIC_FTRACE_WITH_REGS on PPC32") made count_relocs() undercount the PLT entries the loader
consumes: module_finalize_ftrace() now creates two trampolines (mod->arch.tramp for ftrace_caller() and mod->arch.tramp_regs for ftrace_regs_caller()), while count_relocs() reserves only one entry for ftrace.

So the core .plt ends up one ppc_plt_entry (16 bytes) short. The walk in do_plt_call() scans for a free slot with
"while (entry->jump[0])" and has no bound check, so once the last reserved slot is used up, the walk steps past the end of the section and patch_instruction() writes the 4-instruction trampoline into whatever module memory follows the .plt.

Count the second entry, mirroring what module_64.c does for the same pair of stubs.

---
  arch/powerpc/kernel/module_32.c | 3 +++
  1 file changed, 3 insertions(+)
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

Do we also need fixes and stable tag here?

Fixes 7dfbfb87c243 ("powerpc/ftrace: Activate

HAVE_DYNAMIC_FTRACE_WITH_REGS on PPC32")

Quoted 2 lines
Quoted 1 line

Hmm.. could the merger add that? If anyone merges.. :(

planned to be part of my fixes PR and will add it. Thanks for the fix.

No worries, mind changing sob to this email?

Quoted 7 lines

Maddy

Quoted 4 lines
Quoted 3 lines

-ritesh

--- Thanks!

--- Thanks!

maintainer Applied
#7 lore raw
In reply to Bradley Morgan
Quoted 9 lines · Bradley Morgan

Commit 7dfbfb87c243 ("powerpc/ftrace: Activate HAVE_DYNAMIC_FTRACE_WITH_REGS on PPC32") made count_relocs() undercount the PLT entries the loader
consumes: module_finalize_ftrace() now creates two trampolines (mod->arch.tramp for ftrace_caller() and mod->arch.tramp_regs for ftrace_regs_caller()), while count_relocs() reserves only one entry for ftrace.

[...]

Applied to powerpc/fixes.

[1/1] powerpc32/modules: Reserve a PLT entry for ftrace_regs_caller

      https://git.kernel.org/powerpc/c/dc6eb6f08be536223e8289c7a8b1f515b1355721

cheers