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=1796010065; b=APwGT89b2X6AcoIdYUDhEo68/sRotwRXxkVfYytqjDWfF9mgH8/ukdCX8GjaumP8FHUM +VDrADjV6+KcduDwjmm8B6skdu+1c0TGv7ujIhOyAVsWCs0WXQxHWfmaUlUitfEwQn5NY 6w4Aaw4vChElkGw22z9PLTN+37T0EQB12hHqVl543MAzCD1YNFlEF+DNUFe0Ha5QI1I4M WB6DzDcNo7AeR8oe7ykaZ1q9Xm+vzfYI38ys7zYf0Ox7gbGd/ba4e659Iz6mCZPPCCng9 A5wIV1CrOk2SbQYXFdq+VzXy95O4O3/xFMc+lxHT4Hjbvz6woIDrMfjy7lMU9pAiWAQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796010065; 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=8/+0dUFmCYPYVHHPWnBr3gwydjkHMWBUzJV6+jsnzyA=; b=pM2nx/r7nMCB25R1ptYzR8DYJD8e1Ekwzu97h3FJDKfQgbeE8Kllt7A1IhwcTlVdDaJg mIuvUYVKmhhg9cXcN0IBv8u6weFiz0Bp4eLcekh53CN8hijfHoYIogyiTjfYLrs3+Xjx/ lCbKlcaL46snksK5oA5oCLyQsd6M9pqzTA25bBV/EGjjCDvsAb4fPGd4mQFmXBtR7wfnW qEKEFMtxo0gfnCGoXjy54sIFu0n4jrM4U1n3jEDAKyDE9mx9hEsgHmQA3saL3JgZpy4fG uRTFQfvaSog+j+sSUij231+FL4Jy9UB0Soyz2grw/eaYVR9r5j9PNSlDSglsRMyuyUg== 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=DbkknaEN; 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 BC23B606A329; Mon, 30 Nov 2026 03:41:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BC23B606A329 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=DbkknaEN DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796010065; x=1827546065; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Kw7qRSXz5TWbeYzsdNtIhBq/3PGC/ETWZTD1p0JoEvc=; b=DbkknaENnIjRNhAAnW97h8crGLcV4fa63VbhKa8GaGC+60gp+a+e8V37 lvixV2FZ4VgBlOZj5rsMCoe0Cn3IOfyNgqpyDD527LR1DiqYEMNL2oWLB 5Ms8DEzAbT3dYC3lLefiG+WS58K45sg4kl+Jot12qI+HHOfoDeC2ulJIp HFReDQgbU7XZ43O3anHx6i+LBFy8czj+xu8JJxJI8ckH2rgUDnuu24ZgK yBAmdIiUzgJIv8i3aaY+iwWeNgkOy0GHnKBuUWaY99/0Kt/8fMr1hya1G WWULJEhfHeLHCi6oZahZjda/9l8AlBrJqVtqQc0L8cR/tP+PTz0qorCKG w==; X-CSE-ConnectionGUID: FntJ4z3kSu2n0JwjPEkQCg== X-CSE-MsgGUID: rKKmvFofQOKdvZ5wZhDPhg== X-IronPort-AV: E=McAfee;i="6800,10657,11981"; a="4848331" X-IronPort-AV: E=Sophos;i="6.27,242,1787036400"; d="scan'208";a="4848331" 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:04 -0800 X-CSE-ConnectionGUID: bjQG7fLHQSKgBtox6b0QoQ== X-CSE-MsgGUID: olA5PuA6QAqgt9+XUpBgxw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,242,1787036400"; d="scan'208";a="12951073" 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:55 -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 06/10] genirq: Align affinity notifiers and IRQ threads with isolation Date: Mon, 30 Nov 2026 11:37:04 +0800 Message-ID: <20261130033709.2704805-7-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 Filtering changes the mask which is programmed while the requested mask stays as the driver wrote it. Consumers of the affinity notifier and threaded IRQ handlers have to follow the programmed mask, otherwise they keep steering work to a CPU which the partition just took away. Report the requested mask from irq_affinity_notify(), as upstream does; a pending move carries the newest request in the pending mask. A consumer which spreads work over several CPUs asks for the mask the core would hand to the chip with irq_copy_programmed_affinity(): the request (or the pending request) with the runtime-isolated CPUs removed, or the automatic relocation. The effective affinity is deliberately not used for that; it is a single target on chips with IRQD_SINGLE_TARGET and would collapse a multi-CPU queue map. A consumer which stores the notified mask as the request (net/core does) must not be handed the filtered mask, or removing the partition later cannot restore the CPU. The notifier is queued when the affinity is requested, but a deferred move programs the pending mask only from interrupt context. Schedule the notifier again from irq_move_masked_irq() once the pending mask was programmed, so that a consumer which follows the programmed mask converges on the new target. Only do that while runtime isolation is active: without it the programmed mask always tracked the request, and the upstream single notification is kept. A deferred move cannot program the mask synchronously: a chip which sets IRQCHIP_MOVE_DEFERRED queues it in the core, and the x86 vector code returns -EBUSY while a previous move is still in flight. Mark the IRQ threads whenever a pending move is armed while runtime isolation is active: the -EBUSY fallback of irq_try_set_affinity(), the reapply branch, and irq_set_affinity_locked() when a user request cannot be programmed immediately. A handler which is woken by an interrupt on the isolated CPU can then escape to the requested target instead of running there. A pending move carries the newest request in the pending mask; irq_thread_check_affinity() uses it as the escape target, because the descriptor affinity is only updated when the move completes. When that target is already free of runtime-isolated CPUs no filtering applies and the thread follows the pending target itself; falling back to the old effective CPU would keep it on the isolated CPU until the move completes, which is exactly the window the early mark is meant to cover. Signed-off-by: Kris Pan --- include/linux/irq.h | 7 ++++ kernel/irq/isolation.c | 40 ++++++++++++++++++ kernel/irq/manage.c | 92 ++++++++++++++++++++++++++++++++++++++++-- kernel/irq/migration.c | 10 +++++ 4 files changed, 146 insertions(+), 3 deletions(-) diff --git a/include/linux/irq.h b/include/linux/irq.h index 382591da2038d..ffe2339ac6b6f 100644 --- a/include/linux/irq.h +++ b/include/linux/irq.h @@ -641,6 +641,7 @@ 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); +bool irq_copy_programmed_affinity(unsigned int irq, struct cpumask *mask); #else static inline bool irq_isolation_active(void) { return false; } @@ -656,6 +657,12 @@ static inline bool irq_isolation_select_mask(struct irq_data *data, return false; } +static inline bool irq_copy_programmed_affinity(unsigned int irq, + struct cpumask *mask) +{ + return false; +} + #endif #if defined(CONFIG_SMP) && defined(CONFIG_GENERIC_IRQ_MIGRATION) 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; } +/** + * 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 isolation + * may program a different mask for a filterable chip: the request with the + * runtime-isolated CPUs removed, or an automatic relocation when the request + * lost its last online target. A consumer which spreads work over several + * 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 and 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 = 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 = irq_desc_get_pending_mask(desc); + else + req = desc->irq_common_data.affinity; + if (cpumask_empty(req)) + return false; + + return irq_isolation_select_mask(&desc->irq_data, req, mask); +} + /** * irq_isolation_widen_mask - Preferred emergency mask after the filtered * placement failed 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, const struct cpumask *changed) return; 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 = 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; } @@ -410,6 +423,20 @@ void irq_reapply_affinity(struct irq_desc *desc, const 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); + /* + * Report the queued move right away, like a pending user request. + * The completion path reports again once the pending mask was + * programmed, so a consumer which follows the programmed mask + * converges on the new target. + */ + if (desc->affinity_notify) + irq_affinity_schedule_notify_work(desc); #endif } #endif /* CONFIG_CPU_ISOLATION */ @@ -473,6 +500,16 @@ int irq_set_affinity_locked(struct irq_data *data, const struct cpumask *mask, irq_copy_pending(desc, mask); } + /* + * 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); @@ -659,6 +696,11 @@ static void irq_affinity_notify(struct work_struct *work) if (!desc || !alloc_cpumask_var(&cpumask, GFP_KERNEL)) goto out; + /* + * Report the requested mask, not the programmed one. A consumer + * which steers hardware to a CPU uses irq_copy_programmed_affinity() + * instead; runtime IRQ isolation may have filtered the request. + */ scoped_guard(raw_spinlock_irqsave, &desc->lock) { if (irq_move_pending(&desc->irq_data)) irq_get_pending(cpumask, desc); @@ -1187,10 +1229,54 @@ static void irq_thread_check_affinity(struct irq_desc *desc, struct irqaction *a } scoped_guard(raw_spinlock_irq, &desc->lock) { + const struct cpumask *target = desc->irq_common_data.affinity; const struct cpumask *m; + bool pending, trapped; m = 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 = irq_move_pending(&desc->irq_data); + if (pending) + target = 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 = false; + if (irq_isolation_active()) { + rcu_read_lock(); + trapped = 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 = false; + + if (pending && irq_isolation_can_filter(&desc->irq_data)) { + rcu_read_lock(); + clean = !housekeeping_runtime_isolated_intersects(target); + rcu_read_unlock(); + } + if (!clean || !cpumask_and(mask, target, cpu_online_mask)) + cpumask_copy(mask, m); + } } set_cpus_allowed_ptr(current, mask); 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); } -- 2.43.0