From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-bl2nam02on0606.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe46::606]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id DCB1621969F92 for ; Mon, 22 May 2017 08:23:48 -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=iS6hxN0RrEdAh3JgXuJB5jYMFG4d4+qCBB/Eg722SZA=; b=hs9Iv6OaXV63qslO+crdrnioJe26nffCv8tzkU+LD16wEHWUfNdQpfEE7HGCuSoFwH2MDswMTW5OFCJLUzkifHQ7nVlRHZZIpkOeJpjukzgHHu6L79n/OPdOKHfwafqdT/1OMR3ak2dD8scah3geUJyJUy/gOMIjnxiq6Xb/jv8= 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:46 +0000 From: Brijesh Singh To: , , CC: , , Brijesh Singh Date: Mon, 22 May 2017 11:23:12 -0400 Message-ID: <1495466592-21641-15-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: ae554717-9a77-4a27-3e56-08d4a1268acc 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:EzCPoB/xTivzSpEAcEhCQ2XtvXMjvUE7+p6lJIHEqDFtA0pA1bGm/g5AlJF/UU21zR+O6zihsz6d+N24b6Ogs3+rIUbOQQo14FJ8/l6CQWmLDYV6EsUOnY7aeAfXbsLky8QvXijDV+2uucZnp/35SIGxvykdyE000KOWYSRUjmj6gA6ARl3YhpX1reOcNDvSCEtmXIEJUjOIgzOLdPLjEsmODdkDAwcPw7TdKchrdhcTJd2LkD40PkOXoR5d/NzRnQwu5xqOZUUg1v1a2Xbq2rhlS1zMDn73dDtTv1VAynYIeZj+kakwYqE9e9HouFSOY0gsvyUbdkKIuwDoXWcBLgDdJEwQxW3QaMmI7bkq1L4=; 25:e2Ch9RhGE0IBiufVzbX2FZkTVRN+W6oTcd0gitzfQA26VbmGJ3BLM5ococuXYBXFE/5MdmOQcmC4GTttzMjKmwAtSjFX/a8rjquz9hbiGnvM2g8C0uqwSH5+jtNemiuLGNCB19A05bJQzUQfIQQYkptG5pHIviDd0H76J1qomOx/YFnL2Q20DjtJs6HSuW2o4GxSBQHsUD1Rq3FpaBzLWQL9eGywVT1vRTvw4EbR+PQDsII09ZSbeSsBk899dzri5Fsc4S/E9rNmhMhnp8dSOPpj5fedL13otErHF9V4LExjruebP9Dun3QwKo7SqEcN3N1wS5WpnMHtwtOGoRPtE4rw384lJd0Nxx5YdnEiDYREJxh909YeynZXJSD/XQZJYrYdl5EgVyWATtOxZ4VQmn13W3MMuSHUM1QqmznwvcxjCQDw/+3n6w00kDiW+zYm5szUtlm4QPrZFoOX7/jTbuIiX37kDWQdy4KejU2FvzI= X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 31:Rqhj4g4pvctkx2PrKGxEBtdbr0hRLDphfUAbZltcYwJvtPDnLPRP7Rg7R/h/pgMrfeKZKi0VCKbOi+44nA9fp+gvAg35Eu7+srB8n3mi6oz96Q7NpOQGLJ3fkBaqrUWrVac+6t+si8LMaDrrsZnn3D20R53e/Xh+bxShyXZJWLtf+wHoIOu+rBJv+qjAnTPOB99yvfmG12BsTTMoZ7k8MScb5yoaJ+aYcIo52T5pK7Q=; 20:GqBU7JR0dXh9+4w2WFDWGPKHE93rO7VOoaearxUe0k0fen3CPtU0z9VDQi+NdT1wxT8RQNIsXGBkZ7FSzD0BNK3LhEX7t2NghYwua56zvTFPzjH7TMiTrYHaOQAjVgmyY2/Ag8MBkUIFADP2JdPojyjpGUW9nubqQSN2W6bPgdRJT8xSpSPeJKpL3T1s3qLeoL6/Na5YEnkvEABBcWuI+kdf+3wGzQNs/g3RKQTBJRun4JrJ+QrFI5D2xREpKDR2jSKDVf4b78Fp9beH5H9521N6CusWpN9+ytsor/xjy0x39tbI7dJ18ufdMqbrrr1odmhRorxo2W5pqxvi7RtyKkkiq8tbomAENJ5+fuXpUSwSsV8pC3YA4OK1wjnTxM0x+esH/1OI0zFuYNw5KkOnbgKbgu4ZtaVWnetWZcx4i319Y2E8SWC/cA8NolhHRzwt89iXOG9JLHsi1hAKdIk1WKS79XPBTLwHZF572hKmFUxe+2nNPBsYSzgmK6FApxIV 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:/pgh504/3wuzCfO7UquK4GIir861D1iDaHfs1EebDfb/c1S4atXG8RSqXyKegk6cj+CBF2TLhxHU/b2UdUak1QSIFsU7628Dw/B2sELMmT7N9W7z3mF2Td3vyYWPNz9nthHkn3nTIT+T7dg9OXkCsOa0U9j5hrsF49x3D1T4cWO9bVCCdGhRSMe6nMXK2g7WZyVe6sGrkOHz0W/3ojHHH4ywQqPFiLHws2p8N7QF/UqOk4r5d9mXRpY5yas01Z8bgcv3PCx9G+pKuhS7Eceh6oslnKqO2qvW9qOoU19DVxwC1BFDbnanWRtLw24HOH2gdwpI2XHUZ5lib7gyPu6lXynXyFtWJRsgyn4XIZPyW6WjN64JbUBawW/azWv//2MrGYdV/pw4MJk91o8I93/rsy8DO++/kEGGKaECuXtdAqD5vfm6oIjeCRZywAqPV1WwZ84ABXMNvSJU2zF5/F7gG+2rXaXoVO46fLFTfVT/Qt/3IpE9Q7dgnAoE6PWehj/HiENv4eWYL8bTB8mhjQ2RYHeyK0QO0qkcFlRtPOzOKg/38cTj8beR2inqpUmmZaiopAPwxHFGTwd1Q/bM3ednb8UUecQ5Bt1hKGHmBrYvPBELVaGPogd7IJiQpEQQVZCQugPgIMyfuyhaCGNiSSomdrv5pAY64CEohlA3C9tPzytI2EkTcRf0Wk9ilYg1Zkb7FBQ29L0G4iFiZ9H2DOFIgtMqhzVtl+Rw9rX3mO3FzYu2jeTcfHeMqAcrYzjyHjnJZ+XjJbpK6g1UuBPi/sqNPHyVzD3ylXNshBJYuBdunPevsHsc7CNWX1rBsYsyTtHa0LWHYYA04RFSwBlgMYnel++QjYotSwNITR9T2ulz6ygeZt+X3pdwYsuORrZFSAaA X-Forefront-PRVS: 03152A99FF X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(39840400002)(39860400002)(39850400002)(39450400003)(39410400002)(39400400002)(6486002)(5003940100001)(54906002)(6666003)(2950100002)(36756003)(53416004)(42186005)(86362001)(47776003)(2201001)(66066001)(2906002)(5660300001)(305945005)(7736002)(50226002)(38730400002)(3846002)(6116002)(189998001)(8676002)(76176999)(81166006)(53936002)(50986999)(33646002)(4326008)(478600001)(48376002)(50466002)(25786009); 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:2eU0SpYpWSMD0FI2BpHQ/QNvzrsgyCPOe0I53fH3B?= =?us-ascii?Q?u043jZiPNufw3j8/UfaplmFi1rBxeiGrgTWZ0oQ2B2+1akV1+B0NMMBORJnQ?= =?us-ascii?Q?KxcV+r+yPpfwzePQXNDDa9ddO4zpTCvPEfjUDIdry1cl+Gut4M9DIdYXo4b6?= =?us-ascii?Q?HC36KRGGIW4XbCK39W8fgi71ukLQcnj7lAOSxdqNgo/L50Ua08HHPRC6u8+b?= =?us-ascii?Q?mtfdsT0KAp+d8illlhFqz+kOfEyQDsrP+/vgJHCaR9A8tFLyfHjIH3Qa4/OY?= =?us-ascii?Q?4x2mbSQSJMS1oZn5hnQTiVzu/0q3iqlGGIs/Q4deBf/v9mMurGlxQS2K1/xB?= =?us-ascii?Q?Vr+HbzCcda9OzA6y+S7HHxBQqOEd5/RnUvmHwY6oVg9IqItowPqRTmy3lQkQ?= =?us-ascii?Q?Wwsaj4Hh8D8XmGG2a0hueulTKD43nENLbBzw2+4LyLR7RK6TKkCoDveeNGhC?= =?us-ascii?Q?MdYhRghiVakA2adHaqKQq8ZGF51etJR0lujMc8hw4KfBlHW1hatbXAvOfdMh?= =?us-ascii?Q?sADKylG32le0okFrncDHdcCaKIaFwLGgdoRgfPS82VUeDWHBqJ4O3ABTyph9?= =?us-ascii?Q?HWcZ+e2d3bDF85okCe3lTZ4JovQMfCqW2xAcuYz5XgoHW7yiu7dlLbNqiSe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o7gMJko8MiFl8Y0CE1A=; 5:pd1XHxWblrav2eSDohh0si42Ij9EGdoxTYmSkDayJg1/pgIC149SKIipyTd2/3tnS7fFS9/3uieYiJazJ22A+WOXFmwbIkG/++KH9P1M4lNr4hPXFOGt/srMSRYVQcm662297ZpKWw8yTsFRFXUDdQ==; 24:V/TdY5zbyT9WCwO++KUNaSLjG1xSjxy2pq6Fg4B+IqMEIQek0JfFkqVJhNs+Xj+XAmP9XdBc/1mw+flsX0doYP0X+6nUngsEB0jGHgStNCk= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 7:Fq0a4vG29591fc0U4/CZ78DdWalwHteUC+bSYnCElN0o5SVge53Fsy8z7vg6yIew2kwRb1VWCkLfVayxYv9tCIYn0zBcyUhg4xGKLFvyVIcNddJjLGSxjL5aZt+VuNZYBLeAf6aJniL63klDo7hb3cGTWnb7HEi1HHDiDuN47oB/sUk1P6zVJ+hzSI7BqqT0pwpDEJRv23oGm7csAHxs7RPASh18XZggTYT8Een6Hol9HJXV0y2lB1WdJfgmU0Rg4maXrfB7AQpSk5uCER0S2gtOYSiSzkn8zCKW7eklfGc/JI9noKSPZxfFaggYe+h4WJH1Rp8kjuX5u1K6VgAFdg==; 20:OhcPDaXvqMNbZlG+WwTDwWBuv5LSR+Ia3TGHmGMiMwTd2zhtProRX+sZfjnlg/WC+ugGHJXeb5SlazkFfnWg2MFUPESwCZtQI2O5RYGKEgbut02RAq1O2tqE9Hlo2Y+x0YegOOd1k/hUoxFr2BHSUeuTDjc1XL5T6kqNcWfcN8mVP9hcuoE/gelW6nhfcCyuMCrhfWBsoAQ3rNSdp1F0oQD3jMh3Z5dzOrS2fVHSQli8TsfI0w7Eg3QEwqYAqjTP X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 May 2017 15:23:46.9302 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR12MB0155 Subject: [PATCH v5 14/14] OvmfPkg/QemuFwCfgLib: Add SEV support 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:49 -0000 Content-Type: text/plain When SEV is enabled, use a bounce buffer to perform the DMA operation. Cc: Jordan Justen Cc: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Brijesh Singh --- OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c | 54 +++++++++++++++++++- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c index 73a19772bee1..40b43ac78ff4 100644 --- a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c +++ b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c @@ -72,6 +72,8 @@ InternalQemuFwCfgDmaBytes ( volatile FW_CFG_DMA_ACCESS *Access; UINT32 AccessHigh, AccessLow; UINT32 Status; + UINT32 NumPages; + VOID *DmaBuffer, *BounceBuffer; ASSERT (Control == FW_CFG_DMA_CTL_WRITE || Control == FW_CFG_DMA_CTL_READ || Control == FW_CFG_DMA_CTL_SKIP); @@ -80,11 +82,44 @@ InternalQemuFwCfgDmaBytes ( return; } - Access = &LocalAccess; + // + // When SEV is enabled then allocate DMA bounce buffer + // + if (InternalQemuFwCfgSevIsEnabled ()) { + UINTN TotalSize; + + TotalSize = sizeof (*Access); + // + // Control operation does not need buffer + // + if (Control != FW_CFG_DMA_CTL_SKIP) { + TotalSize += Size; + } + + // + // Allocate SEV DMA buffer + // + NumPages = (UINT32)EFI_SIZE_TO_PAGES (TotalSize); + InternalQemuFwCfgSevDmaAllocateBuffer (&BounceBuffer, NumPages); + + Access = BounceBuffer; + DmaBuffer = (UINT8*)BounceBuffer + sizeof (*Access); + + // + // Decrypt data from encrypted guest buffer into DMA buffer + // + if (Control == FW_CFG_DMA_CTL_WRITE) { + CopyMem (DmaBuffer, Buffer, Size); + } + } else { + Access = &LocalAccess; + DmaBuffer = Buffer; + BounceBuffer = NULL; + } Access->Control = SwapBytes32 (Control); Access->Length = SwapBytes32 (Size); - Access->Address = SwapBytes64 ((UINTN)Buffer); + Access->Address = SwapBytes64 ((UINTN)DmaBuffer); // // Delimit the transfer from (a) modifications to Access, (b) in case of a @@ -117,6 +152,21 @@ InternalQemuFwCfgDmaBytes ( // After a read, the caller will want to use Buffer. // MemoryFence (); + + // + // If Bounce buffer was allocated then copy the data into guest buffer and + // free the bounce buffer + // + if (BounceBuffer) { + // + // Encrypt the data from DMA buffer into guest buffer + // + if (Control == FW_CFG_DMA_CTL_READ) { + CopyMem (Buffer, DmaBuffer, Size); + } + + InternalQemuFwCfgSevDmaFreeBuffer (BounceBuffer, NumPages); + } } -- 2.7.4