riscv: alternative: Use the statically extracted vDSO section offsets

Currently the alternative sections are extracted from the vDSO
binaries at runtime. This has runtime overhead and also doesn't
work for the compat vDSO.

Use the offsets generated during the build instead, fixing both issues.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Reviewed-by: Nam Cao <namcao@linutronix.de>
Link: https://patch.msgid.link/20260630-riscv-vdso32-alternative-v1-2-a32fd89b7b1c@linutronix.de
Signed-off-by: Paul Walmsley <pjw@kernel.org>
This commit is contained in:
Thomas Weißschuh 2026-08-07 19:24:33 -06:00 committed by Paul Walmsley
parent 7f2a7bbcd9
commit 63aecaba41

View File

@ -173,24 +173,14 @@ static void __init_or_module _apply_alternatives(struct alt_entry *begin,
stage);
}
static void __init apply_vdso_alternatives(void *start)
static __always_inline
void __init apply_vdso_alternatives(void *base, size_t alternatives_begin, size_t alternatives_end)
{
const Elf_Ehdr *hdr;
const Elf_Shdr *shdr;
const Elf_Shdr *alt;
struct alt_entry *begin, *end;
hdr = (Elf_Ehdr *)start;
shdr = (void *)hdr + hdr->e_shoff;
alt = find_section(hdr, shdr, ".alternative");
if (!alt)
if (alternatives_begin == alternatives_end)
return;
begin = (void *)hdr + alt->sh_offset,
end = (void *)hdr + alt->sh_offset + alt->sh_size,
_apply_alternatives((struct alt_entry *)begin,
(struct alt_entry *)end,
_apply_alternatives(base + alternatives_begin,
base + alternatives_end,
RISCV_ALTERNATIVES_BOOT);
}
@ -204,10 +194,14 @@ void __init apply_boot_alternatives(void)
RISCV_ALTERNATIVES_BOOT);
if (IS_ENABLED(CONFIG_MMU))
apply_vdso_alternatives(vdso_start);
apply_vdso_alternatives(vdso_start,
__vdso_alternatives_start_offset,
__vdso_alternatives_end_offset);
if (IS_ENABLED(CONFIG_RISCV_USER_CFI))
apply_vdso_alternatives(vdso_cfi_start);
apply_vdso_alternatives(vdso_cfi_start,
__vdso_alternatives_start_cfi_offset,
__vdso_alternatives_end_cfi_offset);
}
/*