cxl, acpi/hmat, node: Update CXL access coordinates to node directly
Subsystems (5)
Dave Jiang
maintainerv2 cover cxl, acpi/hmat, node: Update CXL access coordinates to node directly
I plan to take this series through the CXL tree when all the necessary tags are received.
Rafael, please ack patches 3/4 and 4/4 if you are happy with the changes.
Thank you!
v2:
- Use clearer comment from DavidH for 1/4. (DavidH)
- Fix comment in 2/4. (DavidH)
- Streamline code in 2/4. (DavidH)
- Add description to observed issue. (Dan)
- Add correct Fixes tag. (Dan)
- Add cc to stable for fix patch. (Dan)
- Add mechansim to only update on first region for the node. (Jonathan)
The series aim to clean up the current CXL memory region hotplug notifier by removing the update path through HMAT and updating the node access coordinates directly. With the existing implementation, the CXL memory hotplug notifier gets called first. It updates the HMAT target access coordinates. And then the HMAT notifier gets called and create the node sysfs attribs. The new implemenation flips the callback ordering and directly updates the sysfs attribs already created in the node and leaves HMAT data structures alone.
Dave Jiang (4):
mm/memory_hotplug: Update comment for hotplug memory callback
priorities
drivers/base/node: Add a helper function node_update_perf_attrs() cxl, acpi/hmat: Update CXL access coordinates directly instead of
through HMAT
acpi/hmat: Remove now unused hmat_update_target_coordinates()
drivers/acpi/numa/hmat.c | 34 ---------------------------------- drivers/base/node.c | 38 ++++++++++++++++++++++++++++++++++++++ drivers/cxl/core/cdat.c | 11 ----------- drivers/cxl/core/core.h | 3 --- drivers/cxl/core/region.c | 21 +++++++++++++-------- include/linux/acpi.h | 12 ------------ include/linux/memory.h | 6 +++--- include/linux/node.h | 8 ++++++++ 8 files changed, 62 insertions(+), 71 deletions(-)
base-commit: 8f5ae30d69d7543eee0d70083daf4de8fe15d585
Signature · 1 line
2.50.1
Dave Jiang
maintainerPATCH v2 1/4 mm/memory_hotplug: Update comment for hotplug memory callback priorities
Add clarification to comment for memory hotplug callback ordering as the current comment does not provide clear language on which callback happens first.
---
v2:
- Clearer comment suggestion from DavidH.
--- include/linux/memory.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/memory.h +2 -2
@@ -115,8 +115,8 @@ struct notifier_block;struct mem_section ;/* -* Priorities for the hotplug memory callback routines (stored in decreasing -* order in the callback chain) +* Priorities for the hotplug memory callback routines. Invoked from +* high to low. Higher priorities corresponds to higher numbers. */ #define DEFAULT_CALLBACK_PRI 0#define SLAB_CALLBACK_PRI 1
Signature · 1 line
2.50.1
Re: [PATCH v2 1/4] mm/memory_hotplug: Update comment for hotplug memory callback priorities
Quoted 18 lines · Dave Jiang
Add clarification to comment for memory hotplug callback ordering as the current comment does not provide clear language on which callback happens first.
Signed-off-by Dave Jiang <[email protected]>---
v2:
- Clearer comment suggestion from DavidH.--- include/linux/memory.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)include/linux/memory.h +0
-0
include/linux/memory.h struct notifier_block; · line 119
Quoted 7 lines
include/linux/memory.h +2
-2@@ -115,8 +115,8 @@ struct notifier_block;struct mem_section ;/* -* Priorities for the hotplug memory callback routines (stored in decreasing -* order in the callback chain) +* Priorities for the hotplug memory callback routines. Invoked from +* high to low. Higher priorities corresponds to higher numbers.
Minor nit: s/corresponds/correspond/
Signature · 3 lines
Cheers David / dhildenb
Jonathan Cameron
Reviewed-byRe: [PATCH v2 1/4] mm/memory_hotplug: Update comment for hotplug memory callback priorities
Quoted 21 lines · On Thu, 21 Aug 2025 23:17:38 +0200 David Hildenbrand <[email protected]> wrote:
Quoted 20 lines · Dave Jiang
Add clarification to comment for memory hotplug callback ordering as the current comment does not provide clear language on which callback happens first.
Signed-off-by Dave Jiang <[email protected]>---
v2:
- Clearer comment suggestion from DavidH.--- include/linux/memory.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)include/linux/memory.h +0
-0@@ -115,8 +115,8 @@ struct notifier_block;struct mem_section ;
Quoted 7 lines
include/linux/memory.h struct notifier_block; · line 119
Quoted 5 lines
include/linux/memory.h +2
-2/* -* Priorities for the hotplug memory callback routines (stored in decreasing -* order in the callback chain) +* Priorities for the hotplug memory callback routines. Invoked from +* high to low. Higher priorities corresponds to higher numbers. Minor nit: s/corresponds/correspond/
With that tidied up
Quoted 1 line
Dave Jiang
maintainerPATCH v2 2/4 drivers/base/node: Add a helper function node_update_perf_attrs()
In reply to Dave JiangAdd helper function node_update_perf_attrs() to allow update of node access coordinates computed by an external agent such as CXL. The helper allows updating of coordinates after the attribute being created by HMAT.
---
v2:
- Remove extra word in comment. (DavidH)
- Streamline code branching. (DavidH)
--- drivers/base/node.c | 38 ++++++++++++++++++++++++++++++++++++++ include/linux/node.h | 8 ++++++++ 2 files changed, 46 insertions(+)
drivers/base/node.c +38 -0
@@ -248,6 +248,44 @@ void node_set_perf_attrs(unsigned int nid, struct access_coordinate *coord, }EXPORT_SYMBOL_GPL (node_set_perf_attrs); +/** +* node_update_perf_attrs - Update the performance values for given access class +* @nid: Node identifier to be updated +* @coord: Heterogeneous memory performance coordinates +* @access: The access class for the given attributes +*/ +void node_update_perf_attrs (unsigned int nid,struct access_coordinate *coord, +enum access_coordinate_class access) +{ +struct node_access_nodes *access_node; +struct node *node; +int i; + +if (WARN_ON_ONCE (!node_online (nid))) +return ; + + node = node_devices[nid]; +list_for_each_entry (access_node, &node->access_list, list_node) { +if (access_node->access != access) +continue ; + + access_node->coord = *coord; +for (i =0 ; access_attrs[i]; i++) { +sysfs_notify (&access_node->dev.kobj, +NULL , access_attrs[i]->name); + } +break ; + } + +/* When setting CPU access coordinates, update mempolicy */ +if (access !=ACCESS_COORDINATE_CPU ) +return ; + +if (mempolicy_set_node_perf (nid, coord)) +pr_info ("failed to set mempolicy attrs for node %d\n" , nid); +} +EXPORT_SYMBOL_GPL (node_update_perf_attrs); +/** * struct node_cache_info - Internal tracking for memory node caches * @dev: Device represeting the cache level
include/linux/node.h +8 -0
@@ -85,6 +85,8 @@ struct node_cache_attrs {void node_add_cache (unsigned int nid,struct node_cache_attrs *cache_attrs);void node_set_perf_attrs (unsigned int nid,struct access_coordinate *coord,enum access_coordinate_class access); +void node_update_perf_attrs (unsigned int nid,struct access_coordinate *coord, +enum access_coordinate_class access);#else static inline void node_add_cache (unsigned int nid,struct node_cache_attrs *cache_attrs)
@@ -96,6 +98,12 @@ static inline void node_set_perf_attrs(unsigned int nid, enum access_coordinate_class access) { } + +static inline void node_update_perf_attrs (unsigned int nid, +struct access_coordinate *coord, +enum access_coordinate_class access) +{ +}#endif struct node {
Signature · 1 line
2.50.1
Dave Jiang
maintainerPATCH v2 3/4 cxl, acpi/hmat: Update CXL access coordinates directly instead of through HMAT
In reply to Dave JiangThe current implementation of CXL memory hotplug notifier gets called before the HMAT memory hotplug notifier. The CXL driver calculates the access coordinates (bandwidth and latency values) for the CXL end to end path (i.e. CPU to endpoint). When the CXL region is onlined, the CXL memory hotplug notifier writes the access coordinates to the HMAT target structs. Then the HMAT memory hotplug notifier is called and it creates the access coordinates for the node sysfs attributes.
During testing on an Intel platform, it was found that although the newly calculated coordinates were pushed to sysfs, the sysfs attributes for the access coordinates showed up with the wrong initiator. The system has 4 nodes (0, 1, 2, 3) where node 0 and 1 are CPU nodes and node 2 and 3 are CXL nodes. The expectation is that node 2 would show up as a target to node 0:/sys/devices/system/node/node2/access0/initiators/node0
However it was observed that node 2 showed up as a target under node 1:/sys/devices/system/node/node2/access0/initiators/node1
The original intent of the 'ext_updated' flag in HMAT handling code was to stop HMAT memory hotplug callback from clobbering the access coordinates after CXL has injected its calculated coordinates and replaced the generic target access coordinates provided by the HMAT table in the HMAT target structs. However the flag is hacky at best and blocks the updates from other CXL regions that are onlined in the same node later on. Remove the 'ext_updated' flag usage and just update the access coordinates for the nodes directly without touching HMAT target data.
The hotplug memory callback ordering is changed. Instead of changing CXL, move HMAT back so there's room for the levels rather than have CXL share the same level as SLAB_CALLBACK_PRI. The change will resulting in the CXL callback to be executed after the HMAT callback.
With the change, the CXL hotplug memory notifier runs after the HMAT callback. The HMAT callback will create the node sysfs attributes for access coordinates. The CXL callback will write the access coordinates to the now created node sysfs attributes directly and will not pollute the HMAT target values.
---
v2:
- Add description to what was observed for the issue. (Dan)
- Use the correct Fixes tag. (Dan)
- Add Cc to stable. (Dan)
- Add support to only update on first region appearance. (Jonathan)
--- drivers/acpi/numa/hmat.c | 6 ------ drivers/cxl/core/cdat.c | 5 ----- drivers/cxl/core/core.h | 1 - drivers/cxl/core/region.c | 21 +++++++++++++-------- include/linux/memory.h | 2 +- 5 files changed, 14 insertions(+), 21 deletions(-)
drivers/acpi/numa/hmat.c +0 -6
@@ -74,7 +74,6 @@ struct memory_target {struct node_cache_attrs cache_attrs;u8 gen_port_device_handle[ACPI_SRAT_DEVICE_HANDLE_SIZE ];bool registered; -bool ext_updated;/* externally updated */ };struct memory_initiator {
@@ -391,7 +390,6 @@ int hmat_update_target_coordinates(int nid, struct access_coordinate *coord, coord->read_bandwidth, access);hmat_update_target_access (target,ACPI_HMAT_WRITE_BANDWIDTH , coord->write_bandwidth, access); - target->ext_updated = true;return 0 ; }
@@ -773,10 +771,6 @@ static void hmat_update_target_attrs(struct memory_target *target,u32 best =0 ;int i; -/* Don't update if an external agent has changed the data. */ -if (target->ext_updated) -return ; -/* Don't update for generic port if there's no device handle */ if ((access == NODE_ACCESS_CLASS_GENPORT_SINK_LOCAL || access == NODE_ACCESS_CLASS_GENPORT_SINK_CPU) &&
drivers/cxl/core/cdat.c +0 -5
@@ -1081,8 +1081,3 @@ int cxl_update_hmat_access_coordinates(int nid, struct cxl_region *cxlr, {return hmat_update_target_coordinates (nid, &cxlr->coord[access], access); } - -bool cxl_need_node_perf_attrs_update (int nid) -{ -return !acpi_node_backed_by_real_pxm (nid); -}
drivers/cxl/core/core.h +0 -1
@@ -139,7 +139,6 @@ long cxl_pci_get_latency(struct pci_dev *pdev);int cxl_pci_get_bandwidth (struct pci_dev *pdev,struct access_coordinate *c);int cxl_update_hmat_access_coordinates (int nid,struct cxl_region *cxlr,enum access_coordinate_class access); -bool cxl_need_node_perf_attrs_update (int nid);int cxl_port_get_switch_dport_bandwidth (struct cxl_port *port,struct access_coordinate *c);
drivers/cxl/core/region.c +13 -8
@@ -9,6 +9,7 @@#include <linux/uuid.h> #include <linux/sort.h> #include <linux/idr.h> +#include <linux/xarray.h> #include <linux/memory-tiers.h> #include <cxlmem.h> #include <cxl.h>
@@ -30,6 +31,9 @@* 3. Decoder targets */ +/* xarray that stores the reference count per node for regions */ +static DEFINE_XARRAY (node_regions_xa); +static struct cxl_region *to_cxl_region (struct device *dev);#define __ACCESS_ATTR_RO (_level, _name) { \
@@ -2442,14 +2446,8 @@ static bool cxl_region_update_coordinates(struct cxl_region *cxlr, int nid)for (int i =0 ; i <ACCESS_COORDINATE_MAX ; i++) {if (cxlr->coord[i].read_bandwidth) { - rc =0 ; -if (cxl_need_node_perf_attrs_update (nid)) -node_set_perf_attrs (nid, &cxlr->coord[i], i); -else - rc =cxl_update_hmat_access_coordinates (nid, cxlr, i); - -if (rc ==0 ) - cset++; +node_update_perf_attrs (nid, &cxlr->coord[i], i); + cset++; } }
@@ -2475,6 +2473,7 @@ static int cxl_region_perf_attrs_callback(struct notifier_block *nb,struct node_notify *nn = arg;int nid = nn->nid;int region_nid; +int rc;if (action !=NODE_ADDED_FIRST_MEMORY )return NOTIFY_DONE ;
@@ -2487,6 +2486,11 @@ static int cxl_region_perf_attrs_callback(struct notifier_block *nb,if (nid != region_nid)return NOTIFY_DONE ; +/* No action needed if there's existing entry */ + rc =xa_insert (&node_regions_xa, nid,NULL ,GFP_KERNEL ); +if (rc <0 ) +return NOTIFY_DONE ; +if (!cxl_region_update_coordinates (cxlr, nid))return NOTIFY_DONE ;
@@ -3638,6 +3642,7 @@ int cxl_region_init(void)void cxl_region_exit (void ) { +xa_destroy (&node_regions_xa);cxl_driver_unregister (&cxl_region_driver); }
include/linux/memory.h +1 -1
@@ -120,8 +120,8 @@ struct mem_section;*/ #define DEFAULT_CALLBACK_PRI 0#define SLAB_CALLBACK_PRI 1 -#define HMAT_CALLBACK_PRI 2#define CXL_CALLBACK_PRI 5 +#define HMAT_CALLBACK_PRI 6#define MM_COMPUTE_BATCH_PRI 10#define CPUSET_CALLBACK_PRI 10#define MEMTIER_HOTPLUG_PRI 100
Signature · 1 line
2.50.1
Re: [PATCH v2 3/4] cxl, acpi/hmat: Update CXL access coordinates directly instead of through HMAT
Quoted 44 lines · On Wed, 20 Aug 2025 12:47:03 -0700 Dave Jiang <[email protected]> wrote:
The current implementation of CXL memory hotplug notifier gets called before the HMAT memory hotplug notifier. The CXL driver calculates the access coordinates (bandwidth and latency values) for the CXL end to end path (i.e. CPU to endpoint). When the CXL region is onlined, the CXL memory hotplug notifier writes the access coordinates to the HMAT target structs. Then the HMAT memory hotplug notifier is called and it creates the access coordinates for the node sysfs attributes.
During testing on an Intel platform, it was found that although the newly calculated coordinates were pushed to sysfs, the sysfs attributes for the access coordinates showed up with the wrong initiator. The system has 4 nodes (0, 1, 2, 3) where node 0 and 1 are CPU nodes and node 2 and 3 are CXL nodes. The expectation is that node 2 would show up as a target to node 0:
/sys/devices/system/node/node2/access0/initiators/node0However it was observed that node 2 showed up as a target under node 1:
/sys/devices/system/node/node2/access0/initiators/node1The original intent of the '
ext_updated' flag in HMAT handling code was to stop HMAT memory hotplug callback from clobbering the access coordinates after CXL has injected its calculated coordinates and replaced the generic target access coordinates provided by the HMAT table in the HMAT target structs. However the flag is hacky at best and blocks the updates from other CXL regions that are onlined in the same node later on. Remove the 'ext_updated' flag usage and just update the access coordinates for the nodes directly without touching HMAT target data.The hotplug memory callback ordering is changed. Instead of changing CXL, move HMAT back so there's room for the levels rather than have CXL share the same level as
SLAB_CALLBACK_PRI. The change will resulting in the CXL callback to be executed after the HMAT callback.With the change, the CXL hotplug memory notifier runs after the HMAT callback. The HMAT callback will create the node sysfs attributes for access coordinates. The CXL callback will write the access coordinates to the now created node sysfs attributes directly and will not pollute the HMAT target values.
Fixes 067353a46d8c ("cxl/region: Add memory hotplug notifier for cxl region")Tested-by Marc Herbert <[email protected]>Reviewed-by Dan Williams <[email protected]>Signed-off-by Dave Jiang <[email protected]>
Quoted 6 lines
---
v2:
- Add description to what was observed for the issue. (Dan)
- Use the correct Fixes tag. (Dan)
- Add Cc to stable. (Dan)
- Add support to only update on first region appearance. (Jonathan)
The implementation of this seems like overkill. See later, but in short should be able to use a nodemask_t
Quoted 13 lines
drivers/cxl/core/region.c +1
-0@@ -9,6 +9,7 @@#include <linux/uuid.h> #include <linux/sort.h> #include <linux/idr.h> +#include <linux/xarray.h> #include <linux/memory-tiers.h> #include <cxlmem.h> #include <cxl.h>
drivers/cxl/core/region.c line 34
Quoted 4 lines
drivers/cxl/core/region.c +1
-0@@ -30,6 +31,9 @@* 3. Decoder targets */ +/* xarray that stores the reference count per node for regions */
Reference count seems an over the top description.
I think it's just a flag that says if this happened already or not. The term reference count would kind of suggest it would count regions present.
So perhaps a comment along the lines of
/* xarray that stores if a region has previously been seen in a node */ and rename to node_region_seen_xa.
However, can we just use a bitmap sized to MAX_NUMNODES which is a nodemask_t which gives us the helpers nodemask.h
Quoted 31 lines
drivers/cxl/core/region.c +5
-8+static DEFINE_XARRAY (node_regions_xa); +static struct cxl_region *to_cxl_region (struct device *dev);#define __ACCESS_ATTR_RO (_level, _name) { \@@ -2442,14 +2446,8 @@ static bool cxl_region_update_coordinates(struct cxl_region *cxlr, int nid)for (int i =0 ; i <ACCESS_COORDINATE_MAX ; i++) {if (cxlr->coord[i].read_bandwidth) { - rc =0 ; -if (cxl_need_node_perf_attrs_update (nid)) -node_set_perf_attrs (nid, &cxlr->coord[i], i); -else - rc =cxl_update_hmat_access_coordinates (nid, cxlr, i); - -if (rc ==0 ) - cset++; +node_update_perf_attrs (nid, &cxlr->coord[i], i); + cset++; } }@@ -2475,6 +2473,7 @@ static int cxl_region_perf_attrs_callback(struct notifier_block *nb,struct node_notify *nn = arg;int nid = nn->nid;int region_nid; +int rc;if (action !=NODE_ADDED_FIRST_MEMORY )return NOTIFY_DONE ;
drivers/cxl/core/region.c static int cxl_region_perf_attrs_callback(struct notifier_block *nb, · line 2490
Quoted 5 lines
drivers/cxl/core/region.c +2
-0@@ -2487,6 +2486,11 @@ static int cxl_region_perf_attrs_callback(struct notifier_block *nb,if (nid != region_nid)return NOTIFY_DONE ; +/* No action needed if there's existing entry */ + rc =xa_insert (&node_regions_xa, nid,NULL ,GFP_KERNEL );
So this is using the NULL entry quirk of xa_insert() where a reserved entry is put in place so next time we match.
Quoted 13 lines
drivers/cxl/core/region.c +4
-0+if (rc <0 ) +return NOTIFY_DONE ; +if (!cxl_region_update_coordinates (cxlr, nid))return NOTIFY_DONE ;@@ -3638,6 +3642,7 @@ int cxl_region_init(void)void cxl_region_exit (void ) { +xa_destroy (&node_regions_xa);cxl_driver_unregister (&cxl_region_driver); }
Dave Jiang
maintainerPATCH v2 4/4 acpi/hmat: Remove now unused hmat_update_target_coordinates()
In reply to Dave JiangRemove deadcode since CXL no longer calls hmat_update_target_coordinates().
--- drivers/acpi/numa/hmat.c | 28 ---------------------------- drivers/cxl/core/cdat.c | 6 ------ drivers/cxl/core/core.h | 2 -- include/linux/acpi.h | 12 ------------ 4 files changed, 48 deletions(-)
drivers/acpi/numa/hmat.c +0 -28
@@ -367,34 +367,6 @@ static void hmat_update_target_access(struct memory_target *target, } } -int hmat_update_target_coordinates (int nid,struct access_coordinate *coord, -enum access_coordinate_class access) -{ -struct memory_target *target; -int pxm; - -if (nid ==NUMA_NO_NODE ) -return -EINVAL ; - - pxm =node_to_pxm (nid); -guard (mutex)(&target_lock); - target =find_mem_target (pxm); -if (!target) -return -ENODEV ; - -hmat_update_target_access (target,ACPI_HMAT_READ_LATENCY , - coord->read_latency, access); -hmat_update_target_access (target,ACPI_HMAT_WRITE_LATENCY , - coord->write_latency, access); -hmat_update_target_access (target,ACPI_HMAT_READ_BANDWIDTH , - coord->read_bandwidth, access); -hmat_update_target_access (target,ACPI_HMAT_WRITE_BANDWIDTH , - coord->write_bandwidth, access); - -return 0 ; -} -EXPORT_SYMBOL_GPL (hmat_update_target_coordinates); -static __init void hmat_add_locality (struct acpi_hmat_locality *hmat_loc) {struct memory_locality *loc;
drivers/cxl/core/cdat.c +0 -6
@@ -1075,9 +1075,3 @@ void cxl_region_perf_data_calculate(struct cxl_region *cxlr, cxlr->coord[i].write_bandwidth += perf->coord[i].write_bandwidth; } } - -int cxl_update_hmat_access_coordinates (int nid,struct cxl_region *cxlr, -enum access_coordinate_class access) -{ -return hmat_update_target_coordinates (nid, &cxlr->coord[access], access); -}
drivers/cxl/core/core.h +0 -2
@@ -137,8 +137,6 @@ enum cxl_poison_trace_type {long cxl_pci_get_latency (struct pci_dev *pdev);int cxl_pci_get_bandwidth (struct pci_dev *pdev,struct access_coordinate *c); -int cxl_update_hmat_access_coordinates (int nid,struct cxl_region *cxlr, -enum access_coordinate_class access);int cxl_port_get_switch_dport_bandwidth (struct cxl_port *port,struct access_coordinate *c);
include/linux/acpi.h +0 -12
@@ -1595,18 +1595,6 @@ static inline void acpi_use_parent_companion(struct device *dev)ACPI_COMPANION_SET (dev,ACPI_COMPANION (dev->parent)); } -#ifdef CONFIG_ACPI_HMAT -int hmat_update_target_coordinates (int nid,struct access_coordinate *coord, -enum access_coordinate_class access); -#else -static inline int hmat_update_target_coordinates (int nid, -struct access_coordinate *coord, -enum access_coordinate_class access) -{ -return -EOPNOTSUPP ; -} -#endif -#ifdef CONFIG_ACPI_NUMA bool acpi_node_backed_by_real_pxm (int nid);#else
Signature · 1 line
2.50.1