Skip to content

Commit 2396046

Browse files
TinaZhangZWjoergroedel
authored andcommitted
iommu: Add mm_get_enqcmd_pasid() helper function
mm_get_enqcmd_pasid() should be used by architecture code and closely related to learn the PASID value that the x86 ENQCMD operation should use for the mm. For the moment SMMUv3 uses this without any connection to ENQCMD, it will be cleaned up similar to how the prior patch made VT-d use the PASID argument of set_dev_pasid(). The motivation is to replace mm->pasid with an iommu private data structure that is introduced in a later patch. Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Tested-by: Nicolin Chen <nicolinc@nvidia.com> Signed-off-by: Tina Zhang <tina.zhang@intel.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Link: https://lore.kernel.org/r/20231027000525.1278806-4-tina.zhang@intel.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 5c79705 commit 2396046

4 files changed

Lines changed: 29 additions & 10 deletions

File tree

arch/x86/kernel/traps.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ static bool try_fixup_enqcmd_gp(void)
591591
if (!mm_valid_pasid(current->mm))
592592
return false;
593593

594-
pasid = current->mm->pasid;
594+
pasid = mm_get_enqcmd_pasid(current->mm);
595595

596596
/*
597597
* Did this thread already have its PASID activated?

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ static void arm_smmu_mm_arch_invalidate_secondary_tlbs(struct mmu_notifier *mn,
246246
smmu_domain);
247247
}
248248

249-
arm_smmu_atc_inv_domain(smmu_domain, mm->pasid, start, size);
249+
arm_smmu_atc_inv_domain(smmu_domain, mm_get_enqcmd_pasid(mm), start,
250+
size);
250251
}
251252

252253
static void arm_smmu_mm_release(struct mmu_notifier *mn, struct mm_struct *mm)
@@ -264,10 +265,11 @@ static void arm_smmu_mm_release(struct mmu_notifier *mn, struct mm_struct *mm)
264265
* DMA may still be running. Keep the cd valid to avoid C_BAD_CD events,
265266
* but disable translation.
266267
*/
267-
arm_smmu_update_ctx_desc_devices(smmu_domain, mm->pasid, &quiet_cd);
268+
arm_smmu_update_ctx_desc_devices(smmu_domain, mm_get_enqcmd_pasid(mm),
269+
&quiet_cd);
268270

269271
arm_smmu_tlb_inv_asid(smmu_domain->smmu, smmu_mn->cd->asid);
270-
arm_smmu_atc_inv_domain(smmu_domain, mm->pasid, 0, 0);
272+
arm_smmu_atc_inv_domain(smmu_domain, mm_get_enqcmd_pasid(mm), 0, 0);
271273

272274
smmu_mn->cleared = true;
273275
mutex_unlock(&sva_lock);
@@ -325,10 +327,13 @@ arm_smmu_mmu_notifier_get(struct arm_smmu_domain *smmu_domain,
325327

326328
spin_lock_irqsave(&smmu_domain->devices_lock, flags);
327329
list_for_each_entry(master, &smmu_domain->devices, domain_head) {
328-
ret = arm_smmu_write_ctx_desc(master, mm->pasid, cd);
330+
ret = arm_smmu_write_ctx_desc(master, mm_get_enqcmd_pasid(mm),
331+
cd);
329332
if (ret) {
330-
list_for_each_entry_from_reverse(master, &smmu_domain->devices, domain_head)
331-
arm_smmu_write_ctx_desc(master, mm->pasid, NULL);
333+
list_for_each_entry_from_reverse(
334+
master, &smmu_domain->devices, domain_head)
335+
arm_smmu_write_ctx_desc(
336+
master, mm_get_enqcmd_pasid(mm), NULL);
332337
break;
333338
}
334339
}
@@ -358,15 +363,17 @@ static void arm_smmu_mmu_notifier_put(struct arm_smmu_mmu_notifier *smmu_mn)
358363

359364
list_del(&smmu_mn->list);
360365

361-
arm_smmu_update_ctx_desc_devices(smmu_domain, mm->pasid, NULL);
366+
arm_smmu_update_ctx_desc_devices(smmu_domain, mm_get_enqcmd_pasid(mm),
367+
NULL);
362368

363369
/*
364370
* If we went through clear(), we've already invalidated, and no
365371
* new TLB entry can have been formed.
366372
*/
367373
if (!smmu_mn->cleared) {
368374
arm_smmu_tlb_inv_asid(smmu_domain->smmu, cd->asid);
369-
arm_smmu_atc_inv_domain(smmu_domain, mm->pasid, 0, 0);
375+
arm_smmu_atc_inv_domain(smmu_domain, mm_get_enqcmd_pasid(mm), 0,
376+
0);
370377
}
371378

372379
/* Frees smmu_mn */

drivers/iommu/iommu-sva.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ u32 iommu_sva_get_pasid(struct iommu_sva *handle)
141141
{
142142
struct iommu_domain *domain = handle->domain;
143143

144-
return domain->mm->pasid;
144+
return mm_get_enqcmd_pasid(domain->mm);
145145
}
146146
EXPORT_SYMBOL_GPL(iommu_sva_get_pasid);
147147

include/linux/iommu.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,6 +1346,12 @@ static inline bool mm_valid_pasid(struct mm_struct *mm)
13461346
{
13471347
return mm->pasid != IOMMU_PASID_INVALID;
13481348
}
1349+
1350+
static inline u32 mm_get_enqcmd_pasid(struct mm_struct *mm)
1351+
{
1352+
return mm->pasid;
1353+
}
1354+
13491355
void mm_pasid_drop(struct mm_struct *mm);
13501356
struct iommu_sva *iommu_sva_bind_device(struct device *dev,
13511357
struct mm_struct *mm);
@@ -1368,6 +1374,12 @@ static inline u32 iommu_sva_get_pasid(struct iommu_sva *handle)
13681374
}
13691375
static inline void mm_pasid_init(struct mm_struct *mm) {}
13701376
static inline bool mm_valid_pasid(struct mm_struct *mm) { return false; }
1377+
1378+
static inline u32 mm_get_enqcmd_pasid(struct mm_struct *mm)
1379+
{
1380+
return IOMMU_PASID_INVALID;
1381+
}
1382+
13711383
static inline void mm_pasid_drop(struct mm_struct *mm) {}
13721384
#endif /* CONFIG_IOMMU_SVA */
13731385

0 commit comments

Comments
 (0)