Linux-HyperV 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 00/10] genirq/cpuset: Evict unmanaged IRQs from runtime-isolated CPUs
Date: Mon, 30 Nov 2026 11:36:58 +0800	[thread overview]
Message-ID: <20261130033709.2704805-1-kris.pan@intel.com> (raw)

cpuset.cpus.partition=isolated removes CPUs from scheduler load
balancing and HK_TYPE_DOMAIN housekeeping at runtime, but genirq does
not consume that state.  Drivers requesting IRQs after container
start, reopening an interface, or resetting hardware can still route
unmanaged interrupts onto isolated CPUs.

  - Patch 1 defines the IRQCHIP_AFFINITY_FILTERABLE flag and its
    hierarchy contract.
  - Patch 2 adds the sched/isolation runtime-isolated helper.
  - Patch 3 records the placement provenance (automatic or explicit)
    and adds the core-only irq_set_affinity_auto() helper; a bare
    irq_set_affinity() is an explicit pin.
  - Patch 4 adds the filter, the shared mask selection and the
    late-IRQF_NOBALANCING re-align.
  - Patch 5 reapplies the requested affinity when the isolation set
    changes; the policy query lives in isolation.c.
  - Patch 6 keeps the requested mask in the affinity notifier, reports
    a deferred move again when it completes, and aligns the IRQ threads
    with the filtered mask; consumers which build a reverse map follow
    the programmed mask.
  - Patch 7 handles hotplug, suspend/resume replay and the CPU-online
    restore.
  - Patch 8 opts x86 APIC in, filters its vector fallbacks and marks
    the forwarding irqchips PASSTHROUGH.
  - Patch 9 publishes runtime isolation and documents the boundaries.
  - Patch 10 keeps the netdev core-managed affinity automatic and
    steers its ARFS map by the programmed mask while runtime isolation
    is active; it is the consumer of patches 3 and 6.

Runtime-isolated CPUs are detected as DOMAIN_BOOT - DOMAIN.  A mask
which still has an online target after that subtraction keeps its
boot-time isolcpus=domain CPUs, whether it was placed automatically or
explicitly.  Only when no online target remains may an automatically
placed IRQ fall back to online HK_TYPE_DOMAIN CPUs, preferring the
nodes the request covers and then irq_default_affinity and the device
node, so a queue hinted onto another socket is not pulled back.  The
x86 vector fallback
subtracts only the runtime set, so boot isolcpus=domain fallback
targets do not change; a CPU which is both boot-isolated and part of
an isolated partition is not in the runtime set either, so its
interrupt behaviour is unchanged.  The -ENOSPC retry in the core honours
irq_default_affinity first and then widens to the other online
HK_TYPE_DOMAIN CPUs, so a boot-time isolcpus=domain CPU is never used
as an emergency target and the request itself stays the last resort.

Automatic placement is tracked in a genirq-private IRQS_AFFINITY_AUTO
state bit in desc->istate rather than in a public IRQD bit or in
status_use_accessors: it is core-internal, survives
free_irq()/request_irq(), and irq_modify_status() cannot reach it.
Default placement, unmanaged affinity descriptors, the hint API
(irq_set_affinity_and_hint() and its deprecated alias) and the
core-only irq_set_affinity_auto() record automatic placement.  A bare
irq_set_affinity() is an explicit pin, the safe default for per-CPU
PMU, timer and architecture code; a driver which wants a queue to
follow the housekeeping set uses the hint API, so no driver has to
change.  IRQF_NOBALANCING is applied after the interrupt is activated,
so a default placement still starts on a housekeeping CPU; an explicit
request which was narrowed before the flag was applied is then
programmed again, because the filter is inert for a non-balancing
interrupt.  The replay runs through the regular affinity path, so a
chip which cannot move in process context reprograms it from interrupt
context.  It only runs while runtime isolation is active, on a chip
which opted in, for a request which was actually set and still has an
online target.  /proc writes and irq_force_affinity() are
explicit and are never redirected: while the mask keeps an online
non-isolated target the filter still subtracts the runtime-isolated
CPUs, but the request itself remains the last resort and is never
widened to CPUs outside it.  A default placement has no target of its
own and is still chosen among housekeeping CPUs when IRQF_NOBALANCING
is passed to request_irq(); a driver which pre-marks the IRQ with
irq_set_status_flags() skips both steps.

Per-CPU and managed interrupts are excluded.  The affinity notifier
keeps reporting the requested mask for the pending and programmed
paths, as it does upstream: a consumer which stores the notified mask
as the request (net/core does) must not be handed the filtered policy,
or removing the partition later cannot restore the CPU.  A consumer
which spreads work over several CPUs follows the mask the core asks
the chip to program, irq_copy_programmed_affinity(): the request minus
the runtime-isolated CPUs, or the automatic relocation.  The effective
affinity is deliberately not used there; on chips with
IRQD_SINGLE_TARGET it is one CPU, and a reverse map built from it would
collapse to a single entry.  Patch 10 converts net/core and
lib/cpu_rmap.c.  A driver which registers its own irq_affinity_notify
callback and steers hardware to a single CPU (bnxt TPH) is left
unchanged here; it keeps following the notified request, and
converting it needs a per-driver decision about which CPU actually
handles the interrupt.  The other custom callbacks (i40e's polling
check, the mask caches of ionic, funeth, hfi1, qla2xxx and qedf) are
left on the request for the same reason; only the reverse-map
consumers are converted.
The notifier is scheduled from the reapply path as well, and a deferred
move is reported when it is queued and again when the pending mask has
been programmed, so a consumer which follows the programmed mask
converges on the new target.  A CPU which enters isolation re-applies
the interrupts which have a notifier consumer even when the chip
already targets another member of the request, because the policy mask
lost that CPU and a reverse map has to drop it.  Without a notifier
nothing observes the change, so the chip is left alone.  An explicit mask which loses every
online target is not relocated and keeps its request.  When a CPU leaves a
partition the preserved request is handed to the irqchip again even if the
current effective mask still intersects it, so a chip which can place the
interrupt elsewhere includes the returning CPU and the notifier and the
IRQ threads see the restored request.  A single-target IRQ is no
exception: x86 marks its vector IRQs IRQD_SINGLE_TARGET, so the chip
keeps the current target, but the re-apply still restores the reverse
map and the thread mask.  A broad mask whose IRQs were all evicted to
one housekeeping CPU therefore stays there physically until a balancer
or an explicit affinity write moves it.  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 request becomes placeable again.  A CPU which returns
also completes an automatic fallback which had parked an interrupt
outside its requested mask after -ENOSPC.  A threaded IRQ escapes to
the requested mask when its delayed hardware move still points at a
runtime-isolated CPU; the move marks the IRQ threads when it is queued,
not only when it completes.  Reapply runs under cpuset_top_mutex ->
irq_isolation_mutex -> cpus_read_lock -> sparse_irq_lock -> desc->lock,
with the CPU hotplug read lock taken once around the static key update
and the reapply walk.

Points for maintainer feedback:

  - Placement provenance: a bare irq_set_affinity() is explicit, the
    hint API keeps automatic placement, and core code which manages an
    affinity on a driver's behalf uses irq_set_affinity_auto().  The
    helper is not exported and its only consumer is net/core (patch
    10), so no driver changes.  A tree-wide audit of all 69 bare
    irq_set_affinity() call sites confirms that none binds a
    multiqueue NIC queue (they are per-CPU PMU/timer/portal,
    irqchip/MSI-mux, or explicit management pins), whereas multiqueue
    drivers already use the hint API (129 call sites tree-wide, 69
    under drivers/net) or core-managed NAPI/PCI affinity.  Is that the
    preferred shape?

  - Hierarchy contract for IRQCHIP_AFFINITY_FILTERABLE.  Every level
    of the parent chain which implements .irq_set_affinity has to
    declare itself either FILTERABLE (the level which programs
    delivery) or PASSTHROUGH (a forwarder which derives no state from
    the mask); an unmarked level keeps filtering off for the whole
    chain.  This makes an unaudited domain default-off instead of
    inheriting the capability from its parent.  On x86 the vector
    domain is FILTERABLE and the IO-APIC, PCI-MSI, DMAR, HPET,
    INTEL-IR, AMD-IR and HYPERV-IR levels, the Hyper-V PCI MSI parents
    and the UV core domain are PASSTHROUGH.  ARM64/
    GICv3-ITS would have to mark the ITS level explicitly before it
    can be enabled.  Is this the
    contract you want, or should a delivery level be able to opt in on
    behalf of its children?

  - Trigger policy vs. genirq mechanism (LPC 2026 cgroup IRQ isolation
    discussions): this RFC wires the filter directly to runtime
    HK_TYPE_DOMAIN changes (DOMAIN_BOOT - DOMAIN) so existing
    cpuset.cpus.partition=isolated users get unmanaged IRQ eviction out
    of the box.  We are aware of the discussions around exposing a
    dedicated cgroup knob or a separate housekeeping type for IRQ
    isolation, and of the subsystem-specific queue management for
    networking.  The genirq filtering and x86 vector mechanics in
    patches 1 and 4-8 are intentionally decoupled from how the isolated
    mask is configured, and can be switched to a dedicated housekeeping
    mask or cgroup toggle with a contained change to
    housekeeping_runtime_isolated().

Testing:

  - x86_64 and ARM64 build with W=1 and no warnings in the touched
    files.
  - focused KVM test, 8 vCPUs, with isolcpus=domain,2 and also without
    boot-time isolcpus: automatic and explicit filtering, the
    boot-isolated mask preservation, the -ENOSPC fallback, the
    late-IRQF_NOBALANCING replay, the threaded IRQ escape, de-isolation
    restore, the explicit pin and the empty-effective-affinity case all
    pass.
  - a QEMU boot with intel-iommu,intremap=on and an e1000e NIC: a
    PCIe MSI-X IRQ behind INTEL-IR is moved off the isolated CPU when
    its request is widened to include that CPU, which exercises the
    FILTERABLE/PASSTHROUGH walk on the real PCI-MSI -> INTEL-IR ->
    vector chain.
  - scaling up to 4096 unmanaged filterable IRQs, all evicted from and
    restored to the isolated CPU, adds ~1 ms (~0.24 us/IRQ) over the
    ~8.5 ms no-IRQ baseline; the cpuset write path remains dominated by
    housekeeping_update().  Those are whole-request evictions: the
    fallback left them outside the request, so the chip moves them back
    on de-isolation.  A broad mask which was only narrowed is the case
    which is not re-spread.

Boundaries:

  - managed IRQs, queue reallocation and APIC vector compression are
    out of scope;
  - x86 APIC without interrupt remapping migrates on the next
    interrupt;
  - irqbalance must be disabled from boot: stopping it later does not
    restore the automatic placement of the single-CPU /proc pins it
    already wrote.  Writing a broad mask back keeps it explicit but
    still filters the runtime-isolated CPUs; only an IRQ whose entire
    online mask is isolated loses the fallback to other housekeeping
    CPUs.  A balancer which reads cpuset.cpus.isolated is the
    alternative; it cannot close the window in which a driver calls
    request_irq() or pci_alloc_irq_vectors() while the container is
    already running, and there is no balancer on a no-daemon edge
    system.  The kernel-side filter covers that window;
  - de-isolation hands the preserved request to the irqchip again and
    restores the reverse map, but does not force a re-spread.  A
    single-target IRQ (x86 marks its vector IRQs IRQD_SINGLE_TARGET)
    whose effective CPU is still in the request keeps that CPU, because
    the x86 vector code does not move an interrupt whose target is
    still valid; IRQs which were only narrowed (a broad mask evicted to
    one housekeeping CPU) stay there physically after the partition is
    gone, so a balancer which reads cpuset.cpus.isolated, or a new
    affinity write, is needed to spread them again.  An IRQ whose whole
    request was isolated is moved back, because the fallback left it
    outside the request;
  - on PREEMPT_RT the IRQ thread processes IRQTF_AFFINITY at the top of
    its wait loop and blocks in set_cpus_allowed_ptr() until it has
    been moved.  The wake-up is queued against the old scheduling
    affinity, so the thread can still be scheduled once on the isolated
    CPU before it migrates; the handler itself runs on the housekeeping
    CPU.  Keep latency-critical RT tasks at a higher real-time priority
    than the threaded IRQ default, or let the device settle before
    entering the critical loop;
  - only the x86 APIC vector chip opts in today; ARM64 is
    compile-tested only, GICv3/ITS does not opt in yet.

Kris Pan (10):
  genirq: Add IRQCHIP_AFFINITY_FILTERABLE flag
  sched/isolation: Add runtime isolation helpers
  genirq: Track automatic vs. explicit affinity provenance
  genirq: Filter unmanaged IRQ affinity against runtime isolation
  genirq: Reapply unmanaged IRQ affinity on isolation changes
  genirq: Align affinity notifiers and IRQ threads with isolation
  genirq: Handle runtime isolation across hotplug and suspend
  x86/apic: Support runtime IRQ isolation
  sched/isolation: Publish runtime isolation to genirq
  net: Keep core-managed IRQ affinity automatic

 Documentation/admin-guide/cpu-isolation.rst | 102 ++++
 arch/x86/hyperv/irqdomain.c                 |   4 +-
 arch/x86/kernel/apic/io_apic.c              |   6 +-
 arch/x86/kernel/apic/msi.c                  |   8 +-
 arch/x86/kernel/apic/vector.c               | 105 +++-
 arch/x86/kernel/hpet.c                      |   3 +-
 arch/x86/platform/uv/uv_irq.c               |   1 +
 drivers/iommu/amd/iommu.c                   |   1 +
 drivers/iommu/hyperv/hv-irq-remap-x86.c     |   2 +
 drivers/iommu/intel/irq_remapping.c         |   2 +
 drivers/pci/controller/pci-hyperv.c         |   2 +
 include/linux/interrupt.h                   |   8 +
 include/linux/irq.h                         |  54 ++
 include/linux/sched/isolation.h             |  42 ++
 kernel/irq/Makefile                         |   1 +
 kernel/irq/cpuhotplug.c                     |  12 +-
 kernel/irq/debugfs.c                        |   4 +
 kernel/irq/internals.h                      |  62 ++
 kernel/irq/irqdesc.c                        |  10 +
 kernel/irq/isolation.c                      | 623 ++++++++++++++++++++
 kernel/irq/manage.c                         | 385 ++++++++++--
 kernel/irq/migration.c                      |  10 +
 kernel/irq/pm.c                             |  15 +
 kernel/sched/isolation.c                    |  33 ++
 lib/cpu_rmap.c                              |  32 +-
 net/core/dev.c                              |  24 +-
 26 files changed, 1481 insertions(+), 70 deletions(-)
 create mode 100644 kernel/irq/isolation.c

-- 
2.43.0


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

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  3:36 Kris Pan [this message]
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 ` [RFC PATCH 09/10] sched/isolation: Publish runtime isolation to genirq Kris Pan
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-1-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