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=1795937257; b=QQg/q1wATrifGERuYa5bqWTXndf1QK8Qul3ayoZ8d3anhgsBcXBjbR6IfdcRidEHazvi NhQOgovcJdmD2qcW6IPKSy1ztKfLtXEookzUjc70gftVdsrxg/w0775UhsL3XVwh6zUuC giaWIDc5h5l/QKhY/kDMu2Jj4UxeP2OLXXGDK0qYRegua3DTBQEnWs7PZF0t9cJrcs/Bp USp1dm7t3ZfB/8ZPYSBRSnk42lTRVKcfc4fgnZbZx2Wufarr/76fnqxARAnL7SY2GZARF dGU0zH25N3GVmy56NWXG7ZA1QwYny9pi4ivqg9qBe41U893CkrDrilzahpq8QERZkcg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795937257; 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=LjK1KhZN1bG5D7o/KKKDbvrjZrBqfPJ0FBJZhhl0ndw=; b=5GbR3wqfg94SScIJRLHbxjKYF8rbNzPAJD7em1M/oLWkpipSBxfGCPAVg9E/RDpshIGv Vd1V9xUWtSWFTtMDuIXTglQbRftu5cs8iUwCLustJor+slwmzdiaw2Vs/hU5qBUq4QPsF FhIrS0gql4liZbJhUxgix45FgxC+AS8vI9V4SdkNfCIihAlfLzy7Y3Uj4zQ3RI2ulc7Jo kV8w8640oEzijaiYaNGlZpnQOqTXc5sp2LdRkfbjuQ8yyOFQcs6QlH3PZhbYXHeQQaDjt k6Iall2oNQscAUFAUoLnAM0lq8/NjmoN0fwrt/yakw0EeBia2dVyd7zYk2Z86STuXVA== 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=BNvxzDt8; dkim=pass header.d=purelymail.com header.i=@purelymail.com header.a=rsa-sha256 header.s=purelymail3 header.b=uMdcYXWA; 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 483FB606A33D for ; Sun, 29 Nov 2026 07:27:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 483FB606A33D 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=BNvxzDt8; dkim=pass (2048-bit key, unprotected) header.d=purelymail.com header.i=@purelymail.com header.a=rsa-sha256 header.s=purelymail3 header.b=uMdcYXWA DKIM-Signature: a=rsa-sha256; b=BNvxzDt8SKdvvIEm+FVU3XhM6sBOiiza0luFJvHJvJPNIro3NYHU7u2cXM2Z7OO7e2NJeUJD9lXYJxtVbAGI6YrrU2rs2i2G8ACm0IIEIlK8egqaUYWmBlUUA3bSI2Wynt26cVuayUsfBLq4VgVfzoLeYIVWJMpf6ih8WKDfp+iMQxnnIR469ELo4rUsGU/zpVk1N6peIL7WLQLrG2DIYv4kwM2XludMavtqWHhZCkse0WYShBI8T7JzKxJR4vLb0SRJvs35WypOx5nxcQX/4IRWnI+pU0GB3141J5Nst8yHL7+qR6OiW169bCrmZMsJPfrniqXTBj5Z46cI8mxUjQ==; s=purelymail3; d=atomlin.com; v=1; bh=HIAfMmdsXmagVjlpb3AdC2YOtIBP56szosUTIRoRBp0=; h=Received:From:To:Subject:Date:Message-ID; DKIM-Signature: a=rsa-sha256; b=uMdcYXWASWb3PLiTjXc89Y/uPgze+z+OmjriEW1PJIGJNoPMbZXbmhK1MP+LSoIGN95N/AZg8pCct59RpsLLsip0UFbjw7nZgOYIbxWUNhVngAaNMw6lN4X76naTPKPyZBud1m/d2K+SZ5uhO7AcLxmGSwy8fAA4FTRcMwFXv4Vj/Duh2I2jkvMYSXI+stT0Yeur1NdmX8X9n4QtQJzG/LaGaW9z9RRc7RIuAVJLdTbODjDL+rgFXO7WQg03mcjse6SlAYn9eBYoIK0XGkvdv4efX/rU2cHmW8aii/ua3ip3OlrxkvI5gOooEb8sFQHK3vbuvVA1vJsRkpUksfo35Q==; s=purelymail3; d=purelymail.com; v=1; bh=HIAfMmdsXmagVjlpb3AdC2YOtIBP56szosUTIRoRBp0=; h=Feedback-ID:Received:From:To:Subject:Date:Message-ID; Feedback-ID: 1802931:67223:null:purelymail X-Pm-Original-To: linux-doc@vger.kernel.org Authentication-Results: purelymail.com; auth=pass Received: by smtp.purelymail.com (Purelymail SMTP) with ESMTPSA id 1657349675; (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Sun, 29 Nov 2026 07:26:13 +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 v17 06/10] blk-mq: prevent offlining hk CPUs with associated online isolated CPUs Date: Sun, 29 Nov 2026 02:26:06 -0500 Message-ID: <20261129072612.257915-1-atomlin@atomlin.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261129045436.255364-1-atomlin@atomlin.com> References: <20261129045436.255364-1-atomlin@atomlin.com> X-Mailing-List: linux-doc@vger.kernel.org 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 isolated CPUs. Signed-off-by: Daniel Wagner Reviewed-by: Hannes Reinecke Tested-by: Ionut Nechita Co-developed-by: Aaron Tomlin Signed-off-by: Aaron Tomlin --- block/blk-mq.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/block/blk-mq.c b/block/blk-mq.c index 54ccfc43c27c..57afd317bb4f 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 and hibernation are exempted via + * cpuhp_tasks_frozen. + * + * 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 or hibernation, tasks are frozen and all +=09 * CPUs are being taken offline. Allow offlining to proceed so +=09 * suspend is not aborted. +=09 */ +=09if (cpuhp_tasks_frozen) +=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 --=20 2.55.0