Re: [RFC PATCH v1 34/38] coco: guest: arm64: Validate mmio range found in the interface report

Jonathan Cameron
2025-07-30T15:06:36Z

On Mon, 28 Jul 2025 19:22:11 +0530
"Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org> wrote:

> This starts the sequence to transition the realm device to the TDISP RUN
> state by writing 1 to 'tsm/accept'.
>
> Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
Just some trivial stuff.

> diff --git a/drivers/virt/coco/arm-cca-guest/rsi-da.c b/drivers/virt/coco/arm-cca-guest/rsi-da.c
> index 47b379318e7c..936f844880de 100644
> --- a/drivers/virt/coco/arm-cca-guest/rsi-da.c
> +++ b/drivers/virt/coco/arm-cca-guest/rsi-da.c
> @@ -215,3 +215,135 @@ int rsi_device_lock(struct pci_dev *pdev)
>
> return ret;
> }

> +
> +int rsi_update_interface_report(struct pci_dev *pdev, bool validate)
> +{
> + int ret;
> + struct resource *r;
> + int msix_tbl_bar, msix_pba_bar;
> + unsigned int range_id;
> + unsigned long mmio_start_phys;
> + unsigned long mmio_flags = 0; /* non coherent, not limited order */
> + struct pci_tdisp_mmio_range *mmio_range;
> + struct pci_tdisp_device_interface_report *interface_report;
> + struct cca_guest_dsc *dsm = to_cca_guest_dsc(pdev);
> + int vdev_id = (pci_domain_nr(pdev->bus) << 16) |
> + PCI_DEVID(pdev->bus->number, pdev->devfn);
> +
> +
Single line.
> + interface_report = (struct pci_tdisp_device_interface_report *)dsm->interface_report;
> + mmio_range = (struct pci_tdisp_mmio_range *)(interface_report + 1);
> +
> +
Single line

> + msix_tbl_bar = get_msix_bar(pdev, PCI_MSIX_TABLE);
> + msix_pba_bar = get_msix_bar(pdev, PCI_MSIX_PBA);
> +
> + for (int i = 0; i < interface_report->mmio_range_count; i++, mmio_range++) {
> +
> + /*FIXME!! units in 4K size*/
> + range_id = FIELD_GET(TSM_INTF_REPORT_MMIO_RANGE_ID, mmio_range->range_attributes);
> +
> + /* no secure interrupts */
> + if (msix_tbl_bar != -1 && range_id == msix_tbl_bar) {

That first condition can get hiked out of the loop.

> + pr_info("Skipping misx table\n");
> + continue;
> + }
> +
> + if (msix_pba_bar != -1 && range_id == msix_pba_bar) {

Likewise.

> + pr_info("Skipping misx pba\n");
> + continue;
> + }
> +
> + r = pci_resource_n(pdev, range_id);
> +
> + if (r->end == r->start ||
> + ((r->end - r->start + 1) & ~PAGE_MASK) || !mmio_range->num_pages) {
resource_size()
> + pci_warn(pdev, "Skipping broken range [%d] #%d %d pages, %llx..%llx\n",
> + i, range_id, mmio_range->num_pages, r->start, r->end);
> + continue;
> + }
> +
> + if (FIELD_GET(TSM_INTF_REPORT_MMIO_IS_NON_TEE, mmio_range->range_attributes)) {
> + pci_info(pdev, "Skipping non-TEE range [%d] #%d %d pages, %llx..%llx\n",
> + i, range_id, mmio_range->num_pages, r->start, r->end);
> + continue;
> + }
> +
> + /* No secure interrupts, we should not find this set, ignore for now. */
> + if (FIELD_GET(TSM_INTF_REPORT_MMIO_MSIX_TABLE, mmio_range->range_attributes) ||
> + FIELD_GET(TSM_INTF_REPORT_MMIO_PBA, mmio_range->range_attributes)) {
> + pci_info(pdev, "Skipping MSIX (%ld/%ld) range [%d] #%d %d pages, %llx..%llx\n",
> + FIELD_GET(TSM_INTF_REPORT_MMIO_MSIX_TABLE, mmio_range->range_attributes),
> + FIELD_GET(TSM_INTF_REPORT_MMIO_PBA, mmio_range->range_attributes),
> + i, range_id, mmio_range->num_pages, r->start, r->end);
> + continue;
> + }
> +
> + mmio_start_phys = mmio_range->first_page;
> + if (validate)
> + ret = rsi_validate_dev_mapping(vdev_id, dsm->instance_id,
> + r->start, r->end + 1,
> + mmio_start_phys << 12, mmio_flags);
> + else
> + ret = rsi_invalidate_dev_mapping(r->start, r->end + 1);
> + if (ret) {
> + pci_err(pdev, "failed to set protection attributes for the address range\n");
> + return -EIO;
> + }
> + }
> + return 0;
> +}