From mboxrd@z Thu Jan 1 00:00:00 1970 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=1795939129; b=O3Xsjbp4XZ0Su5ai3FlNeDfGmNw6qVuZRtcFobKp5x/kh0UtatVURMUVIHzAzxw93OYN +8ObNm9bhpZHCQIsqw6avu+hnodfFtwTg5m+wpRHDiSyyUSTSBsY42ptWPyvIK3/OFXuc gyvP3d2B9Zmm0CSeqTAY8/awk7wVkDe0lUZHQ5iirI6Fuq5VnV+jm/enxrlGL3ZcK8C/s YO4v5O+0RqjXTUkWeunBy15ONoGsvCLhIDI47Pq2jEQeYA3zjatXjaFj8ptvdykQDydG9 +f7fwriK9aen0fb9dKwpOU8bmP6K7MF2Y57/1saGfvTDhvXjqvEPK5cXFVx678C05ZQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795939129; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=tShp9QTHsRClrtUWzP39gkq6cQ+Ej55asj5MiZdhiR0=; b=W+qDYgrLtDOQg82rftYOBKh+YsrqPm1/DSAqvffd63j1KRx3NS9+0i9ZQKzopgbFQfTZ RWkyjCpeEnT+HFkomY49bzX8wqb5v6V8gpcyo8Z0Xbv362/XkxZnqEYPODLjstczWr5DT HdmHcRBzHpIAXysHHkoD97x7L/WJnckwflUrDKAXH/acsx1Wzbj+t7775QmXe7plJZQo5 QZdj9KWISe3K7xD5sHfxfVCd7MCRcSfcyTR/dtX8pMCtcAu9uhVwRmp30p1Ge7ymU4yVp 3oPyiSbMz2wu6JLkw+l5e0u7mbG6l8Gns9EsJH04W1JBf/BvewnE9j+oukzT2mX7Dxw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=GsQtHW+R; 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 397F1606A31C; Sun, 29 Nov 2026 07:58:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=GsQtHW+R Received: by smtp.kernel.org (Postfix) with ESMTPSA id BEE241F00897; Sun, 29 Nov 2026 07:58:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795939129; bh=tShp9QTHsRClrtUWzP39gkq6cQ+Ej55asj5MiZdhiR0=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=GsQtHW+R9Ug5oYIrPaxTgV9rlZuTdlujKmu0qjs0vTbTwhBWBriCq3QfYxBJjB9YB kBLB357KohS1+ssm3tcODl1Qro5wB4wQ3acPtVRoCqGdNYO/R8q+PJ8tEu+qftkeDI fum/onAjXl4CHo1swWO0XkDR6TxU9Lg41GbcYzAZAR9xpr3tJhgozaFykmiC3w0ca/ IXXcrzkp7h+Us4I+kV5t2yVYArbt/udcmrCxor9IuDEFG/zuljMNsjqz16exsLm4aJ BMOUATIYwx0foYgY7hN7IGLIgYQwh6aMIXfkDHWVaFRWU1c1xn2jeSfhhJt+1eDQX7 r9Y06jsbqNxKg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v17 05/10] blk-mq: use hk cpus only when isolcpus=managed_irq is enabled Reply-To: sashiko-reviews@lists.linux.dev To: "Aaron Tomlin" Cc: linux-scsi@vger.kernel.org, virtualization@lists.linux.dev, "Michael S. Tsirkin" , "Eugenio Perez" In-Reply-To: <20261129045436.255364-6-atomlin@atomlin.com> References: <20261129045436.255364-1-atomlin@atomlin.com> <20261129045436.255364-6-atomlin@atomlin.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 29 Nov 2026 07:58:48 +0000 X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] blk-mq: offline housekeeping queues marked active in blk_mq_map_queues() - [Low] blk-mq: commit message examples contradict blk_mq_map_queues() behavior -- commit b027119b22c4d4a60567ed849ca88fa491e6c4b3 Author: Daniel Wagner blk-mq: use hk cpus only when isolcpus=3Dmanaged_irq is enabled This commit restricts blk-mq queue counting and CPU-to-hctx mapping to housekeeping CPUs when isolcpus=3Dmanaged_irq is enabled, and distributes remaining isolated CPUs across active hardware queues. [ ... ] > A corner case is when the number of online CPUs and present CPUs > differ and the driver asks for less queues than online CPUs, e.g. > =20 > 8 online CPUs, 16 possible CPUs > =20 > isolcpus=3Dmanaged_irq,2-3,6-7,12-13 > virtio_blk.num_request_queues=3D2 > =20 > Queue mapping: > hctx0: default 0 1 2 3 4 5 6 7 8 12 13 > hctx1: default 9 10 11 14 15 [ ... ] > 1. Coarse queue grouping > =20 > Because the driver requests only 2 queues, the 10 possible > housekeeping CPUs are partitioned into two groups: hctx0 > receives CPUs 0-1, 4-5, and 8, while hctx1 receives CPUs 9-11 > and 14-15. All isolated CPUs (both online cores 2-3, 6-7 and > offline cores 12-13) are mapped to hctx0 to share submission > capacity without allocating excess queues. [ ... ] > Noteworthy is that for the normal/default configuration (without > isolcpus=3D) the mapping will change for systems which have non > hyperthreading CPUs. The main assignment loop will completely rely th= at > group_mask_cpus_evenly to do the right thing. The old code would > distribute the CPUs linearly over the hardware context: > =20 > queue mapping for /dev/nvme0n1 > hctx0: default 0 8 > hctx1: default 1 9 > hctx2: default 2 10 > hctx3: default 3 11 > hctx4: default 4 12 > hctx5: default 5 13 > hctx6: default 6 14 > hctx7: default 7 15 > =20 > The assign each hardware context the map generated by the > group_mask_cpus_evenly function: > =20 > queue mapping for /dev/nvme0n1 > hctx0: default 0 1 > hctx1: default 2 3 > hctx2: default 4 5 > hctx3: default 6 7 > hctx4: default 8 9 > hctx5: default 10 11 > hctx6: default 12 13 > hctx7: default 14 15 [Severity: Low] Do these two examples in the commit message match the actual mapping code? In the first quoted example, both blk_mq_map_queues() and blk_mq_map_hw_queues() mark hctx0 and hctx1 as active in active_hctx because both receive possible housekeeping CPUs from constraint, and the unassigned-CPU loop then spreads isolated CPUs across both queues via find_next_bit_wrap() (mapping CPUs 2, 6, 12 to hctx0 and CPUs 3, 7, 13 to hctx1) rather than placing all isolated CPUs on hctx0. In the second quoted example, blk_mq_map_queues() already used group_cpus_evenly() before this patch; when HK_TYPE_MANAGED_IRQ is disabled, constraint is cpu_possible_mask and group_mask_cpus_evenly() produces the same mapping as the baseline code. > diff --git a/block/blk-mq-cpumap.c b/block/blk-mq-cpumap.c > index 705da074ad6c7..d63c298010540 100644 > --- a/block/blk-mq-cpumap.c > +++ b/block/blk-mq-cpumap.c [ ... ] > @@ -56,23 +77,92 @@ unsigned int blk_mq_num_online_queues(unsigned int ma= x_queues) > void blk_mq_map_queues(struct blk_mq_queue_map *qmap) > { > - const struct cpumask *masks; > + struct cpumask *masks; > + const struct cpumask *constraint; > unsigned int queue, cpu, nr_masks; > + unsigned long *active_hctx; > =20 > - masks =3D group_cpus_evenly(qmap->nr_queues, &nr_masks); > - if (!masks) { > - for_each_possible_cpu(cpu) > - qmap->mq_map[cpu] =3D qmap->queue_offset; > - return; > - } > + active_hctx =3D bitmap_zalloc(qmap->nr_queues, GFP_KERNEL); > + if (!active_hctx) > + goto fallback; > =20 > - for (queue =3D 0; queue < qmap->nr_queues; queue++) { > - for_each_cpu(cpu, &masks[queue % nr_masks]) > + if (housekeeping_enabled(HK_TYPE_MANAGED_IRQ)) > + constraint =3D housekeeping_cpumask(HK_TYPE_MANAGED_IRQ); > + else > + constraint =3D cpu_possible_mask; > + > + /* Map CPUs to the hardware contexts (hctx) */ > + masks =3D group_mask_cpus_evenly(qmap->nr_queues, constraint, &nr_masks= ); > + if (!masks) > + goto free_fallback_hctx; > + > + /* > + * Iterate directly over the generated CPU masks. > + * Calculate the final, highest hardware queue index that maps to this > + * mask. This skips all intermediate overwrites and safely evaluates > + * active_hctx only for queues that survive the mapping. > + */ > + for (unsigned int idx =3D 0; idx < nr_masks; idx++) { > + queue =3D qmap->nr_queues - 1 - > + ((qmap->nr_queues - 1 - idx) % nr_masks); > + > + for_each_cpu(cpu, &masks[idx]) > qmap->mq_map[cpu] =3D qmap->queue_offset + queue; > + > + __set_bit(queue, active_hctx); > } > + > + /* > + * If the active_hctx bitmap is empty, attempting to route unassigned > + * CPUs will map them out-of-bounds. Fall back instead. > + */ > + if (bitmap_empty(active_hctx, qmap->nr_queues)) > + goto free_fallback; > + > + /* Map any unassigned CPU evenly to the hardware contexts (hctx) */ > + queue =3D find_first_bit(active_hctx, qmap->nr_queues); > + for_each_cpu_andnot(cpu, cpu_possible_mask, constraint) { > + qmap->mq_map[cpu] =3D qmap->queue_offset + queue; > + queue =3D find_next_bit_wrap(active_hctx, qmap->nr_queues, queue + 1); > + } [ ... ] > @@ -109,24 +199,82 @@ void blk_mq_map_hw_queues(struct blk_mq_queue_map *= qmap, > + /* Map CPUs to the hardware contexts (hctx) */ > for (queue =3D 0; queue < qmap->nr_queues; queue++) { > - mask =3D dev->bus->irq_get_affinity(dev, queue + offset); > - if (!mask) > - goto fallback; > + const struct cpumask *affinity_mask; > + > + affinity_mask =3D dev->bus->irq_get_affinity(dev, offset + queue); > + if (!affinity_mask) > + goto free_map_software; > =20 > - for_each_cpu(cpu, mask) > + for_each_cpu_and(cpu, affinity_mask, constraint) { > qmap->mq_map[cpu] =3D qmap->queue_offset + queue; > + cpumask_set_cpu(cpu, mask); > + } > + } > + > + /* > + * Evaluate active_hctx after mapping to handle overlapping masks. > + * This ensures queues that were overwritten do not falsely pass valida= tion. > + */ > + for_each_cpu(cpu, mask) { > + queue =3D qmap->mq_map[cpu] - qmap->queue_offset; > + __set_bit(queue, active_hctx); > + } > + > + /* > + * If no assigned CPU matches the constraint, the active_hctx > + * bitmap will be empty. Fall back instead of routing out of bounds. > + */ > + if (bitmap_empty(active_hctx, qmap->nr_queues)) > + goto free_fallback; > + > + /* Map any unassigned CPU evenly to the hardware contexts (hctx) */ > + queue =3D find_first_bit(active_hctx, qmap->nr_queues); > + for_each_cpu_andnot(cpu, cpu_possible_mask, mask) { > + qmap->mq_map[cpu] =3D qmap->queue_offset + queue; > + queue =3D find_next_bit_wrap(active_hctx, qmap->nr_queues, queue + 1); > } [Severity: High] Can blk_mq_map_queues() and blk_mq_map_hw_queues() map online isolated CPUs to a hardware queue whose assigned housekeeping CPUs are all offline? Because housekeeping_cpumask(HK_TYPE_MANAGED_IRQ) includes offline possible housekeeping CPUs, both functions set bits in active_hctx for queues that only have offline housekeeping CPUs (such as hctx1 with offline CPUs 9-11 and 14-15 in the second example of the commit message). The unassigned-CPU loop then routes online isolated CPUs (such as CPUs 3 and 7) to that queue. When all housekeeping CPUs in a queue's managed IRQ affinity mask are offline, __irq_startup_managed() aborts startup and leaves the interrupt in IRQD_MANAGED_SHUTDOWN, while blk_mq_init_hctx() leaves BLK_MQ_S_INACTIVE clear. I/O submitted from the online isolated CPUs mapped to that hctx is then dispatched to a queue with no active completion interrupt, causing I/O hangs. The follow-up commit "blk-mq: prevent offlining hk CPUs with associated online isolated CPUs" only checks runtime CPU hot-unplug in blk_mq_hctx_notify_offline() and does not prevent mapping online isolated CPUs onto queues whose housekeeping CPUs are already offline when queues are mapped. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261129045436.2553= 64-1-atomlin@atomlin.com?part=3D5