From nobody Thu Sep 24 14:25:43 2026 Received: from mail-ot1-f98.google.com (mail-ot1-f98.google.com [209.85.210.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E99D7306744 for ; Tue, 22 Sep 2026 20:07:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.98 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790107669; cv=none; b=ElESCDROTcehR8yNehbl5iPFz3a/Ryf9JsismJ2mF2gxne2dBIpR/SQBr8cFPSpHJbwQi3ipOi+f28Xp+ztp3pXYOmGcdvc9wv+D4oytBRg8+puc0Z2GIhptjvIJVkFXDBIXII0FKiSs8ALp/Qfj+LhenURf5MPPs0JOnO3vduc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790107669; c=relaxed/simple; bh=fEN9QWh/H5XLgpzfFOmsp4HYU1gPeFsp9O/y7gJ7pIE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VQhDHBugyCNEUGngWNMAa04AnBdIosYYAPd5orrVBH5+VArj42GTFW7OWFtm8LirDiGovahek7u4mILTUf8NU+7ZBvaek6QT8aQxlOt9EAqwar6CSSUKT2Med10ZgwWKhqYNy//qJ9PWI8HX3yhDwGq0R3OuOfvDeVWcAG8neS4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com; spf=pass smtp.mailfrom=purestorage.com; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b=RiFAOPSW; arc=none smtp.client-ip=209.85.210.98 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=purestorage.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b="RiFAOPSW" Received: by mail-ot1-f98.google.com with SMTP id 46e09a7af769-7f84a55cc06so62595a34.2 for ; Tue, 22 Sep 2026 13:07:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1790107659; x=1790712459; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=UnqNTO+qf2rQpgu0xRZfaRVcdc87gpRUdjQ7jZicuFk=; b=RiFAOPSWFSuH/6SnCln7P4PaXQB/WFTB2FVH4eMoqUA15fpfvdtMHk0AF0cD1A70ii SZh8GO5JYicywjYWhHXLgS6/00JB11cHQVAnolap8E5z9taJ6kVX8o8hJF7RC+pFSnar LCzlFtXSHBb0KflcpULB1L/4IbmZeht5ngXB0BL11RDtGD7KovokcZNkacRAig0juVCg 23X2YYvHIPRroY8FIjDnjumEBwDLJ5baiOnXyXa9C7Wo87z5M313WgTY2y3neUHgZD5S tVv2AVc3UhbdR/tHut+8N9ZoUgvgyBbLekyUw2N+dsrzx9DT6Hk0Dhpymg4kry6JoVNM a82w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790107659; x=1790712459; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=UnqNTO+qf2rQpgu0xRZfaRVcdc87gpRUdjQ7jZicuFk=; b=FZh49p4S1M9vzxIh5EOPnFhpsldYGjiz8bVt5jdGdKEQIHYJoyNYAovK2JD/F0/2Cr Uf97th961wJvW4ywRtRAptR9RL12D1cAJMnNN3Ujs30Qq6Ak5mBUPohjC922b+wfcbIo AG3KYNOiacIB5CE6zpQ+ukO++BJuwoOoZIJpbN2KjyXm0xzYj7iA6F+2cZrwTCDhdWqy NRfBR3SsEhARWuVXzJ3uBuJcKXA89eqpbjWcIC4DinQUISqkilMFTHpG4Cbi+AQw1wDh 6U1S7QJhLECw4TYCdNIrZf/8EAcONwwxgiSikpGLkyGbqaxNwX7fCbkNnGbX694FP6op jK+w== X-Forwarded-Encrypted: i=1; AKwUvBzcCPy42boYzR+IDhNLVjshSCYWvRkJtDpPPM+2E42Jx5dvOHWQKzkjyGHFtcyGfeKbwd9pkDBxcqgQOe8=@vger.kernel.org X-Gm-Message-State: AFuF++lkm1eE19CFHfTx5ZcaPgIqgQDVbjnZFgZvtymqeySfBgQjRQw0 kEa2SGVV3ORSEy//Q0vRovboqO4y2Kt1o05na3lAY3mtm8lw7F8Flq+JMiQ2ZC7t1XtUXKQAnI+ jbEDrYnKe6LVIpqpn9RDWQv+kAFPee4aHcqnf X-Gm-Gg: AYBFou2Q3KXwv1XeUZtke1VWyg/4J1W0LKRQFA1rUhRno4vfaUOsKSZRLDwmlEPg9Z8 zsmJxe+7PaP6Dxh4h5tH7Eg6AkRe/wpjjZ+QW90g3S4p0tXCWWybZGMMa1BvF2bb1CZ5SwtQlK+ ++0wmPw7rGRq0j5g5MKU1GU0lNBdr6qwdjClfrvCRDUkhn4I6WSV6mZ5eWD+zwg3LOjm6cZST0Z mKPV3nN700Z3KZ4d81r/PurBru15XsUKJC0cQp4rtf2eEftilRiXWQcEvyq5+CMV7MpatMgn9SJ aBKx2c+j2JqsPgpMca6+z3p+bfEw9r1NcqPcEn7HKjqgUOpT3vtB15/GrCyPDDSvmLhc65bCqu6 TlDmqYoDnet+sTRrAJCgi8DyLL2kdxlQ= X-Received: by 2002:a05:6830:310c:b0:7fa:5c49:524f with SMTP id 46e09a7af769-815f37ecd7emr730236a34.22.1790107659525; Tue, 22 Sep 2026 13:07:39 -0700 (PDT) Received: from c7-smtp-2026.dev.purestorage.com ([208.88.159.128]) by smtp-relay.gmail.com with ESMTPS id 46e09a7af769-81603fc9137sm164400a34.6.2026.09.22.13.07.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2026 13:07:39 -0700 (PDT) X-Relaying-Domain: purestorage.com Received: from dev-sgogte.dev.purestorage.com (dev-sgogte.dev.purestorage.com [10.112.19.91]) by c7-smtp-2026.dev.purestorage.com (Postfix) with ESMTP id EACE04014B; Tue, 22 Sep 2026 14:07:38 -0600 (MDT) Received: by dev-sgogte.dev.purestorage.com (Postfix, from userid 1557734945) id E7CA23F9F5; Tue, 22 Sep 2026 14:07:38 -0600 (MDT) From: Surabhi Gogte To: Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg Cc: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, mkhalfella@purestorage.com, randyj@purestorage.com, adailey@purestorage.com, Surabhi Gogte , Hannes Reinecke Subject: [PATCH v4 1/3] nvme-tcp: store and use the caller's network namespace Date: Tue, 22 Sep 2026 14:07:16 -0600 Message-ID: <20260922200718.3941465-2-sgogte@purestorage.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260922200718.3941465-1-sgogte@purestorage.com> References: <20260922200718.3941465-1-sgogte@purestorage.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" nvme_tcp_alloc_queue() creates each socket using current->nsproxy->net_ns, which is correct for the initial connect that runs in userspace context. However, the reconnect and error recovery paths run from a workqueue where current netns is a kernel thread in init_net, so sockets created during reconnect end up in a different namespace than the one the controller was originally connected from. Fix this by capturing the caller's network namespace at controller allocation time. Use ctrl->net for all socket creation so that every queue, on initial connect, reset, or reconnect, is created in the same namespace. Fixes: 3f2304f8c6d6 ("nvme-tcp: add NVMe over TCP host driver") Signed-off-by: Surabhi Gogte Reviewed-by: Hannes Reinecke Reviewed-by: Sagi Grimberg --- drivers/nvme/host/tcp.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index 921934028e0b..f916bcca304f 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -171,6 +171,7 @@ struct nvme_tcp_ctrl { struct delayed_work connect_work; struct nvme_tcp_request async_req; u32 io_queues[HCTX_MAX_TYPES]; + struct net *net; }; =20 static struct workqueue_struct *nvme_tcp_wq; @@ -1858,7 +1859,7 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nct= rl, int qid, queue->cmnd_capsule_len =3D sizeof(struct nvme_command) + NVME_TCP_ADMIN_CCSZ; =20 - ret =3D sock_create_kern(current->nsproxy->net_ns, + ret =3D sock_create_kern(ctrl->net, ctrl->addr.ss_family, SOCK_STREAM, IPPROTO_TCP, &queue->sock); if (ret) { @@ -2650,6 +2651,7 @@ static void nvme_tcp_free_ctrl(struct nvme_ctrl *nctr= l) =20 nvmf_free_options(nctrl->opts); free_ctrl: + put_net(ctrl->net); kfree(ctrl->queues); kfree(ctrl); } @@ -3048,12 +3050,15 @@ static struct nvme_tcp_ctrl *nvme_tcp_alloc_ctrl(st= ruct device *dev, goto out_free_ctrl; } =20 + ctrl->net =3D get_net(current->nsproxy->net_ns); + ret =3D nvme_init_ctrl(&ctrl->ctrl, dev, &nvme_tcp_ctrl_ops, 0); if (ret) goto out_kfree_queues; =20 return ctrl; out_kfree_queues: + put_net(ctrl->net); kfree(ctrl->queues); out_free_ctrl: kfree(ctrl); --=20 2.55.0 From nobody Thu Sep 24 14:25:43 2026 Received: from mail-pj1-f98.google.com (mail-pj1-f98.google.com [209.85.216.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE6173BB106 for ; Tue, 22 Sep 2026 20:07:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.98 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790107685; cv=none; b=ApYklQyM0kBrX+WrZ33OrM2yE5F2pZLKjKikcDQwVGtxwDxb2TUVvhkv9M6IUbO2t43Odvrxgz14navot2QhWKvoheuC4Tgeh58f4wQhaHNUtJGh2ZmYIloRPp/A+zJ5jnuM6kyoDU+7nwrnJ4KJ1un4kT3I89PTvLHx/IFnp+I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790107685; c=relaxed/simple; bh=S5tH3o/ryAK221jHcWeohlICbzsgPEfU3j52DB5bczk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IIjgk9+Kln7rvW6O92BFWFxEAWuMJ/DqNeLF8zphrI0rcVlzVVMGzVd7pmxrrmzLg0d1cUfDjvzUscfzndf2Z3/hiPEhpIWame0d2Zyn48XgR71tbXjD8QWHVttnEBTxeJHvJdha2wqqHJgF1pdgXSaTpYmc3kIQmJpscSMazJw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com; spf=pass smtp.mailfrom=purestorage.com; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b=MnYjHVee; arc=none smtp.client-ip=209.85.216.98 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=purestorage.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b="MnYjHVee" Received: by mail-pj1-f98.google.com with SMTP id 98e67ed59e1d1-39647aa9d52so191916a91.0 for ; Tue, 22 Sep 2026 13:07:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1790107662; x=1790712462; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=9DHOT2PMGUFhuByMTJSr3B57dIXKaBHqTAzfX9zwMX8=; b=MnYjHVee/8Oo+rVXn3p7IMyjr39rOfOdfb+aw1RsQcNFobEzi0y2gevQq1PcVTW9/j SUht/+rlv7Ue/WxBt19GI33CLv2Fbfr602ih8aNEdpA/GjiO2hMCZ7JfDNPC7wbk2sxo Ecvs+NW81dRdJXKe/i+qom7J2WyJKMgtvFXZtbZpS/8vPajUORRGruFseroVheA+I1Bp Fop5Wc+nBd/b1JxuY7GE2u3KuUo8y5fMSrOpA1tFWxKGXu/r6qGxu37Wrv+TZJsrqN0Y 20kscBfAy53JPss5TuEJ4xIlG5Ww5HiqHIh/dQwECBIgSOKm8+dPZvn0w7YMBeVbkPab ZzNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790107662; x=1790712462; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=9DHOT2PMGUFhuByMTJSr3B57dIXKaBHqTAzfX9zwMX8=; b=M3rE7/jsP+snuSii3BpRwJGm2W++UfZe4JTyk3kqiso2lb4HPM9TDMU2UjI76N0Uqz lRC1GSluMLZcmUoXC40uSuRB/MY4MW0k1ZVGQm+2dEoo3fFPMEOJ59cYhDaOi56jtyET O0FAu5eNUq03qFkwQ+ds75x+/I4Nk5qjpkCSgm4Sogw0iE85+WcHlIlujI4DbU/Pw+cq BEG9FCgHF+MdDOI/rTPlvYY1+5Hi2FjOi4bTXxEBAem1BDb6ipGCZvSxnIBLEEg2K+Il +edOILWPCPSP+RAis0AhPeDov2DT83UnW+Y9afpLnhNr6X6W5FWHgEBKmqKQ/TkRn8Z5 XfxA== X-Forwarded-Encrypted: i=1; AKwUvBzMrtXZX+OoEM4jyY7NH2NcgfkroNIDOhNACchR+oSI0EPE8LCrqb9r/hbPgsaay2DraeveHjhYpOV4loE=@vger.kernel.org X-Gm-Message-State: AFuF++l+dS7DLD+5f6305kDCyjqcOZy0YNqezFQsavgYsNTcff+c2nUf g8vTXDBnafrCQi64/30oYPx/MxFlLES59SNMVMAXID5bqrzp/IGbE9Oqnhs3hT0HpxC7W+4EaYG C919JuivdVTo39eGV4Aeexl0jYO7bmY61wATAq/I1L5CvcfMVuaNm X-Gm-Gg: AYBFou1eagzIlnhEUgz+/WzF1eYdENaNY8+lhJM5vvDk3xk9SaQO8XlZ/LqMUfVd2Kx Ca7HScAm5H5YGYWsdtVkw57gREinXpE/7l/huGyDTGuKsKyJEdcmGCtV95o0+pDT4s10R2CdLcp Ez8E6OFmP6pUrGnZTGw4GTlbhWivJGUvxi0wswTCy380CIdtB+1/d/lX+TD8FoiKUTXTpW2kQkS wBW+YqpbZxbKAnPBIFiCF+Q9OKD61PM2XsUUNZvzf3i5aVkcmz9b6Z5OjiJpfjGOvyYvDRAHki9 Hb0qwKU+iU3YUAKhEB0uIi4Cm7QkyltD3XuEkHVtKNMHkgUdpTnktNbm6Q1wp0ECFCYwTfNCZ00 v0BAsZ0/fGE0vAK0= X-Received: by 2002:a17:90b:5648:b0:3a0:78b6:588e with SMTP id 98e67ed59e1d1-3a07e5957dbmr300750a91.23.1790107661882; Tue, 22 Sep 2026 13:07:41 -0700 (PDT) Received: from c7-smtp-2026.dev.purestorage.com ([2620:125:9017:12:36:3:6:0]) by smtp-relay.gmail.com with ESMTPS id 98e67ed59e1d1-3a07dcc1b89sm311270a91.3.2026.09.22.13.07.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2026 13:07:41 -0700 (PDT) X-Relaying-Domain: purestorage.com Received: from dev-sgogte.dev.purestorage.com (dev-sgogte.dev.purestorage.com [10.112.19.91]) by c7-smtp-2026.dev.purestorage.com (Postfix) with ESMTP id 45CC94014B; Tue, 22 Sep 2026 14:07:41 -0600 (MDT) Received: by dev-sgogte.dev.purestorage.com (Postfix, from userid 1557734945) id 4334D3F9F5; Tue, 22 Sep 2026 14:07:41 -0600 (MDT) From: Surabhi Gogte To: Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg Cc: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, mkhalfella@purestorage.com, randyj@purestorage.com, adailey@purestorage.com, Surabhi Gogte , Hannes Reinecke Subject: [PATCH v4 2/3] nvme-tcp: refactor I/O queue setup path Date: Tue, 22 Sep 2026 14:07:17 -0600 Message-ID: <20260922200718.3941465-3-sgogte@purestorage.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260922200718.3941465-1-sgogte@purestorage.com> References: <20260922200718.3941465-1-sgogte@purestorage.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Split the I/O queue setup helpers apart so that the individual steps can be called directly from nvme_tcp_configure_io_queues(): - Queue count negotiation moves out of nvme_tcp_alloc_io_queues() into a new nvme_tcp_set_io_queue_count(), leaving the allocator with just the per-queue allocation loop. - TLS PSK validation moves out of __nvme_tcp_alloc_io_queues() into a new nvme_tcp_tls_check_psk(). - nvme_tcp_configure_io_queues() now calls the three steps directly in the same order as before. Signed-off-by: Surabhi Gogte Reviewed-by: Hannes Reinecke Reviewed-by: Sagi Grimberg --- drivers/nvme/host/tcp.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index f916bcca304f..9308feba8a74 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -2184,10 +2184,8 @@ static int nvme_tcp_alloc_admin_queue(struct nvme_ct= rl *ctrl) return ret; } =20 -static int __nvme_tcp_alloc_io_queues(struct nvme_ctrl *ctrl) +static int nvme_tcp_tls_check_psk(struct nvme_ctrl *ctrl) { - int i, ret; - if (nvme_tcp_tls_configured(ctrl)) { if (ctrl->opts->concat) { /* @@ -2209,6 +2207,13 @@ static int __nvme_tcp_alloc_io_queues(struct nvme_ct= rl *ctrl) } } =20 + return 0; +} + +static int __nvme_tcp_alloc_io_queues(struct nvme_ctrl *ctrl) +{ + int i, ret; + for (i =3D 1; i < ctrl->queue_count; i++) { ret =3D nvme_tcp_alloc_queue(ctrl, i, ctrl->tls_pskid); @@ -2225,7 +2230,7 @@ static int __nvme_tcp_alloc_io_queues(struct nvme_ctr= l *ctrl) return ret; } =20 -static int nvme_tcp_alloc_io_queues(struct nvme_ctrl *ctrl) +static int nvme_tcp_set_io_queue_count(struct nvme_ctrl *ctrl) { unsigned int nr_io_queues; int ret; @@ -2247,14 +2252,22 @@ static int nvme_tcp_alloc_io_queues(struct nvme_ctr= l *ctrl) =20 nvmf_set_io_queues(ctrl->opts, nr_io_queues, to_tcp_ctrl(ctrl)->io_queues); - return __nvme_tcp_alloc_io_queues(ctrl); + return 0; } =20 static int nvme_tcp_configure_io_queues(struct nvme_ctrl *ctrl, bool new) { int ret, nr_queues; =20 - ret =3D nvme_tcp_alloc_io_queues(ctrl); + ret =3D nvme_tcp_set_io_queue_count(ctrl); + if (ret) + return ret; + + ret =3D nvme_tcp_tls_check_psk(ctrl); + if (ret) + return ret; + + ret =3D __nvme_tcp_alloc_io_queues(ctrl); if (ret) return ret; =20 --=20 2.55.0 From nobody Thu Sep 24 14:25:43 2026 Received: from mail-pl1-f225.google.com (mail-pl1-f225.google.com [209.85.214.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 470283B2FF8 for ; Tue, 22 Sep 2026 20:07:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.225 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790107686; cv=none; b=r0Fa6NqI6zxRyImu3deUd2h94sEVKrlu9UAN62YhFnFgqDFuBxe79320sOErkcQqlv8HQnlLgi9g6ol9XccutV1F/z+h6sFJsP3d9kOnJ9bpMUsIrZNw3nxi1hMpE1lromfLqilx48dMmSiGu7GUQttv5y6zo0p5qO/Ws8SIKus= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790107686; c=relaxed/simple; bh=YrLCdTCgijXxhNeP071upz/ihBFRy7w7FSybZD6lVsc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Bj98PhEu76NqYCJpKssJUN/5oax5P+Nm+h6rP2cDkLubGEONR3U564bZryU+CBlYWgG7cR1YjaB1f+rPpVvzigIDbf96YY17lM+8ew3gzc/gKB2NCaooxEJQK+KFJUxIUsu34xP6oijGuQtleEvz3D34VAMJ020w3rkj930/u7o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com; spf=pass smtp.mailfrom=purestorage.com; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b=UItcxZw1; arc=none smtp.client-ip=209.85.214.225 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=purestorage.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b="UItcxZw1" Received: by mail-pl1-f225.google.com with SMTP id d9443c01a7336-2df3ae6288cso793645ad.3 for ; Tue, 22 Sep 2026 13:07:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1790107669; x=1790712469; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=jKj3QXNJc64ZYZOzUkze7Bi+QP/5m/9g84NFc6owjQw=; b=UItcxZw1iHlRa/gw43U/jo44quuZREgjU96K023KVkkC8fuVITc8d2GF/BwikuoTL3 o3L8rpv2AG6KzlQz5tZuyXkrlI5/WFd1YT4ll/sQh1ICBhBp8efdenl1OPLnXLE9KEhz o7b2IQG1rs7TZPwR3pqR52NneBbSLY9HZZ0o+GXtq2i0Ai+RG1pXFj6kFbyCTe4ckh2o 2DCDmSMcrMdy9p4hlTjjKCyXZdOhM5SHSLkW1ztEe6MFnKLoTdfN0sh6SVgzDSk5EhOs acbAWjsqBd1fHJgxHdOxFQ7cPzhTexToFt2JS/Mj6yzBP+vLBqdmVX+U/tpYkpXOYueZ GxfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790107669; x=1790712469; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=jKj3QXNJc64ZYZOzUkze7Bi+QP/5m/9g84NFc6owjQw=; b=OOq+3yobwDUw/s09zuKkmah9zZGmzbuB0zrusvYWjXcXCDMHXBYCthNoi7AYzf9Na6 0isE8xTBBfdpLFIDEi+Jq0XgzFOWESqKxIk2kHsrMeFUgoNP7RhmXzY0Y8WTlodrGiAP BbpIoi1GZRB552wbidN9gkIVK1ovGsmqP4DSg4wn+8+ndqqMg8FZ0FbQ/XLH7UortMj/ 8o4OcSUZmeqtZg4GK+RFFfraVawPTSLDZHLEVOSh7ulHmhnDCiGry/QRg7vdXKofTWvk kYZiQ2J5IcQexAWjrLikUQLtBvpJAEk6RsZ6mD2Kw5+lmZyKk4xGTPQ+cjY3BnSPV1e2 gf4w== X-Forwarded-Encrypted: i=1; AKwUvBxBIbjGsqTeWdM2YQfQkEFWfo0Y750qnTowO9UR2waSJQHUsfnefZnH/ncLEcDfgRmVKDNxhuiw8bcCTIk=@vger.kernel.org X-Gm-Message-State: AFuF++nOJFiX8zWcQ3JbFxF9u6cNeX4n4jXfLoNRLP+YjackezVjg3ly 7LLvlHnhe55jv/lZgIH1i/Np8mgH1NDY4P9BYEZvv65DoG0uilM9BDzJ3rnU9kriHxAh6ZoaWcV G5gXwRE+LJhfj4bG8cX/wibNJOK7FnDxKjoyy4+ieZUqDgMEL3yMn X-Gm-Gg: AYBFou3PxPDpCDbELKXTuTbSKmsyPOUCt9y+JB08fKiP7FukT7AsoOrHbsA70fyJJLd kXnNmzjk89/1U0yZdOmyI+X9XgDhYF/26vthj7j2YgmrLVAE0IwoJxjlByJsFP1bHK2CsK13fIH hQ97DTYeXYr4KO3mjuS8RN4Gj37mvJOL3rIMPVJutoFYyWHSM1D6/EkT445SAalTtMmF42gp4QO 1l2ru8ebZtewO6cGb/7vFds9e6fdxOMjJl3In5W1hOvprLcMHVLyYYhwxEUhkwip+tbGYQx699n s3lBrMvdhuKStXkKGtvjwg6lotUW4JTYGq+B9RDfRZDGkUomffcV236JrwAkV+OeJi6Pw3h758D aHIXOuby5yL0peLA= X-Received: by 2002:a17:90b:2e83:b0:3a0:348a:5118 with SMTP id 98e67ed59e1d1-3a07e7555c3mr451315a91.47.1790107669177; Tue, 22 Sep 2026 13:07:49 -0700 (PDT) Received: from c7-smtp-2026.dev.purestorage.com ([2620:125:9017:12:36:3:6:0]) by smtp-relay.gmail.com with ESMTPS id 98e67ed59e1d1-3a07dd381f4sm306951a91.7.2026.09.22.13.07.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2026 13:07:49 -0700 (PDT) X-Relaying-Domain: purestorage.com Received: from dev-sgogte.dev.purestorage.com (bond0.slc5-n22m24-k8s.dev.purestorage.com [IPv6:2620:125:9025:20::a31:429]) by c7-smtp-2026.dev.purestorage.com (Postfix) with ESMTP id F0E694014B; Tue, 22 Sep 2026 14:07:47 -0600 (MDT) Received: by dev-sgogte.dev.purestorage.com (Postfix, from userid 1557734945) id EE52B3F9F5; Tue, 22 Sep 2026 14:07:47 -0600 (MDT) From: Surabhi Gogte To: Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg Cc: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, mkhalfella@purestorage.com, randyj@purestorage.com, adailey@purestorage.com, Surabhi Gogte , Hannes Reinecke Subject: [PATCH v4 3/3] nvme-tcp: parallelize I/O queue allocation and startup Date: Tue, 22 Sep 2026 14:07:18 -0600 Message-ID: <20260922200718.3941465-4-sgogte@purestorage.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260922200718.3941465-1-sgogte@purestorage.com> References: <20260922200718.3941465-1-sgogte@purestorage.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Similar to commit 2a8513091d2f ("nvme-rdma: parallelize I/O queue allocation and startup"), refactor nvme tcp I/O queue setup to use async API, combining allocation and startup into a single parallel operation per queue. This reduces connection and reconnection setup time when there are delays in establishing connections, which is especially important for high-core-count hosts. Key changes: - Use async API to facilitate parallel calls for io queue setup. - Add nvme_tcp_queue_setup_ctx for propagating errors from async workers. - Remove nvme_tcp_start_io_queues() and __nvme_tcp_alloc_io_queues(); their logic is folded into nvme_tcp_setup_io_queues() and nvme_tcp_configure_io_queues(). - Allocate the io tag set before the queues so that the queue range is known, and only set up the reconnect grow case if the queue count actually increased. - Serialize the cpu scan and claim in nvme_tcp_set_queue_io_cpu() with a spinlock, as concurrent callers would otherwise select the same cpu. The per-cpu counters no longer need to be atomics. Testing on a 64-core host with 64 IO-queues shows nvme-tcp connection time reduced from 61ms to 11ms. Signed-off-by: Surabhi Gogte Reviewed-by: Hannes Reinecke --- drivers/nvme/host/tcp.c | 119 ++++++++++++++++++++++++++-------------- 1 file changed, 77 insertions(+), 42 deletions(-) diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index 9308feba8a74..ec678ed07af8 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -54,7 +55,8 @@ MODULE_PARM_DESC(tls_handshake_timeout, "nvme TLS handshake timeout in seconds (default 10)"); #endif =20 -static atomic_t nvme_tcp_cpu_queues[NR_CPUS]; +static int nvme_tcp_cpu_queues[NR_CPUS]; +static DEFINE_SPINLOCK(nvme_tcp_cpu_queues_lock); =20 enum nvme_tcp_send_state { NVME_TCP_SEND_CMD_PDU =3D 0, @@ -154,6 +156,12 @@ struct nvme_tcp_queue { static DEFINE_MUTEX(nvme_tcp_ctrl_mutex); static LIST_HEAD_GUARDED(nvme_tcp_ctrl_list, nvme_tcp_ctrl_mutex); =20 +struct nvme_tcp_queue_setup_ctx { + struct nvme_ctrl *ctrl; + int qid; + int *err; +}; + struct nvme_tcp_ctrl { /* read only in the hot path */ struct nvme_tcp_queue *queues; @@ -1731,9 +1739,10 @@ static void nvme_tcp_set_queue_io_cpu(struct nvme_tc= p_queue *queue) goto out; =20 /* Search for the least used cpu from the mq_map */ + spin_lock(&nvme_tcp_cpu_queues_lock); io_cpu =3D WORK_CPU_UNBOUND; for_each_online_cpu(cpu) { - int num_queues =3D atomic_read(&nvme_tcp_cpu_queues[cpu]); + int num_queues =3D nvme_tcp_cpu_queues[cpu]; =20 if (mq_map[cpu] !=3D qid) continue; @@ -1744,9 +1753,10 @@ static void nvme_tcp_set_queue_io_cpu(struct nvme_tc= p_queue *queue) } if (io_cpu !=3D WORK_CPU_UNBOUND) { queue->io_cpu =3D io_cpu; - atomic_inc(&nvme_tcp_cpu_queues[io_cpu]); + nvme_tcp_cpu_queues[io_cpu]++; set_bit(NVME_TCP_Q_IO_CPU_SET, &queue->flags); } + spin_unlock(&nvme_tcp_cpu_queues_lock); out: dev_dbg(ctrl->ctrl.device, "queue %d: using cpu %d\n", qid, queue->io_cpu); @@ -2023,8 +2033,11 @@ static void nvme_tcp_stop_queue_nowait(struct nvme_c= trl *nctrl, int qid) if (!test_bit(NVME_TCP_Q_ALLOCATED, &queue->flags)) return; =20 - if (test_and_clear_bit(NVME_TCP_Q_IO_CPU_SET, &queue->flags)) - atomic_dec(&nvme_tcp_cpu_queues[queue->io_cpu]); + if (test_and_clear_bit(NVME_TCP_Q_IO_CPU_SET, &queue->flags)) { + spin_lock(&nvme_tcp_cpu_queues_lock); + nvme_tcp_cpu_queues[queue->io_cpu]--; + spin_unlock(&nvme_tcp_cpu_queues_lock); + } =20 mutex_lock(&queue->queue_lock); if (test_and_clear_bit(NVME_TCP_Q_LIVE, &queue->flags)) @@ -2131,25 +2144,6 @@ static void nvme_tcp_stop_io_queues(struct nvme_ctrl= *ctrl) nvme_tcp_wait_queue(ctrl, i); } =20 -static int nvme_tcp_start_io_queues(struct nvme_ctrl *ctrl, - int first, int last) -{ - int i, ret; - - for (i =3D first; i < last; i++) { - ret =3D nvme_tcp_start_queue(ctrl, i); - if (ret) - goto out_stop_queues; - } - - return 0; - -out_stop_queues: - for (i--; i >=3D first; i--) - nvme_tcp_stop_queue(ctrl, i); - return ret; -} - static int nvme_tcp_alloc_admin_queue(struct nvme_ctrl *ctrl) { int ret; @@ -2210,22 +2204,67 @@ static int nvme_tcp_tls_check_psk(struct nvme_ctrl = *ctrl) return 0; } =20 -static int __nvme_tcp_alloc_io_queues(struct nvme_ctrl *ctrl) +static void nvme_tcp_setup_queue_async(void *data, async_cookie_t cookie) { - int i, ret; + struct nvme_tcp_queue_setup_ctx *ctx =3D data; + struct nvme_ctrl *ctrl =3D ctx->ctrl; + int ret; =20 - for (i =3D 1; i < ctrl->queue_count; i++) { - ret =3D nvme_tcp_alloc_queue(ctrl, i, - ctrl->tls_pskid); - if (ret) - goto out_free_queues; + ret =3D nvme_tcp_alloc_queue(ctrl, ctx->qid, ctrl->tls_pskid); + if (ret) + goto out_err; + + ret =3D nvme_tcp_start_queue(ctrl, ctx->qid); + if (ret) + goto out_err; + + return; + +out_err: + WRITE_ONCE(*ctx->err, ret); +} + +static int nvme_tcp_setup_io_queues(struct nvme_ctrl *ctrl, unsigned int f= irst, + unsigned int last) +{ + ASYNC_DOMAIN_EXCLUSIVE(queue_domain); + struct nvme_tcp_queue_setup_ctx *ctxs; + int nr_queues =3D last - first; + int err =3D 0, i, ret; + + if (first >=3D last) + return 0; + + ctxs =3D kmalloc_objs(*ctxs, nr_queues); + if (!ctxs) + return -ENOMEM; + + for (i =3D 0; i < nr_queues; i++) { + ctxs[i].ctrl =3D ctrl; + ctxs[i].qid =3D first + i; + ctxs[i].err =3D &err; + async_schedule_domain(nvme_tcp_setup_queue_async, &ctxs[i], + &queue_domain); } =20 + async_synchronize_full_domain(&queue_domain); + kfree(ctxs); + + ret =3D READ_ONCE(err); + if (ret) + goto out_free_queues; + return 0; =20 out_free_queues: - for (i--; i >=3D 1; i--) - nvme_tcp_free_queue(ctrl, i); + for (i =3D first; i < last; i++) { + struct nvme_tcp_queue *queue =3D &to_tcp_ctrl(ctrl)->queues[i]; + + if (test_bit(NVME_TCP_Q_LIVE, &queue->flags)) + nvme_tcp_stop_queue(ctrl, i); + if (test_bit(NVME_TCP_Q_ALLOCATED, &queue->flags)) + nvme_tcp_free_queue(ctrl, i); + } =20 return ret; } @@ -2267,10 +2306,6 @@ static int nvme_tcp_configure_io_queues(struct nvme_= ctrl *ctrl, bool new) if (ret) return ret; =20 - ret =3D __nvme_tcp_alloc_io_queues(ctrl); - if (ret) - return ret; - if (new) { ret =3D nvme_alloc_io_tag_set(ctrl, &to_tcp_ctrl(ctrl)->tag_set, &nvme_tcp_mq_ops, @@ -2281,12 +2316,12 @@ static int nvme_tcp_configure_io_queues(struct nvme= _ctrl *ctrl, bool new) } =20 /* - * Only start IO queues for which we have allocated the tagset + * Only setup IO queues for which we have allocated the tagset * and limited it to the available queues. On reconnects, the * queue number might have changed. */ nr_queues =3D min(ctrl->tagset->nr_hw_queues + 1, ctrl->queue_count); - ret =3D nvme_tcp_start_io_queues(ctrl, 1, nr_queues); + ret =3D nvme_tcp_setup_io_queues(ctrl, 1, nr_queues); if (ret) goto out_cleanup_connect_q; =20 @@ -2310,9 +2345,9 @@ static int nvme_tcp_configure_io_queues(struct nvme_c= trl *ctrl, bool new) =20 /* * If the number of queues has increased (reconnect case) - * start all new queues now. + * setup all new queues now. */ - ret =3D nvme_tcp_start_io_queues(ctrl, nr_queues, + ret =3D nvme_tcp_setup_io_queues(ctrl, nr_queues, ctrl->tagset->nr_hw_queues + 1); if (ret) goto out_wait_freeze_timed_out; @@ -3157,7 +3192,7 @@ static int __init nvme_tcp_init_module(void) return -ENOMEM; =20 for_each_possible_cpu(cpu) - atomic_set(&nvme_tcp_cpu_queues[cpu], 0); + nvme_tcp_cpu_queues[cpu] =3D 0; =20 nvmf_register_transport(&nvme_tcp_transport); return 0; --=20 2.55.0