Re: [PATCH v1 12/14] cxl/region: Read existing extents on region creation
From: Alison Schofield
Date: Mon Nov 30 2026 - 17:08:03 EST
On Thu, Nov 05, 2026 at 08:02:36AM +0900, Anisa Su wrote:
> From: Ira Weiny <iweiny@xxxxxxxxxx>
>
> Dynamic capacity device extents may be left in an accepted state on a
> device due to an unexpected host crash. In this case it is expected
> that the creation of a new region on top of a DC partition can read
> those extents and surface them for continued use.
>
> Once all endpoint decoders are part of a region and the region is being
> created, a read of the device's extent list can reveal these
> previously accepted extents.
The subject and this paragraph say the read happens at region creation,
while a later paragraph says it is "not at region creation" but at the
cxl_dax_region probe, which also runs again on every dax_cxl bind.
Could the subject and this paragraph match that (which is the correct
statement because dax_cxl driver probes later and async)
>
> CXL r4.0 Section 8.2.10.9.9.2 specifies the mailbox call Get Dynamic
> Capacity Extent List for this purpose. The call returns all the extents
> for all dynamic capacity partitions, so only the extents inside the
> region's decoder DPA range are accepted. The rest belong to other
> regions, or to partitions Linux does not map, so are not tracked on the
> current region. If the fabric manager is adding extents to any DCD
> partition, the extent list for the recovered region may change; the
> generation number changing between queries is detected and the read is
> retried.
>
> The dax_region device probes asynchronously, so the extent list is
> read from the cxl_dax_region probe, not at region creation. Onlining
> a recovered group attaches its devres teardown to the dax_region
> device, and devres present before a probe starts makes the driver
> core refuse to bind ("Resources present before probing").
>
> The same asynchrony means the region can detach its decoder before or
> while the probe runs, and the scan needs that decoder throughout: its
> DPA range filters the extent list, and every recovered extent is
> resolved through it back to the region. So cxl_dax_region_alloc()
> records the decoder in cxlr_dax->cxled with a reference, which keeps
> it valid until the dax_region is released. A detach mid-scan then
> just makes the remaining extents resolve to no region, and the group
> is released back to the device.
wrt a detach mid-scan...I don't think that is true if the decoder is
attached to another region while the scan runs. The extents then
resolve to that region instead.
snip
> diff --git a/drivers/cxl/core/extent.c b/drivers/cxl/core/extent.c
snip
> @@ -230,7 +230,7 @@ static int cxl_validate_extent(struct cxl_memdev_state *mds,
> struct cxl_extent *extent,
> struct cxl_endpoint_decoder **out_cxled,
> struct cxl_dax_region **out_cxlr_dax,
> - struct range *out_ext_range)
> + struct range *out_ext_range, bool existing)
> {
> u64 start_dpa = le64_to_cpu(extent->start_dpa);
> struct cxl_memdev *cxlmd = mds->cxlds.cxlmd;
> @@ -271,6 +271,17 @@ static int cxl_validate_extent(struct cxl_memdev_state *mds,
> if (!cxlr || !cxlr->cxlr_dax)
> return -ENXIO;
>
> + /*
> + * New adds wait for a bound dax driver that has read the device's
> + * pre-existing extents, so a tag already in use is never added twice.
> + */
Same as Sashiko here wrt a decoder re-attached to another region while
this scan runs.
snip
> diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c
snip
> @@ -1627,6 +1641,10 @@ static int cxl_realize_group(struct cxl_memdev_state *mds, const uuid_t *tag,
> mds->dc_chain.group = NULL;
> if (tag_group)
> discard_tag_group(tag_group);
> +err_release:
> + /* A fresh group is simply left out of the Add response */
> + if (existing)
> + cxl_release_recovered(mds, tag, group);
> return rc;
> }
Same as Sashiko here, on releasing DPA the host has just onlined. On the
Add path the same group would only be left out of the response. Should
recovery drop such a group not just release it?
snip
> +static int cxl_read_extent_list(struct cxl_memdev_state *mds,
> + const struct range *dpa_range,
> + struct list_head *existing)
> +{
snip
> + dev_dbg(dev, "Got extent list %d-%d of %d generation Num:%d\n",
> + current_index, total_read ? total_read - 1 : 0,
> + current_total, current_gen_num);
Use %u for these u32's to be consistent w other msgs in this func.
> +
> + if (current_gen_num != initial_gen_num || total_expected != current_total) {
> + dev_warn(dev, "Extent list change detected; gen %u != %u : cnt %u != %u\n",
> + current_gen_num, initial_gen_num,
> + total_expected, current_total);
> + return -EAGAIN;
> + }
> +
> + /* No progress with more expected: a buggy device would loop forever. */
> + if (!nr_returned && total_expected > total_read) {
> + dev_warn(dev, "Device returned 0 of %u remaining extents\n",
> + total_expected - total_read);
> + return -EIO;
> + }
> +
> + for (int i = 0; i < nr_returned ; i++) {
stray space before ;
> + struct cxl_extent *extent = &extents->extent[i];
> + struct range ext_range;
> +
> + ext_range.start = le64_to_cpu(extent->start_dpa);
> + ext_range.end = ext_range.start +
> + le64_to_cpu(extent->length) - 1;
> + dev_dbg(dev, "Processing extent %d/%d %pra (%pUb) seq %u\n",
> + current_index + i, total_expected, &ext_range,
> + extent->uuid,
> + le16_to_cpu(extent->shared_extn_seq));
> + /* Another region's, or an unmapped partition's: not ours */
> + if (!range_contains(dpa_range, &ext_range))
> + continue;
> + rc = stage_pending_extent(existing, extent);
Same as Sashiko here wrt a tag group split by the per-extent filter.
There look to be 2 more beyond what Sashiko notes:
- an extent that only partly overlaps this decoder is not recovered
nor released
- a failed partial release is logged only with dev_dbg(), so those
extents stay accepted on the device with no host tracking
> + if (rc)
> + return rc;
> + }
> +
> + current_index += nr_returned;
> + } while (total_expected > total_read);
> +
> + return 0;
> +}
> +
> +static int __cxl_process_extent_list(struct cxl_endpoint_decoder *cxled)
> +{
> + struct cxl_memdev_state *mds = cxled_to_mds(cxled);
> + struct range dpa_range;
> + LIST_HEAD(existing);
How about making this less confusing w some renaming -
Here "existing" is the list, but in cxl_add_pending() and the functions
it calls the same name is the bool flag, so the call below reads as
cxl_add_pending(mds, &existing, true), with "existing" meaning two
things. How about LIST_HEAD(recovered) instead ?
snip
> +/**
> + * cxl_process_extent_list() - Read existing extents
> + * @cxled: Endpoint decoder which is part of a region
> + *
> + * Issue the Get Dynamic Capacity Extent List command to the device
> + * and add existing extents if found.
> + *
> + * A retry of 10 is somewhat arbitrary, however, extent changes should be
> + * relatively rare while bringing up a region. So 10 should be plenty.
> + */
> +int cxl_process_extent_list(struct cxl_endpoint_decoder *cxled)
I believe noted also in Patch 4. Spec says reread the extent list
on overflow, but we don't yet. Is that planned?
snip
> diff --git a/drivers/cxl/core/region_dax.c b/drivers/cxl/core/region_dax.c
snip
> index 790176a8aadd..816386301b80 100644
> --- a/drivers/cxl/core/region_dax.c
> +++ b/drivers/cxl/core/region_dax.c
> @@ -13,6 +13,8 @@ static void cxl_dax_region_release(struct device *dev)
> {
> struct cxl_dax_region *cxlr_dax = to_cxl_dax_region(dev);
>
> + if (cxlr_dax->cxled)
> + put_device(&cxlr_dax->cxled->cxld.dev);
> xa_destroy(&cxlr_dax->dc_extents);
> ida_destroy(&cxlr_dax->tag_group_ida);
> kfree(cxlr_dax);
> @@ -79,6 +81,15 @@ static struct cxl_dax_region *cxl_dax_region_alloc(struct cxl_region *cxlr)
> cxlr_dax->hpa_range.start = p->res->start;
> cxlr_dax->hpa_range.end = p->res->end;
>
> + /*
> + * DC regions are not interleaved; the probe-time scan uses this decoder
> + * and may outlive its attachment to the region, so hold a reference.
> + */
> + if (cxlr->mode == CXL_PARTMODE_DYNAMIC_RAM)
> + cxlr_dax->cxled = p->targets[0];
> + if (cxlr_dax->cxled)
> + get_device(&cxlr_dax->cxled->cxld.dev);
cxled cannot be null if first test passes. How about:
if (cxlr->mode == CXL_PARTMODE_DYNAMIC_RAM) {
cxlr_dax->cxled = p->targets[0];
get_device(&cxlr_dax->cxled->cxld.dev);
}
snip
> diff --git a/drivers/dax/cxl.c b/drivers/dax/cxl.c
snip
> static int cxl_dax_region_probe(struct device *dev)
> {
> struct cxl_dax_region *cxlr_dax = to_cxl_dax_region(dev);
> @@ -15,6 +21,7 @@ static int cxl_dax_region_probe(struct device *dev)
> struct dev_dax_data data;
> resource_size_t dev_size;
> unsigned long flags;
> + int rc;
>
> if (nid == NUMA_NO_NODE)
> nid = memory_add_physaddr_to_nid(cxlr_dax->hpa_range.start);
> @@ -29,11 +36,17 @@ static int cxl_dax_region_probe(struct device *dev)
> if (!dax_region)
> return -ENOMEM;
>
> - if (cxlr->mode == CXL_PARTMODE_DYNAMIC_RAM)
> + if (cxlr->mode == CXL_PARTMODE_DYNAMIC_RAM) {
> + /* Recover extents the device still holds for this region */
> + rc = cxl_region_add_existing_extents(cxlr_dax);
> + if (rc)
> + goto err_remove;
> +
Should a failed scan fail the whole probe?
> /* Add empty seed dax device */
> dev_size = 0;
> - else
> + } else {
> dev_size = range_len(&cxlr_dax->hpa_range);
> + }
>
> data = (struct dev_dax_data) {
> .dax_region = dax_region,
> @@ -42,12 +55,20 @@ static int cxl_dax_region_probe(struct device *dev)
> .memmap_on_memory = true,
> };
>
> - return PTR_ERR_OR_ZERO(devm_create_dev_dax(&data));
> + rc = PTR_ERR_OR_ZERO(devm_create_dev_dax(&data));
> + if (rc)
> + goto err_remove;
> + return 0;
> +
> +err_remove:
> + cxl_dax_region_remove(dev);
> + return rc;
Is a probe failure meant to give the recovered extents back?
snip to end