public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] acpi/hmat: Fix lockdep warning for hmem_register_resource()
@ 2025-10-15 16:29 Dave Jiang
  2025-10-15 20:19 ` dan.j.williams
  0 siblings, 1 reply; 6+ messages in thread
From: Dave Jiang @ 2025-10-15 16:29 UTC (permalink / raw)
  To: nvdimm, linux-cxl, linux-acpi
  Cc: dan.j.williams, vishal.l.verma, ira.weiny, rafael

The following lockdep splat was observed while kernel auto-online a CXL
memory region:

======================================================
WARNING: possible circular locking dependency detected
6.17.0djtest+ #53 Tainted: G        W
------------------------------------------------------
systemd-udevd/3334 is trying to acquire lock:
ffffffff90346188 (hmem_resource_lock){+.+.}-{4:4}, at: hmem_register_resource+0x31/0x50

but task is already holding lock:
ffffffff90338890 ((node_chain).rwsem){++++}-{4:4}, at: blocking_notifier_call_chain+0x2e/0x70

which lock already depends on the new lock.
[..]
Chain exists of:
  hmem_resource_lock --> mem_hotplug_lock --> (node_chain).rwsem

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  rlock((node_chain).rwsem);
                               lock(mem_hotplug_lock);
                               lock((node_chain).rwsem);
  lock(hmem_resource_lock);

The lock ordering can cause potential deadlock. There are instances
where hmem_resource_lock is taken after (node_chain).rwsem, and vice
versa.

Remove registering of target devices from the hmat_callback(). By the
time the hmat hotplug notifier is being called, there should not be
hmem targets that still need to be registered.

Fixes: cf8741ac57ed ("ACPI: NUMA: HMAT: Register "soft reserved" memory as an "hmem" device")
Link: https://lore.kernel.org/nvdimm/68e46a09c2a07_2980100f3@dwillia2-mobl4.notmuch/
Suggested-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
---
v2:
- Drop target registering in hmat_callback instead. (Dan)
---
 drivers/acpi/numa/hmat.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/acpi/numa/hmat.c b/drivers/acpi/numa/hmat.c
index 5a36d57289b4..5084ae1688f6 100644
--- a/drivers/acpi/numa/hmat.c
+++ b/drivers/acpi/numa/hmat.c
@@ -874,7 +874,8 @@ static void hmat_register_target_devices(struct memory_target *target)
 	}
 }
 
-static void hmat_register_target(struct memory_target *target)
+static void hmat_register_target(struct memory_target *target,
+				 bool register_devices)
 {
 	int nid = pxm_to_node(target->memory_pxm);
 
@@ -882,7 +883,8 @@ static void hmat_register_target(struct memory_target *target)
 	 * Devices may belong to either an offline or online
 	 * node, so unconditionally add them.
 	 */
-	hmat_register_target_devices(target);
+	if (register_devices)
+		hmat_register_target_devices(target);
 
 	/*
 	 * Register generic port perf numbers. The nid may not be
@@ -921,7 +923,7 @@ static void hmat_register_targets(void)
 	struct memory_target *target;
 
 	list_for_each_entry(target, &targets, node)
-		hmat_register_target(target);
+		hmat_register_target(target, true);
 }
 
 static int hmat_callback(struct notifier_block *self,
@@ -939,7 +941,7 @@ static int hmat_callback(struct notifier_block *self,
 	if (!target)
 		return NOTIFY_OK;
 
-	hmat_register_target(target);
+	hmat_register_target(target, false);
 	return NOTIFY_OK;
 }
 

base-commit: 3a8660878839faadb4f1a6dd72c3179c1df56787
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-10-16 21:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-15 16:29 [PATCH v2] acpi/hmat: Fix lockdep warning for hmem_register_resource() Dave Jiang
2025-10-15 20:19 ` dan.j.williams
2025-10-15 20:21   ` Dave Jiang
2025-10-16 17:39   ` Dave Jiang
2025-10-16 19:06     ` dan.j.williams
2025-10-16 21:12       ` Dave Jiang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox