Commit 323e3342 authored by Matthew R. Ochs's avatar Matthew R. Ochs Committed by Martin K. Petersen

scsi: cxlflash: Fence EEH during probe

An EEH during probe can lead to a crash as the recovery thread races with the
probe thread. To avoid this issue, introduce new states to fence out EEH
recovery until probe has completed. Also ensure the reset wait queue is
flushed during device removal to avoid orphaned threads.
Signed-off-by: default avatarMatthew R. Ochs <mrochs@linux.vnet.ibm.com>
Signed-off-by: default avatarUma Krishnan <ukrishn@linux.vnet.ibm.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 1cd7fabc
...@@ -90,6 +90,8 @@ enum cxlflash_init_state { ...@@ -90,6 +90,8 @@ enum cxlflash_init_state {
}; };
enum cxlflash_state { enum cxlflash_state {
STATE_PROBING, /* Initial state during probe */
STATE_PROBED, /* Temporary state, probe completed but EEH occurred */
STATE_NORMAL, /* Normal running state, everything good */ STATE_NORMAL, /* Normal running state, everything good */
STATE_RESET, /* Reset state, trying to reset/recover */ STATE_RESET, /* Reset state, trying to reset/recover */
STATE_FAILTERM /* Failed/terminating state, error out users/threads */ STATE_FAILTERM /* Failed/terminating state, error out users/threads */
......
...@@ -470,6 +470,8 @@ static int cxlflash_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scp) ...@@ -470,6 +470,8 @@ static int cxlflash_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scp)
spin_unlock_irqrestore(&cfg->tmf_slock, lock_flags); spin_unlock_irqrestore(&cfg->tmf_slock, lock_flags);
switch (cfg->state) { switch (cfg->state) {
case STATE_PROBING:
case STATE_PROBED:
case STATE_RESET: case STATE_RESET:
dev_dbg_ratelimited(dev, "%s: device is in reset\n", __func__); dev_dbg_ratelimited(dev, "%s: device is in reset\n", __func__);
rc = SCSI_MLQUEUE_HOST_BUSY; rc = SCSI_MLQUEUE_HOST_BUSY;
...@@ -719,7 +721,8 @@ static void notify_shutdown(struct cxlflash_cfg *cfg, bool wait) ...@@ -719,7 +721,8 @@ static void notify_shutdown(struct cxlflash_cfg *cfg, bool wait)
* cxlflash_remove() - PCI entry point to tear down host * cxlflash_remove() - PCI entry point to tear down host
* @pdev: PCI device associated with the host. * @pdev: PCI device associated with the host.
* *
* Safe to use as a cleanup in partially allocated/initialized state. * Safe to use as a cleanup in partially allocated/initialized state. Note that
* the reset_waitq is flushed as part of the stop/termination of user contexts.
*/ */
static void cxlflash_remove(struct pci_dev *pdev) static void cxlflash_remove(struct pci_dev *pdev)
{ {
...@@ -752,7 +755,6 @@ static void cxlflash_remove(struct pci_dev *pdev) ...@@ -752,7 +755,6 @@ static void cxlflash_remove(struct pci_dev *pdev)
case INIT_STATE_SCSI: case INIT_STATE_SCSI:
cxlflash_term_local_luns(cfg); cxlflash_term_local_luns(cfg);
scsi_remove_host(cfg->host); scsi_remove_host(cfg->host);
/* fall through */
case INIT_STATE_AFU: case INIT_STATE_AFU:
term_afu(cfg); term_afu(cfg);
case INIT_STATE_PCI: case INIT_STATE_PCI:
...@@ -2624,6 +2626,15 @@ static void cxlflash_worker_thread(struct work_struct *work) ...@@ -2624,6 +2626,15 @@ static void cxlflash_worker_thread(struct work_struct *work)
* @pdev: PCI device associated with the host. * @pdev: PCI device associated with the host.
* @dev_id: PCI device id associated with device. * @dev_id: PCI device id associated with device.
* *
* The device will initially start out in a 'probing' state and
* transition to the 'normal' state at the end of a successful
* probe. Should an EEH event occur during probe, the notification
* thread (error_detected()) will wait until the probe handler
* is nearly complete. At that time, the device will be moved to
* a 'probed' state and the EEH thread woken up to drive the slot
* reset and recovery (device moves to 'normal' state). Meanwhile,
* the probe will be allowed to exit successfully.
*
* Return: 0 on success, -errno on failure * Return: 0 on success, -errno on failure
*/ */
static int cxlflash_probe(struct pci_dev *pdev, static int cxlflash_probe(struct pci_dev *pdev,
...@@ -2707,7 +2718,7 @@ static int cxlflash_probe(struct pci_dev *pdev, ...@@ -2707,7 +2718,7 @@ static int cxlflash_probe(struct pci_dev *pdev,
cfg->init_state = INIT_STATE_PCI; cfg->init_state = INIT_STATE_PCI;
rc = init_afu(cfg); rc = init_afu(cfg);
if (rc) { if (rc && !wq_has_sleeper(&cfg->reset_waitq)) {
dev_err(dev, "%s: init_afu failed rc=%d\n", __func__, rc); dev_err(dev, "%s: init_afu failed rc=%d\n", __func__, rc);
goto out_remove; goto out_remove;
} }
...@@ -2720,6 +2731,11 @@ static int cxlflash_probe(struct pci_dev *pdev, ...@@ -2720,6 +2731,11 @@ static int cxlflash_probe(struct pci_dev *pdev,
} }
cfg->init_state = INIT_STATE_SCSI; cfg->init_state = INIT_STATE_SCSI;
if (wq_has_sleeper(&cfg->reset_waitq)) {
cfg->state = STATE_PROBED;
wake_up_all(&cfg->reset_waitq);
} else
cfg->state = STATE_NORMAL;
out: out:
dev_dbg(dev, "%s: returning rc=%d\n", __func__, rc); dev_dbg(dev, "%s: returning rc=%d\n", __func__, rc);
return rc; return rc;
...@@ -2750,7 +2766,8 @@ static pci_ers_result_t cxlflash_pci_error_detected(struct pci_dev *pdev, ...@@ -2750,7 +2766,8 @@ static pci_ers_result_t cxlflash_pci_error_detected(struct pci_dev *pdev,
switch (state) { switch (state) {
case pci_channel_io_frozen: case pci_channel_io_frozen:
wait_event(cfg->reset_waitq, cfg->state != STATE_RESET); wait_event(cfg->reset_waitq, cfg->state != STATE_RESET &&
cfg->state != STATE_PROBING);
if (cfg->state == STATE_FAILTERM) if (cfg->state == STATE_FAILTERM)
return PCI_ERS_RESULT_DISCONNECT; return PCI_ERS_RESULT_DISCONNECT;
......
...@@ -78,17 +78,18 @@ void cxlflash_free_errpage(void) ...@@ -78,17 +78,18 @@ void cxlflash_free_errpage(void)
* memory freed. This is accomplished by putting the contexts in error * memory freed. This is accomplished by putting the contexts in error
* state which will notify the user and let them 'drive' the tear down. * state which will notify the user and let them 'drive' the tear down.
* Meanwhile, this routine camps until all user contexts have been removed. * Meanwhile, this routine camps until all user contexts have been removed.
*
* Note that the main loop in this routine will always execute at least once
* to flush the reset_waitq.
*/ */
void cxlflash_stop_term_user_contexts(struct cxlflash_cfg *cfg) void cxlflash_stop_term_user_contexts(struct cxlflash_cfg *cfg)
{ {
struct device *dev = &cfg->dev->dev; struct device *dev = &cfg->dev->dev;
int i, found; int i, found = true;
cxlflash_mark_contexts_error(cfg); cxlflash_mark_contexts_error(cfg);
while (true) { while (true) {
found = false;
for (i = 0; i < MAX_CONTEXT; i++) for (i = 0; i < MAX_CONTEXT; i++)
if (cfg->ctx_tbl[i]) { if (cfg->ctx_tbl[i]) {
found = true; found = true;
...@@ -102,6 +103,7 @@ void cxlflash_stop_term_user_contexts(struct cxlflash_cfg *cfg) ...@@ -102,6 +103,7 @@ void cxlflash_stop_term_user_contexts(struct cxlflash_cfg *cfg)
__func__); __func__);
wake_up_all(&cfg->reset_waitq); wake_up_all(&cfg->reset_waitq);
ssleep(1); ssleep(1);
found = false;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment