Netdev List
 help / color / mirror / Atom feed
From: Kris Pan <kris.pan@intel.com>
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 <kris.pan@intel.com>
Subject: [RFC PATCH 09/10] sched/isolation: Publish runtime isolation to genirq
Date: Mon, 30 Nov 2026 11:37:07 +0800	[thread overview]
Message-ID: <20261130033709.2704805-10-kris.pan@intel.com> (raw)
In-Reply-To: <20261130033709.2704805-1-kris.pan@intel.com>

Call irq_isolation_update() from housekeeping_update() after
cpuset_mutex and cpus_read_lock() have been released, so runtime
PRS_ISOLATED changes trigger genirq affinity reapplication through the
existing housekeeping synchronization point without lock inversion.
At this point only cpuset_top_mutex is held, so the full order is
cpuset_top_mutex -> irq_isolation_mutex -> cpus_read_lock ->
sparse_irq_lock -> desc->lock.

CPU hotplug already funnels its housekeeping update through
hk_sd_workfn() instead of running it under cpus_write_lock(), so the
same call covers it without a second entry point.  irq_isolation_update()
asserts that the CPU hotplug lock is not held and takes one read lock
itself around the static key update and the reapply walk.

Document runtime-only filtering, the HK_TYPE_DOMAIN AUTO fallback,
explicit /proc pins, the unfiltered irq_force_affinity(), the automatic
placement of irq_set_affinity_and_hint() and irq_set_affinity_auto()
versus the explicit bare irq_set_affinity(), deferred migration on
IRQCHIP_MOVE_DEFERRED chips and the -EBUSY pending path, the notifier
at queue and completion (the completion one only while runtime
isolation is active), the requested or pending mask it reports versus
the mask a reverse-map consumer follows with
irq_copy_programmed_affinity(), the exclusions (per-CPU, managed), the
IRQF_NOBALANCING scope (an explicit request is replayed unfiltered
while a default placement is still chosen among housekeeping CPUs), the
x86-only opt-in today, the threaded IRQ self-migration, and the x86
fallback which only excludes runtime-isolated CPUs.  Warn that
irqbalance has to be disabled before the partition is created, because
stopping it later does not restore the automatic placement of its
earlier single-CPU /proc pins.  A broad mask written back through
/proc is still explicit but is filtered as well; only the cross-mask
fallback to other housekeeping CPUs is lost.  Describe the PREEMPT_RT
window: the IRQ thread self-migrates before it runs the next handler,
the wake-up is queued against the old scheduling affinity so the thread
can be scheduled once on the isolated CPU, and a handler which is
already running finishes on the old CPU.

Signed-off-by: Kris Pan <kris.pan@intel.com>
---
 Documentation/admin-guide/cpu-isolation.rst | 102 ++++++++++++++++++++
 kernel/sched/isolation.c                    |   2 +
 2 files changed, 104 insertions(+)

diff --git a/Documentation/admin-guide/cpu-isolation.rst b/Documentation/admin-guide/cpu-isolation.rst
index b9f13a9286734..df4e9e61e3f3e 100644
--- a/Documentation/admin-guide/cpu-isolation.rst
+++ b/Documentation/admin-guide/cpu-isolation.rst
@@ -355,3 +355,105 @@ Some tools may also be useful for higher level analysis:
 
 - cpunoise does something similar to rtla-osnoise but in userspace. It is available
   at https://git.kernel.org/pub/scm/linux/kernel/git/frederic/cpunoise.git
+
+Runtime IRQ isolation
+=====================
+
+When at least one ``cpuset.cpus.partition=isolated`` partition is active
+at runtime, genirq removes the runtime-isolated CPUs from the affinity
+mask programmed for unmanaged interrupts.  Boot-time
+``isolcpus=domain`` CPUs are not filtered out, preserving existing IRQ
+behavior.  The requested affinity is preserved, so the original mask is
+handed to the irqchip again when runtime isolation is removed.  That
+does not force a re-spread: a single-target IRQ (x86 marks its vector
+IRQs as single-target) whose effective CPU is still in the request
+keeps that CPU, because the x86 vector code does not move an interrupt
+whose current target is still valid.  The re-apply still schedules the
+affinity notification and re-marks the IRQ threads, so a reverse map is
+restored even though the vector stays.  IRQs which were only narrowed
+therefore stay on the housekeeping CPU physically after the partition
+is gone unless a balancer or an explicit affinity write moves them.  An automatic IRQ whose whole request became isolated is
+different: the fallback moved it outside the request, so its current
+CPU is not in the mask and the chip does move it back when the CPU
+returns.  The x86 vector allocator
+likewise excludes only runtime-isolated CPUs from its fallback masks, so
+boot-time ``isolcpus=domain`` fallback targets do not change.  A CPU
+which is both boot-isolated and part of a runtime isolated partition is
+not in the runtime set either (it is computed as
+``HK_TYPE_DOMAIN_BOOT`` minus ``HK_TYPE_DOMAIN``), so its interrupt
+behaviour is unchanged from a kernel without runtime isolation.
+
+Only delivery chips which advertise ``IRQCHIP_AFFINITY_FILTERABLE``
+participate; today that is the x86 APIC vector chip, GICv3/ITS is not
+enabled yet.  Every level between the device and the delivery chip which
+implements ``.irq_set_affinity`` has to be marked either FILTERABLE or
+``IRQCHIP_AFFINITY_PASSTHROUGH``: on x86 those are the IO-APIC, PCI-MSI,
+DMAR/AMDVI, HPET, INTEL-IR, AMD-IR, HYPERV-IR, the Hyper-V PCI MSI
+parents and the UV core domain.  An unmarked level keeps filtering off
+for the whole chain instead of inheriting the capability from its
+parent.  Per-CPU and managed interrupts are never filtered.
+``IRQF_NOBALANCING`` resolves the filter in two steps.  The interrupt is
+activated before the flag is applied, so a default placement still
+starts on a housekeeping CPU; an explicit request which was narrowed
+before ``request_irq()`` is then programmed again, because the filter is
+inert for a non-balancing interrupt.  A driver which pre-marks the
+interrupt with ``irq_set_status_flags(irq, IRQ_NO_BALANCING)`` skips
+both steps.
+Default placement and affinity hints are automatic and fall back to
+online ``HK_TYPE_DOMAIN`` housekeeping CPUs when all requested targets
+are runtime-isolated.  A request made through
+``/proc/irq/N/smp_affinity`` is explicit and remains authoritative; it
+is preserved if all online CPUs in the requested mask are
+runtime-isolated.  ``irq_force_affinity()`` is not filtered at all: it
+bypasses the isolation filter and programs the caller supplied mask
+verbatim.  An in-kernel ``irq_set_affinity()`` call is an explicit
+request and is not redirected.  ``irq_set_affinity_and_hint()`` keeps
+the placement automatic, so a driver which binds a queue after the
+partition became isolated is still evicted; core code which manages an
+affinity on a driver's behalf uses ``irq_set_affinity_auto()``.
+
+irqbalance must be disabled before the runtime partition is created,
+preferably from boot.  It writes single-CPU ``/proc`` affinity masks
+which are explicit pins, and stopping the balancer later does not
+restore their automatic placement.  An on-demand "stop irqbalance
+before starting the RT container" is therefore not sufficient: either
+disable it from boot or use a userspace balancer which reads
+``cpuset.cpus.isolated``.  Writing a broad mask back through ``/proc``
+also keeps the IRQ away from runtime-isolated CPUs, because the filter
+subtracts them from explicit masks as well.  The mask stays explicit
+though: if every online CPU in it is isolated, the IRQ cannot fall back
+to other housekeeping CPUs.  Otherwise the earlier ``/proc`` writes
+keep the IRQs pinned to CPUs which later become isolated.
+
+This is best-effort avoidance, not a hard guarantee
+that no interrupt can ever target an isolated CPU.
+
+A chip which sets ``IRQCHIP_MOVE_DEFERRED`` cannot program a mask in
+process context.  The x86 APIC vector code does not set the flag, but
+returns ``-EBUSY`` while a previous move is still in flight; the old
+vector is then cleaned up by the next interrupt.  In both cases the
+core queues the requested mask and programs it from interrupt context.
+The affinity notification is sent when the move is queued and again
+when the pending mask has been programmed; the second one only runs
+while runtime isolation is active.  The notifier reports the requested
+mask (or the pending request).  A consumer which spreads work over
+several CPUs uses the mask the core asks the chip to program,
+``irq_copy_programmed_affinity()``: the request minus the
+runtime-isolated CPUs, or the automatic relocation.
+On ``CONFIG_PREEMPT_RT`` most handlers are forced to threaded context.
+The IRQ thread follows the requested affinity through the existing
+``IRQTF_AFFINITY`` lazy update:
+it processes the flag at the top of its wait loop and blocks in
+``set_cpus_allowed_ptr()`` until it has been moved, so an idle thread
+runs its next handler on a housekeeping CPU.  A deferred hardware
+move marks the IRQ threads as soon as the move is queued, so an
+awakened thread escapes before the hardware move completes.  The
+wake-up itself is queued against the old scheduling affinity, so the
+thread can still be scheduled once on the isolated CPU before it
+migrates; the migration itself completes before the next handler runs.
+A handler which is already running when the affinity changes finishes
+on the old isolated CPU.
+Keep latency-critical RT tasks at a higher real-time priority than the
+threaded IRQ default (``SCHED_FIFO`` 50), or let the device settle
+before entering the critical loop.  Adding a housekeeping CPU to such a
+task's affinity is not an option inside an isolated cpuset partition.
diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c
index 418579766a364..1539d6ecd4ffb 100644
--- a/kernel/sched/isolation.c
+++ b/kernel/sched/isolation.c
@@ -201,6 +201,8 @@ int housekeeping_update(struct cpumask *isol_mask)
 	err = kthreads_update_housekeeping();
 	WARN_ON_ONCE(err < 0);
 
+	irq_isolation_update();
+
 	kfree(old);
 
 	return 0;
-- 
2.43.0


  parent reply	other threads:[~2026-11-30  3:41 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  3:36 [RFC PATCH 00/10] genirq/cpuset: Evict unmanaged IRQs from runtime-isolated CPUs Kris Pan
2026-11-30  3:36 ` [RFC PATCH 01/10] genirq: Add IRQCHIP_AFFINITY_FILTERABLE flag Kris Pan
2026-11-30  3:37 ` [RFC PATCH 02/10] sched/isolation: Add runtime isolation helpers Kris Pan
2026-11-30  3:37 ` [RFC PATCH 03/10] genirq: Track automatic vs. explicit affinity provenance Kris Pan
2026-11-30  3:37 ` [RFC PATCH 04/10] genirq: Filter unmanaged IRQ affinity against runtime isolation Kris Pan
2026-11-30  3:37 ` [RFC PATCH 05/10] genirq: Reapply unmanaged IRQ affinity on isolation changes Kris Pan
2026-11-30  3:37 ` [RFC PATCH 06/10] genirq: Align affinity notifiers and IRQ threads with isolation Kris Pan
2026-11-30  3:37 ` [RFC PATCH 07/10] genirq: Handle runtime isolation across hotplug and suspend Kris Pan
2026-11-30  3:37 ` [RFC PATCH 08/10] x86/apic: Support runtime IRQ isolation Kris Pan
2026-11-30  3:37 ` Kris Pan [this message]
2026-11-30  3:37 ` [RFC PATCH 10/10] net: Keep core-managed IRQ affinity automatic Kris Pan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261130033709.2704805-10-kris.pan@intel.com \
    --to=kris.pan@intel.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=bhelgaas@google.com \
    --cc=bigeasy@linutronix.de \
    --cc=bp@alien8.de \
    --cc=clrkwllms@kernel.org \
    --cc=corbet@lwn.net \
    --cc=dave.hansen@linux.intel.com \
    --cc=davem@davemloft.net \
    --cc=decui@microsoft.com \
    --cc=dwmw2@infradead.org \
    --cc=edumazet@kernel.org \
    --cc=frederic@kernel.org \
    --cc=haiyangz@microsoft.com \
    --cc=hpa@zytor.com \
    --cc=iommu@lists.linux.dev \
    --cc=joro@8bytes.org \
    --cc=juri.lelli@redhat.com \
    --cc=kuba@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-rt-devel@lists.linux.dev \
    --cc=longman@redhat.com \
    --cc=lpieralisi@kernel.org \
    --cc=maz@kernel.org \
    --cc=mingo@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=peterz@infradead.org \
    --cc=radu@rendec.net \
    --cc=robin.murphy@arm.com \
    --cc=steve.wahl@hpe.com \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=tglx@kernel.org \
    --cc=tj@kernel.org \
    --cc=vasant.hegde@amd.com \
    --cc=vincent.guittot@linaro.org \
    --cc=wei.liu@kernel.org \
    --cc=will@kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox