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=1796010047; b=wFVEEI0b31giBA4/gDal2z+qYk+o58+oWL7RCfnEJ5nv7hCtGo00u1Wi2P7y2c95ugSJ TQNMfEKcls8NJQVXQcPpyo/z0qqVT8aSd6muWiUvCcWdn4LDUC+ibquodA31ucUWjvJcn AXHWo6BKMkEvLl8muWfQcigV3MDCoiPO48MWILHQUHtNdCqdt/bcTUVvA4deZmvsrAo5/ q2Q4X1VXoFdtlan5qsYNwQIpX3NgWl+/tyf9QqcPjmapAS6Zg8IaRz8SyvBhVDrdGeq/G Ry4fhJgyCy5PsTWQOvlBH44zD8jz7cpZL3g331dVji+XnxbggJLXprCirN+cIDz6Jbg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796010047; 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=mpMC3AoL1vdvkQUoj2DquKm76gWz7jw+flJUxeSpIls=; b=HW3ZjikF3a9eeiWKNsNiD1aT/a/yegpk17cI1MK6MbDZepEYEzRWIvH19AL444rximFi ny0c7wgjBsVlL4HsyKBcx1BQeUWsU0bXf7wOshhqKGjM2Fy71yG3lkwnMf/mKulgCGNXl m1WhuMSE9W2dR1N2weo/LSNLDVhzIBFWu49nOEGseAiYPyVd+GO/av7duomb4o5P0EBtL utKQkqCpWb9NFj4Y7KhcdsYw0AmNtKxJDwOVB0pBlnSr+gPnXFpznWOsBeGJIrJNimnt2 /Ms9/aWyymuxQHKpUX4FxFpdvdwl/2ffjN0kTHQB/33Hd0Mb4JlGcbougln4DpYvYSA== 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=l6ad8jS6; 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 6787B606A32C; Mon, 30 Nov 2026 03:40:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6787B606A32C 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=l6ad8jS6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796010046; x=1827546046; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pOYXrFIs7GctSO7Gld0FXsMaBEXubJR0OStI9c2AoiA=; b=l6ad8jS62z1yIXzL99PSnppv+vQHiDJHgjjdXSY9nOX7jtTIBDcqKwGK l6kwlCfwOJhAQn9lVTx8yW0TQ6gnMVoClGQRFC1gxP/ytYMRG9J5tam4j Gtwi6u0M7NgqkgvwjZpmXFTfn78KMmrx26WMZmn+P+sXOXjsMWnKlEj6B HYXJC90zuRjoia2C4W5kwz6mdgtTOVwdLs9IDsIOFp55mtUxd+1iMeTXh mPRHRNNtdOe7B9e24nywBABGAzPKAY9E3Ho5Tgh/5WMrXl3hz7j7hyX+5 uwv5llNd9UI7S21ivAO6JQ081ye+l/OcSl8MJ/r97MrN0sAtrZDUPQC2r A==; X-CSE-ConnectionGUID: wXFxEtPgSdO5fZs/QvbTYg== X-CSE-MsgGUID: /vsLZZJbTryuDEnNxgcKpA== X-IronPort-AV: E=McAfee;i="6800,10657,11981"; a="4848288" X-IronPort-AV: E=Sophos;i="6.27,242,1787036400"; d="scan'208";a="4848288" 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:40:45 -0800 X-CSE-ConnectionGUID: mGzH8ZNBTjaf4CX0JIJxcA== X-CSE-MsgGUID: JesabZt/Sja4MOmMdLI93w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,242,1787036400"; d="scan'208";a="12951041" Received: from pankris-x299-ud4-pro.bj.intel.com ([10.238.152.122]) by fmviesa005.fm.intel.com with ESMTP; 29 Nov 2026 19:40:37 -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 04/10] genirq: Filter unmanaged IRQ affinity against runtime isolation Date: Mon, 30 Nov 2026 11:37:02 +0800 Message-ID: <20261130033709.2704805-5-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 An interrupt whose affinity includes a CPU handed to a cpuset isolated partition still receives work from that CPU. Runtime isolation has to steer the programmed affinity away from it without changing the request itself. Add the mask policy. irq_isolation_select_mask() subtracts the runtime isolated set from the requested mask; a mask without an isolated CPU is left alone, so boot-time isolcpus=domain CPUs are never stripped from an unaffected request. When an automatic placement loses every online target it falls back to the online HK_TYPE_DOMAIN CPUs, preferring a node the request covers over the device node, while an explicit request keeps its mask. Chips opt in with IRQCHIP_AFFINITY_FILTERABLE. The walk requires every level which implements .irq_set_affinity to be either FILTERABLE (the delivery level) or PASSTHROUGH (a forwarder which derives no state from the mask), so an unmarked domain keeps filtering off instead of inheriting it from a parent. A filtered mask can exhaust the vector space of its targets. Isolation is a soft-avoid policy, not a reason to break a working configuration, so retry before failing. An automatic placement may widen the search to the online HK_TYPE_DOMAIN housekeeping CPUs, honouring irq_default_affinity first and only then the full housekeeping set; it prefers a housekeeping CPU in another NUMA node over an isolated CPU in the local one and never spills onto a boot-time isolcpus=domain CPU. An explicit request is never widened and only loses the filter, as before. A driver which applies IRQF_NOBALANCING in request_irq() after an early irq_set_affinity() on an already activated MSI may have had that request narrowed before the flag became visible. Replay it once through irq_set_affinity_locked(): the filter is inert for a no-balancing interrupt, and a chip which cannot move in process context defers the replay to interrupt context instead of programming it from the wrong one. Signed-off-by: Kris Pan --- include/linux/irq.h | 24 +++++ kernel/irq/Makefile | 1 + kernel/irq/internals.h | 22 ++++ kernel/irq/isolation.c | 223 +++++++++++++++++++++++++++++++++++++++++ kernel/irq/manage.c | 135 ++++++++++++++++--------- 5 files changed, 360 insertions(+), 45 deletions(-) create mode 100644 kernel/irq/isolation.c diff --git a/include/linux/irq.h b/include/linux/irq.h index d47ebe8ec3708..382591da2038d 100644 --- a/include/linux/irq.h +++ b/include/linux/irq.h @@ -634,6 +634,30 @@ extern int irq_set_affinity_locked(struct irq_data *data, const struct cpumask *cpumask, bool force); extern int irq_set_vcpu_affinity(unsigned int irq, void *vcpu_info); +/* Runtime IRQ isolation for cpuset isolated partitions. */ +#ifdef CONFIG_CPU_ISOLATION +bool irq_isolation_active(void); +bool irq_isolation_can_filter(struct irq_data *data); +bool irq_isolation_select_mask(struct irq_data *data, + const struct cpumask *src, + struct cpumask *out); + +#else +static inline bool irq_isolation_active(void) { return false; } +static inline bool irq_isolation_can_filter(struct irq_data *data) +{ + return false; +} + +static inline bool irq_isolation_select_mask(struct irq_data *data, + const struct cpumask *src, + struct cpumask *out) +{ + return false; +} + +#endif + #if defined(CONFIG_SMP) && defined(CONFIG_GENERIC_IRQ_MIGRATION) extern void irq_migrate_all_off_this_cpu(void); extern int irq_affinity_online_cpu(unsigned int cpu); diff --git a/kernel/irq/Makefile b/kernel/irq/Makefile index 0e5df962a1497..e56b62d954d99 100644 --- a/kernel/irq/Makefile +++ b/kernel/irq/Makefile @@ -13,6 +13,7 @@ obj-$(CONFIG_GENERIC_MSI_IRQ) += msi.o obj-$(CONFIG_GENERIC_IRQ_IPI) += ipi.o obj-$(CONFIG_GENERIC_IRQ_IPI_MUX) += ipi-mux.o obj-$(CONFIG_SMP) += affinity.o +obj-$(CONFIG_CPU_ISOLATION) += isolation.o obj-$(CONFIG_GENERIC_IRQ_DEBUGFS) += debugfs.o obj-$(CONFIG_GENERIC_IRQ_MATRIX_ALLOCATOR) += matrix.o obj-$(CONFIG_IRQ_KUNIT_TEST) += irq_test.o diff --git a/kernel/irq/internals.h b/kernel/irq/internals.h index 06cfa77409022..abadf24b3d0eb 100644 --- a/kernel/irq/internals.h +++ b/kernel/irq/internals.h @@ -186,6 +186,28 @@ extern int irq_setup_affinity(struct irq_desc *desc); static inline int irq_setup_affinity(struct irq_desc *desc) { return 0; } #endif +#ifdef CONFIG_CPU_ISOLATION +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, + const struct cpumask *mask, + struct cpumask *out); +#else +static inline bool irq_isolation_widen_mask(struct irq_desc *desc, + const struct cpumask *mask, + struct cpumask *out) +{ + return false; +} + +static inline bool irq_isolation_widen_mask_full(struct irq_desc *desc, + const struct cpumask *mask, + struct cpumask *out) +{ + return false; +} +#endif + #define for_each_action_of_desc(desc, act) \ for (act = desc->action; act; act = act->next) diff --git a/kernel/irq/isolation.c b/kernel/irq/isolation.c new file mode 100644 index 0000000000000..af7244ce181a4 --- /dev/null +++ b/kernel/irq/isolation.c @@ -0,0 +1,223 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Runtime IRQ isolation for cpuset isolated partitions. + * + * The requested affinity of an interrupt is never changed here. A mask + * derived from housekeeping tells irq_do_set_affinity() which CPUs must not + * be programmed into the chip. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "internals.h" + +static DEFINE_STATIC_KEY_FALSE(irq_isolation_key); + +bool irq_isolation_active(void) +{ + return static_branch_unlikely(&irq_isolation_key); +} + +/* + * Compute the fallback mask for an auto-placed IRQ. @src is the requested + * mask. Must be called under RCU read lock and must never return a + * boot-time isolcpus=domain CPU. + */ +static bool irq_isolation_fallback_mask(struct irq_data *data, + const struct cpumask *src, + struct cpumask *mask) +{ + const struct cpumask *hk = housekeeping_cpumask(HK_TYPE_DOMAIN); + unsigned int cpu; + int node; + + cpumask_and(mask, irq_default_affinity, hk); + cpumask_and(mask, mask, cpu_online_mask); + if (cpumask_empty(mask)) + cpumask_and(mask, hk, cpu_online_mask); + if (cpumask_empty(mask)) + return false; + + /* + * Prefer a node which the request covers over the node the device + * sits on: a queue which a driver hinted onto another socket must + * not be pulled back to the device node when its CPUs become + * isolated. + */ + for_each_cpu(cpu, src) { + node = cpu_to_node(cpu); + if (node != NUMA_NO_NODE && + cpumask_intersects(mask, cpumask_of_node(node))) { + cpumask_and(mask, mask, cpumask_of_node(node)); + return true; + } + } + + node = irq_data_get_node(data); + if (node != NUMA_NO_NODE) { + const struct cpumask *node_mask = cpumask_of_node(node); + + if (cpumask_intersects(mask, node_mask)) + cpumask_and(mask, mask, node_mask); + } + return true; +} + +bool irq_isolation_can_filter(struct irq_data *data) +{ + bool filterable = false; + + /* + * The flag is owned by the chip which actually routes the + * interrupt. Every level which implements .irq_set_affinity has + * to declare itself either as the delivery level (FILTERABLE) or + * as a pure forwarder (PASSTHROUGH); an unmarked level disables + * filtering for the whole chain. A level which does not implement + * .irq_set_affinity is not part of the affinity path and is + * skipped, matching irq_chip_set_affinity_parent(). + */ + for (; data; data = irqd_get_parent_data(data)) { + if (!data->chip || !data->chip->irq_set_affinity) + continue; + if (data->chip->flags & IRQCHIP_AFFINITY_FILTERABLE) { + filterable = true; + continue; + } + if (data->chip->flags & IRQCHIP_AFFINITY_PASSTHROUGH) + continue; + return false; + } + + return filterable; +} + +/* + * Apply the runtime-isolation policy to @data's requested affinity and + * store the mask to program in @out. Returns false if the chip is not + * filterable, isolation is inactive, @src is unaffected, or no online + * target remains in @src. + * + * @out must not alias @src. + */ +bool irq_isolation_select_mask(struct irq_data *data, + const struct cpumask *src, struct cpumask *out) +{ + bool auto_placed; + + if (!irq_isolation_active() || !irq_isolation_can_filter(data) || + !irqd_can_balance(data) || irqd_affinity_is_managed(data)) + return false; + + rcu_read_lock(); + housekeeping_runtime_isolated(out); + cpumask_andnot(out, src, out); + /* + * Do not touch masks which contain no runtime-isolated CPU. Doing + * so would also strip boot-time isolcpus=domain CPUs from an + * otherwise unaffected request. + */ + if (cpumask_equal(out, src)) { + rcu_read_unlock(); + return false; + } + + /* + * A remaining online target keeps the boot isolcpus=domain CPUs in + * the mask, for explicit and automatic placements alike. Only when + * runtime isolation removed every online target may an automatic + * placement be redirected to online HK_TYPE_DOMAIN CPUs; an + * explicit request which lost all targets is preserved. + */ + auto_placed = 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); + + /* + * An explicit request which lost every online target, or an + * automatic placement without a housekeeping target, is kept as + * requested. Report the mask as unchanged so that the caller does + * not retry it after -ENOSPC and does not widen a single-target + * IRQ thread beyond its effective CPU. + */ + if (!cpumask_intersects(out, cpu_online_mask)) { + rcu_read_unlock(); + return false; + } + rcu_read_unlock(); + return true; +} + +/** + * irq_isolation_widen_mask - Preferred emergency mask after the filtered + * placement failed + * @desc: Interrupt descriptor + * @mask: Requested mask which just failed + * @out: Storage for the widened mask + * + * An automatically placed interrupt may widen the search to the online + * housekeeping CPUs when the requested mask has no vector left. The + * administrator's irq_default_affinity is honoured first, so an + * emergency placement does not spill onto a CPU excluded with + * irqaffinity= while another default CPU has a vector; only when it is + * empty is the full housekeeping set used. + * + * An explicit request is never widened here. + * + * Returns: true when @out contains a CPU outside @mask. + */ +bool irq_isolation_widen_mask(struct irq_desc *desc, + const struct cpumask *mask, struct cpumask *out) +{ + const struct cpumask *hk; + + if (!irq_affinity_is_auto(desc)) + return false; + + rcu_read_lock(); + hk = housekeeping_cpumask(HK_TYPE_DOMAIN); + cpumask_and(out, irq_default_affinity, hk); + cpumask_and(out, out, cpu_online_mask); + if (cpumask_empty(out)) + cpumask_and(out, hk, cpu_online_mask); + rcu_read_unlock(); + + return !cpumask_empty(out) && !cpumask_subset(out, mask); +} + +/** + * irq_isolation_widen_mask_full - Full housekeeping emergency mask + * @desc: Interrupt descriptor + * @mask: Requested mask which just failed + * @out: Storage for the widened mask + * + * The second -ENOSPC retry: the preferred irq_default_affinity subset + * was already tried and is exhausted, so use every online housekeeping + * CPU. The requested mask stays the last resort in the caller. + * + * Returns: true when @out contains a CPU outside @mask. + */ +bool irq_isolation_widen_mask_full(struct irq_desc *desc, + const struct cpumask *mask, + struct cpumask *out) +{ + const struct cpumask *hk; + + if (!irq_affinity_is_auto(desc)) + return false; + + rcu_read_lock(); + hk = housekeeping_cpumask(HK_TYPE_DOMAIN); + cpumask_and(out, hk, cpu_online_mask); + rcu_read_unlock(); + + return !cpumask_empty(out) && !cpumask_subset(out, mask); +} + diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c index 4f5c776e8c5de..25f42256aeabf 100644 --- a/kernel/irq/manage.c +++ b/kernel/irq/manage.c @@ -236,63 +236,81 @@ int irq_do_set_affinity(struct irq_data *data, const struct cpumask *mask, bool struct cpumask *tmp_mask = this_cpu_ptr(&__tmp_mask); struct irq_desc *desc = irq_data_to_desc(data); struct irq_chip *chip = irq_data_get_irq_chip(data); - const struct cpumask *prog_mask; + const struct cpumask *prog_mask = mask; int ret; if (!chip || !chip->irq_set_affinity) return -EINVAL; - /* - * If this is a managed interrupt and housekeeping is enabled on - * it check whether the requested affinity mask intersects with - * a housekeeping CPU. If so, then remove the isolated CPUs from - * the mask and just keep the housekeeping CPU(s). This prevents - * the affinity setter from routing the interrupt to an isolated - * CPU to avoid that I/O submitted from a housekeeping CPU causes - * interrupts on an isolated one. - * - * If the masks do not intersect or include online CPU(s) then - * keep the requested mask. The isolated target CPUs are only - * receiving interrupts when the I/O operation was submitted - * directly from them. - * - * If all housekeeping CPUs in the affinity mask are offline, the - * interrupt will be migrated by the CPU hotplug code once a - * housekeeping CPU which belongs to the affinity mask comes - * online. - */ - if (irqd_affinity_is_managed(data) && - housekeeping_enabled(HK_TYPE_MANAGED_IRQ)) { - const struct cpumask *hk_mask; - - hk_mask = housekeeping_cpumask(HK_TYPE_MANAGED_IRQ); + if (force) { + /* + * Preserve the original force-affinity contract: the + * caller-supplied mask is passed through without online or + * policy filtering. force is not the same as the hotplug + * emergency fallback. + */ + ret = chip->irq_set_affinity(data, mask, true); + } else { + if (irqd_affinity_is_managed(data) && + housekeeping_enabled(HK_TYPE_MANAGED_IRQ)) { + const struct cpumask *hk_mask; + + hk_mask = housekeeping_cpumask(HK_TYPE_MANAGED_IRQ); + cpumask_and(tmp_mask, mask, hk_mask); + if (!cpumask_intersects(tmp_mask, cpu_online_mask)) + prog_mask = mask; + else + prog_mask = tmp_mask; + } else if (!irqd_affinity_is_managed(data) && + irq_isolation_active() && + irq_isolation_select_mask(data, mask, tmp_mask)) { + prog_mask = tmp_mask; + } - cpumask_and(tmp_mask, mask, hk_mask); - if (!cpumask_intersects(tmp_mask, cpu_online_mask)) - prog_mask = mask; + if (cpumask_and(tmp_mask, prog_mask, cpu_online_mask)) + ret = chip->irq_set_affinity(data, tmp_mask, false); else - prog_mask = tmp_mask; - } else { - prog_mask = mask; - } + ret = -EINVAL; - /* - * Make sure we only provide online CPUs to the irqchip, - * unless we are being asked to force the affinity (in which - * case we do as we are told). - */ - cpumask_and(tmp_mask, prog_mask, cpu_online_mask); - if (!force && !cpumask_empty(tmp_mask)) - ret = chip->irq_set_affinity(data, tmp_mask, force); - else if (force) - ret = chip->irq_set_affinity(data, mask, force); - else - ret = -EINVAL; + /* + * The filtered target may have exhausted its vectors. This + * is a soft-avoid policy: an automatic placement may widen + * the search to the online housekeeping CPUs, which prefers + * a CPU outside the (possibly NUMA-node narrowed) request + * over an isolated CPU in it. Boot-time isolcpus=domain + * CPUs are not housekeeping, so they are never used as an + * emergency target; the request itself is the last resort + * below. An explicit request is never widened; it only + * loses the filter, as before. + */ + if (ret == -ENOSPC && !irqd_affinity_is_managed(data) && + prog_mask != mask) { + /* + * @prog_mask aliases @tmp_mask at this point; the + * widening helpers compare their result with the + * request, so only a CPU outside the request is + * worth a retry. + */ + if (irq_isolation_widen_mask(desc, mask, tmp_mask)) + ret = chip->irq_set_affinity(data, tmp_mask, false); + if (ret == -ENOSPC && + irq_isolation_widen_mask_full(desc, mask, tmp_mask)) + ret = chip->irq_set_affinity(data, tmp_mask, false); + if (ret == -ENOSPC && + cpumask_and(tmp_mask, mask, cpu_online_mask)) + ret = chip->irq_set_affinity(data, tmp_mask, false); + } + } switch (ret) { case IRQ_SET_MASK_OK: case IRQ_SET_MASK_OK_DONE: - cpumask_copy(desc->irq_common_data.affinity, mask); + /* + * A replay passes the requested mask itself; copying it + * onto itself is undefined. + */ + if (desc->irq_common_data.affinity != mask) + cpumask_copy(desc->irq_common_data.affinity, mask); fallthrough; case IRQ_SET_MASK_OK_NOCOPY: irq_validate_effective_affinity(data); @@ -1835,6 +1853,33 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new) if (new->flags & IRQF_NOBALANCING) { irq_settings_set_no_balancing(desc); irqd_set(&desc->irq_data, IRQD_NO_BALANCING); +#ifdef CONFIG_CPU_ISOLATION + /* + * The flag is applied after irq_activate(), so a + * default placement still avoided isolated CPUs + * when the vector was assigned. An explicit + * request which was set before request_irq() was + * filtered at that point; now the filter is inert + * for this interrupt and the request can be + * programmed again. + * + * Only touch a filterable chip whose request was + * really set, with an online target. A deferred + * move is left to the regular migration path, which + * programs it unfiltered when it completes. + */ + if (irq_isolation_active() && + irq_isolation_can_filter(&desc->irq_data) && + !irqd_is_per_cpu(&desc->irq_data) && + irqd_affinity_was_set(&desc->irq_data) && + irqd_is_activated(&desc->irq_data) && + !irqd_is_setaffinity_pending(&desc->irq_data) && + cpumask_intersects(desc->irq_common_data.affinity, + cpu_online_mask)) + irq_set_affinity_locked(&desc->irq_data, + desc->irq_common_data.affinity, + false); +#endif } if (!(new->flags & IRQF_NO_AUTOEN) && -- 2.43.0