nvmet-auth: don't try to cancel a non-initialized work_struct
authorChristoph Hellwig <hch@lst.de>
Tue, 20 Sep 2022 13:37:18 +0000 (15:37 +0200)
committerChristoph Hellwig <hch@lst.de>
Tue, 27 Sep 2022 07:22:09 +0000 (09:22 +0200)
Currently blktests nvme/002 trips up debugobjects if CONFIG_NVME_AUTH is
enabled, but authentication is not on a queue.  This is because
nvmet_auth_sq_free cancels sq->auth_expired_work unconditionaly, while
auth_expired_work is only ever initialized if authentication is enabled
for a given controller.

Fix this by calling most of what is nvmet_init_auth unconditionally
when initializing the SQ, and just do the setting of the result
field in the connect command handler.

Fixes: db1312dd9548 ("nvmet: implement basic In-Band Authentication")
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Hannes Reinecke <hare@suse.de>
drivers/nvme/target/core.c
drivers/nvme/target/fabrics-cmd-auth.c
drivers/nvme/target/fabrics-cmd.c
drivers/nvme/target/nvmet.h

index a1345790005f428ce84a718469178157975736cc..8e3cf0c3588ce92e79ec4d33716579fd87c99d07 100644 (file)
@@ -830,6 +830,7 @@ int nvmet_sq_init(struct nvmet_sq *sq)
        }
        init_completion(&sq->free_done);
        init_completion(&sq->confirm_done);
+       nvmet_auth_sq_init(sq);
 
        return 0;
 }
index 84601e38a335acc2a420dfea9acff520a1f7b6d5..7970a7640e5851a045d1e27706e76491e81339ad 100644 (file)
@@ -23,17 +23,12 @@ static void nvmet_auth_expired_work(struct work_struct *work)
        sq->dhchap_tid = -1;
 }
 
-void nvmet_init_auth(struct nvmet_ctrl *ctrl, struct nvmet_req *req)
+void nvmet_auth_sq_init(struct nvmet_sq *sq)
 {
-       u32 result = le32_to_cpu(req->cqe->result.u32);
-
        /* Initialize in-band authentication */
-       INIT_DELAYED_WORK(&req->sq->auth_expired_work,
-                         nvmet_auth_expired_work);
-       req->sq->authenticated = false;
-       req->sq->dhchap_step = NVME_AUTH_DHCHAP_MESSAGE_NEGOTIATE;
-       result |= (u32)NVME_CONNECT_AUTHREQ_ATR << 16;
-       req->cqe->result.u32 = cpu_to_le32(result);
+       INIT_DELAYED_WORK(&sq->auth_expired_work, nvmet_auth_expired_work);
+       sq->authenticated = false;
+       sq->dhchap_step = NVME_AUTH_DHCHAP_MESSAGE_NEGOTIATE;
 }
 
 static u16 nvmet_auth_negotiate(struct nvmet_req *req, void *d)
index c1dfdfb92ebf06f9edbdf8fe67e78449e73a2b7f..c7e903589d377271c9f9f3b2df2a24defd51a6a8 100644 (file)
@@ -272,7 +272,8 @@ static void nvmet_execute_admin_connect(struct nvmet_req *req)
        req->cqe->result.u16 = cpu_to_le16(ctrl->cntlid);
 
        if (nvmet_has_auth(ctrl))
-               nvmet_init_auth(ctrl, req);
+               req->cqe->result.u32 |=
+                       cpu_to_le32((u32)NVME_CONNECT_AUTHREQ_ATR << 16);
 out:
        kfree(d);
 complete:
@@ -333,7 +334,8 @@ static void nvmet_execute_io_connect(struct nvmet_req *req)
 
        pr_debug("adding queue %d to ctrl %d.\n", qid, ctrl->cntlid);
        if (nvmet_has_auth(ctrl))
-               nvmet_init_auth(ctrl, req);
+               req->cqe->result.u32 |=
+                       cpu_to_le32((u32)NVME_CONNECT_AUTHREQ_ATR << 16);
 
 out:
        kfree(d);
index 6ffeeb0a1c49e3feeee56cb708219a34b043981c..dfe3894205aa77f71e49617e32f824bc6dda976e 100644 (file)
@@ -704,7 +704,7 @@ int nvmet_auth_set_key(struct nvmet_host *host, const char *secret,
                       bool set_ctrl);
 int nvmet_auth_set_host_hash(struct nvmet_host *host, const char *hash);
 int nvmet_setup_auth(struct nvmet_ctrl *ctrl);
-void nvmet_init_auth(struct nvmet_ctrl *ctrl, struct nvmet_req *req);
+void nvmet_auth_sq_init(struct nvmet_sq *sq);
 void nvmet_destroy_auth(struct nvmet_ctrl *ctrl);
 void nvmet_auth_sq_free(struct nvmet_sq *sq);
 int nvmet_setup_dhgroup(struct nvmet_ctrl *ctrl, u8 dhgroup_id);
@@ -726,8 +726,9 @@ static inline int nvmet_setup_auth(struct nvmet_ctrl *ctrl)
 {
        return 0;
 }
-static inline void nvmet_init_auth(struct nvmet_ctrl *ctrl,
-                                  struct nvmet_req *req) {};
+static inline void nvmet_auth_sq_init(struct nvmet_sq *sq)
+{
+}
 static inline void nvmet_destroy_auth(struct nvmet_ctrl *ctrl) {};
 static inline void nvmet_auth_sq_free(struct nvmet_sq *sq) {};
 static inline bool nvmet_check_auth_status(struct nvmet_req *req)