Skip to content

Commit edd4403

Browse files
jgunthorpenvidia
authored andcommitted
iommu/arm-smmu-v3: Allow setting a S1 domain to a PASID
The SVA cleanup made the SSID logic entirely general so all we need to do is call it with the correct cd table entry for a S1 domain. This is slightly tricky because of the ASID and how the locking works, the simple fix is to just update the ASID once we get the right locks. Tested-by: Nicolin Chen <nicolinc@nvidia.com> Tested-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com> Reviewed-by: Nicolin Chen <nicolinc@nvidia.com> Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Link: https://lore.kernel.org/r/14-v9-5cd718286059+79186-smmuv3_newapi_p2b_jgg@nvidia.com Signed-off-by: Will Deacon <will@kernel.org> (cherry picked from commit f3b273b) Signed-off-by: Koba Ko <kobak@nvidia.com>
1 parent ac328da commit edd4403

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

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

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2811,6 +2811,36 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
28112811
return 0;
28122812
}
28132813

2814+
static int arm_smmu_s1_set_dev_pasid(struct iommu_domain *domain,
2815+
struct device *dev, ioasid_t id)
2816+
{
2817+
struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain);
2818+
struct arm_smmu_master *master = dev_iommu_priv_get(dev);
2819+
struct arm_smmu_device *smmu = master->smmu;
2820+
struct arm_smmu_cd target_cd;
2821+
int ret = 0;
2822+
2823+
mutex_lock(&smmu_domain->init_mutex);
2824+
if (!smmu_domain->smmu)
2825+
ret = arm_smmu_domain_finalise(smmu_domain, smmu);
2826+
else if (smmu_domain->smmu != smmu)
2827+
ret = -EINVAL;
2828+
mutex_unlock(&smmu_domain->init_mutex);
2829+
if (ret)
2830+
return ret;
2831+
2832+
if (smmu_domain->stage != ARM_SMMU_DOMAIN_S1)
2833+
return -EINVAL;
2834+
2835+
/*
2836+
* We can read cd.asid outside the lock because arm_smmu_set_pasid()
2837+
* will fix it
2838+
*/
2839+
arm_smmu_make_s1_cd(&target_cd, master, smmu_domain);
2840+
return arm_smmu_set_pasid(master, to_smmu_domain(domain), id,
2841+
&target_cd);
2842+
}
2843+
28142844
static void arm_smmu_update_ste(struct arm_smmu_master *master,
28152845
struct iommu_domain *sid_domain,
28162846
bool ats_enabled)
@@ -2838,7 +2868,7 @@ static void arm_smmu_update_ste(struct arm_smmu_master *master,
28382868

28392869
int arm_smmu_set_pasid(struct arm_smmu_master *master,
28402870
struct arm_smmu_domain *smmu_domain, ioasid_t pasid,
2841-
const struct arm_smmu_cd *cd)
2871+
struct arm_smmu_cd *cd)
28422872
{
28432873
struct iommu_domain *sid_domain = iommu_get_domain_for_dev(master->dev);
28442874
struct arm_smmu_attach_state state = {
@@ -2871,6 +2901,14 @@ int arm_smmu_set_pasid(struct arm_smmu_master *master,
28712901
if (ret)
28722902
goto out_unlock;
28732903

2904+
/*
2905+
* We don't want to obtain to the asid_lock too early, so fix up the
2906+
* caller set ASID under the lock in case it changed.
2907+
*/
2908+
cd->data[0] &= ~cpu_to_le64(CTXDESC_CD_0_ASID);
2909+
cd->data[0] |= cpu_to_le64(
2910+
FIELD_PREP(CTXDESC_CD_0_ASID, smmu_domain->cd.asid));
2911+
28742912
arm_smmu_write_cd_entry(master, pasid, cdptr, cd);
28752913
arm_smmu_update_ste(master, sid_domain, state.ats_enabled);
28762914

@@ -3383,6 +3421,7 @@ static struct iommu_ops arm_smmu_ops = {
33833421
.owner = THIS_MODULE,
33843422
.default_domain_ops = &(const struct iommu_domain_ops) {
33853423
.attach_dev = arm_smmu_attach_dev,
3424+
.set_dev_pasid = arm_smmu_s1_set_dev_pasid,
33863425
.map_pages = arm_smmu_map_pages,
33873426
.unmap_pages = arm_smmu_unmap_pages,
33883427
.flush_iotlb_all = arm_smmu_flush_iotlb_all,

drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ void arm_smmu_write_cd_entry(struct arm_smmu_master *master, int ssid,
802802

803803
int arm_smmu_set_pasid(struct arm_smmu_master *master,
804804
struct arm_smmu_domain *smmu_domain, ioasid_t pasid,
805-
const struct arm_smmu_cd *cd);
805+
struct arm_smmu_cd *cd);
806806

807807
void arm_smmu_tlb_inv_asid(struct arm_smmu_device *smmu, u16 asid);
808808
void arm_smmu_tlb_inv_range_asid(unsigned long iova, size_t size, int asid,

0 commit comments

Comments
 (0)