Skip to content

Commit 8c7bfd8

Browse files
committed
drm/msm: Wire up tlb ops
The brute force iommu_flush_iotlb_all() was good enough for unmap, but in some cases a map operation could require removing a table pte entry to replace with a block entry. This also requires tlb invalidation. Missing this was resulting an obscure iova fault on what should be a valid buffer address. Thanks to Robin Murphy for helping me understand the cause of the fault. Cc: Robin Murphy <robin.murphy@arm.com> Cc: stable@vger.kernel.org Fixes: b145c6e ("drm/msm: Add support to create a local pagetable") Signed-off-by: Rob Clark <robdclark@chromium.org> Patchwork: https://patchwork.freedesktop.org/patch/578117/
1 parent 917e9b7 commit 8c7bfd8

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

drivers/gpu/drm/msm/msm_iommu.c

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ struct msm_iommu_pagetable {
2121
struct msm_mmu base;
2222
struct msm_mmu *parent;
2323
struct io_pgtable_ops *pgtbl_ops;
24+
const struct iommu_flush_ops *tlb;
25+
struct device *iommu_dev;
2426
unsigned long pgsize_bitmap; /* Bitmap of page sizes in use */
2527
phys_addr_t ttbr;
2628
u32 asid;
@@ -201,19 +203,41 @@ static const struct msm_mmu_funcs pagetable_funcs = {
201203

202204
static void msm_iommu_tlb_flush_all(void *cookie)
203205
{
206+
struct msm_iommu_pagetable *pagetable = cookie;
207+
struct adreno_smmu_priv *adreno_smmu;
208+
209+
if (!pm_runtime_get_if_in_use(pagetable->iommu_dev))
210+
return;
211+
212+
adreno_smmu = dev_get_drvdata(pagetable->parent->dev);
213+
214+
pagetable->tlb->tlb_flush_all((void *)adreno_smmu->cookie);
215+
216+
pm_runtime_put_autosuspend(pagetable->iommu_dev);
204217
}
205218

206219
static void msm_iommu_tlb_flush_walk(unsigned long iova, size_t size,
207220
size_t granule, void *cookie)
208221
{
222+
struct msm_iommu_pagetable *pagetable = cookie;
223+
struct adreno_smmu_priv *adreno_smmu;
224+
225+
if (!pm_runtime_get_if_in_use(pagetable->iommu_dev))
226+
return;
227+
228+
adreno_smmu = dev_get_drvdata(pagetable->parent->dev);
229+
230+
pagetable->tlb->tlb_flush_walk(iova, size, granule, (void *)adreno_smmu->cookie);
231+
232+
pm_runtime_put_autosuspend(pagetable->iommu_dev);
209233
}
210234

211235
static void msm_iommu_tlb_add_page(struct iommu_iotlb_gather *gather,
212236
unsigned long iova, size_t granule, void *cookie)
213237
{
214238
}
215239

216-
static const struct iommu_flush_ops null_tlb_ops = {
240+
static const struct iommu_flush_ops tlb_ops = {
217241
.tlb_flush_all = msm_iommu_tlb_flush_all,
218242
.tlb_flush_walk = msm_iommu_tlb_flush_walk,
219243
.tlb_add_page = msm_iommu_tlb_add_page,
@@ -254,10 +278,10 @@ struct msm_mmu *msm_iommu_pagetable_create(struct msm_mmu *parent)
254278

255279
/* The incoming cfg will have the TTBR1 quirk enabled */
256280
ttbr0_cfg.quirks &= ~IO_PGTABLE_QUIRK_ARM_TTBR1;
257-
ttbr0_cfg.tlb = &null_tlb_ops;
281+
ttbr0_cfg.tlb = &tlb_ops;
258282

259283
pagetable->pgtbl_ops = alloc_io_pgtable_ops(ARM_64_LPAE_S1,
260-
&ttbr0_cfg, iommu->domain);
284+
&ttbr0_cfg, pagetable);
261285

262286
if (!pagetable->pgtbl_ops) {
263287
kfree(pagetable);
@@ -279,6 +303,8 @@ struct msm_mmu *msm_iommu_pagetable_create(struct msm_mmu *parent)
279303

280304
/* Needed later for TLB flush */
281305
pagetable->parent = parent;
306+
pagetable->tlb = ttbr1_cfg->tlb;
307+
pagetable->iommu_dev = ttbr1_cfg->iommu_dev;
282308
pagetable->pgsize_bitmap = ttbr0_cfg.pgsize_bitmap;
283309
pagetable->ttbr = ttbr0_cfg.arm_lpae_s1_cfg.ttbr;
284310

0 commit comments

Comments
 (0)