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

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


  • To: Mykyta Poturai <Mykyta_Poturai@xxxxxxxx>
  • From: Bertrand Marquis <Bertrand.Marquis@xxxxxxx>
  • Date: Tue, 24 Nov 2026 18:19:47 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 4.158.2.129) smtp.rcpttodomain=epam.com smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=arm.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com])
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=2; 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=tWiTd8I4xbjwAoFrwnVPddqOpQZ+lp9P27aoZDY2zJE=; b=ngTgJkWMr3SEzHAPvao21pW30q5FkACPo0tmEkh4py4yK+dyxou7XnLOGqeS5GkCAApTaB/YA2/pRqkJy9qq0VbD3C0yonxxDyfWigAd8AGeJ043x3Yv5QI4VpfjS4M4ubMztvftz77ZtRmiOTZlTXYZWyimNbmofAKx2+azqSQ1zN4l5Rl42v7NemZhQW4/v1ut55SHtTKaylEAxeoXXRVI6/mQIq/6bTc4tuh/vHy5Kp68kdYES60/dLX3jEfWN+DgY/E7ONT8+S4muK8E0s/uzuw+GMc/U6E6eF0RVIpEXO4rWbGoHpQnB7DwaYdPRHhalmUCJikWlvBO/sL+mA==
  • 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=tWiTd8I4xbjwAoFrwnVPddqOpQZ+lp9P27aoZDY2zJE=; b=q+0MKkLevkxg5zX1vc/dkrZtJZmYr8tmPFpDc5ROPreGhJzRfTwdq/09irhuxGabg92psxzwyZPh3NWrYDSmE6RhuSfepWR4Q1mwl7zalfOjHBnVK6quBpxVotEANoQ0zZWY195WyErJIQETSmQHgff+y569OdR9Zi/WgU5h8Zlm+hT1ans/T2ZcNhVeYZI723fUw6zwPmwnNkDDJRdeZJxZ6pOOr1spldOMz21aVi742GYQnbiAb+EmRh4b0iRT8FkXelK4JbA3wjcX+fIyKcd7KGwA5oc68xKCsmC/H1blmCirPKhioR0pvmtIeEbqy1IFt335jHu+9Ak0S4wVog==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=A41ddrDCAFcy/Qmc0fdJp0umpoD51KtpC9SCM77q+knxYTa/RWcCI3+6ul5c8/xOqdK99wea6xktYD906kLtAik9XT+balsypByYkyQQUmRxrjJdiC/xToDRV9RgU/SneHwSLA5C/Es4fCAos9WxfV3yDdPAyF+rH6fJrqBYISK1yartLZZ/sZ3+WC6rvRHJcw9vtsT/EuWoOKUKzJyS7kC7fLfm2NTNy3mYq1WWPegYHUxd8CFOd/hRDVio6GOCRzgohu1jyAFnX3G7wq3MxhzSYvHFuM9aVZ35OXaldozj+bPjtPCmTuU7G3msOZ4/aTuH1XJQMCAweeU5CrN1Eg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JZA2D3QpcwOrvOYuqZjoRcJxp/do+6HtrIpiC5hdGTApHLeEZFVwLEu1RybuovE+A8bfDevtQ850q1P+x32AbRTjJgkky1axubuZmGApV1uGEijXyuXJdMf26bIGrgZ8NGDsUWrd196k8fSIojASbnxvMHHOgbgFhRchgtTSHzlBs0tNWW/D90qVQbY/Z9OpbCJtl6Da1iju6sMPW5WCL5wTOVYh8PTpbNP/aB8dLodvhbnjWrcLZDyYAdzYGY52EGKe6dtmwCBTHe4Z0SDUP66S5Qs59tIXix/gQBDrfuvqzsZJcwi4d7SKubyNdr0bGCPToLZvpIeWULS3WGpyTw==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=arm.com header.i="@arm.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"; dkim=pass header.s=selector1 header.d=arm.com header.i="@arm.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results-original: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Tue, 24 Nov 2026 18:20:37 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Thread-index: AQHdcDtABYwI/ppPt0GzgWxLLvu3Xbc9oEOA
  • Thread-topic: [PATCH v11 2/6] arm/irq: Migrate IRQs during CPU up/down operations

Hi Mykyta,

> On 9 Nov 2026, at 11:12, Mykyta Poturai <Mykyta_Poturai@xxxxxxxx> wrote:
> 
> 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.
> 
> Signed-off-by: Mykyta Poturai <mykyta_poturai@xxxxxxxx>
> Reviewed-by: Volodymyr Babchuk <volodymyr_babchuk@xxxxxxxx>
> ---
> 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 | 61 ++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 61 insertions(+)
> 
> diff --git a/xen/arch/arm/irq.c b/xen/arch/arm/irq.c
> index 594aaedd22..d5145a4723 100644
> --- a/xen/arch/arm/irq.c
> +++ b/xen/arch/arm/irq.c
> @@ -166,6 +166,58 @@ 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;
> +
> +    cpu_next = cpumask_cycle(cpu_next, &cpu_online_map);
> +    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 +232,15 @@ 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_DEAD:
> +        if ( IS_ENABLED(CONFIG_CPU_ONLINE_OFFLINE) )
> +            rebalance_irqs(cpu, false);

This can rebalance the interrupts after the stopping CPU has called CPU_OFF
leaving cases where some interrupts could occur on the dying cpu core before
it is actually stopped. I think we need to find a way to rebalance the 
interrupts
before we call PSCI CPU_OFF. 

This is actually what is required by the PSCI specification which requires to 
migrate
interrupts before calling CPU_OFF (section 5.5.2).

Cheers
Bertrand

> +        break;
>     }
> 
>     return notifier_from_errno(rc);
> -- 
> 2.56.0




 


Rackspace

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