cxl: Address translation support, part 1: Cleanups and refactoring
v6 cover cxl: Address translation support, part 1: Cleanups and refactoring
This series is the first part of adding support for CXL address translation. It contains cleanup and code refactoring in preparation of the actual implementation that will be sent in part 2. Cleanup and code refactoring have been split in a separate series to reduce the number of patches of the series. Even without address translation on top this rework improves esp. the region code, cleans it up, simplifies it and adds debugging messages to better analyze region creation failures:
Content of patches:
* Patches 1: Remove else after return.
* Patches 2-3: Cleanups and comments around cxl_hdm_decode_init().
* Patches 4-6: Adding and modifying helper functions.
* Patches 7-11: Refactoring of endpoint decoder setup and cxl_find*() including cleanup helpers.
* Patches 12-14: Adding and modifying debug messages.
v6:
* added tags to SOB chain,
* added more occurences to remove-else-after-return (Alison),
* updated description of cxl_port_pick_region_decoder() (Fabio),
v5:
* added tags to SOB chain,
* made comment a oneliner in cxl_hdm_decode_init() (Jonathan),
* updated patch description introducing parent_port_of() (Fabio),
* removed EXPORT_SYMBOL_NS_GPL() of function parent_port_of() (Dan),
* renamed functions to cxl_port_pick_region_decoder() and cxl_rr_assign_decoder(), updated descriptions (Dan),
* added patch to replace put_cxl_root() by a cleanup helper,
* using __free() for reference counting of cxl_find_*() functions, added cleanup helpers (Dan),
* dropped patch adding CFMWS memory log messages (Dan),
v4:
* rebased onto cxl/next, commit 0a14566be090 ("cxl/Documentation:
Remove 'mixed' from sysfs mode doc"),
* added tags to SOB chain,
* reworked comments in cxl_hdm_decode_init() (dropped moving comment and updated patch that modifies comments) (Jonathan),
* reworded patch description that removes duplicate call of cxl_find_decoder_early() (Jonathan),
* moved some patches out of this rework and cleanup series (Dave, Jonathan),
v3:
* added tags to SOB chain,
* fixed NULL pointer dereference in cxl_find_root_decoder() (Alison),
* updated subject line of patches that add kernel messages and included example log messages (Alison),
v2:
* rebased onto cxl/next,
* added tags to SOB chain,
* move patches with cleanups and refactoring into this separate series (Dave),
* added patch "cxl/acpi: Unify CFMWS memory log messages with SRAT messages" to improve CFMWS log messages,
* renamed endpoint decoder functions to cxl_endpoint_decoder_*() (Li),
* reworded patch description that moves find_cxl_root() and reworks cxl_find_root_decoder() (Terry),
* small changes to cxl_find_root_decoder()/ cxl_endpoint_decoder_initialize() (Jonanthan),
* updated comment in cxl_port_find_switch_decoder() (Ben),
* cxl_endpoint_decoder_initialize(): Simplify variable declaration (Jonathan, Ben),
* cxl_find_decoder_early(): Added comment on function usage (Gregory),
* reordered patches and reworded some of the subject for a better structure.
Robert Richter (14):
cxl: Remove else after return
cxl/pci: Moving code in cxl_hdm_decode_init()
cxl/pci: Add comments to cxl_hdm_decode_init()
cxl: Introduce parent_port_of() helper
cxl/region: Rename function to cxl_port_pick_region_decoder() cxl/region: Avoid duplicate call of cxl_port_pick_region_decoder() cxl/region: Move find_cxl_root() to cxl_add_to_region() cxl/port: Replace put_cxl_root() by a cleanup helper cxl/region: Factor out code to find the root decoder cxl/region: Factor out code to find a root decoder's region cxl/region: Add function to find a port's switch decoder by range cxl/region: Add a dev_warn() on registration failure cxl/region: Add a dev_err() on missing target list entries
cxl: Add a dev_dbg() when a decoder was added to a port
drivers/cxl/acpi.c | 10 ++- drivers/cxl/core/cdat.c | 2 +- drivers/cxl/core/hdm.c | 3 +- drivers/cxl/core/memdev.c | 4 +- drivers/cxl/core/pci.c | 48 +++++++---- drivers/cxl/core/port.c | 23 ++--- drivers/cxl/core/region.c | 177 +++++++++++++++++++++++--------------- drivers/cxl/cxl.h | 13 +-- drivers/cxl/port.c | 15 +--- 9 files changed, 173 insertions(+), 122 deletions(-)
base-commit: 8e62ba590160f91abba6490d9c17aa13bada4752
Signature · 1 line
2.39.5
PATCH v6 1/14 cxl: Remove else after return
Remove unnecessary 'else' after return. Improves readability of code. It is easier to place comments. Check and fix all occurrences under drivers/cxl/.
--- drivers/cxl/core/cdat.c | 2 +- drivers/cxl/core/memdev.c | 4 ++-- drivers/cxl/core/pci.c | 3 ++- drivers/cxl/core/region.c | 11 ++++++----- 4 files changed, 11 insertions(+), 9 deletions(-)
drivers/cxl/core/cdat.c +1 -1
@@ -28,7 +28,7 @@ static u32 cdat_normalize(u16 entry, u64 base, u8 type)*/ if (entry ==0xffff || !entry)return 0 ; -else if (base > (UINT_MAX / (entry))) +if (base > (UINT_MAX / (entry)))return 0 ;/*
drivers/cxl/core/memdev.c +2 -2
@@ -153,8 +153,8 @@ static ssize_t security_state_show(struct device *dev,return sysfs_emit (buf,"frozen\n" );if (state &CXL_PMEM_SEC_STATE_LOCKED )return sysfs_emit (buf,"locked\n" ); -else -return sysfs_emit (buf,"unlocked\n" ); + +return sysfs_emit (buf,"unlocked\n" ); }static struct device_attribute dev_attr_security_state =__ATTR (state,0444 , security_state_show,NULL );
drivers/cxl/core/pci.c +2 -1
@@ -415,7 +415,8 @@ int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm,*/ if (global_ctrl &CXL_HDM_DECODER_ENABLE || (!hdm && info->mem_enabled))return devm_cxl_enable_mem (&port->dev, cxlds); -else if (!hdm) + +if (!hdm)return -ENODEV ; root =to_cxl_port (port->dev.parent);
drivers/cxl/core/region.c +6 -5
@@ -231,11 +231,10 @@ static int cxl_region_invalidate_memregion(struct cxl_region *cxlr) &cxlr->dev, "Bypassing cpu_cache_invalidate_memregion() for testing!\n");return 0 ; - }else { -dev_WARN (&cxlr->dev, -"Failed to synchronize CPU cache state\n" ); -return -ENXIO ; } +dev_WARN (&cxlr->dev, +"Failed to synchronize CPU cache state\n" ); +return -ENXIO ; }cpu_cache_invalidate_memregion (IORES_DESC_CXL );
@@ -1940,7 +1939,9 @@ static int cxl_region_attach(struct cxl_region *cxlr,if (p->state >CXL_CONFIG_INTERLEAVE_ACTIVE ) {dev_dbg (&cxlr->dev,"region already active\n" );return -EBUSY ; - }else if (p->state <CXL_CONFIG_INTERLEAVE_ACTIVE ) { + } + +if (p->state <CXL_CONFIG_INTERLEAVE_ACTIVE ) {dev_dbg (&cxlr->dev,"interleave config missing\n" );return -ENXIO ; }
Signature · 1 line
2.39.5
PATCH v6 2/14 cxl/pci: Moving code in cxl_hdm_decode_init()
In reply to Robert RichterCommit 3f9e07531778 ("cxl/pci: simplify the check of mem_enabled in cxl_hdm_decode_init()") changed the code flow in this function. The root port is determined before a check to leave the function. Since the root port is not used by the check it can be moved to run the check first. This improves code readability and avoids unnesessary code execution.
--- drivers/cxl/core/pci.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/cxl/core/pci.c +8 -8
@@ -419,14 +419,6 @@ int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm,if (!hdm)return -ENODEV ; - root =to_cxl_port (port->dev.parent); -while (!is_cxl_root (root) &&is_cxl_port (root->dev.parent)) - root =to_cxl_port (root->dev.parent); -if (!is_cxl_root (root)) { -dev_err (dev,"Failed to acquire root port for HDM enable\n" ); -return -ENODEV ; - } -if (!info->mem_enabled) { rc =devm_cxl_enable_hdm (&port->dev, cxlhdm);if (rc)
@@ -435,6 +427,14 @@ int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm,return devm_cxl_enable_mem (&port->dev, cxlds); } + root =to_cxl_port (port->dev.parent); +while (!is_cxl_root (root) &&is_cxl_port (root->dev.parent)) + root =to_cxl_port (root->dev.parent); +if (!is_cxl_root (root)) { +dev_err (dev,"Failed to acquire root port for HDM enable\n" ); +return -ENODEV ; + } +for (i =0 , allowed =0 ; i < info->ranges; i++) {struct device *cxld_dev;
Signature · 1 line
2.39.5
PATCH v6 3/14 cxl/pci: Add comments to cxl_hdm_decode_init()
In reply to Robert RichterThere are various configuration cases of HDM decoder registers causing different code paths. Add comments to cxl_hdm_decode_init() to better explain them.
--- drivers/cxl/core/pci.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-)
drivers/cxl/core/pci.c +22 -9
@@ -416,9 +416,19 @@ int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm,if (global_ctrl &CXL_HDM_DECODER_ENABLE || (!hdm && info->mem_enabled))return devm_cxl_enable_mem (&port->dev, cxlds); +/* +* If the HDM Decoder Capability does not exist and DVSEC was +* not setup, the DVSEC based emulation cannot be used. +*/ if (!hdm)return -ENODEV ; +/* The HDM Decoder Capability exists but is globally disabled. */ + +/* +* If the DVSEC CXL Range registers are not enabled, just +* enable and use the HDM Decoder Capability registers. +*/ if (!info->mem_enabled) { rc =devm_cxl_enable_hdm (&port->dev, cxlhdm);if (rc)
@@ -427,6 +437,18 @@ int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm,return devm_cxl_enable_mem (&port->dev, cxlds); } +/* +* Per CXL 2.0 Section 8.1.3.8.3 and 8.1.3.8.4 DVSEC CXL Range 1 Base +* [High,Low] when HDM operation is enabled the range register values +* are ignored by the device, but the spec also recommends matching the +* DVSEC Range 1,2 to HDM Decoder Range 0,1. So, non-zero info->ranges +* are expected even though Linux does not require or maintain that +* match. Check if at least one DVSEC range is enabled and allowed by +* the platform. That is, the DVSEC range must be covered by a locked +* platform window (CFMWS). Fail otherwise as the endpoint's decoders +* cannot be used. +*/ + root =to_cxl_port (port->dev.parent);while (!is_cxl_root (root) &&is_cxl_port (root->dev.parent)) root =to_cxl_port (root->dev.parent);
@@ -454,15 +476,6 @@ int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm,return -ENXIO ; } -/* -* Per CXL 2.0 Section 8.1.3.8.3 and 8.1.3.8.4 DVSEC CXL Range 1 Base -* [High,Low] when HDM operation is enabled the range register values -* are ignored by the device, but the spec also recommends matching the -* DVSEC Range 1,2 to HDM Decoder Range 0,1. So, non-zero info->ranges -* are expected even though Linux does not require or maintain that -* match. If at least one DVSEC range is enabled and allowed, skip HDM -* Decoder Capability Enable. -*/ return 0 ; }EXPORT_SYMBOL_NS_GPL (cxl_hdm_decode_init,"CXL" );
Signature · 1 line
2.39.5
PATCH v6 4/14 cxl: Introduce parent_port_of() helper
In reply to Robert RichterOften a parent port must be determined. Introduce the parent_port_of() helper function to avoid open coding of determination of a parent port.
--- drivers/cxl/core/port.c | 14 ++++++++------ drivers/cxl/core/region.c | 11 ++--------- drivers/cxl/cxl.h | 1 + 3 files changed, 11 insertions(+), 15 deletions(-)
drivers/cxl/core/port.c +8 -6
@@ -602,17 +602,19 @@ struct cxl_port *to_cxl_port(const struct device *dev) }EXPORT_SYMBOL_NS_GPL (to_cxl_port,"CXL" ); +struct cxl_port *parent_port_of (struct cxl_port *port) +{ +if (!port || !port->parent_dport) +return NULL ; +return port->parent_dport->port; +} +static void unregister_port (void *_port) {struct cxl_port *port = _port; -struct cxl_port *parent; +struct cxl_port *parent =parent_port_of (port);struct device *lock_dev; -if (is_cxl_root (port)) - parent =NULL ; -else - parent =to_cxl_port (port->dev.parent); -/* * CXL root port's and the first level of ports are unregistered * under the platform firmware device lock, all other ports are
drivers/cxl/core/region.c +2 -9
@@ -1747,13 +1747,6 @@ static int cmp_interleave_pos(const void *a, const void *b)return cxled_a->pos - cxled_b->pos; } -static struct cxl_port *next_port (struct cxl_port *port) -{ -if (!port->parent_dport) -return NULL ; -return port->parent_dport->port; -} -static int match_switch_decoder_by_range (struct device *dev,const void *data) {
@@ -1780,7 +1773,7 @@ static int find_pos_and_ways(struct cxl_port *port, struct range *range,struct device *dev;int rc = -ENXIO ; - parent =next_port (port); + parent =parent_port_of (port);if (!parent)return rc;
@@ -1860,7 +1853,7 @@ static int cxl_calc_interleave_pos(struct cxl_endpoint_decoder *cxled)*/ /* Iterate from endpoint to root_port refining the position */ -for (iter = port; iter; iter =next_port (iter)) { +for (iter = port; iter; iter =parent_port_of (iter)) {if (is_cxl_root (iter))break ;
drivers/cxl/cxl.h +1 -0
@@ -724,6 +724,7 @@ static inline bool is_cxl_root(struct cxl_port *port)int cxl_num_decoders_committed (struct cxl_port *port);bool is_cxl_port (const struct device *dev);struct cxl_port *to_cxl_port (const struct device *dev); +struct cxl_port *parent_port_of (struct cxl_port *port);void cxl_port_commit_reap (struct cxl_decoder *cxld);struct pci_bus ; int devm_cxl_register_pci_bus(struct device *host, struct device *uport_dev,
Signature · 1 line
2.39.5
PATCH v6 5/14 cxl/region: Rename function to cxl_port_pick_region_decoder()
In reply to Robert RichterCurrent function cxl_region_find_decoder() is used to find a port's decoder during region setup. In the region creation path the function is an allocator to find a free port. In the region assembly path, it is recalling the decoder that platform firmware picked for validation purposes.
Rename function to cxl_port_pick_region_decoder() that better describes its use and update the function's description.
The result of cxl_port_pick_region_decoder() is recorded in a 'struct cxl_region_ref' in @port for later recall when other endpoints might also be targets of the picked decoder.
--- drivers/cxl/core/region.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)
drivers/cxl/core/region.c +18 -5
@@ -864,10 +864,23 @@ static int match_auto_decoder(struct device *dev, const void *data)return 0 ; } +/** +* cxl_port_pick_region_decoder() - assign or lookup a decoder for a region +* @port: a port in the ancestry of the endpoint implied by @cxled +* @cxled: endpoint decoder to be, or currently, mapped by @port +* @cxlr: region to establish, or validate, decode @port +* +* In the region creation path cxl_port_pick_region_decoder() is an +* allocator to find a free port. In the region assembly path, it is +* recalling the decoder that platform firmware picked for validation +* purposes. +* +* The result is recorded in a 'struct cxl_region_ref' in @port. +*/ static struct cxl_decoder * -cxl_region_find_decoder (struct cxl_port *port, -struct cxl_endpoint_decoder *cxled, -struct cxl_region *cxlr) +cxl_port_pick_region_decoder (struct cxl_port *port, +struct cxl_endpoint_decoder *cxled, +struct cxl_region *cxlr) {struct device *dev;
@@ -931,7 +944,7 @@ alloc_region_ref(struct cxl_port *port, struct cxl_region *cxlr,if (test_bit (CXL_REGION_F_AUTO , &cxlr->flags)) {struct cxl_decoder *cxld; - cxld =cxl_region_find_decoder (port, cxled, cxlr); + cxld =cxl_port_pick_region_decoder (port, cxled, cxlr);if (auto_order_ok (port, iter->region, cxld))continue ; }
@@ -1019,7 +1032,7 @@ static int cxl_rr_alloc_decoder(struct cxl_port *port, struct cxl_region *cxlr, {struct cxl_decoder *cxld; - cxld =cxl_region_find_decoder (port, cxled, cxlr); + cxld =cxl_port_pick_region_decoder (port, cxled, cxlr);if (!cxld) {dev_dbg (&cxlr->dev,"%s: no decoder available\n" ,dev_name (&port->dev));
Signature · 1 line
2.39.5
PATCH v6 6/14 cxl/region: Avoid duplicate call of cxl_port_pick_region_decoder()
In reply to Robert RichterFunction cxl_port_pick_region_decoder() is called twice, in alloc_region_ref() and cxl_rr_alloc_decoder(). Both functions are subsequently called from cxl_port_attach_region(). Make the decoder a function argument to both which avoids a duplicate call of cxl_port_pick_region_decoder().
Now, cxl_rr_alloc_decoder() no longer allocates the decoder. Instead, the previously picked decoder is assigned to the region reference. Hence, rename the function to cxl_rr_assign_decoder().
Moving the call out of alloc_region_ref() also moves it out of the xa_for_each() loop in there. Now, cxld is determined no longer only for each auto-generated region, but now once for all regions regardless of auto-generated or not. This is fine as the cxld argument is needed for all regions in cxl_rr_assign_decoder() and an error would be returned otherwise anyway. So it is better to determine the decoder in front of all this and fail early if missing instead of running through all that code with multiple calls of cxl_port_pick_region_decoder().
--- drivers/cxl/core/region.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-)
drivers/cxl/core/region.c +17 -18
@@ -928,7 +928,8 @@ static bool auto_order_ok(struct cxl_port *port, struct cxl_region *cxlr_iter,static struct cxl_region_ref *alloc_region_ref (struct cxl_port *port,struct cxl_region *cxlr, -struct cxl_endpoint_decoder *cxled) +struct cxl_endpoint_decoder *cxled, +struct cxl_decoder *cxld) {struct cxl_region_params *p = &cxlr->params;struct cxl_region_ref *cxl_rr, *iter;
@@ -942,9 +943,6 @@ alloc_region_ref(struct cxl_port *port, struct cxl_region *cxlr,continue ;if (test_bit (CXL_REGION_F_AUTO , &cxlr->flags)) { -struct cxl_decoder *cxld; - - cxld =cxl_port_pick_region_decoder (port, cxled, cxlr);if (auto_order_ok (port, iter->region, cxld))continue ; }
@@ -1026,19 +1024,11 @@ static int cxl_rr_ep_add(struct cxl_region_ref *cxl_rr,return 0 ; } -static int cxl_rr_alloc_decoder (struct cxl_port *port,struct cxl_region *cxlr, -struct cxl_endpoint_decoder *cxled, -struct cxl_region_ref *cxl_rr) +static int cxl_rr_assign_decoder (struct cxl_port *port,struct cxl_region *cxlr, +struct cxl_endpoint_decoder *cxled, +struct cxl_region_ref *cxl_rr, +struct cxl_decoder *cxld) { -struct cxl_decoder *cxld; - - cxld =cxl_port_pick_region_decoder (port, cxled, cxlr); -if (!cxld) { -dev_dbg (&cxlr->dev,"%s: no decoder available\n" , -dev_name (&port->dev)); -return -EBUSY ; - } -if (cxld->region) { dev_dbg(&cxlr->dev, "%s: %s already attached to %s\n", dev_name(&port->dev), dev_name(&cxld->dev),
@@ -1129,7 +1119,16 @@ static int cxl_port_attach_region(struct cxl_port *port, nr_targets_inc = true; } }else { - cxl_rr =alloc_region_ref (port, cxlr, cxled); +struct cxl_decoder *cxld; + + cxld =cxl_port_pick_region_decoder (port, cxled, cxlr); +if (!cxld) { +dev_dbg (&cxlr->dev,"%s: no decoder available\n" , +dev_name (&port->dev)); +return -EBUSY ; + } + + cxl_rr =alloc_region_ref (port, cxlr, cxled, cxld);if (IS_ERR (cxl_rr)) { dev_dbg(&cxlr->dev, "%s: failed to allocate region reference\n",
@@ -1138,7 +1137,7 @@ static int cxl_port_attach_region(struct cxl_port *port, } nr_targets_inc = true; - rc =cxl_rr_alloc_decoder (port, cxlr, cxled, cxl_rr); + rc =cxl_rr_assign_decoder (port, cxlr, cxled, cxl_rr, cxld);if (rc) goto out_erase; }
Signature · 1 line
2.39.5
PATCH v6 7/14 cxl/region: Move find_cxl_root() to cxl_add_to_region()
In reply to Robert RichterWhen adding an endpoint to a region, the root port is determined first. Move this directly into cxl_add_to_region(). This is in preparation of the initialization of endpoints that iterates the port hierarchy from the endpoint up to the root port.
As a side-effect the root argument is removed from the argument lists of cxl_add_to_region() and related functions. Now, the endpoint is the only parameter to add a region. This simplifies the function interface.
--- drivers/cxl/core/region.c | 6 ++++-- drivers/cxl/cxl.h | 6 ++---- drivers/cxl/port.c | 15 +++------------ 3 files changed, 9 insertions(+), 18 deletions(-)
drivers/cxl/core/region.c +4 -2
@@ -3382,9 +3382,11 @@ static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd,return cxlr; } -int cxl_add_to_region (struct cxl_port *root,struct cxl_endpoint_decoder *cxled) +int cxl_add_to_region (struct cxl_endpoint_decoder *cxled) {struct cxl_memdev *cxlmd =cxled_to_memdev (cxled); +struct cxl_port *port =cxled_to_port (cxled); + struct cxl_root *cxl_root __free(put_cxl_root) = find_cxl_root(port);struct range *hpa = &cxled->cxld.hpa_range;struct cxl_decoder *cxld = &cxled->cxld;struct device *cxlrd_dev, *region_dev;
@@ -3394,7 +3396,7 @@ int cxl_add_to_region(struct cxl_port *root, struct cxl_endpoint_decoder *cxled)bool attach = false;int rc; - cxlrd_dev =device_find_child (&root->dev, &cxld->hpa_range, + cxlrd_dev =device_find_child (&cxl_root->port.dev, &cxld->hpa_range, match_root_decoder_by_range);if (!cxlrd_dev) { dev_err(cxlmd->dev.parent,
drivers/cxl/cxl.h +2 -4
@@ -857,8 +857,7 @@ struct cxl_nvdimm_bridge *cxl_find_nvdimm_bridge(struct cxl_port *port);#ifdef CONFIG_CXL_REGION bool is_cxl_pmem_region (struct device *dev);struct cxl_pmem_region *to_cxl_pmem_region (struct device *dev); -int cxl_add_to_region (struct cxl_port *root, -struct cxl_endpoint_decoder *cxled); +int cxl_add_to_region (struct cxl_endpoint_decoder *cxled);struct cxl_dax_region *to_cxl_dax_region (struct device *dev);u64 cxl_port_get_spa_cache_alias (struct cxl_port *endpoint,u64 spa);#else
@@ -870,8 +869,7 @@ static inline struct cxl_pmem_region *to_cxl_pmem_region(struct device *dev) {return NULL ; } -static inline int cxl_add_to_region (struct cxl_port *root, -struct cxl_endpoint_decoder *cxled) +static inline int cxl_add_to_region (struct cxl_endpoint_decoder *cxled) {return 0 ; }
drivers/cxl/port.c +3 -12
@@ -30,7 +30,7 @@ static void schedule_detach(void *cxlmd)schedule_cxl_memdev_detach (cxlmd); } -static int discover_region (struct device *dev,void *root) +static int discover_region (struct device *dev,void *unused) {struct cxl_endpoint_decoder *cxled;int rc;
@@ -49,7 +49,7 @@ static int discover_region(struct device *dev, void *root)* Region enumeration is opportunistic, if this add-event fails, * continue to the next endpoint decoder. */ - rc =cxl_add_to_region (root, cxled); + rc =cxl_add_to_region (cxled);if (rc)dev_dbg (dev,"failed to add to region: %#llx-%#llx\n" , cxled->cxld.hpa_range.start, cxled->cxld.hpa_range.end);
@@ -95,7 +95,6 @@ static int cxl_endpoint_port_probe(struct cxl_port *port)struct cxl_memdev *cxlmd =to_cxl_memdev (port->uport_dev);struct cxl_dev_state *cxlds = cxlmd->cxlds;struct cxl_hdm *cxlhdm; -struct cxl_port *root;int rc; rc =cxl_dvsec_rr_decode (cxlds, &info);
@@ -126,19 +125,11 @@ static int cxl_endpoint_port_probe(struct cxl_port *port)if (rc)return rc; -/* -* This can't fail in practice as CXL root exit unregisters all -* descendant ports and that in turn synchronizes with cxl_port_probe() -*/ - struct cxl_root *cxl_root __free(put_cxl_root) = find_cxl_root(port); - - root = &cxl_root->port; -/* * Now that all endpoint decoders are successfully enumerated, try to * assemble regions from committed decoders */ -device_for_each_child (&port->dev, root, discover_region); +device_for_each_child (&port->dev,NULL , discover_region);return 0 ; }
Signature · 1 line
2.39.5
PATCH v6 8/14 cxl/port: Replace put_cxl_root() by a cleanup helper
In reply to Robert RichterFunction put_cxl_root() is only used by its cleanup helper. Remove the function entirely and only use the helper.
--- drivers/cxl/core/port.c | 9 --------- drivers/cxl/cxl.h | 4 ++-- 2 files changed, 2 insertions(+), 11 deletions(-)
drivers/cxl/core/port.c +0 -9
@@ -1037,15 +1037,6 @@ struct cxl_root *find_cxl_root(struct cxl_port *port) }EXPORT_SYMBOL_NS_GPL (find_cxl_root,"CXL" ); -void put_cxl_root (struct cxl_root *cxl_root) -{ -if (!cxl_root) -return ; - -put_device (&cxl_root->port.dev); -} -EXPORT_SYMBOL_NS_GPL (put_cxl_root,"CXL" ); -static struct cxl_dport *find_dport (struct cxl_port *port,int id) {struct cxl_dport *dport;
drivers/cxl/cxl.h +2 -2
@@ -737,10 +737,10 @@ struct cxl_port *devm_cxl_add_port(struct device *host,struct cxl_root *devm_cxl_add_root (struct device *host,const struct cxl_root_ops *ops);struct cxl_root *find_cxl_root (struct cxl_port *port); -void put_cxl_root (struct cxl_root *cxl_root); -DEFINE_FREE(put_cxl_root, struct cxl_root *, if (_T) put_cxl_root(_T)) +DEFINE_FREE(put_cxl_root, struct cxl_root *, if (_T) put_device(&_T->port.dev)) DEFINE_FREE(put_cxl_port, struct cxl_port *, if (!IS_ERR_OR_NULL(_T)) put_device(&_T->dev)) +int devm_cxl_enumerate_ports (struct cxl_memdev *cxlmd);void cxl_bus_rescan (void );void cxl_bus_drain (void );
Signature · 1 line
2.39.5
PATCH v6 9/14 cxl/region: Factor out code to find the root decoder
In reply to Robert RichterIn function cxl_add_to_region() there is code to determine the root decoder associated to an endpoint decoder. Factor out that code for later reuse. This has the benefit of reducing cxl_add_to_region()'s function complexity.
The reference count must be decremented after using the root decoder. cxl_find_root_decoder() is paired with the put_cxl_root_decoder cleanup helper that can be used for this.
--- drivers/cxl/core/region.c | 48 +++++++++++++++++++++++---------------- drivers/cxl/cxl.h | 1 + 2 files changed, 30 insertions(+), 19 deletions(-)
drivers/cxl/core/region.c +29 -19
@@ -3216,6 +3216,29 @@ static int match_root_decoder_by_range(struct device *dev,return range_contains (r1, r2); } +static struct cxl_root_decoder * +cxl_find_root_decoder (struct cxl_endpoint_decoder *cxled) +{ +struct cxl_memdev *cxlmd =cxled_to_memdev (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 *cxld = &cxled->cxld; +struct range *hpa = &cxld->hpa_range; +struct device *cxlrd_dev; + + cxlrd_dev =device_find_child (&cxl_root->port.dev, hpa, + match_root_decoder_by_range); +if (!cxlrd_dev) { +dev_err (cxlmd->dev.parent, +"%s:%s no CXL window for range %#llx:%#llx\n" , +dev_name (&cxlmd->dev),dev_name (&cxld->dev), + cxld->hpa_range.start, cxld->hpa_range.end); +return NULL ; + } + +return to_cxl_root_decoder (cxlrd_dev); +} +static int match_region_by_range (struct device *dev,const void *data) {struct cxl_region_params *p;
@@ -3384,29 +3407,17 @@ static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd,int cxl_add_to_region (struct cxl_endpoint_decoder *cxled) { -struct cxl_memdev *cxlmd =cxled_to_memdev (cxled); -struct cxl_port *port =cxled_to_port (cxled); - struct cxl_root *cxl_root __free(put_cxl_root) = find_cxl_root(port); + struct cxl_root_decoder *cxlrd __free(put_cxl_root_decoder) = NULL;struct range *hpa = &cxled->cxld.hpa_range; -struct cxl_decoder *cxld = &cxled->cxld; -struct device *cxlrd_dev, *region_dev; -struct cxl_root_decoder *cxlrd; +struct device *region_dev;struct cxl_region_params *p;struct cxl_region *cxlr;bool attach = false;int rc; - cxlrd_dev =device_find_child (&cxl_root->port.dev, &cxld->hpa_range, - match_root_decoder_by_range); -if (!cxlrd_dev) { -dev_err (cxlmd->dev.parent, -"%s:%s no CXL window for range %#llx:%#llx\n" , -dev_name (&cxlmd->dev),dev_name (&cxld->dev), - cxld->hpa_range.start, cxld->hpa_range.end); + cxlrd =cxl_find_root_decoder (cxled); +if (!cxlrd)return -ENXIO ; - } - - cxlrd =to_cxl_root_decoder (cxlrd_dev);/* * Ensure that if multiple threads race to construct_region() for @hpa
@@ -3424,7 +3435,7 @@ int cxl_add_to_region(struct cxl_endpoint_decoder *cxled) rc =PTR_ERR_OR_ZERO (cxlr);if (rc) - goto out; +return rc;attach_target (cxlr, cxled,-1 ,TASK_UNINTERRUPTIBLE );
@@ -3445,8 +3456,7 @@ int cxl_add_to_region(struct cxl_endpoint_decoder *cxled) }put_device (region_dev); -out: -put_device (cxlrd_dev); +return rc; }EXPORT_SYMBOL_NS_GPL (cxl_add_to_region,"CXL" );
drivers/cxl/cxl.h +1 -0
@@ -740,6 +740,7 @@ struct cxl_root *find_cxl_root(struct cxl_port *port); DEFINE_FREE(put_cxl_root, struct cxl_root *, if (_T) put_device(&_T->port.dev)) DEFINE_FREE(put_cxl_port, struct cxl_port *, if (!IS_ERR_OR_NULL(_T)) put_device(&_T->dev)) +DEFINE_FREE(put_cxl_root_decoder, struct cxl_root_decoder *, if (!IS_ERR_OR_NULL(_T)) put_device(&_T->cxlsd.cxld.dev))int devm_cxl_enumerate_ports (struct cxl_memdev *cxlmd);void cxl_bus_rescan (void );
Signature · 1 line
2.39.5
Re: [PATCH v6 09/14] cxl/region: Factor out code to find the root decoder
Quoted 8 lines · Robert Richter
In function
cxl_add_to_region()there is code to determine the root decoder associated to an endpoint decoder. Factor out that code for later reuse. This has the benefit of reducing cxl_add_to_region()'s function complexity.The reference count must be decremented after using the root decoder.
cxl_find_root_decoder()is paired with theput_cxl_root_decodercleanup helper that can be used for this.
[..]
Quoted 5 lines
drivers/cxl/core/region.c +0
-0
[..]
drivers/cxl/core/region.c static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd, · line 3410
Quoted 8 lines
drivers/cxl/core/region.c +1
-3@@ -3384,29 +3407,17 @@ static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd,int cxl_add_to_region (struct cxl_endpoint_decoder *cxled) { -struct cxl_memdev *cxlmd =cxled_to_memdev (cxled); -struct cxl_port *port =cxled_to_port (cxled); - struct cxl_root *cxl_root __free(put_cxl_root) = find_cxl_root(port); + struct cxl_root_decoder *cxlrd __free(put_cxl_root_decoder) = NULL;
Please avoid the "obj __free(...) = NULL" pattern. Per the documentation in include/linux/cleanup.h.
Quoted 8 lines
drivers/cxl/core/region.c +1
-3struct range *hpa = &cxled->cxld.hpa_range; -struct cxl_decoder *cxld = &cxled->cxld; -struct device *cxlrd_dev, *region_dev; -struct cxl_root_decoder *cxlrd; +struct device *region_dev;struct cxl_region_params *p;struct cxl_region *cxlr;bool attach = false;
drivers/cxl/core/region.c static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd, · line 3418
Quoted 10 lines
drivers/cxl/core/region.c +1
-7int rc; - cxlrd_dev =device_find_child (&cxl_root->port.dev, &cxld->hpa_range, - match_root_decoder_by_range); -if (!cxlrd_dev) { -dev_err (cxlmd->dev.parent, -"%s:%s no CXL window for range %#llx:%#llx\n" , -dev_name (&cxlmd->dev),dev_name (&cxld->dev), - cxld->hpa_range.start, cxld->hpa_range.end); + cxlrd =cxl_find_root_decoder (cxled);
...i.e. always instantiate and asssign a scope-based cleanup variable in one statement.
cxlrd __free(put_cxl_root_decoder) = cxl_find_root_decoder(cxled);
Otherwise, this looks good.
PATCH v6 10/14 cxl/region: Factor out code to find a root decoder's region
In reply to Robert RichterIn function cxl_add_to_region() there is code to determine a root decoder's region. Factor that code out. This is in preparation to further rework and simplify function cxl_add_to_region().
The reference count must be decremented after using the region. cxl_find_region_by_range() is paired with the put_cxl_region cleanup helper that can be used for this.
--- drivers/cxl/core/region.c | 26 ++++++++++++++++---------- drivers/cxl/cxl.h | 1 + 2 files changed, 17 insertions(+), 10 deletions(-)
drivers/cxl/core/region.c +16 -10
@@ -3405,13 +3405,25 @@ static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd,return cxlr; } +static struct cxl_region * +cxl_find_region_by_range (struct cxl_root_decoder *cxlrd,struct range *hpa) +{ +struct device *region_dev; + + region_dev =device_find_child (&cxlrd->cxlsd.cxld.dev, hpa, + match_region_by_range); +if (!region_dev) +return NULL ; + +return to_cxl_region (region_dev); +} +int cxl_add_to_region (struct cxl_endpoint_decoder *cxled) { struct cxl_root_decoder *cxlrd __free(put_cxl_root_decoder) = NULL; + struct cxl_region *cxlr __free(put_cxl_region) = NULL;struct range *hpa = &cxled->cxld.hpa_range; -struct device *region_dev;struct cxl_region_params *p; -struct cxl_region *cxlr;bool attach = false;int rc;
@@ -3424,13 +3436,9 @@ int cxl_add_to_region(struct cxl_endpoint_decoder *cxled)* one does the construction and the others add to that. */ mutex_lock (&cxlrd->range_lock); - region_dev =device_find_child (&cxlrd->cxlsd.cxld.dev, hpa, - match_region_by_range); -if (!region_dev) { + cxlr =cxl_find_region_by_range (cxlrd, hpa); +if (!cxlr) cxlr =construct_region (cxlrd, cxled); - region_dev = &cxlr->dev; - }else - cxlr =to_cxl_region (region_dev);mutex_unlock (&cxlrd->range_lock); rc =PTR_ERR_OR_ZERO (cxlr);
@@ -3455,8 +3463,6 @@ int cxl_add_to_region(struct cxl_endpoint_decoder *cxled) p->res); } -put_device (region_dev); -return rc; }EXPORT_SYMBOL_NS_GPL (cxl_add_to_region,"CXL" );
drivers/cxl/cxl.h +1 -0
@@ -741,6 +741,7 @@ struct cxl_root *find_cxl_root(struct cxl_port *port); DEFINE_FREE(put_cxl_root, struct cxl_root *, if (_T) put_device(&_T->port.dev)) DEFINE_FREE(put_cxl_port, struct cxl_port *, if (!IS_ERR_OR_NULL(_T)) put_device(&_T->dev)) DEFINE_FREE(put_cxl_root_decoder, struct cxl_root_decoder *, if (!IS_ERR_OR_NULL(_T)) put_device(&_T->cxlsd.cxld.dev)) +DEFINE_FREE(put_cxl_region, struct cxl_region *, if (!IS_ERR_OR_NULL(_T)) put_device(&_T->dev))int devm_cxl_enumerate_ports (struct cxl_memdev *cxlmd);void cxl_bus_rescan (void );
Signature · 1 line
2.39.5
Re: [PATCH v6 10/14] cxl/region: Factor out code to find a root decoder's region
Quoted 36 lines · Robert Richter
In function
cxl_add_to_region()there is code to determine a root decoder's region. Factor that code out. This is in preparation to further rework and simplify functioncxl_add_to_region().The reference count must be decremented after using the region.
cxl_find_region_by_range()is paired with theput_cxl_regioncleanup helper that can be used for this.Signed-off-by Robert Richter <[email protected]>Reviewed-by Gregory Price <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Dave Jiang <[email protected]>Reviewed-by Dan Williams <[email protected]>Reviewed-by Alison Schofield <[email protected]>Reviewed-by Fabio M. De Francesco <[email protected]>Tested-by Gregory Price <[email protected]>--- drivers/cxl/core/region.c | 26 ++++++++++++++++---------- drivers/cxl/cxl.h | 1 + 2 files changed, 17 insertions(+), 10 deletions(-)drivers/cxl/core/region.c +7
-0@@ -3405,13 +3405,25 @@ static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd,return cxlr; } +static struct cxl_region * +cxl_find_region_by_range (struct cxl_root_decoder *cxlrd,struct range *hpa) +{ +struct device *region_dev; + + region_dev =device_find_child (&cxlrd->cxlsd.cxld.dev, hpa, + match_region_by_range);
drivers/cxl/core/region.c static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd, · line 3424
Quoted 10 lines
drivers/cxl/core/region.c +7
-0+if (!region_dev) +return NULL ; + +return to_cxl_region (region_dev); +} +int cxl_add_to_region (struct cxl_endpoint_decoder *cxled) { struct cxl_root_decoder *cxlrd __free(put_cxl_root_decoder) = NULL; + struct cxl_region *cxlr __free(put_cxl_region) = NULL;
Another instance of the "obj __free(...) = NULL" anti-pattern to clean up. The reason it is an anti-pattern is because it risks mixing up the assignment order with the declaration order leading to subtle bugs.
Scope-based cleanup should always be exempted from "x-mas" tree declaration cosmetics.
PATCH v6 11/14 cxl/region: Add function to find a port's switch decoder by range
In reply to Robert RichterFactor out code to find the switch decoder of a port for a specific address range. Reuse the code to search a root decoder, create the function cxl_port_find_switch_decoder() and rework match_root_decoder_by_range() to be usable for switch decoders too.
--- drivers/cxl/core/region.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-)
drivers/cxl/core/region.c +18 -12
@@ -3202,33 +3202,39 @@ static int devm_cxl_add_dax_region(struct cxl_region *cxlr)return rc; } -static int match_root_decoder_by_range (struct device *dev, -const void *data) +static int match_decoder_by_range (struct device *dev,const void *data) {const struct range *r1, *r2 = data; -struct cxl_root_decoder *cxlrd; +struct cxl_decoder *cxld; -if (!is_root_decoder (dev)) +if (!is_switch_decoder (dev))return 0 ; - cxlrd =to_cxl_root_decoder (dev); - r1 = &cxlrd->cxlsd.cxld.hpa_range; + cxld =to_cxl_decoder (dev); + r1 = &cxld->hpa_range;return range_contains (r1, r2); } +static struct cxl_decoder * +cxl_port_find_switch_decoder (struct cxl_port *port,struct range *hpa) +{ +struct device *cxld_dev =device_find_child (&port->dev, hpa, + match_decoder_by_range); + +return cxld_dev ?to_cxl_decoder (cxld_dev) :NULL ; +} +static struct cxl_root_decoder *cxl_find_root_decoder (struct cxl_endpoint_decoder *cxled) {struct cxl_memdev *cxlmd =cxled_to_memdev (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 *cxld = &cxled->cxld; +struct cxl_decoder *root, *cxld = &cxled->cxld;struct range *hpa = &cxld->hpa_range; -struct device *cxlrd_dev; - cxlrd_dev =device_find_child (&cxl_root->port.dev, hpa, - match_root_decoder_by_range); -if (!cxlrd_dev) { + root =cxl_port_find_switch_decoder (&cxl_root->port, hpa); +if (!root) { dev_err(cxlmd->dev.parent, "%s:%s no CXL window for range %#llx:%#llx\n", dev_name(&cxlmd->dev), dev_name(&cxld->dev),
@@ -3236,7 +3242,7 @@ cxl_find_root_decoder(struct cxl_endpoint_decoder *cxled)return NULL ; } -return to_cxl_root_decoder (cxlrd_dev); +return to_cxl_root_decoder (&root->dev); }static int match_region_by_range (struct device *dev,const void *data)
Signature · 1 line
2.39.5
PATCH v6 12/14 cxl/region: Add a dev_warn() on registration failure
In reply to Robert RichterEsp. in complex system configurations with multiple endpoints and interleaving setups it is hard to detect region setup failures as its registration may silently fail. Add messages to show registration failures.
Example log message:
cxl region5: region sort successful
cxl region5: mem0:endpoint5 decoder5.0 add: mem0:decoder5.0 @ 0 next: none nr_eps: 1 nr_targets: 1 cxl_port endpoint5: decoder5.0: range: 0x22350000000-0x2634fffffff iw: 1 ig: 256 cxl region5: pci0000:e0:port1 decoder1.2 add: mem0:decoder5.0 @ 0 next: mem0 nr_eps: 1 nr_targets: 1 cxl region5: pci0000:e0:port1 iw: 1 ig: 256
cxl region5: pci0000:e0:port1: decoder1.2 expected 0000:e0:01.2 at 0
cxl endpoint5: failed to attach decoder5.0 to region5: -6
cxl_port endpoint5: probe: 0
--- drivers/cxl/core/region.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/cxl/core/region.c +6 -0
@@ -2166,6 +2166,12 @@ static int attach_target(struct cxl_region *cxlr, rc =cxl_region_attach (cxlr, cxled, pos);up_read (&cxl_dpa_rwsem);up_write (&cxl_region_rwsem); + +if (rc) +dev_warn (cxled->cxld.dev.parent, +"failed to attach %s to %s: %d\n" , +dev_name (&cxled->cxld.dev),dev_name (&cxlr->dev), rc); +return rc; }
Signature · 1 line
2.39.5
PATCH v6 13/14 cxl/region: Add a dev_err() on missing target list entries
In reply to Robert RichterBroken target lists are hard to discover as the driver fails at a later initialization stage. Add an error message for this.
Example log messages:
cxl_mem mem1: failed to find endpoint6:0000:e0:01.3 in target list of decoder1.1 cxl_port endpoint6: failed to register decoder6.0: -6
cxl_port endpoint6: probe: 0
--- drivers/cxl/core/region.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/cxl/core/region.c +7 -0
@@ -1809,6 +1809,13 @@ static int find_pos_and_ways(struct cxl_port *port, struct range *range, }put_device (dev); +if (rc) +dev_err (port->uport_dev, +"failed to find %s:%s in target list of %s\n" , +dev_name (&port->dev), +dev_name (port->parent_dport->dport_dev), +dev_name (&cxlsd->cxld.dev)); +return rc; }
Signature · 1 line
2.39.5
PATCH v6 14/14 cxl: Add a dev_dbg() when a decoder was added to a port
In reply to Robert RichterImprove debugging by adding and unifying messages whenever a decoder was added to a port. It is especially useful to get the decoder mapping of the involved CXL host bridge or PCI device. This avoids a complex lookup of the decoder/port/device mappings in sysfs.
Example log messages:
cxl_acpi ACPI0017:00: decoder0.0 added to root0
cxl_acpi ACPI0017:00: decoder0.1 added to root0
...
pci0000:e0: decoder1.0 added to port1
pci0000:e0: decoder1.1 added to port1
...
cxl_mem mem0: decoder5.0 added to endpoint5
cxl_mem mem0: decoder5.1 added to endpoint5
--- drivers/cxl/acpi.c | 10 +++++++++- drivers/cxl/core/hdm.c | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-)
drivers/cxl/acpi.c +9 -1
@@ -419,7 +419,15 @@ static int __cxl_parse_cfmws(struct acpi_cedt_cfmws *cfmws, rc =cxl_decoder_add (cxld, target_map);if (rc)return rc; -return cxl_root_decoder_autoremove (dev,no_free_ptr (cxlrd)); + + rc =cxl_root_decoder_autoremove (dev,no_free_ptr (cxlrd)); +if (rc) +return rc; + +dev_dbg (root_port->dev.parent,"%s added to %s\n" , +dev_name (&cxld->dev),dev_name (&root_port->dev)); + +return 0 ; } static int cxl_parse_cfmws(union acpi_subtable_headers *header, void *arg,
drivers/cxl/core/hdm.c +2 -1
@@ -34,7 +34,8 @@ static int add_hdm_decoder(struct cxl_port *port, struct cxl_decoder *cxld,if (rc)return rc; -dev_dbg (&cxld->dev,"Added to port %s\n" ,dev_name (&port->dev)); +dev_dbg (port->uport_dev,"%s added to %s\n" , +dev_name (&cxld->dev),dev_name (&port->dev));return 0 ; }
Signature · 1 line
2.39.5
Quoted 103 lines · Robert Richter
This series is the first part of adding support for CXL address translation. It contains cleanup and code refactoring in preparation of the actual implementation that will be sent in part 2. Cleanup and code refactoring have been split in a separate series to reduce the number of patches of the series. Even without address translation on top this rework improves esp. the region code, cleans it up, simplifies it and adds debugging messages to better analyze region creation failures:
Content of patches:
* Patches 1: Remove else after return.
* Patches 2-3: Cleanups and comments around
cxl_hdm_decode_init().* Patches 4-6: Adding and modifying helper functions.
* Patches 7-11: Refactoring of endpoint decoder setup and cxl_find*() including cleanup helpers.
* Patches 12-14: Adding and modifying debug messages.
v6:
* added tags to SOB chain,
* added more occurences to remove-else-after-return (Alison),
* updated description ofcxl_port_pick_region_decoder()(Fabio),v5:
* added tags to SOB chain,
* made comment a oneliner incxl_hdm_decode_init()(Jonathan),
* updated patch description introducingparent_port_of()(Fabio),
* removedEXPORT_SYMBOL_NS_GPL()of functionparent_port_of()(Dan),
* renamed functions tocxl_port_pick_region_decoder()andcxl_rr_assign_decoder(), updated descriptions (Dan),
* added patch to replaceput_cxl_root()by a cleanup helper,
* using__free()for reference counting of cxl_find_*() functions, added cleanup helpers (Dan),
* dropped patch adding CFMWS memory log messages (Dan),v4:
* rebased onto cxl/next, commit0a14566be090("cxl/Documentation:
Remove 'mixed' from sysfs mode doc"),
* added tags to SOB chain,
* reworked comments incxl_hdm_decode_init()(dropped moving comment and updated patch that modifies comments) (Jonathan),
* reworded patch description that removes duplicate call ofcxl_find_decoder_early()(Jonathan),
* moved some patches out of this rework and cleanup series (Dave, Jonathan),v3:
* added tags to SOB chain,
* fixed NULL pointer dereference incxl_find_root_decoder()(Alison),
* updated subject line of patches that add kernel messages and included example log messages (Alison),v2:
* rebased onto cxl/next,
* added tags to SOB chain,
* move patches with cleanups and refactoring into this separate series (Dave),
* added patch "cxl/acpi: Unify CFMWS memory log messages with SRAT messages" to improve CFMWS log messages,
* renamed endpoint decoder functions to cxl_endpoint_decoder_*() (Li),
* reworded patch description that movesfind_cxl_root()and reworkscxl_find_root_decoder()(Terry),
* small changes to cxl_find_root_decoder()/cxl_endpoint_decoder_initialize()(Jonanthan),
* updated comment incxl_port_find_switch_decoder()(Ben),
*cxl_endpoint_decoder_initialize(): Simplify variable declaration (Jonathan, Ben),
*cxl_find_decoder_early(): Added comment on function usage (Gregory),
* reordered patches and reworded some of the subject for a better structure.Robert Richter (14):
cxl: Remove else after return
cxl/pci: Moving code incxl_hdm_decode_init()
cxl/pci: Add comments tocxl_hdm_decode_init()
cxl: Introduceparent_port_of()helper
cxl/region: Rename function tocxl_port_pick_region_decoder()cxl/region: Avoid duplicate call ofcxl_port_pick_region_decoder()cxl/region: Movefind_cxl_root()tocxl_add_to_region()cxl/port: Replaceput_cxl_root()by a cleanup helper cxl/region: Factor out code to find the root decoder cxl/region: Factor out code to find a root decoder's region cxl/region: Add function to find a port's switch decoder by range cxl/region: Add adev_warn()on registration failure cxl/region: Add adev_err()on missing target list entries
cxl: Add adev_dbg()when a decoder was added to a portdrivers/cxl/acpi.c | 10 ++- drivers/cxl/core/cdat.c | 2 +- drivers/cxl/core/hdm.c | 3 +- drivers/cxl/core/memdev.c | 4 +- drivers/cxl/core/pci.c | 48 +++++++---- drivers/cxl/core/port.c | 23 ++--- drivers/cxl/core/region.c | 177 +++++++++++++++++++++++--------------- drivers/cxl/cxl.h | 13 +-- drivers/cxl/port.c | 15 +--- 9 files changed, 173 insertions(+), 122 deletions(-)
Quoted 1 line
base-commit:
8e62ba590160f91abba6490d9c17aa13bada4752
Applied to cxl/next. Thanks Robert!
Dave Jiang
maintainerQuoted 106 lines · Dave Jiang
Quoted 103 lines · Robert Richter
This series is the first part of adding support for CXL address translation. It contains cleanup and code refactoring in preparation of the actual implementation that will be sent in part 2. Cleanup and code refactoring have been split in a separate series to reduce the number of patches of the series. Even without address translation on top this rework improves esp. the region code, cleans it up, simplifies it and adds debugging messages to better analyze region creation failures:
Content of patches:
* Patches 1: Remove else after return.
* Patches 2-3: Cleanups and comments around
cxl_hdm_decode_init().* Patches 4-6: Adding and modifying helper functions.
* Patches 7-11: Refactoring of endpoint decoder setup and cxl_find*() including cleanup helpers.
* Patches 12-14: Adding and modifying debug messages.
v6:
* added tags to SOB chain,
* added more occurences to remove-else-after-return (Alison),
* updated description ofcxl_port_pick_region_decoder()(Fabio),v5:
* added tags to SOB chain,
* made comment a oneliner incxl_hdm_decode_init()(Jonathan),
* updated patch description introducingparent_port_of()(Fabio),
* removedEXPORT_SYMBOL_NS_GPL()of functionparent_port_of()(Dan),
* renamed functions tocxl_port_pick_region_decoder()andcxl_rr_assign_decoder(), updated descriptions (Dan),
* added patch to replaceput_cxl_root()by a cleanup helper,
* using__free()for reference counting of cxl_find_*() functions, added cleanup helpers (Dan),
* dropped patch adding CFMWS memory log messages (Dan),v4:
* rebased onto cxl/next, commit0a14566be090("cxl/Documentation:
Remove 'mixed' from sysfs mode doc"),
* added tags to SOB chain,
* reworked comments incxl_hdm_decode_init()(dropped moving comment and updated patch that modifies comments) (Jonathan),
* reworded patch description that removes duplicate call ofcxl_find_decoder_early()(Jonathan),
* moved some patches out of this rework and cleanup series (Dave, Jonathan),v3:
* added tags to SOB chain,
* fixed NULL pointer dereference incxl_find_root_decoder()(Alison),
* updated subject line of patches that add kernel messages and included example log messages (Alison),v2:
* rebased onto cxl/next,
* added tags to SOB chain,
* move patches with cleanups and refactoring into this separate series (Dave),
* added patch "cxl/acpi: Unify CFMWS memory log messages with SRAT messages" to improve CFMWS log messages,
* renamed endpoint decoder functions to cxl_endpoint_decoder_*() (Li),
* reworded patch description that movesfind_cxl_root()and reworkscxl_find_root_decoder()(Terry),
* small changes to cxl_find_root_decoder()/cxl_endpoint_decoder_initialize()(Jonanthan),
* updated comment incxl_port_find_switch_decoder()(Ben),
*cxl_endpoint_decoder_initialize(): Simplify variable declaration (Jonathan, Ben),
*cxl_find_decoder_early(): Added comment on function usage (Gregory),
* reordered patches and reworded some of the subject for a better structure.Robert Richter (14):
cxl: Remove else after return
cxl/pci: Moving code incxl_hdm_decode_init()
cxl/pci: Add comments tocxl_hdm_decode_init()
cxl: Introduceparent_port_of()helper
cxl/region: Rename function tocxl_port_pick_region_decoder()cxl/region: Avoid duplicate call ofcxl_port_pick_region_decoder()cxl/region: Movefind_cxl_root()tocxl_add_to_region()cxl/port: Replaceput_cxl_root()by a cleanup helper cxl/region: Factor out code to find the root decoder cxl/region: Factor out code to find a root decoder's region cxl/region: Add function to find a port's switch decoder by range cxl/region: Add adev_warn()on registration failure cxl/region: Add adev_err()on missing target list entries
cxl: Add adev_dbg()when a decoder was added to a portdrivers/cxl/acpi.c | 10 ++- drivers/cxl/core/cdat.c | 2 +- drivers/cxl/core/hdm.c | 3 +- drivers/cxl/core/memdev.c | 4 +- drivers/cxl/core/pci.c | 48 +++++++---- drivers/cxl/core/port.c | 23 ++--- drivers/cxl/core/region.c | 177 +++++++++++++++++++++++--------------- drivers/cxl/cxl.h | 13 +-- drivers/cxl/port.c | 15 +--- 9 files changed, 173 insertions(+), 122 deletions(-)
Quoted 5 lines
Quoted 1 line
base-commit:
8e62ba590160f91abba6490d9c17aa13bada4752Applied to cxl/next. Thanks Robert!
Robert,
I applied Dan's requested changes and also picked up his ACK's. Please check cxl/next to make sure everything looks good to you. Thanks!
Quoted 9 lines · Dave Jiang
Quoted 3 lines · Dave Jiang
Applied to cxl/next. Thanks Robert!
Robert,
I applied Dan's requested changes and also picked up his ACK's. Please check cxl/next to make sure everything looks good to you. Thanks!
Thank you all for your reviews.
-Robert
Quoted 9 lines · Robert Richter
This series is the first part of adding support for CXL address translation. It contains cleanup and code refactoring in preparation of the actual implementation that will be sent in part 2. Cleanup and code refactoring have been split in a separate series to reduce the number of patches of the series. Even without address translation on top this rework improves esp. the region code, cleans it up, simplifies it and adds debugging messages to better analyze region creation failures:
[..]
Quoted 5 lines
v6:
* added tags to SOB chain,
* added more occurences to remove-else-after-return (Alison),
* updated description ofcxl_port_pick_region_decoder()(Fabio),
[..]
Aside from the "obj __free(...) = NULL" anti-pattern to clean up, for the series, you can add: