RE: [PATCH v3 1/3] iommu: Sort out domain user data
From: Tian, Kevin
Date: Thu Mar 06 2025 - 00:59:54 EST
> From: Nicolin Chen <nicolinc@xxxxxxxxxx>
> Sent: Tuesday, March 4, 2025 4:53 AM
>
> From: Robin Murphy <robin.murphy@xxxxxxx>
>
> When DMA/MSI cookies were made first-class citizens back in commit
> 46983fcd67ac ("iommu: Pull IOVA cookie management into the core"), there
> was no real need to further expose the two different cookie types.
> However, now that IOMMUFD wants to add a third type of MSI-mapping
> cookie, we do have a nicely compelling reason to properly dismabiguate
> things at the domain level beyond just vaguely guessing from the domain
> type.
>
> Meanwhile, we also effectively have another "cookie" in the form of the
> anonymous union for other user data, which isn't much better in terms of
> being vague and unenforced. The fact is that all these cookie types are
> mutually exclusive, in the sense that combining them makes zero sense
> and/or would be catastrophic (iommu_set_fault_handler() on an SVA
> domain, anyone?) - the only combination which *might* be reasonable is
> perhaps a fault handler and an MSI cookie, but nobody's doing that at
> the moment, so let's rule it out as well for the sake of being clear and
> robust. To that end, we pull DMA and MSI cookies apart a little more,
> mostly to clear up the ambiguity at domain teardown, then for clarity
> (and to save a little space), move them into the union, whose ownership
> we can then properly describe and enforce entirely unambiguously.
>
> Signed-off-by: Robin Murphy <robin.murphy@xxxxxxx>
> [nicolinc: rebase on latest tree; use prefix IOMMU_COOKIE_; merge unions
> in iommu_domain; add IOMMU_COOKIE_IOMMUFD for
> iommufd_hwpt]
> Signed-off-by: Nicolin Chen <nicolinc@xxxxxxxxxx>
Reviewed-by: Kevin Tian <kevin.tian@xxxxxxxxx>
with a nit:
> msi_addr &= ~(phys_addr_t)(size - 1);
> - list_for_each_entry(msi_page, &cookie->msi_page_list, list)
> + list_for_each_entry(msi_page, cookie_msi_pages(domain), list)
> if (msi_page->phys == msi_addr)
> return msi_page;
>
Above checks cookie type in every iteration. Better save the list
pointer to a local variable.