Skip to content

Commit 07a29b1

Browse files
hreineckekeithbusch
authored andcommitted
nvmet-tcp: avoid circular locking dependency on install_queue()
nvmet_tcp_install_queue() is driven from the ->io_work workqueue function, but will call flush_workqueue() which might trigger ->release_work() which in itself calls flush_work on ->io_work. To avoid that check for pending queue in disconnecting status, and return 'controller busy' when we reached a certain threshold. Signed-off-by: Hannes Reinecke <[email protected]> Tested-by: Shin'ichiro Kawasaki <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Signed-off-by: Keith Busch <[email protected]>
1 parent 06c59d4 commit 07a29b1

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

drivers/nvme/target/tcp.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#define NVMET_TCP_DEF_INLINE_DATA_SIZE (4 * PAGE_SIZE)
2727
#define NVMET_TCP_MAXH2CDATA 0x400000 /* 16M arbitrary limit */
28+
#define NVMET_TCP_BACKLOG 128
2829

2930
static int param_store_val(const char *str, int *val, int min, int max)
3031
{
@@ -2067,7 +2068,7 @@ static int nvmet_tcp_add_port(struct nvmet_port *nport)
20672068
goto err_sock;
20682069
}
20692070

2070-
ret = kernel_listen(port->sock, 128);
2071+
ret = kernel_listen(port->sock, NVMET_TCP_BACKLOG);
20712072
if (ret) {
20722073
pr_err("failed to listen %d on port sock\n", ret);
20732074
goto err_sock;
@@ -2133,8 +2134,19 @@ static u16 nvmet_tcp_install_queue(struct nvmet_sq *sq)
21332134
container_of(sq, struct nvmet_tcp_queue, nvme_sq);
21342135

21352136
if (sq->qid == 0) {
2136-
/* Let inflight controller teardown complete */
2137-
flush_workqueue(nvmet_wq);
2137+
struct nvmet_tcp_queue *q;
2138+
int pending = 0;
2139+
2140+
/* Check for pending controller teardown */
2141+
mutex_lock(&nvmet_tcp_queue_mutex);
2142+
list_for_each_entry(q, &nvmet_tcp_queue_list, queue_list) {
2143+
if (q->nvme_sq.ctrl == sq->ctrl &&
2144+
q->state == NVMET_TCP_Q_DISCONNECTING)
2145+
pending++;
2146+
}
2147+
mutex_unlock(&nvmet_tcp_queue_mutex);
2148+
if (pending > NVMET_TCP_BACKLOG)
2149+
return NVME_SC_CONNECT_CTRL_BUSY;
21382150
}
21392151

21402152
queue->nr_cmds = sq->size * 2;

0 commit comments

Comments
 (0)