The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH 0/3] riscv: alternative: Statically compute alternative section boundaries and patch compat vDSO
@ 2026-06-30  7:41 Thomas Weißschuh
  2026-06-30  7:41 ` [PATCH 1/3] riscv: vdso: Add symbols for the alternative section boundaries Thomas Weißschuh
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Thomas Weißschuh @ 2026-06-30  7:41 UTC (permalink / raw)
  To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti
  Cc: linux-riscv, linux-kernel, Nam Cao,
	Thomas Weißschuh (Schneider Electric)

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.

Extract the offsets of the alternative section during the build with the
existing symbol extraction machinery and use those.

Also add support for the compat vDSO.

Link: https://lore.kernel.org/lkml/cover.1781876501.git.namcao@linutronix.de/
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
---
Thomas Weißschuh (3):
      riscv: vdso: Add symbols for the alternative section boundaries
      riscv: alternative: Use the statically extracted vDSO section offsets
      riscv: alternative: Also patch the compat vDSO

 arch/riscv/include/asm/vdso.h     |  6 ++++++
 arch/riscv/kernel/alternative.c   | 33 ++++++++++++++++-----------------
 arch/riscv/kernel/vdso/vdso.lds.S |  2 ++
 3 files changed, 24 insertions(+), 17 deletions(-)
---
base-commit: 10cd4cf20d3d92532485e3f0384e61abc90d6c54
change-id: 20260626-riscv-vdso32-alternative-9d39250c984a

Best regards,
--  
Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>


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

* [PATCH 1/3] riscv: vdso: Add symbols for the alternative section boundaries
  2026-06-30  7:41 [PATCH 0/3] riscv: alternative: Statically compute alternative section boundaries and patch compat vDSO Thomas Weißschuh
@ 2026-06-30  7:41 ` Thomas Weißschuh
  2026-06-30  7:41 ` [PATCH 2/3] riscv: alternative: Use the statically extracted vDSO section offsets Thomas Weißschuh
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Thomas Weißschuh @ 2026-06-30  7:41 UTC (permalink / raw)
  To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti
  Cc: linux-riscv, linux-kernel, Nam Cao,
	Thomas Weißschuh (Schneider Electric)

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.

Extract the offsets of the alternative section during the build with the
existing symbol extraction machinery.

Also add dummy symbols as fallback.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
 arch/riscv/include/asm/vdso.h     | 6 ++++++
 arch/riscv/kernel/vdso/vdso.lds.S | 2 ++
 2 files changed, 8 insertions(+)

diff --git a/arch/riscv/include/asm/vdso.h b/arch/riscv/include/asm/vdso.h
index f7998d9ad9b2..0259bbc98e93 100644
--- a/arch/riscv/include/asm/vdso.h
+++ b/arch/riscv/include/asm/vdso.h
@@ -19,10 +19,14 @@
 
 #ifdef CONFIG_MMU
 #include <generated/vdso-offsets.h>
+#else
+extern size_t __vdso_alternatives_start_offset, __vdso_alternatives_end_offset;
 #endif
 
 #ifdef CONFIG_RISCV_USER_CFI
 #include <generated/vdso-cfi-offsets.h>
+#else
+extern size_t __vdso_alternatives_start_cfi_offset, __vdso_alternatives_end_cfi_offset;
 #endif
 
 #ifdef CONFIG_RISCV_USER_CFI
@@ -41,6 +45,8 @@
 #define COMPAT_VDSO_SYMBOL(base, name)						\
 	(void __user *)((unsigned long)(base) + compat__vdso_##name##_offset)
 
+#else
+extern size_t compat__vdso_alternatives_start_offset, compat__vdso_alternatives_end_offset;
 #endif /* CONFIG_COMPAT */
 
 extern char vdso_start[], vdso_end[];
diff --git a/arch/riscv/kernel/vdso/vdso.lds.S b/arch/riscv/kernel/vdso/vdso.lds.S
index 9acfa9ef5bab..0cc4b64df994 100644
--- a/arch/riscv/kernel/vdso/vdso.lds.S
+++ b/arch/riscv/kernel/vdso/vdso.lds.S
@@ -45,9 +45,11 @@ SECTIONS
 	.text		: { *(.text .text.*) }		:text
 
 	. = ALIGN(4);
+	__vdso_alternatives_start = .;
 	.alternative : {
 		*(.alternative)
 	}
+	__vdso_alternatives_end = .;
 }
 
 /*

-- 
2.55.0


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

* [PATCH 2/3] riscv: alternative: Use the statically extracted vDSO section offsets
  2026-06-30  7:41 [PATCH 0/3] riscv: alternative: Statically compute alternative section boundaries and patch compat vDSO Thomas Weißschuh
  2026-06-30  7:41 ` [PATCH 1/3] riscv: vdso: Add symbols for the alternative section boundaries Thomas Weißschuh
@ 2026-06-30  7:41 ` Thomas Weißschuh
  2026-06-30  7:41 ` [PATCH 3/3] riscv: alternative: Also patch the compat vDSO Thomas Weißschuh
  2026-07-02  8:12 ` [PATCH 0/3] riscv: alternative: Statically compute alternative section boundaries and patch " Nam Cao
  3 siblings, 0 replies; 5+ messages in thread
From: Thomas Weißschuh @ 2026-06-30  7:41 UTC (permalink / raw)
  To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti
  Cc: linux-riscv, linux-kernel, Nam Cao,
	Thomas Weißschuh (Schneider Electric)

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>
---
 arch/riscv/kernel/alternative.c | 28 +++++++++++-----------------
 1 file changed, 11 insertions(+), 17 deletions(-)

diff --git a/arch/riscv/kernel/alternative.c b/arch/riscv/kernel/alternative.c
index 104dc0862c5c..6aba169fb213 100644
--- a/arch/riscv/kernel/alternative.c
+++ b/arch/riscv/kernel/alternative.c
@@ -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);
 }
 
 /*

-- 
2.55.0


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

* [PATCH 3/3] riscv: alternative: Also patch the compat vDSO
  2026-06-30  7:41 [PATCH 0/3] riscv: alternative: Statically compute alternative section boundaries and patch compat vDSO Thomas Weißschuh
  2026-06-30  7:41 ` [PATCH 1/3] riscv: vdso: Add symbols for the alternative section boundaries Thomas Weißschuh
  2026-06-30  7:41 ` [PATCH 2/3] riscv: alternative: Use the statically extracted vDSO section offsets Thomas Weißschuh
@ 2026-06-30  7:41 ` Thomas Weißschuh
  2026-07-02  8:12 ` [PATCH 0/3] riscv: alternative: Statically compute alternative section boundaries and patch " Nam Cao
  3 siblings, 0 replies; 5+ messages in thread
From: Thomas Weißschuh @ 2026-06-30  7:41 UTC (permalink / raw)
  To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti
  Cc: linux-riscv, linux-kernel, Nam Cao,
	Thomas Weißschuh (Schneider Electric)

The vDSO for compat processes can also contain alternative entries.

Patch those, too.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
 arch/riscv/kernel/alternative.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/riscv/kernel/alternative.c b/arch/riscv/kernel/alternative.c
index 6aba169fb213..c0c9306022c5 100644
--- a/arch/riscv/kernel/alternative.c
+++ b/arch/riscv/kernel/alternative.c
@@ -202,6 +202,11 @@ void __init apply_boot_alternatives(void)
 		apply_vdso_alternatives(vdso_cfi_start,
 					__vdso_alternatives_start_cfi_offset,
 					__vdso_alternatives_end_cfi_offset);
+
+	if (IS_ENABLED(CONFIG_COMPAT))
+		apply_vdso_alternatives(compat_vdso_start,
+					compat__vdso_alternatives_start_offset,
+					compat__vdso_alternatives_end_offset);
 }
 
 /*

-- 
2.55.0


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

* Re: [PATCH 0/3] riscv: alternative: Statically compute alternative section boundaries and patch compat vDSO
  2026-06-30  7:41 [PATCH 0/3] riscv: alternative: Statically compute alternative section boundaries and patch compat vDSO Thomas Weißschuh
                   ` (2 preceding siblings ...)
  2026-06-30  7:41 ` [PATCH 3/3] riscv: alternative: Also patch the compat vDSO Thomas Weißschuh
@ 2026-07-02  8:12 ` Nam Cao
  3 siblings, 0 replies; 5+ messages in thread
From: Nam Cao @ 2026-07-02  8:12 UTC (permalink / raw)
  To: Thomas Weißschuh, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Alexandre Ghiti
  Cc: linux-riscv, linux-kernel,
	Thomas Weißschuh (Schneider Electric)

Thomas Weißschuh <thomas.weissschuh@linutronix.de> writes:
> 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.
>
> Extract the offsets of the alternative section during the build with the
> existing symbol extraction machinery and use those.
>
> Also add support for the compat vDSO.

Reviewed-by: Nam Cao <namcao@linutronix.de>

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

end of thread, other threads:[~2026-07-02  8:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-30  7:41 [PATCH 0/3] riscv: alternative: Statically compute alternative section boundaries and patch compat vDSO Thomas Weißschuh
2026-06-30  7:41 ` [PATCH 1/3] riscv: vdso: Add symbols for the alternative section boundaries Thomas Weißschuh
2026-06-30  7:41 ` [PATCH 2/3] riscv: alternative: Use the statically extracted vDSO section offsets Thomas Weißschuh
2026-06-30  7:41 ` [PATCH 3/3] riscv: alternative: Also patch the compat vDSO Thomas Weißschuh
2026-07-02  8:12 ` [PATCH 0/3] riscv: alternative: Statically compute alternative section boundaries and patch " Nam Cao

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