linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scsi: ufs: core: Free memory allocated for model before reinit
@ 2024-06-13 18:27 Joel Slebodnick
  2024-06-13 19:15 ` Bart Van Assche
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Joel Slebodnick @ 2024-06-13 18:27 UTC (permalink / raw)
  To: linux-scsi
  Cc: linux-kernel, alim.akhtar, avri.altman, bvanassche,
	James.Bottomley, martin.petersen, peter.wang,
	manivannan.sadhasivam, ahalaney, beanhuo, Joel Slebodnick

Under the conditions that a device is to be reinitialized within
ufshcd_probe_hba, the device must first be fully reset.

Resetting the device should include freeing U8 model (member of
dev_info)  but does not, and this causes a memory leak.
ufs_put_device_desc is responsible for freeing model.

unreferenced object 0xffff3f63008bee60 (size 32):
  comm "kworker/u33:1", pid 60, jiffies 4294892642
  hex dump (first 32 bytes):
    54 48 47 4a 46 47 54 30 54 32 35 42 41 5a 5a 41  THGJFGT0T25BAZZA
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
  backtrace (crc ed7ff1a9):
    [<ffffb86705f1243c>] kmemleak_alloc+0x34/0x40
    [<ffffb8670511cee4>] __kmalloc_noprof+0x1e4/0x2fc
    [<ffffb86705c247fc>] ufshcd_read_string_desc+0x94/0x190
    [<ffffb86705c26854>] ufshcd_device_init+0x480/0xdf8
    [<ffffb86705c27b68>] ufshcd_probe_hba+0x3c/0x404
    [<ffffb86705c29264>] ufshcd_async_scan+0x40/0x370
    [<ffffb86704f43e9c>] async_run_entry_fn+0x34/0xe0
    [<ffffb86704f34638>] process_one_work+0x154/0x298
    [<ffffb86704f34a74>] worker_thread+0x2f8/0x408
    [<ffffb86704f3cfa4>] kthread+0x114/0x118
    [<ffffb86704e955a0>] ret_from_fork+0x10/0x20

Signed-off-by: Joel Slebodnick <jslebodn@redhat.com>
---
 drivers/ufs/core/ufshcd.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 0cf07194bbe8..a0407b9213ca 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -8787,6 +8787,7 @@ static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params)
 	    (hba->quirks & UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH)) {
 		/* Reset the device and controller before doing reinit */
 		ufshcd_device_reset(hba);
+		ufs_put_device_desc(hba);
 		ufshcd_hba_stop(hba);
 		ufshcd_vops_reinit_notify(hba);
 		ret = ufshcd_hba_enable(hba);
-- 
2.40.1


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

* Re: [PATCH] scsi: ufs: core: Free memory allocated for model before reinit
  2024-06-13 18:27 [PATCH] scsi: ufs: core: Free memory allocated for model before reinit Joel Slebodnick
@ 2024-06-13 19:15 ` Bart Van Assche
  2024-06-13 19:34 ` Andrew Halaney
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Bart Van Assche @ 2024-06-13 19:15 UTC (permalink / raw)
  To: Joel Slebodnick, linux-scsi
  Cc: linux-kernel, alim.akhtar, avri.altman, James.Bottomley,
	martin.petersen, peter.wang, manivannan.sadhasivam, ahalaney,
	beanhuo

On 6/13/24 11:27 AM, Joel Slebodnick wrote:
> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index 0cf07194bbe8..a0407b9213ca 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -8787,6 +8787,7 @@ static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params)
>   	    (hba->quirks & UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH)) {
>   		/* Reset the device and controller before doing reinit */
>   		ufshcd_device_reset(hba);
> +		ufs_put_device_desc(hba);
>   		ufshcd_hba_stop(hba);
>   		ufshcd_vops_reinit_notify(hba);
>   		ret = ufshcd_hba_enable(hba);

Please add Fixes: and Cc: stable tags. Otherwise this patch looks good to me.
Hence:

Reviewed-by: Bart Van Assche <bvanassche@acm.org>

Thanks,

Bart.

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

* Re: [PATCH] scsi: ufs: core: Free memory allocated for model before reinit
  2024-06-13 18:27 [PATCH] scsi: ufs: core: Free memory allocated for model before reinit Joel Slebodnick
  2024-06-13 19:15 ` Bart Van Assche
@ 2024-06-13 19:34 ` Andrew Halaney
  2024-06-13 20:02 ` Joel Slebodnick
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Andrew Halaney @ 2024-06-13 19:34 UTC (permalink / raw)
  To: Joel Slebodnick
  Cc: linux-scsi, linux-kernel, alim.akhtar, avri.altman, bvanassche,
	James.Bottomley, martin.petersen, peter.wang,
	manivannan.sadhasivam, beanhuo

On Thu, Jun 13, 2024 at 02:27:28PM GMT, Joel Slebodnick wrote:
> Under the conditions that a device is to be reinitialized within
> ufshcd_probe_hba, the device must first be fully reset.
> 
> Resetting the device should include freeing U8 model (member of
> dev_info)  but does not, and this causes a memory leak.
> ufs_put_device_desc is responsible for freeing model.
> 
> unreferenced object 0xffff3f63008bee60 (size 32):
>   comm "kworker/u33:1", pid 60, jiffies 4294892642
>   hex dump (first 32 bytes):
>     54 48 47 4a 46 47 54 30 54 32 35 42 41 5a 5a 41  THGJFGT0T25BAZZA
>     00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
>   backtrace (crc ed7ff1a9):
>     [<ffffb86705f1243c>] kmemleak_alloc+0x34/0x40
>     [<ffffb8670511cee4>] __kmalloc_noprof+0x1e4/0x2fc
>     [<ffffb86705c247fc>] ufshcd_read_string_desc+0x94/0x190
>     [<ffffb86705c26854>] ufshcd_device_init+0x480/0xdf8
>     [<ffffb86705c27b68>] ufshcd_probe_hba+0x3c/0x404
>     [<ffffb86705c29264>] ufshcd_async_scan+0x40/0x370
>     [<ffffb86704f43e9c>] async_run_entry_fn+0x34/0xe0
>     [<ffffb86704f34638>] process_one_work+0x154/0x298
>     [<ffffb86704f34a74>] worker_thread+0x2f8/0x408
>     [<ffffb86704f3cfa4>] kthread+0x114/0x118
>     [<ffffb86704e955a0>] ret_from_fork+0x10/0x20
> 

With the following in place:

    Fixes: 96a7141da332 ("scsi: ufs: core: Add support for reinitializing the UFS device")
    Cc: stable@vger.kernel.org

feel free to add:

    Reviewed-by: Andrew Halaney <ahalaney@redhat.com>

> Signed-off-by: Joel Slebodnick <jslebodn@redhat.com>
> ---
>  drivers/ufs/core/ufshcd.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index 0cf07194bbe8..a0407b9213ca 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -8787,6 +8787,7 @@ static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params)
>  	    (hba->quirks & UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH)) {
>  		/* Reset the device and controller before doing reinit */
>  		ufshcd_device_reset(hba);
> +		ufs_put_device_desc(hba);
>  		ufshcd_hba_stop(hba);
>  		ufshcd_vops_reinit_notify(hba);
>  		ret = ufshcd_hba_enable(hba);
> -- 
> 2.40.1
> 


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

* [PATCH] scsi: ufs: core: Free memory allocated for model before reinit
  2024-06-13 18:27 [PATCH] scsi: ufs: core: Free memory allocated for model before reinit Joel Slebodnick
  2024-06-13 19:15 ` Bart Van Assche
  2024-06-13 19:34 ` Andrew Halaney
@ 2024-06-13 20:02 ` Joel Slebodnick
  2024-06-14  6:27   ` Avri Altman
  2024-06-14  6:30   ` Peter Wang (王信友)
  2024-06-14  2:23 ` Martin K. Petersen
  2024-06-14  8:28 ` Bean Huo
  4 siblings, 2 replies; 8+ messages in thread
From: Joel Slebodnick @ 2024-06-13 20:02 UTC (permalink / raw)
  To: linux-scsi
  Cc: linux-kernel, alim.akhtar, avri.altman, bvanassche,
	James.Bottomley, martin.petersen, peter.wang,
	manivannan.sadhasivam, ahalaney, beanhuo, Joel Slebodnick, stable

Under the conditions that a device is to be reinitialized within
ufshcd_probe_hba, the device must first be fully reset.

Resetting the device should include freeing U8 model (member of
dev_info)  but does not, and this causes a memory leak.
ufs_put_device_desc is responsible for freeing model.

unreferenced object 0xffff3f63008bee60 (size 32):
  comm "kworker/u33:1", pid 60, jiffies 4294892642
  hex dump (first 32 bytes):
    54 48 47 4a 46 47 54 30 54 32 35 42 41 5a 5a 41  THGJFGT0T25BAZZA
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
  backtrace (crc ed7ff1a9):
    [<ffffb86705f1243c>] kmemleak_alloc+0x34/0x40
    [<ffffb8670511cee4>] __kmalloc_noprof+0x1e4/0x2fc
    [<ffffb86705c247fc>] ufshcd_read_string_desc+0x94/0x190
    [<ffffb86705c26854>] ufshcd_device_init+0x480/0xdf8
    [<ffffb86705c27b68>] ufshcd_probe_hba+0x3c/0x404
    [<ffffb86705c29264>] ufshcd_async_scan+0x40/0x370
    [<ffffb86704f43e9c>] async_run_entry_fn+0x34/0xe0
    [<ffffb86704f34638>] process_one_work+0x154/0x298
    [<ffffb86704f34a74>] worker_thread+0x2f8/0x408
    [<ffffb86704f3cfa4>] kthread+0x114/0x118
    [<ffffb86704e955a0>] ret_from_fork+0x10/0x20

Fixes: 96a7141da332 ("scsi: ufs: core: Add support for reinitializing the UFS device")
Cc: <stable@vger.kernel.org>

Reviewed-by: Andrew Halaney <ahalaney@redhat.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Joel Slebodnick <jslebodn@redhat.com>
---
 drivers/ufs/core/ufshcd.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 0cf07194bbe8..a0407b9213ca 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -8787,6 +8787,7 @@ static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params)
 	    (hba->quirks & UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH)) {
 		/* Reset the device and controller before doing reinit */
 		ufshcd_device_reset(hba);
+		ufs_put_device_desc(hba);
 		ufshcd_hba_stop(hba);
 		ufshcd_vops_reinit_notify(hba);
 		ret = ufshcd_hba_enable(hba);
-- 
2.40.1


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

* Re: [PATCH] scsi: ufs: core: Free memory allocated for model before reinit
  2024-06-13 18:27 [PATCH] scsi: ufs: core: Free memory allocated for model before reinit Joel Slebodnick
                   ` (2 preceding siblings ...)
  2024-06-13 20:02 ` Joel Slebodnick
@ 2024-06-14  2:23 ` Martin K. Petersen
  2024-06-14  8:28 ` Bean Huo
  4 siblings, 0 replies; 8+ messages in thread
From: Martin K. Petersen @ 2024-06-14  2:23 UTC (permalink / raw)
  To: linux-scsi, Joel Slebodnick
  Cc: Martin K . Petersen, linux-kernel, alim.akhtar, avri.altman,
	bvanassche, James.Bottomley, peter.wang, manivannan.sadhasivam,
	ahalaney, beanhuo

On Thu, 13 Jun 2024 14:27:28 -0400, Joel Slebodnick wrote:

> Under the conditions that a device is to be reinitialized within
> ufshcd_probe_hba, the device must first be fully reset.
> 
> Resetting the device should include freeing U8 model (member of
> dev_info)  but does not, and this causes a memory leak.
> ufs_put_device_desc is responsible for freeing model.
> 
> [...]

Applied to 6.10/scsi-fixes, thanks!

[1/1] scsi: ufs: core: Free memory allocated for model before reinit
      https://git.kernel.org/mkp/scsi/c/135c6eb27a85

-- 
Martin K. Petersen	Oracle Linux Engineering

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

* RE: [PATCH] scsi: ufs: core: Free memory allocated for model before reinit
  2024-06-13 20:02 ` Joel Slebodnick
@ 2024-06-14  6:27   ` Avri Altman
  2024-06-14  6:30   ` Peter Wang (王信友)
  1 sibling, 0 replies; 8+ messages in thread
From: Avri Altman @ 2024-06-14  6:27 UTC (permalink / raw)
  To: Joel Slebodnick, linux-scsi@vger.kernel.org
  Cc: linux-kernel@vger.kernel.org, alim.akhtar@samsung.com,
	bvanassche@acm.org, James.Bottomley@HansenPartnership.com,
	martin.petersen@oracle.com, peter.wang@mediatek.com,
	manivannan.sadhasivam@linaro.org, ahalaney@redhat.com,
	beanhuo@micron.com, stable@vger.kernel.org

> Under the conditions that a device is to be reinitialized within ufshcd_probe_hba,
> the device must first be fully reset.
> 
> Resetting the device should include freeing U8 model (member of
> dev_info)  but does not, and this causes a memory leak.
> ufs_put_device_desc is responsible for freeing model.
> 
> unreferenced object 0xffff3f63008bee60 (size 32):
>   comm "kworker/u33:1", pid 60, jiffies 4294892642
>   hex dump (first 32 bytes):
>     54 48 47 4a 46 47 54 30 54 32 35 42 41 5a 5a 41  THGJFGT0T25BAZZA
>     00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
>   backtrace (crc ed7ff1a9):
>     [<ffffb86705f1243c>] kmemleak_alloc+0x34/0x40
>     [<ffffb8670511cee4>] __kmalloc_noprof+0x1e4/0x2fc
>     [<ffffb86705c247fc>] ufshcd_read_string_desc+0x94/0x190
>     [<ffffb86705c26854>] ufshcd_device_init+0x480/0xdf8
>     [<ffffb86705c27b68>] ufshcd_probe_hba+0x3c/0x404
>     [<ffffb86705c29264>] ufshcd_async_scan+0x40/0x370
>     [<ffffb86704f43e9c>] async_run_entry_fn+0x34/0xe0
>     [<ffffb86704f34638>] process_one_work+0x154/0x298
>     [<ffffb86704f34a74>] worker_thread+0x2f8/0x408
>     [<ffffb86704f3cfa4>] kthread+0x114/0x118
>     [<ffffb86704e955a0>] ret_from_fork+0x10/0x20
> 
> Fixes: 96a7141da332 ("scsi: ufs: core: Add support for reinitializing the UFS
> device")
> Cc: <stable@vger.kernel.org>
> 
> Reviewed-by: Andrew Halaney <ahalaney@redhat.com>
> Reviewed-by: Bart Van Assche <bvanassche@acm.org>
> Signed-off-by: Joel Slebodnick <jslebodn@redhat.com>
Reviewed-by: Avri Altman <avri.altman@wdc.com>


> ---
>  drivers/ufs/core/ufshcd.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index
> 0cf07194bbe8..a0407b9213ca 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -8787,6 +8787,7 @@ static int ufshcd_probe_hba(struct ufs_hba *hba, bool
> init_dev_params)
>             (hba->quirks & UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH)) {
>                 /* Reset the device and controller before doing reinit */
>                 ufshcd_device_reset(hba);
> +               ufs_put_device_desc(hba);
>                 ufshcd_hba_stop(hba);
>                 ufshcd_vops_reinit_notify(hba);
>                 ret = ufshcd_hba_enable(hba);
> --
> 2.40.1


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

* Re: [PATCH] scsi: ufs: core: Free memory allocated for model before reinit
  2024-06-13 20:02 ` Joel Slebodnick
  2024-06-14  6:27   ` Avri Altman
@ 2024-06-14  6:30   ` Peter Wang (王信友)
  1 sibling, 0 replies; 8+ messages in thread
From: Peter Wang (王信友) @ 2024-06-14  6:30 UTC (permalink / raw)
  To: linux-scsi@vger.kernel.org, jslebodn@redhat.com
  Cc: linux-kernel@vger.kernel.org, ahalaney@redhat.com,
	beanhuo@micron.com, avri.altman@wdc.com,
	martin.petersen@oracle.com, bvanassche@acm.org,
	stable@vger.kernel.org, alim.akhtar@samsung.com,
	manivannan.sadhasivam@linaro.org,
	James.Bottomley@HansenPartnership.com

On Thu, 2024-06-13 at 16:02 -0400, Joel Slebodnick wrote:
>  	 
> External email : Please do not click links or open attachments until
> you have verified the sender or the content.
>  Under the conditions that a device is to be reinitialized within
> ufshcd_probe_hba, the device must first be fully reset.
> 
> Resetting the device should include freeing U8 model (member of
> dev_info)  but does not, and this causes a memory leak.
> ufs_put_device_desc is responsible for freeing model.
> 
> unreferenced object 0xffff3f63008bee60 (size 32):
>   comm "kworker/u33:1", pid 60, jiffies 4294892642
>   hex dump (first 32 bytes):
>     54 48 47 4a 46 47 54 30 54 32 35 42 41 5a 5a 41  THGJFGT0T25BAZZA
>     00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
>   backtrace (crc ed7ff1a9):
>     [<ffffb86705f1243c>] kmemleak_alloc+0x34/0x40
>     [<ffffb8670511cee4>] __kmalloc_noprof+0x1e4/0x2fc
>     [<ffffb86705c247fc>] ufshcd_read_string_desc+0x94/0x190
>     [<ffffb86705c26854>] ufshcd_device_init+0x480/0xdf8
>     [<ffffb86705c27b68>] ufshcd_probe_hba+0x3c/0x404
>     [<ffffb86705c29264>] ufshcd_async_scan+0x40/0x370
>     [<ffffb86704f43e9c>] async_run_entry_fn+0x34/0xe0
>     [<ffffb86704f34638>] process_one_work+0x154/0x298
>     [<ffffb86704f34a74>] worker_thread+0x2f8/0x408
>     [<ffffb86704f3cfa4>] kthread+0x114/0x118
>     [<ffffb86704e955a0>] ret_from_fork+0x10/0x20
> 
> Fixes: 96a7141da332 ("scsi: ufs: core: Add support for reinitializing
> the UFS device")
> Cc: <stable@vger.kernel.org>
> 
> Reviewed-by: Andrew Halaney <ahalaney@redhat.com>
> Reviewed-by: Bart Van Assche <bvanassche@acm.org>
> Signed-off-by: Joel Slebodnick <jslebodn@redhat.com>
> 

Reviewed-by: Peter Wang <peter.wang@mediatek.com>


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

* Re: [PATCH] scsi: ufs: core: Free memory allocated for model before reinit
  2024-06-13 18:27 [PATCH] scsi: ufs: core: Free memory allocated for model before reinit Joel Slebodnick
                   ` (3 preceding siblings ...)
  2024-06-14  2:23 ` Martin K. Petersen
@ 2024-06-14  8:28 ` Bean Huo
  4 siblings, 0 replies; 8+ messages in thread
From: Bean Huo @ 2024-06-14  8:28 UTC (permalink / raw)
  To: Joel Slebodnick, linux-scsi
  Cc: linux-kernel, alim.akhtar, avri.altman, bvanassche,
	James.Bottomley, martin.petersen, peter.wang,
	manivannan.sadhasivam, ahalaney, beanhuo

On Thu, 2024-06-13 at 14:27 -0400, Joel Slebodnick wrote:
> Signed-off-by: Joel Slebodnick <jslebodn@redhat.com>

Reviewed-by: Bean Huo <beanhuo@micron.com>


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

end of thread, other threads:[~2024-06-14  8:29 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-13 18:27 [PATCH] scsi: ufs: core: Free memory allocated for model before reinit Joel Slebodnick
2024-06-13 19:15 ` Bart Van Assche
2024-06-13 19:34 ` Andrew Halaney
2024-06-13 20:02 ` Joel Slebodnick
2024-06-14  6:27   ` Avri Altman
2024-06-14  6:30   ` Peter Wang (王信友)
2024-06-14  2:23 ` Martin K. Petersen
2024-06-14  8:28 ` Bean Huo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).