From: Keith Busch Date: Wed, 14 Dec 2016 22:38:35 +0000 (-0800) Subject: nvme: Limit command retries X-Git-Tag: v4.1.12-92~10^2~2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=582575bf4329fa5e29c0f1eae79cb0fb13fded04;p=users%2Fjedix%2Flinux-maple.git nvme: Limit command retries Many controller implementations will return errors to commands that will not succeed, but without the DNR bit set. The driver previously retried these commands an unlimited number of times until the command timeout has exceeded, which takes an unnecessarilly long period of time. This patch limits the number of retries a command can have, defaulting to 5, but is user tunable at load or runtime. The struct request's 'retries' field is used to track the number of retries attempted. This is in contrast with scsi's use of this field, which indicates how many retries are allowed. Signed-off-by: Keith Busch Reviewed-by: Christoph Hellwig Signed-off-by: Jens Axboe Orabug: 25256529 Conflicts: Patched the commits manually due to the lack of core.c file drivers/nvme/host/pci.c drivers/nvme/host/nvme.h Signed-off-by: Ashok Vairavan Reviewed-by: Martin K. Petersen Signed-off-by: Dhaval Giani --- diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index 8d503dc6269e4..499d04cd5150c 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -19,6 +19,7 @@ #include #include +extern unsigned int nvme_max_retries; extern unsigned char nvme_io_timeout; #define NVME_IO_TIMEOUT (nvme_io_timeout * HZ) diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index 3881e96d87b2a..27558d4ad8582 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -65,6 +65,11 @@ static unsigned char shutdown_timeout = 5; module_param(shutdown_timeout, byte, 0644); MODULE_PARM_DESC(shutdown_timeout, "timeout in seconds for controller shutdown"); +unsigned int nvme_max_retries = 5; +module_param_named(max_retries, nvme_max_retries, uint, 0644); +MODULE_PARM_DESC(max_retries, "max number of retries a command may have"); +EXPORT_SYMBOL_GPL(nvme_max_retries); + static int nvme_major; module_param(nvme_major, int, 0); @@ -624,9 +629,12 @@ static void req_completion(struct nvme_queue *nvmeq, void *ctx, if (unlikely(status)) { if (!(status & NVME_SC_DNR || blk_noretry_request(req)) - && (jiffies - req->start_time) < req->timeout) { + && (jiffies - req->start_time) < req->timeout && + req->retries < nvme_max_retries) { unsigned long flags; + req->retries++; + requeue = true; blk_mq_requeue_request(req); spin_lock_irqsave(req->q->queue_lock, flags); if (!blk_queue_stopped(req->q)) @@ -851,6 +859,11 @@ static void nvme_setup_rw(struct nvme_ns *ns, struct request *req, if (req->cmd_flags & REQ_RAHEAD) dsmgmt |= NVME_RW_DSM_FREQ_PREFETCH; + if (!(req->cmd_flags & REQ_DONTPREP)) { + req->retries = 0; + req->cmd_flags |= REQ_DONTPREP; + } + memset(cmnd, 0, sizeof(*cmnd)); cmnd->rw.opcode = (rq_data_dir(req) ? nvme_cmd_write : nvme_cmd_read); cmnd->rw.command_id = req->tag;