On Mon, Jun 3, 2019 at 7:48 PM Rob Clark wrote:
>
> On Sun, Jun 2, 2019 at 11:25 PM Tomasz Figa wrote:
> >
> > On Mon, Jun 3, 2019 at 4:40 AM Rob Clark wrote:
> > >
> > > On Fri, May 10, 2019 at 7:35 AM Rob Clark wrote:
> > > >
> > > > On Tue, Dec 4, 2018 at 2:29 PM Rob Herring wrote:
> > > > >
> > > > > On Sat, Dec 1, 2018 at 10:54 AM Rob Clark wrote:
> > > > > >
> > > > > > This solves a problem we see with drm/msm, caused by getting
> > > > > > iommu_dma_ops while we attach our own domain and manage it directly
> > > > > > at
> > > > > > the iommu API level:
> > > > > >
> > > > > > [0038] user address but active_mm is swapper
> > > > > > Internal error: Oops: 9605 [#1] PREEMPT SMP
> > > > > > Modules linked in:
> > > > > > CPU: 7 PID: 70 Comm: kworker/7:1 Tainted: GW
> > > > > > 4.19.3 #90
> > > > > > Hardware name: xxx (DT)
> > > > > > Workqueue: events deferred_probe_work_func
> > > > > > pstate: 80c9 (Nzcv daif +PAN +UAO)
> > > > > > pc : iommu_dma_map_sg+0x7c/0x2c8
> > > > > > lr : iommu_dma_map_sg+0x40/0x2c8
> > > > > > sp : ff80095eb4f0
> > > > > > x29: ff80095eb4f0 x28:
> > > > > > x27: ffc0f9431578 x26:
> > > > > > x25: x24: 0003
> > > > > > x23: 0001 x22: ffc0fa9ac010
> > > > > > x21: x20: ffc0fab40980
> > > > > > x19: ffc0fab40980 x18: 0003
> > > > > > x17: 01c4 x16: 0007
> > > > > > x15: 000e x14:
> > > > > > x13: x12: 0028
> > > > > > x11: 0101010101010101 x10: 7f7f7f7f7f7f7f7f
> > > > > > x9 : x8 : ffc0fab409a0
> > > > > > x7 : x6 : 0002
> > > > > > x5 : 0001 x4 :
> > > > > > x3 : 0001 x2 : 0002
> > > > > > x1 : ffc0f9431578 x0 :
> > > > > > Process kworker/7:1 (pid: 70, stack limit = 0x17d08ffb)
> > > > > > Call trace:
> > > > > >iommu_dma_map_sg+0x7c/0x2c8
> > > > > >__iommu_map_sg_attrs+0x70/0x84
> > > > > >get_pages+0x170/0x1e8
> > > > > >msm_gem_get_iova+0x8c/0x128
> > > > > >_msm_gem_kernel_new+0x6c/0xc8
> > > > > >msm_gem_kernel_new+0x4c/0x58
> > > > > >dsi_tx_buf_alloc_6g+0x4c/0x8c
> > > > > >msm_dsi_host_modeset_init+0xc8/0x108
> > > > > >msm_dsi_modeset_init+0x54/0x18c
> > > > > >_dpu_kms_drm_obj_init+0x430/0x474
> > > > > >dpu_kms_hw_init+0x5f8/0x6b4
> > > > > >msm_drm_bind+0x360/0x6c8
> > > > > >try_to_bring_up_master.part.7+0x28/0x70
> > > > > >component_master_add_with_match+0xe8/0x124
> > > > > >msm_pdev_probe+0x294/0x2b4
> > > > > >platform_drv_probe+0x58/0xa4
> > > > > >really_probe+0x150/0x294
> > > > > >driver_probe_device+0xac/0xe8
> > > > > >__device_attach_driver+0xa4/0xb4
> > > > > >bus_for_each_drv+0x98/0xc8
> > > > > >__device_attach+0xac/0x12c
> > > > > >device_initial_probe+0x24/0x30
> > > > > >bus_probe_device+0x38/0x98
> > > > > >deferred_probe_work_func+0x78/0xa4
> > > > > >process_one_work+0x24c/0x3dc
> > > > > >worker_thread+0x280/0x360
> > > > > >kthread+0x134/0x13c
> > > > > >ret_from_fork+0x10/0x18
> > > > > > Code: d284 91000725 6b17039f 5400048a (f9401f40)
> > > > > > ---[ end trace f22dda57f3648e2c ]---
> > > > > > Kernel panic - not syncing: Fatal exception
> > > > > > SMP: stopping secondary CPUs
> > > > > > Kernel Offset: disabled
> > > > > > CPU features: 0x0,22802a18
> > > > > > Memory Limit: none
> > > > > >
> > > > > > The problem is that when drm/msm does it's own
> > > > > > iommu_attach_device(),
> > > > > > now the domain returned by iommu_get_domain_for_dev() is drm/msm's
> > > > > > domain, and it doesn't have domain->iova_cookie.
> > > > > >
> > > > > > We kind of avoided this problem prior to sdm845/dpu because the
> > > > > > iommu
> > > > > > was attached to the mdp node in dt, which is a child of the toplevel
> > > > > > mdss node (which corresponds to the dev passed in dma_map_sg()).
> > > > > > But
> > > > > > with sdm845, now the iommu is attached at the mdss level so we hit
> > > > > > the
> > > > > > iommu_dma_ops in dma_map_sg().
> > > > > >
> > > > > > But auto allocating/attaching a domain before the driver is probed
> > > > > > was
> > > > > > already a blocking problem for enabling per-context pagetables for
> > > > > > the
> > > > > > GPU. This problem is also now solved with this patch.
> > > > > >
> > > > > > Fixes: 97890ba9289c dma-mapping: detect and configure IOMMU in
> > > > > > of_dma_configure
> > > > > > Tested-by: Douglas Anderson
> > > > > > Signed-off-by: Rob Clark
> > > > > > ---
> > > > > > This is an alternative/replacement for [1]. What it lacks in
> > > > > > elegance
> > > > > > it makes up for in practicality ;-)
> > > > > >
> > > >