drm/panthor: Fix potential memleak of vma structure
Subsystems (3)
PATCH v2 1/1 drm/panthor: Fix potential memleak of vma structure
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)
--- drivers/gpu/drm/panthor/panthor_mmu.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/gpu/drm/panthor/panthor_mmu.c +15 -1
@@ -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.
Signature · 1 line
2.25.1
Quoted 9 lines · Akash Goel
This commit addresses a memleak issue of
panthor_vma(ordrm_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 <[email protected]>
Best regards,
Liviu
Quoted 42 lines
--- drivers/gpu/drm/panthor/panthor_mmu.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)drivers/gpu/drm/panthor/panthor_mmu.c +15
-1@@ -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. Signature · 1 line
2.25.1
Signature · 8 lines
====================
| I would like to |
| fix the world, |
| but they're not |
| giving me the |
\ source code! /
---------------
¯\_(ツ)_/¯Quoted 9 lines · On Mon, 20 Oct 2025 21:02:43 +0100 Akash Goel <[email protected]> wrote:
This commit addresses a memleak issue of
panthor_vma(ordrm_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 <[email protected]>
Just one minor thing below, but the patch is
regardless.
Quoted 12 lines
--- drivers/gpu/drm/panthor/panthor_mmu.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)drivers/gpu/drm/panthor/panthor_mmu.c +0
-0@@ -1146,6 +1146,18 @@ static void panthor_vm_cleanup_op_ctx(struct panthor_vm_op_ctx *op_ctx, } }
drivers/gpu/drm/panthor/panthor_mmu.c static void panthor_vm_cleanup_op_ctx(struct panthor_vm_op_ctx *op_ctx, · line 1158
Quoted 10 lines
drivers/gpu/drm/panthor/panthor_mmu.c +10
-0+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.
Quoted 17 lines
drivers/gpu/drm/panthor/panthor_mmu.c +5
-1+} +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.