From: Christoph Hellwig <hch@lst.de>
To: Ruozhu Li <david.li@jaguarmicro.com>
Cc: linux-nvme@lists.infradead.org, hch@lst.de, sagi@grimberg.me
Subject: Re: [PATCH] nvmet-rdma: recheck queue state is LIVE in state lock in recv done
Date: Thu, 13 Feb 2025 07:20:48 +0100 [thread overview]
Message-ID: <20250213062048.GD19608@lst.de> (raw)
In-Reply-To: <20250211034543.808-1-david.li@jaguarmicro.com>
> +++ b/drivers/nvme/target/rdma.c
> @@ -1042,12 +1042,16 @@ static void nvmet_rdma_recv_done(struct ib_cq *cq, struct ib_wc *wc)
> unsigned long flags;
>
> spin_lock_irqsave(&queue->state_lock, flags);
> - if (queue->state == NVMET_RDMA_Q_CONNECTING)
> - list_add_tail(&rsp->wait_list, &queue->rsp_wait_list);
> - else
> - nvmet_rdma_put_rsp(rsp);
> + if (queue->state != NVMET_RDMA_Q_LIVE) {
You'll want a comment based on the commit message that the first live
check is racy.
> + if (queue->state == NVMET_RDMA_Q_CONNECTING)
> + list_add_tail(&rsp->wait_list, &queue->rsp_wait_list);
> + else
> + nvmet_rdma_put_rsp(rsp);
> +
> + spin_unlock_irqrestore(&queue->state_lock, flags);
> + return;
This gets a bit messy now. What about a struture like this instead?
diff --git a/drivers/nvme/target/rdma.c b/drivers/nvme/target/rdma.c
index 1afd93026f9b..ae6a123ac63f 100644
--- a/drivers/nvme/target/rdma.c
+++ b/drivers/nvme/target/rdma.c
@@ -996,6 +996,23 @@ static void nvmet_rdma_handle_command(struct nvmet_rdma_queue *queue,
nvmet_req_complete(&cmd->req, status);
}
+static bool nvmet_rdma_recv_not_live(struct nvmet_rdma_queue *queue,
+ struct nvmet_rdma_rsp *rsp)
+{
+ unsigned long flags;
+ bool ret = true;
+
+ spin_lock_irqsave(&queue->state_lock, flags);
+ if (queue->state == NVMET_RDMA_Q_LIVE)
+ ret = false;
+ else if (queue->state == NVMET_RDMA_Q_CONNECTING)
+ list_add_tail(&rsp->wait_list, &queue->rsp_wait_list);
+ else
+ nvmet_rdma_put_rsp(rsp);
+ spin_unlock_irqrestore(&queue->state_lock, flags);
+ return ret;
+}
+
static void nvmet_rdma_recv_done(struct ib_cq *cq, struct ib_wc *wc)
{
struct nvmet_rdma_cmd *cmd =
@@ -1038,18 +1055,9 @@ static void nvmet_rdma_recv_done(struct ib_cq *cq, struct ib_wc *wc)
rsp->n_rdma = 0;
rsp->invalidate_rkey = 0;
- if (unlikely(queue->state != NVMET_RDMA_Q_LIVE)) {
- unsigned long flags;
-
- spin_lock_irqsave(&queue->state_lock, flags);
- if (queue->state == NVMET_RDMA_Q_CONNECTING)
- list_add_tail(&rsp->wait_list, &queue->rsp_wait_list);
- else
- nvmet_rdma_put_rsp(rsp);
- spin_unlock_irqrestore(&queue->state_lock, flags);
+ if (unlikely(queue->state != NVMET_RDMA_Q_LIVE) &&
+ nvmet_rdma_recv_not_live(queue, rsp))
return;
- }
-
nvmet_rdma_handle_command(queue, rsp);
}
next prev parent reply other threads:[~2025-02-13 6:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-11 3:45 [PATCH] nvmet-rdma: recheck queue state is LIVE in state lock in recv done Ruozhu Li
2025-02-13 6:20 ` Christoph Hellwig [this message]
2025-02-13 10:06 ` Ruozhu Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250213062048.GD19608@lst.de \
--to=hch@lst.de \
--cc=david.li@jaguarmicro.com \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.