hw/mem: add sp-mem device for Specific Purpose Memory
v10 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 reviews [2][3].
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.
Changes since v9
----------------
- Rename spm-memory to sp-mem throughout (cmdline, file, TYPE_, QAPI enum, Kconfig, struct).
- Drop the redundant _md_ infix from local memory-device methods.
- Drop the empty SpmDeviceClass struct and switch to OBJECT_DECLARE_SIMPLE_TYPE.
- Drop the /*< private >*/ / /*< public >*/ markers in the header.
- Use DEFINE_TYPES() instead of type_register_static.
- Comment why .unmigratable = 1.
- Validate the node property in pc_sp_mem_pre_plug().
- Move the select SP_MEM Kconfig hunks for i440fx and Q35 from
patch 1/4 into patch 3/4.
- MAINTAINERS: add an R: line for myself under Memory devices. Keep MAINTAINERS as a separate patch.
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]/
[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/
fanhuang (4):
hw/mem: add sp-mem device for Specific Purpose Memory 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
MAINTAINERS | 3 + qapi/machine.json | 43 +++++++++++- hw/i386/e820_memory_layout.h | 11 +-- include/hw/mem/sp-mem.h | 35 ++++++++++ hw/i386/acpi-build.c | 98 ++++++++++++++++++++++++-- hw/i386/pc.c | 42 +++++++++++ hw/mem/sp-mem.c | 130 +++++++++++++++++++++++++++++++++++ hw/i386/Kconfig | 2 + hw/mem/Kconfig | 4 ++ hw/mem/meson.build | 1 + 10 files changed, 356 insertions(+), 13 deletions(-) create mode 100644 include/hw/mem/sp-mem.h create mode 100644 hw/mem/sp-mem.c
base-commit: 405c32d2b18a683ba36301351af75125d9afda08 --
2.34.1
PATCH v10 1/4 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).
--- qapi/machine.json | 43 ++++++++++++- include/hw/mem/sp-mem.h | 35 +++++++++++ hw/mem/sp-mem.c | 130 ++++++++++++++++++++++++++++++++++++++++ hw/mem/Kconfig | 4 ++ hw/mem/meson.build | 1 + 5 files changed, 211 insertions(+), 2 deletions(-) create mode 100644 include/hw/mem/sp-mem.h create mode 100644 hw/mem/sp-mem.c
qapi/machine.json +41 -2
@@ -1413,6 +1413,32 @@ } } +## +# @SpMemDeviceInfo: +# +# sp-mem device state information +# +# @id: device's ID +# +# @memaddr: physical address in memory, where device is mapped +# +# @size: size of memory that the device provides +# +# @node: NUMA proximity domain to which the device is assigned +# +# @memdev: memory backend linked with device +# +# Since: 11.1 +## +{ 'struct': 'SpMemDeviceInfo', + 'data': { '*id': 'str', + 'memaddr': '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' } }
include/hw/mem/sp-mem.h new file +35 -0
@@ -0,0 +1,35 @@ +/* +* 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/mem/memory-device.h" +#include "hw/core/qdev.h" +#include "qom/object.h" +#include "system/hostmem.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 +130 -0
130 lines not on this page · raw message
hw/mem/Kconfig +4 -0
@@ -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
@@ -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
Quoted 11 lines · fanhuang
Introduce a
TYPE_MEMORY_DEVICEsubclasssp-memfor 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:
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).
Signed-off-by FangSheng Huang <[email protected]>---
Signature · 3 lines
Cheers, David
Quoted 11 lines · fanhuang
Introduce a
TYPE_MEMORY_DEVICEsubclasssp-memfor 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:
Quoted 7 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).
Signed-off-by FangSheng Huang <[email protected]>
Quoted 46 lines · On Fri, 5 Jun 2026 18:46:06 +0800 fanhuang <[email protected]> wrote:
Introduce a
TYPE_MEMORY_DEVICEsubclasssp-memfor 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 sp-mem,id=dev0,memdev=spm0,node=$N[,addr=$GPA]The device is boot-time only (no hotplug).
Signed-off-by FangSheng Huang <[email protected]>--- qapi/machine.json | 43 ++++++++++++- include/hw/mem/sp-mem.h | 35 +++++++++++ hw/mem/sp-mem.c | 130 ++++++++++++++++++++++++++++++++++++++++ hw/mem/Kconfig | 4 ++ hw/mem/meson.build | 1 + 5 files changed, 211 insertions(+), 2 deletions(-) create mode 100644 include/hw/mem/sp-mem.h create mode 100644 hw/mem/sp-mem.cqapi/machine.json +10
-0@@ -1413,6 +1413,32 @@ } } +## +# @SpMemDeviceInfo: +# +# sp-mem 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 1435
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': 'SpMemDeviceInfo', + 'data': { '*id': 'str', + 'memaddr': 'size',
why not 'addr', like DIMM?
Quoted 123 lines
qapi/machine.json +21
-2+ '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' } }include/hw/mem/sp-mem.h new file +35
-0@@ -0,0 +1,35 @@ +/* +* 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/mem/memory-device.h" +#include "hw/core/qdev.h" +#include "qom/object.h" +#include "system/hostmem.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 +25
-0@@ -0,0 +1,130 @@ +/* +* 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/sp-mem.h" +#include "hw/mem/memory-device.h" +#include "migration/vmstate.h" +#include "system/hostmem.h" + +#define SP_MEM_MEMDEV_PROP "memdev" +#define SP_MEM_NODE_PROP "node" +#define SP_MEM_ADDR_PROP "addr" +
hw/mem/sp-mem.c line 35
Quoted 10 lines
hw/mem/sp-mem.c new file +10
-0+static const Property sp_mem_properties[] = { +DEFINE_PROP_LINK (SP_MEM_MEMDEV_PROP , SpMemDevice, hostmem, + TYPE_MEMORY_BACKEND, HostMemoryBackend *), +DEFINE_PROP_UINT32 (SP_MEM_NODE_PROP , SpMemDevice, node,0 ), +DEFINE_PROP_UINT64 (SP_MEM_ADDR_PROP , SpMemDevice, addr,0 ), +}; + +static uint64_t sp_mem_get_addr (const MemoryDeviceState *md) +{ +return SP_MEM (md)->addr;
device cast + deref, should be separate. or even better look at pc_dimm_md_get_addr()
hw/mem/sp-mem.c line 42
Quoted 7 lines
hw/mem/sp-mem.c new file +7
-0+} + +static void sp_mem_set_addr (MemoryDeviceState *md,uint64_t addr, +Error **errp) +{ +SP_MEM (md)->addr = addr; +}
ditto
Quoted 22 lines
hw/mem/sp-mem.c new file +22
-0+ +static MemoryRegion *sp_mem_get_memory_region (MemoryDeviceState *md, +Error **errp) +{ +SpMemDevice *spm =SP_MEM (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 sp_mem_get_plugged_size (const MemoryDeviceState *md, +Error **errp) +{ +SpMemDevice *spm =SP_MEM (md); +return spm->hostmem ? +memory_region_size (host_memory_backend_get_memory (spm->hostmem)) :0 ; +} + +static void sp_mem_fill_device_info(const MemoryDeviceState *md,
hw/mem/sp-mem.c line 74
Quoted 10 lines
hw/mem/sp-mem.c new file +10
-0+ 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->memaddr = spm->addr; + di->size = spm->hostmem ?memory_region_size ( +host_memory_backend_get_memory (spm->hostmem)) :0 ;
why conditional?
hw/mem/sp-mem.c line 77
Quoted 3 lines
hw/mem/sp-mem.c new file +3
-0+ di->node = spm->node; + di->memdev = spm->hostmem ? +object_get_canonical_path (OBJECT (spm->hostmem)) :NULL ;
ditto
Quoted 26 lines
hw/mem/sp-mem.c new file +26
-0+ + 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); + +if (!spm->hostmem) { +error_setg (errp,"'%s' property is required" ,SP_MEM_MEMDEV_PROP ); +return ; + } +} + +/* boot-time only; no plug/unplug state to migrate */ +static const VMStateDescription vmstate_sp_mem = { + .name =TYPE_SP_MEM , + .unmigratable =1 , +}; + +static void sp_mem_class_init (ObjectClass *oc,const void *data) +{ +DeviceClass *dc =DEVICE_CLASS (oc); +MemoryDeviceClass *mdc =MEMORY_DEVICE_CLASS (oc); +
hw/mem/sp-mem.c line 113
Quoted 10 lines
hw/mem/sp-mem.c new file +10
-0+ dc->desc ="SPM (Specific Purpose Memory) device" ; + dc->hotpluggable = false; + dc->realize = sp_mem_realize; + dc->vmsd = &vmstate_sp_mem; +device_class_set_props (dc, sp_mem_properties); + + mdc->get_addr = sp_mem_get_addr; + mdc->set_addr = sp_mem_set_addr; + mdc->get_memory_region = sp_mem_get_memory_region; + mdc->get_plugged_size = sp_mem_get_plugged_size;
^^^^
wouldn't memory_device_get_region_size() do here?
Quoted 41 lines
hw/mem/sp-mem.c new file +17
-0+ mdc->fill_device_info = sp_mem_fill_device_info; +} + +static const TypeInfo sp_mem_types[] = { + { + .name =TYPE_SP_MEM , + .parent =TYPE_DEVICE , + .class_init = sp_mem_class_init, + .instance_size =sizeof (SpMemDevice), + .interfaces = (InterfaceInfo []) { + {TYPE_MEMORY_DEVICE }, + { } + }, + }, +}; + +DEFINE_TYPES (sp_mem_types)hw/mem/Kconfig +4
-0@@ -16,3 +16,7 @@ config CXL_MEM_DEVICE bool default y if CXL select MEM_DEVICE + +config SP_MEM + 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_SP_MEM', if_true: files('sp-mem.c')) stub_ss.add(files('cxl_type3_stubs.c')) stub_ss.add(files('memory-device-stubs.c'))
Quoted 7 lines · Igor Mammedov
Quoted 1 line · On Fri, 5 Jun 2026 18:46:06 +0800 fanhuang <[email protected]> wrote:
+ 'memaddr': 'size',
why not 'addr', like DIMM?
Will rename to 'addr' to match PCDIMMDeviceInfo.
Quoted 7 lines
hw/mem/sp-mem.c line 35
Quoted 3 lines
hw/mem/sp-mem.c new file +3
-0+static uint64_t sp_mem_get_addr (const MemoryDeviceState *md) +{ +return SP_MEM (md)->addr;device cast + deref, should be separate. or even better look at
pc_dimm_md_get_addr()
Will switch to object_property_get_uint(OBJECT(md), SP_MEM_ADDR_PROP, &error_abort), and set_addr to object_property_set_uint(), matching pc-dimm.
Quoted 10 lines
hw/mem/sp-mem.c line 42
Quoted 7 lines
hw/mem/sp-mem.c new file +7
-0+} + +static void sp_mem_set_addr (MemoryDeviceState *md,uint64_t addr, +Error **errp) +{ +SP_MEM (md)->addr = addr; +}ditto
Quoted 5 lines
hw/mem/sp-mem.c line 74
Quoted 2 lines
hw/mem/sp-mem.c new file +2
-0+ di->size = spm->hostmem ?memory_region_size ( +host_memory_backend_get_memory (spm->hostmem)) :0 ;why conditional?
Dropped — hostmem is guaranteed set by realize() before fill_device_info() runs, so the ternaries on di->size and di->memdev go away.
Quoted 9 lines
hw/mem/sp-mem.c line 77
Quoted 3 lines
hw/mem/sp-mem.c new file +3
-0+ di->node = spm->node; + di->memdev = spm->hostmem ? +object_get_canonical_path (OBJECT (spm->hostmem)) :NULL ;ditto
Quoted 1 line
+
mdc->get_plugged_size=sp_mem_get_plugged_size;^^^^wouldn't
memory_device_get_region_size()do here?
Yes — dropping the custom sp_mem_get_plugged_size() and using memory_device_get_region_size directly, as pc-dimm does.
Quoted 3 lines
Quoted 2 lines
stub_ss.add(files('memory-device-stubs.c'))
Quoted 6 lines · FangSheng (Jerry)
Quoted 3 lines · Igor Mammedov
On Fri, 5 Jun 2026 18:46:06 +0800
fanhuang <[email protected]> wrote:
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
+ 'memaddr': 'size',
why not 'addr', like DIMM?
Will rename to 'addr' to match PCDIMMDeviceInfo.
Note that we had to use "memaddr" for virtio-mem etc, because their proxy device (e.g., virtio-mem-pci) already had "addr" taken for other purposes.
I suspect we don't expect any proxy devices in the future? (similar to DIMMs) Then, using "addr" is just fine.
Signature · 3 lines
Cheers, David
Quoted 12 lines · David Hildenbrand (Arm)
Quoted 11 lines · FangSheng (Jerry)
Quoted 7 lines · Igor Mammedov
Quoted 1 line · On Fri, 5 Jun 2026 18:46:06 +0800 fanhuang <[email protected]> wrote:
+ 'memaddr': 'size',
why not 'addr', like DIMM?
Quoted 8 lines
Quoted 1 line
Will rename to 'addr' to match PCDIMMDeviceInfo.
Note that we had to use "memaddr" for virtio-mem etc, because their proxy device (e.g., virtio-mem-pci) already had "addr" taken for other purposes.
I suspect we don't expect any proxy devices in the future? (similar to DIMMs) Then, using "addr" is just fine.
Right, no proxy device expected for sp-mem -- it's instantiated directly, like pc-dimm. Keeping addr.
Best regards,
FangSheng Huang (Jerry)
PATCH v10 2/4 i386/acpi-build: partition device_memory SRAT umbrella for sp-mem
In reply to fanhuangRestructure 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 | 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/sp-mem.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; +}SpMemRange ; + +static int collect_sp_mem_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)); +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_sp_mem_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 (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
Re: [PATCH v10 2/4] i386/acpi-build: partition device_memory SRAT umbrella for sp-mem
Quoted 99 lines · fanhuang
Restructure the
device_memorySRAT umbrella entry into a per-kind
partition: eachTYPE_SP_MEMdevice gets an ENABLED entry at its ownproximity_domain; the remaining sub-ranges get HOTPLUGGABLE | ENABLED placeholders at the highest PXM, preserving the existing umbrella convention.Signed-off-by FangSheng Huang <[email protected]>--- hw/i386/acpi-build.c | 98 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 92 insertions(+), 6 deletions(-)hw/i386/acpi-build.c +73
-0@@ -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" @@ -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; +}SpMemRange ; + +static int collect_sp_mem_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)); +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_sp_mem_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 (cursor < r->addr) {
hw/i386/acpi-build.c build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog, · line 1431
Quoted 10 lines
hw/i386/acpi-build.c +10
-0+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; + } +
Should we expect (cursor == end) here and fire a warning if there wasn't a full range to cover the region? If not - why set it all as hotpluggable anyway?
(Maybe just worth a comment here what the last block is actually doing)
Quoted 28 lines
hw/i386/acpi-build.c +9
-6+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
Re: [PATCH v10 2/4] i386/acpi-build: partition device_memory SRAT umbrella for sp-mem
Quoted 115 lines · Gregory Price
Quoted 99 lines · fanhuang
Restructure the
device_memorySRAT umbrella entry into a per-kind
partition: eachTYPE_SP_MEMdevice gets an ENABLED entry at its ownproximity_domain; the remaining sub-ranges get HOTPLUGGABLE | ENABLED placeholders at the highest PXM, preserving the existing umbrella convention.Signed-off-by FangSheng Huang <[email protected]>--- hw/i386/acpi-build.c | 98 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 92 insertions(+), 6 deletions(-)hw/i386/acpi-build.c +73
-0@@ -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" @@ -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; +}SpMemRange ; + +static int collect_sp_mem_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)); +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_sp_mem_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 (cursor < r->addr) {hw/i386/acpi-build.c build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog, · line 1431
Quoted 10 lines
hw/i386/acpi-build.c +10
-0+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; + } +Should we expect (cursor == end) here and fire a warning if there wasn't a full range to cover the region? If not - why set it all as hotpluggable anyway?
Quoted 2 lines
(Maybe just worth a comment here what the last block is actually doing)
Thanks, Gregory.
(cursor == end) is not an invariant — ms->device_memory is sized for the maxmem cap, so sp-mem typically leaves the rest of the window unused. The trailing HOTPLUGGABLE | ENABLED entry covers that remainder so future pc-dimm / virtio-mem hot-add into the same window still sees a properly-flagged SRAT range, preserving the prior umbrella behaviour.
Agreed on the inline comment; will include if/when we respin.
Quoted 28 lines
Quoted 28 lines
hw/i386/acpi-build.c +9
-6+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
Re: [PATCH v10 2/4] i386/acpi-build: partition device_memory SRAT umbrella for sp-mem
In reply to fanhuangQuoted 24 lines · On Fri, 5 Jun 2026 18:46:07 +0800 fanhuang <[email protected]> wrote:
Restructure the
device_memorySRAT umbrella entry into a per-kind
partition: eachTYPE_SP_MEMdevice gets an ENABLED entry at its ownproximity_domain; the remaining sub-ranges get HOTPLUGGABLE | ENABLED placeholders at the highest PXM, preserving the existing umbrella convention.Signed-off-by FangSheng Huang <[email protected]>--- hw/i386/acpi-build.c | 98 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 92 insertions(+), 6 deletions(-)hw/i386/acpi-build.c +1
-0@@ -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"
hw/i386/acpi-build.c build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog, · line 1356
Quoted 10 lines
hw/i386/acpi-build.c +7
-0@@ -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; +}SpMemRange ; + +static int collect_sp_mem_ranges_cb (Object *obj,void *opaque)
sp_mem_collect... maybe
Quoted 36 lines
hw/i386/acpi-build.c +36
-0+{ +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. +*
hw/i386/acpi-build.c build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog, · line 1402
Quoted 10 lines
hw/i386/acpi-build.c +10
-0+* 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)); +uint64_t cursor, end;
region_start, region_end
hw/i386/acpi-build.c build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog, · line 1404
Quoted 2 lines
hw/i386/acpi-build.c +2
-0+int nb_nodes = ms->numa_state ? ms->numa_state->num_nodes :0 ; +uint32_t hotplug_pxm = nb_nodes >0 ? nb_nodes -1 :0 ;
when function is called ms->numa_state->num_nodes is always > 0, isn't it?
Quoted 39 lines
hw/i386/acpi-build.c +35
-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_sp_mem_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 (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)
hw/i386/acpi-build.c build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine) · line 1484
Quoted 4 lines
hw/i386/acpi-build.c +0
-1@@ -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) {
keep it here, and drop one in build_srat_device_memory()
Quoted 9 lines
hw/i386/acpi-build.c +1
-5-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); }
Re: [PATCH v10 2/4] i386/acpi-build: partition device_memory SRAT umbrella for sp-mem
Quoted 6 lines · Igor Mammedov
Quoted 1 line · On Fri, 5 Jun 2026 18:46:07 +0800 fanhuang <[email protected]> wrote:
+static int
collect_sp_mem_ranges_cb(Object *obj, void *opaque)
sp_mem_collect... maybe
Will rename to sp_mem_collect_ranges_cb.
Quoted 3 lines
Quoted 1 line
+
uint64_tcursor, end;
region_start,region_end
Will rename.
Quoted 5 lines
hw/i386/acpi-build.c build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog, · line 1404
Quoted 2 lines
hw/i386/acpi-build.c +2
-0+int nb_nodes = ms->numa_state ? ms->numa_state->num_nodes :0 ; +uint32_t hotplug_pxm = nb_nodes >0 ? nb_nodes -1 :0 ;when function is called
ms->numa_state->num_nodesis always > 0, isn't it?
Correct — build_srat() already dereferences machine->numa_state->num_nodes unconditionally, so the guard is dead. Will simplify to ms->numa_state->num_nodes.
Quoted 3 lines
Quoted 1 line
- if (
machine->device_memory) {keep it here, and drop one in
build_srat_device_memory()
Will guard the call in build_srat() with if (machine->device_memory) and drop the check inside build_srat_device_memory(), so there is a single guard at the call site.
Quoted 10 lines
Quoted 9 lines
hw/i386/acpi-build.c +1
-5-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); }
PATCH v10 3/4 hw/i386: hook sp-mem into the pc machine plug path
In reply to fanhuangAdd 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 | 42 ++++++++++++++++++++++++++++++++++++ hw/i386/Kconfig | 2 ++ 3 files changed, 50 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 +42 -0
71 lines not on this page · raw message
hw/i386/Kconfig +2 -0
@@ -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
Re: [PATCH v10 3/4] hw/i386: hook sp-mem into the pc machine plug path
Quoted 51 lines · On Fri, 5 Jun 2026 18:46:08 +0800 fanhuang <[email protected]> wrote:
Add the pc machine hookup for
TYPE_SP_MEMso each sp-mem instance is placed by the memory-device framework and reported to the guest asE820_SOFT_RESERVED.Signed-off-by FangSheng Huang <[email protected]>--- hw/i386/e820_memory_layout.h | 11 +++++----- hw/i386/pc.c | 42 ++++++++++++++++++++++++++++++++++++ hw/i386/Kconfig | 2 ++ 3 files changed, 50 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 +3
-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/sp-mem.h" #include "e820_memory_layout.h" #include "trace.h" #include "sev.h" @@ -1283,11 +1284,49 @@ 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)
hw/i386/pc.c static void pc_hv_balloon_plug(HotplugHandler *hotplug_dev, · line 1298
Quoted 10 lines
hw/i386/pc.c +9
-0+{ +MachineState *ms =MACHINE (hotplug_dev); +SpMemDevice *spm =SP_MEM (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 ; + }
this belongs to sp_mem realize
hw/i386/pc.c static void pc_hv_balloon_plug(HotplugHandler *hotplug_dev, · line 1304
Quoted 7 lines
hw/i386/pc.c +7
-0+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 ; + }
I think this the right place for this, despite what other mems do. Perhaps it is worth to consolidate/cleanup 1st.
I'd put it in memory_device_pre_plug():
if has_node_prop:
.....hw/i386/pc.c static void pc_hv_balloon_plug(HotplugHandler *hotplug_dev, · line 1315
Quoted 11 lines
hw/i386/pc.c +11
-0+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; + +host_memory_backend_set_mapped (spm->hostmem, true);
dup? see above.
Quoted 54 lines
hw/i386/pc.c +9
-0+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)) {hw/i386/pc.c +3
-0@@ -1324,6 +1363,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 )) {@@ -1368,6 +1409,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@@ -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
Re: [PATCH v10 3/4] hw/i386: hook sp-mem into the pc machine plug path
Quoted 10 lines · Igor Mammedov
hw/i386/pc.c static void pc_hv_balloon_plug(HotplugHandler *hotplug_dev, · line 1297
Quoted 5 lines · On Fri, 5 Jun 2026 18:46:08 +0800 fanhuang <[email protected]> wrote:
hw/i386/pc.c +5
-0+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 ; + }this belongs to
sp_memrealize
Right — it only needs spm->hostmem, no MachineState. Will move the is_mapped check (and the set_mapped(true)) into sp_mem_realize(), with a matching set_mapped(false) in unrealize, mirroring pc-dimm.
Quoted 8 lines
hw/i386/pc.c static void pc_hv_balloon_plug(HotplugHandler *hotplug_dev, · line 1304
Quoted 7 lines
hw/i386/pc.c +7
-0+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 ; + }
Quoted 7 lines
I think this the right place for this, despite what other mems do. Perhaps it is worth to consolidate/cleanup 1st.
I'd put it in
memory_device_pre_plug():if has_node_prop: .....
Agreed on keeping the check in pre_plug.
I looked into the consolidation: pc-dimm and virtio-mem each carry their own node validation in realize() today, with slightly different wording (and pc-dimm has an extra "machine doesn't support NUMA" branch that virtio-mem folds into its main check). A generic version in memory_device_pre_plug() (gated on the device exposing a "node" property) would have to subsume both and settle on one error path -- a framework change spanning pc-dimm and virtio-mem, separate in scope from adding sp-mem.
So for the next respin the node check stays local to pc_sp_mem_pre_plug(); I'll follow up with the consolidation as a dedicated cleanup once sp-mem lands.
Quoted 4 lines
Quoted 4 lines
hw/i386/pc.c +4
-0+memory_device_pre_plug (MEMORY_DEVICE (dev), ms, errp); +} + +static void pc_sp_mem_plug(HotplugHandler *hotplug_dev,
Quoted 9 lines
hw/i386/pc.c static void pc_hv_balloon_plug(HotplugHandler *hotplug_dev, · line 1315
Quoted 7 lines
hw/i386/pc.c +7
-0+ DeviceState *dev, Error **errp) +{ +SpMemDevice *spm =SP_MEM (dev); +MemoryDeviceClass *mdc =MEMORY_DEVICE_GET_CLASS (MEMORY_DEVICE (dev)); +uint64_t addr, size; + +host_memory_backend_set_mapped (spm->hostmem, true);dup? see above.
Yes — removed from plug once the check/set move to realize.
Best regards,
FangSheng Huang (Jerry)
Quoted 2 lines
Quoted 1 line
PATCH v10 4/4 MAINTAINERS: cover sp-mem under Memory devices, add R: tag
In reply to fanhuang--- MAINTAINERS | 3 +++ 1 file changed, 3 insertions(+)
MAINTAINERS +3 -0
@@ -3361,13 +3361,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
Re: [PATCH v10 4/4] MAINTAINERS: cover sp-mem under Memory devices, add R: tag
Quoted 1 line · On Fri, 5 Jun 2026 18:46:09 +0800 fanhuang <[email protected]> wrote:
Signed-off-by FangSheng Huang <[email protected]>
Quoted 25 lines
--- MAINTAINERS | 3 +++ 1 file changed, 3 insertions(+)MAINTAINERS +3
-0@@ -3361,13 +3361,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
Re: [PATCH v10 4/4] MAINTAINERS: cover sp-mem under Memory devices, add R: tag
In reply to fanhuangOn 6/5/26 12:46, fanhuang wrote:
/insert text here
Signature · 3 lines
Cheers, David