From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web09.3041.1668152856430122365 for ; Thu, 10 Nov 2022 23:47:36 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aaWputfm; spf=pass (domain: kernel.org, ip: 139.178.84.217, mailfrom: ardb@kernel.org) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9F7BD61EC3 for ; Fri, 11 Nov 2022 07:47:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F32EC433B5 for ; Fri, 11 Nov 2022 07:47:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668152855; bh=VAqpxHyN7NFfWIEqd1VFda1q7isdvGz6iohQKowl3VY=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=aaWputfmLudq0ZxUf2NiiMYpmdpozQqcGBszeRe2gYTAcfx+X+XVtHxRBZ1sXa88U vfKWsSaxYADepH5Yd3u8QjRZGAgAP4kz3rfiulIrfQ10MW/qo/DgEL4miCY2RA3bnn j5+ubxlXwp66ltHEgIY0PAEudgVN/ZK2V0ACLUarIB4QYzegLkhsMasMsihQx8UjTQ JczBLCuD+PiC9fwh9QVNoAiqoel4Ufdp1hzsHe+/puyRzsvPb/QlX/Ds9BysqULUzn PM/wdG6i0XT4uSCJc6lCTytA7m7dVGCF18SZccImNq02p1zvz8kx3I86GzPiQIYYX4 oa0juarhAApNw== Received: by mail-lj1-f175.google.com with SMTP id d3so3656873ljl.1 for ; Thu, 10 Nov 2022 23:47:34 -0800 (PST) X-Gm-Message-State: ANoB5pluCB6Zj+nJJHmRcHmCQkzBYKSxrKa/oQe4cVlHfNLqcRHhFlCU 6oqxjfiiJC92GfLQmxcdRXxHa+6fJvcUryS+8tY= X-Google-Smtp-Source: AA0mqf4f/1ZcxI9F018es19jPC/ReV4sYha8Ey7Re1U/dYGrtTGBX4qCNhVm+iWHR7nG64lNKWNpnDzbFNFdvg4srMo= X-Received: by 2002:a2e:b117:0:b0:277:96a:5c32 with SMTP id p23-20020a2eb117000000b00277096a5c32mr237001ljl.415.1668152853061; Thu, 10 Nov 2022 23:47:33 -0800 (PST) MIME-Version: 1.0 References: <20221110134738.3798618-1-ardb@kernel.org> In-Reply-To: From: "Ard Biesheuvel" Date: Fri, 11 Nov 2022 08:47:21 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 0/3] OVMF: support EFI_RNG_PROTOCOL without virtio-rng To: "Jason A. Donenfeld" Cc: devel@edk2.groups.io, Liming Gao , Rebecca Cran , Pierre Gondois , Leif Lindholm , Sami Mujawar , Gerd Hoffmann Content-Type: text/plain; charset="UTF-8" On Fri, 11 Nov 2022 at 03:41, Jason A. Donenfeld wrote: > > Hi Ard, > > On Thu, Nov 10, 2022 at 2:48 PM Ard Biesheuvel wrote: > > > > Currently, we only expose EFI_RNG_PROTOCOL when running under QEMU if it > > exposes a virtio-rng device. This means that generic EFI apps or > > loaders have no access to an entropy source if this device is > > unavailable, unless they implement their own arch-specific handling to > > figure out whether any CPU instructions or monitor calls can be used > > instead. > > > > So let's wire those up as EFI_RNG_PROTOCOL implementations as well, > > using the existing drivers and libraries. > > I tested this series on x86 and it appears to work as expected. Thanks > for putting this together. So, > > Tested-by: Jason A. Donenfeld > > On very brief inspection, this also looks good, though I'm not really > an EDK2 expert and my review isn't very thorough. But in case it > helps, which you can take or leave, > > Reviewed-by: Jason A. Donenfeld > Thanks. > My only question is how it chooses which RNG source to use in the > event that multiple are available. I would think preferring virtio-rng > if available is the right thing there. If it's based on the order of > the items in the .dsc file, then it looks like this series is doing > the right thing. > No, it is essentially arbitrary (but not random :-)) We already have special handling for the virtio RNG device in the BDS code, because normally, EFI only dispatches drivers for devices that it needs to boot (i..e, it walks the device path of the boot entry and only connects a device to its driver at each stage if it needs to do so to get to the next one) So connecting the virtio-rng device to its driver needs to be done explicitly, or it may not be connected at all. We handle this in ConnectVirtioPciRng() for x86 and some similar code exists in ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBm.c On ARM, the RngDxe wired up by this patch is backed by a hypervisor or secure world firmware service, rather than by the VMM, so in the ARM case, I think this one is the preferred one given that the VMM is generally less trusted (although that distinction really only matters for confidential compute). On x86, we use the RdRand instruction, which is also independent from the VMM, so I'd assume this is the preferred choice, no? Or do you have concerns about broken implementations? Another distinction is that the ARM version only implements EFI_RNG_ALGORITHM_RAW, whereas x86 also implements EFI_RNG_ALGORITHM_SP800_90_CTR_256_GUID. (virtio-rng also only implements EFI_RNG_ALGORITHM_RAW). This likely does not matter at all, but it is nevertheless good to call out while we decide which driver to give precedence. Another thing to note is that we generally try very hard to do as little as possible at boot time (although you might get a different impression when looking at the code :-)). So simply skipping the virtio-rng driver dispatch if some implementation of EFI_RNG_PROTOCOL is already available seems appropriate from that angle as well.