Re: [PATCH v1 11/14] cxl/extent: Handle DC Release Capacity events

From: Alison Schofield

Date: Mon Nov 30 2026 - 16:31:47 EST


On Thu, Nov 05, 2026 at 08:02:35AM +0900, Anisa Su wrote:
> From: Ira Weiny <iweiny@xxxxxxxxxx>
>
> Replace the ack-all stub for Release Capacity chains with the real
> teardown.
>
> Similar to add capacity events, Release Capacity records arrive as a
> More-chain and are staged in mds->dc_chain until the chain closes;
> a chain whose closing record never arrives is dropped by the 20s
> watchdog without a response.
>
> A tag group is one logical allocation, so a well-behaved fabric manager
> is expected to release all members of a tag group together. However,
> CXL r4.0 Section 8.2.10.9.9.4 permits the host to issue an "unsolicited
> release" of extents not corresponding to any event. So as a generous
> policy, the kernel releases all members of a tag group upon receiving a
> Release Capacity record containing any member of the group.
>
> Extents are matched to what the host owns by DPA range and tag. An
> extent not matching any host-owned extent is acknowledged for release
> so the device knows the host is not using it. An extent that overlaps
> owned capacity without matching any host-owned extent by tag and DPA is
> left out of the response so the device keeps the capacity for the host
> and must retry.

Should this also mention that an extent is left ouf of the response
when the cache invalidation fails and if -EBUSY (dax_region's unbind
already owns teardown).

snip
> diff --git a/drivers/cxl/core/extent.c b/drivers/cxl/core/extent.c
snip

> +int cxl_resolve_extent(struct cxl_memdev_state *mds, struct cxl_extent *extent,
> + struct cxl_region **cxlrp,
> + struct cxl_dc_tag_group **groupp)
> +{
> + u64 start_dpa = le64_to_cpu(extent->start_dpa);
> + struct cxl_memdev *cxlmd = mds->cxlds.cxlmd;
> + struct cxl_endpoint_decoder *cxled;
> + struct cxl_dax_region *cxlr_dax;
> + struct dc_extent *dc_extent;
> + struct cxl_region *cxlr;
> + struct range dpa_range;
> + unsigned long idx;
> + uuid_t tag;
> +
> + *cxlrp = NULL;
> + *groupp = NULL;
> +
> + dpa_range = (struct range) {
> + .start = start_dpa,
> + .end = start_dpa + le64_to_cpu(extent->length) - 1,
> + };


Same as Sashiko here wrt a release record w length 0 or a wrapped end.


> +
> + cxlr = cxl_dpa_to_region(cxlmd, start_dpa, &cxled);
> + if (!cxlr)
> + return -ENXIO;
> +
> + cxlr_dax = cxlr->cxlr_dax;
> + if (!cxlr_dax)
> + return -ENXIO;


Same as Sashiko and Richard here wrt releases acknowledged while the
region is being torn down.


> +
> + import_uuid(&tag, extent->uuid);
> +
> + /* RCU keeps entries live during the walk; teardown happens later. */


Is above comment accurate? The group is freed w kfree() so does RCU keep
dc_extent->group live? (I think) same as a Sashiko raised issue.


> + scoped_guard(rcu) {
> + xa_for_each(&cxlr_dax->dc_extents, idx, dc_extent) {
> + if (dc_extent->cxled != cxled)
> + continue;


Can this lookup miss an extent whose tag group belongs to another
region? W the 2-regino tag group raised in Patch 6, every member is
stored in the first regions dc_extents.


> + if (!range_overlaps(&dc_extent->dpa_range, &dpa_range))
> + continue;
> + if (!range_contains(&dc_extent->dpa_range, &dpa_range))
> + return -EINVAL;
> + if (!uuid_equal(&dc_extent->group->uuid, &tag))
> + return -EINVAL;
> + *cxlrp = cxlr;
> + *groupp = dc_extent->group;
> + return 0;
> + }
> + }
> + return -ENXIO;
> +}
> +
> +/**
> + * cxl_release_tag_group() - tear a tag group down for a device release
> + * @cxlr: region owning the group
> + * @group: the group to release
> + *
> + * The caller acknowledges the group to the device as a whole; the group is
> + * dropped without a Release DC of its own.
> + *
> + * Return: 0 when the group is gone, negative when the caller must leave it
> + * intact and let the device retry.
> + */
> +int cxl_release_tag_group(struct cxl_region *cxlr,
> + struct cxl_dc_tag_group *group)
> +{
> + int rc;
> +
> + /*
> + * Invalidate CPU caches for the region before releasing the capacity
> + * back to the device so it cannot reassign the range while stale
> + * cached data lingers. On failure do not release: leave the tag
> + * group intact and let the device retry.
> + */
> + rc = cxl_region_invalidate_memregion(cxlr);
> + if (rc)
> + return rc;


On a host without cache invalidation support, like a guest without
CONFIG_CXL_REGION_INVALIDATION_TEST, this always fails, so every
device-initiated release is held forever and each Release Capacity chain
WARNs. Teardown on the same host releases anyway, as raised on patch 6.

What is the policy we want here?

> +
> + /*
> + * An unbinding dax region has already collected the group's devres
> + * teardown; let that finish the release rather than race it.
> + */
> + if (!rm_tag_group(group))
> + return -EBUSY;
> + return 0;
> +}
> +
> /* The group's device may already be visible: readers walk the xarray under RCU */
> static void cleanup_pending_dc_extent(struct dc_extent *dc_extent)
> {
> diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c
> index 0fa501f5800c..c3236fe9e7c5 100644
> --- a/drivers/cxl/core/mbox.c
> +++ b/drivers/cxl/core/mbox.c
> @@ -1747,6 +1747,109 @@ static int cxl_add_pending(struct cxl_memdev_state *mds,
> pending, total_accepted);
> }
>
> +/*
> + * Tear @group down and queue every member on @acks. Members are queued
> + * before rm_tag_group() frees them; on failure nothing is queued and the
> + * group stays intact for the device to retry. Returns the number queued.
> + */
> +static int cxl_release_group(struct cxl_region *cxlr,
> + struct cxl_dc_tag_group *group,
> + struct list_head *acks)


Tidying up needed here. We've got several release group functions now
that are not so crisp in what they actually do:

memdev_release_group() sends a Release DC for the group
(maybe cxl_send_group_release())
cxl_release_group() tears the group down and queues its extents
for the chain's Release DC
(maybe cxl_queue_group_release())
cxl_release_tag_group() flushes caches, then tears the group down
(maybe cxl_flush_rm_tag_group())
rm_tag_group() only tears the group down
(maybe cxl_rm_tag_group())


> +{
> + LIST_HEAD(members);
> + int cnt, rc;
> +
> + cnt = stage_group_release(group, &members);
> + if (cnt < 0)
> + return cnt;
> +
> + rc = cxl_release_tag_group(cxlr, group);
> + if (rc) {
> + drop_extent_group(&members);
> + return rc;
> + }
> +
> + list_splice_tail(&members, acks);
> + return cnt;
> +}
> +
> +/*
> + * Flush a staged Release chain.
> + *
> + * A tag group is one logical allocation: naming any extent of a group
> + * releases the whole group, and members the chain did not name go back as
> + * an unsolicited release (CXL r4.0 9.13.3). Each extent is decided on its
> + * own, so a group that refuses teardown, or an extent that overlaps owned
> + * capacity without naming an owned extent, is held for the device to retry
> + * while the rest proceed. Extents the host is not tracking at all (no
> + * region, no dax region, or nothing owned in range) hold no capacity here
> + * and are acknowledged as named.
> + *
> + * Everything released is acknowledged together in the Release DC response
> + * once the chain is flushed (split across More-chained commands when the
> + * list outgrows the mailbox payload), so a sharable tag is always returned
> + * whole (CXL r4.0 8.2.10.9.9.4).
> + */
> +static int cxl_rm_pending(struct cxl_memdev_state *mds)
> +{
> + struct list_head *pending = &mds->dc_chain.pending_extents;
> + struct device *dev = mds->cxlds.dev;
> + struct cxl_extent_list_node *pos, *tmp;
> + LIST_HEAD(acks);
> + int cnt = 0, rc;
> +
> + /* cxl_resolve_extent() -> cxl_dpa_to_region() walks every decoder's dpa_res */
> + guard(rwsem_read)(&cxl_rwsem.region);
> + guard(rwsem_read)(&cxl_rwsem.dpa);
> +
> + /* Untracked first, before a teardown below makes a sibling look untracked */
> + list_for_each_entry_safe(pos, tmp, pending, list) {
> + struct cxl_dc_tag_group *group;
> + struct cxl_region *cxlr;
> +
> + if (cxl_resolve_extent(mds, pos->extent, &cxlr, &group) != -ENXIO)
> + continue;
> + list_move_tail(&pos->list, &acks);
> + cnt++;
> + }


Should the owned groups get a Release DC of their own? That way a bad
untracked entry can only cuase its own cmd to be rejected.

snip to end