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

Re: [PATCH v9 04/13] xen/arm: gic-v3: Implement GICv3 suspend/resume functions


  • To: Mykola Kvach <xakep.amatop@xxxxxxxxx>
  • From: Luca Fancellu <Luca.Fancellu@xxxxxxx>
  • Date: Wed, 13 May 2026 16:11:27 +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=gmail.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=v4Y94ojXJyOMFRiSC2FcNd1G6ixpJrmC7toPGQRbPGs=; b=DrLvd5v4U0Tb/q2gW5bP4HOdzRewQfpIiok3JM0enWxeY0Kb8RxBSC2JQamQjHvJgc1IXBjA/6aPocwRzjQle68fOc7qwBkT88m+9/YQ+B9JuGWpa7g8yLY1Wbph52Z+JI5X0Krst2CrrnTfZLufZ9Zvpz/AinHBhLG8V0JDghglRoJWBGkDtqpS6Ya+VngoavW524p3inYWtYpQB6a15YPPLQST0OV7xgvvmZm8MprB/lRRUKlygtahlR4RlXstmpyGq31x37T0d4Pd6al6nHNMFaM51wr3mizx+E0SPf+LC1X42YnOUADkfHyPvR6aUihjSfxAeXcr9CgVEyrILA==
  • 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=v4Y94ojXJyOMFRiSC2FcNd1G6ixpJrmC7toPGQRbPGs=; b=pHPEZRcUdxVAbcksZuyUutRKcg/fqSdqt0C58kZhnuPbshe2qx4GgvLRJT1eqEs2HjbnruDum9GAgHLDb6UQM1jQT1peG7BShOS5M/DaTPxmG6lZNTvFZyNv7zgt07Z7POluYz5r6gm9LAM5IaduzWgCyQ0FYi7x1TGeqHTT+OIKgQYU/P8Yjp3O+Pv2+LLuRwOtfhNBCkIsJmMtvZNgsYw9yWFOH7yKqTk1S2DGKHd3c54lIVPNIxIDw4hk8F7GYSgY9IyAnz/h8J+4BfzCBHL49sahhMy8dB8N/bIDWg97vcG1N/8BDRZYSflJXQN8yy+88UnJ5+Wc0n837QTvng==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=T4ENshZ7CzRp+o2By8wnrT/JfaADS+4YnRFISTsJOuE+Woo+XcDjIbQyAoAMGgfJPoimQeSTbgnAAH09qQk2h2TpfDPQeC6yRp3RaJt2GK2HD3LcutTQi/DL4oVTAs3zOEEXzqsm06Ncqr/+9YzxM+8Ctl3MKFEALV+bGutDmprg/nYIVnV4vemU9zyoO67QmacH7jrB7ZlzpYgP+MiX98aCNsYiTw654uhrwwBdeoT/K87+J1UL4fpYCZ6axPeU6iiQwQfR8x69M6qJhqdc0BGdGAXeYZbAcN6qAh3B0nCYHJVprvxRnMEgIB+B0pwgCibNNz1+LzZJoUvual5e9g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=hqw51gl8+IGaPsPVTP/+AYof4HCGt+DgTe5YG2LRbY6bPYYrnzyKrp2qIzCh+fkRc3x/jIZjFq8RvDXCVzBXh4dAIQNKEGMjOe5TDWs3FrmM7kSp1n7kokrugMxwgyGDN6soDMWvFPK3bO30rY6HVaJ0SsvsYYso7xhrBRR6bXs0kZqHGbyY77bapq4kz4NnojzvAvRBzWuqvGs6WviXWwPgbUkJxVYg7YmbTOamsBrQuy8znPjP2dblBRai0U2USEeqbMKm0OaJbu7gyQQZOEyxX5jM3Ignoszk3QAazL37myflPyeABj+3inBepBeSbfdKXITMjyQ8MUyQGcA8Yg==
  • 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: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Mykola Kvach <mykola_kvach@xxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Wed, 13 May 2026 16:12:53 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Thread-index: AQHc4jIxvmGdqMgSz02bPpb5zv+LMLYMIcWA
  • Thread-topic: [PATCH v9 04/13] xen/arm: gic-v3: Implement GICv3 suspend/resume functions

Hi Mykola,

> +}
> +
> +static int gicv3_disable_redist(void)
> +{
> +    void __iomem *waker = GICD_RDIST_BASE + GICR_WAKER;
> +    s_time_t deadline;
> +
> +    /*
> +     * Avoid infinite loop if Non-secure does not have access to GICR_WAKER.
> +     * See Arm IHI 0069H.b, 12.11.42 GICR_WAKER:
> +     *     When GICD_CTLR.DS == 0 and an access is Non-secure accesses to 
> this
> +     *     register are RAZ/WI.
> +     */
> +    if ( !(readl_relaxed(GICD + GICD_CTLR) & GICD_CTLR_DS) )
> +        return 0;
> +
> +    deadline = NOW() + MILLISECS(1000);
> +
> +    writel_relaxed(readl_relaxed(waker) | GICR_WAKER_ProcessorSleep, waker);
> +    while ( (readl_relaxed(waker) & GICR_WAKER_ChildrenAsleep) == 0 )
> +    {
> +        if ( NOW() > deadline )
> +        {
> +            printk("GICv3: Timeout waiting for redistributor to sleep\n");

I think here we should clear GICR_WAKER_ProcessorSleep, the Arm IHI 0069H.b, 
section
11.1 says that

“”"
When GICR_WAKER.ProcessorSleep == 1 or GICR_WAKER.ChildrenAsleep == 1 then a 
write to any GICC_*,
GICV_*, GICH_*, ICC_*, ICV_*, or ICH_* registers, other than those in the 
following list, is unpredictable:
• ICC_SRE_EL1.
• ICC_SRE_EL2.
• ICC_SRE_EL3
“""
But in the error path used in gicv3_suspend() we are writing ICH_HCR_EL2 and 
ICC_IGRPEN1_EL1.

> +            return -ETIMEDOUT;
> +        }
> +        cpu_relax();
> +        udelay(10);
> +    }
> +
> +    return 0;
> +}
> +
> +#define GET_SPI_REG_OFFSET(name, is_espi) \
> +    ((is_espi) ? GICD_##name##nE : GICD_##name)
> +
> +static void gicv3_store_spi_irq_block(struct dist_irq_block *irqs,
> +                                      unsigned int i, bool is_espi)
> +{
> +    void __iomem *base;
> +    unsigned int irq;
> +
> +    base = GICD + GET_SPI_REG_OFFSET(ICFGR, is_espi) + i * 
> sizeof(irqs->icfgr);
> +    irqs->icfgr[0] = readl_relaxed(base);
> +    irqs->icfgr[1] = readl_relaxed(base + 4);
> +
> +    base = GICD + GET_SPI_REG_OFFSET(IPRIORITYR, is_espi);
> +    base += i * sizeof(irqs->ipriorityr);
> +    for ( irq = 0; irq < ARRAY_SIZE(irqs->ipriorityr); irq++ )
> +        irqs->ipriorityr[irq] = readl_relaxed(base + 4 * irq);
> +
> +    base = GICD + GET_SPI_REG_OFFSET(IROUTER, is_espi);
> +    base += i * sizeof(irqs->irouter);
> +    for ( irq = 0; irq < ARRAY_SIZE(irqs->irouter); irq++ )
> +        irqs->irouter[irq] = readq_relaxed_non_atomic(base + 8 * irq);
> +
> +    base = GICD + GET_SPI_REG_OFFSET(ISACTIVER, is_espi);
> +    base += i * sizeof(irqs->isactiver);
> +    irqs->isactiver = readl_relaxed(base);
> +
> +    base = GICD + GET_SPI_REG_OFFSET(ISENABLER, is_espi);
> +    base += i * sizeof(irqs->isenabler);
> +    irqs->isenabler = readl_relaxed(base);
> +}
> +
> +static void gicv3_restore_spi_irq_config(struct dist_irq_block *irqs,
> +                                         unsigned int i, bool is_espi)
> +{
> +    void __iomem *base;
> +    unsigned int irq;
> +
> +    base = GICD + GET_SPI_REG_OFFSET(ICFGR, is_espi) + i * 
> sizeof(irqs->icfgr);
> +    writel_relaxed(irqs->icfgr[0], base);
> +    writel_relaxed(irqs->icfgr[1], base + 4);
> +
> +    base = GICD + GET_SPI_REG_OFFSET(IPRIORITYR, is_espi);
> +    base += i * sizeof(irqs->ipriorityr);
> +    for ( irq = 0; irq < ARRAY_SIZE(irqs->ipriorityr); irq++ )
> +        writel_relaxed(irqs->ipriorityr[irq], base + 4 * irq);
> +}
> +
> +static void gicv3_restore_spi_irq_routing(struct dist_irq_block *irqs,
> +                                          unsigned int i, bool is_espi)
> +{
> +    void __iomem *base;
> +    unsigned int irq;
> +
> +    base = GICD + GET_SPI_REG_OFFSET(IROUTER, is_espi);
> +    base += i * sizeof(irqs->irouter);
> +    for ( irq = 0; irq < ARRAY_SIZE(irqs->irouter); irq++ )
> +        writeq_relaxed_non_atomic(irqs->irouter[irq], base + 8 * irq);
> +}
> +
> +static void gicv3_restore_spi_irq_state(struct dist_irq_block *irqs,
> +                                        unsigned int i, bool is_espi)
> +{
> +    void __iomem *base;
> +
> +    base = GICD + GET_SPI_REG_OFFSET(ICENABLER, is_espi) + i * 4;
> +    writel_relaxed(GENMASK(31, 0), base);
> +
> +    base = GICD + GET_SPI_REG_OFFSET(ISENABLER, is_espi);
> +    base += i * sizeof(irqs->isenabler);
> +    writel_relaxed(irqs->isenabler, base);
> +
> +    base = GICD + GET_SPI_REG_OFFSET(ICACTIVER, is_espi) + i * 4;
> +    writel_relaxed(GENMASK(31, 0), base);
> +
> +    base = GICD + GET_SPI_REG_OFFSET(ISACTIVER, is_espi);
> +    base += i * sizeof(irqs->isactiver);
> +    writel_relaxed(irqs->isactiver, base);
> +}
> +
> +static int gicv3_suspend(void)
> +{
> +    unsigned int i;
> +    void __iomem *base;
> +    int ret;
> +    struct redist_ctx *rdist = &gicv3_ctx.rdist;
> +
> +    /* Save GICC configuration */
> +    gicv3_ctx.cpu.ctlr     = READ_SYSREG(ICC_CTLR_EL1);
> +    gicv3_ctx.cpu.pmr      = READ_SYSREG(ICC_PMR_EL1);
> +    gicv3_ctx.cpu.bpr      = READ_SYSREG(ICC_BPR1_EL1);
> +    gicv3_ctx.cpu.sre_el2  = READ_SYSREG(ICC_SRE_EL2);
> +    gicv3_ctx.cpu.grpen    = READ_SYSREG(ICC_IGRPEN1_EL1);
> +
> +    gicv3_disable_interface();

Should we check that ICC_AP1R<n>_EL1 == 0 before continuing our
suspend? Like we do in the GICv2?

> +
> +    ret = gicv3_disable_redist();
> +    if ( ret )
> +        goto out_enable_iface;
> +
> +    /* Save GICR configuration */
> +    gicv3_redist_wait_for_rwp();
> +
> +    base = GICD_RDIST_BASE;
> +
> +    rdist->ctlr = readl_relaxed(base + GICR_CTLR);
> +
> +    rdist->propbase = readq_relaxed(base + GICR_PROPBASER);
> +    rdist->pendbase = readq_relaxed(base + GICR_PENDBASER);
> +
> +    base = GICD_RDIST_SGI_BASE;
> +
> +    /* Save priority on PPI and SGI interrupts */
> +    for ( i = 0; i < NR_GIC_LOCAL_IRQS / 4; i++ )
> +        rdist->ipriorityr[i] = readl_relaxed(base + GICR_IPRIORITYR0 + 4 * 
> i);
> +
> +    rdist->isactiver = readl_relaxed(base + GICR_ISACTIVER0);
> +    rdist->isenabler = readl_relaxed(base + GICR_ISENABLER0);
> +    rdist->igroupr   = readl_relaxed(base + GICR_IGROUPR0);
> +    rdist->icfgr     = readl_relaxed(base + GICR_ICFGR1);
> +
> +    /* Save GICD configuration */
> +    gicv3_dist_wait_for_rwp();
> +    gicv3_ctx.dist.ctlr = readl_relaxed(GICD + GICD_CTLR);
> +
> +    for ( i = 1; i < DIV_ROUND_UP(gicv3_info.nr_lines, 32); i++ )
> +        gicv3_store_spi_irq_block(gicv3_ctx.dist.irqs + i - 1, i, false);
> +
> +#ifdef CONFIG_GICV3_ESPI
> +    for ( i = 0; i < gic_number_espis() / 32; i++ )
> +        gicv3_store_spi_irq_block(gicv3_ctx.dist.espi_irqs + i, i, true);
> +#endif
> +
> +    return 0;
> +
> + out_enable_iface:
> +    gicv3_hyp_enable(true);
> +    WRITE_SYSREG(gicv3_ctx.cpu.grpen, ICC_IGRPEN1_EL1);
> +    isb();
> +
> +    return ret;
> +}
> +
> +static void gicv3_resume(void)
> +{
> +    int ret;
> +    unsigned int i;
> +    uint32_t dist_ctlr;
> +    void __iomem *base;
> +    struct redist_ctx *rdist = &gicv3_ctx.rdist;
> +
> +    writel_relaxed(0, GICD + GICD_CTLR);
> +
> +    for ( i = NR_GIC_LOCAL_IRQS; i < gicv3_info.nr_lines; i += 32 )
> +        writel_relaxed(GENMASK(31, 0), GICD + GICD_IGROUPR + (i / 32) * 4);
> +
> +    for ( i = 1; i < DIV_ROUND_UP(gicv3_info.nr_lines, 32); i++ )
> +        gicv3_restore_spi_irq_config(gicv3_ctx.dist.irqs + i - 1, i, false);
> +
> +#ifdef CONFIG_GICV3_ESPI
> +    for ( i = 0; i < gic_number_espis() / 32; i++ )
> +    {
> +        writel_relaxed(GENMASK(31, 0), GICD + GICD_IGROUPRnE + i * 4);
> +        gicv3_restore_spi_irq_config(gicv3_ctx.dist.espi_irqs + i, i, true);
> +    }
> +#endif
> +
> +    dist_ctlr = gicv3_ctx.dist.ctlr & GICD_CTLR_ARE_NS;
> +    if ( dist_ctlr )
> +    {
> +        writel_relaxed(dist_ctlr, GICD + GICD_CTLR);
> +        gicv3_dist_wait_for_rwp();
> +
> +        for ( i = 1; i < DIV_ROUND_UP(gicv3_info.nr_lines, 32); i++ )
> +            gicv3_restore_spi_irq_routing(gicv3_ctx.dist.irqs + i - 1, i,
> +                                          false);

I think we have an issue in this loop as we are accessing 
GICD_IROUTER<1020…1023>
and GICD_IPRIORITYR255, while the specs says 1020…1023 are reserved and
GICD_IPRIORITYR<n> goes from 0 to 254. here and in the gicv3_suspend()

Cheers,
Luca


 


Rackspace

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