From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0DF55C54FC6 for ; Fri, 6 Sep 2024 04:53:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 36BFD6B007B; Fri, 6 Sep 2024 00:53:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2F3E36B0082; Fri, 6 Sep 2024 00:53:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 16ED16B0085; Fri, 6 Sep 2024 00:53:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id E8C226B007B for ; Fri, 6 Sep 2024 00:53:32 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 59037120EE9 for ; Fri, 6 Sep 2024 04:53:32 +0000 (UTC) X-FDA: 82533095064.14.0AAC010 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by imf09.hostedemail.com (Postfix) with ESMTP id 0C3DD140002 for ; Fri, 6 Sep 2024 04:53:29 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 93.17.235.10 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu; dmarc=pass (policy=quarantine) header.from=csgroup.eu ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725598312; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LpphzAncrNAhbp68+MlAHJ/QbSS+Voj8bxowdXMcXnM=; b=Tr6uJkKXDG8+murRIClY19s4gMmWiBUUjgYogtEDIiiBvpMlTxEpUPALAk+VMNh41DRjvC 17UwLDlexGNCV0pYhzN22TH+Cs+3hXh0lKTDLlT6asqrvv1g63nmXzFMgm+EpFcHMJcVsY ed7qVuMX8sGtEdwATw7p/LcpbfTxcBY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725598312; a=rsa-sha256; cv=none; b=gaEMwEraW6khCkefH30qyMZlRAZtjf3r8NhJMjloXbNUhsIlUom1zDmfL0LfQ0MgOGdDcw Gv901OH6u9wLyhTU8OMRyB7ov2aEZNi3ey8J8QbeeMySSN7UG5NhDn/8Kuej454z0zEJv7 4ShHhn83yIpDitBOKGLIsdL/YIJfB6o= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 93.17.235.10 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu; dmarc=pass (policy=quarantine) header.from=csgroup.eu Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4X0P4l4sMRz9sRy; Fri, 6 Sep 2024 06:53:27 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id cGNa5ow0wQLB; Fri, 6 Sep 2024 06:53:27 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4X0P4l3spgz9sRs; Fri, 6 Sep 2024 06:53:27 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 739B98B778; Fri, 6 Sep 2024 06:53:27 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id X35N0C8uKPzN; Fri, 6 Sep 2024 06:53:27 +0200 (CEST) Received: from [192.168.235.70] (unknown [192.168.235.70]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 7D03E8B764; Fri, 6 Sep 2024 06:53:26 +0200 (CEST) Message-ID: <45f7170d-a209-4079-9384-274b0c413a4b@csgroup.eu> Date: Fri, 6 Sep 2024 06:53:26 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 4/5] powerpc/vdso: Wire up getrandom() vDSO implementation on VDSO32 To: "Jason A. Donenfeld" Cc: Andrew Morton , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Michael Ellerman , Nicholas Piggin , Naveen N Rao , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Shuah Khan , 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 , Xi Ruoyao References: <1f49c2ce009f8b007ab0676fb41187b2d54f28b2.1725304404.git.christophe.leroy@csgroup.eu> Content-Language: fr-FR From: Christophe Leroy In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Stat-Signature: nx7ikdi1wc71st1aohohkodq6fg3xty5 X-Rspamd-Queue-Id: 0C3DD140002 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1725598409-488548 X-HE-Meta: U2FsdGVkX1/4vqUpYdDxSCbUYbzc3AXumtvTqKzWcojjlsjuaLUS/RDLvlUzwV5Tckl/s18nSREeZDQdSRHOOVYjp6SOyRU5qxJZE6/7yhgUS3s5jTWZPkc2b5OaLrQROBQaioLdvwDd7E5w7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ests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 , CS GROUP France */ +#include #include #include +#include + 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