All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] s390/vfio-ap: Fix module unload memory leak of matrix_dev
@ 2021-06-18 13:35 Jason J. Herne
  2021-06-18 14:10 ` Jason Gunthorpe
  2021-06-18 15:31 ` Tony Krowiak
  0 siblings, 2 replies; 5+ messages in thread
From: Jason J. Herne @ 2021-06-18 13:35 UTC (permalink / raw)
  To: linux-s390; +Cc: linux-kernel, pasic, akrowiak, jgg

vfio_ap_matrix_dev_release is shadowing the global matrix_dev with driver
data that never gets set. So when release is called we end up not freeing
matrix_dev. The fix is to remove the shadow variable and just free the
global.

Signed-off-by: Jason J. Herne <jjherne@linux.ibm.com>
---
 drivers/s390/crypto/vfio_ap_drv.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/s390/crypto/vfio_ap_drv.c b/drivers/s390/crypto/vfio_ap_drv.c
index 7dc72cb718b0..6d3eea838e18 100644
--- a/drivers/s390/crypto/vfio_ap_drv.c
+++ b/drivers/s390/crypto/vfio_ap_drv.c
@@ -82,8 +82,6 @@ static void vfio_ap_queue_dev_remove(struct ap_device *apdev)
 
 static void vfio_ap_matrix_dev_release(struct device *dev)
 {
-	struct ap_matrix_dev *matrix_dev = dev_get_drvdata(dev);
-
 	kfree(matrix_dev);
 }
 
-- 
2.21.1


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

* Re: [PATCH] s390/vfio-ap: Fix module unload memory leak of matrix_dev
  2021-06-18 13:35 [PATCH] s390/vfio-ap: Fix module unload memory leak of matrix_dev Jason J. Herne
@ 2021-06-18 14:10 ` Jason Gunthorpe
  2021-06-18 14:35   ` Jason J. Herne
  2021-06-18 15:31 ` Tony Krowiak
  1 sibling, 1 reply; 5+ messages in thread
From: Jason Gunthorpe @ 2021-06-18 14:10 UTC (permalink / raw)
  To: Jason J. Herne; +Cc: linux-s390, linux-kernel, pasic, akrowiak

On Fri, Jun 18, 2021 at 09:35:24AM -0400, Jason J. Herne wrote:
> vfio_ap_matrix_dev_release is shadowing the global matrix_dev with driver
> data that never gets set. So when release is called we end up not freeing
> matrix_dev. The fix is to remove the shadow variable and just free the
> global.

I would clarify this commit message to say that the drv_data of the
matrix_dev is never set and so dev_get_drvdata() always returns NULL

And I would suggest to use 

  container_of(dev, struct ap_matrix_dev, dev)

instead of the global variable, and probably NULL the global
too..

Jason


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

* Re: [PATCH] s390/vfio-ap: Fix module unload memory leak of matrix_dev
  2021-06-18 14:10 ` Jason Gunthorpe
@ 2021-06-18 14:35   ` Jason J. Herne
  2021-06-18 14:59     ` Jason Gunthorpe
  0 siblings, 1 reply; 5+ messages in thread
From: Jason J. Herne @ 2021-06-18 14:35 UTC (permalink / raw)
  To: Jason Gunthorpe; +Cc: linux-s390, linux-kernel, pasic, akrowiak

On 6/18/21 10:10 AM, Jason Gunthorpe wrote:
> On Fri, Jun 18, 2021 at 09:35:24AM -0400, Jason J. Herne wrote:
>> vfio_ap_matrix_dev_release is shadowing the global matrix_dev with driver
>> data that never gets set. So when release is called we end up not freeing
>> matrix_dev. The fix is to remove the shadow variable and just free the
>> global.
> 
> I would clarify this commit message to say that the drv_data of the
> matrix_dev is never set and so dev_get_drvdata() always returns NULL
> 
> And I would suggest to use
> 
>    container_of(dev, struct ap_matrix_dev, dev)
> 
> instead of the global variable, and probably NULL the global
> too..
> 

The use of driver_data seems to have been completely erroneous here. In this
case the global matrix_dev is the top level struct. It is not contained in
anything. matrix_dev is created upon module load, and it is freed when the
module exits.

So I don't think using container_of makes sense. Unless I've
misunderstood your suggestion?

-- 
-- Jason J. Herne (jjherne@linux.ibm.com)

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

* Re: [PATCH] s390/vfio-ap: Fix module unload memory leak of matrix_dev
  2021-06-18 14:35   ` Jason J. Herne
@ 2021-06-18 14:59     ` Jason Gunthorpe
  0 siblings, 0 replies; 5+ messages in thread
From: Jason Gunthorpe @ 2021-06-18 14:59 UTC (permalink / raw)
  To: Jason J. Herne; +Cc: linux-s390, linux-kernel, pasic, akrowiak

On Fri, Jun 18, 2021 at 10:35:21AM -0400, Jason J. Herne wrote:
> On 6/18/21 10:10 AM, Jason Gunthorpe wrote:
> > On Fri, Jun 18, 2021 at 09:35:24AM -0400, Jason J. Herne wrote:
> > > vfio_ap_matrix_dev_release is shadowing the global matrix_dev with driver
> > > data that never gets set. So when release is called we end up not freeing
> > > matrix_dev. The fix is to remove the shadow variable and just free the
> > > global.
> > 
> > I would clarify this commit message to say that the drv_data of the
> > matrix_dev is never set and so dev_get_drvdata() always returns NULL
> > 
> > And I would suggest to use
> > 
> >    container_of(dev, struct ap_matrix_dev, dev)
> > 
> > instead of the global variable, and probably NULL the global
> > too..
> > 
> 
> The use of driver_data seems to have been completely erroneous here. In this
> case the global matrix_dev is the top level struct. It is not contained in
> anything. matrix_dev is created upon module load, and it is freed when the
> module exits.
> 
> So I don't think using container_of makes sense. Unless I've
> misunderstood your suggestion?

	matrix_dev = kzalloc(sizeof(*matrix_dev), GFP_KERNEL);
	matrix_dev->device.release = vfio_ap_matrix_dev_release;
	ret = device_register(&matrix_dev->device);

"dev" is contained inside matrix_dev which is why we should use
container of to go from a struct device pointer back to the containing
matrix_dev pointer

Jason

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

* Re: [PATCH] s390/vfio-ap: Fix module unload memory leak of matrix_dev
  2021-06-18 13:35 [PATCH] s390/vfio-ap: Fix module unload memory leak of matrix_dev Jason J. Herne
  2021-06-18 14:10 ` Jason Gunthorpe
@ 2021-06-18 15:31 ` Tony Krowiak
  1 sibling, 0 replies; 5+ messages in thread
From: Tony Krowiak @ 2021-06-18 15:31 UTC (permalink / raw)
  To: Jason J. Herne, linux-s390; +Cc: linux-kernel, pasic, jgg

Reviewed-by: Tony Krowiak <akrowiak@linux.ibm.com>

On 6/18/21 9:35 AM, Jason J. Herne wrote:
> vfio_ap_matrix_dev_release is shadowing the global matrix_dev with driver
> data that never gets set. So when release is called we end up not freeing
> matrix_dev. The fix is to remove the shadow variable and just free the
> global.
>
> Signed-off-by: Jason J. Herne <jjherne@linux.ibm.com>
> ---
>   drivers/s390/crypto/vfio_ap_drv.c | 2 --
>   1 file changed, 2 deletions(-)
>
> diff --git a/drivers/s390/crypto/vfio_ap_drv.c b/drivers/s390/crypto/vfio_ap_drv.c
> index 7dc72cb718b0..6d3eea838e18 100644
> --- a/drivers/s390/crypto/vfio_ap_drv.c
> +++ b/drivers/s390/crypto/vfio_ap_drv.c
> @@ -82,8 +82,6 @@ static void vfio_ap_queue_dev_remove(struct ap_device *apdev)
>   
>   static void vfio_ap_matrix_dev_release(struct device *dev)
>   {
> -	struct ap_matrix_dev *matrix_dev = dev_get_drvdata(dev);
> -
>   	kfree(matrix_dev);
>   }
>   


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

end of thread, other threads:[~2021-06-18 15:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-18 13:35 [PATCH] s390/vfio-ap: Fix module unload memory leak of matrix_dev Jason J. Herne
2021-06-18 14:10 ` Jason Gunthorpe
2021-06-18 14:35   ` Jason J. Herne
2021-06-18 14:59     ` Jason Gunthorpe
2021-06-18 15:31 ` Tony Krowiak

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.