[01/15] drm/tegra: Map cmdbuf once for reloc processing
diff mbox series

Message ID 20191118103536.17675-2-daniel.vetter@ffwll.ch
State New
Headers show
Series
  • Retire dma_buf_k(un)map
Related show

Commit Message

Daniel Vetter Nov. 18, 2019, 10:35 a.m. UTC
A few reasons to drop kmap:

- For native objects all we do is look at obj->vaddr anyway, so might
  as well not call functions for every page.

- Reloc-processing on dma-buf is ... questionable.

- Plus most dma-buf that bother kernel cpu mmaps give you at least
  vmap, much less kmaps. And all the ones relevant for arm-soc are
  again doing a obj->vaddr game anyway, there's no real kmap going on
  on arm it seems.

Plus this seems to be the only real in-tree user of dma_buf_kmap, and
I'd like to get rid of that.

Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Cc: Thierry Reding <thierry.reding@gmail.com>
Cc: linux-tegra@vger.kernel.org
---
 drivers/gpu/host1x/job.c | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

Comments

Daniel Vetter Nov. 25, 2019, 9:58 a.m. UTC | #1
On Mon, Nov 18, 2019 at 11:35:22AM +0100, Daniel Vetter wrote:
> A few reasons to drop kmap:
> 
> - For native objects all we do is look at obj->vaddr anyway, so might
>   as well not call functions for every page.
> 
> - Reloc-processing on dma-buf is ... questionable.
> 
> - Plus most dma-buf that bother kernel cpu mmaps give you at least
>   vmap, much less kmaps. And all the ones relevant for arm-soc are
>   again doing a obj->vaddr game anyway, there's no real kmap going on
>   on arm it seems.
> 
> Plus this seems to be the only real in-tree user of dma_buf_kmap, and
> I'd like to get rid of that.
> 
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> Cc: Thierry Reding <thierry.reding@gmail.com>
> Cc: linux-tegra@vger.kernel.org

Ping for testing/review on these first 2 tegra patches. They're holding up
the entire series, and I got acks for all the other bits surprisingly
fast. So would like to land this rather sooner than later. I'm also
working on a lot more dma-buf patches ...

Thanks, Daniel

> ---
>  drivers/gpu/host1x/job.c | 21 +++++++--------------
>  1 file changed, 7 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/gpu/host1x/job.c b/drivers/gpu/host1x/job.c
> index 25ca54de8fc5..60b2fedd0061 100644
> --- a/drivers/gpu/host1x/job.c
> +++ b/drivers/gpu/host1x/job.c
> @@ -244,8 +244,7 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job)
>  
>  static int do_relocs(struct host1x_job *job, struct host1x_job_gather *g)
>  {
> -	u32 last_page = ~0;
> -	void *cmdbuf_page_addr = NULL;
> +	void *cmdbuf_addr = NULL;
>  	struct host1x_bo *cmdbuf = g->bo;
>  	unsigned int i;
>  
> @@ -267,28 +266,22 @@ static int do_relocs(struct host1x_job *job, struct host1x_job_gather *g)
>  			goto patch_reloc;
>  		}
>  
> -		if (last_page != reloc->cmdbuf.offset >> PAGE_SHIFT) {
> -			if (cmdbuf_page_addr)
> -				host1x_bo_kunmap(cmdbuf, last_page,
> -						 cmdbuf_page_addr);
> +		if (!cmdbuf_addr) {
> +			cmdbuf_addr = host1x_bo_mmap(cmdbuf);
>  
> -			cmdbuf_page_addr = host1x_bo_kmap(cmdbuf,
> -					reloc->cmdbuf.offset >> PAGE_SHIFT);
> -			last_page = reloc->cmdbuf.offset >> PAGE_SHIFT;
> -
> -			if (unlikely(!cmdbuf_page_addr)) {
> +			if (unlikely(!cmdbuf_addr)) {
>  				pr_err("Could not map cmdbuf for relocation\n");
>  				return -ENOMEM;
>  			}
>  		}
>  
> -		target = cmdbuf_page_addr + (reloc->cmdbuf.offset & ~PAGE_MASK);
> +		target = cmdbuf_addr + reloc->cmdbuf.offset;
>  patch_reloc:
>  		*target = reloc_addr;
>  	}
>  
> -	if (cmdbuf_page_addr)
> -		host1x_bo_kunmap(cmdbuf, last_page, cmdbuf_page_addr);
> +	if (cmdbuf_addr)
> +		host1x_bo_munmap(cmdbuf, cmdbuf_addr);
>  
>  	return 0;
>  }
> -- 
> 2.24.0
>
Thierry Reding Nov. 25, 2019, 10:47 a.m. UTC | #2
On Mon, Nov 25, 2019 at 10:58:56AM +0100, Daniel Vetter wrote:
> On Mon, Nov 18, 2019 at 11:35:22AM +0100, Daniel Vetter wrote:
> > A few reasons to drop kmap:
> > 
> > - For native objects all we do is look at obj->vaddr anyway, so might
> >   as well not call functions for every page.
> > 
> > - Reloc-processing on dma-buf is ... questionable.
> > 
> > - Plus most dma-buf that bother kernel cpu mmaps give you at least
> >   vmap, much less kmaps. And all the ones relevant for arm-soc are
> >   again doing a obj->vaddr game anyway, there's no real kmap going on
> >   on arm it seems.
> > 
> > Plus this seems to be the only real in-tree user of dma_buf_kmap, and
> > I'd like to get rid of that.
> > 
> > Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> > Cc: Thierry Reding <thierry.reding@gmail.com>
> > Cc: linux-tegra@vger.kernel.org
> 
> Ping for testing/review on these first 2 tegra patches. They're holding up
> the entire series, and I got acks for all the other bits surprisingly
> fast. So would like to land this rather sooner than later. I'm also
> working on a lot more dma-buf patches ...

Right, I had forgotten about this series. Let me go test it right away.

Thierry

> > ---
> >  drivers/gpu/host1x/job.c | 21 +++++++--------------
> >  1 file changed, 7 insertions(+), 14 deletions(-)
> > 
> > diff --git a/drivers/gpu/host1x/job.c b/drivers/gpu/host1x/job.c
> > index 25ca54de8fc5..60b2fedd0061 100644
> > --- a/drivers/gpu/host1x/job.c
> > +++ b/drivers/gpu/host1x/job.c
> > @@ -244,8 +244,7 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job)
> >  
> >  static int do_relocs(struct host1x_job *job, struct host1x_job_gather *g)
> >  {
> > -	u32 last_page = ~0;
> > -	void *cmdbuf_page_addr = NULL;
> > +	void *cmdbuf_addr = NULL;
> >  	struct host1x_bo *cmdbuf = g->bo;
> >  	unsigned int i;
> >  
> > @@ -267,28 +266,22 @@ static int do_relocs(struct host1x_job *job, struct host1x_job_gather *g)
> >  			goto patch_reloc;
> >  		}
> >  
> > -		if (last_page != reloc->cmdbuf.offset >> PAGE_SHIFT) {
> > -			if (cmdbuf_page_addr)
> > -				host1x_bo_kunmap(cmdbuf, last_page,
> > -						 cmdbuf_page_addr);
> > +		if (!cmdbuf_addr) {
> > +			cmdbuf_addr = host1x_bo_mmap(cmdbuf);
> >  
> > -			cmdbuf_page_addr = host1x_bo_kmap(cmdbuf,
> > -					reloc->cmdbuf.offset >> PAGE_SHIFT);
> > -			last_page = reloc->cmdbuf.offset >> PAGE_SHIFT;
> > -
> > -			if (unlikely(!cmdbuf_page_addr)) {
> > +			if (unlikely(!cmdbuf_addr)) {
> >  				pr_err("Could not map cmdbuf for relocation\n");
> >  				return -ENOMEM;
> >  			}
> >  		}
> >  
> > -		target = cmdbuf_page_addr + (reloc->cmdbuf.offset & ~PAGE_MASK);
> > +		target = cmdbuf_addr + reloc->cmdbuf.offset;
> >  patch_reloc:
> >  		*target = reloc_addr;
> >  	}
> >  
> > -	if (cmdbuf_page_addr)
> > -		host1x_bo_kunmap(cmdbuf, last_page, cmdbuf_page_addr);
> > +	if (cmdbuf_addr)
> > +		host1x_bo_munmap(cmdbuf, cmdbuf_addr);
> >  
> >  	return 0;
> >  }
> > -- 
> > 2.24.0
> > 
> 
> -- 
> Daniel Vetter
> Software Engineer, Intel Corporation
> http://blog.ffwll.ch
Thierry Reding Nov. 25, 2019, 11:02 a.m. UTC | #3
On Mon, Nov 18, 2019 at 11:35:22AM +0100, Daniel Vetter wrote:
> A few reasons to drop kmap:
> 
> - For native objects all we do is look at obj->vaddr anyway, so might
>   as well not call functions for every page.
> 
> - Reloc-processing on dma-buf is ... questionable.
> 
> - Plus most dma-buf that bother kernel cpu mmaps give you at least
>   vmap, much less kmaps. And all the ones relevant for arm-soc are
>   again doing a obj->vaddr game anyway, there's no real kmap going on
>   on arm it seems.
> 
> Plus this seems to be the only real in-tree user of dma_buf_kmap, and
> I'd like to get rid of that.
> 
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> Cc: Thierry Reding <thierry.reding@gmail.com>
> Cc: linux-tegra@vger.kernel.org
> ---
>  drivers/gpu/host1x/job.c | 21 +++++++--------------
>  1 file changed, 7 insertions(+), 14 deletions(-)

This looks correct to me, and running some of the grate project's tests
against this works just fine, so:

Reviewed-by: Thierry Reding <treding@nvidia.com>
Tested-by: Thierry Reding <treding@nvidia.com>

> diff --git a/drivers/gpu/host1x/job.c b/drivers/gpu/host1x/job.c
> index 25ca54de8fc5..60b2fedd0061 100644
> --- a/drivers/gpu/host1x/job.c
> +++ b/drivers/gpu/host1x/job.c
> @@ -244,8 +244,7 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job)
>  
>  static int do_relocs(struct host1x_job *job, struct host1x_job_gather *g)
>  {
> -	u32 last_page = ~0;
> -	void *cmdbuf_page_addr = NULL;
> +	void *cmdbuf_addr = NULL;
>  	struct host1x_bo *cmdbuf = g->bo;
>  	unsigned int i;
>  
> @@ -267,28 +266,22 @@ static int do_relocs(struct host1x_job *job, struct host1x_job_gather *g)
>  			goto patch_reloc;
>  		}
>  
> -		if (last_page != reloc->cmdbuf.offset >> PAGE_SHIFT) {
> -			if (cmdbuf_page_addr)
> -				host1x_bo_kunmap(cmdbuf, last_page,
> -						 cmdbuf_page_addr);
> +		if (!cmdbuf_addr) {
> +			cmdbuf_addr = host1x_bo_mmap(cmdbuf);
>  
> -			cmdbuf_page_addr = host1x_bo_kmap(cmdbuf,
> -					reloc->cmdbuf.offset >> PAGE_SHIFT);
> -			last_page = reloc->cmdbuf.offset >> PAGE_SHIFT;
> -
> -			if (unlikely(!cmdbuf_page_addr)) {
> +			if (unlikely(!cmdbuf_addr)) {
>  				pr_err("Could not map cmdbuf for relocation\n");
>  				return -ENOMEM;
>  			}
>  		}
>  
> -		target = cmdbuf_page_addr + (reloc->cmdbuf.offset & ~PAGE_MASK);
> +		target = cmdbuf_addr + reloc->cmdbuf.offset;
>  patch_reloc:
>  		*target = reloc_addr;
>  	}
>  
> -	if (cmdbuf_page_addr)
> -		host1x_bo_kunmap(cmdbuf, last_page, cmdbuf_page_addr);
> +	if (cmdbuf_addr)
> +		host1x_bo_munmap(cmdbuf, cmdbuf_addr);
>  
>  	return 0;
>  }
> -- 
> 2.24.0
>

Patch
diff mbox series

diff --git a/drivers/gpu/host1x/job.c b/drivers/gpu/host1x/job.c
index 25ca54de8fc5..60b2fedd0061 100644
--- a/drivers/gpu/host1x/job.c
+++ b/drivers/gpu/host1x/job.c
@@ -244,8 +244,7 @@  static unsigned int pin_job(struct host1x *host, struct host1x_job *job)
 
 static int do_relocs(struct host1x_job *job, struct host1x_job_gather *g)
 {
-	u32 last_page = ~0;
-	void *cmdbuf_page_addr = NULL;
+	void *cmdbuf_addr = NULL;
 	struct host1x_bo *cmdbuf = g->bo;
 	unsigned int i;
 
@@ -267,28 +266,22 @@  static int do_relocs(struct host1x_job *job, struct host1x_job_gather *g)
 			goto patch_reloc;
 		}
 
-		if (last_page != reloc->cmdbuf.offset >> PAGE_SHIFT) {
-			if (cmdbuf_page_addr)
-				host1x_bo_kunmap(cmdbuf, last_page,
-						 cmdbuf_page_addr);
+		if (!cmdbuf_addr) {
+			cmdbuf_addr = host1x_bo_mmap(cmdbuf);
 
-			cmdbuf_page_addr = host1x_bo_kmap(cmdbuf,
-					reloc->cmdbuf.offset >> PAGE_SHIFT);
-			last_page = reloc->cmdbuf.offset >> PAGE_SHIFT;
-
-			if (unlikely(!cmdbuf_page_addr)) {
+			if (unlikely(!cmdbuf_addr)) {
 				pr_err("Could not map cmdbuf for relocation\n");
 				return -ENOMEM;
 			}
 		}
 
-		target = cmdbuf_page_addr + (reloc->cmdbuf.offset & ~PAGE_MASK);
+		target = cmdbuf_addr + reloc->cmdbuf.offset;
 patch_reloc:
 		*target = reloc_addr;
 	}
 
-	if (cmdbuf_page_addr)
-		host1x_bo_kunmap(cmdbuf, last_page, cmdbuf_page_addr);
+	if (cmdbuf_addr)
+		host1x_bo_munmap(cmdbuf, cmdbuf_addr);
 
 	return 0;
 }