Skip to contentSkip to conversation

cxl: Allow passthrough decoders with >16K granularity

PATCH Superseded Alison Schofield 4 participants 10 messages Jul 25 – Sep 4 CXL

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Alison Schofield

author maintainer
#0 lore raw

v3 cover cxl: Allow passthrough decoders with >16K granularity

Changes in v3:
- Program the real IG encoding for an encodable non-interleaving granularity instead of always writing EIG=0 (RichardC, Sashiko)
- Update Patch 1 commit msg text and this cover letter text per above change Link to v2:
https://lore.kernel.org/linux-cxl/[email protected]/

Changes in v2:
- Rebased on Linux 7.2-rc1
- Only v1 feedback was from Sashiko and that was not an issue Link to v1:
https://lore.kernel.org/linux-cxl/[email protected]/

Sashiko reported [1] that region setup rejects valid topologies containing a passthrough decoder beneath a wide parent interleave. In these configurations, a passthrough decoder can compute a granularity above the 16K maximum encodable in the interleave granularity (IG) field even though non-interleaving decoders do not consume that field.

The first patch avoids validating the interleave granularity of non-interleaving decoders, encodes the IG field as a don't-care only when the computed granularity is not encodable, and updates the sysfs ABI documentation accordingly.

The second patch extends cxl-test with a topology that allows a CXL unit test to cover this case.

A unit test update for this case is posted for review [2].

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/

Alison Schofield (2):
cxl/region: Allow passthrough decoders with >16K granularity cxl/test: Add a 2-way 16K root decoder for passthrough testing

 Documentation/ABI/testing/sysfs-bus-cxl |  5 ++-
 drivers/cxl/core/hdm.c                  |  8 ++++-
 drivers/cxl/core/region.c               | 47 ++++++++++++++----------
 tools/testing/cxl/test/cxl.c            | 48 +++++++++++++++++++++++--
 4 files changed, 85 insertions(+), 23 deletions(-)

base-commit: dc59e4fea9d83f03bad6bddf3fa2e52491777482

Signature · 1 line
2.37.3
author maintainer
#1 lore raw

PATCH v3 1/2 cxl/region: Allow passthrough decoders with >16K granularity

Region configuration rejects valid topologies that contain a passthrough decoder beneath a wide parent interleave.

For example, a passthrough switch below an 8-way root decoder with 4K granularity computes a 32K granularity. That exceeds the maximum encodable value of the HDM Decoder Control IG field, causing region setup to fail even though a non-interleaving decoder does not consume the IG field.

Only require the granularity to be encodable for interleaving decoders, both where it is inherited from the parent and where it is computed for the current decoder. Keep the computed value for passthrough decoders so it can seed descendant decoder setup.

When committing a non-interleaving decoder, still program the granularity if it is encodable; use a don't-care IG encoding only when it is not. This preserves an encodable passthrough granularity across re-enumeration, so descendants do not inherit a stale value.

As a consequence, the interleave_granularity attribute of a decoder whose interleave_ways is 1 may report a value above 16K. Document that the reported granularity for non-interleaving decoders is a don't-care value that may exceed the maximum encodable in hardware.

Fixes 18f35dc9314d ("cxl/region: Refactor granularity select in cxl_port_setup_targets()")
Assisted-by Claude:Opus-4-8
---
 Documentation/ABI/testing/sysfs-bus-cxl |  5 ++-
 drivers/cxl/core/hdm.c                  |  8 ++++-
 drivers/cxl/core/region.c               | 47 +++++++++++++++----------
 3 files changed, 39 insertions(+), 21 deletions(-)
Documentation/ABI/testing/sysfs-bus-cxl +4 -1
index 16a9b3d2e2c0..3f96e5bf1fd3 100644
@@ -407,7 +407,10 @@ Description:
 		space this decoder claims at address N before the decode rotates
 		to the next target in the interleave at address N +
 		interleave_granularity (assuming N is aligned to
-		interleave_granularity).
+		interleave_granularity). When 'interleave_ways' is 1, the
+		decoder does not interleave and the reported granularity is
+		a don't-care value that may exceed the maximum encodable in
+		hardware.
 
 
 What:		/sys/bus/cxl/devices/decoderX.Y/create_{pmem,ram}_region
drivers/cxl/core/hdm.c +7 -1
index 0c80b76a5f9b..d2ada82fe3c7 100644
@@ -691,7 +691,13 @@ static void cxld_set_interleave(struct cxl_decoder *cxld, u32 *ctrl)
 	if (WARN_ONCE(ways_to_eiw(cxld->interleave_ways, &eiw),
 		      "invalid interleave_ways: %d\n", cxld->interleave_ways))
 		return;
-	if (WARN_ONCE(granularity_to_eig(cxld->interleave_granularity, &eig),
+
+	/*
+	 * A non-interleaving decoder ignores the IG field, so an
+	 * unencodable granularity is a don't-care rather than a failure.
+	 */
+	if (granularity_to_eig(cxld->interleave_granularity, &eig) &&
+	    WARN_ONCE(cxld->interleave_ways > 1,
 		      "invalid interleave_granularity: %d\n",
 		      cxld->interleave_granularity))
 		return;
drivers/cxl/core/region.c +28 -19

60 lines not on this page · raw message

Signature · 1 line
2.37.3
author maintainer
#6 lore raw

PATCH v3 2/2 cxl/test: Add a 2-way 16K root decoder for passthrough testing

In reply to Alison Schofield

The cxl-test topologies do not provide a configuration where pass- through decoders compute a granularity above the 16K max encodable in hardware. The widest power-of-2 root decoder currently available is 2-way at 4K granularity, so a passthrough decoder below it computes at most 16K.

Add a CFMWS entry for a 2-way root decoder at 16K granularity. This topology supports a region configuration spanning the two multi-port host bridges and placing one endpoint under each bridge. The intermediate switch decoders are then passthrough decoders with a computed granularity of 32K.

This allows a CXL unit test to be added for this case.

Place the new window in the XOR topology set so the default modulo topology used by most cxl-test coverage is unchanged.

Assisted-by Claude:Opus-4-8
---
 tools/testing/cxl/test/cxl.c | 48 ++++++++++++++++++++++++++++++++++--
 1 file changed, 46 insertions(+), 2 deletions(-)
tools/testing/cxl/test/cxl.c +46 -2
index ef92dd35e030..5b87a3f5673f 100644
@@ -188,10 +188,18 @@ static struct {
 		struct acpi_cedt_cfmws cfmws;
 		u32 target[3];
 	} cfmws8;
+	struct {
+		struct acpi_cedt_cfmws cfmws;
+		u32 target[2];
+	} cfmws9;
 	struct {
 		struct acpi_cedt_cxims cxims;
 		u64 xormap_list[2];
 	} cxims0;
+	struct {
+		struct acpi_cedt_cxims cxims;
+		u64 xormap_list[1];
+	} cxims1;
 } __packed mock_cedt = {
 	.cedt = {
 		.header = {
@@ -371,6 +379,28 @@ static struct {
 		},
 		.target = { 0, 1, 2, },
 	},
+	/*
+	 * A 2-way root at 16K granularity. A passthrough decoder below this
+	 * root computes a 32K granularity (16K * 2), which exceeds the maximum
+	 * encodable in hardware. It exercises the passthrough granularity path
+	 * in cxl_port_setup_targets().
+	 */
+	.cfmws9 = {
+		.cfmws = {
+			.header = {
+				.type = ACPI_CEDT_TYPE_CFMWS,
+				.length = sizeof(mock_cedt.cfmws9),
+			},
+			.interleave_arithmetic = ACPI_CEDT_CFMWS_ARITHMETIC_XOR,
+			.interleave_ways = 1,
+			.granularity = 6,
+			.restrictions = ACPI_CEDT_CFMWS_RESTRICT_HOSTONLYMEM |
+					ACPI_CEDT_CFMWS_RESTRICT_PMEM,
+			.qtg_id = FAKE_QTG_ID,
+			.window_size = SZ_256M * 8UL,
+		},
+		.target = { 0, 1, },
+	},
 	.cxims0 = {
 		.cxims = {
 			.header = {
@@ -382,6 +412,18 @@ static struct {
 		},
 		.xormap_list = { 0x404100, 0x808200, },
 	},
+	/* CXIMS for the 16K (hbig = 6) 2-way root, cfmws9 */
+	.cxims1 = {
+		.cxims = {
+			.header = {
+				.type = ACPI_CEDT_TYPE_CXIMS,
+				.length = sizeof(mock_cedt.cxims1),
+			},
+			.hbig = 6,
+			.nr_xormaps = 1,
+		},
+		.xormap_list = { 0x0, },
+	},
 };
 
 struct acpi_cedt_cfmws *mock_cfmws[] = {
@@ -395,6 +437,7 @@ struct acpi_cedt_cfmws *mock_cfmws[] = {
 	[6] = &mock_cedt.cfmws6.cfmws,
 	[7] = &mock_cedt.cfmws7.cfmws,
 	[8] = &mock_cedt.cfmws8.cfmws,
+	[9] = &mock_cedt.cfmws9.cfmws,
 };
 
 static int cfmws_start;
@@ -402,10 +445,11 @@ static int cfmws_end;
 #define CFMWS_MOD_ARRAY_START 0
 #define CFMWS_MOD_ARRAY_END   5
 #define CFMWS_XOR_ARRAY_START 6
-#define CFMWS_XOR_ARRAY_END   8
+#define CFMWS_XOR_ARRAY_END   9
 
-struct acpi_cedt_cxims *mock_cxims[1] = {
+struct acpi_cedt_cxims *mock_cxims[2] = {
 	[0] = &mock_cedt.cxims0.cxims,
+	[1] = &mock_cedt.cxims1.cxims,
 };
 
 struct cxl_mock_res {
Signature · 1 line
2.37.3
#2 lore raw

Re: [PATCH v3 1/2] cxl/region: Allow passthrough decoders with >16K granularity

In reply to Alison Schofield
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] During region auto-discovery, a passthrough decoder's interleave granularity is not updated to its…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] During region auto-discovery, a passthrough decoder's interleave granularity is not updated to its correct topological value, causing valid interleaving descendants to fail auto-discovery. --

--- Patch [1]: [PATCH v3 1/2] cxl/region: Allow passthrough decoders with >16K granularity --- commit d213bad3e4cb8647e64aafb5eacaa82258aa533b
Author: Alison Schofield <[email protected]>

cxl/region: Allow passthrough decoders with >16K granularity

This commit allows passthrough decoders to have computed granularities larger than 16K by treating the interleave granularity as a don't-care value for non-interleaving decoders. It updates the region configuration to skip validation and hardware encodability checks for these granularities, while keeping the computed value to seed descendant decoder setup.

Quoted 3 lines
drivers/cxl/core/region.c +0 -0

[ ... ]

Quoted 1 line
drivers/cxl/core/region.c +0 -0
@@ -1549,20 +1557,21 @@ static int cxl_port_setup_targets(struct cxl_port *port,

[ ... ]

Quoted 14 lines
drivers/cxl/core/region.c +7 -6
+	ig = parent_ig * parent_iw;
 
-	rc = eig_to_granularity(eig, &ig);
-	if (rc) {
-		dev_dbg(&cxlr->dev, "%s:%s: invalid interleave: %d\n",
-			dev_name(port->uport_dev), dev_name(&port->dev),
-			256 << eig);
-		return rc;
+	/*
+	 * Keep the computed granularity for descendant setup. Only
+	 * interleaving decoders require an encodable granularity.
+	 */
+	if (iw > 1) {
+		rc = granularity_to_eig(ig, &eig);

drivers/cxl/core/region.c static int cxl_port_setup_targets(struct cxl_port *port, · line 1577

Quoted 10 lines
drivers/cxl/core/region.c +7 -0
+		if (rc) {
+			dev_dbg(&cxlr->dev,
+				"%s: invalid granularity calculation (%d * %d)\n",
+				dev_name(&parent_port->dev), parent_ig,
+				parent_iw);
+			return rc;
+		}
 	}
 
 	if (iw > 8 || iw > cxlsd->nr_targets) {

[Severity: High]
When auto-discovering a region with a passthrough decoder (iw == 1), does this skip updating the decoder's interleave granularity to the computed 'ig'?

Looking at cxl_port_setup_targets(), the auto-discovery path handles non-interleaving decoders by bypassing the granularity mismatch check:

    if (test_bit(CXL_REGION_F_AUTO, &cxlr->flags)) {
            if (cxld->interleave_ways != iw ||
                (iw > 1 && cxld->interleave_granularity != ig) || ...

However, because cxld->interleave_granularity is never updated to 'ig' for auto-discovered passthrough decoders, won't it retain its stale hardware value (which could be a don't-care value like 0)?

If so, when descendant decoders load their parent's interleave granularity earlier in cxl_port_setup_targets():

    parent_rr = cxl_rr_load(parent_port, cxlr);
    parent_cxld = parent_rr->decoder;
    parent_ig = parent_cxld->interleave_granularity;

won't they inherit this stale hardware don't-care value? This appears to cause their own expected 'ig' calculation to fail validation during auto-discovery, resulting in the region being rejected.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
author maintainer
#3 lore raw

Re: [PATCH v3 1/2] cxl/region: Allow passthrough decoders with >16K granularity

Quoted 2 lines · On Sat, Jul 25, 2026 at 01:26:37AM +0000, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] During region auto-discovery, a passthrough decoder's interleave granularity is not updated to its correct topological value, causing valid interleaving descendants to fail auto-discovery.

Same NO as in v1[1] (and in v2).
Gratuitously updating the field is not the right thing to do.

[1] https://lore.kernel.org/linux-cxl/[email protected]/#r
No. A downstream decoder can't inherit an unecodable value into a failing check. A >16K granularity only appears below a wide interleave, and everything below that inherits an equal-or-larger value that an interleaving decoder couldn't encode. So every descendant is necessarily passthrough and never validates granularity. There is no path where updating the F_AUTO value would prevent a failure because the failure cannot happen.

Quoted 73 lines

--

--- Patch [1]: [PATCH v3 1/2] cxl/region: Allow passthrough decoders with >16K granularity --- commit d213bad3e4cb8647e64aafb5eacaa82258aa533b
Author: Alison Schofield <[email protected]>

cxl/region: Allow passthrough decoders with >16K granularity

This commit allows passthrough decoders to have computed granularities larger than 16K by treating the interleave granularity as a don't-care value for non-interleaving decoders. It updates the region configuration to skip validation and hardware encodability checks for these granularities, while keeping the computed value to seed descendant decoder setup.

Quoted 3 lines
drivers/cxl/core/region.c +0 -0

[ ... ]

Quoted 1 line
drivers/cxl/core/region.c +0 -0
@@ -1549,20 +1557,21 @@ static int cxl_port_setup_targets(struct cxl_port *port,

[ ... ]

Quoted 14 lines
drivers/cxl/core/region.c +7 -6
+	ig = parent_ig * parent_iw;
 
-	rc = eig_to_granularity(eig, &ig);
-	if (rc) {
-		dev_dbg(&cxlr->dev, "%s:%s: invalid interleave: %d\n",
-			dev_name(port->uport_dev), dev_name(&port->dev),
-			256 << eig);
-		return rc;
+	/*
+	 * Keep the computed granularity for descendant setup. Only
+	 * interleaving decoders require an encodable granularity.
+	 */
+	if (iw > 1) {
+		rc = granularity_to_eig(ig, &eig);

drivers/cxl/core/region.c static int cxl_port_setup_targets(struct cxl_port *port, · line 1577

Quoted 10 lines
drivers/cxl/core/region.c +7 -0
+		if (rc) {
+			dev_dbg(&cxlr->dev,
+				"%s: invalid granularity calculation (%d * %d)\n",
+				dev_name(&parent_port->dev), parent_ig,
+				parent_iw);
+			return rc;
+		}
 	}
 
 	if (iw > 8 || iw > cxlsd->nr_targets) {

[Severity: High]
When auto-discovering a region with a passthrough decoder (iw == 1), does this skip updating the decoder's interleave granularity to the computed 'ig'?

Looking at cxl_port_setup_targets(), the auto-discovery path handles non-interleaving decoders by bypassing the granularity mismatch check:

    if (test_bit(CXL_REGION_F_AUTO, &cxlr->flags)) {
            if (cxld->interleave_ways != iw ||
                (iw > 1 && cxld->interleave_granularity != ig) || ...

However, because cxld->interleave_granularity is never updated to 'ig' for auto-discovered passthrough decoders, won't it retain its stale hardware value (which could be a don't-care value like 0)?

If so, when descendant decoders load their parent's interleave granularity earlier in cxl_port_setup_targets():

    parent_rr = cxl_rr_load(parent_port, cxlr);
    parent_cxld = parent_rr->decoder;
    parent_ig = parent_cxld->interleave_granularity;

won't they inherit this stale hardware don't-care value? This appears to cause their own expected 'ig' calculation to fail validation during auto-discovery, resulting in the region being rejected.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Reviewed-by on the v3 series
#9 lore raw
In reply to Alison Schofield
Quoted 7 lines · Alison Schofield

Changes in v3:
- Program the real IG encoding for an encodable non-interleaving granularity instead of always writing EIG=0 (RichardC, Sashiko)
- Update Patch 1 commit msg text and this cover letter text per above change Link to v2:
https://lore.kernel.org/linux-cxl/[email protected]/

For the series:

DJ

Quoted 38 lines

Changes in v2:
- Rebased on Linux 7.2-rc1
- Only v1 feedback was from Sashiko and that was not an issue Link to v1:
https://lore.kernel.org/linux-cxl/[email protected]/

Sashiko reported [1] that region setup rejects valid topologies containing a passthrough decoder beneath a wide parent interleave. In these configurations, a passthrough decoder can compute a granularity above the 16K maximum encodable in the interleave granularity (IG) field even though non-interleaving decoders do not consume that field.

The first patch avoids validating the interleave granularity of non-interleaving decoders, encodes the IG field as a don't-care only when the computed granularity is not encodable, and updates the sysfs ABI documentation accordingly.

The second patch extends cxl-test with a topology that allows a CXL unit test to cover this case.

A unit test update for this case is posted for review [2].

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/

Alison Schofield (2):
cxl/region: Allow passthrough decoders with >16K granularity cxl/test: Add a 2-way 16K root decoder for passthrough testing

 Documentation/ABI/testing/sysfs-bus-cxl |  5 ++-
 drivers/cxl/core/hdm.c                  |  8 ++++-
 drivers/cxl/core/region.c               | 47 ++++++++++++++----------
 tools/testing/cxl/test/cxl.c            | 48 +++++++++++++++++++++++--
 4 files changed, 85 insertions(+), 23 deletions(-)

base-commit: dc59e4fea9d83f03bad6bddf3fa2e52491777482

Reviewed-by on v3 1/2
#4 lore raw

Re: [PATCH v3 1/2] cxl/region: Allow passthrough decoders with >16K granularity

In reply to Alison Schofield
Quoted 124 lines · Alison Schofield

Region configuration rejects valid topologies that contain a passthrough decoder beneath a wide parent interleave.

For example, a passthrough switch below an 8-way root decoder with 4K granularity computes a 32K granularity. That exceeds the maximum encodable value of the HDM Decoder Control IG field, causing region setup to fail even though a non-interleaving decoder does not consume the IG field.

Only require the granularity to be encodable for interleaving decoders, both where it is inherited from the parent and where it is computed for the current decoder. Keep the computed value for passthrough decoders so it can seed descendant decoder setup.

When committing a non-interleaving decoder, still program the granularity if it is encodable; use a don't-care IG encoding only when it is not. This preserves an encodable passthrough granularity across re-enumeration, so descendants do not inherit a stale value.

As a consequence, the interleave_granularity attribute of a decoder whose interleave_ways is 1 may report a value above 16K. Document that the reported granularity for non-interleaving decoders is a don't-care value that may exceed the maximum encodable in hardware.

Fixes 18f35dc9314d ("cxl/region: Refactor granularity select in cxl_port_setup_targets()")
Assisted-by Claude:Opus-4-8
---
 Documentation/ABI/testing/sysfs-bus-cxl |  5 ++-
 drivers/cxl/core/hdm.c                  |  8 ++++-
 drivers/cxl/core/region.c               | 47 +++++++++++++++----------
 3 files changed, 39 insertions(+), 21 deletions(-)
Documentation/ABI/testing/sysfs-bus-cxl +4 -1
index 16a9b3d2e2c0..3f96e5bf1fd3 100644
@@ -407,7 +407,10 @@ Description:
 		space this decoder claims at address N before the decode rotates
 		to the next target in the interleave at address N +
 		interleave_granularity (assuming N is aligned to
-		interleave_granularity).
+		interleave_granularity). When 'interleave_ways' is 1, the
+		decoder does not interleave and the reported granularity is
+		a don't-care value that may exceed the maximum encodable in
+		hardware.
 
 
 What:		/sys/bus/cxl/devices/decoderX.Y/create_{pmem,ram}_region
drivers/cxl/core/hdm.c +7 -1
index 0c80b76a5f9b..d2ada82fe3c7 100644
@@ -691,7 +691,13 @@ static void cxld_set_interleave(struct cxl_decoder *cxld, u32 *ctrl)
 	if (WARN_ONCE(ways_to_eiw(cxld->interleave_ways, &eiw),
 		      "invalid interleave_ways: %d\n", cxld->interleave_ways))
 		return;
-	if (WARN_ONCE(granularity_to_eig(cxld->interleave_granularity, &eig),
+
+	/*
+	 * A non-interleaving decoder ignores the IG field, so an
+	 * unencodable granularity is a don't-care rather than a failure.
+	 */
+	if (granularity_to_eig(cxld->interleave_granularity, &eig) &&
+	    WARN_ONCE(cxld->interleave_ways > 1,
 		      "invalid interleave_granularity: %d\n",
 		      cxld->interleave_granularity))
 		return;
drivers/cxl/core/region.c +20 -19
index 1e211542b6b6..5a443551288c 100644
@@ -1521,12 +1521,20 @@ static int cxl_port_setup_targets(struct cxl_port *port,
 		parent_iw = parent_cxld->interleave_ways;
 	}
 
-	rc = granularity_to_eig(parent_ig, &peig);
-	if (rc) {
-		dev_dbg(&cxlr->dev, "%s:%s: invalid parent granularity: %d\n",
-			dev_name(parent_port->uport_dev),
-			dev_name(&parent_port->dev), parent_ig);
-		return rc;
+	/*
+	 * A non-interleaving parent does not encode its granularity, so its
+	 * stored value may exceed the maximum encodable and need not be
+	 * validated here.
+	 */
+	if (parent_iw > 1) {
+		rc = granularity_to_eig(parent_ig, &peig);
+		if (rc) {
+			dev_dbg(&cxlr->dev,
+				"%s:%s: invalid parent granularity: %d\n",
+				dev_name(parent_port->uport_dev),
+				dev_name(&parent_port->dev), parent_ig);
+			return rc;
+		}
 	}
 
 	rc = ways_to_eiw(parent_iw, &peiw);
@@ -1549,20 +1557,21 @@ static int cxl_port_setup_targets(struct cxl_port *port,
 	 * Interleave granularity is a multiple of @parent_port granularity.
 	 * Multiplier is the parent port interleave ways.
 	 */
-	rc = granularity_to_eig(parent_ig * parent_iw, &eig);
-	if (rc) {
-		dev_dbg(&cxlr->dev,
-			"%s: invalid granularity calculation (%d * %d)\n",
-			dev_name(&parent_port->dev), parent_ig, parent_iw);
-		return rc;
-	}
+	ig = parent_ig * parent_iw;
 
-	rc = eig_to_granularity(eig, &ig);
-	if (rc) {
-		dev_dbg(&cxlr->dev, "%s:%s: invalid interleave: %d\n",
-			dev_name(port->uport_dev), dev_name(&port->dev),
-			256 << eig);
-		return rc;
+	/*
+	 * Keep the computed granularity for descendant setup. Only
+	 * interleaving decoders require an encodable granularity.
+	 */
+	if (iw > 1) {

drivers/cxl/core/region.c static int cxl_port_setup_targets(struct cxl_port *port, · line 1576

Quoted 10 lines
drivers/cxl/core/region.c +8 -0
+		rc = granularity_to_eig(ig, &eig);
+		if (rc) {
+			dev_dbg(&cxlr->dev,
+				"%s: invalid granularity calculation (%d * %d)\n",
+				dev_name(&parent_port->dev), parent_ig,
+				parent_iw);
+			return rc;
+		}
 	}
 

Hi Alison,

Looks sane to me, just that this check pattern appears twice and peig and eig are both write-only afterwards.
Could they be formed into a helper or macro ?

Something like the following might do ?
"""
static bool granularity_is_encodable(int ways, int granularity)

{
    u16 eig;
    if (ways <= 1)
        return true;

    return granularity_to_eig(granularity, &eig) == 0;
}
if (!granularity_is_encodable(parent_iw, parent_ig) {
    dev_dbg();
    return -EINVAL;
}

"""

Best regards,
Richard Cheng.

Quoted 5 lines
drivers/cxl/core/region.c +0 -0
 	if (iw > 8 || iw > cxlsd->nr_targets) {
Signature · 1 line
2.37.3
Reviewed-by on v3 2/2
#7 lore raw

Re: [PATCH v3 2/2] cxl/test: Add a 2-way 16K root decoder for passthrough testing

In reply to Alison Schofield
Quoted 6 lines · Alison Schofield

The cxl-test topologies do not provide a configuration where pass- through decoders compute a granularity above the 16K max encodable in hardware. The widest power-of-2 root decoder currently available is 2-way at 4K granularity, so a passthrough decoder below it computes at most 16K.

I think 2-way with 4K granularity computes 8K, not 16K. The conclusion does hold, just the number.

Quoted 114 lines

Add a CFMWS entry for a 2-way root decoder at 16K granularity. This topology supports a region configuration spanning the two multi-port host bridges and placing one endpoint under each bridge. The intermediate switch decoders are then passthrough decoders with a computed granularity of 32K.

This allows a CXL unit test to be added for this case.

Place the new window in the XOR topology set so the default modulo topology used by most cxl-test coverage is unchanged.

Assisted-by Claude:Opus-4-8
---
 tools/testing/cxl/test/cxl.c | 48 ++++++++++++++++++++++++++++++++++--
 1 file changed, 46 insertions(+), 2 deletions(-)
tools/testing/cxl/test/cxl.c +46 -2
index ef92dd35e030..5b87a3f5673f 100644
@@ -188,10 +188,18 @@ static struct {
 		struct acpi_cedt_cfmws cfmws;
 		u32 target[3];
 	} cfmws8;
+	struct {
+		struct acpi_cedt_cfmws cfmws;
+		u32 target[2];
+	} cfmws9;
 	struct {
 		struct acpi_cedt_cxims cxims;
 		u64 xormap_list[2];
 	} cxims0;
+	struct {
+		struct acpi_cedt_cxims cxims;
+		u64 xormap_list[1];
+	} cxims1;
 } __packed mock_cedt = {
 	.cedt = {
 		.header = {
@@ -371,6 +379,28 @@ static struct {
 		},
 		.target = { 0, 1, 2, },
 	},
+	/*
+	 * A 2-way root at 16K granularity. A passthrough decoder below this
+	 * root computes a 32K granularity (16K * 2), which exceeds the maximum
+	 * encodable in hardware. It exercises the passthrough granularity path
+	 * in cxl_port_setup_targets().
+	 */
+	.cfmws9 = {
+		.cfmws = {
+			.header = {
+				.type = ACPI_CEDT_TYPE_CFMWS,
+				.length = sizeof(mock_cedt.cfmws9),
+			},
+			.interleave_arithmetic = ACPI_CEDT_CFMWS_ARITHMETIC_XOR,
+			.interleave_ways = 1,
+			.granularity = 6,
+			.restrictions = ACPI_CEDT_CFMWS_RESTRICT_HOSTONLYMEM |
+					ACPI_CEDT_CFMWS_RESTRICT_PMEM,
+			.qtg_id = FAKE_QTG_ID,
+			.window_size = SZ_256M * 8UL,
+		},
+		.target = { 0, 1, },
+	},
 	.cxims0 = {
 		.cxims = {
 			.header = {
@@ -382,6 +412,18 @@ static struct {
 		},
 		.xormap_list = { 0x404100, 0x808200, },
 	},
+	/* CXIMS for the 16K (hbig = 6) 2-way root, cfmws9 */
+	.cxims1 = {
+		.cxims = {
+			.header = {
+				.type = ACPI_CEDT_TYPE_CXIMS,
+				.length = sizeof(mock_cedt.cxims1),
+			},
+			.hbig = 6,
+			.nr_xormaps = 1,
+		},
+		.xormap_list = { 0x0, },
+	},
 };
 
 struct acpi_cedt_cfmws *mock_cfmws[] = {
@@ -395,6 +437,7 @@ struct acpi_cedt_cfmws *mock_cfmws[] = {
 	[6] = &mock_cedt.cfmws6.cfmws,
 	[7] = &mock_cedt.cfmws7.cfmws,
 	[8] = &mock_cedt.cfmws8.cfmws,
+	[9] = &mock_cedt.cfmws9.cfmws,
 };
 
 static int cfmws_start;
@@ -402,10 +445,11 @@ static int cfmws_end;
 #define CFMWS_MOD_ARRAY_START 0
 #define CFMWS_MOD_ARRAY_END   5
 #define CFMWS_XOR_ARRAY_START 6
-#define CFMWS_XOR_ARRAY_END   8
+#define CFMWS_XOR_ARRAY_END   9
 
-struct acpi_cedt_cxims *mock_cxims[1] = {
+struct acpi_cedt_cxims *mock_cxims[2] = {
 	[0] = &mock_cedt.cxims0.cxims,
+	[1] = &mock_cedt.cxims1.cxims,
 };
 
 struct cxl_mock_res {
Signature · 1 line
2.37.3

Best regards,
Richard Cheng.

author maintainer
#8 lore raw

Re: [PATCH v3 2/2] cxl/test: Add a 2-way 16K root decoder for passthrough testing

Quoted 10 lines · Richard Cheng
Quoted 6 lines · Alison Schofield

The cxl-test topologies do not provide a configuration where pass- through decoders compute a granularity above the 16K max encodable in hardware. The widest power-of-2 root decoder currently available is 2-way at 4K granularity, so a passthrough decoder below it computes at most 16K.

I think 2-way with 4K granularity computes 8K, not 16K. The conclusion does hold, just the number.

Yes and thanks for the review. Fixed up in v4.

-- Alison

author maintainer
#5 lore raw

Re: [PATCH v3 1/2] cxl/region: Allow passthrough decoders with >16K granularity

In reply to Richard Cheng
Quoted 1 line · Richard Cheng

On Fri, Jul 24, 2026 at 06:08:54PM +0800, Alison Schofield wrote:

snip

Quoted 83 lines
Quoted 55 lines
drivers/cxl/core/region.c +20 -19
index 1e211542b6b6..5a443551288c 100644
@@ -1521,12 +1521,20 @@ static int cxl_port_setup_targets(struct cxl_port *port,
 		parent_iw = parent_cxld->interleave_ways;
 	}
 
-	rc = granularity_to_eig(parent_ig, &peig);
-	if (rc) {
-		dev_dbg(&cxlr->dev, "%s:%s: invalid parent granularity: %d\n",
-			dev_name(parent_port->uport_dev),
-			dev_name(&parent_port->dev), parent_ig);
-		return rc;
+	/*
+	 * A non-interleaving parent does not encode its granularity, so its
+	 * stored value may exceed the maximum encodable and need not be
+	 * validated here.
+	 */
+	if (parent_iw > 1) {
+		rc = granularity_to_eig(parent_ig, &peig);
+		if (rc) {
+			dev_dbg(&cxlr->dev,
+				"%s:%s: invalid parent granularity: %d\n",
+				dev_name(parent_port->uport_dev),
+				dev_name(&parent_port->dev), parent_ig);
+			return rc;
+		}
 	}
 
 	rc = ways_to_eiw(parent_iw, &peiw);
@@ -1549,20 +1557,21 @@ static int cxl_port_setup_targets(struct cxl_port *port,
 	 * Interleave granularity is a multiple of @parent_port granularity.
 	 * Multiplier is the parent port interleave ways.
 	 */
-	rc = granularity_to_eig(parent_ig * parent_iw, &eig);
-	if (rc) {
-		dev_dbg(&cxlr->dev,
-			"%s: invalid granularity calculation (%d * %d)\n",
-			dev_name(&parent_port->dev), parent_ig, parent_iw);
-		return rc;
-	}
+	ig = parent_ig * parent_iw;
 
-	rc = eig_to_granularity(eig, &ig);
-	if (rc) {
-		dev_dbg(&cxlr->dev, "%s:%s: invalid interleave: %d\n",
-			dev_name(port->uport_dev), dev_name(&port->dev),
-			256 << eig);
-		return rc;
+	/*
+	 * Keep the computed granularity for descendant setup. Only
+	 * interleaving decoders require an encodable granularity.
+	 */
+	if (iw > 1) {

drivers/cxl/core/region.c static int cxl_port_setup_targets(struct cxl_port *port, · line 1576

Quoted 10 lines
drivers/cxl/core/region.c +8 -0
+		rc = granularity_to_eig(ig, &eig);
+		if (rc) {
+			dev_dbg(&cxlr->dev,
+				"%s: invalid granularity calculation (%d * %d)\n",
+				dev_name(&parent_port->dev), parent_ig,
+				parent_iw);
+			return rc;
+		}
 	}
 

Hi Alison,

Looks sane to me, just that this check pattern appears twice and peig and eig are both write-only afterwards.
Could they be formed into a helper or macro ?

Something like the following might do ?
"""
static bool granularity_is_encodable(int ways, int granularity)

{
    u16 eig;
    if (ways <= 1)
        return true;

    return granularity_to_eig(granularity, &eig) == 0;
}
Quoted 7 lines
if (!granularity_is_encodable(parent_iw, parent_ig) {
    dev_dbg();
    return -EINVAL;
}

"""

Thanks Richard!
I took the helper but wrote it to return an errno rather than a bool because it seemed that a bool would answer true for any gran at all when ways is 1.

Went w the style of the other check_*() helpers in region.c that return errno.

Please take a look in v4.

-- Alison

Quoted 9 lines

Best regards,
Richard Cheng.

Quoted 5 lines
drivers/cxl/core/region.c +0 -0
 	if (iw > 8 || iw > cxlsd->nr_targets) {
Signature · 1 line
2.37.3