Re: [PATCH 1/9] iommu: introduce iova_to_phys_length in iommu_domain_ops
From: guanghuifeng@xxxxxxxxxxxxxxxxx
Date: Mon Jun 01 2026 - 10:25:22 EST
在 2026/6/1 21:43, Jason Gunthorpe 写道:
On Mon, Jun 01, 2026 at 04:41:48PM +0800, guanghuifeng@xxxxxxxxxxxxxxxxx wrote:
I know, but this bad choice has already caused bugs so if we areImplementations such as arm_smmu_iova_to_phys/DOMAIN_NS(iova_to_phys)+/**When introducing the new function I would like to fix this 0 error as
+ * iommu_iova_to_phys_length - Translate IOVA and return mapping page size
+ * @domain: IOMMU domain to query
+ * @iova: IO virtual address to translate
+ * @mapped_length: Output parameter for the PTE page size (e.g. 4KB/2MB/1GB)
+ *
+ * Like iommu_iova_to_phys() but additionally returns the page size of the
+ * PTE mapping at @iova through @mapped_length.
+ *
+ * Return: The physical address for the given IOVA, or 0 if no translation.
+ */
well, it should return PHYS_MAX for error
all use a return value of 0 as an invalid state, so 0 is used as the
representation of an invalid state to maintain compatibility.
changing everything I would prefer we fix it.
OK, there are a lot of changes in the current commit. This issue will be fixed in a subsequent series patch.
Detect the invalid states by looking at ops not domain->typeIn accordance with the implementation of iommu_iova_to_phys, it returns a+phys_addr_t iommu_iova_to_phys_length(struct iommu_domain *domain,Any domain that doesn't have an op should fail, blocked is one example
+ dma_addr_t iova,
+ size_t *mapped_length)
{
+ if (mapped_length)
+ *mapped_length = 0;
+
if (domain->type == IOMMU_DOMAIN_IDENTITY)
return iova;
if (domain->type == IOMMU_DOMAIN_BLOCKED)
return 0;
phy value of 0 in invalid states.
YesI suggest you approach the patch plan a little differently, the firstDoes this mean retaining the iommu_iova_to_phys implementation but
patches should implement the new function and an iommput
implementation
Arrange things so the normal iova_to_phys calls the new function if it
is available and discards the length.
Then convert callers that can take advantage of it. Have the fallback
path also compute the length by iterating internally.
Finally one patch per driver implementing the new op, this could even
be a second series.
Don't remove iova_to_phys(), it is fine for things that don't need the
length.
implementing it through domain->ops->iova_to_phys_length (mapped_length is
NULL)?
Jason