Hi Ard, On Fri, Nov 11, 2022 at 8:47 AM Ard Biesheuvel <a...@kernel.org> wrote: > > On Fri, 11 Nov 2022 at 03:41, Jason A. Donenfeld <ja...@zx2c4.com> wrote: > > > > Hi Ard, > > > > On Thu, Nov 10, 2022 at 2:48 PM Ard Biesheuvel <a...@kernel.org> 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 <ja...@zx2c4.com> > > > > 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 <ja...@zx2c4.com> > > > > 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.
That all seems reasonable to me, your arguments about secure world etc. So in case there's another rng dxe available, we can just skip the (more expensive) virtio initialization, and this will make things generally simpler too. Sounds alright. Jason -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#96309): https://edk2.groups.io/g/devel/message/96309 Mute This Topic: https://groups.io/mt/94935839/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-