Skip to contentSkip to conversation

cxl/core: Enable Region creation on x86 with Low Mem Hole

PATCH Superseded Fabio M. De Francesco 4 participants 12 messages Jan 14, 2025 – Apr 2, 2025 CXL

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v2 cover cxl/core: Enable Region creation on x86 with Low Mem Hole

The CXL Fixed Memory Window Structure (CFMWS) describes zero or more Host Physical Address (HPA) windows that are associated with each CXL Host Bridge. Each window represents a contiguous HPA that may be interleaved with one or more targets (CXL v3.1 - 9.18.1.3).

The Low Memory Hole (LMH) of x86 is a range of addresses of physical low memory to which systems cannot send transactions. On those systems, BIOS publishes CFMWS which communicate the active System Physical Address (SPA) ranges that map to a subset of the Host Physical Address (HPA) ranges. The SPA range trims out the hole, and capacity in the endpoint is lost with no SPA to map to CXL HPA in that hole.

In the early stages of CXL Regions construction and attach on platforms with Low Memory Holes, the driver fails and returns an error because it expects that the CXL Endpoint Decoder range is a subset of the Root Decoder's (SPA >= HPA). On x86 with LMH's, it happens that SPA < HPA.

Therefore, detect x86 Low Memory Holes, match CXL Root and Endpoint Decoders or already made CXL Regions and Decoders to allow the construction of new CXL Regions and the attachment of Endpoint Decoders, even if SPA < HPA. If needed because of LMH's, adjust the Endpoint Decoder range end to match Root Decoder's.

- Patch 1/4 changes the calling conventions of three match_*_by_range() helpers in preparation of 3/4.
- Patch 2/4 Introduces helpers to detect LMH's and also one to adjust the HPA range end for CXL Regions construction.
- Patch 3/4 enables CXL Regions construction and Endpoint Decoders attachment by matching Root Decoders or Regions with Endpoint Decoders, adjusting Endpoint Decoders HPA range end, and relaxing constraints while Endpoints decoders' attachment.
- Patch 4/4 simulates a LMH for the CXL tests on patched CXL driver.

Many thanks to Alison, Dan, and Ira for their help and for their reviews of my RFC on Intel's internal ML.

Commenting on v1, Alison wrote a couple of observations on what users will see. I suggest anyone interested to see how this series affect users to take a look at her observations.[0] Thank you!

Changes for v2:

Cover:
Extend and elaborate more on how the series works.
1/4:
Add Reviewed-by tags (Alison, Ira).
2/4:
Make a separate patch for LMH helpers. (Alison)
Add spaces before final returns. (Alison)
Change trim_by_spa() to arch_adjust_region_resource(). (Alison) Check that SPA is below CFMWS range start + 4GB. (Ming) Change storage class of default helpers to "static".[1] (KTR)
3/4:
Add dev_dbg() logs before and after adjusting resource for Region construction to match the Root Decoder range. (Alison)
4/4:
Conditionally create a LMH simulation only if CXL_ARCH_LOW_MEMORY_HOLE is set. (Jonathan)
Make the start address of the CFMWS range dependent either on real hardware (0x0) or on mock_cfmws[0] for tests. (Alison) Extend the commit message to confirm successful creation of a Region with a LMH on loading of the cxl-test module. (Alison) Define the CFMWS range start on real hardware as LMH_CFMWS_RANGE_START (Alison)

v1 - https://lore.kernel.org/all/[email protected]/

[0] - https://lore.kernel.org/all/[email protected]/
[1] - https://lore.kernel.org/oe-kbuild-all/[email protected]/

Fabio M. De Francesco (4):
cxl/core: Change match_*_by_range() calling convention cxl/core: Add helpers to detect Low memory Holes on x86 cxl/core: Enable Region creation on x86 with Low Memory Hole cxl/test: Simulate an x86 Low Memory Hole for tests

 drivers/cxl/Kconfig                  |  5 ++
 drivers/cxl/core/Makefile            |  1 +
 drivers/cxl/core/lmh.c               | 81 ++++++++++++++++++++++++++++
 drivers/cxl/core/lmh.h               | 30 +++++++++++
 drivers/cxl/core/region.c            | 81 +++++++++++++++++++++-------
 tools/testing/cxl/Kbuild             |  1 +
 tools/testing/cxl/cxl_core_exports.c |  2 +
 tools/testing/cxl/test/cxl.c         | 10 ++++
 8 files changed, 193 insertions(+), 18 deletions(-)
 create mode 100644 drivers/cxl/core/lmh.c
 create mode 100644 drivers/cxl/core/lmh.h
Signature · 1 line
2.47.1
#1 lore raw

PATCH v2 1/4 cxl/core: Change match_*_by_range() calling convention

Replace struct range parameter with struct cxl_endpoint_decoder of which range is a member in the match_*_by_range() functions.

This is in preparation for expanding these helpers to perform arch specific region matching that requires a cxl_endpoint_decoder.

No functional changes.

---
 drivers/cxl/core/region.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)
drivers/cxl/core/region.c +16 -9
index b98b1ccffd1ca..9d2c31f5caf26 100644
@@ -1735,23 +1735,27 @@ static struct cxl_port *next_port(struct cxl_port *port)
 
 static int match_switch_decoder_by_range(struct device *dev, void *data)
 {
+	struct cxl_endpoint_decoder *cxled = data;
 	struct cxl_switch_decoder *cxlsd;
-	struct range *r1, *r2 = data;
+	struct range *r1, *r2;
 
 	if (!is_switch_decoder(dev))
 		return 0;
 
 	cxlsd = to_cxl_switch_decoder(dev);
 	r1 = &cxlsd->cxld.hpa_range;
+	r2 = &cxled->cxld.hpa_range;
 
 	if (is_root_decoder(dev))
 		return range_contains(r1, r2);
 	return (r1->start == r2->start && r1->end == r2->end);
 }
 
-static int find_pos_and_ways(struct cxl_port *port, struct range *range,
+static int find_pos_and_ways(struct cxl_port *port,
+			     struct cxl_endpoint_decoder *cxled,
 			     int *pos, int *ways)
 {
+	struct range *range = &cxled->cxld.hpa_range;
 	struct cxl_switch_decoder *cxlsd;
 	struct cxl_port *parent;
 	struct device *dev;
@@ -1761,7 +1765,7 @@ static int find_pos_and_ways(struct cxl_port *port, struct range *range,
 	if (!parent)
 		return rc;
 
-	dev = device_find_child(&parent->dev, range,
+	dev = device_find_child(&parent->dev, cxled,
 				match_switch_decoder_by_range);
 	if (!dev) {
 		dev_err(port->uport_dev,
@@ -1841,7 +1845,7 @@ static int cxl_calc_interleave_pos(struct cxl_endpoint_decoder *cxled)
 		if (is_cxl_root(iter))
 			break;
 
-		rc = find_pos_and_ways(iter, range, &parent_pos, &parent_ways);
+		rc = find_pos_and_ways(iter, cxled, &parent_pos, &parent_ways);
 		if (rc)
 			return rc;
 
@@ -3189,22 +3193,26 @@ static int devm_cxl_add_dax_region(struct cxl_region *cxlr)
 
 static int match_root_decoder_by_range(struct device *dev, void *data)
 {
-	struct range *r1, *r2 = data;
+	struct cxl_endpoint_decoder *cxled = data;
 	struct cxl_root_decoder *cxlrd;
+	struct range *r1, *r2;
 
 	if (!is_root_decoder(dev))
 		return 0;
 
 	cxlrd = to_cxl_root_decoder(dev);
 	r1 = &cxlrd->cxlsd.cxld.hpa_range;
+	r2 = &cxled->cxld.hpa_range;
+
 	return range_contains(r1, r2);
 }
 
 static int match_region_by_range(struct device *dev, void *data)
 {
+	struct cxl_endpoint_decoder *cxled = data;
+	struct range *r = &cxled->cxld.hpa_range;
 	struct cxl_region_params *p;
 	struct cxl_region *cxlr;
-	struct range *r = data;
 	int rc = 0;
 
 	if (!is_cxl_region(dev))
@@ -3308,7 +3316,6 @@ static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd,
 int cxl_add_to_region(struct cxl_port *root, struct cxl_endpoint_decoder *cxled)
 {
 	struct cxl_memdev *cxlmd = cxled_to_memdev(cxled);
-	struct range *hpa = &cxled->cxld.hpa_range;
 	struct cxl_decoder *cxld = &cxled->cxld;
 	struct device *cxlrd_dev, *region_dev;
 	struct cxl_root_decoder *cxlrd;
@@ -3317,7 +3324,7 @@ int cxl_add_to_region(struct cxl_port *root, struct cxl_endpoint_decoder *cxled)
 	bool attach = false;
 	int rc;
 
-	cxlrd_dev = device_find_child(&root->dev, &cxld->hpa_range,
+	cxlrd_dev = device_find_child(&root->dev, cxled,
 				      match_root_decoder_by_range);
 	if (!cxlrd_dev) {
 		dev_err(cxlmd->dev.parent,
@@ -3334,7 +3341,7 @@ int cxl_add_to_region(struct cxl_port *root, struct cxl_endpoint_decoder *cxled)
 	 * one does the construction and the others add to that.
 	 */
 	mutex_lock(&cxlrd->range_lock);
-	region_dev = device_find_child(&cxlrd->cxlsd.cxld.dev, hpa,
+	region_dev = device_find_child(&cxlrd->cxlsd.cxld.dev, cxled,
 				       match_region_by_range);
 	if (!region_dev) {
 		cxlr = construct_region(cxlrd, cxled);
Signature · 1 line
2.47.1
#2 lore raw

PATCH v2 2/4 cxl/core: Add helpers to detect Low memory Holes on x86

In reply to Fabio M. De Francesco

In x86 with Low memory Hole, the BIOS may publishes CFMWS that describe SPA ranges which are subsets of the corresponding CXL Endpoint Decoders HPA's because the CFMWS never intersects LMH's while EP Decoders HPA's ranges are always guaranteed to align to the NIW * 256M rule.

In order to construct Regions and attach Decoders, the driver needs to match Root Decoders and Regions with Endpoint Decoders, but it fails and the entire process returns errors because it doesn't expect to deal with SPA range lengths smaller than corresponding HPA's.

Introduce functions that indirectly detect x86 LMH's by comparing SPA's with corresponding HPA's. They will be used in the process of Regions creation and Endpoint attachments to prevent driver failures in a few steps of the above-mentioned process.

The helpers return true when HPA/SPA misalignments are detected under specific conditions: both the SPA and HPA ranges must start at LMH_CFMWS_RANGE_START (that in x86 with LMH's is 0x0), SPA range sizes be less than HPA's, SPA's range's size be less than 4G, HPA's size be aligned to the NIW * 256M rule.

Also introduce a function to adjust the range end of the Regions to be created on x86 with LMH's.

Cc Alison Schofield <[email protected]>
Cc Dan Williams <[email protected]>
Cc Ira Weiny <[email protected]>
---
 drivers/cxl/core/lmh.c | 55 ++++++++++++++++++++++++++++++++++++++++++
 drivers/cxl/core/lmh.h | 28 +++++++++++++++++++++
 2 files changed, 83 insertions(+)
 create mode 100644 drivers/cxl/core/lmh.c
 create mode 100644 drivers/cxl/core/lmh.h
drivers/cxl/core/lmh.c new file +55 -0
new file mode 100644
index 0000000000000..232ebea0a8364
@@ -0,0 +1,55 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/range.h>
+#include "lmh.h"
+
+/* Start of CFMWS range that end before x86 Low Memory Holes */
+#define LMH_CFMWS_RANGE_START 0x0ULL
+
+/*
+ * Match CXL Root and Endpoint Decoders by comparing SPA and HPA ranges.
+ *
+ * On x86, CFMWS ranges never intersect memory holes while endpoint decoders
+ * HPA range sizes are always guaranteed aligned to NIW * 256MB; therefore,
+ * the given endpoint decoder HPA range size is always expected aligned and
+ * also larger than that of the matching root decoder. If there are LMH's,
+ * the root decoder range end is always less than SZ_4G.
+ */
+bool arch_match_spa(struct cxl_root_decoder *cxlrd,
+		    struct cxl_endpoint_decoder *cxled)
+{
+	struct range *r1, *r2;
+	int niw;
+
+	r1 = &cxlrd->cxlsd.cxld.hpa_range;
+	r2 = &cxled->cxld.hpa_range;
+	niw = cxled->cxld.interleave_ways;
+
+	if (r1->start == LMH_CFMWS_RANGE_START && r1->start == r2->start &&
+	    r1->end < (LMH_CFMWS_RANGE_START + SZ_4G) && r1->end < r2->end &&
+	    IS_ALIGNED(range_len(r2), niw * SZ_256M))
+		return true;
+
+	return false;
+}
+
+/* Similar to arch_match_spa(), it matches regions and decoders */
+bool arch_match_region(struct cxl_region_params *p, struct cxl_decoder *cxld)
+{
+	struct range *r = &cxld->hpa_range;
+	struct resource *res = p->res;
+	int niw = cxld->interleave_ways;
+
+	if (res->start == LMH_CFMWS_RANGE_START && res->start == r->start &&
+	    res->end < (LMH_CFMWS_RANGE_START + SZ_4G) && res->end < r->end &&
+	    IS_ALIGNED(range_len(r), niw * SZ_256M))
+		return true;
+
+	return false;
+}
+
+void arch_adjust_region_resource(struct resource *res,
+				 struct cxl_root_decoder *cxlrd)
+{
+	res->end = cxlrd->res->end;
+}
drivers/cxl/core/lmh.h new file +28 -0
new file mode 100644
index 0000000000000..ec8907145afe8
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include "cxl.h"
+
+#ifdef CONFIG_CXL_ARCH_LOW_MEMORY_HOLE
+bool arch_match_spa(struct cxl_root_decoder *cxlrd,
+		    struct cxl_endpoint_decoder *cxled);
+bool arch_match_region(struct cxl_region_params *p, struct cxl_decoder *cxld);
+void arch_adjust_region_resource(struct resource *res,
+				 struct cxl_root_decoder *cxlrd);
+#else
+static bool arch_match_spa(struct cxl_root_decoder *cxlrd,
+			   struct cxl_endpoint_decoder *cxled)
+{
+	return false;
+}
+
+static bool arch_match_region(struct cxl_region_params *p,
+			      struct cxl_decoder *cxld)
+{
+	return false;
+}
+
+static void arch_adjust_region_resource(struct resource *res,
+					struct cxl_root_decoder *cxlrd)
+{
+}
+#endif /* CXL_ARCH_LOW_MEMORY_HOLE */
Signature · 1 line
2.47.1
#3 lore raw

Re: [PATCH 2/4 v2] cxl/core: Add helpers to detect Low memory Holes on x86

Quoted 9 lines · Fabio M. De Francesco

+/*
+ * Match CXL Root and Endpoint Decoders by comparing SPA and HPA ranges.
+ *
+ * On x86, CFMWS ranges never intersect memory holes while endpoint decoders
+ * HPA range sizes are always guaranteed aligned to NIW * 256MB; therefore,
+ * the given endpoint decoder HPA range size is always expected aligned and
+ * also larger than that of the matching root decoder. If there are LMH's,
+ * the root decoder range end is always less than SZ_4G.
+ */

Is there any reason to limit this memory-hole handling to only low memory holes? I have observed systems where the following memory hole situation occurs:

(example, not exact sizes)

CFMW1:   [  0xc0000000 - 0xdfffffff  ] 512MB range
Reserved [  0xe0000000 - 0xffffffff  ] 512MB range

CFMW2: [ 0x100000000 - 0x15fffffff ] 1.5GB range

2 CXL Memory Devices w/ 1GB capacity each (again, an example).

Note that 1 device has its capacity split across the hole, but if the devices are interleaved then both devices have their capacity split across the hole.

It seems with some mild modification, this patch set could be re-used to handle this memory hole scenario as well (w/ addr translation - Robert's patch set)

Is there a reason not to handle more than just LMH's in this set?

(I may try to hack this up on my test system and report back.)

~Gregory

#4 lore raw

Re: [PATCH 2/4 v2] cxl/core: Add helpers to detect Low memory Holes on x86

Quoted 11 lines · On Wednesday, January 15, 2025 3:23:36 AM GMT+1 Gregory Price wrote:
Quoted 9 lines · Fabio M. De Francesco

+/*
+ * Match CXL Root and Endpoint Decoders by comparing SPA and HPA ranges.
+ *
+ * On x86, CFMWS ranges never intersect memory holes while endpoint decoders
+ * HPA range sizes are always guaranteed aligned to NIW * 256MB; therefore,
+ * the given endpoint decoder HPA range size is always expected aligned and
+ * also larger than that of the matching root decoder. If there are LMH's,
+ * the root decoder range end is always less than SZ_4G.
+ */

Quoted 3 lines

Is there any reason to limit this memory-hole handling to only low memory holes?

No I don't see any special reasons to limit this to only low memory holes. It's just that I didn't know about others.

Quoted 15 lines

I have observed systems where the following memory hole situation occurs:

(example, not exact sizes)

CFMW1:   [  0xc0000000 - 0xdfffffff  ] 512MB range
Reserved [  0xe0000000 - 0xffffffff  ] 512MB range

CFMW2: [ 0x100000000 - 0x15fffffff ] 1.5GB range

2 CXL Memory Devices w/ 1GB capacity each (again, an example).

Note that 1 device has its capacity split across the hole, but if the devices are interleaved then both devices have their capacity split across the hole.

Quoted 8 lines

It seems with some mild modification, this patch set could be re-used to handle this memory hole scenario as well (w/ addr translation - Robert's patch set)

Is there a reason not to handle more than just LMH's in this set?

(I may try to hack this up on my test system and report back.)

I'd appreciate it if you want to report back.

Thank you,

Fabio

Quoted 3 lines

~Gregory

#5 lore raw

Re: [PATCH 2/4 v2] cxl/core: Add helpers to detect Low memory Holes on x86

In reply to Gregory Price
Quoted 26 lines · Gregory Price
Quoted 9 lines · Fabio M. De Francesco

+/*
+ * Match CXL Root and Endpoint Decoders by comparing SPA and HPA ranges.
+ *
+ * On x86, CFMWS ranges never intersect memory holes while endpoint decoders
+ * HPA range sizes are always guaranteed aligned to NIW * 256MB; therefore,
+ * the given endpoint decoder HPA range size is always expected aligned and
+ * also larger than that of the matching root decoder. If there are LMH's,
+ * the root decoder range end is always less than SZ_4G.
+ */

Is there any reason to limit this memory-hole handling to only low memory holes? I have observed systems where the following memory hole situation occurs:

(example, not exact sizes)

CFMW1:   [  0xc0000000 - 0xdfffffff  ] 512MB range
Reserved [  0xe0000000 - 0xffffffff  ] 512MB range

CFMW2: [ 0x100000000 - 0x15fffffff ] 1.5GB range

2 CXL Memory Devices w/ 1GB capacity each (again, an example).

Note that 1 device has its capacity split across the hole, but if the devices are interleaved then both devices have their capacity split across the hole.

Quoted 5 lines

It seems with some mild modification, this patch set could be re-used to handle this memory hole scenario as well (w/ addr translation - Robert's patch set)

Is there a reason not to handle more than just LMH's in this set?

This discussion was referenced recently on an IM and I wanted to share my response to it:

The rules for when to apply this memory hole quirk are explicit and suitable to add to the CXL specification. I want the same standard for any other quirk and ideally some proof-of-work to get that quirk recognized by the specification. Otherwise, I worry that generalizing for all the possible ways that platform BIOS tries to be clever means we end up with something that has no rules.

The spec is there to allow software to delineate valid configurations vs mistakes, and this slow drip of "Linux does not understand this platform configuration" is a spec gap.

#6 lore raw

Re: [PATCH 2/4 v2] cxl/core: Add helpers to detect Low memory Holes on x86

Quoted 13 lines · Dan Williams
Quoted 1 line · Gregory Price

Is there a reason not to handle more than just LMH's in this set?

This discussion was referenced recently on an IM and I wanted to share my response to it:

The rules for when to apply this memory hole quirk are explicit and suitable to add to the CXL specification. I want the same standard for any other quirk and ideally some proof-of-work to get that quirk recognized by the specification. Otherwise, I worry that generalizing for all the possible ways that platform BIOS tries to be clever means we end up with something that has no rules.

Quoted 3 lines

The spec is there to allow software to delineate valid configurations vs mistakes, and this slow drip of "Linux does not understand this platform configuration" is a spec gap.

Note: I've since come around to understand the whole ecosystem a bit
better since i wrote this response. I don't know that it's needed.

Some of the explanation of this patch series is a bit confusing. It justifies itself by saying CFMWS don't intersect memory holes and that endpoint decoders have to be 256MB aligned.

/*
* Match CXL Root and Endpoint Decoders by comparing SPA and HPA ranges. *
* On x86, CFMWS ranges never intersect memory holes while endpoint decoders
* HPA range sizes are always guaranteed aligned to NIW * 256MB; therefore,
* the given endpoint decoder HPA range size is always expected aligned and
* also larger than that of the matching root decoder. If there are LMH's,
* the root decoder range end is always less than SZ_4G.
*/

But per the spec, CFMWS is also aligned to be aligned to 256MB.

Shouldn't the platform work around memory holes to generate multiple CFMWS for the entire capacity, and then use multiple endpoint decoders (1 per CFMWS) to map the capacity accordingly?

(Also, I still don't understand the oracle value of <4GB address range.
It seems like if this is some quirk of SPA vs HPA alignment, then it can hold for *all* ocurrances, not just stuff below 4GB)

~Gregory

#7 lore raw

Re: [PATCH 2/4 v2] cxl/core: Add helpers to detect Low memory Holes on x86

Quoted 14 lines · Gregory Price
Quoted 13 lines · Dan Williams
Quoted 1 line · Gregory Price

Is there a reason not to handle more than just LMH's in this set?

This discussion was referenced recently on an IM and I wanted to share my response to it:

The rules for when to apply this memory hole quirk are explicit and suitable to add to the CXL specification. I want the same standard for any other quirk and ideally some proof-of-work to get that quirk recognized by the specification. Otherwise, I worry that generalizing for all the possible ways that platform BIOS tries to be clever means we end up with something that has no rules.

Quoted 6 lines
Quoted 3 lines

The spec is there to allow software to delineate valid configurations vs mistakes, and this slow drip of "Linux does not understand this platform configuration" is a spec gap.

Note: I've since come around to understand the whole ecosystem a bit
better since i wrote this response.

Yes, I should have acknowledged shifts in understanding since this thread went quiet. Fabio was about to spin this set again to add more "generalization" and I wanted to clarify my current thinking that generalization is the opposite of what should happen here.

Quoted 1 line

I don't know that it's needed.

Referring to spec changes? I think they are, see below

Quoted 14 lines

Some of the explanation of this patch series is a bit confusing. It justifies itself by saying CFMWS don't intersect memory holes and that endpoint decoders have to be 256MB aligned.

/*
* Match CXL Root and Endpoint Decoders by comparing SPA and HPA ranges. *
* On x86, CFMWS ranges never intersect memory holes while endpoint decoders
* HPA range sizes are always guaranteed aligned to NIW * 256MB; therefore,
* the given endpoint decoder HPA range size is always expected aligned and
* also larger than that of the matching root decoder. If there are LMH's,
* the root decoder range end is always less than SZ_4G.
*/

Quoted 1 line

But per the spec, CFMWS is also aligned to be aligned to 256MB.

Right, something has to give, i.e. "spec meet reality". Hardware endpoint decoders must be aligned, that is a shipping expectation, and endpoints are not in a position to know or care about host platform constraints. In constrast, the CFMWS definition runs into a practical problem meeting the same expectation given competing host phyiscal memory map constraints.

The platforms with this condition want to support CXL mapped starting at zero *and* the typical/historical PCI MMIO space in low memory (for those PCI devices that do not support 64-bit addressing). If the CFMWS blindly followed the 256MB*NIW constraint the CXL window would overlap the MMIO space. So the choices are:

1/ Give up on mapping CXL starting at zero when 256MB * NIW does not fit 2/ Give up on maintaining historical availabilty of and compatibility
with 32-bit only PCI devices (PCI configuration regression)
3/ Trim CFMWS to match the reality that the platform will always route
memory cycles in that PCI MMIO range to PCI MMIO and never to CXL.
4/ Define some new protocol for when CFMWS is explicitly countermanded
by other platform resource descriptors, and not a BIOS bug.

The platform in question chose option 3.

Quoted 3 lines

Shouldn't the platform work around memory holes to generate multiple CFMWS for the entire capacity, and then use multiple endpoint decoders (1 per CFMWS) to map the capacity accordingly?

Per above, the maths do not work out to be able to support that relative to a CXL region with problematic NIW.

Quoted 3 lines

(Also, I still don't understand the oracle value of <4GB address range.
It seems like if this is some quirk of SPA vs HPA alignment, then it can hold for *all* ocurrances, not just stuff below 4GB)

The goal is to get platform vendors to define the rules so that an OS has a reasonable expectation to know what is a valid vs invalid configuration. A hole above 4GB has no reason to exist, there is no resource conflict like PCI MMIO that explains why typical spec expectation can not be met.

So I want the subsystem to have an explicit set of platform quirks ideally backed up by updated spec language. That allows us to validate that the Linux implementation is correct by some objective source of truth, encourage platform vendors to update that source of truth when they create new corner cases, or even better, be more mindful to not create new corner cases.

#8 lore raw

Re: [PATCH 2/4 v2] cxl/core: Add helpers to detect Low memory Holes on x86

Quoted 6 lines · Dan Williams

The platforms with this condition want to support CXL mapped starting at zero *and* the typical/historical PCI MMIO space in low memory (for those PCI devices that do not support 64-bit addressing). If the CFMWS blindly followed the 256MB*NIW constraint the CXL window would overlap the MMIO space. So the choices are:

If I'm understanding everything correctly, then I think this is intended to work only when EFI_MEMORY_SP is *not* set for these particular CXL devices - so it comes up as memory in early boot and we're just trying to wire up all the bits to let the driver manage it accordingly?

If that's the case, then ignore me, i'm just bikeshedding at this point.

I can't imagine a system where the memory at 0x0-4GB is intended to come up as EFI_MEMORY_SP, so I hope no one ever tries this :D

Quoted 10 lines
Quoted 3 lines

(Also, I still don't understand the oracle value of <4GB address range.
It seems like if this is some quirk of SPA vs HPA alignment, then it can hold for *all* ocurrances, not just stuff below 4GB)

The goal is to get platform vendors to define the rules so that an OS has a reasonable expectation to know what is a valid vs invalid configuration. A hole above 4GB has no reason to exist, there is no resource conflict like PCI MMIO that explains why typical spec expectation can not be met.

Quoted 6 lines

So I want the subsystem to have an explicit set of platform quirks ideally backed up by updated spec language. That allows us to validate that the Linux implementation is correct by some objective source of truth, encourage platform vendors to update that source of truth when they create new corner cases, or even better, be more mindful to not create new corner cases.

I follow, seems reasonable.

~Gregory

#9 lore raw

Re: [PATCH 2/4 v2] cxl/core: Add helpers to detect Low memory Holes on x86

Quoted 8 lines · Gregory Price
Quoted 6 lines · Dan Williams

The platforms with this condition want to support CXL mapped starting at zero *and* the typical/historical PCI MMIO space in low memory (for those PCI devices that do not support 64-bit addressing). If the CFMWS blindly followed the 256MB*NIW constraint the CXL window would overlap the MMIO space. So the choices are:

Quoted 4 lines

If I'm understanding everything correctly, then I think this is intended to work only when EFI_MEMORY_SP is *not* set for these particular CXL devices - so it comes up as memory in early boot and we're just trying to wire up all the bits to let the driver manage it accordingly?

That is how I understand things. But I'm just jumping in just to review the patches so I could be wrong...

Ira

Quoted 26 lines

If that's the case, then ignore me, i'm just bikeshedding at this point.

I can't imagine a system where the memory at 0x0-4GB is intended to come up as EFI_MEMORY_SP, so I hope no one ever tries this :D

Quoted 10 lines
Quoted 3 lines

(Also, I still don't understand the oracle value of <4GB address range.
It seems like if this is some quirk of SPA vs HPA alignment, then it can hold for *all* ocurrances, not just stuff below 4GB)

The goal is to get platform vendors to define the rules so that an OS has a reasonable expectation to know what is a valid vs invalid configuration. A hole above 4GB has no reason to exist, there is no resource conflict like PCI MMIO that explains why typical spec expectation can not be met.

Quoted 6 lines

So I want the subsystem to have an explicit set of platform quirks ideally backed up by updated spec language. That allows us to validate that the Linux implementation is correct by some objective source of truth, encourage platform vendors to update that source of truth when they create new corner cases, or even better, be more mindful to not create new corner cases.

I follow, seems reasonable.

~Gregory

#10 lore raw

PATCH v2 3/4 cxl/core: Enable Region creation on x86 with Low Memory Hole

In reply to Fabio M. De Francesco

The CXL Fixed Memory Window Structure (CFMWS) describes zero or more Host Physical Address (HPA) windows that are associated with each CXL Host Bridge. Each window represents a contiguous HPA that may be interleaved with one or more targets (CXL v3.1 - 9.18.1.3).

The Low Memory Hole (LMH) of x86 is a range of addresses of physical low memory to which systems cannot send transactions. In some cases the size of that hole is not compatible with the CXL hardware decoder constraint that the size is always aligned to 256M * Interleave Ways.

On those systems, BIOS publishes CFMWS which communicate the active System Physical Address (SPA) ranges that map to a subset of the Host Physical Address (HPA) ranges. The SPA range trims out the hole, and capacity in the endpoint is lost with no SPA to map to CXL HPA in that hole.

In the early stages of CXL Regions construction and attach on platforms with Low Memory Holes, cxl_add_to_region() fails and returns an error because it can't find any CXL Window that matches a given CXL Endpoint Decoder.

Detect a Low Memory Hole by comparing Root Decoders and Endpoint Decoders ranges with the use of arch_match_{spa,region}() helpers.

Match Root Decoders and CXL Regions with corresponding CXL Endpoint Decoders. Currently a Low Memory Holes would prevent the matching functions to return true.

Construct CXL Regions with HPA range's end adjusted to the matching SPA.

Allow the attach target process to complete by allowing Regions to not comply with alignment constraints (i.e., alignment to NIW * 256M rule).

Cc Alison Schofield <[email protected]>
Cc Dan Williams <[email protected]>
Cc Ira Weiny <[email protected]>
---
 drivers/cxl/Kconfig       |  5 ++++
 drivers/cxl/core/Makefile |  1 +
 drivers/cxl/core/region.c | 56 ++++++++++++++++++++++++++++++++-------
 tools/testing/cxl/Kbuild  |  1 +
 4 files changed, 54 insertions(+), 9 deletions(-)
drivers/cxl/Kconfig +5 -0
index 876469e23f7a7..07b87f217e590 100644
@@ -128,6 +128,11 @@ config CXL_REGION
 
 	  If unsure say 'y'
 
+config CXL_ARCH_LOW_MEMORY_HOLE
+	def_bool y
+	depends on CXL_REGION
+	depends on X86
+
 config CXL_REGION_INVALIDATION_TEST
 	bool "CXL: Region Cache Management Bypass (TEST)"
 	depends on CXL_REGION
drivers/cxl/core/Makefile +1 -0
index 9259bcc6773c8..6e80215e8444f 100644
@@ -15,4 +15,5 @@ cxl_core-y += hdm.o
 cxl_core-y += pmu.o
 cxl_core-y += cdat.o
 cxl_core-$(CONFIG_TRACING) += trace.o
+cxl_core-$(CONFIG_CXL_ARCH_LOW_MEMORY_HOLE) += lmh.o
 cxl_core-$(CONFIG_CXL_REGION) += region.o
drivers/cxl/core/region.c +47 -9

110 lines not on this page · raw message

tools/testing/cxl/Kbuild +1 -0
index b1256fee3567f..fe9c4480f7583 100644
@@ -62,6 +62,7 @@ cxl_core-y += $(CXL_CORE_SRC)/hdm.o
 cxl_core-y += $(CXL_CORE_SRC)/pmu.o
 cxl_core-y += $(CXL_CORE_SRC)/cdat.o
 cxl_core-$(CONFIG_TRACING) += $(CXL_CORE_SRC)/trace.o
+cxl_core-$(CONFIG_CXL_ARCH_LOW_MEMORY_HOLE) += $(CXL_CORE_SRC)/lmh.o
 cxl_core-$(CONFIG_CXL_REGION) += $(CXL_CORE_SRC)/region.o
 cxl_core-y += config_check.o
 cxl_core-y += cxl_core_test.o
Signature · 1 line
2.47.1
#11 lore raw

PATCH v2 4/4 cxl/test: Simulate an x86 Low Memory Hole for tests

In reply to Fabio M. De Francesco

Simulate an x86 Low Memory Hole for the CXL tests by changing the first mock CFMWS range size to 768MB and the CXL Endpoint Decoder HPA range sizes to 1GB.

Since the auto-created region of cxl-test uses mock_cfmws[0], whose range base address is typically different from the one published by the BIOS on real hardware, the driver would fail to create and attach CXL Regions if it was run on the mock environment created by cxl-tests.

Therefore, save the mock_cfmsw[0] range base_hpa and reuse it to match CXL Root Decoders and Regions with Endpoint Decoders when the driver is run on mock devices.

Since the auto-created region of cxl-test uses mock_cfmws[0], the LMH path in the CXL Driver will be exercised every time the cxl-test module is loaded. Executing unit test: cxl-topology.sh, confirms the region created successfully with a LMH.

Cc Alison Schofield <[email protected]>
Cc Dan Williams <[email protected]>
Cc Ira Weiny <[email protected]>
---
 drivers/cxl/core/lmh.c               | 32 +++++++++++++++++++++++++---
 drivers/cxl/core/lmh.h               |  2 ++
 tools/testing/cxl/cxl_core_exports.c |  2 ++
 tools/testing/cxl/test/cxl.c         | 10 +++++++++
 4 files changed, 43 insertions(+), 3 deletions(-)
drivers/cxl/core/lmh.c +29 -3
index 232ebea0a8364..b981aeea805d6 100644
@@ -1,11 +1,28 @@
 // SPDX-License-Identifier: GPL-2.0-only
 
 #include <linux/range.h>
+#include <linux/pci.h>
+
 #include "lmh.h"
 
 /* Start of CFMWS range that end before x86 Low Memory Holes */
 #define LMH_CFMWS_RANGE_START 0x0ULL
 
+static u64 mock_cfmws0_range_start = ULLONG_MAX;
+
+void set_mock_cfmws0_range_start(u64 start)
+{
+	mock_cfmws0_range_start = start;
+}
+
+static u64 get_cfmws_range_start(struct device *dev)
+{
+	if (dev_is_pci(dev))
+		return LMH_CFMWS_RANGE_START;
+
+	return mock_cfmws0_range_start;
+}
+
 /*
  * Match CXL Root and Endpoint Decoders by comparing SPA and HPA ranges.
  *
@@ -18,9 +35,14 @@
 bool arch_match_spa(struct cxl_root_decoder *cxlrd,
 		    struct cxl_endpoint_decoder *cxled)
 {
+	u64 cfmws_range_start;
 	struct range *r1, *r2;
 	int niw;
 
+	cfmws_range_start = get_cfmws_range_start(&cxled->cxld.dev);
+	if (cfmws_range_start == ULLONG_MAX)
+		return false;
+
 	r1 = &cxlrd->cxlsd.cxld.hpa_range;
 	r2 = &cxled->cxld.hpa_range;
 	niw = cxled->cxld.interleave_ways;
@@ -36,13 +58,17 @@ bool arch_match_spa(struct cxl_root_decoder *cxlrd,
 /* Similar to arch_match_spa(), it matches regions and decoders */
 bool arch_match_region(struct cxl_region_params *p, struct cxl_decoder *cxld)
 {
+	u64 cfmws_range_start;
 	struct range *r = &cxld->hpa_range;
 	struct resource *res = p->res;
 	int niw = cxld->interleave_ways;
 
-	if (res->start == LMH_CFMWS_RANGE_START && res->start == r->start &&
-	    res->end < (LMH_CFMWS_RANGE_START + SZ_4G) && res->end < r->end &&
-	    IS_ALIGNED(range_len(r), niw * SZ_256M))
+	cfmws_range_start = get_cfmws_range_start(&cxld->dev);
+	if (cfmws_range_start == ULLONG_MAX)
+		return false;
+
+	if (res->start == cfmws_range_start && res->start == r->start &&
+	    res->end < r->end && IS_ALIGNED(range_len(r), niw * SZ_256M))
 		return true;
 
 	return false;
drivers/cxl/core/lmh.h +2 -0
index ec8907145afe8..d804108fbb41a 100644
@@ -2,6 +2,8 @@
 
 #include "cxl.h"
 
+void set_mock_cfmws0_range_start(u64 start);
+
 #ifdef CONFIG_CXL_ARCH_LOW_MEMORY_HOLE
 bool arch_match_spa(struct cxl_root_decoder *cxlrd,
 		    struct cxl_endpoint_decoder *cxled);
tools/testing/cxl/cxl_core_exports.c +2 -0
index f088792a8925f..7b20f9fcf0d75 100644
@@ -2,6 +2,8 @@
 /* Copyright(c) 2022 Intel Corporation. All rights reserved. */
 
 #include "cxl.h"
+#include "lmh.h"
 
 /* Exporting of cxl_core symbols that are only used by cxl_test */
 EXPORT_SYMBOL_NS_GPL(cxl_num_decoders_committed, "CXL");
+EXPORT_SYMBOL_NS_GPL(set_mock_cfmws0_range_start, "CXL");
tools/testing/cxl/test/cxl.c +10 -0
index d0337c11f9ee6..6bd305e778687 100644
@@ -9,6 +9,7 @@
 #include <linux/pci.h>
 #include <linux/mm.h>
 #include <cxlmem.h>
+#include <core/lmh.h>
 
 #include "../watermark.h"
 #include "mock.h"
@@ -212,7 +213,11 @@ static struct {
 			.restrictions = ACPI_CEDT_CFMWS_RESTRICT_TYPE3 |
 					ACPI_CEDT_CFMWS_RESTRICT_VOLATILE,
 			.qtg_id = FAKE_QTG_ID,
+#if defined(CONFIG_CXL_ARCH_LOW_MEMORY_HOLE)
+			.window_size = SZ_256M * 3UL,
+#else
 			.window_size = SZ_256M * 4UL,
+#endif
 		},
 		.target = { 0 },
 	},
@@ -454,6 +459,7 @@ static int populate_cedt(void)
 			return -ENOMEM;
 		window->base_hpa = res->range.start;
 	}
+	set_mock_cfmws0_range_start(mock_cfmws[0]->base_hpa);
 
 	return 0;
 }
@@ -744,7 +750,11 @@ static void mock_init_hdm_decoder(struct cxl_decoder *cxld)
 	struct cxl_endpoint_decoder *cxled;
 	struct cxl_switch_decoder *cxlsd;
 	struct cxl_port *port, *iter;
+#if defined(CONFIG_CXL_ARCH_LOW_MEMORY_HOLE)
+	const int size = SZ_1G;
+#else
 	const int size = SZ_512M;
+#endif
 	struct cxl_memdev *cxlmd;
 	struct cxl_dport *dport;
 	struct device *dev;
Signature · 1 line
2.47.1