mirror of
https://github.com/torvalds/linux.git
synced 2026-03-08 04:04:43 +01:00
powerpc64/modules: replace stub allocation sentinel with an explicit counter
The logic for allocating ppc64_stub_entry trampolines in the .stubs section relies on an inline sentinel, where a NULL .funcdata member indicates an available slot. While preceding commits fixed the initialization bugs that led to ftrace stub corruption, the sentinel-based approach remains fragile: it depends on an implicit convention between subsystems modifying different struct types in the same memory area. Replace the sentinel with an explicit counter, module->arch.num_stubs. Instead of iterating through memory to find a NULL marker, the module loader uses this counter as the boundary for the next free slot. This simplifies the allocation code, hardens it against future changes to stub structures, and removes the need for an extra relocation slot previously reserved to terminate the sentinel search. Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com> Acked-by: Naveen N Rao (AMD) <naveen@kernel.org> Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com> Link: https://patch.msgid.link/20250912142740.3581368-4-joe.lawrence@redhat.com
This commit is contained in:
parent
f6b4df37eb
commit
b137312fbf
2 changed files with 9 additions and 18 deletions
|
|
@ -27,6 +27,7 @@ struct ppc_plt_entry {
|
|||
struct mod_arch_specific {
|
||||
#ifdef __powerpc64__
|
||||
unsigned int stubs_section; /* Index of stubs section in module */
|
||||
unsigned int stub_count; /* Number of stubs used */
|
||||
#ifdef CONFIG_PPC_KERNEL_PCREL
|
||||
unsigned int got_section; /* What section is the GOT? */
|
||||
unsigned int pcpu_section; /* .data..percpu section */
|
||||
|
|
|
|||
|
|
@ -209,8 +209,7 @@ static unsigned long get_stubs_size(const Elf64_Ehdr *hdr,
|
|||
char *secstrings,
|
||||
struct module *me)
|
||||
{
|
||||
/* One extra reloc so it's always 0-addr terminated */
|
||||
unsigned long relocs = 1;
|
||||
unsigned long relocs = 0;
|
||||
unsigned i;
|
||||
|
||||
/* Every relocated section... */
|
||||
|
|
@ -705,7 +704,7 @@ static unsigned long stub_for_addr(const Elf64_Shdr *sechdrs,
|
|||
|
||||
/* Find this stub, or if that fails, the next avail. entry */
|
||||
stubs = (void *)sechdrs[me->arch.stubs_section].sh_addr;
|
||||
for (i = 0; stub_func_addr(stubs[i].funcdata); i++) {
|
||||
for (i = 0; i < me->arch.stub_count; i++) {
|
||||
if (WARN_ON(i >= num_stubs))
|
||||
return 0;
|
||||
|
||||
|
|
@ -716,6 +715,7 @@ static unsigned long stub_for_addr(const Elf64_Shdr *sechdrs,
|
|||
if (!create_stub(sechdrs, &stubs[i], addr, me, name))
|
||||
return 0;
|
||||
|
||||
me->arch.stub_count++;
|
||||
return (unsigned long)&stubs[i];
|
||||
}
|
||||
|
||||
|
|
@ -1118,29 +1118,19 @@ int module_trampoline_target(struct module *mod, unsigned long addr,
|
|||
static int setup_ftrace_ool_stubs(const Elf64_Shdr *sechdrs, unsigned long addr, struct module *me)
|
||||
{
|
||||
#ifdef CONFIG_PPC_FTRACE_OUT_OF_LINE
|
||||
unsigned int i, total_stubs, num_stubs;
|
||||
unsigned int total_stubs, num_stubs;
|
||||
struct ppc64_stub_entry *stub;
|
||||
|
||||
total_stubs = sechdrs[me->arch.stubs_section].sh_size / sizeof(*stub);
|
||||
num_stubs = roundup(me->arch.ool_stub_count * sizeof(struct ftrace_ool_stub),
|
||||
sizeof(struct ppc64_stub_entry)) / sizeof(struct ppc64_stub_entry);
|
||||
|
||||
/* Find the next available entry */
|
||||
stub = (void *)sechdrs[me->arch.stubs_section].sh_addr;
|
||||
for (i = 0; stub_func_addr(stub[i].funcdata); i++)
|
||||
if (WARN_ON(i >= total_stubs))
|
||||
return -1;
|
||||
|
||||
if (WARN_ON(i + num_stubs > total_stubs))
|
||||
if (WARN_ON(me->arch.stub_count + num_stubs > total_stubs))
|
||||
return -1;
|
||||
|
||||
stub += i;
|
||||
me->arch.ool_stubs = (struct ftrace_ool_stub *)stub;
|
||||
|
||||
/* reserve stubs */
|
||||
for (i = 0; i < num_stubs; i++)
|
||||
if (patch_u32((void *)&stub[i].funcdata, PPC_RAW_NOP()))
|
||||
return -1;
|
||||
stub = (void *)sechdrs[me->arch.stubs_section].sh_addr;
|
||||
me->arch.ool_stubs = (struct ftrace_ool_stub *)(stub + me->arch.stub_count);
|
||||
me->arch.stub_count += num_stubs;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue