From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.58]) by mx.groups.io with SMTP id smtpd.web11.1658.1580857331216675910 for ; Tue, 04 Feb 2020 15:02:11 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=CY5lkU5X; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.92.58, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HnkD81ZzHMQppwblSD+9im6h8KWC0zI/XF4k9AMcPLALABUcjGlGNEKx1MoZewgqaJuRNxNVDwVEYxqPEC8wYlBI+lI/XfRqYByqqIU9WLRhonUePrKJK8KNgxLsCn/XBRXhoiNgd4c4RuTx7aUKD/aT+Y5h6Tn0FIqfrMtT6Os6rJHnIvIvTPxzW8Fow2YEBSOVhhrigm4+lA5JfQE9WJHwp8S/OTrP4Bpry4UHssKoXvBVldXHLS6xuRHMC7lSA48B70So2fz9LPOpIe647Hrt3e7p0GTX9U3l6PwtSaT7gHmKP3zGNDnve3f9PubIUej6yvZsCLU2n3LddmNQgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VlKNk8XISNE0+kGfjnY5dpnhM2VN1+HF+zu/1w+l3H8=; b=eMU68UduuoAO0uyUn5j/2aetu+6AzdIMqI2p1TJNHgBrrraHVuhpFMsJP1vr+CZ/TvDzNet9G/ayw16xvLuzv5/68Y0nw5reLMCYZ53uP85xWxym6IrURmpOuevTDyPX63gmqu3f2SIX3dMKbxpxqMPG7HdaNXVR7hlA/eSeYGUbFHyzhsR2gqmEhmtGFNab9XmhXNy40SG6T9u2HcpdyPnDwSJomSOYXKW1c7dROH/+NMFT1dpifkqjFloUeHYBZdcTyMRjje/hItKqW3o+IP+nnxzldP56JPJVgLqoIUi1DziDqrvflcPhAz8bHLO6n1hkniITQH2BfZYfPZejXg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VlKNk8XISNE0+kGfjnY5dpnhM2VN1+HF+zu/1w+l3H8=; b=CY5lkU5XR3nuvZSpBcULea0gqdFsAzBsfddVJBZwBmbTSpCpvl/QzncoQ65R9zOYz8abZvWiYyhMnAcKtlZHxs9aKtcd7g74ZsoSCN3yt7bZXZmyceQEnOK0XZ/5K/fofb1nDgh7OIhJZGp9w61SoDbAh4OrNjQVYKq8HsdlbGM= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; Received: from DM6PR12MB3163.namprd12.prod.outlook.com (20.179.71.154) by DM6PR12MB3930.namprd12.prod.outlook.com (10.255.174.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2686.29; Tue, 4 Feb 2020 23:02:09 +0000 Received: from DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::a0cd:463:f444:c270]) by DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::a0cd:463:f444:c270%7]) with mapi id 15.20.2707.020; Tue, 4 Feb 2020 23:02:09 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh , Maurice Ma , Guo Dong , Benjamin You Subject: [PATCH v4 08/40] UefiCpuPkg/CpuExceptionHandler: Add base support for the #VC exception Date: Tue, 4 Feb 2020 17:01:12 -0600 Message-Id: <18638c9ee90a20f9758bf6072115e8c491dfb098.1580857303.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: SN6PR16CA0062.namprd16.prod.outlook.com (2603:10b6:805:ca::39) To DM6PR12MB3163.namprd12.prod.outlook.com (2603:10b6:5:15e::26) Return-Path: thomas.lendacky@amd.com MIME-Version: 1.0 Received: from tlendack-t1.amd.com (165.204.77.1) by SN6PR16CA0062.namprd16.prod.outlook.com (2603:10b6:805:ca::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2686.32 via Frontend Transport; Tue, 4 Feb 2020 23:02:08 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 84c71f87-e94c-4e85-d6d7-08d7a9c64306 X-MS-TrafficTypeDiagnostic: DM6PR12MB3930:|DM6PR12MB3930: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-Forefront-PRVS: 03030B9493 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4636009)(39860400002)(366004)(376002)(136003)(396003)(346002)(199004)(189003)(4326008)(478600001)(6916009)(81156014)(2616005)(956004)(81166006)(8676002)(6666004)(966005)(316002)(54906003)(19627235002)(2906002)(6486002)(66476007)(66556008)(30864003)(7416002)(52116002)(7696005)(186003)(26005)(16526019)(5660300002)(86362001)(36756003)(66946007)(8936002);DIR:OUT;SFP:1101;SCL:1;SRVR:DM6PR12MB3930;H:DM6PR12MB3163.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 83/WGPSCjXCtywIxMYOdTf+Y3O4JUToEC5tQpNLop7kxBHkTxk3+g2MdkrB4WPgOHOE8KQQzrZoViKhlCzZ/4HDWOxm3D9ZBSeoBqruT0R3RdPY/YzmgURF/fZGuYAHRWc53J62g/wEjn4Qpqs9+x2w5pNLdHvSrUNSXe4T628iNAm/n3r54kedfsGFvUhkERQGMUmHmcPha8fKnKkeP/7SQzcn5H7eBKFD5GX09JqaY1LZXge/DNzkYSlOL5PcpnFV1gsadEWiScOr3LW4+pEd1Llxfl6yqRVEHdv2y3OlIvGfwmAFIhHZ8j/37I9Z+Bi4FNLnZYCflLmCwN9W7X8PgPwJ7IxgZJ/OEK1xSWp2Q30ic1JvPg3eGF/ZVtuHGjTeHu9kfSP/rzGrC+OaXbaZ3HvDNtu5fwF6m8a13mhqkMTTjD8v5j1D4dqJKjTPBqhPlChbgUeb2rF9uUi858vt9312UPbeAW/yTQjZTtZAW4RJIytOAVjzJzAggirnFPeuPG0ve5sOtlmEIknANQw== X-MS-Exchange-AntiSpam-MessageData: blOXpRXY007Z7yPDU8DChL2wd7OGhS/X7pc1rCYfV4ZeHBxUYee7jOA+rVbiY/gC6Hpf06e8hjK56141zOg83dZRcn21K82FAOnaTcTsm0G5xUG4RX/i/Iwwl+wXci2aE8yNx1NLARMb/37QDAL2lQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 84c71f87-e94c-4e85-d6d7-08d7a9c64306 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Feb 2020 23:02:09.2693 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: p72eU/Red2a54jhkZA6xvEoKdD8J6VKNoV4juCTmE3VEn1enJsedXeaM8Sgl51Ueixk1vxT25OrznygiLuKYjg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3930 Content-Type: text/plain BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2198 Add base support to handle #VC exceptions. This includes a stub routine to invoke when a #VC exception occurs and special checks in the common exception handlers to invoke the #VC exception handler routine. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Cc: Jordan Justen Cc: Ard Biesheuvel Cc: Maurice Ma Cc: Guo Dong Cc: Benjamin You Signed-off-by: Tom Lendacky --- OvmfPkg/OvmfPkgIa32.dsc | 5 ++ OvmfPkg/OvmfPkgIa32X64.dsc | 5 ++ OvmfPkg/OvmfPkgX64.dsc | 5 ++ UefiPayloadPkg/UefiPayloadPkgIa32.dsc | 2 + UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc | 2 + .../DxeCpuExceptionHandlerLib.inf | 5 ++ .../PeiCpuExceptionHandlerLib.inf | 5 ++ .../SecPeiCpuExceptionHandlerLib.inf | 8 +++ .../SmmCpuExceptionHandlerLib.inf | 5 ++ .../CpuExceptionHandlerLib/AMDSevVcCommon.h | 26 +++++++++ .../CpuExceptionCommon.h | 2 + .../CpuExceptionCommon.c | 2 +- .../Ia32/AMDSevVcCommon.c | 24 ++++++++ .../PeiDxeAMDSevVcHandler.c | 29 ++++++++++ .../PeiDxeSmmCpuException.c | 16 ++++++ .../SecAMDSevVcHandler.c | 55 +++++++++++++++++++ .../SecPeiCpuException.c | 16 ++++++ .../X64/AMDSevVcCommon.c | 50 +++++++++++++++++ 18 files changed, 261 insertions(+), 1 deletion(-) create mode 100644 UefiCpuPkg/Library/CpuExceptionHandlerLib/AMDSevVcCommon.h create mode 100644 UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/AMDSevVcCommon.c create mode 100644 UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeAMDSevVcHandler.c create mode 100644 UefiCpuPkg/Library/CpuExceptionHandlerLib/SecAMDSevVcHandler.c create mode 100644 UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/AMDSevVcCommon.c diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index 4568b78cadf1..41ec761e3f17 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -236,6 +236,7 @@ [LibraryClasses.common.SEC] PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLibIdt/PeiServicesTablePointerLibIdt.inf MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLib/VmgExitLib.inf [LibraryClasses.common.PEI_CORE] HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf @@ -274,6 +275,7 @@ [LibraryClasses.common.PEIM] DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgentLib.inf !endif CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLib/VmgExitLib.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/PeiQemuFwCfgS3LibFwCfg.inf PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf @@ -299,6 +301,7 @@ [LibraryClasses.common.DXE_CORE] DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf !endif CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLib/VmgExitLib.inf PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf [LibraryClasses.common.DXE_RUNTIME_DRIVER] @@ -349,6 +352,7 @@ [LibraryClasses.common.DXE_DRIVER] PlatformBmPrintScLib|OvmfPkg/Library/PlatformBmPrintScLib/PlatformBmPrintScLib.inf QemuBootOrderLib|OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLib/VmgExitLib.inf !if $(SMM_REQUIRE) == TRUE LockBoxLib|MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.inf !else @@ -392,6 +396,7 @@ [LibraryClasses.common.DXE_SMM_DRIVER] DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf !endif CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLib/VmgExitLib.inf !if $(SOURCE_DEBUG_ENABLE) == TRUE DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgentLib.inf !endif diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index 152b5d067116..41cc3eec3757 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -241,6 +241,7 @@ [LibraryClasses.common.SEC] PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLibIdt/PeiServicesTablePointerLibIdt.inf MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLib/VmgExitLib.inf [LibraryClasses.common.PEI_CORE] HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf @@ -279,6 +280,7 @@ [LibraryClasses.common.PEIM] DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgentLib.inf !endif CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLib/VmgExitLib.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/PeiQemuFwCfgS3LibFwCfg.inf PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf @@ -304,6 +306,7 @@ [LibraryClasses.common.DXE_CORE] DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf !endif CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLib/VmgExitLib.inf PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf [LibraryClasses.common.DXE_RUNTIME_DRIVER] @@ -354,6 +357,7 @@ [LibraryClasses.common.DXE_DRIVER] PlatformBmPrintScLib|OvmfPkg/Library/PlatformBmPrintScLib/PlatformBmPrintScLib.inf QemuBootOrderLib|OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLib/VmgExitLib.inf !if $(SMM_REQUIRE) == TRUE LockBoxLib|MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.inf !else @@ -397,6 +401,7 @@ [LibraryClasses.common.DXE_SMM_DRIVER] DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf !endif CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLib/VmgExitLib.inf !if $(SOURCE_DEBUG_ENABLE) == TRUE DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgentLib.inf !endif diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 4bfad441bd9f..46a679a0073e 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -241,6 +241,7 @@ [LibraryClasses.common.SEC] PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLibIdt/PeiServicesTablePointerLibIdt.inf MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLib/VmgExitLib.inf [LibraryClasses.common.PEI_CORE] HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf @@ -279,6 +280,7 @@ [LibraryClasses.common.PEIM] DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgentLib.inf !endif CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLib/VmgExitLib.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/PeiQemuFwCfgS3LibFwCfg.inf PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf @@ -304,6 +306,7 @@ [LibraryClasses.common.DXE_CORE] DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf !endif CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLib/VmgExitLib.inf PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf [LibraryClasses.common.DXE_RUNTIME_DRIVER] @@ -354,6 +357,7 @@ [LibraryClasses.common.DXE_DRIVER] PlatformBmPrintScLib|OvmfPkg/Library/PlatformBmPrintScLib/PlatformBmPrintScLib.inf QemuBootOrderLib|OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLib/VmgExitLib.inf !if $(SMM_REQUIRE) == TRUE LockBoxLib|MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.inf !else @@ -397,6 +401,7 @@ [LibraryClasses.common.DXE_SMM_DRIVER] DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf !endif CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLib/VmgExitLib.inf !if $(SOURCE_DEBUG_ENABLE) == TRUE DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgentLib.inf !endif diff --git a/UefiPayloadPkg/UefiPayloadPkgIa32.dsc b/UefiPayloadPkg/UefiPayloadPkgIa32.dsc index d52945442e0e..c2f7217c964e 100644 --- a/UefiPayloadPkg/UefiPayloadPkgIa32.dsc +++ b/UefiPayloadPkg/UefiPayloadPkgIa32.dsc @@ -233,6 +233,7 @@ [LibraryClasses.common.DXE_CORE] DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf !endif CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLib/VmgExitLib.inf [LibraryClasses.common.DXE_DRIVER] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf @@ -244,6 +245,7 @@ [LibraryClasses.common.DXE_DRIVER] DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf !endif CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLib/VmgExitLib.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf [LibraryClasses.common.DXE_RUNTIME_DRIVER] diff --git a/UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc b/UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc index 0736cd995476..b7cfeeff9b49 100644 --- a/UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc +++ b/UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc @@ -234,6 +234,7 @@ [LibraryClasses.common.DXE_CORE] DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf !endif CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLib/VmgExitLib.inf [LibraryClasses.common.DXE_DRIVER] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf @@ -245,6 +246,7 @@ [LibraryClasses.common.DXE_DRIVER] DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf !endif CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLib/VmgExitLib.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf [LibraryClasses.common.DXE_RUNTIME_DRIVER] diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf index e41383573043..dc328e230de3 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf @@ -26,17 +26,21 @@ [Sources.Ia32] Ia32/ExceptionTssEntryAsm.nasm Ia32/ArchExceptionHandler.c Ia32/ArchInterruptDefs.h + Ia32/AMDSevVcCommon.c [Sources.X64] X64/ExceptionHandlerAsm.nasm X64/ArchExceptionHandler.c X64/ArchInterruptDefs.h + X64/AMDSevVcCommon.c [Sources.common] CpuExceptionCommon.h CpuExceptionCommon.c PeiDxeSmmCpuException.c DxeException.c + PeiDxeAMDSevVcHandler.c + AMDSevVcCommon.h [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard @@ -57,3 +61,4 @@ [LibraryClasses] PeCoffGetEntryPointLib MemoryAllocationLib DebugLib + VmgExitLib diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf index f31423ac0f91..37dbbdb35711 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf @@ -26,17 +26,21 @@ [Sources.Ia32] Ia32/ExceptionTssEntryAsm.nasm Ia32/ArchExceptionHandler.c Ia32/ArchInterruptDefs.h + Ia32/AMDSevVcCommon.c [Sources.X64] X64/ExceptionHandlerAsm.nasm X64/ArchExceptionHandler.c X64/ArchInterruptDefs.h + X64/AMDSevVcCommon.c [Sources.common] CpuExceptionCommon.h CpuExceptionCommon.c PeiCpuException.c PeiDxeSmmCpuException.c + PeiDxeAMDSevVcHandler.c + AMDSevVcCommon.h [Packages] MdePkg/MdePkg.dec @@ -52,6 +56,7 @@ [LibraryClasses] HobLib MemoryAllocationLib SynchronizationLib + VmgExitLib [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard # CONSUMES diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf index 6d25cafe2ca3..86f21abd9fd0 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf @@ -26,16 +26,20 @@ [Sources.Ia32] Ia32/ExceptionTssEntryAsm.nasm Ia32/ArchExceptionHandler.c Ia32/ArchInterruptDefs.h + Ia32/AMDSevVcCommon.c [Sources.X64] X64/ExceptionHandlerAsm.nasm X64/ArchExceptionHandler.c X64/ArchInterruptDefs.h + X64/AMDSevVcCommon.c [Sources.common] CpuExceptionCommon.h CpuExceptionCommon.c SecPeiCpuException.c + SecAMDSevVcHandler.c + AMDSevVcCommon.h [Packages] MdePkg/MdePkg.dec @@ -48,3 +52,7 @@ [LibraryClasses] PrintLib LocalApicLib PeCoffGetEntryPointLib + VmgExitLib + +[Pcd] + gUefiCpuPkgTokenSpaceGuid.PcdSecGhcbBase diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf index 66c7f59e3c91..c84f964b5f89 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf @@ -26,17 +26,21 @@ [Sources.Ia32] Ia32/ExceptionTssEntryAsm.nasm Ia32/ArchExceptionHandler.c Ia32/ArchInterruptDefs.h + Ia32/AMDSevVcCommon.c [Sources.X64] X64/ExceptionHandlerAsm.nasm X64/ArchExceptionHandler.c X64/ArchInterruptDefs.h + X64/AMDSevVcCommon.c [Sources.common] CpuExceptionCommon.h CpuExceptionCommon.c PeiDxeSmmCpuException.c SmmException.c + PeiDxeAMDSevVcHandler.c + AMDSevVcCommon.h [Packages] MdePkg/MdePkg.dec @@ -51,4 +55,5 @@ [LibraryClasses] LocalApicLib PeCoffGetEntryPointLib DebugLib + VmgExitLib diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/AMDSevVcCommon.h b/UefiCpuPkg/Library/CpuExceptionHandlerLib/AMDSevVcCommon.h new file mode 100644 index 000000000000..c0a2ecd17d4c --- /dev/null +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/AMDSevVcCommon.h @@ -0,0 +1,26 @@ +/** @file + Common header file for SEV-ES #VC Exception Handler Support. + + Copyright (c) 2019, Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef _AMD_SEV_VC_COMMON_H_ +#define _AMD_SEV_VC_COMMON_H_ + +#include +#include + +UINTN +DoVcException( + EFI_SYSTEM_CONTEXT Context + ); + +UINTN +DoVcCommon( + GHCB *Ghcb, + EFI_SYSTEM_CONTEXT Context + ); + +#endif diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h index 805dd9cbb4ff..0f274e7ea328 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h @@ -24,6 +24,8 @@ #define CPU_INTERRUPT_NUM 256 #define HOOKAFTER_STUB_SIZE 16 +#define VC_EXCEPTION 29 + // // Exception Error Code of Page-Fault Exception // diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c index 8adbd43fefb4..39e4dd9e9417 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c @@ -14,7 +14,7 @@ // // 1 means an error code will be pushed, otherwise 0 // -CONST UINT32 mErrorCodeFlag = 0x00227d00; +CONST UINT32 mErrorCodeFlag = 0x20227d00; // // Define the maximum message length diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/AMDSevVcCommon.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/AMDSevVcCommon.c new file mode 100644 index 000000000000..0b67ac69d7f4 --- /dev/null +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/AMDSevVcCommon.c @@ -0,0 +1,24 @@ +/** @file + IA32 SEV-ES #VC Exception Handler functons. + + Copyright (c) 2019, Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include "AMDSevVcCommon.h" + +UINTN +DoVcCommon ( + GHCB *Ghcb, + EFI_SYSTEM_CONTEXT Context + ) +{ + EFI_SYSTEM_CONTEXT_IA32 *Regs = Context.SystemContextIa32; + + Regs->ExceptionData = 0; + + return GP_EXCEPTION; +} diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeAMDSevVcHandler.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeAMDSevVcHandler.c new file mode 100644 index 000000000000..9c86c01cac74 --- /dev/null +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeAMDSevVcHandler.c @@ -0,0 +1,29 @@ +/** @file + PEI and DXE SEV-ES #VC Exception Handler functons. + + Copyright (c) 2019, Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include "CpuExceptionCommon.h" +#include "AMDSevVcCommon.h" + +UINTN +DoVcException ( + EFI_SYSTEM_CONTEXT Context + ) +{ + MSR_SEV_ES_GHCB_REGISTER Msr; + GHCB *Ghcb; + + Msr.GhcbPhysicalAddress = AsmReadMsr64 (MSR_SEV_ES_GHCB); + ASSERT(Msr.GhcbInfo.Function == 0); + + Ghcb = Msr.Ghcb; + + return DoVcCommon (Ghcb, Context); +} diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c index 72c2aeca4c13..0c248e7eb904 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c @@ -7,6 +7,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include "CpuExceptionCommon.h" +#include "AMDSevVcCommon.h" #include /** @@ -86,6 +87,21 @@ CommonExceptionHandlerWorker ( break; } + if (ExceptionType == VC_EXCEPTION) { + UINTN Status; + // + // #VC must be handled for an SEV-ES guest + // + Status = DoVcException(SystemContext); + if (Status) { + // Exception not handled - Status contains the desired exception now + ExceptionType = Status; + } else { + // Exception handled + return; + } + } + if (ExternalInterruptHandler != NULL && ExternalInterruptHandler[ExceptionType] != NULL) { (ExternalInterruptHandler[ExceptionType]) (ExceptionType, SystemContext); diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecAMDSevVcHandler.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecAMDSevVcHandler.c new file mode 100644 index 000000000000..ca8fc486be81 --- /dev/null +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecAMDSevVcHandler.c @@ -0,0 +1,55 @@ +/** @file + SEC SEV-ES #VC Exception Handler functons. + + Copyright (c) 2019, Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include "CpuExceptionCommon.h" +#include "AMDSevVcCommon.h" + + +UINTN +DoVcException( + EFI_SYSTEM_CONTEXT Context + ) +{ + MSR_SEV_ES_GHCB_REGISTER Msr; + GHCB *Ghcb; + + Msr.GhcbPhysicalAddress = AsmReadMsr64 (MSR_SEV_ES_GHCB); + Ghcb = Msr.Ghcb; + + if (Msr.GhcbInfo.Function != 0) { + if (Msr.GhcbInfo.Function != GHCB_INFO_SEV_INFO) { + ASSERT (0); + return GP_EXCEPTION; + } + + if (Msr.GhcbProtocol.SevEsProtocolMin > Msr.GhcbProtocol.SevEsProtocolMax) { + ASSERT (0); + return GP_EXCEPTION; + } + + if ((Msr.GhcbProtocol.SevEsProtocolMin > GHCB_VERSION_MAX) || + (Msr.GhcbProtocol.SevEsProtocolMax < GHCB_VERSION_MIN)) { + ASSERT (0); + return GP_EXCEPTION; + } + + Msr.GhcbPhysicalAddress = FixedPcdGet32 (PcdSecGhcbBase); + AsmWriteMsr64(MSR_SEV_ES_GHCB, Msr.GhcbPhysicalAddress); + + Ghcb = Msr.Ghcb; + SetMem (Ghcb, sizeof (*Ghcb), 0); + + /* Set the version to the maximum that can be supported */ + Ghcb->ProtocolVersion = MIN (Msr.GhcbProtocol.SevEsProtocolMax, GHCB_VERSION_MAX); + Ghcb->GhcbUsage = GHCB_STANDARD_USAGE; + } + + return DoVcCommon(Ghcb, Context); +} diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c index 20148db74cf8..998a90ba61a6 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c @@ -8,6 +8,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include "CpuExceptionCommon.h" +#include "AMDSevVcCommon.h" CONST UINTN mDoFarReturnFlag = 0; @@ -24,6 +25,21 @@ CommonExceptionHandler ( IN EFI_SYSTEM_CONTEXT SystemContext ) { + if (ExceptionType == VC_EXCEPTION) { + UINTN Status; + // + // #VC must be handled for an SEV-ES guest + // + Status = DoVcException(SystemContext); + if (Status) { + // Exception not handled - Status contains the desired exception now + ExceptionType = Status; + } else { + // Exception handled + return; + } + } + // // Initialize the serial port before dumping. // diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/AMDSevVcCommon.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/AMDSevVcCommon.c new file mode 100644 index 000000000000..cee5ce806473 --- /dev/null +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/AMDSevVcCommon.c @@ -0,0 +1,50 @@ +/** @file + X64 SEV-ES #VC Exception Handler functons. + + Copyright (c) 2019, Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include "AMDSevVcCommon.h" + +UINTN +DoVcCommon ( + GHCB *Ghcb, + EFI_SYSTEM_CONTEXT Context + ) +{ + EFI_SYSTEM_CONTEXT_X64 *Regs = Context.SystemContextX64; + UINT64 Status; + UINTN ExitCode, VcRet; + + VmgInit (Ghcb); + + ExitCode = Regs->ExceptionData; + switch (ExitCode) { + default: + Status = VmgExit (Ghcb, SvmExitUnsupported, ExitCode, 0); + if (Status == 0) { + Regs->ExceptionData = 0; + VcRet = GP_EXCEPTION; + } else { + GHCB_EVENT_INJECTION Event; + + Event.Uint64 = Status; + if (Event.Elements.ErrorCodeValid) { + Regs->ExceptionData = Event.Elements.ErrorCode; + } else { + Regs->ExceptionData = 0; + } + + VcRet = Event.Elements.Vector; + } + } + + VmgDone (Ghcb); + + return VcRet; +} -- 2.17.1