hw/mem: add spm-memory device for Specific Purpose Memory
v9 cover hw/mem: add spm-memory device for Specific Purpose Memory
This series adds a TYPE_MEMORY_DEVICE subclass spm-memory for boot-time SOFT_RESERVED guest memory, following the direction from the v7 thread [1] and the v8 review [2].
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 HBM 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 spm-memory. 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.
The series is split into four patches:
1/4 spm-memory device (boilerplate + QAPI) 2/4 acpi-build.c SRAT umbrella partition for SPM 3/4 pc machine plug-handler integration + E820 entry 4/4 MAINTAINERS coverage
Testing
-------
Verified end-to-end on q35 + KVM, with both SeaBIOS and OVMF, for:
- single spm-memory instance
- two spm-memory instances on different NUMA nodes
Guest observations: /proc/iomem shows one SOFT_RESERVED entry per spm-memory 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 SPM ranges.
Changes since v8
----------------
- Split the single v8 patch into four bisect-safe patches.
- Drop the per-machine QLIST and the spm_addresses reservation array; the SRAT partition iterates the device tree directly via object_child_foreach_recursive().
- Drop spm_memory_check_node_exclusive(); the existing memory-device framework already enforces the relevant placement invariants.
- Slim spm_memory_realize() to a hostmem-set check; move the is_mapped check to pc_spm_memory_pre_plug().
- Split the pc-side hookup into pre_plug and plug callbacks dispatched from pc_machine_device_{pre_,}plug_cb, matching the pc-dimm pattern.
- Add hw/mem/spm-memory.c and include/hw/mem/spm-memory.h to the Memory devices entry in MAINTAINERS.
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]/
[1] v7 thread closeout:
https://lore.kernel.org/qemu-devel/[email protected]/ [2] v8 review (Igor Mammedov): https://lore.kernel.org/qemu-devel/20260601105057.2d764e55@imammedo/
fanhuang (4):
hw/mem: add spm-memory device for Specific Purpose Memory i386/acpi-build: partition device_memory SRAT umbrella for SPM hw/i386: integrate spm-memory into the pc machine plug path
MAINTAINERS: cover spm-memory under Memory devices
MAINTAINERS | 2 + hw/i386/Kconfig | 2 + hw/i386/acpi-build.c | 98 ++++++++++++++++++++++++-- hw/i386/e820_memory_layout.h | 11 +-- hw/i386/pc.c | 35 +++++++++ hw/mem/Kconfig | 4 ++ hw/mem/meson.build | 1 + hw/mem/spm-memory.c | 133 +++++++++++++++++++++++++++++++++++ include/hw/mem/spm-memory.h | 42 +++++++++++ qapi/machine.json | 43 ++++++++++- 10 files changed, 358 insertions(+), 13 deletions(-) create mode 100644 hw/mem/spm-memory.c create mode 100644 include/hw/mem/spm-memory.h
base-commit: 5611a9268dae7b7ff99d478ed134052a9fc7e9f7 --
2.34.1
PATCH v9 1/4 hw/mem: add spm-memory device for Specific Purpose Memory
Introduce a TYPE_MEMORY_DEVICE subclass spm-memory 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 spm-memory,id=dev0,memdev=spm0,node=$N[,addr=$GPA]The device is boot-time only (no hotplug).
--- hw/i386/Kconfig | 2 + hw/mem/Kconfig | 4 ++ hw/mem/meson.build | 1 + hw/mem/spm-memory.c | 133 ++++++++++++++++++++++++++++++++++++ include/hw/mem/spm-memory.h | 42 ++++++++++++ qapi/machine.json | 43 +++++++++++- 6 files changed, 223 insertions(+), 2 deletions(-) create mode 100644 hw/mem/spm-memory.c create mode 100644 include/hw/mem/spm-memory.h
hw/i386/Kconfig +2 -0
@@ -84,6 +84,7 @@ config I440FX select PCI_I440FX select PIIX select DIMM + select SPM_MEMORY select SMBIOS select SMBIOS_LEGACY select FW_CFG_DMA
@@ -113,6 +114,7 @@ config Q35 select LPC_ICH9 select AHCI_ICH9 select DIMM + select SPM_MEMORY select SMBIOS select FW_CFG_DMA
hw/mem/Kconfig +4 -0
@@ -16,3 +16,7 @@ config CXL_MEM_DEVICE bool default y if CXL select MEM_DEVICE + +config SPM_MEMORY + bool + select MEM_DEVICE
hw/mem/meson.build +1 -0
@@ -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_SPM_MEMORY', if_true: files('spm-memory.c')) stub_ss.add(files('cxl_type3_stubs.c')) stub_ss.add(files('memory-device-stubs.c'))
hw/mem/spm-memory.c new file +133 -0
133 lines not on this page · raw message
include/hw/mem/spm-memory.h new file +42 -0
42 lines not on this page · raw message
qapi/machine.json +41 -2
71 lines not on this page · raw message
Signature · 1 line
2.34.1
Hi,
Quoted 26 lines · fanhuang
Introduce a
TYPE_MEMORY_DEVICEsubclassspm-memoryfor boot-timeSOFT_RESERVEDmemory 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_RESERVEDmemory, 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 spm-memory,id=dev0,memdev=spm0,node=$N[,addr=$GPA]The device is boot-time only (no hotplug).
Signed-off-by FangSheng Huang <[email protected]>--- hw/i386/Kconfig | 2 + hw/mem/Kconfig | 4 ++ hw/mem/meson.build | 1 + hw/mem/spm-memory.c | 133 ++++++++++++++++++++++++++++++++++++ include/hw/mem/spm-memory.h | 42 ++++++++++++ qapi/machine.json | 43 +++++++++++- 6 files changed, 223 insertions(+), 2 deletions(-)
Quoted 2 lines
create mode 100644
hw/mem/spm-memory.c
create mode 100644include/hw/mem/spm-memory.h
Please enable scripts/git.orderfile to ease review.
Quoted 13 lines
hw/i386/Kconfig +1
-0@@ -84,6 +84,7 @@ config I440FX select PCI_I440FX select PIIX select DIMM + select SPM_MEMORY select SMBIOS select SMBIOS_LEGACY select FW_CFG_DMA
hw/i386/Kconfig config Q35 · line 119
Quoted 6 lines
hw/i386/Kconfig +1
-0@@ -113,6 +114,7 @@ config Q35 select LPC_ICH9 select AHCI_ICH9 select DIMM + select SPM_MEMORY select SMBIOS select FW_CFG_DMA
This hunk seems to belong to patch #3.
hw/mem/Kconfig config CXL_MEM_DEVICE · line 20
Quoted 10 lines
hw/mem/Kconfig +2
-0@@ -16,3 +16,7 @@ config CXL_MEM_DEVICE bool default y if CXL select MEM_DEVICE + +config SPM_MEMORY
Simply 'SPM'.
Quoted 43 lines
hw/mem/Kconfig +2
-0+ bool + select MEM_DEVICEhw/mem/meson.build +1
-0@@ -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_SPM_MEMORY', if_true: files('spm-memory.c')) stub_ss.add(files('cxl_type3_stubs.c')) stub_ss.add(files('memory-device-stubs.c'))hw/mem/spm-memory.c new file +23
-0@@ -0,0 +1,133 @@ +/* +* Specific Purpose Memory (SPM) device +* +* 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 "qemu/module.h" +#include "qapi/error.h" +#include "hw/core/qdev-properties.h" +#include "hw/core/qdev.h" +#include "hw/mem/spm-memory.h" +#include "hw/mem/memory-device.h" +#include "migration/vmstate.h" +#include "system/hostmem.h" + +#define SPM_MEMORY_MEMDEV_PROP "memdev" +#define SPM_MEMORY_NODE_PROP "node"
hw/mem/spm-memory.c line 33
Quoted 10 lines
hw/mem/spm-memory.c new file +10
-0+#define SPM_MEMORY_ADDR_PROP "addr" + +static const Property spm_memory_properties[] = { +DEFINE_PROP_LINK (SPM_MEMORY_MEMDEV_PROP , SpmMemoryDevice, hostmem, + TYPE_MEMORY_BACKEND, HostMemoryBackend *), +DEFINE_PROP_UINT32 (SPM_MEMORY_NODE_PROP , SpmMemoryDevice, node,0 ), +DEFINE_PROP_UINT64 (SPM_MEMORY_ADDR_PROP , SpmMemoryDevice, addr,0 ), +}; + +static uint64_t spm_memory_md_get_addr (const MemoryDeviceState *md)
KISS, s/memory_md_// for local methods.
Quoted 47 lines
hw/mem/spm-memory.c new file +47
-0+{ +return SPM_MEMORY (md)->addr; +} + +static void spm_memory_md_set_addr (MemoryDeviceState *md,uint64_t addr, +Error **errp) +{ +SPM_MEMORY (md)->addr = addr; +} + +static MemoryRegion *spm_memory_md_get_memory_region (MemoryDeviceState *md, +Error **errp) +{ +SpmMemoryDevice *spm =SPM_MEMORY (md); + +if (!spm->hostmem) { +error_setg (errp,"'memdev' property must be set" ); +return NULL ; + } +return host_memory_backend_get_memory (spm->hostmem); +} + +static uint64_t spm_memory_md_get_plugged_size (const MemoryDeviceState *md, +Error **errp) +{ +SpmMemoryDevice *spm =SPM_MEMORY (md); +return spm->hostmem ? +memory_region_size (host_memory_backend_get_memory (spm->hostmem)) :0 ; +} + +static void spm_memory_md_fill_device_info (const MemoryDeviceState *md, +MemoryDeviceInfo *info) +{ +SpmMemoryDeviceInfo *di =g_new0 (SpmMemoryDeviceInfo,1 ); +SpmMemoryDevice *spm =SPM_MEMORY (md); +DeviceState *dev =DEVICE (md); + + di->id = dev->id ?g_strdup (dev->id) :NULL ; + di->memaddr = spm->addr; + di->size = spm->hostmem ?memory_region_size ( +host_memory_backend_get_memory (spm->hostmem)) :0 ; + di->node = spm->node; + di->memdev = spm->hostmem ? +object_get_canonical_path (OBJECT (spm->hostmem)) :NULL ; + + info->u.spm_memory.data = di; + info->type =MEMORY_DEVICE_INFO_KIND_SPM_MEMORY ;
hw/mem/spm-memory.c line 90
Quoted 10 lines
hw/mem/spm-memory.c new file +10
-0+} + +static void spm_memory_realize (DeviceState *dev,Error **errp) +{ +SpmMemoryDevice *spm =SPM_MEMORY (dev); + +if (!spm->hostmem) { +error_setg (errp,"'%s' property is required" ,SPM_MEMORY_MEMDEV_PROP ); +return ; + }
Should the 'node' property be validated?
hw/mem/spm-memory.c line 95
Quoted 5 lines
hw/mem/spm-memory.c new file +5
-0+} + +static const VMStateDescription vmstate_spm_memory = { + .name =TYPE_SPM_MEMORY , + .unmigratable =1 ,
Please add a comment explaining the reason.
hw/mem/spm-memory.c line 107
Quoted 12 lines
hw/mem/spm-memory.c new file +12
-0+}; + +static void spm_memory_class_init (ObjectClass *oc,const void *data) +{ +DeviceClass *dc =DEVICE_CLASS (oc); +MemoryDeviceClass *mdc =MEMORY_DEVICE_CLASS (oc); + + dc->desc ="SPM (Specific Purpose Memory) device" ; + dc->hotpluggable = false; + dc->realize = spm_memory_realize; + dc->vmsd = &vmstate_spm_memory; +device_class_set_props (dc, spm_memory_properties);
Should we add/use DEVICE_CATEGORY_MEMORY?
set_bit(DEVICE_CATEGORY_MEMORY, dc->categories);
Quoted 13 lines
hw/mem/spm-memory.c new file +13
-0+ + mdc->get_addr = spm_memory_md_get_addr; + mdc->set_addr = spm_memory_md_set_addr; + mdc->get_memory_region = spm_memory_md_get_memory_region; + mdc->get_plugged_size = spm_memory_md_get_plugged_size; + mdc->fill_device_info = spm_memory_md_fill_device_info; +} + +static const TypeInfo spm_memory_info = { + .name =TYPE_SPM_MEMORY , + .parent =TYPE_DEVICE , + .class_size =sizeof (SpmMemoryDeviceClass), + .class_init = spm_memory_class_init,
hw/mem/spm-memory.c line 130
Quoted 10 lines
hw/mem/spm-memory.c new file +10
-0+ .instance_size = sizeof(SpmMemoryDevice), + .interfaces = (InterfaceInfo []) { + {TYPE_MEMORY_DEVICE }, + { } + }, +}; + +static void spm_memory_register_types (void ) +{ +type_register_static (&spm_memory_info);
Preferrably DEFINE_TYPES().
Quoted 22 lines
hw/mem/spm-memory.c new file +3
-0+} + +type_init (spm_memory_register_types)include/hw/mem/spm-memory.h new file +13
-0@@ -0,0 +1,42 @@ +/* +* 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 +*/
include/hw/mem/spm-memory.h line 23
Quoted 10 lines
include/hw/mem/spm-memory.h new file +10
-0+ +#ifndef QEMU_SPM_MEMORY_H +#define QEMU_SPM_MEMORY_H + +#include "hw/mem/memory-device.h" +#include "hw/core/qdev.h" +#include "qom/object.h" +#include "system/hostmem.h" + +#define TYPE_SPM_MEMORY "spm-memory"
#define TYPE_SPM "spm"
(or TYPE_SPM_DEVICE if you rather).
include/hw/mem/spm-memory.h line 25
Quoted 2 lines
include/hw/mem/spm-memory.h new file +2
-0+ +OBJECT_DECLARE_TYPE (SpmMemoryDevice, SpmMemoryDeviceClass,SPM_MEMORY )
OBJECT_DECLARE_SIMPLE_TYPE(SpmDevice, SPM_DEVICE)
include/hw/mem/spm-memory.h line 31
Quoted 6 lines
include/hw/mem/spm-memory.h new file +6
-0+ +struct SpmMemoryDevice { +/*< private >*/ +DeviceState parent_obj; + +/*< public >*/
Please drop this public/private unuseful comments.
include/hw/mem/spm-memory.h line 40
Quoted 9 lines
include/hw/mem/spm-memory.h new file +9
-0+HostMemoryBackend *hostmem;/* memdev= backend */ +uint32_t node;/* NUMA proximity domain (node=) */ +uint64_t addr;/* GPA (from addr= or framework-assigned) */ +}; + +struct SpmMemoryDeviceClass { +/*< private >*/ +DeviceClass parent_class; +};
Not needed (empty).
Quoted 21 lines
include/hw/mem/spm-memory.h new file +2
-0+ +#endif /* QEMU_SPM_MEMORY_H */ qapi/machine.json +11
-0@@ -1413,6 +1413,32 @@ } } +## +# @SpmMemoryDeviceInfo: +# +# spm-memory device state information +# +# @id: device's ID +# +# @memaddr: physical address in memory, where device is mapped +# +# @size: size of memory that the device provides +#
qapi/machine.json line 1436
Quoted 10 lines
qapi/machine.json +10
-0+# @node: NUMA proximity domain to which the device is assigned +# +# @memdev: memory backend linked with device +# +# Since: 11.1 +## +{ 'struct': 'SpmMemoryDeviceInfo', + 'data': { '*id': 'str', + 'memaddr': 'size', + 'size': 'size',
Pre-existing, these fields belong to the TYPE_MEMORY_DEVICE interface. Isn't it a way to have all implementation field directly QAPIfied?
Quoted 10 lines
qapi/machine.json +5
-0+ 'node': 'int', + 'memdev': 'str' + } +} + ## # @MemoryDeviceInfoKind: #@@ -1426,11 +1452,13 @@ #
qapi/machine.json line 1461
Quoted 10 lines
qapi/machine.json +3
-1# @hv-balloon: since 8.2. # +# @spm-memory: since 11.1. +# # Since: 2.1 ## { 'enum': 'MemoryDeviceInfoKind', 'data': [ 'dimm', 'nvdimm', 'virtio-pmem', 'virtio-mem', 'sgx-epc', - 'hv-balloon' ] } + 'hv-balloon', 'spm-memory' ] }
Clearly 'spm' :)
Quoted 21 lines
qapi/machine.json +10
-0## # @PCDIMMDeviceInfoWrapper:@@ -1482,6 +1510,16 @@ { 'struct': 'HvBalloonDeviceInfoWrapper', 'data': { 'data': 'HvBalloonDeviceInfo' } } +## +# @SpmMemoryDeviceInfoWrapper: +# +# @data: spm-memory device state information +# +# Since: 11.1 +## +{ 'struct': 'SpmMemoryDeviceInfoWrapper', + 'data': { 'data': 'SpmMemoryDeviceInfo' } } + ## # @MemoryDeviceInfo: #
qapi/machine.json line 1544
Quoted 9 lines
qapi/machine.json +2
-1@@ -1499,7 +1537,8 @@ 'virtio-pmem': 'VirtioPMEMDeviceInfoWrapper', 'virtio-mem': 'VirtioMEMDeviceInfoWrapper', 'sgx-epc': 'SgxEPCDeviceInfoWrapper', - 'hv-balloon': 'HvBalloonDeviceInfoWrapper' + 'hv-balloon': 'HvBalloonDeviceInfoWrapper', + 'spm-memory': 'SpmMemoryDeviceInfoWrapper' } }
Patch LGTM.
PATCH v9 2/4 i386/acpi-build: partition device_memory SRAT umbrella for SPM
In reply to fanhuangRestructure the device_memory SRAT umbrella entry into a per-kind
partition: each TYPE_SPM_MEMORY device gets an ENABLED entry at its own proximity_domain; the remaining sub-ranges get HOTPLUGGABLE | ENABLED placeholders at the highest PXM, preserving the upstream convention required by Windows hotplug and Linux SWIOTLB.
--- hw/i386/acpi-build.c | 98 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 92 insertions(+), 6 deletions(-)
hw/i386/acpi-build.c +92 -6
@@ -52,6 +52,7 @@#include "migration/vmstate.h" #include "hw/mem/memory-device.h" #include "hw/mem/nvdimm.h" +#include "hw/mem/spm-memory.h" #include "system/numa.h" #include "system/reset.h" #include "hw/hyperv/vmbus-bridge.h"
@@ -1346,6 +1347,96 @@ build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog, }#endif +typedef struct { +uint64_t addr; +uint64_t size; +uint32_t node; +}SpmRange ; + +static int collect_spm_ranges_cb (Object *obj,void *opaque) +{ +GArray *ranges = opaque; +SpmMemoryDevice *spm; +MemoryDeviceClass *mdc; +SpmRange r; + +if (!object_dynamic_cast (obj,TYPE_SPM_MEMORY )) { +return 0 ; + } + spm =SPM_MEMORY (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 spm_range_compare (gconstpointer a,gconstpointer b) +{ +const SpmRange *range_a = a; +const SpmRange *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_SPM_MEMORY device, emit an ENABLED entry at the +* device's own proximity_domain. All remaining sub-ranges (gaps between +* SPM devices, leading and trailing padding, ranges occupied by non-SPM +* 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 (SpmRange)); +uint64_t cursor, end; +int nb_nodes = ms->numa_state ? ms->numa_state->num_nodes :0 ; +uint32_t hotplug_pxm = nb_nodes >0 ? nb_nodes -1 :0 ; +guint i; + +if (!ms->device_memory) { +return ; + } + + cursor = ms->device_memory->base; + end = cursor +memory_region_size (&ms->device_memory->mr); + +object_child_foreach_recursive (qdev_get_machine (), + collect_spm_ranges_cb, ranges); +g_array_sort (ranges, spm_range_compare); + +for (i =0 ; i < ranges->len; i++) { +SpmRange *r = &g_array_index (ranges, SpmRange, i); + +if (cursor < r->addr) { +build_srat_memory (table_data, cursor, r->addr - cursor, + hotplug_pxm, +MEM_AFFINITY_HOTPLUGGABLE | +MEM_AFFINITY_ENABLED ); + } +build_srat_memory (table_data, r->addr, r->size, r->node, +MEM_AFFINITY_ENABLED ); + cursor = r->addr + r->size; + } + +if (cursor < end) { +build_srat_memory (table_data, cursor, end - cursor, + hotplug_pxm, +MEM_AFFINITY_HOTPLUGGABLE | +MEM_AFFINITY_ENABLED ); + } +} +#define HOLE_640K_START (640 * KiB)#define HOLE_640K_END (1 * MiB)
@@ -1481,12 +1572,7 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine)* Memory devices may override proximity set by this entry, * 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
PATCH v9 3/4 hw/i386: integrate spm-memory into the pc machine plug path
In reply to fanhuangAdd the pc machine hookup for TYPE_SPM_MEMORY so each spm-memory 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 | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 5 deletions(-)
hw/i386/e820_memory_layout.h +6 -5
@@ -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 0xefffffffstruct e820_entry {uint64_t address;
hw/i386/pc.c +35 -0
@@ -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/spm-memory.h" #include "e820_memory_layout.h" #include "trace.h" #include "sev.h"
@@ -1283,11 +1284,42 @@ static void pc_hv_balloon_plug(HotplugHandler *hotplug_dev,memory_device_plug (MEMORY_DEVICE (dev),MACHINE (hotplug_dev)); } +static void pc_spm_memory_pre_plug (HotplugHandler *hotplug_dev, +DeviceState *dev,Error **errp) +{ +SpmMemoryDevice *spm =SPM_MEMORY (dev); + +if (host_memory_backend_is_mapped (spm->hostmem)) { +error_setg (errp,"memory backend '%s' is already in use" , +object_get_canonical_path_component (OBJECT (spm->hostmem))); +return ; + } +memory_device_pre_plug (MEMORY_DEVICE (dev),MACHINE (hotplug_dev), + errp); +} + +static void pc_spm_memory_plug (HotplugHandler *hotplug_dev, +DeviceState *dev,Error **errp) +{ +SpmMemoryDevice *spm =SPM_MEMORY (dev); +MemoryDeviceClass *mdc =MEMORY_DEVICE_GET_CLASS (MEMORY_DEVICE (dev)); +uint64_t addr, size; + +host_memory_backend_set_mapped (spm->hostmem, true); +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_SPM_MEMORY )) { +pc_spm_memory_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 )) {
@@ -1324,6 +1356,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_SPM_MEMORY )) { +pc_spm_memory_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 )) {
@@ -1368,6 +1402,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_SPM_MEMORY) || 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) ||
Signature · 1 line
2.34.1
PATCH v9 4/4 MAINTAINERS: cover spm-memory under Memory devices
In reply to fanhuang--- MAINTAINERS | 2 ++ 1 file changed, 2 insertions(+)
MAINTAINERS +2 -0
@@ -3365,9 +3365,11 @@ S: Supported F: hw/mem/memory-device*.c F: hw/mem/nvdimm.c F: hw/mem/pc-dimm.c +F: hw/mem/spm-memory.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/spm-memory.h F: docs/nvdimm.txt SPICE
Signature · 1 line
2.34.1
Re: [PATCH v9 4/4] MAINTAINERS: cover spm-memory under Memory devices
MAINTAINERS S: Supported
Quoted 10 lines · fanhuang
Signed-off-by FangSheng Huang <[email protected]>--- MAINTAINERS | 2 ++ 1 file changed, 2 insertions(+)MAINTAINERS +0
-0@@ -3365,9 +3365,11 @@ S: Supported
Add yourself as R: ?
MAINTAINERS S: Supported · line 3373
Quoted 9 lines
MAINTAINERS +2
-0F: hw/mem/memory-device*.c F: hw/mem/nvdimm.c F: hw/mem/pc-dimm.c +F: hw/mem/spm-memory.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/spm-memory.h F: docs/nvdimm.txt
Squash with patch #1?
Quoted 1 line · fanhuang
This series adds a
TYPE_MEMORY_DEVICEsubclassspm-memory
Very nitty: but spm already includes "memory". And I think most things on the cmdline use "mem" as abbreviation.
"sp-mem" ? or simply "spm" ? Thoughts?
Signature · 3 lines
Cheers, David
Quoted 8 lines · David Hildenbrand
Quoted 1 line · fanhuang
This series adds a
TYPE_MEMORY_DEVICEsubclassspm-memoryVery nitty: but spm already includes "memory". And I think most things on the cmdline use "mem" as abbreviation.
"sp-mem" ? or simply "spm" ? Thoughts?
Good point — the duplication didn't quite register when I named it. I lean toward simply spm: matches the dimm / nvdimm acronym-only pattern. Will go with that in the next iteration unless you'd prefer sp-mem.
Best regards,
FangSheng Huang (Jerry)
Quoted 6 lines · FangSheng (Jerry)
Quoted 3 lines · David Hildenbrand
Quoted 1 line · fanhuang
This series adds a
TYPE_MEMORY_DEVICEsubclassspm-memory
Quoted 8 lines
Quoted 5 lines
Very nitty: but spm already includes "memory". And I think most things on the cmdline use "mem" as abbreviation.
"sp-mem" ? or simply "spm" ? Thoughts?
Good point — the duplication didn't quite register when I named it. I lean toward simply
spm: matches thedimm/nvdimmacronym-only pattern.
Best to wait for more feedback :)
Signature · 3 lines
Cheers, David
Quoted 10 lines · David Hildenbrand (Arm)
Quoted 9 lines · FangSheng (Jerry)
Quoted 6 lines · David Hildenbrand
Quoted 1 line · fanhuang
This series adds a
TYPE_MEMORY_DEVICEsubclassspm-memoryVery nitty: but spm already includes "memory". And I think most things on the cmdline use "mem" as abbreviation.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
"sp-mem" ? or simply "spm" ? Thoughts?
Good point — the duplication didn't quite register when I named it. I lean toward simply
spm: matches thedimm/nvdimmacronym-only pattern.Best to wait for more feedback :)
+1 for 'spm'
Quoted 13 lines · On Wed, 3 Jun 2026 09:45:28 +0200 Philippe Mathieu-Daudé <[email protected]>…
Quoted 12 lines · David Hildenbrand (Arm)
Quoted 11 lines · FangSheng (Jerry)
Quoted 8 lines · David Hildenbrand
Quoted 1 line · fanhuang
This series adds a
TYPE_MEMORY_DEVICEsubclassspm-memoryVery nitty: but spm already includes "memory". And I think most things on the cmdline use "mem" as abbreviation.
"sp-mem" ? or simply "spm" ? Thoughts?
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Good point — the duplication didn't quite register when I named it. I lean toward simply
spm: matches thedimm/nvdimmacronym-only pattern.Best to wait for more feedback :)
+1 for 'spm'
I like spm as well, but it's a very short acronym and /me/ uselessly worrying about ambiguity and future name conflicts.
perhaps: sp-mem would be better in that regards.
Quoted 3 lines
Quoted 22 lines · Igor Mammedov
Quoted 19 lines · On Wed, 3 Jun 2026 09:45:28 +0200 Philippe Mathieu-Daudé <[email protected]>…
Quoted 17 lines · David Hildenbrand (Arm)
Quoted 6 lines · FangSheng (Jerry)
Quoted 3 lines · David Hildenbrand
Quoted 1 line · fanhuang
This series adds a
TYPE_MEMORY_DEVICEsubclassspm-memoryQuoted 8 lines
Quoted 5 lines
Very nitty: but spm already includes "memory". And I think most things on the cmdline use "mem" as abbreviation.
"sp-mem" ? or simply "spm" ? Thoughts?
Good point — the duplication didn't quite register when I named it. I lean toward simply
spm: matches thedimm/nvdimmacronym-only pattern.Best to wait for more feedback :)
Quoted 7 lines
Quoted 1 line
+1 for 'spm'
I like spm as well, but it's a very short acronym and /me/ uselessly worrying about ambiguity and future name conflicts.
perhaps: sp-mem would be better in that regards. Confirmed — quick grep on master finds "SPM" used in four unrelated
subsystems already (AVR SPM instruction, s390x spm instruction, m25p80 SPI flash Status Protection Mode, AHCI Staggered Power Management). Bare spm would land in noisy company.
Leaning toward sp-mem as you suggested. Concrete before/after:
cmdline:
BEFORE: -device spm-memory,memdev=m0,node=1
AFTER: -device sp-mem,memdev=m0,node=1
file / TYPE / function (after also dropping the redundant _md_ infix per Philippe's KISS suggestion):
BEFORE:
hw/mem/spm-memory.c TYPE_SPM_MEMORY spm_memory_md_get_addr()
AFTER:
hw/mem/sp-mem.c TYPE_SP_MEM sp_mem_get_addr()
QAPI enum value:
BEFORE: 'spm-memory'
AFTER: 'sp-mem'
Kconfig symbol:
BEFORE: CONFIG_SPM_MEMORY
AFTER: CONFIG_SP_MEM
struct + cast macro (using OBJECT_DECLARE_SIMPLE_TYPE per Philippe, since the class struct is empty and can be dropped):
BEFORE:
OBJECT_DECLARE_TYPE(SpmMemoryDevice, SpmMemoryDeviceClass,
SPM_MEMORY)
AFTER:
OBJECT_DECLARE_SIMPLE_TYPE(SpMemDevice, SP_MEM)
David, Philippe — any preference between this and spm? If sp-mem works for everyone, I'll respin accordingly.
Best regards,
FangSheng Huang (Jerry)
Quoted 56 lines · FangSheng (Jerry)
Quoted 21 lines · Igor Mammedov
Quoted 18 lines · On Wed, 3 Jun 2026 09:45:28 +0200 Philippe Mathieu-Daudé <[email protected]>…
Quoted 16 lines · David Hildenbrand (Arm)
Quoted 6 lines · FangSheng (Jerry)
Quoted 3 lines · David Hildenbrand
Quoted 1 line · fanhuang
This series adds a
TYPE_MEMORY_DEVICEsubclassspm-memoryQuoted 7 lines
Quoted 4 lines
Very nitty: but spm already includes "memory". And I think most things on the cmdline use "mem" as abbreviation.
"sp-mem" ? or simply "spm" ? Thoughts?
Good point — the duplication didn't quite register when I named it. I lean toward simply
spm: matches thedimm/nvdimmacronym-only pattern.Best to wait for more feedback :)
Quoted 7 lines
Quoted 1 line
+1 for 'spm'
I like spm as well, but it's a very short acronym and /me/ uselessly worrying about ambiguity and future name conflicts.
perhaps: sp-mem would be better in that regards. Confirmed — quick grep on master finds "SPM" used in four unrelated
subsystems already (AVR SPM instruction, s390x spm instruction, m25p80 SPI flash Status Protection Mode, AHCI Staggered Power Management). Bare
spmwould land in noisy company.Leaning toward
sp-memas you suggested. Concrete before/after:cmdline:
BEFORE: -device spm-memory,memdev=m0,node=1
AFTER: -device sp-mem,memdev=m0,node=1file / TYPE / function (after also dropping the redundant _md_ infix per Philippe's KISS suggestion):
BEFORE:
hw/mem/spm-memory.c TYPE_SPM_MEMORYspm_memory_md_get_addr()AFTER:
hw/mem/sp-mem.c TYPE_SP_MEMsp_mem_get_addr()QAPI enum value:
BEFORE: 'spm-memory'
AFTER: 'sp-mem'
Kconfigsymbol:
BEFORE:CONFIG_SPM_MEMORY
AFTER:CONFIG_SP_MEM
Quoted 7 lines
struct + cast macro (using
OBJECT_DECLARE_SIMPLE_TYPEper Philippe, since the class struct is empty and can be dropped):
BEFORE:
OBJECT_DECLARE_TYPE(SpmMemoryDevice, SpmMemoryDeviceClass, SPM_MEMORY)
AFTER:
OBJECT_DECLARE_SIMPLE_TYPE(SpMemDevice, SP_MEM)
All these changes LGTM!
Quoted 6 lines
David, Philippe — any preference between this and
spm? If sp-mem works for everyone, I'll respin accordingly.Best regards,
FangSheng Huang (Jerry)
Quoted 68 lines · Philippe Mathieu-Daudé
[Some people who received this message don't often get email from [email protected]. Learn why this is important at https://aka.ms/ LearnAboutSenderIdentification ]
Quoted 57 lines · FangSheng (Jerry)
Quoted 20 lines · Igor Mammedov
Quoted 17 lines · On Wed, 3 Jun 2026 09:45:28 +0200 Philippe Mathieu-Daudé <[email protected]>…
Quoted 16 lines · David Hildenbrand (Arm)
Quoted 14 lines · FangSheng (Jerry)
Quoted 8 lines · David Hildenbrand
Quoted 1 line · fanhuang
This series adds a
TYPE_MEMORY_DEVICEsubclassspm-memoryVery nitty: but spm already includes "memory". And I think most things on the
cmdline use "mem" as abbreviation."sp-mem" ? or simply "spm" ? Thoughts?
Good point — the duplication didn't quite register when I named it. I lean toward simply
spm: matches thedimm/nvdimmacronym- only pattern.Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Best to wait for more feedback :)
+1 for 'spm'
I like spm as well, but it's a very short acronym and /me/ uselessly worrying about ambiguity and future name conflicts.
perhaps: sp-mem would be better in that regards.
Confirmed — quick grep on master finds "SPM" used in four unrelated subsystems already (AVR SPM instruction, s390x spm instruction, m25p80 SPI flash Status Protection Mode, AHCI Staggered Power Management). Bare
spmwould land in noisy company.Leaning toward
sp-memas you suggested. Concrete before/after:cmdline:
BEFORE: -device spm-memory,memdev=m0,node=1
AFTER: -device sp-mem,memdev=m0,node=1file / TYPE / function (after also dropping the redundant _md_ infix per Philippe's KISS suggestion):
BEFORE:
hw/mem/spm-memory.c TYPE_SPM_MEMORYspm_memory_md_get_addr()AFTER:
hw/mem/sp-mem.c TYPE_SP_MEMsp_mem_get_addr()QAPI enum value:
BEFORE: 'spm-memory'
AFTER: 'sp-mem'
Kconfigsymbol:
BEFORE:CONFIG_SPM_MEMORY
AFTER:CONFIG_SP_MEMQuoted 7 lines
struct + cast macro (using
OBJECT_DECLARE_SIMPLE_TYPEper Philippe, since the class struct is empty and can be dropped):
BEFORE:
OBJECT_DECLARE_TYPE(SpmMemoryDevice, SpmMemoryDeviceClass, SPM_MEMORY)
AFTER:
OBJECT_DECLARE_SIMPLE_TYPE(SpMemDevice, SP_MEM)
Quoted 2 lines
All these changes LGTM!
Thanks, Philippe. v10 also addresses the rest of your patch 1 / patch 4 review (node validation moved to pc_sp_mem_pre_plug, .unmigratable comment, DEFINE_TYPES(), dropped /*< private >*/ markers, R: tag under Memory devices); diffs visible in the v10 series.
Three items deviate from your suggestion:
- DEVICE_CATEGORY_MEMORY: the enum doesn't currently exist in include/hw/core/qdev.h, and pc-dimm / nvdimm don't set any device category here. v10 follows the pc-dimm precedent.
- QAPI base refactor (id / memaddr / size at TYPE_MEMORY_DEVICE):
acknowledged as a pre-existing pattern across PCDIMM / NVDIMM / VirtioMEM / SgxEPC / HvBalloon; out of scope for this series.
- MAINTAINERS squash into patch 1: Igor's v8 review asked for MAINTAINERS as a separate patch, so v10 keeps it split as patch 4/4.
Quoted 8 lines
Quoted 6 lines
David, Philippe — any preference between this and
spm? If sp-mem works for everyone, I'll respin accordingly.Best regards,
FangSheng Huang (Jerry)
Quoted 5 lines · FangSheng (Jerry)
Three items deviate from your suggestion:
-
DEVICE_CATEGORY_MEMORY: the enum doesn't currently exist ininclude/hw/core/qdev.h, and pc-dimm / nvdimm don't set any device category here. v10 follows the pc-dimm precedent.
Yes, this was a question for Thomas / Igor, do we want to categorize memory devices out of misc ones?
Quoted 4 lines
- QAPI base refactor (id / memaddr / size at
TYPE_MEMORY_DEVICE):
acknowledged as a pre-existing pattern across PCDIMM / NVDIMM / VirtioMEM / SgxEPC / HvBalloon; out of scope for this series.
Agreed.
Regards,
Phil.