From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=34.202.193.197 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796074198; b=k6gtW/Tg2SKrEWo9SY2kRBS3zS3jsQn51Hsk8m9tA17Ixdn08aD4pBzx/ztmlXbyErC9 /eS0o7nieZnheUcvk7DsUTlU61bx7jbfhf39uBE93IyZmH/gVe7Wx40Mkzee7zpafZgke O4eQZgrR6viF/4w+orDagYnpOumtZXROOS3NwCFNteyov2wiBKiOhsZIN0rkf2F1cza/G 96W7gtX8yi9Nz1LGfZf6KJbsLtMZ7ld11wjGPgdbzZZUMpso0zQ73TOb7eLb3tzk7oUo6 tpFgSQ72JFqg1flLH6tNGFfUCKsWWqCTfwyqfkibgBbk3HsT/0QOqLqWi89Y6OapUAQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796074198; h=DMARC-Filter:DKIM-Signature:DKIM-Signature:Feedback-ID: X-Pm-Original-To:Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding: X-MIME-Autoconverted:Content-Type; bh=TcwX17xcx2zQToRSO8pCV+rZ6D1udEaXYZqwRFr+W5I=; b=Oz2z7/1FiuEIbnW6wZ2S3LDV2CsDWtzuWMghF2kIGuND1D2n0X6WoEzqYtMDZIOyNPGh QrCkFFQ1HhVysvZr6PdhB9dpq2f/6lC+1IpsJpDSa4eLNPjKzRdDu1UKhldKWm6OhwMVC 7sEfwbaaPJUjE5lCnhu4gq64nyyLDbkMPb/cBBl7opmhudNEIDB0m05YjQKLji9GjmnIJ 69OMhP4bByHZLuq8crsPtMRZ+FHVqFO8T4QWqM0E1BIb/qhlLOywOJpbr4V7dMCtCyLas dVXrerk+GjExnNKwRYWmH1J/GVSB3uxmBvbQP12ooYlLLt1gZFggCvIhKSJR8Nll7Og== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=atomlin.com; spf=pass smtp.mailfrom=atomlin.com; dkim=pass header.d=atomlin.com header.i=@atomlin.com header.a=rsa-sha256 header.s=purelymail3 header.b=A2zPJTkI; dkim=pass header.d=purelymail.com header.i=@purelymail.com header.a=rsa-sha256 header.s=purelymail3 header.b=wQxiFxgT; arc=none smtp.remote-ip=34.202.193.197 Received: from sendmail.purelymail.com (sendmail.purelymail.com [34.202.193.197]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 93CF6606A685 for ; Mon, 30 Nov 2026 21:29:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 93CF6606A685 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=atomlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=atomlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=atomlin.com header.i=@atomlin.com header.a=rsa-sha256 header.s=purelymail3 header.b=A2zPJTkI; dkim=pass (2048-bit key, unprotected) header.d=purelymail.com header.i=@purelymail.com header.a=rsa-sha256 header.s=purelymail3 header.b=wQxiFxgT DKIM-Signature: a=rsa-sha256; b=A2zPJTkIGDlf068tB8j3VvHtfAUP40gVmrNCFIhvTc3Tc91g2ZoH4TWN5UHPza7f5Zndz4x/IBkvUscliK2pqFkprffSBG+lbRhCR+Ah3Ru7ErwGPe6BJ4+DSKL1zb3p3CPBOj0wRvoR+/JWTtS2+V1w/GdnfuEDy45V0oynT98TmW01NBBPzBxXZ4MgZ4auaRjCw0b6vqPygq5tLPvTATHcAQE4bC53E5fEeMTlW2VgW06Xw/CNAAziZdqu4VyGM4Buu5aguOK857GOym49KIWG5fLnrB4PteFCDXOjoTFkibnDLW2bb6CweCQqDx68NgwymhUz4eNpC7+7PO6KJg==; s=purelymail3; d=atomlin.com; v=1; bh=Yp4mYhn6NplfpeJZ7M5LwQZCul6h36dhtE73yshmq1Q=; h=Received:From:To:Subject:Date:Message-ID; DKIM-Signature: a=rsa-sha256; b=wQxiFxgTvYEhBtlxU55meOk2ShZUraCJDOkiyKAdEu3fN4OXreaeBDgb8Mxo7LNFu7aQpWvQQINOgkbqlbkNSXzp6Q9AV0JZlHIlB8LORTZ8m1MQqbGKaXlXSybw6AZ3vn4MIjZhbR/jRI0uCrkWNtEBxE9XivccX2BoPG4JSx1ZSRQqiWF8g22TWRqV7HE82Kp0nGDcdl6UDnKRkd8EkUk7fo/Xtv8Q8KmU4gV4B6MWgcTb80RmM3m7B+r9Qh5Pmz1nxRtJH7z+X0xFXscn1V5AKXJdjxxiqPpt4NUB3DKhtpdf/yGkivoxo8oumV+7mwh4EFwGlp33yw4DJ+jBfw==; s=purelymail3; d=purelymail.com; v=1; bh=Yp4mYhn6NplfpeJZ7M5LwQZCul6h36dhtE73yshmq1Q=; h=Feedback-ID:Received:From:To:Subject:Date:Message-ID; Feedback-ID: 1802931:67223:null:purelymail X-Pm-Original-To: virtualization@lists.linux.dev Authentication-Results: purelymail.com; auth=pass Received: by smtp.purelymail.com (Purelymail SMTP) with ESMTPSA id -1042642541; (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Mon, 30 Nov 2026 21:28:34 +0000 (UTC) From: Aaron Tomlin To: axboe@kernel.dk, tglx@kernel.org, aacraid@microsemi.com, James.Bottomley@HansenPartnership.com, mkp@kernel.org, frederic@kernel.org, bigeasy@linutronix.de, gmaglione@redhat.com, vgoyal@redhat.com, stefanha@redhat.com, miklos@szeredi.hu Cc: atomlin@atomlin.com, dwagner@suse.de, eperezma@redhat.com, tom.leiming@gmail.com, ionut.nechita@windriver.com, corbet@lwn.net, vincent.guittot@linaro.org, mingo@redhat.com, peterz@infradead.org, radu@rendec.net, akpm@linux-foundation.org, steve@abita.co, sean@ashe.io, chjohnst@gmail.com, neelx@suse.com, mproche@gmail.com, nick.lange@gmail.com, marco.crivellari@suse.com, rishil1999@outlook.com, linux-doc@vger.kernel.org, linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, virtualization@lists.linux.dev, linux-fsdevel@vger.kernel.org, fuse-devel@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v18 5/9] blk-mq: prevent offlining hk CPUs with associated online isolated CPUs Date: Mon, 30 Nov 2026 16:28:08 -0500 Message-ID: <20261130212830.373057-6-atomlin@atomlin.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261130212830.373057-1-atomlin@atomlin.com> References: <20261130212830.373057-1-atomlin@atomlin.com> X-Mailing-List: virtualization@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by Purelymail Content-Type: text/plain; charset=UTF-8 From: Daniel Wagner When isolcpus=3Dmanaged_irq 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 online isolated CPUs, and conversely disallow bringing an isolated CPU online while its mapped hctx has no online housekeeping CPU. Signed-off-by: Daniel Wagner Reviewed-by: Hannes Reinecke Tested-by: Ionut Nechita Acked-by: Frederic Weisbecker Acked-by: Marco Crivellari Co-developed-by: Aaron Tomlin Signed-off-by: Aaron Tomlin --- block/blk-mq.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 116 insertions(+), 2 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 54ccfc43c27c..3b48951d459f 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -3726,6 +3726,76 @@ static bool blk_mq_hctx_has_requests(struct blk_mq_h= w_ctx *hctx) =09return data.has_rq; } =20 +/** + * blk_mq_hctx_can_offline_hk_cpu - Check if a housekeeping CPU may go off= line + * @hctx:=09Hardware queue context being evaluated + * @this_cpu:=09CPU going offline + * + * Prevent offlining the last online housekeeping CPU mapped to @hctx whil= e + * any isolated CPU mapped to @hctx remains online, avoiding stranded I/O + * submissions. System suspend, hibernation, and shutdown/reboot are exemp= ted + * via cpuhp_tasks_frozen and system_state. + * + * Return: true if @this_cpu may go offline, false otherwise. + */ +static bool blk_mq_hctx_can_offline_hk_cpu(struct blk_mq_hw_ctx *hctx, +=09=09=09=09=09 unsigned int this_cpu) +{ +=09const struct cpumask *hk_mask =3D housekeeping_cpumask(HK_TYPE_MANAGED_= IRQ); +=09int cpu, fallback_isolated_cpu =3D -1; + +=09/* +=09 * During system suspend, hibernation, or shutdown/reboot, all CPUs +=09 * are being taken offline. Allow offlining to proceed so the +=09 * transition is not aborted. +=09 */ +=09if (cpuhp_tasks_frozen || system_state > SYSTEM_RUNNING) +=09=09return true; + +=09/* +=09 * If the CPU being offlined is not a housekeeping CPU, +=09 * offlining it will not strand isolated CPUs. Allow it. +=09 */ +=09if (!cpumask_test_cpu(this_cpu, hk_mask)) +=09=09return true; +=09/* +=09 * If this CPU is not mapped to this specific hardware context, +=09 * offlining it will not affect the context's I/O routing. Allow it. +=09 */ +=09if (blk_mq_map_queue_type(hctx->queue, hctx->type, this_cpu) !=3D hctx) +=09=09return true; +=09/* +=09 * Iterate over all online CPUs and manually check their mapping. +=09 * We cannot use hctx->cpumask here because blk_mq_map_swqueue() +=09 * intentionally strips isolated CPUs from it to prevent kworker +=09 * routing. +=09 */ +=09for_each_online_cpu(cpu) { +=09=09struct blk_mq_hw_ctx *h; + +=09=09if (cpu =3D=3D this_cpu) +=09=09=09continue; + +=09=09h =3D blk_mq_map_queue_type(hctx->queue, hctx->type, cpu); +=09=09if (h !=3D hctx) +=09=09=09continue; + +=09=09if (cpumask_test_cpu(cpu, hk_mask)) +=09=09=09return true; + +=09=09if (fallback_isolated_cpu =3D=3D -1) +=09=09=09fallback_isolated_cpu =3D cpu; +=09} + +=09if (fallback_isolated_cpu !=3D -1) { +=09=09pr_warn("blk-mq: cannot offline CPU %u: online isolated CPU %d is st= ill mapped to hctx%u\n", +=09=09=09this_cpu, fallback_isolated_cpu, hctx->queue_num); +=09=09return false; +=09} + +=09return true; +} + static bool blk_mq_hctx_has_online_cpu(struct blk_mq_hw_ctx *hctx, =09=09unsigned int this_cpu) { @@ -3758,6 +3828,11 @@ static int blk_mq_hctx_notify_offline(unsigned int c= pu, struct hlist_node *node) =09=09=09struct blk_mq_hw_ctx, cpuhp_online); =09int ret =3D 0; =20 +=09if (housekeeping_enabled(HK_TYPE_MANAGED_IRQ)) { +=09=09if (!blk_mq_hctx_can_offline_hk_cpu(hctx, cpu)) +=09=09=09return -EINVAL; +=09} + =09if (!hctx->nr_ctx || blk_mq_hctx_has_online_cpu(hctx, cpu)) =09=09return 0; =20 @@ -3813,13 +3888,52 @@ static bool blk_mq_cpu_mapped_to_hctx(unsigned int = cpu, =09return mapped_hctx =3D=3D hctx; } =20 +/** + * blk_mq_hctx_has_online_hk_cpu - Check if @hctx has an online housekeepi= ng CPU + * @hctx:=09Hardware queue context being evaluated + * + * Determine whether at least one online HK_TYPE_MANAGED_IRQ housekeeping = CPU + * is mapped to @hctx. + * + * Return: true if an online housekeeping CPU is mapped to @hctx, false + * otherwise. + */ +static bool blk_mq_hctx_has_online_hk_cpu(struct blk_mq_hw_ctx *hctx) +{ +=09const struct cpumask *hk_mask =3D +=09=09housekeeping_cpumask(HK_TYPE_MANAGED_IRQ); +=09int cpu; + +=09for_each_cpu_and(cpu, cpu_online_mask, hk_mask) { +=09=09if (blk_mq_cpu_mapped_to_hctx(cpu, hctx)) +=09=09=09return true; +=09} + +=09return false; +} + static int blk_mq_hctx_notify_online(unsigned int cpu, struct hlist_node *= node) { =09struct blk_mq_hw_ctx *hctx =3D hlist_entry_safe(node, =09=09=09struct blk_mq_hw_ctx, cpuhp_online); =20 -=09if (blk_mq_cpu_mapped_to_hctx(cpu, hctx)) -=09=09clear_bit(BLK_MQ_S_INACTIVE, &hctx->state); +=09if (!blk_mq_cpu_mapped_to_hctx(cpu, hctx)) +=09=09return 0; + +=09if (housekeeping_enabled(HK_TYPE_MANAGED_IRQ) && +=09 !cpumask_test_cpu(cpu, housekeeping_cpumask(HK_TYPE_MANAGED_IRQ))) = { +=09=09if (cpuhp_tasks_frozen || system_state > SYSTEM_RUNNING) +=09=09=09return 0; + +=09=09if (!blk_mq_hctx_has_online_hk_cpu(hctx)) { +=09=09=09pr_warn("blk-mq: cannot online isolated CPU %u: hctx%u has no onl= ine housekeeping CPU\n", +=09=09=09=09cpu, hctx->queue_num); +=09=09=09return -EINVAL; +=09=09} +=09=09return 0; +=09} + +=09clear_bit(BLK_MQ_S_INACTIVE, &hctx->state); =09return 0; } =20 --=20 2.55.0