Skip to contentSkip to conversation

Fix hmat_adist_nb for CXL

PATCH Applied [email protected] 4 participants 6 messages Jul 16 – Sep 18 ACPI

lore
Share & tools
lore
#0 lore raw

v2 cover Fix hmat_adist_nb for CXL

From: Alejandro Lucero <[email protected]>

v2:
- Add Fixes (Richarg Cheng)
- Change commit as fix for Type2/Type3 (Richar Cheng)

RFC
===
While working on adding CXL Type2 support I found a problem with register_mt_adistance_algorithm() which is used inside cxl_region_probe(). It turns out my kernel config had not CONFIG_MEMORY_HOTPLUG enabled leading to the hmat_adist_nb notifier block deleted after kernel initialization without doing any notifer block unregister, leaving the notifier chain unaware of this. A CXL Type2 driver can be load after kernel initialization and with a kernel not enabling memory hotplug, the notifier registration crashes if the released memory from hmat_adist_nb is reused.

I'm not sure but I do not think this can happen for Type3 devices because the related CXL driver is used only during kernel initialization if memory hotplug not enabled. Type2, aka CXL accelerator drivers, is coming and the problem will arise with certainty.

I have contemplated to modify how the identified __meminit and __meminitdat are defined in linux/init.h, extending the case for being empty definitions if CONFIG_CXL_MEM=y, but I think it makes sense to only avoid the use of __meminit for hmat_adist_nb.

FWIW, a Type2 device should not require CONFIG_MEMORY_HOTPLUG and its memory is currently initialized by the BIOS. Maybe not having memory hotplug enabled is unusual and even more with CXL, so another option could be to enable memory hotplug if CXL mem is enabled.

Alejandro Lucero (1):
acpi/hmat: preserve hmat_adist_nb notifier block

 drivers/acpi/numa/hmat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

base-commit: 8cd9520d35a6c38db6567e97dd93b1f11f185dc6

Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/1 acpi/hmat: preserve hmat_adist_nb notifier block

From: Alejandro Lucero <[email protected]>

Remove __meminitdata from hmat_adist_nb declaration preserving it even when CONFIG_MEMORY_HOTPLUG is not set. Otherwise further notifier registrations using register_mt_adistance_algorithm() will find a notifier chain likely corrupted.

This is the case when cxl_region_probe() calls register_mt_adistance_algorithm() what can happen when CXL regions are dynamically created at any time from Type3 device(s) or when a Type2 device is initialized at its driver probe.

Fixes 3718c02dbd4c ("acpi, hmat: calculate abstract distance with HMAT")
---
 drivers/acpi/numa/hmat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/numa/hmat.c +1 -1
index 9792dc394756..3006789ae31f 100644
@@ -995,7 +995,7 @@ static int hmat_calculate_adistance(struct notifier_block *self,
 	return NOTIFY_STOP;
 }
 
-static struct notifier_block hmat_adist_nb __meminitdata = {
+static struct notifier_block hmat_adist_nb = {
 	.notifier_call = hmat_calculate_adistance,
 	.priority = 100,
 };
Signature · 1 line
2.34.1
Reviewed-by on v2 1/1
#2 lore raw

Re: [PATCH v2 1/1] acpi/hmat: preserve hmat_adist_nb notifier block

Quoted 7 lines · On 7/16/26 11:11 AM, [email protected] wrote:

From: Alejandro Lucero <[email protected]>

Remove __meminitdata from hmat_adist_nb declaration preserving it even when CONFIG_MEMORY_HOTPLUG is not set. Otherwise further notifier registrations using register_mt_adistance_algorithm() will find a notifier chain likely corrupted.

Quoted 8 lines

This is the case when cxl_region_probe() calls register_mt_adistance_algorithm() what can happen when CXL regions are dynamically created at any time from Type3 device(s) or when a Type2 device is initialized at its driver probe.

Fixes 3718c02dbd4c ("acpi, hmat: calculate abstract distance with HMAT")
Quoted 17 lines
---
 drivers/acpi/numa/hmat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/numa/hmat.c +1 -1
index 9792dc394756..3006789ae31f 100644
@@ -995,7 +995,7 @@ static int hmat_calculate_adistance(struct notifier_block *self,
 	return NOTIFY_STOP;
 }
 
-static struct notifier_block hmat_adist_nb __meminitdata = {
+static struct notifier_block hmat_adist_nb = {
 	.notifier_call = hmat_calculate_adistance,
 	.priority = 100,
 };
Reviewed-by
#3 lore raw

Re: [PATCH v2 1/1] acpi/hmat: preserve hmat_adist_nb notifier block

Quoted 8 lines · On Thu, 16 Jul 2026 13:27:56 -0700 Dave Jiang <[email protected]> wrote:
Quoted 7 lines · On 7/16/26 11:11 AM, [email protected] wrote:

From: Alejandro Lucero <[email protected]>

Remove __meminitdata from hmat_adist_nb declaration preserving it even when CONFIG_MEMORY_HOTPLUG is not set. Otherwise further notifier registrations using register_mt_adistance_algorithm() will find a notifier chain likely corrupted.

Quoted 7 lines
Quoted 7 lines

This is the case when cxl_region_probe() calls register_mt_adistance_algorithm() what can happen when CXL regions are dynamically created at any time from Type3 device(s) or when a Type2 device is initialized at its driver probe.

Fixes 3718c02dbd4c ("acpi, hmat: calculate abstract distance with HMAT")

This will trip some of the checker scripts that run on various trees. No blank lines in a commit tag block. I guess who ever picks this up can tidy that up though rather than needing a v2.

Quoted 3 lines
Quoted 1 line

Seems sensible to me.

Quoted 21 lines
Quoted 19 lines

---
 drivers/acpi/numa/hmat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/numa/hmat.c +1 -1
index 9792dc394756..3006789ae31f 100644
@@ -995,7 +995,7 @@ static int hmat_calculate_adistance(struct notifier_block *self,
 	return NOTIFY_STOP;
 }
 
-static struct notifier_block hmat_adist_nb __meminitdata = {
+static struct notifier_block hmat_adist_nb = {
 	.notifier_call = hmat_calculate_adistance,
 	.priority = 100,
 };  
maintainer Applied
#4 lore raw

Re: [PATCH v2 1/1] acpi/hmat: preserve hmat_adist_nb notifier block

In reply to Dave Jiang
Quoted 16 lines · Dave Jiang
Quoted 12 lines · On 7/16/26 11:11 AM, [email protected] wrote:

From: Alejandro Lucero <[email protected]>

Remove __meminitdata from hmat_adist_nb declaration preserving it even when CONFIG_MEMORY_HOTPLUG is not set. Otherwise further notifier registrations using register_mt_adistance_algorithm() will find a notifier chain likely corrupted.

This is the case when cxl_region_probe() calls register_mt_adistance_algorithm() what can happen when CXL regions are dynamically created at any time from Type3 device(s) or when a Type2 device is initialized at its driver probe.

Quoted 5 lines
Quoted 3 lines
Fixes 3718c02dbd4c ("acpi, hmat: calculate abstract distance with HMAT")

Applied as 7.4 material, thanks!

Quoted 18 lines
Quoted 17 lines
---
 drivers/acpi/numa/hmat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/numa/hmat.c +1 -1
index 9792dc394756..3006789ae31f 100644
@@ -995,7 +995,7 @@ static int hmat_calculate_adistance(struct notifier_block *self,
      return NOTIFY_STOP;
 }
 
-static struct notifier_block hmat_adist_nb __meminitdata = {
+static struct notifier_block hmat_adist_nb = {
      .notifier_call = hmat_calculate_adistance,
      .priority = 100,
 };
#5 lore raw
In reply to [email protected]

Hi Rafael,

Just a reminder of this fix which, if not applied, could trigger problems for the CXL Type2 drivers recently merged in net-next: https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=997bfb05c919d2c5ee77c594d354f6c61b99ccdf

As stated in the commit after comments from Richard, this could also be a problem for current Type3 CXL kernel support depending on kernel configuration.

Let me know if you see any problem with this fix.

Thank you.

Quoted 41 lines · On 7/16/26 19:11, [email protected] wrote:

From: Alejandro Lucero <[email protected]>

v2:
- Add Fixes (Richarg Cheng)
- Change commit as fix for Type2/Type3 (Richar Cheng)

RFC
===
While working on adding CXL Type2 support I found a problem with register_mt_adistance_algorithm() which is used inside cxl_region_probe(). It turns out my kernel config had not CONFIG_MEMORY_HOTPLUG enabled leading to the hmat_adist_nb notifier block deleted after kernel initialization without doing any notifer block unregister, leaving the notifier chain unaware of this. A CXL Type2 driver can be load after kernel initialization and with a kernel not enabling memory hotplug, the notifier registration crashes if the released memory from hmat_adist_nb is reused.

I'm not sure but I do not think this can happen for Type3 devices because the related CXL driver is used only during kernel initialization if memory hotplug not enabled. Type2, aka CXL accelerator drivers, is coming and the problem will arise with certainty.

I have contemplated to modify how the identified __meminit and __meminitdat are defined in linux/init.h, extending the case for being empty definitions if CONFIG_CXL_MEM=y, but I think it makes sense to only avoid the use of __meminit for hmat_adist_nb.

FWIW, a Type2 device should not require CONFIG_MEMORY_HOTPLUG and its memory is currently initialized by the BIOS. Maybe not having memory hotplug enabled is unusual and even more with CXL, so another option could be to enable memory hotplug if CXL mem is enabled.

Alejandro Lucero (1):
acpi/hmat: preserve hmat_adist_nb notifier block

  drivers/acpi/numa/hmat.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

base-commit: 8cd9520d35a6c38db6567e97dd93b1f11f185dc6