From nobody Wed Nov 22 18:14:15 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Sb8X92LF7z51LMJ; Wed, 22 Nov 2023 18:14:17 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Sb8X91vZkz3ZGN; Wed, 22 Nov 2023 18:14:17 +0000 (UTC) (envelope-from jhb@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1700676857; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nC6OdJPPe5KqXFFjeoG5iBeZEhrAbJjLmIdALjFnqww=; b=B5Gp4qoKeXXZQqSQgIqVTlXP4WReUeK6k+64O+C8q4W70nupJHcXEyYVXDBfBbIILtaLlK lm3OlxBm+BC7P0iC9RPWwDyyS/hQR+Ewj54iv4TwsEf5j+LpX7UBzCMUXlXmV50ZHuksnF AW4+Q5Leo3wu/hbypY+CUSCwnqqI0VyGduPudIEpoPPaBv/lGRh6RG5mOXt7pCu2nVLx0E yuoQkDT+hFI57GKGk+hdyhwToieQqQMDy87boA+nvhh49K4KVqy9NUqu2SoqXi96Xf8Cgl /YM7H4KfChXNCJmtPlw0HBWNsrWxCcvdyhMB1lDUPgK+MBnqLK6GA/WkfSbJyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1700676857; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nC6OdJPPe5KqXFFjeoG5iBeZEhrAbJjLmIdALjFnqww=; b=rpW2Q2x91pL+ucg0iw6Aq69KiU9GhdwXK3oEzbVD6xtJYp5b/K2jHbWU3d71H/CY5elKXv xBWL11jAtsPgmUcLQC4OZty2LP9k6x1ysMLmlMmdFgeuz4WTHzY5ZYh2PcEzqmN7Bsj/jU d47/aJHm90KoNkBd7iHK6m8xzp+O4Vs77Z+nXK2sN6NZmc1OOpcADxdIyupFE1zicen8M0 OIoLdtXdRSzSVFTkVKEvzTd0vjYRKfaPzSqur8WBtEkZJTSaZwwzp6aIJisXL+I8tK0HeN HmXI7orhPV1EFyCbrt2PiSE/0bHW9i9jsEBFFMBnqLj7cEmeI+lxwfkEhfNh4w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1700676857; a=rsa-sha256; cv=none; b=HE+aG3UDgGQU7ISJEtLXy1lINOQc+d0cVRs7bziz21zyF7uARnkF4oOluu5XX5cB9ESmd2 sAbmIlho+WO1bCi/vszm7OO2kCbx4Pq3uE4RokGbhVZ27leNhViXhzujOh2VJ5gcmKdiSh R5gFp/ZCWLY37iFOKRD0e4+wUHDQjUj6c+rM5h4LHlqJvsxgBZDx7IMzfizaz6zDm8SS6/ nx3v3Aco6vHLW9kCXYYZAR6YcpyE3Mw4aZi7s2iktD/4RotDVSSEU8pINh06ZeAIDNQN6s ms1JOiX0uAzc2OIOCoYLlbTrjQlrqAXm7BC4ynMkSd0k9KC+/EqkW640cyRgDg== Received: from [IPV6:2601:648:8384:fd00:51ff:8c8b:b16b:8ec9] (unknown [IPv6:2601:648:8384:fd00:51ff:8c8b:b16b:8ec9]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: jhb) by smtp.freebsd.org (Postfix) with ESMTPSA id 4Sb8X84Y7Nz83G; Wed, 22 Nov 2023 18:14:16 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Message-ID: Date: Wed, 22 Nov 2023 10:14:15 -0800 List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: git: 9eecef052155 - main - Add an Armv8 rndr random number provider Content-Language: en-US To: Andrew Turner Cc: "src-committers@freebsd.org" , "dev-commits-src-all@freebsd.org" , "dev-commits-src-main@freebsd.org" , Jessica Clarke References: <202311151812.3AFICLIs077567@gitrepo.freebsd.org> <2423E245-0F1B-4195-A766-166183774421@freebsd.org> From: John Baldwin In-Reply-To: <2423E245-0F1B-4195-A766-166183774421@freebsd.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 11/15/23 4:29 PM, Jessica Clarke wrote: > On 15 Nov 2023, at 18:27, Jessica Clarke wrote: >> >> On 15 Nov 2023, at 18:12, Andrew Turner wrote: >>> >>> The branch main has been updated by andrew: >>> >>> URL: https://cgit.FreeBSD.org/src/commit/?id=9eecef052155646fbc5f8f533b952b372572d06a >>> >>> commit 9eecef052155646fbc5f8f533b952b372572d06a >>> Author: Andrew Turner >>> AuthorDate: 2023-11-15 17:42:02 +0000 >>> Commit: Andrew Turner >>> CommitDate: 2023-11-15 18:05:08 +0000 >>> >>> Add an Armv8 rndr random number provider >>> >>> Armv8.5 adds an optional random number generator. This is implemented >>> as two special registers one to read a random number, the other to >>> re-seed the entropy pool before reading a random number. Both registers >>> will set the condition flags to tell the caller they can't produce a >>> random number in a reasonable amount of time. >>> >>> Without a signal to reseed the entropy pool use the latter register >>> to provide random numbers to the kernel pool. If at a later time we >>> had a way to tell the provider if it needs to reseed or not we could >>> use the former. >>> >>> On an Amazon AWS Graviton3 VM this never failed, however this may not >>> be the case on low end CPUs so retry reading the random number 10 times >>> before returning an error. >>> >>> Reviewed by: imp, delphij (csprng) >>> Sponsored by: The FreeBSD Foundation >>> Sponsored by: Arm Ltd >>> Differential Revision: https://reviews.freebsd.org/D35411 >>> --- >>> sys/arm64/conf/std.dev | 1 + >>> sys/conf/files.arm64 | 2 + >>> sys/dev/random/armv8rng.c | 135 +++++++++++++++++++++++++++++++++++++++ >>> sys/dev/random/random_harvestq.c | 1 + >>> sys/modules/Makefile | 2 + >>> sys/modules/armv8_rng/Makefile | 11 ++++ >>> sys/sys/random.h | 1 + >>> 7 files changed, 153 insertions(+) >>> >>> diff --git a/sys/arm64/conf/std.dev b/sys/arm64/conf/std.dev >>> index 74d2407e0aec..0ebf2e775b11 100644 >>> --- a/sys/arm64/conf/std.dev >>> +++ b/sys/arm64/conf/std.dev >>> @@ -53,6 +53,7 @@ device vt_simplefb >>> >>> # Pseudo devices. >>> device crypto # core crypto support >>> +device armv8_rng # Armv8.5 rndr RNG >>> device loop # Network loopback >>> device ether # Ethernet support >>> device vlan # 802.1Q VLAN support >>> diff --git a/sys/conf/files.arm64 b/sys/conf/files.arm64 >>> index 38b9e40463eb..9ccead6a98e1 100644 >>> --- a/sys/conf/files.arm64 >>> +++ b/sys/conf/files.arm64 >>> @@ -379,6 +379,8 @@ dev/psci/psci.c standard >>> dev/psci/smccc_arm64.S standard >>> dev/psci/smccc.c standard >>> >>> +dev/random/armv8rng.c optional armv8_rng !random_loadable >>> + >>> dev/safexcel/safexcel.c optional safexcel fdt >>> >>> dev/sdhci/sdhci_xenon.c optional sdhci_xenon sdhci >>> diff --git a/sys/dev/random/armv8rng.c b/sys/dev/random/armv8rng.c >>> new file mode 100644 >>> index 000000000000..3cca42a5bbf3 >>> --- /dev/null >>> +++ b/sys/dev/random/armv8rng.c >>> @@ -0,0 +1,135 @@ >>> +/*- >>> + * Copyright (c) 2022 The FreeBSD Foundation >>> + * >>> + * This software was developed by Andrew Turner under sponsorship from >>> + * the FreeBSD Foundation. >>> + * >>> + * Redistribution and use in source and binary forms, with or without >>> + * modification, are permitted provided that the following conditions >>> + * are met: >>> + * 1. Redistributions of source code must retain the above copyright >>> + * notice, this list of conditions and the following disclaimer. >>> + * 2. Redistributions in binary form must reproduce the above copyright >>> + * notice, this list of conditions and the following disclaimer in the >>> + * documentation and/or other materials provided with the distribution. >>> + * >>> + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND >>> + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >>> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE >>> + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE >>> + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL >>> + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS >>> + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) >>> + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT >>> + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY >>> + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF >>> + * SUCH DAMAGE. >>> + */ >>> + >>> +#include >>> + >>> +#include >>> +#include >>> +#include >>> +#include >>> +#include >>> +#include >>> +#include >>> +#include >>> + >>> +#include >>> + >>> +#include >>> + >>> +static u_int random_rndr_read(void *, u_int); >>> + >>> +static bool has_rndr; >>> +static struct random_source random_armv8_rndr = { >>> + .rs_ident = "Armv8 rndr RNG", >>> + .rs_source = RANDOM_PURE_ARMV8, >>> + .rs_read = random_rndr_read, >>> +}; >>> + >>> +static inline int >>> +random_rndr_read_one(u_long *buf) >>> +{ >>> + u_long val; >>> + int loop, ret; >>> + >>> + loop = 10; >>> + do { >>> + __asm __volatile( >>> + ".arch_extension rng \n" >>> + "mrs %0, rndrrs \n" /* Read the random number */ >>> + "cset %w1, ne \n" /* 1 on success, 0 on failure */ >>> + ".arch_extension norng \n" >>> + : "=&r" (val), "=&r"(ret) :: "cc"); >> >> Early clobber doesn’t make sense with no inputs. > > This also breaks the aarch64 ubuntu-20.04 GitHub build, as its LLVM > doesn’t know about the RNG extension. Can you please stop breaking the > arm64 kernel build with older LLVM, this is far from the first time > it’s happened, and some of those never got fixed upstream, we just had > to hack around them downstream. The aarch64 GitHub build is still broken and has been broken now for a week. Can this be fixed to work with that version or should we deprecated support for LLVM 12 for aarch64? Morello LLVM is at LLVM 13 currently. -- John Baldwin