mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/4] riscv: alternative: Also patch the CFI vDSO
@ 2026-05-04  6:30 Thomas Weißschuh
  2026-05-04  6:30 ` [PATCH 1/4] riscv: vdso: Always declare vdso_start symbols Thomas Weißschuh
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Thomas Weißschuh @ 2026-05-04  6:30 UTC (permalink / raw)
  To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Deepak Gupta, Charles Mirabile
  Cc: linux-riscv, linux-kernel, Nam Cao, Thomas Weißschuh

The dedicated vDSO for CFI-enabled userspace can also contain
alternative entries.

It seems the vDSO alternative patching is actually dead code since
commit 0b1d60d6dd9e ("riscv: Fix build with
CONFIG_CC_OPTIMIZE_FOR_SIZE=y"). However new usages will be added 
soonish.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
Thomas Weißschuh (4):
      riscv: vdso: Always declare vdso_start symbols
      riscv: alternative: Use IS_ENABLED() over ifdeffery for apply_vdso_alternatives()
      riscv: alternative: Pass vDSO start as parameter to apply_vdso_alternatives()
      riscv: alternative: Also patch the CFI vDSO

 arch/riscv/include/asm/vdso.h   | 10 +++++-----
 arch/riscv/kernel/alternative.c | 14 +++++++-------
 2 files changed, 12 insertions(+), 12 deletions(-)
---
base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731
change-id: 20260428-riscv-cfi-vdso-alternative-7d8ad1a1c29c

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


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

* [PATCH 1/4] riscv: vdso: Always declare vdso_start symbols
  2026-05-04  6:30 [PATCH 0/4] riscv: alternative: Also patch the CFI vDSO Thomas Weißschuh
@ 2026-05-04  6:30 ` Thomas Weißschuh
  2026-05-04  6:30 ` [PATCH 2/4] riscv: alternative: Use IS_ENABLED() over ifdeffery for apply_vdso_alternatives() Thomas Weißschuh
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Thomas Weißschuh @ 2026-05-04  6:30 UTC (permalink / raw)
  To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Deepak Gupta, Charles Mirabile
  Cc: linux-riscv, linux-kernel, Nam Cao, Thomas Weißschuh

Make the declarations of vdso_start and its related symbols always
visible. With that their users don't have to use ifdeffery but can
use the better IS_ENABLED() compile-time checks.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
 arch/riscv/include/asm/vdso.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/riscv/include/asm/vdso.h b/arch/riscv/include/asm/vdso.h
index 35bf830a5576..f7998d9ad9b2 100644
--- a/arch/riscv/include/asm/vdso.h
+++ b/arch/riscv/include/asm/vdso.h
@@ -12,12 +12,15 @@
  * All systems with an MMU have a VDSO, but systems without an MMU don't
  * support shared libraries and therefore don't have one.
  */
-#ifdef CONFIG_MMU
 
 #define __VDSO_PAGES    4
 
 #ifndef __ASSEMBLER__
+
+#ifdef CONFIG_MMU
 #include <generated/vdso-offsets.h>
+#endif
+
 #ifdef CONFIG_RISCV_USER_CFI
 #include <generated/vdso-cfi-offsets.h>
 #endif
@@ -38,15 +41,12 @@
 #define COMPAT_VDSO_SYMBOL(base, name)						\
 	(void __user *)((unsigned long)(base) + compat__vdso_##name##_offset)
 
-extern char compat_vdso_start[], compat_vdso_end[];
-
 #endif /* CONFIG_COMPAT */
 
 extern char vdso_start[], vdso_end[];
 extern char vdso_cfi_start[], vdso_cfi_end[];
+extern char compat_vdso_start[], compat_vdso_end[];
 
 #endif /* !__ASSEMBLER__ */
 
-#endif /* CONFIG_MMU */
-
 #endif /* _ASM_RISCV_VDSO_H */

-- 
2.53.0


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

* [PATCH 2/4] riscv: alternative: Use IS_ENABLED() over ifdeffery for apply_vdso_alternatives()
  2026-05-04  6:30 [PATCH 0/4] riscv: alternative: Also patch the CFI vDSO Thomas Weißschuh
  2026-05-04  6:30 ` [PATCH 1/4] riscv: vdso: Always declare vdso_start symbols Thomas Weißschuh
@ 2026-05-04  6:30 ` Thomas Weißschuh
  2026-05-04  6:30 ` [PATCH 3/4] riscv: alternative: Pass vDSO start as parameter to apply_vdso_alternatives() Thomas Weißschuh
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Thomas Weißschuh @ 2026-05-04  6:30 UTC (permalink / raw)
  To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Deepak Gupta, Charles Mirabile
  Cc: linux-riscv, linux-kernel, Nam Cao, Thomas Weißschuh

IS_ENABLED() allows better compilation coverage while still optimizing
away all the dead code. Also it will make some upcoming changes easier.

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

diff --git a/arch/riscv/kernel/alternative.c b/arch/riscv/kernel/alternative.c
index 7642704c7f18..59991922a5dc 100644
--- a/arch/riscv/kernel/alternative.c
+++ b/arch/riscv/kernel/alternative.c
@@ -173,7 +173,6 @@ static void __init_or_module _apply_alternatives(struct alt_entry *begin,
 				stage);
 }
 
-#ifdef CONFIG_MMU
 static void __init apply_vdso_alternatives(void)
 {
 	const Elf_Ehdr *hdr;
@@ -194,9 +193,6 @@ static void __init apply_vdso_alternatives(void)
 			    (struct alt_entry *)end,
 			    RISCV_ALTERNATIVES_BOOT);
 }
-#else
-static void __init apply_vdso_alternatives(void) { }
-#endif
 
 void __init apply_boot_alternatives(void)
 {
@@ -207,7 +203,8 @@ void __init apply_boot_alternatives(void)
 			    (struct alt_entry *)__alt_end,
 			    RISCV_ALTERNATIVES_BOOT);
 
-	apply_vdso_alternatives();
+	if (IS_ENABLED(CONFIG_MMU))
+		apply_vdso_alternatives();
 }
 
 /*

-- 
2.53.0


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

* [PATCH 3/4] riscv: alternative: Pass vDSO start as parameter to apply_vdso_alternatives()
  2026-05-04  6:30 [PATCH 0/4] riscv: alternative: Also patch the CFI vDSO Thomas Weißschuh
  2026-05-04  6:30 ` [PATCH 1/4] riscv: vdso: Always declare vdso_start symbols Thomas Weißschuh
  2026-05-04  6:30 ` [PATCH 2/4] riscv: alternative: Use IS_ENABLED() over ifdeffery for apply_vdso_alternatives() Thomas Weißschuh
@ 2026-05-04  6:30 ` Thomas Weißschuh
  2026-05-04  6:30 ` [PATCH 4/4] riscv: alternative: Also patch the CFI vDSO Thomas Weißschuh
  2026-06-07  8:00 ` [PATCH 0/4] " patchwork-bot+linux-riscv
  4 siblings, 0 replies; 6+ messages in thread
From: Thomas Weißschuh @ 2026-05-04  6:30 UTC (permalink / raw)
  To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Deepak Gupta, Charles Mirabile
  Cc: linux-riscv, linux-kernel, Nam Cao, Thomas Weißschuh

The dedicated vDSO with CFI should also be patched in the same way.
To prepare for that move the currently hardcoded vDSO start symbol
into a parameter.

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

diff --git a/arch/riscv/kernel/alternative.c b/arch/riscv/kernel/alternative.c
index 59991922a5dc..89c283a5cec7 100644
--- a/arch/riscv/kernel/alternative.c
+++ b/arch/riscv/kernel/alternative.c
@@ -173,14 +173,14 @@ static void __init_or_module _apply_alternatives(struct alt_entry *begin,
 				stage);
 }
 
-static void __init apply_vdso_alternatives(void)
+static void __init apply_vdso_alternatives(void *start)
 {
 	const Elf_Ehdr *hdr;
 	const Elf_Shdr *shdr;
 	const Elf_Shdr *alt;
 	struct alt_entry *begin, *end;
 
-	hdr = (Elf_Ehdr *)vdso_start;
+	hdr = (Elf_Ehdr *)start;
 	shdr = (void *)hdr + hdr->e_shoff;
 	alt = find_section(hdr, shdr, ".alternative");
 	if (!alt)
@@ -204,7 +204,7 @@ void __init apply_boot_alternatives(void)
 			    RISCV_ALTERNATIVES_BOOT);
 
 	if (IS_ENABLED(CONFIG_MMU))
-		apply_vdso_alternatives();
+		apply_vdso_alternatives(vdso_start);
 }
 
 /*

-- 
2.53.0


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

* [PATCH 4/4] riscv: alternative: Also patch the CFI vDSO
  2026-05-04  6:30 [PATCH 0/4] riscv: alternative: Also patch the CFI vDSO Thomas Weißschuh
                   ` (2 preceding siblings ...)
  2026-05-04  6:30 ` [PATCH 3/4] riscv: alternative: Pass vDSO start as parameter to apply_vdso_alternatives() Thomas Weißschuh
@ 2026-05-04  6:30 ` Thomas Weißschuh
  2026-06-07  8:00 ` [PATCH 0/4] " patchwork-bot+linux-riscv
  4 siblings, 0 replies; 6+ messages in thread
From: Thomas Weißschuh @ 2026-05-04  6:30 UTC (permalink / raw)
  To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Deepak Gupta, Charles Mirabile
  Cc: linux-riscv, linux-kernel, Nam Cao, Thomas Weißschuh

The dedicated vDSO for CFI-enabled userspace can also contain
alternative entries.

Patch those, too.

Fixes: ccad8c1336b6 ("arch/riscv: add dual vdso creation logic and select vdso based on hw")
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
 arch/riscv/kernel/alternative.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/riscv/kernel/alternative.c b/arch/riscv/kernel/alternative.c
index 89c283a5cec7..104dc0862c5c 100644
--- a/arch/riscv/kernel/alternative.c
+++ b/arch/riscv/kernel/alternative.c
@@ -205,6 +205,9 @@ void __init apply_boot_alternatives(void)
 
 	if (IS_ENABLED(CONFIG_MMU))
 		apply_vdso_alternatives(vdso_start);
+
+	if (IS_ENABLED(CONFIG_RISCV_USER_CFI))
+		apply_vdso_alternatives(vdso_cfi_start);
 }
 
 /*

-- 
2.53.0


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

* Re: [PATCH 0/4] riscv: alternative: Also patch the CFI vDSO
  2026-05-04  6:30 [PATCH 0/4] riscv: alternative: Also patch the CFI vDSO Thomas Weißschuh
                   ` (3 preceding siblings ...)
  2026-05-04  6:30 ` [PATCH 4/4] riscv: alternative: Also patch the CFI vDSO Thomas Weißschuh
@ 2026-06-07  8:00 ` patchwork-bot+linux-riscv
  4 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+linux-riscv @ 2026-06-07  8:00 UTC (permalink / raw)
  To: =?utf-8?q?Thomas_Wei=C3=9Fschuh_=3Cthomas=2Eweissschuh=40linutronix=2Ede=3E?=
  Cc: linux-riscv, pjw, palmer, aou, alex, debug, cmirabil,
	linux-kernel, namcao

Hello:

This series was applied to riscv/linux.git (for-next)
by Paul Walmsley <pjw@kernel.org>:

On Mon, 04 May 2026 08:30:49 +0200 you wrote:
> The dedicated vDSO for CFI-enabled userspace can also contain
> alternative entries.
> 
> It seems the vDSO alternative patching is actually dead code since
> commit 0b1d60d6dd9e ("riscv: Fix build with
> CONFIG_CC_OPTIMIZE_FOR_SIZE=y"). However new usages will be added
> soonish.
> 
> [...]

Here is the summary with links:
  - [1/4] riscv: vdso: Always declare vdso_start symbols
    https://git.kernel.org/riscv/c/499578e22ae0
  - [2/4] riscv: alternative: Use IS_ENABLED() over ifdeffery for apply_vdso_alternatives()
    https://git.kernel.org/riscv/c/4fd6505f189d
  - [3/4] riscv: alternative: Pass vDSO start as parameter to apply_vdso_alternatives()
    https://git.kernel.org/riscv/c/6386161abb02
  - [4/4] riscv: alternative: Also patch the CFI vDSO
    https://git.kernel.org/riscv/c/d3e0634787a2

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

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

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-04  6:30 [PATCH 0/4] riscv: alternative: Also patch the CFI vDSO Thomas Weißschuh
2026-05-04  6:30 ` [PATCH 1/4] riscv: vdso: Always declare vdso_start symbols Thomas Weißschuh
2026-05-04  6:30 ` [PATCH 2/4] riscv: alternative: Use IS_ENABLED() over ifdeffery for apply_vdso_alternatives() Thomas Weißschuh
2026-05-04  6:30 ` [PATCH 3/4] riscv: alternative: Pass vDSO start as parameter to apply_vdso_alternatives() Thomas Weißschuh
2026-05-04  6:30 ` [PATCH 4/4] riscv: alternative: Also patch the CFI vDSO Thomas Weißschuh
2026-06-07  8:00 ` [PATCH 0/4] " patchwork-bot+linux-riscv

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®