From nobody Fri Sep 25 15:13:51 2026 Received: from mail-vk1-f226.google.com (mail-vk1-f226.google.com [209.85.221.226]) (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 E69FA28505E for ; Thu, 10 Sep 2026 20:29:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.226 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789072143; cv=none; b=ienjaTbYEQ2JwRNixFRUuL4afY06i6XQD6u8xe4KKjhqRQkJl4vJ3mtgCtQKRSwYXe50PucBONIQIAzrnFbVipCcDn3btyxqD/PHbF1sAwcUraHOTD5kqwto6r61IAPpBslslWg4jJ0tXeJ3ZEwkvCNSyGl9QdMewfkZW/O4y8g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789072143; c=relaxed/simple; bh=w5qIasXbZ8QltJ+wv9iGuUVg8HATw1SkxO3Xz/8hbis=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AREEx9X9hiCyQ/Q0snzsvnfuHYci5mKLrvhRvChJiElCKAoqTO8ShM/siXMy8PlNuh15fElgipJqxfleWbJh83TRJItu3uO97hYve/5GzfPtZpEpwfj/2/eOUjHsbOpVRULhZ1zbt+uhHiJWDSQ6SKQ3UzqftZDKzDZrsvgCYIc= 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=axBWX4mT; arc=none smtp.client-ip=209.85.221.226 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="axBWX4mT" Received: by mail-vk1-f226.google.com with SMTP id 71dfb90a1353d-5c65093556aso264649e0c.2 for ; Thu, 10 Sep 2026 13:29:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1789072141; x=1789676941; 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=+jY8D98dI3BJh9bGxWJLTam08cqOXeCPFw0Ktg9MgRA=; b=axBWX4mTxY1D5R11miYohkuZeaDPCeLjVMeQ9Zp0k+ok/R3MuX1w4SH62l1WpEVy6+ B+BXFqxTmq9HhkOnaOK+935GtN9KniqBckpn2vR1YxwRSmJa9m9jFI8uG8NrCOx5HpA6 MSfL4EkQlTASjP6umGu5v7/xB1ndT5ARYkZG3vL2aq9nO56d5YsBCpC2QK4Wibax/8yR 1iRh2qvjCyksfxu77L6clyB5lKXFyzx5DFgUWSTYxigvL3A33NHeWedYNAPAduNsRC3q TLmBEkHOnww2zl9HIEeBwSlnnf9Yd3nZ6l3nZP+m6WwgUR2DtHNklFYaYOz9VBIqG+BT vFSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789072141; x=1789676941; 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=+jY8D98dI3BJh9bGxWJLTam08cqOXeCPFw0Ktg9MgRA=; b=JvixKWCPZBYMm57lgJaTKCwz0FKntZl7AxcUP5YBx/KjRfWQQSeWqTjYiVWjzqV4uD 3ObDcXxqYq/y1tTUGI1MSA/hN1ukOBGBhdfY4r+i8UiwkX6UmmAAbYTuh/lAFBo2HI/Y zwCFDAykBQJc0z7ks3C0wldMrnPAxjaJWB5F+5komj/106lHhbeWNSjy6+993Y1KFGPO gObmZ4/3FfJDI0K+Y5BHbDlSTy9UJJOWgH1sdpKX+OObIEIfd1Q5lOIj5T3PqF9T4r9A gaTLeM3QDYGlyO7+lcYE/FQOJYLiBu/PzP6/8Vti8iQw6zgQHpaqyB/P+Nh0//OJvm/H M/ew== X-Forwarded-Encrypted: i=1; AKwUvByIOqNT2qDBukFnk3f4gKY5gk49wTJFGbNWx5u+WojZsCG4FTV9l2KSvIgjmIhwizNPkgUDeBho1DcXpPE=@vger.kernel.org X-Gm-Message-State: AFuF++maKVGuO8bnD3O/PrlFkF+1M35zkVC3+p2r3GQNXWFLXCIJRjVe Inm+LgCeIoWRwhPfn2VdaLjX0bTV1A+rkoH0c4NFd40JTiQeuJl2abpLAfBj4UEeFnFYC9Zi7ft nV3dl2D3SG9ATxhoCiDN8CGS6RobPNzja3972 X-Gm-Gg: AYBFou2SAf9/OLmjDOJdX8Xsw64J47pi+knN/a7CDWRuqWknKyXnI2jFX7JbCx+EiuB I/BCnzcjpNOP6sEIVk4BPOPHjmnm8rIc3ZHqA4bz2lIUzIkpeZvxvHSAezJM3i89ERbC7z62ctr vtcvyv1MNUX0FxSyxht+ltiGNA/d/8cEHm2gQsY4IHlv33z+oB8a2SGulpR0PSctZq7MRBoQrUL qBiTv3v7pgkbI+kiySzWOXcmtkIuUZyxnbcTX87hSpKDtbiFo0pKUHINxrH4qGduHL1060DL5Sz NWNqJXLKxUJ8T5fS4wzZ0iaE1bmkFy0zJfH3N3IJHkg9V8fKNfqehmCEH0JkhHcwv4IEbvm2N2Y luKIwVNZdSzZIQh25aWoHWnwnwXxUUqY= X-Received: by 2002:a05:6122:4894:b0:5c6:8480:35c8 with SMTP id 71dfb90a1353d-5c8462f5c71mr2417289e0c.8.1789072140729; Thu, 10 Sep 2026 13:29:00 -0700 (PDT) Received: from c7-smtp-2026.dev.purestorage.com ([208.88.159.128]) by smtp-relay.gmail.com with ESMTPS id 71dfb90a1353d-5c846f624f2sm163189e0c.2.2026.09.10.13.29.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Sep 2026 13:29:00 -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 24849400F1; Thu, 10 Sep 2026 14:29:00 -0600 (MDT) Received: by dev-sgogte.dev.purestorage.com (Postfix, from userid 1557734945) id 20E1551EC2; Thu, 10 Sep 2026 14:29:00 -0600 (MDT) From: Surabhi Gogte To: Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg Cc: Solganik Alexander , Roy Shterman , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, mkhalfella@purestorage.com, randyj@purestorage.com, adailey@purestorage.com, Surabhi Gogte Subject: [PATCH v3 1/3] nvme-tcp: store and use the caller's network namespace Date: Thu, 10 Sep 2026 14:28:10 -0600 Message-ID: <20260910202812.1642832-2-sgogte@purestorage.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260910202812.1642832-1-sgogte@purestorage.com> References: <20260910202812.1642832-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 5fda9661bdb7..8e5e22febe2a 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; @@ -1846,7 +1847,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) { @@ -2638,6 +2639,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); } @@ -3036,12 +3038,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 Fri Sep 25 15:13:51 2026 Received: from mail-pf1-f226.google.com (mail-pf1-f226.google.com [209.85.210.226]) (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 8FBC73B0AC7 for ; Thu, 10 Sep 2026 20:29:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.226 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789072145; cv=none; b=MDtT5mmJgcKu4DhrCJ4wvLsT7Ni2i6uUA5sPwjGdlAKD3uR0+6nWsNk8uadT727I6+5nWquJVGLI4auOo1BajByD/JTVpxJMkxgyEvMk5wp5nNyct6yxXIBvAD+Nicf1YZXGKBf+MhBGPRMvBtdB4YbV8gxSLhZ3w1U0vT6pmUM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789072145; c=relaxed/simple; bh=6C9oiDzf6tyX3YCqnKIrUShg+EaUa5nRAx/MHFChfKQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YTxgZxgYJQsAmbskFVIPF61qf6K7CRGPGpp2toYzWsmJ6OvFOBsNDsNHnK0I3bt02cuv+6LCGAVullzacMWBKCN0n32aMzpOWxtIfH9NvxGejqrRVC0D/aKk+MGNBh1Gl3V+dNlvd7zpf8mMDVtdKn5agVrZR6CxWpf+SFmMRzQ= 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=bhiEOsGM; arc=none smtp.client-ip=209.85.210.226 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="bhiEOsGM" Received: by mail-pf1-f226.google.com with SMTP id d2e1a72fcca58-8541875f596so119901b3a.0 for ; Thu, 10 Sep 2026 13:29:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1789072144; x=1789676944; 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=exD+q8RvsL8LlA1NdvdgIxXpMfooqJfEtsvkYfwTOw8=; b=bhiEOsGMb3NsHV3/jY9ynlH3NHILp7klEmAvivWkZB7aIFlMGAZvGVbv9+dXLM0OkX ovi2sJVV1rSZfFrzUO+l3GXaKSg8WX40tswsPCzTS0ErhY48mMs7wE48vStT0CU7y/aU B46pt1ABqqLJPoyz8Rwe1dcFswPWU/KrQ1mgiqjtoZf/1KacC0gJHbWSgpCAdyBMquPh 7A+A+FxD5k6wKRnj3lw+I96YmJEMh758kaJ84zvJrEILecfvhBzMKfCKF3Vzzu9IUBA0 fk/hHF2GmfdNmxbXe7ez54lqryrrG5dPdMv/naG//gKfNz+/IvN4mEJKa5oc5b+eKLxg 9VUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789072144; x=1789676944; 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=exD+q8RvsL8LlA1NdvdgIxXpMfooqJfEtsvkYfwTOw8=; b=N2Q3shWDp8DtFj1S6mbTSvxhXKUHawr1Oa7FN9hPl6diUKQPmrl79DI5whQ2nak8BY flqc3xdw3PV0Hri0i3S6GfsKvoUcW28nWRZgx9zD+O8yyL3cy+Gov90Swe/FAbHq2sJo ZNi166ETHqTuRY/l9mtreGcooEomhAzm5+7ACNu2m5FnD2AyTSAlqZjrNwaWqqzHNe77 v3tN0CcDud1h0mO7+uNMiwETS6W2EyJenW2mBPPHt3TGgI2QMIBGuj5ytM4oRX4JIpxi NP+GjiU2ti8lg8Gxs48veGxoWvComy9b/ovUkMRhhp3NLVqNn0FuxxJYzQNAa+lkyrYW ysxw== X-Forwarded-Encrypted: i=1; AKwUvBxoDqF0ygU206ZZN3UG6uGtyRrl8aheGSCYQeaaj8BfsU3bBHIHbQ7VZoAywkScKo4aR3r9PDdDwSwE7xE=@vger.kernel.org X-Gm-Message-State: AFuF++nIa4NeKoqG62aW09ipiojJbH9m5ydqNCU4wnzqV5HmnINrCFxn QVHtWTOVozxRlVun7hBGtuXo6zPu6jJj6lVVJZFC/W9T5darI5T8+XTVJeG9ZrwGpZX3R+sPLDE ldWTXFeuAm5dGVEIqd+vwptsBOB1KhC3AEfEn X-Gm-Gg: AYBFou24qQLjK96P+/hNVJc7PbbUvrMCtW+Q3tETWdNxxaVoagDHVo0vVsqx55Knq2z oxiBcUOOOOEcyGcHFyeKe0SGe75nmft8A3i0YfY5ncfsQCmaGg023tsQPVHuS9MiwJM4j8mSUW1 weTo8t7/Xzro3xyUVWTfAQc3s7wAJHJvSjF0kG8hUVBsX6I/k7N7yVxuMtZNQfetUb+mHrVY/Al EpPoAybV5QrWJ6hYzYxWsc2YkQ0Z/KVAn0g7fuO8JQx6o4laU4HRS5ReigWucUlAQqcJUNZGnIn wiwxRhYO/nVT36R0FjU9V6llgJTAsru2Q8zx9687+aymHvxJMGalp3kS2jVkTHaF5TkJCkcN1ay 8LXMQf1xkWtgmofOM+B6zWITZIvJMMlQ= X-Received: by 2002:a05:6a00:39a8:b0:857:73e2:9107 with SMTP id d2e1a72fcca58-86b344f0d09mr814115b3a.23.1789072143746; Thu, 10 Sep 2026 13:29:03 -0700 (PDT) Received: from c7-smtp-2026.dev.purestorage.com ([208.88.159.128]) by smtp-relay.gmail.com with ESMTPS id d2e1a72fcca58-86b27dc0f73sm108946b3a.5.2026.09.10.13.29.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Sep 2026 13:29:03 -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 1044940320; Thu, 10 Sep 2026 14:29:03 -0600 (MDT) Received: by dev-sgogte.dev.purestorage.com (Postfix, from userid 1557734945) id 0D37851EC2; Thu, 10 Sep 2026 14:29:03 -0600 (MDT) From: Surabhi Gogte To: Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg Cc: Solganik Alexander , Roy Shterman , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, mkhalfella@purestorage.com, randyj@purestorage.com, adailey@purestorage.com, Surabhi Gogte Subject: [PATCH v3 2/3] nvme-tcp: refactor I/O queue setup path Date: Thu, 10 Sep 2026 14:28:11 -0600 Message-ID: <20260910202812.1642832-3-sgogte@purestorage.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260910202812.1642832-1-sgogte@purestorage.com> References: <20260910202812.1642832-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: 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 8e5e22febe2a..fe0e581608b4 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -2172,10 +2172,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) { /* @@ -2197,6 +2195,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); @@ -2213,7 +2218,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; @@ -2235,14 +2240,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 Fri Sep 25 15:13:51 2026 Received: from mail-ua1-f100.google.com (mail-ua1-f100.google.com [209.85.222.100]) (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 DA1F03C1F54 for ; Thu, 10 Sep 2026 20:29:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789072149; cv=none; b=aS7oQa94I1E7Fj5XDRnM9qPiFWHU3QJ8Q1GQnFZ77vDTri+156Ssy0S51R21A/rKrDEI6iX4pBodv+0yCdTfMtPilqHe7eDRDGvRdgGZlaptFR95ez3/949YMxaG8BWJO5+jP5h7kZHrP7scL57PaexGVeLDItQdvT2i5pTr4ik= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789072149; c=relaxed/simple; bh=Ido0/YKhr4hg8bNx3bDhlcMvk0FeolehPfNczkmbUZ8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZrilhFKYMacOa1ehsu+HGxrK6xDnufPudgyWiaocMVaYEcwRK47YGF57ZfVArn5XRpQmcLutGk6BgcPnKghROzOEjsuq5TshV48qpeYIzMxhZgn7738s+95KZheRUeu1VMFzFwTiiGHP9iYjbuM81pk3/5CadDwfcEikQTsa5Yg= 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=CtIVkZRZ; arc=none smtp.client-ip=209.85.222.100 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="CtIVkZRZ" Received: by mail-ua1-f100.google.com with SMTP id a1e0cc1a2514c-97ccbba8e86so114693241.3 for ; Thu, 10 Sep 2026 13:29:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1789072147; x=1789676947; 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=45lPbm0J/mESc8mxYG8Q+81MuxbcOW2zJuqMUPNJZwM=; b=CtIVkZRZXiGouwtnxaew75Uvt/XLyuCHTX3xpdBsMb7yrgDvHyu9SLjmPJ+lHeFRG3 zquun2dX1odHBiLkhgM7NkzAej4GGUphSNGlwgEvhj1eHCpJH1jOhsvanhvmsmEtI9bd 4x+E0jffbpsDH8F8RWhf+EmLtl4N2wAcbf8iJxl1K8c3Hj/iZ4tBCOyiP6gxrB9U8+nA rfkB6uGuZzlSsnUcTMJoLI5K0Ppqz2k/ctfp2JvdvhrTpcmIXQ6nvN026CcBnY7mD/5j Z1j8xjY/WtQSMta2SGxzM5fuBwuH+4anZzNoD+n2cVQJX0aqU6vq5HtXkF/h3eExQHEO QIFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789072147; x=1789676947; 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=45lPbm0J/mESc8mxYG8Q+81MuxbcOW2zJuqMUPNJZwM=; b=ixCgHISIgZkvCL5QS78thWwS3sPcL/hxtqH/WlXs2aurBQ032ssqTKzYiSE6jL6/5v +33qftmZDtahR/hI1nVuXJbwCeMAuMpxLLLstZYWfpUuHy4JeVzKzDS+KtEXxmsX9jBo 91ZRQMsVELw0aRmnk6+7iwV11XHmlcqXQF5ua3EpY5D4al156SeCMBKwk25YO0dPlCUO SQhV5o37I0QuZCfy9WQHwcVzPXV4byknnFFo6sM4yUzLn3pEhYN5gm3qqUscYFkhI1/D BvLQZf0G6pmIw3+V38AcOZZXB+wHbn1xmupIEtsm6M1Bjlu7fiAhwKPwF1EggSEYcInv aZvA== X-Forwarded-Encrypted: i=1; AKwUvBwFSNBiY5vTepH7HRQo/lZI7RPjqnxqQKMzR0WU/oWe87BY23nRGvmcfEZ8XJ1wFv/i75agngTVJjNvzpk=@vger.kernel.org X-Gm-Message-State: AFuF++n3ztLM8dj5akCe/yJtRq0Sgo05dB8A0edPCUzRhSn1ey59M17j cSHqnGbgYoNbSLjNCBzcFevJO7iidxMT0d4RJ61t7QayVJ3Ytp9YHc4OnIKk/rQYSiyXd2irzwG JeYujRgvaat/TYNiQRHLZPgZeakHKhe60EkY110pRp5Zb6MGuI+kK X-Gm-Gg: AYBFou1mQZxv2JluQyqpJg1Gr/YMAj0LqM5WgHtaODdzmKEHHAo0swni7R2wSueRASj Uji7aBw6Wnedc0wXkGWh5KvGTqLrM2Dz9igLFO9EsM1B+b45wce2o5I5BTgd/j5Q/0zFYxj1ZWi pWRWMpV5cOzC5ICdVmwMOQB/Cxzcs3nvZg1iIDysuwBnpQbLAn5oime66mewaobqdl9VOB7zHYY uhWeU45VwMU5HPCMh/LxrUvjmKedEgN/mAQX0nmWoqOjgh2uwTzKF8fLxvn4BtsQOIu1sp9F/Ib BmAS7WpgaozhkuP8mQZ9B/eOaFOvhCbQxFNZCh+JTml8XnPAxCD91pEAmHWd9w42dYwgaW9J2sz JINNxRrt+7jTk3gbK X-Received: by 2002:a05:6102:61cd:20b0:780:c715:292a with SMTP id ada2fe7eead31-792aaa6154cmr1361188137.13.1789072146598; Thu, 10 Sep 2026 13:29:06 -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 a1e0cc1a2514c-982b9c9e3cesm142178241.6.2026.09.10.13.29.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Sep 2026 13:29:06 -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 1D799400F1; Thu, 10 Sep 2026 14:29:06 -0600 (MDT) Received: by dev-sgogte.dev.purestorage.com (Postfix, from userid 1557734945) id 1A11E51EC2; Thu, 10 Sep 2026 14:29:06 -0600 (MDT) From: Surabhi Gogte To: Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg Cc: Solganik Alexander , Roy Shterman , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, mkhalfella@purestorage.com, randyj@purestorage.com, adailey@purestorage.com, Surabhi Gogte Subject: [PATCH v3 3/3] nvme-tcp: parallelize I/O queue allocation and startup Date: Thu, 10 Sep 2026 14:28:12 -0600 Message-ID: <20260910202812.1642832-4-sgogte@purestorage.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260910202812.1642832-1-sgogte@purestorage.com> References: <20260910202812.1642832-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 | 124 +++++++++++++++++++++++++--------------- 1 file changed, 79 insertions(+), 45 deletions(-) diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index fe0e581608b4..0fc244e676f9 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; @@ -1719,9 +1727,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; @@ -1732,9 +1741,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); @@ -2011,8 +2021,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)) @@ -2119,25 +2132,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; @@ -2198,22 +2192,64 @@ 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; + + 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; } @@ -2255,10 +2291,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, @@ -2269,12 +2301,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 @@ -2298,12 +2330,14 @@ static int nvme_tcp_configure_io_queues(struct nvme= _ctrl *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, - ctrl->tagset->nr_hw_queues + 1); - if (ret) - goto out_wait_freeze_timed_out; + if (ctrl->tagset->nr_hw_queues + 1 > 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; + } =20 return 0; =20 @@ -3145,7 +3179,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