Skip to contentSkip to conversation

hw/mem: add sp-mem device for Specific Purpose Memory

PATCH In review fanhuang 4 participants 17 messages Jun 23 – Jul 3 Arm/Amlogic Meson SoC support

lore
Share & tools
lore

fanhuang

author
#0 lore raw

v14 cover hw/mem: add sp-mem device for Specific Purpose Memory

This series adds a TYPE_MEMORY_DEVICE subclass sp-mem for boot-time SOFT_RESERVED guest memory, following the direction from the v7 thread [1] and the v8 / v9 / v10 / v11 / v12 / v13 reviews [2][3][4][5][6][7].

Background
----------

This series targets coherent CPU + accelerator shared-address-space systems, where the accelerator's HBM is not a device-private framebuffer behind a PCIe BAR but a tier of host system memory:
visible to the CPU in the platform physical address space, shared coherently with the accelerator over the platform fabric, and bound to a NUMA proximity domain set by platform firmware at boot fabric training.

For such a region to function correctly in the guest, two things must hold simultaneously: the CPU memory subsystem has to see it in the system memory map (so the CPU side can address it), and it has to be reserved exclusively for the accelerator's driver (so the kernel's general allocator does not hand SPM pages to unrelated workloads). The SOFT_RESERVED memory type in E820 plus a matching SRAT memory-affinity entry is the mechanism that delivers both: a firmware-produced topology that the CPU memory subsystem honors and the accelerator's driver consumes for its own range.

Approach
--------

The series introduces a new TYPE_MEMORY_DEVICE subclass sp-mem. Each instance binds one host memory backend to a single NUMA proximity domain and is boot-time only; placement, mapped-state enforcement, and QMP introspection come from the existing memory-device framework.

Testing
-------

Verified end-to-end on q35 + KVM, with both SeaBIOS and OVMF, for:

- single sp-mem instance
- two sp-mem instances on different NUMA nodes

Guest observations: /proc/iomem shows one SOFT_RESERVED entry per sp-mem device, dmesg SRAT parsing reports the matching memory_affinity entries with correct PXM, and the umbrella HOTPLUGGABLE entry covers the remaining hotplug-memory window without overlapping the sp-mem ranges.

In-tree coverage: a bios-tables-test case validates the SRAT partition for two sp-mem devices on distinct nodes, and an e820 fw_cfg test checks the SOFT_RESERVED range.

Changes since v13
-----------------

- qapi: note that SpMemDeviceInfo's @size is in bytes.
- pc: fix the indentation of the pc_sp_mem_plug() continuation line.
- Collected the Reviewed-by / Acked-by tags from the v13 review.

Previous versions
-----------------

v1: https://lore.kernel.org/qemu-devel/[email protected]/
v2: https://lore.kernel.org/qemu-devel/[email protected]/
v3: https://lore.kernel.org/qemu-devel/[email protected]/
v4: https://lore.kernel.org/qemu-devel/[email protected]/
v5: https://lore.kernel.org/qemu-devel/[email protected]/
v6: https://lore.kernel.org/qemu-devel/[email protected]/
v7: https://lore.kernel.org/qemu-devel/[email protected]/
v8: https://lore.kernel.org/qemu-devel/[email protected]/
v9: https://lore.kernel.org/qemu-devel/[email protected]/
v10: https://lore.kernel.org/qemu-devel/[email protected]/
v11: https://lore.kernel.org/qemu-devel/[email protected]/
v12: https://lore.kernel.org/qemu-devel/[email protected]/
v13: https://lore.kernel.org/qemu-devel/[email protected]/

[1] v7 thread closeout:

      https://lore.kernel.org/qemu-devel/[email protected]/
  [2] v8 review:
      https://lore.kernel.org/qemu-devel/20260601105057.2d764e55@imammedo/
  [3] v9 review:
      https://lore.kernel.org/qemu-devel/[email protected]/T/
  [4] v10 review:
      https://lore.kernel.org/qemu-devel/[email protected]/T/
  [5] v11 review:
      https://lore.kernel.org/qemu-devel/[email protected]/T/
  [6] v12 review:
      https://lore.kernel.org/qemu-devel/[email protected]/T/
  [7] v13 review:
      https://lore.kernel.org/qemu-devel/[email protected]/T/

fanhuang (10):
hw/mem: add sp-mem device for Specific Purpose Memory qapi, hmp: introspection for the sp-mem device i386/acpi-build: partition device_memory SRAT umbrella for sp-mem hw/i386: hook sp-mem into the pc machine plug path
MAINTAINERS: cover sp-mem under Memory devices, add R: tag tests/acpi: add empty expected blobs for sp-mem SRAT test tests/acpi: add bios-tables-test case for sp-mem tests/acpi: generate expected blobs for sp-mem SRAT test tests/qtest: add e820 fw_cfg test
tests/qtest: cover sp-mem SOFT_RESERVED e820 entry

 MAINTAINERS                        |   3 +
 qapi/machine.json                  |  43 +++++++++-
 hw/i386/e820_memory_layout.h       |  11 +--
 include/hw/mem/sp-mem.h            |  33 ++++++++
 hw/core/machine-hmp-cmds.c         |  11 +++
 hw/i386/acpi-build.c               |  96 ++++++++++++++++++++-
 hw/i386/pc.c                       |  36 ++++++++
 hw/mem/sp-mem.c                    | 128 ++++++++++++++++++++++++++++
 tests/qtest/bios-tables-test.c     |  21 +++++
 tests/qtest/e820-test.c            | 129 +++++++++++++++++++++++++++++
 hw/i386/Kconfig                    |   2 +
 hw/mem/Kconfig                     |   4 +
 hw/mem/meson.build                 |   1 +
 tests/data/acpi/x86/q35/DSDT.spmem | Bin 0 -> 9910 bytes
 tests/data/acpi/x86/q35/SRAT.spmem | Bin 0 -> 384 bytes
 tests/qtest/meson.build            |   1 +
 16 files changed, 508 insertions(+), 11 deletions(-)
 create mode 100644 include/hw/mem/sp-mem.h
 create mode 100644 hw/mem/sp-mem.c
 create mode 100644 tests/qtest/e820-test.c
 create mode 100644 tests/data/acpi/x86/q35/DSDT.spmem
 create mode 100644 tests/data/acpi/x86/q35/SRAT.spmem

base-commit: b83371668192a705b878e909c5ae9c1233cbd5fb

Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v14 1/10 hw/mem: add sp-mem device for Specific Purpose Memory

Introduce a TYPE_MEMORY_DEVICE subclass sp-mem for boot-time SOFT_RESERVED memory exposed to the guest with a per-device NUMA proximity domain.

The device targets accelerator memory (HBM and similar) that the firmware hands to the guest OS as SOFT_RESERVED memory, so a driver in the guest -- rather than the kernel's general allocator -- owns the range.

Usage:

    -object memory-backend-ram,id=spm0,size=$SIZE
    -numa node,nodeid=$N
    -device sp-mem,id=dev0,memdev=spm0,node=$N[,addr=$GPA]

The device is boot-time only (no hotplug).

---
 include/hw/mem/sp-mem.h |  33 ++++++++++++
 hw/mem/sp-mem.c         | 109 ++++++++++++++++++++++++++++++++++++++++
 hw/mem/Kconfig          |   4 ++
 hw/mem/meson.build      |   1 +
 4 files changed, 147 insertions(+)
 create mode 100644 include/hw/mem/sp-mem.h
 create mode 100644 hw/mem/sp-mem.c
include/hw/mem/sp-mem.h new file +33 -0
new file mode 100644
index 0000000000..a8951b49e6
@@ -0,0 +1,33 @@
+/*
+ * Specific Purpose Memory (SPM) device
+ *
+ * TYPE_MEMORY_DEVICE subclass for boot-time-only memory exposed to the
+ * guest as an E820 SOFT_RESERVED range with a SRAT memory-affinity entry.
+ *
+ * Copyright (c) 2026 Advanced Micro Devices, Inc.
+ *
+ * Authors:
+ *  FangSheng Huang <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef QEMU_SP_MEM_H
+#define QEMU_SP_MEM_H
+
+#include "hw/core/qdev.h"
+#include "qom/object.h"
+
+#define TYPE_SP_MEM "sp-mem"
+
+OBJECT_DECLARE_SIMPLE_TYPE(SpMemDevice, SP_MEM)
+
+struct SpMemDevice {
+    DeviceState parent_obj;
+
+    HostMemoryBackend *hostmem;
+    uint32_t node;
+    uint64_t addr;
+};
+
+#endif /* QEMU_SP_MEM_H */
hw/mem/sp-mem.c new file +109 -0

109 lines not on this page · raw message

hw/mem/Kconfig +4 -0
index 73c5ae8ad9..39ddb36710 100644
@@ -16,3 +16,7 @@ config CXL_MEM_DEVICE
     bool
     default y if CXL
     select MEM_DEVICE
+
+config SP_MEM
+    bool
+    select MEM_DEVICE
hw/mem/meson.build +1 -0
index 8c2beeb7d4..f410d75475 100644
@@ -4,6 +4,7 @@ mem_ss.add(when: 'CONFIG_DIMM', if_true: files('pc-dimm.c'))
 mem_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_mc.c'))
 mem_ss.add(when: 'CONFIG_NVDIMM', if_true: files('nvdimm.c'))
 mem_ss.add(when: 'CONFIG_CXL_MEM_DEVICE', if_true: files('cxl_type3.c'))
+mem_ss.add(when: 'CONFIG_SP_MEM', if_true: files('sp-mem.c'))
 stub_ss.add(files('cxl_type3_stubs.c'))
 
 stub_ss.add(files('memory-device-stubs.c'))
Signature · 1 line
2.34.1
Reviewed-by on v14 1/10
#2 lore raw
Quoted 11 lines · fanhuang

Introduce a TYPE_MEMORY_DEVICE subclass sp-mem for boot-time SOFT_RESERVED memory exposed to the guest with a per-device NUMA proximity domain.

The device targets accelerator memory (HBM and similar) that the firmware hands to the guest OS as SOFT_RESERVED memory, so a driver in the guest -- rather than the kernel's general allocator -- owns the range.

Usage:

Quoted 8 lines
    -object memory-backend-ram,id=spm0,size=$SIZE
    -numa node,nodeid=$N
    -device sp-mem,id=dev0,memdev=spm0,node=$N[,addr=$GPA]

The device is boot-time only (no hotplug).

Signature · 3 lines
Cheers,

David
author
#3 lore raw

PATCH v14 2/10 qapi, hmp: introspection for the sp-mem device

In reply to fanhuang

Add a SpMemDeviceInfo variant to MemoryDeviceInfo so query-memory-devices reports each sp-mem instance (id, addr, size, node, memdev), and print it from HMP info memory-devices.

---
 qapi/machine.json          | 43 ++++++++++++++++++++++++++++++++++++--
 hw/core/machine-hmp-cmds.c | 11 ++++++++++
 hw/mem/sp-mem.c            | 19 +++++++++++++++++
 3 files changed, 71 insertions(+), 2 deletions(-)
qapi/machine.json +41 -2
index 685e4e29b8..9b2248038f 100644
@@ -1413,6 +1413,32 @@
           }
 }
 
+##
+# @SpMemDeviceInfo:
+#
+# sp-mem device state information
+#
+# @id: device's ID
+#
+# @addr: physical address, where device is mapped
+#
+# @size: size of memory that the device provides, in bytes
+#
+# @node: NUMA proximity domain to which the device is assigned
+#
+# @memdev: memory backend linked with device
+#
+# Since: 11.1
+##
+{ 'struct': 'SpMemDeviceInfo',
+  'data': { '*id': 'str',
+            'addr': 'size',
+            'size': 'size',
+            'node': 'int',
+            'memdev': 'str'
+          }
+}
+
 ##
 # @MemoryDeviceInfoKind:
 #
@@ -1426,11 +1452,13 @@
 #
 # @hv-balloon: since 8.2.
 #
+# @sp-mem: since 11.1.
+#
 # Since: 2.1
 ##
 { 'enum': 'MemoryDeviceInfoKind',
   'data': [ 'dimm', 'nvdimm', 'virtio-pmem', 'virtio-mem', 'sgx-epc',
-            'hv-balloon' ] }
+            'hv-balloon', 'sp-mem' ] }
 
 ##
 # @PCDIMMDeviceInfoWrapper:
@@ -1482,6 +1510,16 @@
 { 'struct': 'HvBalloonDeviceInfoWrapper',
   'data': { 'data': 'HvBalloonDeviceInfo' } }
 
+##
+# @SpMemDeviceInfoWrapper:
+#
+# @data: sp-mem device state information
+#
+# Since: 11.1
+##
+{ 'struct': 'SpMemDeviceInfoWrapper',
+  'data': { 'data': 'SpMemDeviceInfo' } }
+
 ##
 # @MemoryDeviceInfo:
 #
@@ -1499,7 +1537,8 @@
             'virtio-pmem': 'VirtioPMEMDeviceInfoWrapper',
             'virtio-mem': 'VirtioMEMDeviceInfoWrapper',
             'sgx-epc': 'SgxEPCDeviceInfoWrapper',
-            'hv-balloon': 'HvBalloonDeviceInfoWrapper'
+            'hv-balloon': 'HvBalloonDeviceInfoWrapper',
+            'sp-mem': 'SpMemDeviceInfoWrapper'
           }
 }
 
hw/core/machine-hmp-cmds.c +11 -0
index 46846f741a..686304bafa 100644
@@ -279,6 +279,7 @@ void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
     PCDIMMDeviceInfo *di;
     SgxEPCDeviceInfo *se;
     HvBalloonDeviceInfo *hi;
+    SpMemDeviceInfo *spmi;
 
     for (info = info_list; info; info = info->next) {
         value = info->value;
@@ -350,6 +351,16 @@ void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
                     monitor_printf(mon, "  memdev: %s\n", hi->memdev);
                 }
                 break;
+            case MEMORY_DEVICE_INFO_KIND_SP_MEM:
+                spmi = value->u.sp_mem.data;
+                monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
+                               MemoryDeviceInfoKind_str(value->type),
+                               spmi->id ? spmi->id : "");
+                monitor_printf(mon, "  addr: 0x%" PRIx64 "\n", spmi->addr);
+                monitor_printf(mon, "  node: %" PRId64 "\n", spmi->node);
+                monitor_printf(mon, "  size: %" PRIu64 "\n", spmi->size);
+                monitor_printf(mon, "  memdev: %s\n", spmi->memdev);
+                break;
             default:
                 g_assert_not_reached();
             }
hw/mem/sp-mem.c +19 -0
index d088222f54..962d0f937e 100644
@@ -53,6 +53,24 @@ static MemoryRegion *sp_mem_get_memory_region(MemoryDeviceState *md,
     return host_memory_backend_get_memory(spm->hostmem);
 }
 
+static void sp_mem_fill_device_info(const MemoryDeviceState *md,
+                                    MemoryDeviceInfo *info)
+{
+    SpMemDeviceInfo *di = g_new0(SpMemDeviceInfo, 1);
+    SpMemDevice *spm = SP_MEM(md);
+    DeviceState *dev = DEVICE(md);
+
+    di->id = dev->id ? g_strdup(dev->id) : NULL;
+    di->addr = spm->addr;
+    di->size = memory_region_size(
+                   host_memory_backend_get_memory(spm->hostmem));
+    di->node = spm->node;
+    di->memdev = object_get_canonical_path(OBJECT(spm->hostmem));
+
+    info->u.sp_mem.data = di;
+    info->type = MEMORY_DEVICE_INFO_KIND_SP_MEM;
+}
+
 static void sp_mem_realize(DeviceState *dev, Error **errp)
 {
     SpMemDevice *spm = SP_MEM(dev);
@@ -91,6 +109,7 @@ static void sp_mem_class_init(ObjectClass *oc, const void *data)
     mdc->set_addr            = sp_mem_set_addr;
     mdc->get_memory_region   = sp_mem_get_memory_region;
     mdc->get_plugged_size    = memory_device_get_region_size;
+    mdc->fill_device_info    = sp_mem_fill_device_info;
 }
 
 static const TypeInfo sp_mem_types[] = {
Signature · 1 line
2.34.1
Reviewed-by on v14 2/10
#4 lore raw

Re: [PATCH v14 02/10] qapi, hmp: introspection for the sp-mem device

Quoted 7 lines · fanhuang

Add a SpMemDeviceInfo variant to MemoryDeviceInfo so query-memory-devices reports each sp-mem instance (id, addr, size, node, memdev), and print it from HMP info memory-devices.

---

Signature · 3 lines
Cheers,

David
author
#5 lore raw

PATCH v14 3/10 i386/acpi-build: partition device_memory SRAT umbrella for sp-mem

In reply to fanhuang

Restructure the device_memory SRAT umbrella entry into a per-kind
partition: each TYPE_SP_MEM device gets an ENABLED entry at its own proximity_domain; the remaining sub-ranges get HOTPLUGGABLE | ENABLED placeholders at the highest PXM, preserving the existing umbrella convention.

---
 hw/i386/acpi-build.c | 96 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 92 insertions(+), 4 deletions(-)
hw/i386/acpi-build.c +92 -4
index 2ee061558c..8837b69687 100644
@@ -52,6 +52,7 @@
 #include "migration/vmstate.h"
 #include "hw/mem/memory-device.h"
 #include "hw/mem/nvdimm.h"
+#include "hw/mem/sp-mem.h"
 #include "system/numa.h"
 #include "system/reset.h"
 #include "hw/hyperv/vmbus-bridge.h"
@@ -1351,6 +1352,96 @@ build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog,
 }
 #endif
 
+typedef struct {
+    uint64_t addr;
+    uint64_t size;
+    uint32_t node;
+} SpMemRange;
+
+static int sp_mem_collect_ranges_cb(Object *obj, void *opaque)
+{
+    GArray *ranges = opaque;
+    SpMemDevice *spm;
+    MemoryDeviceClass *mdc;
+    SpMemRange r;
+
+    if (!object_dynamic_cast(obj, TYPE_SP_MEM)) {
+        return 0;
+    }
+    spm = SP_MEM(obj);
+    mdc = MEMORY_DEVICE_GET_CLASS(MEMORY_DEVICE(spm));
+    r.addr = mdc->get_addr(MEMORY_DEVICE(spm));
+    r.size = memory_region_size(
+                 host_memory_backend_get_memory(spm->hostmem));
+    r.node = spm->node;
+    g_array_append_val(ranges, r);
+    return 0;
+}
+
+static gint sp_mem_range_compare(gconstpointer a, gconstpointer b)
+{
+    const SpMemRange *range_a = a;
+    const SpMemRange *range_b = b;
+
+    if (range_a->addr < range_b->addr) {
+        return -1;
+    }
+    if (range_a->addr > range_b->addr) {
+        return 1;
+    }
+    return 0;
+}
+
+/*
+ * Emit SRAT memory-affinity entries covering the device_memory region.
+ *
+ * For each plugged TYPE_SP_MEM device, emit an ENABLED entry at the
+ * device's own proximity_domain.  All remaining sub-ranges (gaps
+ * between sp-mem devices, leading and trailing padding, and ranges
+ * occupied by other memory devices) are covered by HOTPLUGGABLE |
+ * ENABLED placeholder entries at PXM = nb_numa_nodes - 1.
+ */
+static void build_srat_device_memory(GArray *table_data, MachineState *ms)
+{
+    g_autoptr(GArray) ranges = g_array_new(FALSE, TRUE, sizeof(SpMemRange));
+    uint32_t hotplug_pxm = ms->numa_state->num_nodes - 1;
+    uint64_t region_start, region_end;
+    guint i;
+
+    region_start = ms->device_memory->base;
+    region_end = region_start + memory_region_size(&ms->device_memory->mr);
+
+    object_child_foreach_recursive(qdev_get_machine(),
+                                   sp_mem_collect_ranges_cb, ranges);
+    g_array_sort(ranges, sp_mem_range_compare);
+
+    for (i = 0; i < ranges->len; i++) {
+        SpMemRange *r = &g_array_index(ranges, SpMemRange, i);
+
+        if (region_start < r->addr) {
+            build_srat_memory(table_data, region_start, r->addr - region_start,
+                              hotplug_pxm,
+                              MEM_AFFINITY_HOTPLUGGABLE |
+                              MEM_AFFINITY_ENABLED);
+        }
+        build_srat_memory(table_data, r->addr, r->size, r->node,
+                          MEM_AFFINITY_ENABLED);
+        region_start = r->addr + r->size;
+    }
+
+    /*
+     * Cover the rest of the device_memory window that no sp-mem device
+     * occupies. Keeping it HOTPLUGGABLE preserves the umbrella entry's
+     * role for future pc-dimm / virtio-mem hot-add into this window.
+     */
+    if (region_start < region_end) {
+        build_srat_memory(table_data, region_start, region_end - region_start,
+                          hotplug_pxm,
+                          MEM_AFFINITY_HOTPLUGGABLE |
+                          MEM_AFFINITY_ENABLED);
+    }
+}
+
 #define HOLE_640K_START  (640 * KiB)
 #define HOLE_640K_END   (1 * MiB)
 
@@ -1487,10 +1578,7 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine)
      * providing _PXM method if necessary.
      */
     if (machine->device_memory) {
-        build_srat_memory(table_data, machine->device_memory->base,
-                          memory_region_size(&machine->device_memory->mr),
-                          nb_numa_nodes - 1,
-                          MEM_AFFINITY_HOTPLUGGABLE | MEM_AFFINITY_ENABLED);
+        build_srat_device_memory(table_data, machine);
     }
 
     acpi_table_end(linker, &table);
Signature · 1 line
2.34.1
author
#6 lore raw

PATCH v14 4/10 hw/i386: hook sp-mem into the pc machine plug path

In reply to fanhuang

Add the pc machine hookup for TYPE_SP_MEM so each sp-mem instance is placed by the memory-device framework and reported to the guest as E820_SOFT_RESERVED.

---
 hw/i386/e820_memory_layout.h | 11 ++++++-----
 hw/i386/pc.c                 | 36 ++++++++++++++++++++++++++++++++++++
 hw/i386/Kconfig              |  2 ++
 3 files changed, 44 insertions(+), 5 deletions(-)
hw/i386/e820_memory_layout.h +6 -5
index b50acfa201..6ef169db9c 100644
@@ -10,11 +10,12 @@
 #define HW_I386_E820_MEMORY_LAYOUT_H
 
 /* e820 types */
-#define E820_RAM        1
-#define E820_RESERVED   2
-#define E820_ACPI       3
-#define E820_NVS        4
-#define E820_UNUSABLE   5
+#define E820_RAM           1
+#define E820_RESERVED      2
+#define E820_ACPI          3
+#define E820_NVS           4
+#define E820_UNUSABLE      5
+#define E820_SOFT_RESERVED 0xefffffff
 
 struct e820_entry {
     uint64_t address;
hw/i386/pc.c +36 -0
index 73a625327c..2bacece249 100644
@@ -63,6 +63,7 @@
 #include "hw/i386/kvm/xen_gnttab.h"
 #include "hw/i386/kvm/xen_xenstore.h"
 #include "hw/mem/memory-device.h"
+#include "hw/mem/sp-mem.h"
 #include "e820_memory_layout.h"
 #include "trace.h"
 #include "sev.h"
@@ -1285,11 +1286,43 @@ static void pc_hv_balloon_plug(HotplugHandler *hotplug_dev,
     memory_device_plug(MEMORY_DEVICE(dev), MACHINE(hotplug_dev));
 }
 
+static void pc_sp_mem_pre_plug(HotplugHandler *hotplug_dev,
+                               DeviceState *dev, Error **errp)
+{
+    MachineState *ms = MACHINE(hotplug_dev);
+    SpMemDevice *spm = SP_MEM(dev);
+
+    if (ms->numa_state && spm->node >= ms->numa_state->num_nodes) {
+        error_setg(errp,
+                   "'node' property value %" PRIu32
+                   " exceeds the number of NUMA nodes (%d)",
+                   spm->node, ms->numa_state->num_nodes);
+        return;
+    }
+    memory_device_pre_plug(MEMORY_DEVICE(dev), ms, errp);
+}
+
+static void pc_sp_mem_plug(HotplugHandler *hotplug_dev,
+                           DeviceState *dev, Error **errp)
+{
+    SpMemDevice *spm = SP_MEM(dev);
+    MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(MEMORY_DEVICE(dev));
+    uint64_t addr, size;
+
+    memory_device_plug(MEMORY_DEVICE(dev), MACHINE(hotplug_dev));
+
+    addr = mdc->get_addr(MEMORY_DEVICE(dev));
+    size = memory_region_size(host_memory_backend_get_memory(spm->hostmem));
+    e820_add_entry(addr, size, E820_SOFT_RESERVED);
+}
+
 static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev,
                                           DeviceState *dev, Error **errp)
 {
     if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
         pc_memory_pre_plug(hotplug_dev, dev, errp);
+    } else if (object_dynamic_cast(OBJECT(dev), TYPE_SP_MEM)) {
+        pc_sp_mem_pre_plug(hotplug_dev, dev, errp);
     } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
         x86_cpu_pre_plug(hotplug_dev, dev, errp);
     } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_PCI)) {
@@ -1326,6 +1359,8 @@ static void pc_machine_device_plug_cb(HotplugHandler *hotplug_dev,
 {
     if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
         pc_memory_plug(hotplug_dev, dev, errp);
+    } else if (object_dynamic_cast(OBJECT(dev), TYPE_SP_MEM)) {
+        pc_sp_mem_plug(hotplug_dev, dev, errp);
     } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
         x86_cpu_plug(hotplug_dev, dev, errp);
     } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_PCI)) {
@@ -1370,6 +1405,7 @@ static HotplugHandler *pc_get_hotplug_handler(MachineState *machine,
                                              DeviceState *dev)
 {
     if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM) ||
+        object_dynamic_cast(OBJECT(dev), TYPE_SP_MEM) ||
         object_dynamic_cast(OBJECT(dev), TYPE_CPU) ||
         object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_PCI) ||
         object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI) ||
hw/i386/Kconfig +2 -0
index 12473acaa7..e27d8816e5 100644
@@ -84,6 +84,7 @@ config I440FX
     select PCI_I440FX
     select PIIX
     select DIMM
+    select SP_MEM
     select SMBIOS
     select SMBIOS_LEGACY
     select FW_CFG_DMA
@@ -113,6 +114,7 @@ config Q35
     select LPC_ICH9
     select AHCI_ICH9
     select DIMM
+    select SP_MEM
     select SMBIOS
     select FW_CFG_DMA
 
Signature · 1 line
2.34.1
Reviewed-by on v14 4/10
#7 lore raw

Re: [PATCH v14 04/10] hw/i386: hook sp-mem into the pc machine plug path

Quoted 7 lines · fanhuang

Add the pc machine hookup for TYPE_SP_MEM so each sp-mem instance is placed by the memory-device framework and reported to the guest as E820_SOFT_RESERVED.

---

Signature · 3 lines
Cheers,

David
author
#8 lore raw

PATCH v14 5/10 MAINTAINERS: cover sp-mem under Memory devices, add R: tag

In reply to fanhuang
---
 MAINTAINERS | 3 +++
 1 file changed, 3 insertions(+)
MAINTAINERS +3 -0
index 93df53d87f..08f0d11a74 100644
@@ -3364,13 +3364,16 @@ F: scripts/coccinelle/memory-region-housekeeping.cocci
 Memory devices
 M: David Hildenbrand <[email protected]>
 M: Igor Mammedov <[email protected]>
+R: FangSheng Huang <[email protected]>
 S: Supported
 F: hw/mem/memory-device*.c
 F: hw/mem/nvdimm.c
 F: hw/mem/pc-dimm.c
+F: hw/mem/sp-mem.c
 F: include/hw/mem/memory-device.h
 F: include/hw/mem/nvdimm.h
 F: include/hw/mem/pc-dimm.h
+F: include/hw/mem/sp-mem.h
 F: docs/nvdimm.txt
 
 SPICE
Signature · 1 line
2.34.1
author
#9 lore raw

PATCH v14 6/10 tests/acpi: add empty expected blobs for sp-mem SRAT test

In reply to fanhuang

Add empty SRAT.spmem and DSDT.spmem stubs and list them in bios-tables-test-allowed-diff.h.

---
 tests/qtest/bios-tables-test-allowed-diff.h | 2 ++
 tests/data/acpi/x86/q35/DSDT.spmem          | 0
 tests/data/acpi/x86/q35/SRAT.spmem          | 0
 3 files changed, 2 insertions(+)
 create mode 100644 tests/data/acpi/x86/q35/DSDT.spmem
 create mode 100644 tests/data/acpi/x86/q35/SRAT.spmem
tests/qtest/bios-tables-test-allowed-diff.h +2 -0
index dfb8523c8b..188003fa90 100644
@@ -1 +1,3 @@
 /* List of comma-separated changed AML files to ignore */
+"tests/data/acpi/x86/q35/DSDT.spmem",
+"tests/data/acpi/x86/q35/SRAT.spmem",
tests/data/acpi/x86/q35/DSDT.spmem new file +0 -0
new file mode 100644
index 0000000000..e69de29bb2
tests/data/acpi/x86/q35/SRAT.spmem new file +0 -0
new file mode 100644
index 0000000000..e69de29bb2
Signature · 1 line
2.34.1
author
#10 lore raw

PATCH v14 7/10 tests/acpi: add bios-tables-test case for sp-mem

In reply to fanhuang

Add a q35 bios-tables-test case that boots two sp-mem devices on distinct NUMA nodes within the device_memory window, exercising the per-kind SRAT partition (per-device ENABLED entries plus HOTPLUGGABLE placeholders for the remaining sub-ranges).

---
 tests/qtest/bios-tables-test.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
tests/qtest/bios-tables-test.c +21 -0
index af6d9b5136..45abd8bd8c 100644
@@ -1416,6 +1416,26 @@ static void test_acpi_q35_tcg_numamem(void)
     free_test_data(&data);
 }
 
+static void test_acpi_q35_tcg_sp_mem(void)
+{
+    test_data data = {};
+
+    data.machine = MACHINE_Q35;
+    data.arch    = "x86",
+    data.variant = ".spmem";
+    test_acpi_one(" -m 128M,slots=4,maxmem=1G"
+                  " -object memory-backend-ram,id=ram0,size=128M"
+                  " -numa node,nodeid=0,memdev=ram0"
+                  " -numa node,nodeid=1"
+                  " -numa node,nodeid=2"
+                  " -object memory-backend-ram,id=spm0,size=128M"
+                  " -object memory-backend-ram,id=spm1,size=128M"
+                  " -device sp-mem,id=sp0,memdev=spm0,node=1"
+                  " -device sp-mem,id=sp1,memdev=spm1,node=2",
+                  &data);
+    free_test_data(&data);
+}
+
 static void test_acpi_q35_kvm_xapic(void)
 {
     test_data data = {};
@@ -2807,6 +2827,7 @@ int main(int argc, char *argv[])
             if (strcmp(arch, "i386")) {
                 qtest_add_func("acpi/q35/memhp", test_acpi_q35_tcg_memhp);
                 qtest_add_func("acpi/q35/dimmpxm", test_acpi_q35_tcg_dimm_pxm);
+                qtest_add_func("acpi/q35/sp-mem", test_acpi_q35_tcg_sp_mem);
                 qtest_add_func("acpi/q35/acpihmat",
                                test_acpi_q35_tcg_acpi_hmat);
                 qtest_add_func("acpi/q35/mmio64", test_acpi_q35_tcg_mmio64);
Signature · 1 line
2.34.1
author
#11 lore raw

PATCH v14 8/10 tests/acpi: generate expected blobs for sp-mem SRAT test

In reply to fanhuang

Populate the expected ACPI blobs for the sp-mem test and clear the allowed-diff list.

SRAT memory-affinity entries for the device_memory window (q35, -m 128M,maxmem=1G, sp0 on node 1 and sp1 on node 2, each 128M):

  Proximity Domain : 1  Base : 0x100000000  Length : 0x08000000  (Enabled)
  Proximity Domain : 2  Base : 0x108000000  Length : 0x08000000  (Enabled)
  Proximity Domain : 2  Base : 0x110000000  Length : 0x128000000 (Hot Pluggable)

Each sp-mem device gets an ENABLED entry at its own proximity domain; the remaining device_memory window is covered by a HOTPLUGGABLE placeholder at the highest proximity domain.

(DSDT.spmem differs from the base only by the memory-hotplug AML enabled by -m,maxmem.)

---
 tests/qtest/bios-tables-test-allowed-diff.h |   2 --
 tests/data/acpi/x86/q35/DSDT.spmem          | Bin 0 -> 9910 bytes
 tests/data/acpi/x86/q35/SRAT.spmem          | Bin 0 -> 384 bytes
 3 files changed, 2 deletions(-)
tests/qtest/bios-tables-test-allowed-diff.h +0 -2
index 188003fa90..dfb8523c8b 100644
@@ -1,3 +1 @@
 /* List of comma-separated changed AML files to ignore */
-"tests/data/acpi/x86/q35/DSDT.spmem",
-"tests/data/acpi/x86/q35/SRAT.spmem",
tests/data/acpi/x86/q35/DSDT.spmem binary +0 -0
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..7e6f850e7a25aaa3cb7abc0ff2aeab4ca7fdb716 100644
GIT binary patch
tests/data/acpi/x86/q35/SRAT.spmem binary +0 -0
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..9ecd266eda68d035f72f170cb1346b97da623c28 100644
GIT binary patch
Signature · 1 line
2.34.1
author
#12 lore raw

PATCH v14 9/10 tests/qtest: add e820 fw_cfg test

In reply to fanhuang

Add a qtest that reads the "etc/e820" fw_cfg table and checks its structural invariants: the file is a whole number of e820 entries and every entry has a non-zero length. The baseline q35 case asserts the guest sees RAM and, with no sp-mem device, no SOFT_RESERVED range.

---
 tests/qtest/e820-test.c | 95 +++++++++++++++++++++++++++++++++++++++++
 tests/qtest/meson.build |  1 +
 2 files changed, 96 insertions(+)
 create mode 100644 tests/qtest/e820-test.c
tests/qtest/e820-test.c new file +95 -0
new file mode 100644
index 0000000000..1db0744c08
@@ -0,0 +1,95 @@
+/*
+ * qtest e820 fw_cfg test case
+ *
+ * Validate the "etc/e820" fw_cfg table that QEMU hands to the firmware.
+ *
+ * Copyright (c) 2026 Advanced Micro Devices, Inc.
+ *
+ * Authors:
+ *  FangSheng Huang <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+
+#include "libqtest.h"
+#include "libqos/fw_cfg.h"
+#include "qemu/bswap.h"
+
+/* e820 entry layout and types (cf. hw/i386/e820_memory_layout.h) */
+#define E820_RAM            1
+#define E820_SOFT_RESERVED  0xefffffff
+
+struct e820_entry {
+    uint64_t address;
+    uint64_t length;
+    uint32_t type;
+} QEMU_PACKED;
+
+#define E820_MAX_ENTRIES    128
+
+/*
+ * Read and structurally validate "etc/e820": the file is a packed array
+ * of struct e820_entry, so its size must be a whole multiple of the entry
+ * size and every entry must have a non-zero length. Returns the entry
+ * count and fills @table.
+ */
+static size_t get_e820_table(QFWCFG *fw_cfg, struct e820_entry *table)
+{
+    size_t filesize, n, i;
+
+    filesize = qfw_cfg_get_file(fw_cfg, "etc/e820", table,
+                                E820_MAX_ENTRIES * sizeof(*table));
+    g_assert_cmpint(filesize, >, 0);
+    g_assert_cmpint(filesize % sizeof(struct e820_entry), ==, 0);
+
+    n = filesize / sizeof(struct e820_entry);
+    g_assert_cmpint(n, <=, E820_MAX_ENTRIES);
+
+    for (i = 0; i < n; i++) {
+        g_assert_cmpint(le64_to_cpu(table[i].length), >, 0);
+    }
+
+    return n;
+}
+
+static void test_e820_basic(void)
+{
+    struct e820_entry table[E820_MAX_ENTRIES];
+    QFWCFG *fw_cfg;
+    QTestState *s;
+    size_t n, i;
+    bool found_ram = false, found_soft_reserved = false;
+
+    s = qtest_init("-machine q35 -m 256M");
+    fw_cfg = pc_fw_cfg_init(s);
+
+    n = get_e820_table(fw_cfg, table);
+    for (i = 0; i < n; i++) {
+        switch (le32_to_cpu(table[i].type)) {
+        case E820_RAM:
+            found_ram = true;
+            break;
+        case E820_SOFT_RESERVED:
+            found_soft_reserved = true;
+            break;
+        }
+    }
+
+    /* baseline: RAM present, no SOFT_RESERVED range */
+    g_assert_true(found_ram);
+    g_assert_false(found_soft_reserved);
+
+    pc_fw_cfg_uninit(fw_cfg);
+    qtest_quit(s);
+}
+
+int main(int argc, char **argv)
+{
+    g_test_init(&argc, &argv, NULL);
+
+    qtest_add_func("e820/basic", test_e820_basic);
+
+    return g_test_run();
+}
tests/qtest/meson.build +1 -0
index 4897325d84..d69ee27fa4 100644
@@ -58,6 +58,7 @@ qtests_i386 = \
   (config_all_devices.has_key('CONFIG_AHCI_ICH9') ? ['tco-test'] : []) +                    \
   (config_all_devices.has_key('CONFIG_FDC_ISA') ? ['fdc-test'] : []) +                      \
   (config_all_devices.has_key('CONFIG_I440FX') ? ['fw_cfg-test'] : []) +                    \
+  (config_all_devices.has_key('CONFIG_Q35') ? ['e820-test'] : []) +                          \
   (config_all_devices.has_key('CONFIG_FW_CFG_DMA') ? ['vmcoreinfo-test'] : []) +            \
   (config_all_devices.has_key('CONFIG_I440FX') ? ['i440fx-test'] : []) +                    \
   (config_all_devices.has_key('CONFIG_I440FX') ? ['ide-test'] : []) +                       \
Signature · 1 line
2.34.1
author
#13 lore raw

PATCH v14 10/10 tests/qtest: cover sp-mem SOFT_RESERVED e820 entry

In reply to fanhuang

Boot one sp-mem device and assert the guest's e820 table gains exactly one E820_SOFT_RESERVED range whose length matches the device's backend size.

---
 tests/qtest/e820-test.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
tests/qtest/e820-test.c +34 -0
index 1db0744c08..aafa3c1aa2 100644
@@ -16,6 +16,7 @@
 #include "libqtest.h"
 #include "libqos/fw_cfg.h"
 #include "qemu/bswap.h"
+#include "qemu/units.h"
 
 /* e820 entry layout and types (cf. hw/i386/e820_memory_layout.h) */
 #define E820_RAM            1
@@ -85,11 +86,44 @@ static void test_e820_basic(void)
     qtest_quit(s);
 }
 
+static void test_e820_sp_mem(void)
+{
+    struct e820_entry table[E820_MAX_ENTRIES];
+    QFWCFG *fw_cfg;
+    QTestState *s;
+    size_t n, i;
+    int soft_reserved = 0;
+    uint64_t soft_reserved_len = 0;
+
+    s = qtest_init("-machine q35 -m 256M,slots=2,maxmem=2G "
+                   "-object memory-backend-ram,id=ram0,size=256M "
+                   "-numa node,nodeid=0,memdev=ram0 "
+                   "-object memory-backend-ram,id=spm0,size=128M "
+                   "-device sp-mem,id=sp0,memdev=spm0,node=0");
+    fw_cfg = pc_fw_cfg_init(s);
+
+    n = get_e820_table(fw_cfg, table);
+    for (i = 0; i < n; i++) {
+        if (le32_to_cpu(table[i].type) == E820_SOFT_RESERVED) {
+            soft_reserved++;
+            soft_reserved_len = le64_to_cpu(table[i].length);
+        }
+    }
+
+    /* exactly one SOFT_RESERVED range, sized to the backend */
+    g_assert_cmpint(soft_reserved, ==, 1);
+    g_assert_cmpint(soft_reserved_len, ==, 128 * MiB);
+
+    pc_fw_cfg_uninit(fw_cfg);
+    qtest_quit(s);
+}
+
 int main(int argc, char **argv)
 {
     g_test_init(&argc, &argv, NULL);
 
     qtest_add_func("e820/basic", test_e820_basic);
+    qtest_add_func("e820/sp-mem", test_e820_sp_mem);
 
     return g_test_run();
 }
Signature · 1 line
2.34.1
#14 lore raw
In reply to fanhuang
Quoted 4 lines · On Tue, 23 Jun 2026 15:50:41 +0800 fanhuang <[email protected]> wrote:

This series adds a TYPE_MEMORY_DEVICE subclass sp-mem for boot-time SOFT_RESERVED guest memory, following the direction from the v7 thread [1] and the v8 / v9 / v10 / v11 / v12 / v13 reviews [2][3][4][5][6][7].

review is done at this point,
I guess Michael will take it via his tree.

Quoted 125 lines

Background
----------

This series targets coherent CPU + accelerator shared-address-space systems, where the accelerator's HBM is not a device-private framebuffer behind a PCIe BAR but a tier of host system memory:
visible to the CPU in the platform physical address space, shared coherently with the accelerator over the platform fabric, and bound to a NUMA proximity domain set by platform firmware at boot fabric training.

For such a region to function correctly in the guest, two things must hold simultaneously: the CPU memory subsystem has to see it in the system memory map (so the CPU side can address it), and it has to be reserved exclusively for the accelerator's driver (so the kernel's general allocator does not hand SPM pages to unrelated workloads). The SOFT_RESERVED memory type in E820 plus a matching SRAT memory-affinity entry is the mechanism that delivers both: a firmware-produced topology that the CPU memory subsystem honors and the accelerator's driver consumes for its own range.

Approach
--------

The series introduces a new TYPE_MEMORY_DEVICE subclass sp-mem. Each instance binds one host memory backend to a single NUMA proximity domain and is boot-time only; placement, mapped-state enforcement, and QMP introspection come from the existing memory-device framework.

Testing
-------

Verified end-to-end on q35 + KVM, with both SeaBIOS and OVMF, for:

- single sp-mem instance
- two sp-mem instances on different NUMA nodes

Guest observations: /proc/iomem shows one SOFT_RESERVED entry per sp-mem device, dmesg SRAT parsing reports the matching memory_affinity entries with correct PXM, and the umbrella HOTPLUGGABLE entry covers the remaining hotplug-memory window without overlapping the sp-mem ranges.

In-tree coverage: a bios-tables-test case validates the SRAT partition for two sp-mem devices on distinct nodes, and an e820 fw_cfg test checks the SOFT_RESERVED range.

Changes since v13
-----------------

- qapi: note that SpMemDeviceInfo's @size is in bytes.
- pc: fix the indentation of the pc_sp_mem_plug() continuation line.
- Collected the Reviewed-by / Acked-by tags from the v13 review.

Previous versions
-----------------

v1: https://lore.kernel.org/qemu-devel/[email protected]/
v2: https://lore.kernel.org/qemu-devel/[email protected]/
v3: https://lore.kernel.org/qemu-devel/[email protected]/
v4: https://lore.kernel.org/qemu-devel/[email protected]/
v5: https://lore.kernel.org/qemu-devel/[email protected]/
v6: https://lore.kernel.org/qemu-devel/[email protected]/
v7: https://lore.kernel.org/qemu-devel/[email protected]/
v8: https://lore.kernel.org/qemu-devel/[email protected]/
v9: https://lore.kernel.org/qemu-devel/[email protected]/
v10: https://lore.kernel.org/qemu-devel/[email protected]/
v11: https://lore.kernel.org/qemu-devel/[email protected]/
v12: https://lore.kernel.org/qemu-devel/[email protected]/
v13: https://lore.kernel.org/qemu-devel/[email protected]/

[1] v7 thread closeout:

      https://lore.kernel.org/qemu-devel/[email protected]/
  [2] v8 review:
      https://lore.kernel.org/qemu-devel/20260601105057.2d764e55@imammedo/
  [3] v9 review:
      https://lore.kernel.org/qemu-devel/[email protected]/T/
  [4] v10 review:
      https://lore.kernel.org/qemu-devel/[email protected]/T/
  [5] v11 review:
      https://lore.kernel.org/qemu-devel/[email protected]/T/
  [6] v12 review:
      https://lore.kernel.org/qemu-devel/[email protected]/T/
  [7] v13 review:
      https://lore.kernel.org/qemu-devel/[email protected]/T/

fanhuang (10):
hw/mem: add sp-mem device for Specific Purpose Memory qapi, hmp: introspection for the sp-mem device i386/acpi-build: partition device_memory SRAT umbrella for sp-mem hw/i386: hook sp-mem into the pc machine plug path
MAINTAINERS: cover sp-mem under Memory devices, add R: tag tests/acpi: add empty expected blobs for sp-mem SRAT test tests/acpi: add bios-tables-test case for sp-mem tests/acpi: generate expected blobs for sp-mem SRAT test tests/qtest: add e820 fw_cfg test
tests/qtest: cover sp-mem SOFT_RESERVED e820 entry

 MAINTAINERS                        |   3 +
 qapi/machine.json                  |  43 +++++++++-
 hw/i386/e820_memory_layout.h       |  11 +--
 include/hw/mem/sp-mem.h            |  33 ++++++++
 hw/core/machine-hmp-cmds.c         |  11 +++
 hw/i386/acpi-build.c               |  96 ++++++++++++++++++++-
 hw/i386/pc.c                       |  36 ++++++++
 hw/mem/sp-mem.c                    | 128 ++++++++++++++++++++++++++++
 tests/qtest/bios-tables-test.c     |  21 +++++
 tests/qtest/e820-test.c            | 129 +++++++++++++++++++++++++++++
 hw/i386/Kconfig                    |   2 +
 hw/mem/Kconfig                     |   4 +
 hw/mem/meson.build                 |   1 +
 tests/data/acpi/x86/q35/DSDT.spmem | Bin 0 -> 9910 bytes
 tests/data/acpi/x86/q35/SRAT.spmem | Bin 0 -> 384 bytes
 tests/qtest/meson.build            |   1 +
 16 files changed, 508 insertions(+), 11 deletions(-)
 create mode 100644 include/hw/mem/sp-mem.h
 create mode 100644 hw/mem/sp-mem.c
 create mode 100644 tests/qtest/e820-test.c
 create mode 100644 tests/data/acpi/x86/q35/DSDT.spmem
 create mode 100644 tests/data/acpi/x86/q35/SRAT.spmem

base-commit: b83371668192a705b878e909c5ae9c1233cbd5fb

#15 lore raw
Quoted 11 lines · Igor Mammedov
Quoted 4 lines · On Tue, 23 Jun 2026 15:50:41 +0800 fanhuang <[email protected]> wrote:

This series adds a TYPE_MEMORY_DEVICE subclass sp-mem for boot-time SOFT_RESERVED guest memory, following the direction from the v7 thread [1] and the v8 / v9 / v10 / v11 / v12 / v13 reviews [2][3][4][5][6][7].

review is done at this point,
I guess Michael will take it via his tree.

Hi Michael,

All patches now carry Reviewed-by / Acked-by. Would it be possible to queue this for the 11.1 soft freeze (7/7)?

Best regards,
FangSheng Huang (Jerry)

Quoted 126 lines
Quoted 125 lines

Background
----------

This series targets coherent CPU + accelerator shared-address-space systems, where the accelerator's HBM is not a device-private framebuffer behind a PCIe BAR but a tier of host system memory:
visible to the CPU in the platform physical address space, shared coherently with the accelerator over the platform fabric, and bound to a NUMA proximity domain set by platform firmware at boot fabric training.

For such a region to function correctly in the guest, two things must hold simultaneously: the CPU memory subsystem has to see it in the system memory map (so the CPU side can address it), and it has to be reserved exclusively for the accelerator's driver (so the kernel's general allocator does not hand SPM pages to unrelated workloads). The SOFT_RESERVED memory type in E820 plus a matching SRAT memory-affinity entry is the mechanism that delivers both: a firmware-produced topology that the CPU memory subsystem honors and the accelerator's driver consumes for its own range.

Approach
--------

The series introduces a new TYPE_MEMORY_DEVICE subclass sp-mem. Each instance binds one host memory backend to a single NUMA proximity domain and is boot-time only; placement, mapped-state enforcement, and QMP introspection come from the existing memory-device framework.

Testing
-------

Verified end-to-end on q35 + KVM, with both SeaBIOS and OVMF, for:

- single sp-mem instance
- two sp-mem instances on different NUMA nodes

Guest observations: /proc/iomem shows one SOFT_RESERVED entry per sp-mem device, dmesg SRAT parsing reports the matching memory_affinity entries with correct PXM, and the umbrella HOTPLUGGABLE entry covers the remaining hotplug-memory window without overlapping the sp-mem ranges.

In-tree coverage: a bios-tables-test case validates the SRAT partition for two sp-mem devices on distinct nodes, and an e820 fw_cfg test checks the SOFT_RESERVED range.

Changes since v13
-----------------

- qapi: note that SpMemDeviceInfo's @size is in bytes.
- pc: fix the indentation of the pc_sp_mem_plug() continuation line.
- Collected the Reviewed-by / Acked-by tags from the v13 review.

Previous versions
-----------------

   v1: https://lore.kernel.org/qemu-devel/[email protected]/
   v2: https://lore.kernel.org/qemu-devel/[email protected]/
   v3: https://lore.kernel.org/qemu-devel/[email protected]/
   v4: https://lore.kernel.org/qemu-devel/[email protected]/
   v5: https://lore.kernel.org/qemu-devel/[email protected]/
   v6: https://lore.kernel.org/qemu-devel/[email protected]/
   v7: https://lore.kernel.org/qemu-devel/[email protected]/
   v8: https://lore.kernel.org/qemu-devel/[email protected]/
   v9: https://lore.kernel.org/qemu-devel/[email protected]/
   v10: https://lore.kernel.org/qemu-devel/[email protected]/
   v11: https://lore.kernel.org/qemu-devel/[email protected]/
   v12: https://lore.kernel.org/qemu-devel/[email protected]/
   v13: https://lore.kernel.org/qemu-devel/[email protected]/

   [1] v7 thread closeout:
       https://lore.kernel.org/qemu-devel/[email protected]/
   [2] v8 review:
       https://lore.kernel.org/qemu-devel/20260601105057.2d764e55@imammedo/
   [3] v9 review:
       https://lore.kernel.org/qemu-devel/[email protected]/T/
   [4] v10 review:
       https://lore.kernel.org/qemu-devel/[email protected]/T/
   [5] v11 review:
       https://lore.kernel.org/qemu-devel/[email protected]/T/
   [6] v12 review:
       https://lore.kernel.org/qemu-devel/[email protected]/T/
   [7] v13 review:
       https://lore.kernel.org/qemu-devel/[email protected]/T/

fanhuang (10):
hw/mem: add sp-mem device for Specific Purpose Memory qapi, hmp: introspection for the sp-mem device i386/acpi-build: partition device_memory SRAT umbrella for sp-mem hw/i386: hook sp-mem into the pc machine plug path
MAINTAINERS: cover sp-mem under Memory devices, add R: tag tests/acpi: add empty expected blobs for sp-mem SRAT test tests/acpi: add bios-tables-test case for sp-mem tests/acpi: generate expected blobs for sp-mem SRAT test tests/qtest: add e820 fw_cfg test
tests/qtest: cover sp-mem SOFT_RESERVED e820 entry

  MAINTAINERS                        |   3 +
  qapi/machine.json                  |  43 +++++++++-
  hw/i386/e820_memory_layout.h       |  11 +--
  include/hw/mem/sp-mem.h            |  33 ++++++++
  hw/core/machine-hmp-cmds.c         |  11 +++
  hw/i386/acpi-build.c               |  96 ++++++++++++++++++++-
  hw/i386/pc.c                       |  36 ++++++++
  hw/mem/sp-mem.c                    | 128 ++++++++++++++++++++++++++++
  tests/qtest/bios-tables-test.c     |  21 +++++
  tests/qtest/e820-test.c            | 129 +++++++++++++++++++++++++++++
  hw/i386/Kconfig                    |   2 +
  hw/mem/Kconfig                     |   4 +
  hw/mem/meson.build                 |   1 +
  tests/data/acpi/x86/q35/DSDT.spmem | Bin 0 -> 9910 bytes
  tests/data/acpi/x86/q35/SRAT.spmem | Bin 0 -> 384 bytes
  tests/qtest/meson.build            |   1 +
  16 files changed, 508 insertions(+), 11 deletions(-)

create mode 100644 include/hw/mem/sp-mem.h create mode 100644 hw/mem/sp-mem.c
create mode 100644 tests/qtest/e820-test.c create mode 100644 tests/data/acpi/x86/q35/DSDT.spmem create mode 100644 tests/data/acpi/x86/q35/SRAT.spmem

base-commit: b83371668192a705b878e909c5ae9c1233cbd5fb

#16 lore raw
Quoted 15 lines · FangSheng (Jerry)
Quoted 11 lines · Igor Mammedov
Quoted 4 lines · On Tue, 23 Jun 2026 15:50:41 +0800 fanhuang <[email protected]> wrote:

This series adds a TYPE_MEMORY_DEVICE subclass sp-mem for boot-time SOFT_RESERVED guest memory, following the direction from the v7 thread [1] and the v8 / v9 / v10 / v11 / v12 / v13 reviews [2][3][4][5][6][7].

review is done at this point,
I guess Michael will take it via his tree.

Quoted 7 lines

Hi Michael,

All patches now carry Reviewed-by / Acked-by. Would it be possible to queue this for the 11.1 soft freeze (7/7)?

Best regards,
FangSheng Huang (Jerry)

Working on it, thanks!

Quoted 126 lines
Quoted 126 lines
Quoted 125 lines

Background
----------

This series targets coherent CPU + accelerator shared-address-space systems, where the accelerator's HBM is not a device-private framebuffer behind a PCIe BAR but a tier of host system memory:
visible to the CPU in the platform physical address space, shared coherently with the accelerator over the platform fabric, and bound to a NUMA proximity domain set by platform firmware at boot fabric training.

For such a region to function correctly in the guest, two things must hold simultaneously: the CPU memory subsystem has to see it in the system memory map (so the CPU side can address it), and it has to be reserved exclusively for the accelerator's driver (so the kernel's general allocator does not hand SPM pages to unrelated workloads). The SOFT_RESERVED memory type in E820 plus a matching SRAT memory-affinity entry is the mechanism that delivers both: a firmware-produced topology that the CPU memory subsystem honors and the accelerator's driver consumes for its own range.

Approach
--------

The series introduces a new TYPE_MEMORY_DEVICE subclass sp-mem. Each instance binds one host memory backend to a single NUMA proximity domain and is boot-time only; placement, mapped-state enforcement, and QMP introspection come from the existing memory-device framework.

Testing
-------

Verified end-to-end on q35 + KVM, with both SeaBIOS and OVMF, for:

- single sp-mem instance
- two sp-mem instances on different NUMA nodes

Guest observations: /proc/iomem shows one SOFT_RESERVED entry per sp-mem device, dmesg SRAT parsing reports the matching memory_affinity entries with correct PXM, and the umbrella HOTPLUGGABLE entry covers the remaining hotplug-memory window without overlapping the sp-mem ranges.

In-tree coverage: a bios-tables-test case validates the SRAT partition for two sp-mem devices on distinct nodes, and an e820 fw_cfg test checks the SOFT_RESERVED range.

Changes since v13
-----------------

- qapi: note that SpMemDeviceInfo's @size is in bytes.
- pc: fix the indentation of the pc_sp_mem_plug() continuation line.
- Collected the Reviewed-by / Acked-by tags from the v13 review.

Previous versions
-----------------

   v1: https://lore.kernel.org/qemu-devel/[email protected]/
   v2: https://lore.kernel.org/qemu-devel/[email protected]/
   v3: https://lore.kernel.org/qemu-devel/[email protected]/
   v4: https://lore.kernel.org/qemu-devel/[email protected]/
   v5: https://lore.kernel.org/qemu-devel/[email protected]/
   v6: https://lore.kernel.org/qemu-devel/[email protected]/
   v7: https://lore.kernel.org/qemu-devel/[email protected]/
   v8: https://lore.kernel.org/qemu-devel/[email protected]/
   v9: https://lore.kernel.org/qemu-devel/[email protected]/
   v10: https://lore.kernel.org/qemu-devel/[email protected]/
   v11: https://lore.kernel.org/qemu-devel/[email protected]/
   v12: https://lore.kernel.org/qemu-devel/[email protected]/
   v13: https://lore.kernel.org/qemu-devel/[email protected]/

   [1] v7 thread closeout:
       https://lore.kernel.org/qemu-devel/[email protected]/
   [2] v8 review:
       https://lore.kernel.org/qemu-devel/20260601105057.2d764e55@imammedo/
   [3] v9 review:
       https://lore.kernel.org/qemu-devel/[email protected]/T/
   [4] v10 review:
       https://lore.kernel.org/qemu-devel/[email protected]/T/
   [5] v11 review:
       https://lore.kernel.org/qemu-devel/[email protected]/T/
   [6] v12 review:
       https://lore.kernel.org/qemu-devel/[email protected]/T/
   [7] v13 review:
       https://lore.kernel.org/qemu-devel/[email protected]/T/

fanhuang (10):
hw/mem: add sp-mem device for Specific Purpose Memory qapi, hmp: introspection for the sp-mem device i386/acpi-build: partition device_memory SRAT umbrella for sp-mem hw/i386: hook sp-mem into the pc machine plug path
MAINTAINERS: cover sp-mem under Memory devices, add R: tag tests/acpi: add empty expected blobs for sp-mem SRAT test tests/acpi: add bios-tables-test case for sp-mem tests/acpi: generate expected blobs for sp-mem SRAT test tests/qtest: add e820 fw_cfg test
tests/qtest: cover sp-mem SOFT_RESERVED e820 entry

  MAINTAINERS                        |   3 +
  qapi/machine.json                  |  43 +++++++++-
  hw/i386/e820_memory_layout.h       |  11 +--
  include/hw/mem/sp-mem.h            |  33 ++++++++
  hw/core/machine-hmp-cmds.c         |  11 +++
  hw/i386/acpi-build.c               |  96 ++++++++++++++++++++-
  hw/i386/pc.c                       |  36 ++++++++
  hw/mem/sp-mem.c                    | 128 ++++++++++++++++++++++++++++
  tests/qtest/bios-tables-test.c     |  21 +++++
  tests/qtest/e820-test.c            | 129 +++++++++++++++++++++++++++++
  hw/i386/Kconfig                    |   2 +
  hw/mem/Kconfig                     |   4 +
  hw/mem/meson.build                 |   1 +
  tests/data/acpi/x86/q35/DSDT.spmem | Bin 0 -> 9910 bytes
  tests/data/acpi/x86/q35/SRAT.spmem | Bin 0 -> 384 bytes
  tests/qtest/meson.build            |   1 +
  16 files changed, 508 insertions(+), 11 deletions(-)

create mode 100644 include/hw/mem/sp-mem.h create mode 100644 hw/mem/sp-mem.c
create mode 100644 tests/qtest/e820-test.c create mode 100644 tests/data/acpi/x86/q35/DSDT.spmem create mode 100644 tests/data/acpi/x86/q35/SRAT.spmem

base-commit: b83371668192a705b878e909c5ae9c1233cbd5fb