From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0609.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe48::609]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id D024121C8D0A8 for ; Fri, 26 May 2017 07:44:39 -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=6fm5Eb3pxypAlLhRYuYiGoKthUG8CLhkcmYjfFWNE3c=; b=39GNfbzZQsRJEOIqIkm1Y4GubYExYc6AyIEYJKUMwcd63GIwE3qgcBOELe78DESf3zLE9zQ+mz6oSP/BNY75YlEjKxuQk1ITlU6HAzCH634O9XMXeqd6QxekijGH0leddx2XBsVhT28bxr1jLtesplUXWc3gUmSXUiO9glOt+Mo= 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:38 +0000 From: Brijesh Singh To: CC: , , Brijesh Singh , Jordan Justen , Laszlo Ersek Date: Fri, 26 May 2017 10:44:04 -0400 Message-ID: <1495809845-32472-17-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: 21417e70-44e0-43a9-90e3-08d4a445bc88 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:aZhJ+/Wsy9zRHAxjAchv2pH2x9bewdyfet3P7m9wH5RAsNC6ALYCbKdtIlkkutS/fC16Yp27ibXVRKIGfld0ubTFXjUBx4R5xKfRFh1ECBzuKSUnQ2p1q0r10nu3fCnAMKTcImhqpNQK0wjpr0diO5iq2HgZuDc+KgXL1lijzZeAqYNKQe8BakfSeE3XasXI0bYsdifdFZ7wJTF40JxWLbB3Yuii1+f8zPgcw0DmA9FrEYBcTiv3q/z+dLQoKHJaQxR5bhRM57aab6XAzSIExovG2Ide9B0QExUFoVdu+C0xAH3u6x5Tt7xphUI9B4wAm3+pNS4mHhQzM91M4CHmQmgt1j6rqEvkhoHdLiEUKiA=; 25:yxsDnlmMXrm0x1mvM0GqUXTl8K0nh1Cw5JMOkD53o4y9t8Qdx4zwKM2Sxq/ImXdNryS78hkFaYl4L8zpoq1WLr3EIeIEUXg5tNYYAZXMBmvV0Dncafdz7NB+07hvCTwz1F0nRpiaUNGLc7xkPqcdLJgeMWnjPJ6fIjowigOf4Hbpl78nx84ml30MqAvX9ki4nOb5sYz1LxeWacy9wRT6+AHfxNu0otNOKuSWfFpntkcaJ9xHywoYHXPWV6rjEbQOyTKBZpEQTWK4ZbXBjY+hQMDL7Efh68lgCkzqIcUpcrV+uS9PPl9sW7xcB+GmjT76dpjiZAlnvOPp04lrLhMbxhEOpSemjZjiuTGgTC1pBbb+m1u7nO6LF8hmFI0oUwNA8VXKxM2HJu+VypXSKreOw8N6WjPUqDmWLjF0nhOljbFfAvGPmrx0mLQaXrf05PobkgInMsMs3tSqLN6k8/jrBiUj1FE5BGIGxAGvkg4xOLQ= X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 31:xYO7xAEOvKh1F7SGusaXo+HCSST62cxaSM0VNzVwr1r3UneOi3ok53/hH/QgIX+JpNsYHwbQYyKQ9EOLdQjT9BmfyZrFU7llKxosvVMfYztBkeKP+MRpofsH22KPWxB2K4jE2a3Hm798p/9IhgDmADAKVWwJh4QXmd66P9+ZtWc9QYY50LJGhSuQD/yn052JPosSR+CbwoLUqyISLfUKg41qnuaBcsGwBy8bBlXZcH8=; 20:PRpy1E/oPdzyvn6333OTKhA4m1UpGVAZenn/TfGh0VZANTe3oQnblwV8X3DNdJCNi+d/alIU9Ordt7FX6fFlAYVEh9jy/lak4gGZgmn1U5b1QXFeIQwCoPvNI/lTuZivTyyhVibOAPKPR5UW2OR/GAgn6wBrwps3RcSIRMw9/E5lWBtjA9HCur4FLIToZsAGA52YaoTQJzw9GUFTDXbu4oXui1WY5z//+cy5b+5KxvxBt8aG2Vh7Y10vs/xSEA5YYnxztTsPOxINu6m9faHERsgiMSxG/NhwHfD71DmGiupZ6RO2+zzZVJ4HG0lNjfa/KGzfQZ1zSvJ/hJthDazB06y7qdz00F1oiUvjBs9w6S+acMcM2XQdYO1aEGv6a8XUDTbxoDNXbbzPc5Yio158EV3AKPT1Q3Pv3DDOHWqtVi3MC7cgKpVLGsqhZoDRht28j6z2C9X/df7E6Zm+D7c/+lo4CuXB8ZNynHWlthA/S9XasS2fPIbUxfIjaQyV6DRo 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:GBNyaefYy6F9QXrMmx/5B1pxLFCWCNi0hd8wp7Q+UmVui6e5wT16pv8fq6naN3J2wynaNRb0K7pg5VmCxzYxqO3OZkvK4pwOPWwpHsmOPDwFBKdbzZuG8JqGpH1Y+hJeI0H0TLgLeTCD1thbcVCOVkJiS5AW5TSK04v0IVcXjc22qceJWd/sxLJ1GRX/okEovLrR5leh9C2Af3kJ5Dh12Om+BL5i0/sOhKsCTCmCpcdtQs33lEstF2SLz3QkBkLYeKkN+bFlx6BHwX9Ccj944aYeS6BG37wg6Fuiwsj6WjtyTOCoGfAQscrLBjEjnC/2nINwLmSbf6zEtKZd7V6WzLVcKneALlTUZ2gYrozLyzvM7ULZs6JShDFnPCuKbORGK71BTvR5DEUXhgOvY7nJBRrABZ6D3eacU5TBqS3gOo7Md3TphgJJ07KDnhrHzU2hQLK4IFy1DMNHM0GMbMyk8yzrAdFA3E85hsELAxF9KM0MCFlhXnNWJF/Q+lugGnJ0V4kZvVjuZmyfSm3K3quetabhXjRylsdDC2EFtXS9z5zNDW7IRut0OrmGrZJo7hUaL4UOXjOKVaTQAwxY8uUR/jG6ff8rs6vHddCpFtzl1Ue4BhQpXFE7PsToGZw2PKprmUrW0Dl3ulc4pQHeQWsu7HdvIy+DoLAvC2fISt6/wKDtJmeV4NCzsSk1RdkdZJRwDqpLj4GRtWa+KxF2hCgngyetzr9J6CPcF7Nxak2T0ZRrk6frKiZYmqa+0jNO71MHzBqLo/eMBrFOwgoC4irZZCG/WBB6rnGv9VOp/29djTusR1SJygpDbKTwrrWIXVrJzXq8Focnpmvc2D5fuR3MXaBrIiVMHrslQdpFrbLQzZZqAr7Cn3dkHpLQ0c+IqL2R 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:U39w0txfmaXBNK7jPQEJi3enFT75RoT7pBMg5izVK?= =?us-ascii?Q?tGjLr9BGj3bUvpVEcB6+K3YtKlcSCHtDQ6sxh9+FlAnYd1UOp9bWGJwQbQAM?= =?us-ascii?Q?l/CuIQ4y4zF3dLPoMZK+eXPsLut8Wa7v6xeKMM7ALgsIqqR4THOX0f93n/Uq?= =?us-ascii?Q?KCPs3SSVTJ4SjzjMYIai8wrdvcozaYUbd840c3suW5E61D2UvIfVCFU2H1a9?= =?us-ascii?Q?8+FYrHeBJ00h8iPawopSy+zqj+P7dZKUSw2EYBje0WVq9DWBq5yTjJ2+VQmE?= =?us-ascii?Q?PMEYsyq308BOu6PC5qwsd7Eo+jrPdv809vhUa/7UfIGxKy4SvycjIRE1l+cO?= =?us-ascii?Q?Nc3FZkfWOX4ur+FHYzVJcoJ5Zing+NGZYPNLyt8z66GqbNz8xPrP9ZFwBB94?= =?us-ascii?Q?mcyL5MAtczaGcvfdDWCD+Ho97AXt7xZv0R7djFel4lq7U+iWSHXymTaa5Dzv?= =?us-ascii?Q?XoRlewfEJnQE8JX4r3gdHW9vIw2XoCWilRIZTPmQIgoyqJccLXUN4YHW1dQC?= =?us-ascii?Q?6G2tc06bUtNO1k8odKJzxLD2FjW7KnbXB9vwsEVvtDrgM3AQCUqt1wQ8lKa3?= =?us-ascii?Q?ORMgAhps7nX2iIC42jTwjK/fmZ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lRx X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 May 2017 14:44:38.4074 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0158 Subject: [PATCH v6 16/17] 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: Fri, 26 May 2017 14:44:40 -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 Reviewed-by: Laszlo Ersek --- 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..dbebd36b1853 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); + // + // Skip 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 != NULL) { + // + // 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