[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v12 2/6] arm/irq: Migrate IRQs during CPU up/down operations


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Mykyta Poturai <Mykyta_Poturai@xxxxxxxx>
  • Date: Fri, 27 Nov 2026 11:45:26 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=yXPLYj9b75KDSmbYWzoS048WLaVkghtf/axPHG5t25Q=; b=Q56IZEnouLvfYtS9PpmkNMKaZXlcMP2KJ5tkmy9g1k9MH9i3P5DzC2cLtkAl9eKazVPXIhfF/uNwkfcT4orlmJJPWhyWC2/3dAnA4RloaXrIbMVhTYA3+rb4rSlxUn7sfSiPkmEGySF5vPQVSN+Wqqt6BLkwK5cp6CCyj3tEK9BeXOOmIS3tlAW8t/tYzoB2ApCIVK6gA+mdjtpujE77pY72u5h9ZTbMqCDL5G1EefKVixKg3zg4mEfckafZCk9Yw7S3JRcWnXNLENvRNijCmeva/y0agG6tZWvO8fVfb0XXTjSoBUZdwBhxMrP23vIult1twml7yqqdvwkt7ZtcBQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=hdzCybjiGmbQ2JZF0Gedn3zxgpV70Yt+bjgzbIVI3zl/yEq7earLOW0pq2Dcg42kCFCzrQJ2OyGytFdNOBFrU17Ecz2ZdVZgF/yjPAYl1qI1Zt9DOo0ewD3SJZh0qcqK0roLf46XgJywUVSfD4kiXrImGmUH1vfkt28PIZlhjl86x3NAxk8Kxf9RLdnEd53rm5CChkP7APR5OQjVC/05c+KEjNXqqsJygebmppW5TOkSolVVGwIMueostg+izt5SI+t+37EBIJi1qpGiwvJWUNVeBok9khgYWCAUevwIbXc/IPWXW5uAOd4jsmUgKCuL4gKc9rocQ0yTXjQiLxPhJQ==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=epam.com header.i="@epam.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:x-ms-exchange-senderadcheck"
  • Authentication-results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com;
  • Cc: Mykyta Poturai <Mykyta_Poturai@xxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Fri, 27 Nov 2026 11:45:40 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHdfmTL5aZmm45L5kGb0KDSIgy5dA==
  • Thread-topic: [PATCH v12 2/6] arm/irq: Migrate IRQs during CPU up/down operations

Move IRQs from dying CPU to the online ones when a CPU is getting
offlined. When onlining, rebalance all IRQs in a round-robin fashion.
Guest-bound IRQs are already handled by scheduler in the process of
moving vCPUs to active pCPUs, so we only need to handle IRQs used by Xen
itself.

The offline migration is done from the CPU_DYING notifier, on the dying
CPU before it calls PSCI CPU_OFF, as PSCI (DEN0022F.b 5.5.2) requires
all interrupts to be migrated away from a core before it is powered
down. At that point the dying CPU is still in cpu_online_map, so skip
it when picking the new target.

Signed-off-by: Mykyta Poturai <mykyta_poturai@xxxxxxxx>
Reviewed-by: Volodymyr Babchuk <volodymyr_babchuk@xxxxxxxx>
---
v11->v12:
* move the offline path to the CPU_DYING notifier, so IRQs are migrated
  before PSCI CPU_OFF

v10->v11:
* collect RB

v9->v10:
* make cpu_next static to balance_irq
* move the offline path to the CPU_DEAD notifier
* make rebalance_irqs static

v8->v9:
* replace CONFIG_CPU_HOTPLUG with CONFIG_CPU_ONLINE_OFFLINE

v7->v8:
* check only existings ESPIs

v6->v7:
* replace ifdef with IS_ENABLED

v5->v6:
* don't do any balancing on boot
* only do balancing when cpu hotplug is enabled

v4->v5:
* handle CPU onlining as well
* more comments
* fix crash when ESPI is disabled
* don't assume CPU 0 is a boot CPU
* use insigned int for irq number
* remove assumption that all irqs a bound to CPU 0 by default from the
  commit message

v3->v4:
* patch introduced
---
 xen/arch/arm/irq.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)

diff --git a/xen/arch/arm/irq.c b/xen/arch/arm/irq.c
index 19bb6f2f63..bfd47f7dc0 100644
--- a/xen/arch/arm/irq.c
+++ b/xen/arch/arm/irq.c
@@ -166,6 +166,66 @@ static int init_local_irq_data(unsigned int cpu)
     return 0;
 }
 
+static void balance_irq(int irq, unsigned int from, bool up)
+{
+    static int cpu_next;
+    struct irq_desc *desc = irq_to_desc(irq);
+    unsigned long flags;
+
+    ASSERT(!cpumask_empty(&cpu_online_map));
+
+    spin_lock_irqsave(&desc->lock, flags);
+    if ( likely(!desc->action) )
+        goto out;
+
+    if ( likely(test_bit(_IRQ_GUEST, &desc->status) ||
+                test_bit(_IRQ_MOVE_PENDING, &desc->status)) )
+        goto out;
+
+    /*
+     * Setting affinity to a mask of multiple CPUs causes the GIC drivers to
+     * select one CPU from that mask. If the dying CPU was included in the 
IRQ's
+     * affinity mask, we cannot determine exactly which CPU the interrupt is
+     * currently routed to, as GIC drivers lack a concrete get_affinity API. So
+     * to be safe we must reroute it to a new, definitely online, CPU. In the
+     * case of CPU going down, we move only the interrupt that could reside on
+     * it. Otherwise, we rearrange all interrupts in a round-robin fashion.
+     */
+    if ( !up && !cpumask_test_cpu(from, desc->affinity) )
+        goto out;
+
+    /*
+     * On the way down this runs from CPU_DYING, before __cpu_disable() drops
+     * the CPU from cpu_online_map. The boot CPU cannot be offlined, so there
+     * is always another target.
+     */
+    do
+        cpu_next = cpumask_cycle(cpu_next, &cpu_online_map);
+    while ( !up && cpu_next == from );
+
+    irq_set_affinity(desc, cpumask_of(cpu_next));
+
+out:
+    spin_unlock_irqrestore(&desc->lock, flags);
+}
+
+static void rebalance_irqs(unsigned int from, bool up)
+{
+    int irq;
+
+    if ( cpumask_empty(&cpu_online_map) )
+        return;
+
+    for ( irq = NR_LOCAL_IRQS; irq < NR_IRQS; irq++ )
+        balance_irq(irq, from, up);
+
+#ifdef CONFIG_GICV3_ESPI
+    for ( irq = ESPI_BASE_INTID; irq < ESPI_BASE_INTID + gic_number_espis();
+          irq++ )
+        balance_irq(irq, from, up);
+#endif
+}
+
 static int cpu_callback(struct notifier_block *nfb, unsigned long action,
                         void *hcpu)
 {
@@ -180,6 +240,16 @@ static int cpu_callback(struct notifier_block *nfb, 
unsigned long action,
             printk(XENLOG_ERR "Unable to allocate local IRQ for CPU%u\n",
                    cpu);
         break;
+    case CPU_ONLINE:
+        if ( IS_ENABLED(CONFIG_CPU_ONLINE_OFFLINE) &&
+             system_state >= SYS_STATE_active )
+            rebalance_irqs(cpu, true);
+        break;
+    case CPU_DYING:
+        /* PSCI requires interrupts to be migrated before CPU_OFF. */
+        if ( IS_ENABLED(CONFIG_CPU_ONLINE_OFFLINE) )
+            rebalance_irqs(cpu, false);
+        break;
     }
 
     return notifier_from_errno(rc);
-- 
2.56.1

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.