cxl/core: Enable Region creation/attach on x86 with LMH
v4 cover cxl/core: Enable Region creation/attach on x86 with LMH
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, Dave and Ira for their help.
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 v4:
Re-base on top of
"cxl: Address translation support, part 1: Cleanups and refactoring";[1]
Drop no more necessary 2/4;
Drop collected tags because of major changes throughout the series.
1/3 - Adjust Endpoint Decoders dpa_res->end (Alison) [2] 3/3 - Use weak/strong mechanism (Dan) [3]
Changes for v3:
Re-base the series on cxl/next.
1/4 - 2/4:
Constify local variables.
3/4:
Call arch_match_region() from region_res_match_cxl_range().
4/4:
arch_match_region() - Check that region end is under start + 4G; arch_match_spa() - Check that SPA range start is cfmws_range_start.
v3 - https://lore.kernel.org/linux-cxl/[email protected]/
v2 - https://lore.kernel.org/linux-cxl/[email protected]/
v1 - https://lore.kernel.org/all/[email protected]/
[0] - https://lore.kernel.org/all/[email protected]/
[1] - https://lore.kernel.org/linux-cxl/[email protected]/
[2] - https://lore.kernel.org/linux-cxl/[email protected]/
[3] - https://lore.kernel.org/linux-cxl/[email protected]/
Fabio M. De Francesco (4):
cxl/core: Change match_*_by_range() signatures cxl/core: Add helpers to detect Low Memory Holes on x86 cxl/core: Enable Region creation on x86 with LMH cxl/test: Simulate an x86 Low Memory Hole for tests
drivers/cxl/Kconfig | 5 ++ drivers/cxl/core/Makefile | 1 + drivers/cxl/core/platform.c | 86 +++++++++++++++++++ drivers/cxl/core/platform.h | 32 +++++++ drivers/cxl/core/region.c | 113 ++++++++++++++++-------- tools/testing/cxl/Kbuild | 2 + tools/testing/cxl/mock_platform.c | 137 ++++++++++++++++++++++++++++++ tools/testing/cxl/test/cxl.c | 10 +++ tools/testing/cxl/test/mock.h | 1 + 9 files changed, 352 insertions(+), 35 deletions(-) create mode 100644 drivers/cxl/core/platform.c create mode 100644 drivers/cxl/core/platform.h create mode 100644 tools/testing/cxl/mock_platform.c
base-commit: acc2913692413df9d1
Signature · 1 line
2.50.1
PATCH v4 1/4 cxl/core: Change match_*_by_range() signatures
Replace struct range parameter with struct cxl_endpoint_decoder of which range is a member in the match_*_by_range() functions and rename them according to their semantics.
This is in preparation for expanding these helpers to perform arch specific Root Decoders and Region matchings with cxl_endpoint_decoder(s).
--- drivers/cxl/core/region.c | 60 +++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 27 deletions(-)
drivers/cxl/core/region.c +33 -27
@@ -1759,27 +1759,29 @@ static int cmp_interleave_pos(const void *a, const void *b)return cxled_a->pos - cxled_b->pos; } -static int match_switch_decoder_by_range (struct device *dev, -const void *data) +static int match_switch_and_ep_decoders (struct device *dev,const void *data) { +const struct cxl_endpoint_decoder *cxled = data;struct cxl_switch_decoder *cxlsd; -const struct range *r1, *r2 = data; - +const 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, -int *pos,int *ways) +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;
@@ -1789,8 +1791,8 @@ static int find_pos_and_ways(struct cxl_port *port, struct range *range,if (!parent)return rc; - dev =device_find_child (&parent->dev, range, - match_switch_decoder_by_range); + dev =device_find_child (&parent->dev, cxled, + match_switch_and_ep_decoders);if (!dev) { dev_err(port->uport_dev, "failed to find decoder mapping %#llx-%#llx\n",
@@ -1876,7 +1878,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;
@@ -3215,24 +3217,28 @@ static int devm_cxl_add_dax_region(struct cxl_region *cxlr)return rc; } -static int match_decoder_by_range (struct device *dev,const void *data) +static int match_root_and_ep_decoders (struct device *dev,const void *data) { -const struct range *r1, *r2 = data; -struct cxl_decoder *cxld; +const struct cxl_endpoint_decoder *cxled = data; +const struct range *r1, *r2; +struct cxl_root_decoder *cxlrd; -if (!is_switch_decoder (dev)) +if (!is_root_decoder (dev))return 0 ; - cxld =to_cxl_decoder (dev); - r1 = &cxld->hpa_range; + cxlrd =to_cxl_root_decoder (dev); + r1 = &cxlrd->cxlsd.cxld.hpa_range; + r2 = &cxled->cxld.hpa_range; +return range_contains (r1, r2); }static struct cxl_decoder * -cxl_port_find_switch_decoder (struct cxl_port *port,struct range *hpa) +cxl_port_find_root_decoder (struct cxl_port *port, +struct cxl_endpoint_decoder *cxled) { -struct device *cxld_dev =device_find_child (&port->dev, hpa, - match_decoder_by_range); +struct device *cxld_dev =device_find_child (&port->dev, cxled, + match_root_and_ep_decoders);return cxld_dev ?to_cxl_decoder (cxld_dev) :NULL ; }
@@ -3244,9 +3250,8 @@ cxl_find_root_decoder(struct cxl_endpoint_decoder *cxled)struct cxl_port *port =cxled_to_port (cxled); struct cxl_root *cxl_root __free(put_cxl_root) = find_cxl_root(port);struct cxl_decoder *root, *cxld = &cxled->cxld; -struct range *hpa = &cxld->hpa_range; - root =cxl_port_find_switch_decoder (&cxl_root->port, hpa); + root =cxl_port_find_root_decoder (&cxl_root->port, cxled);if (!root) { dev_err(cxlmd->dev.parent, "%s:%s no CXL window for range %#llx:%#llx\n",
@@ -3258,11 +3263,12 @@ cxl_find_root_decoder(struct cxl_endpoint_decoder *cxled)return to_cxl_root_decoder (&root->dev); } -static int match_region_by_range (struct device *dev,const void *data) +static int match_region_and_ep_decoder (struct device *dev,const void *data) { +const struct cxl_endpoint_decoder *cxled = data; +const struct range *r = &cxled->cxld.hpa_range;struct cxl_region_params *p;struct cxl_region *cxlr; -const struct range *r = data;if (!is_cxl_region (dev))return 0 ;
@@ -3425,12 +3431,13 @@ static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd, }static struct cxl_region * -cxl_find_region_by_range (struct cxl_root_decoder *cxlrd,struct range *hpa) +cxl_find_region_by_range (struct cxl_root_decoder *cxlrd, +struct cxl_endpoint_decoder *cxled) {struct device *region_dev; - region_dev =device_find_child (&cxlrd->cxlsd.cxld.dev, hpa, - match_region_by_range); + region_dev =device_find_child (&cxlrd->cxlsd.cxld.dev, cxled, + match_region_and_ep_decoder);if (!region_dev)return NULL ;
@@ -3439,7 +3446,6 @@ cxl_find_region_by_range(struct cxl_root_decoder *cxlrd, struct range *hpa)int cxl_add_to_region (struct cxl_endpoint_decoder *cxled) { -struct range *hpa = &cxled->cxld.hpa_range;struct cxl_region_params *p;bool attach = false;int rc;
@@ -3455,7 +3461,7 @@ int cxl_add_to_region(struct cxl_endpoint_decoder *cxled)*/ mutex_lock (&cxlrd->range_lock); struct cxl_region *cxlr __free(put_cxl_region) = -cxl_find_region_by_range (cxlrd, hpa); +cxl_find_region_by_range (cxlrd, cxled);if (!cxlr) cxlr =construct_region (cxlrd, cxled);mutex_unlock (&cxlrd->range_lock);
Signature · 1 line
2.50.1
Re: [PATCH 1/4 v4] cxl/core: Change match_*_by_range() signatures
Quoted 79 lines · Fabio M. De Francesco
Replace struct range parameter with struct
cxl_endpoint_decoderof which range is a member in the match_*_by_range() functions and rename them according to their semantics.This is in preparation for expanding these helpers to perform arch specific Root Decoders and Region matchings with
cxl_endpoint_decoder(s).Cc Alison Schofield <[email protected]>Cc Dan Williams <[email protected]>Cc Dave Jiang <[email protected]>Cc Ira Weiny <[email protected]>Signed-off-by Fabio M. De Francesco <[email protected]>--- drivers/cxl/core/region.c | 60 +++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 27 deletions(-)drivers/cxl/core/region.c +11
-9@@ -1759,27 +1759,29 @@ static int cmp_interleave_pos(const void *a, const void *b)return cxled_a->pos - cxled_b->pos; } -static int match_switch_decoder_by_range (struct device *dev, -const void *data) +static int match_switch_and_ep_decoders (struct device *dev,const void *data) { +const struct cxl_endpoint_decoder *cxled = data;struct cxl_switch_decoder *cxlsd; -const struct range *r1, *r2 = data; - +const 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, -int *pos,int *ways) +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;@@ -1789,8 +1791,8 @@ static int find_pos_and_ways(struct cxl_port *port, struct range *range,if (!parent)return rc; - dev =device_find_child (&parent->dev, range, - match_switch_decoder_by_range); + dev =device_find_child (&parent->dev, cxled, + match_switch_and_ep_decoders);if (!dev) { dev_err(port->uport_dev, "failed to find decoder mapping %#llx-%#llx\n",@@ -1876,7 +1878,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;@@ -3215,24 +3217,28 @@ static int devm_cxl_add_dax_region(struct cxl_region *cxlr)return rc;
drivers/cxl/core/region.c static int devm_cxl_add_dax_region(struct cxl_region *cxlr) · line 3224
Quoted 10 lines
drivers/cxl/core/region.c +4
-3} -static int match_decoder_by_range (struct device *dev,const void *data) +static int match_root_and_ep_decoders (struct device *dev,const void *data) { -const struct range *r1, *r2 = data; -struct cxl_decoder *cxld; +const struct cxl_endpoint_decoder *cxled = data; +const struct range *r1, *r2; +struct cxl_root_decoder *cxlrd;
Nit: cxlrd should be above the r1, r2 declaration (reverse christmas tree).
drivers/cxl/core/region.c static int devm_cxl_add_dax_region(struct cxl_region *cxlr) · line 3234
Quoted 13 lines
drivers/cxl/core/region.c +5
-3-if (!is_switch_decoder (dev)) +if (!is_root_decoder (dev))return 0 ; - cxld =to_cxl_decoder (dev); - r1 = &cxld->hpa_range; + cxlrd =to_cxl_root_decoder (dev); + r1 = &cxlrd->cxlsd.cxld.hpa_range; + r2 = &cxled->cxld.hpa_range; +return range_contains (r1, r2); }
You could reuse the code from match_switch_and_ep_decoders() here by doing:
static int match_root_and_ep_decoders(struct device *dev, const void *data)
{
if (!is_root_decoder(dev))
return 0;
return match_switch_and_ep_decoders(dev, data);
}Re: [PATCH 1/4 v4] cxl/core: Change match_*_by_range() signatures
In reply to Fabio M. De FrancescoQuoted 8 lines · On Thu, 24 Jul 2025 16:20:31 +0200 "Fabio M. De Francesco"…
Replace struct range parameter with struct
cxl_endpoint_decoderof which range is a member in the match_*_by_range() functions and rename them according to their semantics.This is in preparation for expanding these helpers to perform arch specific Root Decoders and Region matchings with
cxl_endpoint_decoder(s).
Quoted 5 lines
Cc Alison Schofield <[email protected]>Cc Dan Williams <[email protected]>Cc Dave Jiang <[email protected]>Cc Ira Weiny <[email protected]>Signed-off-by Fabio M. De Francesco <[email protected]>
Dave Jiang
maintainerRe: [PATCH 1/4 v4] cxl/core: Change match_*_by_range() signatures
In reply to Fabio M. De FrancescoQuoted 22 lines · Fabio M. De Francesco
Replace struct range parameter with struct
cxl_endpoint_decoderof which range is a member in the match_*_by_range() functions and rename them according to their semantics.This is in preparation for expanding these helpers to perform arch specific Root Decoders and Region matchings with
cxl_endpoint_decoder(s).Cc Alison Schofield <[email protected]>Cc Dan Williams <[email protected]>Cc Dave Jiang <[email protected]>Cc Ira Weiny <[email protected]>Signed-off-by Fabio M. De Francesco <[email protected]>--- drivers/cxl/core/region.c | 60 +++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 27 deletions(-)drivers/cxl/core/region.c +0
-0
drivers/cxl/core/region.c static int cmp_interleave_pos(const void *a, const void *b) · line 1762
Quoted 6 lines
drivers/cxl/core/region.c +1
-2@@ -1759,27 +1759,29 @@ static int cmp_interleave_pos(const void *a, const void *b)return cxled_a->pos - cxled_b->pos; } -static int match_switch_decoder_by_range (struct device *dev, -const void *data) +static int match_switch_and_ep_decoders (struct device *dev,const void *data)
match_cxlsd_to_cxled_by_range()?
Quoted 50 lines
drivers/cxl/core/region.c +10
-7{ +const struct cxl_endpoint_decoder *cxled = data;struct cxl_switch_decoder *cxlsd; -const struct range *r1, *r2 = data; - +const 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, -int *pos,int *ways) +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;@@ -1789,8 +1791,8 @@ static int find_pos_and_ways(struct cxl_port *port, struct range *range,if (!parent)return rc; - dev =device_find_child (&parent->dev, range, - match_switch_decoder_by_range); + dev =device_find_child (&parent->dev, cxled, + match_switch_and_ep_decoders);if (!dev) { dev_err(port->uport_dev, "failed to find decoder mapping %#llx-%#llx\n",@@ -1876,7 +1878,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;
drivers/cxl/core/region.c static int devm_cxl_add_dax_region(struct cxl_region *cxlr) · line 3220
Quoted 5 lines
drivers/cxl/core/region.c +1
-1@@ -3215,24 +3217,28 @@ static int devm_cxl_add_dax_region(struct cxl_region *cxlr)return rc; } -static int match_decoder_by_range (struct device *dev,const void *data) +static int match_root_and_ep_decoders (struct device *dev,const void *data)
match_cxlrd_to_cxled_by_range()
Quoted 44 lines
drivers/cxl/core/region.c +13
-10{ -const struct range *r1, *r2 = data; -struct cxl_decoder *cxld; +const struct cxl_endpoint_decoder *cxled = data; +const struct range *r1, *r2; +struct cxl_root_decoder *cxlrd; -if (!is_switch_decoder (dev)) +if (!is_root_decoder (dev))return 0 ; - cxld =to_cxl_decoder (dev); - r1 = &cxld->hpa_range; + cxlrd =to_cxl_root_decoder (dev); + r1 = &cxlrd->cxlsd.cxld.hpa_range; + r2 = &cxled->cxld.hpa_range; +return range_contains (r1, r2); }static struct cxl_decoder * -cxl_port_find_switch_decoder (struct cxl_port *port,struct range *hpa) +cxl_port_find_root_decoder (struct cxl_port *port, +struct cxl_endpoint_decoder *cxled) { -struct device *cxld_dev =device_find_child (&port->dev, hpa, - match_decoder_by_range); +struct device *cxld_dev =device_find_child (&port->dev, cxled, + match_root_and_ep_decoders);return cxld_dev ?to_cxl_decoder (cxld_dev) :NULL ; }@@ -3244,9 +3250,8 @@ cxl_find_root_decoder(struct cxl_endpoint_decoder *cxled)struct cxl_port *port =cxled_to_port (cxled); struct cxl_root *cxl_root __free(put_cxl_root) = find_cxl_root(port);struct cxl_decoder *root, *cxld = &cxled->cxld; -struct range *hpa = &cxld->hpa_range; - root =cxl_port_find_switch_decoder (&cxl_root->port, hpa); + root =cxl_port_find_root_decoder (&cxl_root->port, cxled);if (!root) { dev_err(cxlmd->dev.parent, "%s:%s no CXL window for range %#llx:%#llx\n",
drivers/cxl/core/region.c cxl_find_root_decoder(struct cxl_endpoint_decoder *cxled) · line 3266
Quoted 5 lines
drivers/cxl/core/region.c +1
-1@@ -3258,11 +3263,12 @@ cxl_find_root_decoder(struct cxl_endpoint_decoder *cxled)return to_cxl_root_decoder (&root->dev); } -static int match_region_by_range (struct device *dev,const void *data) +static int match_region_and_ep_decoder (struct device *dev,const void *data)
match_region_to_cxled_by_range()
DJ
Quoted 43 lines
drivers/cxl/core/region.c +7
-6{ +const struct cxl_endpoint_decoder *cxled = data; +const struct range *r = &cxled->cxld.hpa_range;struct cxl_region_params *p;struct cxl_region *cxlr; -const struct range *r = data;if (!is_cxl_region (dev))return 0 ;@@ -3425,12 +3431,13 @@ static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd, }static struct cxl_region * -cxl_find_region_by_range (struct cxl_root_decoder *cxlrd,struct range *hpa) +cxl_find_region_by_range (struct cxl_root_decoder *cxlrd, +struct cxl_endpoint_decoder *cxled) {struct device *region_dev; - region_dev =device_find_child (&cxlrd->cxlsd.cxld.dev, hpa, - match_region_by_range); + region_dev =device_find_child (&cxlrd->cxlsd.cxld.dev, cxled, + match_region_and_ep_decoder);if (!region_dev)return NULL ;@@ -3439,7 +3446,6 @@ cxl_find_region_by_range(struct cxl_root_decoder *cxlrd, struct range *hpa)int cxl_add_to_region (struct cxl_endpoint_decoder *cxled) { -struct range *hpa = &cxled->cxld.hpa_range;struct cxl_region_params *p;bool attach = false;int rc;@@ -3455,7 +3461,7 @@ int cxl_add_to_region(struct cxl_endpoint_decoder *cxled)*/ mutex_lock (&cxlrd->range_lock); struct cxl_region *cxlr __free(put_cxl_region) = -cxl_find_region_by_range (cxlrd, hpa); +cxl_find_region_by_range (cxlrd, cxled);if (!cxlr) cxlr =construct_region (cxlrd, cxled);mutex_unlock (&cxlrd->range_lock);
PATCH v4 2/4 cxl/core: Add helpers to detect Low Memory Holes on x86
In reply to Fabio M. De FrancescoIn 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.
--- drivers/cxl/Kconfig | 5 +++ drivers/cxl/core/Makefile | 1 + drivers/cxl/core/platform.c | 85 +++++++++++++++++++++++++++++++++++++ drivers/cxl/core/platform.h | 32 ++++++++++++++ 4 files changed, 123 insertions(+) create mode 100644 drivers/cxl/core/platform.c create mode 100644 drivers/cxl/core/platform.h
drivers/cxl/Kconfig +5 -0
@@ -211,6 +211,11 @@ config CXL_REGION If unsure say 'y' +config CXL_PLATFORM_QUIRKS + 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
@@ -18,6 +18,7 @@ cxl_core-y += ras.o cxl_core-y += acpi.o cxl_core-$(CONFIG_TRACING) += trace.o cxl_core-$(CONFIG_CXL_REGION) += region.o +cxl_core-$(CONFIG_CXL_PLATFORM_QUIRKS) += platform.o cxl_core-$(CONFIG_CXL_MCE) += mce.o cxl_core-$(CONFIG_CXL_FEATURES) += features.o cxl_core-$(CONFIG_CXL_EDAC_MEM_FEATURES) += edac.o
drivers/cxl/core/platform.c new file +85 -0
85 lines not on this page · raw message
drivers/cxl/core/platform.h new file +32 -0
@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include "cxl.h" + +#ifdef CONFIG_CXL_PLATFORM_QUIRKS +bool platform_root_decoder_contains (const struct cxl_root_decoder *cxlrd, +const struct cxl_endpoint_decoder *cxled); +bool platform_region_contains (const struct cxl_region_params *p, +const struct cxl_decoder *cxld); +void platform_res_adjust (struct resource *res, +struct cxl_endpoint_decoder *cxled, +const struct cxl_root_decoder *cxlrd); +#else +static bool +platform_root_decoder_contains (const struct cxl_root_decoder *cxlrd, +const struct cxl_endpoint_decoder *cxled) +{ +return false; +} + +static bool platform_region_contains (const struct cxl_region_params *p, +const struct cxl_decoder *cxld) +{ +return false; +} + +void platform_res_adjust (struct resource *res, +struct cxl_endpoint_decoder *cxled, +const struct cxl_root_decoder *cxlrd) +{ +} +#endif /* CONFIG_CXL_PLATFORM_QUIRKS */
Signature · 1 line
2.50.1
Re: [PATCH 2/4 v4] cxl/core: Add helpers to detect Low Memory Holes on x86
Quoted 1 line · Fabio M. De Francesco
In x86 with Low memory Hole, the BIOS may publishes CFMWS that describe
s/publishes/publish
Quoted 3 lines
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.
s/to align to/to align due to/
Also a spec reference for the rule would be helpful (same with next patch).
Quoted 6 lines
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.
Quoted 8 lines
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 is0x0), SPA range sizes
maybe sub "that in x86 with LMH's is 0x0" with "0x0 on x86 with LMH's" also s/SPA range sizes/SPA range's size/.
Quoted 2 lines
be less than HPA's, SPA's range's size be less than 4G, HPA's size be aligned to the NIW * 256M rule.
s/be/is/ in above list.
Quoted 23 lines
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 Dave Jiang <[email protected]>Cc Ira Weiny <[email protected]>Signed-off-by Fabio M. De Francesco <[email protected]>--- drivers/cxl/Kconfig | 5 +++ drivers/cxl/core/Makefile | 1 + drivers/cxl/core/platform.c | 85 +++++++++++++++++++++++++++++++++++++ drivers/cxl/core/platform.h | 32 ++++++++++++++ 4 files changed, 123 insertions(+) create mode 100644 drivers/cxl/core/platform.c create mode 100644 drivers/cxl/core/platform.hdrivers/cxl/Kconfig +0
-0
drivers/cxl/Kconfig config CXL_REGION · line 218
Quoted 8 lines
drivers/cxl/Kconfig +5
-0@@ -211,6 +211,11 @@ config CXL_REGION If unsure say 'y' +config CXL_PLATFORM_QUIRKS + def_bool y + depends on CXL_REGION + depends on X86 +
I'm confused on the intention behind this symbol. The naming suggests it's for all platform quirks, but the code and dependencies make this x86-specific.
I'm going to suggest making this x86-specific for now. I'm not aware of any other platforms with quirks (someone correct me if I'm wrong), so making this x86-specific is fine for now. I would rename this symbol to CXL_X86_QUIRKS, leave dependencies as-is, and rename platform.c to something like platform_x86.c. Then, if someone comes along with other platform quirks they can do their own symbol and file (or come up with a generic scheme).
Quoted 30 lines
drivers/cxl/Kconfig +0
-0config CXL_REGION_INVALIDATION_TEST bool "CXL: Region Cache Management Bypass (TEST)" depends on CXL_REGIONdrivers/cxl/core/Makefile +1
-0@@ -18,6 +18,7 @@ cxl_core-y += ras.o cxl_core-y += acpi.o cxl_core-$(CONFIG_TRACING) += trace.o cxl_core-$(CONFIG_CXL_REGION) += region.o +cxl_core-$(CONFIG_CXL_PLATFORM_QUIRKS) += platform.o cxl_core-$(CONFIG_CXL_MCE) += mce.o cxl_core-$(CONFIG_CXL_FEATURES) += features.o cxl_core-$(CONFIG_CXL_EDAC_MEM_FEATURES) += edac.odrivers/cxl/core/platform.c new file +9
-0@@ -0,0 +1,85 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include <linux/range.h> +#include "platform.h" +#include "cxlmem.h" +#include "core.h" + +/* Start of CFMWS range that end before x86 Low Memory Holes */ +#define LMH_CFMWS_RANGE_START 0x0ULL
drivers/cxl/core/platform.c line 19
Quoted 10 lines
drivers/cxl/core/platform.c new file +10
-0+ +/* +* 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. +*/
Where does the SZ_4G restraint come from?
Also, might as well make this a kdoc comment since you've already done the majority of the work.
drivers/cxl/core/platform.c line 22
Quoted 3 lines
drivers/cxl/core/platform.c new file +3
-0+bool platform_root_decoder_contains (const struct cxl_root_decoder *cxlrd, +const struct cxl_endpoint_decoder *cxled) +{
Assuming you take renaming suggestion above, these functions should probably be start with "platform_x86_*" instead.
Quoted 21 lines
drivers/cxl/core/platform.c new file +21
-0+const 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 platform_root_decoder_contains(), it matches regions and +* decoders +*/ +bool platform_region_contains (const struct cxl_region_params *p, +const struct cxl_decoder *cxld)
drivers/cxl/core/platform.c line 53
Quoted 10 lines
drivers/cxl/core/platform.c new file +10
-0+{ +const struct range *r = &cxld->hpa_range; +const 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; +
This if condition could probably move into its own helper function that takes the ranges and interleave ways. My only hang up is that these functions become 2-3 lines each after doing so.
You could also get rid of these two functions and just export the "helper" function instead. It would probably add some bloat to patch 3/4, so it's your call here.
Quoted 9 lines
drivers/cxl/core/platform.c new file +9
-0+return false; +} + +void platform_res_adjust (struct resource *res, +struct cxl_endpoint_decoder *cxled, +const struct cxl_root_decoder *cxlrd) +{ +if (!platform_root_decoder_contains (cxlrd, cxled)) +return ;
drivers/cxl/core/platform.c line 72
Quoted 10 lines
drivers/cxl/core/platform.c new file +10
-0+ +guard (rwsem_write)(&cxl_dpa_rwsem); +dev_info (cxled_to_memdev (cxled)->dev.parent, +"(LMH) Resources were (%s: %pr, %pr)\n" , +dev_name (&cxled->cxld.dev), res, cxled->dpa_res); +if (res) { +/* +* A region must be constructed with Endpoint Decoder's +* HPA range end adjusted to Root Decoder's resource end +*/
This comment (and one below) are confusing to me. I'd reword as "Trim region resource overlap with LMH".
drivers/cxl/core/platform.c line 78
Quoted 6 lines
drivers/cxl/core/platform.c new file +6
-0+ res->end = cxlrd->res->end; + } +/* +* The Endpoint Decoder's dpa_res->end must be adjusted with Root +* Decoder's resource end +*/
and reword this one to "Match endpoint decoder's DPA resource to root decoder's". You could also leave out this comment altogether, the below is self-explanatory IMO.
drivers/cxl/core/platform.c line 84
Quoted 6 lines
drivers/cxl/core/platform.c new file +6
-0+ cxled->dpa_res->end = + cxled->dpa_res->start + +resource_size (cxlrd->res) / cxled->cxld.interleave_ways -1 ; +dev_info (cxled_to_memdev (cxled)->dev.parent, +"(LMH) Resources have been adjusted (%s: %pr, %pr)\n" , +dev_name (&cxled->cxld.dev), res, cxled->dpa_res);
I think this function is a bit too noisy. I'd recommend having just this print and have it say something like "Low memory hole overlap detected, trimmed DPA to %pr". You could also include the amount trimmed, but that may not be very useful info.
I'd make the first print a dev_dbg() and spell out LMH at the very least. If it's a dev_info() it should be relatively easy to tell what's going on for a layman.
drivers/cxl/core/platform.h
Quoted 6 lines
drivers/cxl/core/platform.c new file +1
-0+}drivers/cxl/core/platform.h new file +0
-0
This is a new file so that these functions can hook into cxl_test, right? If not, I'd move the below into cxl/core/core.h and remove this file.
Quoted 22 lines
drivers/cxl/core/platform.h new file +21
-0@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include "cxl.h" + +#ifdef CONFIG_CXL_PLATFORM_QUIRKS +bool platform_root_decoder_contains (const struct cxl_root_decoder *cxlrd, +const struct cxl_endpoint_decoder *cxled); +bool platform_region_contains (const struct cxl_region_params *p, +const struct cxl_decoder *cxld); +void platform_res_adjust (struct resource *res, +struct cxl_endpoint_decoder *cxled, +const struct cxl_root_decoder *cxlrd); +#else +static bool +platform_root_decoder_contains (const struct cxl_root_decoder *cxlrd, +const struct cxl_endpoint_decoder *cxled) +{ +return false; +} + +static bool platform_region_contains(const struct cxl_region_params *p,
drivers/cxl/core/platform.h line 31
Quoted 10 lines
drivers/cxl/core/platform.h new file +10
-0+ const struct cxl_decoder *cxld) +{ +return false; +} + +void platform_res_adjust (struct resource *res, +struct cxl_endpoint_decoder *cxled, +const struct cxl_root_decoder *cxlrd) +{ +}
Don't these need "inline" in the function signatures?
Quoted 1 line
drivers/cxl/core/platform.h new file +1
-0+#endif /* CONFIG_CXL_PLATFORM_QUIRKS */
Re: [PATCH 2/4 v4] cxl/core: Add helpers to detect Low Memory Holes on x86
Quoted 28 lines · Benjamin
Quoted 1 line · Fabio M. De Francesco
In x86 with Low memory Hole, the BIOS may publishes CFMWS that describe
s/publishes/publish
Quoted 3 lines
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.
s/to align to/to align due to/
Also a spec reference for the rule would be helpful (same with next patch).
Quoted 6 lines
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.
Quoted 8 lines
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 is0x0), SPA range sizes
Quoted 8 lines
maybe sub "that in x86 with LMH's is
0x0" with "0x0on x86 with LMH's" also s/SPA range sizes/SPA range's size/.Quoted 2 lines
be less than HPA's, SPA's range's size be less than 4G, HPA's size be aligned to the NIW * 256M rule.
s/be/is/ in above list.
I'll change the lines you corrected. Thank you.
Quoted 26 lines
Quoted 26 lines
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 Dave Jiang <[email protected]>Cc Ira Weiny <[email protected]>Signed-off-by Fabio M. De Francesco <[email protected]>--- drivers/cxl/Kconfig | 5 +++ drivers/cxl/core/Makefile | 1 + drivers/cxl/core/platform.c | 85 +++++++++++++++++++++++++++++++++++++ drivers/cxl/core/platform.h | 32 ++++++++++++++ 4 files changed, 123 insertions(+) create mode 100644 drivers/cxl/core/platform.c create mode 100644 drivers/cxl/core/platform.hdrivers/cxl/Kconfig +0
-0@@ -211,6 +211,11 @@ config CXL_REGION If unsure say 'y'
Quoted 9 lines
drivers/cxl/Kconfig config CXL_REGION · line 218
Quoted 5 lines
drivers/cxl/Kconfig +5
-0+config CXL_PLATFORM_QUIRKS + def_bool y + depends on CXL_REGION + depends on X86 +I'm confused on the intention behind this symbol. The naming suggests it's for all platform quirks, but the code and dependencies make this x86-specific.
I'll remove this dependence on X86; it's neither needed nor wanted.
Quoted 7 lines
I'm going to suggest making this x86-specific for now. I'm not aware of any other platforms with quirks (someone correct me if I'm wrong), so making this x86-specific is fine for now. I would rename this symbol to
CXL_X86_QUIRKS, leave dependencies as-is, and renameplatform.cto something likeplatform_x86.c. Then, if someone comes along with other platform quirks they can do their own symbol and file (or come up with a generic scheme).
Dan suggested this approach and I agree with him.[1]
Quoted 35 lines
Quoted 35 lines
drivers/cxl/Kconfig +0
-0config CXL_REGION_INVALIDATION_TEST bool "CXL: Region Cache Management Bypass (TEST)" depends on CXL_REGIONdrivers/cxl/core/Makefile +1
-0@@ -18,6 +18,7 @@ cxl_core-y += ras.o cxl_core-y += acpi.o cxl_core-$(CONFIG_TRACING) += trace.o cxl_core-$(CONFIG_CXL_REGION) += region.o +cxl_core-$(CONFIG_CXL_PLATFORM_QUIRKS) += platform.o cxl_core-$(CONFIG_CXL_MCE) += mce.o cxl_core-$(CONFIG_CXL_FEATURES) += features.o cxl_core-$(CONFIG_CXL_EDAC_MEM_FEATURES) += edac.odrivers/cxl/core/platform.c new file +13
-0@@ -0,0 +1,85 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include <linux/range.h> +#include "platform.h" +#include "cxlmem.h" +#include "core.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. +*
Quoted 9 lines
drivers/cxl/core/platform.c line 19
Quoted 6 lines
drivers/cxl/core/platform.c new file +6
-0+* 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. +*/ Where does the
SZ_4Grestraint come from?
The hole is in low memory.
Quoted 45 lines
Also, might as well make this a kdoc comment since you've already done the majority of the work.
drivers/cxl/core/platform.c line 22
Quoted 3 lines
drivers/cxl/core/platform.c new file +3
-0+bool platform_root_decoder_contains (const struct cxl_root_decoder *cxlrd, +const struct cxl_endpoint_decoder *cxled) +{Assuming you take renaming suggestion above, these functions should probably be start with "platform_x86_*" instead.
Quoted 21 lines
drivers/cxl/core/platform.c new file +21
-0+const 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 platform_root_decoder_contains(), it matches regions and +* decoders +*/ +bool platform_region_contains (const struct cxl_region_params *p, +const struct cxl_decoder *cxld)drivers/cxl/core/platform.c line 53
Quoted 10 lines
drivers/cxl/core/platform.c new file +10
-0+{ +const struct range *r = &cxld->hpa_range; +const 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; +This if condition could probably move into its own helper function that takes the ranges and interleave ways. My only hang up is that these functions become 2-3 lines each after doing so.
Quoted 3 lines
You could also get rid of these two functions and just export the "helper" function instead. It would probably add some bloat to patch 3/4, so it's your call here.
I'd rather leave these functions as they are.
Quoted 15 lines
Quoted 15 lines
drivers/cxl/core/platform.c new file +14
-0+return false; +} + +void platform_res_adjust (struct resource *res, +struct cxl_endpoint_decoder *cxled, +const struct cxl_root_decoder *cxlrd) +{ +if (!platform_root_decoder_contains (cxlrd, cxled)) +return ; + +guard (rwsem_write)(&cxl_dpa_rwsem); +dev_info (cxled_to_memdev (cxled)->dev.parent, +"(LMH) Resources were (%s: %pr, %pr)\n" , +dev_name (&cxled->cxld.dev), res, cxled->dpa_res);
Quoted 9 lines
drivers/cxl/core/platform.c line 72
Quoted 5 lines
drivers/cxl/core/platform.c new file +5
-0+if (res) { +/* +* A region must be constructed with Endpoint Decoder's +* HPA range end adjusted to Root Decoder's resource end +*/ This comment (and one below) are confusing to me. I'd reword as "Trim region resource overlap with LMH".
Okay, thanks.
Quoted 11 lines
drivers/cxl/core/platform.c line 78
Quoted 7 lines
drivers/cxl/core/platform.c new file +6
-0+ res->end = cxlrd->res->end; + } +/* +* The Endpoint Decoder's dpa_res->end must be adjusted with Root +* Decoder's resource end +*/ and reword this one to "Match endpoint decoder's DPA resource to root decoder's". You could also leave out this comment altogether, the below is self-explanatory IMO.
Okay.
Quoted 12 lines
drivers/cxl/core/platform.c line 84
Quoted 7 lines
drivers/cxl/core/platform.c new file +6
-0+ cxled->dpa_res->end = + cxled->dpa_res->start + +resource_size (cxlrd->res) / cxled->cxld.interleave_ways -1 ; +dev_info (cxled_to_memdev (cxled)->dev.parent, +"(LMH) Resources have been adjusted (%s: %pr, %pr)\n" , +dev_name (&cxled->cxld.dev), res, cxled->dpa_res);I think this function is a bit too noisy. I'd recommend having just this print and have it say something like "Low memory hole overlap detected, trimmed DPA to %pr". You could also include the amount trimmed, but that may not be very useful info.
Quoted 3 lines
I'd make the first print a
dev_dbg()and spell out LMH at the very least. If it's adev_info()it should be relatively easy to tell what's going on for a layman.
I'm using dev_info() according to what Alison suggested.[2]
Quoted 37 lines
drivers/cxl/core/platform.h
Quoted 7 lines
drivers/cxl/core/platform.c new file +1
-0+}drivers/cxl/core/platform.h new file +0
-0This is a new file so that these functions can hook into
cxl_test, right? If not, I'd move the below intocxl/core/core.hand remove this file.Quoted 26 lines
drivers/cxl/core/platform.h new file +25
-0@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include "cxl.h" + +#ifdef CONFIG_CXL_PLATFORM_QUIRKS +bool platform_root_decoder_contains (const struct cxl_root_decoder *cxlrd, +const struct cxl_endpoint_decoder *cxled); +bool platform_region_contains (const struct cxl_region_params *p, +const struct cxl_decoder *cxld); +void platform_res_adjust (struct resource *res, +struct cxl_endpoint_decoder *cxled, +const struct cxl_root_decoder *cxlrd); +#else +static bool +platform_root_decoder_contains (const struct cxl_root_decoder *cxlrd, +const struct cxl_endpoint_decoder *cxled) +{ +return false; +} + +static bool platform_region_contains (const struct cxl_region_params *p, +const struct cxl_decoder *cxld) +{ +return false; +}
Quoted 9 lines
drivers/cxl/core/platform.h line 31
Quoted 6 lines
drivers/cxl/core/platform.h new file +6
-0+ +void platform_res_adjust (struct resource *res, +struct cxl_endpoint_decoder *cxled, +const struct cxl_root_decoder *cxlrd) +{ +}Don't these need "inline" in the function signatures?
Yes, sure. They'll be inline in the next version.
Quoted 3 lines
drivers/cxl/core/platform.h line 32
Quoted 2 lines
drivers/cxl/core/platform.h new file +1
-0+#endif /* CONFIG_CXL_PLATFORM_QUIRKS */
Thank you,
Fabio
[1] https://lore.kernel.org/linux-cxl/[email protected]
[2] https://lore.kernel.org/linux-cxl/[email protected]/
Re: [PATCH 2/4 v4] cxl/core: Add helpers to detect Low Memory Holes on x86
In reply to Cheatham, BenjaminHi Benjamin,
I thought again and decided to do a few more changes that you suggested...
Quoted 71 lines · Benjamin
Quoted 1 line · Fabio M. De Francesco
In x86 with Low memory Hole, the BIOS may publishes CFMWS that describe
s/publishes/publish
Quoted 3 lines
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.
s/to align to/to align due to/
Also a spec reference for the rule would be helpful (same with next patch).
Quoted 6 lines
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.
Quoted 8 lines
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 is0x0), SPA range sizesmaybe sub "that in x86 with LMH's is
0x0" with "0x0on x86 with LMH's" also s/SPA range sizes/SPA range's size/.Quoted 2 lines
be less than HPA's, SPA's range's size be less than 4G, HPA's size be aligned to the NIW * 256M rule.
s/be/is/ in above list.
Quoted 23 lines
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 Dave Jiang <[email protected]>Cc Ira Weiny <[email protected]>Signed-off-by Fabio M. De Francesco <[email protected]>--- drivers/cxl/Kconfig | 5 +++ drivers/cxl/core/Makefile | 1 + drivers/cxl/core/platform.c | 85 +++++++++++++++++++++++++++++++++++++ drivers/cxl/core/platform.h | 32 ++++++++++++++ 4 files changed, 123 insertions(+) create mode 100644 drivers/cxl/core/platform.c create mode 100644 drivers/cxl/core/platform.hdrivers/cxl/Kconfig +0
-0drivers/cxl/Kconfig config CXL_REGION · line 218
Quoted 8 lines
drivers/cxl/Kconfig +5
-0@@ -211,6 +211,11 @@ config CXL_REGION If unsure say 'y' +config CXL_PLATFORM_QUIRKS + def_bool y + depends on CXL_REGION + depends on X86 +I'm confused on the intention behind this symbol. The naming suggests it's for all platform quirks, but the code and dependencies make this x86-specific.
Quoted 6 lines
I'm going to suggest making this x86-specific for now. I'm not aware of any other platforms with quirks (someone correct me if I'm wrong), so making this x86-specific is fine for now. I would rename this symbol to
CXL_X86_QUIRKS, leave dependencies as-is, and renameplatform.cto something likeplatform_x86.c. Then, if someone comes along with other platform quirks they can do their own symbol and file (or come up with a generic scheme).
I'll make it x86-specific for now. platform.c will be renamed to platform_x86.c and CXL_PLATFORM_QUIRKS to CXL_X86_QUIRKS.
Thanks,
Fabio
Dave Jiang
maintainerRe: [PATCH 2/4 v4] cxl/core: Add helpers to detect Low Memory Holes on x86
In reply to Fabio M. De FrancescoOn 7/24/25 7:20 AM, Fabio M. De Francesco wrote:
s/Holes/Hole/ for subject. Only 1 right?
Quoted 3 lines
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.
On a x86 platform with a low memory hole (LHM), the BIOS may publish CFMWS that describes SPA ranges. The SPA ranges are subsets of the corresponding CXL endpoint decoder's HPA ranges because the CFMWS never intersects the LHM while the endpoint decoder's HPA ranges are always guaranteed to align to the "NIW * 256M" rule.
Quoted 4 lines
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.
To construct regions and attach decoders, the driver needs to match root decoders and regions with endpoint decoders. The process fails and returns errors because it isn't expected to deal with SPA range smaller than the corresponding HPA range.
Quoted 2 lines
Introduce functions that indirectly detect x86 LMH's by comparing SPA's
s/LMH's/LMH/
s/SPA/SPA range/
Quoted 1 line
with corresponding HPA's. They will be used in the process of Regions
s/HPA's/HPA range/
s/Regions/region/
Quoted 1 line
creation and Endpoint attachments to prevent driver failures in a few
s/Endpoint/endpoints/
Quoted 1 line
steps of the above-mentioned process.
s/above-mentioned process/the process mentioned above/
Quoted 6 lines
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 is0x0), 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.
I would make it clearer to read by listing them:
1. ....
2. ....
Quoted 2 lines
Also introduce a function to adjust the range end of the Regions to be
s/Regions/region/ singular right?
Quoted 1 line
created on x86 with LMH's.
s/LMH's/LMH/
Quoted 36 lines
Cc Alison Schofield <[email protected]>Cc Dan Williams <[email protected]>Cc Dave Jiang <[email protected]>Cc Ira Weiny <[email protected]>Signed-off-by Fabio M. De Francesco <[email protected]>--- drivers/cxl/Kconfig | 5 +++ drivers/cxl/core/Makefile | 1 + drivers/cxl/core/platform.c | 85 +++++++++++++++++++++++++++++++++++++ drivers/cxl/core/platform.h | 32 ++++++++++++++ 4 files changed, 123 insertions(+) create mode 100644 drivers/cxl/core/platform.c create mode 100644 drivers/cxl/core/platform.hdrivers/cxl/Kconfig +5
-0@@ -211,6 +211,11 @@ config CXL_REGION If unsure say 'y' +config CXL_PLATFORM_QUIRKS + 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_REGIONdrivers/cxl/core/Makefile +0
-0
drivers/cxl/core/Makefile cxl_core-y += ras.o · line 21
Quoted 4 lines
drivers/cxl/core/Makefile +1
-0@@ -18,6 +18,7 @@ cxl_core-y += ras.o cxl_core-y += acpi.o cxl_core-$(CONFIG_TRACING) += trace.o cxl_core-$(CONFIG_CXL_REGION) += region.o +cxl_core-$(CONFIG_CXL_PLATFORM_QUIRKS) += platform.o
Given that you are creating a quirk, make the object obvious it's a quirk.
platform_quirks.o
Quoted 26 lines
drivers/cxl/core/Makefile +0
-0cxl_core-$(CONFIG_CXL_MCE) += mce.o cxl_core-$(CONFIG_CXL_FEATURES) += features.o cxl_core-$(CONFIG_CXL_EDAC_MEM_FEATURES) += edac.odrivers/cxl/core/platform.c new file +17
-0@@ -0,0 +1,85 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include <linux/range.h> +#include "platform.h" +#include "cxlmem.h" +#include "core.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,
drivers/cxl/core/platform.c line 27
Quoted 10 lines
drivers/cxl/core/platform.c new file +10
-0+* the root decoder range end is always less than SZ_4G. +*/ +bool platform_root_decoder_contains (const struct cxl_root_decoder *cxlrd, +const struct cxl_endpoint_decoder *cxled) +{ +const struct range *r1, *r2; +int niw; + + r1 = &cxlrd->cxlsd.cxld.hpa_range; + r2 = &cxled->cxld.hpa_range;
I would name it rd_r and ed_r so it's easier to remember which is which below when you do compare below.
drivers/cxl/core/platform.c line 28
Quoted 1 line
drivers/cxl/core/platform.c new file +1
-0+ niw = cxled->cxld.interleave_ways;
Just make this 'align', and you can just do:
align = cxled->cxld.interleave_ways * SZ_256M;
That way it's cleaner below when you do compare.
drivers/cxl/core/platform.c line 30
Quoted 2 lines
drivers/cxl/core/platform.c new file +2
-0+ + if (r1->start == LMH_CFMWS_RANGE_START && r1->start == r2->start &&
May as well make it 'r2->start == LMH_CFMWS_RANGE_START'?
drivers/cxl/core/platform.c line 33
Quoted 3 lines
drivers/cxl/core/platform.c new file +3
-0+ r1->end < (LMH_CFMWS_RANGE_START + SZ_4G) && r1->end < r2->end && + IS_ALIGNED(range_len(r2), niw * SZ_256M)) +return true;
Maybe have 1 conditional per line to make it easier to read since this is a big one
Quoted 9 lines
drivers/cxl/core/platform.c new file +9
-0+ +return false; +} + +/* +* Similar to platform_root_decoder_contains(), it matches regions and +* decoders +*/ +bool platform_region_contains(const struct cxl_region_params *p,
drivers/cxl/core/platform.c line 52
Quoted 10 lines
drivers/cxl/core/platform.c new file +10
-0+ const struct cxl_decoder *cxld) +{ +const struct range *r = &cxld->hpa_range; +const 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;
similar comments as the previous function
Quoted 6 lines
drivers/cxl/core/platform.c new file +6
-0+ +return false; +} + +void platform_res_adjust(struct resource *res, + struct cxl_endpoint_decoder *cxled,
drivers/cxl/core/platform.c line 68
Quoted 10 lines
drivers/cxl/core/platform.c new file +10
-0+ const struct cxl_root_decoder *cxlrd) +{ +if (!platform_root_decoder_contains (cxlrd, cxled)) +return ; + +guard (rwsem_write)(&cxl_dpa_rwsem); +dev_info (cxled_to_memdev (cxled)->dev.parent, +"(LMH) Resources were (%s: %pr, %pr)\n" , +dev_name (&cxled->cxld.dev), res, cxled->dpa_res); +if (res) {
Do you ever expect a scenario where the 'res' passed in is NULL?
Quoted 6 lines
drivers/cxl/core/platform.c new file +6
-0+/* +* A region must be constructed with Endpoint Decoder's +* HPA range end adjusted to Root Decoder's resource end +*/ + res->end = cxlrd->res->end; + }
drivers/cxl/core/platform.c line 84
Quoted 10 lines
drivers/cxl/core/platform.c new file +10
-0+/* +* The Endpoint Decoder's dpa_res->end must be adjusted with Root +* Decoder's resource end +*/ + cxled->dpa_res->end = + cxled->dpa_res->start + +resource_size (cxlrd->res) / cxled->cxld.interleave_ways -1 ; +dev_info (cxled_to_memdev (cxled)->dev.parent, +"(LMH) Resources have been adjusted (%s: %pr, %pr)\n" , +dev_name (&cxled->cxld.dev), res, cxled->dpa_res);
If the res passed in is ever NULL, this line would crash when accessing res here.
Quoted 28 lines
drivers/cxl/core/platform.c new file +1
-0+}drivers/cxl/core/platform.h new file +21
-0@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include "cxl.h" + +#ifdef CONFIG_CXL_PLATFORM_QUIRKS +bool platform_root_decoder_contains (const struct cxl_root_decoder *cxlrd, +const struct cxl_endpoint_decoder *cxled); +bool platform_region_contains (const struct cxl_region_params *p, +const struct cxl_decoder *cxld); +void platform_res_adjust (struct resource *res, +struct cxl_endpoint_decoder *cxled, +const struct cxl_root_decoder *cxlrd); +#else +static bool +platform_root_decoder_contains (const struct cxl_root_decoder *cxlrd, +const struct cxl_endpoint_decoder *cxled) +{ +return false; +} + +static bool platform_region_contains(const struct cxl_region_params *p,
drivers/cxl/core/platform.h line 31
Quoted 10 lines
drivers/cxl/core/platform.h new file +10
-0+ const struct cxl_decoder *cxld) +{ +return false; +} + +void platform_res_adjust (struct resource *res, +struct cxl_endpoint_decoder *cxled, +const struct cxl_root_decoder *cxlrd) +{ +}
these need inline
Quoted 1 line
drivers/cxl/core/platform.h new file +1
-0+#endif /* CONFIG_CXL_PLATFORM_QUIRKS */
PATCH v4 3/4 cxl/core: Enable Region creation on x86 with LMH
In reply to Fabio M. De FrancescoThe 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 fit with alignment constraints (i.e., alignment to NIW * 256M rule).
--- drivers/cxl/core/region.c | 53 +++++++++++++++++++++++++++++++++------ tools/testing/cxl/Kbuild | 1 + 2 files changed, 46 insertions(+), 8 deletions(-)
drivers/cxl/core/region.c +45 -8
@@ -12,6 +12,7 @@#include <linux/memory-tiers.h> #include <cxlmem.h> #include <cxl.h> +#include "platform.h" #include "core.h" /**
@@ -834,6 +835,8 @@ static int match_free_decoder(struct device *dev, const void *data)static bool region_res_match_cxl_range (const struct cxl_region_params *p,struct range *range) { +struct cxl_decoder *cxld; +if (!p->res)return false;
@@ -842,8 +845,15 @@ static bool region_res_match_cxl_range(const struct cxl_region_params *p,* to be fronted by the DRAM range in current known implementation. * This assumption will be made until a variant implementation exists. */ -return p->res->start + p->cache_size == range->start && - p->res->end == range->end; +if (p->res->start + p->cache_size == range->start && + p->res->end == range->end) +return true; + + cxld = container_of(range, struct cxl_decoder, hpa_range); +if (platform_region_contains (p, cxld)) +return true; + +return false; }static int match_auto_decoder (struct device *dev,const void *data)
@@ -1763,6 +1773,7 @@ static int match_switch_and_ep_decoders(struct device *dev, const void *data) {const struct cxl_endpoint_decoder *cxled = data;struct cxl_switch_decoder *cxlsd; +struct cxl_root_decoder *cxlrd;const struct range *r1, *r2;if (!is_switch_decoder (dev))
@@ -1772,8 +1783,13 @@ static int match_switch_and_ep_decoders(struct device *dev, const void *data) r1 = &cxlsd->cxld.hpa_range; r2 = &cxled->cxld.hpa_range; -if (is_root_decoder (dev)) -return range_contains (r1, r2); +if (is_root_decoder (dev)) { +if (range_contains (r1, r2)) +return 1 ; + cxlrd =to_cxl_root_decoder (dev); +if (platform_root_decoder_contains (cxlrd, cxled)) +return 1 ; + }return (r1->start == r2->start && r1->end == r2->end); }
@@ -1990,7 +2006,7 @@ static int cxl_region_attach(struct cxl_region *cxlr, }if (resource_size (cxled->dpa_res) * p->interleave_ways + p->cache_size != -resource_size (p->res)) { +resource_size (p->res) && !platform_root_decoder_contains (cxlrd, cxled)) { dev_dbg(&cxlr->dev, "%s:%s-size-%#llx * ways-%d + cache-%#llx != region-size-%#llx\n", dev_name(&cxlmd->dev), dev_name(&cxled->cxld.dev),
@@ -3230,7 +3246,12 @@ static int match_root_and_ep_decoders(struct device *dev, const void *data) r1 = &cxlrd->cxlsd.cxld.hpa_range; r2 = &cxled->cxld.hpa_range; -return range_contains (r1, r2); +if (range_contains (r1, r2)) +return true; +if (platform_root_decoder_contains (cxlrd, cxled)) +return true; + +return false; } static struct cxl_decoder *
@@ -3277,8 +3298,12 @@ static int match_region_and_ep_decoder(struct device *dev, const void *data) p = &cxlr->params;guard (rwsem_read)(&cxl_region_rwsem); -if (p->res && p->res->start == r->start && p->res->end == r->end) -return 1 ; +if (p->res) { +if (p->res->start == r->start && p->res->end == r->end) +return 1 ; +if (platform_region_contains (p, &cxled->cxld)) +return 1 ; + }return 0 ; }
@@ -3355,6 +3380,12 @@ static int __construct_region(struct cxl_region *cxlr, *res =DEFINE_RES_MEM_NAMED (hpa->start,range_len (hpa),dev_name (&cxlr->dev)); +/* +* Trim the HPA retrieved from hardware to fit the SPA mapped by the +* platform +*/ +platform_res_adjust (res, cxled, cxlrd); + rc =cxl_extended_linear_cache_resize (cxlr, res);if (rc && rc != -EOPNOTSUPP ) {/*
@@ -3464,6 +3495,12 @@ int cxl_add_to_region(struct cxl_endpoint_decoder *cxled)cxl_find_region_by_range (cxlrd, cxled);if (!cxlr) cxlr =construct_region (cxlrd, cxled); +else +/* +* Adjust the Endpoint Decoder's dpa_res to fit the Region which +* it has to be attached to +*/ +platform_res_adjust (NULL , cxled, cxlrd);mutex_unlock (&cxlrd->range_lock); rc =PTR_ERR_OR_ZERO (cxlr);
tools/testing/cxl/Kbuild +1 -0
@@ -65,6 +65,7 @@ cxl_core-y += $(CXL_CORE_SRC)/ras.o cxl_core-y += $(CXL_CORE_SRC)/acpi.o cxl_core-$(CONFIG_TRACING) += $(CXL_CORE_SRC)/trace.o cxl_core-$(CONFIG_CXL_REGION) += $(CXL_CORE_SRC)/region.o +cxl_core-$(CONFIG_CXL_PLATFORM_QUIRKS) += $(CXL_CORE_SRC)/platform.o cxl_core-$(CONFIG_CXL_MCE) += $(CXL_CORE_SRC)/mce.o cxl_core-$(CONFIG_CXL_FEATURES) += $(CXL_CORE_SRC)/features.o cxl_core-$(CONFIG_CXL_EDAC_MEM_FEATURES) += $(CXL_CORE_SRC)/edac.o
Signature · 1 line
2.50.1
Re: [PATCH 3/4 v4] cxl/core: Enable Region creation on x86 with LMH
Quoted 4 lines · 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).
Update to 3.2 spec? Sorry I forgot to mention it earlier, but you'll probably want to do this for the whole series.
Quoted 5 lines
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.
Spec ref here.
Quoted 59 lines
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 fit with alignment constraints (i.e., alignment to NIW * 256M rule).
Cc Alison Schofield <[email protected]>Cc Dan Williams <[email protected]>Cc Dave Jiang <[email protected]>Cc Ira Weiny <[email protected]>Signed-off-by Fabio M. De Francesco <[email protected]>--- drivers/cxl/core/region.c | 53 +++++++++++++++++++++++++++++++++------ tools/testing/cxl/Kbuild | 1 + 2 files changed, 46 insertions(+), 8 deletions(-)drivers/cxl/core/region.c +3
-1@@ -12,6 +12,7 @@#include <linux/memory-tiers.h> #include <cxlmem.h> #include <cxl.h> +#include "platform.h" #include "core.h" /** @@ -834,6 +835,8 @@ static int match_free_decoder(struct device *dev, const void *data)static bool region_res_match_cxl_range (const struct cxl_region_params *p,struct range *range) { +struct cxl_decoder *cxld; +if (!p->res)return false;@@ -842,8 +845,15 @@ static bool region_res_match_cxl_range(const struct cxl_region_params *p,* to be fronted by the DRAM range in current known implementation. * This assumption will be made until a variant implementation exists. */ - return p->res->start + p->cache_size == range->start &&
drivers/cxl/core/region.c static bool region_res_match_cxl_range(const struct cxl_region_params *p, · line 856
Quoted 10 lines
drivers/cxl/core/region.c +9
-1- p->res->end == range->end; +if (p->res->start + p->cache_size == range->start && + p->res->end == range->end) +return true; + + cxld = container_of(range, struct cxl_decoder, hpa_range); +if (platform_region_contains (p, cxld)) +return true; + +return false;
Can just return result of platform_region_contains() here.
Quoted 14 lines
drivers/cxl/core/region.c +1
-0}static int match_auto_decoder (struct device *dev,const void *data)@@ -1763,6 +1773,7 @@ static int match_switch_and_ep_decoders(struct device *dev, const void *data) {const struct cxl_endpoint_decoder *cxled = data;struct cxl_switch_decoder *cxlsd; +struct cxl_root_decoder *cxlrd;const struct range *r1, *r2;if (!is_switch_decoder (dev))@@ -1772,8 +1783,13 @@ static int match_switch_and_ep_decoders(struct device *dev, const void *data) r1 = &cxlsd->cxld.hpa_range; r2 = &cxled->cxld.hpa_range;
drivers/cxl/core/region.c static int match_switch_and_ep_decoders(struct device *dev, const void *data) · line 1792
Quoted 10 lines
drivers/cxl/core/region.c +7
-2-if (is_root_decoder (dev)) -return range_contains (r1, r2); +if (is_root_decoder (dev)) { +if (range_contains (r1, r2)) +return 1 ; + cxlrd =to_cxl_root_decoder (dev); +if (platform_root_decoder_contains (cxlrd, cxled)) +return 1 ; + }
I don't think it's possible, but the way this is written allows falling through to the return statement below. This if statement should probably be:
if (is_root_decoder(dev)) {
cxlrd = to_cxl_root_decoder(dev);
return range_contains(r1, r2) || platform_root_decoder_contains(cxlrd, cxled));
}Quoted 13 lines
drivers/cxl/core/region.c +1
-1return (r1->start == r2->start && r1->end == r2->end); }@@ -1990,7 +2006,7 @@ static int cxl_region_attach(struct cxl_region *cxlr, }if (resource_size (cxled->dpa_res) * p->interleave_ways + p->cache_size != -resource_size (p->res)) { +resource_size (p->res) && !platform_root_decoder_contains (cxlrd, cxled)) { dev_dbg(&cxlr->dev, "%s:%s-size-%#llx * ways-%d + cache-%#llx != region-size-%#llx\n", dev_name(&cxlmd->dev), dev_name(&cxled->cxld.dev),
drivers/cxl/core/region.c static int match_root_and_ep_decoders(struct device *dev, const void *data) · line 3254
Quoted 10 lines
drivers/cxl/core/region.c +6
-1@@ -3230,7 +3246,12 @@ static int match_root_and_ep_decoders(struct device *dev, const void *data) r1 = &cxlrd->cxlsd.cxld.hpa_range; r2 = &cxled->cxld.hpa_range; -return range_contains (r1, r2); +if (range_contains (r1, r2)) +return true; +if (platform_root_decoder_contains (cxlrd, cxled)) +return true; + +return false;
Can just return the || of the two above if statements.
Quoted 5 lines
drivers/cxl/core/region.c +0
-0} static struct cxl_decoder *@@ -3277,8 +3298,12 @@ static int match_region_and_ep_decoder(struct device *dev, const void *data) p = &cxlr->params;
drivers/cxl/core/region.c static int match_region_and_ep_decoder(struct device *dev, const void *data) · line 3306
Quoted 10 lines
drivers/cxl/core/region.c +6
-2guard (rwsem_read)(&cxl_region_rwsem); -if (p->res && p->res->start == r->start && p->res->end == r->end) -return 1 ; +if (p->res) { +if (p->res->start == r->start && p->res->end == r->end) +return 1 ; +if (platform_region_contains (p, &cxled->cxld)) +return 1 ; + }
Same thing here.
Quoted 17 lines
drivers/cxl/core/region.c +6
-0return 0 ; }@@ -3355,6 +3380,12 @@ static int __construct_region(struct cxl_region *cxlr, *res =DEFINE_RES_MEM_NAMED (hpa->start,range_len (hpa),dev_name (&cxlr->dev)); +/* +* Trim the HPA retrieved from hardware to fit the SPA mapped by the +* platform +*/ +platform_res_adjust (res, cxled, cxlrd); + rc =cxl_extended_linear_cache_resize (cxlr, res);if (rc && rc != -EOPNOTSUPP ) {/*
drivers/cxl/core/region.c int cxl_add_to_region(struct cxl_endpoint_decoder *cxled) · line 3503
Quoted 9 lines
drivers/cxl/core/region.c +6
-0@@ -3464,6 +3495,12 @@ int cxl_add_to_region(struct cxl_endpoint_decoder *cxled)cxl_find_region_by_range (cxlrd, cxled);if (!cxlr) cxlr =construct_region (cxlrd, cxled); +else +/* +* Adjust the Endpoint Decoder's dpa_res to fit the Region which +* it has to be attached to +*/ +platform_res_adjust (NULL , cxled, cxlrd);
I'm 50/50 on whether these comments are unnecessary. The routine is pretty well documented and also has an explanatory comment above the definition in platform.c. I think you can probably remove them, but I'll defer to your/someone else's judgement here.
Thanks,
Ben
Re: [PATCH 3/4 v4] cxl/core: Enable Region creation on x86 with LMH
Quoted 9 lines · Benjamin
Quoted 4 lines · 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).
Update to 3.2 spec? Sorry I forgot to mention it earlier, but you'll probably want to do this for the whole series.
Sure, thanks.
Quoted 8 lines
Quoted 5 lines
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.
Spec ref here.
Okay.
Quoted 63 lines
Quoted 63 lines
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 fit with alignment constraints (i.e., alignment to NIW * 256M rule).
Cc Alison Schofield <[email protected]>Cc Dan Williams <[email protected]>Cc Dave Jiang <[email protected]>Cc Ira Weiny <[email protected]>Signed-off-by Fabio M. De Francesco <[email protected]>--- drivers/cxl/core/region.c | 53 +++++++++++++++++++++++++++++++++------ tools/testing/cxl/Kbuild | 1 + 2 files changed, 46 insertions(+), 8 deletions(-)drivers/cxl/core/region.c +6
-2@@ -12,6 +12,7 @@#include <linux/memory-tiers.h> #include <cxlmem.h> #include <cxl.h> +#include "platform.h" #include "core.h" /** @@ -834,6 +835,8 @@ static int match_free_decoder(struct device *dev, const void *data)static bool region_res_match_cxl_range (const struct cxl_region_params *p,struct range *range) { +struct cxl_decoder *cxld; +if (!p->res)return false;@@ -842,8 +845,15 @@ static bool region_res_match_cxl_range(const struct cxl_region_params *p,* to be fronted by the DRAM range in current known implementation. * This assumption will be made until a variant implementation exists. */ -return p->res->start + p->cache_size == range->start && - p->res->end == range->end; +if (p->res->start + p->cache_size == range->start && + p->res->end == range->end) +return true;
Quoted 9 lines
drivers/cxl/core/region.c static bool region_res_match_cxl_range(const struct cxl_region_params *p, · line 856
Quoted 6 lines
drivers/cxl/core/region.c +6
-0+ + cxld = container_of(range, struct cxl_decoder, hpa_range); +if (platform_region_contains (p, cxld)) +return true; + +return false;Can just return result of
platform_region_contains()here.
Okay.
Quoted 16 lines
Quoted 16 lines
drivers/cxl/core/region.c +1
-0}static int match_auto_decoder (struct device *dev,const void *data)@@ -1763,6 +1773,7 @@ static int match_switch_and_ep_decoders(struct device *dev, const void *data) {const struct cxl_endpoint_decoder *cxled = data;struct cxl_switch_decoder *cxlsd; +struct cxl_root_decoder *cxlrd;const struct range *r1, *r2;if (!is_switch_decoder (dev))@@ -1772,8 +1783,13 @@ static int match_switch_and_ep_decoders(struct device *dev, const void *data) r1 = &cxlsd->cxld.hpa_range; r2 = &cxled->cxld.hpa_range;
Quoted 13 lines
drivers/cxl/core/region.c static int match_switch_and_ep_decoders(struct device *dev, const void *data) · line 1792
Quoted 9 lines
drivers/cxl/core/region.c +7
-2-if (is_root_decoder (dev)) -return range_contains (r1, r2); +if (is_root_decoder (dev)) { +if (range_contains (r1, r2)) +return 1 ; + cxlrd =to_cxl_root_decoder (dev); +if (platform_root_decoder_contains (cxlrd, cxled)) +return 1 ; + }I don't think it's possible, but the way this is written allows falling through to the return statement below.
It's possible. It can happen and it's harmless yet unnecessary.
Quoted 10 lines
This if statement should probably be:
if (is_root_decoder(dev)) { cxlrd = to_cxl_root_decoder(dev); return range_contains(r1, r2) || platform_root_decoder_contains(cxlrd, cxled)); }Quoted 3 lines
drivers/cxl/core/region.c +0
-0return (r1->start == r2->start && r1->end == r2->end); }
And since it's unnecessary, I agree with you and rewrite it.
I just wanted, out of my personal preference, to highlight that calls of platform_root_decoder_contains() happen only to allow the driver to succeed also on a less common case, that is on platforms with LMH.
Quoted 14 lines
Quoted 14 lines
drivers/cxl/core/region.c +1
-1@@ -1990,7 +2006,7 @@ static int cxl_region_attach(struct cxl_region *cxlr, }if (resource_size (cxled->dpa_res) * p->interleave_ways + p->cache_size != -resource_size (p->res)) { +resource_size (p->res) && !platform_root_decoder_contains (cxlrd, cxled)) { dev_dbg(&cxlr->dev, "%s:%s-size-%#llx * ways-%d + cache-%#llx != region-size-%#llx\n", dev_name(&cxlmd->dev), dev_name(&cxled->cxld.dev),@@ -3230,7 +3246,12 @@ static int match_root_and_ep_decoders(struct device *dev, const void *data) r1 = &cxlrd->cxlsd.cxld.hpa_range; r2 = &cxled->cxld.hpa_range;
Quoted 10 lines
drivers/cxl/core/region.c static int match_root_and_ep_decoders(struct device *dev, const void *data) · line 3254
Quoted 7 lines
drivers/cxl/core/region.c +6
-1-return range_contains (r1, r2); +if (range_contains (r1, r2)) +return true; +if (platform_root_decoder_contains (cxlrd, cxled)) +return true; + +return false;Can just return the || of the two above if statements.
Sure, as it is going to be with the other function.
Quoted 40 lines
Quoted 5 lines
drivers/cxl/core/region.c +0
-0} static struct cxl_decoder *@@ -3277,8 +3298,12 @@ static int match_region_and_ep_decoder(struct device *dev, const void *data) p = &cxlr->params;drivers/cxl/core/region.c static int match_region_and_ep_decoder(struct device *dev, const void *data) · line 3306
Quoted 10 lines
drivers/cxl/core/region.c +6
-2guard (rwsem_read)(&cxl_region_rwsem); -if (p->res && p->res->start == r->start && p->res->end == r->end) -return 1 ; +if (p->res) { +if (p->res->start == r->start && p->res->end == r->end) +return 1 ; +if (platform_region_contains (p, &cxled->cxld)) +return 1 ; + }Same thing here.
Quoted 22 lines
drivers/cxl/core/region.c +8
-0return 0 ; }@@ -3355,6 +3380,12 @@ static int __construct_region(struct cxl_region *cxlr, *res =DEFINE_RES_MEM_NAMED (hpa->start,range_len (hpa),dev_name (&cxlr->dev)); +/* +* Trim the HPA retrieved from hardware to fit the SPA mapped by the +* platform +*/ +platform_res_adjust (res, cxled, cxlrd); + rc =cxl_extended_linear_cache_resize (cxlr, res);if (rc && rc != -EOPNOTSUPP ) {/* @@ -3464,6 +3495,12 @@ int cxl_add_to_region(struct cxl_endpoint_decoder *cxled)cxl_find_region_by_range (cxlrd, cxled);if (!cxlr) cxlr =construct_region (cxlrd, cxled); +else +/*
Quoted 9 lines
drivers/cxl/core/region.c int cxl_add_to_region(struct cxl_endpoint_decoder *cxled) · line 3503
Quoted 4 lines
drivers/cxl/core/region.c +4
-0+* Adjust the Endpoint Decoder's dpa_res to fit the Region which +* it has to be attached to +*/ +platform_res_adjust (NULL , cxled, cxlrd);I'm 50/50 on whether these comments are unnecessary. The routine is pretty well documented and also has an explanatory comment above the definition in
platform.c. I think you can probably remove them, but I'll defer to your/someone else's judgement here.
I'll think about it. Anyway, I wanted to clarify that the two call sites serve two different purposes (i.e., for already constructed regions we may still need to adjust dpa_res).
Thanks,
Fabio
Quoted 4 lines
Thanks,
Ben
Dave Jiang
maintainerRe: [PATCH 3/4 v4] cxl/core: Enable Region creation on x86 with LMH
In reply to Fabio M. De FrancescoQuoted 4 lines · 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).
Should bump it to the latest spec available (r3.2)
Quoted 3 lines
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
s/cases/cases, /
Quoted 4 lines
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
s/BIOS/the BIOS/
Quoted 2 lines
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
s/capacity/the capacity/
Quoted 1 line
the endpoint is lost with no SPA to map to CXL HPA in that hole.
s/with/because there is/
Quoted 2 lines
In the early stages of CXL Regions construction and attach on platforms
s/Regions/region/
Quoted 1 line
with Low Memory Holes,
cxl_add_to_region()fails and returns an error
s/Low Memory Holes/LMH/
Quoted 1 line
because it can't find any CXL Window that matches a given CXL Endpoint
s/CXL Window/CFMWS range/ I think?
Quoted 1 line
Decoder.
s/Endpoint Decoder/endpoint decoder HPA range/
Quoted 2 lines
Detect a Low Memory Hole by comparing Root Decoders and Endpoint Decoders
s/Low Memory Hole/LMH/
s/Root Decoders/root decoder HPA range/
s/Endpoint Decoders/endpoint decoder HPA range/
Quoted 5 lines
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.
s/Root Decoders/root decoder HPA range/
s/Regions/region/
s/Endpoint Decoders/endpoint decoder HPA range/
s/Low Memory Hole/LMH/
Quoted 2 lines
Construct CXL Regions with HPA range's end adjusted to the matching SPA.
Construct CXL region with the end of its HPA range adjusted to the matching SPA.
Quoted 2 lines
Allow the attach target process to complete by allowing Regions to not
s/Regions/regions/
Quoted 1 line
fit with alignment constraints (i.e., alignment to NIW * 256M rule).
s/to not fit with/to bypass the/ ?
Quoted 33 lines
Cc Alison Schofield <[email protected]>Cc Dan Williams <[email protected]>Cc Dave Jiang <[email protected]>Cc Ira Weiny <[email protected]>Signed-off-by Fabio M. De Francesco <[email protected]>--- drivers/cxl/core/region.c | 53 +++++++++++++++++++++++++++++++++------ tools/testing/cxl/Kbuild | 1 + 2 files changed, 46 insertions(+), 8 deletions(-)drivers/cxl/core/region.c +3
-0@@ -12,6 +12,7 @@#include <linux/memory-tiers.h> #include <cxlmem.h> #include <cxl.h> +#include "platform.h" #include "core.h" /** @@ -834,6 +835,8 @@ static int match_free_decoder(struct device *dev, const void *data)static bool region_res_match_cxl_range (const struct cxl_region_params *p,struct range *range) { +struct cxl_decoder *cxld; +if (!p->res)return false;
drivers/cxl/core/region.c static bool region_res_match_cxl_range(const struct cxl_region_params *p, · line 850
Quoted 8 lines
drivers/cxl/core/region.c +3
-2@@ -842,8 +845,15 @@ static bool region_res_match_cxl_range(const struct cxl_region_params *p,* to be fronted by the DRAM range in current known implementation. * This assumption will be made until a variant implementation exists. */ -return p->res->start + p->cache_size == range->start && - p->res->end == range->end; +if (p->res->start + p->cache_size == range->start && + p->res->end == range->end) +return true;
Have you thought through the scenario where extended linear cache exists and covers LMH? You may need to extend the math for platform_region_contains() maybe?
drivers/cxl/core/region.c static bool region_res_match_cxl_range(const struct cxl_region_params *p, · line 856
Quoted 6 lines
drivers/cxl/core/region.c +6
-0+ + cxld = container_of(range, struct cxl_decoder, hpa_range); +if (platform_region_contains (p, cxld)) +return true; + +return false;
return platform_region_contains(p, cxld);
Quoted 37 lines
drivers/cxl/core/region.c +9
-3}static int match_auto_decoder (struct device *dev,const void *data)@@ -1763,6 +1773,7 @@ static int match_switch_and_ep_decoders(struct device *dev, const void *data) {const struct cxl_endpoint_decoder *cxled = data;struct cxl_switch_decoder *cxlsd; +struct cxl_root_decoder *cxlrd;const struct range *r1, *r2;if (!is_switch_decoder (dev))@@ -1772,8 +1783,13 @@ static int match_switch_and_ep_decoders(struct device *dev, const void *data) r1 = &cxlsd->cxld.hpa_range; r2 = &cxled->cxld.hpa_range; -if (is_root_decoder (dev)) -return range_contains (r1, r2); +if (is_root_decoder (dev)) { +if (range_contains (r1, r2)) +return 1 ; + cxlrd =to_cxl_root_decoder (dev); +if (platform_root_decoder_contains (cxlrd, cxled)) +return 1 ; + }return (r1->start == r2->start && r1->end == r2->end); }@@ -1990,7 +2006,7 @@ static int cxl_region_attach(struct cxl_region *cxlr, }if (resource_size (cxled->dpa_res) * p->interleave_ways + p->cache_size != -resource_size (p->res)) { +resource_size (p->res) && !platform_root_decoder_contains (cxlrd, cxled)) { dev_dbg(&cxlr->dev, "%s:%s-size-%#llx * ways-%d + cache-%#llx != region-size-%#llx\n", dev_name(&cxlmd->dev), dev_name(&cxled->cxld.dev),
drivers/cxl/core/region.c static int match_root_and_ep_decoders(struct device *dev, const void *data) · line 3254
Quoted 10 lines
drivers/cxl/core/region.c +6
-1@@ -3230,7 +3246,12 @@ static int match_root_and_ep_decoders(struct device *dev, const void *data) r1 = &cxlrd->cxlsd.cxld.hpa_range; r2 = &cxled->cxld.hpa_range; -return range_contains (r1, r2); +if (range_contains (r1, r2)) +return true; +if (platform_root_decoder_contains (cxlrd, cxled)) +return true; + +return false;
return range_contais(...) || platform_root_decoder_contains(...);
DJ
Quoted 56 lines
drivers/cxl/core/region.c +18
-2} static struct cxl_decoder *@@ -3277,8 +3298,12 @@ static int match_region_and_ep_decoder(struct device *dev, const void *data) p = &cxlr->params;guard (rwsem_read)(&cxl_region_rwsem); -if (p->res && p->res->start == r->start && p->res->end == r->end) -return 1 ; +if (p->res) { +if (p->res->start == r->start && p->res->end == r->end) +return 1 ; +if (platform_region_contains (p, &cxled->cxld)) +return 1 ; + }return 0 ; }@@ -3355,6 +3380,12 @@ static int __construct_region(struct cxl_region *cxlr, *res =DEFINE_RES_MEM_NAMED (hpa->start,range_len (hpa),dev_name (&cxlr->dev)); +/* +* Trim the HPA retrieved from hardware to fit the SPA mapped by the +* platform +*/ +platform_res_adjust (res, cxled, cxlrd); + rc =cxl_extended_linear_cache_resize (cxlr, res);if (rc && rc != -EOPNOTSUPP ) {/* @@ -3464,6 +3495,12 @@ int cxl_add_to_region(struct cxl_endpoint_decoder *cxled)cxl_find_region_by_range (cxlrd, cxled);if (!cxlr) cxlr =construct_region (cxlrd, cxled); +else +/* +* Adjust the Endpoint Decoder's dpa_res to fit the Region which +* it has to be attached to +*/ +platform_res_adjust (NULL , cxled, cxlrd);mutex_unlock (&cxlrd->range_lock); rc =PTR_ERR_OR_ZERO (cxlr);tools/testing/cxl/Kbuild +1
-0@@ -65,6 +65,7 @@ cxl_core-y += $(CXL_CORE_SRC)/ras.o cxl_core-y += $(CXL_CORE_SRC)/acpi.o cxl_core-$(CONFIG_TRACING) += $(CXL_CORE_SRC)/trace.o cxl_core-$(CONFIG_CXL_REGION) += $(CXL_CORE_SRC)/region.o +cxl_core-$(CONFIG_CXL_PLATFORM_QUIRKS) += $(CXL_CORE_SRC)/platform.o cxl_core-$(CONFIG_CXL_MCE) += $(CXL_CORE_SRC)/mce.o cxl_core-$(CONFIG_CXL_FEATURES) += $(CXL_CORE_SRC)/features.o cxl_core-$(CONFIG_CXL_EDAC_MEM_FEATURES) += $(CXL_CORE_SRC)/edac.o
PATCH v4 4/4 cxl/test: Simulate an x86 Low Memory Hole for tests
In reply to Fabio M. De FrancescoSimulate 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.
The auto-created region of cxl-test uses mock_cfmws[0], therefore 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.
Since mock_cfmws[0] 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 when it's 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.
--- drivers/cxl/core/platform.c | 9 +- tools/testing/cxl/Kbuild | 1 + tools/testing/cxl/mock_platform.c | 137 ++++++++++++++++++++++++++++++ tools/testing/cxl/test/cxl.c | 10 +++ tools/testing/cxl/test/mock.h | 1 + 5 files changed, 154 insertions(+), 4 deletions(-) create mode 100644 tools/testing/cxl/mock_platform.c
drivers/cxl/core/platform.c +5 -4
@@ -17,8 +17,9 @@* 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 platform_root_decoder_contains (const struct cxl_root_decoder *cxlrd, -const struct cxl_endpoint_decoder *cxled) +__weak bool +platform_root_decoder_contains (const struct cxl_root_decoder *cxlrd, +const struct cxl_endpoint_decoder *cxled) {const struct range *r1, *r2;int niw;
@@ -39,8 +40,8 @@ bool platform_root_decoder_contains(const struct cxl_root_decoder *cxlrd,* Similar to platform_root_decoder_contains(), it matches regions and * decoders */ -bool platform_region_contains (const struct cxl_region_params *p, -const struct cxl_decoder *cxld) +__weak bool platform_region_contains (const struct cxl_region_params *p, +const struct cxl_decoder *cxld) {const struct range *r = &cxld->hpa_range;const struct resource *res = p->res;
tools/testing/cxl/Kbuild +1 -0
@@ -66,6 +66,7 @@ cxl_core-y += $(CXL_CORE_SRC)/acpi.o cxl_core-$(CONFIG_TRACING) += $(CXL_CORE_SRC)/trace.o cxl_core-$(CONFIG_CXL_REGION) += $(CXL_CORE_SRC)/region.o cxl_core-$(CONFIG_CXL_PLATFORM_QUIRKS) += $(CXL_CORE_SRC)/platform.o +cxl_core-$(CONFIG_CXL_PLATFORM_QUIRKS) += mock_platform.o cxl_core-$(CONFIG_CXL_MCE) += $(CXL_CORE_SRC)/mce.o cxl_core-$(CONFIG_CXL_FEATURES) += $(CXL_CORE_SRC)/features.o cxl_core-$(CONFIG_CXL_EDAC_MEM_FEATURES) += $(CXL_CORE_SRC)/edac.o
tools/testing/cxl/mock_platform.c new file +137 -0
137 lines not on this page · raw message
tools/testing/cxl/test/cxl.c +10 -0
@@ -212,7 +212,11 @@ static struct { .restrictions = ACPI_CEDT_CFMWS_RESTRICT_TYPE3 | ACPI_CEDT_CFMWS_RESTRICT_VOLATILE, .qtg_id = FAKE_QTG_ID, +#if defined(CONFIG_CXL_PLATFORM_QUIRKS) + .window_size = SZ_256M * 3UL, +#else .window_size = SZ_256M * 4UL, +#endif }, .target = { 0 }, },
@@ -453,6 +457,8 @@ static int populate_cedt(void)if (!res)return -ENOMEM ; window->base_hpa = res->range.start; +if (i ==0 ) +set_mock_cfmws0_range_start (res->range.start); }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_PLATFORM_QUIRKS ) +const int size =SZ_1G ; +#else const int size =SZ_512M ; +#endif struct cxl_memdev *cxlmd;struct cxl_dport *dport;struct device *dev;
tools/testing/cxl/test/mock.h +1 -0
@@ -32,3 +32,4 @@ void register_cxl_mock_ops(struct cxl_mock_ops *ops);void unregister_cxl_mock_ops (struct cxl_mock_ops *ops);struct cxl_mock_ops *get_cxl_mock_ops (int *index);void put_cxl_mock_ops (int index); +void set_mock_cfmws0_range_start (u64 start);
Signature · 1 line
2.50.1
Alison Schofield
maintainerRe: [PATCH 4/4 v4] cxl/test: Simulate an x86 Low Memory Hole for tests
Quoted 9 lines · 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.
The auto-created region of cxl-test uses mock_cfmws[0], therefore 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.
Quoted 4 lines
Since mock_cfmws[0] 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 when it's run on the mock environment created by cxl-tests.
Can you add a unit test that in addition to confirming that the auto region appears, (like cxl-topology.sh does) also verifies region and decoder settings and address translations.
That is work I did in a prior review and I was remiss in not asking for a unit test back then. I suspect it entails turning what you examine during your testing into a unit test script. cxl-poison.sh shows how to send clear-poison commands to validate address translations.
Related topic - if/when you get on real hardware with an LMH it would be useful to collect address translation samples to add to the cxl-translate.sh collection. (cxl-translate.sh is in review, not yet merged, see on the mailing list)
snip
Dave Jiang
maintainerRe: [PATCH 4/4 v4] cxl/test: Simulate an x86 Low Memory Hole for tests
In reply to Fabio M. De FrancescoQuoted 37 lines · 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.
The auto-created region of cxl-test uses mock_cfmws[0], therefore 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.Since mock_cfmws[0] 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 when it's run on the mock environment created by cxl-tests.
Therefore, save the mock_cfmsw[0] range
base_hpaand reuse it to match CXL Root Decoders and Regions with Endpoint Decoders when the driver is run on mock devices.Cc Alison Schofield <[email protected]>Cc Dan Williams <[email protected]>Cc Dave Jiang <[email protected]>Cc Ira Weiny <[email protected]>Signed-off-by Fabio M. De Francesco <[email protected]>--- drivers/cxl/core/platform.c | 9 +- tools/testing/cxl/Kbuild | 1 + tools/testing/cxl/mock_platform.c | 137 ++++++++++++++++++++++++++++++ tools/testing/cxl/test/cxl.c | 10 +++ tools/testing/cxl/test/mock.h | 1 + 5 files changed, 154 insertions(+), 4 deletions(-) create mode 100644 tools/testing/cxl/mock_platform.cdrivers/cxl/core/platform.c +0
-0
drivers/cxl/core/platform.c line 22
Quoted 8 lines
drivers/cxl/core/platform.c +3
-2@@ -17,8 +17,9 @@* 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 platform_root_decoder_contains (const struct cxl_root_decoder *cxlrd, -const struct cxl_endpoint_decoder *cxled) +__weak bool +platform_root_decoder_contains (const struct cxl_root_decoder *cxlrd, +const struct cxl_endpoint_decoder *cxled)
Can you take a look at this and see if something similar can be used instead of what you are doing here? Would prefer not introduce a third type of emulation.
Quoted 79 lines
drivers/cxl/core/platform.c +2
-2{const struct range *r1, *r2;int niw;@@ -39,8 +40,8 @@ bool platform_root_decoder_contains(const struct cxl_root_decoder *cxlrd,* Similar to platform_root_decoder_contains(), it matches regions and * decoders */ -bool platform_region_contains (const struct cxl_region_params *p, -const struct cxl_decoder *cxld) +__weak bool platform_region_contains (const struct cxl_region_params *p, +const struct cxl_decoder *cxld) {const struct range *r = &cxld->hpa_range;const struct resource *res = p->res;tools/testing/cxl/Kbuild +1
-0@@ -66,6 +66,7 @@ cxl_core-y += $(CXL_CORE_SRC)/acpi.o cxl_core-$(CONFIG_TRACING) += $(CXL_CORE_SRC)/trace.o cxl_core-$(CONFIG_CXL_REGION) += $(CXL_CORE_SRC)/region.o cxl_core-$(CONFIG_CXL_PLATFORM_QUIRKS) += $(CXL_CORE_SRC)/platform.o +cxl_core-$(CONFIG_CXL_PLATFORM_QUIRKS) += mock_platform.o cxl_core-$(CONFIG_CXL_MCE) += $(CXL_CORE_SRC)/mce.o cxl_core-$(CONFIG_CXL_FEATURES) += $(CXL_CORE_SRC)/features.o cxl_core-$(CONFIG_CXL_EDAC_MEM_FEATURES) += $(CXL_CORE_SRC)/edac.otools/testing/cxl/mock_platform.c new file +47
-0@@ -0,0 +1,137 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include <linux/completion.h> +#include <linux/module.h> +#include <linux/range.h> +#include <linux/pci.h> + +#include <cxlmem.h> +#include <platform.h> +#include "test/mock.h" + +static u64 mock_cfmws0_range_start; + +void set_mock_cfmws0_range_start (u64 start) +{ + mock_cfmws0_range_start = start; +} +EXPORT_SYMBOL_NS_GPL (set_mock_cfmws0_range_start,"CXL" ); + +static bool is_mock_port (struct device *dev) +{ +struct cxl_mock_ops *(*get_ops_fn)(int *index); +struct cxl_mock_ops *ops =NULL ; +void (*put_ops_fn)(int index); +bool is_mock = false; +int index; + + get_ops_fn =symbol_get (get_cxl_mock_ops); +if (!get_ops_fn) +return false; + put_ops_fn =symbol_get (put_cxl_mock_ops); +if (!put_ops_fn) + goto out; + + ops =get_ops_fn (&index); +if (ops) + is_mock = ops->is_mock_port (dev); +put_ops_fn (index); + +out: +symbol_put (get_cxl_mock_ops); + +return is_mock; +} + +/* Start of CFMWS range that end before x86 Low Memory Holes */ +#define LMH_CFMWS_RANGE_START 0x0ULL
tools/testing/cxl/mock_platform.c line 57
Quoted 10 lines
tools/testing/cxl/mock_platform.c new file +10
-0+ +static bool +real_platform_root_decoder_contains (const struct cxl_root_decoder *cxlrd, +const struct cxl_endpoint_decoder *cxled) +{ +const struct range *r1, *r2; +int niw; + + r1 = &cxlrd->cxlsd.cxld.hpa_range; + r2 = &cxled->cxld.hpa_range;
cxlsd_rangecxled_range
Makes it easier to read vs r1 and r2 and knowing what's being compared.
tools/testing/cxl/mock_platform.c line 62
Quoted 5 lines
tools/testing/cxl/mock_platform.c new file +5
-0+ 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 ))
Can this check be turned into a helper function? Also, maybe line it up with one check per line. Otherwise it looks rather confusing. Comment applies to rest of the patch.
DJ
Quoted 121 lines
tools/testing/cxl/mock_platform.c new file +75
-0+return true; + +return false; +} + +static bool +cxl_test_platform_root_decoder_contains (const struct cxl_root_decoder *cxlrd, +const struct cxl_endpoint_decoder *cxled) +{ +const 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 == mock_cfmws0_range_start && r1->start == r2->start && + r1->end < (mock_cfmws0_range_start +SZ_4G ) && r1->end < r2->end && +IS_ALIGNED (range_len (r2), niw *SZ_256M )) +return true; + +return false; +} + +bool platform_root_decoder_contains (const struct cxl_root_decoder *cxlrd, +const struct cxl_endpoint_decoder *cxled) +{ +struct cxl_port *port =to_cxl_port (cxled->cxld.dev.parent); + +if (is_mock_port (port->uport_dev)) +return cxl_test_platform_root_decoder_contains (cxlrd, cxled); + +return real_platform_root_decoder_contains (cxlrd, cxled); +} + +static bool real_platform_region_contains (const struct cxl_region_params *p, +const struct cxl_decoder *cxld) +{ +const struct range *r = &cxld->hpa_range; +const 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; +} + +static bool cxl_test_platform_region_contains (const struct cxl_region_params *p, +const struct cxl_decoder *cxld) +{ +const struct range *r = &cxld->hpa_range; +const struct resource *res = p->res; +int niw = cxld->interleave_ways; + +if (res->start == mock_cfmws0_range_start && res->start == r->start && + res->end < (mock_cfmws0_range_start +SZ_4G ) && res->end < r->end && +IS_ALIGNED (range_len (r), niw *SZ_256M )) +return true; + +return false; +} + +bool platform_region_contains (const struct cxl_region_params *p, +const struct cxl_decoder *cxld) +{ +struct cxl_port *port =to_cxl_port (cxld->dev.parent); + +if (is_mock_port (port->uport_dev)) +return cxl_test_platform_region_contains (p, cxld); + +return real_platform_region_contains (p, cxld); +}tools/testing/cxl/test/cxl.c +10
-0@@ -212,7 +212,11 @@ static struct { .restrictions = ACPI_CEDT_CFMWS_RESTRICT_TYPE3 | ACPI_CEDT_CFMWS_RESTRICT_VOLATILE, .qtg_id = FAKE_QTG_ID, +#if defined(CONFIG_CXL_PLATFORM_QUIRKS) + .window_size = SZ_256M * 3UL, +#else .window_size = SZ_256M * 4UL, +#endif }, .target = { 0 }, },@@ -453,6 +457,8 @@ static int populate_cedt(void)if (!res)return -ENOMEM ; window->base_hpa = res->range.start; +if (i ==0 ) +set_mock_cfmws0_range_start (res->range.start); }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_PLATFORM_QUIRKS ) +const int size =SZ_1G ; +#else const int size =SZ_512M ; +#endif struct cxl_memdev *cxlmd;struct cxl_dport *dport;struct device *dev;tools/testing/cxl/test/mock.h +1
-0@@ -32,3 +32,4 @@ void register_cxl_mock_ops(struct cxl_mock_ops *ops);void unregister_cxl_mock_ops (struct cxl_mock_ops *ops);struct cxl_mock_ops *get_cxl_mock_ops (int *index);void put_cxl_mock_ops (int index); +void set_mock_cfmws0_range_start (u64 start);
Dave Jiang
maintainerQuoted 90 lines · 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. 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, Dave and Ira for their help.
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 v4:
Re-base on top of
"cxl: Address translation support, part 1: Cleanups and refactoring";[1]
Drop no more necessary 2/4;
Drop collected tags because of major changes throughout the series.1/3 - Adjust Endpoint Decoders
dpa_res->end(Alison) [2] 3/3 - Use weak/strong mechanism (Dan) [3]Changes for v3:
Re-base the series on cxl/next.
1/4 - 2/4:
Constify local variables.
3/4:
Callarch_match_region()fromregion_res_match_cxl_range().
4/4:
arch_match_region()- Check that region end is under start + 4G;arch_match_spa()- Check that SPA range start iscfmws_range_start.v3 - https://lore.kernel.org/linux-cxl/[email protected]/
v2 - https://lore.kernel.org/linux-cxl/[email protected]/
v1 - https://lore.kernel.org/all/[email protected]/[0] - https://lore.kernel.org/all/[email protected]/
[1] - https://lore.kernel.org/linux-cxl/[email protected]/
[2] - https://lore.kernel.org/linux-cxl/[email protected]/
[3] - https://lore.kernel.org/linux-cxl/[email protected]/Fabio M. De Francesco (4):
cxl/core: Change match_*_by_range() signatures cxl/core: Add helpers to detect Low Memory Holes on x86 cxl/core: Enable Region creation on x86 with LMH cxl/test: Simulate an x86 Low Memory Hole for testsdrivers/cxl/Kconfig | 5 ++ drivers/cxl/core/Makefile | 1 + drivers/cxl/core/platform.c | 86 +++++++++++++++++++ drivers/cxl/core/platform.h | 32 +++++++ drivers/cxl/core/region.c | 113 ++++++++++++++++-------- tools/testing/cxl/Kbuild | 2 + tools/testing/cxl/mock_platform.c | 137 ++++++++++++++++++++++++++++++ tools/testing/cxl/test/cxl.c | 10 +++ tools/testing/cxl/test/mock.h | 1 + 9 files changed, 352 insertions(+), 35 deletions(-) create mode 100644 drivers/cxl/core/platform.c create mode 100644 drivers/cxl/core/platform.h create mode 100644 tools/testing/cxl/mock_platform.c
Quoted 1 line
base-commit:
acc2913692413df9d1
The series doesn't seem to apply to this base commit.
Quoted 1 line
Dave Jiang
maintainerQuoted 93 lines · Dave Jiang
Quoted 90 lines · 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. 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, Dave and Ira for their help.
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 v4:
Re-base on top of
"cxl: Address translation support, part 1: Cleanups and refactoring";[1]
Drop no more necessary 2/4;
Drop collected tags because of major changes throughout the series.1/3 - Adjust Endpoint Decoders
dpa_res->end(Alison) [2] 3/3 - Use weak/strong mechanism (Dan) [3]Changes for v3:
Re-base the series on cxl/next.
1/4 - 2/4:
Constify local variables.
3/4:
Callarch_match_region()fromregion_res_match_cxl_range().
4/4:
arch_match_region()- Check that region end is under start + 4G;arch_match_spa()- Check that SPA range start iscfmws_range_start.v3 - https://lore.kernel.org/linux-cxl/[email protected]/
v2 - https://lore.kernel.org/linux-cxl/[email protected]/
v1 - https://lore.kernel.org/all/[email protected]/[0] - https://lore.kernel.org/all/[email protected]/
[1] - https://lore.kernel.org/linux-cxl/[email protected]/
[2] - https://lore.kernel.org/linux-cxl/[email protected]/
[3] - https://lore.kernel.org/linux-cxl/[email protected]/Fabio M. De Francesco (4):
cxl/core: Change match_*_by_range() signatures cxl/core: Add helpers to detect Low Memory Holes on x86 cxl/core: Enable Region creation on x86 with LMH cxl/test: Simulate an x86 Low Memory Hole for testsdrivers/cxl/Kconfig | 5 ++ drivers/cxl/core/Makefile | 1 + drivers/cxl/core/platform.c | 86 +++++++++++++++++++ drivers/cxl/core/platform.h | 32 +++++++ drivers/cxl/core/region.c | 113 ++++++++++++++++-------- tools/testing/cxl/Kbuild | 2 + tools/testing/cxl/mock_platform.c | 137 ++++++++++++++++++++++++++++++ tools/testing/cxl/test/cxl.c | 10 +++ tools/testing/cxl/test/mock.h | 1 + 9 files changed, 352 insertions(+), 35 deletions(-) create mode 100644 drivers/cxl/core/platform.c create mode 100644 drivers/cxl/core/platform.h create mode 100644 tools/testing/cxl/mock_platform.c
Quoted 3 lines
Quoted 1 line
base-commit:
acc2913692413df9d1The series doesn't seem to apply to this base commit.
Please rebase v5 against v6.17-rc. Thanks!
Quoted 3 lines
Quoted 1 line