Skip to contentSkip to conversation

Update for Tianocore/EDK2 needed for ARM

PATCH Elliott Mitchell 1 participant 1 message Jun 23

lore
Share & tools
lore
#0 lore raw

Tianocore/EDK2 is one of the prefered Xen bootloaders. On ARM it is indeed very functional. Unfortunately the change of disallowing multiple mappings of the shared information page breaks booting with Tianocore/EDK2. As the change was done on Xen I suspect they would say it is the Xen Project's job to submit a fix.

Their history suggests Julien Grall had been the liason for Tianocore/EDK2, so you're the one I'm sending this message towards.

The attached patch restores Tianocore/EDK2's ability to function as a DomU bootloader on Xen. I believe this patch though is incomplete. In particular I believe Dev->SharedInfo is a region marked as retained by firmware and not to be used by the OS. This would need to be changed to only being used until BootServices exits.

I'm not really up for polishing the patch to get it into Tianocore/EDK2. Problem is their style seems awful to me and I don't want to finish. Nonetheless this seems fairly crucial as DomU bootloaders are.

Signature · 4 lines
(\___(\___(\______          --=> 8-) EHM <=--          ______/)___/)___/)
 \BS (    |         [email protected]  PGP 87145445         |    )   /
  \_CS\   |  _____  -O #include <stddisclaimer.h> O-   _____  |   /  _/
8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445

From 225da4bd7b73d48ae54b4bacc7ffd8596ee370fa Mon Sep 17 00:00:00 2001
Message-ID: <225da4bd7b73d48ae54b4bacc7ffd8596ee370fa.1782247458.git.ehem+xen@m5p.com>
From: Elliott Mitchell <[email protected]>
Date: Wed, 4 Oct 2023 21:47:17 -0700
Subject: [PATCH] OvmfPkg/XenBusDxe: Unmap shared information page on exit

Xen/ARM now requires the shared information page to only be mapped once. This behavior is expected to be copied to Xen/x86 at some future point.

---
 OvmfPkg/XenBusDxe/XenBusDxe.c | 33 +++++++++++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)
OvmfPkg/XenBusDxe/XenBusDxe.c +31 -2
index 132f43a72b..117a299d10 100644
@@ -83,7 +83,34 @@ XenGetSharedInfoPage (
 
   return EFI_SUCCESS;
 }
-
+
+/**
+  Map the shared_info_t page into memory.
+
+  @param Dev    A XENBUS_DEVICE instance.
+**/
+VOID
+XenClearSharedInfoPage (
+  IN OUT XENBUS_DEVICE  *Dev
+  )
+{
+  xen_remove_from_physmap_t  Parameter;
+
+  //
+  // Either never mapped, or else already cleared.  No further cleanup
+  // action required.
+  //
+  if (!Dev->SharedInfo) return;
+
+  Parameter.domid = DOMID_SELF;
+  Parameter.gpfn  = (UINTN)Dev->SharedInfo >> EFI_PAGE_SHIFT;
+  if (XenHypercallMemoryOp (XENMEM_remove_from_physmap, &Parameter) != 0)
+    return;
+
+  FreePages (Dev->SharedInfo, 1);
+  Dev->SharedInfo = NULL;
+}
+
 /**
   Unloads an image.
 
@@ -500,7 +527,9 @@ XenBusDxeDriverBindingStop (
   gBS->CloseEvent (Dev->ExitBootEvent);
   XenStoreDeinit (Dev);
   XenGrantTableDeinit (Dev);
-
+
+  XenClearSharedInfoPage(Dev);
+
   gBS->CloseProtocol (
          ControllerHandle,
          &gEfiDevicePathProtocolGuid,
Signature · 1 line
2.47.3