From nobody Wed Nov 29 13:36:40 2023 X-Original-To: dev-commits-src-all@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 4SgL2w5MXRz52jtq for ; Wed, 29 Nov 2023 13:36:56 +0000 (UTC) (envelope-from bT.wtqgzz4f30=pfz97fk8457t=u8ed1yjih0@return.smtpservice.net) Received: from e2i190.smtp2go.com (e2i190.smtp2go.com [103.2.140.190]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4SgL2v65bcz4Q7H for ; Wed, 29 Nov 2023 13:36:55 +0000 (UTC) (envelope-from bT.wtqgzz4f30=pfz97fk8457t=u8ed1yjih0@return.smtpservice.net) Authentication-Results: mx1.freebsd.org; dkim=none ("invalid DKIM record") header.d=smtpservice.net header.s=mgy720.a1-4.dyn header.b=FyJozi8f; spf=pass (mx1.freebsd.org: domain of "bT.wtqgzz4f30=pfz97fk8457t=u8ed1yjih0@return.smtpservice.net" designates 103.2.140.190 as permitted sender) smtp.mailfrom="bT.wtqgzz4f30=pfz97fk8457t=u8ed1yjih0@return.smtpservice.net"; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=smtpservice.net; s=mgy720.a1-4.dyn; x=1701265915; h=Feedback-ID: X-Smtpcorp-Track:To:Date:Subject:Message-Id:From:Reply-To:Sender: List-Unsubscribe; bh=zlLIqYpnhHovu+qKNws5CjLcgDKSXhPv0nMmU6xpUSU=; b=FyJozi8f Et6a0G5OGmMllI82IrEaE/uwmdp/FrWFdW/qRvnudB5sIvi1uIhG6riSvOciidGHblUvIQ7QCEiTQ 2aSGBbKZXhtrN3yZtM57RSSmao4vQO6GjlvGYxwjPuUSRciun7rWprUwr+pU+eDFMU9gAOBNg5xQE vTeH3kGKRcwfQioio35oMx1gQvs8uauQzLJdrHgVsIAHCssKTVnwX6IjMnAlYTqbIEmrnECflEois lUIVj5QmpudhAbf0QC1S+l4R/XNtgvRA4voA9QU1WPpvxTgrxNwbXWdAxPMR+lHTFdzhiu8GjFQfB fT23338Q652kZqfXdyJGfworNA==; Received: from [10.176.58.103] (helo=SmtpCorp) by smtpcorp.com with esmtpsa (TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.94.2-S2G) (envelope-from ) id 1r8KkF-Y8PGM5-Rm; Wed, 29 Nov 2023 13:36:51 +0000 Received: from [10.99.243.232] (helo=morbo.fubar.geek.nz) by smtpcorp.com with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96.1-S2G) (envelope-from ) id 1r8KkF-9EPw8Y-1k; Wed, 29 Nov 2023 13:36:51 +0000 Received: from smtpclient.apple (cpc91210-cmbg18-2-0-cust37.5-4.cable.virginm.net [81.102.44.38]) by morbo.fubar.geek.nz (Postfix) with ESMTPSA id B4D6835E67; Wed, 29 Nov 2023 13:36:50 +0000 (UTC) From: Andrew Turner Message-Id: Content-Type: multipart/alternative; boundary="Apple-Mail=_02C5D982-810F-4E82-812F-EC44B08517A3" List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.100.2.1.4\)) Subject: Re: git: 9eecef052155 - main - Add an Armv8 rndr random number provider Date: Wed, 29 Nov 2023 13:36:40 +0000 In-Reply-To: Cc: "src-committers@freebsd.org" , "dev-commits-src-all@freebsd.org" , "dev-commits-src-main@freebsd.org" , Jessica Clarke To: John Baldwin References: <202311151812.3AFICLIs077567@gitrepo.freebsd.org> <2423E245-0F1B-4195-A766-166183774421@freebsd.org> X-Mailer: Apple Mail (2.3774.100.2.1.4) X-Smtpcorp-Track: 1r8KkF9Eew8Y1k.ZA5yay9tbb_tZ Feedback-ID: 790814m:790814amQcrys:790814sbzm_Pu5WD X-Report-Abuse: Please forward a copy of this message, including all headers, to X-Spamd-Result: default: False [-1.81 / 15.00]; NEURAL_HAM_SHORT(-1.00)[-1.000]; NEURAL_HAM_LONG(-0.80)[-0.798]; MV_CASE(0.50)[]; NEURAL_HAM_MEDIUM(-0.41)[-0.407]; FORGED_SENDER(0.30)[andrew@FreeBSD.org,bT.wtqgzz4f30=pfz97fk8457t=u8ed1yjih0@return.smtpservice.net]; R_SPF_ALLOW(-0.20)[+ip4:103.2.140.0/22]; RCVD_IN_DNSWL_LOW(-0.10)[103.2.140.190:from]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; DKIM_TRACE(0.00)[smtpservice.net:~]; ASN(0.00)[asn:23352, ipnet:103.2.140.0/22, country:US]; MIME_TRACE(0.00)[0:+,1:+,2:~]; R_DKIM_PERMFAIL(0.00)[smtpservice.net:s=mgy720.a1-4.dyn]; MLMMJ_DEST(0.00)[dev-commits-src-all@FreeBSD.org]; TO_MATCH_ENVRCPT_SOME(0.00)[]; TO_DN_EQ_ADDR_SOME(0.00)[]; FROM_NEQ_ENVFROM(0.00)[andrew@FreeBSD.org,bT.wtqgzz4f30=pfz97fk8457t=u8ed1yjih0@return.smtpservice.net]; FROM_HAS_DN(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; TO_DN_SOME(0.00)[]; ARC_NA(0.00)[]; DMARC_NA(0.00)[freebsd.org]; RCPT_COUNT_FIVE(0.00)[5]; RCVD_TLS_ALL(0.00)[] X-Rspamd-Queue-Id: 4SgL2v65bcz4Q7H X-Spamd-Bar: - --Apple-Mail=_02C5D982-810F-4E82-812F-EC44B08517A3 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On 22 Nov 2023, at 18:14, John Baldwin wrote: >=20 > On 11/15/23 4:29 PM, Jessica Clarke wrote: >> On 15 Nov 2023, at 18:27, Jessica Clarke wrote: >>>=20 >>> On 15 Nov 2023, at 18:12, Andrew Turner wrote: >>>>=20 >>>> The branch main has been updated by andrew: >>>>=20 >>>> URL: = https://cgit.FreeBSD.org/src/commit/?id=3D9eecef052155646fbc5f8f533b952b37= 2572d06a >>>>=20 >>>> commit 9eecef052155646fbc5f8f533b952b372572d06a >>>> Author: Andrew Turner >>>> AuthorDate: 2023-11-15 17:42:02 +0000 >>>> Commit: Andrew Turner >>>> CommitDate: 2023-11-15 18:05:08 +0000 >>>>=20 >>>> Add an Armv8 rndr random number provider >>>>=20 >>>> 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. >>>>=20 >>>> 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. >>>>=20 >>>> 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. >>>>=20 >>>> 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(+) >>>>=20 >>>> 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 >>>>=20 >>>> # 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 >>>>=20 >>>> +dev/random/armv8rng.c optional armv8_rng !random_loadable >>>> + >>>> dev/safexcel/safexcel.c optional safexcel fdt >>>>=20 >>>> 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 =3D { >>>> + .rs_ident =3D "Armv8 rndr RNG", >>>> + .rs_source =3D RANDOM_PURE_ARMV8, >>>> + .rs_read =3D random_rndr_read, >>>> +}; >>>> + >>>> +static inline int >>>> +random_rndr_read_one(u_long *buf) >>>> +{ >>>> + u_long val; >>>> + int loop, ret; >>>> + >>>> + loop =3D 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" >>>> + : "=3D&r" (val), "=3D&r"(ret) :: "cc"); >>>=20 >>> Early clobber doesn=E2=80=99t make sense with no inputs. >> This also breaks the aarch64 ubuntu-20.04 GitHub build, as its LLVM >> doesn=E2=80=99t 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=E2=80=99s happened, and some of those never got fixed upstream, we = just had >> to hack around them downstream. >=20 > 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. I think depicting LLVM 12 is best. There is https://apt.llvm.org/ that = may be usable to get a toolchain to build FreeBSD on older Ubuntu and = Debian installs. I=E2=80=99m happy to keep 13 as the baseline for now, but expect we will = find it=E2=80=99s too old as I work through adding support for newer = Architecture features. Andrew= --Apple-Mail=_02C5D982-810F-4E82-812F-EC44B08517A3 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

On 22 Nov 2023, at 18:14, John Baldwin = <jhb@FreeBSD.org> wrote:

On 11/15/23 4:29 PM, Jessica Clarke = wrote:
On 15 Nov 2023, at 18:27, Jessica Clarke = <jrtc27@FreeBSD.org> wrote:

On 15 = Nov 2023, at 18:12, Andrew Turner <andrew@FreeBSD.org> = wrote:

The branch main has been updated = by andrew:

URL: = https://cgit.FreeBSD.org/src/commit/?id=3D9eecef052155646fbc5f8f533b952b37= 2572d06a

commit = 9eecef052155646fbc5f8f533b952b372572d06a
Author: =     Andrew Turner = <andrew@FreeBSD.org>
AuthorDate: 2023-11-15 17:42:02 = +0000
Commit:     Andrew Turner = <andrew@FreeBSD.org>
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 =             &n= bsp;   |   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 <sys/cdefs.h>
+
+#include = <sys/param.h>
+#include <sys/systm.h>
+#include = <sys/conf.h>
+#include <sys/kernel.h>
+#include = <sys/lock.h>
+#include <sys/malloc.h>
+#include = <sys/module.h>
+#include <sys/random.h>
+
+#include = <machine/armreg.h>
+
+#include = <dev/random/randomdev.h>
+
+static u_int = random_rndr_read(void *, u_int);
+
+static bool = has_rndr;
+static struct random_source random_armv8_rndr =3D {
+ = .rs_ident =3D "Armv8 rndr RNG",
+ .rs_source =3D = RANDOM_PURE_ARMV8,
+ .rs_read =3D = random_rndr_read,
+};
+
+static inline = int
+random_rndr_read_one(u_long *buf)
+{
+ u_long val;
+ = int loop, ret;
+
+ loop =3D 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"
+    : = "=3D&r" (val), "=3D&r"(ret) :: "cc");

Early = clobber doesn=E2=80=99t make sense with no inputs.
This = also breaks the aarch64 ubuntu-20.04 GitHub build, as its = LLVM
doesn=E2=80=99t 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=E2=80=99s 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.

I think depicting LLVM 12 is = best. There is https://apt.llvm.org/ that may be usable to get a = toolchain to build FreeBSD on older Ubuntu and Debian = installs.

I=E2=80=99m happy to keep 13 as the = baseline for now, but expect we will find it=E2=80=99s too old as I work = through adding support for newer Architecture = features.

Andrew
= --Apple-Mail=_02C5D982-810F-4E82-812F-EC44B08517A3--