From: Brijesh Singh <brijesh.singh@amd.com>
To: edk2-devel@lists.01.org
Cc: Thomas.Lendacky@amd.com, lersek@redhat.com,
jordan.l.justen@intel.com, leo.duran@amd.com,
Brijesh Singh <brijesh.singh@amd.com>
Subject: [PATCH v8 15/16] OvmfPkg/QemuFwCfgLib: Add SEV support
Date: Thu, 6 Jul 2017 10:29:53 -0400 [thread overview]
Message-ID: <1499351394-1175-16-git-send-email-brijesh.singh@amd.com> (raw)
In-Reply-To: <1499351394-1175-1-git-send-email-brijesh.singh@amd.com>
When SEV is enabled, use a bounce buffer to perform the DMA operation.
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
---
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
next prev parent reply other threads:[~2017-07-06 14:28 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-06 14:29 [PATCH v8 00/16] x86: Secure Encrypted Virtualization (AMD) Brijesh Singh
2017-07-06 14:29 ` [PATCH v8 01/16] OvmfPkg/ResetVector: Set C-bit when building initial page table Brijesh Singh
2017-07-06 14:29 ` [PATCH v8 02/16] OvmfPkg: Update dsc to use IoLib from BaseIoLibIntrinsicSev.inf Brijesh Singh
2017-07-06 14:29 ` [PATCH v8 03/16] OvmfPkg/BaseMemcryptSevLib: Add SEV helper library Brijesh Singh
2017-07-06 14:29 ` [PATCH v8 04/16] OvmfPkg/PlatformPei: Set memory encryption PCD when SEV is enabled Brijesh Singh
2017-07-06 14:29 ` [PATCH v8 05/16] OvmfPkg: Add AmdSevDxe driver Brijesh Singh
2017-07-06 14:29 ` [PATCH v8 06/16] OvmfPkg: Introduce IoMmuAbsent Protocol GUID Brijesh Singh
2017-07-06 14:29 ` [PATCH v8 07/16] OvmfPkg: Add PlatformHasIoMmuLib Brijesh Singh
2017-07-06 14:29 ` [PATCH v8 08/16] OvmfPkg: Add IoMmuDxe driver Brijesh Singh
2017-07-06 14:29 ` [PATCH v8 09/16] OvmfPkg/QemuFwCfgLib: Provide Pei and Dxe specific library Brijesh Singh
2017-07-06 14:29 ` [PATCH v8 10/16] OvmfPkg/QemuFwCfgLib: Prepare for SEV support Brijesh Singh
2017-07-06 14:29 ` [PATCH v8 11/16] OvmfPkg/QemuFwCfgLib: Implement SEV internal function for SEC phase Brijesh Singh
2017-07-06 14:29 ` [PATCH v8 12/16] OvmfPkg/QemuFwCfgLib: Implement SEV internal functions for PEI phase Brijesh Singh
2017-07-06 14:29 ` [PATCH v8 13/16] OvmfPkg/QemuFwCfgLib: Implement SEV internal function for Dxe phase Brijesh Singh
2017-07-06 14:29 ` [PATCH v8 14/16] OvmfPkg/QemuFwCfgLib: Add option to dynamic alloc FW_CFG_DMA Access Brijesh Singh
2017-07-06 14:29 ` Brijesh Singh [this message]
2017-07-06 14:29 ` [PATCH v8 16/16] OvmfPkg: update PciHostBridgeDxe to use PlatformHasIoMmuLib Brijesh Singh
2017-07-11 8:34 ` [PATCH v8 00/16] x86: Secure Encrypted Virtualization (AMD) Jordan Justen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1499351394-1175-16-git-send-email-brijesh.singh@amd.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox