From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: "Christophe Leroy (CS GROUP)" <chleroy@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Andy Lutomirski <luto@kernel.org>,
Thomas Gleixner <tglx@kernel.org>, Theodore Ts'o <tytso@mit.edu>,
Vincenzo Frascino <vincenzo.frascino@arm.com>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Huacai Chen <chenhuacai@kernel.org>,
WANG Xuerui <kernel@xen0n.name>,
Madhavan Srinivasan <maddy@linux.ibm.com>,
Michael Ellerman <mpe@ellerman.id.au>,
Nicholas Piggin <npiggin@gmail.com>,
Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>,
Heiko Carstens <hca@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
Alexander Gordeev <agordeev@linux.ibm.com>,
Christian Borntraeger <borntraeger@linux.ibm.com>,
Sven Schnelle <svens@linux.ibm.com>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
"H. Peter Anvin" <hpa@zytor.com>,
x86@kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, loongarch@lists.linux.dev,
linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org,
linux-s390@vger.kernel.org, llvm@lists.linux.dev
Subject: Re: [PATCH v2] random: vDSO: Avoid call to memset() when zeroing reserved in __cvdso_getrandom_data()
Date: Thu, 1 Oct 2026 11:25:35 +0200 [thread overview]
Message-ID: <ar4nD8aRH7wEvTMt@zx2c4.com> (raw)
In-Reply-To: <ede392d7-3104-4a0f-9fa1-99b22552dcd6@kernel.org>
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
next prev parent reply other threads:[~2026-10-01 9:25 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-25 21:46 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 [this message]
2026-10-01 10:20 ` Nathan Chancellor
2026-10-01 10:48 ` Jason A. Donenfeld
2026-10-01 11:03 ` Nathan Chancellor
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
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=ar4nD8aRH7wEvTMt@zx2c4.com \
--to=jason@zx2c4.com \
--cc=agordeev@linux.ibm.com \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=borntraeger@linux.ibm.com \
--cc=bp@alien8.de \
--cc=catalin.marinas@arm.com \
--cc=chenhuacai@kernel.org \
--cc=chleroy@kernel.org \
--cc=dave.hansen@linux.intel.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=hpa@zytor.com \
--cc=justinstitt@google.com \
--cc=kernel@xen0n.name \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=linux-s390@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=llvm@lists.linux.dev \
--cc=loongarch@lists.linux.dev \
--cc=luto@kernel.org \
--cc=maddy@linux.ibm.com \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=morbo@google.com \
--cc=mpe@ellerman.id.au \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=npiggin@gmail.com \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=svens@linux.ibm.com \
--cc=tglx@kernel.org \
--cc=tytso@mit.edu \
--cc=vincenzo.frascino@arm.com \
--cc=will@kernel.org \
--cc=x86@kernel.org \
/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®