Message ID | 20210527230334.151947-1-paul@crapouillou.net (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | drm: Fix for GEM buffers with write-combine memory | expand |
On 28/05/2021 02:03, Paul Cercueil wrote: > The previous commit wrongly assumed that dma_mmap_wc() could be replaced > by pgprot_writecombine() + dma_mmap_pages(). It did work on my setup, > but did not work everywhere. > > Use dma_mmap_wc() when the buffer has the write-combine cache attribute, > and dma_mmap_pages() when it has the non-coherent cache attribute. > > Signed-off-by: Paul Cercueil <paul@crapouillou.net> > Reported-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> > Fixes: cf8ccbc72d61 ("drm: Add support for GEM buffers backed by non-coherent memory") > --- > drivers/gpu/drm/drm_gem_cma_helper.c | 16 ++++++++++------ > 1 file changed, 10 insertions(+), 6 deletions(-) > > diff --git a/drivers/gpu/drm/drm_gem_cma_helper.c b/drivers/gpu/drm/drm_gem_cma_helper.c > index 235c7a63da2b..4c3772651954 100644 > --- a/drivers/gpu/drm/drm_gem_cma_helper.c > +++ b/drivers/gpu/drm/drm_gem_cma_helper.c > @@ -514,13 +514,17 @@ int drm_gem_cma_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma) > > cma_obj = to_drm_gem_cma_obj(obj); > > - vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); > - if (!cma_obj->map_noncoherent) > - vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); > + if (cma_obj->map_noncoherent) { > + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); > + > + ret = dma_mmap_pages(cma_obj->base.dev->dev, > + vma, vma->vm_end - vma->vm_start, > + virt_to_page(cma_obj->vaddr)); > + } else { > + ret = dma_mmap_wc(cma_obj->base.dev->dev, vma, cma_obj->vaddr, > + cma_obj->paddr, vma->vm_end - vma->vm_start); > > - ret = dma_mmap_pages(cma_obj->base.dev->dev, > - vma, vma->vm_end - vma->vm_start, > - virt_to_page(cma_obj->vaddr)); > + } > if (ret) > drm_gem_vm_close(vma); > > Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> and Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> Thanks! Btw, the kernel-doc for drm_gem_cma_create doesn't quite match, as it says wc is always used. Tomi
Hi Tomi, Le ven., mai 28 2021 at 08:59:15 +0300, Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> a écrit : > On 28/05/2021 02:03, Paul Cercueil wrote: >> The previous commit wrongly assumed that dma_mmap_wc() could be >> replaced >> by pgprot_writecombine() + dma_mmap_pages(). It did work on my setup, >> but did not work everywhere. >> >> Use dma_mmap_wc() when the buffer has the write-combine cache >> attribute, >> and dma_mmap_pages() when it has the non-coherent cache attribute. >> >> Signed-off-by: Paul Cercueil <paul@crapouillou.net> >> Reported-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> >> Fixes: cf8ccbc72d61 ("drm: Add support for GEM buffers backed by >> non-coherent memory") >> --- >> drivers/gpu/drm/drm_gem_cma_helper.c | 16 ++++++++++------ >> 1 file changed, 10 insertions(+), 6 deletions(-) >> >> diff --git a/drivers/gpu/drm/drm_gem_cma_helper.c >> b/drivers/gpu/drm/drm_gem_cma_helper.c >> index 235c7a63da2b..4c3772651954 100644 >> --- a/drivers/gpu/drm/drm_gem_cma_helper.c >> +++ b/drivers/gpu/drm/drm_gem_cma_helper.c >> @@ -514,13 +514,17 @@ int drm_gem_cma_mmap(struct drm_gem_object >> *obj, struct vm_area_struct *vma) >> cma_obj = to_drm_gem_cma_obj(obj); >> - vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); >> - if (!cma_obj->map_noncoherent) >> - vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); >> + if (cma_obj->map_noncoherent) { >> + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); >> + >> + ret = dma_mmap_pages(cma_obj->base.dev->dev, >> + vma, vma->vm_end - vma->vm_start, >> + virt_to_page(cma_obj->vaddr)); >> + } else { >> + ret = dma_mmap_wc(cma_obj->base.dev->dev, vma, cma_obj->vaddr, >> + cma_obj->paddr, vma->vm_end - vma->vm_start); >> - ret = dma_mmap_pages(cma_obj->base.dev->dev, >> - vma, vma->vm_end - vma->vm_start, >> - virt_to_page(cma_obj->vaddr)); >> + } >> if (ret) >> drm_gem_vm_close(vma); >> > > Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> > > and > > Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> Thanks, I applied it now. > > Thanks! > > Btw, the kernel-doc for drm_gem_cma_create doesn't quite match, as it > says wc is always used. Alright, I'll send a patch later for this one too. Cheers, -Paul
diff --git a/drivers/gpu/drm/drm_gem_cma_helper.c b/drivers/gpu/drm/drm_gem_cma_helper.c index 235c7a63da2b..4c3772651954 100644 --- a/drivers/gpu/drm/drm_gem_cma_helper.c +++ b/drivers/gpu/drm/drm_gem_cma_helper.c @@ -514,13 +514,17 @@ int drm_gem_cma_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma) cma_obj = to_drm_gem_cma_obj(obj); - vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); - if (!cma_obj->map_noncoherent) - vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); + if (cma_obj->map_noncoherent) { + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); + + ret = dma_mmap_pages(cma_obj->base.dev->dev, + vma, vma->vm_end - vma->vm_start, + virt_to_page(cma_obj->vaddr)); + } else { + ret = dma_mmap_wc(cma_obj->base.dev->dev, vma, cma_obj->vaddr, + cma_obj->paddr, vma->vm_end - vma->vm_start); - ret = dma_mmap_pages(cma_obj->base.dev->dev, - vma, vma->vm_end - vma->vm_start, - virt_to_page(cma_obj->vaddr)); + } if (ret) drm_gem_vm_close(vma);
The previous commit wrongly assumed that dma_mmap_wc() could be replaced by pgprot_writecombine() + dma_mmap_pages(). It did work on my setup, but did not work everywhere. Use dma_mmap_wc() when the buffer has the write-combine cache attribute, and dma_mmap_pages() when it has the non-coherent cache attribute. Signed-off-by: Paul Cercueil <paul@crapouillou.net> Reported-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> Fixes: cf8ccbc72d61 ("drm: Add support for GEM buffers backed by non-coherent memory") --- drivers/gpu/drm/drm_gem_cma_helper.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)