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 71C12CA0ED3 for ; Mon, 2 Sep 2024 13:07:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D82628D00D9; Mon, 2 Sep 2024 09:07:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D32398D0098; Mon, 2 Sep 2024 09:07:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BF9E48D00D9; Mon, 2 Sep 2024 09:07:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id A29778D0098 for ; Mon, 2 Sep 2024 09:07:11 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id A806A1214B5 for ; Mon, 2 Sep 2024 13:07:10 +0000 (UTC) X-FDA: 82519823820.24.392969F Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by imf20.hostedemail.com (Postfix) with ESMTP id 31F971C0024 for ; Mon, 2 Sep 2024 13:07:07 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; spf=pass (imf20.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=1725282405; 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=+tQOD9NWAYHoXwqb+CUO3TF73BxJoIY/zOUUL+NmKks=; b=eoO+bmK7z8z3TdEKaX3YdLDiDukULMeOUsmuAloKeNWVt63kwux1mWEc9wHFYyqME7o9U4 4XW/MqlKMrcVAP8+NX27DNz1s1fqT//L55RiF5pK7yLd4kHi/qRv+n9neH3FJujV2LsO2d AEg8C67WMuLF3tkAqBnQPkVZJCeS3ic= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none; spf=pass (imf20.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725282405; a=rsa-sha256; cv=none; b=OdrVQY+s+3+rzb5xGctOr43YADe5befz3td6hplMD85MYn9PJO5n1bi927xHu4QmtoYJCN /soeFQcRk1zUU+l4VVWka7ZerHssSSSsjeiPuaULIp9Zrbzdkn8jzPtxUlwf+3qVTHnVlt SpWayBkH+BRIPi6leH01jId35VwxtB4= Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4Wy8DB1TB0z9sSN; Mon, 2 Sep 2024 15:07:06 +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 pEK_keS0MYWc; Mon, 2 Sep 2024 15:07:06 +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 4Wy8DB0STbz9sS7; Mon, 2 Sep 2024 15:07:06 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id F114A8B76C; Mon, 2 Sep 2024 15:07:05 +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 unc9YceQJHKx; Mon, 2 Sep 2024 15:07:05 +0200 (CEST) Received: from [192.168.234.167] (unknown [192.168.234.167]) by messagerie.si.c-s.fr (Postfix) with ESMTP id F2E7F8B763; Mon, 2 Sep 2024 15:07:04 +0200 (CEST) Message-ID: <23dcd8ab-592f-4e74-b7a7-99df3ffb9a3a@csgroup.eu> Date: Mon, 2 Sep 2024 15:07:04 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 4/5] powerpc/vdso: Wire up getrandom() vDSO implementation on PPC32 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: Content-Language: fr-FR From: Christophe Leroy In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspam-User: X-Stat-Signature: bdr6pzixu1m91k5ncqmnd1nh5kqazxjs X-Rspamd-Queue-Id: 31F971C0024 X-Rspamd-Server: rspam11 X-HE-Tag: 1725282427-109319 X-HE-Meta: U2FsdGVkX1/Yq1tOwx+TGos5fnmZuIjwOTxEbI1pEfLzzZiZRZmieQyewhicjbTpaAOLjXiM7qGLAt/K5D6x0Rlomnf8lkwQSGwaJo9CrKl6zEoskPZWEoBmhpzF+EEg0ESkkIjKntJ0denVdMEy1rDAeJvFPpIU5WN7Nf6C2I5QEwMTXFaoj5Y2Tpa7A4TInCPs+xmwtTW26qoYKVb46MJfIh6vCfGhvdG8G3g6AlBzjvDbKmXrFyaWsYZhGC4fV7lw+RmYwcIId8ujtyj3AkzspPGMYpF1Lo63tawmPy2jH7Z33zBK5BjXZt5jcFaJxUxJcQWc5L+Fppr0NX3UU758DHkYmlmuNZDGz2gp2LrA08+BlIEwKne1kdIRjdEU+U+zf7nD8sULHqms4QZoUnx053i5SzlSeRnf5H+FcWOb+KsYtP9MgqbJZUemfLO5GTY9yPN2tx22QYINIyCAPweqReWZxJjzN1WvdPJIuoQJve5f6BdsJKHMn1Kjy2AZI40QmJALuQXdxTKfhOxgTcwDIHSbWtwZpOOWPugeEbmlZbKilPaTvw5NqnidxCfbQe5mDPhoCmIr1WnWrJZ6xorBFwXPZgOaRSr4r7XAw2HjE+SV+OmPUoGG0qrAG4xi+zna0o6ybWN5uNTDIn3RBPKhYJ30SCpSqcb5UiUoI9smhHzJiFi/PnmmzK42xvjoAkSl2sfh26yGOJLMAEAWHtfLx/l1tanSMmzVjXWTj9+ARD0LAmQtqlzJZsUwvlZl8ECHSRvV8kn+ehP/gh7VTDhjox7Z6DjMTGPKYzd07fQirpFZovgg0bLYKLW4bh2K61UY1ne9sYCB4VvmO8Rq/3w6eRTUaeDboUpCxVEg40AtfeB+X0BiBR9va4mgIx3XXph2hyUdNBYW77QnbgwyaQUFXmoqbyBejN9bO+T01M/lKGU1Ng/k9JHtOc7hQht4yCgZ0HOpd/e7Tgq8K8f LbaABu5C vKLaA6So6PatB7LqWynqGyOmXleoMBwGBGdfsU+d3w2Iy01kQrU26iOE2TvNU7B7kLpm75dzQaFs1+9KJT0HEwPJhbBVzDEj28r2Lh3AazhcXuVQZWRLY5cWaOLoqWOnJX6n8/I0ejEZz/BA= 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: Le 02/09/2024 à 14:34, Jason A. Donenfeld a écrit : > 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? In v3 selftests were already wired up in v3, and there was the following build failure: $ make ARCH=powerpc CROSS_COMPILE=powerpc64le-linux- CC vdso_test_gettimeofday CC vdso_test_getcpu CC vdso_test_abi CC vdso_test_clock_getres CC vdso_test_correctness CC vdso_test_getrandom CC vdso_test_chacha /home/chleroy/linux-powerpc/tools/testing/selftests/../../../tools/arch/powerpc/vdso/vgetrandom-chacha.S: Assembler messages: /home/chleroy/linux-powerpc/tools/testing/selftests/../../../tools/arch/powerpc/vdso/vgetrandom-chacha.S:84: Error: `stmw' invalid when little-endian /home/chleroy/linux-powerpc/tools/testing/selftests/../../../tools/arch/powerpc/vdso/vgetrandom-chacha.S:198: Error: `lmw' invalid when little-endian make: *** [../lib.mk:222: /home/chleroy/linux-powerpc/tools/testing/selftests/vDSO/vdso_test_chacha] Error 1 So I did this change to get a clean PPC32 implementation before going into PPC64. I thought it was easier to go in two steps for reviews, bisectability, etc .... for just a very little extra stuff. > >> 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). ???? That's odd. All CI tests on github went ok !!! Looks like the CI tests for selftests are broken. Argh ! And of course on my computer the link was there so I didn't notice. > >> +/* >> + * 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. I'll have a look. > >> + >> + li r4, 4 >> +.Lblock: >> + li r31, 10 >> + > > Maybe a comment here, "expand 32-byte k" or similar. ok > >> + 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 >> + >> + >> + subic. r0, r0, 1 /* subi. can't use r0 as source */ > > Never seen the period suffix. Just looked this up. Neat. Not sure what your comment is. Are you talking about the dot suffix after subic ? That dot means I want CR register to be updated by the instruction. It is equivalent to doing a comparision of the result with 0. It is used by the bne (branch if not equal) a few lines later.