]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg: VirtioScsiDxe: reset device at ExitBootServices()
authorLaszlo Ersek <lersek@redhat.com>
Fri, 16 Oct 2015 19:52:18 +0000 (19:52 +0000)
committerlersek <lersek@Edk2>
Fri, 16 Oct 2015 19:52:18 +0000 (19:52 +0000)
(1) VirtioLib allocates the virtio ring in EfiBootServicesData memory.
    (This is intentional.) Code that executes after ExitBootServices() is
    permitted to reuse such memory.

(2) The hypervisor is allowed to look at, and act upon, a live virtio ring
    at any time, even without explicit virtio kicks from the guest.

Should boot loader code or kernel code, running between ExitBootServices()
and the kernel's own virtio drivers resetting the device, overwrite the
pages that used to contain the virtio ring before ExitBootServices(), QEMU
could theoretically interpret that unrelated data as garbage ring
contents, and abort the guest.

Although we have seen no such reports, better be prudent and reset the
device in an ExitBootServices() event handler. Among other things, this
causes QEMU to forget about the device's virtio ring.

Cc: Jordan Justen <jordan.l.justen@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18623 6f19259b-4bc3-4df7-8a09-765794883524

OvmfPkg/VirtioScsiDxe/VirtioScsi.c
OvmfPkg/VirtioScsiDxe/VirtioScsi.h

index 2cb3f43bb01c25c29297f0e7027d11dcd5391b8d..e1e12039b3591b0ecfce21c63e849b89d7b8ae11 100644 (file)
@@ -933,7 +933,6 @@ Failed:
 }\r
 \r
 \r
-\r
 STATIC\r
 VOID\r
 EFIAPI\r
@@ -960,6 +959,32 @@ VirtioScsiUninit (
 }\r
 \r
 \r
+//\r
+// Event notification function enqueued by ExitBootServices().\r
+//\r
+\r
+STATIC\r
+VOID\r
+EFIAPI\r
+VirtioScsiExitBoot (\r
+  IN  EFI_EVENT Event,\r
+  IN  VOID      *Context\r
+  )\r
+{\r
+  VSCSI_DEV *Dev;\r
+\r
+  //\r
+  // Reset the device. This causes the hypervisor to forget about the virtio\r
+  // ring.\r
+  //\r
+  // We allocated said ring in EfiBootServicesData type memory, and code\r
+  // executing after ExitBootServices() is permitted to overwrite it.\r
+  //\r
+  Dev = Context;\r
+  Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0);\r
+}\r
+\r
+\r
 //\r
 // Probe, start and stop functions of this driver, called by the DXE core for\r
 // specific devices.\r
@@ -1050,6 +1075,12 @@ VirtioScsiDriverBindingStart (
     goto CloseVirtIo;\r
   }\r
 \r
+  Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_CALLBACK,\r
+                  &VirtioScsiExitBoot, Dev, &Dev->ExitBoot);\r
+  if (EFI_ERROR (Status)) {\r
+    goto UninitDev;\r
+  }\r
+\r
   //\r
   // Setup complete, attempt to export the driver instance's PassThru\r
   // interface.\r
@@ -1059,11 +1090,14 @@ VirtioScsiDriverBindingStart (
                   &gEfiExtScsiPassThruProtocolGuid, EFI_NATIVE_INTERFACE,\r
                   &Dev->PassThru);\r
   if (EFI_ERROR (Status)) {\r
-    goto UninitDev;\r
+    goto CloseExitBoot;\r
   }\r
 \r
   return EFI_SUCCESS;\r
 \r
+CloseExitBoot:\r
+  gBS->CloseEvent (Dev->ExitBoot);\r
+\r
 UninitDev:\r
   VirtioScsiUninit (Dev);\r
 \r
@@ -1114,6 +1148,8 @@ VirtioScsiDriverBindingStop (
     return Status;\r
   }\r
 \r
+  gBS->CloseEvent (Dev->ExitBoot);\r
+\r
   VirtioScsiUninit (Dev);\r
 \r
   gBS->CloseProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,\r
index 0d3181d140dcac484d6335c370bf102ceab65b3a..80840d353e585c238b63eb10c93ae6d37f73b2b8 100644 (file)
@@ -52,6 +52,7 @@ typedef struct {
   //                              ----------------   ------------------  ----------\r
   UINT32                          Signature;      // DriverBindingStart  0\r
   VIRTIO_DEVICE_PROTOCOL          *VirtIo;        // DriverBindingStart  0\r
+  EFI_EVENT                       ExitBoot;       // DriverBindingStart  0\r
   BOOLEAN                         InOutSupported; // VirtioScsiInit      1\r
   UINT16                          MaxTarget;      // VirtioScsiInit      1\r
   UINT32                          MaxLun;         // VirtioScsiInit      1\r