mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] powerpc32/modules: Reserve a PLT entry for ftrace_regs_caller
@ 2026-09-23 17:56 Bradley Morgan
  2026-11-10  8:57 ` Christophe Leroy (CS GROUP)
  2026-11-11  3:48 ` Ritesh Harjani
  0 siblings, 2 replies; 7+ messages in thread
From: Bradley Morgan @ 2026-09-23 17:56 UTC (permalink / raw)
  To: Madhavan Srinivasan
  Cc: Michael Ellerman, Nicholas Piggin, Christophe Leroy,
	Ritesh Harjani, Shrikanth Hegde, linuxppc-dev, linux-kernel,
	brads

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.

Signed-off-by: Bradley Morgan <brads@mainlining.org>
---
 arch/powerpc/kernel/module_32.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
index f930e3395a7f..61152deffc55 100644
--- a/arch/powerpc/kernel/module_32.c
+++ b/arch/powerpc/kernel/module_32.c
@@ -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.53.0


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

* Re: [PATCH] powerpc32/modules: Reserve a PLT entry for ftrace_regs_caller
  2026-09-23 17:56 [PATCH] powerpc32/modules: Reserve a PLT entry for ftrace_regs_caller Bradley Morgan
@ 2026-11-10  8:57 ` Christophe Leroy (CS GROUP)
  2026-11-10 21:22   ` Bradley Morgan
  2026-11-11  3:48 ` Ritesh Harjani
  1 sibling, 1 reply; 7+ messages in thread
From: Christophe Leroy (CS GROUP) @ 2026-11-10  8:57 UTC (permalink / raw)
  To: Bradley Morgan, Madhavan Srinivasan
  Cc: Michael Ellerman, Nicholas Piggin, Ritesh Harjani,
	Shrikanth Hegde, linuxppc-dev, linux-kernel



Le 23/09/2026 à 19:56, Bradley Morgan a écrit :
> 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.
> 
> Signed-off-by: Bradley Morgan <brads@mainlining.org>

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

Nevertheless,

Reviewed-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>



> ---
>   arch/powerpc/kernel/module_32.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
> index f930e3395a7f..61152deffc55 100644
> --- a/arch/powerpc/kernel/module_32.c
> +++ b/arch/powerpc/kernel/module_32.c
> @@ -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;
>   }


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

* Re: [PATCH] powerpc32/modules: Reserve a PLT entry for ftrace_regs_caller
  2026-11-10  8:57 ` Christophe Leroy (CS GROUP)
@ 2026-11-10 21:22   ` Bradley Morgan
  0 siblings, 0 replies; 7+ messages in thread
From: Bradley Morgan @ 2026-11-10 21:22 UTC (permalink / raw)
  To: chleroy
  Cc: brads, linux-kernel, linuxppc-dev, maddy, mpe, npiggin,
	ritesh.list, sshegde

On 10 November 2026 08:57:28 GMT, "Christophe Leroy (CS GROUP)"
<chleroy@kernel.org> wrote:
>
>
>Le 23/09/2026 à 19:56, Bradley Morgan a écrit :
>> 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.
>> 
>> Signed-off-by: Bradley Morgan <brads@mainlining.org>
>
>I would have had a preference for something similar to commit c12cfe9dee07
>("powerpc/module_64: Convert #ifdef to IS_ENABLED()")
>
>Nevertheless,
>
>Reviewed-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>

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

>
>
>
>> ---
>>   arch/powerpc/kernel/module_32.c | 3 +++
>>   1 file changed, 3 insertions(+)
>> 
>> diff --git a/arch/powerpc/kernel/module_32.c
>b/arch/powerpc/kernel/module_32.c
>> index f930e3395a7f..61152deffc55 100644
>> --- a/arch/powerpc/kernel/module_32.c
>> +++ b/arch/powerpc/kernel/module_32.c
>> @@ -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;
>>   }
>

--- Thanks!

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

* Re: [PATCH] powerpc32/modules: Reserve a PLT entry for ftrace_regs_caller
  2026-09-23 17:56 [PATCH] powerpc32/modules: Reserve a PLT entry for ftrace_regs_caller Bradley Morgan
  2026-11-10  8:57 ` Christophe Leroy (CS GROUP)
@ 2026-11-11  3:48 ` Ritesh Harjani
  2026-11-11  7:28   ` Bradley Morgan
  1 sibling, 1 reply; 7+ messages in thread
From: Ritesh Harjani @ 2026-11-11  3:48 UTC (permalink / raw)
  To: Bradley Morgan, Madhavan Srinivasan, Christophe Leroy
  Cc: Michael Ellerman, Nicholas Piggin, Shrikanth Hegde, linuxppc-dev,
	linux-kernel, brads

Bradley Morgan <brads@mainlining.org> writes:

> 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.
>
> Signed-off-by: Bradley Morgan <brads@mainlining.org>
> ---
>  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")
Cc: stable@vger.kernel.org


-ritesh

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

* Re: [PATCH] powerpc32/modules: Reserve a PLT entry for ftrace_regs_caller
  2026-11-11  3:48 ` Ritesh Harjani
@ 2026-11-11  7:28   ` Bradley Morgan
  2026-11-11 11:58     ` Madhavan Srinivasan
  0 siblings, 1 reply; 7+ messages in thread
From: Bradley Morgan @ 2026-11-11  7:28 UTC (permalink / raw)
  To: ritesh.list
  Cc: brads, chleroy, linux-kernel, linuxppc-dev, maddy, mpe, npiggin, sshegde

On 11 November 2026 03:48:41 GMT, Ritesh Harjani <ritesh.list@gmail.com>
wrote:
>Bradley Morgan <brads@mainlining.org> writes:
>
>> 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.
>>
>> Signed-off-by: Bradley Morgan <brads@mainlining.org>
>> ---
>>  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")
>Cc: stable@vger.kernel.org

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

>
>
>-ritesh
>

--- Thanks!

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

* Re: [PATCH] powerpc32/modules: Reserve a PLT entry for ftrace_regs_caller
  2026-11-11  7:28   ` Bradley Morgan
@ 2026-11-11 11:58     ` Madhavan Srinivasan
  2026-11-11 15:40       ` Bradley Morgan
  0 siblings, 1 reply; 7+ messages in thread
From: Madhavan Srinivasan @ 2026-11-11 11:58 UTC (permalink / raw)
  To: Bradley Morgan, ritesh.list
  Cc: brads, chleroy, linux-kernel, linuxppc-dev, mpe, npiggin, sshegde


On 11/11/26 12:58 PM, Bradley Morgan wrote:
> On 11 November 2026 03:48:41 GMT, Ritesh Harjani <ritesh.list@gmail.com>
> wrote:
>> Bradley Morgan <brads@mainlining.org> writes:
>>
>>> 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.
>>>
>>> Signed-off-by: Bradley Morgan <brads@mainlining.org>
>>> ---
>>>   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")
>> Cc: stable@vger.kernel.org
> 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
>>
>> -ritesh
>>
> --- Thanks!

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

* Re: [PATCH] powerpc32/modules: Reserve a PLT entry for ftrace_regs_caller
  2026-11-11 11:58     ` Madhavan Srinivasan
@ 2026-11-11 15:40       ` Bradley Morgan
  0 siblings, 0 replies; 7+ messages in thread
From: Bradley Morgan @ 2026-11-11 15:40 UTC (permalink / raw)
  To: Madhavan Srinivasan, ritesh.list
  Cc: brads, chleroy, linux-kernel, linuxppc-dev, mpe, npiggin, sshegde

On 11 November 2026 11:58:28 GMT, Madhavan Srinivasan <maddy@linux.ibm.com>
wrote:
>
>On 11/11/26 12:58 PM, Bradley Morgan wrote:
>> On 11 November 2026 03:48:41 GMT, Ritesh Harjani <ritesh.list@gmail.com>
>> wrote:
>>> Bradley Morgan <brads@mainlining.org> writes:
>>> 
>>>> 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.
>>>> 
>>>> Signed-off-by: Bradley Morgan <brads@mainlining.org>
>>>> ---
>>>>   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")
>>> Cc: stable@vger.kernel.org
>> 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?

>
>Maddy
>>> 
>>> -ritesh
>>> 
>> --- Thanks!
>

--- Thanks!

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

end of thread, other threads:[~2026-11-11 15:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-23 17:56 [PATCH] powerpc32/modules: Reserve a PLT entry for ftrace_regs_caller Bradley Morgan
2026-11-10  8:57 ` Christophe Leroy (CS GROUP)
2026-11-10 21:22   ` Bradley Morgan
2026-11-11  3:48 ` Ritesh Harjani
2026-11-11  7:28   ` Bradley Morgan
2026-11-11 11:58     ` Madhavan Srinivasan
2026-11-11 15:40       ` Bradley Morgan

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

all inboxes | Powered by JetHome®