Add interfaces for ACPI MRRM table
v5 cover Add interfaces for ACPI MRRM table
This series based on:
https://web.git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git/log/?h=testing
Memory used to be homogeneous. Then NUMA came along. Later different types of memory (persistent memory, on-package high bandwidth memory, CXL attached memory).
Each type of memory has its own performance characteristics, and users will need to monitor and control access by type.
The MRRM solution is to tag physical address ranges with "region IDs" so that platform firmware[1] can indicate the type of memory for each range (with separate tags available for local vs. remote access to each range). Note that these ranges can include addresses reserved for future hotplugged memory.
The region IDs will be used to provide separate event counts for each region for "perf" and for the "resctrl" file system to monitor and control memory bandwidth in each region.
Users will need to know the address range(s) that are part of each region. This patch series adds
/sys/firmware/acpi/memory_ranges/rangeX
directories to provide user space accessible enumeration.
-Tony
[1] MRRM definition allow for future expansion for the OS to assign these region IDs.
Changes since version 4 here:
https://lore.kernel.org/all/[email protected]/
*) Dropped patch 1. ACPICA changes have been merged into the linux-pm
tree.
*) Removed spurious blank file from mrrm_init() (Thanks, Fenghua).
Tony Luck (3):
ACPI/MRRM: Minimal parse of ACPI MRRM table ACPI/MRRM: Add /sys files to describe memory ranges
ACPI: Add documentation for exposing MRRM data
include/linux/acpi.h | 9 + drivers/acpi/acpi_mrrm.c | 182 ++++++++++++++++++ Documentation/ABI/testing/sysfs-firmware-acpi | 21 ++ arch/x86/Kconfig | 1 + drivers/acpi/Kconfig | 3 + drivers/acpi/Makefile | 1 + 6 files changed, 217 insertions(+) create mode 100644 drivers/acpi/acpi_mrrm.c
base-repo: git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git
base-branch: testing
base-commit: 70cb3b9a371fe9ff4f50cd7889763abd4ab621dc
Signature · 1 line
2.48.1
PATCH v5 1/3 ACPI/MRRM: Minimal parse of ACPI MRRM table
The resctrl file system code needs to know how many region tags are supported. Parse the ACPI MRRM table and save the max_mem_region value.
Provide a function for resctrl to collect that value.
--- include/linux/acpi.h | 9 +++++++++ drivers/acpi/acpi_mrrm.c | 42 ++++++++++++++++++++++++++++++++++++++++ arch/x86/Kconfig | 1 + drivers/acpi/Kconfig | 3 +++ drivers/acpi/Makefile | 1 + 5 files changed, 56 insertions(+) create mode 100644 drivers/acpi/acpi_mrrm.c
include/linux/acpi.h +9 -0
@@ -772,6 +772,10 @@ int acpi_get_local_u64_address(acpi_handle handle, u64 *addr);int acpi_get_local_address (acpi_handle handle,u32 *addr);const char *acpi_get_subsystem_id (acpi_handle handle); +#ifdef CONFIG_ACPI_MRRM +int acpi_mrrm_max_mem_region (void ); +#endif +#else /* !CONFIG_ACPI */ #define acpi_disabled 1
@@ -1092,6 +1096,11 @@ static inline acpi_handle acpi_get_processor_handle(int cpu) return NULL; } +static inline int acpi_mrrm_max_mem_region (void ) +{ +return -ENOENT ; +} +#endif /* !CONFIG_ACPI */ #ifdef CONFIG_ACPI_HMAT
drivers/acpi/acpi_mrrm.c new file +42 -0
42 lines not on this page · raw message
arch/x86/Kconfig +1 -0
@@ -38,6 +38,7 @@ config X86_64 select ARCH_HAS_ELFCORE_COMPAT select ZONE_DMA32 select EXECMEM if DYNAMIC_FTRACE + select ACPI_MRRM if ACPI config FORCE_DYNAMIC_FTRACE def_bool y
drivers/acpi/Kconfig +3 -0
@@ -576,6 +576,9 @@ config ACPI_FFH Enable this feature if you want to set up and install the FFH Address Space handler to handle FFH OpRegion in the firmware. +config ACPI_MRRM + bool + source "drivers/acpi/pmic/Kconfig" config ACPI_VIOT
drivers/acpi/Makefile +1 -0
@@ -66,6 +66,7 @@ acpi-$(CONFIG_ACPI_WATCHDOG) += acpi_watchdog.o acpi-$(CONFIG_ACPI_PRMT) += prmt.o acpi-$(CONFIG_ACPI_PCC) += acpi_pcc.o acpi-$(CONFIG_ACPI_FFH) += acpi_ffh.o +acpi-$(CONFIG_ACPI_MRRM) += acpi_mrrm.o # Address translation acpi-$(CONFIG_ACPI_ADXL) += acpi_adxl.o
Signature · 1 line
2.48.1
A message that is not in the archive (sent off-list or not yet received): [email protected]
RE: [PATCH v5 1/3] ACPI/MRRM: Minimal parse of ACPI MRRM table
Quoted 28 lines
drivers/acpi/acpi_mrrm.c new file +13
-0@@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2025, Intel Corporation. +* +* Memory Range and Region Mapping (MRRM) structure +*/ + +#define pr_fmt (fmt) "acpi/mrrm: " fmt + +#include <linux/acpi.h> +#include <linux/init.h> + +static int max_mem_region = -ENOENT ;This should be initialized to 1 instead of -ENOENT(-2).
Per the spec, sec 5.1, if platform does not define MRRM, it says, SW may assume that only one memory region is defined.drivers/acpi/acpi_mrrm.c new file +6
-0+ +/* Access for use by resctrl file system */ +int acpi_mrrm_max_mem_region (void ) +{ +return max_mem_region; +}
Quoted 2 lines
In which case this function will return a minimum of 1 region as
max_mem_regionof -2 has no meaning. When resctrl file system calls this function, it expects at least one region exists.
[Replying to HTML e-mail that will have been dropped from LKML and other lists]
Anil,
Rafael has this queued for next merge window. Please send a patch to fix the issues you found.
Thanks
-Tony
PATCH v5 2/3 ACPI/MRRM: Add /sys files to describe memory ranges
In reply to Tony LuckPerf and resctrl users need an enumeration of which memory addresses are bound to which "region" tag.
Parse the ACPI MRRM table and add /sys entries for each memory range describing base address, length, NUMA node, and which region tags apply for same-socket and cross-socket access.
--- drivers/acpi/acpi_mrrm.c | 142 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 141 insertions(+), 1 deletion(-)
drivers/acpi/acpi_mrrm.c +141 -1
@@ -3,12 +3,16 @@* Copyright (c) 2025, Intel Corporation. * * Memory Range and Region Mapping (MRRM) structure +* +* Parse and report the platform's MRRM table in /sys. */ #define pr_fmt (fmt) "acpi/mrrm: " fmt#include <linux/acpi.h> #include <linux/init.h> +#include <linux/string.h> +#include <linux/sysfs.h> static int max_mem_region = -ENOENT ;
@@ -18,25 +22,161 @@ int acpi_mrrm_max_mem_region(void)return max_mem_region; } +struct mrrm_mem_range_entry { +u64 base; +u64 length; +int node; +u8 local_region_id; +u8 remote_region_id; +}; + +static struct mrrm_mem_range_entry *mrrm_mem_range_entry; +static u32 mrrm_mem_entry_num; + +static int get_node_num (struct mrrm_mem_range_entry *e) +{ +unsigned int nid; + +for_each_online_node (nid) { +for (int z =0 ; z <MAX_NR_ZONES ; z++) { +struct zone *zone =NODE_DATA (nid)->node_zones + z; + +if (!populated_zone (zone)) +continue ; +if (zone_intersects (zone,PHYS_PFN (e->base),PHYS_PFN (e->length))) +return zone_to_nid (zone); + } + } + +return -ENOENT ; +} +static __init int acpi_parse_mrrm (struct acpi_table_header *table) { +struct acpi_mrrm_mem_range_entry *mre_entry;struct acpi_table_mrrm *mrrm; +void *mre, *mrrm_end; +int mre_count =0 ; mrrm = (struct acpi_table_mrrm *)table;if (!mrrm)return -ENODEV ; +if (mrrm->flags &ACPI_MRRM_FLAGS_REGION_ASSIGNMENT_OS ) +return -EOPNOTSUPP ; + + mrrm_end = (void *)mrrm + mrrm->header.length -1 ; + mre = (void *)mrrm +sizeof (struct acpi_table_mrrm ); +while (mre < mrrm_end) { + mre_entry = mre; + mre_count++; + mre += mre_entry->header.length; + } +if (!mre_count) { +pr_info (FW_BUG "No ranges listed in MRRM table\n" ); +return -EINVAL ; + } + + mrrm_mem_range_entry =kmalloc_array (mre_count,sizeof (*mrrm_mem_range_entry), +GFP_KERNEL | __GFP_ZERO); +if (!mrrm_mem_range_entry) +return -ENOMEM ; + + mre = (void *)mrrm +sizeof (struct acpi_table_mrrm ); +while (mre < mrrm_end) { +struct mrrm_mem_range_entry *e; + + mre_entry = mre; + e = mrrm_mem_range_entry + mrrm_mem_entry_num; + + e->base = mre_entry->addr_base; + e->length = mre_entry->addr_len; + e->node =get_node_num (e); + +if (mre_entry->region_id_flags &ACPI_MRRM_VALID_REGION_ID_FLAGS_LOCAL ) + e->local_region_id = mre_entry->local_region_id; +else + e->local_region_id =-1 ; +if (mre_entry->region_id_flags &ACPI_MRRM_VALID_REGION_ID_FLAGS_REMOTE ) + e->remote_region_id = mre_entry->remote_region_id; +else + e->remote_region_id =-1 ; + + mrrm_mem_entry_num++; + mre += mre_entry->header.length; + } + max_mem_region = mrrm->max_mem_region;return 0 ; } +#define RANGE_ATTR (name, fmt) \ +static ssize_t name##_show(struct kobject *kobj, \ + struct kobj_attribute *attr, char *buf) \ +{ \ + struct mrrm_mem_range_entry *mre; \ + const char *kname = kobject_name(kobj); \ + int n, ret; \ + \ + ret = kstrtoint(kname + 5, 10, &n); \ + if (ret) \ + return ret; \ + \ + mre = mrrm_mem_range_entry + n; \ + \ + return sysfs_emit(buf, fmt, mre->name); \ +} \ +static struct kobj_attribute name##_attr = __ATTR_RO(name) + +RANGE_ATTR (base,"0x%llx\n" ); +RANGE_ATTR (length,"0x%llx\n" ); +RANGE_ATTR (node,"%d\n" ); +RANGE_ATTR (local_region_id,"%d\n" ); +RANGE_ATTR (remote_region_id,"%d\n" ); + +static struct attribute *memory_range_attrs[] = { + &base_attr.attr, + &length_attr.attr, + &node_attr.attr, + &local_region_id_attr.attr, + &remote_region_id_attr.attr, +NULL +}; + +ATTRIBUTE_GROUPS (memory_range); + +static __init int add_boot_memory_ranges (void ) +{ +struct kobject *pkobj, *kobj; +int ret = -EINVAL ; +char *name; + + pkobj =kobject_create_and_add ("memory_ranges" , acpi_kobj); + +for (int i =0 ; i < mrrm_mem_entry_num; i++) { + name =kasprintf (GFP_KERNEL ,"range%d" , i); +if (!name) +break ; + + kobj =kobject_create_and_add (name, pkobj); + + ret =sysfs_create_groups (kobj, memory_range_groups); +if (ret) +return ret; + } + +return ret; +} +static __init int mrrm_init (void ) {int ret; ret =acpi_table_parse (ACPI_SIG_MRRM , acpi_parse_mrrm); +if (ret <0 ) +return ret; -return ret; +return add_boot_memory_ranges (); }device_initcall (mrrm_init);
Signature · 1 line
2.48.1
PATCH v5 3/3 ACPI: Add documentation for exposing MRRM data
In reply to Tony LuckInitial implementation provides enumeration of the address ranges NUMA node numbers, and BIOS assigned region IDs for each range.
--- Documentation/ABI/testing/sysfs-firmware-acpi | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+)
Documentation/ABI/testing/sysfs-firmware-acpi +21 -0
@@ -248,3 +248,24 @@ Description: # cat ff_pwr_btn 7 enabled +What: /sys/firmware/acpi/memory_ranges/rangeX +Date: February 2025 +Contact: Tony Luck <[email protected]> +Description: + On systems with the ACPI MRRM table reports the + parameters for each range. + + base: Starting system physical address. + + length: Length of this range in bytes. + + node: NUMA node that this range belongs to. Negative numbers + indicate that the node number could not be determined (e.g + for an address range that is reserved for future hot add of + memory). + + local_region_id: ID associated with access by agents + local to this range of addresses. + + remote_region_id: ID associated with access by agents + non-local to this range of addresses.
Signature · 1 line
2.48.1
Rafael J. Wysocki
maintainerQuoted 43 lines · Tony Luck
This series based on:
https://web.git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git/log/?h=testingMemory used to be homogeneous. Then NUMA came along. Later different types of memory (persistent memory, on-package high bandwidth memory, CXL attached memory).
Each type of memory has its own performance characteristics, and users will need to monitor and control access by type.
The MRRM solution is to tag physical address ranges with "region IDs" so that platform firmware[1] can indicate the type of memory for each range (with separate tags available for local vs. remote access to each range). Note that these ranges can include addresses reserved for future hotplugged memory.
The region IDs will be used to provide separate event counts for each region for "perf" and for the "resctrl" file system to monitor and control memory bandwidth in each region.
Users will need to know the address range(s) that are part of each region. This patch series adds
/sys/firmware/acpi/memory_ranges/rangeX
directories to provide user space accessible enumeration.-Tony
[1] MRRM definition allow for future expansion for the OS to assign these region IDs.
Changes since version 4 here:
https://lore.kernel.org/all/[email protected]/*) Dropped patch 1. ACPICA changes have been merged into the linux-pm
tree.
*) Removed spurious blank file frommrrm_init()(Thanks, Fenghua).Tony Luck (3):
ACPI/MRRM: Minimal parse of ACPI MRRM table ACPI/MRRM: Add /sys files to describe memory ranges
ACPI: Add documentation for exposing MRRM data
Quoted 9 lines
include/linux/acpi.h | 9 + drivers/acpi/acpi_mrrm.c | 182 ++++++++++++++++++ Documentation/ABI/testing/sysfs-firmware-acpi | 21 ++ arch/x86/Kconfig | 1 + drivers/acpi/Kconfig | 3 + drivers/acpi/Makefile | 1 + 6 files changed, 217 insertions(+) create mode 100644 drivers/acpi/acpi_mrrm.c
All patches applied as 6.16 material, thanks!