Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shim Reboot workaround #3

Open
wants to merge 1 commit into
base: svsm
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions OvmfPkg/AmdSevDxe/AmdSevDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Guid/ConfidentialComputingSevSnpBlob.h>
#include <Guid/GlobalVariable.h>
#include <Library/PcdLib.h>
#include <Pi/PrePiDxeCis.h>
#include <Protocol/SevMemoryAcceptance.h>
Expand All @@ -28,6 +29,10 @@
// Present, initialized, tested bits defined in MdeModulePkg/Core/Dxe/DxeMain.h
#define EFI_MEMORY_INTERNAL_MASK 0x0700000000000000ULL

static EFI_GUID ShimLockGuid = {
0x605dab50, 0xe046, 0x4300, { 0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23 }
};

STATIC
EFI_STATUS
AllocateConfidentialComputingBlob (
Expand Down Expand Up @@ -191,6 +196,32 @@ STATIC EDKII_MEMORY_ACCEPT_PROTOCOL mMemoryAcceptProtocol = {
AmdSevMemoryAccept
};

VOID
EFIAPI
PopulateVarstore (
EFI_EVENT Event,
VOID *Context
)
{
EFI_SYSTEM_TABLE *SystemTable = (EFI_SYSTEM_TABLE *)Context;
EFI_STATUS Status;

DEBUG ((DEBUG_INFO, "Populating Varstore\n"));
UINT32 data = 1;

Status = SystemTable->RuntimeServices->SetVariable (
L"FB_NO_REBOOT",
&ShimLockGuid,
EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS,
sizeof (data),
&data
);
ASSERT_EFI_ERROR (Status);

Status = SystemTable->BootServices->CloseEvent (Event);
ASSERT_EFI_ERROR (Status);
}

EFI_STATUS
EFIAPI
AmdSevDxeEntryPoint (
Expand All @@ -203,6 +234,7 @@ AmdSevDxeEntryPoint (
UINTN NumEntries;
UINTN Index;
CONFIDENTIAL_COMPUTING_SNP_BLOB_LOCATION *SnpBootDxeTable;
EFI_EVENT PopulateVarstoreEvent;

//
// Do nothing when SEV is not enabled
Expand All @@ -211,6 +243,17 @@ AmdSevDxeEntryPoint (
return EFI_UNSUPPORTED;
}

// Workaround for shim fallback reboot
Status = gBS->CreateEventEx (
EVT_NOTIFY_SIGNAL,
TPL_CALLBACK,
PopulateVarstore,
SystemTable,
&gEfiEndOfDxeEventGroupGuid,
&PopulateVarstoreEvent
);
ASSERT_EFI_ERROR (Status);

//
// Iterate through the GCD map and clear the C-bit from MMIO and NonExistent
// memory space. The NonExistent memory space will be used for mapping the
Expand Down
1 change: 1 addition & 0 deletions OvmfPkg/AmdSevDxe/AmdSevDxe.inf
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
[Guids]
gConfidentialComputingSevSnpBlobGuid
gEfiEventBeforeExitBootServicesGuid
gEfiEndOfDxeEventGroupGuid ## CONSUMES ## Event

[Pcd]
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId