From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-BY2-obe.outbound.protection.outlook.com (mail-by2nam01on0608.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe42::608]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 2CAE921C8D0AC for ; Fri, 26 May 2017 07:44:38 -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=/Asil2816ASr8KRIj3/3gahauqj9dtqD0ZVRbYKL4aA=; b=wDL8RoyBeKq2ddVRA978ZJm0jQBvlFne7R3qsicbTv0+hKhMOgM+wwipS3VT79FMisvfzPMPzRTQFwnXJ72LSXFXIpRL1oGDsO5izqlYOnyl+p4fAF3vZG2X+KHtH6WSfkWUrNLTtNOYihKuOwIPhZ6nKM4LbAZrikLpgPC8NJk= 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 SN1PR12MB0158.namprd12.prod.outlook.com (10.162.3.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1124.9; Fri, 26 May 2017 14:44:36 +0000 From: Brijesh Singh To: CC: , , Brijesh Singh , Jordan Justen , Laszlo Ersek Date: Fri, 26 May 2017 10:44:02 -0400 Message-ID: <1495809845-32472-15-git-send-email-brijesh.singh@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1495809845-32472-1-git-send-email-brijesh.singh@amd.com> References: <1495809845-32472-1-git-send-email-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: CY4PR16CA0024.namprd16.prod.outlook.com (10.172.173.34) To SN1PR12MB0158.namprd12.prod.outlook.com (10.162.3.145) X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PR12MB0158: X-MS-Office365-Filtering-Correlation-Id: 89181017-88a6-4871-b301-08d4a445bb9d X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081)(201703131423075)(201703031133081); SRVR:SN1PR12MB0158; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 3:Vx9m8C6iv6nbmyY4In1xxkDrZwxTTR5rqkZFTHHrrvfjfOhkpWdNYeB2ipV7unfX73gYoEFwbBSaYFKNEUwmXr1QwmC5Kduli1sNJ75FCCZcHA+KrPC+hxXGNqebeejMk1v1+P6VGhfbuD3t/pGPsa1hfApY2R7dtQfAsLYcKRENBMtROBjou/l+ERO1Ghk0GQydce3mlq5vnDB8Tnc2fpy+kIpvIrMgXHjx4xpatYBl667PxM/i1U3pJLMsSi2ueL4TGacRYAgiOCUH1i4lcbQYKJE125xQX36md681XBZNI67HIqdJYf8gysdQuRLQNMq75r7XRFZu14hmioNUD8b7mbc36f7pKF4KTnfkmU4=; 25:VwFVdRzNLZG2uuYQ1ADRWAo//zsTe/F7RIy5KH/ffm8VFY6VrXtlWuBF/i5Y4KB57lZ0vdC4i7YgsF/01H/KvDFqOPTLw6z8CmdEC3ZxWNi7y0z8HplT9/VixcBZtKB/oWfMIVjjQ72FX7FVMSanteh8JHVw4S7q9kwuBUTg5jmkTdw2rOZsz5pPeXMLLimmBiH67sSvSTopjv16f8aKEwXeoJiieJvP/167ZiIIMBljFuZTAzQKQdbOuce+8z+zeuf5XgS0WzWLXdRLGP+ZnUeQ7BPA8PoTkW5XXG0/f00EXS0NFHAb797AFRQHj4excU/pqOHc0Q0k8iZkeEBWh4+JYpzAWNQ5quhgvSz9cjmX24W5FOdrk8b2SYG+z8vQO6UXkDansTCUoBxGQj6usnvYK76f4j6uQk766Om77t0Rdy7bzqitF7+lzRhNCPUwJp/7jv7qtKzGTjCPz013WdGoro1MQSBgBqz8QT7XQfQ= X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 31:siOacAea/9bo511BSheo5ESsklL5ArikJaYVx7nYHkXk8VK49rowmPI0NzXWYlDHbl3imBiS4cWywpH4lJ5EMnD1VI+wCGEhg90+i8RB6/uIz9XLITXibCm3BO0w8wjt4mzZdWTsSZ3pyY9ee+IkSugyGQ1KD+vKEwJ5+MCk2pkguc7pk0JFGnDkWMeJI2OYUokpDCcGIVXesisCtcCSb6GvZMvL6SM7vg8YG1OLpLQ=; 20:bGjwxHc+AGuF3swp1ZveQn/fFgEEuHSq/5jDWt6Nm2zStQInmy7lSXirIag38XJ+RUc7Ixo9YDkbr3WTU3y7JvdVGiVDrsSpzP6zpgG/zfC0sZPBcRLWZbRyOm5jZ0fBf5asuTknr6x1JeqVsX/i46qEkyPF7DF9bSHfqkLF+pVHTWpyYuxSwQpg0Btda7FLPZr/Vh4zkjxbnSP3ahnEV1X8h8EZhp+O5uqtP2lXTHMK6gIHsn5ycwUHAUgz/oAWqEqEQqkjNwUgl6tyG2G0HmncFffOkGV/n8rvnwLEc5t5JiWj71XaiaacWaj6rGnOU9MGa1uyjwAiEsF0Eps1mHLpIEG51zOi24U2zYCOqryqx1a/mhMpTsZel0QfTO6gEm5ANddcJs0Nfk3viMJVSu8Tk9devOjdBIPsI7j5nMm2nhPtX8xrdPRrHxxBaoKHNDuGq7MUgNuEH/xu7rm9m94D9khoSauI7d0NAChF6wiL36N68DGRe4AIIY3TZVWf 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)(8121501046)(5005006)(93006095)(93001095)(3002001)(10201501046)(6055026)(6041248)(20161123562025)(20161123564025)(20161123555025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(6072148); SRVR:SN1PR12MB0158; BCL:0; PCL:0; RULEID:; SRVR:SN1PR12MB0158; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 4:VJ74GHMKwySKMW+VzDORN9Cqfiht+HhS9hmTtSoBG0jEwIWTSAeihnI+bifr2FGqbaR7ZXB4qGI54MhOmlze9/t5lrbAXG05CckrlWNohWBn/54eGyJFbjC3nbVa4fDFBf07WRK5+o4Nabn9GyGv/q1GN+Hvo3VNkwkrD1VgGrut55IPRGMGIRjorFx8PeoDln87ZWkfibVC0PziCmC9lMpAAVFnLW+QJ+t4IWWI3DnJMq+URY/eYuO/UbMjM6x1Fi+ayq7MjF7RK4/VrkX1yVQ0So/rOcwCxgzizGcHKOBJjUY0YaWSvLDRd0M/UVnykaLHpRfQ8OtmgFEmNauV1beOvJ2DZ/GAJU1nx6OQXauVsIBLmlh3CkzP/zuj3QzFBzM+gfwaZcrPlPdYac4gBZjAHfLZCZHuIVDYmTNLPJ+UMNWJwH7rMVUxAl4/fp7WRXB9OIr9znOvK3ywQq80a3RHzfS3gl5ar498bnNqlhSAauJXUiiD6zVrkkGq+Va9Hwdy0AHnbUkWrkJxCbVblVj3A0SRmMQ+7KcobhcLX1x71PC9ypmcTQWLyKFjsmm/7BMJ1CmgYWcNI1DETzJAkzk95tYEt8JN/NgBuevS+88Gdcvmjuuhtw2TaCn7qBWPkdgUtUTIqVjewtonwFHLEjLS6p+GNrqjz2H4CdPUFyqVUiIlGGUvQvFDHsNUSF0CVpxsLpDDkNkXRC+b7FjWPhvDXQNRjT6+bEk35XnIK//9D/2kTq9JxClomU05b8TnlfDFdPygbM/xSPmfNLt009zdUNKp1nInxj/JFn38fWEKq0VNzF5zHIL84UCQfYKc8YfvGEzODCvXHfelxXHTNoTxG/TaChECTikEH34VjO997KDNNdggJkjY1o3zFmU6 X-Forefront-PRVS: 031996B7EF X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(6029001)(39450400003)(39410400002)(39840400002)(39860400002)(39400400002)(39850400002)(2950100002)(6916009)(6666003)(38730400002)(110136004)(50226002)(76176999)(36756003)(81166006)(8676002)(53936002)(86362001)(478600001)(48376002)(54906002)(25786009)(5660300001)(50986999)(189998001)(5003940100001)(33646002)(305945005)(6486002)(2906002)(53416004)(47776003)(2351001)(42186005)(3846002)(6116002)(66066001)(4326008)(50466002)(7736002); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0158; H:brijesh-build-machine.amd.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN1PR12MB0158; 23:DHVGfJ3vyIZoBiOKLbS/sqob9yo3bkLwfbZL/JplA?= =?us-ascii?Q?ailk2dJ0I3B0oWwIiNpXeieVWxHP3ajGBmyI7bs6Sa4j6hiWn8cbKCDVV+Hm?= =?us-ascii?Q?gIaDPxw2mMab4KTzJT+QqT2jWcJnJRFvyWuZjNc68upmMiCETKmRCOjFt4YW?= =?us-ascii?Q?yBxc26gHDnw1NV8ym4b4Hz69TB3aPiLkvduOJ1lxRzsBC8LlxpEhp6g7LRY7?= =?us-ascii?Q?5jf+pTDvLzH39BAw/LfBP0dIgl/QXDuv8LtNUq4xBvihF0WqChhAkM0RrV2J?= =?us-ascii?Q?DG+ulLdZn0qDhZE1AD0ni48/V4Qgn8tKWceEJfPedtOV4PCKF5sSGvfV/kYb?= =?us-ascii?Q?oz9isOT1YeNkbtgAVjUleYZyx/InbQqbNRvXwgjTlvhXlUZe9yhiDltt0k7s?= =?us-ascii?Q?qgOL4MPHOQJAaaNpI5WvutHwacsGRGVaYIcKdZ1dLeGnlq1tgIWupbHCdaEB?= =?us-ascii?Q?9S9rYthlq762claChzoIq+DX963SSZ3ggt78S1p4wBBS/dMnYQK2f3FkmM/b?= =?us-ascii?Q?rHfQPOX8ixFpyiwLuDnNakBq+an+phoATfUcLnoCR+H+0tA5vu4Br2ApyVF5?= =?us-ascii?Q?qdkN9QIhqfyxRR0jnrlRPt82VLnVQUIUyTe37bjsQdy0lT9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G9LXc11mCHl8AljdAURZyWWizRBovLpBm3IF5LrtNkELnIOaJvzW3Z0HH+iPCK+rlFoT5ecGWgC1Gbnssc4yQ9BOa5TOd6kHpr2m+rgTU=; 5:2ppeiHV72lMw7Glmu4b3kfH4Jvpl5n9QFgDxILx9NV3WUhXHdjqMqqH2CPSHD03fopuvpoD4jnVOjykt53Jia0SCvAwKTm9IZ/ayfYwr/WQx/QOfkLPle6lubk/jjy9qwwawD+B5KmlYbwaCucUdeQ==; 24:201LkIhG0/xXL1g2H92D+KZZj4GcVq979CcHcUoNaeU07c64GUYaeup640yxnSI07Mqf8mFXPIbB2txOrkTbXKyLXJuPwtlw+3fyHumCnEk= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 7:ATjHFhOb7PdftcmKFov48oIp+loTvfce3GYESZb9m3Pscg2Ecd4ISgXZ+6k8gn04lYoL1+DqRC7xj2SsHmI3NQ5WARmQHoVHvwp08nn6bwsHkLi5cxki8tvrQpCiTFs8e2CABi+QfrW4jibWMFqag2PABwhqCLWklzdsztaTWTG4G+tB73Zvz40dvMzKLBksSQzZaol2cnmqi4RP1Uui4emzmP9Z5QJPXp4LS+RnebHFc+vTwAoWe3F4IK7c32kqagxqEI9vU600mdmLCOnXvONJoq3PQJW5IH+wXcsBS0eBTsm4HRIxLfgFJGeUGBOq/tj8sRpa3qFriw1ko4pG+w==; 20:lZBFQIxUnQ/WkswlDjgR1xa4dBHlgNAHq8Fm6D1/PaFuFcJ+BmCjMTvNwcvhEKxYQBpu4+0nyv4ddfpXVnwazYTs1riD78l6wuFewO1YIJPw/ps1XW3QlZ9ols1Ix6wa9znDQDHx1zFS86DEduG/SgFiWi8GNLnj2w+CoVP2cIssaiQF6KvOBUOKaud7mClICRRpGpbfrlEMJlcFJMMB7PLGgCbn5i4/wldkeuJkJEfqTk39exDjkou+3yUvaUIK X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 May 2017 14:44:36.8671 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0158 Subject: [PATCH v6 14/17] OvmfPkg/QemuFwCfgLib: Implement SEV internal function for Dxe phase 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: Fri, 26 May 2017 14:44:38 -0000 Content-Type: text/plain When SEV is enabled, the DMA must be performed on unencrypted pages. So when get asked to perfom FWCFG DMA read or write, we allocate a intermediate (bounce buffer) unencrypted buffer and use this buffer for DMA read or write. Cc: Jordan Justen Cc: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Brijesh Singh --- OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgDxeLib.inf | 7 ++ OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgDxe.c | 114 ++++++++++++++++++++ 2 files changed, 121 insertions(+) diff --git a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgDxeLib.inf b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgDxeLib.inf index d7e368e5435d..11cbb3c4f393 100644 --- a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgDxeLib.inf +++ b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgDxeLib.inf @@ -39,6 +39,7 @@ [Sources] [Packages] MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec OvmfPkg/OvmfPkg.dec [LibraryClasses] @@ -47,4 +48,10 @@ [LibraryClasses] DebugLib IoLib MemoryAllocationLib + MemEncryptSevLib +[Protocols] + gEdkiiIoMmuProtocolGuid ## SOMETIMES_CONSUMES + +[Depex] + gEdkiiIoMmuProtocolGuid OR gIoMmuAbsentProtocolGuid diff --git a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgDxe.c b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgDxe.c index ac05f4c347f3..f8eb03bc3a9a 100644 --- a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgDxe.c +++ b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgDxe.c @@ -4,6 +4,7 @@ Copyright (C) 2013, Red Hat, Inc. Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.
+ Copyright (c) 2017, Advanced Micro Devices. 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 @@ -14,14 +15,36 @@ WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ +#include + +#include + +#include #include #include +#include +#include #include "QemuFwCfgLibInternal.h" STATIC BOOLEAN mQemuFwCfgSupported = FALSE; STATIC BOOLEAN mQemuFwCfgDmaSupported; +STATIC EDKII_IOMMU_PROTOCOL *mIoMmuProtocol; +/** + + Returns a boolean indicating whether SEV is enabled + + @retval TRUE SEV is enabled + @retval FALSE SEV is disabled +**/ +BOOLEAN +InternalQemuFwCfgSevIsEnabled ( + VOID + ) +{ + return MemEncryptSevIsEnabled (); +} /** Returns a boolean indicating if the firmware configuration interface @@ -79,6 +102,24 @@ QemuFwCfgInitialize ( mQemuFwCfgDmaSupported = TRUE; DEBUG ((DEBUG_INFO, "QemuFwCfg interface (DMA) is supported.\n")); } + + if (mQemuFwCfgDmaSupported && MemEncryptSevIsEnabled ()) { + EFI_STATUS Status; + + // + // IoMmuDxe driver must have installed the IOMMU protocol. If we are not + // able to locate the protocol then something must have gone wrong. + // + Status = gBS->LocateProtocol (&gEdkiiIoMmuProtocolGuid, NULL, (VOID **)&mIoMmuProtocol); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, + "QemuFwCfgSevDma %a:%a Failed to locate IOMMU protocol.\n", + gEfiCallerBaseName, __FUNCTION__)); + ASSERT (FALSE); + CpuDeadLoop (); + } + } + return RETURN_SUCCESS; } @@ -114,3 +155,76 @@ InternalQemuFwCfgDmaIsAvailable ( { return mQemuFwCfgDmaSupported; } + +/** + Allocate a bounce buffer for SEV DMA. + + @param[in] NumPage Number of pages. + @param[out] Buffer Allocated DMA Buffer pointer + +**/ +VOID +InternalQemuFwCfgSevDmaAllocateBuffer ( + OUT VOID **Buffer, + IN UINT32 NumPages + ) +{ + EFI_STATUS Status; + + ASSERT (mIoMmuProtocol != NULL); + + Status = mIoMmuProtocol->AllocateBuffer ( + mIoMmuProtocol, + 0, + EfiBootServicesData, + NumPages, + Buffer, + EDKII_IOMMU_ATTRIBUTE_MEMORY_CACHED + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, + "%a:%a failed to allocate %u pages\n", gEfiCallerBaseName, __FUNCTION__, + NumPages)); + ASSERT (FALSE); + CpuDeadLoop (); + } + + DEBUG ((DEBUG_VERBOSE, + "%a:%a buffer 0x%Lx Pages %u\n", gEfiCallerBaseName, __FUNCTION__, + (UINT64)(UINTN)Buffer, NumPages)); +} + +/** + Free the DMA buffer allocated using InternalQemuFwCfgSevDmaAllocateBuffer + + @param[in] NumPage Number of pages. + @param[in] Buffer DMA Buffer pointer + +**/ +VOID +InternalQemuFwCfgSevDmaFreeBuffer ( + IN VOID *Buffer, + IN UINT32 NumPages + ) +{ + EFI_STATUS Status; + + ASSERT (mIoMmuProtocol != NULL); + + Status = mIoMmuProtocol->FreeBuffer ( + mIoMmuProtocol, + NumPages, + Buffer + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, + "%a:%a failed to free buffer 0x%Lx pages %u\n", gEfiCallerBaseName, + __FUNCTION__, (UINT64)(UINTN)Buffer, NumPages)); + ASSERT (FALSE); + CpuDeadLoop (); + } + + DEBUG ((DEBUG_VERBOSE, + "%a:%a buffer 0x%Lx Pages %u\n", gEfiCallerBaseName,__FUNCTION__, + (UINT64)(UINTN)Buffer, NumPages)); +} -- 2.7.4