diff options
author | Phil Noh <Phil.Noh@amd.com> | 2024-11-21 10:05:01 -0600 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2024-11-22 17:11:25 +0000 |
commit | edb312d5d0f00685e75639b8607d54c93d47aca8 (patch) | |
tree | 52ebe3ae103a97d6d701633ae22592aa5a4e6e0a /MdePkg | |
parent | 4d3cf37ff05d532c5750f6387193c3f30f2c401b (diff) | |
download | edk2-edb312d5d0f00685e75639b8607d54c93d47aca8.tar.gz |
MdePkg/BaseRngLib: Remove global variable for RDRAND state update
As a BASE type library, some PEI drivers could link and use it.
Tcg2Pei.inf is an example. On edk2-stable202408 version, PEI drivers
that link the library include the global variable of mRdRandSupported.
The previous commit (c3a8ca7) that refers to the global variable actually
is found to influence the link status. Updating the global variable
in PEI drivers could affect the following issues.
PEI ROM Boot : Global variable is not updated
PEI RAM Boot : PEI FV integration/security check is failed
To address these issues, remove the global variable usage.
Signed-off-by: Phil Noh <Phil.Noh@amd.com>
Diffstat (limited to 'MdePkg')
-rw-r--r-- | MdePkg/Library/BaseRngLib/Rand/RdRand.c | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/MdePkg/Library/BaseRngLib/Rand/RdRand.c b/MdePkg/Library/BaseRngLib/Rand/RdRand.c index 06d2a6f12d..85441c392c 100644 --- a/MdePkg/Library/BaseRngLib/Rand/RdRand.c +++ b/MdePkg/Library/BaseRngLib/Rand/RdRand.c @@ -2,6 +2,7 @@ Random number generator services that uses RdRand instruction access
to provide high-quality random numbers.
+Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
Copyright (c) 2023, Arm Limited. All rights reserved.<BR>
Copyright (c) 2022, Pedro Falcato. All rights reserved.<BR>
Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR>
@@ -23,8 +24,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent //
#define RDRAND_MASK BIT30
-STATIC BOOLEAN mRdRandSupported;
-
//
// Intel SDM says 10 tries is good enough for reliable RDRAND usage.
//
@@ -124,20 +123,6 @@ BaseRngLibConstructor ( VOID
)
{
- UINT32 RegEcx;
-
- //
- // Determine RDRAND support by examining bit 30 of the ECX register returned by
- // CPUID. A value of 1 indicates that processor support RDRAND instruction.
- //
- AsmCpuid (1, 0, 0, &RegEcx, 0);
-
- mRdRandSupported = ((RegEcx & RDRAND_MASK) == RDRAND_MASK);
-
- if (mRdRandSupported) {
- mRdRandSupported = TestRdRand ();
- }
-
return EFI_SUCCESS;
}
@@ -156,7 +141,6 @@ ArchGetRandomNumber16 ( OUT UINT16 *Rand
)
{
- ASSERT (mRdRandSupported);
return AsmRdRand16 (Rand);
}
@@ -175,7 +159,6 @@ ArchGetRandomNumber32 ( OUT UINT32 *Rand
)
{
- ASSERT (mRdRandSupported);
return AsmRdRand32 (Rand);
}
@@ -194,7 +177,6 @@ ArchGetRandomNumber64 ( OUT UINT64 *Rand
)
{
- ASSERT (mRdRandSupported);
return AsmRdRand64 (Rand);
}
@@ -211,7 +193,22 @@ ArchIsRngSupported ( VOID
)
{
- return mRdRandSupported;
+ BOOLEAN RdRandSupported;
+ UINT32 RegEcx;
+
+ //
+ // Determine RDRAND support by examining bit 30 of the ECX register returned by
+ // CPUID. A value of 1 indicates that processor support RDRAND instruction.
+ //
+ AsmCpuid (1, 0, 0, &RegEcx, 0);
+
+ RdRandSupported = ((RegEcx & RDRAND_MASK) == RDRAND_MASK);
+
+ if (RdRandSupported) {
+ RdRandSupported = TestRdRand ();
+ }
+
+ return RdRandSupported;
}
/**
|