Skip to content

Commit edb312d

Browse files
philnoh2mergify[bot]
authored andcommitted
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>
1 parent 4d3cf37 commit edb312d

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

MdePkg/Library/BaseRngLib/Rand/RdRand.c

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Random number generator services that uses RdRand instruction access
33
to provide high-quality random numbers.
44
5+
Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
56
Copyright (c) 2023, Arm Limited. All rights reserved.<BR>
67
Copyright (c) 2022, Pedro Falcato. All rights reserved.<BR>
78
Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR>
@@ -23,8 +24,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
2324
//
2425
#define RDRAND_MASK BIT30
2526

26-
STATIC BOOLEAN mRdRandSupported;
27-
2827
//
2928
// Intel SDM says 10 tries is good enough for reliable RDRAND usage.
3029
//
@@ -124,20 +123,6 @@ BaseRngLibConstructor (
124123
VOID
125124
)
126125
{
127-
UINT32 RegEcx;
128-
129-
//
130-
// Determine RDRAND support by examining bit 30 of the ECX register returned by
131-
// CPUID. A value of 1 indicates that processor support RDRAND instruction.
132-
//
133-
AsmCpuid (1, 0, 0, &RegEcx, 0);
134-
135-
mRdRandSupported = ((RegEcx & RDRAND_MASK) == RDRAND_MASK);
136-
137-
if (mRdRandSupported) {
138-
mRdRandSupported = TestRdRand ();
139-
}
140-
141126
return EFI_SUCCESS;
142127
}
143128

@@ -156,7 +141,6 @@ ArchGetRandomNumber16 (
156141
OUT UINT16 *Rand
157142
)
158143
{
159-
ASSERT (mRdRandSupported);
160144
return AsmRdRand16 (Rand);
161145
}
162146

@@ -175,7 +159,6 @@ ArchGetRandomNumber32 (
175159
OUT UINT32 *Rand
176160
)
177161
{
178-
ASSERT (mRdRandSupported);
179162
return AsmRdRand32 (Rand);
180163
}
181164

@@ -194,7 +177,6 @@ ArchGetRandomNumber64 (
194177
OUT UINT64 *Rand
195178
)
196179
{
197-
ASSERT (mRdRandSupported);
198180
return AsmRdRand64 (Rand);
199181
}
200182

@@ -211,7 +193,22 @@ ArchIsRngSupported (
211193
VOID
212194
)
213195
{
214-
return mRdRandSupported;
196+
BOOLEAN RdRandSupported;
197+
UINT32 RegEcx;
198+
199+
//
200+
// Determine RDRAND support by examining bit 30 of the ECX register returned by
201+
// CPUID. A value of 1 indicates that processor support RDRAND instruction.
202+
//
203+
AsmCpuid (1, 0, 0, &RegEcx, 0);
204+
205+
RdRandSupported = ((RegEcx & RDRAND_MASK) == RDRAND_MASK);
206+
207+
if (RdRandSupported) {
208+
RdRandSupported = TestRdRand ();
209+
}
210+
211+
return RdRandSupported;
215212
}
216213

217214
/**

0 commit comments

Comments
 (0)