From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-bl2nam02on060a.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe46::60a]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 96A5121969F92 for ; Mon, 22 May 2017 08:23:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=Xq1M/9+JXNGv84XKEawSMFi67taNdq/jxLf/H5NiNtI=; b=I+Dc4FbnFDlVo7ScOGj5y5LHNwlrSEULCx05H7w/0rKaLpUcGClrDNodffAC3xpPqZyPcXekkvGqYkzo9uDGe93TMcmaOdYc87yBoFr6nZeW3J8K9qiultmYLNItwTwmqAG1BCU8QZXhhI3Pc6HpSckon2XeEqmRMKPGKdBw77s= Authentication-Results: lists.01.org; dkim=none (message not signed) header.d=none;lists.01.org; dmarc=none action=none header.from=amd.com; Received: from brijesh-build-machine.amd.com (165.204.77.1) by DM2PR12MB0155.namprd12.prod.outlook.com (2a01:111:e400:50ce::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1101.14; Mon, 22 May 2017 15:23:38 +0000 From: Brijesh Singh To: , , CC: , , Brijesh Singh , Jiewen Yao Date: Mon, 22 May 2017 11:23:04 -0400 Message-ID: <1495466592-21641-7-git-send-email-brijesh.singh@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1495466592-21641-1-git-send-email-brijesh.singh@amd.com> References: <1495466592-21641-1-git-send-email-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BN6PR17CA0030.namprd17.prod.outlook.com (2603:10b6:404:123::16) To DM2PR12MB0155.namprd12.prod.outlook.com (2a01:111:e400:50ce::18) X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM2PR12MB0155: X-MS-Office365-Filtering-Correlation-Id: 656acf7b-5d14-4cb4-edbb-08d4a12685ea X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081)(201703131423075)(201703031133081); SRVR:DM2PR12MB0155; X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 3:5CK1W+s2XiEw5qQ/MPb4KG1lU2zYVw9P6urlhR2dMfayvQ9oXBvS7X7uy+UyyB4P31XRLRli47AbyBmNW0Rx/gyGkwbruVgKtxqSLAtJa93iLcwBcO9IDmG/AxpoNoSqkKxYdKTwFD+foDZcJJH7XTmFCbCBozfhDgWJCNoYTymmf+Q2Nx5ZgZQ/fphDWJHBy9Ps/cw/Plt2GDz1LjOlAjKreCZ1qiusdJfvJgNfGSqNhtbTY4QZWYJO5cjwqpSuF9oLaERsc9VD9wxgfOaE9KNGXglzcAmjuJUIACB7KgcwGhxN5yQjac0CfppJBVhSWbF9lrpmM4A+lJx4rAGm9nRZ2QnQQ66czQvnu773tdg=; 25:kJGDZuwN4atjlGzp7kMGf0e54X54YYZighQIj5bAV8Ublrn1CKW+aTJeWQki7VDR/1Kh5ZHfuY4u1p68YnX0uAXqsr6a+E5lxgZqxDzjX1yqN1deRF+nhaHVjqOj6NJ5otnq1FCAMWCdFPmttHqwYXR1f6IvtScG+k2NOMvoeosCHEwVgtZrc2Tp9YIyEop608Ba+l9VEGcm90su1kw1EL9Dt4ICc4vweGhpdvj1QaRAyQYfL6niiStn/XIwuzU9N0sljFCa5IE5i7FxGRbHyT+Zqpil3dlAhF9v5+W2HBeG27MXDQmUBZuik4Kr89VMSlOfi343YZAxAPCOHJpYNpvcP9vCcynIj3/RMEy1iRpKukxwJgypq7lxK1PjnjvVVXSGl8y1ZNQ/0DHN+iB7InFx/ZRkO7lDyO3CILs/X2z8O1OD18NFgsHgTfl4Z3IquqABFhGibcnndT6QaiyyxVHMlJE0BpJzdD6wkqtwdQM= X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 31:P94kryIeqynM9EfAnzxQEWbA5PW6mEIuzbjuzZ3YuMfwJTO64D/ZfxJcJU0I4XPkpPr6kReqoIxZwAEjw2p8pFV45qlFtcccIU4ZtE+3A2d52utH+UNAb0DQQpS0F7Ut7ac21zTMfSUfHjytvkw1+Z2d5Xt7voynWrr49qvbRQau/CMMStg9uyQGHfaQ1qrEbnheaUI7HYj8Acp8kkLi7CpkfQ7sLwVpfTx3r6gJifk=; 20:rFaI18kk7WEbGgBwDZ2Vce7Avr8z18ZQVCd2bzq/qO3naywrE6oZDUKyZSZ5bZhZes8jo1ti9kzL+1iNv7bhH5mwiJXqivOtomQothxjaVXXdrCFxKehSZHbGZQ1Gt/eeEs1XiMWjZy1AJ43eA8HHTvQUEfkiLHzZOrpUMoilYhEhkTeywlHxC8679ZVDrnmqHYNpKNl906prkEMziakitUKF9DC+7ygLH0NAJnru3RHRqa+NGM23FhavNuAIyYJXc6aT37CPD2InY1ZzMVQ33str6MeuvZ/ILRhZR+Cmb95n5phObwk5eXGCL3h4ZBiVv7CmIV1m353mw4/RddYlU0KeoyarnejDLfQcGTcD/tqTl6UouwpTDlnR4Ob+PtQR5qMxZlLf38FZ9qDFSKbGYTrTTnXjYxasrkbegxhant4+wbcnbSAuzFQ0aZTXe8qqLh0aj6WOLr6cFEE2tgrAxqVM808Gfg232usPGDA83YCMHCw9cew9LEA6IOGr6iH X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110)(228905959029699); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(601004)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3002001)(6055026)(6041248)(20161123558100)(20161123560025)(20161123555025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(6072148); SRVR:DM2PR12MB0155; BCL:0; PCL:0; RULEID:; SRVR:DM2PR12MB0155; X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 4:RW+ACbb7PcaQbrns0sX+uWMBFZXFWt40lC1oeHAoU7femDXKBjXyKYPiQuiSwS84Zt+M9mJYJzjEm+VVU2QcpVTGeoLfcEgVuRBGzotWMxFQWG/Y5mLCgK66uNTwiOIGlU2faaBWp9CjsHsavv3P12ORnhVKEv+u+XcQLr0FE9g1e+glyXDBSF/RTUprkd3IOmMGZbKmEyd+ag1VqKIpnkYu5/yYiN0uqT7t6eegx4Yfa4lbwnS5W8olYWz0VE3o77MbMPCAHIWDnuLDygrRVgO4juI2iGVvSjsryEbUG7u7ICTop4pge+rJJ0w27/qPzvqWFzemDW/A2a29zbkYh1Q6KJv7REb/MSiTPkmdF9ojsOLbbbTekjnkaYHUcPf7E7wB1T86rgEptZ2/pB0aTCjAPEiJuLgSd8om14LsxToqJxPoKiyXpnh1t+7TMihcoTjwq02Q/9a4cMOr0VLoQXZR6iBTrzPEuTo4Yp/fEViKB8RBxpAk3n8qcQ7XBN4cH2UwJWABcnelE2E/mD6GdAlZWrE2/UXRZB1FyGd9Xm40gOv7qV+pW4tbzczjCV7PDcpE7xiqhCeSoS1TxVgaM80Mg6gJXk4gLOVMclGzQChzwh4XMMCSHKiEPPgQkFD+KFwAva5kGPnRsDvpuzyGgoIPfID/U0PH539BvWkOPyDsGBMuuXKm5B0JsnqPvlYyyuK5KBgOIyN/ArisDNn6egAmVnZCkb7ibAMD6tHhe5NRYDLdOR9EBTNJpmh7fvYnSTrVK11tNv9ZIv+8sO7flhuc7eH326J4/Ho9pihiM2ndm5cYHG9cd94Et0NdPdNh1Urb/vET2SSwUMgXcn17G9Srd+J4hVQWQg4EpRli/7TLwGxkbdaUP4+4UtW4zSML X-Forefront-PRVS: 03152A99FF X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(39840400002)(39860400002)(39850400002)(39450400003)(39410400002)(39400400002)(6486002)(5003940100001)(54906002)(16799955002)(6666003)(2950100002)(15188155005)(36756003)(53416004)(42186005)(86362001)(47776003)(2201001)(66066001)(2906002)(5660300001)(305945005)(7736002)(50226002)(38730400002)(3846002)(6116002)(189998001)(8676002)(6306002)(76176999)(81166006)(53936002)(50986999)(53376002)(33646002)(4326008)(478600001)(48376002)(50466002)(25786009)(19627235001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR12MB0155; H:brijesh-build-machine.amd.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM2PR12MB0155; 23:gMVIuPdzr5QP7BKrv8Ujx+/FGMGwVoKBHNUMNOLhC?= =?us-ascii?Q?giCh04+Hd9KChN3o6MbSjDmuaWxLOdOKB/X7NEXb4fQyMGpb3U5e9KBl7bWi?= =?us-ascii?Q?zanKoRkJgcV/58tn0NRol8AJ/UOPHJoDPc/gY4IsAj/wCPFatu6/o69PzSIl?= =?us-ascii?Q?Q1hCFx+maQkwOPmDM72/KOcNCdYtZeM7DwPTMLE7H8aals2VrtGQ7f9HqydW?= =?us-ascii?Q?zXIsxpEir6z1UF1ky0lLgNRXe1R22KGtYleWyblRR+SIxnjVbgIkROVsBZDu?= =?us-ascii?Q?bUHxNfWEqSUuw7qYfvZ2FiDuq4BwOSFJFUL/7F/HTvFkQSlgWjBDO22Kh/r8?= =?us-ascii?Q?IXyyHSlu+rm9tuQwjrpRcPuOpYbyreQz9ctJVozgSTJE9bd58Fdv+j4w7NtR?= =?us-ascii?Q?S3HooJq7cYKw1scpW/Ixuqcc4oCVJ2TOBn4man7OQ4sdKl2JuwsaOe8FPJlU?= =?us-ascii?Q?jyh9LGdu5wM/Uul9SqH0f3emfrk9kkhF04bfhmbMAyEcneJDiyvCc/XTXUzw?= =?us-ascii?Q?9nv+qg5YZVDlkgqEhCrgLgDQFdlAPgnjY4Bz5YsUziJepJEwT9mYTZnjxcuZ?= =?us-ascii?Q?xbfJW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+IXWlHqKgG7UvUpicbf0BjM6noC4ipkJm9B6PjkSfBACfcAzCiIu4uqR4fhX1q8H/e69iYBDd8ptHrLgELbXBjmzixfDghypm5a6o4XdSgTPQ4DBYsRNjbCMxa8litYJtGik X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 May 2017 15:23:38.6802 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR12MB0155 Subject: [PATCH v5 06/14] OvmfPkg:AmdSevDxe: Add AmdSevDxe driver X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 May 2017 15:23:41 -0000 Content-Type: text/plain When SEV is enabled, the MMIO memory range must be mapped as unencrypted (i.e C-bit cleared). We need to clear the C-bit for MMIO GCD entries in order to cover the ranges that were added during the PEI phase (through memory resource descriptor HOBs). Additionally, the NonExistent ranges are processed in order to cover, in advance, MMIO ranges added later in the DXE phase by various device drivers, via the appropriate DXE memory space services. The approach is not transparent for later addition of system memory ranges to the GCD memory space map. (Such ranges should be encrypted.) OVMF does not do such a thing at the moment, so this approach should be OK. The driver is being added to the APRIORI DXE file so that, we clear the C-bit from MMIO regions before any driver accesses it. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Leo Duran Cc: Jiewen Yao Contributed-under: TianoCore Contribution Agreement 1.0 Suggested-by: Jiewen Yao Signed-off-by: Brijesh Singh Reviewed-by: Jiewen Yao --- OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/OvmfPkgIa32X64.fdf | 2 + OvmfPkg/OvmfPkgX64.fdf | 2 + OvmfPkg/AmdSevDxe/AmdSevDxe.inf | 43 ++++++++++++ OvmfPkg/AmdSevDxe/AmdSevDxe.c | 71 ++++++++++++++++++++ 6 files changed, 120 insertions(+) diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index ef245635224c..daf2faadea35 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -822,6 +822,7 @@ [Components.X64] !endif OvmfPkg/PlatformDxe/Platform.inf + OvmfPkg/AmdSevDxe/AmdSevDxe.inf !if $(SMM_REQUIRE) == TRUE OvmfPkg/SmmAccess/SmmAccess2Dxe.inf diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 0a693f2772a7..6189088da86c 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -820,6 +820,7 @@ [Components] !endif OvmfPkg/PlatformDxe/Platform.inf + OvmfPkg/AmdSevDxe/AmdSevDxe.inf !if $(SMM_REQUIRE) == TRUE OvmfPkg/SmmAccess/SmmAccess2Dxe.inf diff --git a/OvmfPkg/OvmfPkgIa32X64.fdf b/OvmfPkg/OvmfPkgIa32X64.fdf index 5233314139bc..12871860d001 100644 --- a/OvmfPkg/OvmfPkgIa32X64.fdf +++ b/OvmfPkg/OvmfPkgIa32X64.fdf @@ -190,6 +190,7 @@ [FV.DXEFV] APRIORI DXE { INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf INF MdeModulePkg/Universal/PCD/Dxe/Pcd.inf + INF OvmfPkg/AmdSevDxe/AmdSevDxe.inf !if $(SMM_REQUIRE) == FALSE INF OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf !endif @@ -351,6 +352,7 @@ [FV.DXEFV] INF OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf INF OvmfPkg/VirtioGpuDxe/VirtioGpu.inf INF OvmfPkg/PlatformDxe/Platform.inf +INF OvmfPkg/AmdSevDxe/AmdSevDxe.inf !if $(SMM_REQUIRE) == TRUE INF OvmfPkg/SmmAccess/SmmAccess2Dxe.inf diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf index 36150101e784..ae6e66a1c08d 100644 --- a/OvmfPkg/OvmfPkgX64.fdf +++ b/OvmfPkg/OvmfPkgX64.fdf @@ -190,6 +190,7 @@ [FV.DXEFV] APRIORI DXE { INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf INF MdeModulePkg/Universal/PCD/Dxe/Pcd.inf + INF OvmfPkg/AmdSevDxe/AmdSevDxe.inf !if $(SMM_REQUIRE) == FALSE INF OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf !endif @@ -351,6 +352,7 @@ [FV.DXEFV] INF OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf INF OvmfPkg/VirtioGpuDxe/VirtioGpu.inf INF OvmfPkg/PlatformDxe/Platform.inf +INF OvmfPkg/AmdSevDxe/AmdSevDxe.inf !if $(SMM_REQUIRE) == TRUE INF OvmfPkg/SmmAccess/SmmAccess2Dxe.inf diff --git a/OvmfPkg/AmdSevDxe/AmdSevDxe.inf b/OvmfPkg/AmdSevDxe/AmdSevDxe.inf new file mode 100644 index 000000000000..41635a57a454 --- /dev/null +++ b/OvmfPkg/AmdSevDxe/AmdSevDxe.inf @@ -0,0 +1,43 @@ +#/** @file +# +# Driver clears the encryption attribute from MMIO regions when SEV is enabled +# +# Copyright (c) 2017, AMD Inc. All rights reserved.
+# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD +# License which accompanies this distribution. The full text of the license may +# be found at http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#**/ + +[Defines] + INF_VERSION = 1.25 + BASE_NAME = AmdSevDxe + FILE_GUID = 2ec9da37-ee35-4de9-86c5-6d9a81dc38a7 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = AmdSevDxeEntryPoint + +[Sources] + AmdSevDxe.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + OvmfPkg/OvmfPkg.dec + +[LibraryClasses] + BaseLib + UefiLib + UefiDriverEntryPoint + UefiBootServicesTableLib + DxeServicesTableLib + DebugLib + MemEncryptSevLib + +[Depex] + TRUE diff --git a/OvmfPkg/AmdSevDxe/AmdSevDxe.c b/OvmfPkg/AmdSevDxe/AmdSevDxe.c new file mode 100644 index 000000000000..c483ae1419fd --- /dev/null +++ b/OvmfPkg/AmdSevDxe/AmdSevDxe.c @@ -0,0 +1,71 @@ +/** @file + + AMD Sev Dxe driver. The driver runs in APRIORI phase and clears C-bit from + MMIO and NonExistent Memory space when SEV is enabled. + + Copyright (c) 2017, AMD Inc. All rights reserved.
+ + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD + License which accompanies this distribution. The full text of the license may + be found at http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include + +#include +#include +#include +#include +#include +#include +#include + +EFI_STATUS +EFIAPI +AmdSevDxeEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + EFI_GCD_MEMORY_SPACE_DESCRIPTOR *AllDescMap; + UINTN NumEntries; + UINTN Index; + + // + // Do nothing when SEV is not enabled + // + if (!MemEncryptSevIsEnabled ()) { + return EFI_UNSUPPORTED; + } + + // + // 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 MMIO + // space added later (eg PciRootBridge). By clearing both known MMIO and NonExistent + // memory space can gurantee that current and furture MMIO adds will have + // C-bit cleared. + // + Status = gDS->GetMemorySpaceMap (&NumEntries, &AllDescMap); + if (Status == EFI_SUCCESS) { + for (Index = 0; Index < NumEntries; Index++) { + CONST EFI_GCD_MEMORY_SPACE_DESCRIPTOR *Desc; + + Desc = &AllDescMap[Index]; + if (Desc->GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo || + Desc->GcdMemoryType == EfiGcdMemoryTypeNonExistent) { + Status = MemEncryptSevClearPageEncMask (0, Desc->BaseAddress, EFI_SIZE_TO_PAGES(Desc->Length), FALSE); + ASSERT_EFI_ERROR(Status); + } + } + + FreePool (AllDescMap); + } + + return EFI_SUCCESS; +} -- 2.7.4