Skip to contentSkip to conversation

nvme: set NVME_REQ_CANCELLED flag when cancelling a request

PATCH In review Sagi Grimberg 3 participants 5 messages Sep 20, 2019 – Sep 27, 2019 NVMe

lore
Share & tools
lore

Sagi Grimberg

author maintainer
#0 lore raw

PATCH 1/1 nvme: set NVME_REQ_CANCELLED flag when cancelling a request

This will prevent userspace to wrongly get the completion result when we cancelled the command. Also, make sure to clear it from the request flags in nvme_setup_cmd.

---
 drivers/nvme/host/core.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/nvme/host/core.c +2 -0
index f85e7b09d1d4..fc3ed75ef80b 100644
@@ -298,6 +298,7 @@ bool nvme_cancel_request(struct request *req, void *data, bool reserved)
 	if (blk_mq_request_completed(req))
 		return true;
 
+	nvme_req(req)->flags |= NVME_REQ_CANCELLED;
 	nvme_req(req)->status = NVME_SC_HOST_PATH_ERROR;
 	blk_mq_complete_request(req);
 	return true;
@@ -434,6 +435,7 @@ static inline void nvme_clear_nvme_request(struct request *req)
 		nvme_req(req)->flags = 0;
 		req->rq_flags |= RQF_DONTPREP;
 	}
+	nvme_req(req)->flags &= ~NVME_REQ_CANCELLED;
 }
 
 struct request *nvme_alloc_request(struct request_queue *q,
Signature · 7 lines
2.17.1


_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
#1 lore raw

There are couple of places where we explicitly set the NVME_REQ_CANCALLED which is followed by the call to nvme_dev_disable(). Since :-

nvme_dev_disable()
blk_mq_tagset_busy_iter()
nvme_cancel_requets()

with your patch nvme_cancel_request() will duplicate NVME_REQ_CANCELLED assignment, we need to avoid duplicate assignment. Following patch is on the top of yours, please have a look :-

drivers/nvme/host/pci.c +0 -0
index 6447702..4c71bbd 100644
@@ -1286,7 +1286,6 @@ static enum blk_eh_timer_return 

nvme_timeout(struct request *req, bool reserved

                          "I/O %d QID %d timeout, disable controller\n",
                          req->tag, nvmeq->qid);
                 nvme_dev_disable(dev, true);
-               nvme_req(req)->flags |= NVME_REQ_CANCELLED;
                 return BLK_EH_DONE;
         case NVME_CTRL_RESETTING:
                 return BLK_EH_RESET_TIMER;
@@ -1306,7 +1305,6 @@ static enum blk_eh_timer_return 
nvme_timeout(struct request *req, bool reserved
                 nvme_dev_disable(dev, false);
                 nvme_reset_ctrl(&dev->ctrl);
-               nvme_req(req)->flags |= NVME_REQ_CANCELLED;
                 return BLK_EH_DONE;
         }

If you are okay I can send a separate patch on the top yours.

Quoted 30 lines · Sagi Grimberg

This will prevent userspace to wrongly get the completion result when we cancelled the command. Also, make sure to clear it from the request flags in nvme_setup_cmd.

---
  drivers/nvme/host/core.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/nvme/host/core.c +2 -1
index f85e7b09d1d4..fc3ed75ef80b 100644
@@ -298,6 +298,7 @@ bool nvme_cancel_request(struct request *req, void *data, bool reserved)
  	if (blk_mq_request_completed(req))
  		return true;
 
+	nvme_req(req)->flags |= NVME_REQ_CANCELLED;
  	nvme_req(req)->status = NVME_SC_HOST_PATH_ERROR;
  	blk_mq_complete_request(req);
  	return true;
@@ -434,6 +435,7 @@ static inline void nvme_clear_nvme_request(struct request *req)
  		nvme_req(req)->flags = 0;
  		req->rq_flags |= RQF_DONTPREP;
  	}
+	nvme_req(req)->flags &= ~NVME_REQ_CANCELLED;
  }
 
  struct request *nvme_alloc_request(struct request_queue *q,
-- 2.17.1 _______________________________________________ Linux-nvme
Quoted 3 lines

mailing list [email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

author maintainer
#2 lore raw
Quoted 29 lines

There are couple of places where we explicitly set the NVME_REQ_CANCALLED which is followed by the call to nvme_dev_disable(). Since :-

nvme_dev_disable()
blk_mq_tagset_busy_iter()
nvme_cancel_requets()

with your patch nvme_cancel_request() will duplicate NVME_REQ_CANCELLED assignment, we need to avoid duplicate assignment. Following patch is on the top of yours, please have a look :-

drivers/nvme/host/pci.c +0 -0
index 6447702..4c71bbd 100644
@@ -1286,7 +1286,6 @@ static enum blk_eh_timer_return

nvme_timeout(struct request *req, bool reserved

                           "I/O %d QID %d timeout, disable controller\n",
                           req->tag, nvmeq->qid);
                  nvme_dev_disable(dev, true);
drivers/nvme/host/pci.c +0 -1
-               nvme_req(req)->flags |= NVME_REQ_CANCELLED;
                  return BLK_EH_DONE;
          case NVME_CTRL_RESETTING:
                  return BLK_EH_RESET_TIMER;
@@ -1306,7 +1305,6 @@ static enum blk_eh_timer_return

nvme_timeout(struct request *req, bool reserved

Quoted 8 lines
                  nvme_dev_disable(dev, false);
                  nvme_reset_ctrl(&dev->ctrl);
-               nvme_req(req)->flags |= NVME_REQ_CANCELLED;
                  return BLK_EH_DONE;
          }

If you are okay I can send a separate patch on the top yours.

That is fine with me.

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

#4 lore raw

Okay. We can add missing changes at the time of apply I am fine anyway.

Quoted 9 lines · Christoph Hellwig
Quoted 3 lines · Sagi Grimberg
Quoted 1 line

If you are okay I can send a separate patch on the top yours.

That is fine with me.

I think we really should have the whole thing in one patch one way or another.

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme