TianoCore EDK2 master
|
#include <Base.h>
#include <Uefi.h>
#include <Library/BaseMemoryLib.h>
#include <Library/LocalApicLib.h>
#include <Library/MemEncryptSevLib.h>
#include <Library/VmgExitLib.h>
#include <Register/Amd/Msr.h>
#include <Register/Intel/Cpuid.h>
#include <IndustryStandard/InstructionParsing.h>
#include "VmgExitVcHandler.h"
Go to the source code of this file.
Data Structures | |
struct | SEV_ES_INSTRUCTION_MODRM_EXT |
struct | SEV_ES_INSTRUCTION_SIB_EXT |
struct | SEV_ES_INSTRUCTION_OPCODE_EXT |
struct | SEV_ES_INSTRUCTION_DATA |
Typedefs | |
typedef UINT64(* | NAE_EXIT) (GHCB *Ghcb, EFI_SYSTEM_CONTEXT_X64 *Regs, SEV_ES_INSTRUCTION_DATA *InstructionData) |
struct { | |
UINT32 EaxIn | |
UINT32 EcxIn | |
UINT64 Unused | |
UINT64 Unused2 | |
UINT32 Eax | |
UINT32 Ebx | |
UINT32 Ecx | |
UINT32 Edx | |
UINT64 Reserved | |
} | SEV_SNP_CPUID_FUNCTION |
struct { | |
UINT32 Count | |
UINT32 Reserved1 | |
UINT64 Reserved2 | |
SEV_SNP_CPUID_FUNCTION function [0] | |
} | SEV_SNP_CPUID_INFO |
X64 #VC Exception Handler functon.
Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
Definition in file VmgExitVcHandler.c.
typedef UINT64(* NAE_EXIT) (GHCB *Ghcb, EFI_SYSTEM_CONTEXT_X64 *Regs, SEV_ES_INSTRUCTION_DATA *InstructionData) |
Definition at line 127 of file VmgExitVcHandler.c.
enum SEV_ES_INSTRUCTION_MODE |
Definition at line 25 of file VmgExitVcHandler.c.
enum SEV_ES_INSTRUCTION_REP |
Definition at line 56 of file VmgExitVcHandler.c.
enum SEV_ES_INSTRUCTION_SEGMENT |
Definition at line 44 of file VmgExitVcHandler.c.
enum SEV_ES_INSTRUCTION_SIZE |
Definition at line 34 of file VmgExitVcHandler.c.
STATIC UINT64 CpuidExit | ( | IN OUT GHCB * | Ghcb, |
IN OUT EFI_SYSTEM_CONTEXT_X64 * | Regs, | ||
IN SEV_ES_INSTRUCTION_DATA * | InstructionData | ||
) |
Handle a CPUID event.
Use VMGEXIT instruction or CPUID table to handle a CPUID event.
[in,out] | Ghcb | Pointer to the Guest-Hypervisor Communication Block |
[in,out] | Regs | x64 processor context |
[in] | InstructionData | Instruction parsing context |
0 | Event handled successfully |
Definition at line 1952 of file VmgExitVcHandler.c.
STATIC VOID DecodeModRm | ( | IN EFI_SYSTEM_CONTEXT_X64 * | Regs, |
IN OUT SEV_ES_INSTRUCTION_DATA * | InstructionData | ||
) |
Decode a ModRM byte.
Examine the instruction parsing context to decode a ModRM byte and the SIB byte, if present.
[in] | Regs | x64 processor context |
[in,out] | InstructionData | Instruction parsing context |
Definition at line 388 of file VmgExitVcHandler.c.
STATIC VOID DecodePrefixes | ( | IN EFI_SYSTEM_CONTEXT_X64 * | Regs, |
IN OUT SEV_ES_INSTRUCTION_DATA * | InstructionData | ||
) |
Decode instruction prefixes.
Parse the instruction data to track the instruction prefixes that have been used.
[in] | Regs | x64 processor context |
[in,out] | InstructionData | Instruction parsing context |
Definition at line 448 of file VmgExitVcHandler.c.
STATIC UINT64 Dr7ReadExit | ( | IN OUT GHCB * | Ghcb, |
IN OUT EFI_SYSTEM_CONTEXT_X64 * | Regs, | ||
IN SEV_ES_INSTRUCTION_DATA * | InstructionData | ||
) |
Handle a DR7 register read event.
Use the VMGEXIT instruction to handle a DR7 read event.
[in,out] | Ghcb | Pointer to the Guest-Hypervisor Communication Block |
[in,out] | Regs | x64 processor context |
[in] | InstructionData | Instruction parsing context |
0 | Event handled successfully |
Definition at line 2182 of file VmgExitVcHandler.c.
STATIC UINT64 Dr7WriteExit | ( | IN OUT GHCB * | Ghcb, |
IN OUT EFI_SYSTEM_CONTEXT_X64 * | Regs, | ||
IN SEV_ES_INSTRUCTION_DATA * | InstructionData | ||
) |
Handle a DR7 register write event.
Use the VMGEXIT instruction to handle a DR7 write event.
[in,out] | Ghcb | Pointer to the Guest-Hypervisor Communication Block |
[in,out] | Regs | x64 processor context |
[in] | InstructionData | Instruction parsing context |
0 | Event handled successfully |
Definition at line 2129 of file VmgExitVcHandler.c.
STATIC BOOLEAN GetCpuidFw | ( | IN OUT GHCB * | Ghcb, |
IN UINT32 | EaxIn, | ||
IN UINT32 | EcxIn, | ||
IN UINT64 | XCr0, | ||
IN OUT UINT32 * | Eax, | ||
IN OUT UINT32 * | Ebx, | ||
IN OUT UINT32 * | Ecx, | ||
IN OUT UINT32 * | Edx, | ||
IN OUT UINT64 * | Status, | ||
IN OUT BOOLEAN * | Unsupported | ||
) |
Fetch CPUID leaf/function via SEV-SNP CPUID table.
[in,out] | Ghcb | Pointer to the Guest-Hypervisor Communication Block |
[in] | EaxIn | EAX input for cpuid instruction |
[in] | EcxIn | ECX input for cpuid instruction |
[in] | Xcr0In | XCR0 at time of cpuid instruction |
[in,out] | Eax | Pointer to store leaf's EAX value |
[in,out] | Ebx | Pointer to store leaf's EBX value |
[in,out] | Ecx | Pointer to store leaf's ECX value |
[in,out] | Edx | Pointer to store leaf's EDX value |
[in,out] | Status | Pointer to store status from VMGEXIT (always 0 unless return value indicates failure) |
[in,out] | Unsupported | Pointer to store indication of unsupported VMGEXIT (always false unless return value indicates failure) |
TRUE | CPUID leaf fetch successfully. |
FALSE | Error occurred while fetching CPUID leaf. Callers should Status and Unsupported and handle accordingly if they indicate a more precise error condition. |
Definition at line 1773 of file VmgExitVcHandler.c.
STATIC BOOLEAN GetCpuidHyp | ( | IN OUT GHCB * | Ghcb, |
IN UINT32 | EaxIn, | ||
IN UINT32 | EcxIn, | ||
IN UINT64 | XCr0, | ||
IN OUT UINT32 * | Eax, | ||
IN OUT UINT32 * | Ebx, | ||
IN OUT UINT32 * | Ecx, | ||
IN OUT UINT32 * | Edx, | ||
IN OUT UINT64 * | Status, | ||
IN OUT BOOLEAN * | UnsupportedExit | ||
) |
Fetch CPUID leaf/function via hypervisor/VMGEXIT.
[in,out] | Ghcb | Pointer to the Guest-Hypervisor Communication Block |
[in] | EaxIn | EAX input for cpuid instruction |
[in] | EcxIn | ECX input for cpuid instruction |
[in] | Xcr0In | XCR0 at time of cpuid instruction |
[in,out] | Eax | Pointer to store leaf's EAX value |
[in,out] | Ebx | Pointer to store leaf's EBX value |
[in,out] | Ecx | Pointer to store leaf's ECX value |
[in,out] | Edx | Pointer to store leaf's EDX value |
[in,out] | Status | Pointer to store status from VMGEXIT (always 0 unless return value indicates failure) |
[in,out] | Unsupported | Pointer to store indication of unsupported VMGEXIT (always false unless return value indicates failure) |
TRUE | CPUID leaf fetch successfully. |
FALSE | Error occurred while fetching CPUID leaf. Callers should Status and Unsupported and handle accordingly if they indicate a more precise error condition. |
Definition at line 1570 of file VmgExitVcHandler.c.
STATIC BOOLEAN GetCpuidXSaveSize | ( | IN UINT64 | XFeaturesEnabled, |
IN UINT32 | XSaveBaseSize, | ||
IN OUT UINT32 * | XSaveSize, | ||
IN BOOLEAN | Compacted | ||
) |
Calculate the total XSAVE area size for enabled XSAVE areas
[in] | XFeaturesEnabled | Bit-mask of enabled XSAVE features/areas as indicated by XCR0/MSR_IA32_XSS bits |
[in] | XSaveBaseSize | Base/legacy XSAVE area size (e.g. when XCR0 is 1) |
[in,out] | XSaveSize | Pointer to storage for calculated XSAVE area size |
[in] | Compacted | Whether or not the calculation is for the normal XSAVE area size (leaf 0xD,0x0,EBX) or compacted XSAVE area size (leaf 0xD,0x1,EBX) |
TRUE | XSAVE size calculation was successful. |
FALSE | XSAVE size calculation was unsuccessful. |
Definition at line 1665 of file VmgExitVcHandler.c.
STATIC UINT64 GetEffectiveMemoryAddress | ( | IN EFI_SYSTEM_CONTEXT_X64 * | Regs, |
IN SEV_ES_INSTRUCTION_DATA * | InstructionData | ||
) |
Return the effective address of a memory operand.
Examine the instruction parsing context to obtain the effective memory address of a memory operand.
[in] | Regs | x64 processor context |
[in] | InstructionData | Instruction parsing context |
Definition at line 299 of file VmgExitVcHandler.c.
Return a pointer to the contents of the specified register.
Based upon the input register, return a pointer to the registers contents in the x86 processor context.
[in] | Regs | x64 processor context |
[in] | Register | Register to obtain pointer for |
Definition at line 173 of file VmgExitVcHandler.c.
STATIC VOID InitInstructionData | ( | IN OUT SEV_ES_INSTRUCTION_DATA * | InstructionData, |
IN GHCB * | Ghcb, | ||
IN EFI_SYSTEM_CONTEXT_X64 * | Regs | ||
) |
Initialize the instruction parsing context.
Initialize the instruction parsing context, which includes decoding the instruction prefixes.
[in,out] | InstructionData | Instruction parsing context |
[in] | Ghcb | Pointer to the Guest-Hypervisor Communication Block |
[in] | Regs | x64 processor context |
Definition at line 578 of file VmgExitVcHandler.c.
STATIC UINT64 InstructionLength | ( | IN SEV_ES_INSTRUCTION_DATA * | InstructionData | ) |
Determine instruction length
Return the total length of the parsed instruction.
[in] | InstructionData | Instruction parsing context |
Definition at line 557 of file VmgExitVcHandler.c.
EFI_STATUS EFIAPI InternalVmgExitHandleVc | ( | IN OUT GHCB * | Ghcb, |
IN OUT EFI_EXCEPTION_TYPE * | ExceptionType, | ||
IN OUT EFI_SYSTEM_CONTEXT | SystemContext | ||
) |
Handle a #VC exception.
Performs the necessary processing to handle a #VC exception.
[in,out] | Ghcb | Pointer to the GHCB |
[in,out] | ExceptionType | Pointer to an EFI_EXCEPTION_TYPE to be set as value to use on error. |
[in,out] | SystemContext | Pointer to EFI_SYSTEM_CONTEXT |
EFI_SUCCESS | Exception handled |
EFI_UNSUPPORTED | #VC not supported, (new) exception value to propagate provided |
EFI_PROTOCOL_ERROR | #VC handling failed, (new) exception value to propagate provided |
Definition at line 2230 of file VmgExitVcHandler.c.
STATIC UINT64 InvdExit | ( | IN OUT GHCB * | Ghcb, |
IN OUT EFI_SYSTEM_CONTEXT_X64 * | Regs, | ||
IN SEV_ES_INSTRUCTION_DATA * | InstructionData | ||
) |
Handle a INVD event.
Use the VMGEXIT instruction to handle a INVD event.
[in,out] | Ghcb | Pointer to the Guest-Hypervisor Communication Block |
[in,out] | Regs | x64 processor context |
[in] | InstructionData | Instruction parsing context |
0 | Event handled successfully |
Definition at line 1534 of file VmgExitVcHandler.c.
STATIC UINT64 IoioExit | ( | IN OUT GHCB * | Ghcb, |
IN OUT EFI_SYSTEM_CONTEXT_X64 * | Regs, | ||
IN SEV_ES_INSTRUCTION_DATA * | InstructionData | ||
) |
Handle an IOIO event.
Use the VMGEXIT instruction to handle an IOIO event.
[in,out] | Ghcb | Pointer to the Guest-Hypervisor Communication Block |
[in,out] | Regs | x64 processor context |
[in] | InstructionData | Instruction parsing context |
0 | Event handled successfully |
Definition at line 1440 of file VmgExitVcHandler.c.
STATIC UINT64 IoioExitInfo | ( | IN EFI_SYSTEM_CONTEXT_X64 * | Regs, |
IN OUT SEV_ES_INSTRUCTION_DATA * | InstructionData | ||
) |
Build the IOIO event information.
The IOIO event information identifies the type of IO operation to be performed by the hypervisor. Build this information based on the instruction data.
[in] | Regs | x64 processor context |
[in,out] | InstructionData | Instruction parsing context |
Definition at line 1305 of file VmgExitVcHandler.c.
Check if a CPUID leaf/function is indexed via ECX sub-leaf/sub-function
[in] | EaxIn | EAX input for cpuid instruction |
FALSE | cpuid leaf/function is not indexed by ECX input |
TRUE | cpuid leaf/function is indexed by ECX input |
Definition at line 1724 of file VmgExitVcHandler.c.
STATIC BOOLEAN IsRipRelative | ( | IN SEV_ES_INSTRUCTION_DATA * | InstructionData | ) |
Determine if an instruction address if RIP relative.
Examine the instruction parsing context to determine if the address offset is relative to the instruction pointer.
[in] | InstructionData | Instruction parsing context |
TRUE | Instruction addressing is RIP relative |
FALSE | Instruction addressing is not RIP relative |
Definition at line 271 of file VmgExitVcHandler.c.
STATIC UINT64 MmioExit | ( | IN OUT GHCB * | Ghcb, |
IN OUT EFI_SYSTEM_CONTEXT_X64 * | Regs, | ||
IN OUT SEV_ES_INSTRUCTION_DATA * | InstructionData | ||
) |
Handle an MMIO event.
Use the VMGEXIT instruction to handle either an MMIO read or an MMIO write.
[in,out] | Ghcb | Pointer to the Guest-Hypervisor Communication Block |
[in,out] | Regs | x64 processor context |
[in,out] | InstructionData | Instruction parsing context |
0 | Event handled successfully |
Definition at line 706 of file VmgExitVcHandler.c.
STATIC UINT64 MonitorExit | ( | IN OUT GHCB * | Ghcb, |
IN OUT EFI_SYSTEM_CONTEXT_X64 * | Regs, | ||
IN SEV_ES_INSTRUCTION_DATA * | InstructionData | ||
) |
Handle a MONITOR event.
Use the VMGEXIT instruction to handle a MONITOR event.
[in,out] | Ghcb | Pointer to the Guest-Hypervisor Communication Block |
[in,out] | Regs | x64 processor context |
[in] | InstructionData | Instruction parsing context |
0 | Event handled successfully |
Definition at line 1095 of file VmgExitVcHandler.c.
STATIC UINT64 MsrExit | ( | IN OUT GHCB * | Ghcb, |
IN OUT EFI_SYSTEM_CONTEXT_X64 * | Regs, | ||
IN SEV_ES_INSTRUCTION_DATA * | InstructionData | ||
) |
Handle an MSR event.
Use the VMGEXIT instruction to handle either a RDMSR or WRMSR event.
[in,out] | Ghcb | Pointer to the Guest-Hypervisor Communication Block |
[in,out] | Regs | x64 processor context |
[in] | InstructionData | Instruction parsing context |
0 | Event handled successfully |
Definition at line 1244 of file VmgExitVcHandler.c.
STATIC UINT64 MwaitExit | ( | IN OUT GHCB * | Ghcb, |
IN OUT EFI_SYSTEM_CONTEXT_X64 * | Regs, | ||
IN SEV_ES_INSTRUCTION_DATA * | InstructionData | ||
) |
Handle a MWAIT event.
Use the VMGEXIT instruction to handle a MWAIT event.
[in,out] | Ghcb | Pointer to the Guest-Hypervisor Communication Block |
[in,out] | Regs | x64 processor context |
[in] | InstructionData | Instruction parsing context |
0 | Event handled successfully |
Definition at line 1063 of file VmgExitVcHandler.c.
STATIC UINT64 RdpmcExit | ( | IN OUT GHCB * | Ghcb, |
IN OUT EFI_SYSTEM_CONTEXT_X64 * | Regs, | ||
IN SEV_ES_INSTRUCTION_DATA * | InstructionData | ||
) |
Handle a RDPMC event.
Use the VMGEXIT instruction to handle a RDPMC event.
[in,out] | Ghcb | Pointer to the Guest-Hypervisor Communication Block |
[in,out] | Regs | x64 processor context |
[in] | InstructionData | Instruction parsing context |
0 | Event handled successfully |
Definition at line 2044 of file VmgExitVcHandler.c.
STATIC UINT64 RdtscExit | ( | IN OUT GHCB * | Ghcb, |
IN OUT EFI_SYSTEM_CONTEXT_X64 * | Regs, | ||
IN SEV_ES_INSTRUCTION_DATA * | InstructionData | ||
) |
Handle a RDTSC event.
Use the VMGEXIT instruction to handle a RDTSC event.
[in,out] | Ghcb | Pointer to the Guest-Hypervisor Communication Block |
[in,out] | Regs | x64 processor context |
[in] | InstructionData | Instruction parsing context |
0 | Event handled successfully |
Definition at line 2088 of file VmgExitVcHandler.c.
STATIC UINT64 RdtscpExit | ( | IN OUT GHCB * | Ghcb, |
IN OUT EFI_SYSTEM_CONTEXT_X64 * | Regs, | ||
IN SEV_ES_INSTRUCTION_DATA * | InstructionData | ||
) |
Handle a RDTSCP event.
Use the VMGEXIT instruction to handle a RDTSCP event.
[in,out] | Ghcb | Pointer to the Guest-Hypervisor Communication Block |
[in,out] | Regs | x64 processor context |
[in] | InstructionData | Instruction parsing context |
0 | Event handled successfully |
Definition at line 1154 of file VmgExitVcHandler.c.
Check if SEV-SNP enabled.
TRUE | SEV-SNP is enabled. |
FALSE | SEV-SNP is disabled. |
Definition at line 1635 of file VmgExitVcHandler.c.
STATIC UINT64 UnsupportedExit | ( | IN GHCB * | Ghcb, |
IN EFI_SYSTEM_CONTEXT_X64 * | Regs, | ||
IN SEV_ES_INSTRUCTION_DATA * | InstructionData | ||
) |
Report an unsupported event to the hypervisor
Use the VMGEXIT support to report an unsupported event to the hypervisor.
[in] | Ghcb | Pointer to the Guest-Hypervisor Communication Block |
[in] | Regs | x64 processor context |
[in] | InstructionData | Instruction parsing context |
Definition at line 607 of file VmgExitVcHandler.c.
STATIC VOID UpdateForDisplacement | ( | IN OUT SEV_ES_INSTRUCTION_DATA * | InstructionData, |
IN UINTN | Size | ||
) |
Update the instruction parsing context for displacement bytes.
[in,out] | InstructionData | Instruction parsing context |
[in] | Size | The instruction displacement size |
Definition at line 247 of file VmgExitVcHandler.c.
Validate that the MMIO memory access is not to encrypted memory.
Examine the pagetable entry for the memory specified. MMIO should not be performed against encrypted memory. MMIO to the APIC page is always allowed.
[in] | Ghcb | Pointer to the Guest-Hypervisor Communication Block |
[in] | MemoryAddress | Memory address to validate |
[in] | MemoryLength | Memory length to validate |
0 | Memory is not encrypted |
Definition at line 646 of file VmgExitVcHandler.c.
VOID EFIAPI VmgExitIssueAssert | ( | IN OUT SEV_ES_PER_CPU_DATA * | SevEsData | ) |
Routine to allow ASSERT from within #VC.
[in,out] | SevEsData | Pointer to the per-CPU data |
Definition at line 2344 of file VmgExitVcHandler.c.
STATIC UINT64 VmmCallExit | ( | IN OUT GHCB * | Ghcb, |
IN OUT EFI_SYSTEM_CONTEXT_X64 * | Regs, | ||
IN SEV_ES_INSTRUCTION_DATA * | InstructionData | ||
) |
Handle a VMMCALL event.
Use the VMGEXIT instruction to handle a VMMCALL event.
[in,out] | Ghcb | Pointer to the Guest-Hypervisor Communication Block |
[in,out] | Regs | x64 processor context |
[in] | InstructionData | Instruction parsing context |
0 | Event handled successfully |
Definition at line 1199 of file VmgExitVcHandler.c.
STATIC UINT64 WbinvdExit | ( | IN OUT GHCB * | Ghcb, |
IN OUT EFI_SYSTEM_CONTEXT_X64 * | Regs, | ||
IN SEV_ES_INSTRUCTION_DATA * | InstructionData | ||
) |
Handle a WBINVD event.
Use the VMGEXIT instruction to handle a WBINVD event.
[in,out] | Ghcb | Pointer to the Guest-Hypervisor Communication Block |
[in,out] | Regs | x64 processor context |
[in] | InstructionData | Instruction parsing context |
0 | Event handled successfully |
Definition at line 1129 of file VmgExitVcHandler.c.
UINT32 Count |
Definition at line 153 of file VmgExitVcHandler.c.
UINT32 Eax |
Definition at line 142 of file VmgExitVcHandler.c.
UINT32 EaxIn |
Definition at line 138 of file VmgExitVcHandler.c.
UINT32 Ebx |
Definition at line 143 of file VmgExitVcHandler.c.
UINT32 Ecx |
Definition at line 144 of file VmgExitVcHandler.c.
UINT32 EcxIn |
Definition at line 139 of file VmgExitVcHandler.c.
UINT32 Edx |
Definition at line 145 of file VmgExitVcHandler.c.
SEV_SNP_CPUID_FUNCTION function[0] |
Definition at line 156 of file VmgExitVcHandler.c.
UINT64 Reserved |
Definition at line 146 of file VmgExitVcHandler.c.
UINT32 Reserved1 |
Definition at line 154 of file VmgExitVcHandler.c.
UINT64 Reserved2 |
Definition at line 155 of file VmgExitVcHandler.c.
UINT64 Unused |
Definition at line 140 of file VmgExitVcHandler.c.
UINT64 Unused2 |
Definition at line 141 of file VmgExitVcHandler.c.