public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] drm/panthor: Fix potential memleak of vma structure
@ 2025-10-20 20:02 Akash Goel
  2025-10-20 21:59 ` Liviu Dudau
  2025-10-21  7:41 ` Boris Brezillon
  0 siblings, 2 replies; 3+ messages in thread
From: Akash Goel @ 2025-10-20 20:02 UTC (permalink / raw)
  To: boris.brezillon, liviu.dudau, steven.price
  Cc: dri-devel, linux-kernel, maarten.lankhorst, mripard, tzimmermann,
	airlied, daniel, nd, Akash Goel

This commit addresses a memleak issue of panthor_vma (or drm_gpuva)
structure in Panthor driver, that can happen if the GPU page table
update operation to map the pages fail.
The issue is very unlikely to occur in practice.

v2: Add panthor_vm_op_ctx_return_vma() helper (Boris)

Fixes: 647810ec2476 ("drm/panthor: Add the MMU/VM logical block")
Signed-off-by: Akash Goel <akash.goel@arm.com>
---
 drivers/gpu/drm/panthor/panthor_mmu.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c
index 6dec4354e378..63af8ee89b08 100644
--- a/drivers/gpu/drm/panthor/panthor_mmu.c
+++ b/drivers/gpu/drm/panthor/panthor_mmu.c
@@ -1146,6 +1146,18 @@ static void panthor_vm_cleanup_op_ctx(struct panthor_vm_op_ctx *op_ctx,
 	}
 }
 
+static void
+panthor_vm_op_ctx_return_vma(struct panthor_vm_op_ctx *op_ctx,
+			     struct panthor_vma *vma)
+{
+	for (u32 i = 0; i < ARRAY_SIZE(op_ctx->preallocated_vmas); i++) {
+		if (!op_ctx->preallocated_vmas[i]) {
+			op_ctx->preallocated_vmas[i] = vma;
+			return;
+		}
+	}
+}
+
 static struct panthor_vma *
 panthor_vm_op_ctx_get_vma(struct panthor_vm_op_ctx *op_ctx)
 {
@@ -2081,8 +2093,10 @@ static int panthor_gpuva_sm_step_map(struct drm_gpuva_op *op, void *priv)
 	ret = panthor_vm_map_pages(vm, op->map.va.addr, flags_to_prot(vma->flags),
 				   op_ctx->map.sgt, op->map.gem.offset,
 				   op->map.va.range);
-	if (ret)
+	if (ret) {
+		panthor_vm_op_ctx_return_vma(op_ctx, vma);
 		return ret;
+	}
 
 	/* Ref owned by the mapping now, clear the obj field so we don't release the
 	 * pinning/obj ref behind GPUVA's back.
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] drm/panthor: Fix potential memleak of vma structure
  2025-10-20 20:02 [PATCH v2] drm/panthor: Fix potential memleak of vma structure Akash Goel
@ 2025-10-20 21:59 ` Liviu Dudau
  2025-10-21  7:41 ` Boris Brezillon
  1 sibling, 0 replies; 3+ messages in thread
From: Liviu Dudau @ 2025-10-20 21:59 UTC (permalink / raw)
  To: Akash Goel
  Cc: boris.brezillon, steven.price, dri-devel, linux-kernel,
	maarten.lankhorst, mripard, tzimmermann, airlied, daniel, nd

On Mon, Oct 20, 2025 at 09:02:43PM +0100, Akash Goel wrote:
> This commit addresses a memleak issue of panthor_vma (or drm_gpuva)
> structure in Panthor driver, that can happen if the GPU page table
> update operation to map the pages fail.
> The issue is very unlikely to occur in practice.
> 
> v2: Add panthor_vm_op_ctx_return_vma() helper (Boris)
> 
> Fixes: 647810ec2476 ("drm/panthor: Add the MMU/VM logical block")
> Signed-off-by: Akash Goel <akash.goel@arm.com>

Reviewed-by: Liviu Dudau <liviu.dudau@arm.com>

Best regards,
Liviu

> ---
>  drivers/gpu/drm/panthor/panthor_mmu.c | 16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c
> index 6dec4354e378..63af8ee89b08 100644
> --- a/drivers/gpu/drm/panthor/panthor_mmu.c
> +++ b/drivers/gpu/drm/panthor/panthor_mmu.c
> @@ -1146,6 +1146,18 @@ static void panthor_vm_cleanup_op_ctx(struct panthor_vm_op_ctx *op_ctx,
>  	}
>  }
>  
> +static void
> +panthor_vm_op_ctx_return_vma(struct panthor_vm_op_ctx *op_ctx,
> +			     struct panthor_vma *vma)
> +{
> +	for (u32 i = 0; i < ARRAY_SIZE(op_ctx->preallocated_vmas); i++) {
> +		if (!op_ctx->preallocated_vmas[i]) {
> +			op_ctx->preallocated_vmas[i] = vma;
> +			return;
> +		}
> +	}
> +}
> +
>  static struct panthor_vma *
>  panthor_vm_op_ctx_get_vma(struct panthor_vm_op_ctx *op_ctx)
>  {
> @@ -2081,8 +2093,10 @@ static int panthor_gpuva_sm_step_map(struct drm_gpuva_op *op, void *priv)
>  	ret = panthor_vm_map_pages(vm, op->map.va.addr, flags_to_prot(vma->flags),
>  				   op_ctx->map.sgt, op->map.gem.offset,
>  				   op->map.va.range);
> -	if (ret)
> +	if (ret) {
> +		panthor_vm_op_ctx_return_vma(op_ctx, vma);
>  		return ret;
> +	}
>  
>  	/* Ref owned by the mapping now, clear the obj field so we don't release the
>  	 * pinning/obj ref behind GPUVA's back.
> -- 
> 2.25.1
> 

-- 
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] drm/panthor: Fix potential memleak of vma structure
  2025-10-20 20:02 [PATCH v2] drm/panthor: Fix potential memleak of vma structure Akash Goel
  2025-10-20 21:59 ` Liviu Dudau
@ 2025-10-21  7:41 ` Boris Brezillon
  1 sibling, 0 replies; 3+ messages in thread
From: Boris Brezillon @ 2025-10-21  7:41 UTC (permalink / raw)
  To: Akash Goel
  Cc: liviu.dudau, steven.price, dri-devel, linux-kernel,
	maarten.lankhorst, mripard, tzimmermann, airlied, daniel, nd

On Mon, 20 Oct 2025 21:02:43 +0100
Akash Goel <akash.goel@arm.com> wrote:

> This commit addresses a memleak issue of panthor_vma (or drm_gpuva)
> structure in Panthor driver, that can happen if the GPU page table
> update operation to map the pages fail.
> The issue is very unlikely to occur in practice.
> 
> v2: Add panthor_vm_op_ctx_return_vma() helper (Boris)
> 
> Fixes: 647810ec2476 ("drm/panthor: Add the MMU/VM logical block")
> Signed-off-by: Akash Goel <akash.goel@arm.com>

Just one minor thing below, but the patch is

Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>

regardless.

> ---
>  drivers/gpu/drm/panthor/panthor_mmu.c | 16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c
> index 6dec4354e378..63af8ee89b08 100644
> --- a/drivers/gpu/drm/panthor/panthor_mmu.c
> +++ b/drivers/gpu/drm/panthor/panthor_mmu.c
> @@ -1146,6 +1146,18 @@ static void panthor_vm_cleanup_op_ctx(struct panthor_vm_op_ctx *op_ctx,
>  	}
>  }
>  
> +static void
> +panthor_vm_op_ctx_return_vma(struct panthor_vm_op_ctx *op_ctx,
> +			     struct panthor_vma *vma)
> +{
> +	for (u32 i = 0; i < ARRAY_SIZE(op_ctx->preallocated_vmas); i++) {
> +		if (!op_ctx->preallocated_vmas[i]) {
> +			op_ctx->preallocated_vmas[i] = vma;
> +			return;
> +		}
> +	}

Maybe add a WARN_ON_ONCE() here.

> +}
> +
>  static struct panthor_vma *
>  panthor_vm_op_ctx_get_vma(struct panthor_vm_op_ctx *op_ctx)
>  {
> @@ -2081,8 +2093,10 @@ static int panthor_gpuva_sm_step_map(struct drm_gpuva_op *op, void *priv)
>  	ret = panthor_vm_map_pages(vm, op->map.va.addr, flags_to_prot(vma->flags),
>  				   op_ctx->map.sgt, op->map.gem.offset,
>  				   op->map.va.range);
> -	if (ret)
> +	if (ret) {
> +		panthor_vm_op_ctx_return_vma(op_ctx, vma);
>  		return ret;
> +	}
>  
>  	/* Ref owned by the mapping now, clear the obj field so we don't release the
>  	 * pinning/obj ref behind GPUVA's back.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-10-21  7:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-20 20:02 [PATCH v2] drm/panthor: Fix potential memleak of vma structure Akash Goel
2025-10-20 21:59 ` Liviu Dudau
2025-10-21  7:41 ` Boris Brezillon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox