cxl: access_coordinate validity fixes for 6.9
Dave Jiang
maintainerv5 cover cxl: access_coordinate validity fixes for 6.9
v5:
- Rebased against v6.9-rc1 and adjusted to multi access levels from the HMEM_REPORTING support code added in the v6.9 merge window.
Hi Jonathan and Davidlohr,
Please take a look at 2/4 again and also review 3/4 which is new. The introduction of the 2 access level for 'struct access_coordinate' caused a bit of adjustment to the code. To keep flow of looping through the dports without additional existance check, I made the setting of both access class coordinates from the beginning of the calculation.
[1/4] cxl: Remove checking of iter in cxl_endpoint_get_perf_coordinates() [2/4] cxl: Consolidate dport access_coordinate ->hb_coord and ->sw_coord into ->coord [3/4] cxl: Fix incorrect region perf data calculation
[4/4] cxl: Add checks to access_coordinate calculation to fail missing data
Dave Jiang
maintainerPATCH v5 1/4 cxl: Remove checking of iter in cxl_endpoint_get_perf_coordinates()
The while() loop in cxl_endpoint_get_perf_coordinates() checks to see if 'iter' is valid as part of the condition breaking out of the loop. However, iter is being used before the check at the end of the while loop before the next iteration starts. Given that the loop doesn't expect the iter to be NULL because it stops before the root port, remove the iter check.
The presence of the iter or removing the iter does not impact the behavior of the code. This is a code clean up and not a bug fix.
--- drivers/cxl/core/port.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cxl/core/port.c +1 -1
@@ -2197,7 +2197,7 @@ int cxl_endpoint_get_perf_coordinates(struct cxl_port *port,* port each iteration. If the parent is cxl root then there is * nothing to gather. */ -while (iter && !is_cxl_root (to_cxl_port (iter->dev.parent))) { +while (!is_cxl_root (to_cxl_port (iter->dev.parent))) {cxl_coordinates_combine (&c, &c, &dport->sw_coord); c.write_latency += dport->link_latency; c.read_latency += dport->link_latency;
Signature · 1 line
2.44.0
RE: [PATCH v5 1/4] cxl: Remove checking of iter in cxl_endpoint_get_perf_coordinates()
Quoted 5 lines · Dave Jiang
The
while()loop incxl_endpoint_get_perf_coordinates()checks to see if 'iter' is valid as part of the condition breaking out of the loop. However, iter is being used before the check at the end of the while loop before the next iteration starts. Given that the loop doesn't expect the iter to be NULL because it stops before the root port, remove the iter check.
This description can get much smaller by realizing that is_cxl_root() will always stop the loop before the next iteration could go NULL. I.e.
Quoted 6 lines
The presence of the iter or removing the iter does not impact the behavior of the code. This is a code clean up and not a bug fix.
Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Davidlohr Bueso <[email protected]>
Even though the changelog is not as concise as it could be, you can add:
Dave Jiang
maintainerPATCH v5 2/4 cxl: Consolidate dport access_coordinate ->hb_coord and ->sw_coord into ->coord
In reply to Dave JiangThe driver stores access_coordinate for host bridge in ->hb_coord and switch CDAT access_coordinate in ->sw_coord. Since neither of these access_coordinate clobber each other, the variable name can be consolidated into ->coord to simplify the code. This change also simplifies the iteration loop in cxl_endpoint_get_perf_coordinates() and allow all the access_coordinate to be picked up in the loop.
---
v5:
- Rebased against v6.9-rc1
With 2 access classes, switch coords will use first element has holder
--- drivers/cxl/acpi.c | 6 +-- drivers/cxl/core/cdat.c | 99 +++++++++++++++++++---------------------- drivers/cxl/core/port.c | 67 +++++++++++++--------------- drivers/cxl/cxl.h | 6 +-- drivers/cxl/cxlmem.h | 2 +- 5 files changed, 81 insertions(+), 99 deletions(-)
drivers/cxl/acpi.c +3 -3
@@ -530,14 +530,14 @@ static int get_genport_coordinates(struct device *dev, struct cxl_dport *dport)if (kstrtou32 (acpi_device_uid (hb),0 , &uid))return -EINVAL ; - rc =acpi_get_genport_coordinates (uid, dport->hb_coord); + rc =acpi_get_genport_coordinates (uid, dport->coord);if (rc <0 )return rc;/* Adjust back to picoseconds from nanoseconds */ for (int i =0 ; i <ACCESS_COORDINATE_MAX ; i++) { - dport->hb_coord[i].read_latency *=1000 ; - dport->hb_coord[i].write_latency *=1000 ; + dport->coord[i].read_latency *=1000 ; + dport->coord[i].write_latency *=1000 ; }return 0 ;
drivers/cxl/core/cdat.c +45 -54
203 lines not on this page · raw message
drivers/cxl/core/port.c +30 -37
96 lines not on this page · raw message
drivers/cxl/cxl.h +2 -4
@@ -663,8 +663,7 @@ struct cxl_rcrb_info {* @rch: Indicate whether this dport was enumerated in RCH or VH mode * @port: reference to cxl_port that contains this downstream port * @regs: Dport parsed register blocks -* @sw_coord: access coordinates (performance) for switch from CDAT -* @hb_coord: access coordinates (performance) from ACPI generic port (host bridge) +* @coord: access coordinates (bandwidth and latency performance attributes) * @link_latency: calculated PCIe downstream latency */ struct cxl_dport {
@@ -675,8 +674,7 @@ struct cxl_dport {bool rch;struct cxl_port *port;struct cxl_regs regs; -struct access_coordinate sw_coord; -struct access_coordinate hb_coord[ACCESS_COORDINATE_MAX ]; +struct access_coordinate coord[ACCESS_COORDINATE_MAX ];long link_latency; };
drivers/cxl/cxlmem.h +1 -1
@@ -401,7 +401,7 @@ enum cxl_devtype {*/ struct cxl_dpa_perf {struct range dpa_range; -struct access_coordinate coord; +struct access_coordinate coord[ACCESS_COORDINATE_MAX ];int qos_class; };
Signature · 1 line
2.44.0
RE: [PATCH v5 2/4] cxl: Consolidate dport access_coordinate ->hb_coord and ->sw_coord into ->coord
Quoted 9 lines · Dave Jiang
The driver stores
access_coordinatefor host bridge in ->hb_coord and switch CDATaccess_coordinatein ->sw_coord. Since neither of theseaccess_coordinateclobber each other, the variable name can be consolidated into ->coord to simplify the code. This change also simplifies the iteration loop incxl_endpoint_get_perf_coordinates()and allow all theaccess_coordinateto be picked up in the loop.Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Davidlohr Bueso <[email protected]>
Looks good,
Dave Jiang
maintainerPATCH v5 3/4 cxl: Fix incorrect region perf data calculation
In reply to Dave JiangCurrent math in cxl_region_perf_data_calculate divides the latency by 1000 every time the function gets called. This causes the region latency to be divided by 1000 per memory device and the math is incorrect. This is user visible as the latency access_coordinate exposed via sysfs will show incorrect latency data.
Move the latency adjustment to where dpa_perf is set and this should provide the appropriate latency for the region for each endpoint.
--- drivers/cxl/core/cdat.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)
drivers/cxl/core/cdat.c +12 -11
@@ -214,8 +214,19 @@ static int cxl_port_perf_data_calculate(struct cxl_port *port,static void update_perf_entry (struct device *dev,struct dsmas_entry *dent,struct cxl_dpa_perf *dpa_perf) { -for (int i =0 ; i <ACCESS_COORDINATE_MAX ; i++) +for (int i =0 ; i <ACCESS_COORDINATE_MAX ; i++) { dpa_perf->coord[i] = dent->coord[i]; +/* +* Convert latency to nanosec from picosec to be consistent +* with the resulting latency coordinates computed by the +* HMAT_REPORTING code. +*/ + dpa_perf->coord[i].read_latency = +DIV_ROUND_UP (dpa_perf->coord[i].read_latency,1000 ); + dpa_perf->coord[i].write_latency = +DIV_ROUND_UP (dpa_perf->coord[i].write_latency,1000 ); + } + dpa_perf->dpa_range = dent->dpa_range; dpa_perf->qos_class = dent->qos_class; dev_dbg(dev,
@@ -559,16 +570,6 @@ void cxl_region_perf_data_calculate(struct cxl_region *cxlr, perf->coord[i].write_latency); cxlr->coord[i].read_bandwidth += perf->coord[i].read_bandwidth; cxlr->coord[i].write_bandwidth += perf->coord[i].write_bandwidth; - -/* -* Convert latency to nanosec from picosec to be consistent -* with the resulting latency coordinates computed by the -* HMAT_REPORTING code. -*/ - cxlr->coord[i].read_latency = -DIV_ROUND_UP (cxlr->coord[i].read_latency,1000 ); - cxlr->coord[i].write_latency = -DIV_ROUND_UP (cxlr->coord[i].write_latency,1000 ); } }
Signature · 1 line
2.44.0
Re: [PATCH v5 3/4] cxl: Fix incorrect region perf data calculation
Quoted 25 lines · Dave Jiang
Current math in
cxl_region_perf_data_calculatedivides the latency by 1000 every time the function gets called. This causes the region latency to be divided by 1000 per memory device and the math is incorrect. This is user visible as the latencyaccess_coordinateexposed via sysfs will show incorrect latency data.Move the latency adjustment to where
dpa_perfis set and this should provide the appropriate latency for the region for each endpoint.Fixes 3d9f4a197230 ("cxl/region: Calculate performance data for a region")Signed-off-by Dave Jiang <[email protected]>--- drivers/cxl/core/cdat.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)drivers/cxl/core/cdat.c +1
-1@@ -214,8 +214,19 @@ static int cxl_port_perf_data_calculate(struct cxl_port *port,static void update_perf_entry (struct device *dev,struct dsmas_entry *dent,struct cxl_dpa_perf *dpa_perf) { -for (int i =0 ; i <ACCESS_COORDINATE_MAX ; i++) +for (int i =0 ; i <ACCESS_COORDINATE_MAX ; i++) {
drivers/cxl/core/cdat.c static int cxl_port_perf_data_calculate(struct cxl_port *port, · line 227
Quoted 10 lines
drivers/cxl/core/cdat.c +9
-0dpa_perf->coord[i] = dent->coord[i]; +/* +* Convert latency to nanosec from picosec to be consistent +* with the resulting latency coordinates computed by the +* HMAT_REPORTING code. +*/ + dpa_perf->coord[i].read_latency = +DIV_ROUND_UP (dpa_perf->coord[i].read_latency,1000 ); + dpa_perf->coord[i].write_latency = +DIV_ROUND_UP (dpa_perf->coord[i].write_latency,1000 );
It feels like a latent bug that dpa_perf is temporarily counted in picoseconds. I.e. every place that assigns into a 'struct access_coordinate' should do so in nanoseconds. I see how this change fixes the "over-division" problem, but dpa_perf->coord should never have storted picosecond values in the first instance.
Something like the following, to match / reuse hmat_normalize() (untested!):
drivers/cxl/acpi.c +1 -11
@@ -530,17 +530,7 @@ static int get_genport_coordinates(struct device *dev, struct cxl_dport *dport)if (kstrtou32 (acpi_device_uid (hb),0 , &uid))return -EINVAL ; - rc =acpi_get_genport_coordinates (uid, dport->hb_coord); -if (rc <0 ) -return rc; - -/* Adjust back to picoseconds from nanoseconds */ -for (int i =0 ; i <ACCESS_COORDINATE_MAX ; i++) { - dport->hb_coord[i].read_latency *=1000 ; - dport->hb_coord[i].write_latency *=1000 ; - } - -return 0 ; +return acpi_get_genport_coordinates (uid, dport->hb_coord); }static int add_host_bridge_dport (struct device *match,void *arg)
drivers/cxl/core/cdat.c +2 -4
@@ -124,10 +124,8 @@ static int cdat_dslbis_handler(union acpi_subtable_headers *header, void *arg, le_base = (__force __le64 )dslbis->entry_base_unit; le_val = (__force __le16 )dslbis->entry[0 ]; - rc =check_mul_overflow (le64_to_cpu (le_base), -le16_to_cpu (le_val), &val); -if (rc) -pr_warn ("DSLBIS value overflowed.\n" ); + val =hmat_normalize (le16_to_cpu (le_val),le64_to_cpu (le_base), + dslbis->data_type);cxl_access_coordinate_set (&dent->coord, dslbis->data_type, val);
Dave Jiang
maintainerPATCH v5 4/4 cxl: Add checks to access_coordinate calculation to fail missing data
In reply to Dave JiangJonathan noted that when the coordinates for host bridge and switches can be 0s if no actual data are retrieved and the calculation continues. The resulting number would be inaccurate. Add checks to ensure that the calculation would complete only if the numbers are valid.
While not seen in the wild, issue may show up with a BIOS that reported CXL root ports via Generic Ports (via a PCI handle in the SRAT entry).
---
v5:
- Adjust for multiple access classes.
--- drivers/cxl/core/port.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-)
drivers/cxl/core/port.c +27 -11
@@ -2141,6 +2141,18 @@ static void add_latency(struct access_coordinate *c, long latency) } } +static bool coordinates_valid (struct access_coordinate *c) +{ +for (int i =0 ; i <ACCESS_COORDINATE_MAX ; i++) { +if (c[i].read_bandwidth && c[i].write_bandwidth && + c[i].read_latency && c[i].write_latency) +continue ; +return false; + } + +return true; +} +static void set_min_bandwidth (struct access_coordinate *c,unsigned int bw) {for (int i =0 ; i <ACCESS_COORDINATE_MAX ; i++) {
@@ -2156,6 +2168,11 @@ static void set_access_coordinates(struct access_coordinate *out, out[i] = in[i]; } +static bool parent_port_is_cxl_root (struct cxl_port *port) +{ +return is_cxl_root (to_cxl_port (port->dev.parent)); +} +/** * cxl_endpoint_get_perf_coordinates - Retrieve performance numbers stored in dports * of CXL path
@@ -2185,21 +2202,20 @@ int cxl_endpoint_get_perf_coordinates(struct cxl_port *port,if (!is_cxl_endpoint (port))return -EINVAL ; - dport = iter->parent_dport; -/* -* Exit the loop when the parent port of the current port is cxl root. -* The iterative loop starts at the endpoint and gathers the -* latency of the CXL link from the current iter to the next downstream -* port each iteration. If the parent is cxl root then there is -* nothing to gather. +* Exit the loop when the parent port of the current iter port is cxl +* root. The iterative loop starts at the endpoint and gathers the +* latency of the CXL link from the current device/port to the connected +* downstream port each iteration. */ -while (!is_cxl_root (to_cxl_port (iter->dev.parent))) { - iter =to_cxl_port (iter->dev.parent); +do { + dport = iter->parent_dport; +if (!coordinates_valid (dport->coord)) +return -EINVAL ;cxl_coordinates_combine (c, c, dport->coord);add_latency (c, dport->link_latency); - dport = iter->parent_dport; - } + iter =to_cxl_port (iter->dev.parent); + }while (!parent_port_is_cxl_root (iter));/* Get the calculated PCI paths bandwidth */ pdev =to_pci_dev (port->uport_dev->parent);
Signature · 1 line
2.44.0
Re: [PATCH v5 4/4] cxl: Add checks to access_coordinate calculation to fail missing data
Quoted 25 lines · Dave Jiang
Jonathan noted that when the coordinates for host bridge and switches can be 0s if no actual data are retrieved and the calculation continues. The resulting number would be inaccurate. Add checks to ensure that the calculation would complete only if the numbers are valid.
While not seen in the wild, issue may show up with a BIOS that reported CXL root ports via Generic Ports (via a PCI handle in the SRAT entry).
Fixes 14a6960b3e92 ("cxl: Add helper function that calculate performance data for downstream ports")Reported-by Jonathan Cameron <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Davidlohr Bueso <[email protected]>Signed-off-by Dave Jiang <[email protected]>---
v5:
- Adjust for multiple access classes.--- drivers/cxl/core/port.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-)drivers/cxl/core/port.c +0
-0
drivers/cxl/core/port.c static void add_latency(struct access_coordinate *c, long latency) · line 2150
Quoted 10 lines
drivers/cxl/core/port.c +7
-0@@ -2141,6 +2141,18 @@ static void add_latency(struct access_coordinate *c, long latency) } } +static bool coordinates_valid (struct access_coordinate *c) +{ +for (int i =0 ; i <ACCESS_COORDINATE_MAX ; i++) { +if (c[i].read_bandwidth && c[i].write_bandwidth && + c[i].read_latency && c[i].write_latency) +continue ; +return false;
With the observation that a coordinate tracks nanoseconds while the CDAT reports picoseconds I wonder what this check does for sub-nanosecond latency values. Does that need a min_not_zero(1, latency) somewhere... and if that is in place does it mean latency can never be zero?