From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.19 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796010074; b=uu1yKdkfVK1mlgIGCGNB+XCyH736gvY/TqZX5x5c+54pNlc+zYgxlwpTBQjltzBC6Xl4 e2mmNa9HhFuxWQU7tsqSkqQngLohRTg8rLZdX2t6Rlpj+XZ6pmytYsEVifcCPxXkzcYCg lc+O6bNMfxzRwVe3D/kNUV7nEFzJp/8S4PI5peClR3tjnA68zVkRtVM6g5a+wLbZRxbhu HL7/iQQTtnD7NeBUvrnz4WHorehz8vCb+2MN5yZtgZbqYCk5Te9gHTaGkYohTSz9lm7uM 4Kyo9WV4WRVlppUaOAd5IawD9nf6xKazhDqpnWW6BZfaBmqG7EOV9JPQZlCL/S6fgbg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796010074; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=s+nYyCV3AtMQPK7LTnKJC02Wpdeq68SifFe+yhaQz/8=; b=aEW3W1il4YyJUFhT5gPHB+WFxuXFNGwCOAyIUj970zrslGq3gYcP/YNS9CK/RlitgU7n +9MUd/FQk+cKE9N+/ttRrybchNdOLkdWBFuHpwQ9gQsG0JPR2SU/A0h3qj2UVPXoBMPp1 SpjYv1bRzwJWVqMc6JJ5Vi7x5UnGHD13cE/WepoBFUabW581FvD5M3dwVItYkyk4kv7VQ Y3Z61pHjIv84pftId7s0dpYK5XQ4/ZneFa1r55f84Waacc5WiUYfQba3DLItfJQE+xU4Q Ayn/65NieCeqgLNmLvI/d4ovc12ZtBYrrEBk2rkqTU6Ruw+6yfd/FAD6QiLe7I7BT8Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b="k0G/Ntjt"; arc=none smtp.remote-ip=192.198.163.19 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ACD23606A32C; Mon, 30 Nov 2026 03:41:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org ACD23606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=k0G/Ntjt DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796010074; x=1827546074; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kNLH/bO0WnVxXb8aOkXMFk6D/jiV0aIe99baWqBAbUs=; b=k0G/NtjtkRYg8ndgdkYtqz5wohca67Q3iXIVHesntoA2Tk7RQfWnuKIv tn0zjhHKPuIA13h68GLdKugahOb8WOgB0D8KLtvW8JfoBWgzj5hDHPlup zdvLoMHCtCc62O5PqHLS2Mx1pDrvo8pDyCiPF0XuDM7VhOGBy+wGjiFXa t2TjSh+0KyzEE8+bpPHsbAYws2RvpRngwJa1zYvXjwYM5mQCQC+bO4bzp qaY0SFAxsmEtAvggekAdz91xAqdSAQNQIC29gAbWfXX3w88Fdz2fJzsDN asnhBJ5Auroc1oma8+YpywDsx8AqkAOjZ8twXa08iD40WaPm8cx9MN/nO g==; X-CSE-ConnectionGUID: KR95hH2XQZO22N2tzXmDaw== X-CSE-MsgGUID: 8vFM3fuIS7SOEu0HUCmDHA== X-IronPort-AV: E=McAfee;i="6800,10657,11981"; a="4848350" X-IronPort-AV: E=Sophos;i="6.27,242,1787036400"; d="scan'208";a="4848350" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Nov 2026 19:41:13 -0800 X-CSE-ConnectionGUID: fbn9qGrVQG2SMPKRPUKglg== X-CSE-MsgGUID: qq8jo1n7SoOwnWo/AXQgYg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,242,1787036400"; d="scan'208";a="12951091" Received: from pankris-x299-ud4-pro.bj.intel.com ([10.238.152.122]) by fmviesa005.fm.intel.com with ESMTP; 29 Nov 2026 19:41:04 -0800 From: Kris Pan To: tglx@kernel.org, maz@kernel.org Cc: mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, x86@kernel.org, peterz@infradead.org, frederic@kernel.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, longman@redhat.com, tj@kernel.org, corbet@lwn.net, linux-doc@vger.kernel.org, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, vasant.hegde@amd.com, suravee.suthikulpanit@amd.com, iommu@lists.linux.dev, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, linux-hyperv@vger.kernel.org, bhelgaas@google.com, lpieralisi@kernel.org, linux-pci@vger.kernel.org, steve.wahl@hpe.com, bigeasy@linutronix.de, clrkwllms@kernel.org, linux-rt-devel@lists.linux.dev, radu@rendec.net, linux-kernel@vger.kernel.org, Kris Pan Subject: [RFC PATCH 07/10] genirq: Handle runtime isolation across hotplug and suspend Date: Mon, 30 Nov 2026 11:37:05 +0800 Message-ID: <20261130033709.2704805-8-kris.pan@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261130033709.2704805-1-kris.pan@intel.com> References: <20261130033709.2704805-1-kris.pan@intel.com> X-Mailing-List: linux-hyperv@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit CPU hotplug runs with the IRQ chip masked for interrupts which cannot move in process context, and a suspend must not lose a pending reapply. The CPU offline path keeps the upstream behaviour: an interrupt whose request cannot be satisfied is broken to the online CPUs, and the isolation filter still applies while that emergency mask is programmed. A CPU which comes back re-evaluates an unmanaged interrupt; irq_isolation_restore_affinity() returns true when the returning CPU is part of the request and the interrupt is still parked on an isolated CPU, outside its request after the -ENOSPC fallback, or displaced off the device NUMA node. This also covers isolation which was removed while the interrupt sat outside its requested mask. The CPU-online convergence only runs when runtime isolation was active at least once; a system which never used it keeps the upstream "leave unmanaged interrupts alone" behaviour. A reapply which runs while the interrupt is suspended is remembered in IRQS_ISOLATION_PENDING and replayed from resume_irq() and rearm_wake_irq() once IRQS_SUSPENDED is cleared. The window is real: the cpuset housekeeping work runs on system_dfl_wq, which is events_unbound without WQ_FREEZABLE, so an update queued around the userspace freeze can still execute after dpm_suspend_noirq() has set IRQS_SUSPENDED. The replay is best effort and clears the bit once resume runs; a mask which cannot be programmed right away converges on the next isolation change or the CPU-online restore. A user affinity request supersedes the pending replay, and free_irq() drops it with the last action. Signed-off-by: Kris Pan --- kernel/irq/cpuhotplug.c | 12 ++++- kernel/irq/debugfs.c | 1 + kernel/irq/internals.h | 9 ++++ kernel/irq/irqdesc.c | 1 + kernel/irq/isolation.c | 97 +++++++++++++++++++++++++++++++++++++++++ kernel/irq/manage.c | 19 +++++++- kernel/irq/pm.c | 15 +++++++ 7 files changed, 150 insertions(+), 4 deletions(-) diff --git a/kernel/irq/cpuhotplug.c b/kernel/irq/cpuhotplug.c index cd5689e383b00..ee14fc5dd16ff 100644 --- a/kernel/irq/cpuhotplug.c +++ b/kernel/irq/cpuhotplug.c @@ -208,8 +208,16 @@ static void irq_restore_affinity_of_irq(struct irq_desc *desc, unsigned int cpu) struct irq_data *data = irq_desc_get_irq_data(desc); const struct cpumask *affinity = irq_data_get_affinity_mask(data); - if (!irqd_affinity_is_managed(data) || !desc->action || - !irq_data_get_irq_chip(data) || !cpumask_test_cpu(cpu, affinity)) + if (!desc->action || !irq_data_get_irq_chip(data)) + return; + + if (!irqd_affinity_is_managed(data)) { + if (irq_isolation_restore_affinity(desc, cpu)) + irq_reapply_affinity(desc, NULL); + return; + } + + if (!cpumask_test_cpu(cpu, affinity)) return; if (irqd_is_managed_and_shutdown(data)) diff --git a/kernel/irq/debugfs.c b/kernel/irq/debugfs.c index 515c01754f1f0..776289a4f91e2 100644 --- a/kernel/irq/debugfs.c +++ b/kernel/irq/debugfs.c @@ -155,6 +155,7 @@ static const struct irq_bit_descr irqdesc_istates[] = { BIT_MASK_DESCR(IRQS_SUSPENDED), BIT_MASK_DESCR(IRQS_NMI), BIT_MASK_DESCR(IRQS_AFFINITY_AUTO), + BIT_MASK_DESCR(IRQS_ISOLATION_PENDING), }; diff --git a/kernel/irq/internals.h b/kernel/irq/internals.h index d2123d140a1c4..2adac3316ea7e 100644 --- a/kernel/irq/internals.h +++ b/kernel/irq/internals.h @@ -65,6 +65,7 @@ enum { * IRQS_NMI - irq line is used to deliver NMIs * IRQS_SYSFS - descriptor has been added to sysfs * IRQS_AFFINITY_AUTO - affinity placement was chosen automatically + * IRQS_ISOLATION_PENDING - reapply skipped due to suspend */ enum { IRQS_AUTODETECT = 0x00000001, @@ -79,6 +80,7 @@ enum { IRQS_NMI = 0x00002000, IRQS_SYSFS = 0x00004000, IRQS_AFFINITY_AUTO = 0x00008000, + IRQS_ISOLATION_PENDING = 0x00010000, }; static inline bool irq_affinity_is_auto(struct irq_desc *desc) @@ -190,6 +192,7 @@ static inline int irq_setup_affinity(struct irq_desc *desc) { return 0; } void irq_reapply_affinity(struct irq_desc *desc, const struct cpumask *changed); bool irq_isolation_needs_reapply(struct irq_desc *desc, const struct cpumask *changed); +bool irq_isolation_restore_affinity(struct irq_desc *desc, unsigned int cpu); bool irq_isolation_widen_mask(struct irq_desc *desc, const struct cpumask *mask, struct cpumask *out); bool irq_isolation_widen_mask_full(struct irq_desc *desc, @@ -207,6 +210,12 @@ static inline bool irq_isolation_needs_reapply(struct irq_desc *desc, return false; } +static inline bool irq_isolation_restore_affinity(struct irq_desc *desc, + unsigned int cpu) +{ + return false; +} + static inline bool irq_isolation_widen_mask(struct irq_desc *desc, const struct cpumask *mask, struct cpumask *out) diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c index 4f578f8d497fd..7c000241784af 100644 --- a/kernel/irq/irqdesc.c +++ b/kernel/irq/irqdesc.c @@ -138,6 +138,7 @@ static void desc_set_defaults(unsigned int irq, struct irq_desc *desc, int node, irq_settings_clr_and_set(desc, ~0, _IRQ_DEFAULT_INIT_FLAGS); irqd_set(&desc->irq_data, IRQD_IRQ_DISABLED); irqd_set(&desc->irq_data, IRQD_IRQ_MASKED); + desc->istate &= ~IRQS_ISOLATION_PENDING; irq_affinity_set_auto(desc); desc->handle_irq = handle_bad_irq; desc->depth = 1; diff --git a/kernel/irq/isolation.c b/kernel/irq/isolation.c index 6307b7508057e..1d65447f38d6c 100644 --- a/kernel/irq/isolation.c +++ b/kernel/irq/isolation.c @@ -38,6 +38,8 @@ static cpumask_var_t irq_isolation_old; static cpumask_var_t irq_isolation_curr; static cpumask_var_t irq_isolation_changed; static bool irq_isolation_ready; +/* Set once a runtime isolated CPU existed, never cleared. */ +static bool irq_isolation_used; bool irq_isolation_active(void) { @@ -411,6 +413,99 @@ bool irq_isolation_needs_reapply(struct irq_desc *desc, !unaffected || needs_restore; } +/** + * irq_isolation_restore_affinity - Re-evaluate an unmanaged IRQ on CPU online + * @desc: interrupt descriptor, desc->lock held + * @cpu: CPU which just came online + * + * An AUTO IRQ may be parked on a runtime-isolated CPU or displaced to a + * remote NUMA node when no local housekeeping CPU was online. A returning + * CPU may also bring back a request which was filtered away, or complete an + * emergency fallback of the CPU offline path. Return true when @cpu can + * improve the placement and the caller should reapply the requested + * affinity. + */ +bool irq_isolation_restore_affinity(struct irq_desc *desc, unsigned int cpu) +{ + const struct cpumask *affinity = irq_data_get_affinity_mask(&desc->irq_data); + struct irq_data *data = &desc->irq_data; + int node = irq_data_get_node(data); + bool isolated_cpu, trapped; + const struct cpumask *eff; + + lockdep_assert_held(&desc->lock); + + if (!irq_isolation_can_filter(data) || !irqd_can_balance(data) || + irqd_affinity_is_managed(data)) + return false; + + eff = irq_data_get_effective_affinity_mask(data); + /* + * A chip which does not report its programming cannot be reasoned + * about; do not rebind on every CPU online event. + */ + if (cpumask_empty(eff)) + return false; + + if (!irq_isolation_active()) { + /* + * Isolation is gone, but a CPU offline may have parked the + * interrupt outside its requested mask through the -ENOSPC + * emergency fallback. Nothing else reprograms an unmanaged + * IRQ when a CPU comes online, so converge here. + * + * Only do that on a system which used runtime isolation at + * least once. A pristine system keeps the upstream "leave + * unmanaged interrupts alone" behaviour, even when the + * vector fallback placed one outside its request. + */ + if (!READ_ONCE(irq_isolation_used)) + return false; + return cpumask_test_cpu(cpu, affinity) && + !cpumask_intersects(eff, affinity); + } + + rcu_read_lock(); + isolated_cpu = housekeeping_runtime_isolated_cpu(cpu); + if (isolated_cpu) { + /* + * A CPU which just entered an isolated partition cannot + * improve any placement; the filter would only remove it + * again. Return before the NUMA and request checks so that + * the caller does not program the chip and notify for + * nothing. + */ + rcu_read_unlock(); + return false; + } + trapped = housekeeping_runtime_isolated_intersects(eff); + rcu_read_unlock(); + + if (!cpumask_test_cpu(cpu, affinity)) { + /* + * Do not redirect an explicit mask which does not contain + * the new CPU. An AUTO fallback, however, may still be + * parked on a runtime-isolated CPU or on a remote NUMA + * node. Only a request which wants the device node counts + * as displaced; a queue which was hinted onto another node + * is already where it belongs. + */ + return irq_affinity_is_auto(desc) && + (trapped || + (node != NUMA_NO_NODE && cpu_to_node(cpu) == node && + cpumask_intersects(affinity, cpumask_of_node(node)) && + !cpumask_intersects(eff, cpumask_of_node(node)))); + } + + /* + * The CPU is back in the requested mask. Reapply only if the IRQ + * is still parked on an isolated CPU or its effective mask no + * longer intersects the request; avoid rebinding every unmanaged + * IRQ on each CPU online event. + */ + return trapped || !cpumask_intersects(eff, affinity); +} + static void irq_isolation_reapply_all(const struct cpumask *changed) { unsigned int irq; @@ -499,6 +594,8 @@ void irq_isolation_update(void) housekeeping_runtime_isolated(irq_isolation_curr); rcu_read_unlock(); active = !cpumask_empty(irq_isolation_curr); + if (active) + WRITE_ONCE(irq_isolation_used, true); if (cpumask_equal(irq_isolation_old, irq_isolation_curr)) return; diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c index 6e6fdae14bb07..06bfaaa9d6b23 100644 --- a/kernel/irq/manage.c +++ b/kernel/irq/manage.c @@ -231,7 +231,8 @@ static inline void irq_validate_effective_affinity(struct irq_data *data) { } static DEFINE_PER_CPU(struct cpumask, __tmp_mask); -int irq_do_set_affinity(struct irq_data *data, const struct cpumask *mask, bool force) +int irq_do_set_affinity(struct irq_data *data, const struct cpumask *mask, + bool force) { struct cpumask *tmp_mask = this_cpu_ptr(&__tmp_mask); struct irq_desc *desc = irq_data_to_desc(data); @@ -386,8 +387,11 @@ void irq_reapply_affinity(struct irq_desc *desc, const struct cpumask *changed) if (changed && !irq_isolation_needs_reapply(desc, changed)) return; - if (desc->istate & IRQS_SUSPENDED) + if (desc->istate & IRQS_SUSPENDED) { + desc->istate |= IRQS_ISOLATION_PENDING; return; + } + desc->istate &= ~IRQS_ISOLATION_PENDING; if (irq_can_move_pcntxt(data)) { int ret; @@ -493,6 +497,11 @@ int irq_set_affinity_locked(struct irq_data *data, const struct cpumask *mask, if (irq_set_affinity_deactivated(data, mask)) return 0; + /* + * A replay which was skipped because the IRQ was suspended is + * superseded by this request. The notifier is scheduled below. + */ + desc->istate &= ~IRQS_ISOLATION_PENDING; if (irq_can_move_pcntxt(data) && !irqd_is_setaffinity_pending(data)) { ret = irq_try_set_affinity(data, mask, force); } else { @@ -2171,6 +2180,12 @@ static struct irqaction *__free_irq(struct irq_desc *desc, void *dev_id) /* If this was the last handler, shut down the IRQ line: */ if (!desc->action) { irq_settings_clr_disable_unlazy(desc); + /* + * AUTO and IRQD_AFFINITY_SET describe the current placement + * and must survive close/reopen. Only the per-request + * isolation replay state is cleared here. + */ + desc->istate &= ~IRQS_ISOLATION_PENDING; /* Only shutdown. Deactivate after synchronize_hardirq() */ irq_shutdown(desc); } diff --git a/kernel/irq/pm.c b/kernel/irq/pm.c index 99ff65466d871..63b59e610f4af 100644 --- a/kernel/irq/pm.c +++ b/kernel/irq/pm.c @@ -170,6 +170,16 @@ static void resume_irq(struct irq_desc *desc) irq_state_set_masked(desc); resume: desc->istate &= ~IRQS_SUSPENDED; + if (desc->istate & IRQS_ISOLATION_PENDING) { + desc->istate &= ~IRQS_ISOLATION_PENDING; + /* + * Best effort: a replay which cannot program the mask now + * is retried by the next isolation change or by the CPU + * online restore, so do not keep the bit set on an + * interrupt which is no longer suspended. + */ + irq_reapply_affinity(desc, NULL); + } __enable_irq(desc); } @@ -204,6 +214,11 @@ void rearm_wake_irq(unsigned int irq) return; desc->istate &= ~IRQS_SUSPENDED; + if (desc->istate & IRQS_ISOLATION_PENDING) { + desc->istate &= ~IRQS_ISOLATION_PENDING; + /* Best effort, see resume_irq(). */ + irq_reapply_affinity(desc, NULL); + } irqd_set(&desc->irq_data, IRQD_WAKEUP_ARMED); __enable_irq(desc); } -- 2.43.0