pm80xx updates
Subsystems (2)
cover pm80xx updates
From: Viswas G <[email protected]>
This patch set include some bug fixes for pm80xx driver.
Viswas G (1):
pm80xx: make running_req atomic.
akshatzen (1):
pm80xx: Avoid busywait in FW ready check
peter chang (1):
pm80xx: make mpi_build_cmd locking consistent
yuuzheng (1):
pm80xx: make pm8001_mpi_set_nvmd_resp free of race condition
drivers/scsi/pm8001/pm8001_hwi.c | 86 +++++++++++++++++++------ drivers/scsi/pm8001/pm8001_init.c | 2 +- drivers/scsi/pm8001/pm8001_sas.c | 11 ++-- drivers/scsi/pm8001/pm8001_sas.h | 2 +- drivers/scsi/pm8001/pm80xx_hwi.c | 130 ++++++++++++++++++++++++++++++-------- drivers/scsi/pm8001/pm80xx_hwi.h | 6 ++ 6 files changed, 185 insertions(+), 52 deletions(-)
Signature · 1 line
2.16.3
PATCH 1/4 pm80xx: make mpi_build_cmd locking consistent
From: peter chang <[email protected]>
the missing task completions appear to be because the driver shadow structures for the command issue queue can get out of sync between issues because the locking is inconsistent (none, host adapter lock, and per-cpu issue queue). the inconsistency is because sata requests issue per-cpu but management commands (eg, aborts etc) issue from queue zero. if a sata request issues from cpu zero when a management request issues, then there is some 'tearing' and the issue queue is sort of broken and we lose track of issues.
disabling interrupts may be overkill because there may not be cases where we're using this from interrupt context (the interrupt path has a different per-queue lock).
--- drivers/scsi/pm8001/pm8001_hwi.c | 21 +++++++++++++++------ drivers/scsi/pm8001/pm80xx_hwi.c | 8 -------- 2 files changed, 15 insertions(+), 14 deletions(-)
drivers/scsi/pm8001/pm8001_hwi.c +15 -6
@@ -1356,12 +1356,19 @@ int pm8001_mpi_build_cmd(struct pm8001_hba_info *pm8001_ha, {u32 Header =0 , hpriority =0 , bc =1 , category =0x02 ;void *pMessage; - -if (pm8001_mpi_msg_free_get (circularQ, pm8001_ha->iomb_size, - &pMessage) <0 ) { +unsigned long flags; +int q_index = circularQ - pm8001_ha->inbnd_q_tbl; +int rv =-1 ; + +WARN_ON (q_index >=PM8001_MAX_INB_NUM ); +spin_lock_irqsave (&circularQ->iq_lock, flags); + rv =pm8001_mpi_msg_free_get (circularQ, pm8001_ha->iomb_size, + &pMessage); +if (rv <0 ) {PM8001_IO_DBG (pm8001_ha, -pm8001_printk ("No free mpi buffer\n" )); -return -ENOMEM ; +pm8001_printk ("No free mpi buffer\n" )); + rv = -ENOMEM ; + goto done; }if (nb > (pm8001_ha->iomb_size -sizeof (struct mpi_msg_hdr )))
@@ -1384,7 +1391,9 @@ int pm8001_mpi_build_cmd(struct pm8001_hba_info *pm8001_ha,pm8001_printk ("INB Q %x OPCODE:%x , UPDATED PI=%d CI=%d\n" , responseQueue, opCode, circularQ->producer_idx, circularQ->consumer_index)); -return 0 ; +done: +spin_unlock_irqrestore (&circularQ->iq_lock, flags); +return rv; } u32 pm8001_mpi_msg_free_set(struct pm8001_hba_info *pm8001_ha, void *pMsg,
drivers/scsi/pm8001/pm80xx_hwi.c +0 -8
@@ -4281,7 +4281,6 @@ static int pm80xx_chip_smp_req(struct pm8001_hba_info *pm8001_ha,char *preq_dma_addr =NULL ;__le64 tmp_addr;u32 i, length; -unsigned long flags;memset (&smp_cmd,0 ,sizeof (smp_cmd));/*
@@ -4377,10 +4376,8 @@ static int pm80xx_chip_smp_req(struct pm8001_hba_info *pm8001_ha,build_smp_cmd (pm8001_dev->device_id, smp_cmd.tag, &smp_cmd, pm8001_ha->smp_exp_mode, length); -spin_lock_irqsave (&circularQ->iq_lock, flags); rc =pm8001_mpi_build_cmd (pm8001_ha, circularQ, opc, &smp_cmd,sizeof (smp_cmd),0 ); -spin_unlock_irqrestore (&circularQ->iq_lock, flags);if (rc) goto err_out_2;return 0 ;
@@ -4444,7 +4441,6 @@ static int pm80xx_chip_ssp_io_req(struct pm8001_hba_info *pm8001_ha,u64 phys_addr, start_addr, end_addr;u32 end_addr_high, end_addr_low;struct inbound_queue_table *circularQ; -unsigned long flags;u32 q_index, cpu_id;u32 opc =OPC_INB_SSPINIIOSTART ;memset (&ssp_cmd,0 ,sizeof (ssp_cmd));
@@ -4582,10 +4578,8 @@ static int pm80xx_chip_ssp_io_req(struct pm8001_hba_info *pm8001_ha, ssp_cmd.esgl =0 ; } } -spin_lock_irqsave (&circularQ->iq_lock, flags); ret =pm8001_mpi_build_cmd (pm8001_ha, circularQ, opc, &ssp_cmd,sizeof (ssp_cmd), q_index); -spin_unlock_irqrestore (&circularQ->iq_lock, flags);return ret; }
@@ -4819,10 +4813,8 @@ static int pm80xx_chip_sata_req(struct pm8001_hba_info *pm8001_ha, } } } -spin_lock_irqsave (&circularQ->iq_lock, flags); ret =pm8001_mpi_build_cmd (pm8001_ha, circularQ, opc, &sata_cmd,sizeof (sata_cmd), q_index); -spin_unlock_irqrestore (&circularQ->iq_lock, flags);return ret; }
Signature · 1 line
2.16.3
Re: [PATCH 1/4] pm80xx: make mpi_build_cmd locking consistent
Hi Viswas,
Your patch descriptions need some work. See
Documentation/process/submitting-patches.rst
Specifically the section named "Describe your changes".
Quoted 1 line
the missing task completions appear to be
Which missing completions are these?
[...]
Quoted 3 lines
if a sata request issues from cpu zero when a management request issues, then there is some 'tearing' and the issue queue is sort of broken and we lose track of issues.
Too vague for a problem description.
Quoted 3 lines
disabling interrupts may be overkill because there may not be cases where we're using this from interrupt context (the interrupt path has a different per-queue lock).
No clear description of what the fix is.
Please reword your patch descriptions so it is clear to the reviewer what the problem is and how it is being addressed in the code changes that follow.
Thank you!
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
PATCH 2/4 pm80xx: make running_req atomic.
In reply to Viswas GFrom: Viswas G <[email protected]>
Incorrect value of the running_req was causing the driver unload to be stuck during the sas lldd_dev_gone notification handling. During sata IO completion, for some of the error status, driver is scheduling event handler and running_req is decremented from that. But there are some other error status (like IO_DS_IN_RECOVERY, IO_XFER_ERR_LAST_PIO_DATAIN_CRC_ERR) where the IO have been completed by fw/driver, but running_req is not decremented.
Also During NCQ error handling, driver itself will initiate READ_LOG_EXT and ABORT_ALL. When libsas/libata initiate READ_LOG_EXT (0x2F), driver increments the running_req. But this will be completed by the driver in pm80xx_chip_sata_req(), but running_req was not decremented.
--- drivers/scsi/pm8001/pm8001_hwi.c | 58 +++++++++++++++++----- drivers/scsi/pm8001/pm8001_init.c | 2 +- drivers/scsi/pm8001/pm8001_sas.c | 11 +++-- drivers/scsi/pm8001/pm8001_sas.h | 2 +- drivers/scsi/pm8001/pm80xx_hwi.c | 101 ++++++++++++++++++++++++++++++++++---- 5 files changed, 147 insertions(+), 27 deletions(-)
drivers/scsi/pm8001/pm8001_hwi.c +47 -11
@@ -1587,7 +1587,7 @@ void pm8001_work_fn(struct work_struct *work) ts->stat =SAS_QUEUE_FULL ; pm8001_dev = ccb->device;if (pm8001_dev) - pm8001_dev->running_req--; +atomic_dec (&pm8001_dev->running_req);spin_lock_irqsave (&t->task_state_lock, flags1); t->task_state_flags &= ~SAS_TASK_STATE_PENDING ; t->task_state_flags &= ~SAS_TASK_AT_INITIATOR ;
@@ -1942,7 +1942,7 @@ mpi_ssp_completion(struct pm8001_hba_info *pm8001_ha , void *piomb)sas_ssp_task_response (pm8001_ha->dev, t, iu); }if (pm8001_dev) - pm8001_dev->running_req--; +atomic_dec (&pm8001_dev->running_req);break ;case IO_ABORTED : PM8001_IO_DBG(pm8001_ha,
@@ -1958,7 +1958,7 @@ mpi_ssp_completion(struct pm8001_hba_info *pm8001_ha , void *piomb) ts->stat =SAS_DATA_UNDERRUN ; ts->residual = param;if (pm8001_dev) - pm8001_dev->running_req--; +atomic_dec (&pm8001_dev->running_req);break ;case IO_NO_DEVICE : PM8001_IO_DBG(pm8001_ha,
@@ -2172,7 +2172,7 @@ static void mpi_ssp_event(struct pm8001_hba_info *pm8001_ha , void *piomb) ts->stat =SAS_DATA_OVERRUN ; ts->residual =0 ;if (pm8001_dev) - pm8001_dev->running_req--; +atomic_dec (&pm8001_dev->running_req);break ;case IO_XFER_ERROR_BREAK : PM8001_IO_DBG(pm8001_ha,
@@ -2487,7 +2487,7 @@ mpi_sata_completion(struct pm8001_hba_info *pm8001_ha, void *piomb) pm8001_printk("response to large\n")); }if (pm8001_dev) - pm8001_dev->running_req--; +atomic_dec (&pm8001_dev->running_req);break ;case IO_ABORTED : PM8001_IO_DBG(pm8001_ha,
@@ -2495,7 +2495,7 @@ mpi_sata_completion(struct pm8001_hba_info *pm8001_ha, void *piomb) ts->resp =SAS_TASK_COMPLETE ; ts->stat =SAS_ABORTED_TASK ;if (pm8001_dev) - pm8001_dev->running_req--; +atomic_dec (&pm8001_dev->running_req);break ;/* following cases are to do cases */ case IO_UNDERFLOW :
@@ -2506,19 +2506,23 @@ mpi_sata_completion(struct pm8001_hba_info *pm8001_ha, void *piomb) ts->stat =SAS_DATA_UNDERRUN ; ts->residual = param;if (pm8001_dev) - pm8001_dev->running_req--; +atomic_dec (&pm8001_dev->running_req);break ;case IO_NO_DEVICE :PM8001_IO_DBG (pm8001_ha,pm8001_printk ("IO_NO_DEVICE\n" )); ts->resp =SAS_TASK_UNDELIVERED ; ts->stat =SAS_PHY_DOWN ; +if (pm8001_dev) +atomic_dec (&pm8001_dev->running_req);break ;case IO_XFER_ERROR_BREAK :PM8001_IO_DBG (pm8001_ha,pm8001_printk ("IO_XFER_ERROR_BREAK\n" )); ts->resp =SAS_TASK_COMPLETE ; ts->stat =SAS_INTERRUPTED ; +if (pm8001_dev) +atomic_dec (&pm8001_dev->running_req);break ;case IO_XFER_ERROR_PHY_NOT_READY : PM8001_IO_DBG(pm8001_ha,
@@ -2526,6 +2530,8 @@ mpi_sata_completion(struct pm8001_hba_info *pm8001_ha, void *piomb) ts->resp =SAS_TASK_COMPLETE ; ts->stat =SAS_OPEN_REJECT ; ts->open_rej_reason =SAS_OREJ_RSVD_RETRY ; +if (pm8001_dev) +atomic_dec (&pm8001_dev->running_req);break ;case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED : PM8001_IO_DBG(pm8001_ha,
@@ -2534,6 +2540,8 @@ mpi_sata_completion(struct pm8001_hba_info *pm8001_ha, void *piomb) ts->resp =SAS_TASK_COMPLETE ; ts->stat =SAS_OPEN_REJECT ; ts->open_rej_reason =SAS_OREJ_EPROTO ; +if (pm8001_dev) +atomic_dec (&pm8001_dev->running_req);break ;case IO_OPEN_CNX_ERROR_ZONE_VIOLATION : PM8001_IO_DBG(pm8001_ha,
@@ -2541,6 +2549,8 @@ mpi_sata_completion(struct pm8001_hba_info *pm8001_ha, void *piomb) ts->resp =SAS_TASK_COMPLETE ; ts->stat =SAS_OPEN_REJECT ; ts->open_rej_reason =SAS_OREJ_UNKNOWN ; +if (pm8001_dev) +atomic_dec (&pm8001_dev->running_req);break ;case IO_OPEN_CNX_ERROR_BREAK : PM8001_IO_DBG(pm8001_ha,
@@ -2548,6 +2558,8 @@ mpi_sata_completion(struct pm8001_hba_info *pm8001_ha, void *piomb) ts->resp =SAS_TASK_COMPLETE ; ts->stat =SAS_OPEN_REJECT ; ts->open_rej_reason =SAS_OREJ_RSVD_CONT0 ; +if (pm8001_dev) +atomic_dec (&pm8001_dev->running_req);break ;case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS : PM8001_IO_DBG(pm8001_ha,
@@ -2587,6 +2599,8 @@ mpi_sata_completion(struct pm8001_hba_info *pm8001_ha, void *piomb) ts->resp =SAS_TASK_COMPLETE ; ts->stat =SAS_OPEN_REJECT ; ts->open_rej_reason =SAS_OREJ_CONN_RATE ; +if (pm8001_dev) +atomic_dec (&pm8001_dev->running_req);break ;case IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY : PM8001_IO_DBG(pm8001_ha,
@@ -2610,48 +2624,64 @@ mpi_sata_completion(struct pm8001_hba_info *pm8001_ha, void *piomb) ts->resp =SAS_TASK_COMPLETE ; ts->stat =SAS_OPEN_REJECT ; ts->open_rej_reason =SAS_OREJ_WRONG_DEST ; +if (pm8001_dev) +atomic_dec (&pm8001_dev->running_req);break ;case IO_XFER_ERROR_NAK_RECEIVED :PM8001_IO_DBG (pm8001_ha,pm8001_printk ("IO_XFER_ERROR_NAK_RECEIVED\n" )); ts->resp =SAS_TASK_COMPLETE ; ts->stat =SAS_NAK_R_ERR ; +if (pm8001_dev) +atomic_dec (&pm8001_dev->running_req);break ;case IO_XFER_ERROR_ACK_NAK_TIMEOUT :PM8001_IO_DBG (pm8001_ha,pm8001_printk ("IO_XFER_ERROR_ACK_NAK_TIMEOUT\n" )); ts->resp =SAS_TASK_COMPLETE ; ts->stat =SAS_NAK_R_ERR ; +if (pm8001_dev) +atomic_dec (&pm8001_dev->running_req);break ;case IO_XFER_ERROR_DMA :PM8001_IO_DBG (pm8001_ha,pm8001_printk ("IO_XFER_ERROR_DMA\n" )); ts->resp =SAS_TASK_COMPLETE ; ts->stat =SAS_ABORTED_TASK ; +if (pm8001_dev) +atomic_dec (&pm8001_dev->running_req);break ;case IO_XFER_ERROR_SATA_LINK_TIMEOUT :PM8001_IO_DBG (pm8001_ha,pm8001_printk ("IO_XFER_ERROR_SATA_LINK_TIMEOUT\n" )); ts->resp =SAS_TASK_UNDELIVERED ; ts->stat =SAS_DEV_NO_RESPONSE ; +if (pm8001_dev) +atomic_dec (&pm8001_dev->running_req);break ;case IO_XFER_ERROR_REJECTED_NCQ_MODE :PM8001_IO_DBG (pm8001_ha,pm8001_printk ("IO_XFER_ERROR_REJECTED_NCQ_MODE\n" )); ts->resp =SAS_TASK_COMPLETE ; ts->stat =SAS_DATA_UNDERRUN ; +if (pm8001_dev) +atomic_dec (&pm8001_dev->running_req);break ;case IO_XFER_OPEN_RETRY_TIMEOUT :PM8001_IO_DBG (pm8001_ha,pm8001_printk ("IO_XFER_OPEN_RETRY_TIMEOUT\n" )); ts->resp =SAS_TASK_COMPLETE ; ts->stat =SAS_OPEN_TO ; +if (pm8001_dev) +atomic_dec (&pm8001_dev->running_req);break ;case IO_PORT_IN_RESET :PM8001_IO_DBG (pm8001_ha,pm8001_printk ("IO_PORT_IN_RESET\n" )); ts->resp =SAS_TASK_COMPLETE ; ts->stat =SAS_DEV_NO_RESPONSE ; +if (pm8001_dev) +atomic_dec (&pm8001_dev->running_req);break ;case IO_DS_NON_OPERATIONAL : PM8001_IO_DBG(pm8001_ha,
@@ -2672,6 +2702,8 @@ mpi_sata_completion(struct pm8001_hba_info *pm8001_ha, void *piomb) pm8001_printk(" IO_DS_IN_RECOVERY\n")); ts->resp =SAS_TASK_COMPLETE ; ts->stat =SAS_DEV_NO_RESPONSE ; +if (pm8001_dev) +atomic_dec (&pm8001_dev->running_req);break ;case IO_DS_IN_ERROR : PM8001_IO_DBG(pm8001_ha,
@@ -2693,6 +2725,8 @@ mpi_sata_completion(struct pm8001_hba_info *pm8001_ha, void *piomb) ts->resp =SAS_TASK_COMPLETE ; ts->stat =SAS_OPEN_REJECT ; ts->open_rej_reason =SAS_OREJ_RSVD_RETRY ; +if (pm8001_dev) +atomic_dec (&pm8001_dev->running_req);break ;default : PM8001_DEVIO_DBG(pm8001_ha,
@@ -2700,6 +2734,8 @@ mpi_sata_completion(struct pm8001_hba_info *pm8001_ha, void *piomb)/* not allowed case. Therefore, return failed status */ ts->resp =SAS_TASK_COMPLETE ; ts->stat =SAS_DEV_NO_RESPONSE ; +if (pm8001_dev) +atomic_dec (&pm8001_dev->running_req);break ; }spin_lock_irqsave (&t->task_state_lock, flags);
@@ -2776,7 +2812,7 @@ static void mpi_sata_event(struct pm8001_hba_info *pm8001_ha , void *piomb) ts->stat =SAS_DATA_OVERRUN ; ts->residual =0 ;if (pm8001_dev) - pm8001_dev->running_req--; +atomic_dec (&pm8001_dev->running_req);break ;case IO_XFER_ERROR_BREAK : PM8001_IO_DBG(pm8001_ha,
@@ -2976,7 +3012,7 @@ mpi_smp_completion(struct pm8001_hba_info *pm8001_ha, void *piomb) ts->resp =SAS_TASK_COMPLETE ; ts->stat =SAM_STAT_GOOD ;if (pm8001_dev) - pm8001_dev->running_req--; +atomic_dec (&pm8001_dev->running_req);break ;case IO_ABORTED : PM8001_IO_DBG(pm8001_ha,
@@ -2984,7 +3020,7 @@ mpi_smp_completion(struct pm8001_hba_info *pm8001_ha, void *piomb) ts->resp =SAS_TASK_COMPLETE ; ts->stat =SAS_ABORTED_TASK ;if (pm8001_dev) - pm8001_dev->running_req--; +atomic_dec (&pm8001_dev->running_req);break ;case IO_OVERFLOW :PM8001_IO_DBG (pm8001_ha,pm8001_printk ("IO_UNDERFLOW\n" ));
@@ -2992,7 +3028,7 @@ mpi_smp_completion(struct pm8001_hba_info *pm8001_ha, void *piomb) ts->stat =SAS_DATA_OVERRUN ; ts->residual =0 ;if (pm8001_dev) - pm8001_dev->running_req--; +atomic_dec (&pm8001_dev->running_req);break ;case IO_NO_DEVICE :PM8001_IO_DBG (pm8001_ha,pm8001_printk ("IO_NO_DEVICE\n" ));
drivers/scsi/pm8001/pm8001_init.c +1 -1
@@ -412,7 +412,7 @@ static int pm8001_alloc(struct pm8001_hba_info *pm8001_ha, pm8001_ha->devices[i].dev_type =SAS_PHY_UNUSED ; pm8001_ha->devices[i].id = i; pm8001_ha->devices[i].device_id =PM8001_MAX_DEVICES ; - pm8001_ha->devices[i].running_req =0 ; +atomic_set (&pm8001_ha->devices[i].running_req,0 ); } pm8001_ha->flags =PM8001F_INIT_TIME ;/* Initialize tags */
drivers/scsi/pm8001/pm8001_sas.c +7 -4
@@ -456,9 +456,11 @@ static int pm8001_task_exec(struct sas_task *task, ccb->device = pm8001_dev;switch (task_proto) {case SAS_PROTOCOL_SMP : +atomic_inc (&pm8001_dev->running_req); rc =pm8001_task_prep_smp (pm8001_ha, ccb);break ;case SAS_PROTOCOL_SSP : +atomic_inc (&pm8001_dev->running_req);if (is_tmf) rc =pm8001_task_prep_ssp_tm (pm8001_ha, ccb, tmf);
@@ -467,6 +469,7 @@ static int pm8001_task_exec(struct sas_task *task,break ;case SAS_PROTOCOL_SATA :case SAS_PROTOCOL_STP : +atomic_inc (&pm8001_dev->running_req); rc =pm8001_task_prep_ata (pm8001_ha, ccb);break ;default :
@@ -479,13 +482,13 @@ static int pm8001_task_exec(struct sas_task *task,if (rc) {PM8001_IO_DBG (pm8001_ha,pm8001_printk ("rc is %x\n" , rc)); +atomic_dec (&pm8001_dev->running_req); goto err_out_tag; }/* TODO: select normal or high priority */ spin_lock (&t->task_state_lock); t->task_state_flags |=SAS_TASK_AT_INITIATOR ;spin_unlock (&t->task_state_lock); - pm8001_dev->running_req++; }while (0 ); rc =0 ; goto out_done;
@@ -886,11 +889,11 @@ static void pm8001_dev_gone_notify(struct domain_device *dev)PM8001_DISC_DBG (pm8001_ha,pm8001_printk ("found dev[%d:%x] is gone.\n" , pm8001_dev->device_id, pm8001_dev->dev_type)); -if (pm8001_dev->running_req) { +if (atomic_read (&pm8001_dev->running_req)) {spin_unlock_irqrestore (&pm8001_ha->lock, flags);pm8001_exec_internal_task_abort (pm8001_ha, pm8001_dev , dev,1 ,0 ); -while (pm8001_dev->running_req) +while (atomic_read (&pm8001_dev->running_req))msleep (20 );spin_lock_irqsave (&pm8001_ha->lock, flags); }
@@ -968,7 +971,7 @@ void pm8001_open_reject_retry( ts->stat =SAS_OPEN_REJECT ; ts->open_rej_reason =SAS_OREJ_RSVD_RETRY ;if (pm8001_dev) - pm8001_dev->running_req--; +atomic_dec (&pm8001_dev->running_req);spin_lock_irqsave (&task->task_state_lock, flags1); task->task_state_flags &= ~SAS_TASK_STATE_PENDING ; task->task_state_flags &= ~SAS_TASK_AT_INITIATOR ;
drivers/scsi/pm8001/pm8001_sas.h +1 -1
@@ -293,7 +293,7 @@ struct pm8001_device {struct completion *dcompletion;struct completion *setds_completion;u32 device_id; -u32 running_req; +atomic_t running_req; };struct pm8001_prd_imt {
drivers/scsi/pm8001/pm80xx_hwi.c +91 -10
407 lines not on this page · raw message
Signature · 1 line
2.16.3
PATCH 3/4 pm80xx: Avoid busywait in FW ready check
In reply to Viswas GFrom: akshatzen <[email protected]>
Today in function check_fw_ready we do busy wait using udelay. Due to which CPU is not released and we see CPU need_resched failures.
Here busy waiting is not necessary since we are in process context and we should sleep instead. So to avoid busy waiting we are replacing udelay with msleep of 20 ms intervals to check for FW to become ready.
It's verified that check_fw_ready today is not being used in interrupt context anywhere, hence it is safe to make this change.
Tested:
Installed the kernel and looked at dmesg for failures pertaining to need_resched and did not find them.
--- drivers/scsi/pm8001/pm80xx_hwi.c | 21 +++++++++++---------- drivers/scsi/pm8001/pm80xx_hwi.h | 6 ++++++ 2 files changed, 17 insertions(+), 10 deletions(-)
drivers/scsi/pm8001/pm80xx_hwi.c +11 -10
@@ -1042,6 +1042,7 @@ static int mpi_init_check(struct pm8001_hba_info *pm8001_ha)/** * check_fw_ready - The LLDD check if the FW is ready, if not, return error. +* This function sleeps hence it must not be used in atomic context. * @pm8001_ha: our hba card information */ static int check_fw_ready (struct pm8001_hba_info *pm8001_ha)
@@ -1052,16 +1053,16 @@ static int check_fw_ready(struct pm8001_hba_info *pm8001_ha)int ret =0 ;/* reset / PCIe ready */ - max_wait_time = max_wait_count =100 *1000 ;/* 100 milli sec */ + max_wait_time = max_wait_count =5 ;/* 100 milli sec */ do { -udelay (1 ); +msleep (FW_READY_INTERVAL ); value =pm8001_cr32 (pm8001_ha,0 ,MSGU_SCRATCH_PAD_1 ); }while ((value ==0xFFFFFFFF ) && (--max_wait_count));/* check ila status */ - max_wait_time = max_wait_count =1000 *1000 ;/* 1000 milli sec */ + max_wait_time = max_wait_count =50 ;/* 1000 milli sec */ do { -udelay (1 ); +msleep (FW_READY_INTERVAL ); value =pm8001_cr32 (pm8001_ha,0 ,MSGU_SCRATCH_PAD_1 ); }while (((value &SCRATCH_PAD_ILA_READY ) !=SCRATCH_PAD_ILA_READY ) && (--max_wait_count));
@@ -1074,9 +1075,9 @@ static int check_fw_ready(struct pm8001_hba_info *pm8001_ha) }/* check RAAE status */ - max_wait_time = max_wait_count =1800 *1000 ;/* 1800 milli sec */ + max_wait_time = max_wait_count =90 ;/* 1800 milli sec */ do { -udelay (1 ); +msleep (FW_READY_INTERVAL ); value =pm8001_cr32 (pm8001_ha,0 ,MSGU_SCRATCH_PAD_1 ); }while (((value &SCRATCH_PAD_RAAE_READY ) !=SCRATCH_PAD_RAAE_READY ) && (--max_wait_count));
@@ -1089,9 +1090,9 @@ static int check_fw_ready(struct pm8001_hba_info *pm8001_ha) }/* check iop0 status */ - max_wait_time = max_wait_count =600 *1000 ;/* 600 milli sec */ + max_wait_time = max_wait_count =30 ;/* 600 milli sec */ do { -udelay (1 ); +msleep (FW_READY_INTERVAL ); value =pm8001_cr32 (pm8001_ha,0 ,MSGU_SCRATCH_PAD_1 ); }while (((value &SCRATCH_PAD_IOP0_READY ) !=SCRATCH_PAD_IOP0_READY ) && (--max_wait_count));
@@ -1107,9 +1108,9 @@ static int check_fw_ready(struct pm8001_hba_info *pm8001_ha)if ((pm8001_ha->chip_id != chip_8008) && (pm8001_ha->chip_id != chip_8009)) {/* 200 milli sec */ - max_wait_time = max_wait_count =200 *1000 ; + max_wait_time = max_wait_count =10 ;do { -udelay (1 ); +msleep (FW_READY_INTERVAL ); value =pm8001_cr32 (pm8001_ha,0 ,MSGU_SCRATCH_PAD_1 ); }while (((value &SCRATCH_PAD_IOP1_READY ) !=SCRATCH_PAD_IOP1_READY ) && (--max_wait_count));
drivers/scsi/pm8001/pm80xx_hwi.h +6 -0
@@ -1639,3 +1639,9 @@ typedef struct SASProtocolTimerConfig SASProtocolTimerConfig_t;#define MEMBASE_II_SHIFT_REGISTER 0x1010#endif + +/** +* As we know sleep (1~20) ms may result in sleep longer than ~20 ms, hence we +* choose 20 ms interval. +*/ +#define FW_READY_INTERVAL 20
Signature · 1 line
2.16.3
PATCH 4/4 pm80xx: make pm8001_mpi_set_nvmd_resp free of race condition
In reply to Viswas GFrom: yuuzheng <[email protected]>
The use-after-free or null-pointer error occurs when the 251-byte response data are copied from IOMB buffer to response message buffer in function mp8001_mpi_set_nvmd_resp. pm8001_mpi_set_nvmd_resp is a function to process the response of command set_nvmd_data_resp. After sending the command set_nvmd_data, the caller begins to sleep by calling wait_for_complete() and wait for the wake-up from calling complete() in pm8001_mpi_set_nvmd_resp. In the current code, the memcpy for response message buffer occurs after calling complete(). So, it is not protected by the use of wait_for_completion() and complete().
Due to unexpected events (e.g., interrupt), if response buffer gets freed before memcpy, the use-after-free error will occur. To fix it, the complete() should be called after memcpy.
--- drivers/scsi/pm8001/pm8001_hwi.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/scsi/pm8001/pm8001_hwi.c +6 -1
@@ -3279,10 +3279,15 @@ pm8001_mpi_get_nvmd_resp(struct pm8001_hba_info *pm8001_ha, void *piomb) pm8001_ha->memoryMap.region[NVMD ].virt_ptr, fw_control_context->len);kfree (ccb->fw_control_context); +/* To avoid race condition, complete should be +* called after the message is copied to +* fw_control_context->usrAddr +*/ +complete (pm8001_ha->nvmd_completion); +PM8001_MSG_DBG (pm8001_ha,pm8001_printk ("Set nvm data complete!\n" )); ccb->task =NULL ; ccb->ccb_tag =0xFFFFFFFF ;pm8001_tag_free (pm8001_ha, tag); -complete (pm8001_ha->nvmd_completion); }int pm8001_mpi_local_phy_ctl (struct pm8001_hba_info *pm8001_ha,void *piomb)
Signature · 1 line
2.16.3