Fix a rare crash in the UFS driver
Subsystems (4)
Bart Van Assche
reviewercover Fix a rare crash in the UFS driver
Hi Martin,
Sporadic crashes have been observed with the UFS kernel driver if a timeout occurs. This patch series fixes these crashes. Please consider this patch series for the next merge window.
Thanks,
Bart.
Bart Van Assche (4):
scsi: ufs: Declare ufshcd_mcq_poll_cqe_lock() once
scsi: ufs: Make ufshcd_poll() complain about unsupported arguments
scsi: ufs: Make the polling code report which command has been
completed
scsi: ufs: Check for completion from the timeout handler
drivers/ufs/core/ufs-mcq.c | 23 ++++++++----- drivers/ufs/core/ufshcd-priv.h | 6 ++-- drivers/ufs/core/ufshcd.c | 59 +++++++++++++++++++++++++++------- drivers/ufs/host/ufs-qcom.c | 2 +- include/ufs/ufshcd.h | 3 +- 5 files changed, 67 insertions(+), 26 deletions(-)
Bart Van Assche
reviewerPATCH 1/4 scsi: ufs: Declare ufshcd_mcq_poll_cqe_lock() once
ufshcd_mcq_poll_cqe_lock() is declared in include/ufs/ufshcd.h and also in drivers/ufs/core/ufshcd-priv.h. Remove the declaration from the latter file.
--- drivers/ufs/core/ufshcd-priv.h | 2 -- 1 file changed, 2 deletions(-)
drivers/ufs/core/ufshcd-priv.h +0 -2
@@ -72,8 +72,6 @@ u32 ufshcd_mcq_read_cqis(struct ufs_hba *hba, int i);void ufshcd_mcq_write_cqis (struct ufs_hba *hba,u32 val,int i);struct ufs_hw_queue *ufshcd_mcq_req_to_hwq (struct ufs_hba *hba,struct request *req); -unsigned long ufshcd_mcq_poll_cqe_lock (struct ufs_hba *hba, -struct ufs_hw_queue *hwq);void ufshcd_mcq_compl_all_cqes_lock (struct ufs_hba *hba,struct ufs_hw_queue *hwq);bool ufshcd_cmd_inflight (struct scsi_cmnd *cmd);
Bart Van Assche
reviewerPATCH 2/4 scsi: ufs: Make ufshcd_poll() complain about unsupported arguments
In reply to Bart Van AsscheThe ufshcd_poll() implementation does not support queue_num == UFSHCD_POLL_FROM_INTERRUPT_CONTEXT in MCQ mode. Hence complain if queue_num == UFSHCD_POLL_FROM_INTERRUPT_CONTEXT in MCQ mode.
--- drivers/ufs/core/ufshcd.c | 1 + 1 file changed, 1 insertion(+)
drivers/ufs/core/ufshcd.c +1 -0
@@ -5617,6 +5617,7 @@ static int ufshcd_poll(struct Scsi_Host *shost, unsigned int queue_num)struct ufs_hw_queue *hwq;if (is_mcq_enabled (hba)) { +WARN_ON_ONCE (queue_num ==UFSHCD_POLL_FROM_INTERRUPT_CONTEXT ); hwq = &hba->uhq[queue_num];return ufshcd_mcq_poll_cqe_lock (hba, hwq);
Avri Altman
reviewerRE: [PATCH 2/4] scsi: ufs: Make ufshcd_poll() complain about unsupported arguments
Quoted 4 lines
The
ufshcd_poll()implementation does not supportqueue_num==UFSHCD_POLL_FROM_INTERRUPT_CONTEXTin MCQ mode. Hence complain ifqueue_num==UFSHCD_POLL_FROM_INTERRUPT_CONTEXTin MCQ mode.
Fixes tag - is it ed975065c31c ?
Thanks,
Avri
Quoted 19 lines
Signed-off-by Bart Van Assche <[email protected]>--- drivers/ufs/core/ufshcd.c | 1 + 1 file changed, 1 insertion(+)drivers/ufs/core/ufshcd.c +1
-0@@ -5617,6 +5617,7 @@ static int ufshcd_poll(struct Scsi_Host *shost, unsigned int queue_num)struct ufs_hw_queue *hwq;if (is_mcq_enabled (hba)) { +WARN_ON_ONCE (queue_num ==UFSHCD_POLL_FROM_INTERRUPT_CONTEXT ); hwq = &hba->uhq[queue_num];return ufshcd_mcq_poll_cqe_lock(hba, hwq);
Bart Van Assche
reviewerRe: [PATCH 2/4] scsi: ufs: Make ufshcd_poll() complain about unsupported arguments
Quoted 5 lines · Avri Altman
Quoted 3 lines
The
ufshcd_poll()implementation does not supportqueue_num==UFSHCD_POLL_FROM_INTERRUPT_CONTEXTin MCQ mode. Hence complain ifqueue_num==UFSHCD_POLL_FROM_INTERRUPT_CONTEXTin MCQ mode.Fixes tag - is it
ed975065c31c?
Isn't the Fixes tag for patches that fix a shortcoming? This patch does not change the behavior of the UFS driver so I don't see it as a fix.
Thanks,
Bart.
Bart Van Assche
reviewerPATCH 3/4 scsi: ufs: Make the polling code report which command has been completed
In reply to Bart Van AsschePrepare for introducing a new __ufshcd_poll() caller that will need to know whether or not a specific command has been completed.
--- drivers/ufs/core/ufs-mcq.c | 23 +++++++++++++------- drivers/ufs/core/ufshcd-priv.h | 4 ++-- drivers/ufs/core/ufshcd.c | 39 +++++++++++++++++++++++----------- drivers/ufs/host/ufs-qcom.c | 2 +- include/ufs/ufshcd.h | 3 ++- 5 files changed, 47 insertions(+), 24 deletions(-)
drivers/ufs/core/ufs-mcq.c +15 -8
@@ -268,17 +268,20 @@ static int ufshcd_mcq_get_tag(struct ufs_hba *hba, struct cq_entry *cqe)return div_u64 (addr,ufshcd_get_ucd_size (hba)); } -static void ufshcd_mcq_process_cqe (struct ufs_hba *hba, -struct ufs_hw_queue *hwq) +/* Returns true if and only if @compl_cmd has been completed. */ +static bool ufshcd_mcq_process_cqe (struct ufs_hba *hba, +struct ufs_hw_queue *hwq, +struct scsi_cmnd *compl_cmd) {struct cq_entry *cqe =ufshcd_mcq_cur_cqe (hwq); -int tag =ufshcd_mcq_get_tag (hba, cqe);if (cqe->command_desc_base_addr) { -ufshcd_compl_one_cqe (hba, tag, cqe); -/* After processed the cqe, mark it empty (invalid) entry */ +const int tag =ufshcd_mcq_get_tag (hba, cqe); +/* Mark the CQE as invalid. */ cqe->command_desc_base_addr =0 ; +return ufshcd_compl_one_cqe (hba, tag, cqe, compl_cmd); } +return false; } void ufshcd_mcq_compl_all_cqes_lock(struct ufs_hba *hba,
@@ -289,7 +292,7 @@ void ufshcd_mcq_compl_all_cqes_lock(struct ufs_hba *hba,spin_lock_irqsave (&hwq->cq_lock, flags);while (entries >0 ) { -ufshcd_mcq_process_cqe (hba, hwq); +ufshcd_mcq_process_cqe (hba, hwq,NULL );ufshcd_mcq_inc_cq_head_slot (hwq); entries--; }
@@ -299,8 +302,10 @@ void ufshcd_mcq_compl_all_cqes_lock(struct ufs_hba *hba,spin_unlock_irqrestore (&hwq->cq_lock, flags); } +/* Clears *@compl_cmd if and only if *@compl_cmd has been completed. */ unsigned long ufshcd_mcq_poll_cqe_lock (struct ufs_hba *hba, -struct ufs_hw_queue *hwq) +struct ufs_hw_queue *hwq, +struct scsi_cmnd **compl_cmd) {unsigned long completed_reqs =0 ;unsigned long flags;
@@ -308,7 +313,9 @@ unsigned long ufshcd_mcq_poll_cqe_lock(struct ufs_hba *hba,spin_lock_irqsave (&hwq->cq_lock, flags);ufshcd_mcq_update_cq_tail_slot (hwq);while (!ufshcd_mcq_is_cq_empty (hwq)) { -ufshcd_mcq_process_cqe (hba, hwq); +if (ufshcd_mcq_process_cqe (hba, hwq, + compl_cmd ? *compl_cmd :NULL )) + *compl_cmd =NULL ;ufshcd_mcq_inc_cq_head_slot (hwq); completed_reqs++; }
drivers/ufs/core/ufshcd-priv.h +2 -2
@@ -61,8 +61,8 @@ int ufshcd_query_attr(struct ufs_hba *hba, enum query_opcode opcode,int ufshcd_query_flag (struct ufs_hba *hba,enum query_opcode opcode,enum flag_idn idn,u8 index,bool *flag_res);void ufshcd_auto_hibern8_update (struct ufs_hba *hba,u32 ahit); -void ufshcd_compl_one_cqe (struct ufs_hba *hba,int task_tag, -struct cq_entry *cqe); +bool ufshcd_compl_one_cqe (struct ufs_hba *hba,int task_tag, +struct cq_entry *cqe,struct scsi_cmnd *compl_cmd);int ufshcd_mcq_init (struct ufs_hba *hba);int ufshcd_mcq_decide_queue_depth (struct ufs_hba *hba);int ufshcd_mcq_memory_alloc (struct ufs_hba *hba);
drivers/ufs/core/ufshcd.c +27 -12
@@ -5540,9 +5540,12 @@ void ufshcd_release_scsi_cmd(struct ufs_hba *hba,* @hba: per adapter instance * @task_tag: the task tag of the request to be completed * @cqe: pointer to the completion queue entry +* @compl_cmd: if not NULL, check whether this command has been completed +* +* Returns: true if and only if @compl_cmd has been completed. */ -void ufshcd_compl_one_cqe (struct ufs_hba *hba,int task_tag, -struct cq_entry *cqe) +bool ufshcd_compl_one_cqe (struct ufs_hba *hba,int task_tag, +struct cq_entry *cqe,struct scsi_cmnd *compl_cmd) {struct ufshcd_lrb *lrbp;struct scsi_cmnd *cmd;
@@ -5559,6 +5562,7 @@ void ufshcd_compl_one_cqe(struct ufs_hba *hba, int task_tag,ufshcd_release_scsi_cmd (hba, lrbp);/* Do not touch lrbp after scsi done */ scsi_done (cmd); +return cmd == compl_cmd; }else if (lrbp->command_type ==UTP_CMD_TYPE_DEV_MANAGE || lrbp->command_type ==UTP_CMD_TYPE_UFS_STORAGE ) {if (hba->dev_cmd.complete) {
@@ -5569,6 +5573,7 @@ void ufshcd_compl_one_cqe(struct ufs_hba *hba, int task_tag,complete (hba->dev_cmd.complete); } } +return false; }/**
@@ -5577,12 +5582,15 @@ void ufshcd_compl_one_cqe(struct ufs_hba *hba, int task_tag,* @completed_reqs: bitmask that indicates which requests to complete */ static void __ufshcd_transfer_req_compl (struct ufs_hba *hba, -unsigned long completed_reqs) +unsigned long completed_reqs, +struct scsi_cmnd **compl_cmd) {int tag;for_each_set_bit (tag, &completed_reqs, hba->nutrs) -ufshcd_compl_one_cqe (hba, tag,NULL ); +if (ufshcd_compl_one_cqe (hba, tag,NULL , + compl_cmd ? *compl_cmd :NULL )) + *compl_cmd =NULL ; }/* Any value that is not an existing queue number is fine for this constant. */
@@ -5609,7 +5617,8 @@ static void ufshcd_clear_polled(struct ufs_hba *hba,* Return: > 0 if one or more commands have been completed or 0 if no * requests have been completed. */ -static int ufshcd_poll (struct Scsi_Host *shost,unsigned int queue_num) +static int __ufshcd_poll (struct Scsi_Host *shost,unsigned int queue_num, +struct scsi_cmnd **compl_cmd) {struct ufs_hba *hba =shost_priv (shost);unsigned long completed_reqs, flags;
@@ -5620,7 +5629,7 @@ static int ufshcd_poll(struct Scsi_Host *shost, unsigned int queue_num)WARN_ON_ONCE (queue_num ==UFSHCD_POLL_FROM_INTERRUPT_CONTEXT ); hwq = &hba->uhq[queue_num]; -return ufshcd_mcq_poll_cqe_lock (hba, hwq); +return ufshcd_mcq_poll_cqe_lock (hba, hwq, compl_cmd); }spin_lock_irqsave (&hba->outstanding_lock, flags);
@@ -5637,11 +5646,16 @@ static int ufshcd_poll(struct Scsi_Host *shost, unsigned int queue_num)spin_unlock_irqrestore (&hba->outstanding_lock, flags);if (completed_reqs) -__ufshcd_transfer_req_compl (hba, completed_reqs); +__ufshcd_transfer_req_compl (hba, completed_reqs, compl_cmd);return completed_reqs !=0 ; } +static int ufshcd_poll (struct Scsi_Host *shost,unsigned int queue_num) +{ +return __ufshcd_poll (shost, queue_num,NULL ); +} +/** * ufshcd_mcq_compl_pending_transfer - MCQ mode function. It is * invoked from the error handler context or ufshcd_host_reset_and_restore()
@@ -5685,7 +5699,7 @@ static void ufshcd_mcq_compl_pending_transfer(struct ufs_hba *hba, }spin_unlock_irqrestore (&hwq->cq_lock, flags); }else { -ufshcd_mcq_poll_cqe_lock (hba, hwq); +ufshcd_mcq_poll_cqe_lock (hba, hwq,NULL ); } } }
@@ -6960,7 +6974,7 @@ static irqreturn_t ufshcd_handle_mcq_cq_events(struct ufs_hba *hba)ufshcd_mcq_write_cqis (hba, events, i);if (events &UFSHCD_MCQ_CQIS_TAIL_ENT_PUSH_STS ) -ufshcd_mcq_poll_cqe_lock (hba, hwq); +ufshcd_mcq_poll_cqe_lock (hba, hwq,NULL ); }return IRQ_HANDLED ;
@@ -7453,7 +7467,7 @@ static int ufshcd_eh_device_reset_handler(struct scsi_cmnd *cmd) lrbp->lun == lun) {ufshcd_clear_cmd (hba, pos); hwq =ufshcd_mcq_req_to_hwq (hba,scsi_cmd_to_rq (lrbp->cmd)); -ufshcd_mcq_poll_cqe_lock (hba, hwq); +ufshcd_mcq_poll_cqe_lock (hba, hwq,NULL ); } } err =0 ;
@@ -7481,7 +7495,8 @@ static int ufshcd_eh_device_reset_handler(struct scsi_cmnd *cmd) __func__, pos); } } -__ufshcd_transfer_req_compl (hba, pending_reqs & ~not_cleared_mask); +__ufshcd_transfer_req_compl (hba, pending_reqs & ~not_cleared_mask, +NULL ); out: hba->req_abort_count =0 ;
@@ -7658,7 +7673,7 @@ static int ufshcd_abort(struct scsi_cmnd *cmd)dev_err (hba->dev,"%s: cmd was completed, but without a notifying intr, tag = %d" , __func__, tag); -__ufshcd_transfer_req_compl (hba,1UL << tag); +__ufshcd_transfer_req_compl (hba,1UL << tag,NULL ); goto release; }
drivers/ufs/host/ufs-qcom.c +1 -1
@@ -1704,7 +1704,7 @@ static irqreturn_t ufs_qcom_mcq_esi_handler(int irq, void *data)struct ufs_hw_queue *hwq = &hba->uhq[id];ufshcd_mcq_write_cqis (hba,0x1 , id); -ufshcd_mcq_poll_cqe_lock (hba, hwq); +ufshcd_mcq_poll_cqe_lock (hba, hwq,NULL );return IRQ_HANDLED ; }
include/ufs/ufshcd.h +2 -1
@@ -1263,7 +1263,8 @@ void ufshcd_mcq_config_mac(struct ufs_hba *hba, u32 max_active_cmds);u32 ufshcd_mcq_read_cqis (struct ufs_hba *hba,int i);void ufshcd_mcq_write_cqis (struct ufs_hba *hba,u32 val,int i);unsigned long ufshcd_mcq_poll_cqe_lock (struct ufs_hba *hba, -struct ufs_hw_queue *hwq); +struct ufs_hw_queue *hwq, +struct scsi_cmnd **compl_cmd);void ufshcd_mcq_make_queues_operational (struct ufs_hba *hba);void ufshcd_mcq_enable_esi (struct ufs_hba *hba);void ufshcd_mcq_enable (struct ufs_hba *hba);
Avri Altman
reviewerRE: [PATCH 3/4] scsi: ufs: Make the polling code report which command has been completed
Quoted 31 lines
Prepare for introducing a new
__ufshcd_poll()caller that will need to know whether or not a specific command has been completed.Signed-off-by Bart Van Assche <[email protected]>--- drivers/ufs/core/ufs-mcq.c | 23 +++++++++++++------- drivers/ufs/core/ufshcd-priv.h | 4 ++-- drivers/ufs/core/ufshcd.c | 39 +++++++++++++++++++++++----------- drivers/ufs/host/ufs-qcom.c | 2 +- include/ufs/ufshcd.h | 3 ++- 5 files changed, 47 insertions(+), 24 deletions(-)drivers/ufs/core/ufs-mcq.c +4
-3@@ -268,17 +268,20 @@ static int ufshcd_mcq_get_tag(struct ufs_hba *hba, struct cq_entry *cqe)return div_u64 (addr,ufshcd_get_ucd_size (hba)); } -static void ufshcd_mcq_process_cqe (struct ufs_hba *hba, -struct ufs_hw_queue *hwq) +/* Returns true if and only if @compl_cmd has been completed. */ +static bool ufshcd_mcq_process_cqe (struct ufs_hba *hba, +struct ufs_hw_queue *hwq, +struct scsi_cmnd *compl_cmd) {struct cq_entry *cqe =ufshcd_mcq_cur_cqe (hwq); -int tag =ufshcd_mcq_get_tag (hba, cqe);
drivers/ufs/core/ufs-mcq.c static int ufshcd_mcq_get_tag(struct ufs_hba *hba, · line 286
Quoted 10 lines
drivers/ufs/core/ufs-mcq.c +4
-2if (cqe->command_desc_base_addr) { -ufshcd_compl_one_cqe (hba, tag, cqe); -/* After processed the cqe, mark it empty (invalid) entry */ +const int tag =ufshcd_mcq_get_tag (hba, cqe); +/* Mark the CQE as invalid. */ cqe->command_desc_base_addr =0 ; +return ufshcd_compl_one_cqe (hba, tag, cqe, compl_cmd); } +return false; }
Maybe elaborate on explaining why the tag isn't enough to designate the completing command?
Thanks,
Avri
Quoted 230 lines
drivers/ufs/core/ufs-mcq.c +1
-1void ufshcd_mcq_compl_all_cqes_lock(struct ufs_hba *hba,@@ -289,7 +292,7 @@ void ufshcd_mcq_compl_all_cqes_lock(struct ufs_hba *hba,spin_lock_irqsave (&hwq->cq_lock, flags);while (entries >0 ) { -ufshcd_mcq_process_cqe (hba, hwq); +ufshcd_mcq_process_cqe (hba, hwq,NULL );ufshcd_mcq_inc_cq_head_slot (hwq); entries--;}drivers/ufs/core/ufs-mcq.c +3
-1@@ -299,8 +302,10 @@ void ufshcd_mcq_compl_all_cqes_lock(struct ufs_hba *hba,spin_unlock_irqrestore (&hwq->cq_lock, flags); } +/* Clears *@compl_cmd if and only if *@compl_cmd has been completed. */ unsigned long ufshcd_mcq_poll_cqe_lock (struct ufs_hba *hba, -struct ufs_hw_queue *hwq) +struct ufs_hw_queue *hwq, +struct scsi_cmnd **compl_cmd) {unsigned long completed_reqs =0 ;unsigned long flags;drivers/ufs/core/ufs-mcq.c +3
-1@@ -308,7 +313,9 @@ unsigned long ufshcd_mcq_poll_cqe_lock(struct ufs_hba *hba,spin_lock_irqsave (&hwq->cq_lock, flags);ufshcd_mcq_update_cq_tail_slot (hwq);while (!ufshcd_mcq_is_cq_empty (hwq)) { -ufshcd_mcq_process_cqe (hba, hwq); +if (ufshcd_mcq_process_cqe (hba, hwq, + compl_cmd ? *compl_cmd :NULL )) + *compl_cmd =NULL ;ufshcd_mcq_inc_cq_head_slot (hwq); completed_reqs++;}drivers/ufs/core/ufshcd-priv.h +2
-2@@ -61,8 +61,8 @@ int ufshcd_query_attr(struct ufs_hba *hba, enumquery_opcode opcode, int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode,enum flag_idn idn,u8 index,bool *flag_res);void ufshcd_auto_hibern8_update (struct ufs_hba *hba,u32 ahit); -void ufshcd_compl_one_cqe (struct ufs_hba *hba,int task_tag, -struct cq_entry *cqe); +bool ufshcd_compl_one_cqe (struct ufs_hba *hba,int task_tag, +struct cq_entry *cqe,struct scsi_cmnd *compl_cmd);int ufshcd_mcq_init (struct ufs_hba *hba);int ufshcd_mcq_decide_queue_depth (struct ufs_hba *hba);int
ufshcd_mcq_memory_alloc(struct ufs_hba *hba);drivers/ufs/core/ufshcd.c +1
-0@@ -5540,9 +5540,12 @@ void ufshcd_release_scsi_cmd(struct ufs_hba *hba,* @hba: per adapter instance * @task_tag: the task tag of the request to be completed * @cqe: pointer to the completion queue entry +* @compl_cmd: if not NULL, check whether this command has been completed
+ *
+ * Returns: true if and only if @compl_cmd has been completed. */drivers/ufs/core/ufshcd.c +3
-2-void ufshcd_compl_one_cqe (struct ufs_hba *hba,int task_tag, -struct cq_entry *cqe) +bool ufshcd_compl_one_cqe (struct ufs_hba *hba,int task_tag, +struct cq_entry *cqe,struct scsi_cmnd *compl_cmd) {struct ufshcd_lrb *lrbp;struct scsi_cmnd *cmd;@@ -5559,6 +5562,7 @@ void ufshcd_compl_one_cqe(struct ufs_hba *hba, int task_tag,ufshcd_release_scsi_cmd (hba, lrbp);/* Do not touch lrbp after scsi done */ scsi_done (cmd); +return cmd == compl_cmd; }else if (lrbp->command_type ==UTP_CMD_TYPE_DEV_MANAGE || lrbp->command_type ==UTP_CMD_TYPE_UFS_STORAGE ) {if (hba->dev_cmd.complete) {drivers/ufs/core/ufshcd.c +1
-0@@ -5569,6 +5573,7 @@ void ufshcd_compl_one_cqe(struct ufs_hba *hba, int task_tag,complete (hba->dev_cmd.complete); } } +return false; }/**
drivers/ufs/core/ufshcd.c +5
-2@@ -5577,12 +5582,15 @@ void ufshcd_compl_one_cqe(struct ufs_hba *hba,int task_tag, * @completed_reqs: bitmask that indicates which requests to complete */ static void __ufshcd_transfer_req_compl (struct ufs_hba *hba, -unsigned long completed_reqs) +unsigned long completed_reqs, +struct scsi_cmnd **compl_cmd) {int tag;for_each_set_bit (tag, &completed_reqs, hba->nutrs) -ufshcd_compl_one_cqe (hba, tag,NULL ); +if (ufshcd_compl_one_cqe (hba, tag,NULL , + compl_cmd ? *compl_cmd :NULL )) + *compl_cmd =NULL ; }/* Any value that is not an existing queue number is fine for this constant. */
drivers/ufs/core/ufshcd.c +3
-2@@ -5609,7 +5617,8 @@ static void ufshcd_clear_polled(struct ufs_hba *hba,* Return: > 0 if one or more commands have been completed or 0 if no * requests have been completed. */ -static int ufshcd_poll (struct Scsi_Host *shost,unsigned int queue_num) +static int __ufshcd_poll (struct Scsi_Host *shost,unsigned int queue_num, +struct scsi_cmnd **compl_cmd) {struct ufs_hba *hba =shost_priv (shost);unsigned long completed_reqs, flags;@@ -5620,7 +5629,7 @@ static int ufshcd_poll(struct Scsi_Host *shost, unsigned int queue_num) WARN_ON_ONCE(queue_num ==UFSHCD_POLL_FROM_INTERRUPT_CONTEXT ); hwq = &hba->uhq[queue_num]; -return ufshcd_mcq_poll_cqe_lock (hba, hwq); +return ufshcd_mcq_poll_cqe_lock (hba, hwq, compl_cmd); }spin_lock_irqsave(&hba->outstanding_lock, flags);drivers/ufs/core/ufshcd.c +6
-1@@ -5637,11 +5646,16 @@ static int ufshcd_poll(struct Scsi_Host *shost, unsigned int queue_num) spin_unlock_irqrestore(&hba->outstanding_lock, flags);if (completed_reqs) -__ufshcd_transfer_req_compl (hba, completed_reqs); +__ufshcd_transfer_req_compl (hba, completed_reqs, compl_cmd);return completed_reqs !=0 ; } +static int ufshcd_poll (struct Scsi_Host *shost,unsigned int queue_num) +{ +return __ufshcd_poll (shost, queue_num,NULL ); +} +/** * ufshcd_mcq_compl_pending_transfer - MCQ mode function. It is * invoked from the error handler context or
ufshcd_host_reset_and_restore()drivers/ufs/core/ufshcd.c +1
-1@@ -5685,7 +5699,7 @@ static void ufshcd_mcq_compl_pending_transfer(struct ufs_hba *hba, }spin_unlock_irqrestore (&hwq->cq_lock, flags); }else { -ufshcd_mcq_poll_cqe_lock (hba, hwq); +ufshcd_mcq_poll_cqe_lock (hba, hwq,NULL ); } }}
drivers/ufs/core/ufshcd.c +1
-1@@ -6960,7 +6974,7 @@ static irqreturn_t ufshcd_handle_mcq_cq_events(struct ufs_hba *hba)ufshcd_mcq_write_cqis (hba, events, i);if (events &UFSHCD_MCQ_CQIS_TAIL_ENT_PUSH_STS ) -ufshcd_mcq_poll_cqe_lock (hba, hwq); +ufshcd_mcq_poll_cqe_lock (hba, hwq,NULL ); }return IRQ_HANDLED;drivers/ufs/core/ufshcd.c +1
-1@@ -7453,7 +7467,7 @@ static int ufshcd_eh_device_reset_handler(struct scsi_cmnd *cmd) lrbp->lun == lun) {ufshcd_clear_cmd (hba, pos); hwq =ufshcd_mcq_req_to_hwq (hba,scsi_cmd_to_rq (lrbp- >cmd)); -ufshcd_mcq_poll_cqe_lock (hba, hwq); +ufshcd_mcq_poll_cqe_lock (hba, hwq,NULL ); }} err = 0;drivers/ufs/core/ufshcd.c +2
-1@@ -7481,7 +7495,8 @@ static int ufshcd_eh_device_reset_handler(struct scsi_cmnd *cmd) __func__, pos); } } -__ufshcd_transfer_req_compl (hba, pending_reqs & ~not_cleared_mask); +__ufshcd_transfer_req_compl (hba, pending_reqs & ~not_cleared_mask, +NULL ); out:hba->req_abort_count = 0;drivers/ufs/core/ufshcd.c +1
-1@@ -7658,7 +7673,7 @@ static int ufshcd_abort(struct scsi_cmnd *cmd)dev_err (hba->dev,"%s: cmd was completed, but without a notifying intr, tag = %d" , __func__, tag); -__ufshcd_transfer_req_compl (hba,1UL << tag); +__ufshcd_transfer_req_compl (hba,1UL << tag,NULL ); goto release; }drivers/ufs/host/ufs-qcom.c +1
-1@@ -1704,7 +1704,7 @@ static irqreturn_t ufs_qcom_mcq_esi_handler(int irq, void *data)struct ufs_hw_queue *hwq = &hba->uhq[id];ufshcd_mcq_write_cqis (hba,0x1 , id); -ufshcd_mcq_poll_cqe_lock (hba, hwq); +ufshcd_mcq_poll_cqe_lock (hba, hwq,NULL );return IRQ_HANDLED ;}
include/ufs/ufshcd.h +2
-1@@ -1263,7 +1263,8 @@ void ufshcd_mcq_config_mac(struct ufs_hba *hba, u32 max_active_cmds);u32 ufshcd_mcq_read_cqis (struct ufs_hba *hba,int i);void ufshcd_mcq_write_cqis (struct ufs_hba *hba,u32 val,int i);unsigned long ufshcd_mcq_poll_cqe_lock (struct ufs_hba *hba, -struct ufs_hw_queue *hwq); +struct ufs_hw_queue *hwq, +struct scsi_cmnd **compl_cmd);void ufshcd_mcq_make_queues_operational (struct ufs_hba *hba);void ufshcd_mcq_enable_esi (struct ufs_hba *hba);void
ufshcd_mcq_enable(struct ufs_hba *hba);
Bart Van Assche
reviewerRe: [PATCH 3/4] scsi: ufs: Make the polling code report which command has been completed
Quoted 10 lines · Avri Altman
Quoted 10 lines
drivers/ufs/core/ufs-mcq.c +4
-3-static void ufshcd_mcq_process_cqe (struct ufs_hba *hba, -struct ufs_hw_queue *hwq) +/* Returns true if and only if @compl_cmd has been completed. */ +static bool ufshcd_mcq_process_cqe (struct ufs_hba *hba, +struct ufs_hw_queue *hwq, +struct scsi_cmnd *compl_cmd) {struct cq_entry *cqe =ufshcd_mcq_cur_cqe (hwq); -int tag =ufshcd_mcq_get_tag (hba, cqe);
Quoted 12 lines
drivers/ufs/core/ufs-mcq.c static int ufshcd_mcq_get_tag(struct ufs_hba *hba, struct cq_entry *cqe) · line 285
Quoted 10 lines
if (cqe->command_desc_base_addr) {drivers/ufs/core/ufs-mcq.c +4
-2-ufshcd_compl_one_cqe (hba, tag, cqe); -/* After processed the cqe, mark it empty (invalid) entry */ +const int tag =ufshcd_mcq_get_tag (hba, cqe); +/* Mark the CQE as invalid. */ cqe->command_desc_base_addr =0 ; +return ufshcd_compl_one_cqe (hba, tag, cqe, compl_cmd); } +return false; }Maybe elaborate on explaining why the tag isn't enough to designate the completing command?
Hi Avri,
Anything that uniquely identifies a SCSI command would work. I think it's more a matter of making a choice rather than arguing why not using the blk_mq_unique_tag_to_hwq() return value?
Thanks,
Bart.
Re: [PATCH 3/4] scsi: ufs: Make the polling code report which command has been completed
In reply to Bart Van AsscheQuoted 9 lines · Bart Van Assche
External email : Please do not click links or open attachments until you have verified the sender or the content.
Prepare for introducing a new__ufshcd_poll()caller that will need
to
know whether or not a specific command has been completed.Signed-off-by Bart Van Assche <[email protected]>
Hi Bart,
Please also change ufs-medatek.c ufshcd_mcq_poll_cqe_lock usage.
Thanks.
Peter
Bart Van Assche
reviewerRe: [PATCH 3/4] scsi: ufs: Make the polling code report which command has been completed
Quoted 1 line · Peter Wang (王信友)
Please also change
ufs-medatek.cufshcd_mcq_poll_cqe_lockusage.
Will do. Thanks for having reported this.
Bart.
kernel test robot
build botRe: [PATCH 3/4] scsi: ufs: Make the polling code report which command has been completed
In reply to Bart Van Asschekernel test robot noticed the following build errors:
Hi Bart,
kernel test robot noticed the following build errors:
[auto build test ERROR on mkp-scsi/for-next]
[also build test ERROR on jejb-scsi/for-next linus/master v6.9-rc3 next-20240412] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Bart-Van-Assche/scsi-ufs-Declare-ufshcd_mcq_poll_cqe_lock-once/20240412-080540 base: https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next patch link: https://lore.kernel.org/r/20240412000246.1167600-4-bvanassche%40acm.org patch subject: [PATCH 3/4] scsi: ufs: Make the polling code report which command has been completed config: arm-allmodconfig (https://download.01.org/0day-ci/archive/20240412/[email protected]/config) compiler: arm-linux-gnueabi-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240412/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
drivers/ufs/host/ufs-mediatek.c: In function 'ufs_mtk_mcq_intr':
>> drivers/ufs/host/ufs-mediatek.c:1717:17: error: too few arguments to function 'ufshcd_mcq_poll_cqe_lock'
1717 | ufshcd_mcq_poll_cqe_lock(hba, hwq);
| ^~~~~~~~~~~~~~~~~~~~~~~~ In file included from drivers/ufs/host/ufs-mediatek.c:23:
include/ufs/ufshcd.h:1267:15: note: declared here
1267 | unsigned long ufshcd_mcq_poll_cqe_lock(struct ufs_hba *hba,
| ^~~~~~~~~~~~~~~~~~~~~~~~
vim +/ufshcd_mcq_poll_cqe_lock +1717 drivers/ufs/host/ufs-mediatek.c
e152a616c88653 Po-Wen Kao 2023-07-01 1701
e152a616c88653 Po-Wen Kao 2023-07-01 1702 static irqreturn_t ufs_mtk_mcq_intr(int irq, void *__intr_info)
e152a616c88653 Po-Wen Kao 2023-07-01 1703 {
e152a616c88653 Po-Wen Kao 2023-07-01 1704 struct ufs_mtk_mcq_intr_info *mcq_intr_info = __intr_info;
e152a616c88653 Po-Wen Kao 2023-07-01 1705 struct ufs_hba *hba = mcq_intr_info->hba;
e152a616c88653 Po-Wen Kao 2023-07-01 1706 struct ufs_hw_queue *hwq;
e152a616c88653 Po-Wen Kao 2023-07-01 1707 u32 events;
e152a616c88653 Po-Wen Kao 2023-07-01 1708 int qid = mcq_intr_info->qid;
e152a616c88653 Po-Wen Kao 2023-07-01 1709
e152a616c88653 Po-Wen Kao 2023-07-01 1710 hwq = &hba->uhq[qid];
e152a616c88653 Po-Wen Kao 2023-07-01 1711
e152a616c88653 Po-Wen Kao 2023-07-01 1712 events = ufshcd_mcq_read_cqis(hba, qid);
e152a616c88653 Po-Wen Kao 2023-07-01 1713 if (events)
e152a616c88653 Po-Wen Kao 2023-07-01 1714 ufshcd_mcq_write_cqis(hba, events, qid);
e152a616c88653 Po-Wen Kao 2023-07-01 1715
e152a616c88653 Po-Wen Kao 2023-07-01 1716 if (events & UFSHCD_MCQ_CQIS_TAIL_ENT_PUSH_STS)
e152a616c88653 Po-Wen Kao 2023-07-01 @1717 ufshcd_mcq_poll_cqe_lock(hba, hwq);
e152a616c88653 Po-Wen Kao 2023-07-01 1718
e152a616c88653 Po-Wen Kao 2023-07-01 1719 return IRQ_HANDLED;
e152a616c88653 Po-Wen Kao 2023-07-01 1720 }
e152a616c88653 Po-Wen Kao 2023-07-01 1721 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH 3/4] scsi: ufs: Make the polling code report which command has been completed
In reply to Bart Van Asschekernel test robot noticed the following build errors:
Hi Bart,
kernel test robot noticed the following build errors:
[auto build test ERROR on mkp-scsi/for-next]
[also build test ERROR on jejb-scsi/for-next linus/master v6.9-rc3 next-20240412] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Bart-Van-Assche/scsi-ufs-Declare-ufshcd_mcq_poll_cqe_lock-once/20240412-080540 base: https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next patch link: https://lore.kernel.org/r/20240412000246.1167600-4-bvanassche%40acm.org patch subject: [PATCH 3/4] scsi: ufs: Make the polling code report which command has been completed config: arm64-allmodconfig (https://download.01.org/0day-ci/archive/20240412/[email protected]/config) compiler: clang version 19.0.0git (https://github.com/llvm/llvm-project 8b3b4a92adee40483c27f26c478a384cd69c6f05) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240412/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from drivers/ufs/host/ufs-mediatek.c:18:
In file included from include/linux/phy/phy.h:17:
In file included from include/linux/regulator/consumer.h:35:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:21:
In file included from include/linux/mm.h:2208:
include/linux/vmstat.h:508:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
508 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~ ^
509 | item];
| ~~~~
include/linux/vmstat.h:515:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
515 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~ ^
516 | NR_VM_NUMA_EVENT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~~
include/linux/vmstat.h:522:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
522 | return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
| ~~~~~~~~~~~ ^ ~~~
include/linux/vmstat.h:527:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
527 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~ ^
528 | NR_VM_NUMA_EVENT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~~
include/linux/vmstat.h:536:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
536 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~ ^
537 | NR_VM_NUMA_EVENT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~~
>> drivers/ufs/host/ufs-mediatek.c:1717:36: error: too few arguments to function call, expected 3, have 2
1717 | ufshcd_mcq_poll_cqe_lock(hba, hwq);
| ~~~~~~~~~~~~~~~~~~~~~~~~ ^
include/ufs/ufshcd.h:1267:15: note: 'ufshcd_mcq_poll_cqe_lock' declared here
1267 | unsigned long ufshcd_mcq_poll_cqe_lock(struct ufs_hba *hba,
| ^ ~~~~~~~~~~~~~~~~~~~~
1268 | struct ufs_hw_queue *hwq,
| ~~~~~~~~~~~~~~~~~~~~~~~~~
1269 | struct scsi_cmnd **compl_cmd);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~5 warnings and 1 error generated.
vim +1717 drivers/ufs/host/ufs-mediatek.c
e152a616c88653 Po-Wen Kao 2023-07-01 1701
e152a616c88653 Po-Wen Kao 2023-07-01 1702 static irqreturn_t ufs_mtk_mcq_intr(int irq, void *__intr_info)
e152a616c88653 Po-Wen Kao 2023-07-01 1703 {
e152a616c88653 Po-Wen Kao 2023-07-01 1704 struct ufs_mtk_mcq_intr_info *mcq_intr_info = __intr_info;
e152a616c88653 Po-Wen Kao 2023-07-01 1705 struct ufs_hba *hba = mcq_intr_info->hba;
e152a616c88653 Po-Wen Kao 2023-07-01 1706 struct ufs_hw_queue *hwq;
e152a616c88653 Po-Wen Kao 2023-07-01 1707 u32 events;
e152a616c88653 Po-Wen Kao 2023-07-01 1708 int qid = mcq_intr_info->qid;
e152a616c88653 Po-Wen Kao 2023-07-01 1709
e152a616c88653 Po-Wen Kao 2023-07-01 1710 hwq = &hba->uhq[qid];
e152a616c88653 Po-Wen Kao 2023-07-01 1711
e152a616c88653 Po-Wen Kao 2023-07-01 1712 events = ufshcd_mcq_read_cqis(hba, qid);
e152a616c88653 Po-Wen Kao 2023-07-01 1713 if (events)
e152a616c88653 Po-Wen Kao 2023-07-01 1714 ufshcd_mcq_write_cqis(hba, events, qid);
e152a616c88653 Po-Wen Kao 2023-07-01 1715
e152a616c88653 Po-Wen Kao 2023-07-01 1716 if (events & UFSHCD_MCQ_CQIS_TAIL_ENT_PUSH_STS)
e152a616c88653 Po-Wen Kao 2023-07-01 @1717 ufshcd_mcq_poll_cqe_lock(hba, hwq);
e152a616c88653 Po-Wen Kao 2023-07-01 1718
e152a616c88653 Po-Wen Kao 2023-07-01 1719 return IRQ_HANDLED;
e152a616c88653 Po-Wen Kao 2023-07-01 1720 }
e152a616c88653 Po-Wen Kao 2023-07-01 1721 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH 3/4] scsi: ufs: Make the polling code report which command has been completed
In reply to Bart Van Asschekernel test robot noticed the following build warnings:
Hi Bart,
kernel test robot noticed the following build warnings:
[auto build test WARNING on mkp-scsi/for-next]
[also build test WARNING on jejb-scsi/for-next linus/master v6.9-rc3 next-20240412] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Bart-Van-Assche/scsi-ufs-Declare-ufshcd_mcq_poll_cqe_lock-once/20240412-080540 base: https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next patch link: https://lore.kernel.org/r/20240412000246.1167600-4-bvanassche%40acm.org patch subject: [PATCH 3/4] scsi: ufs: Make the polling code report which command has been completed config: i386-randconfig-061-20240412 (https://download.01.org/0day-ci/archive/20240412/[email protected]/config) compiler: gcc-13 (Ubuntu 13.2.0-4ubuntu3) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240412/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/ufs/core/ufshcd.c:5587: warning: Function parameter or struct member 'compl_cmd' not described in '__ufshcd_transfer_req_compl'
vim +5587 drivers/ufs/core/ufshcd.c
c30d8d010b5efd drivers/ufs/core/ufshcd.c Asutosh Das 2023-01-13 5578
c30d8d010b5efd drivers/ufs/core/ufshcd.c Asutosh Das 2023-01-13 5579 /**
c30d8d010b5efd drivers/ufs/core/ufshcd.c Asutosh Das 2023-01-13 5580 * __ufshcd_transfer_req_compl - handle SCSI and query command completion
c30d8d010b5efd drivers/ufs/core/ufshcd.c Asutosh Das 2023-01-13 5581 * @hba: per adapter instance
c30d8d010b5efd drivers/ufs/core/ufshcd.c Asutosh Das 2023-01-13 5582 * @completed_reqs: bitmask that indicates which requests to complete
c30d8d010b5efd drivers/ufs/core/ufshcd.c Asutosh Das 2023-01-13 5583 */
c30d8d010b5efd drivers/ufs/core/ufshcd.c Asutosh Das 2023-01-13 5584 static void __ufshcd_transfer_req_compl(struct ufs_hba *hba,
56399aa6ca74cf drivers/ufs/core/ufshcd.c Bart Van Assche 2024-04-11 5585 unsigned long completed_reqs,
56399aa6ca74cf drivers/ufs/core/ufshcd.c Bart Van Assche 2024-04-11 5586 struct scsi_cmnd **compl_cmd)
c30d8d010b5efd drivers/ufs/core/ufshcd.c Asutosh Das 2023-01-13 @5587 {
c30d8d010b5efd drivers/ufs/core/ufshcd.c Asutosh Das 2023-01-13 5588 int tag;
c30d8d010b5efd drivers/ufs/core/ufshcd.c Asutosh Das 2023-01-13 5589
c30d8d010b5efd drivers/ufs/core/ufshcd.c Asutosh Das 2023-01-13 5590 for_each_set_bit(tag, &completed_reqs, hba->nutrs)
56399aa6ca74cf drivers/ufs/core/ufshcd.c Bart Van Assche 2024-04-11 5591 if (ufshcd_compl_one_cqe(hba, tag, NULL,
56399aa6ca74cf drivers/ufs/core/ufshcd.c Bart Van Assche 2024-04-11 5592 compl_cmd ? *compl_cmd : NULL))
56399aa6ca74cf drivers/ufs/core/ufshcd.c Bart Van Assche 2024-04-11 5593 *compl_cmd = NULL;
a45f937110fa6b drivers/scsi/ufs/ufshcd.c Can Guo 2021-05-24 5594 }7a3e97b0dc4bba drivers/scsi/ufs/ufshcd.c Santosh Yaraganavi 2012-02-29 5595
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Bart Van Assche
reviewerPATCH 4/4 scsi: ufs: Check for completion from the timeout handler
In reply to Bart Van AsscheIf ufshcd_abort() returns SUCCESS for an already completed command then that command is completed twice. This results in a crash. Prevent this by checking whether a command has completed without completion interrupt from the timeout handler. This CL fixes the following kernel crash:
Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000 Call trace: dma_direct_map_sg+0x70/0x274 scsi_dma_map+0x84/0x124 ufshcd_queuecommand+0x3fc/0x880 scsi_queue_rq+0x7d0/0x111c blk_mq_dispatch_rq_list+0x440/0xebc blk_mq_do_dispatch_sched+0x5a4/0x6b8 __blk_mq_sched_dispatch_requests+0x150/0x220 __blk_mq_run_hw_queue+0xf0/0x218 __blk_mq_delay_run_hw_queue+0x8c/0x18c blk_mq_run_hw_queue+0x1a4/0x360 blk_mq_sched_insert_requests+0x130/0x334 blk_mq_flush_plug_list+0x138/0x234 blk_flush_plug_list+0x118/0x164 blk_finish_plug() read_pages+0x38c/0x408 page_cache_ra_unbounded+0x230/0x2f8 do_sync_mmap_readahead+0x1a4/0x208 filemap_fault+0x27c/0x8f4 f2fs_filemap_fault+0x28/0xfc __do_fault+0xc4/0x208 handle_pte_fault+0x290/0xe04 do_handle_mm_fault+0x52c/0x858 do_page_fault+0x5dc/0x798 do_translation_fault+0x40/0x54 do_mem_abort+0x60/0x134 el0_da+0x40/0xb8 el0t_64_sync_handler+0xc4/0xe4 el0t_64_sync+0x1b4/0x1b8
--- drivers/ufs/core/ufshcd.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
drivers/ufs/core/ufshcd.c +19 -0
@@ -9022,6 +9022,25 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie)static enum scsi_timeout_action ufshcd_eh_timed_out (struct scsi_cmnd *scmd) {struct ufs_hba *hba =shost_priv (scmd->device->host); +struct scsi_cmnd *cmd2 = scmd; + +WARN_ON_ONCE (!scmd); + +if (is_mcq_enabled (hba)) { +struct ufs_hw_queue *hwq = +ufshcd_mcq_req_to_hwq (hba,scsi_cmd_to_rq (scmd)); + +ufshcd_mcq_poll_cqe_lock (hba, hwq, &cmd2); + }else { +__ufshcd_poll (hba->host,UFSHCD_POLL_FROM_INTERRUPT_CONTEXT , + &cmd2); + } +if (cmd2 ==NULL ) { +sdev_printk (KERN_INFO , scmd->device, +"%s: cmd with tag %#x has already been completed\n" , + __func__,blk_mq_unique_tag (scsi_cmd_to_rq (scmd))); +return SCSI_EH_DONE ; + }if (!hba->system_suspending) {/* Activate the error handler in the SCSI core. */
Re: [PATCH 4/4] scsi: ufs: Check for completion from the timeout handler
Quoted 61 lines · Bart Van Assche
External email : Please do not click links or open attachments until you have verified the sender or the content.
Ifufshcd_abort()returns SUCCESS for an already completed command
then
that command is completed twice. This results in a crash. Prevent this by
checking whether a command has completed without completion interrupt from
the timeout handler. This CL fixes the following kernel crash:Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000 Call trace: dma_direct_map_sg+0x70/0x274 scsi_dma_map+0x84/0x124 ufshcd_queuecommand+0x3fc/0x880 scsi_queue_rq+0x7d0/0x111c blk_mq_dispatch_rq_list+0x440/0xebc blk_mq_do_dispatch_sched+0x5a4/0x6b8 __blk_mq_sched_dispatch_requests+0x150/0x220 __blk_mq_run_hw_queue+0xf0/0x218 __blk_mq_delay_run_hw_queue+0x8c/0x18c blk_mq_run_hw_queue+0x1a4/0x360 blk_mq_sched_insert_requests+0x130/0x334 blk_mq_flush_plug_list+0x138/0x234 blk_flush_plug_list+0x118/0x164 blk_finish_plug() read_pages+0x38c/0x408 page_cache_ra_unbounded+0x230/0x2f8 do_sync_mmap_readahead+0x1a4/0x208 filemap_fault+0x27c/0x8f4 f2fs_filemap_fault+0x28/0xfc __do_fault+0xc4/0x208 handle_pte_fault+0x290/0xe04 do_handle_mm_fault+0x52c/0x858 do_page_fault+0x5dc/0x798 do_translation_fault+0x40/0x54 do_mem_abort+0x60/0x134 el0_da+0x40/0xb8 el0t_64_sync_handler+0xc4/0xe4 el0t_64_sync+0x1b4/0x1b8Signed-off-by Bart Van Assche <[email protected]>--- drivers/ufs/core/ufshcd.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)drivers/ufs/core/ufshcd.c +3
-0@@ -9022,6 +9022,25 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie)static enum scsi_timeout_action ufshcd_eh_timed_out (struct scsi_cmnd *scmd) {struct ufs_hba *hba =shost_priv (scmd->device->host); +struct scsi_cmnd *cmd2 = scmd; + +WARN_ON_ONCE (!scmd);
drivers/ufs/core/ufshcd.c static void ufshcd_async_scan(void *data, · line 9039
Quoted 10 lines
drivers/ufs/core/ufshcd.c +9
-0+ +if (is_mcq_enabled (hba)) { +struct ufs_hw_queue *hwq = +ufshcd_mcq_req_to_hwq (hba,scsi_cmd_to_rq (scmd)); + +ufshcd_mcq_poll_cqe_lock (hba, hwq, &cmd2); +}else { +__ufshcd_poll (hba->host,UFSHCD_POLL_FROM_INTERRUPT_CONTEXT , + &cmd2);
may need check __ufshcd_poll return value?
Quoted 10 lines
drivers/ufs/core/ufshcd.c +7
-0+} +if (cmd2 ==NULL ) { +sdev_printk (KERN_INFO , scmd->device, +"%s: cmd with tag %#x has already been completed\n" , + __func__,blk_mq_unique_tag (scsi_cmd_to_rq (scmd))); +return SCSI_EH_DONE ; +}if (!hba->system_suspending) {
/* Activate the error handler in the SCSI core. */
Bart Van Assche
reviewerRe: [PATCH 4/4] scsi: ufs: Check for completion from the timeout handler
Quoted 10 lines · Peter Wang (王信友)
drivers/ufs/core/ufshcd.c static void ufshcd_async_scan(void *data, async_cookie_t cookie) · line 9036
Quoted 8 lines
drivers/ufs/core/ufshcd.c +8
-0+if (is_mcq_enabled (hba)) { +struct ufs_hw_queue *hwq = +ufshcd_mcq_req_to_hwq (hba,scsi_cmd_to_rq (scmd)); + +ufshcd_mcq_poll_cqe_lock (hba, hwq, &cmd2); +}else { +__ufshcd_poll (hba->host,UFSHCD_POLL_FROM_INTERRUPT_CONTEXT , + &cmd2);may need check
__ufshcd_pollreturn value?
I don't think we should do that. __ufshcd_poll() returns a value > 0 if it has completed any SCSI command and may complete commands other than @scmd. In this function we need to know whether or not @scmd has been completed.
Thanks,
Bart.