From nobody Tue Nov 28 23:40:49 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 4SfzVS0Qk9z52l23 for ; Tue, 28 Nov 2023 23:41:04 +0000 (UTC) (envelope-from jrtc27@jrtc27.com) Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4SfzVR1yYxz3WcL for ; Tue, 28 Nov 2023 23:41:03 +0000 (UTC) (envelope-from jrtc27@jrtc27.com) Authentication-Results: mx1.freebsd.org; dkim=none; spf=pass (mx1.freebsd.org: domain of jrtc27@jrtc27.com designates 209.85.128.52 as permitted sender) smtp.mailfrom=jrtc27@jrtc27.com; dmarc=none Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-40b4734b975so20887815e9.2 for ; Tue, 28 Nov 2023 15:41:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701214861; x=1701819661; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+3QKsaJj/RWaDAF8ycrdCmCVX6f9Xo1yv1JcSB2x5YE=; b=UbL23fW8cP2ze2vGG8dmAHrTWYV6Nua/RZdVy7MCU48WIDUPAyozJATmJW66YYCiAC jAS/VXWv9UTgZZBuLtDn4p9XfI/pfnCATvGXxd203s4QGKes4RY139zRc/hECMtetyRs QH7gfjd0z4vF/4Y+dzGnxA8w1lG4uaYMU6O3T5srkkuU/Rv0phGOkwdvszHYX90Tjr1B XDxIcXvKLz0YCybMPjUb8OasLOnveI0vPCQH4tOwKdfxcX5VppwPq9290lh9cQxZzQlA +3mz0EYk9GtvFM6iFAfWEDPFzL3WWFiwkdsTymc/2ppP1WSiGoG8qOUTbSYoEUnAR+2d 4CSg== X-Gm-Message-State: AOJu0Yzti5Awcx9hygoT30U7j4kT88MdU3G/PqecTxEf8crgupPTt1Sp t3blZAs9ZEnnPM1YOpRE1G+09hVk/z4ajOPvOic= X-Google-Smtp-Source: AGHT+IG7/jPrxn7hzOlGa6w5DXAQsvOw26Ez8kFO3FSpLFwguw7tyREYgFC/7qDOOCBaDIxr+as71A== X-Received: by 2002:a05:600c:4ec7:b0:40b:4b93:a369 with SMTP id g7-20020a05600c4ec700b0040b4b93a369mr2592984wmq.14.1701214861089; Tue, 28 Nov 2023 15:41:01 -0800 (PST) Received: from smtpclient.apple ([131.111.5.246]) by smtp.gmail.com with ESMTPSA id a8-20020adffb88000000b00333083a20e5sm4910777wrr.113.2023.11.28.15.40.59 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Nov 2023 15:40:59 -0800 (PST) Content-Type: text/plain; charset=utf-8 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.200.91.1.1\)) Subject: Re: git: 9eecef052155 - main - Add an Armv8 rndr random number provider From: Jessica Clarke In-Reply-To: Date: Tue, 28 Nov 2023 23:40:49 +0000 Cc: Andrew Turner , "src-committers@freebsd.org" , "dev-commits-src-all@freebsd.org" , "dev-commits-src-main@freebsd.org" Content-Transfer-Encoding: quoted-printable Message-Id: <0831C0D9-428C-4DA7-A205-277B6729DB8F@freebsd.org> References: <202311151812.3AFICLIs077567@gitrepo.freebsd.org> <2423E245-0F1B-4195-A766-166183774421@freebsd.org> To: John Baldwin X-Mailer: Apple Mail (2.3774.200.91.1.1) X-Spamd-Result: default: False [-2.23 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.88)[-0.879]; NEURAL_HAM_MEDIUM(-0.85)[-0.853]; MV_CASE(0.50)[]; FORGED_SENDER(0.30)[jrtc27@freebsd.org,jrtc27@jrtc27.com]; R_SPF_ALLOW(-0.20)[+ip4:209.85.128.0/17]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[dev-commits-src-all@freebsd.org]; DMARC_NA(0.00)[freebsd.org]; TO_DN_EQ_ADDR_SOME(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; FROM_HAS_DN(0.00)[]; MLMMJ_DEST(0.00)[dev-commits-src-all@freebsd.org]; RCVD_IN_DNSWL_NONE(0.00)[209.85.128.52:from]; FREEFALL_USER(0.00)[jrtc27]; MIME_TRACE(0.00)[0:+]; RWL_MAILSPIKE_POSSIBLE(0.00)[209.85.128.52:from]; RCPT_COUNT_FIVE(0.00)[5]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US]; R_DKIM_NA(0.00)[]; FROM_NEQ_ENVFROM(0.00)[jrtc27@freebsd.org,jrtc27@jrtc27.com]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_COUNT_TWO(0.00)[2] X-Rspamd-Queue-Id: 4SfzVR1yYxz3WcL X-Spamd-Bar: -- 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. It=E2=80=99s been another week. I intend to revert this tomorrow unless = a real alternative solution is put forwards. We can=E2=80=99t keep leaving CI = broken for weeks on end due to a lack of pre-commit testing and committer responsiveness. Jess