public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] ufs: core: fix racing issue between ufshcd_mcq_abort and ISR
@ 2023-10-27  8:43 peter.wang
  2023-11-03  2:23 ` Peter Wang (王信友)
  2023-11-03 14:57 ` Bart Van Assche
  0 siblings, 2 replies; 4+ messages in thread
From: peter.wang @ 2023-10-27  8:43 UTC (permalink / raw)
  To: stanley.chu, linux-scsi, martin.petersen, avri.altman,
	alim.akhtar, jejb
  Cc: wsd_upstream, linux-mediatek, peter.wang, chun-hung.wu,
	alice.chao, cc.chou, chaotian.jing, jiajie.hao, powen.kao,
	qilin.tan, lin.gui, tun-yu.yu, eddie.huang, naomi.chu

From: Peter Wang <peter.wang@mediatek.com>

If command timeout happen and cq complete irq raise at the same time,
ufshcd_mcq_abort null the lprb->cmd and NULL poiner KE in ISR.
Below is error log.

ufshcd_abort: Device abort task at tag 18
Unable to handle kernel NULL pointer dereference at virtual address
0000000000000108
pc : [0xffffffe27ef867ac] scsi_dma_unmap+0xc/0x44
lr : [0xffffffe27f1b898c] ufshcd_release_scsi_cmd+0x24/0x114

Signed-off-by: Peter Wang <peter.wang@mediatek.com>
---
 drivers/ufs/core/ufs-mcq.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/ufs/core/ufs-mcq.c b/drivers/ufs/core/ufs-mcq.c
index 2ba8ec254dce..6ea96406f2bf 100644
--- a/drivers/ufs/core/ufs-mcq.c
+++ b/drivers/ufs/core/ufs-mcq.c
@@ -630,6 +630,7 @@ int ufshcd_mcq_abort(struct scsi_cmnd *cmd)
 	int tag = scsi_cmd_to_rq(cmd)->tag;
 	struct ufshcd_lrb *lrbp = &hba->lrb[tag];
 	struct ufs_hw_queue *hwq;
+	unsigned long flags;
 	int err = FAILED;
 
 	if (!ufshcd_cmd_inflight(lrbp->cmd)) {
@@ -670,8 +671,10 @@ int ufshcd_mcq_abort(struct scsi_cmnd *cmd)
 	}
 
 	err = SUCCESS;
+	spin_lock_irqsave(&hwq->cq_lock, flags);
 	if (ufshcd_cmd_inflight(lrbp->cmd))
 		ufshcd_release_scsi_cmd(hba, lrbp);
+	spin_unlock_irqrestore(&hwq->cq_lock, flags);
 
 out:
 	return err;
-- 
2.18.0


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

* Re: [PATCH v1] ufs: core: fix racing issue between ufshcd_mcq_abort and ISR
  2023-10-27  8:43 [PATCH v1] ufs: core: fix racing issue between ufshcd_mcq_abort and ISR peter.wang
@ 2023-11-03  2:23 ` Peter Wang (王信友)
  2023-11-03 14:57 ` Bart Van Assche
  1 sibling, 0 replies; 4+ messages in thread
From: Peter Wang (王信友) @ 2023-11-03  2:23 UTC (permalink / raw)
  To: linux-scsi@vger.kernel.org, avri.altman@wdc.com,
	alim.akhtar@samsung.com, Stanley Chu (朱原陞),
	jejb@linux.ibm.com, martin.petersen@oracle.com
  Cc: linux-mediatek@lists.infradead.org,
	Jiajie Hao (郝加节),
	CC Chou (周志杰),
	Eddie Huang (黃智傑),
	Alice Chao (趙珮均), wsd_upstream,
	Lin Gui (桂林),
	Chun-Hung Wu (巫駿宏),
	Tun-yu Yu (游敦聿),
	Chaotian Jing (井朝天),
	Powen Kao (高伯文),
	Naomi Chu (朱詠田),
	Qilin Tan (谭麒麟)

Hi all,

Gentle ping for this bug fix review.

Thanks.



On Fri, 2023-10-27 at 16:43 +0800, peter.wang@mediatek.com wrote:
> From: Peter Wang <peter.wang@mediatek.com>
> 
> If command timeout happen and cq complete irq raise at the same time,
> ufshcd_mcq_abort null the lprb->cmd and NULL poiner KE in ISR.
> Below is error log.
> 
> ufshcd_abort: Device abort task at tag 18
> Unable to handle kernel NULL pointer dereference at virtual address
> 0000000000000108
> pc : [0xffffffe27ef867ac] scsi_dma_unmap+0xc/0x44
> lr : [0xffffffe27f1b898c] ufshcd_release_scsi_cmd+0x24/0x114
> 
> Signed-off-by: Peter Wang <peter.wang@mediatek.com>
> ---
>  drivers/ufs/core/ufs-mcq.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/ufs/core/ufs-mcq.c b/drivers/ufs/core/ufs-mcq.c
> index 2ba8ec254dce..6ea96406f2bf 100644
> --- a/drivers/ufs/core/ufs-mcq.c
> +++ b/drivers/ufs/core/ufs-mcq.c
> @@ -630,6 +630,7 @@ int ufshcd_mcq_abort(struct scsi_cmnd *cmd)
>  	int tag = scsi_cmd_to_rq(cmd)->tag;
>  	struct ufshcd_lrb *lrbp = &hba->lrb[tag];
>  	struct ufs_hw_queue *hwq;
> +	unsigned long flags;
>  	int err = FAILED;
>  
>  	if (!ufshcd_cmd_inflight(lrbp->cmd)) {
> @@ -670,8 +671,10 @@ int ufshcd_mcq_abort(struct scsi_cmnd *cmd)
>  	}
>  
>  	err = SUCCESS;
> +	spin_lock_irqsave(&hwq->cq_lock, flags);
>  	if (ufshcd_cmd_inflight(lrbp->cmd))
>  		ufshcd_release_scsi_cmd(hba, lrbp);
> +	spin_unlock_irqrestore(&hwq->cq_lock, flags);
>  
>  out:
>  	return err;

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

* Re: [PATCH v1] ufs: core: fix racing issue between ufshcd_mcq_abort and ISR
  2023-10-27  8:43 [PATCH v1] ufs: core: fix racing issue between ufshcd_mcq_abort and ISR peter.wang
  2023-11-03  2:23 ` Peter Wang (王信友)
@ 2023-11-03 14:57 ` Bart Van Assche
  2023-11-06  7:34   ` Peter Wang (王信友)
  1 sibling, 1 reply; 4+ messages in thread
From: Bart Van Assche @ 2023-11-03 14:57 UTC (permalink / raw)
  To: peter.wang, stanley.chu, linux-scsi, martin.petersen, avri.altman,
	alim.akhtar, jejb
  Cc: wsd_upstream, linux-mediatek, chun-hung.wu, alice.chao, cc.chou,
	chaotian.jing, jiajie.hao, powen.kao, qilin.tan, lin.gui,
	tun-yu.yu, eddie.huang, naomi.chu

On 10/27/23 01:43, peter.wang@mediatek.com wrote:
> If command timeout happen and cq complete irq raise at the same time,
> ufshcd_mcq_abort null the lprb->cmd and NULL poiner KE in ISR.

Please add a Fixes: tag. Otherwise this patch looks good to me.

Thanks,

Bart.

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

* Re: [PATCH v1] ufs: core: fix racing issue between ufshcd_mcq_abort and ISR
  2023-11-03 14:57 ` Bart Van Assche
@ 2023-11-06  7:34   ` Peter Wang (王信友)
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Wang (王信友) @ 2023-11-06  7:34 UTC (permalink / raw)
  To: linux-scsi@vger.kernel.org, bvanassche@acm.org,
	avri.altman@wdc.com, Stanley Chu (朱原陞),
	alim.akhtar@samsung.com, martin.petersen@oracle.com,
	jejb@linux.ibm.com
  Cc: linux-mediatek@lists.infradead.org,
	Jiajie Hao (郝加节),
	CC Chou (周志杰),
	Eddie Huang (黃智傑),
	Alice Chao (趙珮均), wsd_upstream,
	Lin Gui (桂林),
	Chun-Hung Wu (巫駿宏),
	Tun-yu Yu (游敦聿),
	Chaotian Jing (井朝天),
	Powen Kao (高伯文),
	Naomi Chu (朱詠田),
	Qilin Tan (谭麒麟)

On Fri, 2023-11-03 at 07:57 -0700, Bart Van Assche wrote:
>  	 
> External email : Please do not click links or open attachments until
> you have verified the sender or the content.
>  On 10/27/23 01:43, peter.wang@mediatek.com wrote:
> > If command timeout happen and cq complete irq raise at the same
> time,
> > ufshcd_mcq_abort null the lprb->cmd and NULL poiner KE in ISR.
> 
> Please add a Fixes: tag. Otherwise this patch looks good to me.
> 
> Thanks,
> 
> Bart.

Hi Bart,

Thank you for review, will add fixes tag next version.

Thanks.
Peter


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

end of thread, other threads:[~2023-11-06  7:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-27  8:43 [PATCH v1] ufs: core: fix racing issue between ufshcd_mcq_abort and ISR peter.wang
2023-11-03  2:23 ` Peter Wang (王信友)
2023-11-03 14:57 ` Bart Van Assche
2023-11-06  7:34   ` Peter Wang (王信友)

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