TianoCore EDK2 master
|
#include <Base.h>
#include <Uefi.h>
#include <Library/BaseMemoryLib.h>
#include <Library/LocalApicLib.h>
#include <Library/MemEncryptSevLib.h>
#include <Library/CcExitLib.h>
#include <Library/AmdSvsmLib.h>
#include <Register/Amd/Msr.h>
#include <Register/Intel/Cpuid.h>
#include <IndustryStandard/InstructionParsing.h>
#include "CcExitVcHandler.h"
#include "CcInstruction.h"
Go to the source code of this file.
Typedefs | |
typedef UINT64(* | NAE_EXIT) (GHCB *Ghcb, EFI_SYSTEM_CONTEXT_X64 *Regs, CC_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 - 2024, Advanced Micro Devices, Inc. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
Definition in file CcExitVcHandler.c.
typedef UINT64(* NAE_EXIT) (GHCB *Ghcb, EFI_SYSTEM_CONTEXT_X64 *Regs, CC_INSTRUCTION_DATA *InstructionData) |
Definition at line 27 of file CcExitVcHandler.c.
STATIC UINT64 CpuidExit | ( | IN OUT GHCB * | Ghcb, |
IN OUT EFI_SYSTEM_CONTEXT_X64 * | Regs, | ||
IN CC_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 1424 of file CcExitVcHandler.c.
STATIC UINT64 Dr7ReadExit | ( | IN OUT GHCB * | Ghcb, |
IN OUT EFI_SYSTEM_CONTEXT_X64 * | Regs, | ||
IN CC_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 1656 of file CcExitVcHandler.c.
STATIC UINT64 Dr7WriteExit | ( | IN OUT GHCB * | Ghcb, |
IN OUT EFI_SYSTEM_CONTEXT_X64 * | Regs, | ||
IN CC_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 1601 of file CcExitVcHandler.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 1241 of file CcExitVcHandler.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 1040 of file CcExitVcHandler.c.
STATIC BOOLEAN GetCpuidXSaveSize | ( | IN UINT64 | XFeaturesEnabled, |
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,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 1133 of file CcExitVcHandler.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 1870 of file CcExitVcHandler.c.
STATIC UINT64 InvdExit | ( | IN OUT GHCB * | Ghcb, |
IN OUT EFI_SYSTEM_CONTEXT_X64 * | Regs, | ||
IN CC_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 1004 of file CcExitVcHandler.c.
STATIC UINT64 IoioExit | ( | IN OUT GHCB * | Ghcb, |
IN OUT EFI_SYSTEM_CONTEXT_X64 * | Regs, | ||
IN CC_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 910 of file CcExitVcHandler.c.
STATIC UINT64 IoioExitInfo | ( | IN EFI_SYSTEM_CONTEXT_X64 * | Regs, |
IN OUT CC_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 775 of file CcExitVcHandler.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 1192 of file CcExitVcHandler.c.
STATIC UINT64 MmioExit | ( | IN OUT GHCB * | Ghcb, |
IN OUT EFI_SYSTEM_CONTEXT_X64 * | Regs, | ||
IN OUT CC_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 163 of file CcExitVcHandler.c.
STATIC UINT64 MonitorExit | ( | IN OUT GHCB * | Ghcb, |
IN OUT EFI_SYSTEM_CONTEXT_X64 * | Regs, | ||
IN CC_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 550 of file CcExitVcHandler.c.
STATIC UINT64 MsrExit | ( | IN OUT GHCB * | Ghcb, |
IN OUT EFI_SYSTEM_CONTEXT_X64 * | Regs, | ||
IN CC_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 695 of file CcExitVcHandler.c.
STATIC UINT64 MwaitExit | ( | IN OUT GHCB * | Ghcb, |
IN OUT EFI_SYSTEM_CONTEXT_X64 * | Regs, | ||
IN CC_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 520 of file CcExitVcHandler.c.
STATIC UINT64 RdpmcExit | ( | IN OUT GHCB * | Ghcb, |
IN OUT EFI_SYSTEM_CONTEXT_X64 * | Regs, | ||
IN CC_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 1516 of file CcExitVcHandler.c.
STATIC UINT64 RdtscExit | ( | IN OUT GHCB * | Ghcb, |
IN OUT EFI_SYSTEM_CONTEXT_X64 * | Regs, | ||
IN CC_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 1560 of file CcExitVcHandler.c.
STATIC UINT64 RdtscpExit | ( | IN OUT GHCB * | Ghcb, |
IN OUT EFI_SYSTEM_CONTEXT_X64 * | Regs, | ||
IN CC_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 607 of file CcExitVcHandler.c.
STATIC BOOLEAN SnpEnabled | ( | VOID | ) |
Check if SEV-SNP enabled.
TRUE | SEV-SNP is enabled. |
FALSE | SEV-SNP is disabled. |
Definition at line 1105 of file CcExitVcHandler.c.
STATIC UINT64 UnsupportedExit | ( | IN GHCB * | Ghcb, |
IN EFI_SYSTEM_CONTEXT_X64 * | Regs, | ||
IN CC_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 74 of file CcExitVcHandler.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.
[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 113 of file CcExitVcHandler.c.
STATIC UINT64 VcCheckOpcodeBytes | ( | IN OUT GHCB * | Ghcb, |
IN OUT EFI_SYSTEM_CONTEXT_X64 * | Regs, | ||
IN OUT CC_INSTRUCTION_DATA * | InstructionData, | ||
IN UINT64 | ExitCode | ||
) |
Check that the opcode matches the exit code for a #VC.
Each exit code should only be raised while executing certain instructions. Verify that rIP points to a correct instruction based on the exit code to protect against maliciously injected interrupts via the hypervisor. If it does not, report an unsupported event to the hypervisor.
Decodes the ModRm byte into InstructionData if necessary.
[in,out] | Ghcb | Pointer to the Guest-Hypervisor Communication Block |
[in,out] | Regs | x64 processor context |
[in,out] | InstructionData | Instruction parsing context |
[in] | ExitCode | Exit code given by #VC. |
0 | No problems detected. |
Definition at line 1710 of file CcExitVcHandler.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 1992 of file CcExitVcHandler.c.
STATIC UINT64 VmmCallExit | ( | IN OUT GHCB * | Ghcb, |
IN OUT EFI_SYSTEM_CONTEXT_X64 * | Regs, | ||
IN CC_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 652 of file CcExitVcHandler.c.
STATIC UINT64 WbinvdExit | ( | IN OUT GHCB * | Ghcb, |
IN OUT EFI_SYSTEM_CONTEXT_X64 * | Regs, | ||
IN CC_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 582 of file CcExitVcHandler.c.
UINT32 Count |
Definition at line 53 of file CcExitVcHandler.c.
UINT32 Eax |
Definition at line 42 of file CcExitVcHandler.c.
UINT32 EaxIn |
Definition at line 38 of file CcExitVcHandler.c.
UINT32 Ebx |
Definition at line 43 of file CcExitVcHandler.c.
UINT32 Ecx |
Definition at line 44 of file CcExitVcHandler.c.
UINT32 EcxIn |
Definition at line 39 of file CcExitVcHandler.c.
UINT32 Edx |
Definition at line 45 of file CcExitVcHandler.c.
SEV_SNP_CPUID_FUNCTION function[0] |
Definition at line 56 of file CcExitVcHandler.c.
UINT64 Reserved |
Definition at line 46 of file CcExitVcHandler.c.
UINT32 Reserved1 |
Definition at line 54 of file CcExitVcHandler.c.
UINT64 Reserved2 |
Definition at line 55 of file CcExitVcHandler.c.
UINT64 Unused |
Definition at line 40 of file CcExitVcHandler.c.
UINT64 Unused2 |
Definition at line 41 of file CcExitVcHandler.c.