Skip to contentSkip to conversation

cxl/region: Reject a repeat write of an endpoint decoder to targetN

PATCH Applied Alison Schofield 4 participants 9 messages Nov 3 – Nov 17 CXL

lore
Share & tools
lore

Alison Schofield

author maintainer
#0 lore raw

PATCH v4 1/2 cxl/region: Reject a repeat write of an endpoint decoder to targetN

Writing an endpoint decoder to a region targetN attribute that already holds it returns -EBUSY, but leaves the partially populated region in an inconsistent state. The targetN attribute still names the decoder, so the failed write gives no indication that the region was damaged.

Filling the remaining target positions can then trigger a NULL pointer dereference in cxl_region_setup_targets(). This can be reproduced through sysfs:

echo $decoder > /sys/bus/cxl/devices/region0/target0 echo $decoder > /sys/bus/cxl/devices/region0/target0 echo $other_decoder > /sys/bus/cxl/devices/region0/target1

An existing check recognizes the repeated assignment but incorrectly allows the attachment to proceed, damaging region state. Remove that check so the repeated write is rejected without disturbing the existing attachment, consistent with the documented targetN ABI.

Fixes 9995576cef48 ("cxl/region: Move region-position validation to a helper")

---

Note: cxl_region_perf_data_calculate() currently updates region performance data before attachment validation completes. This is a pre-existing issue that will be addressed separately.

Changes in v4:
- Drop the added useless check in cxl_region_attach() (Sashiko)
The pre-existing occupied position check already returns -EBUSY.
v3: https://lore.kernel.org/linux-cxl/3e5af9d6d59f8df52b9d21bcf1c7e78f06918f80.1793653629.git.alison.schofield@intel.com/

Changes in v3:
- Reject repeat writes with -EBUSY, consistent with the documented ABI
- Rebase on 7.4-rc1
v2: https://lore.kernel.org/linux-cxl/920d80735a449f93a1f17a8bca4c25e4b302cb42.1792989098.git.alison.schofield@intel.com/

Changes in v2:
- Preserve the successful no-op behavior for repeated writes (Jonathan)
- Correct the Fixes tag
v1: https://lore.kernel.org/linux-cxl/94e9157aac2e99df1251d733769d539b914fdefc.1790829690.git.alison.schofield@intel.com/

---
 drivers/cxl/core/region.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/cxl/core/region.c +0 -3
index a048bd5c06cb..f42c6b6e3213 100644
@@ -1764,9 +1764,6 @@ static int cxl_region_validate_position(struct cxl_region *cxlr,
 		return -ENXIO;
 	}
 
-	if (p->targets[pos] == cxled)
-		return 0;
-
 	if (p->targets[pos]) {
 		struct cxl_endpoint_decoder *cxled_target = p->targets[pos];
 		struct cxl_memdev *cxlmd_target = cxled_to_memdev(cxled_target);

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4

Signature · 1 line
2.37.3
author maintainer
#1 lore raw

PATCH v4 2/2 cxl/Documentation: Describe clearing a region targetN position

The region targetN ABI documents that writing to an occupied position returns EBUSY, but does not describe how to clear the position after assigning the wrong endpoint decoder.

Document how to clear a position by writing an empty string, how clearing a position decommits a committed region, and how the region can be committed again after all positions are filled.

---

Changes in v4:
- Minor wordsmithing in commit log
v3: https://lore.kernel.org/linux-cxl/e87248b8d13d3f07741243a45891365450c66881.1793653629.git.alison.schofield@intel.com/

Changes in v3:
- Restore the original entry text and append how to clear a position
v2: https://lore.kernel.org/linux-cxl/efa1a098550077dc3571796ba0102ddabe1e9b0d.1792989098.git.alison.schofield@intel.com/

Changes in v2:
- Say that writing the endpoint decoder already at a position succeeds
- Split the entry into paragraphs and drop the v1 error code reordering
v1: https://lore.kernel.org/linux-cxl/a007c751d88ee64c9d0b7bb3c69a486c42358b36.1790829690.git.alison.schofield@intel.com/

---
 Documentation/ABI/testing/sysfs-bus-cxl | 4 ++++
 1 file changed, 4 insertions(+)
Documentation/ABI/testing/sysfs-bus-cxl +4 -0
index 7352dbd70bc7..3629c983f05c 100644
@@ -568,6 +568,10 @@ Description:
 		not an endpoint decoder. Once all positions have been
 		successfully written a final validation for decode conflicts is
 		performed before activating the region.
+		To clear a position, for example to replace an endpoint
+		decoder, write an empty string (echo > targetX). Clearing
+		a position in a committed region also decommits the region.
+		It can be committed again after all positions are filled.
 
 
 What:		/sys/bus/cxl/devices/regionZ/commit
Signature · 1 line
2.37.3
maintainer Reviewed-by on v4 2/2
#2 lore raw

Re: [PATCH v4 2/2] cxl/Documentation: Describe clearing a region targetN position

Quoted 9 lines · Alison Schofield

The region targetN ABI documents that writing to an occupied position returns EBUSY, but does not describe how to clear the position after assigning the wrong endpoint decoder.

Document how to clear a position by writing an empty string, how clearing a position decommits a committed region, and how the region can be committed again after all positions are filled.

this change for the most part is unrelated to 1/2 right?

Quoted 33 lines

---

Changes in v4:
- Minor wordsmithing in commit log
v3: https://lore.kernel.org/linux-cxl/e87248b8d13d3f07741243a45891365450c66881.1793653629.git.alison.schofield@intel.com/

Changes in v3:
- Restore the original entry text and append how to clear a position
v2: https://lore.kernel.org/linux-cxl/efa1a098550077dc3571796ba0102ddabe1e9b0d.1792989098.git.alison.schofield@intel.com/

Changes in v2:
- Say that writing the endpoint decoder already at a position succeeds
- Split the entry into paragraphs and drop the v1 error code reordering
v1: https://lore.kernel.org/linux-cxl/a007c751d88ee64c9d0b7bb3c69a486c42358b36.1790829690.git.alison.schofield@intel.com/

---
 Documentation/ABI/testing/sysfs-bus-cxl | 4 ++++
 1 file changed, 4 insertions(+)
Documentation/ABI/testing/sysfs-bus-cxl +4 -0
index 7352dbd70bc7..3629c983f05c 100644
@@ -568,6 +568,10 @@ Description:
 		not an endpoint decoder. Once all positions have been
 		successfully written a final validation for decode conflicts is
 		performed before activating the region.
+		To clear a position, for example to replace an endpoint
+		decoder, write an empty string (echo > targetX). Clearing
+		a position in a committed region also decommits the region.
+		It can be committed again after all positions are filled.
 
 
 What:		/sys/bus/cxl/devices/regionZ/commit
author maintainer
#3 lore raw

Re: [PATCH v4 2/2] cxl/Documentation: Describe clearing a region targetN position

Quoted 11 lines · Dave Jiang
Quoted 8 lines · Alison Schofield

The region targetN ABI documents that writing to an occupied position returns EBUSY, but does not describe how to clear the position after assigning the wrong endpoint decoder.

Document how to clear a position by writing an empty string, how clearing a position decommits a committed region, and how the region can be committed again after all positions are filled.

Quoted 5 lines
Quoted 1 line

this change for the most part is unrelated to 1/2 right?

It is independent of 1/2, but related because both are about the same sysfs attribute.

With Patch 1 we've upheld the original ABI that writing to a position that is already occupied returns -EBUSY. It doesn't matter if you are writing the same decoder or a different one, if pos is occupied, you get -EBUSY!

So, with that, the user might ask, how do I make a change to a position? This patch gives them the directions. It always worked but just was never documented.

-- Alison

Quoted 35 lines
Quoted 34 lines

---

Changes in v4:
- Minor wordsmithing in commit log
v3: https://lore.kernel.org/linux-cxl/e87248b8d13d3f07741243a45891365450c66881.1793653629.git.alison.schofield@intel.com/

Changes in v3:
- Restore the original entry text and append how to clear a position
v2: https://lore.kernel.org/linux-cxl/efa1a098550077dc3571796ba0102ddabe1e9b0d.1792989098.git.alison.schofield@intel.com/

Changes in v2:
- Say that writing the endpoint decoder already at a position succeeds
- Split the entry into paragraphs and drop the v1 error code reordering
v1: https://lore.kernel.org/linux-cxl/a007c751d88ee64c9d0b7bb3c69a486c42358b36.1790829690.git.alison.schofield@intel.com/

---
 Documentation/ABI/testing/sysfs-bus-cxl | 4 ++++
 1 file changed, 4 insertions(+)
Documentation/ABI/testing/sysfs-bus-cxl +4 -0
index 7352dbd70bc7..3629c983f05c 100644
@@ -568,6 +568,10 @@ Description:
 		not an endpoint decoder. Once all positions have been
 		successfully written a final validation for decode conflicts is
 		performed before activating the region.
+		To clear a position, for example to replace an endpoint
+		decoder, write an empty string (echo > targetX). Clearing
+		a position in a committed region also decommits the region.
+		It can be committed again after all positions are filled.
 
 
 What:		/sys/bus/cxl/devices/regionZ/commit
maintainer Applied
#4 lore raw

Re: [PATCH v4 2/2] cxl/Documentation: Describe clearing a region targetN position

In reply to Alison Schofield
Quoted 9 lines · Alison Schofield

The region targetN ABI documents that writing to an occupied position returns EBUSY, but does not describe how to clear the position after assigning the wrong endpoint decoder.

Document how to clear a position by writing an empty string, how clearing a position decommits a committed region, and how the region can be committed again after all positions are filled.

Applied to cxl/next:
726d9be5f09e

Quoted 33 lines

---

Changes in v4:
- Minor wordsmithing in commit log
v3: https://lore.kernel.org/linux-cxl/e87248b8d13d3f07741243a45891365450c66881.1793653629.git.alison.schofield@intel.com/

Changes in v3:
- Restore the original entry text and append how to clear a position
v2: https://lore.kernel.org/linux-cxl/efa1a098550077dc3571796ba0102ddabe1e9b0d.1792989098.git.alison.schofield@intel.com/

Changes in v2:
- Say that writing the endpoint decoder already at a position succeeds
- Split the entry into paragraphs and drop the v1 error code reordering
v1: https://lore.kernel.org/linux-cxl/a007c751d88ee64c9d0b7bb3c69a486c42358b36.1790829690.git.alison.schofield@intel.com/

---
 Documentation/ABI/testing/sysfs-bus-cxl | 4 ++++
 1 file changed, 4 insertions(+)
Documentation/ABI/testing/sysfs-bus-cxl +4 -0
index 7352dbd70bc7..3629c983f05c 100644
@@ -568,6 +568,10 @@ Description:
 		not an endpoint decoder. Once all positions have been
 		successfully written a final validation for decode conflicts is
 		performed before activating the region.
+		To clear a position, for example to replace an endpoint
+		decoder, write an empty string (echo > targetX). Clearing
+		a position in a committed region also decommits the region.
+		It can be committed again after all positions are filled.
 
 
 What:		/sys/bus/cxl/devices/regionZ/commit
Reviewed-by on v4 1/2
#5 lore raw
In reply to Alison Schofield
Quoted 13 lines · Alison Schofield

Writing an endpoint decoder to a region targetN attribute that already holds it returns -EBUSY, but leaves the partially populated region in an inconsistent state. The targetN attribute still names the decoder, so the failed write gives no indication that the region was damaged.

Filling the remaining target positions can then trigger a NULL pointer dereference in cxl_region_setup_targets(). This can be reproduced through sysfs:

echo $decoder > /sys/bus/cxl/devices/region0/target0 echo $decoder > /sys/bus/cxl/devices/region0/target0 echo $other_decoder > /sys/bus/cxl/devices/region0/target1

Quoted 8 lines

An existing check recognizes the repeated assignment but incorrectly allows the attachment to proceed, damaging region state. Remove that check so the repeated write is rejected without disturbing the existing attachment, consistent with the documented targetN ABI.

Fixes 9995576cef48 ("cxl/region: Move region-position validation to a helper")

---

I didn't see this before I hit send on v3, you can disregard the comments on this patch there. I skipped the Sashiko review and basically commented the same thing (whoops), and you fixed that in this version, so:

Thanks,
Ben

maintainer Reviewed-by on v4 1/2
#6 lore raw
In reply to Alison Schofield
Quoted 13 lines · Alison Schofield

Writing an endpoint decoder to a region targetN attribute that already holds it returns -EBUSY, but leaves the partially populated region in an inconsistent state. The targetN attribute still names the decoder, so the failed write gives no indication that the region was damaged.

Filling the remaining target positions can then trigger a NULL pointer dereference in cxl_region_setup_targets(). This can be reproduced through sysfs:

echo $decoder > /sys/bus/cxl/devices/region0/target0 echo $decoder > /sys/bus/cxl/devices/region0/target0 echo $other_decoder > /sys/bus/cxl/devices/region0/target1

Quoted 7 lines

An existing check recognizes the repeated assignment but incorrectly allows the attachment to proceed, damaging region state. Remove that check so the repeated write is rejected without disturbing the existing attachment, consistent with the documented targetN ABI.

Fixes 9995576cef48 ("cxl/region: Move region-position validation to a helper")
Quoted 40 lines

---

Note: cxl_region_perf_data_calculate() currently updates region performance data before attachment validation completes. This is a pre-existing issue that will be addressed separately.

Changes in v4:
- Drop the added useless check in cxl_region_attach() (Sashiko)
The pre-existing occupied position check already returns -EBUSY.
v3: https://lore.kernel.org/linux-cxl/3e5af9d6d59f8df52b9d21bcf1c7e78f06918f80.1793653629.git.alison.schofield@intel.com/

Changes in v3:
- Reject repeat writes with -EBUSY, consistent with the documented ABI
- Rebase on 7.4-rc1
v2: https://lore.kernel.org/linux-cxl/920d80735a449f93a1f17a8bca4c25e4b302cb42.1792989098.git.alison.schofield@intel.com/

Changes in v2:
- Preserve the successful no-op behavior for repeated writes (Jonathan)
- Correct the Fixes tag
v1: https://lore.kernel.org/linux-cxl/94e9157aac2e99df1251d733769d539b914fdefc.1790829690.git.alison.schofield@intel.com/

---
 drivers/cxl/core/region.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/cxl/core/region.c +0 -3
index a048bd5c06cb..f42c6b6e3213 100644
@@ -1764,9 +1764,6 @@ static int cxl_region_validate_position(struct cxl_region *cxlr,
 		return -ENXIO;
 	}
 
-	if (p->targets[pos] == cxled)
-		return 0;
-
 	if (p->targets[pos]) {
 		struct cxl_endpoint_decoder *cxled_target = p->targets[pos];
 		struct cxl_memdev *cxlmd_target = cxled_to_memdev(cxled_target);

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4

maintainer Reviewed-by on v4 1/2
#7 lore raw
In reply to Alison Schofield
Quoted 13 lines · On Tue, 3 Nov 2026 09:07:10 -0800 Alison Schofield…

Writing an endpoint decoder to a region targetN attribute that already holds it returns -EBUSY, but leaves the partially populated region in an inconsistent state. The targetN attribute still names the decoder, so the failed write gives no indication that the region was damaged.

Filling the remaining target positions can then trigger a NULL pointer dereference in cxl_region_setup_targets(). This can be reproduced through sysfs:

echo $decoder > /sys/bus/cxl/devices/region0/target0 echo $decoder > /sys/bus/cxl/devices/region0/target0 echo $other_decoder > /sys/bus/cxl/devices/region0/target1

Quoted 7 lines

An existing check recognizes the repeated assignment but incorrectly allows the attachment to proceed, damaging region state. Remove that check so the repeated write is rejected without disturbing the existing attachment, consistent with the documented targetN ABI.

Fixes 9995576cef48 ("cxl/region: Move region-position validation to a helper")
maintainer Applied
#8 lore raw
In reply to Alison Schofield
Quoted 13 lines · Alison Schofield

Writing an endpoint decoder to a region targetN attribute that already holds it returns -EBUSY, but leaves the partially populated region in an inconsistent state. The targetN attribute still names the decoder, so the failed write gives no indication that the region was damaged.

Filling the remaining target positions can then trigger a NULL pointer dereference in cxl_region_setup_targets(). This can be reproduced through sysfs:

echo $decoder > /sys/bus/cxl/devices/region0/target0 echo $decoder > /sys/bus/cxl/devices/region0/target0 echo $other_decoder > /sys/bus/cxl/devices/region0/target1

Quoted 7 lines

An existing check recognizes the repeated assignment but incorrectly allows the attachment to proceed, damaging region state. Remove that check so the repeated write is rejected without disturbing the existing attachment, consistent with the documented targetN ABI.

Fixes 9995576cef48 ("cxl/region: Move region-position validation to a helper")

Applied to cxl/fixes (only this patch, not 2/2)
b8183f9259b5

Quoted 40 lines

---

Note: cxl_region_perf_data_calculate() currently updates region performance data before attachment validation completes. This is a pre-existing issue that will be addressed separately.

Changes in v4:
- Drop the added useless check in cxl_region_attach() (Sashiko)
The pre-existing occupied position check already returns -EBUSY.
v3: https://lore.kernel.org/linux-cxl/3e5af9d6d59f8df52b9d21bcf1c7e78f06918f80.1793653629.git.alison.schofield@intel.com/

Changes in v3:
- Reject repeat writes with -EBUSY, consistent with the documented ABI
- Rebase on 7.4-rc1
v2: https://lore.kernel.org/linux-cxl/920d80735a449f93a1f17a8bca4c25e4b302cb42.1792989098.git.alison.schofield@intel.com/

Changes in v2:
- Preserve the successful no-op behavior for repeated writes (Jonathan)
- Correct the Fixes tag
v1: https://lore.kernel.org/linux-cxl/94e9157aac2e99df1251d733769d539b914fdefc.1790829690.git.alison.schofield@intel.com/

---
 drivers/cxl/core/region.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/cxl/core/region.c +0 -3
index a048bd5c06cb..f42c6b6e3213 100644
@@ -1764,9 +1764,6 @@ static int cxl_region_validate_position(struct cxl_region *cxlr,
 		return -ENXIO;
 	}
 
-	if (p->targets[pos] == cxled)
-		return 0;
-
 	if (p->targets[pos]) {
 		struct cxl_endpoint_decoder *cxled_target = p->targets[pos];
 		struct cxl_memdev *cxlmd_target = cxled_to_memdev(cxled_target);

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4