Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795032706; b=QpMyLukgAqOnNtHDufwcseQD1KD2IzKbSfb1kDUGr5GOyf1n2PLi4Ta27j0WCqdzaKCo wch7NAmHU/O4YuTprTEMBXuc/GnpCVg4tXz6chhIHLk5hNQqVTfDyN8vGeb3yGvfLSWyX /pHHq96z6BwnsV5d7WGOOL44cC0dMZz5FwjFXvV2OC5fe/o85x/fW2kTs/rMEzvtD5rPW NBiOk06f5YUgT4ymEo/Y/qDYGSjs2EBiLD1//hU9tPhxswD0INrxny//7fxLdMYukFskp tgtpVWNEIwlyvglUtXgpD8pMlw9+tZd43qYUgSokp/V6OYWMDcP/3BHSniG2hRrK06A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795032706; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=l5ejY9ps9Kpf9n/jn8PMF1DA9iglJJP1nChn6l7CGSg=; b=pZP8S8NLbZcUDtpjvVKFVkzBjyth+H7EkhWT/nxrA78U68FBrZJMLCWm2kaFhmTVQ3bC WtwBR1yBiJ7WaTp33vyTcWBY347ZUm768804jg9sKJH8410MA+Shuc4hFw4H0a5SLdI3z L0cvBXhnrjWAfWrO1tYL5FTQnPhhwixAnM93m+uQBcwyKOTEImt0ywLOZV/AJ39SuZKdJ Os71DJYJEg4ITTbbYP2bABWV5Fd5H3W/S5/r+zGPHv5gNlo6qDFBL6H11FoFIjvUCAbKP 6upsgL1goBkHs+otMmM22XwTiA0h+pAQZVwOOyc3z6a/6v3T8yQ0tMCpqkV8hxmHlSw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=KpR0j5jX; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B783A60A260A; Wed, 18 Nov 2026 20:11:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=KpR0j5jX Received: by smtp.kernel.org (Postfix) with ESMTPSA id 190F11F000C4; Wed, 18 Nov 2026 20:11:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795032706; bh=l5ejY9ps9Kpf9n/jn8PMF1DA9iglJJP1nChn6l7CGSg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=KpR0j5jXdwssTlSJIMiWtkuOMar7x3Q9xRiRxl1AMoaewe+shUHSLVW8Fe2L/cgj7 x4ku4HvAOmiOHF44nDGyQqkhzp1o8ekPnMANusBv+S/oXExeoDauBN25HDlY43rpPC zb6B0qr2tTgeskM4QMUihZ6SAXFrAcLJ3uDzYIpg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Hannes Reinecke , Maurizio Lombardi , Daniel Wagner , Keith Busch , Sasha Levin Subject: [PATCH 6.12 1505/1756] nvme-fabrics: limit each queue type to the number of online CPUs Date: Wed, 18 Nov 2026 16:00:32 +0100 Message-ID: <20261118150108.829075093@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150007.957976754@linuxfoundation.org> References: <20261118150007.957976754@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Daniel Wagner [ Upstream commit 99fd0cbae84988e0af34784aa18ddd51ae094ade ] nvmf_nr_io_queues limits each queue type to the number of online CPUs when asking for I/O queues, but nvmf_set_io_queues hands out the granted queues without these limits, and only nr_io_queues is clamped when parsing the options. E.g. with 2 CPUs, nr_io_queues=2, nr_write_queues=10 and nr_poll_queues=10, 2 + 2 + 2 = 6 queues are requested, but handed out as 4 default, 2 read and 0 poll queues. blk_mq_map_queues can't create more CPU masks than there are CPUs, so default queues 2 and 3 take over the CPUs of default queues 0 and 1, and connecting the I/O queue of default queue 1 fails with -EXDEV. Apply the same limits in nvmf_set_io_queues. A queue type with more queues than online CPUs always has a hardware context without an online CPU, so no working setup changes. The options are not modified, so the limits follow CPU hotplug on reconnect. Fixes: 6486199378a5 ("nvme-tcp: fix queue mapping when queue count is limited") Fixes: a249d3066de6 ("nvme-fabrics: add queue setup helpers") Reviewed-by: Hannes Reinecke Tested-by: Maurizio Lombardi Signed-off-by: Daniel Wagner Signed-off-by: Keith Busch Signed-off-by: Sasha Levin --- drivers/nvme/host/fabrics.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c index 5e8f2edd5ace3..438cd602f641f 100644 --- a/drivers/nvme/host/fabrics.c +++ b/drivers/nvme/host/fabrics.c @@ -1097,18 +1097,27 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts, void nvmf_set_io_queues(struct nvmf_ctrl_options *opts, u32 nr_io_queues, u32 io_queues[HCTX_MAX_TYPES]) { + /* + * Each queue type is mapped to the CPUs separately, so a type with + * more queues than online CPUs has hardware contexts without an online + * CPU. Use the same limits as nvmf_nr_io_queues. + */ + u32 nr_io = min(opts->nr_io_queues, num_online_cpus()); + u32 nr_write = min(opts->nr_write_queues, num_online_cpus()); + u32 nr_poll = min(opts->nr_poll_queues, num_online_cpus()); + memset(io_queues, 0, sizeof(*io_queues) * HCTX_MAX_TYPES); - if (opts->nr_write_queues && opts->nr_io_queues < nr_io_queues) { + if (nr_write && nr_io < nr_io_queues) { /* * separate read/write queues * hand out dedicated default queues only after we have * sufficient read queues. */ - io_queues[HCTX_TYPE_READ] = opts->nr_io_queues; + io_queues[HCTX_TYPE_READ] = nr_io; nr_io_queues -= io_queues[HCTX_TYPE_READ]; io_queues[HCTX_TYPE_DEFAULT] = - min(opts->nr_write_queues, nr_io_queues); + min(nr_write, nr_io_queues); nr_io_queues -= io_queues[HCTX_TYPE_DEFAULT]; } else { /* @@ -1117,14 +1126,14 @@ void nvmf_set_io_queues(struct nvmf_ctrl_options *opts, u32 nr_io_queues, * sufficient queue count to have dedicated default queues. */ io_queues[HCTX_TYPE_DEFAULT] = - min(opts->nr_io_queues, nr_io_queues); + min(nr_io, nr_io_queues); nr_io_queues -= io_queues[HCTX_TYPE_DEFAULT]; } - if (opts->nr_poll_queues && nr_io_queues) { + if (nr_poll && nr_io_queues) { /* map dedicated poll queues only if we have queues left */ io_queues[HCTX_TYPE_POLL] = - min(opts->nr_poll_queues, nr_io_queues); + min(nr_poll, nr_io_queues); } } EXPORT_SYMBOL_GPL(nvmf_set_io_queues); -- 2.53.0