public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 1/1] OvmfPkg/VirtioBlk: Check the returns status of unmap data buffer
@ 2017-08-30 16:28 Brijesh Singh
  2017-08-30 17:41 ` Laszlo Ersek
  0 siblings, 1 reply; 2+ messages in thread
From: Brijesh Singh @ 2017-08-30 16:28 UTC (permalink / raw)
  To: edk2-devel
  Cc: Brijesh Singh, Ard Biesheuvel, Jordan Justen, Tom Lendacky,
	Laszlo Ersek

when "RequestIsWrite" is FALSE -- i.e., the CPU wants data from
the device, we map "Buffer" for VirtioOperationBusMasterWrite. In
this case, checking the return status of

Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, BufferMapping);

is must. If the unmapping fails, then "Buffer" will not contain the
actual data from the device, and we must fail the request with
EFI_DEVICE_ERROR.

Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
---
 OvmfPkg/VirtioBlkDxe/VirtioBlk.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/OvmfPkg/VirtioBlkDxe/VirtioBlk.c b/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
index 6abd937f86c6..5a63986b3f39 100644
--- a/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
+++ b/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
@@ -260,6 +260,7 @@ SynchronousRequest (
   EFI_PHYSICAL_ADDRESS    HostStatusDeviceAddress;
   EFI_PHYSICAL_ADDRESS    RequestDeviceAddress;
   EFI_STATUS              Status;
+  EFI_STATUS              UnmapStatus;
 
   BlockSize = Dev->BlockIoMedia.BlockSize;
 
@@ -430,7 +431,13 @@ SynchronousRequest (
 
 UnmapDataBuffer:
   if (BufferSize > 0) {
-    Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, BufferMapping);
+    UnmapStatus = Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, BufferMapping);
+    if (EFI_ERROR (UnmapStatus) && !RequestIsWrite && !EFI_ERROR (Status)) {
+      //
+      // Data from the bus master may not reach the caller; fail the request.
+      //
+      Status = EFI_DEVICE_ERROR;
+    }
   }
 
 UnmapRequestBuffer:
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-08-30 17:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-30 16:28 [PATCH 1/1] OvmfPkg/VirtioBlk: Check the returns status of unmap data buffer Brijesh Singh
2017-08-30 17:41 ` Laszlo Ersek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox