nvme: switch abort_limit to an atomic_t
authorChristoph Hellwig <hch@lst.de>
Fri, 20 Nov 2015 08:36:44 +0000 (09:36 +0100)
committerJens Axboe <axboe@fb.com>
Tue, 22 Dec 2015 16:38:33 +0000 (09:38 -0700)
There is no lock to sychronize access to the abort_limit field of
struct nvme_ctrl, so switch it to an atomic_t.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Keith Busch <keith.busch@intel.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
drivers/nvme/host/core.c
drivers/nvme/host/nvme.h
drivers/nvme/host/pci.c

index 64891ebc4c524a7f2b92f021e238df8ac2b0dfc3..859b1896d3374b7b72c2924ed1fc9195bfa7b8be 100644 (file)
@@ -839,7 +839,7 @@ int nvme_init_identify(struct nvme_ctrl *ctrl)
        }
 
        ctrl->oncs = le16_to_cpup(&id->oncs);
-       ctrl->abort_limit = id->acl + 1;
+       atomic_set(&ctrl->abort_limit, id->acl + 1);
        ctrl->vwc = id->vwc;
        memcpy(ctrl->serial, id->sn, sizeof(id->sn));
        memcpy(ctrl->model, id->mn, sizeof(id->mn));
index 88950f362d9772f33a70d5b37ef55addb0c07911..982fa303cec6cfec3c884265ed6ce57c0cb8936c 100644 (file)
@@ -77,7 +77,7 @@ struct nvme_ctrl {
        u32 max_hw_sectors;
        u32 stripe_size;
        u16 oncs;
-       u16 abort_limit;
+       atomic_t abort_limit;
        u8 event_limit;
        u8 vwc;
        u32 vs;
index 26e982359a747d647b7b6130bf553b7314304c6f..1ad7f18d48e2146f582204f36e0804658e609f7e 100644 (file)
@@ -388,7 +388,7 @@ static void abort_completion(struct nvme_queue *nvmeq, void *ctx,
        blk_mq_free_request(req);
 
        dev_warn(nvmeq->q_dmadev, "Abort status:%x result:%x", status, result);
-       ++nvmeq->dev->ctrl.abort_limit;
+       atomic_inc(&nvmeq->dev->ctrl.abort_limit);
 }
 
 static void async_completion(struct nvme_queue *nvmeq, void *ctx,
@@ -1124,13 +1124,15 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req, bool reserved)
                return BLK_EH_HANDLED;
        }
 
-       if (!dev->ctrl.abort_limit)
+       if (atomic_dec_and_test(&dev->ctrl.abort_limit))
                return BLK_EH_RESET_TIMER;
 
        abort_req = blk_mq_alloc_request(dev->ctrl.admin_q, WRITE,
                        BLK_MQ_REQ_NOWAIT);
-       if (IS_ERR(abort_req))
+       if (IS_ERR(abort_req)) {
+               atomic_inc(&dev->ctrl.abort_limit);
                return BLK_EH_RESET_TIMER;
+       }
 
        abort_cmd = blk_mq_rq_to_pdu(abort_req);
        nvme_set_info(abort_cmd, abort_req, abort_completion);
@@ -1141,7 +1143,6 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req, bool reserved)
        cmd.abort.sqid = cpu_to_le16(nvmeq->qid);
        cmd.abort.command_id = abort_req->tag;
 
-       --dev->ctrl.abort_limit;
        cmd_rq->aborted = 1;
 
        dev_warn(nvmeq->q_dmadev, "I/O %d QID %d timeout, aborting\n",