[PATCH] drm/imagination: Free pvr_vm_gpuva after unlink

Matt Coster posted 1 patch 1 year, 3 months ago
There is a newer version of this series
drivers/gpu/drm/imagination/pvr_vm.c | 4 ++++
1 file changed, 4 insertions(+)
[PATCH] drm/imagination: Free pvr_vm_gpuva after unlink
Posted by Matt Coster 1 year, 3 months ago
This caused a measurable memory leak. Although the individual
allocations are small, the leaks occurs in a high-usage codepath
(remapping or unmapping device memory) so they add up quickly.

Signed-off-by: Matt Coster <matt.coster@imgtec.com>
Fixes: ff5f643de0bf ("drm/imagination: Add GEM and VM related code")
Cc: stable@vger.kernel.org
---
  drivers/gpu/drm/imagination/pvr_vm.c | 4 ++++
  1 file changed, 4 insertions(+)

diff --git a/drivers/gpu/drm/imagination/pvr_vm.c 
b/drivers/gpu/drm/imagination/pvr_vm.c
index e59517ba039e..97c0f772ed65 100644
--- a/drivers/gpu/drm/imagination/pvr_vm.c
+++ b/drivers/gpu/drm/imagination/pvr_vm.c
@@ -114,6 +114,8 @@ struct pvr_vm_gpuva {
  	struct drm_gpuva base;
  };
  +#define to_pvr_vm_gpuva(va) container_of_const(va, struct 
pvr_vm_gpuva, base)
+
  enum pvr_vm_bind_type {
  	PVR_VM_BIND_TYPE_MAP,
  	PVR_VM_BIND_TYPE_UNMAP,
@@ -386,6 +388,7 @@ pvr_vm_gpuva_unmap(struct drm_gpuva_op *op, void 
*op_ctx)
   	drm_gpuva_unmap(&op->unmap);
  	drm_gpuva_unlink(op->unmap.va);
+	kfree(to_pvr_vm_gpuva(op->unmap.va));
   	return 0;
  }
@@ -433,6 +436,7 @@ pvr_vm_gpuva_remap(struct drm_gpuva_op *op, void 
*op_ctx)
  	}
   	drm_gpuva_unlink(op->remap.unmap->va);
+	kfree(to_pvr_vm_gpuva(op->remap.unmap->va));
   	return 0;
  }
-- 
2.46.0


Re: [PATCH] drm/imagination: Free pvr_vm_gpuva after unlink
Posted by Frank Binns 1 year, 3 months ago
On Wed, 2024-08-28 at 13:13 +0000, Matt Coster wrote:
> This caused a measurable memory leak. Although the individual
> allocations are small, the leaks occurs in a high-usage codepath
> (remapping or unmapping device memory) so they add up quickly.
> 

Reviewed-by: Frank Binns <frank.binns@imgtec.com>

> Signed-off-by: Matt Coster <matt.coster@imgtec.com>
> Fixes: ff5f643de0bf ("drm/imagination: Add GEM and VM related code")
> Cc: stable@vger.kernel.org
> ---
>   drivers/gpu/drm/imagination/pvr_vm.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/gpu/drm/imagination/pvr_vm.c 
> b/drivers/gpu/drm/imagination/pvr_vm.c
> index e59517ba039e..97c0f772ed65 100644
> --- a/drivers/gpu/drm/imagination/pvr_vm.c
> +++ b/drivers/gpu/drm/imagination/pvr_vm.c
> @@ -114,6 +114,8 @@ struct pvr_vm_gpuva {
>   	struct drm_gpuva base;
>   };
>   +#define to_pvr_vm_gpuva(va) container_of_const(va, struct 
> pvr_vm_gpuva, base)
> +
>   enum pvr_vm_bind_type {
>   	PVR_VM_BIND_TYPE_MAP,
>   	PVR_VM_BIND_TYPE_UNMAP,
> @@ -386,6 +388,7 @@ pvr_vm_gpuva_unmap(struct drm_gpuva_op *op, void 
> *op_ctx)
>    	drm_gpuva_unmap(&op->unmap);
>   	drm_gpuva_unlink(op->unmap.va);
> +	kfree(to_pvr_vm_gpuva(op->unmap.va));
>    	return 0;
>   }
> @@ -433,6 +436,7 @@ pvr_vm_gpuva_remap(struct drm_gpuva_op *op, void 
> *op_ctx)
>   	}
>    	drm_gpuva_unlink(op->remap.unmap->va);
> +	kfree(to_pvr_vm_gpuva(op->remap.unmap->va));
>    	return 0;
>   }
> -- 
> 2.46.0
> 
> 
[PATCH RESEND] drm/imagination: Free pvr_vm_gpuva after unlink
Posted by Matt Coster 1 year, 3 months ago
This caused a measurable memory leak. Although the individual
allocations are small, the leaks occurs in a high-usage codepath
(remapping or unmapping device memory) so they add up quickly.

Signed-off-by: Matt Coster <matt.coster@imgtec.com>
Fixes: ff5f643de0bf ("drm/imagination: Add GEM and VM related code")
Cc: stable@vger.kernel.org
---
 drivers/gpu/drm/imagination/pvr_vm.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/gpu/drm/imagination/pvr_vm.c b/drivers/gpu/drm/imagination/pvr_vm.c
index e59517ba039e..97c0f772ed65 100644
--- a/drivers/gpu/drm/imagination/pvr_vm.c
+++ b/drivers/gpu/drm/imagination/pvr_vm.c
@@ -114,6 +114,8 @@ struct pvr_vm_gpuva {
 	struct drm_gpuva base;
 };
 
+#define to_pvr_vm_gpuva(va) container_of_const(va, struct pvr_vm_gpuva, base)
+
 enum pvr_vm_bind_type {
 	PVR_VM_BIND_TYPE_MAP,
 	PVR_VM_BIND_TYPE_UNMAP,
@@ -386,6 +388,7 @@ pvr_vm_gpuva_unmap(struct drm_gpuva_op *op, void *op_ctx)
 
 	drm_gpuva_unmap(&op->unmap);
 	drm_gpuva_unlink(op->unmap.va);
+	kfree(to_pvr_vm_gpuva(op->unmap.va));
 
 	return 0;
 }
@@ -433,6 +436,7 @@ pvr_vm_gpuva_remap(struct drm_gpuva_op *op, void *op_ctx)
 	}
 
 	drm_gpuva_unlink(op->remap.unmap->va);
+	kfree(to_pvr_vm_gpuva(op->remap.unmap->va));
 
 	return 0;
 }
-- 
2.46.0


Re: [PATCH RESEND] drm/imagination: Free pvr_vm_gpuva after unlink
Posted by Frank Binns 1 year, 3 months ago
On Fri, 2024-08-30 at 15:07 +0000, Matt Coster wrote:
> This caused a measurable memory leak. Although the individual
> allocations are small, the leaks occurs in a high-usage codepath
> (remapping or unmapping device memory) so they add up quickly.
> 

Reviewed-by: Frank Binns <frank.binns@imgtec.com>

> Signed-off-by: Matt Coster <matt.coster@imgtec.com>
> Fixes: ff5f643de0bf ("drm/imagination: Add GEM and VM related code")
> Cc: stable@vger.kernel.org
> ---
>  drivers/gpu/drm/imagination/pvr_vm.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/gpu/drm/imagination/pvr_vm.c b/drivers/gpu/drm/imagination/pvr_vm.c
> index e59517ba039e..97c0f772ed65 100644
> --- a/drivers/gpu/drm/imagination/pvr_vm.c
> +++ b/drivers/gpu/drm/imagination/pvr_vm.c
> @@ -114,6 +114,8 @@ struct pvr_vm_gpuva {
>  	struct drm_gpuva base;
>  };
>  
> +#define to_pvr_vm_gpuva(va) container_of_const(va, struct pvr_vm_gpuva, base)
> +
>  enum pvr_vm_bind_type {
>  	PVR_VM_BIND_TYPE_MAP,
>  	PVR_VM_BIND_TYPE_UNMAP,
> @@ -386,6 +388,7 @@ pvr_vm_gpuva_unmap(struct drm_gpuva_op *op, void *op_ctx)
>  
>  	drm_gpuva_unmap(&op->unmap);
>  	drm_gpuva_unlink(op->unmap.va);
> +	kfree(to_pvr_vm_gpuva(op->unmap.va));
>  
>  	return 0;
>  }
> @@ -433,6 +436,7 @@ pvr_vm_gpuva_remap(struct drm_gpuva_op *op, void *op_ctx)
>  	}
>  
>  	drm_gpuva_unlink(op->remap.unmap->va);
> +	kfree(to_pvr_vm_gpuva(op->remap.unmap->va));
>  
>  	return 0;
>  }