From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA433301129; Wed, 2 Jul 2025 16:34:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751474069; cv=none; b=jsd16/bJxmuoPhb5+0QK1J5uf9wQVoGtW/NyKPErPu8PEIQSt/jOlnYyoPQfk6rRAwd37/G5iZbyTum6oHwiof+rum2i5sHimhNzwuorj4wTw8cpD9W09idLgylpus0i72IGZFKuNL16Tto0IUFvxVccXRU1pJvVqyw50noIUE8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751474069; c=relaxed/simple; bh=23j3KSCA64Mgm0T8Sek4hATHwAlMZA3/GjuzRB7crDc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=A+mi0cLiakk50rHlBWUbrGNQOC+xJh/+RugfuVIbYO2zeMskCydi20nNKPgviW2dU37K8aNDnd1Bb7I4913RzWpzjZl6tdApdV1iMP6f3wBd6zENUFHrdCG3jKsrTLU072RKd8vU4N3ujli1QXsPGWGqZj7DDTIfHYwE9HnOAJE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=s7wAi7y2; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="s7wAi7y2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F0E5C4CEE7; Wed, 2 Jul 2025 16:34:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751474069; bh=23j3KSCA64Mgm0T8Sek4hATHwAlMZA3/GjuzRB7crDc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=s7wAi7y2o1DL6JllRa1VtciP4EQmr1mB0MRo0dTiVfDYh65PnoG4GYIyLKZt2c4L0 b2W+70CYPuwhX6T2da+c2AOfc0h/4I7g4dXHd0ZTviVJPF1X+ABG+9CeZxqMHR6h7R 1BaZ8gaKVypEO0rduEfLlAzfEoyCxyzG+QcG7w6Ws4qjT2495qy01DlQJfg9WuEmKX dzedhsXifh51x268vpDeVXpUXmk9rxKf05VxSk9jWPGR6ytUxPbxTCFwyPRcxZ8LQc Iye7z9OndxqV1/ldX/fLvoCDYb/2T02pzRKFGJ6vMuSoMPEpDWzwPl6NA0C+beAgsL iE4TRAceikqRg== From: Daniel Wagner Date: Wed, 02 Jul 2025 18:33:59 +0200 Subject: [PATCH v7 09/10] blk-mq: prevent offlining hk CPUs with associated online isolated CPUs Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20250702-isolcpus-io-queues-v7-9-557aa7eacce4@kernel.org> References: <20250702-isolcpus-io-queues-v7-0-557aa7eacce4@kernel.org> In-Reply-To: <20250702-isolcpus-io-queues-v7-0-557aa7eacce4@kernel.org> To: Jens Axboe , Keith Busch , Christoph Hellwig , Sagi Grimberg , "Michael S. Tsirkin" Cc: Aaron Tomlin , "Martin K. Petersen" , Thomas Gleixner , Costa Shulyupin , Juri Lelli , Valentin Schneider , Waiman Long , Ming Lei , Frederic Weisbecker , Mel Gorman , Hannes Reinecke , Mathieu Desnoyers , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-nvme@lists.infradead.org, megaraidlinux.pdl@broadcom.com, linux-scsi@vger.kernel.org, storagedev@microchip.com, virtualization@lists.linux.dev, GR-QLogic-Storage-Upstream@marvell.com, Daniel Wagner X-Mailer: b4 0.14.2 When isolcpus=io_queue is enabled, and the last housekeeping CPU for a given hctx goes offline, there would be no CPU left to handle I/O. To prevent I/O stalls, prevent offlining housekeeping CPUs that are still serving isolated CPUs. When isolcpus=io_queue is enabled and the last housekeeping CPU for a given hctx goes offline, no CPU would be left to handle I/O. To prevent I/O stalls, disallow offlining housekeeping CPUs that are still serving isolated CPUs. Signed-off-by: Daniel Wagner --- block/blk-mq.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/block/blk-mq.c b/block/blk-mq.c index 0c61492724d228736f975f1d8f195515603801b6..87240644f73ed0490a5459e042c68e0e168f727d 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -3681,6 +3681,43 @@ static bool blk_mq_hctx_has_requests(struct blk_mq_hw_ctx *hctx) return data.has_rq; } +static bool blk_mq_hctx_can_offline_hk_cpu(struct blk_mq_hw_ctx *hctx, + unsigned int this_cpu) +{ + const struct cpumask *hk_mask = housekeeping_cpumask(HK_TYPE_IO_QUEUE); + + for (int i = 0; i < hctx->nr_ctx; i++) { + struct blk_mq_ctx *ctx = hctx->ctxs[i]; + + if (ctx->cpu == this_cpu) + continue; + + /* + * Check if this context has at least one online + * housekeeping CPU; in this case the hardware context is + * usable. + */ + if (cpumask_test_cpu(ctx->cpu, hk_mask) && + cpu_online(ctx->cpu)) + break; + + /* + * The context doesn't have any online housekeeping CPUs, + * but there might be an online isolated CPU mapped to + * it. + */ + if (cpu_is_offline(ctx->cpu)) + continue; + + pr_warn("%s: trying to offline hctx%d but there is still an online isolcpu CPU %d mapped to it\n", + hctx->queue->disk->disk_name, + hctx->queue_num, ctx->cpu); + return false; + } + + return true; +} + static bool blk_mq_hctx_has_online_cpu(struct blk_mq_hw_ctx *hctx, unsigned int this_cpu) { @@ -3712,6 +3749,11 @@ static int blk_mq_hctx_notify_offline(unsigned int cpu, struct hlist_node *node) struct blk_mq_hw_ctx *hctx = hlist_entry_safe(node, struct blk_mq_hw_ctx, cpuhp_online); + if (housekeeping_enabled(HK_TYPE_IO_QUEUE)) { + if (!blk_mq_hctx_can_offline_hk_cpu(hctx, cpu)) + return -EINVAL; + } + if (blk_mq_hctx_has_online_cpu(hctx, cpu)) return 0; -- 2.50.0