Package: edk2
Version: 2022.11-6+deb12u2
Severity: normal
Tags: patch/bookworm
Dear Maintainer,
When I run a QEMU image on Debian Bookworm, I observed the following
warning during early boot:
[ 0.000000] NUMA: Warning: invalid memblk node 16 [mem
0x0000000004000000-0x0000000007ffffff]
[ 0.000000] NUMA: Faking a node at [mem
0x0000000004000000-0x00000000bfffffff]
[ 0.000000] NUMA: NODE_DATA [mem 0xbfbf9f80-0xbfbfcfff]
Steps to reproduce:
# on the host:
wget
https://downloads.elxr.dev/elxr-minimal-ostree-imx-12.9.0.0-arm64.img.zst
zstd -d elxr-minimal-ostree-imx-12.9.0.0-arm64.img.zst
cp -f /usr/share/AAVMF/AAVMF_VARS.fd ./
cp -f /usr/share/AAVMF/AAVMF_CODE.fd ./
qemu-img create -f raw boot-image-qemu-single.hddimg 10G
dd if=elxr-minimal-ostree-imx-12.9.0.0-arm64.img
of=boot-image-qemu-single.hddimg conv=notrunc
qemu-system-aarch64 -m 2048 -cpu cortex-a57 -M virt -nographic \
-smp 2,sockets=2,cores=1,threads=1 \
-m 2G,slots=2,maxmem=8G \
-object memory-backend-ram,size=1024M,id=mem0 \
-object memory-backend-ram,size=1024M,id=mem1 \
-numa node,nodeid=0,cpus=0,memdev=mem0 \
-numa node,nodeid=1,cpus=1,memdev=mem1 \
-drive if=pflash,format=raw,file=AAVMF_CODE.fd \
-drive if=pflash,format=raw,file=AAVMF_VARS.fd \
-drive if=none,file=boot-image-qemu-single.hddimg,id=hd,format=raw
-device virtio-blk-device,drive=hd
# on the guest:
root@localhost:~#
root@localhost:~# dmesg | grep -w invalid
[ 0.000000] NUMA: Warning: invalid memblk node 16 [mem
0x0000000004000000-0x0000000007ffffff]
root@localhost:~#
After investigating, I found that the following upstream commit resolves
the issue:
https://salsa.debian.org/qemu-team/edk2/-/commit/e5ec3ba409b5baa9cf429cc25fdf3c8d1b8dcef0
I have backported this patch for bookworm and attached it here for your
consideration.
From f40e6e98861b15de7052e6e596be7ef0de95300d Mon Sep 17 00:00:00 2001
From: Wenlin Kang <wenlin.k...@windriver.com>
Date: Mon, 14 Apr 2025 22:58:29 -0700
Subject: [PATCH] OvmfPkg/VirtNorFlashDxe: Map flash memory as uncacheable
Backport patch to fix a memory attribute warning triggered during boot:
NUMA: Warning: invalid memblk node 16 [mem 0x0000000004000000-0x0000000007ffffff]
NUMA: Faking a node at [mem 0x0000000004000000-0x00000000bfffffff]
NUMA: NODE_DATA [mem 0xbfbf9f80-0xbfbfcfff]
Reference:
https://salsa.debian.org/qemu-team/edk2/-/commit/e5ec3ba409b5baa9cf429cc25fdf3c8d1b8dcef0
Signed-off-by: Wenlin Kang <wenlin.k...@windriver.com>
---
...lashDxe-map-flash-memory-as-uncachea.patch | 60 +++++++++++++++++++
debian/patches/series | 1 +
2 files changed, 61 insertions(+)
create mode 100644 debian/patches/0001-OvmfPkg-VirtNorFlashDxe-map-flash-memory-as-uncachea.patch
diff --git a/debian/patches/0001-OvmfPkg-VirtNorFlashDxe-map-flash-memory-as-uncachea.patch b/debian/patches/0001-OvmfPkg-VirtNorFlashDxe-map-flash-memory-as-uncachea.patch
new file mode 100644
index 0000000000..c3aedadc8d
--- /dev/null
+++ b/debian/patches/0001-OvmfPkg-VirtNorFlashDxe-map-flash-memory-as-uncachea.patch
@@ -0,0 +1,60 @@
+From e5ec3ba409b5baa9cf429cc25fdf3c8d1b8dcef0 Mon Sep 17 00:00:00 2001
+From: Gerd Hoffmann <kra...@redhat.com>
+Date: Wed, 11 Jan 2023 19:00:23 +0100
+Subject: [PATCH] OvmfPkg/VirtNorFlashDxe: map flash memory as uncacheable
+
+Switching from the ArmPlatformPkg/NorFlashDxe driver to the
+OvmfPkg/VirtNorFlashDxe driver had the side effect that flash address
+space got registered as EFI_MEMORY_WC instead of EFI_MEMORY_UC.
+
+That confuses the linux kernel's numa code, seems this makes kernel
+consider the flash being node memory. "lsmem" changes from ...
+
+ RANGE SIZE STATE REMOVABLE BLOCK
+ 0x0000000040000000-0x000000013fffffff 4G online yes 8-39
+
+... to ...
+
+ RANGE SIZE STATE REMOVABLE BLOCK
+ 0x0000000000000000-0x0000000007ffffff 128M online yes 0
+ 0x0000000040000000-0x000000013fffffff 4G online yes 8-39
+
+... and in the kernel log got new error lines:
+
+ NUMA: Warning: invalid memblk node 512 [mem 0x0000000004000000-0x0000000007ffffff]
+ NUMA: Faking a node at [mem 0x0000000004000000-0x000000013fffffff]
+
+Changing the attributes back to EFI_MEMORY_UC fixes this.
+
+Fixes: b92298af8218 ("ArmVirtPkg/ArmVirtQemu: migrate to OVMF's VirtNorFlashDxe")
+Signed-off-by: Gerd Hoffmann <kra...@redhat.com>
+Reviewed-by: Ard Biesheuvel <a...@kernel.org>
+Signed-off-by: Wenlin Kang <wenlin.k...@windriver.com>
+---
+ OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c b/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c
+index ff3121af2a..f9a41f6aab 100644
+--- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c
++++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c
+@@ -394,14 +394,14 @@ NorFlashFvbInitialize (
+ EfiGcdMemoryTypeMemoryMappedIo,
+ Instance->DeviceBaseAddress,
+ RuntimeMmioRegionSize,
+- EFI_MEMORY_WC | EFI_MEMORY_RUNTIME
++ EFI_MEMORY_UC | EFI_MEMORY_RUNTIME
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ Status = gDS->SetMemorySpaceAttributes (
+ Instance->DeviceBaseAddress,
+ RuntimeMmioRegionSize,
+- EFI_MEMORY_WC | EFI_MEMORY_RUNTIME
++ EFI_MEMORY_UC | EFI_MEMORY_RUNTIME
+ );
+ ASSERT_EFI_ERROR (Status);
+
+--
+2.42.0
+
diff --git a/debian/patches/series b/debian/patches/series
index a4e889f0fc..c8a9653de0 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -32,3 +32,4 @@ Disable-the-Shell-when-SecureBoot-is-enabled.patch
0001-MdePkg-Fix-overflow-issue-in-BasePeCoffLib.patch
0002-MdePkg-Improving-readability-of-CVE-patch-for-PeCoff.patch
MdeModulePkg-Potential-UINT32-overflow-in-S3-ResumeC.patch
+0001-OvmfPkg-VirtNorFlashDxe-map-flash-memory-as-uncachea.patch
--
2.42.0