linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] core: ufs: fix racing issue between force complete and isr
@ 2023-10-24  8:43 alice.chao
  2023-10-24 19:00 ` Bart Van Assche
  2023-10-25  2:43 ` Martin K. Petersen
  0 siblings, 2 replies; 4+ messages in thread
From: alice.chao @ 2023-10-24  8:43 UTC (permalink / raw)
  To: Alim Akhtar, Avri Altman, Bart Van Assche, James E.J. Bottomley,
	Martin K. Petersen, Matthias Brugger, AngeloGioacchino Del Regno
  Cc: wsd_upstream, stanley.chu, peter.wang, powen.kao, naomi.chu,
	cc.chou, tun-yu.yu, chun-hung.wu, casper.li, Alice Chao,
	linux-scsi, linux-kernel, linux-arm-kernel, linux-mediatek

From: Alice Chao <alice.chao@mediatek.com>

While error handler force complete command (Thread A) and completion irq
raising (Thread B) of the same command, it may cause race condition.

Below is racing step (from 1 to 6):
	ufshcd_mcq_compl_pending_transfer (Thread A)
1	if (cmd && !test_bit(SCMD_STATE_COMPLETE, &cmd->state)) {
5		spin_lock_irqsave(&hwq->cq_lock, flags);	// wait lock release
		set_host_byte(cmd, DID_REQUEUE);
6		ufshcd_release_scsi_cmd(hba, lrbp);	// access null pointer
		scsi_done(cmd);
		spin_unlock_irqrestore(&hwq->cq_lock, flags);
	}

	ufshcd_mcq_poll_cqe_lock (Thread B)
2	spin_lock_irqsave(&hwq->cq_lock, flags);
	 ufshcd_mcq_poll_cqe_nolock()
	  ufshcd_compl_one_cqe()
3	   ufshcd_release_scsi_cmd()	// lrbp->cmd = NULL;
4	spin_unlock_irqrestore(&hwq->cq_lock, flags);

Signed-off-by: Alice Chao <alice.chao@mediatek.com>
---
 drivers/ufs/core/ufshcd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 8382e8cfa414..ef6bd146a767 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -5518,13 +5518,13 @@ static void ufshcd_mcq_compl_pending_transfer(struct ufs_hba *hba,
 			 * For those cmds of which the cqes are not present
 			 * in the cq, complete them explicitly.
 			 */
+			spin_lock_irqsave(&hwq->cq_lock, flags);
 			if (cmd && !test_bit(SCMD_STATE_COMPLETE, &cmd->state)) {
-				spin_lock_irqsave(&hwq->cq_lock, flags);
 				set_host_byte(cmd, DID_REQUEUE);
 				ufshcd_release_scsi_cmd(hba, lrbp);
 				scsi_done(cmd);
-				spin_unlock_irqrestore(&hwq->cq_lock, flags);
 			}
+			spin_unlock_irqrestore(&hwq->cq_lock, flags);
 		} else {
 			ufshcd_mcq_poll_cqe_lock(hba, hwq);
 		}
-- 
2.18.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 1/1] core: ufs: fix racing issue between force complete and isr
  2023-10-24  8:43 [PATCH 1/1] core: ufs: fix racing issue between force complete and isr alice.chao
@ 2023-10-24 19:00 ` Bart Van Assche
  2023-10-25  2:43 ` Martin K. Petersen
  1 sibling, 0 replies; 4+ messages in thread
From: Bart Van Assche @ 2023-10-24 19:00 UTC (permalink / raw)
  To: alice.chao, Alim Akhtar, Avri Altman, James E.J. Bottomley,
	Martin K. Petersen, Matthias Brugger, AngeloGioacchino Del Regno
  Cc: wsd_upstream, stanley.chu, peter.wang, powen.kao, naomi.chu,
	cc.chou, tun-yu.yu, chun-hung.wu, casper.li, linux-scsi,
	linux-kernel, linux-arm-kernel, linux-mediatek

On 10/24/23 01:43, alice.chao@mediatek.com wrote:
> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index 8382e8cfa414..ef6bd146a767 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -5518,13 +5518,13 @@ static void ufshcd_mcq_compl_pending_transfer(struct ufs_hba *hba,
>   			 * For those cmds of which the cqes are not present
>   			 * in the cq, complete them explicitly.
>   			 */
> +			spin_lock_irqsave(&hwq->cq_lock, flags);
>   			if (cmd && !test_bit(SCMD_STATE_COMPLETE, &cmd->state)) {
> -				spin_lock_irqsave(&hwq->cq_lock, flags);
>   				set_host_byte(cmd, DID_REQUEUE);
>   				ufshcd_release_scsi_cmd(hba, lrbp);
>   				scsi_done(cmd);
> -				spin_unlock_irqrestore(&hwq->cq_lock, flags);
>   			}
> +			spin_unlock_irqrestore(&hwq->cq_lock, flags);
>   		} else {
>   			ufshcd_mcq_poll_cqe_lock(hba, hwq);
>   		}

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


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 1/1] core: ufs: fix racing issue between force complete and isr
  2023-10-24  8:43 [PATCH 1/1] core: ufs: fix racing issue between force complete and isr alice.chao
  2023-10-24 19:00 ` Bart Van Assche
@ 2023-10-25  2:43 ` Martin K. Petersen
       [not found]   ` <dd57ef80bcf451e2daab2b08b8f6a6e11b4e4003.camel@mediatek.com>
  1 sibling, 1 reply; 4+ messages in thread
From: Martin K. Petersen @ 2023-10-25  2:43 UTC (permalink / raw)
  To: alice.chao
  Cc: Alim Akhtar, Avri Altman, Bart Van Assche, James E.J. Bottomley,
	Martin K. Petersen, Matthias Brugger, AngeloGioacchino Del Regno,
	wsd_upstream, stanley.chu, peter.wang, powen.kao, naomi.chu,
	cc.chou, tun-yu.yu, chun-hung.wu, casper.li, linux-scsi,
	linux-kernel, linux-arm-kernel, linux-mediatek


Alice,

> While error handler force complete command (Thread A) and completion
> irq raising (Thread B) of the same command, it may cause race
> condition.

Applied to 6.7/scsi-staging, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 1/1] core: ufs: fix racing issue between force complete and isr
       [not found]   ` <dd57ef80bcf451e2daab2b08b8f6a6e11b4e4003.camel@mediatek.com>
@ 2023-10-25  8:31     ` gregkh
  0 siblings, 0 replies; 4+ messages in thread
From: gregkh @ 2023-10-25  8:31 UTC (permalink / raw)
  To: Alice Chao (趙珮均)
  Cc: martin.petersen@oracle.com, Peter Wang (王信友),
	linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org,
	CC Chou (周志杰), jejb@linux.ibm.com,
	wsd_upstream, avri.altman@wdc.com, bvanassche@acm.org,
	Casper Li (李中榮),
	Tun-yu Yu (游敦聿),
	Chun-Hung Wu (巫駿宏), alim.akhtar@samsung.com,
	linux-scsi@vger.kernel.org, Powen Kao (高伯文),
	Naomi Chu (朱詠田),
	linux-arm-kernel@lists.infradead.org,
	Stanley Chu (朱原陞), matthias.bgg@gmail.com,
	angelogioacchino.delregno@collabora.com

On Wed, Oct 25, 2023 at 07:20:53AM +0000, Alice Chao (趙珮均) wrote:
> Can we take it to the LTS version(6.1)?

<formletter>

This is not the correct way to submit patches for inclusion in the
stable kernel tree.  Please read:
    https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.

</formletter>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2023-10-25  8:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-24  8:43 [PATCH 1/1] core: ufs: fix racing issue between force complete and isr alice.chao
2023-10-24 19:00 ` Bart Van Assche
2023-10-25  2:43 ` Martin K. Petersen
     [not found]   ` <dd57ef80bcf451e2daab2b08b8f6a6e11b4e4003.camel@mediatek.com>
2023-10-25  8:31     ` gregkh

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).