diff mbox series

[11/11] OvmfPkg/XenBusDxe: Fix XenStoreWaitForEvent use during EBS

Message ID 20190913145100.303433-12-anthony.perard@citrix.com (mailing list archive)
State New, archived
Headers show
Series OvmfPkg/XenBusDxe: Fix ExitBootServices handler to avoid allocation | expand

Commit Message

Anthony PERARD Sept. 13, 2019, 2:51 p.m. UTC
XenStoreWaitForEvent is going to be called when the ExitBootServices
is signaled, but both CreateEvent and WaitForEvent can't be used.
CreateEvent allocate some memory and WaitForEvent can only be used
when TPL is TPL_APPLICATION.

When ExitBootServices has been called, simply return immediately and
let caller of XenStoreWaitForEvent do a busy loop.

Also cleanup error handling in XenStoreWaitForEvent, WaitForEvent
shouldn't return EFI_UNSUPPORTED anymore.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2190
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
 OvmfPkg/XenBusDxe/XenBusDxe.c |  2 ++
 OvmfPkg/XenBusDxe/XenBusDxe.h |  1 +
 OvmfPkg/XenBusDxe/XenStore.c  | 13 +++++++++----
 3 files changed, 12 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/OvmfPkg/XenBusDxe/XenBusDxe.c b/OvmfPkg/XenBusDxe/XenBusDxe.c
index c71966a666..eb1503ad2b 100644
--- a/OvmfPkg/XenBusDxe/XenBusDxe.c
+++ b/OvmfPkg/XenBusDxe/XenBusDxe.c
@@ -264,6 +264,8 @@  NotifyExitBoot (
 
   Dev = Context;
 
+  Dev->ExitBootNotified = TRUE;
+
   //
   // First, ask every driver using xenbus to disconnect without
   // deallocating memory.
diff --git a/OvmfPkg/XenBusDxe/XenBusDxe.h b/OvmfPkg/XenBusDxe/XenBusDxe.h
index 0e91c24338..80162fc3ff 100644
--- a/OvmfPkg/XenBusDxe/XenBusDxe.h
+++ b/OvmfPkg/XenBusDxe/XenBusDxe.h
@@ -79,6 +79,7 @@  struct _XENBUS_DEVICE {
   EFI_HANDLE                    ControllerHandle;
   XENIO_PROTOCOL                *XenIo;
   EFI_EVENT                     ExitBootEvent;
+  BOOLEAN                       ExitBootNotified;
   EFI_DEVICE_PATH_PROTOCOL      *DevicePath;
   LIST_ENTRY                    ChildList;
 
diff --git a/OvmfPkg/XenBusDxe/XenStore.c b/OvmfPkg/XenBusDxe/XenStore.c
index 4026c8a829..4f126109d4 100644
--- a/OvmfPkg/XenBusDxe/XenStore.c
+++ b/OvmfPkg/XenBusDxe/XenStore.c
@@ -401,17 +401,22 @@  XenStoreWaitForEvent (
   EFI_EVENT TimerEvent;
   EFI_EVENT WaitList[2];
 
+  //
+  // If the ExitBootServices event have been signaled, simply allow to have
+  // busy loop in the caller.
+  //
+  if (xs.Dev->ExitBootNotified) {
+    return EFI_SUCCESS;
+  }
+
   gBS->CreateEvent (EVT_TIMER, 0, NULL, NULL, &TimerEvent);
   gBS->SetTimer (TimerEvent, TimerRelative, Timeout);
 
   WaitList[0] = xs.EventChannelEvent;
   WaitList[1] = TimerEvent;
   Status = gBS->WaitForEvent (2, WaitList, &Index);
-  ASSERT (Status != EFI_INVALID_PARAMETER);
+  ASSERT_EFI_ERROR (Status);
   gBS->CloseEvent (TimerEvent);
-  if (Status == EFI_UNSUPPORTED) {
-    return EFI_SUCCESS;
-  }
   if (Index == 1) {
     return EFI_TIMEOUT;
   } else {