mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nathan Chancellor <nathan@kernel.org>
To: Andy Lutomirski <luto@kernel.org>,
	Thomas Gleixner <tglx@kernel.org>,  Theodore Ts'o <tytso@mit.edu>,
	"Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>,
	 Nick Desaulniers <ndesaulniers@google.com>,
	 Bill Wendling <morbo@google.com>,
	Justin Stitt <justinstitt@google.com>,
	 linux-kernel@vger.kernel.org, llvm@lists.linux.dev,
	 Nathan Chancellor <nathan@kernel.org>
Subject: [PATCH] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data()
Date: Wed, 16 Sep 2026 14:58:44 -0700	[thread overview]
Message-ID: <20260916-vdso-getrandom-avoid-memset-llvm-24-v1-1-80a92f2e225a@kernel.org> (raw)

After a recent change in LLVM [1], RISC-V builds fail when checking the
vDSO:

  arch/riscv/kernel/vdso/vdso.so.dbg: dynamic relocations are not supported
  make[4]: *** [arch/riscv/kernel/vdso/Makefile:78: arch/riscv/kernel/vdso/vdso.so.dbg] Error 1

memset() is now generated when zeroing params->reserved 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].

Hide the value of the iterator variable from the optimizer using
OPTIMIZER_HIDE_VAR to inhibit this optimization since it can no longer
assume that the zeroing is contiguous.

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]
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
 lib/vdso/getrandom.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/vdso/getrandom.c b/lib/vdso/getrandom.c
index 2851afa9154f..d48d1fdb3351 100644
--- a/lib/vdso/getrandom.c
+++ b/lib/vdso/getrandom.c
@@ -4,6 +4,7 @@
  */
 
 #include <linux/array_size.h>
+#include <linux/compiler.h>
 #include <linux/minmax.h>
 #include <vdso/datapage.h>
 #include <vdso/getrandom.h>
@@ -83,8 +84,11 @@ __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)
+		for (size_t i = 0; i < ARRAY_SIZE(params->reserved); ++i) {
+			/* prevent compiler from turning loop into memset() */
+			OPTIMIZER_HIDE_VAR(i);
 			params->reserved[i] = 0;
+		}
 		return 0;
 	}
 

---
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
change-id: 20260916-vdso-getrandom-avoid-memset-llvm-24-74d45fa6031e

Best regards,
--  
Cheers,
Nathan


             reply	other threads:[~2026-09-16 21:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-16 21:58 Nathan Chancellor [this message]
2026-09-16 22:08 ` Nick Desaulniers
2026-09-16 22:57   ` Nathan Chancellor
2026-09-16 23:40     ` Nick Desaulniers
2026-09-17  9:26 ` Jason A. Donenfeld
2026-09-17 17:39   ` Nathan Chancellor
2026-09-17 22:49     ` Nick Desaulniers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260916-vdso-getrandom-avoid-memset-llvm-24-v1-1-80a92f2e225a@kernel.org \
    --to=nathan@kernel.org \
    --cc=Jason@zx2c4.com \
    --cc=justinstitt@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=luto@kernel.org \
    --cc=morbo@google.com \
    --cc=ndesaulniers@google.com \
    --cc=tglx@kernel.org \
    --cc=tytso@mit.edu \
    --cc=vincenzo.frascino@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®