Skip to content

Commit 0de9297

Browse files
try apply ubuntu patches
Signed-off-by: Nikita Korolev <nikita.korolev@flant.com>
1 parent 615ef90 commit 0de9297

17 files changed

+1448
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
From 9ac1704af6645da45d20fb545294e308ef9c887e Mon Sep 17 00:00:00 2001
2+
From: Mitchell Augustin <mitchell.augustin@canonical.com>
3+
Date: Thu, 13 Mar 2025 08:52:03 -0500
4+
Subject: [PATCH] OvmfPkg: Use user-specified opt/ovmf/X-PciMmio64Mb value
5+
unconditionally
6+
7+
Prior to this change, OVMF considers opt/ovmf/X-PciMmio64Mb the
8+
minimum aperture size, allowing us to force the window to be larger
9+
but not smaller than what PlatformDynamicMmioWindow calculates.
10+
11+
Adjust OVMF so that a smaller value for the aperture is honored.
12+
13+
Context:
14+
Due to an inefficiency in the way older host kernels manage
15+
pfnmaps for guest VM memory ranges [0], guests with large-BAR
16+
GPUs passed-through have a very long (multiple minutes) initialization
17+
time when the MMIO window advertised by OVMF is sufficiently sized for
18+
the passed-through BARs (i.e., the correct OVMF behavior). However, on
19+
older distro series such as Ubuntu Jammy, users have benefited from fast
20+
guest boot times when OVMF advertised an MMIO window that was too small
21+
to accommodate the full BAR, since this resulted in the long PCI initialization
22+
process being skipped (and retried later, if pci=realloc pci=nocrs were set).
23+
24+
While the root cause is being fully addressed in the upstream kernel [1],
25+
the solution relies on huge pfnmap support, which is a substantial series
26+
with many ABI changes that is unlikely to land in many LTS and legacy distro kernels,
27+
including those of Ubuntu Noble. As a result, the only kernel improvement
28+
supported on those kernels is this patch [2], which reduces the extra boot
29+
time by about half. Unfortunately, that boot time is still an average of
30+
1-3 minutes longer per-VM-boot than what can be achieved when the host is
31+
running a version of OVMF without PlatformDynamicMmioWindow (PDMW) support
32+
(introduced in [3])
33+
34+
Since there is no way to force the use of the classic MMIO window size[4]
35+
in any version of OVMF after [3], and since we have a use case for such
36+
functionality on legacy distro kernels that would yield significant,
37+
recurring compute time savings across all impacted VMs, this change to
38+
this knob's behavior seems appropriate.
39+
40+
[0]: https://lore.kernel.org/all/CAHTA-uYp07FgM6T1OZQKqAdSA5JrZo0ReNEyZgQZub4mDRrV5w@mail.gmail.com/
41+
[1]: https://lore.kernel.org/all/20250205231728.2527186-1-alex.williamson@redhat.com/
42+
[2]: https://lore.kernel.org/all/20250111210652.402845-1-alex.williamson@redhat.com/
43+
[3]: ecb778d
44+
[4]: https://edk2.groups.io/g/devel/topic/109651206?p=Created,,,20,1,0,0
45+
46+
Signed-off-by: Mitchell Augustin <mitchell.augustin@canonical.com>
47+
48+
Bug-Ubuntu: https://launchpad.net/bugs/2101903
49+
Last-Update: 2025-03-15
50+
51+
52+
diff --git a/OvmfPkg/Include/Library/PlatformInitLib.h b/OvmfPkg/Include/Library/PlatformInitLib.h
53+
index 57b18b94d9..ce5af42e09 100644
54+
--- a/OvmfPkg/Include/Library/PlatformInitLib.h
55+
+++ b/OvmfPkg/Include/Library/PlatformInitLib.h
56+
@@ -37,6 +37,7 @@ typedef struct {
57+
58+
UINT64 PcdPciMmio64Base;
59+
UINT64 PcdPciMmio64Size;
60+
+ BOOLEAN PcdPciMmio64Override;
61+
UINT32 PcdPciMmio32Base;
62+
UINT32 PcdPciMmio32Size;
63+
UINT64 PcdPciIoBase;
64+
diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c b/OvmfPkg/Library/PlatformInitLib/MemDetect.c
65+
index 1f987f2efd..44b2e0d24f 100644
66+
--- a/OvmfPkg/Library/PlatformInitLib/MemDetect.c
67+
+++ b/OvmfPkg/Library/PlatformInitLib/MemDetect.c
68+
@@ -556,7 +556,8 @@ PlatformGetFirstNonAddress (
69+
break;
70+
case EFI_SUCCESS:
71+
if (FwCfgPciMmio64Mb <= 0x1000000) {
72+
- PlatformInfoHob->PcdPciMmio64Size = LShiftU64 (FwCfgPciMmio64Mb, 20);
73+
+ PlatformInfoHob->PcdPciMmio64Size = LShiftU64 (FwCfgPciMmio64Mb, 20);
74+
+ PlatformInfoHob->PcdPciMmio64Override = TRUE;
75+
break;
76+
}
77+
78+
@@ -795,8 +796,10 @@ PlatformDynamicMmioWindow (
79+
AddrSpace = LShiftU64 (1, PlatformInfoHob->PhysMemAddressWidth);
80+
MmioSpace = LShiftU64 (1, PlatformInfoHob->PhysMemAddressWidth - 3);
81+
82+
- if ((PlatformInfoHob->PcdPciMmio64Size < MmioSpace) &&
83+
- (PlatformInfoHob->PcdPciMmio64Base + MmioSpace < AddrSpace))
84+
+ if (PlatformInfoHob->PcdPciMmio64Override) {
85+
+ DEBUG ((DEBUG_INFO, "%a: using fwcfg override for mmio window\n", __func__));
86+
+ } else if ((PlatformInfoHob->PcdPciMmio64Size < MmioSpace) &&
87+
+ (PlatformInfoHob->PcdPciMmio64Base + MmioSpace < AddrSpace))
88+
{
89+
DEBUG ((DEBUG_INFO, "%a: using dynamic mmio window\n", __func__));
90+
DEBUG ((DEBUG_INFO, "%a: Addr Space 0x%Lx (%Ld GB)\n", __func__, AddrSpace, RShiftU64 (AddrSpace, 30)));
91+
--
92+
2.47.2
93+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
Description: ArmVirtPkg: Disable the EFI memory attributes protocol
2+
Temporarily disable the EFI_MEMORY_ATTRIBUTE_PROTOCOL to workaround
3+
a bug in shim until distributions have had a chance to fix it.
4+
Author: dann frazier <dannf@debian.org>
5+
Bug-Debian: https://bugs.debian.org/1042438
6+
Bug-Ubuntu: https://launchpad.net/bugs/2036604
7+
Last-Update: 2025-03-01
8+
9+
--- a/ArmPkg/Drivers/CpuDxe/CpuDxe.c
10+
+++ b/ArmPkg/Drivers/CpuDxe/CpuDxe.c
11+
@@ -429,8 +429,6 @@
12+
&CpuHandle,
13+
&gEfiCpuArchProtocolGuid,
14+
&mCpu,
15+
- &gEfiMemoryAttributeProtocolGuid,
16+
- &mMemoryAttribute,
17+
NULL
18+
);
19+
if (EFI_ERROR (Status)) {
20+
--- a/ArmPkg/Drivers/CpuDxe/CpuDxe.h
21+
+++ b/ArmPkg/Drivers/CpuDxe/CpuDxe.h
22+
@@ -30,12 +30,9 @@
23+
#include <Protocol/Cpu.h>
24+
#include <Protocol/DebugSupport.h>
25+
#include <Protocol/LoadedImage.h>
26+
-#include <Protocol/MemoryAttribute.h>
27+
28+
extern BOOLEAN mIsFlushingGCD;
29+
30+
-extern EFI_MEMORY_ATTRIBUTE_PROTOCOL mMemoryAttribute;
31+
-
32+
/**
33+
This function registers and enables the handler specified by InterruptHandler for a processor
34+
interrupt or exception type specified by InterruptType. If InterruptHandler is NULL, then the
35+
--- a/ArmPkg/Drivers/CpuDxe/CpuDxe.inf
36+
+++ b/ArmPkg/Drivers/CpuDxe/CpuDxe.inf
37+
@@ -23,7 +23,6 @@
38+
CpuDxe.h
39+
CpuMmuCommon.c
40+
Exception.c
41+
- MemoryAttribute.c
42+
43+
[Sources.ARM]
44+
Arm/Mmu.c
45+
@@ -55,7 +54,6 @@
46+
47+
[Protocols]
48+
gEfiCpuArchProtocolGuid
49+
- gEfiMemoryAttributeProtocolGuid
50+
gHardwareInterruptProtocolGuid
51+
52+
[Guids]
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
From: Gerd Hoffmann <kraxel@redhat.com>
2+
Date: Thu, 16 Jan 2025 17:20:38 +0100
3+
Subject: [PATCH] OvmfPkg/X64: add opt/org.tianocore/UninstallMemAttrProtocol
4+
support
5+
6+
Add support for opt/org.tianocore/UninstallMemAttrProtocol, to allow
7+
turning off EFI_MEMORY_ATTRIBUTE_PROTOCOL, simliar to ArmVirtPkg.
8+
9+
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
10+
11+
Origin: https://github.com/tianocore/edk2/pull/10667/commits/aa7f29a9e92b9e6f8b2e56bacaef6c96b8dc80ed
12+
Bug-Debian: https://bugs.debian.org/1099500
13+
Bug-Ubuntu: https://launchpad.net/bugs/2104316
14+
Last-Updated: 2025-03-28
15+
---
16+
.../Library/PlatformBootManagerLib/BdsPlatform.c | 63 ++++++++++++++++++++++
17+
.../PlatformBootManagerLib.inf | 2 +
18+
2 files changed, 65 insertions(+)
19+
20+
diff --git a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
21+
index e666938..f4ae8dc 100644
22+
--- a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
23+
+++ b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
24+
@@ -1836,6 +1836,49 @@ SaveS3BootScript (
25+
ASSERT_EFI_ERROR (Status);
26+
}
27+
28+
+/**
29+
+ Uninstall the EFI memory attribute protocol if it exists.
30+
+**/
31+
+STATIC
32+
+VOID
33+
+UninstallEfiMemoryAttributesProtocol (
34+
+ VOID
35+
+ )
36+
+{
37+
+ EFI_STATUS Status;
38+
+ EFI_HANDLE Handle;
39+
+ UINTN Size;
40+
+ VOID *MemoryAttributeProtocol;
41+
+
42+
+ Size = sizeof (Handle);
43+
+ Status = gBS->LocateHandle (
44+
+ ByProtocol,
45+
+ &gEfiMemoryAttributeProtocolGuid,
46+
+ NULL,
47+
+ &Size,
48+
+ &Handle
49+
+ );
50+
+
51+
+ if (EFI_ERROR (Status)) {
52+
+ ASSERT (Status == EFI_NOT_FOUND);
53+
+ return;
54+
+ }
55+
+
56+
+ Status = gBS->HandleProtocol (
57+
+ Handle,
58+
+ &gEfiMemoryAttributeProtocolGuid,
59+
+ &MemoryAttributeProtocol
60+
+ );
61+
+ ASSERT_EFI_ERROR (Status);
62+
+
63+
+ Status = gBS->UninstallProtocolInterface (
64+
+ Handle,
65+
+ &gEfiMemoryAttributeProtocolGuid,
66+
+ MemoryAttributeProtocol
67+
+ );
68+
+ ASSERT_EFI_ERROR (Status);
69+
+}
70+
+
71+
/**
72+
Do the platform specific action after the console is ready
73+
74+
@@ -1856,6 +1899,7 @@ PlatformBootManagerAfterConsole (
75+
)
76+
{
77+
EFI_BOOT_MODE BootMode;
78+
+ BOOLEAN Uninstall;
79+
80+
DEBUG ((DEBUG_INFO, "PlatformBootManagerAfterConsole\n"));
81+
82+
@@ -1900,6 +1944,25 @@ PlatformBootManagerAfterConsole (
83+
//
84+
StoreQemuBootOrder ();
85+
86+
+ //
87+
+ // Work around shim's terminally broken use of the EFI memory attributes
88+
+ // protocol, by uninstalling it if requested on the QEMU command line.
89+
+ //
90+
+ // E.g.,
91+
+ // -fw_cfg opt/org.tianocore/UninstallMemAttrProtocol,string=y
92+
+ //
93+
+ Uninstall = FixedPcdGetBool (PcdUninstallMemAttrProtocol);
94+
+ QemuFwCfgParseBool ("opt/org.tianocore/UninstallMemAttrProtocol", &Uninstall);
95+
+ DEBUG ((
96+
+ DEBUG_WARN,
97+
+ "%a: %auninstalling EFI memory protocol\n",
98+
+ __func__,
99+
+ Uninstall ? "" : "not "
100+
+ ));
101+
+ if (Uninstall) {
102+
+ UninstallEfiMemoryAttributesProtocol ();
103+
+ }
104+
+
105+
//
106+
// Process QEMU's -kernel command line option
107+
//
108+
diff --git a/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf b/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
109+
index 1a422eb..73190a3 100644
110+
--- a/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
111+
+++ b/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
112+
@@ -63,6 +63,7 @@
113+
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashVariablesEnable
114+
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId
115+
gUefiOvmfPkgTokenSpaceGuid.PcdBootRestrictToFirmware
116+
+ gUefiOvmfPkgTokenSpaceGuid.PcdUninstallMemAttrProtocol
117+
gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiS3Enable
118+
gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut
119+
gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate ## CONSUMES
120+
@@ -81,6 +82,7 @@
121+
gEfiDxeSmmReadyToLockProtocolGuid # PROTOCOL SOMETIMES_PRODUCED
122+
gEfiLoadedImageProtocolGuid # PROTOCOL SOMETIMES_PRODUCED
123+
gEfiFirmwareVolume2ProtocolGuid # PROTOCOL SOMETIMES_CONSUMED
124+
+ gEfiMemoryAttributeProtocolGuid
125+
126+
[Guids]
127+
gEfiEndOfDxeEventGroupGuid
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Description: Revert "ArmVirtPkg: make EFI_LOADER_DATA non-executable"
2+
The versions of GRUB most distros are shipping still depend on executable
3+
EFI_LOADER_DATA. Revert this upstream change until the necessary fixes are
4+
more generally available.
5+
Author: dann frazier <dannf@debian.org>
6+
Bug-Debian: https://bugs.debian.org/1025656
7+
Forwarded: https://edk2.groups.io/g/devel/message/97814
8+
Last-Update: 2023-07-21
9+
10+
--- a/ArmVirtPkg/ArmVirt.dsc.inc
11+
+++ b/ArmVirtPkg/ArmVirt.dsc.inc
12+
@@ -398,7 +398,7 @@
13+
# build command line you can allow code execution in EfiLoaderData. This is
14+
# required when using some outdated GRUB versions.
15+
#
16+
- gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPolicy|0xC000000000007FD5
17+
+ gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPolicy|0xC000000000007FD1
18+
19+
gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard|TRUE
20+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
From: Mate Kukri <mate.kukri@canonical.com>
2+
Date: Thu, 20 Mar 2025 10:49:22 +0000
3+
Subject: Revert "OvmfPkg/QemuKernelLoaderFsDxe: accept absolute paths"
4+
5+
This reverts commit 46ae4e4b9574530e5081e98af0495d6f6d28379f.
6+
---
7+
OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c | 5 -----
8+
1 file changed, 5 deletions(-)
9+
10+
diff --git a/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c b/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c
11+
index 5b90420..3e1a876 100644
12+
--- a/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c
13+
+++ b/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c
14+
@@ -806,11 +806,6 @@ QemuKernelStubFileOpen (
15+
//
16+
// Locate the file.
17+
//
18+
- if (FileName[0] == '\\') {
19+
- // also accept absolute paths, i.e. '\kernel' for 'kernel'
20+
- FileName++;
21+
- }
22+
-
23+
Blob = FindKernelBlob (FileName);
24+
25+
if (Blob == NULL) {

0 commit comments

Comments
 (0)