* [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data()
@ 2026-09-25 21:46 Nathan Chancellor
2026-09-25 21:53 ` Nick Desaulniers
` (2 more replies)
0 siblings, 3 replies; 37+ messages in thread
From: Nathan Chancellor @ 2026-09-25 21:46 UTC (permalink / raw)
To: Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Jason A. Donenfeld
Cc: Vincenzo Frascino, Nick Desaulniers, Bill Wendling, Justin Stitt,
Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen,
WANG Xuerui, Madhavan Srinivasan, Michael Ellerman,
Nicholas Piggin, Christophe Leroy (CS GROUP),
Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
Christian Borntraeger, Sven Schnelle, Ingo Molnar,
Borislav Petkov, Dave Hansen, H. Peter Anvin, x86,
linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev,
linux-riscv, linux-s390, llvm, Nathan Chancellor
After a recent change in LLVM [1], builds with the random vDSO
implementation, such as PowerPC and RISC-V, fail when checking the vDSO:
arch/powerpc/kernel/vdso/vdso32.so.dbg: dynamic relocations are not supported
arch/riscv/kernel/vdso/vdso.so.dbg: dynamic relocations are not supported
memset() is now generated when zeroing params->reserved for some builds
because LLVM has an optimization (now run in more instances) that can
recognize at compile time when it is assigning a static value to a
contiguous area of memory and turn that into a call to memset(). Both
clang and GCC assume memset() is always available [2].
clang provides a builtin, __builtin_memset_inline [3][4], that can be
used to ensure an external function call is not generated when zeroing
this memory. Use it when it is available.
While GCC has no issues with the current code, it has generated memset()
before, as seen in commit b7bad082e113 ("random: vDSO: avoid call to out
of line memset()"). GCC 14 provides '-finline-stringops=memset' [5][6]
with a similar guarantee to the clang builtin, so use it and
__builtin_memset() when available.
If no option is available, provide a simple memset_inline() like the one
from lib/string.c to avoid adding an ugly ifdef.
Link: https://github.com/llvm/llvm-project/commit/90cebef1411617fc3eedd359bdf00cb44b1c2439 [1]
Link: https://gcc.gnu.org/onlinedocs/gcc-16.2.0/gcc/Standards.html#index-ffreestanding [2]
Link: https://github.com/llvm/llvm-project/commit/38637ee477541370a90b37f149069d8e5c0c2efd [3]
Link: https://clang.llvm.org/docs/LanguageExtensions.html#guaranteed-inlined-memset [4]
Link: https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=1ff6d9f7428b0668cd8ab0b3e3ab94f1d733124d [5]
Link: https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-finline-stringops [6]
Suggested-by: "Jason A. Donenfeld" <Jason@zx2c4.com>
Suggested-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
Changes in v2:
- Switch approach entirely (Jason, Nick)
- clang: use __builtin_memset_inline() to avoid external call
- GCC 14+: use __builtin_memset + -finline-stringops=memset (hence the
massive CC list increase)
- GCC < 14: no issues currently but avoid ifdef with simple memset
implementation
- Link to v1: https://patch.msgid.link/20260916-vdso-getrandom-avoid-memset-llvm-24-v1-1-80a92f2e225a@kernel.org
---
arch/arm64/kernel/vdso/Makefile | 2 +-
arch/loongarch/vdso/Makefile | 1 +
arch/powerpc/kernel/vdso/Makefile | 1 +
arch/riscv/kernel/vdso/Makefile | 1 +
arch/s390/kernel/vdso/Makefile | 1 +
arch/x86/entry/vdso/vdso64/Makefile | 2 +-
init/Kconfig | 7 +++++++
lib/vdso/getrandom.c | 19 +++++++++++++++++--
8 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/arch/arm64/kernel/vdso/Makefile b/arch/arm64/kernel/vdso/Makefile
index 7dec05dd33b7..f6619e1cb2ce 100644
--- a/arch/arm64/kernel/vdso/Makefile
+++ b/arch/arm64/kernel/vdso/Makefile
@@ -41,7 +41,7 @@ CC_FLAGS_REMOVE_VDSO := $(CC_FLAGS_FTRACE) -Os $(CC_FLAGS_SCS) \
$(CC_FLAGS_LTO) $(CC_FLAGS_CFI) \
-Wmissing-prototypes -Wmissing-declarations
-CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tables
+CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tables $(CONFIG_CC_OPT_INLINE_MEMSET)
CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_REMOVE_VDSO)
CFLAGS_REMOVE_vgetrandom.o = $(CC_FLAGS_REMOVE_VDSO)
diff --git a/arch/loongarch/vdso/Makefile b/arch/loongarch/vdso/Makefile
index 9c9181bb4071..0b84892d084b 100644
--- a/arch/loongarch/vdso/Makefile
+++ b/arch/loongarch/vdso/Makefile
@@ -16,6 +16,7 @@ ccflags-vdso := \
$(filter -m64,$(KBUILD_CFLAGS)) \
$(filter -march=%,$(KBUILD_CFLAGS)) \
$(filter -m%-float,$(KBUILD_CFLAGS)) \
+ $(CONFIG_CC_OPT_INLINE_MEMSET) \
$(CLANG_FLAGS) \
-D__VDSO__
diff --git a/arch/powerpc/kernel/vdso/Makefile b/arch/powerpc/kernel/vdso/Makefile
index 368759f81708..0d1a49529885 100644
--- a/arch/powerpc/kernel/vdso/Makefile
+++ b/arch/powerpc/kernel/vdso/Makefile
@@ -43,6 +43,7 @@ ccflags-y := -fno-common -fno-builtin -DBUILD_VDSO
ccflags-y += $(DISABLE_LATENT_ENTROPY_PLUGIN)
ccflags-y += $(call cc-option, -fno-stack-protector)
ccflags-y += -DDISABLE_BRANCH_PROFILING
+ccflags-y += $(CONFIG_CC_OPT_INLINE_MEMSET)
ccflags-y += -ffreestanding -fasynchronous-unwind-tables
ccflags-remove-y := $(CC_FLAGS_FTRACE)
ldflags-y := -Wl,--hash-style=both -nostdlib -shared -z noexecstack $(CLANG_FLAGS)
diff --git a/arch/riscv/kernel/vdso/Makefile b/arch/riscv/kernel/vdso/Makefile
index 8dbf2532a573..c023046a3fd7 100644
--- a/arch/riscv/kernel/vdso/Makefile
+++ b/arch/riscv/kernel/vdso/Makefile
@@ -36,6 +36,7 @@ endif
ccflags-y := -fno-stack-protector
ccflags-y += -DDISABLE_BRANCH_PROFILING
ccflags-y += -fno-builtin
+ccflags-y += $(CONFIG_CC_OPT_INLINE_MEMSET)
ccflags-y += $(KBUILD_BASE_ISA)$(CFI_MARCH)
ccflags-y += $(CFI_FULL)
asflags-y += $(KBUILD_BASE_ISA)$(CFI_MARCH)
diff --git a/arch/s390/kernel/vdso/Makefile b/arch/s390/kernel/vdso/Makefile
index 35c834b895ec..54bcf2984ca1 100644
--- a/arch/s390/kernel/vdso/Makefile
+++ b/arch/s390/kernel/vdso/Makefile
@@ -29,6 +29,7 @@ KBUILD_CFLAGS_VDSO := $(filter-out -munaligned-symbols,$(KBUILD_CFLAGS_VDSO))
KBUILD_CFLAGS_VDSO := $(filter-out -fno-asynchronous-unwind-tables,$(KBUILD_CFLAGS_VDSO))
KBUILD_CFLAGS_VDSO += -fPIC -fno-common -fno-builtin -fasynchronous-unwind-tables
KBUILD_CFLAGS_VDSO += -fno-stack-protector $(DISABLE_KSTACK_ERASE)
+KBUILD_CFLAGS_VDSO += $(CONFIG_CC_OPT_INLINE_MEMSET)
ldflags-y := -shared -soname=linux-vdso.so.1 \
--hash-style=both --build-id=sha1 \
$(call ld-option, --eh-frame-hdr) -T
diff --git a/arch/x86/entry/vdso/vdso64/Makefile b/arch/x86/entry/vdso/vdso64/Makefile
index 7c0790065b5e..c2353a065279 100644
--- a/arch/x86/entry/vdso/vdso64/Makefile
+++ b/arch/x86/entry/vdso/vdso64/Makefile
@@ -14,7 +14,7 @@ vobjs-$(CONFIG_X86_SGX) += vsgx.o
vobjs-$(CONFIG_FUTEX_ROBUST_UNLOCK) += vfutex.o
# Compilation flags
-flags-y := -DBUILD_VDSO64 -m64 -mcmodel=small
+flags-y := -DBUILD_VDSO64 -m64 -mcmodel=small $(CONFIG_CC_OPT_INLINE_MEMSET)
# The location of this include matters!
include $(src)/../common/Makefile.include
diff --git a/init/Kconfig b/init/Kconfig
index 8583d9f06c52..ff3f8475dd2f 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -173,6 +173,13 @@ config CC_HAS_ALLOC_TOKEN
config CC_HAS_MULTIDIMENSIONAL_NONSTRING
def_bool $(success,echo 'char tag[][4] __attribute__((__nonstring__)) = { };' | $(CC) $(CLANG_FLAGS) -x c - -c -o /dev/null -Werror)
+config CC_HAS_OPT_INLINE_MEMSET
+ def_bool $(cc-option,-finline-stringops=memset)
+
+config CC_OPT_INLINE_MEMSET
+ string
+ default "-finline-stringops=memset" if CC_HAS_OPT_INLINE_MEMSET
+
config LD_CAN_USE_KEEP_IN_OVERLAY
# ld.lld prior to 21.0.0 did not support KEEP within an overlay description
# https://github.com/llvm/llvm-project/pull/130661
diff --git a/lib/vdso/getrandom.c b/lib/vdso/getrandom.c
index 2851afa9154f..f5cad5641985 100644
--- a/lib/vdso/getrandom.c
+++ b/lib/vdso/getrandom.c
@@ -29,6 +29,22 @@
} \
} while (0)
+#if __has_builtin(__builtin_memset_inline)
+#define memset_inline(dst, value, size) __builtin_memset_inline(dst, value, size)
+#elif IS_ENABLED(CONFIG_CC_HAS_OPT_INLINE_MEMSET)
+#define memset_inline(dst, value, size) __builtin_memset(dst, value, size)
+#else
+static inline void *memset_inline(void *dst, int value, size_t size)
+{
+ char *d = dst;
+
+ while (size--)
+ *d++ = value;
+
+ return d;
+}
+#endif
+
static void memcpy_and_zero_src(void *dst, void *src, size_t len)
{
if (IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)) {
@@ -83,8 +99,7 @@ __cvdso_getrandom_data(const struct vdso_rng_data *rng_info, void *buffer, size_
params->size_of_opaque_state = sizeof(*state);
params->mmap_prot = PROT_READ | PROT_WRITE;
params->mmap_flags = MAP_DROPPABLE | MAP_ANONYMOUS;
- for (size_t i = 0; i < ARRAY_SIZE(params->reserved); ++i)
- params->reserved[i] = 0;
+ memset_inline(params->reserved, 0, sizeof(params->reserved));
return 0;
}
---
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
change-id: 20260916-vdso-getrandom-avoid-memset-llvm-24-74d45fa6031e
Best regards,
--
Cheers,
Nathan
^ permalink raw reply [flat|nested] 37+ messages in thread* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-09-25 21:46 [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() Nathan Chancellor @ 2026-09-25 21:53 ` Nick Desaulniers 2026-09-25 21:56 ` Nick Desaulniers 2026-09-26 9:39 ` Andreas Schwab 2026-10-02 10:57 ` Christophe Leroy (CS GROUP) 2 siblings, 1 reply; 37+ messages in thread From: Nick Desaulniers @ 2026-09-25 21:53 UTC (permalink / raw) To: Nathan Chancellor Cc: Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Jason A. Donenfeld, Vincenzo Frascino, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Christophe Leroy (CS GROUP), Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm On Fri, Sep 25, 2026 at 2:46 PM Nathan Chancellor <nathan@kernel.org> wrote: > > After a recent change in LLVM [1], builds with the random vDSO > implementation, such as PowerPC and RISC-V, fail when checking the vDSO: > > arch/powerpc/kernel/vdso/vdso32.so.dbg: dynamic relocations are not supported > arch/riscv/kernel/vdso/vdso.so.dbg: dynamic relocations are not supported > > memset() is now generated when zeroing params->reserved for some builds > because LLVM has an optimization (now run in more instances) that can > recognize at compile time when it is assigning a static value to a > contiguous area of memory and turn that into a call to memset(). Both > clang and GCC assume memset() is always available [2]. > > clang provides a builtin, __builtin_memset_inline [3][4], that can be > used to ensure an external function call is not generated when zeroing > this memory. Use it when it is available. > > While GCC has no issues with the current code, it has generated memset() > before, as seen in commit b7bad082e113 ("random: vDSO: avoid call to out > of line memset()"). GCC 14 provides '-finline-stringops=memset' [5][6] > with a similar guarantee to the clang builtin, so use it and > __builtin_memset() when available. > > If no option is available, provide a simple memset_inline() like the one > from lib/string.c to avoid adding an ugly ifdef. > > Link: https://github.com/llvm/llvm-project/commit/90cebef1411617fc3eedd359bdf00cb44b1c2439 [1] > Link: https://gcc.gnu.org/onlinedocs/gcc-16.2.0/gcc/Standards.html#index-ffreestanding [2] > Link: https://github.com/llvm/llvm-project/commit/38637ee477541370a90b37f149069d8e5c0c2efd [3] > Link: https://clang.llvm.org/docs/LanguageExtensions.html#guaranteed-inlined-memset [4] > Link: https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=1ff6d9f7428b0668cd8ab0b3e3ab94f1d733124d [5] > Link: https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-finline-stringops [6] > Suggested-by: "Jason A. Donenfeld" <Jason@zx2c4.com> > Suggested-by: Nick Desaulniers <ndesaulniers@google.com> > Signed-off-by: Nathan Chancellor <nathan@kernel.org> > --- > Changes in v2: > - Switch approach entirely (Jason, Nick) > - clang: use __builtin_memset_inline() to avoid external call > - GCC 14+: use __builtin_memset + -finline-stringops=memset (hence the > massive CC list increase) > - GCC < 14: no issues currently but avoid ifdef with simple memset > implementation > - Link to v1: https://patch.msgid.link/20260916-vdso-getrandom-avoid-memset-llvm-24-v1-1-80a92f2e225a@kernel.org > --- > arch/arm64/kernel/vdso/Makefile | 2 +- > arch/loongarch/vdso/Makefile | 1 + > arch/powerpc/kernel/vdso/Makefile | 1 + > arch/riscv/kernel/vdso/Makefile | 1 + > arch/s390/kernel/vdso/Makefile | 1 + > arch/x86/entry/vdso/vdso64/Makefile | 2 +- > init/Kconfig | 7 +++++++ > lib/vdso/getrandom.c | 19 +++++++++++++++++-- > 8 files changed, 30 insertions(+), 4 deletions(-) > > diff --git a/arch/arm64/kernel/vdso/Makefile b/arch/arm64/kernel/vdso/Makefile > index 7dec05dd33b7..f6619e1cb2ce 100644 > --- a/arch/arm64/kernel/vdso/Makefile > +++ b/arch/arm64/kernel/vdso/Makefile > @@ -41,7 +41,7 @@ CC_FLAGS_REMOVE_VDSO := $(CC_FLAGS_FTRACE) -Os $(CC_FLAGS_SCS) \ > $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) \ > -Wmissing-prototypes -Wmissing-declarations > > -CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tables > +CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tables $(CONFIG_CC_OPT_INLINE_MEMSET) > > CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_REMOVE_VDSO) > CFLAGS_REMOVE_vgetrandom.o = $(CC_FLAGS_REMOVE_VDSO) > diff --git a/arch/loongarch/vdso/Makefile b/arch/loongarch/vdso/Makefile > index 9c9181bb4071..0b84892d084b 100644 > --- a/arch/loongarch/vdso/Makefile > +++ b/arch/loongarch/vdso/Makefile > @@ -16,6 +16,7 @@ ccflags-vdso := \ > $(filter -m64,$(KBUILD_CFLAGS)) \ > $(filter -march=%,$(KBUILD_CFLAGS)) \ > $(filter -m%-float,$(KBUILD_CFLAGS)) \ > + $(CONFIG_CC_OPT_INLINE_MEMSET) \ > $(CLANG_FLAGS) \ > -D__VDSO__ > > diff --git a/arch/powerpc/kernel/vdso/Makefile b/arch/powerpc/kernel/vdso/Makefile > index 368759f81708..0d1a49529885 100644 > --- a/arch/powerpc/kernel/vdso/Makefile > +++ b/arch/powerpc/kernel/vdso/Makefile > @@ -43,6 +43,7 @@ ccflags-y := -fno-common -fno-builtin -DBUILD_VDSO > ccflags-y += $(DISABLE_LATENT_ENTROPY_PLUGIN) > ccflags-y += $(call cc-option, -fno-stack-protector) > ccflags-y += -DDISABLE_BRANCH_PROFILING > +ccflags-y += $(CONFIG_CC_OPT_INLINE_MEMSET) > ccflags-y += -ffreestanding -fasynchronous-unwind-tables > ccflags-remove-y := $(CC_FLAGS_FTRACE) > ldflags-y := -Wl,--hash-style=both -nostdlib -shared -z noexecstack $(CLANG_FLAGS) > diff --git a/arch/riscv/kernel/vdso/Makefile b/arch/riscv/kernel/vdso/Makefile > index 8dbf2532a573..c023046a3fd7 100644 > --- a/arch/riscv/kernel/vdso/Makefile > +++ b/arch/riscv/kernel/vdso/Makefile > @@ -36,6 +36,7 @@ endif > ccflags-y := -fno-stack-protector > ccflags-y += -DDISABLE_BRANCH_PROFILING > ccflags-y += -fno-builtin > +ccflags-y += $(CONFIG_CC_OPT_INLINE_MEMSET) > ccflags-y += $(KBUILD_BASE_ISA)$(CFI_MARCH) > ccflags-y += $(CFI_FULL) > asflags-y += $(KBUILD_BASE_ISA)$(CFI_MARCH) > diff --git a/arch/s390/kernel/vdso/Makefile b/arch/s390/kernel/vdso/Makefile > index 35c834b895ec..54bcf2984ca1 100644 > --- a/arch/s390/kernel/vdso/Makefile > +++ b/arch/s390/kernel/vdso/Makefile > @@ -29,6 +29,7 @@ KBUILD_CFLAGS_VDSO := $(filter-out -munaligned-symbols,$(KBUILD_CFLAGS_VDSO)) > KBUILD_CFLAGS_VDSO := $(filter-out -fno-asynchronous-unwind-tables,$(KBUILD_CFLAGS_VDSO)) > KBUILD_CFLAGS_VDSO += -fPIC -fno-common -fno-builtin -fasynchronous-unwind-tables > KBUILD_CFLAGS_VDSO += -fno-stack-protector $(DISABLE_KSTACK_ERASE) > +KBUILD_CFLAGS_VDSO += $(CONFIG_CC_OPT_INLINE_MEMSET) > ldflags-y := -shared -soname=linux-vdso.so.1 \ > --hash-style=both --build-id=sha1 \ > $(call ld-option, --eh-frame-hdr) -T > diff --git a/arch/x86/entry/vdso/vdso64/Makefile b/arch/x86/entry/vdso/vdso64/Makefile > index 7c0790065b5e..c2353a065279 100644 > --- a/arch/x86/entry/vdso/vdso64/Makefile > +++ b/arch/x86/entry/vdso/vdso64/Makefile > @@ -14,7 +14,7 @@ vobjs-$(CONFIG_X86_SGX) += vsgx.o > vobjs-$(CONFIG_FUTEX_ROBUST_UNLOCK) += vfutex.o > > # Compilation flags > -flags-y := -DBUILD_VDSO64 -m64 -mcmodel=small > +flags-y := -DBUILD_VDSO64 -m64 -mcmodel=small $(CONFIG_CC_OPT_INLINE_MEMSET) > > # The location of this include matters! > include $(src)/../common/Makefile.include > diff --git a/init/Kconfig b/init/Kconfig > index 8583d9f06c52..ff3f8475dd2f 100644 > --- a/init/Kconfig > +++ b/init/Kconfig > @@ -173,6 +173,13 @@ config CC_HAS_ALLOC_TOKEN > config CC_HAS_MULTIDIMENSIONAL_NONSTRING > def_bool $(success,echo 'char tag[][4] __attribute__((__nonstring__)) = { };' | $(CC) $(CLANG_FLAGS) -x c - -c -o /dev/null -Werror) > > +config CC_HAS_OPT_INLINE_MEMSET > + def_bool $(cc-option,-finline-stringops=memset) > + > +config CC_OPT_INLINE_MEMSET > + string > + default "-finline-stringops=memset" if CC_HAS_OPT_INLINE_MEMSET > + > config LD_CAN_USE_KEEP_IN_OVERLAY > # ld.lld prior to 21.0.0 did not support KEEP within an overlay description > # https://github.com/llvm/llvm-project/pull/130661 > diff --git a/lib/vdso/getrandom.c b/lib/vdso/getrandom.c > index 2851afa9154f..f5cad5641985 100644 > --- a/lib/vdso/getrandom.c > +++ b/lib/vdso/getrandom.c > @@ -29,6 +29,22 @@ > } \ > } while (0) > > +#if __has_builtin(__builtin_memset_inline) > +#define memset_inline(dst, value, size) __builtin_memset_inline(dst, value, size) > +#elif IS_ENABLED(CONFIG_CC_HAS_OPT_INLINE_MEMSET) > +#define memset_inline(dst, value, size) __builtin_memset(dst, value, size) > +#else > +static inline void *memset_inline(void *dst, int value, size_t size) > +{ > + char *d = dst; > + > + while (size--) > + *d++ = value; > + > + return d; > +} > +#endif Does this work? https://godbolt.org/z/Tx6EaGMfb (Sorry, I _should_ have replied to Jason on V1. I'm not ignoring him, just way behind on my code reviews. Sorry!) > + > static void memcpy_and_zero_src(void *dst, void *src, size_t len) > { > if (IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)) { > @@ -83,8 +99,7 @@ __cvdso_getrandom_data(const struct vdso_rng_data *rng_info, void *buffer, size_ > params->size_of_opaque_state = sizeof(*state); > params->mmap_prot = PROT_READ | PROT_WRITE; > params->mmap_flags = MAP_DROPPABLE | MAP_ANONYMOUS; > - for (size_t i = 0; i < ARRAY_SIZE(params->reserved); ++i) > - params->reserved[i] = 0; > + memset_inline(params->reserved, 0, sizeof(params->reserved)); > return 0; > } > > > --- > base-commit: cee9395acd8043be0644b25c34bfa86623f2b935 > change-id: 20260916-vdso-getrandom-avoid-memset-llvm-24-74d45fa6031e > > Best regards, > -- > Cheers, > Nathan > -- Thanks, ~Nick Desaulniers ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-09-25 21:53 ` Nick Desaulniers @ 2026-09-25 21:56 ` Nick Desaulniers 2026-09-25 22:00 ` Nick Desaulniers 0 siblings, 1 reply; 37+ messages in thread From: Nick Desaulniers @ 2026-09-25 21:56 UTC (permalink / raw) To: Nathan Chancellor Cc: Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Jason A. Donenfeld, Vincenzo Frascino, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Christophe Leroy (CS GROUP), Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm On Fri, Sep 25, 2026 at 2:53 PM Nick Desaulniers <ndesaulniers@google.com> wrote: > > On Fri, Sep 25, 2026 at 2:46 PM Nathan Chancellor <nathan@kernel.org> wrote: > > > > After a recent change in LLVM [1], builds with the random vDSO > > implementation, such as PowerPC and RISC-V, fail when checking the vDSO: > > > > arch/powerpc/kernel/vdso/vdso32.so.dbg: dynamic relocations are not supported > > arch/riscv/kernel/vdso/vdso.so.dbg: dynamic relocations are not supported > > > > memset() is now generated when zeroing params->reserved for some builds > > because LLVM has an optimization (now run in more instances) that can > > recognize at compile time when it is assigning a static value to a > > contiguous area of memory and turn that into a call to memset(). Both > > clang and GCC assume memset() is always available [2]. > > > > clang provides a builtin, __builtin_memset_inline [3][4], that can be > > used to ensure an external function call is not generated when zeroing > > this memory. Use it when it is available. > > > > While GCC has no issues with the current code, it has generated memset() > > before, as seen in commit b7bad082e113 ("random: vDSO: avoid call to out > > of line memset()"). GCC 14 provides '-finline-stringops=memset' [5][6] > > with a similar guarantee to the clang builtin, so use it and > > __builtin_memset() when available. > > > > If no option is available, provide a simple memset_inline() like the one > > from lib/string.c to avoid adding an ugly ifdef. > > > > Link: https://github.com/llvm/llvm-project/commit/90cebef1411617fc3eedd359bdf00cb44b1c2439 [1] > > Link: https://gcc.gnu.org/onlinedocs/gcc-16.2.0/gcc/Standards.html#index-ffreestanding [2] > > Link: https://github.com/llvm/llvm-project/commit/38637ee477541370a90b37f149069d8e5c0c2efd [3] > > Link: https://clang.llvm.org/docs/LanguageExtensions.html#guaranteed-inlined-memset [4] > > Link: https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=1ff6d9f7428b0668cd8ab0b3e3ab94f1d733124d [5] > > Link: https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-finline-stringops [6] > > Suggested-by: "Jason A. Donenfeld" <Jason@zx2c4.com> > > Suggested-by: Nick Desaulniers <ndesaulniers@google.com> > > Signed-off-by: Nathan Chancellor <nathan@kernel.org> > > --- > > Changes in v2: > > - Switch approach entirely (Jason, Nick) > > - clang: use __builtin_memset_inline() to avoid external call > > - GCC 14+: use __builtin_memset + -finline-stringops=memset (hence the > > massive CC list increase) > > - GCC < 14: no issues currently but avoid ifdef with simple memset > > implementation > > - Link to v1: https://patch.msgid.link/20260916-vdso-getrandom-avoid-memset-llvm-24-v1-1-80a92f2e225a@kernel.org > > --- > > arch/arm64/kernel/vdso/Makefile | 2 +- > > arch/loongarch/vdso/Makefile | 1 + > > arch/powerpc/kernel/vdso/Makefile | 1 + > > arch/riscv/kernel/vdso/Makefile | 1 + > > arch/s390/kernel/vdso/Makefile | 1 + > > arch/x86/entry/vdso/vdso64/Makefile | 2 +- > > init/Kconfig | 7 +++++++ > > lib/vdso/getrandom.c | 19 +++++++++++++++++-- > > 8 files changed, 30 insertions(+), 4 deletions(-) > > > > diff --git a/arch/arm64/kernel/vdso/Makefile b/arch/arm64/kernel/vdso/Makefile > > index 7dec05dd33b7..f6619e1cb2ce 100644 > > --- a/arch/arm64/kernel/vdso/Makefile > > +++ b/arch/arm64/kernel/vdso/Makefile > > @@ -41,7 +41,7 @@ CC_FLAGS_REMOVE_VDSO := $(CC_FLAGS_FTRACE) -Os $(CC_FLAGS_SCS) \ > > $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) \ > > -Wmissing-prototypes -Wmissing-declarations > > > > -CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tables > > +CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tables $(CONFIG_CC_OPT_INLINE_MEMSET) > > > > CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_REMOVE_VDSO) > > CFLAGS_REMOVE_vgetrandom.o = $(CC_FLAGS_REMOVE_VDSO) > > diff --git a/arch/loongarch/vdso/Makefile b/arch/loongarch/vdso/Makefile > > index 9c9181bb4071..0b84892d084b 100644 > > --- a/arch/loongarch/vdso/Makefile > > +++ b/arch/loongarch/vdso/Makefile > > @@ -16,6 +16,7 @@ ccflags-vdso := \ > > $(filter -m64,$(KBUILD_CFLAGS)) \ > > $(filter -march=%,$(KBUILD_CFLAGS)) \ > > $(filter -m%-float,$(KBUILD_CFLAGS)) \ > > + $(CONFIG_CC_OPT_INLINE_MEMSET) \ > > $(CLANG_FLAGS) \ > > -D__VDSO__ > > > > diff --git a/arch/powerpc/kernel/vdso/Makefile b/arch/powerpc/kernel/vdso/Makefile > > index 368759f81708..0d1a49529885 100644 > > --- a/arch/powerpc/kernel/vdso/Makefile > > +++ b/arch/powerpc/kernel/vdso/Makefile > > @@ -43,6 +43,7 @@ ccflags-y := -fno-common -fno-builtin -DBUILD_VDSO > > ccflags-y += $(DISABLE_LATENT_ENTROPY_PLUGIN) > > ccflags-y += $(call cc-option, -fno-stack-protector) > > ccflags-y += -DDISABLE_BRANCH_PROFILING > > +ccflags-y += $(CONFIG_CC_OPT_INLINE_MEMSET) > > ccflags-y += -ffreestanding -fasynchronous-unwind-tables > > ccflags-remove-y := $(CC_FLAGS_FTRACE) > > ldflags-y := -Wl,--hash-style=both -nostdlib -shared -z noexecstack $(CLANG_FLAGS) > > diff --git a/arch/riscv/kernel/vdso/Makefile b/arch/riscv/kernel/vdso/Makefile > > index 8dbf2532a573..c023046a3fd7 100644 > > --- a/arch/riscv/kernel/vdso/Makefile > > +++ b/arch/riscv/kernel/vdso/Makefile > > @@ -36,6 +36,7 @@ endif > > ccflags-y := -fno-stack-protector > > ccflags-y += -DDISABLE_BRANCH_PROFILING > > ccflags-y += -fno-builtin > > +ccflags-y += $(CONFIG_CC_OPT_INLINE_MEMSET) > > ccflags-y += $(KBUILD_BASE_ISA)$(CFI_MARCH) > > ccflags-y += $(CFI_FULL) > > asflags-y += $(KBUILD_BASE_ISA)$(CFI_MARCH) > > diff --git a/arch/s390/kernel/vdso/Makefile b/arch/s390/kernel/vdso/Makefile > > index 35c834b895ec..54bcf2984ca1 100644 > > --- a/arch/s390/kernel/vdso/Makefile > > +++ b/arch/s390/kernel/vdso/Makefile > > @@ -29,6 +29,7 @@ KBUILD_CFLAGS_VDSO := $(filter-out -munaligned-symbols,$(KBUILD_CFLAGS_VDSO)) > > KBUILD_CFLAGS_VDSO := $(filter-out -fno-asynchronous-unwind-tables,$(KBUILD_CFLAGS_VDSO)) > > KBUILD_CFLAGS_VDSO += -fPIC -fno-common -fno-builtin -fasynchronous-unwind-tables > > KBUILD_CFLAGS_VDSO += -fno-stack-protector $(DISABLE_KSTACK_ERASE) > > +KBUILD_CFLAGS_VDSO += $(CONFIG_CC_OPT_INLINE_MEMSET) > > ldflags-y := -shared -soname=linux-vdso.so.1 \ > > --hash-style=both --build-id=sha1 \ > > $(call ld-option, --eh-frame-hdr) -T > > diff --git a/arch/x86/entry/vdso/vdso64/Makefile b/arch/x86/entry/vdso/vdso64/Makefile > > index 7c0790065b5e..c2353a065279 100644 > > --- a/arch/x86/entry/vdso/vdso64/Makefile > > +++ b/arch/x86/entry/vdso/vdso64/Makefile > > @@ -14,7 +14,7 @@ vobjs-$(CONFIG_X86_SGX) += vsgx.o > > vobjs-$(CONFIG_FUTEX_ROBUST_UNLOCK) += vfutex.o > > > > # Compilation flags > > -flags-y := -DBUILD_VDSO64 -m64 -mcmodel=small > > +flags-y := -DBUILD_VDSO64 -m64 -mcmodel=small $(CONFIG_CC_OPT_INLINE_MEMSET) > > > > # The location of this include matters! > > include $(src)/../common/Makefile.include > > diff --git a/init/Kconfig b/init/Kconfig > > index 8583d9f06c52..ff3f8475dd2f 100644 > > --- a/init/Kconfig > > +++ b/init/Kconfig > > @@ -173,6 +173,13 @@ config CC_HAS_ALLOC_TOKEN > > config CC_HAS_MULTIDIMENSIONAL_NONSTRING > > def_bool $(success,echo 'char tag[][4] __attribute__((__nonstring__)) = { };' | $(CC) $(CLANG_FLAGS) -x c - -c -o /dev/null -Werror) > > > > +config CC_HAS_OPT_INLINE_MEMSET > > + def_bool $(cc-option,-finline-stringops=memset) > > + > > +config CC_OPT_INLINE_MEMSET > > + string > > + default "-finline-stringops=memset" if CC_HAS_OPT_INLINE_MEMSET > > + > > config LD_CAN_USE_KEEP_IN_OVERLAY > > # ld.lld prior to 21.0.0 did not support KEEP within an overlay description > > # https://github.com/llvm/llvm-project/pull/130661 > > diff --git a/lib/vdso/getrandom.c b/lib/vdso/getrandom.c > > index 2851afa9154f..f5cad5641985 100644 > > --- a/lib/vdso/getrandom.c > > +++ b/lib/vdso/getrandom.c > > @@ -29,6 +29,22 @@ > > } \ > > } while (0) > > > > +#if __has_builtin(__builtin_memset_inline) > > +#define memset_inline(dst, value, size) __builtin_memset_inline(dst, value, size) > > +#elif IS_ENABLED(CONFIG_CC_HAS_OPT_INLINE_MEMSET) > > +#define memset_inline(dst, value, size) __builtin_memset(dst, value, size) > > +#else > > +static inline void *memset_inline(void *dst, int value, size_t size) > > +{ > > + char *d = dst; > > + > > + while (size--) > > + *d++ = value; > > + > > + return d; > > +} > > +#endif > > Does this work? > https://godbolt.org/z/Tx6EaGMfb Hmmm...possibly. https://godbolt.org/z/ec9rzd9Yf I don't get it... > > (Sorry, I _should_ have replied to Jason on V1. I'm not ignoring him, > just way behind on my code reviews. Sorry!) > > > + > > static void memcpy_and_zero_src(void *dst, void *src, size_t len) > > { > > if (IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)) { > > @@ -83,8 +99,7 @@ __cvdso_getrandom_data(const struct vdso_rng_data *rng_info, void *buffer, size_ > > params->size_of_opaque_state = sizeof(*state); > > params->mmap_prot = PROT_READ | PROT_WRITE; > > params->mmap_flags = MAP_DROPPABLE | MAP_ANONYMOUS; > > - for (size_t i = 0; i < ARRAY_SIZE(params->reserved); ++i) > > - params->reserved[i] = 0; > > + memset_inline(params->reserved, 0, sizeof(params->reserved)); > > return 0; > > } > > > > > > --- > > base-commit: cee9395acd8043be0644b25c34bfa86623f2b935 > > change-id: 20260916-vdso-getrandom-avoid-memset-llvm-24-74d45fa6031e > > > > Best regards, > > -- > > Cheers, > > Nathan > > > > > -- > Thanks, > ~Nick Desaulniers -- Thanks, ~Nick Desaulniers ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-09-25 21:56 ` Nick Desaulniers @ 2026-09-25 22:00 ` Nick Desaulniers 2026-09-25 22:19 ` Nathan Chancellor ` (2 more replies) 0 siblings, 3 replies; 37+ messages in thread From: Nick Desaulniers @ 2026-09-25 22:00 UTC (permalink / raw) To: Nathan Chancellor Cc: Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Jason A. Donenfeld, Vincenzo Frascino, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Christophe Leroy (CS GROUP), Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm On Fri, Sep 25, 2026 at 2:56 PM Nick Desaulniers <ndesaulniers@google.com> wrote: > > On Fri, Sep 25, 2026 at 2:53 PM Nick Desaulniers > <ndesaulniers@google.com> wrote: > > > > On Fri, Sep 25, 2026 at 2:46 PM Nathan Chancellor <nathan@kernel.org> wrote: > > > > > > After a recent change in LLVM [1], builds with the random vDSO > > > implementation, such as PowerPC and RISC-V, fail when checking the vDSO: > > > > > > arch/powerpc/kernel/vdso/vdso32.so.dbg: dynamic relocations are not supported > > > arch/riscv/kernel/vdso/vdso.so.dbg: dynamic relocations are not supported > > > > > > memset() is now generated when zeroing params->reserved for some builds > > > because LLVM has an optimization (now run in more instances) that can > > > recognize at compile time when it is assigning a static value to a > > > contiguous area of memory and turn that into a call to memset(). Both > > > clang and GCC assume memset() is always available [2]. > > > > > > clang provides a builtin, __builtin_memset_inline [3][4], that can be > > > used to ensure an external function call is not generated when zeroing > > > this memory. Use it when it is available. > > > > > > While GCC has no issues with the current code, it has generated memset() > > > before, as seen in commit b7bad082e113 ("random: vDSO: avoid call to out > > > of line memset()"). GCC 14 provides '-finline-stringops=memset' [5][6] > > > with a similar guarantee to the clang builtin, so use it and > > > __builtin_memset() when available. > > > > > > If no option is available, provide a simple memset_inline() like the one > > > from lib/string.c to avoid adding an ugly ifdef. > > > > > > Link: https://github.com/llvm/llvm-project/commit/90cebef1411617fc3eedd359bdf00cb44b1c2439 [1] > > > Link: https://gcc.gnu.org/onlinedocs/gcc-16.2.0/gcc/Standards.html#index-ffreestanding [2] > > > Link: https://github.com/llvm/llvm-project/commit/38637ee477541370a90b37f149069d8e5c0c2efd [3] > > > Link: https://clang.llvm.org/docs/LanguageExtensions.html#guaranteed-inlined-memset [4] > > > Link: https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=1ff6d9f7428b0668cd8ab0b3e3ab94f1d733124d [5] > > > Link: https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-finline-stringops [6] > > > Suggested-by: "Jason A. Donenfeld" <Jason@zx2c4.com> > > > Suggested-by: Nick Desaulniers <ndesaulniers@google.com> > > > Signed-off-by: Nathan Chancellor <nathan@kernel.org> > > > --- > > > Changes in v2: > > > - Switch approach entirely (Jason, Nick) > > > - clang: use __builtin_memset_inline() to avoid external call > > > - GCC 14+: use __builtin_memset + -finline-stringops=memset (hence the > > > massive CC list increase) > > > - GCC < 14: no issues currently but avoid ifdef with simple memset > > > implementation > > > - Link to v1: https://patch.msgid.link/20260916-vdso-getrandom-avoid-memset-llvm-24-v1-1-80a92f2e225a@kernel.org > > > --- > > > arch/arm64/kernel/vdso/Makefile | 2 +- > > > arch/loongarch/vdso/Makefile | 1 + > > > arch/powerpc/kernel/vdso/Makefile | 1 + > > > arch/riscv/kernel/vdso/Makefile | 1 + > > > arch/s390/kernel/vdso/Makefile | 1 + > > > arch/x86/entry/vdso/vdso64/Makefile | 2 +- > > > init/Kconfig | 7 +++++++ > > > lib/vdso/getrandom.c | 19 +++++++++++++++++-- > > > 8 files changed, 30 insertions(+), 4 deletions(-) > > > > > > diff --git a/arch/arm64/kernel/vdso/Makefile b/arch/arm64/kernel/vdso/Makefile > > > index 7dec05dd33b7..f6619e1cb2ce 100644 > > > --- a/arch/arm64/kernel/vdso/Makefile > > > +++ b/arch/arm64/kernel/vdso/Makefile > > > @@ -41,7 +41,7 @@ CC_FLAGS_REMOVE_VDSO := $(CC_FLAGS_FTRACE) -Os $(CC_FLAGS_SCS) \ > > > $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) \ > > > -Wmissing-prototypes -Wmissing-declarations > > > > > > -CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tables > > > +CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tables $(CONFIG_CC_OPT_INLINE_MEMSET) > > > > > > CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_REMOVE_VDSO) > > > CFLAGS_REMOVE_vgetrandom.o = $(CC_FLAGS_REMOVE_VDSO) > > > diff --git a/arch/loongarch/vdso/Makefile b/arch/loongarch/vdso/Makefile > > > index 9c9181bb4071..0b84892d084b 100644 > > > --- a/arch/loongarch/vdso/Makefile > > > +++ b/arch/loongarch/vdso/Makefile > > > @@ -16,6 +16,7 @@ ccflags-vdso := \ > > > $(filter -m64,$(KBUILD_CFLAGS)) \ > > > $(filter -march=%,$(KBUILD_CFLAGS)) \ > > > $(filter -m%-float,$(KBUILD_CFLAGS)) \ > > > + $(CONFIG_CC_OPT_INLINE_MEMSET) \ > > > $(CLANG_FLAGS) \ > > > -D__VDSO__ > > > > > > diff --git a/arch/powerpc/kernel/vdso/Makefile b/arch/powerpc/kernel/vdso/Makefile > > > index 368759f81708..0d1a49529885 100644 > > > --- a/arch/powerpc/kernel/vdso/Makefile > > > +++ b/arch/powerpc/kernel/vdso/Makefile > > > @@ -43,6 +43,7 @@ ccflags-y := -fno-common -fno-builtin -DBUILD_VDSO > > > ccflags-y += $(DISABLE_LATENT_ENTROPY_PLUGIN) > > > ccflags-y += $(call cc-option, -fno-stack-protector) > > > ccflags-y += -DDISABLE_BRANCH_PROFILING > > > +ccflags-y += $(CONFIG_CC_OPT_INLINE_MEMSET) > > > ccflags-y += -ffreestanding -fasynchronous-unwind-tables > > > ccflags-remove-y := $(CC_FLAGS_FTRACE) > > > ldflags-y := -Wl,--hash-style=both -nostdlib -shared -z noexecstack $(CLANG_FLAGS) > > > diff --git a/arch/riscv/kernel/vdso/Makefile b/arch/riscv/kernel/vdso/Makefile > > > index 8dbf2532a573..c023046a3fd7 100644 > > > --- a/arch/riscv/kernel/vdso/Makefile > > > +++ b/arch/riscv/kernel/vdso/Makefile > > > @@ -36,6 +36,7 @@ endif > > > ccflags-y := -fno-stack-protector > > > ccflags-y += -DDISABLE_BRANCH_PROFILING > > > ccflags-y += -fno-builtin > > > +ccflags-y += $(CONFIG_CC_OPT_INLINE_MEMSET) > > > ccflags-y += $(KBUILD_BASE_ISA)$(CFI_MARCH) > > > ccflags-y += $(CFI_FULL) > > > asflags-y += $(KBUILD_BASE_ISA)$(CFI_MARCH) > > > diff --git a/arch/s390/kernel/vdso/Makefile b/arch/s390/kernel/vdso/Makefile > > > index 35c834b895ec..54bcf2984ca1 100644 > > > --- a/arch/s390/kernel/vdso/Makefile > > > +++ b/arch/s390/kernel/vdso/Makefile > > > @@ -29,6 +29,7 @@ KBUILD_CFLAGS_VDSO := $(filter-out -munaligned-symbols,$(KBUILD_CFLAGS_VDSO)) > > > KBUILD_CFLAGS_VDSO := $(filter-out -fno-asynchronous-unwind-tables,$(KBUILD_CFLAGS_VDSO)) > > > KBUILD_CFLAGS_VDSO += -fPIC -fno-common -fno-builtin -fasynchronous-unwind-tables > > > KBUILD_CFLAGS_VDSO += -fno-stack-protector $(DISABLE_KSTACK_ERASE) > > > +KBUILD_CFLAGS_VDSO += $(CONFIG_CC_OPT_INLINE_MEMSET) > > > ldflags-y := -shared -soname=linux-vdso.so.1 \ > > > --hash-style=both --build-id=sha1 \ > > > $(call ld-option, --eh-frame-hdr) -T > > > diff --git a/arch/x86/entry/vdso/vdso64/Makefile b/arch/x86/entry/vdso/vdso64/Makefile > > > index 7c0790065b5e..c2353a065279 100644 > > > --- a/arch/x86/entry/vdso/vdso64/Makefile > > > +++ b/arch/x86/entry/vdso/vdso64/Makefile > > > @@ -14,7 +14,7 @@ vobjs-$(CONFIG_X86_SGX) += vsgx.o > > > vobjs-$(CONFIG_FUTEX_ROBUST_UNLOCK) += vfutex.o > > > > > > # Compilation flags > > > -flags-y := -DBUILD_VDSO64 -m64 -mcmodel=small > > > +flags-y := -DBUILD_VDSO64 -m64 -mcmodel=small $(CONFIG_CC_OPT_INLINE_MEMSET) > > > > > > # The location of this include matters! > > > include $(src)/../common/Makefile.include > > > diff --git a/init/Kconfig b/init/Kconfig > > > index 8583d9f06c52..ff3f8475dd2f 100644 > > > --- a/init/Kconfig > > > +++ b/init/Kconfig > > > @@ -173,6 +173,13 @@ config CC_HAS_ALLOC_TOKEN > > > config CC_HAS_MULTIDIMENSIONAL_NONSTRING > > > def_bool $(success,echo 'char tag[][4] __attribute__((__nonstring__)) = { };' | $(CC) $(CLANG_FLAGS) -x c - -c -o /dev/null -Werror) > > > > > > +config CC_HAS_OPT_INLINE_MEMSET > > > + def_bool $(cc-option,-finline-stringops=memset) > > > + > > > +config CC_OPT_INLINE_MEMSET > > > + string > > > + default "-finline-stringops=memset" if CC_HAS_OPT_INLINE_MEMSET > > > + > > > config LD_CAN_USE_KEEP_IN_OVERLAY > > > # ld.lld prior to 21.0.0 did not support KEEP within an overlay description > > > # https://github.com/llvm/llvm-project/pull/130661 > > > diff --git a/lib/vdso/getrandom.c b/lib/vdso/getrandom.c > > > index 2851afa9154f..f5cad5641985 100644 > > > --- a/lib/vdso/getrandom.c > > > +++ b/lib/vdso/getrandom.c > > > @@ -29,6 +29,22 @@ > > > } \ > > > } while (0) > > > > > > +#if __has_builtin(__builtin_memset_inline) > > > +#define memset_inline(dst, value, size) __builtin_memset_inline(dst, value, size) > > > +#elif IS_ENABLED(CONFIG_CC_HAS_OPT_INLINE_MEMSET) > > > +#define memset_inline(dst, value, size) __builtin_memset(dst, value, size) > > > +#else > > > +static inline void *memset_inline(void *dst, int value, size_t size) > > > +{ > > > + char *d = dst; > > > + > > > + while (size--) > > > + *d++ = value; > > > + > > > + return d; > > > +} > > > +#endif > > > > Does this work? > > https://godbolt.org/z/Tx6EaGMfb > > Hmmm...possibly. > https://godbolt.org/z/ec9rzd9Yf > I don't get it... Just keep it under 2 pages, it will be fine: https://godbolt.org/z/qqoMqfxev > > > > > (Sorry, I _should_ have replied to Jason on V1. I'm not ignoring him, > > just way behind on my code reviews. Sorry!) > > > > > + > > > static void memcpy_and_zero_src(void *dst, void *src, size_t len) > > > { > > > if (IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)) { > > > @@ -83,8 +99,7 @@ __cvdso_getrandom_data(const struct vdso_rng_data *rng_info, void *buffer, size_ > > > params->size_of_opaque_state = sizeof(*state); > > > params->mmap_prot = PROT_READ | PROT_WRITE; > > > params->mmap_flags = MAP_DROPPABLE | MAP_ANONYMOUS; > > > - for (size_t i = 0; i < ARRAY_SIZE(params->reserved); ++i) > > > - params->reserved[i] = 0; > > > + memset_inline(params->reserved, 0, sizeof(params->reserved)); > > > return 0; > > > } > > > > > > > > > --- > > > base-commit: cee9395acd8043be0644b25c34bfa86623f2b935 > > > change-id: 20260916-vdso-getrandom-avoid-memset-llvm-24-74d45fa6031e > > > > > > Best regards, > > > -- > > > Cheers, > > > Nathan > > > > > > > > > -- > > Thanks, > > ~Nick Desaulniers > > > > -- > Thanks, > ~Nick Desaulniers -- Thanks, ~Nick Desaulniers ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-09-25 22:00 ` Nick Desaulniers @ 2026-09-25 22:19 ` Nathan Chancellor 2026-09-26 6:34 ` Christophe Leroy (CS GROUP) 2026-09-26 10:02 ` Jason A. Donenfeld 2 siblings, 0 replies; 37+ messages in thread From: Nathan Chancellor @ 2026-09-25 22:19 UTC (permalink / raw) To: Nick Desaulniers Cc: Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Jason A. Donenfeld, Vincenzo Frascino, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Christophe Leroy (CS GROUP), Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm On Fri, Sep 25, 2026 at 03:00:46PM -0700, Nick Desaulniers wrote: > > > > +static inline void *memset_inline(void *dst, int value, size_t size) > > > > +{ > > > > + char *d = dst; > > > > + > > > > + while (size--) > > > > + *d++ = value; > > > > + > > > > + return d; > > > > +} > > > > > > Does this work? > > > https://godbolt.org/z/Tx6EaGMfb > > > > Hmmm...possibly. > > https://godbolt.org/z/ec9rzd9Yf > > I don't get it... > > Just keep it under 2 pages, it will be fine: > https://godbolt.org/z/qqoMqfxev Yeah, it might be worth a comment that this is only safe for small values of size so it should not be blindly copied elsewhere (although I guess if it is, the outlined version exists in the majority of other places). -- Cheers, Nathan ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-09-25 22:00 ` Nick Desaulniers 2026-09-25 22:19 ` Nathan Chancellor @ 2026-09-26 6:34 ` Christophe Leroy (CS GROUP) 2026-09-26 10:02 ` Jason A. Donenfeld 2 siblings, 0 replies; 37+ messages in thread From: Christophe Leroy (CS GROUP) @ 2026-09-26 6:34 UTC (permalink / raw) To: Nick Desaulniers, Nathan Chancellor Cc: Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Jason A. Donenfeld, Vincenzo Frascino, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm Le 26/09/2026 à 00:00, Nick Desaulniers a écrit : > On Fri, Sep 25, 2026 at 2:56 PM Nick Desaulniers > <ndesaulniers@google.com> wrote: >> >> On Fri, Sep 25, 2026 at 2:53 PM Nick Desaulniers >> <ndesaulniers@google.com> wrote: >>> >>> On Fri, Sep 25, 2026 at 2:46 PM Nathan Chancellor <nathan@kernel.org> wrote: >>>> >>>> After a recent change in LLVM [1], builds with the random vDSO >>>> implementation, such as PowerPC and RISC-V, fail when checking the vDSO: >>>> >>>> arch/powerpc/kernel/vdso/vdso32.so.dbg: dynamic relocations are not supported >>>> arch/riscv/kernel/vdso/vdso.so.dbg: dynamic relocations are not supported >>>> >>>> memset() is now generated when zeroing params->reserved for some builds >>>> because LLVM has an optimization (now run in more instances) that can >>>> recognize at compile time when it is assigning a static value to a >>>> contiguous area of memory and turn that into a call to memset(). Both >>>> clang and GCC assume memset() is always available [2]. >>>> >>>> clang provides a builtin, __builtin_memset_inline [3][4], that can be >>>> used to ensure an external function call is not generated when zeroing >>>> this memory. Use it when it is available. >>>> >>>> While GCC has no issues with the current code, it has generated memset() >>>> before, as seen in commit b7bad082e113 ("random: vDSO: avoid call to out >>>> of line memset()"). GCC 14 provides '-finline-stringops=memset' [5][6] >>>> with a similar guarantee to the clang builtin, so use it and >>>> __builtin_memset() when available. >>>> >>>> If no option is available, provide a simple memset_inline() like the one >>>> from lib/string.c to avoid adding an ugly ifdef. >>>> >>>> Link: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fllvm%2Fllvm-project%2Fcommit%2F90cebef1411617fc3eedd359bdf00cb44b1c2439&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C8130be3fe7304659b8e308df1b507f25%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639259704683663121%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=TzFmsIf6K0ZNffmwZjFRWcrFHJ4akhMw%2FxcWeHR4hFY%3D&reserved=0 [1] >>>> Link: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgcc.gnu.org%2Fonlinedocs%2Fgcc-16.2.0%2Fgcc%2FStandards.html%23index-ffreestanding&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C8130be3fe7304659b8e308df1b507f25%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639259704683681786%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=A6PdZfaF0MvKQ0TEuJEnFWmXpMKD5CPz6Ko2fWh9ZGY%3D&reserved=0 [2] >>>> Link: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fllvm%2Fllvm-project%2Fcommit%2F38637ee477541370a90b37f149069d8e5c0c2efd&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C8130be3fe7304659b8e308df1b507f25%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639259704683693796%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=ordMFwd99jKGsM6%2F5jqb6T%2FCzJZ%2BccJTNL6Zyyz38S4%3D&reserved=0 [3] >>>> Link: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fclang.llvm.org%2Fdocs%2FLanguageExtensions.html%23guaranteed-inlined-memset&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C8130be3fe7304659b8e308df1b507f25%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639259704683704121%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=mqgeAxJp0cTsBD1qngk%2BliTUC1kID648Z81H6hiKYDI%3D&reserved=0 [4] >>>> Link: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgcc.gnu.org%2Fgit%2F%3Fp%3Dgcc.git%3Ba%3Dcommit%3Bh%3D1ff6d9f7428b0668cd8ab0b3e3ab94f1d733124d&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C8130be3fe7304659b8e308df1b507f25%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639259704683713563%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=hNiJSMBbn6k7Pq4uBYQ5Bi6fO8ttW8KXVK6hPLEfJCM%3D&reserved=0 [5] >>>> Link: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgcc.gnu.org%2Fonlinedocs%2Fgcc%2FOptimize-Options.html%23index-finline-stringops&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C8130be3fe7304659b8e308df1b507f25%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639259704683722844%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=BwB1lUSynGcGGLwkspnlVbkBAkdeRo4ItXk19ffMU44%3D&reserved=0 [6] >>>> Suggested-by: "Jason A. Donenfeld" <Jason@zx2c4.com> >>>> Suggested-by: Nick Desaulniers <ndesaulniers@google.com> >>>> Signed-off-by: Nathan Chancellor <nathan@kernel.org> >>>> --- >>>> Changes in v2: >>>> - Switch approach entirely (Jason, Nick) >>>> - clang: use __builtin_memset_inline() to avoid external call >>>> - GCC 14+: use __builtin_memset + -finline-stringops=memset (hence the >>>> massive CC list increase) >>>> - GCC < 14: no issues currently but avoid ifdef with simple memset >>>> implementation >>>> - Link to v1: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatch.msgid.link%2F20260916-vdso-getrandom-avoid-memset-llvm-24-v1-1-80a92f2e225a%40kernel.org&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C8130be3fe7304659b8e308df1b507f25%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639259704683731836%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=Z1w8wFKZCVjlUIwkIjffeIBIPkDhRRln3l7xot3daRc%3D&reserved=0 >>>> --- >>>> arch/arm64/kernel/vdso/Makefile | 2 +- >>>> arch/loongarch/vdso/Makefile | 1 + >>>> arch/powerpc/kernel/vdso/Makefile | 1 + >>>> arch/riscv/kernel/vdso/Makefile | 1 + >>>> arch/s390/kernel/vdso/Makefile | 1 + >>>> arch/x86/entry/vdso/vdso64/Makefile | 2 +- >>>> init/Kconfig | 7 +++++++ >>>> lib/vdso/getrandom.c | 19 +++++++++++++++++-- >>>> 8 files changed, 30 insertions(+), 4 deletions(-) >>>> >>>> diff --git a/arch/arm64/kernel/vdso/Makefile b/arch/arm64/kernel/vdso/Makefile >>>> index 7dec05dd33b7..f6619e1cb2ce 100644 >>>> --- a/arch/arm64/kernel/vdso/Makefile >>>> +++ b/arch/arm64/kernel/vdso/Makefile >>>> @@ -41,7 +41,7 @@ CC_FLAGS_REMOVE_VDSO := $(CC_FLAGS_FTRACE) -Os $(CC_FLAGS_SCS) \ >>>> $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) \ >>>> -Wmissing-prototypes -Wmissing-declarations >>>> >>>> -CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tables >>>> +CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tables $(CONFIG_CC_OPT_INLINE_MEMSET) >>>> >>>> CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_REMOVE_VDSO) >>>> CFLAGS_REMOVE_vgetrandom.o = $(CC_FLAGS_REMOVE_VDSO) >>>> diff --git a/arch/loongarch/vdso/Makefile b/arch/loongarch/vdso/Makefile >>>> index 9c9181bb4071..0b84892d084b 100644 >>>> --- a/arch/loongarch/vdso/Makefile >>>> +++ b/arch/loongarch/vdso/Makefile >>>> @@ -16,6 +16,7 @@ ccflags-vdso := \ >>>> $(filter -m64,$(KBUILD_CFLAGS)) \ >>>> $(filter -march=%,$(KBUILD_CFLAGS)) \ >>>> $(filter -m%-float,$(KBUILD_CFLAGS)) \ >>>> + $(CONFIG_CC_OPT_INLINE_MEMSET) \ >>>> $(CLANG_FLAGS) \ >>>> -D__VDSO__ >>>> >>>> diff --git a/arch/powerpc/kernel/vdso/Makefile b/arch/powerpc/kernel/vdso/Makefile >>>> index 368759f81708..0d1a49529885 100644 >>>> --- a/arch/powerpc/kernel/vdso/Makefile >>>> +++ b/arch/powerpc/kernel/vdso/Makefile >>>> @@ -43,6 +43,7 @@ ccflags-y := -fno-common -fno-builtin -DBUILD_VDSO >>>> ccflags-y += $(DISABLE_LATENT_ENTROPY_PLUGIN) >>>> ccflags-y += $(call cc-option, -fno-stack-protector) >>>> ccflags-y += -DDISABLE_BRANCH_PROFILING >>>> +ccflags-y += $(CONFIG_CC_OPT_INLINE_MEMSET) >>>> ccflags-y += -ffreestanding -fasynchronous-unwind-tables >>>> ccflags-remove-y := $(CC_FLAGS_FTRACE) >>>> ldflags-y := -Wl,--hash-style=both -nostdlib -shared -z noexecstack $(CLANG_FLAGS) >>>> diff --git a/arch/riscv/kernel/vdso/Makefile b/arch/riscv/kernel/vdso/Makefile >>>> index 8dbf2532a573..c023046a3fd7 100644 >>>> --- a/arch/riscv/kernel/vdso/Makefile >>>> +++ b/arch/riscv/kernel/vdso/Makefile >>>> @@ -36,6 +36,7 @@ endif >>>> ccflags-y := -fno-stack-protector >>>> ccflags-y += -DDISABLE_BRANCH_PROFILING >>>> ccflags-y += -fno-builtin >>>> +ccflags-y += $(CONFIG_CC_OPT_INLINE_MEMSET) >>>> ccflags-y += $(KBUILD_BASE_ISA)$(CFI_MARCH) >>>> ccflags-y += $(CFI_FULL) >>>> asflags-y += $(KBUILD_BASE_ISA)$(CFI_MARCH) >>>> diff --git a/arch/s390/kernel/vdso/Makefile b/arch/s390/kernel/vdso/Makefile >>>> index 35c834b895ec..54bcf2984ca1 100644 >>>> --- a/arch/s390/kernel/vdso/Makefile >>>> +++ b/arch/s390/kernel/vdso/Makefile >>>> @@ -29,6 +29,7 @@ KBUILD_CFLAGS_VDSO := $(filter-out -munaligned-symbols,$(KBUILD_CFLAGS_VDSO)) >>>> KBUILD_CFLAGS_VDSO := $(filter-out -fno-asynchronous-unwind-tables,$(KBUILD_CFLAGS_VDSO)) >>>> KBUILD_CFLAGS_VDSO += -fPIC -fno-common -fno-builtin -fasynchronous-unwind-tables >>>> KBUILD_CFLAGS_VDSO += -fno-stack-protector $(DISABLE_KSTACK_ERASE) >>>> +KBUILD_CFLAGS_VDSO += $(CONFIG_CC_OPT_INLINE_MEMSET) >>>> ldflags-y := -shared -soname=linux-vdso.so.1 \ >>>> --hash-style=both --build-id=sha1 \ >>>> $(call ld-option, --eh-frame-hdr) -T >>>> diff --git a/arch/x86/entry/vdso/vdso64/Makefile b/arch/x86/entry/vdso/vdso64/Makefile >>>> index 7c0790065b5e..c2353a065279 100644 >>>> --- a/arch/x86/entry/vdso/vdso64/Makefile >>>> +++ b/arch/x86/entry/vdso/vdso64/Makefile >>>> @@ -14,7 +14,7 @@ vobjs-$(CONFIG_X86_SGX) += vsgx.o >>>> vobjs-$(CONFIG_FUTEX_ROBUST_UNLOCK) += vfutex.o >>>> >>>> # Compilation flags >>>> -flags-y := -DBUILD_VDSO64 -m64 -mcmodel=small >>>> +flags-y := -DBUILD_VDSO64 -m64 -mcmodel=small $(CONFIG_CC_OPT_INLINE_MEMSET) >>>> >>>> # The location of this include matters! >>>> include $(src)/../common/Makefile.include >>>> diff --git a/init/Kconfig b/init/Kconfig >>>> index 8583d9f06c52..ff3f8475dd2f 100644 >>>> --- a/init/Kconfig >>>> +++ b/init/Kconfig >>>> @@ -173,6 +173,13 @@ config CC_HAS_ALLOC_TOKEN >>>> config CC_HAS_MULTIDIMENSIONAL_NONSTRING >>>> def_bool $(success,echo 'char tag[][4] __attribute__((__nonstring__)) = { };' | $(CC) $(CLANG_FLAGS) -x c - -c -o /dev/null -Werror) >>>> >>>> +config CC_HAS_OPT_INLINE_MEMSET >>>> + def_bool $(cc-option,-finline-stringops=memset) >>>> + >>>> +config CC_OPT_INLINE_MEMSET >>>> + string >>>> + default "-finline-stringops=memset" if CC_HAS_OPT_INLINE_MEMSET >>>> + >>>> config LD_CAN_USE_KEEP_IN_OVERLAY >>>> # ld.lld prior to 21.0.0 did not support KEEP within an overlay description >>>> # https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fllvm%2Fllvm-project%2Fpull%2F130661&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C8130be3fe7304659b8e308df1b507f25%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639259704683740883%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=JlYxG81FQsC5sm3aLe4M6uUIaU5QNmdbupcy3LuGPGQ%3D&reserved=0 >>>> diff --git a/lib/vdso/getrandom.c b/lib/vdso/getrandom.c >>>> index 2851afa9154f..f5cad5641985 100644 >>>> --- a/lib/vdso/getrandom.c >>>> +++ b/lib/vdso/getrandom.c >>>> @@ -29,6 +29,22 @@ >>>> } \ >>>> } while (0) >>>> >>>> +#if __has_builtin(__builtin_memset_inline) >>>> +#define memset_inline(dst, value, size) __builtin_memset_inline(dst, value, size) >>>> +#elif IS_ENABLED(CONFIG_CC_HAS_OPT_INLINE_MEMSET) >>>> +#define memset_inline(dst, value, size) __builtin_memset(dst, value, size) >>>> +#else >>>> +static inline void *memset_inline(void *dst, int value, size_t size) >>>> +{ >>>> + char *d = dst; >>>> + >>>> + while (size--) >>>> + *d++ = value; >>>> + >>>> + return d; >>>> +} >>>> +#endif >>> >>> Does this work? >>> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgodbolt.org%2Fz%2FTx6EaGMfb&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C8130be3fe7304659b8e308df1b507f25%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639259704683749874%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=3MCx7IwcEz2ieYYZzQ2dLdrxFTjJiUqH0c1qiOXeLlo%3D&reserved=0 >> >> Hmmm...possibly. >> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgodbolt.org%2Fz%2Fec9rzd9Yf&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C8130be3fe7304659b8e308df1b507f25%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639259704683758681%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=5T4oq%2B4AfVJBqvBNA19kzNq19kRYM9u8YzYcP%2B8P7Mw%3D&reserved=0 >> I don't get it... > > Just keep it under 2 pages, it will be fine: > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgodbolt.org%2Fz%2FqqoMqfxev&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C8130be3fe7304659b8e308df1b507f25%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639259704683768107%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=FrwGHnEXsSp8scH8GtL%2BlqjymHfVokSrtaOqhp2iZPg%3D&reserved=0 > Doesn't work on powerpc (gcc 13.4): foo: li 5,8192 li 4,0 b memset foo2: li 5,8193 li 4,0 b memset But that's the reason why vdso Makefile has option -fno-builtin, that option gives instead: foo: li 10,2048 li 9,0 addi 3,3,-1 mtctr 10 .L2: stb 9,1(3) stb 9,2(3) stb 9,3(3) stbu 9,4(3) bdnz .L2 blr foo2: li 9,0 li 10,2048 stb 9,0(3) mtctr 10 .L10: stb 9,1(3) stb 9,2(3) stb 9,3(3) stbu 9,4(3) bdnz .L10 blr Christophe ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-09-25 22:00 ` Nick Desaulniers 2026-09-25 22:19 ` Nathan Chancellor 2026-09-26 6:34 ` Christophe Leroy (CS GROUP) @ 2026-09-26 10:02 ` Jason A. Donenfeld 2026-09-26 10:55 ` Christophe Leroy (CS GROUP) 2 siblings, 1 reply; 37+ messages in thread From: Jason A. Donenfeld @ 2026-09-26 10:02 UTC (permalink / raw) To: Nick Desaulniers Cc: Nathan Chancellor, Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Vincenzo Frascino, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Christophe Leroy (CS GROUP), Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm On Fri, Sep 25, 2026 at 03:00:46PM -0700, Nick Desaulniers wrote: > On Fri, Sep 25, 2026 at 2:56 PM Nick Desaulniers > <ndesaulniers@google.com> wrote: > > > > On Fri, Sep 25, 2026 at 2:53 PM Nick Desaulniers > > <ndesaulniers@google.com> wrote: > > > > > > On Fri, Sep 25, 2026 at 2:46 PM Nathan Chancellor <nathan@kernel.org> wrote: > > > > > > > > After a recent change in LLVM [1], builds with the random vDSO > > > > implementation, such as PowerPC and RISC-V, fail when checking the vDSO: > > > > > > > > arch/powerpc/kernel/vdso/vdso32.so.dbg: dynamic relocations are not supported > > > > arch/riscv/kernel/vdso/vdso.so.dbg: dynamic relocations are not supported > > > > > > > > memset() is now generated when zeroing params->reserved for some builds > > > > because LLVM has an optimization (now run in more instances) that can > > > > recognize at compile time when it is assigning a static value to a > > > > contiguous area of memory and turn that into a call to memset(). Both > > > > clang and GCC assume memset() is always available [2]. > > > > > > > > clang provides a builtin, __builtin_memset_inline [3][4], that can be > > > > used to ensure an external function call is not generated when zeroing > > > > this memory. Use it when it is available. > > > > > > > > While GCC has no issues with the current code, it has generated memset() > > > > before, as seen in commit b7bad082e113 ("random: vDSO: avoid call to out > > > > of line memset()"). GCC 14 provides '-finline-stringops=memset' [5][6] > > > > with a similar guarantee to the clang builtin, so use it and > > > > __builtin_memset() when available. > > > > > > > > If no option is available, provide a simple memset_inline() like the one > > > > from lib/string.c to avoid adding an ugly ifdef. > > > > > > > > Link: https://github.com/llvm/llvm-project/commit/90cebef1411617fc3eedd359bdf00cb44b1c2439 [1] > > > > Link: https://gcc.gnu.org/onlinedocs/gcc-16.2.0/gcc/Standards.html#index-ffreestanding [2] > > > > Link: https://github.com/llvm/llvm-project/commit/38637ee477541370a90b37f149069d8e5c0c2efd [3] > > > > Link: https://clang.llvm.org/docs/LanguageExtensions.html#guaranteed-inlined-memset [4] > > > > Link: https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=1ff6d9f7428b0668cd8ab0b3e3ab94f1d733124d [5] > > > > Link: https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-finline-stringops [6] > > > > Suggested-by: "Jason A. Donenfeld" <Jason@zx2c4.com> > > > > Suggested-by: Nick Desaulniers <ndesaulniers@google.com> > > > > Signed-off-by: Nathan Chancellor <nathan@kernel.org> > > > > --- > > > > Changes in v2: > > > > - Switch approach entirely (Jason, Nick) > > > > - clang: use __builtin_memset_inline() to avoid external call > > > > - GCC 14+: use __builtin_memset + -finline-stringops=memset (hence the > > > > massive CC list increase) > > > > - GCC < 14: no issues currently but avoid ifdef with simple memset > > > > implementation > > > > - Link to v1: https://patch.msgid.link/20260916-vdso-getrandom-avoid-memset-llvm-24-v1-1-80a92f2e225a@kernel.org > > > > --- > > > > arch/arm64/kernel/vdso/Makefile | 2 +- > > > > arch/loongarch/vdso/Makefile | 1 + > > > > arch/powerpc/kernel/vdso/Makefile | 1 + > > > > arch/riscv/kernel/vdso/Makefile | 1 + > > > > arch/s390/kernel/vdso/Makefile | 1 + > > > > arch/x86/entry/vdso/vdso64/Makefile | 2 +- > > > > init/Kconfig | 7 +++++++ > > > > lib/vdso/getrandom.c | 19 +++++++++++++++++-- > > > > 8 files changed, 30 insertions(+), 4 deletions(-) > > > > > > > > diff --git a/arch/arm64/kernel/vdso/Makefile b/arch/arm64/kernel/vdso/Makefile > > > > index 7dec05dd33b7..f6619e1cb2ce 100644 > > > > --- a/arch/arm64/kernel/vdso/Makefile > > > > +++ b/arch/arm64/kernel/vdso/Makefile > > > > @@ -41,7 +41,7 @@ CC_FLAGS_REMOVE_VDSO := $(CC_FLAGS_FTRACE) -Os $(CC_FLAGS_SCS) \ > > > > $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) \ > > > > -Wmissing-prototypes -Wmissing-declarations > > > > > > > > -CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tables > > > > +CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tables $(CONFIG_CC_OPT_INLINE_MEMSET) > > > > > > > > CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_REMOVE_VDSO) > > > > CFLAGS_REMOVE_vgetrandom.o = $(CC_FLAGS_REMOVE_VDSO) > > > > diff --git a/arch/loongarch/vdso/Makefile b/arch/loongarch/vdso/Makefile > > > > index 9c9181bb4071..0b84892d084b 100644 > > > > --- a/arch/loongarch/vdso/Makefile > > > > +++ b/arch/loongarch/vdso/Makefile > > > > @@ -16,6 +16,7 @@ ccflags-vdso := \ > > > > $(filter -m64,$(KBUILD_CFLAGS)) \ > > > > $(filter -march=%,$(KBUILD_CFLAGS)) \ > > > > $(filter -m%-float,$(KBUILD_CFLAGS)) \ > > > > + $(CONFIG_CC_OPT_INLINE_MEMSET) \ > > > > $(CLANG_FLAGS) \ > > > > -D__VDSO__ > > > > > > > > diff --git a/arch/powerpc/kernel/vdso/Makefile b/arch/powerpc/kernel/vdso/Makefile > > > > index 368759f81708..0d1a49529885 100644 > > > > --- a/arch/powerpc/kernel/vdso/Makefile > > > > +++ b/arch/powerpc/kernel/vdso/Makefile > > > > @@ -43,6 +43,7 @@ ccflags-y := -fno-common -fno-builtin -DBUILD_VDSO > > > > ccflags-y += $(DISABLE_LATENT_ENTROPY_PLUGIN) > > > > ccflags-y += $(call cc-option, -fno-stack-protector) > > > > ccflags-y += -DDISABLE_BRANCH_PROFILING > > > > +ccflags-y += $(CONFIG_CC_OPT_INLINE_MEMSET) > > > > ccflags-y += -ffreestanding -fasynchronous-unwind-tables > > > > ccflags-remove-y := $(CC_FLAGS_FTRACE) > > > > ldflags-y := -Wl,--hash-style=both -nostdlib -shared -z noexecstack $(CLANG_FLAGS) > > > > diff --git a/arch/riscv/kernel/vdso/Makefile b/arch/riscv/kernel/vdso/Makefile > > > > index 8dbf2532a573..c023046a3fd7 100644 > > > > --- a/arch/riscv/kernel/vdso/Makefile > > > > +++ b/arch/riscv/kernel/vdso/Makefile > > > > @@ -36,6 +36,7 @@ endif > > > > ccflags-y := -fno-stack-protector > > > > ccflags-y += -DDISABLE_BRANCH_PROFILING > > > > ccflags-y += -fno-builtin > > > > +ccflags-y += $(CONFIG_CC_OPT_INLINE_MEMSET) > > > > ccflags-y += $(KBUILD_BASE_ISA)$(CFI_MARCH) > > > > ccflags-y += $(CFI_FULL) > > > > asflags-y += $(KBUILD_BASE_ISA)$(CFI_MARCH) > > > > diff --git a/arch/s390/kernel/vdso/Makefile b/arch/s390/kernel/vdso/Makefile > > > > index 35c834b895ec..54bcf2984ca1 100644 > > > > --- a/arch/s390/kernel/vdso/Makefile > > > > +++ b/arch/s390/kernel/vdso/Makefile > > > > @@ -29,6 +29,7 @@ KBUILD_CFLAGS_VDSO := $(filter-out -munaligned-symbols,$(KBUILD_CFLAGS_VDSO)) > > > > KBUILD_CFLAGS_VDSO := $(filter-out -fno-asynchronous-unwind-tables,$(KBUILD_CFLAGS_VDSO)) > > > > KBUILD_CFLAGS_VDSO += -fPIC -fno-common -fno-builtin -fasynchronous-unwind-tables > > > > KBUILD_CFLAGS_VDSO += -fno-stack-protector $(DISABLE_KSTACK_ERASE) > > > > +KBUILD_CFLAGS_VDSO += $(CONFIG_CC_OPT_INLINE_MEMSET) > > > > ldflags-y := -shared -soname=linux-vdso.so.1 \ > > > > --hash-style=both --build-id=sha1 \ > > > > $(call ld-option, --eh-frame-hdr) -T > > > > diff --git a/arch/x86/entry/vdso/vdso64/Makefile b/arch/x86/entry/vdso/vdso64/Makefile > > > > index 7c0790065b5e..c2353a065279 100644 > > > > --- a/arch/x86/entry/vdso/vdso64/Makefile > > > > +++ b/arch/x86/entry/vdso/vdso64/Makefile > > > > @@ -14,7 +14,7 @@ vobjs-$(CONFIG_X86_SGX) += vsgx.o > > > > vobjs-$(CONFIG_FUTEX_ROBUST_UNLOCK) += vfutex.o > > > > > > > > # Compilation flags > > > > -flags-y := -DBUILD_VDSO64 -m64 -mcmodel=small > > > > +flags-y := -DBUILD_VDSO64 -m64 -mcmodel=small $(CONFIG_CC_OPT_INLINE_MEMSET) > > > > > > > > # The location of this include matters! > > > > include $(src)/../common/Makefile.include > > > > diff --git a/init/Kconfig b/init/Kconfig > > > > index 8583d9f06c52..ff3f8475dd2f 100644 > > > > --- a/init/Kconfig > > > > +++ b/init/Kconfig > > > > @@ -173,6 +173,13 @@ config CC_HAS_ALLOC_TOKEN > > > > config CC_HAS_MULTIDIMENSIONAL_NONSTRING > > > > def_bool $(success,echo 'char tag[][4] __attribute__((__nonstring__)) = { };' | $(CC) $(CLANG_FLAGS) -x c - -c -o /dev/null -Werror) > > > > > > > > +config CC_HAS_OPT_INLINE_MEMSET > > > > + def_bool $(cc-option,-finline-stringops=memset) > > > > + > > > > +config CC_OPT_INLINE_MEMSET > > > > + string > > > > + default "-finline-stringops=memset" if CC_HAS_OPT_INLINE_MEMSET > > > > + > > > > config LD_CAN_USE_KEEP_IN_OVERLAY > > > > # ld.lld prior to 21.0.0 did not support KEEP within an overlay description > > > > # https://github.com/llvm/llvm-project/pull/130661 > > > > diff --git a/lib/vdso/getrandom.c b/lib/vdso/getrandom.c > > > > index 2851afa9154f..f5cad5641985 100644 > > > > --- a/lib/vdso/getrandom.c > > > > +++ b/lib/vdso/getrandom.c > > > > @@ -29,6 +29,22 @@ > > > > } \ > > > > } while (0) > > > > > > > > +#if __has_builtin(__builtin_memset_inline) > > > > +#define memset_inline(dst, value, size) __builtin_memset_inline(dst, value, size) > > > > +#elif IS_ENABLED(CONFIG_CC_HAS_OPT_INLINE_MEMSET) > > > > +#define memset_inline(dst, value, size) __builtin_memset(dst, value, size) > > > > +#else > > > > +static inline void *memset_inline(void *dst, int value, size_t size) > > > > +{ > > > > + char *d = dst; > > > > + > > > > + while (size--) > > > > + *d++ = value; > > > > + > > > > + return d; > > > > +} > > > > +#endif > > > > > > Does this work? > > > https://godbolt.org/z/Tx6EaGMfb > > > > Hmmm...possibly. > > https://godbolt.org/z/ec9rzd9Yf > > I don't get it... > > Just keep it under 2 pages, it will be fine: > https://godbolt.org/z/qqoMqfxev https://godbolt.org/z/9W9f5a7Wx Apparently not on RISCV, which is what prompted this patch in the first place. So I suspect Nathan's v2 here is the way to go. Jason ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-09-26 10:02 ` Jason A. Donenfeld @ 2026-09-26 10:55 ` Christophe Leroy (CS GROUP) 2026-09-26 12:29 ` Jason A. Donenfeld 2026-09-26 12:39 ` Nathan Chancellor 0 siblings, 2 replies; 37+ messages in thread From: Christophe Leroy (CS GROUP) @ 2026-09-26 10:55 UTC (permalink / raw) To: Jason A. Donenfeld, Nick Desaulniers Cc: Nathan Chancellor, Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Vincenzo Frascino, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm Hi Jason, Le 26/09/2026 à 12:02, Jason A. Donenfeld a écrit : > On Fri, Sep 25, 2026 at 03:00:46PM -0700, Nick Desaulniers wrote: >> On Fri, Sep 25, 2026 at 2:56 PM Nick Desaulniers >> <ndesaulniers@google.com> wrote: >>> >>> On Fri, Sep 25, 2026 at 2:53 PM Nick Desaulniers >>> <ndesaulniers@google.com> wrote: >>>> >>>> On Fri, Sep 25, 2026 at 2:46 PM Nathan Chancellor <nathan@kernel.org> wrote: >>>>> >>>>> After a recent change in LLVM [1], builds with the random vDSO >>>>> implementation, such as PowerPC and RISC-V, fail when checking the vDSO: >>>>> >>>>> arch/powerpc/kernel/vdso/vdso32.so.dbg: dynamic relocations are not supported >>>>> arch/riscv/kernel/vdso/vdso.so.dbg: dynamic relocations are not supported >>>>> >>>>> memset() is now generated when zeroing params->reserved for some builds >>>>> because LLVM has an optimization (now run in more instances) that can >>>>> recognize at compile time when it is assigning a static value to a >>>>> contiguous area of memory and turn that into a call to memset(). Both >>>>> clang and GCC assume memset() is always available [2]. >>>>> >>>>> clang provides a builtin, __builtin_memset_inline [3][4], that can be >>>>> used to ensure an external function call is not generated when zeroing >>>>> this memory. Use it when it is available. >>>>> >>>>> While GCC has no issues with the current code, it has generated memset() >>>>> before, as seen in commit b7bad082e113 ("random: vDSO: avoid call to out >>>>> of line memset()"). GCC 14 provides '-finline-stringops=memset' [5][6] >>>>> with a similar guarantee to the clang builtin, so use it and >>>>> __builtin_memset() when available. >>>>> >>>>> If no option is available, provide a simple memset_inline() like the one >>>>> from lib/string.c to avoid adding an ugly ifdef. >>>>> >>>>> Link: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fllvm%2Fllvm-project%2Fcommit%2F90cebef1411617fc3eedd359bdf00cb44b1c2439&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4df96063ffd94e6204df08df1bb54e3d%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639260137659627802%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=ku4l8Ol5OJ2qi%2BcSblspxxUKOA6rNpiUO3ZvGSoAb1s%3D&reserved=0 [1] >>>>> Link: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgcc.gnu.org%2Fonlinedocs%2Fgcc-16.2.0%2Fgcc%2FStandards.html%23index-ffreestanding&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4df96063ffd94e6204df08df1bb54e3d%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639260137659651194%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=jQa1eTDLk3cPNTa3GEBwVEohHh67ukShaRHMZvA%2FHDg%3D&reserved=0 [2] >>>>> Link: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fllvm%2Fllvm-project%2Fcommit%2F38637ee477541370a90b37f149069d8e5c0c2efd&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4df96063ffd94e6204df08df1bb54e3d%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639260137659668579%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=zY7Kr9ZZNNZR%2FVsnwYRlubPRpbMaKe9QtMD2snd8ZvA%3D&reserved=0 [3] >>>>> Link: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fclang.llvm.org%2Fdocs%2FLanguageExtensions.html%23guaranteed-inlined-memset&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4df96063ffd94e6204df08df1bb54e3d%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639260137659678360%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=vUU2fhCVcUWsbQD3IsRaUzSO8KVSpxwSpgr9San4aq0%3D&reserved=0 [4] >>>>> Link: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgcc.gnu.org%2Fgit%2F%3Fp%3Dgcc.git%3Ba%3Dcommit%3Bh%3D1ff6d9f7428b0668cd8ab0b3e3ab94f1d733124d&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4df96063ffd94e6204df08df1bb54e3d%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639260137659687815%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=qHRqxAO252imwH1W93yHlp6jdcFGkFOr2Y2hXbG2MLU%3D&reserved=0 [5] >>>>> Link: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgcc.gnu.org%2Fonlinedocs%2Fgcc%2FOptimize-Options.html%23index-finline-stringops&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4df96063ffd94e6204df08df1bb54e3d%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639260137659698298%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=0ecc%2BXd6o3nozh3N71aq%2F98Xam%2Fdol7GUHmC637Iv7I%3D&reserved=0 [6] >>>>> Suggested-by: "Jason A. Donenfeld" <Jason@zx2c4.com> >>>>> Suggested-by: Nick Desaulniers <ndesaulniers@google.com> >>>>> Signed-off-by: Nathan Chancellor <nathan@kernel.org> >>>>> --- >>>>> Changes in v2: >>>>> - Switch approach entirely (Jason, Nick) >>>>> - clang: use __builtin_memset_inline() to avoid external call >>>>> - GCC 14+: use __builtin_memset + -finline-stringops=memset (hence the >>>>> massive CC list increase) >>>>> - GCC < 14: no issues currently but avoid ifdef with simple memset >>>>> implementation >>>>> - Link to v1: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatch.msgid.link%2F20260916-vdso-getrandom-avoid-memset-llvm-24-v1-1-80a92f2e225a%40kernel.org&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4df96063ffd94e6204df08df1bb54e3d%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639260137659712983%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=%2Ftq3tUHqDmbXesqB69w6umXAuaTsfzOIhk54Jy76cwo%3D&reserved=0 >>>>> --- >>>>> arch/arm64/kernel/vdso/Makefile | 2 +- >>>>> arch/loongarch/vdso/Makefile | 1 + >>>>> arch/powerpc/kernel/vdso/Makefile | 1 + >>>>> arch/riscv/kernel/vdso/Makefile | 1 + >>>>> arch/s390/kernel/vdso/Makefile | 1 + >>>>> arch/x86/entry/vdso/vdso64/Makefile | 2 +- >>>>> init/Kconfig | 7 +++++++ >>>>> lib/vdso/getrandom.c | 19 +++++++++++++++++-- >>>>> 8 files changed, 30 insertions(+), 4 deletions(-) >>>>> >>>>> diff --git a/arch/arm64/kernel/vdso/Makefile b/arch/arm64/kernel/vdso/Makefile >>>>> index 7dec05dd33b7..f6619e1cb2ce 100644 >>>>> --- a/arch/arm64/kernel/vdso/Makefile >>>>> +++ b/arch/arm64/kernel/vdso/Makefile >>>>> @@ -41,7 +41,7 @@ CC_FLAGS_REMOVE_VDSO := $(CC_FLAGS_FTRACE) -Os $(CC_FLAGS_SCS) \ >>>>> $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) \ >>>>> -Wmissing-prototypes -Wmissing-declarations >>>>> >>>>> -CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tables >>>>> +CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tables $(CONFIG_CC_OPT_INLINE_MEMSET) >>>>> >>>>> CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_REMOVE_VDSO) >>>>> CFLAGS_REMOVE_vgetrandom.o = $(CC_FLAGS_REMOVE_VDSO) >>>>> diff --git a/arch/loongarch/vdso/Makefile b/arch/loongarch/vdso/Makefile >>>>> index 9c9181bb4071..0b84892d084b 100644 >>>>> --- a/arch/loongarch/vdso/Makefile >>>>> +++ b/arch/loongarch/vdso/Makefile >>>>> @@ -16,6 +16,7 @@ ccflags-vdso := \ >>>>> $(filter -m64,$(KBUILD_CFLAGS)) \ >>>>> $(filter -march=%,$(KBUILD_CFLAGS)) \ >>>>> $(filter -m%-float,$(KBUILD_CFLAGS)) \ >>>>> + $(CONFIG_CC_OPT_INLINE_MEMSET) \ >>>>> $(CLANG_FLAGS) \ >>>>> -D__VDSO__ >>>>> >>>>> diff --git a/arch/powerpc/kernel/vdso/Makefile b/arch/powerpc/kernel/vdso/Makefile >>>>> index 368759f81708..0d1a49529885 100644 >>>>> --- a/arch/powerpc/kernel/vdso/Makefile >>>>> +++ b/arch/powerpc/kernel/vdso/Makefile >>>>> @@ -43,6 +43,7 @@ ccflags-y := -fno-common -fno-builtin -DBUILD_VDSO >>>>> ccflags-y += $(DISABLE_LATENT_ENTROPY_PLUGIN) >>>>> ccflags-y += $(call cc-option, -fno-stack-protector) >>>>> ccflags-y += -DDISABLE_BRANCH_PROFILING >>>>> +ccflags-y += $(CONFIG_CC_OPT_INLINE_MEMSET) >>>>> ccflags-y += -ffreestanding -fasynchronous-unwind-tables >>>>> ccflags-remove-y := $(CC_FLAGS_FTRACE) >>>>> ldflags-y := -Wl,--hash-style=both -nostdlib -shared -z noexecstack $(CLANG_FLAGS) >>>>> diff --git a/arch/riscv/kernel/vdso/Makefile b/arch/riscv/kernel/vdso/Makefile >>>>> index 8dbf2532a573..c023046a3fd7 100644 >>>>> --- a/arch/riscv/kernel/vdso/Makefile >>>>> +++ b/arch/riscv/kernel/vdso/Makefile >>>>> @@ -36,6 +36,7 @@ endif >>>>> ccflags-y := -fno-stack-protector >>>>> ccflags-y += -DDISABLE_BRANCH_PROFILING >>>>> ccflags-y += -fno-builtin >>>>> +ccflags-y += $(CONFIG_CC_OPT_INLINE_MEMSET) >>>>> ccflags-y += $(KBUILD_BASE_ISA)$(CFI_MARCH) >>>>> ccflags-y += $(CFI_FULL) >>>>> asflags-y += $(KBUILD_BASE_ISA)$(CFI_MARCH) >>>>> diff --git a/arch/s390/kernel/vdso/Makefile b/arch/s390/kernel/vdso/Makefile >>>>> index 35c834b895ec..54bcf2984ca1 100644 >>>>> --- a/arch/s390/kernel/vdso/Makefile >>>>> +++ b/arch/s390/kernel/vdso/Makefile >>>>> @@ -29,6 +29,7 @@ KBUILD_CFLAGS_VDSO := $(filter-out -munaligned-symbols,$(KBUILD_CFLAGS_VDSO)) >>>>> KBUILD_CFLAGS_VDSO := $(filter-out -fno-asynchronous-unwind-tables,$(KBUILD_CFLAGS_VDSO)) >>>>> KBUILD_CFLAGS_VDSO += -fPIC -fno-common -fno-builtin -fasynchronous-unwind-tables >>>>> KBUILD_CFLAGS_VDSO += -fno-stack-protector $(DISABLE_KSTACK_ERASE) >>>>> +KBUILD_CFLAGS_VDSO += $(CONFIG_CC_OPT_INLINE_MEMSET) >>>>> ldflags-y := -shared -soname=linux-vdso.so.1 \ >>>>> --hash-style=both --build-id=sha1 \ >>>>> $(call ld-option, --eh-frame-hdr) -T >>>>> diff --git a/arch/x86/entry/vdso/vdso64/Makefile b/arch/x86/entry/vdso/vdso64/Makefile >>>>> index 7c0790065b5e..c2353a065279 100644 >>>>> --- a/arch/x86/entry/vdso/vdso64/Makefile >>>>> +++ b/arch/x86/entry/vdso/vdso64/Makefile >>>>> @@ -14,7 +14,7 @@ vobjs-$(CONFIG_X86_SGX) += vsgx.o >>>>> vobjs-$(CONFIG_FUTEX_ROBUST_UNLOCK) += vfutex.o >>>>> >>>>> # Compilation flags >>>>> -flags-y := -DBUILD_VDSO64 -m64 -mcmodel=small >>>>> +flags-y := -DBUILD_VDSO64 -m64 -mcmodel=small $(CONFIG_CC_OPT_INLINE_MEMSET) >>>>> >>>>> # The location of this include matters! >>>>> include $(src)/../common/Makefile.include >>>>> diff --git a/init/Kconfig b/init/Kconfig >>>>> index 8583d9f06c52..ff3f8475dd2f 100644 >>>>> --- a/init/Kconfig >>>>> +++ b/init/Kconfig >>>>> @@ -173,6 +173,13 @@ config CC_HAS_ALLOC_TOKEN >>>>> config CC_HAS_MULTIDIMENSIONAL_NONSTRING >>>>> def_bool $(success,echo 'char tag[][4] __attribute__((__nonstring__)) = { };' | $(CC) $(CLANG_FLAGS) -x c - -c -o /dev/null -Werror) >>>>> >>>>> +config CC_HAS_OPT_INLINE_MEMSET >>>>> + def_bool $(cc-option,-finline-stringops=memset) >>>>> + >>>>> +config CC_OPT_INLINE_MEMSET >>>>> + string >>>>> + default "-finline-stringops=memset" if CC_HAS_OPT_INLINE_MEMSET >>>>> + >>>>> config LD_CAN_USE_KEEP_IN_OVERLAY >>>>> # ld.lld prior to 21.0.0 did not support KEEP within an overlay description >>>>> # https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fllvm%2Fllvm-project%2Fpull%2F130661&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4df96063ffd94e6204df08df1bb54e3d%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639260137659727352%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=03eAQvPTDs%2FN28bYiiZAVYcx2JFSkuOM7x2iwFU%2F%2FxA%3D&reserved=0 >>>>> diff --git a/lib/vdso/getrandom.c b/lib/vdso/getrandom.c >>>>> index 2851afa9154f..f5cad5641985 100644 >>>>> --- a/lib/vdso/getrandom.c >>>>> +++ b/lib/vdso/getrandom.c >>>>> @@ -29,6 +29,22 @@ >>>>> } \ >>>>> } while (0) >>>>> >>>>> +#if __has_builtin(__builtin_memset_inline) >>>>> +#define memset_inline(dst, value, size) __builtin_memset_inline(dst, value, size) >>>>> +#elif IS_ENABLED(CONFIG_CC_HAS_OPT_INLINE_MEMSET) >>>>> +#define memset_inline(dst, value, size) __builtin_memset(dst, value, size) >>>>> +#else >>>>> +static inline void *memset_inline(void *dst, int value, size_t size) >>>>> +{ >>>>> + char *d = dst; >>>>> + >>>>> + while (size--) >>>>> + *d++ = value; >>>>> + >>>>> + return d; >>>>> +} >>>>> +#endif >>>> >>>> Does this work? >>>> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgodbolt.org%2Fz%2FTx6EaGMfb&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4df96063ffd94e6204df08df1bb54e3d%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639260137659741160%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=Xv0rle85Js5BH2qNUL4q2Iv2ZwgJhJ4FaTuHYAvvEVo%3D&reserved=0 >>> >>> Hmmm...possibly. >>> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgodbolt.org%2Fz%2Fec9rzd9Yf&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4df96063ffd94e6204df08df1bb54e3d%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639260137659754022%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=bLajY6c3CbYOZMJlBA4bYlVE3bNVc%2Fxe1KYk0rUJgjM%3D&reserved=0 >>> I don't get it... >> >> Just keep it under 2 pages, it will be fine: >> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgodbolt.org%2Fz%2FqqoMqfxev&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4df96063ffd94e6204df08df1bb54e3d%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639260137659763804%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=Bcp1%2B%2Fir05tsPwf08OQkJx4vDkPliaSppam1e%2BTPprk%3D&reserved=0 > > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgodbolt.org%2Fz%2F9W9f5a7Wx&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4df96063ffd94e6204df08df1bb54e3d%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639260137659773169%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=YPGYXcKrnM4e1Q2nHdshRUaMT36w%2BRkHuIWIgcbpA94%3D&reserved=0 > > Apparently not on RISCV, which is what prompted this patch in the first > place. So I suspect Nathan's v2 here is the way to go. Don't you have -fno-builtin on RISCV like we have on powerpc ? Or is it clang that is missing this option ? Christophe ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-09-26 10:55 ` Christophe Leroy (CS GROUP) @ 2026-09-26 12:29 ` Jason A. Donenfeld 2026-09-29 18:24 ` Nick Desaulniers 2026-09-26 12:39 ` Nathan Chancellor 1 sibling, 1 reply; 37+ messages in thread From: Jason A. Donenfeld @ 2026-09-26 12:29 UTC (permalink / raw) To: Christophe Leroy (CS GROUP) Cc: Nick Desaulniers, Nathan Chancellor, Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Vincenzo Frascino, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm On Sat, Sep 26, 2026 at 12:55:34PM +0200, Christophe Leroy (CS GROUP) wrote: > Hi Jason, > > Le 26/09/2026 à 12:02, Jason A. Donenfeld a écrit : > > On Fri, Sep 25, 2026 at 03:00:46PM -0700, Nick Desaulniers wrote: > >> On Fri, Sep 25, 2026 at 2:56 PM Nick Desaulniers > >> <ndesaulniers@google.com> wrote: > >>> > >>> On Fri, Sep 25, 2026 at 2:53 PM Nick Desaulniers > >>> <ndesaulniers@google.com> wrote: > >>>> > >>>> On Fri, Sep 25, 2026 at 2:46 PM Nathan Chancellor <nathan@kernel.org> wrote: > >>>>> > >>>>> After a recent change in LLVM [1], builds with the random vDSO > >>>>> implementation, such as PowerPC and RISC-V, fail when checking the vDSO: > >>>>> > >>>>> arch/powerpc/kernel/vdso/vdso32.so.dbg: dynamic relocations are not supported > >>>>> arch/riscv/kernel/vdso/vdso.so.dbg: dynamic relocations are not supported > >>>>> > >>>>> memset() is now generated when zeroing params->reserved for some builds > >>>>> because LLVM has an optimization (now run in more instances) that can > >>>>> recognize at compile time when it is assigning a static value to a > >>>>> contiguous area of memory and turn that into a call to memset(). Both > >>>>> clang and GCC assume memset() is always available [2]. > >>>>> > >>>>> clang provides a builtin, __builtin_memset_inline [3][4], that can be > >>>>> used to ensure an external function call is not generated when zeroing > >>>>> this memory. Use it when it is available. > >>>>> > >>>>> While GCC has no issues with the current code, it has generated memset() > >>>>> before, as seen in commit b7bad082e113 ("random: vDSO: avoid call to out > >>>>> of line memset()"). GCC 14 provides '-finline-stringops=memset' [5][6] > >>>>> with a similar guarantee to the clang builtin, so use it and > >>>>> __builtin_memset() when available. > >>>>> > >>>>> If no option is available, provide a simple memset_inline() like the one > >>>>> from lib/string.c to avoid adding an ugly ifdef. > >>>>> > >>>>> Link: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fllvm%2Fllvm-project%2Fcommit%2F90cebef1411617fc3eedd359bdf00cb44b1c2439&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4df96063ffd94e6204df08df1bb54e3d%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639260137659627802%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=ku4l8Ol5OJ2qi%2BcSblspxxUKOA6rNpiUO3ZvGSoAb1s%3D&reserved=0 [1] > >>>>> Link: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgcc.gnu.org%2Fonlinedocs%2Fgcc-16.2.0%2Fgcc%2FStandards.html%23index-ffreestanding&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4df96063ffd94e6204df08df1bb54e3d%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639260137659651194%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=jQa1eTDLk3cPNTa3GEBwVEohHh67ukShaRHMZvA%2FHDg%3D&reserved=0 [2] > >>>>> Link: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fllvm%2Fllvm-project%2Fcommit%2F38637ee477541370a90b37f149069d8e5c0c2efd&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4df96063ffd94e6204df08df1bb54e3d%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639260137659668579%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=zY7Kr9ZZNNZR%2FVsnwYRlubPRpbMaKe9QtMD2snd8ZvA%3D&reserved=0 [3] > >>>>> Link: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fclang.llvm.org%2Fdocs%2FLanguageExtensions.html%23guaranteed-inlined-memset&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4df96063ffd94e6204df08df1bb54e3d%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639260137659678360%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=vUU2fhCVcUWsbQD3IsRaUzSO8KVSpxwSpgr9San4aq0%3D&reserved=0 [4] > >>>>> Link: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgcc.gnu.org%2Fgit%2F%3Fp%3Dgcc.git%3Ba%3Dcommit%3Bh%3D1ff6d9f7428b0668cd8ab0b3e3ab94f1d733124d&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4df96063ffd94e6204df08df1bb54e3d%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639260137659687815%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=qHRqxAO252imwH1W93yHlp6jdcFGkFOr2Y2hXbG2MLU%3D&reserved=0 [5] > >>>>> Link: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgcc.gnu.org%2Fonlinedocs%2Fgcc%2FOptimize-Options.html%23index-finline-stringops&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4df96063ffd94e6204df08df1bb54e3d%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639260137659698298%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=0ecc%2BXd6o3nozh3N71aq%2F98Xam%2Fdol7GUHmC637Iv7I%3D&reserved=0 [6] > >>>>> Suggested-by: "Jason A. Donenfeld" <Jason@zx2c4.com> > >>>>> Suggested-by: Nick Desaulniers <ndesaulniers@google.com> > >>>>> Signed-off-by: Nathan Chancellor <nathan@kernel.org> > >>>>> --- > >>>>> Changes in v2: > >>>>> - Switch approach entirely (Jason, Nick) > >>>>> - clang: use __builtin_memset_inline() to avoid external call > >>>>> - GCC 14+: use __builtin_memset + -finline-stringops=memset (hence the > >>>>> massive CC list increase) > >>>>> - GCC < 14: no issues currently but avoid ifdef with simple memset > >>>>> implementation > >>>>> - Link to v1: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatch.msgid.link%2F20260916-vdso-getrandom-avoid-memset-llvm-24-v1-1-80a92f2e225a%40kernel.org&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4df96063ffd94e6204df08df1bb54e3d%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639260137659712983%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=%2Ftq3tUHqDmbXesqB69w6umXAuaTsfzOIhk54Jy76cwo%3D&reserved=0 > >>>>> --- > >>>>> arch/arm64/kernel/vdso/Makefile | 2 +- > >>>>> arch/loongarch/vdso/Makefile | 1 + > >>>>> arch/powerpc/kernel/vdso/Makefile | 1 + > >>>>> arch/riscv/kernel/vdso/Makefile | 1 + > >>>>> arch/s390/kernel/vdso/Makefile | 1 + > >>>>> arch/x86/entry/vdso/vdso64/Makefile | 2 +- > >>>>> init/Kconfig | 7 +++++++ > >>>>> lib/vdso/getrandom.c | 19 +++++++++++++++++-- > >>>>> 8 files changed, 30 insertions(+), 4 deletions(-) > >>>>> > >>>>> diff --git a/arch/arm64/kernel/vdso/Makefile b/arch/arm64/kernel/vdso/Makefile > >>>>> index 7dec05dd33b7..f6619e1cb2ce 100644 > >>>>> --- a/arch/arm64/kernel/vdso/Makefile > >>>>> +++ b/arch/arm64/kernel/vdso/Makefile > >>>>> @@ -41,7 +41,7 @@ CC_FLAGS_REMOVE_VDSO := $(CC_FLAGS_FTRACE) -Os $(CC_FLAGS_SCS) \ > >>>>> $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) \ > >>>>> -Wmissing-prototypes -Wmissing-declarations > >>>>> > >>>>> -CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tables > >>>>> +CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tables $(CONFIG_CC_OPT_INLINE_MEMSET) > >>>>> > >>>>> CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_REMOVE_VDSO) > >>>>> CFLAGS_REMOVE_vgetrandom.o = $(CC_FLAGS_REMOVE_VDSO) > >>>>> diff --git a/arch/loongarch/vdso/Makefile b/arch/loongarch/vdso/Makefile > >>>>> index 9c9181bb4071..0b84892d084b 100644 > >>>>> --- a/arch/loongarch/vdso/Makefile > >>>>> +++ b/arch/loongarch/vdso/Makefile > >>>>> @@ -16,6 +16,7 @@ ccflags-vdso := \ > >>>>> $(filter -m64,$(KBUILD_CFLAGS)) \ > >>>>> $(filter -march=%,$(KBUILD_CFLAGS)) \ > >>>>> $(filter -m%-float,$(KBUILD_CFLAGS)) \ > >>>>> + $(CONFIG_CC_OPT_INLINE_MEMSET) \ > >>>>> $(CLANG_FLAGS) \ > >>>>> -D__VDSO__ > >>>>> > >>>>> diff --git a/arch/powerpc/kernel/vdso/Makefile b/arch/powerpc/kernel/vdso/Makefile > >>>>> index 368759f81708..0d1a49529885 100644 > >>>>> --- a/arch/powerpc/kernel/vdso/Makefile > >>>>> +++ b/arch/powerpc/kernel/vdso/Makefile > >>>>> @@ -43,6 +43,7 @@ ccflags-y := -fno-common -fno-builtin -DBUILD_VDSO > >>>>> ccflags-y += $(DISABLE_LATENT_ENTROPY_PLUGIN) > >>>>> ccflags-y += $(call cc-option, -fno-stack-protector) > >>>>> ccflags-y += -DDISABLE_BRANCH_PROFILING > >>>>> +ccflags-y += $(CONFIG_CC_OPT_INLINE_MEMSET) > >>>>> ccflags-y += -ffreestanding -fasynchronous-unwind-tables > >>>>> ccflags-remove-y := $(CC_FLAGS_FTRACE) > >>>>> ldflags-y := -Wl,--hash-style=both -nostdlib -shared -z noexecstack $(CLANG_FLAGS) > >>>>> diff --git a/arch/riscv/kernel/vdso/Makefile b/arch/riscv/kernel/vdso/Makefile > >>>>> index 8dbf2532a573..c023046a3fd7 100644 > >>>>> --- a/arch/riscv/kernel/vdso/Makefile > >>>>> +++ b/arch/riscv/kernel/vdso/Makefile > >>>>> @@ -36,6 +36,7 @@ endif > >>>>> ccflags-y := -fno-stack-protector > >>>>> ccflags-y += -DDISABLE_BRANCH_PROFILING > >>>>> ccflags-y += -fno-builtin > >>>>> +ccflags-y += $(CONFIG_CC_OPT_INLINE_MEMSET) > >>>>> ccflags-y += $(KBUILD_BASE_ISA)$(CFI_MARCH) > >>>>> ccflags-y += $(CFI_FULL) > >>>>> asflags-y += $(KBUILD_BASE_ISA)$(CFI_MARCH) > >>>>> diff --git a/arch/s390/kernel/vdso/Makefile b/arch/s390/kernel/vdso/Makefile > >>>>> index 35c834b895ec..54bcf2984ca1 100644 > >>>>> --- a/arch/s390/kernel/vdso/Makefile > >>>>> +++ b/arch/s390/kernel/vdso/Makefile > >>>>> @@ -29,6 +29,7 @@ KBUILD_CFLAGS_VDSO := $(filter-out -munaligned-symbols,$(KBUILD_CFLAGS_VDSO)) > >>>>> KBUILD_CFLAGS_VDSO := $(filter-out -fno-asynchronous-unwind-tables,$(KBUILD_CFLAGS_VDSO)) > >>>>> KBUILD_CFLAGS_VDSO += -fPIC -fno-common -fno-builtin -fasynchronous-unwind-tables > >>>>> KBUILD_CFLAGS_VDSO += -fno-stack-protector $(DISABLE_KSTACK_ERASE) > >>>>> +KBUILD_CFLAGS_VDSO += $(CONFIG_CC_OPT_INLINE_MEMSET) > >>>>> ldflags-y := -shared -soname=linux-vdso.so.1 \ > >>>>> --hash-style=both --build-id=sha1 \ > >>>>> $(call ld-option, --eh-frame-hdr) -T > >>>>> diff --git a/arch/x86/entry/vdso/vdso64/Makefile b/arch/x86/entry/vdso/vdso64/Makefile > >>>>> index 7c0790065b5e..c2353a065279 100644 > >>>>> --- a/arch/x86/entry/vdso/vdso64/Makefile > >>>>> +++ b/arch/x86/entry/vdso/vdso64/Makefile > >>>>> @@ -14,7 +14,7 @@ vobjs-$(CONFIG_X86_SGX) += vsgx.o > >>>>> vobjs-$(CONFIG_FUTEX_ROBUST_UNLOCK) += vfutex.o > >>>>> > >>>>> # Compilation flags > >>>>> -flags-y := -DBUILD_VDSO64 -m64 -mcmodel=small > >>>>> +flags-y := -DBUILD_VDSO64 -m64 -mcmodel=small $(CONFIG_CC_OPT_INLINE_MEMSET) > >>>>> > >>>>> # The location of this include matters! > >>>>> include $(src)/../common/Makefile.include > >>>>> diff --git a/init/Kconfig b/init/Kconfig > >>>>> index 8583d9f06c52..ff3f8475dd2f 100644 > >>>>> --- a/init/Kconfig > >>>>> +++ b/init/Kconfig > >>>>> @@ -173,6 +173,13 @@ config CC_HAS_ALLOC_TOKEN > >>>>> config CC_HAS_MULTIDIMENSIONAL_NONSTRING > >>>>> def_bool $(success,echo 'char tag[][4] __attribute__((__nonstring__)) = { };' | $(CC) $(CLANG_FLAGS) -x c - -c -o /dev/null -Werror) > >>>>> > >>>>> +config CC_HAS_OPT_INLINE_MEMSET > >>>>> + def_bool $(cc-option,-finline-stringops=memset) > >>>>> + > >>>>> +config CC_OPT_INLINE_MEMSET > >>>>> + string > >>>>> + default "-finline-stringops=memset" if CC_HAS_OPT_INLINE_MEMSET > >>>>> + > >>>>> config LD_CAN_USE_KEEP_IN_OVERLAY > >>>>> # ld.lld prior to 21.0.0 did not support KEEP within an overlay description > >>>>> # https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fllvm%2Fllvm-project%2Fpull%2F130661&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4df96063ffd94e6204df08df1bb54e3d%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639260137659727352%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=03eAQvPTDs%2FN28bYiiZAVYcx2JFSkuOM7x2iwFU%2F%2FxA%3D&reserved=0 > >>>>> diff --git a/lib/vdso/getrandom.c b/lib/vdso/getrandom.c > >>>>> index 2851afa9154f..f5cad5641985 100644 > >>>>> --- a/lib/vdso/getrandom.c > >>>>> +++ b/lib/vdso/getrandom.c > >>>>> @@ -29,6 +29,22 @@ > >>>>> } \ > >>>>> } while (0) > >>>>> > >>>>> +#if __has_builtin(__builtin_memset_inline) > >>>>> +#define memset_inline(dst, value, size) __builtin_memset_inline(dst, value, size) > >>>>> +#elif IS_ENABLED(CONFIG_CC_HAS_OPT_INLINE_MEMSET) > >>>>> +#define memset_inline(dst, value, size) __builtin_memset(dst, value, size) > >>>>> +#else > >>>>> +static inline void *memset_inline(void *dst, int value, size_t size) > >>>>> +{ > >>>>> + char *d = dst; > >>>>> + > >>>>> + while (size--) > >>>>> + *d++ = value; > >>>>> + > >>>>> + return d; > >>>>> +} > >>>>> +#endif > >>>> > >>>> Does this work? > >>>> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgodbolt.org%2Fz%2FTx6EaGMfb&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4df96063ffd94e6204df08df1bb54e3d%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639260137659741160%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=Xv0rle85Js5BH2qNUL4q2Iv2ZwgJhJ4FaTuHYAvvEVo%3D&reserved=0 > >>> > >>> Hmmm...possibly. > >>> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgodbolt.org%2Fz%2Fec9rzd9Yf&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4df96063ffd94e6204df08df1bb54e3d%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639260137659754022%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=bLajY6c3CbYOZMJlBA4bYlVE3bNVc%2Fxe1KYk0rUJgjM%3D&reserved=0 > >>> I don't get it... > >> > >> Just keep it under 2 pages, it will be fine: > >> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgodbolt.org%2Fz%2FqqoMqfxev&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4df96063ffd94e6204df08df1bb54e3d%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639260137659763804%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=Bcp1%2B%2Fir05tsPwf08OQkJx4vDkPliaSppam1e%2BTPprk%3D&reserved=0 > > > > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgodbolt.org%2Fz%2F9W9f5a7Wx&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4df96063ffd94e6204df08df1bb54e3d%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639260137659773169%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=YPGYXcKrnM4e1Q2nHdshRUaMT36w%2BRkHuIWIgcbpA94%3D&reserved=0 > > > > Apparently not on RISCV, which is what prompted this patch in the first > > place. So I suspect Nathan's v2 here is the way to go. > > > Don't you have -fno-builtin on RISCV like we have on powerpc ? I think Nick mentioned this led to other problems and didn't exactly solve the problem. ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-09-26 12:29 ` Jason A. Donenfeld @ 2026-09-29 18:24 ` Nick Desaulniers 2026-09-30 13:38 ` Nathan Chancellor 0 siblings, 1 reply; 37+ messages in thread From: Nick Desaulniers @ 2026-09-29 18:24 UTC (permalink / raw) To: Jason A. Donenfeld, Nathan Chancellor Cc: Christophe Leroy (CS GROUP), Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Vincenzo Frascino, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm On Sat, Sep 26, 2026 at 5:29 AM Jason A. Donenfeld <Jason@zx2c4.com> wrote: > > On Sat, Sep 26, 2026 at 12:55:34PM +0200, Christophe Leroy (CS GROUP) wrote: > > Hi Jason, > > > > Le 26/09/2026 à 12:02, Jason A. Donenfeld a écrit : > > > Apparently not on RISCV, which is what prompted this patch in the first > > > place. So I suspect Nathan's v2 here is the way to go. > > > > > > Don't you have -fno-builtin on RISCV like we have on powerpc ? > > I think Nick mentioned this led to other problems and didn't exactly > solve the problem. Sorry, been very busy. Getting blasted from a fire hose of AI generated patches to review... arch/arm64/kvm/hyp/nvhe/Makefile has this pattern for exactly the same problem I suspect. Maybe that's the right tool in the toolbox? ``` diff --git a/arch/riscv/kernel/vdso/Makefile b/arch/riscv/kernel/vdso/Makefile index 8dbf2532a573..27fa72d8fb86 100644 --- a/arch/riscv/kernel/vdso/Makefile +++ b/arch/riscv/kernel/vdso/Makefile @@ -27,7 +27,7 @@ asflags-y += -DVDSO_CFI=1 endif # Files to link into the vdso -obj-vdso = $(patsubst %, %.o, $(vdso-syms)) note.o +obj-vdso = $(patsubst %, %.o, $(vdso-syms)) note.o ../../lib/memset.o ifdef CONFIG_VDSO_GETRANDOM obj-vdso += vgetrandom-chacha.o ``` Fixes `make -skj"$(nproc)" ARCH=riscv LLVM=1 mrproper allmodconfig vdso_prepare` for me, as per https://github.com/ClangBuiltLinux/linux/issues/2183 (Nathan, don't forget to link to that in the commit message) I'm surprised I didn't need -fno-semantic-interposition (or one of the related flags... -fvisibility=hidden) If we want to get better, (if performance matters here and we want to trade source+build system complexity for absolute code perf) I would start with that, then worry about clawing back performance via things like: - __builtin_memset_inline - -finline-stringops=memset - -ffunction-sections+-Wl,--gc-sections to dead code eliminate the out of line copy of memset, though IIRC there's potential for wasted space due to alignment requirements (maybe the out of line copy of memset is smaller...idk) -- Thanks, ~Nick Desaulniers ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-09-29 18:24 ` Nick Desaulniers @ 2026-09-30 13:38 ` Nathan Chancellor 2026-09-30 14:21 ` Jason A. Donenfeld 0 siblings, 1 reply; 37+ messages in thread From: Nathan Chancellor @ 2026-09-30 13:38 UTC (permalink / raw) To: Nick Desaulniers Cc: Jason A. Donenfeld, Christophe Leroy (CS GROUP), Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Vincenzo Frascino, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm On Tue, Sep 29, 2026 at 11:24:11AM -0700, Nick Desaulniers wrote: > arch/arm64/kvm/hyp/nvhe/Makefile has this pattern for exactly the same > problem I suspect. Maybe that's the right tool in the toolbox? > > ``` > diff --git a/arch/riscv/kernel/vdso/Makefile b/arch/riscv/kernel/vdso/Makefile > index 8dbf2532a573..27fa72d8fb86 100644 > --- a/arch/riscv/kernel/vdso/Makefile > +++ b/arch/riscv/kernel/vdso/Makefile > @@ -27,7 +27,7 @@ asflags-y += -DVDSO_CFI=1 > endif > > # Files to link into the vdso > -obj-vdso = $(patsubst %, %.o, $(vdso-syms)) note.o > +obj-vdso = $(patsubst %, %.o, $(vdso-syms)) note.o ../../lib/memset.o > > ifdef CONFIG_VDSO_GETRANDOM > obj-vdso += vgetrandom-chacha.o > ``` > Fixes `make -skj"$(nproc)" ARCH=riscv LLVM=1 mrproper allmodconfig > vdso_prepare` for me, as per For the record, this also happens with the 32-bit PowerPC vDSO, as I noted in the commit message of v2. I should update the issue too, I only realized this after wider testing. So if this is the route we want to go, we would need a memset() for that vDSO as well. > https://github.com/ClangBuiltLinux/linux/issues/2183 > (Nathan, don't forget to link to that in the commit message) Yes, thanks, I have added it for v3. > I'm surprised I didn't need -fno-semantic-interposition (or one of the > related flags... -fvisibility=hidden) > > If we want to get better, (if performance matters here and we want to > trade source+build system complexity for absolute code perf) I would > start with that, then worry about clawing back performance via things > like: > - __builtin_memset_inline > - -finline-stringops=memset > - -ffunction-sections+-Wl,--gc-sections to dead code eliminate the out > of line copy of memset, though IIRC there's potential for wasted space > due to alignment requirements (maybe the out of line copy of memset is > smaller...idk) Yeah, I guess it is ultimately up to the maintainers what route they prefer. -- Cheers, Nathan ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-09-30 13:38 ` Nathan Chancellor @ 2026-09-30 14:21 ` Jason A. Donenfeld 2026-09-30 14:44 ` Jason A. Donenfeld 0 siblings, 1 reply; 37+ messages in thread From: Jason A. Donenfeld @ 2026-09-30 14:21 UTC (permalink / raw) To: Nathan Chancellor Cc: Nick Desaulniers, Christophe Leroy (CS GROUP), Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Vincenzo Frascino, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm On Wed, Sep 30, 2026 at 03:38:13PM +0200, Nathan Chancellor wrote: > On Tue, Sep 29, 2026 at 11:24:11AM -0700, Nick Desaulniers wrote: > > arch/arm64/kvm/hyp/nvhe/Makefile has this pattern for exactly the same > > problem I suspect. Maybe that's the right tool in the toolbox? > > > > ``` > > diff --git a/arch/riscv/kernel/vdso/Makefile b/arch/riscv/kernel/vdso/Makefile > > index 8dbf2532a573..27fa72d8fb86 100644 > > --- a/arch/riscv/kernel/vdso/Makefile > > +++ b/arch/riscv/kernel/vdso/Makefile > > @@ -27,7 +27,7 @@ asflags-y += -DVDSO_CFI=1 > > endif > > > > # Files to link into the vdso > > -obj-vdso = $(patsubst %, %.o, $(vdso-syms)) note.o > > +obj-vdso = $(patsubst %, %.o, $(vdso-syms)) note.o ../../lib/memset.o > > > > ifdef CONFIG_VDSO_GETRANDOM > > obj-vdso += vgetrandom-chacha.o > > ``` > > Fixes `make -skj"$(nproc)" ARCH=riscv LLVM=1 mrproper allmodconfig > > vdso_prepare` for me, as per > > For the record, this also happens with the 32-bit PowerPC vDSO, as I > noted in the commit message of v2. I should update the issue too, I only > realized this after wider testing. So if this is the route we want to > go, we would need a memset() for that vDSO as well. > > > https://github.com/ClangBuiltLinux/linux/issues/2183 > > (Nathan, don't forget to link to that in the commit message) > > Yes, thanks, I have added it for v3. > > > I'm surprised I didn't need -fno-semantic-interposition (or one of the > > related flags... -fvisibility=hidden) > > > > If we want to get better, (if performance matters here and we want to > > trade source+build system complexity for absolute code perf) I would > > start with that, then worry about clawing back performance via things > > like: > > - __builtin_memset_inline > > - -finline-stringops=memset > > - -ffunction-sections+-Wl,--gc-sections to dead code eliminate the out > > of line copy of memset, though IIRC there's potential for wasted space > > due to alignment requirements (maybe the out of line copy of memset is > > smaller...idk) > > Yeah, I guess it is ultimately up to the maintainers what route they > prefer. I think linking in an out-of-line memset.o is not appealing. This isn't a general library or something. So let's just go with your v2 approach, fixed up in the ways we mentioned. ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-09-30 14:21 ` Jason A. Donenfeld @ 2026-09-30 14:44 ` Jason A. Donenfeld 2026-09-30 15:13 ` Nathan Chancellor 0 siblings, 1 reply; 37+ messages in thread From: Jason A. Donenfeld @ 2026-09-30 14:44 UTC (permalink / raw) To: Nathan Chancellor Cc: Nick Desaulniers, Christophe Leroy (CS GROUP), Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Vincenzo Frascino, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm On Wed, Sep 30, 2026 at 04:21:21PM +0200, Jason A. Donenfeld wrote: > On Wed, Sep 30, 2026 at 03:38:13PM +0200, Nathan Chancellor wrote: > > On Tue, Sep 29, 2026 at 11:24:11AM -0700, Nick Desaulniers wrote: > > > arch/arm64/kvm/hyp/nvhe/Makefile has this pattern for exactly the same > > > problem I suspect. Maybe that's the right tool in the toolbox? > > > > > > ``` > > > diff --git a/arch/riscv/kernel/vdso/Makefile b/arch/riscv/kernel/vdso/Makefile > > > index 8dbf2532a573..27fa72d8fb86 100644 > > > --- a/arch/riscv/kernel/vdso/Makefile > > > +++ b/arch/riscv/kernel/vdso/Makefile > > > @@ -27,7 +27,7 @@ asflags-y += -DVDSO_CFI=1 > > > endif > > > > > > # Files to link into the vdso > > > -obj-vdso = $(patsubst %, %.o, $(vdso-syms)) note.o > > > +obj-vdso = $(patsubst %, %.o, $(vdso-syms)) note.o ../../lib/memset.o > > > > > > ifdef CONFIG_VDSO_GETRANDOM > > > obj-vdso += vgetrandom-chacha.o > > > ``` > > > Fixes `make -skj"$(nproc)" ARCH=riscv LLVM=1 mrproper allmodconfig > > > vdso_prepare` for me, as per > > > > For the record, this also happens with the 32-bit PowerPC vDSO, as I > > noted in the commit message of v2. I should update the issue too, I only > > realized this after wider testing. So if this is the route we want to > > go, we would need a memset() for that vDSO as well. > > > > > https://github.com/ClangBuiltLinux/linux/issues/2183 > > > (Nathan, don't forget to link to that in the commit message) > > > > Yes, thanks, I have added it for v3. > > > > > I'm surprised I didn't need -fno-semantic-interposition (or one of the > > > related flags... -fvisibility=hidden) > > > > > > If we want to get better, (if performance matters here and we want to > > > trade source+build system complexity for absolute code perf) I would > > > start with that, then worry about clawing back performance via things > > > like: > > > - __builtin_memset_inline > > > - -finline-stringops=memset > > > - -ffunction-sections+-Wl,--gc-sections to dead code eliminate the out > > > of line copy of memset, though IIRC there's potential for wasted space > > > due to alignment requirements (maybe the out of line copy of memset is > > > smaller...idk) > > > > Yeah, I guess it is ultimately up to the maintainers what route they > > prefer. > > I think linking in an out-of-line memset.o is not appealing. This isn't > a general library or something. So let's just go with your v2 approach, > fixed up in the ways we mentioned. Nathan, would this be okay with you? https://git.zx2c4.com/linux-rng/commit/?id=d216701724b7d8209ff42150658ad5c712bdb503 ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-09-30 14:44 ` Jason A. Donenfeld @ 2026-09-30 15:13 ` Nathan Chancellor 2026-09-30 15:16 ` Jason A. Donenfeld 0 siblings, 1 reply; 37+ messages in thread From: Nathan Chancellor @ 2026-09-30 15:13 UTC (permalink / raw) To: Jason A. Donenfeld Cc: Nick Desaulniers, Christophe Leroy (CS GROUP), Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Vincenzo Frascino, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm On Wed, Sep 30, 2026 at 04:44:29PM +0200, Jason A. Donenfeld wrote: > Nathan, would this be okay with you? > https://git.zx2c4.com/linux-rng/commit/?id=d216701724b7d8209ff42150658ad5c712bdb503 Can you stick Cc: stable@vger.kernel.org # v6.12+ Closes: https://github.com/ClangBuiltLinux/linux/issues/2183 on that? Otherwise, looks good to me, that's basically what I had for my v3 locally. -- Cheers, Nathan ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-09-30 15:13 ` Nathan Chancellor @ 2026-09-30 15:16 ` Jason A. Donenfeld 2026-10-01 4:41 ` Christophe Leroy (CS GROUP) 0 siblings, 1 reply; 37+ messages in thread From: Jason A. Donenfeld @ 2026-09-30 15:16 UTC (permalink / raw) To: Nathan Chancellor Cc: Nick Desaulniers, Christophe Leroy (CS GROUP), Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Vincenzo Frascino, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm On Wed, Sep 30, 2026 at 5:13 PM Nathan Chancellor <nathan@kernel.org> wrote: > > On Wed, Sep 30, 2026 at 04:44:29PM +0200, Jason A. Donenfeld wrote: > > Nathan, would this be okay with you? > > https://git.zx2c4.com/linux-rng/commit/?id=d216701724b7d8209ff42150658ad5c712bdb503 > > Can you stick > > Cc: stable@vger.kernel.org # v6.12+ > Closes: https://github.com/ClangBuiltLinux/linux/issues/2183 > > on that? Otherwise, looks good to me, that's basically what I had for my > v3 locally. Sure, done. Also removed the now-unused array_size.h include. Jason ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-09-30 15:16 ` Jason A. Donenfeld @ 2026-10-01 4:41 ` Christophe Leroy (CS GROUP) 2026-10-01 9:25 ` Jason A. Donenfeld 0 siblings, 1 reply; 37+ messages in thread From: Christophe Leroy (CS GROUP) @ 2026-10-01 4:41 UTC (permalink / raw) To: Jason A. Donenfeld, Nathan Chancellor Cc: Nick Desaulniers, Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Vincenzo Frascino, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm Hi, Le 30/09/2026 à 17:16, Jason A. Donenfeld a écrit : > On Wed, Sep 30, 2026 at 5:13 PM Nathan Chancellor <nathan@kernel.org> wrote: >> >> On Wed, Sep 30, 2026 at 04:44:29PM +0200, Jason A. Donenfeld wrote: >>> Nathan, would this be okay with you? >>> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.zx2c4.com%2Flinux-rng%2Fcommit%2F%3Fid%3Dd216701724b7d8209ff42150658ad5c712bdb503&data=05%7C02%7Cchristophe.leroy2%40cs-soprasteria.com%7C8f69935bffb344bf0ddc08df1f05e358%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639263782324080837%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=BA7Fyr0%2FynggvBnR%2FpiCvNCQHtNBagqvSb0i11AvoLU%3D&reserved=0 >> >> Can you stick >> >> Cc: stable@vger.kernel.org # v6.12+ >> Closes: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FClangBuiltLinux%2Flinux%2Fissues%2F2183&data=05%7C02%7Cchristophe.leroy2%40cs-soprasteria.com%7C8f69935bffb344bf0ddc08df1f05e358%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639263782324110679%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=6C8%2FAEQoh%2B8pfgfYQkL7qf5Ue%2F5sAGtfqRptzsSG0CM%3D&reserved=0 >> >> on that? Otherwise, looks good to me, that's basically what I had for my >> v3 locally. > > Sure, done. Also removed the now-unused array_size.h include. I'm still very sceptic with this patch. You are degrading the behaviour with GCC for a problem with CLANG. Why ? Before the patch, with both GCC 13 and GCC 16 on powerpc32 I get a pretty standard optimised loop that clears words 4 by 4 (with auto increment of pointer) which is the most optimal on powerpc: 3f0: 39 00 00 0c li r8,12 3f4: 35 08 ff fc addic. r8,r8,-4 3f8: 91 49 00 04 stw r10,4(r9) 3fc: 91 49 00 08 stw r10,8(r9) 400: 91 49 00 0c stw r10,12(r9) 404: 95 49 00 10 stwu r10,16(r9) 408: 40 82 ff ec bne 3f4 <__c_kernel_getrandom+0x3f4> With the patch, With GCC 13 I get a very suboptimal loop copying bytes one by one 3d8: 39 40 00 34 li r10,52 ... 3e4: 39 20 00 00 li r9,0 3e8: 7d 49 03 a6 mtctr r10 3ec: 9d 3e 00 01 stbu r9,1(r30) 3f0: 42 00 ff fc bdnz 3ec <__c_kernel_getrandom+0x3ec> With GCC 16 I get something a bit better but not as good as before, it is a loop clearing words only one by one and incrementing pointer with an additional insn instead of using auto-increment instruction stwu. 3e0: 39 40 00 0d li r10,13 ... 3f0: 7d 49 03 a6 mtctr r10 3f4: 91 3f 00 00 stw r9,0(r31) 3f8: 3b ff 00 04 addi r31,r31,4 3fc: 42 00 ff f8 bdnz 3f4 <__c_kernel_getrandom+0x3f4> Please restrict the patch to clang builds. Christophe ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-10-01 4:41 ` Christophe Leroy (CS GROUP) @ 2026-10-01 9:25 ` Jason A. Donenfeld 2026-10-01 10:20 ` Nathan Chancellor 0 siblings, 1 reply; 37+ messages in thread From: Jason A. Donenfeld @ 2026-10-01 9:25 UTC (permalink / raw) To: Christophe Leroy (CS GROUP) Cc: Nathan Chancellor, Nick Desaulniers, Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Vincenzo Frascino, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm On Thu, Oct 01, 2026 at 06:41:20AM +0200, Christophe Leroy (CS GROUP) wrote: > Hi, > > Le 30/09/2026 à 17:16, Jason A. Donenfeld a écrit : > > On Wed, Sep 30, 2026 at 5:13 PM Nathan Chancellor <nathan@kernel.org> wrote: > >> > >> On Wed, Sep 30, 2026 at 04:44:29PM +0200, Jason A. Donenfeld wrote: > >>> Nathan, would this be okay with you? > >>> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.zx2c4.com%2Flinux-rng%2Fcommit%2F%3Fid%3Dd216701724b7d8209ff42150658ad5c712bdb503&data=05%7C02%7Cchristophe.leroy2%40cs-soprasteria.com%7C8f69935bffb344bf0ddc08df1f05e358%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639263782324080837%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=BA7Fyr0%2FynggvBnR%2FpiCvNCQHtNBagqvSb0i11AvoLU%3D&reserved=0 > >> > >> Can you stick > >> > >> Cc: stable@vger.kernel.org # v6.12+ > >> Closes: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FClangBuiltLinux%2Flinux%2Fissues%2F2183&data=05%7C02%7Cchristophe.leroy2%40cs-soprasteria.com%7C8f69935bffb344bf0ddc08df1f05e358%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639263782324110679%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=6C8%2FAEQoh%2B8pfgfYQkL7qf5Ue%2F5sAGtfqRptzsSG0CM%3D&reserved=0 > >> > >> on that? Otherwise, looks good to me, that's basically what I had for my > >> v3 locally. > > > > Sure, done. Also removed the now-unused array_size.h include. > > I'm still very sceptic with this patch. You are degrading the behaviour > with GCC for a problem with CLANG. Why ? > > Before the patch, with both GCC 13 and GCC 16 on powerpc32 I get a > pretty standard optimised loop that clears words 4 by 4 (with auto > increment of pointer) which is the most optimal on powerpc: > > 3f0: 39 00 00 0c li r8,12 > 3f4: 35 08 ff fc addic. r8,r8,-4 > 3f8: 91 49 00 04 stw r10,4(r9) > 3fc: 91 49 00 08 stw r10,8(r9) > 400: 91 49 00 0c stw r10,12(r9) > 404: 95 49 00 10 stwu r10,16(r9) > 408: 40 82 ff ec bne 3f4 <__c_kernel_getrandom+0x3f4> > > With the patch, > > With GCC 13 I get a very suboptimal loop copying bytes one by one > > 3d8: 39 40 00 34 li r10,52 > ... > 3e4: 39 20 00 00 li r9,0 > 3e8: 7d 49 03 a6 mtctr r10 > 3ec: 9d 3e 00 01 stbu r9,1(r30) > 3f0: 42 00 ff fc bdnz 3ec <__c_kernel_getrandom+0x3ec> > > With GCC 16 I get something a bit better but not as good as before, it > is a loop clearing words only one by one and incrementing pointer with > an additional insn instead of using auto-increment instruction stwu. > > 3e0: 39 40 00 0d li r10,13 > ... > 3f0: 7d 49 03 a6 mtctr r10 > 3f4: 91 3f 00 00 stw r9,0(r31) > 3f8: 3b ff 00 04 addi r31,r31,4 > 3fc: 42 00 ff f8 bdnz 3f4 <__c_kernel_getrandom+0x3f4> > > Please restrict the patch to clang builds. Darn. Yea. The naive memset kills optimizations. Okay, new strategy: - on clang, pass `-mllvm -max-store-memset=4294967295` - on gcc, pass `-finline-stringops=memset` And keep the same code. (Or, better, see if those options generate good code with b7bad082e113640fc81200ff869e5c2d7a9c29a2 reverted; I would prefer that simpler initializer.) Nathan, do these work? Jason ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-10-01 9:25 ` Jason A. Donenfeld @ 2026-10-01 10:20 ` Nathan Chancellor 2026-10-01 10:48 ` Jason A. Donenfeld 0 siblings, 1 reply; 37+ messages in thread From: Nathan Chancellor @ 2026-10-01 10:20 UTC (permalink / raw) To: Jason A. Donenfeld Cc: Christophe Leroy (CS GROUP), Nick Desaulniers, Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Vincenzo Frascino, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm On Thu, Oct 01, 2026 at 11:25:35AM +0200, Jason A. Donenfeld wrote: > Darn. Yea. The naive memset kills optimizations. > > Okay, new strategy: > > - on clang, pass `-mllvm -max-store-memset=4294967295` > - on gcc, pass `-finline-stringops=memset` > > And keep the same code. (Or, better, see if those options generate good > code with b7bad082e113640fc81200ff869e5c2d7a9c29a2 reverted; I would > prefer that simpler initializer.) Reverting b7bad082e113640fc81200ff869e5c2d7a9c29a2 would break GCC < 14 though, right (since no '-finline-stringops=memset')? > Nathan, do these work? I would really prefer not to use an internal LLVM flag here. While there are some instances of internal LLVM flags in the kernel tree already, LLVM generally only provides them for debugging and not end user control. The change that introduced -max-store-memset only did it to "allow fine-tuning of the inlining threshold for performance analysis and optimization". If they decide to remove it for whatever reason, we're back to square one. https://github.com/llvm/llvm-project/commit/b28eeb28bea39148738dc375e8a97072a1907e64 I know something like below would be uglier due to the ifdef but it would avoid changing anything for GCC while clearing up the issue at hand for clang in a guaranteed stable and succinct manner. diff --git a/lib/vdso/getrandom.c b/lib/vdso/getrandom.c index 2851afa9154f..f495d2111ee3 100644 --- a/lib/vdso/getrandom.c +++ b/lib/vdso/getrandom.c @@ -83,8 +83,12 @@ __cvdso_getrandom_data(const struct vdso_rng_data *rng_info, void *buffer, size_ params->size_of_opaque_state = sizeof(*state); params->mmap_prot = PROT_READ | PROT_WRITE; params->mmap_flags = MAP_DROPPABLE | MAP_ANONYMOUS; +#if __has_builtin(__builtin_memset_inline) + __builtin_memset_inline(params->reserved, 0, sizeof(params->reserved)); +#else for (size_t i = 0; i < ARRAY_SIZE(params->reserved); ++i) params->reserved[i] = 0; +#endif return 0; } -- If that is not acceptable, something like the following does appear to work for me. diff --git a/arch/arm64/kernel/vdso/Makefile b/arch/arm64/kernel/vdso/Makefile index 7dec05dd33b7..f6619e1cb2ce 100644 --- a/arch/arm64/kernel/vdso/Makefile +++ b/arch/arm64/kernel/vdso/Makefile @@ -41,7 +41,7 @@ CC_FLAGS_REMOVE_VDSO := $(CC_FLAGS_FTRACE) -Os $(CC_FLAGS_SCS) \ $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) \ -Wmissing-prototypes -Wmissing-declarations -CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tables +CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tables $(CONFIG_CC_OPT_INLINE_MEMSET) CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_REMOVE_VDSO) CFLAGS_REMOVE_vgetrandom.o = $(CC_FLAGS_REMOVE_VDSO) diff --git a/arch/loongarch/vdso/Makefile b/arch/loongarch/vdso/Makefile index 9c9181bb4071..0b84892d084b 100644 --- a/arch/loongarch/vdso/Makefile +++ b/arch/loongarch/vdso/Makefile @@ -16,6 +16,7 @@ ccflags-vdso := \ $(filter -m64,$(KBUILD_CFLAGS)) \ $(filter -march=%,$(KBUILD_CFLAGS)) \ $(filter -m%-float,$(KBUILD_CFLAGS)) \ + $(CONFIG_CC_OPT_INLINE_MEMSET) \ $(CLANG_FLAGS) \ -D__VDSO__ diff --git a/arch/powerpc/kernel/vdso/Makefile b/arch/powerpc/kernel/vdso/Makefile index 368759f81708..0d1a49529885 100644 --- a/arch/powerpc/kernel/vdso/Makefile +++ b/arch/powerpc/kernel/vdso/Makefile @@ -43,6 +43,7 @@ ccflags-y := -fno-common -fno-builtin -DBUILD_VDSO ccflags-y += $(DISABLE_LATENT_ENTROPY_PLUGIN) ccflags-y += $(call cc-option, -fno-stack-protector) ccflags-y += -DDISABLE_BRANCH_PROFILING +ccflags-y += $(CONFIG_CC_OPT_INLINE_MEMSET) ccflags-y += -ffreestanding -fasynchronous-unwind-tables ccflags-remove-y := $(CC_FLAGS_FTRACE) ldflags-y := -Wl,--hash-style=both -nostdlib -shared -z noexecstack $(CLANG_FLAGS) diff --git a/arch/riscv/kernel/vdso/Makefile b/arch/riscv/kernel/vdso/Makefile index 8dbf2532a573..c023046a3fd7 100644 --- a/arch/riscv/kernel/vdso/Makefile +++ b/arch/riscv/kernel/vdso/Makefile @@ -36,6 +36,7 @@ endif ccflags-y := -fno-stack-protector ccflags-y += -DDISABLE_BRANCH_PROFILING ccflags-y += -fno-builtin +ccflags-y += $(CONFIG_CC_OPT_INLINE_MEMSET) ccflags-y += $(KBUILD_BASE_ISA)$(CFI_MARCH) ccflags-y += $(CFI_FULL) asflags-y += $(KBUILD_BASE_ISA)$(CFI_MARCH) diff --git a/arch/s390/kernel/vdso/Makefile b/arch/s390/kernel/vdso/Makefile index 35c834b895ec..54bcf2984ca1 100644 --- a/arch/s390/kernel/vdso/Makefile +++ b/arch/s390/kernel/vdso/Makefile @@ -29,6 +29,7 @@ KBUILD_CFLAGS_VDSO := $(filter-out -munaligned-symbols,$(KBUILD_CFLAGS_VDSO)) KBUILD_CFLAGS_VDSO := $(filter-out -fno-asynchronous-unwind-tables,$(KBUILD_CFLAGS_VDSO)) KBUILD_CFLAGS_VDSO += -fPIC -fno-common -fno-builtin -fasynchronous-unwind-tables KBUILD_CFLAGS_VDSO += -fno-stack-protector $(DISABLE_KSTACK_ERASE) +KBUILD_CFLAGS_VDSO += $(CONFIG_CC_OPT_INLINE_MEMSET) ldflags-y := -shared -soname=linux-vdso.so.1 \ --hash-style=both --build-id=sha1 \ $(call ld-option, --eh-frame-hdr) -T diff --git a/arch/x86/entry/vdso/vdso64/Makefile b/arch/x86/entry/vdso/vdso64/Makefile index 7c0790065b5e..c2353a065279 100644 --- a/arch/x86/entry/vdso/vdso64/Makefile +++ b/arch/x86/entry/vdso/vdso64/Makefile @@ -14,7 +14,7 @@ vobjs-$(CONFIG_X86_SGX) += vsgx.o vobjs-$(CONFIG_FUTEX_ROBUST_UNLOCK) += vfutex.o # Compilation flags -flags-y := -DBUILD_VDSO64 -m64 -mcmodel=small +flags-y := -DBUILD_VDSO64 -m64 -mcmodel=small $(CONFIG_CC_OPT_INLINE_MEMSET) # The location of this include matters! include $(src)/../common/Makefile.include diff --git a/init/Kconfig b/init/Kconfig index 8583d9f06c52..98d8d7fa64c5 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -173,6 +173,11 @@ config CC_HAS_ALLOC_TOKEN config CC_HAS_MULTIDIMENSIONAL_NONSTRING def_bool $(success,echo 'char tag[][4] __attribute__((__nonstring__)) = { };' | $(CC) $(CLANG_FLAGS) -x c - -c -o /dev/null -Werror) +config CC_OPT_INLINE_MEMSET + string + default "-finline-stringops=memset" if $(cc-option,-finline-stringops=memset) + default "-mllvm -max-store-memset=4294967295" if $(cc-option,-mllvm -max-store-memset=4294967295) + config LD_CAN_USE_KEEP_IN_OVERLAY # ld.lld prior to 21.0.0 did not support KEEP within an overlay description # https://github.com/llvm/llvm-project/pull/130661 -- Cheers, Nathan ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-10-01 10:20 ` Nathan Chancellor @ 2026-10-01 10:48 ` Jason A. Donenfeld 2026-10-01 11:03 ` Nathan Chancellor 2026-10-02 9:18 ` Christophe Leroy (CS GROUP) 0 siblings, 2 replies; 37+ messages in thread From: Jason A. Donenfeld @ 2026-10-01 10:48 UTC (permalink / raw) To: Nathan Chancellor Cc: Christophe Leroy (CS GROUP), Nick Desaulniers, Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Vincenzo Frascino, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm On Thu, Oct 01, 2026 at 12:20:59PM +0200, Nathan Chancellor wrote: > control. The change that introduced -max-store-memset only did it to > "allow fine-tuning of the inlining threshold for performance analysis > and optimization". If they decide to remove it for whatever reason, > we're back to square one. I suppose all the more reason to get -finline-stringops=memset added to clang. Then the dual-default thing you came up with below will naturally start choosing the first option when it becomes available. > I know something like below would be uglier due to the ifdef but it > would avoid changing anything for GCC while clearing up the issue at > hand for clang in a guaranteed stable and succinct manner. But then we're back to the byte-by-byte codegen that Christophe pointed out. > If that is not acceptable, something like the following does appear to > work for me. Okay, great, let's do that. Does this commit seem okay with you? I used the diff you sent below and adjusted the commit message: https://git.zx2c4.com/linux-rng/commit/?id=56ff95ee85715047eb5b5220243778af657778c8 Jason ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-10-01 10:48 ` Jason A. Donenfeld @ 2026-10-01 11:03 ` Nathan Chancellor 2026-10-02 9:49 ` Nathan Chancellor 2026-10-02 9:18 ` Christophe Leroy (CS GROUP) 1 sibling, 1 reply; 37+ messages in thread From: Nathan Chancellor @ 2026-10-01 11:03 UTC (permalink / raw) To: Jason A. Donenfeld Cc: Christophe Leroy (CS GROUP), Nick Desaulniers, Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Vincenzo Frascino, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm On Thu, Oct 01, 2026 at 12:48:10PM +0200, Jason A. Donenfeld wrote: > On Thu, Oct 01, 2026 at 12:20:59PM +0200, Nathan Chancellor wrote: > > control. The change that introduced -max-store-memset only did it to > > "allow fine-tuning of the inlining threshold for performance analysis > > and optimization". If they decide to remove it for whatever reason, > > we're back to square one. > > I suppose all the more reason to get -finline-stringops=memset added to > clang. Then the dual-default thing you came up with below will naturally > start choosing the first option when it becomes available. Fair point, I can file an issue with LLVM upstream. > > I know something like below would be uglier due to the ifdef but it > > would avoid changing anything for GCC while clearing up the issue at > > hand for clang in a guaranteed stable and succinct manner. > > But then we're back to the byte-by-byte codegen that Christophe pointed > out. I thought that was only because the fallback memset_inline() from v2 was doing a byte-by-byte initialization? With my suggested diff, nothing should change for GCC, as it does not have __builtin_memset_inline(), so the "Before the patch" code generation that Christophe showed should still be present. > > If that is not acceptable, something like the following does appear to > > work for me. > > Okay, great, let's do that. > > Does this commit seem okay with you? I used the diff you sent below and > adjusted the commit message: https://git.zx2c4.com/linux-rng/commit/?id=56ff95ee85715047eb5b5220243778af657778c8 Yeah, that seems fine to me, thanks for taking care of it! -- Cheers, Nathan ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-10-01 11:03 ` Nathan Chancellor @ 2026-10-02 9:49 ` Nathan Chancellor 2026-10-02 10:13 ` Jason A. Donenfeld 0 siblings, 1 reply; 37+ messages in thread From: Nathan Chancellor @ 2026-10-02 9:49 UTC (permalink / raw) To: Jason A. Donenfeld Cc: Christophe Leroy (CS GROUP), Nick Desaulniers, Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Vincenzo Frascino, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm On Thu, Oct 01, 2026 at 01:03:10PM +0200, Nathan Chancellor wrote: > On Thu, Oct 01, 2026 at 12:48:10PM +0200, Jason A. Donenfeld wrote: > > Does this commit seem okay with you? I used the diff you sent below and > > adjusted the commit message: https://git.zx2c4.com/linux-rng/commit/?id=56ff95ee85715047eb5b5220243778af657778c8 > > Yeah, that seems fine to me, thanks for taking care of it! Can you adjust the LLVM value by one from 4294967295 to 4294967294? ~0U is actually a special value, so we hit an assertion in the SystemZ backend. https://github.com/llvm/llvm-project/blob/3f48e22a1f321d5d3341bd812803694cea588785/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp#L9547 https://github.com/llvm/llvm-project/blob/3f48e22a1f321d5d3341bd812803694cea588785/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp#L1470-L1471 clang: llvm/lib/Target/SystemZ/SystemZISelLowering.cpp:1471: virtual bool llvm::SystemZTargetLowering::findOptimalMemOpLowering(LLVMContext &, std::vector<EVT> &, unsigned int, const MemOp &, unsigned int, unsigned int, const AttributeList &, EVT *) const: Assertion `Limit != ~0U && "Expected EmitTargetCodeForMemXXX() to handle AlwaysInline cases."' failed. PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and dumped files. Stack dump: 0. Program arguments: ... 1. <eof> parser at end of file 2. Code generation 3. Running pass 'Function Pass Manager' on module 'arch/s390/kernel/vdso/vgetrandom.c'. 4. Running pass 'SystemZ DAG->DAG Pattern Instruction Selection' on function '@__kernel_getrandom' ... -- Cheers, Nathan ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-10-02 9:49 ` Nathan Chancellor @ 2026-10-02 10:13 ` Jason A. Donenfeld 2026-10-02 18:21 ` Christophe Leroy (CS GROUP) 0 siblings, 1 reply; 37+ messages in thread From: Jason A. Donenfeld @ 2026-10-02 10:13 UTC (permalink / raw) To: Nathan Chancellor Cc: Christophe Leroy (CS GROUP), Nick Desaulniers, Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Vincenzo Frascino, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm On Fri, Oct 02, 2026 at 11:49:32AM +0200, Nathan Chancellor wrote: > On Thu, Oct 01, 2026 at 01:03:10PM +0200, Nathan Chancellor wrote: > > On Thu, Oct 01, 2026 at 12:48:10PM +0200, Jason A. Donenfeld wrote: > > > Does this commit seem okay with you? I used the diff you sent below and > > > adjusted the commit message: https://git.zx2c4.com/linux-rng/commit/?id=56ff95ee85715047eb5b5220243778af657778c8 > > > > Yeah, that seems fine to me, thanks for taking care of it! > > Can you adjust the LLVM value by one from 4294967295 to 4294967294? ~0U > is actually a special value, so we hit an assertion in the SystemZ > backend. > > https://github.com/llvm/llvm-project/blob/3f48e22a1f321d5d3341bd812803694cea588785/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp#L9547 > https://github.com/llvm/llvm-project/blob/3f48e22a1f321d5d3341bd812803694cea588785/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp#L1470-L1471 > > clang: llvm/lib/Target/SystemZ/SystemZISelLowering.cpp:1471: virtual bool llvm::SystemZTargetLowering::findOptimalMemOpLowering(LLVMContext &, std::vector<EVT> &, unsigned int, const MemOp &, unsigned int, unsigned int, const AttributeList &, EVT *) const: Assertion `Limit != ~0U && "Expected EmitTargetCodeForMemXXX() to handle AlwaysInline cases."' failed. > PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and dumped files. > Stack dump: > 0. Program arguments: ... > 1. <eof> parser at end of file > 2. Code generation > 3. Running pass 'Function Pass Manager' on module 'arch/s390/kernel/vdso/vgetrandom.c'. > 4. Running pass 'SystemZ DAG->DAG Pattern Instruction Selection' on function '@__kernel_getrandom' > ... Holy smokes. Sure, fixed: https://git.zx2c4.com/linux-rng/commit/?id=eb13a1ff271b0d180687eebb30611b0b276d5193 From eb13a1ff271b0d180687eebb30611b0b276d5193 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor <nathan@kernel.org> Date: Fri, 25 Sep 2026 22:46:32 +0100 Subject: [PATCH] random: vDSO: avoid call to memset() when zeroing reserved parameter After a recent change in LLVM [1], builds with the random vDSO implementation, such as PowerPC and RISC-V, fail when checking the vDSO: arch/powerpc/kernel/vdso/vdso32.so.dbg: dynamic relocations are not supported arch/riscv/kernel/vdso/vdso.so.dbg: dynamic relocations are not supported memset() is now generated when zeroing params->reserved for some builds because LLVM has an optimization (now run in more instances) that can recognize at compile time when it is assigning a static value to a contiguous area of memory and turn that into a call to memset(). Both clang and GCC assume memset() is always available [2]. Clang has an internal fiddly hook, -max-store-memset, which we can set to a high number, to disable generating out of line memset calls [3]. Similarly, GCC has -finline-stringops=memset to do the same [4], should this issue ever hit future version of GCC. While these options wouldn't make sense for normal kernel code, it is fine for the extremely limited and intentionally compact vDSO code. Link: https://github.com/llvm/llvm-project/commit/90cebef1411617fc3eedd359bdf00cb44b1c2439 [1] Link: https://gcc.gnu.org/onlinedocs/gcc-16.2.0/gcc/Standards.html#index-ffreestanding [2] Link: https://github.com/llvm/llvm-project/commit/b28eeb28bea39148738dc375e8a97072a1907e64 [3] Link: https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-finline-stringops [4] Closes: https://github.com/ClangBuiltLinux/linux/issues/2183 Cc: stable@vger.kernel.org # v6.12+ Signed-off-by: Nathan Chancellor <nathan@kernel.org> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- arch/arm64/kernel/vdso/Makefile | 2 +- arch/loongarch/vdso/Makefile | 1 + arch/powerpc/kernel/vdso/Makefile | 1 + arch/riscv/kernel/vdso/Makefile | 1 + arch/s390/kernel/vdso/Makefile | 1 + arch/x86/entry/vdso/vdso64/Makefile | 2 +- init/Kconfig | 5 +++++ 7 files changed, 11 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/vdso/Makefile b/arch/arm64/kernel/vdso/Makefile index 7dec05dd33b7..f6619e1cb2ce 100644 --- a/arch/arm64/kernel/vdso/Makefile +++ b/arch/arm64/kernel/vdso/Makefile @@ -41,7 +41,7 @@ CC_FLAGS_REMOVE_VDSO := $(CC_FLAGS_FTRACE) -Os $(CC_FLAGS_SCS) \ $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) \ -Wmissing-prototypes -Wmissing-declarations -CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tables +CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tables $(CONFIG_CC_OPT_INLINE_MEMSET) CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_REMOVE_VDSO) CFLAGS_REMOVE_vgetrandom.o = $(CC_FLAGS_REMOVE_VDSO) diff --git a/arch/loongarch/vdso/Makefile b/arch/loongarch/vdso/Makefile index 9c9181bb4071..0b84892d084b 100644 --- a/arch/loongarch/vdso/Makefile +++ b/arch/loongarch/vdso/Makefile @@ -16,6 +16,7 @@ ccflags-vdso := \ $(filter -m64,$(KBUILD_CFLAGS)) \ $(filter -march=%,$(KBUILD_CFLAGS)) \ $(filter -m%-float,$(KBUILD_CFLAGS)) \ + $(CONFIG_CC_OPT_INLINE_MEMSET) \ $(CLANG_FLAGS) \ -D__VDSO__ diff --git a/arch/powerpc/kernel/vdso/Makefile b/arch/powerpc/kernel/vdso/Makefile index 368759f81708..0d1a49529885 100644 --- a/arch/powerpc/kernel/vdso/Makefile +++ b/arch/powerpc/kernel/vdso/Makefile @@ -43,6 +43,7 @@ ccflags-y := -fno-common -fno-builtin -DBUILD_VDSO ccflags-y += $(DISABLE_LATENT_ENTROPY_PLUGIN) ccflags-y += $(call cc-option, -fno-stack-protector) ccflags-y += -DDISABLE_BRANCH_PROFILING +ccflags-y += $(CONFIG_CC_OPT_INLINE_MEMSET) ccflags-y += -ffreestanding -fasynchronous-unwind-tables ccflags-remove-y := $(CC_FLAGS_FTRACE) ldflags-y := -Wl,--hash-style=both -nostdlib -shared -z noexecstack $(CLANG_FLAGS) diff --git a/arch/riscv/kernel/vdso/Makefile b/arch/riscv/kernel/vdso/Makefile index 8dbf2532a573..c023046a3fd7 100644 --- a/arch/riscv/kernel/vdso/Makefile +++ b/arch/riscv/kernel/vdso/Makefile @@ -36,6 +36,7 @@ endif ccflags-y := -fno-stack-protector ccflags-y += -DDISABLE_BRANCH_PROFILING ccflags-y += -fno-builtin +ccflags-y += $(CONFIG_CC_OPT_INLINE_MEMSET) ccflags-y += $(KBUILD_BASE_ISA)$(CFI_MARCH) ccflags-y += $(CFI_FULL) asflags-y += $(KBUILD_BASE_ISA)$(CFI_MARCH) diff --git a/arch/s390/kernel/vdso/Makefile b/arch/s390/kernel/vdso/Makefile index 35c834b895ec..54bcf2984ca1 100644 --- a/arch/s390/kernel/vdso/Makefile +++ b/arch/s390/kernel/vdso/Makefile @@ -29,6 +29,7 @@ KBUILD_CFLAGS_VDSO := $(filter-out -munaligned-symbols,$(KBUILD_CFLAGS_VDSO)) KBUILD_CFLAGS_VDSO := $(filter-out -fno-asynchronous-unwind-tables,$(KBUILD_CFLAGS_VDSO)) KBUILD_CFLAGS_VDSO += -fPIC -fno-common -fno-builtin -fasynchronous-unwind-tables KBUILD_CFLAGS_VDSO += -fno-stack-protector $(DISABLE_KSTACK_ERASE) +KBUILD_CFLAGS_VDSO += $(CONFIG_CC_OPT_INLINE_MEMSET) ldflags-y := -shared -soname=linux-vdso.so.1 \ --hash-style=both --build-id=sha1 \ $(call ld-option, --eh-frame-hdr) -T diff --git a/arch/x86/entry/vdso/vdso64/Makefile b/arch/x86/entry/vdso/vdso64/Makefile index 7c0790065b5e..c2353a065279 100644 --- a/arch/x86/entry/vdso/vdso64/Makefile +++ b/arch/x86/entry/vdso/vdso64/Makefile @@ -14,7 +14,7 @@ vobjs-$(CONFIG_X86_SGX) += vsgx.o vobjs-$(CONFIG_FUTEX_ROBUST_UNLOCK) += vfutex.o # Compilation flags -flags-y := -DBUILD_VDSO64 -m64 -mcmodel=small +flags-y := -DBUILD_VDSO64 -m64 -mcmodel=small $(CONFIG_CC_OPT_INLINE_MEMSET) # The location of this include matters! include $(src)/../common/Makefile.include diff --git a/init/Kconfig b/init/Kconfig index 8583d9f06c52..ad592fdf29af 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -173,6 +173,11 @@ config CC_HAS_ALLOC_TOKEN config CC_HAS_MULTIDIMENSIONAL_NONSTRING def_bool $(success,echo 'char tag[][4] __attribute__((__nonstring__)) = { };' | $(CC) $(CLANG_FLAGS) -x c - -c -o /dev/null -Werror) +config CC_OPT_INLINE_MEMSET + string + default "-finline-stringops=memset" if $(cc-option,-finline-stringops=memset) + default "-mllvm -max-store-memset=4294967294" if $(cc-option,-mllvm -max-store-memset=4294967294) + config LD_CAN_USE_KEEP_IN_OVERLAY # ld.lld prior to 21.0.0 did not support KEEP within an overlay description # https://github.com/llvm/llvm-project/pull/130661 -- 2.55.0 ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-10-02 10:13 ` Jason A. Donenfeld @ 2026-10-02 18:21 ` Christophe Leroy (CS GROUP) 0 siblings, 0 replies; 37+ messages in thread From: Christophe Leroy (CS GROUP) @ 2026-10-02 18:21 UTC (permalink / raw) To: Jason A. Donenfeld, Nathan Chancellor Cc: Nick Desaulniers, Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Vincenzo Frascino, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm Le 02/10/2026 à 12:13, Jason A. Donenfeld a écrit : > On Fri, Oct 02, 2026 at 11:49:32AM +0200, Nathan Chancellor wrote: >> On Thu, Oct 01, 2026 at 01:03:10PM +0200, Nathan Chancellor wrote: >>> On Thu, Oct 01, 2026 at 12:48:10PM +0200, Jason A. Donenfeld wrote: >>>> Does this commit seem okay with you? I used the diff you sent below and >>>> adjusted the commit message: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.zx2c4.com%2Flinux-rng%2Fcommit%2F%3Fid%3D56ff95ee85715047eb5b5220243778af657778c8&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4caf8956c2d94439c19a08df206dd40b%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639265328227648970%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=H27VGYLdNkvQiA6l%2BJNnEModMbEySwTMXpLAt8iAFiI%3D&reserved=0 >>> >>> Yeah, that seems fine to me, thanks for taking care of it! >> >> Can you adjust the LLVM value by one from 4294967295 to 4294967294? ~0U >> is actually a special value, so we hit an assertion in the SystemZ >> backend. >> >> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fllvm%2Fllvm-project%2Fblob%2F3f48e22a1f321d5d3341bd812803694cea588785%2Fllvm%2Flib%2FCodeGen%2FSelectionDAG%2FSelectionDAG.cpp%23L9547&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4caf8956c2d94439c19a08df206dd40b%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639265328227670583%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=u8petgY9wU9ur%2By4kaOrb6VFKL%2FNf4tcCIUL%2BcUcDfs%3D&reserved=0 >> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fllvm%2Fllvm-project%2Fblob%2F3f48e22a1f321d5d3341bd812803694cea588785%2Fllvm%2Flib%2FTarget%2FSystemZ%2FSystemZISelLowering.cpp%23L1470-L1471&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4caf8956c2d94439c19a08df206dd40b%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639265328227686571%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=cSwt%2BTJdYa%2Bbwe8HyO6FsIq6oU6YNplRlwCa0upif9Q%3D&reserved=0 >> >> clang: llvm/lib/Target/SystemZ/SystemZISelLowering.cpp:1471: virtual bool llvm::SystemZTargetLowering::findOptimalMemOpLowering(LLVMContext &, std::vector<EVT> &, unsigned int, const MemOp &, unsigned int, unsigned int, const AttributeList &, EVT *) const: Assertion `Limit != ~0U && "Expected EmitTargetCodeForMemXXX() to handle AlwaysInline cases."' failed. >> PLEASE submit a bug report to https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fllvm%2Fllvm-project%2Fissues%2F&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4caf8956c2d94439c19a08df206dd40b%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639265328227701575%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=%2F3q8laZb%2FDhCWp117N9EtyxLIc5lq%2FzEN2l0z%2BXwDHY%3D&reserved=0 and include the crash backtrace and dumped files. >> Stack dump: >> 0. Program arguments: ... >> 1. <eof> parser at end of file >> 2. Code generation >> 3. Running pass 'Function Pass Manager' on module 'arch/s390/kernel/vdso/vgetrandom.c'. >> 4. Running pass 'SystemZ DAG->DAG Pattern Instruction Selection' on function '@__kernel_getrandom' >> ... > > Holy smokes. Sure, fixed: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.zx2c4.com%2Flinux-rng%2Fcommit%2F%3Fid%3Deb13a1ff271b0d180687eebb30611b0b276d5193&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4caf8956c2d94439c19a08df206dd40b%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639265328227716550%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=WcnFE6S72OrDTNNvU1T06BtUTyI1sDx%2F%2Btz%2FkpGslMA%3D&reserved=0 > > > From eb13a1ff271b0d180687eebb30611b0b276d5193 Mon Sep 17 00:00:00 2001 > From: Nathan Chancellor <nathan@kernel.org> > Date: Fri, 25 Sep 2026 22:46:32 +0100 > Subject: [PATCH] random: vDSO: avoid call to memset() when zeroing reserved > parameter > > After a recent change in LLVM [1], builds with the random vDSO > implementation, such as PowerPC and RISC-V, fail when checking the vDSO: > > arch/powerpc/kernel/vdso/vdso32.so.dbg: dynamic relocations are not supported > arch/riscv/kernel/vdso/vdso.so.dbg: dynamic relocations are not supported > > memset() is now generated when zeroing params->reserved for some builds > because LLVM has an optimization (now run in more instances) that can > recognize at compile time when it is assigning a static value to a > contiguous area of memory and turn that into a call to memset(). Both > clang and GCC assume memset() is always available [2]. > > Clang has an internal fiddly hook, -max-store-memset, which we can set > to a high number, to disable generating out of line memset calls [3]. > Similarly, GCC has -finline-stringops=memset to do the same [4], should > this issue ever hit future version of GCC. While these options wouldn't > make sense for normal kernel code, it is fine for the extremely limited > and intentionally compact vDSO code. > > Link: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fllvm%2Fllvm-project%2Fcommit%2F90cebef1411617fc3eedd359bdf00cb44b1c2439&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4caf8956c2d94439c19a08df206dd40b%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639265328227732238%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=cYZ2nUalY%2F6yarydfMIlcGpDVlztXRBeg7UG7tpCO9g%3D&reserved=0 [1] > Link: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgcc.gnu.org%2Fonlinedocs%2Fgcc-16.2.0%2Fgcc%2FStandards.html%23index-ffreestanding&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4caf8956c2d94439c19a08df206dd40b%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639265328227748542%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=vRl%2BQgL5GJ0wowXAIlRIczC5XqUXyOFUvFVe5C8XWAc%3D&reserved=0 [2] > Link: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fllvm%2Fllvm-project%2Fcommit%2Fb28eeb28bea39148738dc375e8a97072a1907e64&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4caf8956c2d94439c19a08df206dd40b%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639265328227762721%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=nt59J3%2BOoiEKYGzfFfAq7WoAnEMAimt6vKDaJjhvHtg%3D&reserved=0 [3] > Link: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgcc.gnu.org%2Fonlinedocs%2Fgcc%2FOptimize-Options.html%23index-finline-stringops&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4caf8956c2d94439c19a08df206dd40b%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639265328227777215%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=fyZA9XC%2FwSAUc346VWT%2FmyeqddqeTo62dBKtiJilR9U%3D&reserved=0 [4] > Closes: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FClangBuiltLinux%2Flinux%2Fissues%2F2183&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4caf8956c2d94439c19a08df206dd40b%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639265328227792263%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=49HfUDlzn%2FLUeISQ7%2BFR5jE7lZkqfORaqjauLn8cdm0%3D&reserved=0 > Cc: stable@vger.kernel.org # v6.12+ > Signed-off-by: Nathan Chancellor <nathan@kernel.org> > Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Ok, I checked the version that is in the rng tree, namely commit eb13a1ff271b ("random: vDSO: avoid call to memset() when zeroing reserved parameter"). Looks similar to this mail. It looks ok, no change to generated loop on powerpc32 neither with gcc 13 nor gcc 16. Reviewed-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org> > --- > arch/arm64/kernel/vdso/Makefile | 2 +- > arch/loongarch/vdso/Makefile | 1 + > arch/powerpc/kernel/vdso/Makefile | 1 + > arch/riscv/kernel/vdso/Makefile | 1 + > arch/s390/kernel/vdso/Makefile | 1 + > arch/x86/entry/vdso/vdso64/Makefile | 2 +- > init/Kconfig | 5 +++++ > 7 files changed, 11 insertions(+), 2 deletions(-) > ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-10-01 10:48 ` Jason A. Donenfeld 2026-10-01 11:03 ` Nathan Chancellor @ 2026-10-02 9:18 ` Christophe Leroy (CS GROUP) 2026-10-02 9:27 ` Jason A. Donenfeld 1 sibling, 1 reply; 37+ messages in thread From: Christophe Leroy (CS GROUP) @ 2026-10-02 9:18 UTC (permalink / raw) To: Jason A. Donenfeld, Nathan Chancellor Cc: Nick Desaulniers, Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Vincenzo Frascino, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm Le 01/10/2026 à 12:48, Jason A. Donenfeld a écrit : > On Thu, Oct 01, 2026 at 12:20:59PM +0200, Nathan Chancellor wrote: >> control. The change that introduced -max-store-memset only did it to >> "allow fine-tuning of the inlining threshold for performance analysis >> and optimization". If they decide to remove it for whatever reason, >> we're back to square one. > > I suppose all the more reason to get -finline-stringops=memset added to > clang. Then the dual-default thing you came up with below will naturally > start choosing the first option when it becomes available. > >> I know something like below would be uglier due to the ifdef but it >> would avoid changing anything for GCC while clearing up the issue at >> hand for clang in a guaranteed stable and succinct manner. > > But then we're back to the byte-by-byte codegen that Christophe pointed > out. > >> If that is not acceptable, something like the following does appear to >> work for me. > > Okay, great, let's do that. > > Does this commit seem okay with you? I used the diff you sent below and > adjusted the commit message: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.zx2c4.com%2Flinux-rng%2Fcommit%2F%3Fid%3D56ff95ee85715047eb5b5220243778af657778c8&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7Cd89b4de22ff94b6be71208df1fa9839a%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639264485055490029%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=Vxf8xRCdLavtw4Dmi%2B49FY1lJDWtm%2BjKv7f8BxKTGq4%3D&reserved=0 > The commit message says: Similarly, GCC has -finline-stringops=memset to do the same [4], should this issue ever hit future version of GCC. Why default "-finline-stringops=memset" if $(cc-option,-finline-stringops=memset), have we identified cases where build fail without that or is it just for future provision ? As shown in my previous email, with GCC 16 on powerpc32 we get a slightly better code without this option. --- diff --git a/init/Kconfig b/init/Kconfig index 8583d9f06c52..98d8d7fa64c5 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -173,6 +173,11 @@ config CC_HAS_ALLOC_TOKEN config CC_HAS_MULTIDIMENSIONAL_NONSTRING def_bool $(success,echo 'char tag[][4] __attribute__((__nonstring__)) = { };' | $(CC) $(CLANG_FLAGS) -x c - -c -o /dev/null -Werror) +config CC_OPT_INLINE_MEMSET + string + default "-finline-stringops=memset" if $(cc-option,-finline-stringops=memset) + default "-mllvm -max-store-memset=4294967295" if $(cc-option,-mllvm -max-store-memset=4294967295) + config LD_CAN_USE_KEEP_IN_OVERLAY # ld.lld prior to 21.0.0 did not support KEEP within an overlay description # https://github.com/llvm/llvm-project/pull/130661 ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-10-02 9:18 ` Christophe Leroy (CS GROUP) @ 2026-10-02 9:27 ` Jason A. Donenfeld 0 siblings, 0 replies; 37+ messages in thread From: Jason A. Donenfeld @ 2026-10-02 9:27 UTC (permalink / raw) To: Christophe Leroy (CS GROUP) Cc: Nathan Chancellor, Nick Desaulniers, Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Vincenzo Frascino, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm On Fri, Oct 02, 2026 at 11:18:51AM +0200, Christophe Leroy (CS GROUP) wrote: > > > Le 01/10/2026 à 12:48, Jason A. Donenfeld a écrit : > > On Thu, Oct 01, 2026 at 12:20:59PM +0200, Nathan Chancellor wrote: > >> control. The change that introduced -max-store-memset only did it to > >> "allow fine-tuning of the inlining threshold for performance analysis > >> and optimization". If they decide to remove it for whatever reason, > >> we're back to square one. > > > > I suppose all the more reason to get -finline-stringops=memset added to > > clang. Then the dual-default thing you came up with below will naturally > > start choosing the first option when it becomes available. > > > >> I know something like below would be uglier due to the ifdef but it > >> would avoid changing anything for GCC while clearing up the issue at > >> hand for clang in a guaranteed stable and succinct manner. > > > > But then we're back to the byte-by-byte codegen that Christophe pointed > > out. > > > >> If that is not acceptable, something like the following does appear to > >> work for me. > > > > Okay, great, let's do that. > > > > Does this commit seem okay with you? I used the diff you sent below and > > adjusted the commit message: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.zx2c4.com%2Flinux-rng%2Fcommit%2F%3Fid%3D56ff95ee85715047eb5b5220243778af657778c8&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7Cd89b4de22ff94b6be71208df1fa9839a%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639264485055490029%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=Vxf8xRCdLavtw4Dmi%2B49FY1lJDWtm%2BjKv7f8BxKTGq4%3D&reserved=0 > > > > The commit message says: Similarly, GCC has -finline-stringops=memset to > do the same [4], should this issue ever hit future version of GCC. > > Why default "-finline-stringops=memset" if > $(cc-option,-finline-stringops=memset), have we identified cases where > build fail without that or is it just for future provision ? > > As shown in my previous email, with GCC 16 on powerpc32 we get a > slightly better code without this option. No, that patch tested this option + actually calling builtin_memset. This new patch has the original code of zeroing a long at a time, but has the inline memset option to prevent future GCC from recognizing that pattern and making it outline. Codegen should be the same. Jason ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-09-26 10:55 ` Christophe Leroy (CS GROUP) 2026-09-26 12:29 ` Jason A. Donenfeld @ 2026-09-26 12:39 ` Nathan Chancellor 1 sibling, 0 replies; 37+ messages in thread From: Nathan Chancellor @ 2026-09-26 12:39 UTC (permalink / raw) To: Christophe Leroy (CS GROUP) Cc: Jason A. Donenfeld, Nick Desaulniers, Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Vincenzo Frascino, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm On Sat, Sep 26, 2026 at 12:55:34PM +0200, Christophe Leroy (CS GROUP) wrote: > Le 26/09/2026 à 12:02, Jason A. Donenfeld a écrit : > > Apparently not on RISCV, which is what prompted this patch in the first > > place. So I suspect Nathan's v2 here is the way to go. > > > Don't you have -fno-builtin on RISCV like we have on powerpc ? > > Or is it clang that is missing this option ? Yes, clang has -fno-builtin but as I mention in the commit message, that may not always stop the compiler from generating calls to memset(), which it is allowed to do even with -ffreestanding (which implies -fno-builtin) per GCC's documentation. -fno-builtin with GCC < 14 just happens to avoid generating memset() for memset_inline() in all of my tests, hence why I went with this approach as suggested by Jason. -- Cheers, Nathan ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-09-25 21:46 [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() Nathan Chancellor 2026-09-25 21:53 ` Nick Desaulniers @ 2026-09-26 9:39 ` Andreas Schwab 2026-09-26 12:19 ` Nathan Chancellor 2026-10-02 10:57 ` Christophe Leroy (CS GROUP) 2 siblings, 1 reply; 37+ messages in thread From: Andreas Schwab @ 2026-09-26 9:39 UTC (permalink / raw) To: Nathan Chancellor Cc: Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Jason A. Donenfeld, Vincenzo Frascino, Nick Desaulniers, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Christophe Leroy (CS GROUP), Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm On Sep 25 2026, Nathan Chancellor wrote: > +#if __has_builtin(__builtin_memset_inline) > +#define memset_inline(dst, value, size) __builtin_memset_inline(dst, value, size) > +#elif IS_ENABLED(CONFIG_CC_HAS_OPT_INLINE_MEMSET) > +#define memset_inline(dst, value, size) __builtin_memset(dst, value, size) > +#else > +static inline void *memset_inline(void *dst, int value, size_t size) > +{ > + char *d = dst; > + > + while (size--) > + *d++ = value; > + > + return d; > +} > +#endif > + memset actually returns the original pointer, not the incremented one. Nothing uses the return value of memset_inline here, but it is confusing. -- Andreas Schwab, schwab@linux-m68k.org GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 "And now for something completely different." ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-09-26 9:39 ` Andreas Schwab @ 2026-09-26 12:19 ` Nathan Chancellor 2026-09-26 12:32 ` Jason A. Donenfeld 0 siblings, 1 reply; 37+ messages in thread From: Nathan Chancellor @ 2026-09-26 12:19 UTC (permalink / raw) To: Andreas Schwab Cc: Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Jason A. Donenfeld, Vincenzo Frascino, Nick Desaulniers, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Christophe Leroy (CS GROUP), Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm On Sat, Sep 26, 2026 at 11:39:43AM +0200, Andreas Schwab wrote: > On Sep 25 2026, Nathan Chancellor wrote: > > > +#if __has_builtin(__builtin_memset_inline) > > +#define memset_inline(dst, value, size) __builtin_memset_inline(dst, value, size) > > +#elif IS_ENABLED(CONFIG_CC_HAS_OPT_INLINE_MEMSET) > > +#define memset_inline(dst, value, size) __builtin_memset(dst, value, size) > > +#else > > +static inline void *memset_inline(void *dst, int value, size_t size) > > +{ > > + char *d = dst; > > + > > + while (size--) > > + *d++ = value; > > + > > + return d; > > +} > > +#endif > > + > > memset actually returns the original pointer, not the incremented one. > Nothing uses the return value of memset_inline here, but it is > confusing. Whoops, good catch, I guess my fingers gave up on those last two characters :) I will fix this for v3 once there has been some time for further review. -- Cheers, Nathan ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-09-26 12:19 ` Nathan Chancellor @ 2026-09-26 12:32 ` Jason A. Donenfeld 2026-09-26 12:49 ` Nathan Chancellor 2026-09-27 7:02 ` David Laight 0 siblings, 2 replies; 37+ messages in thread From: Jason A. Donenfeld @ 2026-09-26 12:32 UTC (permalink / raw) To: Nathan Chancellor Cc: Andreas Schwab, Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Vincenzo Frascino, Nick Desaulniers, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Christophe Leroy (CS GROUP), Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm On Sat, Sep 26, 2026 at 01:19:27PM +0100, Nathan Chancellor wrote: > On Sat, Sep 26, 2026 at 11:39:43AM +0200, Andreas Schwab wrote: > > On Sep 25 2026, Nathan Chancellor wrote: > > > > > +#if __has_builtin(__builtin_memset_inline) > > > +#define memset_inline(dst, value, size) __builtin_memset_inline(dst, value, size) > > > +#elif IS_ENABLED(CONFIG_CC_HAS_OPT_INLINE_MEMSET) > > > +#define memset_inline(dst, value, size) __builtin_memset(dst, value, size) > > > +#else > > > +static inline void *memset_inline(void *dst, int value, size_t size) > > > +{ > > > + char *d = dst; > > > + > > > + while (size--) > > > + *d++ = value; > > > + > > > + return d; > > > +} > > > +#endif > > > + > > > > memset actually returns the original pointer, not the incremented one. > > Nothing uses the return value of memset_inline here, but it is > > confusing. > > Whoops, good catch, I guess my fingers gave up on those last two > characters :) I will fix this for v3 once there has been some time for > further review. Do we even need to return a value at all? Might as well just make the function two lines: + for (char *d = dst; size--;) + *d++ = value; (Technically that could even be one, but maybe that sort of golf loses clarity. Your choice.) ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-09-26 12:32 ` Jason A. Donenfeld @ 2026-09-26 12:49 ` Nathan Chancellor 2026-09-27 7:02 ` David Laight 1 sibling, 0 replies; 37+ messages in thread From: Nathan Chancellor @ 2026-09-26 12:49 UTC (permalink / raw) To: Jason A. Donenfeld Cc: Andreas Schwab, Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Vincenzo Frascino, Nick Desaulniers, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Christophe Leroy (CS GROUP), Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm On Sat, Sep 26, 2026 at 02:32:49PM +0200, Jason A. Donenfeld wrote: > On Sat, Sep 26, 2026 at 01:19:27PM +0100, Nathan Chancellor wrote: > > On Sat, Sep 26, 2026 at 11:39:43AM +0200, Andreas Schwab wrote: > > > On Sep 25 2026, Nathan Chancellor wrote: > > > > > > > +#if __has_builtin(__builtin_memset_inline) > > > > +#define memset_inline(dst, value, size) __builtin_memset_inline(dst, value, size) > > > > +#elif IS_ENABLED(CONFIG_CC_HAS_OPT_INLINE_MEMSET) > > > > +#define memset_inline(dst, value, size) __builtin_memset(dst, value, size) > > > > +#else > > > > +static inline void *memset_inline(void *dst, int value, size_t size) > > > > +{ > > > > + char *d = dst; > > > > + > > > > + while (size--) > > > > + *d++ = value; > > > > + > > > > + return d; > > > > +} > > > > +#endif > > > > + > > > > > > memset actually returns the original pointer, not the incremented one. > > > Nothing uses the return value of memset_inline here, but it is > > > confusing. > > > > Whoops, good catch, I guess my fingers gave up on those last two > > characters :) I will fix this for v3 once there has been some time for > > further review. > > Do we even need to return a value at all? Might as well just make the > function two lines: > > + for (char *d = dst; size--;) > + *d++ = value; Yeah, good point, no point in returning something that we don't need plus this is basically what we had before, just with a different pointer type. Thanks for the suggestion. > (Technically that could even be one, but maybe that sort of golf loses > clarity. Your choice.) I'll keep it two lines just for the sake of clarity. -- Cheers, Nathan ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-09-26 12:32 ` Jason A. Donenfeld 2026-09-26 12:49 ` Nathan Chancellor @ 2026-09-27 7:02 ` David Laight 2026-09-29 16:59 ` Nathan Chancellor 1 sibling, 1 reply; 37+ messages in thread From: David Laight @ 2026-09-27 7:02 UTC (permalink / raw) To: Jason A. Donenfeld Cc: Nathan Chancellor, Andreas Schwab, Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Vincenzo Frascino, Nick Desaulniers, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Christophe Leroy (CS GROUP), Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm On Sat, 26 Sep 2026 14:32:49 +0200 "Jason A. Donenfeld" <Jason@zx2c4.com> wrote: > On Sat, Sep 26, 2026 at 01:19:27PM +0100, Nathan Chancellor wrote: > > On Sat, Sep 26, 2026 at 11:39:43AM +0200, Andreas Schwab wrote: > > > On Sep 25 2026, Nathan Chancellor wrote: > > > > > > > +#if __has_builtin(__builtin_memset_inline) > > > > +#define memset_inline(dst, value, size) __builtin_memset_inline(dst, value, size) > > > > +#elif IS_ENABLED(CONFIG_CC_HAS_OPT_INLINE_MEMSET) > > > > +#define memset_inline(dst, value, size) __builtin_memset(dst, value, size) > > > > +#else > > > > +static inline void *memset_inline(void *dst, int value, size_t size) > > > > +{ > > > > + char *d = dst; > > > > + > > > > + while (size--) > > > > + *d++ = value; > > > > + > > > > + return d; > > > > +} > > > > +#endif > > > > + > > > > > > memset actually returns the original pointer, not the incremented one. > > > Nothing uses the return value of memset_inline here, but it is > > > confusing. > > > > Whoops, good catch, I guess my fingers gave up on those last two > > characters :) I will fix this for v3 once there has been some time for > > further review. > > Do we even need to return a value at all? Might as well just make the > function two lines: > > + for (char *d = dst; size--;) > + *d++ = value; Wouldn't it be better to add a barrier() or similar in there to stop the compiler playing unwanted games> David > > (Technically that could even be one, but maybe that sort of golf loses > clarity. Your choice.) > ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-09-27 7:02 ` David Laight @ 2026-09-29 16:59 ` Nathan Chancellor 2026-09-29 17:44 ` David Laight 0 siblings, 1 reply; 37+ messages in thread From: Nathan Chancellor @ 2026-09-29 16:59 UTC (permalink / raw) To: David Laight Cc: Jason A. Donenfeld, Andreas Schwab, Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Vincenzo Frascino, Nick Desaulniers, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Christophe Leroy (CS GROUP), Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm On Sun, Sep 27, 2026 at 08:02:25AM +0100, David Laight wrote: > On Sat, 26 Sep 2026 14:32:49 +0200 > "Jason A. Donenfeld" <Jason@zx2c4.com> wrote: > > Do we even need to return a value at all? Might as well just make the > > function two lines: > > > > + for (char *d = dst; size--;) > > + *d++ = value; > > Wouldn't it be better to add a barrier() or similar in there to > stop the compiler playing unwanted games> Wouldn't that just result in the same code generation issue that Jason pointed out on my v1? https://lore.kernel.org/aquyVkdYceiWdckX@zx2c4.com/ Maybe that doesn't matter because modern compilers have better options? -- Cheers, Nathan ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-09-29 16:59 ` Nathan Chancellor @ 2026-09-29 17:44 ` David Laight 0 siblings, 0 replies; 37+ messages in thread From: David Laight @ 2026-09-29 17:44 UTC (permalink / raw) To: Nathan Chancellor Cc: Jason A. Donenfeld, Andreas Schwab, Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Vincenzo Frascino, Nick Desaulniers, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Christophe Leroy (CS GROUP), Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm On Tue, 29 Sep 2026 18:59:39 +0200 Nathan Chancellor <nathan@kernel.org> wrote: > On Sun, Sep 27, 2026 at 08:02:25AM +0100, David Laight wrote: > > On Sat, 26 Sep 2026 14:32:49 +0200 > > "Jason A. Donenfeld" <Jason@zx2c4.com> wrote: > > > Do we even need to return a value at all? Might as well just make the > > > function two lines: > > > > > > + for (char *d = dst; size--;) > > > + *d++ = value; > > > > Wouldn't it be better to add a barrier() or similar in there to > > stop the compiler playing unwanted games> > > Wouldn't that just result in the same code generation issue that Jason > pointed out on my v1? > > https://lore.kernel.org/aquyVkdYceiWdckX@zx2c4.com/ I missed that one going past.... You only get 'rep stosq' because the compiler first converts it to memset(). > Maybe that doesn't matter because modern compilers have better options? A lot of cpu will run the 'rep stosq' very slowly (it has a big fixed cost). At a guess the loop is 3 clocks (possibly 2; but that usually needs you to use negative offsets from the end - and gcc doesn't like that). That is comparable to a mispredicted branch (and you might get two of them). It still might actually be faster than the 'rep stosq' version! I suspect the fastest code is to unroll the loop. xor %eax, %eax movl %eax, 12(%rbx) movq %rax, 16(%rbx) movq %rax, 24(%rbx) movq %rax, 32(%rbx) movq %rax, 40(%rbx) movq %rax, 48(%rbx) movq %rax, 56(%rbx) 8 clocks on old cpu, 4 on newer ones. But more likely to be limited be I-cache reads. If you are going to use 'rep stos' then you might as well write 13 32bit words. David ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-09-25 21:46 [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() Nathan Chancellor 2026-09-25 21:53 ` Nick Desaulniers 2026-09-26 9:39 ` Andreas Schwab @ 2026-10-02 10:57 ` Christophe Leroy (CS GROUP) 2026-10-02 10:58 ` Jason A. Donenfeld 2 siblings, 1 reply; 37+ messages in thread From: Christophe Leroy (CS GROUP) @ 2026-10-02 10:57 UTC (permalink / raw) To: Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Jason A. Donenfeld, Nathan Chancellor Cc: Christophe Leroy, Vincenzo Frascino, Nick Desaulniers, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm On Fri, 25 Sep 2026 22:46:32 +0100, Nathan Chancellor wrote: > After a recent change in LLVM [1], builds with the random vDSO > implementation, such as PowerPC and RISC-V, fail when checking the vDSO: > > arch/powerpc/kernel/vdso/vdso32.so.dbg: dynamic relocations are not supported > arch/riscv/kernel/vdso/vdso.so.dbg: dynamic relocations are not supported > > memset() is now generated when zeroing params->reserved for some builds > because LLVM has an optimization (now run in more instances) that can > recognize at compile time when it is assigning a static value to a > contiguous area of memory and turn that into a call to memset(). Both > clang and GCC assume memset() is always available [2]. > > [...] Applied, thanks! [1/1] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() (no commit info) Best regards, -- Christophe Leroy (CS GROUP) <chleroy@kernel.org> ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-10-02 10:57 ` Christophe Leroy (CS GROUP) @ 2026-10-02 10:58 ` Jason A. Donenfeld 2026-10-02 11:01 ` LEROY Christophe 2026-10-02 11:02 ` Christophe Leroy (CS GROUP) 0 siblings, 2 replies; 37+ messages in thread From: Jason A. Donenfeld @ 2026-10-02 10:58 UTC (permalink / raw) To: Christophe Leroy (CS GROUP) Cc: Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Nathan Chancellor, Vincenzo Frascino, Nick Desaulniers, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm On Fri, Oct 2, 2026 at 12:57 PM Christophe Leroy (CS GROUP) <chleroy@kernel.org> wrote: > > > On Fri, 25 Sep 2026 22:46:32 +0100, Nathan Chancellor wrote: > > After a recent change in LLVM [1], builds with the random vDSO > > implementation, such as PowerPC and RISC-V, fail when checking the vDSO: > > > > arch/powerpc/kernel/vdso/vdso32.so.dbg: dynamic relocations are not supported > > arch/riscv/kernel/vdso/vdso.so.dbg: dynamic relocations are not supported > > > > memset() is now generated when zeroing params->reserved for some builds > > because LLVM has an optimization (now run in more instances) that can > > recognize at compile time when it is assigning a static value to a > > contiguous area of memory and turn that into a call to memset(). Both > > clang and GCC assume memset() is always available [2]. > > > > [...] > > Applied, thanks! > > [1/1] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() > (no commit info) That's not for you to apply. I'm sending this through my random tree, along with a handful of other things I need to fix. But I wanted to let this cook a bit more. I can add your reviewed-by line, though. Jason ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-10-02 10:58 ` Jason A. Donenfeld @ 2026-10-02 11:01 ` LEROY Christophe 2026-10-02 11:02 ` Christophe Leroy (CS GROUP) 1 sibling, 0 replies; 37+ messages in thread From: LEROY Christophe @ 2026-10-02 11:01 UTC (permalink / raw) To: Jason A. Donenfeld, Christophe Leroy (CS GROUP) Cc: Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Nathan Chancellor, Vincenzo Frascino, Nick Desaulniers, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm Le 02/10/2026 à 12:58, Jason A. Donenfeld a écrit : > On Fri, Oct 2, 2026 at 12:57 PM Christophe Leroy (CS GROUP) > <chleroy@kernel.org> wrote: >> >> >> On Fri, 25 Sep 2026 22:46:32 +0100, Nathan Chancellor wrote: >>> After a recent change in LLVM [1], builds with the random vDSO >>> implementation, such as PowerPC and RISC-V, fail when checking the vDSO: >>> >>> arch/powerpc/kernel/vdso/vdso32.so.dbg: dynamic relocations are not supported >>> arch/riscv/kernel/vdso/vdso.so.dbg: dynamic relocations are not supported >>> >>> memset() is now generated when zeroing params->reserved for some builds >>> because LLVM has an optimization (now run in more instances) that can >>> recognize at compile time when it is assigning a static value to a >>> contiguous area of memory and turn that into a call to memset(). Both >>> clang and GCC assume memset() is always available [2]. >>> >>> [...] >> >> Applied, thanks! >> >> [1/1] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() >> (no commit info) > > That's not for you to apply. I'm sending this through my random tree, > along with a handful of other things I need to fix. But I wanted to > let this cook a bit more. I can add your reviewed-by line, though. Sorry I messed up with 'b4 ty', I do not intent to take this patch in my tree. ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() 2026-10-02 10:58 ` Jason A. Donenfeld 2026-10-02 11:01 ` LEROY Christophe @ 2026-10-02 11:02 ` Christophe Leroy (CS GROUP) 1 sibling, 0 replies; 37+ messages in thread From: Christophe Leroy (CS GROUP) @ 2026-10-02 11:02 UTC (permalink / raw) To: Jason A. Donenfeld Cc: Andy Lutomirski, Thomas Gleixner, Theodore Ts'o, Nathan Chancellor, Vincenzo Frascino, Nick Desaulniers, Bill Wendling, Justin Stitt, Catalin Marinas, Will Deacon, Mark Rutland, Huacai Chen, WANG Xuerui, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, linux-arm-kernel, linux-kernel, loongarch, linuxppc-dev, linux-riscv, linux-s390, llvm Le 02/10/2026 à 12:58, Jason A. Donenfeld a écrit : > On Fri, Oct 2, 2026 at 12:57 PM Christophe Leroy (CS GROUP) > <chleroy@kernel.org> wrote: >> >> >> On Fri, 25 Sep 2026 22:46:32 +0100, Nathan Chancellor wrote: >>> After a recent change in LLVM [1], builds with the random vDSO >>> implementation, such as PowerPC and RISC-V, fail when checking the vDSO: >>> >>> arch/powerpc/kernel/vdso/vdso32.so.dbg: dynamic relocations are not supported >>> arch/riscv/kernel/vdso/vdso.so.dbg: dynamic relocations are not supported >>> >>> memset() is now generated when zeroing params->reserved for some builds >>> because LLVM has an optimization (now run in more instances) that can >>> recognize at compile time when it is assigning a static value to a >>> contiguous area of memory and turn that into a call to memset(). Both >>> clang and GCC assume memset() is always available [2]. >>> >>> [...] >> >> Applied, thanks! >> >> [1/1] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() >> (no commit info) > > That's not for you to apply. I'm sending this through my random tree, > along with a handful of other things I need to fix. But I wanted to > let this cook a bit more. I can add your reviewed-by line, though. Sorry I messed up with 'b4 ty', I do not intent to take this patch in my tree. ^ permalink raw reply [flat|nested] 37+ messages in thread
end of thread, other threads:[~2026-10-02 18:22 UTC | newest] Thread overview: 37+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2026-09-25 21:46 [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data() Nathan Chancellor 2026-09-25 21:53 ` Nick Desaulniers 2026-09-25 21:56 ` Nick Desaulniers 2026-09-25 22:00 ` Nick Desaulniers 2026-09-25 22:19 ` Nathan Chancellor 2026-09-26 6:34 ` Christophe Leroy (CS GROUP) 2026-09-26 10:02 ` Jason A. Donenfeld 2026-09-26 10:55 ` Christophe Leroy (CS GROUP) 2026-09-26 12:29 ` Jason A. Donenfeld 2026-09-29 18:24 ` Nick Desaulniers 2026-09-30 13:38 ` Nathan Chancellor 2026-09-30 14:21 ` Jason A. Donenfeld 2026-09-30 14:44 ` Jason A. Donenfeld 2026-09-30 15:13 ` Nathan Chancellor 2026-09-30 15:16 ` Jason A. Donenfeld 2026-10-01 4:41 ` Christophe Leroy (CS GROUP) 2026-10-01 9:25 ` Jason A. Donenfeld 2026-10-01 10:20 ` Nathan Chancellor 2026-10-01 10:48 ` Jason A. Donenfeld 2026-10-01 11:03 ` Nathan Chancellor 2026-10-02 9:49 ` Nathan Chancellor 2026-10-02 10:13 ` Jason A. Donenfeld 2026-10-02 18:21 ` Christophe Leroy (CS GROUP) 2026-10-02 9:18 ` Christophe Leroy (CS GROUP) 2026-10-02 9:27 ` Jason A. Donenfeld 2026-09-26 12:39 ` Nathan Chancellor 2026-09-26 9:39 ` Andreas Schwab 2026-09-26 12:19 ` Nathan Chancellor 2026-09-26 12:32 ` Jason A. Donenfeld 2026-09-26 12:49 ` Nathan Chancellor 2026-09-27 7:02 ` David Laight 2026-09-29 16:59 ` Nathan Chancellor 2026-09-29 17:44 ` David Laight 2026-10-02 10:57 ` Christophe Leroy (CS GROUP) 2026-10-02 10:58 ` Jason A. Donenfeld 2026-10-02 11:01 ` LEROY Christophe 2026-10-02 11:02 ` Christophe Leroy (CS GROUP)
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®