Re: [PATCH v1 08/14] cxl/extent: Validate DC extent partition

From: Alison Schofield

Date: Mon Nov 30 2026 - 15:13:29 EST


On Thu, Nov 05, 2026 at 08:02:32AM +0900, Anisa Su wrote:
> From: Ira Weiny <iweiny@xxxxxxxxxx>
>
> Extend cxl_validate_extent() — the per-extent check of the add pipeline
> to check partition membership.
>
> Resolves an extent's DPA to its containing DC partition. Sharability is
> a property of the partition (part->shareable), taken from its CDAT DSMAS
> entry.
>
> An extent from a sharable partition must carry a non-null tag, since hosts
> sharing the allocation key on that tag. A null tag there is a device
> firmware bug; reject the extent.
>
> A non-sharable extent must carry 0 in shared_extn_seq (CXL r4.0 Table
> 8-230); a non-zero value is rejected the same way. The dense 0..n-1
> check for sharable groups follows in the next commit, once the whole
> tag group is collected.

"follows in the next commit" loses meaning after merged. Maybe: "The
dense 0..n-1 check for shareable groups needs the whole tag group, so it
is done at the group level."

>
> Based on patches by John Groves.
>
> Signed-off-by: Ira Weiny <iweiny@xxxxxxxxxx>
> Co-developed-by: John Groves <John@xxxxxxxxxx>
> Signed-off-by: John Groves <John@xxxxxxxxxx>
> Co-developed-by: Anisa Su <anisa.su@xxxxxxxxxxx>
> Signed-off-by: Anisa Su <anisa.su@xxxxxxxxxxx>
> Tested-by: Wonjae Lee <wj28.lee@xxxxxxxxxxx>
> Tested-by: Junhee Park <jh9934.park@xxxxxxxxxxx>
> Tested-by: Heesoo Kim <habil.kim@xxxxxxxxxxx>
> ---
> drivers/cxl/core/core.h | 12 +++++++
> drivers/cxl/core/extent.c | 70 +++++++++++++++++++++++++++++++++++++++
> 2 files changed, 82 insertions(+)
>

snip

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

> +const struct cxl_dpa_partition *
> +cxl_extent_dc_partition(struct cxl_memdev_state *mds,
> + struct cxl_extent *extent,
> + struct range *ext_range)
> +{
> + struct cxl_dev_state *cxlds = &mds->cxlds;
> + struct device *dev = mds->cxlds.dev;


Since cxlds is right above, perhaps "struct device *dev = cxlds->dev;"


> +
> + /*
> + * A device-side error could cause end < start, which range_contains()
> + * would treat as contained in any partition.
> + */
> + if (ext_range->end < ext_range->start) {
> + dev_err_ratelimited(dev,
> + "DC extent DPA %pra (%pU) has invalid length (firmware bug)\n",
> + ext_range, extent->uuid);
> + return NULL;


start_dpa of 0 survives above length check and is rejected below.
Should it be rejected above as not a valid length?


> + }
> +
> + for (int i = 0; i < cxlds->nr_partitions; i++) {
> + struct cxl_dpa_partition *part = &cxlds->part[i];
> + struct range partition_range = {
> + .start = part->res.start,
> + .end = part->res.end,
> + };
> +
> + if (part->mode != CXL_PARTMODE_DYNAMIC_RAM)
> + continue;
> +
> + if (range_contains(&partition_range, ext_range))
> + return part;
> + }
> +
> + dev_err_ratelimited(dev,
> + "DC extent DPA %pra (%pU) is not in a valid DC partition\n",
> + ext_range, extent->uuid);
> + return NULL;
> +}
> +
> /*
> * Stage 1 of the add pipeline: pure, no allocation. Resolve the extent
> * to its region/endpoint decoder and ext_range, and verify the range
> @@ -133,6 +178,8 @@ static int cxl_validate_extent(struct cxl_memdev_state *mds,
> {
> u64 start_dpa = le64_to_cpu(extent->start_dpa);
> struct cxl_memdev *cxlmd = mds->cxlds.cxlmd;
> + struct device *dev = mds->cxlds.dev;
> + const struct cxl_dpa_partition *part;
> struct cxl_endpoint_decoder *cxled;
> struct cxl_region *cxlr;
> struct range ext_range = (struct range) {
> @@ -140,6 +187,29 @@ static int cxl_validate_extent(struct cxl_memdev_state *mds,
> .end = start_dpa + le64_to_cpu(extent->length) - 1,
> };
> struct range ed_range;
> + uuid_t uuid;
> +
> + import_uuid(&uuid, extent->uuid);
> +
> + part = cxl_extent_dc_partition(mds, extent, &ext_range);
> + if (!part)
> + return -ENXIO;
> + dev_dbg(dev, "DC extent DPA %pra (DCR:%pR)(%pU)\n", &ext_range,
> + &part->res, &uuid);
> +
> + if (part->shareable) {
> + if (uuid_is_null(&uuid)) {


Is the partition lookup needed here? The decoder containment check
below already implies it, since a region's decoder sits inside its
partition, and cxlds->part[cxled->part] gives the same part.


> + dev_err_ratelimited(dev,
> + "DC extent DPA %pra: sharable-partition extent has null tag (firmware bug)\n",
> + &ext_range);
> + return -ENXIO;
> + }
> + } else if (le16_to_cpu(extent->shared_extn_seq)) {
> + dev_err_ratelimited(dev,
> + "DC extent DPA %pra (%pU): non-sharable partition but shared_extn_seq=%u (firmware bug)\n",
> + &ext_range, &uuid, le16_to_cpu(extent->shared_extn_seq));
> + return -ENXIO;
> + }
>
> cxlr = cxl_dpa_to_region(cxlmd, start_dpa, &cxled);
> if (!cxlr || !cxlr->cxlr_dax)
> --
> 2.43.0
>