Skip to content

Commit adfe197

Browse files
committed
cxl/region: Fix state transitions after reset failure
Jonathan reports that failed attempts to reset a region (teardown its HDM decoder configuration) mistakenly advance the state of the region to "not committed". Revert to the previous state of the region on reset failure so that the reset can be re-attempted. Reported-by: Jonathan Cameron <Jonathan.Cameron@Huawei.com> Closes: http://lore.kernel.org/r/20230316171441.0000205b@Huawei.com Fixes: 176baef ("cxl/hdm: Commit decoder state to hardware") Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Link: https://lore.kernel.org/r/168696507968.3590522.14484000711718573626.stgit@dwillia2-xfh.jf.intel.com Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 2ab4704 commit adfe197

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

drivers/cxl/core/region.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,11 @@ static ssize_t commit_store(struct device *dev, struct device_attribute *attr,
296296
if (rc)
297297
return rc;
298298

299-
if (commit)
299+
if (commit) {
300300
rc = cxl_region_decode_commit(cxlr);
301-
else {
301+
if (rc == 0)
302+
p->state = CXL_CONFIG_COMMIT;
303+
} else {
302304
p->state = CXL_CONFIG_RESET_PENDING;
303305
up_write(&cxl_region_rwsem);
304306
device_release_driver(&cxlr->dev);
@@ -308,18 +310,20 @@ static ssize_t commit_store(struct device *dev, struct device_attribute *attr,
308310
* The lock was dropped, so need to revalidate that the reset is
309311
* still pending.
310312
*/
311-
if (p->state == CXL_CONFIG_RESET_PENDING)
313+
if (p->state == CXL_CONFIG_RESET_PENDING) {
312314
rc = cxl_region_decode_reset(cxlr, p->interleave_ways);
315+
/*
316+
* Revert to committed since there may still be active
317+
* decoders associated with this region, or move forward
318+
* to active to mark the reset successful
319+
*/
320+
if (rc)
321+
p->state = CXL_CONFIG_COMMIT;
322+
else
323+
p->state = CXL_CONFIG_ACTIVE;
324+
}
313325
}
314326

315-
if (rc)
316-
goto out;
317-
318-
if (commit)
319-
p->state = CXL_CONFIG_COMMIT;
320-
else if (p->state == CXL_CONFIG_RESET_PENDING)
321-
p->state = CXL_CONFIG_ACTIVE;
322-
323327
out:
324328
up_write(&cxl_region_rwsem);
325329

0 commit comments

Comments
 (0)