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=1796096511; b=1sGOx590uQmivQacnpzU5stDu0j5Je7EEANVXplXwOHAHlw1zeRGCzARLDU4sBEW5h2S jrpuqAwLT4gCivXcL+tYoCm7AftQAKDoGjt3lu0Nkbv7WhHhdWTQQN2dWiF1k4iwj7IgN cFv7jLwrpsplDunKsBiv/DnaIsmTgKQSRqZhhbWr0H+ZuREVFNiPb86gwBAefCDweUcjR QfoIYTubIJottCEGIj78gPeFidlQDF+fbf+INBERhIC6a+ZTR7O3lwhrj6plOYNgPQWKv AuVS4xj0LdUAD8o/0OsmUK8dW+GTqbxcEvGTCOHqTfuAgBpE7R3TRzdA9j9PBC8f74A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796096511; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=jWU85q4P+eWhblogYZT3fQM0ObA/Vin+toKsy9aJOLM=; b=q9ox4qP09/zUK9t6xmzn8D8cW9+vlC2JLEOgtaLNKtYxP6koOVLNTtFm6qZW/meNfJX2 ltnWwAc3ZrgV/563TufBPrtmIHzItkJxpGdOEFHzwIwvzxjcM7qnMbej41CiEbuqvwXjv +nQKGIwiLW0BwJJr95rzgIQ32MQPEjPRmLwUAD2GO4Sl1md2QSOOXY3g5se/S73/ZI/5s AtqMUCQjEPdgHqhfi3IBLHbpOWQOGO5gKzC8fxlk4Z5/QGdH1UZLLKFl9tjxZbFmWb25Y B8goZbuNhf+EhjuKvFEc42FZNDtfkdPXBK9GTjvY+48+wZP1LYmuux6ZENypZJZjMEQ== 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="cvf/ljam"; 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 2D77F606A331; Tue, 1 Dec 2026 03:41:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=cvf/ljam Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6ADB1F00919; Tue, 1 Dec 2026 03:41:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796096511; bh=jWU85q4P+eWhblogYZT3fQM0ObA/Vin+toKsy9aJOLM=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=cvf/ljamnK+QSmhFtXrUUUgKgVXO6D1fpF6Yh8DpNqMIMDUZbrisaPsfoc+SatTcW DhmGdK77P9kXYy2xQS1SY9Y/vPEzpcQgNBicFpENvwPbalNKFWVJ/SrJY8KcremZ9v jJhi4ugNIGSduMXKMEtdCDLjIUWT+x04uLw8wnStfeacIRKm89gfX4R+iFpd30juC9 +wODcXrlnIyulpHk379sokBcdyVCREvfr+aZa4yFthPYDT03F70gLucI/drz/ENWiW DoVPoNvzQ3jAmiJrYfRW+FUzaWN7FcCUyg7jzFDztfPzfmK2j+uMtaTo7uLoUAtGwk ps6D37DiqfTHQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [RFC PATCH 05/10] genirq: Reapply unmanaged IRQ affinity on isolation changes Reply-To: sashiko-reviews@lists.linux.dev To: "Kris Pan" Cc: linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, linux-rt-devel@lists.linux.dev, linux-kernel@vger.kernel.org In-Reply-To: <20261130033709.2704805-6-kris.pan@intel.com> References: <20261130033709.2704805-1-kris.pan@intel.com> <20261130033709.2704805-6-kris.pan@intel.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 03:41:50 +0000 X-Mailing-List: linux-pci@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: - [Medium] genirq: trapped auto-placed IRQ not moved in irq_reapply_affinity() - [Low] genirq: dead and inverted trapped checks in irq_isolation_needs_reapply() -- commit 14a3c1ca3828631268f1df40b6be7e180646bfa2 Author: Kris Pan genirq: Reapply unmanaged IRQ affinity on isolation changes This commit tracks changes to the runtime-isolated CPU set and walks active unmanaged interrupt descriptors to reapply their requested affinity masks w= hen affected by an isolation update. > diff --git a/kernel/irq/isolation.c b/kernel/irq/isolation.c > index af7244ce181a4..4ff45da90f909 100644 > --- a/kernel/irq/isolation.c > +++ b/kernel/irq/isolation.c [ ... ] > @@ -221,3 +239,248 @@ bool irq_isolation_widen_mask_full(struct irq_desc = *desc, > return !cpumask_empty(out) && !cpumask_subset(out, mask); > } > =20 > +/* > + * Return true when @changed contains a CPU which left a runtime-isolated > + * partition and is part of @affinity. Such a CPU was filtered out befo= re > + * and is a valid target again. > + * > + * Must be called under RCU read lock. > + */ > +static bool irq_reapply_restores_target(const struct cpumask *changed, > + const struct cpumask *affinity) > +{ > + unsigned int cpu; > + > + for_each_cpu_and(cpu, changed, affinity) { > + if (!housekeeping_runtime_isolated_cpu(cpu)) > + return true; > + } > + > + return false; > +} > + > +/** > + * irq_isolation_needs_reapply - Does @changed affect this interrupt? > + * @desc: Interrupt descriptor, desc->lock held > + * @changed: Old/current difference of the runtime-isolated set > + * > + * A change may isolate a CPU the interrupt is running on, take a CPU out > + * of the requested mask, return a CPU to it, move the programmed mask, = or > + * leave an emergency fallback outside the request while isolation is > + * going away. Only the interrupts where one of those applies have to be > + * re-applied; everything else keeps its programming untouched. A CPU > + * which enters isolation while it sits in the request changes the policy > + * mask even when the chip already targets another member, so a register= ed > + * notifier has to run and the reverse map has to drop it. An automatic > + * placement which sits outside its request is in the emergency fallback; > + * its mask follows the housekeeping set, so every change reaches it. > + * > + * Returns: true when the interrupt has to be re-applied. > + */ > +bool irq_isolation_needs_reapply(struct irq_desc *desc, > + const struct cpumask *changed) > +{ > + struct irq_data *data =3D &desc->irq_data; > + const struct cpumask *eff, *affinity; > + bool restored, trapped =3D false; > + bool unaffected, needs_restore, notify_changed; > + > + lockdep_assert_held(&desc->lock); > + WARN_ON_ONCE(!changed); > + > + eff =3D irq_data_get_effective_affinity_mask(data); > + affinity =3D desc->irq_common_data.affinity; > + > + rcu_read_lock(); > + > + /* > + * An automatic placement may be stuck on an isolated CPU, or > + * parked outside its request after the isolation went away. > + * > + * While isolation is active, an automatic placement which sits > + * outside its request is in the emergency fallback: its programmed > + * mask is derived from the housekeeping set, not from the request, > + * so every isolation change can change it. Converge it even when > + * the change does not touch the current CPU. > + */ > + if (irq_affinity_is_auto(desc)) { > + if (irq_isolation_active()) > + trapped =3D cpumask_empty(eff) || > + housekeeping_runtime_isolated_intersects(eff) || > + (!cpumask_empty(eff) && > + !cpumask_intersects(eff, affinity)); > + else > + trapped =3D !cpumask_empty(eff) && > + !cpumask_intersects(eff, affinity); > + } > + > + /* > + * A CPU which left a runtime-isolated partition is a valid target > + * again. Hand the full requested mask to the irqchip again even > + * when the current effective mask still intersects it, so a chip > + * which can place the interrupt on another target includes the > + * returning CPU, and so that the notifier and the IRQ threads see > + * the restored request. The request itself is never changed. > + */ > + restored =3D irq_reapply_restores_target(changed, affinity); > + > + /* > + * A CPU which enters isolation changes the policy mask even if the > + * chip is not delivering on it: the request loses a target, so a > + * consumer which follows the programmed mask has to be told. > + * Only the notifier consumer needs the update, and only it gets > + * the chip reprogrammed; an interrupt without a notifier keeps its > + * current target and does not pay for a hardware write. While a > + * move is queued, the pending mask carries the newest request and > + * is the mask the notifier reports. > + */ > + notify_changed =3D desc->affinity_notify && > + (cpumask_intersects(changed, affinity) || > + (irq_move_pending(data) && > + cpumask_intersects(changed, > + irq_desc_get_pending_mask(desc)))); > + > + rcu_read_unlock(); > + > + /* > + * A CPU which just left a runtime-isolated partition must pull back > + * an interrupt that was displaced away from it, even while other > + * partitions remain active. > + */ > + if (cpumask_intersects(changed, affinity) && > + !cpumask_intersects(eff, affinity)) > + trapped =3D true; > + > + /* > + * An empty effective mask means the chip does not report its > + * programming; treat the programmed placement as unaffected here > + * and let @trapped, @restored and @notify_changed decide. A > + * change which does not touch the effective CPU and does not > + * change the request leaves the chip alone. > + */ > + unaffected =3D cpumask_empty(eff) || !cpumask_intersects(changed, eff); [Severity: Low] Are the two trapped assignments in irq_isolation_needs_reapply() doing what their comments describe? In the irq_affinity_is_auto(desc) block, starting the OR chain with cpumask_empty(eff) makes the later !cpumask_empty(eff) check dead code and marks every automatic interrupt as trapped on chips that do not report effective affinity, which conflicts with the comment on unaffected below. In the second trapped check: if (cpumask_intersects(changed, affinity) && !cpumask_intersects(eff, affinity)) trapped =3D true; any CPU in changed & affinity that left isolation already sets restored =3D= true via irq_reapply_restores_target(changed, affinity). This check therefore o= nly changes the result when every CPU in changed & affinity entered isolation, = and because it also omits !cpumask_empty(eff), it triggers a reapply for explic= it interrupts without a notifier when eff is empty or was previously displaced outside affinity. > diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c > index 25f42256aeabf..76c8cb679f4cc 100644 > --- a/kernel/irq/manage.c > +++ b/kernel/irq/manage.c > @@ -354,6 +354,66 @@ static int irq_try_set_affinity(struct irq_data *dat= a, > return ret; > } > =20 > +#ifdef CONFIG_CPU_ISOLATION > +/* > + * Reapply the requested affinity after a global isolation change. > + * Does not set IRQD_AFFINITY_SET. > + */ > +void irq_reapply_affinity(struct irq_desc *desc, const struct cpumask *c= hanged) > +{ > + struct irq_chip *chip =3D irq_desc_get_chip(desc); > + struct irq_data *data =3D &desc->irq_data; > + > + lockdep_assert_held(&desc->lock); > + > + if (!chip || !chip->irq_set_affinity) > + return; > + if (!irq_isolation_can_filter(data)) > + return; > + if (irqd_affinity_is_managed(data)) > + return; > + if (!irqd_can_balance(data)) > + return; > + if (!irqd_is_activated(data)) > + return; > + > + /* > + * The caller holds desc->lock, so the query sees a stable request > + * and effective mask. Skip interrupts which cannot be affected by > + * the changed set; the pre-check in the caller is only advisory > + * and avoids taking desc->lock for clearly inactive descriptors. > + */ > + if (changed && !irq_isolation_needs_reapply(desc, changed)) > + return; > + > + if (desc->istate & IRQS_SUSPENDED) > + return; > + > + if (irq_can_move_pcntxt(data)) { > +#ifdef CONFIG_GENERIC_PENDING_IRQ > + if (irqd_is_setaffinity_pending(data)) > + goto pending; > +#endif > + irq_try_set_affinity(data, desc->irq_common_data.affinity, > + false); > + return; > + } [Severity: Medium] Can an automatic interrupt that was redirected to a fallback housekeeping C= PU remain trapped on that CPU when the fallback CPU is later isolated? If all online CPUs in desc->irq_common_data.affinity (say CPU 2) are isolat= ed, irq_isolation_select_mask() redirects the effective affinity to a fallback housekeeping CPU (say CPU 0) while keeping desc->irq_common_data.affinity as {CPU 2}. If CPU 2 is then taken offline, migrate_one_irq() sees that the effective mask {CPU 0} is still online and leaves affinity untouched. When CPU 2 leaves the isolated set and CPU 0 enters isolation, irq_isolation_needs_reapply() marks the interrupt trapped and irq_reapply_affinity() calls irq_try_set_affinity() with {CPU 2}, but irq_isolation_select_mask() returns early because {CPU 2} no longer interse= cts the runtime-isolated mask: kernel/irq/isolation.c:irq_isolation_select_mask() { ... housekeeping_runtime_isolated(out); cpumask_andnot(out, src, out); if (cpumask_equal(out, src)) { rcu_read_unlock(); return false; } auto_placed =3D irq_affinity_is_auto(irq_data_to_desc(data)); if (!cpumask_intersects(out, cpu_online_mask) && auto_placed) irq_isolation_fallback_mask(data, src, out); ... } irq_do_set_affinity() then intersects {CPU 2} with cpu_online_mask and fails with -EINVAL (or skips the -ENOSPC widening path because prog_mask =3D=3D m= ask when affinity is online but out of vectors), leaving the interrupt programmed on= the newly isolated CPU 0. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261130033709.2704= 805-1-kris.pan@intel.com?part=3D5