Re: [PATCH v15 5/8] blk-mq: use hk cpus only when isolcpus=io_queue is enabled
Aaron Tomlin <[email protected]> Wed, 5 Aug 2026 15:01:19 -0400
| Newsgroups | org.kernel.vger.linux-block,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <j4vezfte2lairuxebayen2meqyqbwl33vv353gsgh4bfr42w7j@szhqn4zqxpnx> |
On Tue, Jul 21, 2026 at 12:28:04PM +0200, Marco Crivellari wrote: > Hi, > > On Fri, May 22, 2026 at 1:30 AM Aaron Tomlin <[email protected]> wrote: > > + void blk_mq_map_queues(struct blk_mq_queue_map *qmap) > > [..] > > + /* > > + * Snapshot online CPUs to prevent TOCTOU races between the > > + * mapping phase and the validation phase. > > + */ > > + cpumask_copy(online_mask, cpu_online_mask); > > I'm wondering: should this code be protected somehow, maybe directly > by the caller (eg w/ cpus_read_lock()) to avoid a CPU going offline eg > after the copy? > This invalidates the copy because a CPU set there might have gone > offline, and the blk code would then still use that CPU. > > Does that make sense or it is not the case? > > Thanks! Hi Marco, Thank you for reviewing the patch and raising this point! Yes, taking a lockless snapshot via cpumask_copy(online_mask, cpu_online_mask) introduces a TOCTOU race, as a CPU could go offline immediately after the copy, leaving online_mask stale during validation. Rather than introducing cpus_read_lock() into block/ to protect a dynamic cpu_online_mask sample, a cleaner solution is to align blk_mq_map_queues() with existing blk-mq architectural patterns. 1. Refactor blk_mq_map_queues() to build mappings using the static housekeeping mask intersected with cpu_present_mask (or cpu_possible_mask), removing the dynamic cpu_online_mask snapshot and blk_mq_validate() check altogether 2. Rely on blk_mq_hctx_notify_offline()—introduced in patch 4/8 of this series—to enforce runtime hotplug safety. The function blk_mq_hctx_notify_offline() already runs under cpus_write_lock() during CPU hotplug and explicitly prevents offlining the final housekeeping CPU serving an active isolated CPU Kind regards, -- Aaron Tomlin
signature.asc
(application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEeQaE6/qKljiNHm6b4t6WWBnMd9YFAmpziHoACgkQ4t6WWBnM d9YSrxAAtLsWXYYMYYOQMRFOJKQ9y0ktzKASBIIIUbZ1wDxwJdzK3vg6HXYxHbRn TR8++VuJulqfQZ9xu0ecvUIUhSzPzAB+Y636H/w9VjREtU4cHm7TzUsAWoCUtv7S /T3GbTAjT+tXBrVweT4BNMej08O6N0BMDbIxRwRTBMsg+0UVrQSR9Xuk99z/usyU i4ZAAnkbGVxuOu2bc3O6bwui9DP+fg3FL4TqCcNKHq57UFvnNy52YfGgvLaD5zuI CGQuVQrZzkOKlaBD9DkrAp8+59eNzoFHaAu6TBBqk1nujnwWuNW8cxAdRDOMWZcw UjIPpQF8BAkqG+z3bVA+rX57Q/qkCN/S3xNE9k6LeXW0BZpin3SEDiCWC9fT2tVb kE9XnmXuAatYMrd2W9Ou6b1NeZjnGHw5jS2yi9/b3TjBknrko7njXmAIBe3drF5V YwIgymbEveh4aBRGoBmfDpLej6cDbuiZSKb1wCH+Y7gTHo7Z8uaiSKjGi2AMau7O jw9epoFrjsjHbetbwtc8r3jIkh9LmxxHmus8u9qaZS4ONkwGYwAFHy5qci8pN1ci LtSds+QIJOOPT/JVzw8qFisKiLxaiEgPdg8QYagHxEk48xLv5VFm3dqF4wSXP4hi LXM3r3E+Rp+AY0aY5KUDLgatOmDwcemQSOGpjSDAmjyPyl944Fs= =AUdu -----END PGP SIGNATURE-----