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=1796010012; b=a/FW8W5YlDp5gmvFxV+MclfhVF/eSsYoiMNzogxDkprLKqL15Q631ViMV6rJw5WvBfgr e8Xnr2MO3TBjgqavbGECa5kkXJgW5sm2g0ESWEdiJ8kBWQb78mM08w/SNZcwZiDwpCn5l nrG/K7m6FI0tKMWUlNjIAnNRdMtj9MskHTHk3FUYC0bbGXslL0fmsAEEiSzHb2W1rFIZ4 crdzAtDSEuZVGW7Mtba7eyNUwuH/HlOxNn2gfeGfwVpEfKGOWw3zwtjQfVBQexz9uK5+c RBUy8r1wO1o9ZsQFHzfc5RklV5mJmaDNzLGydXDtIyorz99e/6Eo/uJktQc/f89fXkQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796010012; 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:MIME-Version:Content-Transfer-Encoding; bh=SuubuYnsEQtEST6SJGuKJh9sWgdVU+luRgGuZEveN1c=; b=p1S8/SduiWTZN8YQ+DX1+2I8+FMOIYe/8QrLfnm8Cp/6nSt0rUbzZuTB0E9ZLfXo/c2M 7omYOJBkP/m3OuMTsJ+T8ZfYnnUoJGaYcZVHJ8v99COQkNdYKMMpHel+xSThn8/cGlGX4 a4iz8JECw3G08XH8YVT7Jy6yU0c60EUqJecXV93mrYr6q7BQKDX8b0/gGxjQUYEyKXHCt zuf27WTCLpK66jw2hGboNDFqsRWlBlWWlg4f/czJImV8LgEU7kQmeRb/FDVdSLLhveRG1 jlApz5fQsP45yj6fprMtadMuzWDAzxOl7tsZ1gny7Xa/suvWOuOmIh022S9+w2E5Jyg== 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=IZXGAoI9; 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 8D89B606A31C; Mon, 30 Nov 2026 03:40:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8D89B606A31C 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=IZXGAoI9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796010011; x=1827546011; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=4rBas+xP//LNV+9j+2Bnl707cPHqnFnhvvvcg+Azaac=; b=IZXGAoI9n+ionzUtZTwtl3Ea6LpKl12YE6lJwzy1RGRHTW7/qRgBPXR2 NbgFJEz+BISq0mEy10VyHSvL0l6liFYAyib7tNvcOAHjl6vdnQ44QN9Gs xjZ5fFMSwfeRmK1/qqxfjma4HJZx+hz6VL7QQ+ebJAPYIJXnHCFFLp4LP XA/nj8YRH+xPAMEGmhPU8vKEWnwLj8TSI5EGZkn1awHlkmPf0h2NxglYF VS7qvdinXICJB2HNfqmxFZkE+BmRT7z4EA2N7hsH7x8xdkvNf+mnDkAJw 9a8DmaOVpFPJPg0H9IMZRrzfQWm6lASBdMhavrWQAm7FjwTjzv/H4JEkT w==; X-CSE-ConnectionGUID: JMMJDRYrR2Odwg2PT28egQ== X-CSE-MsgGUID: KjCsXyaTR5aZpF1p3RcaAw== X-IronPort-AV: E=McAfee;i="6800,10657,11981"; a="4848202" X-IronPort-AV: E=Sophos;i="6.27,242,1787036400"; d="scan'208";a="4848202" 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:09 -0800 X-CSE-ConnectionGUID: R+Nek4YfQma7Mt8QaeXjsg== X-CSE-MsgGUID: cV24wSxiQ7+yOwgLup314Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,242,1787036400"; d="scan'208";a="12950956" 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:00 -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 00/10] genirq/cpuset: Evict unmanaged IRQs from runtime-isolated CPUs Date: Mon, 30 Nov 2026 11:36:58 +0800 Message-ID: <20261130033709.2704805-1-kris.pan@intel.com> X-Mailer: git-send-email 2.43.0 X-Mailing-List: linux-doc@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 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