]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/VirtioBlkDxe: Check the return status of unmap data buffer
authorBrijesh Singh <brijesh.singh@amd.com>
Wed, 30 Aug 2017 16:28:29 +0000 (12:28 -0400)
committerLaszlo Ersek <lersek@redhat.com>
Wed, 30 Aug 2017 16:53:54 +0000 (18:53 +0200)
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>
[lersek@redhat.com: fix typos in subject]
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Tested-by: Laszlo Ersek <lersek@redhat.com>
OvmfPkg/VirtioBlkDxe/VirtioBlk.c

index 6abd937f86c6c2c677d04b2652b465d0568937e1..5a63986b3f39ffb19c57ccfcabeb7d2ce7e327b0 100644 (file)
@@ -260,6 +260,7 @@ SynchronousRequest (
   EFI_PHYSICAL_ADDRESS    HostStatusDeviceAddress;\r
   EFI_PHYSICAL_ADDRESS    RequestDeviceAddress;\r
   EFI_STATUS              Status;\r
+  EFI_STATUS              UnmapStatus;\r
 \r
   BlockSize = Dev->BlockIoMedia.BlockSize;\r
 \r
@@ -430,7 +431,13 @@ SynchronousRequest (
 \r
 UnmapDataBuffer:\r
   if (BufferSize > 0) {\r
-    Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, BufferMapping);\r
+    UnmapStatus = Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, BufferMapping);\r
+    if (EFI_ERROR (UnmapStatus) && !RequestIsWrite && !EFI_ERROR (Status)) {\r
+      //\r
+      // Data from the bus master may not reach the caller; fail the request.\r
+      //\r
+      Status = EFI_DEVICE_ERROR;\r
+    }\r
   }\r
 \r
 UnmapRequestBuffer:\r