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 25088CD13CF for ; Mon, 2 Sep 2024 12:35:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A56968D00D5; Mon, 2 Sep 2024 08:35:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9DEE38D0098; Mon, 2 Sep 2024 08:35:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 831DD8D00D5; Mon, 2 Sep 2024 08:35:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 56F248D0098 for ; Mon, 2 Sep 2024 08:35:03 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 0197DC047D for ; Mon, 2 Sep 2024 12:35:02 +0000 (UTC) X-FDA: 82519742886.12.4872E70 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf05.hostedemail.com (Postfix) with ESMTP id 204F4100006 for ; Mon, 2 Sep 2024 12:35:00 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=zx2c4.com header.s=20210105 header.b=GvCPvbhW; spf=pass (imf05.hostedemail.com: domain of "SRS0=HWIV=QA=zx2c4.com=Jason@kernel.org" designates 139.178.84.217 as permitted sender) smtp.mailfrom="SRS0=HWIV=QA=zx2c4.com=Jason@kernel.org"; dmarc=pass (policy=quarantine) header.from=zx2c4.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725280407; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=882s/0oxY3IaUveWmEXQ9Cl4UCSpcI/yfMpsZGvZIqQ=; b=EOZljZJv6etHHN/ndcxMziBCEhG+VRC3Z2b8LcaK8v3AGW9E5Cjmr1absOV4mq9MTDbo2t GqJq6VqWUsL9Upw7dCoh+8B3LUNyCRB3xvoRmDpiyVEvf1zV+GYY7YapnOKiHzYIT4fZ84 Ibw839DZGvWxUwJx7D78qtH8W2SD2is= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725280407; a=rsa-sha256; cv=none; b=0mKGvbs31VRv1qZpLnVarjTYSYKtb+LkNyVWTLKlUoMNSsFVkax0M7GNlvzupfWwwJbs7N xzbwtsX3uVNKDHsvPFG/juK3mWksj8M/X80V9rf8iDx4R5zmE0r16u74Q6GSnse2TLSKSt +Y7x4ByS5vd+BbV/31wCZ/2VBTvlCaU= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=zx2c4.com header.s=20210105 header.b=GvCPvbhW; spf=pass (imf05.hostedemail.com: domain of "SRS0=HWIV=QA=zx2c4.com=Jason@kernel.org" designates 139.178.84.217 as permitted sender) smtp.mailfrom="SRS0=HWIV=QA=zx2c4.com=Jason@kernel.org"; dmarc=pass (policy=quarantine) header.from=zx2c4.com Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 81C975C5839; Mon, 2 Sep 2024 12:34:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 839DDC4CEC2; Mon, 2 Sep 2024 12:34:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1725280495; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=882s/0oxY3IaUveWmEXQ9Cl4UCSpcI/yfMpsZGvZIqQ=; b=GvCPvbhW2m2jYoAxPU1wvqvYj9FboQLHWShrj+s+adjZAJT3TuHPHxTV7jxhkLBDOaMexZ lgOnLbMwcrBalkcwK2Us5lCoS0HPCfmqmBrkvHWRXH4kgn5eiovHjf2iVAYU/SglD3w6gQ EdxGyEKCEpN2M6xkxzv9bOZ82o4t/fw= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 6aea6560 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 2 Sep 2024 12:34:54 +0000 (UTC) Date: Mon, 2 Sep 2024 14:34:49 +0200 From: "Jason A. Donenfeld" To: Christophe Leroy 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 Subject: Re: [PATCH v4 4/5] powerpc/vdso: Wire up getrandom() vDSO implementation on PPC32 Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Stat-Signature: nefrd8ppsimttcfse4k9hqcn4hz6z9uh X-Rspamd-Queue-Id: 204F4100006 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1725280500-875443 X-HE-Meta: U2FsdGVkX18Or/G8nmkN5a9yEOGiQ4JtpMrSiOP+zblmy4C4Pq2R+QmEohpDKrBIRyEb7gyUYFQ44HJpgT1oY/2YhwBS10XXk3vdJSiM2Rx0309mIeFoVPP3gYGAc4SzaujjXx+LOWiWTjxmQ1w5FimT7hqPXt5tvFhgFvlWZD77uVnJJxULUxM0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yVwVqQGDXSVZMbqyiFZ59nS3v1PWDSNcRl2hJwhSpJxTuWSHoc61y9Mzj2rAoTbuUims5aKdQnCv6ljCLjoxZjst2A+R/uGEOZvzfaEUVux+QkwGejeMMC7wRxn3ThpiykP+7adb3TGPAK7MX2oXN/rEC2e+V2CogDPSyWlk4zC1Kil7lZQ== X-Bogosity: Ham, tests=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: On Mon, Sep 02, 2024 at 02:04:41PM +0200, Christophe Leroy wrote: > This first patch adds support for PPC32. As selftests cannot easily > be generated only for PPC32, and because the following patch brings > support for PPC64 anyway, this patch opts out all code in > __arch_chacha20_blocks_nostack() so that vdso_test_chacha will not > fail to compile and will not crash on PPC64/PPC64LE, allthough the > selftest itself will fail. This patch also adds a dummy > __kernel_getrandom() function that returns ENOSYS on PPC64 so that > vdso_test_getrandom returns KSFT_SKIP instead of KSFT_FAIL. Why not just wire up the selftests in the next patch like you did for v3? This seems like extra stuff for no huge reason? > arch/powerpc/Kconfig | 1 + > arch/powerpc/include/asm/vdso/getrandom.h | 54 +++++ > arch/powerpc/include/asm/vdso/vsyscall.h | 6 + > arch/powerpc/include/asm/vdso_datapage.h | 2 + > arch/powerpc/kernel/asm-offsets.c | 1 + > arch/powerpc/kernel/vdso/Makefile | 13 +- > arch/powerpc/kernel/vdso/getrandom.S | 58 ++++++ > arch/powerpc/kernel/vdso/vdso32.lds.S | 1 + > arch/powerpc/kernel/vdso/vdso64.lds.S | 1 + > arch/powerpc/kernel/vdso/vgetrandom-chacha.S | 207 +++++++++++++++++++ > arch/powerpc/kernel/vdso/vgetrandom.c | 16 ++ > tools/testing/selftests/vDSO/Makefile | 2 +- > 12 files changed, 359 insertions(+), 3 deletions(-) > create mode 100644 arch/powerpc/include/asm/vdso/getrandom.h > create mode 100644 arch/powerpc/kernel/vdso/getrandom.S > create mode 100644 arch/powerpc/kernel/vdso/vgetrandom-chacha.S > create mode 100644 arch/powerpc/kernel/vdso/vgetrandom.c I think you might have forgotten to add the symlink in this commit (or the next one, per my comment above, if you agree with it). > +/* > + * Very basic 32 bits implementation of ChaCha20. Produces a given positive number > + * of blocks of output with a nonce of 0, taking an input key and 8-byte > + * counter. Importantly does not spill to the stack. Its arguments are: > + * > + * r3: output bytes > + * r4: 32-byte key input > + * r5: 8-byte counter input/output (saved on stack) > + * r6: number of 64-byte blocks to write to output > + * > + * r0: counter of blocks (initialised with r6) > + * r4: Value '4' after key has been read. > + * r5-r12: key > + * r14-r15: counter > + * r16-r31: state > + */ > +SYM_FUNC_START(__arch_chacha20_blocks_nostack) > +#ifdef __powerpc64__ > + blr > +#else > + stwu r1, -96(r1) > + stw r5, 20(r1) > + stmw r14, 24(r1) > + > + lwz r14, 0(r5) > + lwz r15, 4(r5) > + mr r0, r6 > + subi r3, r3, 4 > + > + lwz r5, 0(r4) > + lwz r6, 4(r4) > + lwz r7, 8(r4) > + lwz r8, 12(r4) > + lwz r9, 16(r4) > + lwz r10, 20(r4) > + lwz r11, 24(r4) > + lwz r12, 28(r4) If you don't want to do this, don't worry about it, but while I'm commenting on things, I think it's worth noting that x86, loongarch, and arm64 implementations all use the preprocessor or macros to give names to these registers -- state1,2,3,...copy1,2,3 and so forth. Might be worth doing the same if you think there's an easy and obvious way of doing it. If not -- or if that kind of work abhors you -- don't worry about it, as I'm confident enough that this code works fine. But it might be "nice to have". Up to you. > + > + li r4, 4 > +.Lblock: > + li r31, 10 > + Maybe a comment here, "expand 32-byte k" or similar. > + lis r16, 0x6170 > + lis r17, 0x3320 > + lis r18, 0x7962 > + lis r19, 0x6b20 > + addi r16, r16, 0x7865 > + addi r17, r17, 0x646e > + addi r18, r18, 0x2d32 > + addi r19, r19, 0x6574 > + > + mtctr r31 > + > + mr r20, r5 > + mr r21, r6 > + mr r22, r7 > + mr r23, r8 > + mr r24, r9 > + mr r25, r10 > + mr r26, r11 > + mr r27, r12 > + > + mr r28, r14 > + mr r29, r15 > + li r30, 0 > + li r31, 0 > + > +.Lpermute: > + QUARTERROUND4( 0, 4, 8,12, 1, 5, 9,13, 2, 6,10,14, 3, 7,11,15) > + QUARTERROUND4( 0, 5,10,15, 1, 6,11,12, 2, 7, 8,13, 3, 4, 9,14) > + > + bdnz .Lpermute > + > + addis r16, r16, 0x6170 > + addis r17, r17, 0x3320 > + addis r18, r18, 0x7962 > + addis r19, r19, 0x6b20 > + addi r16, r16, 0x7865 > + addi r17, r17, 0x646e > + addi r18, r18, 0x2d32 > + addi r19, r19, 0x6574 > + > + add r20, r20, r5 > + add r21, r21, r6 > + add r22, r22, r7 > + add r23, r23, r8 > + add r24, r24, r9 > + add r25, r25, r10 > + add r26, r26, r11 > + add r27, r27, r12 > + > + add r28, r28, r14 > + add r29, r29, r15 > + > + stwbrx r16, r4, r3 > + addi r3, r3, 8 > + stwbrx r17, 0, r3 > + stwbrx r18, r4, r3 > + addi r3, r3, 8 > + stwbrx r19, 0, r3 > + stwbrx r20, r4, r3 > + addi r3, r3, 8 > + stwbrx r21, 0, r3 > + stwbrx r22, r4, r3 > + addi r3, r3, 8 > + stwbrx r23, 0, r3 > + stwbrx r24, r4, r3 > + addi r3, r3, 8 > + stwbrx r25, 0, r3 > + stwbrx r26, r4, r3 > + addi r3, r3, 8 > + stwbrx r27, 0, r3 > + stwbrx r28, r4, r3 > + addi r3, r3, 8 > + stwbrx r29, 0, r3 > + stwbrx r30, r4, r3 > + addi r3, r3, 8 > + stwbrx r31, 0, r3 > + > + subic. r0, r0, 1 /* subi. can't use r0 as source */ Never seen the period suffix. Just looked this up. Neat.