Skip to contentSkip to conversation

dax/kmem: account for partial dis-contiguous resource upon removal

PATCH Applied Davidlohr Bueso 3 participants 5 messages Feb 23 – Mar 11

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 dax/kmem: account for partial dis-contiguous resource upon removal

When dev_dax_kmem_probe() partially succeeds (at least one range is mapped) but a subsequent range fails request_mem_region() or add_memory_driver_managed(), the probe silently continues, ultimately returning success, but with the corresponding range resource NULL'ed out.

dev_dax_kmem_remove() iterates over all dax_device ranges regardless of if the underlying resource exists. When remove_memory() is called later, it returns 0 because the memory was never added which causes dev_dax_kmem_remove() to incorrectly assume the (nonexistent) resource can be removed and attempts cleanup on a NULL pointer.

Fix this by skipping these ranges altogether, noting that these cases are considered success, such that the cleanup is still reached when all actually-added ranges are successfully removed.

Fixes 60e93dc097f7 ("device-dax: add dis-contiguous resource support")

---
Changes from v1: reword some of the changelog (Ben)

 drivers/dax/kmem.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/dax/kmem.c +6 -0
index c036e4d0b610..edd62e68ffb7 100644
@@ -227,6 +227,12 @@ static void dev_dax_kmem_remove(struct dev_dax *dev_dax)
 		if (rc)
 			continue;
 
+		/* range was never added during probe */
+		if (!data->res[i]) {
+			success++;
+			continue;
+		}
+
 		rc = remove_memory(range.start, range_len(&range));
 		if (rc == 0) {
 			remove_resource(data->res[i]);
Signature · 1 line
2.39.5
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 11 lines · Davidlohr Bueso

When dev_dax_kmem_probe() partially succeeds (at least one range is mapped) but a subsequent range fails request_mem_region() or add_memory_driver_managed(), the probe silently continues, ultimately returning success, but with the corresponding range resource NULL'ed out.

dev_dax_kmem_remove() iterates over all dax_device ranges regardless of if the underlying resource exists. When remove_memory() is called later, it returns 0 because the memory was never added which causes dev_dax_kmem_remove() to incorrectly assume the (nonexistent) resource can be removed and attempts cleanup on a NULL pointer.

Do you have a failure signature w Call Trace to paste here? If not, maybe just insert the expected signature for grepping:
"BUG: unable to handle kernel NULL pointer dereference"

Quoted 35 lines

Fix this by skipping these ranges altogether, noting that these cases are considered success, such that the cleanup is still reached when all actually-added ranges are successfully removed.

Fixes 60e93dc097f7 ("device-dax: add dis-contiguous resource support")

---
Changes from v1: reword some of the changelog (Ben)

 drivers/dax/kmem.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/dax/kmem.c +6 -0
index c036e4d0b610..edd62e68ffb7 100644
@@ -227,6 +227,12 @@ static void dev_dax_kmem_remove(struct dev_dax *dev_dax)
 		if (rc)
 			continue;
 
+		/* range was never added during probe */
+		if (!data->res[i]) {
+			success++;
+			continue;
+		}
+
 		rc = remove_memory(range.start, range_len(&range));
 		if (rc == 0) {
 			remove_resource(data->res[i]);
Signature · 1 line
2.39.5
Reviewed-by
#2 lore raw
Quoted 13 lines · On Wed, 25 Feb 2026 21:01:08 -0800 Alison Schofield…
Quoted 11 lines · Davidlohr Bueso

When dev_dax_kmem_probe() partially succeeds (at least one range is mapped) but a subsequent range fails request_mem_region() or add_memory_driver_managed(), the probe silently continues, ultimately returning success, but with the corresponding range resource NULL'ed out.

dev_dax_kmem_remove() iterates over all dax_device ranges regardless of if the underlying resource exists. When remove_memory() is called later, it returns 0 because the memory was never added which causes dev_dax_kmem_remove() to incorrectly assume the (nonexistent) resource can be removed and attempts cleanup on a NULL pointer.

Quoted 5 lines

Do you have a failure signature w Call Trace to paste here? If not, maybe just insert the expected signature for grepping:
"BUG: unable to handle kernel NULL pointer dereference"

#3 lore raw
In reply to Alison Schofield
Quoted 1 line · Alison Schofield

Do you have a failure signature w Call Trace to paste here?

No, I have no splat, this was found while getting more acquianted with dax code while looking at dcd topics.

Quoted 2 lines

If not, maybe just insert the expected signature for grepping:
"BUG: unable to handle kernel NULL pointer dereference"

I don't think this doesn't really adds much to the changelog. Not worth a v2.

Thanks,
Davidlohr

#4 lore raw
In reply to Davidlohr Bueso

ping? Unless any concerns, can this be picked up?

Thanks,
Davidlohr

Quoted 45 lines · Davidlohr Bueso

When dev_dax_kmem_probe() partially succeeds (at least one range is mapped) but a subsequent range fails request_mem_region() or add_memory_driver_managed(), the probe silently continues, ultimately returning success, but with the corresponding range resource NULL'ed out.

dev_dax_kmem_remove() iterates over all dax_device ranges regardless of if the underlying resource exists. When remove_memory() is called later, it returns 0 because the memory was never added which causes dev_dax_kmem_remove() to incorrectly assume the (nonexistent) resource can be removed and attempts cleanup on a NULL pointer.

Fix this by skipping these ranges altogether, noting that these cases are considered success, such that the cleanup is still reached when all actually-added ranges are successfully removed.

Fixes 60e93dc097f7 ("device-dax: add dis-contiguous resource support")

---
Changes from v1: reword some of the changelog (Ben)

drivers/dax/kmem.c | 6 ++++++

1 file changed, 6 insertions(+)
drivers/dax/kmem.c +6 -0
index c036e4d0b610..edd62e68ffb7 100644
@@ -227,6 +227,12 @@ static void dev_dax_kmem_remove(struct dev_dax *dev_dax)
 		if (rc)
 			continue;
 
+		/* range was never added during probe */
+		if (!data->res[i]) {
+			success++;
+			continue;
+		}
+
 		rc = remove_memory(range.start, range_len(&range));
 		if (rc == 0) {
 			remove_resource(data->res[i]);
Signature · 1 line
2.39.5