Skip to content

Commit 5349b00

Browse files
committed
Merge branch 'acpi-tables'
Merge updates related to the handling of static (data-only) ACPI tables for 6.16-rc1: - Add __nonstring annotations for unterminated strings in the static ACPI tables parsing code (Kees Cook). - Add support for parsing the MRRM ACPI table and sysfs files to describe memory regions listed in it (Tony Luck, Anil Keshavamurthy). - Remove an (explicitly) unused header file include from the VIOT ACPI table parser file (Andy Shevchenko). - Improve logging around acpi_initialize_tables() (Bartosz Szczepanek). * acpi-tables: ACPI: MRRM: Fix default max memory region ACPI: tables: Improve logging around acpi_initialize_tables() ACPI: VIOT: Remove (explicitly) unused header ACPI: Add documentation for exposing MRRM data ACPI: MRRM: Add /sys files to describe memory ranges ACPI: MRRM: Minimal parse of ACPI MRRM table ACPI: tables: Add __nonstring annotations for unterminated strings
2 parents 57356d9 + 059717c commit 5349b00

File tree

8 files changed

+225
-3
lines changed

8 files changed

+225
-3
lines changed

Documentation/ABI/testing/sysfs-firmware-acpi

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,24 @@ Description:
248248
# cat ff_pwr_btn
249249
7 enabled
250250

251+
What: /sys/firmware/acpi/memory_ranges/rangeX
252+
Date: February 2025
253+
Contact: Tony Luck <[email protected]>
254+
Description:
255+
On systems with the ACPI MRRM table reports the parameters for
256+
each range.
257+
258+
base: Starting system physical address.
259+
260+
length: Length of this range in bytes.
261+
262+
node: NUMA node that this range belongs to. Negative numbers
263+
indicate that the node number could not be determined (e.g
264+
for an address range that is reserved for future hot add of
265+
memory).
266+
267+
local_region_id: ID associated with access by agents
268+
local to this range of addresses.
269+
270+
remote_region_id: ID associated with access by agents
271+
non-local to this range of addresses.

arch/x86/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ config X86_64
3838
select ARCH_HAS_ELFCORE_COMPAT
3939
select ZONE_DMA32
4040
select EXECMEM if DYNAMIC_FTRACE
41+
select ACPI_MRRM if ACPI
4142

4243
config FORCE_DYNAMIC_FTRACE
4344
def_bool y

drivers/acpi/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,9 @@ config ACPI_FFH
576576
Enable this feature if you want to set up and install the FFH Address
577577
Space handler to handle FFH OpRegion in the firmware.
578578

579+
config ACPI_MRRM
580+
bool
581+
579582
source "drivers/acpi/pmic/Kconfig"
580583

581584
config ACPI_VIOT

drivers/acpi/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ acpi-$(CONFIG_ACPI_WATCHDOG) += acpi_watchdog.o
6666
acpi-$(CONFIG_ACPI_PRMT) += prmt.o
6767
acpi-$(CONFIG_ACPI_PCC) += acpi_pcc.o
6868
acpi-$(CONFIG_ACPI_FFH) += acpi_ffh.o
69+
acpi-$(CONFIG_ACPI_MRRM) += acpi_mrrm.o
6970

7071
# Address translation
7172
acpi-$(CONFIG_ACPI_ADXL) += acpi_adxl.o

drivers/acpi/acpi_mrrm.c

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Copyright (c) 2025, Intel Corporation.
4+
*
5+
* Memory Range and Region Mapping (MRRM) structure
6+
*
7+
* Parse and report the platform's MRRM table in /sys.
8+
*/
9+
10+
#define pr_fmt(fmt) "acpi/mrrm: " fmt
11+
12+
#include <linux/acpi.h>
13+
#include <linux/init.h>
14+
#include <linux/string.h>
15+
#include <linux/sysfs.h>
16+
17+
/* Default assume one memory region covering all system memory, per the spec */
18+
static int max_mem_region = 1;
19+
20+
/* Access for use by resctrl file system */
21+
int acpi_mrrm_max_mem_region(void)
22+
{
23+
return max_mem_region;
24+
}
25+
26+
struct mrrm_mem_range_entry {
27+
u64 base;
28+
u64 length;
29+
int node;
30+
u8 local_region_id;
31+
u8 remote_region_id;
32+
};
33+
34+
static struct mrrm_mem_range_entry *mrrm_mem_range_entry;
35+
static u32 mrrm_mem_entry_num;
36+
37+
static int get_node_num(struct mrrm_mem_range_entry *e)
38+
{
39+
unsigned int nid;
40+
41+
for_each_online_node(nid) {
42+
for (int z = 0; z < MAX_NR_ZONES; z++) {
43+
struct zone *zone = NODE_DATA(nid)->node_zones + z;
44+
45+
if (!populated_zone(zone))
46+
continue;
47+
if (zone_intersects(zone, PHYS_PFN(e->base), PHYS_PFN(e->length)))
48+
return zone_to_nid(zone);
49+
}
50+
}
51+
52+
return -ENOENT;
53+
}
54+
55+
static __init int acpi_parse_mrrm(struct acpi_table_header *table)
56+
{
57+
struct acpi_mrrm_mem_range_entry *mre_entry;
58+
struct acpi_table_mrrm *mrrm;
59+
void *mre, *mrrm_end;
60+
int mre_count = 0;
61+
62+
mrrm = (struct acpi_table_mrrm *)table;
63+
if (!mrrm)
64+
return -ENODEV;
65+
66+
if (mrrm->flags & ACPI_MRRM_FLAGS_REGION_ASSIGNMENT_OS)
67+
return -EOPNOTSUPP;
68+
69+
mrrm_end = (void *)mrrm + mrrm->header.length - 1;
70+
mre = (void *)mrrm + sizeof(struct acpi_table_mrrm);
71+
while (mre < mrrm_end) {
72+
mre_entry = mre;
73+
mre_count++;
74+
mre += mre_entry->header.length;
75+
}
76+
if (!mre_count) {
77+
pr_info(FW_BUG "No ranges listed in MRRM table\n");
78+
return -EINVAL;
79+
}
80+
81+
mrrm_mem_range_entry = kmalloc_array(mre_count, sizeof(*mrrm_mem_range_entry),
82+
GFP_KERNEL | __GFP_ZERO);
83+
if (!mrrm_mem_range_entry)
84+
return -ENOMEM;
85+
86+
mre = (void *)mrrm + sizeof(struct acpi_table_mrrm);
87+
while (mre < mrrm_end) {
88+
struct mrrm_mem_range_entry *e;
89+
90+
mre_entry = mre;
91+
e = mrrm_mem_range_entry + mrrm_mem_entry_num;
92+
93+
e->base = mre_entry->addr_base;
94+
e->length = mre_entry->addr_len;
95+
e->node = get_node_num(e);
96+
97+
if (mre_entry->region_id_flags & ACPI_MRRM_VALID_REGION_ID_FLAGS_LOCAL)
98+
e->local_region_id = mre_entry->local_region_id;
99+
else
100+
e->local_region_id = -1;
101+
if (mre_entry->region_id_flags & ACPI_MRRM_VALID_REGION_ID_FLAGS_REMOTE)
102+
e->remote_region_id = mre_entry->remote_region_id;
103+
else
104+
e->remote_region_id = -1;
105+
106+
mrrm_mem_entry_num++;
107+
mre += mre_entry->header.length;
108+
}
109+
110+
max_mem_region = mrrm->max_mem_region;
111+
112+
return 0;
113+
}
114+
115+
#define RANGE_ATTR(name, fmt) \
116+
static ssize_t name##_show(struct kobject *kobj, \
117+
struct kobj_attribute *attr, char *buf) \
118+
{ \
119+
struct mrrm_mem_range_entry *mre; \
120+
const char *kname = kobject_name(kobj); \
121+
int n, ret; \
122+
\
123+
ret = kstrtoint(kname + 5, 10, &n); \
124+
if (ret) \
125+
return ret; \
126+
\
127+
mre = mrrm_mem_range_entry + n; \
128+
\
129+
return sysfs_emit(buf, fmt, mre->name); \
130+
} \
131+
static struct kobj_attribute name##_attr = __ATTR_RO(name)
132+
133+
RANGE_ATTR(base, "0x%llx\n");
134+
RANGE_ATTR(length, "0x%llx\n");
135+
RANGE_ATTR(node, "%d\n");
136+
RANGE_ATTR(local_region_id, "%d\n");
137+
RANGE_ATTR(remote_region_id, "%d\n");
138+
139+
static struct attribute *memory_range_attrs[] = {
140+
&base_attr.attr,
141+
&length_attr.attr,
142+
&node_attr.attr,
143+
&local_region_id_attr.attr,
144+
&remote_region_id_attr.attr,
145+
NULL
146+
};
147+
148+
ATTRIBUTE_GROUPS(memory_range);
149+
150+
static __init int add_boot_memory_ranges(void)
151+
{
152+
struct kobject *pkobj, *kobj;
153+
int ret = -EINVAL;
154+
char *name;
155+
156+
pkobj = kobject_create_and_add("memory_ranges", acpi_kobj);
157+
158+
for (int i = 0; i < mrrm_mem_entry_num; i++) {
159+
name = kasprintf(GFP_KERNEL, "range%d", i);
160+
if (!name)
161+
break;
162+
163+
kobj = kobject_create_and_add(name, pkobj);
164+
165+
ret = sysfs_create_groups(kobj, memory_range_groups);
166+
if (ret)
167+
return ret;
168+
}
169+
170+
return ret;
171+
}
172+
173+
static __init int mrrm_init(void)
174+
{
175+
int ret;
176+
177+
ret = acpi_table_parse(ACPI_SIG_MRRM, acpi_parse_mrrm);
178+
if (ret < 0)
179+
return ret;
180+
181+
return add_boot_memory_ranges();
182+
}
183+
device_initcall(mrrm_init);

drivers/acpi/tables.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ static u8 __init acpi_table_checksum(u8 *buffer, u32 length)
396396
}
397397

398398
/* All but ACPI_SIG_RSDP and ACPI_SIG_FACS: */
399-
static const char table_sigs[][ACPI_NAMESEG_SIZE] __initconst = {
399+
static const char table_sigs[][ACPI_NAMESEG_SIZE] __nonstring_array __initconst = {
400400
ACPI_SIG_BERT, ACPI_SIG_BGRT, ACPI_SIG_CPEP, ACPI_SIG_ECDT,
401401
ACPI_SIG_EINJ, ACPI_SIG_ERST, ACPI_SIG_HEST, ACPI_SIG_MADT,
402402
ACPI_SIG_MSCT, ACPI_SIG_SBST, ACPI_SIG_SLIT, ACPI_SIG_SRAT,
@@ -719,8 +719,12 @@ int __init acpi_locate_initial_tables(void)
719719
}
720720

721721
status = acpi_initialize_tables(initial_tables, ACPI_MAX_TABLES, 0);
722-
if (ACPI_FAILURE(status))
722+
if (ACPI_FAILURE(status)) {
723+
const char *msg = acpi_format_exception(status);
724+
725+
pr_warn("Failed to initialize tables, status=0x%x (%s)", status, msg);
723726
return -EINVAL;
727+
}
724728

725729
return 0;
726730
}

drivers/acpi/viot.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
#define pr_fmt(fmt) "ACPI: VIOT: " fmt
2020

2121
#include <linux/acpi_viot.h>
22-
#include <linux/fwnode.h>
2322
#include <linux/iommu.h>
2423
#include <linux/list.h>
2524
#include <linux/pci.h>
2625
#include <linux/platform_device.h>
26+
#include <linux/property.h>
2727

2828
struct viot_iommu {
2929
/* Node offset within the table */

include/linux/acpi.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,10 @@ int acpi_get_local_u64_address(acpi_handle handle, u64 *addr);
772772
int acpi_get_local_address(acpi_handle handle, u32 *addr);
773773
const char *acpi_get_subsystem_id(acpi_handle handle);
774774

775+
#ifdef CONFIG_ACPI_MRRM
776+
int acpi_mrrm_max_mem_region(void);
777+
#endif
778+
775779
#else /* !CONFIG_ACPI */
776780

777781
#define acpi_disabled 1
@@ -1092,6 +1096,11 @@ static inline acpi_handle acpi_get_processor_handle(int cpu)
10921096
return NULL;
10931097
}
10941098

1099+
static inline int acpi_mrrm_max_mem_region(void)
1100+
{
1101+
return 1;
1102+
}
1103+
10951104
#endif /* !CONFIG_ACPI */
10961105

10971106
#ifdef CONFIG_ACPI_HMAT

0 commit comments

Comments
 (0)