mtip_check_surprise_removal() calls blk_mark_disk_dead() from the interrupt handler, which acquires bd_holder_lock and calls into the holder, which may sleep. Only record the removal in mtip_check_surprise_removal(): replace the unsynchronized bool dd->sr with MTIP_DDF_DEAD_BIT so new commands fail immediately, and wake the service thread with MTIP_PF_SR_BIT. In mtip_exec_internal_command(), reset int_cmd->status before calling blk_execute_rq() and treat a non-zero return value as a failure too, since rejecting a reserved command with BLK_STS_IOERR leaves int_cmd->status untouched. In mtip_handle_surprise_removal(), quiesce the queue, wait for the interrupt handler with synchronize_irq(), flush isr_workq, abort commands in flight through blk_mq_complete_request(), unquiesce the queue, and only then mark the disk dead. Doing this in that order matters because blk_mark_disk_dead() acquires s_umount of a mounted filesystem, whose holder may be waiting for those commands. Clear the tag bit in port->cmds_to_issue before testing blk_mq_request_completed() in mtip_abort_cmd() so no stale bit remains for an already completed request. If MTIP_DDF_REMOVE_PENDING_BIT is set, wait for in-progress mtip_queue_rq() calls with synchronize_rcu() instead of quiescing and unquiescing the queue, and skip blk_mark_disk_dead() because mtip_pci_remove() is already tearing down the disk. Fixes: f55e017c6420 ("block: add a mark_dead holder operation") Reported-by: Josef Bacik Signed-off-by: Jens Axboe Signed-off-by: Bart Van Assche --- drivers/block/mtip32xx/mtip32xx.c | 65 +++++++++++++++++++++++++------ drivers/block/mtip32xx/mtip32xx.h | 9 +++-- 2 files changed, 60 insertions(+), 14 deletions(-) diff --git a/drivers/block/mtip32xx/mtip32xx.c b/drivers/block/mtip32xx/mtip32xx.c index aa44b13d506b..24cef62136f1 100644 --- a/drivers/block/mtip32xx/mtip32xx.c +++ b/drivers/block/mtip32xx/mtip32xx.c @@ -134,15 +134,17 @@ static bool mtip_check_surprise_removal(struct driver_data *dd) { u16 vendor_id = 0; - if (dd->sr) + if (test_bit(MTIP_DDF_DEAD_BIT, &dd->dd_flag)) return true; /* Read the vendorID from the configuration space */ pci_read_config_word(dd->pdev, 0x00, &vendor_id); if (vendor_id == 0xFFFF) { - dd->sr = true; - if (dd->disk) - blk_mark_disk_dead(dd->disk); + set_bit(MTIP_DDF_DEAD_BIT, &dd->dd_flag); + if (dd->port) { + set_bit(MTIP_PF_SR_BIT, &dd->port->flags); + wake_up_interruptible(&dd->port->svc_wait); + } return true; /* device removed */ } @@ -998,14 +1000,13 @@ static int mtip_exec_internal_command(struct mtip_port *port, /* Copy the command to the command table */ int_cmd = blk_mq_rq_to_pdu(rq); int_cmd->icmd = &icmd; + int_cmd->status = BLK_STS_OK; memcpy(int_cmd->command, fis, fis_len*4); rq->timeout = timeout; /* insert request and run queue */ - blk_execute_rq(rq, true); - - if (int_cmd->status) { + if (blk_execute_rq(rq, true) || int_cmd->status) { dev_err(&dd->pdev->dev, "Internal command [%02X] failed %d\n", fis->command, int_cmd->status); rv = -EIO; @@ -2439,8 +2440,11 @@ static bool mtip_abort_cmd(struct request *req, void *data) dbg_printk(MTIP_DRV_NAME " Aborting request, tag = %d\n", req->tag); clear_bit(req->tag, dd->port->cmds_to_issue); + if (blk_mq_request_completed(req)) + return true; + cmd->status = BLK_STS_IOERR; - mtip_softirq_done_fn(req); + blk_mq_complete_request(req); return true; } @@ -2453,6 +2457,31 @@ static bool mtip_queue_cmd(struct request *req, void *data) return true; } +static void mtip_handle_surprise_removal(struct driver_data *dd) +{ + bool removing = test_bit(MTIP_DDF_REMOVE_PENDING_BIT, &dd->dd_flag); + + if (dd->queue) { + if (!removing) + blk_mq_quiesce_queue(dd->queue); + else + synchronize_rcu(); + + synchronize_irq(dd->pdev->irq); + if (dd->isr_workq) + flush_workqueue(dd->isr_workq); + + blk_mq_tagset_busy_iter(&dd->tags, mtip_abort_cmd, dd); + + if (!removing) + blk_mq_unquiesce_queue(dd->queue); + } + if (!removing && + test_bit(MTIP_DDF_INIT_DONE_BIT, &dd->dd_flag) && + !test_and_set_bit(MTIP_DDF_DISK_DEAD_BIT, &dd->dd_flag)) + blk_mark_disk_dead(dd->disk); +} + /* * service thread to issue queued commands * @@ -2492,6 +2521,15 @@ static int mtip_service_thread(void *data) set_bit(MTIP_PF_SVC_THD_ACTIVE_BIT, &port->flags); + if (test_and_clear_bit(MTIP_PF_SR_BIT, &port->flags)) { + mtip_handle_surprise_removal(dd); + clear_bit(MTIP_PF_EH_ACTIVE_BIT, &port->flags); + clear_bit(MTIP_PF_TO_ACTIVE_BIT, &port->flags); + clear_bit(MTIP_PF_ISSUE_CMDS_BIT, &port->flags); + clear_bit(MTIP_PF_REBUILD_BIT, &port->flags); + continue; + } + restart_eh: /* Demux bits: start with error handling */ if (test_bit(MTIP_PF_EH_ACTIVE_BIT, &port->flags)) { @@ -2848,7 +2886,7 @@ static int mtip_standby_drive(struct driver_data *dd) { int rv = 0; - if (dd->sr || !dd->port) + if (test_bit(MTIP_DDF_DEAD_BIT, &dd->dd_flag) || !dd->port) return -ENODEV; /* * Send standby immediate (E0h) to the drive so that it @@ -2875,7 +2913,7 @@ static int mtip_standby_drive(struct driver_data *dd) */ static int mtip_hw_exit(struct driver_data *dd) { - if (!dd->sr) { + if (!test_bit(MTIP_DDF_DEAD_BIT, &dd->dd_flag)) { /* de-initialize the port. */ mtip_deinit_port(dd->port); @@ -3241,6 +3279,8 @@ static inline bool is_stopped(struct driver_data *dd, struct request *rq) return true; if (test_bit(MTIP_DDF_REBUILD_FAILED_BIT, &dd->dd_flag)) return true; + if (test_bit(MTIP_DDF_DEAD_BIT, &dd->dd_flag)) + return true; return false; } @@ -3279,6 +3319,9 @@ static blk_status_t mtip_issue_reserved_cmd(struct blk_mq_hw_ctx *hctx, dd->port->command_list + sizeof(struct mtip_cmd_hdr) * rq->tag; struct mtip_cmd_sg *command_sg; + if (test_bit(MTIP_DDF_DEAD_BIT, &dd->dd_flag)) + return BLK_STS_IOERR; + if (mtip_commands_active(dd->port)) return BLK_STS_DEV_RESOURCE; @@ -3905,7 +3948,7 @@ static void mtip_pci_remove(struct pci_dev *pdev) kthread_stop(dd->mtip_svc_handler); } - if (!dd->sr) { + if (!test_bit(MTIP_DDF_DEAD_BIT, &dd->dd_flag)) { /* * Explicitly wait here for IOs to quiesce, * as mtip_standby_drive usually won't wait for IOs. diff --git a/drivers/block/mtip32xx/mtip32xx.h b/drivers/block/mtip32xx/mtip32xx.h index 0963c07b5845..5bc86363a4c7 100644 --- a/drivers/block/mtip32xx/mtip32xx.h +++ b/drivers/block/mtip32xx/mtip32xx.h @@ -134,11 +134,13 @@ enum { MTIP_PF_ISSUE_CMDS_BIT = 5, MTIP_PF_REBUILD_BIT = 6, MTIP_PF_SVC_THD_STOP_BIT = 8, + MTIP_PF_SR_BIT = 11, /* surprise removal seen */ MTIP_PF_SVC_THD_WORK = ((1 << MTIP_PF_EH_ACTIVE_BIT) | (1 << MTIP_PF_ISSUE_CMDS_BIT) | (1 << MTIP_PF_REBUILD_BIT) | (1 << MTIP_PF_SVC_THD_STOP_BIT) | + (1 << MTIP_PF_SR_BIT) | (1 << MTIP_PF_TO_ACTIVE_BIT)), /* below are bit numbers in 'dd_flag' defined in driver_data */ @@ -150,12 +152,15 @@ enum { MTIP_DDF_RESUME_BIT = 6, MTIP_DDF_INIT_DONE_BIT = 7, MTIP_DDF_REBUILD_FAILED_BIT = 8, + MTIP_DDF_DEAD_BIT = 9, + MTIP_DDF_DISK_DEAD_BIT = 10, MTIP_DDF_STOP_IO = ((1 << MTIP_DDF_REMOVE_PENDING_BIT) | (1 << MTIP_DDF_SEC_LOCK_BIT) | (1 << MTIP_DDF_OVER_TEMP_BIT) | (1 << MTIP_DDF_WRITE_PROTECT_BIT) | - (1 << MTIP_DDF_REBUILD_FAILED_BIT)), + (1 << MTIP_DDF_REBUILD_FAILED_BIT) | + (1 << MTIP_DDF_DEAD_BIT)), }; @@ -449,8 +454,6 @@ struct driver_data { struct dentry *dfs_node; - bool sr; - int numa_node; /* NUMA support */ char workq_name[32];