From nobody Sat Jul 25 02:34:13 2026 Received: from vib-mx01.apple.com (vib-mx01.apple.com [17.132.96.0]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C12123B47F5 for ; Mon, 20 Jul 2026 15:09:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.132.96.0 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784560167; cv=none; b=mu7qQN7YO5iwpHfM30CoNImzjiw4PNTyS5yMpjSuLP16KRwRnuVB9iajOBudSLdsKRYM/Wb3inaW2D+llcZ+BusG3SNwViCY4QoarRDRXeGPKYMZKq7DFsTAv/VHgRTaJqgE//LIWV2e0ft1e2TbKCMV48SUUEeI0eQoyStNyRk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784560167; c=relaxed/simple; bh=0Ma7AbOpX/k0VyxNmmwkpZqmtGtZ8w7toBJbJg0RVug=; h=From:To:Cc:Subject:Date:Message-id:MIME-version; b=EtbDmBfpnygZv5SZJFUec/97OL4tkZVWrJmB56xRcNtW6IJCorZ/g2l8bnK1Fwh/vN9UniFR3T6RX6EsAqdAAddVIMVPR4ezykiZlYz9zDlpoAFRb7Ao9qOiwXXzfVrdNa5aScDF32UOcoYOv777UR14S3aooLnjy4Agfe8jEZ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=apple.com; spf=pass smtp.mailfrom=apple.com; dkim=pass (2048-bit key) header.d=apple.com header.i=@apple.com header.b=s5Dn55Uo; arc=none smtp.client-ip=17.132.96.0 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=apple.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=apple.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=apple.com header.i=@apple.com header.b="s5Dn55Uo" Received: from am11p01nt-mtap01.apple.com (am11p01nt-mtap01.ise.apple.com [100.85.69.146]) by vb11p01nt-mxp01.apple.com (Oracle Communications Messaging Server 8.1.0.28.20250821 64bit (built Aug 21 2025)) with ESMTPS id <0TIH02LQT8NGQQ00@vb11p01nt-mxp01.apple.com> for linux-kernel@vger.kernel.org; Mon, 20 Jul 2026 14:09:17 +0000 (GMT) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-07-20_03,2026-07-20_02,2025-10-01_01 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=apple.com; h=cc : content-transfer-encoding : date : from : message-id : mime-version : subject : to; s=20180706; bh=rpvkHatc5venoF9j9L6XoNX8JdOk4x19jKiLt8qwkGg=; b=s5Dn55UoMmTP/XSzcCqKoFDU27jZJDMKcRoIaw0yOCcD4zfZwtybrM5EV0UEgkd0UUa5 qj05K/cVWKQ2ne4l22SABHOoBnNwxUriDuPLMO6lBsY4CZJCbfhGR9YUwmvtR6CCpTdS oEq/IJhF5lcxSGloZfAna1t88+bG3JA9qFmln7fw0GQpXQTzEgILpFQ9diww+y5ZmmzQ Oa/wCtNI1wKRL3MVSdVg6CJUOP6IgEEO/8kIfwyUNFZ+H92qAI3fywRwWLK5SxA5+TRH p+CHJ34mqrGLG7ax6VgfkBYyBAnsyf20X/sxZ1ZTNYJ1k0kRkE4ygeTqfeXnSDFoQ2E5 /Q== Received: from am11p01nt-relayp03.apple.com (am11p01nt-relayp03.ise.apple.com [100.85.69.150]) by am11p01nt-mtap01.apple.com (Oracle Communications Messaging Server 8.1.0.28.20250821 64bit (built Aug 21 2025)) with ESMTPS id <0TIH1W79N8IV1210@am11p01nt-mtap01.apple.com>; Mon, 20 Jul 2026 14:06:32 +0000 (GMT) Received: from process_milters-daemon.am11p01nt-relayp03.apple.com by am11p01nt-relayp03.apple.com (Oracle Communications Messaging Server 8.1.0.28.20250821 64bit (built Aug 21 2025)) id <0TIH2D2008A70P00@am11p01nt-relayp03.apple.com>; Mon, 20 Jul 2026 14:06:31 +0000 (GMT) X-Va-A: X-Va-T-CD: ce4f70dc1a2240fbd24f73b1a9e97a59 X-Va-E-CD: 8ade7adb67953b6c8d3e3cec0ec7a4d5 X-Va-R-CD: 4aecd6208650d7300b2b78998d1f3b9e X-Va-ID: b321d080-9dd8-46af-ae81-ccd23a3de1a4 X-Va-CD: 0 X-V-A: X-V-T-CD: ce4f70dc1a2240fbd24f73b1a9e97a59 X-V-E-CD: 8ade7adb67953b6c8d3e3cec0ec7a4d5 X-V-R-CD: 4aecd6208650d7300b2b78998d1f3b9e X-V-ID: bddfdfeb-f8f1-4386-bb63-476d01f6b7b2 X-V-CD: 0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-07-20_03,2026-07-20_02,2025-10-01_01 Received: from amanp-m5d.apple.com (unknown [10.106.6.90]) by am11p01nt-relayp03.apple.com (Oracle Communications Messaging Server 8.1.0.28.20250821 64bit (built Aug 21 2025)) with ESMTP id <0TIH2COZ18IVW310@am11p01nt-relayp03.apple.com>; Mon, 20 Jul 2026 14:06:31 +0000 (GMT) From: Aman Priyadarshi To: catalin.marinas@arm.com, will@kernel.org Cc: Jason@zx2c4.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Aman Priyadarshi , Ard Biesheuvel Subject: [PATCH] arm64: archrandom: avoid trapping ID register read in __cpu_has_rng() Date: Mon, 20 Jul 2026 15:06:15 +0100 Message-id: <20260720140615.99343-1-amanp@apple.com> X-Mailer: git-send-email 2.54.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-version: 1.0 Content-transfer-encoding: quoted-printable Content-Type: text/plain; charset="utf-8" __cpu_has_rng() has an early-boot fallback, taken before the ARM64_HAS_RNG alternative is patched, that calls this_cpu_has_cap(ARM64_HAS_RNG). With SCOPE_LOCAL_CPU that resolves the capability by reading ID_AA64ISAR0_EL1 directly from hardware via __read_sysreg_by_encoding(), on every invocation. Until the CRNG is seeded, crng_make_state() routes every get_random_*() through extract_entropy(), which drains architectural entropy via arch_get_random_seed_longs()/arch_get_random_longs() and so calls __cpu_has_rng() several times per request. On a direct (non-EFI) boot there is no bootloader seed, so the CRNG stays unseeded for much of boot and essentially every early randomness consumer takes this path. Under virtualization this is costly: the hypervisor traps guest accesses to the ID registers (HCR_EL2.TID3), making each read a vmexit, producing ~200k trapped ID_AA64ISAR0_EL1 reads during boot. The register value is invariant, so read the sanitised feature register instead. read_sanitised_ftr_reg() returns the cached value from arm64_ftr_regs[] with no sysreg access, and hence no trap. That array is populated by cpuinfo_store_boot_cpu() in smp_prepare_boot_cpu(), before the first early RNG use in random_init_early(), so it is always valid here. With this change the trapped reads drop from ~200k to handful number of times, and the boot time drops roughly by 6.3% in the test environment. Fixes: 2c03e16f4499 ("random: remove early archrandom abstraction") Cc: Jason A. Donenfeld Cc: Ard Biesheuvel Cc: Will Deacon Signed-off-by: Aman Priyadarshi --- arch/arm64/include/asm/archrandom.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/archrandom.h b/arch/arm64/include/asm/a= rchrandom.h index 8babfbe31f95..8067e9a35641 100644 --- a/arch/arm64/include/asm/archrandom.h +++ b/arch/arm64/include/asm/archrandom.h @@ -61,8 +61,22 @@ static inline bool __arm64_rndrrs(unsigned long *v) =20 static __always_inline bool __cpu_has_rng(void) { - if (unlikely(!system_capabilities_finalized() && !preemptible())) - return this_cpu_has_cap(ARM64_HAS_RNG); + if (unlikely(!system_capabilities_finalized() && !preemptible())) { + /* + * Until the ARM64_HAS_RNG alternative is patched we can't use + * the static-branch form, so consult the feature register + * directly. Don't use this_cpu_has_cap() here: it reads + * ID_AA64ISAR0_EL1 from hardware on every call, under + * virtualization each ID register read traps to the hypervisor + * (HCR_EL2.TID3) -- producing a storm of vmexits during boot. + * The sanitised value is cached in memory. + */ + u64 isar0 =3D read_sanitised_ftr_reg(SYS_ID_AA64ISAR0_EL1); + + return cpuid_feature_extract_unsigned_field(isar0, + ID_AA64ISAR0_EL1_RNDR_SHIFT) >=3D + ID_AA64ISAR0_EL1_RNDR_IMP; + } return alternative_has_cap_unlikely(ARM64_HAS_RNG); } =20 --=20 2.54.0 (Apple Git-156)