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=1796096512; b=q2lfd7daJ478ddWq5zeLNzf5Lml2LKkNUYYLjDEvPOM/MyqZknyeSix/So4PD7zMZxS8 /2s7/R8FfSOx6HglpHgoWLV2BR8C36DfU7Se8s3XErHOGiW3UGX+gDaey9OEOr0FgXvNs XlIMxJK77qWbhuDkSnlz531QDL+SwlzICM41Mp916nnJxadNQDOlvkvQ3iodyOerCn92H bnQnNiDcAJWe1apsP8wPXNWt/fMTsNWFAnLMUY5V7dAuOO8Mc6a+GZ5r9E4tzaU0FZK8v 7vLvoXOLJP62p+6VetRJAG5BnwBroY0M58HnqJZpsiY4gmXQqMvfeLrht1QjA4EmfPA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796096512; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=/0UYDKaUDDpBF0I1Kyy0ol3j8bXUbIhYJHXjfQ6JKKY=; b=bKKNwmBKu3IOl63YtHdI4haMIWNXAnuL00/UT+M1A3IzqeQ1KxdF4hV6qDTvqryMwTu5 TiP/l22ZCzmfc2vT4pPnxtc16Wb6TgmsCMqbWPA5pmQwQT3hQh8IZB0VeiUm/eDxfuqyf JkSiJwsncCuiWY5ca18ETp/maGfCXQKg6/CpL2U01dUUiA/k7t7VlPiqejGHczx1Ow0lE suQ3zLEdOgZWMnF/g+rdM+GVyIoqaqyQt+09PUKLyUbeELjAAfNCDF38BFVWy2TOxcQlI 8sdYLWCnlCErHgOGHSl7UlNlUapdwsVvmXtRb6ISYzb9Ka20kt115Gjii2ItvdLP0bg== 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=G6sJEcGr; 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 3BDC8606A686; 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=G6sJEcGr Received: by smtp.kernel.org (Postfix) with ESMTPSA id 887491F008A0; Tue, 1 Dec 2026 03:41:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796096511; bh=/0UYDKaUDDpBF0I1Kyy0ol3j8bXUbIhYJHXjfQ6JKKY=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=G6sJEcGrOE6uUHMHRO+/acm3dddY93Tb5AK2Ev/4yLQTBdLV/b7jxNKMwLNodOqBz VrFmjd7d6Jd8tPdl5JVtTRKwg23qs6ZPQ6rpk8cV6GwApLIdHnBq0bfX/vu/iBPrPu 6SI3JlY3IOPnu2HG9fy7MxWGRfyWOzTCC7musBX5tJg+dtAvDE3dR2a4zOOCTwOLvw UbGskfXz+TW6QbGGhhEQtpTlP31ug8BZ9DIVk/bA8Y68ajkfBE4n1ob0n6MiYG9JWg qjeLxsK2OZBCmM3FsIcy0D14RTz0UcjjANj8JPsjlkBu93fcwppfxdujSP3FGxVqH1 EVd5f3xPK2bfw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [RFC PATCH 06/10] genirq: Align affinity notifiers and IRQ threads with isolation 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-7-kris.pan@intel.com> References: <20261130033709.2704805-1-kris.pan@intel.com> <20261130033709.2704805-7-kris.pan@intel.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 03:41:51 +0000 X-Mailing-List: linux-hyperv@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 6 potential issues to consider: - [Medium] genirq: missed thread affinity update in irq_isolation_needs_reapply() - [Medium] genirq: stale thread and notifier affinity in irq_move_masked_irq() - [Medium] genirq: broken fallback in irq_thread_check_affinity() on false filter - [Medium] genirq: redundant affinity notifier work in irq_move_masked_irq() - [Medium] genirq: unconditional IRQ thread wakeups on pending affinity moves - [Medium] genirq: programmed affinity mismatch after -ENOSPC in irq_do_set_affinity() -- commit 1aff5a02a459cf6c403f218b2e8e9313e0d75920 Author: Kris Pan genirq: Align affinity notifiers and IRQ threads with isolation This commit adds irq_copy_programmed_affinity() for consumers that need the runtime-isolation-filtered affinity mask, keeps irq_affinity_notify() reporting the requested mask, and updates IRQ thread affinity when a move is pending or trapped on a runtime-isolated CPU. > diff --git a/kernel/irq/isolation.c b/kernel/irq/isolation.c > index 4ff45da90f909..6307b7508057e 100644 > --- a/kernel/irq/isolation.c > +++ b/kernel/irq/isolation.c > @@ -173,6 +173,46 @@ bool irq_isolation_select_mask(struct irq_data *data, > return true; > } > =20 > +/** > + * irq_copy_programmed_affinity - Snapshot the mask the chip is asked to= use > + * @irq: Interrupt number > + * @mask: Storage for the snapshot > + * > + * The affinity notifier reports the requested mask. Runtime IRQ isolat= ion > + * may program a different mask for a filterable chip: the request with = the > + * runtime-isolated CPUs removed, or an automatic relocation when the re= quest > + * lost its last online target. A consumer which spreads work over seve= ral > + * CPUs, such as a reverse map, has to follow that mask. The effective > + * affinity is a single target on chips which only deliver to one CPU an= d is > + * the wrong input for a multi-CPU map. > + * > + * Returns: true when the policy changed the requested mask. > + * Must not be called with desc->lock held. > + */ > +bool irq_copy_programmed_affinity(unsigned int irq, struct cpumask *mask) > +{ > + struct irq_desc *desc =3D irq_to_desc(irq); > + const struct cpumask *req; > + > + if (!desc) > + return false; > + > + guard(raw_spinlock_irqsave)(&desc->lock); > + /* > + * A deferred move keeps the newest request in the pending mask and > + * the notifier reports that mask; the descriptor affinity is only > + * updated when the move completes. > + */ > + if (irq_move_pending(&desc->irq_data)) > + req =3D irq_desc_get_pending_mask(desc); > + else > + req =3D desc->irq_common_data.affinity; > + if (cpumask_empty(req)) > + return false; > + > + return irq_isolation_select_mask(&desc->irq_data, req, mask); > +} [Severity: Medium] Can irq_copy_programmed_affinity() return a mask that excludes the CPU actually programmed when irq_do_set_affinity() falls back on -ENOSPC? When chip->irq_set_affinity() returns -ENOSPC on the mask produced by irq_isolation_select_mask(), irq_do_set_affinity() retries with irq_isolation_widen_mask(), irq_isolation_widen_mask_full(), and finally the unfiltered requested mask. If one of those retries succeeds, irq_copy_programmed_affinity() still returns the narrower irq_isolation_select_mask() result that failed vector allocation. In the same situation, if irq_do_set_affinity() fell back to a runtime-isolated CPU in the request, irq_thread_check_affinity() sees trapped =3D=3D true and uses irq_isolation_select_mask() to move the IRQ thread onto the non-isolated CPUs where vector allocation failed, away from the effective CPU where the interrupt fires. > diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c > index 76c8cb679f4cc..6e6fdae14bb07 100644 > --- a/kernel/irq/manage.c > +++ b/kernel/irq/manage.c > @@ -390,12 +390,25 @@ void irq_reapply_affinity(struct irq_desc *desc, co= nst struct cpumask *changed) > return; > =20 > if (irq_can_move_pcntxt(data)) { > + int ret; > + > #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); > + ret =3D irq_try_set_affinity(data, > + desc->irq_common_data.affinity, > + false); > + /* > + * irq_try_set_affinity() turns -EBUSY into a pending move > + * and returns success; mark the IRQ threads like the > + * pending branch below, so they can escape while the > + * hardware still points at the isolated CPU. > + */ > + if (!ret && irqd_is_setaffinity_pending(data)) > + irq_set_thread_affinity(desc); > + if (!ret && desc->affinity_notify) > + irq_affinity_schedule_notify_work(desc); > return; > } > =20 > @@ -410,6 +423,20 @@ void irq_reapply_affinity(struct irq_desc *desc, con= st struct cpumask *changed) > irqd_set_move_pending(data); > irq_copy_pending(desc, desc->irq_common_data.affinity); > } > + /* > + * The hardware move is deferred, but the IRQ threads must not run > + * a handler on a CPU which is being isolated while the move is > + * pending. Mark them so that they re-evaluate their affinity. > + */ > + irq_set_thread_affinity(desc); [Severity: Medium] Can irq_isolation_needs_reapply() cause irq_reapply_affinity() to return early and skip irq_set_thread_affinity(desc) for threaded IRQs without an affinity notifier? kernel/irq/isolation.c:irq_isolation_needs_reapply() { ... if (irq_affinity_is_auto(desc)) { if (irq_isolation_active()) trapped =3D cpumask_empty(eff) || housekeeping_runtime_isolated_intersects(eff) || ... } restored =3D irq_reapply_restores_target(changed, affinity); notify_changed =3D desc->affinity_notify && (cpumask_intersects(changed, affinity) || (irq_move_pending(data) && cpumask_intersects(changed, irq_desc_get_pending_mask(desc)))); ... } In irq_thread_check_affinity(), whenever the effective mask is on a runtime-isolated CPU (for example CPU 0), the IRQ thread escapes to the filtered target in desc->pending_mask or desc->irq_common_data.affinity (say {CPU 1, CPU 2}), even when the affinity was set explicitly (!irq_affinity_is_auto(desc)) and desc->affinity_notify is NULL. If a later partition change isolates CPU 1 (changed =3D {CPU 1}), irq_isolation_needs_reapply() sees trapped =3D=3D false, restored =3D=3D fa= lse, notify_changed =3D=3D false, and unaffected =3D=3D true (because changed do= es not intersect the old effective CPU 0), so irq_reapply_affinity() returns before calling irq_set_thread_affinity(desc) and leaves the IRQ thread allowed to run on the newly isolated CPU 1. Likewise, because restored only checks desc->irq_common_data.affinity, de-isolating a CPU that is in desc->pending_mask will not update the IRQ thread when desc->affinity_notify is NULL. > @@ -473,6 +500,16 @@ int irq_set_affinity_locked(struct irq_data *data, c= onst struct cpumask *mask, > irq_copy_pending(desc, mask); > } > =20 > + /* > + * A pending move keeps the newest request in the pending mask. > + * Mark the threads so that a handler which is woken on an isolated > + * CPU can escape to it before the move completes; without runtime > + * isolation the upstream behaviour (mark on completion) is kept. > + */ > + if (!ret && irq_isolation_active() && > + irqd_is_setaffinity_pending(data)) > + irq_set_thread_affinity(desc); > + > if (desc->affinity_notify) > irq_affinity_schedule_notify_work(desc); [Severity: Medium] Does calling irq_set_thread_affinity(desc) unconditionally on every pending move in irq_set_affinity_locked() and irq_reapply_affinity() wake the IRQ kthreads even when the effective CPU is not isolated? irq_set_thread_affinity() does not just set IRQTF_AFFINITY; it also calls wake_up_process() on every action thread. When the current effective mask m does not intersect a runtime-isolated CPU (or when irq_isolation_update() just disabled irq_isolation_key before calling irq_isolation_reapply_all()), the woken kthread enters irq_thread_check_affinity(), sees !trapped, and runs a no-op set_cpus_allowed_ptr(current, m), only to be woken again when the pending move completes. [ ... ] > @@ -1187,10 +1229,54 @@ static void irq_thread_check_affinity(struct irq_= desc *desc, struct irqaction *a > } > =20 > scoped_guard(raw_spinlock_irq, &desc->lock) { > + const struct cpumask *target =3D desc->irq_common_data.affinity; > const struct cpumask *m; > + bool pending, trapped; > =20 > m =3D irq_data_get_effective_affinity_mask(&desc->irq_data); > - cpumask_copy(mask, m); > + /* > + * A pending move carries the newest request in the pending > + * mask; the descriptor affinity is only updated when the > + * move completes. Use it as the escape target. > + */ > + pending =3D irq_move_pending(&desc->irq_data); > + if (pending) > + target =3D irq_desc_get_pending_mask(desc); > + /* > + * Keep the upstream single-target convergence while the > + * hardware is not on a runtime-isolated CPU. Only a delayed > + * move which still points there needs the requested mask as > + * the escape target. The static key keeps the common > + * non-isolated case out of RCU and the CPU loop. > + */ > + trapped =3D false; > + if (irq_isolation_active()) { > + rcu_read_lock(); > + trapped =3D cpumask_empty(m) || > + housekeeping_runtime_isolated_intersects(m); > + rcu_read_unlock(); > + } > + if (!trapped) { > + cpumask_copy(mask, m); > + } else if (!irq_isolation_select_mask(&desc->irq_data, target, mask)) { > + /* > + * Nothing had to be filtered. A pending move is the > + * newest request: when its target is already free of > + * runtime-isolated CPUs, the thread must follow it > + * instead of the old effective CPU, or it keeps > + * running on the isolated CPU until the move > + * completes. > + */ > + bool clean =3D false; > + > + if (pending && irq_isolation_can_filter(&desc->irq_data)) { > + rcu_read_lock(); > + clean =3D !housekeeping_runtime_isolated_intersects(target); > + rcu_read_unlock(); > + } > + if (!clean || !cpumask_and(mask, target, cpu_online_mask)) > + cpumask_copy(mask, m); > + } > } > =20 > set_cpus_allowed_ptr(current, mask); [Severity: Medium] What happens in this fallback when the effective affinity mask m is empty or when the IRQ is non-balancing or managed? On a filterable chip where cpumask_empty(m) is true, if target initially contains both an isolated CPU and a housekeeping CPU, trapped is true and irq_isolation_select_mask() narrows the thread to the housekeeping CPU. When that isolated CPU is later de-isolated (or target is updated synchronously to a mask without isolated CPUs), irq_isolation_select_mask() returns false, clean is false because pending is false (or !trapped is taken if the last isolated partition was removed), and mask is copied from the empty mask m. set_cpus_allowed_ptr(current, mask) then fails with -EINVAL, leaving the IRQ thread permanently pinned to the old filtered CPU subset. In addition, the clean check only tests irq_isolation_can_filter(&desc->irq_data) without checking irqd_can_balance(&desc->irq_data) && !irqd_affinity_is_managed(&desc->irq_d= ata) as irq_isolation_select_mask() does, so a pending move on an IRQF_NOBALANCING or managed IRQ whose target has no runtime-isolated CPUs will widen the thread affinity to target & cpu_online_mask instead of keeping m. > diff --git a/kernel/irq/migration.c b/kernel/irq/migration.c > index f2b2929986ffa..39d0e701af52e 100644 > --- a/kernel/irq/migration.c > +++ b/kernel/irq/migration.c > @@ -97,6 +97,16 @@ void irq_move_masked_irq(struct irq_data *idata) > irqd_set_move_pending(data); > return; > } > + /* > + * The notifier queued when the move was requested reports > + * the requested mask, but the mask a consumer follows only > + * changes here. Report the completed move so that the > + * consumer converges on the new target. Without runtime > + * isolation the programmed mask always tracked the request, > + * so keep the upstream single notification. > + */ > + if (!ret && irq_isolation_active() && desc->affinity_notify) > + irq_affinity_schedule_notify_work(desc); > } > cpumask_clear(desc->pending_mask); > } [Severity: Medium] If the deferred move in irq_move_masked_irq() is dropped or fails with an error other than -EBUSY, do the IRQ threads and affinity notifier consumers stay stuck on the discarded pending_mask? When a move is deferred in irq_set_affinity_locked() or irq_reapply_affinity(), the IRQ threads and desc->affinity_notify are immediately updated from desc->pending_mask while desc->irq_common_data.affinity keeps the previous mask. If desc->pending_mask no longer intersects cpu_online_mask by the time irq_move_masked_irq() runs, or if irq_do_set_affinity() fails with an error such as -ENOSPC, irq_move_masked_irq() clears desc->pending_mask without calling irq_set_thread_affinity(desc) or scheduling desc->affinity_notify, leaving both the threads and notifier consumers diverged from desc->irq_common_data.affinity. [Severity: Medium] In the success case (!ret), is scheduling desc->affinity_notify a second time from irq_move_masked_irq() redundant? When the deferred move was queued, irq_set_affinity_locked() or irq_reapply_affinity() already scheduled the notifier, and both irq_affinity_notify() and irq_copy_programmed_affinity() already use desc->pending_mask while irq_move_pending(&desc->irq_data) is true. Once irq_do_set_affinity() copies desc->pending_mask into desc->irq_common_data.affinity and clears IRQD_SETAFFINITY_PENDING, irq_affinity_notify() and irq_copy_programmed_affinity() produce the exact same masks as before, so this schedules duplicate notifier work from hardirq context on every deferred move completion. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261130033709.2704= 805-1-kris.pan@intel.com?part=3D6