From: Christophe Leroy <christophe.leroy@csgroup.eu>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Steven Rostedt <rostedt@goodmis.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Michael Ellerman <mpe@ellerman.id.au>,
Nicholas Piggin <npiggin@gmail.com>,
Naveen N Rao <naveen@kernel.org>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>,
Shuah Khan <shuah@kernel.org>,
linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
linux-kselftest@vger.kernel.org, llvm@lists.linux.dev,
linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
linux-trace-kernel@vger.kernel.org,
Adhemerval Zanella <adhemerval.zanella@linaro.org>,
Xi Ruoyao <xry111@xry111.site>
Subject: Re: [PATCH v5 4/5] powerpc/vdso: Wire up getrandom() vDSO implementation on VDSO32
Date: Fri, 6 Sep 2024 06:53:26 +0200 [thread overview]
Message-ID: <45f7170d-a209-4079-9384-274b0c413a4b@csgroup.eu> (raw)
In-Reply-To: <Ztp16FkqG0ALlXnh@zx2c4.com>
Hi Jason,
Le 06/09/2024 à 05:24, Jason A. Donenfeld a écrit :
> On Fri, Sep 06, 2024 at 04:48:28AM +0200, Jason A. Donenfeld wrote:
>> On Thu, Sep 05, 2024 at 10:41:40PM +0200, Jason A. Donenfeld wrote:
>>> On Thu, Sep 05, 2024 at 06:13:29PM +0200, Jason A. Donenfeld wrote:
>>>>> +/*
>>>>> + * The macro sets two stack frames, one for the caller and one for the callee
>>>>> + * because there are no requirement for the caller to set a stack frame when
>>>>> + * calling VDSO so it may have omitted to set one, especially on PPC64
>>>>> + */
>>>>> +
>>>>> +.macro cvdso_call funct
>>>>> + .cfi_startproc
>>>>> + PPC_STLU r1, -PPC_MIN_STKFRM(r1)
>>>>> + .cfi_adjust_cfa_offset PPC_MIN_STKFRM
>>>>> + mflr r0
>>>>> + PPC_STLU r1, -PPC_MIN_STKFRM(r1)
>>>>> + .cfi_adjust_cfa_offset PPC_MIN_STKFRM
>>>>> + PPC_STL r0, PPC_MIN_STKFRM + PPC_LR_STKOFF(r1)
>>>>> + .cfi_rel_offset lr, PPC_MIN_STKFRM + PPC_LR_STKOFF
>>>>> + get_datapage r8
>>>>> + addi r8, r8, VDSO_RNG_DATA_OFFSET
>>>>> + bl CFUNC(DOTSYM(\funct))
>>>>> + PPC_LL r0, PPC_MIN_STKFRM + PPC_LR_STKOFF(r1)
>>>>> + cmpwi r3, 0
>>>>> + mtlr r0
>>>>> + addi r1, r1, 2 * PPC_MIN_STKFRM
>>>>> + .cfi_restore lr
>>>>> + .cfi_def_cfa_offset 0
>>>>> + crclr so
>>>>> + bgelr+
>>>>> + crset so
>>>>> + neg r3, r3
>>>>> + blr
>>>>> + .cfi_endproc
>>>>> +.endm
>>>>
>>>> Can you figure out what's going on and send a fix, which I'll squash
>>>> into this commit?
>>>
>>> This doesn't work, but I wonder if something like it is what we want. I
>>> need to head out for the day, but here's what I've got. It's all wrong
>>> but might be of interest.
>>
>> Oh, I just got one small detail wrong before. The below actually works,
>> and uses the same strategy as on arm64.
>>
>> Let me know if you'd like me to fix up this commit with the below patch,
>> or if you have another way you'd like to go about it.
>
> And here's the much shorter version in assembly, which maybe you prefer.
> Also works, and is a bit less invasive than the other thing.
>
> diff --git a/arch/powerpc/kernel/vdso/getrandom.S b/arch/powerpc/kernel/vdso/getrandom.S
> index a957cd2b2b03..070daba2d547 100644
> --- a/arch/powerpc/kernel/vdso/getrandom.S
> +++ b/arch/powerpc/kernel/vdso/getrandom.S
> @@ -32,6 +32,14 @@
> .cfi_rel_offset r2, PPC_MIN_STKFRM + STK_GOT
> #endif
> get_datapage r8
> +#ifdef CONFIG_TIME_NS
> + lis r10, 0x7fff
> + ori r10, r10, 0xffff
> + lwz r9, VDSO_DATA_OFFSET + 4(r8)
> + cmpw r9, r10
> + bne +8
> + addi r8, r8, (1 << CONFIG_PAGE_SHIFT)
> +#endif
> addi r8, r8, VDSO_RNG_DATA_OFFSET
> bl CFUNC(DOTSYM(\funct))
> PPC_LL r0, PPC_MIN_STKFRM + PPC_LR_STKOFF(r1)
>
Thanks for looking.
I came to more or less the same solutions thnt you with the following
that seems to work:
diff --git a/arch/powerpc/kernel/vdso/vgetrandom.c
b/arch/powerpc/kernel/vdso/vgetrandom.c
index 5f855d45fb7b..9705344d39d0 100644
--- a/arch/powerpc/kernel/vdso/vgetrandom.c
+++ b/arch/powerpc/kernel/vdso/vgetrandom.c
@@ -4,11 +4,19 @@
*
* Copyright (C) 2024 Christophe Leroy <christophe.leroy@csgroup.eu>,
CS GROUP France
*/
+#include <linux/container_of.h>
#include <linux/time.h>
#include <linux/types.h>
+#include <asm/vdso_datapage.h>
+
ssize_t __c_kernel_getrandom(void *buffer, size_t len, unsigned int
flags, void *opaque_state,
size_t opaque_len, const struct vdso_rng_data *vd)
{
+ struct vdso_arch_data *arch_data = container_of(vd, struct
vdso_arch_data, rng_data);
+
+ if (IS_ENABLED(CONFIG_TIME_NS) && arch_data->data[0].clock_mode ==
VDSO_CLOCKMODE_TIMENS)
+ vd = (void *)vd + (1UL << CONFIG_PAGE_SHIFT);
+
return __cvdso_getrandom_data(vd, buffer, len, flags, opaque_state,
opaque_len);
}
However, if we have this problem with __kernel_getrandom, don't we also
have it with: ?
__kernel_get_syscall_map;
__kernel_get_tbfreq;
__kernel_sync_dicache;
If they are also affected, then get_page macro is the place to fix.
I will check all of this now and keep you updated before noon (Paris Time).
Christophe
next prev parent reply other threads:[~2024-09-06 4:53 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-02 19:17 [PATCH v5 0/5] Wire up getrandom() vDSO implementation on powerpc Christophe Leroy
2024-09-02 19:17 ` [PATCH v5 1/5] mm: Define VM_DROPPABLE for powerpc/32 Christophe Leroy
2024-09-02 19:17 ` [PATCH v5 2/5] powerpc/vdso32: Add crtsavres Christophe Leroy
2024-09-02 19:17 ` [PATCH v5 3/5] powerpc/vdso: Refactor CFLAGS for CVDSO build Christophe Leroy
2024-09-02 19:17 ` [PATCH v5 4/5] powerpc/vdso: Wire up getrandom() vDSO implementation on VDSO32 Christophe Leroy
2024-09-05 16:13 ` Jason A. Donenfeld
2024-09-05 16:25 ` Jason A. Donenfeld
2024-09-05 16:55 ` Christophe Leroy
2024-09-05 17:01 ` Xi Ruoyao
2024-09-05 17:03 ` Jason A. Donenfeld
2024-09-05 17:16 ` Jason A. Donenfeld
2024-09-05 20:41 ` Jason A. Donenfeld
2024-09-06 2:48 ` Jason A. Donenfeld
2024-09-06 3:24 ` Jason A. Donenfeld
2024-09-06 4:53 ` Christophe Leroy [this message]
2024-09-02 19:17 ` [PATCH v5 5/5] powerpc/vdso: Wire up getrandom() vDSO implementation on VDSO64 Christophe Leroy
2024-09-04 11:46 ` Madhavan Srinivasan
2024-09-04 14:16 ` [PATCH v5 0/5] Wire up getrandom() vDSO implementation on powerpc Jason A. Donenfeld
2024-09-04 14:36 ` Christophe Leroy
2024-09-05 12:18 ` Michael Ellerman
2024-09-05 12:56 ` 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=45f7170d-a209-4079-9384-274b0c413a4b@csgroup.eu \
--to=christophe.leroy@csgroup.eu \
--cc=Jason@zx2c4.com \
--cc=adhemerval.zanella@linaro.org \
--cc=akpm@linux-foundation.org \
--cc=justinstitt@google.com \
--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=llvm@lists.linux.dev \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=morbo@google.com \
--cc=mpe@ellerman.id.au \
--cc=nathan@kernel.org \
--cc=naveen@kernel.org \
--cc=ndesaulniers@google.com \
--cc=npiggin@gmail.com \
--cc=rostedt@goodmis.org \
--cc=shuah@kernel.org \
--cc=xry111@xry111.site \
/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