Re: [RFC PATCH 3/4] PCI/TSM: Derive the coherent-range IPA from CXL

From: Andy Shevchenko

Date: Mon Oct 12 2026 - 15:49:47 EST


On Mon, Oct 05, 2026 at 09:02:51AM +0200, Ankit Agrawal wrote:
> The DevIf report range with range ID 0xffff describes the device's
> coherent (CXL) memory window and unlike every other reported range
> carries no BAR number. Recognize
> PCI_TSM_DEVIF_REPORT_MMIO_RANGE_ID_COHERENT and recover that window's
> address from the CXL side of the device instead of treating it as a
> BAR-relative offset.
>
> pci_tsm_coherent_range() resolves the window from pdev->coh_resource[],
> snapshotted once with the committed CXL HDM decoders range. The
> range to IPA conversion is applied onto range_base/range_len using
> pdev->coh_resource[]. The ascending BAR order checks stay on the BAR
> path only. The coherent range is required to be the last report entry
> and is not part of the BAR sequence.
>
> An HDM decoded window lives in the CXL Fixed Memory Window and is not
> part of a BAR. So by construction, no pci_dev resource contains it. So
> the function pci_tsm_coh_resource_contains() validates the range against
> pdev->coh_resource[] instead; the same known-good snapshot
> pci_tsm_coherent_range() already trusts.

> Assisted-by: Claude:sonnet-5

Assisted-by: LLM

...

> +static bool pci_tsm_coh_resource_contains(struct pci_dev *pdev,
> + const struct resource *res)
> +{
> + int i;
> +
> + for (i = 0; i < PCI_CXL_MAX_COHERENT_RANGES; i++) {

for (int i = 0...)

> + struct resource *coh_res = &pdev->coh_resource[i];

pci_resource_n()

> + if ((coh_res->flags & IORESOURCE_MEM) &&
> + resource_contains(coh_res, res))
> + return true;
> + }
> +
> + return false;
> +}

...

> + for (j = 0; j < PCI_NUM_RESOURCES; j++)
> + if (resource_contains(pci_resource_n(pdev, j), res))
> + break;

pci_dev_for_each_resource()

...

> +static int pci_tsm_coherent_range(struct pci_dev *pdev, u64 *out_base,
> + u64 *out_size)

Instead of the last two you can use struct range.

> +{
> + for (int i = 0; i < PCI_CXL_MAX_COHERENT_RANGES; i++) {
> + struct resource *res = &pdev->coh_resource[i];

pci_resource_n()

> + if (!(res->flags & IORESOURCE_MEM))
> + continue;

resource_type()

> + *out_base = res->start;
> + *out_size = resource_size(res);
> + return 0;
> + }
> +
> + return -ENODEV;
> +}

...

> + if (pci_tsm_coherent_range(pdev, &range_base,
> + &range_len)) {

I would leave it on a single line.

> + pci_dbg(pdev, "No CXL region or committed HDM decoder for coherent reporting range\n");
> + return NULL;
> + }


...

> + range_off = coherent ? tsm_offset :
> + tsm_offset - reporting_bar_base;

Indentation is broken. I think it's better to read when it's a single line.

--
With Best Regards,
Andy Shevchenko