Skip to content

Commit ae91f65

Browse files
jgunthorpewilldeacon
authored andcommitted
iommu/arm-smmu-v3: Check that the RID domain is S1 in SVA
The SVA code only works if the RID domain is a S1 domain and has already installed the cdtable. Originally the check for this was in arm_smmu_sva_bind() but when the op was removed the test didn't get copied over to the new arm_smmu_sva_set_dev_pasid(). Without the test wrong usage usually will hit a WARN_ON() in arm_smmu_write_ctx_desc() due to a missing ctx table. However, the next patches wil change things so that an IDENTITY domain is not a struct arm_smmu_domain and this will get into memory corruption if the struct is wrongly casted. Fail in arm_smmu_sva_set_dev_pasid() if the STE does not have a S1, which is a proxy for the STE having a pointer to the CD table. Write it in a way that will be compatible with the next patches. Fixes: 386fa64 ("arm-smmu-v3/sva: Add SVA domain support") Reported-by: Shameerali Kolothum Thodi <[email protected]> Closes: https://lore.kernel.org/linux-iommu/[email protected]/ Tested-by: Nicolin Chen <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 1b50017 commit ae91f65

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,13 @@ static int __arm_smmu_sva_bind(struct device *dev, ioasid_t pasid,
364364
struct arm_smmu_bond *bond;
365365
struct arm_smmu_master *master = dev_iommu_priv_get(dev);
366366
struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
367-
struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain);
367+
struct arm_smmu_domain *smmu_domain;
368+
369+
if (!(domain->type & __IOMMU_DOMAIN_PAGING))
370+
return -ENODEV;
371+
smmu_domain = to_smmu_domain(domain);
372+
if (smmu_domain->stage != ARM_SMMU_DOMAIN_S1)
373+
return -ENODEV;
368374

369375
if (!master || !master->sva_enabled)
370376
return -ENODEV;

0 commit comments

Comments
 (0)