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 19 commits into
base: svsm
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
b732fcb
disable brotli
joergroedel Jun 14, 2022
d4a2ac8
OvmfPkg/BaseMemEncryptSevLib: Re-organize page state change support
tlendacky Jan 9, 2024
f8f548e
MdePkg/Register/Amd: Define the SVSM related information
tlendacky Jan 9, 2024
1d2ae5e
MdePkg/BaseLib: Add a new VMGEXIT instruction invocation for SVSM
tlendacky Jan 25, 2024
b144a31
UefiCpuPkg/CcExitLib: Extend the CcExitLib library to support an SVSM
tlendacky Jan 9, 2024
2aaca82
Ovmfpkg/CcExitLib: Extend CcExitLib to handle SVSM related services
tlendacky Jan 9, 2024
918bf44
OvmfPkg: Create a calling area used to communicate with the SVSM
tlendacky Jan 9, 2024
afdb015
OvmfPkg/CcExitLib: Add support for the SVSM_CORE_PVALIDATE call
tlendacky Jan 25, 2024
a3730e9
OvmfPkg/CcExitLib: Add support for the SVSM create/delete vCPU calls
tlendacky Jan 15, 2024
c4c3c43
UefiCpuPkg/MpInitLib: Use CcExitSnpVmsaRmpAdjust() to set/clear VMSA
tlendacky Jan 15, 2024
2e684fb
MdePkg: GHCB APIC ID retrieval support definitions
tlendacky Jan 9, 2024
521457d
UefiCpuPkg: Create APIC ID list PCD
tlendacky Jan 9, 2024
143a55b
OvmfPkg/PlatformPei: Retrieve APIC IDs from the hypervisor
tlendacky Jan 9, 2024
b85fb7a
UefiCpuPkg/MpInitLib: Always use AP Create if PcdSevSnpApicIds is set
tlendacky Jan 9, 2024
9fe09ce
UefiCpuPkg/MpInitLib: AP creation support under an SVSM
tlendacky Jan 15, 2024
9141843
Ovmfpkg/CcExitLib: Provide SVSM discovery support
tlendacky Jan 9, 2024
db38985
OvmfPkg/BaseMemEncryptLib: Check for presence of an SVSM when not at …
tlendacky Jan 9, 2024
d965a1b
Add SVSM based vTPM
Aug 24, 2023
7a4cf97
OvmfPkg/AmdSevDxe: Shim Reboot workaround
osteffenrh Aug 26, 2024
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
1 change: 0 additions & 1 deletion BaseTools/Source/C/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ all: makerootdir subdirs
LIBRARIES = Common
VFRAUTOGEN = VfrCompile/VfrLexer.h
APPLICATIONS = \
BrotliCompress \
VfrCompile \
EfiRom \
GenFfs \
Expand Down
3 changes: 0 additions & 3 deletions MdeModulePkg/MdeModulePkg.dec
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
Include
Test/Mock/Include

[Includes.Common.Private]
Library/BrotliCustomDecompressLib/brotli/c/include

[LibraryClasses]
## @libraryclass Defines a set of methods to reset whole system.
ResetSystemLib|Include/Library/ResetSystemLib.h
Expand Down
1 change: 0 additions & 1 deletion MdeModulePkg/MdeModulePkg.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,6 @@
MdeModulePkg/Universal/EbcDxe/EbcDebuggerConfig.inf

[Components.IA32, Components.X64, Components.ARM, Components.AARCH64]
MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliCustomDecompressLib.inf
MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf
MdeModulePkg/Library/VarCheckUefiLib/VarCheckUefiLib.inf
MdeModulePkg/Core/Dxe/DxeMain.inf {
Expand Down
39 changes: 39 additions & 0 deletions MdePkg/Include/Library/BaseLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -7592,6 +7592,45 @@ AsmVmgExit (
VOID
);

///
/// The structure used to supply and return data to and from the SVSM.
///
typedef struct {
VOID *Caa;
UINT64 RaxIn;
UINT64 RcxIn;
UINT64 RdxIn;
UINT64 R8In;
UINT64 R9In;
UINT64 RaxOut;
UINT64 RcxOut;
UINT64 RdxOut;
UINT64 R8Out;
UINT64 R9Out;
UINT8 *CallPending;
} SVSM_CALL_DATA;

/**
Executes a VMGEXIT instruction (VMMCALL with a REP prefix) with arguments
and return code

Executes a VMGEXIT instruction placing the specified arguments in the
corresponding registers before invocation. Upon return an XCHG is done to
atomically clear and retrieve the SVSM call pending value. The returned RAX
register value becomes the function return code. This function is intended
for use with an SVSM. This function is only available on IA-32 and x64.

@param[in,out] SvsmCallPending Pointer to the location of the SVSM call data

@return Value of the RAX register on return

**/
UINT32
EFIAPI
AsmVmgExitSvsm (
IN OUT SVSM_CALL_DATA *SvsmCallData
);

/**
Patch the immediate operand of an IA32 or X64 instruction such that the byte,
word, dword or qword operand is encoded at the end of the instruction's
Expand Down
19 changes: 18 additions & 1 deletion MdePkg/Include/Register/Amd/Fam17Msr.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
returned is a single 32-bit or 64-bit value, then a data structure is not
provided for that MSR.

Copyright (c) 2017, Advanced Micro Devices. All rights reserved.<BR>
Copyright (c) 2017 - 2024, Advanced Micro Devices. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent

@par Specification Reference:
Expand Down Expand Up @@ -71,9 +71,24 @@ typedef union {
UINT32 ErrorCode;
} SnpPageStateChangeResponse;

struct {
UINT64 Function : 12;
UINT64 Reserved1 : 20;
UINT64 Vmpl : 8;
UINT64 Reserved2 : 56;
} SnpVmplRequest;

struct {
UINT32 Function : 12;
UINT32 Reserved : 20;
UINT32 ErrorCode;
} SnpVmplResponse;

VOID *Ghcb;

UINT64 GhcbPhysicalAddress;

UINT64 Uint64;
} MSR_SEV_ES_GHCB_REGISTER;

#define GHCB_INFO_SEV_INFO 1
Expand All @@ -84,6 +99,8 @@ typedef union {
#define GHCB_INFO_GHCB_GPA_REGISTER_RESPONSE 19
#define GHCB_INFO_SNP_PAGE_STATE_CHANGE_REQUEST 20
#define GHCB_INFO_SNP_PAGE_STATE_CHANGE_RESPONSE 21
#define GHCB_INFO_SNP_VMPL_REQUEST 22
#define GHCB_INFO_SNP_VMPL_RESPONSE 23
#define GHCB_HYPERVISOR_FEATURES_REQUEST 128
#define GHCB_HYPERVISOR_FEATURES_RESPONSE 129
#define GHCB_INFO_TERMINATE_REQUEST 256
Expand Down
19 changes: 15 additions & 4 deletions MdePkg/Include/Register/Amd/Ghcb.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Provides data types allowing an SEV-ES guest to interact with the hypervisor
using the GHCB protocol.

Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.<BR>
Copyright (C) 2020 - 2024, Advanced Micro Devices, Inc. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent

@par Specification Reference:
Expand Down Expand Up @@ -56,6 +56,7 @@
#define SVM_EXIT_AP_JUMP_TABLE 0x80000005ULL
#define SVM_EXIT_SNP_PAGE_STATE_CHANGE 0x80000010ULL
#define SVM_EXIT_SNP_AP_CREATION 0x80000013ULL
#define SVM_EXIT_GET_APIC_IDS 0x80000017ULL
#define SVM_EXIT_HYPERVISOR_FEATURES 0x8000FFFDULL
#define SVM_EXIT_UNSUPPORTED 0x8000FFFFULL

Expand Down Expand Up @@ -170,6 +171,7 @@ typedef union {
#define GHCB_HV_FEATURES_SNP_AP_CREATE (GHCB_HV_FEATURES_SNP | BIT1)
#define GHCB_HV_FEATURES_SNP_RESTRICTED_INJECTION (GHCB_HV_FEATURES_SNP_AP_CREATE | BIT2)
#define GHCB_HV_FEATURES_SNP_RESTRICTED_INJECTION_TIMER (GHCB_HV_FEATURES_SNP_RESTRICTED_INJECTION | BIT3)
#define GHCB_HV_FEATURES_APIC_ID_LIST BIT4

//
// SNP Page State Change.
Expand All @@ -195,13 +197,22 @@ typedef struct {
UINT32 Reserved;
} SNP_PAGE_STATE_HEADER;

#define SNP_PAGE_STATE_MAX_ENTRY 253

typedef struct {
SNP_PAGE_STATE_HEADER Header;
SNP_PAGE_STATE_ENTRY Entry[SNP_PAGE_STATE_MAX_ENTRY];
SNP_PAGE_STATE_ENTRY Entry[];
} SNP_PAGE_STATE_CHANGE_INFO;

#define SNP_PAGE_STATE_MAX_ENTRY \
((sizeof (((GHCB *)0)->SharedBuffer) - sizeof (SNP_PAGE_STATE_HEADER)) / sizeof (SNP_PAGE_STATE_ENTRY))

//
// Get APIC IDs
//
typedef struct {
UINT32 NumEntries;
UINT32 ApicIds[];
} GHCB_APIC_IDS;

//
// SEV-ES save area mapping structures used for SEV-SNP AP Creation.
// Only the fields required to be set to a non-zero value are defined.
Expand Down
3 changes: 2 additions & 1 deletion MdePkg/Include/Register/Amd/Msr.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
returned is a single 32-bit or 64-bit value, then a data structure is not
provided for that MSR.

Copyright (c) 2017 - 2019, Advanced Micro Devices. All rights reserved.<BR>
Copyright (c) 2017 - 2024, Advanced Micro Devices. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent

@par Specification Reference:
Expand All @@ -19,5 +19,6 @@

#include <Register/Intel/ArchitecturalMsr.h>
#include <Register/Amd/Fam17Msr.h>
#include <Register/Amd/SvsmMsr.h>

#endif
101 changes: 101 additions & 0 deletions MdePkg/Include/Register/Amd/Svsm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/** @file
Secure VM Service Module (SVSM) Definition.

Provides data types allowing an SEV-SNP guest to interact with the SVSM.

Copyright (C) 2024, Advanced Micro Devices, Inc. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent

@par Specification Reference:
Secure VM Service Module Specification

**/

#ifndef SVSM_H_
#define SVSM_H_

#include <Base.h>
#include <Uefi.h>
#include <Library/BaseLib.h>

//
// The SVSM definitions are part of the SNP Secrets Page:
// An SVSM is considered present if the SvsmSize field is non-zero.
//
typedef PACKED struct {
UINT8 Reserved1[320];

UINT64 SvsmBase;
UINT64 SvsmSize;
UINT64 SvsmCaa;
UINT32 SvsmMaxVersion;
UINT8 SvsmGuestVmpl;
UINT8 Reserved2[3];
} SVSM_INFORMATION;

typedef PACKED struct {
UINT8 SvsmCallPending;
UINT8 SvsmMemAvailable;
UINT8 Reserved1[6];

//
// The remainder of the CAA 4KB area can be used for argument
// passing to the SVSM.
//
UINT8 SvsmBuffer[SIZE_4KB - 8];
} SVSM_CAA;

#define SVSM_SUCCESS 0x00000000
#define SVSM_ERR_INCOMPLETE 0x80000000
#define SVSM_ERR_UNSUPPORTED_PROTOCOL 0x80000001
#define SVSM_ERR_UNSUPPORTED_CALL 0x80000002
#define SVSM_ERR_INVALID_ADDRESS 0x80000003
#define SVSM_ERR_INVALID_FORMAT 0x80000004
#define SVSM_ERR_INVALID_PARAMETER 0x80000005
#define SVSM_ERR_INVALID_REQUEST 0x80000006
#define SVSM_ERR_BUSY 0x80000007

#define SVSM_ERR_PVALIDATE_FAIL_INPUT 0x80001001
#define SVSM_ERR_PVALIDATE_FAIL_SIZE_MISMATCH 0x80001006
#define SVSM_ERR_PVALIDATE_FAIL_NO_CHANGE 0x80001010

typedef PACKED struct {
UINT16 Entries;
UINT16 Next;

UINT8 Reserved[4];
} SVSM_PVALIDATE_HEADER;

typedef union {
struct {
UINT64 PageSize : 2;
UINT64 Action : 1;
UINT64 IgnoreCf : 1;
UINT64 Reserved_2 : 8;
UINT64 Address : 52;
} Bits;
UINT64 Uint64;
} SVSM_PVALIDATE_ENTRY;

typedef PACKED struct {
SVSM_PVALIDATE_HEADER Header;
SVSM_PVALIDATE_ENTRY Entry[];
} SVSM_PVALIDATE_REQUEST;

#define SVSM_PVALIDATE_MAX_ENTRY \
((sizeof (((SVSM_CAA *)0)->SvsmBuffer) - sizeof (SVSM_PVALIDATE_HEADER)) / sizeof (SVSM_PVALIDATE_ENTRY))

typedef union {
SVSM_PVALIDATE_REQUEST PvalidateRequest;
} SVSM_REQUEST;

typedef union {
struct {
UINT32 CallId;
UINT32 Protocol;
} Id;

UINT64 Uint64;
} SVSM_FUNCTION;

#endif
35 changes: 35 additions & 0 deletions MdePkg/Include/Register/Amd/SvsmMsr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/** @file
MSR Definitions.

Provides defines for Machine Specific Registers(MSR) indexes. Data structures
are provided for MSRs that contain one or more bit fields. If the MSR value
returned is a single 32-bit or 64-bit value, then a data structure is not
provided for that MSR.

Copyright (c) 2024, Advanced Micro Devices. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent

**/

#ifndef SVSM_MSR_H_
#define SVSM_MSR_H_

/**
Secure VM Service Module CAA register

**/
#define MSR_SVSM_CAA 0xc001f000

/**
MSR information returned for #MSR_SVSM_CAA
**/
typedef union {
struct {
UINT32 Lower32Bits;
UINT32 Upper32Bits;
} Bits;

UINT64 Uint64;
} MSR_SVSM_CAA_REGISTER;

#endif
2 changes: 2 additions & 0 deletions MdePkg/Library/BaseLib/BaseLib.inf
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
Ia32/XGetBv.nasm
Ia32/XSetBv.nasm
Ia32/VmgExit.nasm
Ia32/VmgExitSvsm.nasm

Ia32/DivS64x64Remainder.c
Ia32/InternalSwitchStack.c | MSFT
Expand Down Expand Up @@ -328,6 +329,7 @@
X64/XGetBv.nasm
X64/XSetBv.nasm
X64/VmgExit.nasm
X64/VmgExitSvsm.nasm
ChkStkGcc.c | GCC

[Sources.EBC]
Expand Down
39 changes: 39 additions & 0 deletions MdePkg/Library/BaseLib/Ia32/VmgExitSvsm.nasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
;------------------------------------------------------------------------------
;
; Copyright (C) 2024, Advanced Micro Devices, Inc. All rights reserved.<BR>
; SPDX-License-Identifier: BSD-2-Clause-Patent
;
; Module Name:
;
; VmgExitSvsm.Asm
;
; Abstract:
;
; AsmVmgExitSvsm function
;
; Notes:
;
;------------------------------------------------------------------------------

DEFAULT REL
SECTION .text

;------------------------------------------------------------------------------
; UINT32
; EFIAPI
; AsmVmgExitSvsm (
; SVSM_CALL_DATA *SvsmCallData
; );
;------------------------------------------------------------------------------
global ASM_PFX(AsmVmgExitSvsm)
ASM_PFX(AsmVmgExitSvsm):
;
; NASM doesn't support the vmmcall instruction in 32-bit mode and NASM versions
; before 2.12 cannot translate the 64-bit "rep vmmcall" instruction into elf32
; format. Given that VMGEXIT does not make sense on IA32, provide a stub
; implementation that is identical to CpuBreakpoint(). In practice,
; AsmVmgExitSvsm() should never be called on IA32.
;
int 3
ret

Loading