Skip to content

Commit

Permalink
Merge branch 'master' into bitvarfix
Browse files Browse the repository at this point in the history
  • Loading branch information
dandanbi authored Nov 25, 2024
2 parents e0d1b03 + 8002056 commit 44e76d1
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 43 deletions.
32 changes: 21 additions & 11 deletions DynamicTablesPkg/Library/FdtHwInfoParserLib/Arm/Gic/ArmGicCParser.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ CpusNodeParser (
IN CONST VOID *Fdt,
IN INT32 CpusNode,
IN UINT32 GicVersion,
OUT CM_OBJ_DESCRIPTOR **NewGicCmObjDesc
OUT CM_OBJ_DESCRIPTOR **NewGicCmObjDesc,
OUT UINTN *CpuCount
)
{
EFI_STATUS Status;
Expand Down Expand Up @@ -202,6 +203,8 @@ CpusNodeParser (
return EFI_NOT_FOUND;
}

*CpuCount = CpuNodeCount;

// Allocate memory for CpuNodeCount CM_ARM_GICC_INFO structures.
GicCInfoBufferSize = CpuNodeCount * sizeof (CM_ARM_GICC_INFO);
GicCInfoBuffer = AllocateZeroPool (GicCInfoBufferSize);
Expand Down Expand Up @@ -280,6 +283,7 @@ EFIAPI
GicCIntcNodeParser (
IN CONST VOID *Fdt,
IN INT32 GicIntcNode,
IN UINTN CpuCount,
IN OUT CM_OBJ_DESCRIPTOR *GicCCmObjDesc
)
{
Expand All @@ -289,6 +293,8 @@ GicCIntcNodeParser (

CONST UINT8 *Data;
INT32 DataSize;
UINT32 MaintenanceInterrupt;
UINT32 Flags;

if (GicCCmObjDesc == NULL) {
ASSERT (0);
Expand All @@ -308,14 +314,17 @@ GicCIntcNodeParser (
// but it is assumed that only one Gic is available.
Data = fdt_getprop (Fdt, GicIntcNode, "interrupts", &DataSize);
if ((Data != NULL) && (DataSize == (IntCells * sizeof (UINT32)))) {
GicCInfo = (CM_ARM_GICC_INFO *)GicCCmObjDesc->Data;
GicCInfo->VGICMaintenanceInterrupt =
FdtGetInterruptId ((CONST UINT32 *)Data);
GicCInfo->Flags = DT_IRQ_IS_EDGE_TRIGGERED (
fdt32_to_cpu (((UINT32 *)Data)[IRQ_FLAGS_OFFSET])
) ?
EFI_ACPI_6_3_VGIC_MAINTENANCE_INTERRUPT_MODE_FLAGS :
0;
MaintenanceInterrupt = FdtGetInterruptId ((CONST UINT32 *)Data);
Flags = DT_IRQ_IS_EDGE_TRIGGERED (
fdt32_to_cpu (((UINT32 *)Data)[IRQ_FLAGS_OFFSET])
) ?
EFI_ACPI_6_3_VGIC_MAINTENANCE_INTERRUPT_MODE_FLAGS :
0;
for (GicCInfo = (CM_ARM_GICC_INFO *)GicCCmObjDesc->Data; CpuCount--; GicCInfo++) {
GicCInfo->VGICMaintenanceInterrupt = MaintenanceInterrupt;
GicCInfo->Flags |= Flags;
}

return Status;
} else if (DataSize < 0) {
// This property is optional and was not found. Just return.
Expand Down Expand Up @@ -816,6 +825,7 @@ ArmGicCInfoParser (
UINT32 GicVersion;
CM_OBJ_DESCRIPTOR *NewCmObjDesc;
VOID *Fdt;
UINTN CpuCount;

if (FdtParserHandle == NULL) {
ASSERT (0);
Expand Down Expand Up @@ -846,7 +856,7 @@ ArmGicCInfoParser (

// Parse the "cpus" nodes and its children "cpu" nodes,
// and create a CM_OBJ_DESCRIPTOR.
Status = CpusNodeParser (Fdt, FdtBranch, GicVersion, &NewCmObjDesc);
Status = CpusNodeParser (Fdt, FdtBranch, GicVersion, &NewCmObjDesc, &CpuCount);
if (EFI_ERROR (Status)) {
ASSERT (0);
return Status;
Expand Down Expand Up @@ -878,7 +888,7 @@ ArmGicCInfoParser (
}

// Parse the Gic information common to Gic v2 and v3.
Status = GicCIntcNodeParser (Fdt, IntcNode, NewCmObjDesc);
Status = GicCIntcNodeParser (Fdt, IntcNode, CpuCount, NewCmObjDesc);
if (EFI_ERROR (Status)) {
ASSERT (0);
goto exit_handler;
Expand Down
1 change: 1 addition & 0 deletions MdeModulePkg/Library/HobPrintLib/HobPrintLib.inf
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@
gEfiHobMemoryAllocBspStoreGuid
gEfiHobMemoryAllocStackGuid
gEfiMemoryTypeInformationGuid
gEfiHobMemoryAllocModuleGuid
37 changes: 17 additions & 20 deletions MdePkg/Library/BaseRngLib/Rand/RdRand.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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.
//
Expand Down Expand Up @@ -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;
}

Expand All @@ -156,7 +141,6 @@ ArchGetRandomNumber16 (
OUT UINT16 *Rand
)
{
ASSERT (mRdRandSupported);
return AsmRdRand16 (Rand);
}

Expand All @@ -175,7 +159,6 @@ ArchGetRandomNumber32 (
OUT UINT32 *Rand
)
{
ASSERT (mRdRandSupported);
return AsmRdRand32 (Rand);
}

Expand All @@ -194,7 +177,6 @@ ArchGetRandomNumber64 (
OUT UINT64 *Rand
)
{
ASSERT (mRdRandSupported);
return AsmRdRand64 (Rand);
}

Expand All @@ -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;
}

/**
Expand Down
1 change: 1 addition & 0 deletions MdePkg/Library/SmmPciExpressLib/SmmPciExpressLib.inf
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
PcdLib
DebugLib
IoLib
UefiBootServicesTableLib

[Pcd]
gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress ## CONSUMES
Expand Down
3 changes: 2 additions & 1 deletion NetworkPkg/Ip6Dxe/Ip6Impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ EfiIp6GetModeData (
return EFI_INVALID_PARAMETER;
}

OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
IpInstance = IP6_INSTANCE_FROM_PROTOCOL (This);
IpSb = IpInstance->Service;
IpIf = IpInstance->Interface;
Expand All @@ -70,6 +69,8 @@ EfiIp6GetModeData (
return EFI_INVALID_PARAMETER;
}

OldTpl = gBS->RaiseTPL (TPL_CALLBACK);

if (Ip6ModeData != NULL) {
//
// IsStarted is "whether the EfiIp6Configure has been called".
Expand Down
4 changes: 2 additions & 2 deletions NetworkPkg/SnpDxe/Get_status.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,12 @@ SnpUndi32GetStatus (

Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);

OldTpl = gBS->RaiseTPL (TPL_CALLBACK);

if (Snp == NULL) {
return EFI_DEVICE_ERROR;
}

OldTpl = gBS->RaiseTPL (TPL_CALLBACK);

switch (Snp->Mode.State) {
case EfiSimpleNetworkInitialized:
break;
Expand Down
4 changes: 2 additions & 2 deletions NetworkPkg/SnpDxe/Transmit.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,12 @@ SnpUndi32Transmit (

Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);

OldTpl = gBS->RaiseTPL (TPL_CALLBACK);

if (Snp == NULL) {
return EFI_DEVICE_ERROR;
}

OldTpl = gBS->RaiseTPL (TPL_CALLBACK);

switch (Snp->Mode.State) {
case EfiSimpleNetworkInitialized:
break;
Expand Down
2 changes: 2 additions & 0 deletions OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,8 @@ InitializeFvAndVariableStoreHeaders (
//
Fv = (EFI_FIRMWARE_VOLUME_HEADER *)Ptr;
Fv->Checksum = CalculateCheckSum16 (Ptr, Fv->HeaderLength);

DEBUG ((DEBUG_INFO, "EMU Variable FVB: Initialized FV using template structure\n"));
}

/**
Expand Down
32 changes: 30 additions & 2 deletions OvmfPkg/Library/PlatformInitLib/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <Guid/VariableFormat.h>
#include <OvmfPlatforms.h>
#include <Library/TdxLib.h>
#include <Library/MemEncryptSevLib.h>

#include <Library/PlatformInitLib.h>

Expand Down Expand Up @@ -774,6 +775,8 @@ PlatformValidateNvVarStore (
EFI_FIRMWARE_VOLUME_HEADER *NvVarStoreFvHeader;
VARIABLE_STORE_HEADER *NvVarStoreHeader;
AUTHENTICATED_VARIABLE_HEADER *VariableHeader;
BOOLEAN Retry;
EFI_STATUS Status;

static EFI_GUID FvHdrGUID = EFI_SYSTEM_NV_DATA_FV_GUID;
static EFI_GUID VarStoreHdrGUID = EFI_AUTHENTICATED_VARIABLE_GUID;
Expand All @@ -792,6 +795,15 @@ PlatformValidateNvVarStore (
//
NvVarStoreFvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)NvVarStoreBase;

//
// SEV and SEV-ES can use separate flash devices for OVMF code and
// OVMF variables. In this case, the OVMF variables will need to be
// mapped unencrypted. If the initial validation fails, remap the
// NV variable store as unencrypted and retry the validation.
//
Retry = MemEncryptSevIsEnabled ();

RETRY:
if ((!IsZeroBuffer (NvVarStoreFvHeader->ZeroVector, 16)) ||
(!CompareGuid (&FvHdrGUID, &NvVarStoreFvHeader->FileSystemGuid)) ||
(NvVarStoreFvHeader->Signature != EFI_FVH_SIGNATURE) ||
Expand All @@ -801,8 +813,24 @@ PlatformValidateNvVarStore (
(NvVarStoreFvHeader->FvLength != NvVarStoreSize)
)
{
DEBUG ((DEBUG_ERROR, "NvVarStore FV headers were invalid.\n"));
return FALSE;
if (!Retry) {
DEBUG ((DEBUG_ERROR, "NvVarStore FV headers were invalid.\n"));
return FALSE;
}

DEBUG ((DEBUG_INFO, "Remapping NvVarStore as shared\n"));
Status = MemEncryptSevClearMmioPageEncMask (
0,
(UINTN)NvVarStoreBase,
EFI_SIZE_TO_PAGES (NvVarStoreSize)
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Failed to map NvVarStore as shared\n"));
return FALSE;
}

Retry = FALSE;
goto RETRY;
}

//
Expand Down
1 change: 1 addition & 0 deletions OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
HobLib
QemuFwCfgLib
QemuFwCfgSimpleParserLib
MemEncryptSevLib
MemoryAllocationLib
MtrrLib
PcdLib
Expand Down
14 changes: 10 additions & 4 deletions OvmfPkg/PlatformPei/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,6 @@ InitializePlatform (
InitializeRamRegions (PlatformInfoHob);

if (PlatformInfoHob->BootMode != BOOT_ON_S3_RESUME) {
if (!PlatformInfoHob->SmmSmramRequire) {
ReserveEmuVariableNvStore ();
}

PeiFvInitialization (PlatformInfoHob);
MemTypeInfoInitialization (PlatformInfoHob);
MemMapInitialization (PlatformInfoHob);
Expand All @@ -378,5 +374,15 @@ InitializePlatform (
RelocateSmBase ();
}

//
// Performed after CoCo (SEV/TDX) initialization to allow the memory
// used to be validated before being used.
//
if (PlatformInfoHob->BootMode != BOOT_ON_S3_RESUME) {
if (!PlatformInfoHob->SmmSmramRequire) {
ReserveEmuVariableNvStore ();
}
}

return EFI_SUCCESS;
}
8 changes: 8 additions & 0 deletions OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,14 @@ QemuFlashInitialize (
VOID
)
{
//
// The SNP model does not provide for QEMU flash device support, so exit
// early before attempting to initialize any QEMU flash device support.
//
if (MemEncryptSevSnpIsEnabled ()) {
return EFI_UNSUPPORTED;
}

mFlashBase = (UINT8 *)(UINTN)PcdGet32 (PcdOvmfFdBaseAddress);
mFdBlockSize = PcdGet32 (PcdOvmfFirmwareBlockSize);
ASSERT (PcdGet32 (PcdOvmfFirmwareFdSize) % mFdBlockSize == 0);
Expand Down
2 changes: 1 addition & 1 deletion ShellPkg/Application/Shell/ShellParametersProtocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,7 @@ UpdateArgcArgv (
*OldArgc = ShellParameters->Argc;
}

if (OldArgc != NULL) {
if (OldArgv != NULL) {
*OldArgv = ShellParameters->Argv;
}

Expand Down

0 comments on commit 44e76d1

Please sign in to comment.