public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Rebecca Cran" <rebecca@nuviainc.com>
To: devel@edk2.groups.io, sami.mujawar@arm.com
Cc: Jiewen Yao <jiewen.yao@intel.com>,
	Jian J Wang <jian.j.wang@intel.com>,
	Michael D Kinney <michael.d.kinney@intel.com>,
	Liming Gao <gaoliming@byosoft.com.cn>,
	Zhiguang Liu <zhiguang.liu@intel.com>,
	Ard Biesheuvel <ardb+tianocore@kernel.org>,
	nd@arm.com
Subject: Re: [edk2-devel] [PATCH 2/3] MdePkg: Refactor BaseRngLib to support AARCH64 in addition to X86
Date: Thu, 6 May 2021 15:47:04 -0600	[thread overview]
Message-ID: <17a133b7-c3e0-773d-4aa8-78ce05050d33@nuviainc.com> (raw)
In-Reply-To: <c62272f7-73f9-b27a-3391-cb0338723d14@arm.com>

On 5/4/21 3:09 PM, Sami Mujawar wrote:

>> +EFIAPI
>> +BaseRngLibConstructor (
>> +  VOID
>> +  )
>> +{
>> +  UINT64 Isar0;
>> +  //
>> +  // Determine RNDR support by examining bits 63:60 of the ISAR0 register returned by
>> +  // MSR. A non-zero value indicates that the processor supports the RNDR instruction.
>> +  //
>> +  Isar0 = ArmReadIdIsar0 ();
>> +  ASSERT ((Isar0 & RNDR_MASK) != 0);
>> +  (void)Isar0;
> [SAMI] ASSERTs will vanish in the release builds. So, I think this needs 
> to be an if condition. If RNDR is not supported RETURN_UNSUPPORTED 
> should be returned.
> However, it appears thatthe auto generated function 
> ProcessLibraryConstructorList() disregards the error code returned by 
> the constructor (see Build\...\AutoGen.c files). So it looks like the 
> loading operation would continue in release builds despite of an error.
> I am not aware if this is the desired behavior or why the status code 
> returned by the constructor is disregarded.
> 
> However, this would be a probem in the current case as subsequent calls 
> to generate random numbers will result in an undefined instruction 
> exception.
> To prevent this, I think the above check should be done in either
>     - ArmRndr()/ArmRndrrs()
>    or
>     - preferably in ArchGetRandomNumberXX(), which should return an 
> error code EFI_UNSUPPORTED, EFI_NOT_READY or EFI_SUCCESS. However, the 
> impact on IA32/x64 code needs to be evaluated.

I've updated both the x86 and aarch64 code to add checks that the RDRAND 
and RNDR instructions are supported before trying to use them in 
GetRandomNumber[16,32,64,128].
However, it causes the X64 CryptoPkg host-based unit tests to fail 
because UnitTestHostBaseLibAsmCpuid just sets all the OUT parameters to 
0, which causes RngDxe to think RDRAND isn't supported.

Should the unit tests be using BaseRngLibTimerLib instead of BaseRngLib? 
Or should I leave the x86 code as it was, with the ASSERT in the 
constructor and no further checks at the time of use?

-- 
Rebecca Cran

  parent reply	other threads:[~2021-05-06 21:47 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-28 20:44 [PATCH 0/3] MdePkg,SecurityPkg: Update BaseRngLib and RngDxe to support ARMv8.5 FEAT_RNG Rebecca Cran
2021-04-28 20:44 ` [PATCH 1/3] MdePkg/BaseLib: Add support for ARMv8.5 RNG instructions Rebecca Cran
2021-04-29  1:08   ` 回复: " gaoliming
2021-05-05 21:02     ` [edk2-devel] " Rebecca Cran
2021-05-04 21:06   ` Sami Mujawar
2021-05-04 21:42     ` Rebecca Cran
2021-04-28 20:44 ` [PATCH 2/3] MdePkg: Refactor BaseRngLib to support AARCH64 in addition to X86 Rebecca Cran
2021-04-29  1:10   ` 回复: " gaoliming
2021-04-29  3:01     ` [edk2-devel] " Rebecca Cran
2021-05-04 21:09   ` Sami Mujawar
2021-05-05 19:27     ` [edk2-devel] " Rebecca Cran
2021-05-06 21:47     ` Rebecca Cran [this message]
2021-04-28 20:44 ` [PATCH 3/3] SecurityPkg: Add support for RngDxe on AARCH64 Rebecca Cran
2021-04-29  1:13   ` 回复: " gaoliming
2021-04-29 15:50     ` [edk2-devel] " Rebecca Cran
2021-04-29 10:35   ` Ard Biesheuvel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=17a133b7-c3e0-773d-4aa8-78ce05050d33@nuviainc.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox