Skip to content

Commit cd0d0e4

Browse files
jgunthorpewilldeacon
authored andcommitted
iommu/vt-d: Lift the __pa to domain_setup_first_level/intel_svm_set_dev_pasid()
Pass the phys_addr_t down through the call chain from the top instead of passing a pgd_t * KVA. This moves the __pa() into domain_setup_first_level() which is the first function to obtain the pgd from the IOMMU page table in this call chain. The SVA flow is also adjusted to get the pa of the mm->pgd. iommput will move the __pa() into iommupt code, it never shares the KVA of the page table with the driver. Reviewed-by: Kevin Tian <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lu Baolu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 12724ce commit cd0d0e4

File tree

5 files changed

+25
-27
lines changed

5 files changed

+25
-27
lines changed

drivers/iommu/intel/iommu.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,15 +1736,14 @@ static void domain_context_clear_one(struct device_domain_info *info, u8 bus, u8
17361736
intel_context_flush_no_pasid(info, context, did);
17371737
}
17381738

1739-
int __domain_setup_first_level(struct intel_iommu *iommu,
1740-
struct device *dev, ioasid_t pasid,
1741-
u16 did, pgd_t *pgd, int flags,
1742-
struct iommu_domain *old)
1739+
int __domain_setup_first_level(struct intel_iommu *iommu, struct device *dev,
1740+
ioasid_t pasid, u16 did, phys_addr_t fsptptr,
1741+
int flags, struct iommu_domain *old)
17431742
{
17441743
if (!old)
1745-
return intel_pasid_setup_first_level(iommu, dev, pgd,
1746-
pasid, did, flags);
1747-
return intel_pasid_replace_first_level(iommu, dev, pgd, pasid, did,
1744+
return intel_pasid_setup_first_level(iommu, dev, fsptptr, pasid,
1745+
did, flags);
1746+
return intel_pasid_replace_first_level(iommu, dev, fsptptr, pasid, did,
17481747
iommu_domain_did(old, iommu),
17491748
flags);
17501749
}
@@ -1793,7 +1792,7 @@ static int domain_setup_first_level(struct intel_iommu *iommu,
17931792

17941793
return __domain_setup_first_level(iommu, dev, pasid,
17951794
domain_id_iommu(domain, iommu),
1796-
(pgd_t *)pgd, flags, old);
1795+
__pa(pgd), flags, old);
17971796
}
17981797

17991798
static bool domain_need_iotlb_sync_map(struct dmar_domain *domain,

drivers/iommu/intel/iommu.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,10 +1255,9 @@ domain_add_dev_pasid(struct iommu_domain *domain,
12551255
void domain_remove_dev_pasid(struct iommu_domain *domain,
12561256
struct device *dev, ioasid_t pasid);
12571257

1258-
int __domain_setup_first_level(struct intel_iommu *iommu,
1259-
struct device *dev, ioasid_t pasid,
1260-
u16 did, pgd_t *pgd, int flags,
1261-
struct iommu_domain *old);
1258+
int __domain_setup_first_level(struct intel_iommu *iommu, struct device *dev,
1259+
ioasid_t pasid, u16 did, phys_addr_t fsptptr,
1260+
int flags, struct iommu_domain *old);
12621261

12631262
int dmar_ir_support(void);
12641263

drivers/iommu/intel/pasid.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -348,14 +348,15 @@ static void intel_pasid_flush_present(struct intel_iommu *iommu,
348348
*/
349349
static void pasid_pte_config_first_level(struct intel_iommu *iommu,
350350
struct pasid_entry *pte,
351-
pgd_t *pgd, u16 did, int flags)
351+
phys_addr_t fsptptr, u16 did,
352+
int flags)
352353
{
353354
lockdep_assert_held(&iommu->lock);
354355

355356
pasid_clear_entry(pte);
356357

357358
/* Setup the first level page table pointer: */
358-
pasid_set_flptr(pte, (u64)__pa(pgd));
359+
pasid_set_flptr(pte, fsptptr);
359360

360361
if (flags & PASID_FLAG_FL5LP)
361362
pasid_set_flpm(pte, 1);
@@ -372,9 +373,9 @@ static void pasid_pte_config_first_level(struct intel_iommu *iommu,
372373
pasid_set_present(pte);
373374
}
374375

375-
int intel_pasid_setup_first_level(struct intel_iommu *iommu,
376-
struct device *dev, pgd_t *pgd,
377-
u32 pasid, u16 did, int flags)
376+
int intel_pasid_setup_first_level(struct intel_iommu *iommu, struct device *dev,
377+
phys_addr_t fsptptr, u32 pasid, u16 did,
378+
int flags)
378379
{
379380
struct pasid_entry *pte;
380381

@@ -402,7 +403,7 @@ int intel_pasid_setup_first_level(struct intel_iommu *iommu,
402403
return -EBUSY;
403404
}
404405

405-
pasid_pte_config_first_level(iommu, pte, pgd, did, flags);
406+
pasid_pte_config_first_level(iommu, pte, fsptptr, did, flags);
406407

407408
spin_unlock(&iommu->lock);
408409

@@ -412,7 +413,7 @@ int intel_pasid_setup_first_level(struct intel_iommu *iommu,
412413
}
413414

414415
int intel_pasid_replace_first_level(struct intel_iommu *iommu,
415-
struct device *dev, pgd_t *pgd,
416+
struct device *dev, phys_addr_t fsptptr,
416417
u32 pasid, u16 did, u16 old_did,
417418
int flags)
418419
{
@@ -430,7 +431,7 @@ int intel_pasid_replace_first_level(struct intel_iommu *iommu,
430431
return -EINVAL;
431432
}
432433

433-
pasid_pte_config_first_level(iommu, &new_pte, pgd, did, flags);
434+
pasid_pte_config_first_level(iommu, &new_pte, fsptptr, did, flags);
434435

435436
spin_lock(&iommu->lock);
436437
pte = intel_pasid_get_entry(dev, pasid);

drivers/iommu/intel/pasid.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,9 @@ extern unsigned int intel_pasid_max_id;
288288
int intel_pasid_alloc_table(struct device *dev);
289289
void intel_pasid_free_table(struct device *dev);
290290
struct pasid_table *intel_pasid_get_table(struct device *dev);
291-
int intel_pasid_setup_first_level(struct intel_iommu *iommu,
292-
struct device *dev, pgd_t *pgd,
293-
u32 pasid, u16 did, int flags);
291+
int intel_pasid_setup_first_level(struct intel_iommu *iommu, struct device *dev,
292+
phys_addr_t fsptptr, u32 pasid, u16 did,
293+
int flags);
294294
int intel_pasid_setup_second_level(struct intel_iommu *iommu,
295295
struct dmar_domain *domain,
296296
struct device *dev, u32 pasid);
@@ -302,9 +302,8 @@ int intel_pasid_setup_pass_through(struct intel_iommu *iommu,
302302
int intel_pasid_setup_nested(struct intel_iommu *iommu, struct device *dev,
303303
u32 pasid, struct dmar_domain *domain);
304304
int intel_pasid_replace_first_level(struct intel_iommu *iommu,
305-
struct device *dev, pgd_t *pgd,
306-
u32 pasid, u16 did, u16 old_did,
307-
int flags);
305+
struct device *dev, phys_addr_t fsptptr,
306+
u32 pasid, u16 did, u16 old_did, int flags);
308307
int intel_pasid_replace_second_level(struct intel_iommu *iommu,
309308
struct dmar_domain *domain,
310309
struct device *dev, u16 old_did,

drivers/iommu/intel/svm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ static int intel_svm_set_dev_pasid(struct iommu_domain *domain,
171171
/* Setup the pasid table: */
172172
sflags = cpu_feature_enabled(X86_FEATURE_LA57) ? PASID_FLAG_FL5LP : 0;
173173
ret = __domain_setup_first_level(iommu, dev, pasid,
174-
FLPT_DEFAULT_DID, mm->pgd,
174+
FLPT_DEFAULT_DID, __pa(mm->pgd),
175175
sflags, old);
176176
if (ret)
177177
goto out_unwind_iopf;

0 commit comments

Comments
 (0)