From: LEROY Christophe <christophe.leroy2@cs-soprasteria.com>
To: Thomas Gleixner <tglx@linutronix.de>,
"Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>,
Nicholas Piggin <npiggin@gmail.com>,
Naveen N Rao <naveen@kernel.org>,
Andy Lutomirski <luto@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
"x86@kernel.org" <x86@kernel.org>,
"H. Peter Anvin" <hpa@zytor.com>, Theodore Ts'o <tytso@mit.edu>,
Arnd Bergmann <arnd@arndb.de>,
Andrew Morton <akpm@linux-foundation.org>,
Steven Rostedt <rostedt@goodmis.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Vincenzo Frascino <vincenzo.frascino@arm.com>,
Shuah Khan <shuah@kernel.org>,
"linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
"linux-arch@vger.kernel.org" <linux-arch@vger.kernel.org>,
"linux-mm@kvack.org" <linux-mm@kvack.org>,
"linux-trace-kernel@vger.kernel.org"
<linux-trace-kernel@vger.kernel.org>,
"linux-kselftest@vger.kernel.org"
<linux-kselftest@vger.kernel.org>
Subject: Re: [PATCH v2 06/17] vdso: Change getrandom's generation to unsigned long
Date: Mon, 26 Aug 2024 10:20:09 +0000 [thread overview]
Message-ID: <ce5eba04-77a6-4a64-aec9-64196cdf64fc@cs-soprasteria.com> (raw)
In-Reply-To: <87v7znd3g4.ffs@tglx>
Le 26/08/2024 à 11:43, Thomas Gleixner a écrit :
> On Mon, Aug 26 2024 at 10:01, Christophe Leroy wrote:
>> Le 26/08/2024 à 09:50, Jason A. Donenfeld a écrit :
>>> But tglx pointed out in that thread that this actually isn't necessary:
>>>
>>> | All of this is pointless because if a 32-bit application runs on a
>>> | 64-bit kernel it has to use the 64-bit 'generation'. So why on earth do
>>> | we need magic here for a 32-bit kernel?
>>> |
>>> | Just use u64 for both and spare all this voodoo. We're seriously not
>>> | "optimizing" for 32-bit kernels.
>>> |
>>> | All what happens on a 32-bit kernel is that the RNG will store the
>>> | unsigned long (32bit) generation into a 64bit variable:
>>> |
>>> | smp_store_release(&_vdso_rng_data.generation, next_gen + 1);
>>> |
>>> | As the upper 32bit are always zero, there is no issue vs. load store
>>> | tearing at all. So there is zero benefit for this aside of slightly
>>> | "better" user space code when running on a 32-bit kernel. Who cares?
>>>
>>> So I just got rid of it and used a u64 as he suggested.
>>>
>>> However, there's also an additional reason why it's not worth churning
>>> further over this - because VM_DROPPABLE is 64-bit only (due to flags in
>>> vma bits), likely so is vDSO getrandom() for the time being. So I think
>>> it makes more sense to retool this series to be ppc64, and then if you
>>> really really want 32-bit and can convince folks it matters, then all of
>>> these parts (for example, here, the fact that the smp helper doesn't
>>> want to tear) can be fixed up in a separate series.
>>
>> So yes I really really want it on ppc32 because this is the only type of
>> boards I have and this is really were we need getrandom() to be
>> optimised,
>
> For nostalgic reasons?
No nostalgy here. We deliver voice communication systems for air trafic
control that we are commited to maintain for at least the next 15 years.
The MPC 885 was manufactured by NXP until recently and we have several
hundreds in stock in case one of our customer needs to extend an
existing system.
The MPC 8321 is still manufactured by NXP and the boards on new systems
we deliver use that CPU.
Both are 32 bits powerpc.
>
>> indeed ppc64 was sherry-on-the-cake in my series, I just added it
>> because it was easy to do after doing ppc32.
>
> The rng problem for ppc32 seems to be:
>
> smp_store_release(&_vdso_rng_data.generation, next_gen + 1);
>
> right?
right.
>
> Your proposed type change creates inconsistency for 32-bit userspace
> running on 64-bit kernels because the data struct layout changes.
>
> As explained before, there is no problem with store or load tearing on
> 32bit systems because the generation counter is only 32bit wide. So the
> obvious solution is to only update 32 bits on a 32bit kernel:
>
> --- a/drivers/char/random.c
> +++ b/drivers/char/random.c
> @@ -282,7 +282,7 @@ static void crng_reseed(struct work_stru
> * is ordered with the write above to base_crng.generation. Pairs with
> * the smp_rmb() before the syscall in the vDSO code.
> */
> - smp_store_release(&_vdso_rng_data.generation, next_gen + 1);
> + smp_store_release((unsigned long *)&_vdso_rng_data.generation, next_gen + 1);
> #endif
> if (!static_branch_likely(&crng_is_ready))
> crng_init = CRNG_READY;
>
> Which is perfectly fine on 32-bit independent of endianess because the
> user space side does READ_ONCE(data->generation) and the read value is
> solely used for comparison so it does not matter at all whether the
> generation information is in the upper or the lower 32bit of the u64. >
> No?
Yes that looks ok, it will only require a big fat comment to explain
that. I'll give it a try.
>
> But that's a trivial fix compared to making VM_DROPPABLE work on 32-bit
> correclty. :)
Euh ... Ok. What's the problem here ? I have used VM_ARCH_1 which is
available. Is there more to do ?
Thanks
Christophe
next prev parent reply other threads:[~2024-08-26 10:20 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-22 7:13 [PATCH v2 00/17] Wire up getrandom() vDSO implementation on powerpc Christophe Leroy
2024-08-22 7:13 ` [PATCH v2 01/17] asm-generic/unaligned.h: Extract common header for vDSO Christophe Leroy
2024-08-26 7:20 ` Jason A. Donenfeld
2024-08-26 7:32 ` Christophe Leroy
2024-08-22 7:13 ` [PATCH v2 02/17] vdso: Clean header inclusion in getrandom Christophe Leroy
2024-08-26 8:07 ` Jason A. Donenfeld
2024-08-26 8:37 ` Christophe Leroy
2024-08-26 8:58 ` Jason A. Donenfeld
2024-08-26 10:45 ` Christophe Leroy
2024-08-26 13:17 ` Jason A. Donenfeld
2024-08-26 13:24 ` Thomas Gleixner
2024-08-22 7:13 ` [PATCH v2 03/17] vdso: Add __arch_get_k_vdso_rng_data() Christophe Leroy
2024-08-26 7:24 ` Jason A. Donenfeld
2024-08-22 7:13 ` [PATCH v2 04/17] vdso: Add missing c-getrandom-y in Makefile Christophe Leroy
2024-08-26 7:40 ` Jason A. Donenfeld
2024-08-22 7:13 ` [PATCH v2 05/17] vdso: Avoid call to memset() by getrandom Christophe Leroy
2024-08-26 8:01 ` Jason A. Donenfeld
2024-08-27 18:08 ` Eric Biggers
2024-08-27 18:22 ` Jason A. Donenfeld
2024-08-27 22:53 ` Segher Boessenkool
2024-08-28 11:18 ` Jason A. Donenfeld
2024-08-28 12:24 ` Arnd Bergmann
2024-08-28 12:26 ` Jason A. Donenfeld
2024-08-28 12:51 ` Segher Boessenkool
2024-08-28 12:45 ` Segher Boessenkool
2024-08-28 15:40 ` Ard Biesheuvel
2024-08-28 16:20 ` Segher Boessenkool
2024-08-28 17:12 ` Ard Biesheuvel
2024-08-28 17:25 ` Segher Boessenkool
2024-08-29 17:36 ` Christophe Leroy
2024-08-29 18:02 ` Segher Boessenkool
2024-08-29 18:50 ` Christophe Leroy
2024-08-30 10:01 ` Michael Ellerman
2024-08-28 12:33 ` Segher Boessenkool
2024-08-28 12:51 ` Jason A. Donenfeld
2024-08-22 7:13 ` [PATCH v2 06/17] vdso: Change getrandom's generation to unsigned long Christophe Leroy
2024-08-26 7:50 ` Jason A. Donenfeld
2024-08-26 8:01 ` Christophe Leroy
2024-08-26 8:16 ` Jason A. Donenfeld
2024-08-26 9:43 ` Thomas Gleixner
2024-08-26 9:48 ` Jason A. Donenfeld
2024-08-26 10:20 ` LEROY Christophe [this message]
2024-08-22 7:13 ` [PATCH v2 07/17] mm: Define VM_DROPPABLE for powerpc/32 Christophe Leroy
2024-08-26 9:53 ` kernel test robot
2024-08-26 10:13 ` kernel test robot
2024-08-26 21:34 ` kernel test robot
2024-08-22 7:13 ` [PATCH v2 08/17] powerpc: Add little endian variants of LWZX_BE and STWX_BE Christophe Leroy
2024-08-22 7:13 ` [PATCH v2 09/17] powerpc/vdso32: Add crtsavres Christophe Leroy
2024-08-22 7:13 ` [PATCH v2 10/17] powerpc/vdso: Refactor CFLAGS for CVDSO build Christophe Leroy
2024-08-22 7:13 ` [PATCH v2 11/17] powerpc/vdso: Wire up getrandom() vDSO implementation Christophe Leroy
2024-08-22 7:13 ` [PATCH v2 12/17] selftests: vdso: Fix powerpc64 vdso_config Christophe Leroy
2024-08-22 7:13 ` [PATCH v2 13/17] selftests: vdso: Don't hard-code location of vDSO sources Christophe Leroy
2024-08-26 7:26 ` Jason A. Donenfeld
2024-08-22 7:13 ` [PATCH v2 14/17] selftests: vdso: Make test_vdso_getrandom look for the right vDSO function Christophe Leroy
2024-08-26 7:28 ` Jason A. Donenfeld
2024-08-26 7:35 ` LEROY Christophe
2024-08-22 7:13 ` [PATCH v2 15/17] selftests: vdso: Fix build of test_vdso_chacha Christophe Leroy
2024-08-26 7:33 ` Jason A. Donenfeld
2024-08-22 7:13 ` [PATCH v2 16/17] selftests: vdso: Make VDSO function call more generic Christophe Leroy
2024-08-26 7:37 ` Jason A. Donenfeld
2024-08-26 7:48 ` LEROY Christophe
2024-08-22 7:13 ` [PATCH v2 17/17] selftests: vdso: Add support for vdso_test_random for powerpc Christophe Leroy
2024-08-26 7:19 ` [PATCH v2 00/17] Wire up getrandom() vDSO implementation on powerpc Jason A. Donenfeld
2024-08-26 8:23 ` Jason A. Donenfeld
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=ce5eba04-77a6-4a64-aec9-64196cdf64fc@cs-soprasteria.com \
--to=christophe.leroy2@cs-soprasteria.com \
--cc=Jason@zx2c4.com \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=luto@kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=mingo@redhat.com \
--cc=mpe@ellerman.id.au \
--cc=naveen@kernel.org \
--cc=npiggin@gmail.com \
--cc=rostedt@goodmis.org \
--cc=shuah@kernel.org \
--cc=tglx@linutronix.de \
--cc=tytso@mit.edu \
--cc=vincenzo.frascino@arm.com \
--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