From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Subject: [PULL 14/32] hw/arm: add static NVDIMMs in device tree
Date: Thu, 28 Aug 2025 12:34:11 +0100 [thread overview]
Message-ID: <20250828113430.3214314-15-peter.maydell@linaro.org> (raw)
In-Reply-To: <20250828113430.3214314-1-peter.maydell@linaro.org>
From: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
NVDIMM is used for fast rootfs with EROFS, for example by kata
containers. To allow booting with static NVDIMM memory, add them to the
device tree in arm virt machine.
This allows users to boot directly with nvdimm memory devices without
having to rely on ACPI and hotplug.
Verified to work with command invocation:
./qemu-system-aarch64 \
-M virt,nvdimm=on \
-cpu cortex-a57 \
-m 4G,slots=2,maxmem=8G \
-object memory-backend-file,id=mem1,share=on,mem-path=/tmp/nvdimm,size=4G,readonly=off \
-device nvdimm,id=nvdimm1,memdev=mem1,unarmed=off \
-drive file=./debian-12-nocloud-arm64-commited.qcow2,format=qcow2 \
-kernel ./vmlinuz-6.1.0-13-arm64 \
-append "root=/dev/vda1 console=ttyAMA0,115200 acpi=off"
-initrd ./initrd.img-6.1.0-13-arm64 \
-nographic \
-serial mon:stdio
Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Message-id: 20250807-nvdimm_arm64_virt-v2-1-b8054578bea8@linaro.org
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/arm/boot.c | 42 ++++++++++++++++++++++++++++++++++++++++++
hw/arm/virt.c | 8 +++++---
2 files changed, 47 insertions(+), 3 deletions(-)
diff --git a/hw/arm/boot.c b/hw/arm/boot.c
index d391cd01bb1..1e57c4ab9ee 100644
--- a/hw/arm/boot.c
+++ b/hw/arm/boot.c
@@ -25,6 +25,7 @@
#include "hw/boards.h"
#include "system/reset.h"
#include "hw/loader.h"
+#include "hw/mem/memory-device.h"
#include "elf.h"
#include "system/device_tree.h"
#include "qemu/config-file.h"
@@ -515,6 +516,29 @@ static void fdt_add_psci_node(void *fdt, ARMCPU *armcpu)
qemu_fdt_setprop_cell(fdt, "/psci", "migrate", migrate_fn);
}
+static int fdt_add_pmem_node(void *fdt, uint32_t acells, uint32_t scells,
+ int64_t mem_base, int64_t size, int64_t node)
+{
+ int ret;
+
+ g_autofree char *nodename = g_strdup_printf("/pmem@%" PRIx64, mem_base);
+
+ qemu_fdt_add_subnode(fdt, nodename);
+ qemu_fdt_setprop_string(fdt, nodename, "compatible", "pmem-region");
+ ret = qemu_fdt_setprop_sized_cells(fdt, nodename, "reg", acells,
+ mem_base, scells, size);
+ if (ret) {
+ return ret;
+ }
+
+ if (node >= 0) {
+ return qemu_fdt_setprop_cell(fdt, nodename, "numa-node-id",
+ node);
+ }
+
+ return 0;
+}
+
int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo,
hwaddr addr_limit, AddressSpace *as, MachineState *ms,
ARMCPU *cpu)
@@ -525,6 +549,7 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo,
unsigned int i;
hwaddr mem_base, mem_len;
char **node_path;
+ g_autofree MemoryDeviceInfoList *md_list = NULL;
Error *err = NULL;
if (binfo->dtb_filename) {
@@ -628,6 +653,23 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo,
}
}
+ md_list = qmp_memory_device_list();
+ for (MemoryDeviceInfoList *m = md_list; m != NULL; m = m->next) {
+ MemoryDeviceInfo *mi = m->value;
+
+ if (mi->type == MEMORY_DEVICE_INFO_KIND_NVDIMM) {
+ PCDIMMDeviceInfo *di = mi->u.nvdimm.data;
+
+ rc = fdt_add_pmem_node(fdt, acells, scells,
+ di->addr, di->size, di->node);
+ if (rc < 0) {
+ fprintf(stderr, "couldn't add NVDIMM /pmem@%"PRIx64" node\n",
+ di->addr);
+ goto fail;
+ }
+ }
+ }
+
rc = fdt_path_offset(fdt, "/chosen");
if (rc < 0) {
qemu_fdt_add_subnode(fdt, "/chosen");
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 9326cfc895f..1e63f40fbec 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -2917,7 +2917,7 @@ static void virt_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
const MachineState *ms = MACHINE(hotplug_dev);
const bool is_nvdimm = object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM);
- if (!vms->acpi_dev) {
+ if (!vms->acpi_dev && !(is_nvdimm && !dev->hotplugged)) {
error_setg(errp,
"memory hotplug is not enabled: missing acpi-ged device");
return;
@@ -2949,8 +2949,10 @@ static void virt_memory_plug(HotplugHandler *hotplug_dev,
nvdimm_plug(ms->nvdimms_state);
}
- hotplug_handler_plug(HOTPLUG_HANDLER(vms->acpi_dev),
- dev, &error_abort);
+ if (vms->acpi_dev) {
+ hotplug_handler_plug(HOTPLUG_HANDLER(vms->acpi_dev),
+ dev, &error_abort);
+ }
}
static void virt_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev,
--
2.43.0
next prev parent reply other threads:[~2025-08-28 11:35 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-28 11:33 [PULL 00/32] target-arm queue Peter Maydell
2025-08-28 11:33 ` [PULL 01/32] target/arm: Clean up of register field definitions Peter Maydell
2025-08-28 11:33 ` [PULL 02/32] tests/functional/test_aarch64_device_passthrough: update image Peter Maydell
2025-08-28 11:34 ` [PULL 03/32] tests/functional/test_aarch64_rme: " Peter Maydell
2025-08-28 11:34 ` [PULL 04/32] target/arm: Implement FEAT_SCTLR2 and enable with -cpu max Peter Maydell
2025-08-28 11:34 ` [PULL 05/32] target/arm: Implement FEAT_TCR2 " Peter Maydell
2025-08-28 11:34 ` [PULL 06/32] hw/intc/arm_gicv3_kvm: preserve pending interrupts during cpr Peter Maydell
2025-08-28 11:34 ` [PULL 07/32] target/arm: Trap PMCR when MDCR_EL2.TPMCR is set Peter Maydell
2025-08-28 11:34 ` [PULL 08/32] target/arm: Add feature predicate for FEAT_CSSC Peter Maydell
2025-08-28 11:34 ` [PULL 09/32] target/arm: Implement MIN/MAX (immediate) Peter Maydell
2025-08-28 11:34 ` [PULL 10/32] target/arm: Implement MIN/MAX (register) Peter Maydell
2025-08-28 11:34 ` [PULL 11/32] target/arm: Split out gen_wrap2_i32 helper Peter Maydell
2025-08-28 11:34 ` [PULL 12/32] target/arm: Implement CTZ, CNT, ABS Peter Maydell
2025-08-28 11:34 ` [PULL 13/32] target/arm: Enable FEAT_CSSC for -cpu max Peter Maydell
2025-08-28 11:34 ` Peter Maydell [this message]
2025-08-28 11:34 ` [PULL 15/32] scripts/kernel-doc: Avoid new Perl precedence warning Peter Maydell
2025-08-28 11:34 ` [PULL 16/32] docs/sphinx/kerneldoc.py: Handle new LINENO syntax Peter Maydell
2025-08-28 11:34 ` [PULL 17/32] tests/qtest/libqtest.h: Remove stray space from doc comment Peter Maydell
2025-08-28 11:34 ` [PULL 18/32] scripts: Import Python kerneldoc from Linux kernel Peter Maydell
2025-08-28 11:34 ` [PULL 19/32] scripts/kernel-doc: strip QEMU_ from function definitions Peter Maydell
2025-08-28 11:34 ` [PULL 20/32] scripts/kernel-doc: tweak for QEMU coding standards Peter Maydell
2025-08-28 11:34 ` [PULL 21/32] scripts/kerneldoc: Switch to the Python kernel-doc script Peter Maydell
2025-08-28 11:34 ` [PULL 22/32] scripts/kernel-doc: Delete the old Perl " Peter Maydell
2025-08-28 11:34 ` [PULL 23/32] MAINTAINERS: Put kernel-doc under the "docs build machinery" section Peter Maydell
2025-08-28 11:34 ` [PULL 24/32] target/arm: Correct condition of aa64_atomics feature function Peter Maydell
2025-08-28 11:34 ` [PULL 25/32] qemu/atomic: Finish renaming atomic128-cas.h headers Peter Maydell
2025-08-28 11:34 ` [PULL 26/32] qemu/atomic: Add atomic16 primitives for xchg, fetch_and, fetch_or Peter Maydell
2025-08-28 11:34 ` [PULL 27/32] accel/tcg: Add cpu_atomic_*_mmu for 16-byte " Peter Maydell
2025-08-28 11:34 ` [PULL 28/32] tcg: Add tcg_gen_atomic_{xchg,fetch_and,fetch_or}_i128 Peter Maydell
2025-08-28 11:34 ` [PULL 29/32] target/arm: Rename isar_feature_aa64_atomics Peter Maydell
2025-08-28 21:42 ` Richard Henderson
2025-08-28 11:34 ` [PULL 30/32] target/arm: Implement FEAT_LSE128 Peter Maydell
2025-08-28 11:34 ` [PULL 31/32] target/arm: Enable FEAT_LSE128 for -cpu max Peter Maydell
2025-08-28 11:34 ` [PULL 32/32] hw/arm/stm32f205_soc: Don't leak TYPE_OR_IRQ objects Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250828113430.3214314-15-peter.maydell@linaro.org \
--to=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).