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=1796010092; b=2hPYSjVuAV40Vmf1JMwKjpu31jI1uSxSAysln5FVXsZ81/DUD+1fcLJPcjsZGDOfOnDh t0iZ2EReW445+DIoOI16H6N7maSGOgsqAYpV6NxdvPCNzMA+TSnpp6xemh/fzbwGyDqaV VBBMl+zsDt9YPSfDBvmBFYiBVG3XaS+IGEeL/cJHsRP7AIuCsjTPJIzz9+U126Ep8zQxC 7qCDAu15VgUt2wsqryH7wGusskzxajRx3rz0A6VNByNa9QO4xfw1Z6foyQpYS38HD7psA mtD8o65XMW7tnZ5qhuTTVJlDphxH/0z7rTd8OgIbUKLsBdi13+BtAr2dItu9g7MvCjA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796010092; 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=ItWayofy6WAtNAkKWDXpzaidX73J3y2qfqoslT/G/1s=; b=O/Y0LWSw2pJL3dJIXPa3EhT1fZpC4XMB9jbvceSQWIhhKztlQT/edBqkDvIS8aaOomXo ynuS17jrjKzoUE8Qc4OYA77VnAu5oGyy7UYfblZQe84U2hMVpv390pvW9Ic74Y4ovSkWY NC9VyEGM5gLylMrLwSHCFMz+cQnrkZLwLvSbB4sz8etsU5ef8UVD+xoibp4kZtAtzIkJV XafOPU3QpNUURYOQ9J5vG3jqY83ciczv/kdWfMmJS7G1japtTiuC27YXnJZ5HFgKX7o/R zvVVWgc/SqV7Tg/CvzI+JenNcRLiDgJrxl3TI7eb3YAB0u5c3v5J4xV004X1s2k9kBw== 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=VW12DeeE; 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 DCC47606A32D; Mon, 30 Nov 2026 03:41:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DCC47606A32D 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=VW12DeeE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796010092; x=1827546092; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hrchAVQe9QyGQPhpYPG/ViSSlKMgyDZ3ITtjJou+AQM=; b=VW12DeeERjy3pJYrPGU7Fe04pEwWfCryvYzhyI/zoJYw6taSeLGYjbc6 XNU+a6sRLpZ6XjAgiTpIDmqIy1U+REWE04/mSpes0EYBIVZuQJJqFhWd4 y8u4r+w5SlyYE9T3w4e+lBplwNYYxRzNwENjTX9/GChXBVIo0dOr/FiG2 RGPeyBNSvC6Kq8DCMl0bozEyQVxWWsiAv6TQZhfAQi+grsSYzsUsYmZKY LoGeJzfBXKb8+0HEvYjKornqMkMV19dwkquTKhxV0AqsBcRNQBUJfLKXN clOmIQDJAH+qQnDk4yEzPftVPG2Kc8jOv7Ne80I5FGVUR/5i6tO5F1szX A==; X-CSE-ConnectionGUID: oGJir4q4QI28Z+YlVbRvUw== X-CSE-MsgGUID: d0xASri5R0WFaVOGEmP8Lw== X-IronPort-AV: E=McAfee;i="6800,10657,11981"; a="4848446" X-IronPort-AV: E=Sophos;i="6.27,242,1787036400"; d="scan'208";a="4848446" 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:31 -0800 X-CSE-ConnectionGUID: 4Fi7JsS+THCXYbVr33qIyQ== X-CSE-MsgGUID: dPU+AkbzSHSrZg9X5u3+sQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,242,1787036400"; d="scan'208";a="12951111" Received: from pankris-x299-ud4-pro.bj.intel.com ([10.238.152.122]) by fmviesa005.fm.intel.com with ESMTP; 29 Nov 2026 19:41:22 -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 09/10] sched/isolation: Publish runtime isolation to genirq Date: Mon, 30 Nov 2026 11:37:07 +0800 Message-ID: <20261130033709.2704805-10-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: netdev@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 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 --- 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