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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A640FCD4F59 for ; Thu, 5 Sep 2024 08:19:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=tBmvfxauYz1L5z0Sxd1r9l2MtdaVr9hv8U5W6iBP7tA=; b=RqX+LLTU1DxQ2Gc5wOtOXncsvM mzWEatAKkGK5Q1almBxdM7zsNHoZ65MZozR6ESmJSq/XCUss/BAITyEoKp+bY36pwdtqbNVdy92b0 yXxft60dDviGhOdnAToVSXl6Rjef1HwH1ZWzxdlC7FTrnNPe8DMTPfvxnDcY9vqinkf/FbkN3u4Vj UyHtcg1hFPUStogllVUOhJYZ/W5cEGtITj7geZi/OWPhCC0yH7lvfgefxuY3ju6TsIJJpl65XYMM7 p77pWMUZGC0tYKgdbdPFfHZHfPhMDbu/jZP1m3Ag1i5C64Xa2gVXaKVHUf9M9dhl1ml0UE/UTRUtS vzGoHt7A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm7hd-00000007XOH-1HGA; Thu, 05 Sep 2024 08:18:53 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm7gf-00000007X8w-0DZ9 for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 08:17:54 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id CF7945C54AE; Thu, 5 Sep 2024 08:17:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01043C4CEC6; Thu, 5 Sep 2024 08:17:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725524272; bh=4BgpG7pyrHOCPPJY6stTA1hZpalX0Vyz6jSvDtEs21k=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=WWyeyYtcPUUdm/2HfEdk3D8kxVLsWtQ/nWkjwM9J6Y/elUalWvhJ7Mp2OBGhQVQxN MpVZ3TSNFobeWrxwDPNgJ/a4uLzuh/G7762jrsVXNM/g3Xe1qicjmGnLyS+gBvJIsN PqJbIHV+HCpLAc782dyqiZEopKjxo3NuWAQpTAM5yvxQOiIUdZESIfgBYXpRBkasBp J96jA9wuYLcy8E7//xMlT6TUc7Iq2xcXaYZuG2w6wGOCpRQKlJ2SuvIyMiw9m6HSao u2+aDQfskgGQpLtOAf2hD3BeNeyb+nOwQQ51V3glA43pRPwDagbd7bmI0taw1UFBKl BaajngYl/5dCw== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1sm7gb-009rov-Fa; Thu, 05 Sep 2024 09:17:49 +0100 Date: Thu, 05 Sep 2024 09:17:49 +0100 Message-ID: <86jzfqv7iq.wl-maz@kernel.org> From: Marc Zyngier To: Tangnianyao Cc: Ard Biesheuvel , Will Deacon , , , , , "guoyang (C)" Subject: Re: Question on get random long worse in VM than on host In-Reply-To: References: <214e37e9-7aba-1e61-f63f-85cb10c9a878@huawei.com> <86zfotuoio.wl-maz@kernel.org> <86y14dun1f.wl-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/29.4 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: tangnianyao@huawei.com, ardb@kernel.org, will@kernel.org, oliver.upton@linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, guoyang2@huawei.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240905_011753_246835_39BAE2A5 X-CRM114-Status: GOOD ( 33.89 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, 05 Sep 2024 04:12:42 +0100, Tangnianyao wrote: > > > > On 9/3/2024 23:04, Ard Biesheuvel wrote: > > On Tue, 3 Sept 2024 at 03:39, Tangnianyao wrote: > >> > >> > >> On 9/3/2024 5:26, Ard Biesheuvel wrote: > >>> On Sat, 31 Aug 2024 at 10:14, Marc Zyngier wrote: > >>>> On Sat, 31 Aug 2024 08:56:23 +0100, > >>>> Ard Biesheuvel wrote: > >>>>> As for RNDR/RNDRRS vs TRNG: the former is not a raw entropy source, it > >>>>> is a DRBG (or CSPRNG) which provides cryptographically secure random > >>>>> numbers whose security strength is limited by the size of the seed. > >>>>> TRNG does not have this limitation in principle, although non-p KVM > >>>>> happily seeds it from the kernel's entropy pool, which has the same > >>>>> limitation in practice. > >>>> Is that something we should address? I assume that this has an impact > >>>> on the quality of the provided random numbers? > >>>> > >>> To be honest, I personally find the distinction rather theoretical - I > >>> think it will be mostly the FIPS fetishists who may object to the > >>> seeding of a DRBG of security strength 'n' from the kernel entropy > >>> pool without proving that the sample has 'n' bits of entropy. > >>> > >>> For pKVM, the concern was that the untrusted host could observe and > >>> manipulate the entropy and therefore the protected guest's entropy > >>> source, which is why the hypervisor relays TRNG SMCCC calls directly > >>> to the secure firmware in that case. The quality of the entropy was > >>> never a concern here. > >>> > >>> . > >>> > >> Thank you for reply. > >> > >> In case that EL3 firmware not support SMCCC TRNG, host and guest can only > >> get randomness from DRBG-based RNDRRS, right? > >> > > There are other, non-architected ways too to get entropy and/or > > randomness. There are many hardware random number generator > > peripherals that the OS can drive directly, and there are vendor > > specific EL3 services too that a system might use. > > > > RNDR/RNDRRS does not exist yet in practical terms - there are very few > > SOCs that actually implement that used in the field. > > > >> In this case, guest get DRBG-based randomness via HVC and host, but the > >> randomness returned by host kvm is not really backed by EL3 SMCCC TRNG, > >> and actually get from DRBG-based RNDRRS. > >> Is this hvc process is redundancy? > >> > > I don't understand this question. How the host obtains its entropy > > and/or randomness and how the guest does it are completely separate > > concerns. > > > > . > > > > Process is different between host and guest in arch/arm64, arch_get_random_seed_longs. > (1) In host , smccc_trng_available is false, it get randomness from RNDRRS. > > (2) In guest, smccc_trng_available is true, because kvm emulate it. Guest use smccc trng > and hvc, and trap to host kvm. Then in host call stack: > kvm_smccc_call_handler > kvm_trng_call > kvm_trng_do_rnd > get_random_long > ... > arch_get_random_seed_longs > > host get randomness as (1) and return random u64 to guest. > So the randomness guest finally get is from RNDRRS too. > Can we let guest get randomness directly from RNDRRS, not using hvc first? > The process for guest like (1): > 1) kvm not emulated smccc trng for guest > 2) guest check smccc trng, and get smccc_trng_available=false > 3) guest get randomness from RNDRRS I think I gave you the answer to this in my first reply [1]. M. [1] https://lore.kernel.org/all/86zfotuoio.wl-maz@kernel.org/ -- Without deviation from the norm, progress is not possible.