hw/mem: add sp-mem device for Specific Purpose Memory
v13 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 reviews [2][3][4][5][6].
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 v12
-----------------
- Split the QMP/HMP introspection (query-memory-devices and info memory-devices) into its own patch.
- Drop the device-level unmigratable flag; the device carries no migration state of its own.
- Add tests: a bios-tables-test case for the sp-mem SRAT partition, and an e820 fw_cfg test for the SOFT_RESERVED range.
The feature patches (acpi-build, pc, MAINTAINERS) are unchanged from v12; the MAINTAINERS patch retains the Acked-by from Igor and David.
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]/
[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/
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: b0df6e2f2c6c45df8d4d286933799c623e124d98
Signature · 1 line
2.34.1
PATCH v13 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
@@ -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
@@ -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 · On Fri, 19 Jun 2026 19:11:27 +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:
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 187 lines
--- 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.cinclude/hw/mem/sp-mem.h new file +33
-0@@ -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@@ -0,0 +1,109 @@ +/* +* 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 "system/hostmem.h" + +#define SP_MEM_MEMDEV_PROP "memdev" +#define SP_MEM_NODE_PROP "node" +#define SP_MEM_ADDR_PROP "addr" + +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 object_property_get_uint (OBJECT (md),SP_MEM_ADDR_PROP , + &error_abort); +} + +static void sp_mem_set_addr (MemoryDeviceState *md,uint64_t addr, +Error **errp) +{ +object_property_set_uint (OBJECT (md),SP_MEM_ADDR_PROP , addr, errp); +} + +static MemoryRegion *sp_mem_get_memory_region (MemoryDeviceState *md, +Error **errp) +{ +SpMemDevice *spm =SP_MEM (md); + +if (!spm->hostmem) { +error_setg (errp,"'%s' property must be set" ,SP_MEM_MEMDEV_PROP ); +return NULL ; + } +return host_memory_backend_get_memory (spm->hostmem); +} + +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 ; + } +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 ; + } +host_memory_backend_set_mapped (spm->hostmem, true); +} + +static void sp_mem_unrealize (DeviceState *dev) +{ +SpMemDevice *spm =SP_MEM (dev); + +host_memory_backend_set_mapped (spm->hostmem, false); +} + +static void sp_mem_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 = sp_mem_realize; + dc->unrealize = sp_mem_unrealize; +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 = memory_device_get_region_size; +} + +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'))
PATCH v13 2/10 qapi, hmp: introspection for the sp-mem device
In reply to fanhuangAdd 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
@@ -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 +# +# @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
@@ -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
@@ -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
Re: [PATCH v13 02/10] qapi, hmp: introspection for the sp-mem device
Quoted 5 lines · On Fri, 19 Jun 2026 19:11:28 +0800 fanhuang <[email protected]> wrote:
Add a SpMemDeviceInfo variant to MemoryDeviceInfo so
query-memory-devicesreports each sp-mem instance (id, addr, size, node, memdev), and print it from HMPinfo memory-devices.Signed-off-by FangSheng Huang <[email protected]>
Quoted 151 lines
--- 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@@ -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 +# +# @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@@ -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@@ -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[] = {
Re: [PATCH v13 02/10] qapi, hmp: introspection for the sp-mem device
In reply to fanhuangQuoted 19 lines · fanhuang
Add a SpMemDeviceInfo variant to MemoryDeviceInfo so
query-memory-devicesreports each sp-mem instance (id, addr, size, node, memdev), and print it from HMPinfo memory-devices.Signed-off-by FangSheng Huang <[email protected]>--- 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 +0
-0@@ -1413,6 +1413,32 @@ } }
qapi/machine.json line 1425
Quoted 10 lines
qapi/machine.json +10
-0+## +# @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
Is this bytes ? Please include the units in the comment.
Quoted 6 lines
qapi/machine.json +6
-0+# +# @node: NUMA proximity domain to which the device is assigned +# +# @memdev: memory backend linked with device +# +# Since: 11.1
qapi/machine.json line 1441
Quoted 10 lines
qapi/machine.json +10
-0+## +{ 'struct': 'SpMemDeviceInfo', + 'data': { '*id': 'str', + 'addr': 'size', + 'size': 'size', + 'node': 'int', + 'memdev': 'str' + } +} +
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com ~~ https://hachyderm.io/@berrange :| |: https://libvirt.org ~~ https://entangle-photo.org :| |: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|
Re: [PATCH v13 02/10] qapi, hmp: introspection for the sp-mem device
Quoted 20 lines · On Mon, 22 Jun 2026 13:55:10 +0100 Daniel P. Berrangé <[email protected]>…
Quoted 19 lines · fanhuang
Add a SpMemDeviceInfo variant to MemoryDeviceInfo so
query-memory-devicesreports each sp-mem instance (id, addr, size, node, memdev), and print it from HMPinfo memory-devices.Signed-off-by FangSheng Huang <[email protected]>--- 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 +0
-0@@ -1413,6 +1413,32 @@ } }
Quoted 12 lines
qapi/machine.json line 1425
Quoted 10 lines
qapi/machine.json +10
-0+## +# @SpMemDeviceInfo: +# +# sp-mem device state information +# +# @id: device's ID +# +# @addr: physical address, where device is mapped +# +# @size: size of memory that the device providesIs this bytes ? Please include the units in the comment.
we don't do that with any of memory devices,
given it's QAPI - I guess bytes are implied for 'size' type (i.e. no suffix massaging)
Quoted 19 lines
Quoted 6 lines
qapi/machine.json +6
-0+# +# @node: NUMA proximity domain to which the device is assigned +# +# @memdev: memory backend linked with device +# +# Since: 11.1qapi/machine.json line 1441
Quoted 10 lines
qapi/machine.json +10
-0+## +{ 'struct': 'SpMemDeviceInfo', + 'data': { '*id': 'str', + 'addr': 'size', + 'size': 'size', + 'node': 'int', + 'memdev': 'str' + } +} +With regards,
Daniel
Re: [PATCH v13 02/10] qapi, hmp: introspection for the sp-mem device
Quoted 36 lines · Igor Mammedov
Quoted 20 lines · On Mon, 22 Jun 2026 13:55:10 +0100 Daniel P. Berrangé <[email protected]>…
Quoted 19 lines · fanhuang
Add a SpMemDeviceInfo variant to MemoryDeviceInfo so
query-memory-devicesreports each sp-mem instance (id, addr, size, node, memdev), and print it from HMPinfo memory-devices.Signed-off-by FangSheng Huang <[email protected]>--- 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 +0
-0@@ -1413,6 +1413,32 @@ } }Quoted 12 lines
qapi/machine.json line 1425
Quoted 10 lines
qapi/machine.json +10
-0+## +# @SpMemDeviceInfo: +# +# sp-mem device state information +# +# @id: device's ID +# +# @addr: physical address, where device is mapped +# +# @size: size of memory that the device providesIs this bytes ? Please include the units in the comment.
Quoted 3 lines
we don't do that with any of memory devices,
given it's QAPI - I guess bytes are implied for 'size' type (i.e. no suffix massaging)
The trouble with "implied" is that it relies on the reader being familiar with QEMU's normal practice. Perhaps passable for regular QEMU maintainers, but not good for app developers/users consuming QEMU. It doesn't take much to add "in bytes" to these comments to make it clear.
Although we don't do it universally/consistently, we do have quite a few examples:
$ git grep 'in bytes' | wc -l 95
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com ~~ https://hachyderm.io/@berrange :| |: https://libvirt.org ~~ https://entangle-photo.org :| |: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|
PATCH v13 3/10 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 | 96 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 92 insertions(+), 4 deletions(-)
hw/i386/acpi-build.c +92 -4
@@ -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
PATCH v13 4/10 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 | 36 ++++++++++++++++++++++++++++++++++++ hw/i386/Kconfig | 2 ++ 3 files changed, 44 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 +36 -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"
@@ -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
@@ -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 v13 04/10] hw/i386: hook sp-mem into the pc machine plug path
Quoted 58 lines · On Fri, 19 Jun 2026 19:11:30 +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]>Reviewed-by Igor Mammedov <[email protected]>--- 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@@ -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 +9
-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" @@ -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,
hw/i386/pc.c static void pc_hv_balloon_plug(HotplugHandler *hotplug_dev, · line 1306
Quoted 10 lines
hw/i386/pc.c +10
-0+"'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)
^^^ fix indent
Quoted 59 lines
hw/i386/pc.c +17
-0+{ +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@@ -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
PATCH v13 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
@@ -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
PATCH v13 6/10 tests/acpi: add empty expected blobs for sp-mem SRAT test
In reply to fanhuangAdd 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
@@ -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
tests/data/acpi/x86/q35/SRAT.spmem new file +0 -0
Signature · 1 line
2.34.1
Re: [PATCH v13 06/10] tests/acpi: add empty expected blobs for sp-mem SRAT test
Quoted 4 lines · On Fri, 19 Jun 2026 19:11:32 +0800 fanhuang <[email protected]> wrote:
Add empty SRAT.spmem and DSDT.spmem stubs and list them in
bios-tables-test-allowed-diff.h.Signed-off-by FangSheng Huang <[email protected]>
Quoted 22 lines
--- 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.spmemtests/qtest/bios-tables-test-allowed-diff.h +2
-0@@ -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
-0tests/data/acpi/x86/q35/SRAT.spmem new file +0
-0
PATCH v13 7/10 tests/acpi: add bios-tables-test case for sp-mem
In reply to fanhuangAdd 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
@@ -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
Re: [PATCH v13 07/10] tests/acpi: add bios-tables-test case for sp-mem
Quoted 6 lines · On Fri, 19 Jun 2026 19:11:33 +0800 fanhuang <[email protected]> wrote:
Add a q35 bios-tables-test case that boots two sp-mem devices on distinct NUMA nodes within the
device_memorywindow, exercising the per-kind SRAT partition (per-device ENABLED entries plus HOTPLUGGABLE placeholders for the remaining sub-ranges).Signed-off-by FangSheng Huang <[email protected]>
Quoted 43 lines
--- tests/qtest/bios-tables-test.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)tests/qtest/bios-tables-test.c +21
-0@@ -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);
PATCH v13 8/10 tests/acpi: generate expected blobs for sp-mem SRAT test
In reply to fanhuangPopulate 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
@@ -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
tests/data/acpi/x86/q35/SRAT.spmem binary +0 -0
Signature · 1 line
2.34.1
Re: [PATCH v13 08/10] tests/acpi: generate expected blobs for sp-mem SRAT test
Quoted 10 lines · On Fri, 19 Jun 2026 19:11:34 +0800 fanhuang <[email protected]> wrote:
Populate the expected ACPI blobs for the sp-mem test and clear the allowed-diff list.
SRAT memory-affinity entries for the
device_memorywindow (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)
Quoted 8 lines
Each sp-mem device gets an ENABLED entry at its own proximity domain; the remaining
device_memorywindow 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.)
Signed-off-by FangSheng Huang <[email protected]>
Quoted 106 lines
--- 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@@ -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
-0zcmcgyO>7&-6`tjfv|3UUDXnB%c5K3S(lkjEN^+c_KWWHa{#jg^Ch4DI4R9q{t>mQ0 z!m*1ufdN?o633@Htb_K(7z)r^d&;#2dTDRIH9${2^pa~)#HXm=o7s_PNE(O^DG$qe zv+sLvzM0wic4yaZx$Q5XW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V zNkFT_S2%rILG{W#EN;@<1uLaUP;MkQV&JP3fBQ_LQEfE&B<%}=P8xDQJQ(X?eE9D zoMnD^8PlP)*qIth7|>XhPj#lugcY;E1lFrhKOW-@?;qN?U&0J9r3s{ey-%5hk(;8 z?r(7>nMu-Jccy&!GTrHBmgi^{q0mMpYNERg4+a}7h3t(g@F+>7@px;^DZ=r3JbEZ zNCkg;$!?XOI3J_?`C9W_%nGb@#!2ub{_P*X5~noeNoNh(<-(5Kxgs4LI=Cjo!_2u7 zmCJOf(4lJj+ozU_E*c{)|2UqBh*R|Na?qNo7y%2If$4UIUBUnH7$4P>-r4hes7XB3 zDk#%R9;c6q{OyH$qm5NY#7>~UupVKXP4UfG;}zq*_<M2FJif&vFFI$vJxmhb0~kC~ zVe-cx$C-H|!*5ZxpKZ3Cz2>Blh#tLo?2vbFpo2X+B4ZI7ovjG4v%>6r+kbDl%!h MvBJ}12_H=T4{{!rhyVZpliteral 0
HcmV?d00001tests/data/acpi/x86/q35/SRAT.spmem binary +0
-0
PATCH v13 9/10 tests/qtest: add e820 fw_cfg test
In reply to fanhuangAdd 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
@@ -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
@@ -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
Re: [PATCH v13 09/10] tests/qtest: add e820 fw_cfg test
Quoted 6 lines · On Fri, 19 Jun 2026 19:11:35 +0800 fanhuang <[email protected]> wrote:
Add a qtest that reads the "etc/e820"
fw_cfgtable 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, noSOFT_RESERVEDrange.Signed-off-by FangSheng Huang <[email protected]>
Quoted 119 lines
--- tests/qtest/e820-test.c | 95 +++++++++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 1 + 2 files changed, 96 insertions(+) create mode 100644 tests/qtest/e820-test.ctests/qtest/e820-test.c new file +95
-0@@ -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@@ -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'] : []) + \
PATCH v13 10/10 tests/qtest: cover sp-mem SOFT_RESERVED e820 entry
In reply to fanhuangBoot 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
@@ -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
Re: [PATCH v13 10/10] tests/qtest: cover sp-mem SOFT_RESERVED e820 entry
Quoted 5 lines · On Fri, 19 Jun 2026 19:11:36 +0800 fanhuang <[email protected]> wrote:
Boot one sp-mem device and assert the guest's e820 table gains exactly one
E820_SOFT_RESERVEDrange whose length matches the device's backend size.Signed-off-by FangSheng Huang <[email protected]>
Quoted 61 lines
--- tests/qtest/e820-test.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)tests/qtest/e820-test.c +34
-0@@ -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 (); }