Add initial Xen Suspend-to-RAM support on ARM64
v7 cover Add initial Xen Suspend-to-RAM support on ARM64
From: Mykola Kvach <[email protected]>
This is part 2 of version 7 of the ARM Xen system suspend/resume patch series, based on earlier work by Mirela Simonovic and Mykyta Poturai.
The first part is here:
https://patchew.org/Xen/[email protected]/
NOTE: Most of the code is guarded by CONFIG_SYSTEM_SUSPEND, which can currently only be selected when UNSUPPORTED is set, and thus the functionality is neither enabled by default nor even built.
This version is ported to Xen master and includes extensive improvements based on reviewer feedback. The patch series restructures code to improve robustness, maintainability, and implements system Suspend-to-RAM support on ARM64 hardware/control domains.
Key updates in this series:
- Introduced architecture-specific suspend/resume infrastructure
- Integrated GICv2/GICv3 suspend and resume, including memory-backed context save/restore with error handling
- Added time and IRQ suspend/resume hooks, ensuring correct timer/interrupt state across suspend cycles
- Implemented proper PSCI SYSTEM_SUSPEND invocation and version checks
- Improved state management and recovery in error cases during suspend/resume
- Added support for IPMMU-VMSA/SMMUv3 context save/restore
- Added support for GICv3 eSPI registers context save/restore
- Added support for ITS registers context save/restore
---
TODOs:
- Enable "xl suspend" support on ARM
- Properly disable Xen timer watchdog from relevant services (only init.d left)
- Add suspend/resume CI test for ARM (QEMU if feasible)
---
Detailed changelogs can be found in each patch.
Changes in v7:
- Timer helper renamed/clarified; virtual/hyper/phys handling documented.
- GICv2 uses one context block; restore saved CTLR; panic on alloc failure.
- GICv3/eSPI/ITS always suspend/resume; restore LPI/eSPI; rdist timeout.
- IPMMU suspend context allocated before PCI setup.
- System suspend: control domain drives host suspend.
- Dropped v6 IRQ descriptor restore patches; use setup_irq and re-register local IRQs on resume instead.
For earlier changelogs, please refer to the previous cover letters.
Mirela Simonovic (6):
xen/arm: Add suspend and resume timer helpers
xen/arm: gic-v2: Implement GIC suspend/resume functions xen/arm: Resume memory management on Xen resume
xen/arm: Save/restore context on suspend/resume
xen/arm: Implement PSCI SYSTEM_SUSPEND call (host interface) xen/arm: Add support for system suspend triggered by control domain
Mykola Kvach (5):
xen/arm: gic-v3: Implement GICv3 suspend/resume functions xen/arm: gic-v3: add ITS suspend/resume support xen/arm: tee: keep init_tee_secondary() for hotplug and resume xen/arm: ffa: fix notification SRI across CPU hotplug/suspend arm/smmu-v3: add suspend/resume handlers
Oleksandr Tyshchenko (1):
iommu/ipmmu-vmsa: Implement suspend/resume callbacks
xen/arch/arm/Kconfig | 1 + xen/arch/arm/Makefile | 1 + xen/arch/arm/arm64/head.S | 112 ++++++++ xen/arch/arm/gic-v2.c | 126 +++++++++ xen/arch/arm/gic-v3-its.c | 91 +++++++ xen/arch/arm/gic-v3-lpi.c | 3 + xen/arch/arm/gic-v3.c | 332 ++++++++++++++++++++++- xen/arch/arm/gic.c | 29 ++ xen/arch/arm/include/asm/gic.h | 12 + xen/arch/arm/include/asm/gic_v3_defs.h | 1 + xen/arch/arm/include/asm/gic_v3_its.h | 23 ++ xen/arch/arm/include/asm/mm.h | 2 + xen/arch/arm/include/asm/psci.h | 1 + xen/arch/arm/include/asm/suspend.h | 31 +++ xen/arch/arm/include/asm/time.h | 5 + xen/arch/arm/mmu/smpboot.c | 2 +- xen/arch/arm/psci.c | 23 +- xen/arch/arm/suspend.c | 153 +++++++++++ xen/arch/arm/tee/ffa_notif.c | 63 ++++- xen/arch/arm/tee/tee.c | 2 +- xen/arch/arm/time.c | 44 ++- xen/arch/arm/vpsci.c | 12 +- xen/common/Kconfig | 5 + xen/common/domain.c | 7 +- xen/drivers/passthrough/arm/ipmmu-vmsa.c | 305 ++++++++++++++++++++- xen/drivers/passthrough/arm/smmu-v3.c | 170 +++++++++--- xen/drivers/passthrough/arm/smmu.c | 10 + xen/include/xen/list.h | 14 + 28 files changed, 1507 insertions(+), 73 deletions(-) create mode 100644 xen/arch/arm/suspend.c
Signature · 1 line
2.43.0
PATCH v7 1/12 xen/arm: Add suspend and resume timer helpers
From: Mirela Simonovic <[email protected]>
Timer interrupts must be disabled while the system is suspended to prevent spurious wake-ups. Suspending timers in Xen consists of disabling the physical timer and the hypervisor timer on the current CPU. The virtual timer does not need explicit handling here, as it is already disabled on vCPU context switch and its state is restored per-vCPU on the next context restore.
Resuming consists of raising TIMER_SOFTIRQ, which prompts the generic timer code to reprogram the hypervisor timer with the correct timeout.
Xen does not use or expose the physical timer, so it remains disabled across suspend/resume.
Introduce a new helper, disable_phys_hyp_timers(), to encapsulate disabling of the physical and hypervisor timers.
---
Changes in V7:
- Dropped EL1/EL2 wording; use "physical timer" and "hypervisor timer"
- Renamed helper to disable_phys_hyp_timers() to reflect its actual scope
- Clarified virtual timer handling (disabled on vCPU switch-out, restored on context restore) and added comments in suspend/resume paths
- Added resume comment explaining which timers are restored by TIMER_SOFTIRQ
--- xen/arch/arm/include/asm/time.h | 5 ++++ xen/arch/arm/time.c | 44 ++++++++++++++++++++++++++++----- 2 files changed, 43 insertions(+), 6 deletions(-)
xen/arch/arm/include/asm/time.h +5 -0
@@ -108,6 +108,11 @@ void preinit_xen_time(void);void force_update_vcpu_system_time (struct vcpu *v); +#ifdef CONFIG_SYSTEM_SUSPEND +void time_suspend (void ); +void time_resume (void ); +#endif /* CONFIG_SYSTEM_SUSPEND */ +#endif /* __ARM_TIME_H__ */ /* * Local variables:
xen/arch/arm/time.c +38 -6
68 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v7 01/12] xen/arm: Add suspend and resume timer helpers
Hi Mykola,
Quoted 15 lines · Mykola Kvach
From: Mirela Simonovic <[email protected]>
Timer interrupts must be disabled while the system is suspended to prevent spurious wake-ups. Suspending timers in Xen consists of disabling the physical timer and the hypervisor timer on the current CPU. The virtual timer does not need explicit handling here, as it is already disabled on vCPU context switch and its state is restored per-vCPU on the next context restore.
Resuming consists of raising
TIMER_SOFTIRQ, which prompts the generic timer code to reprogram the hypervisor timer with the correct timeout.Xen does not use or expose the physical timer, so it remains disabled across suspend/resume.
Quoted 6 lines
Introduce a new helper,
disable_phys_hyp_timers(), to encapsulate disabling of the physical and hypervisor timers.Signed-off-by Mirela Simonovic <[email protected]>Signed-off-by Saeed Nowshadi <[email protected]>Signed-off-by Mykola Kvach <[email protected]>
Cheers,
Signature · 1 line
Julien Grall
PATCH v7 2/12 xen/arm: gic-v2: Implement GIC suspend/resume functions
In reply to Mykola KvachFrom: Mirela Simonovic <[email protected]>
System suspend may lead to a state where GIC would be powered down. Therefore, Xen should save/restore the context of GIC on suspend/resume.
Note that the context consists of states of registers which are controlled by the hypervisor. Other GIC registers which are accessible by guests are saved/restored on context switch.
---
Changes in V7:
- Allocate one contiguous memory block for the GICv2 dist suspend context.
- gicv2_resume() no longer unconditionally re-enables the distributor/CPU interface; it now writes back the saved CTLR values as-is.
- gicv2_alloc_context() now returns 0 on success and panics on failure, since suspend context allocation is not recoverable.
--- xen/arch/arm/gic-v2.c | 126 +++++++++++++++++++++++++++++++++ xen/arch/arm/gic.c | 29 ++++++++ xen/arch/arm/include/asm/gic.h | 12 ++++ 3 files changed, 167 insertions(+)
xen/arch/arm/gic-v2.c +126 -0
@@ -1098,6 +1098,123 @@ static int gicv2_iomem_deny_access(struct domain *d)return iomem_deny_access (d, mfn, mfn + nr); } +#ifdef CONFIG_SYSTEM_SUSPEND + +/* This struct represent block of 32 IRQs */ +struct irq_block { +uint32_t icfgr[2 ];/* 2 registers of 16 IRQs each */ +uint32_t ipriorityr[8 ]; +uint32_t isenabler; +uint32_t isactiver; +uint32_t itargetsr[8 ]; +}; + +/* GICv2 registers to be saved/restored on system suspend/resume */ +struct gicv2_context { +/* GICC context */ +struct cpu_ctx { +uint32_t ctlr; +uint32_t pmr; +uint32_t bpr; + } cpu; + +/* GICD context */ +struct dist_ctx { +uint32_t ctlr; +struct irq_block *irqs; + } dist; +}; + +static struct gicv2_context gic_ctx; + +static int gicv2_suspend (void ) +{ +unsigned int i, blocks =DIV_ROUND_UP (gicv2_info.nr_lines,32 ); + +/* Save GICC configuration */ + gic_ctx.cpu.ctlr =readl_gicc (GICC_CTLR ); + gic_ctx.cpu.pmr =readl_gicc (GICC_PMR ); + gic_ctx.cpu.bpr =readl_gicc (GICC_BPR ); + +/* Save GICD configuration */ + gic_ctx.dist.ctlr =readl_gicd (GICD_CTLR ); + +for ( i =0 ; i < blocks; i++ ) + { +struct irq_block *irqs = gic_ctx.dist.irqs + i; +size_t j, off = i *sizeof (irqs->isenabler); + + irqs->isenabler =readl_gicd (GICD_ISENABLER + off); + irqs->isactiver =readl_gicd (GICD_ISACTIVER + off); + + off = i *sizeof (irqs->ipriorityr); +for ( j =0 ; j <ARRAY_SIZE (irqs->ipriorityr); j++ ) + { + irqs->ipriorityr[j] =readl_gicd (GICD_IPRIORITYR + off + j *4 ); + irqs->itargetsr[j] =readl_gicd (GICD_ITARGETSR + off + j *4 ); + } + + off = i *sizeof (irqs->icfgr); +for ( j =0 ; j <ARRAY_SIZE (irqs->icfgr); j++ ) + irqs->icfgr[j] =readl_gicd (GICD_ICFGR + off + j *4 ); + } + +return 0 ; +} + +static void gicv2_resume (void ) +{ +unsigned int i, blocks =DIV_ROUND_UP (gicv2_info.nr_lines,32 ); + +gicv2_cpu_disable (); +/* Disable distributor */ +writel_gicd (0 ,GICD_CTLR ); + +for ( i =0 ; i < blocks; i++ ) + { +struct irq_block *irqs = gic_ctx.dist.irqs + i; +size_t j, off = i *sizeof (irqs->isenabler); + +writel_gicd (0xffffffffU ,GICD_ICENABLER + off); +writel_gicd (irqs->isenabler,GICD_ISENABLER + off); + +writel_gicd (0xffffffffU ,GICD_ICACTIVER + off); +writel_gicd (irqs->isactiver,GICD_ISACTIVER + off); + + off = i *sizeof (irqs->ipriorityr); +for ( j =0 ; j <ARRAY_SIZE (irqs->ipriorityr); j++ ) + { +writel_gicd (irqs->ipriorityr[j],GICD_IPRIORITYR + off + j *4 ); +writel_gicd (irqs->itargetsr[j],GICD_ITARGETSR + off + j *4 ); + } + + off = i *sizeof (irqs->icfgr); +for ( j =0 ; j <ARRAY_SIZE (irqs->icfgr); j++ ) +writel_gicd (irqs->icfgr[j],GICD_ICFGR + off + j *4 ); + } + +/* Make sure all registers are restored and enable distributor */ +writel_gicd (gic_ctx.dist.ctlr,GICD_CTLR ); + +/* Restore GIC CPU interface configuration */ +writel_gicc (gic_ctx.cpu.pmr,GICC_PMR ); +writel_gicc (gic_ctx.cpu.bpr,GICC_BPR ); + +/* Enable GIC CPU interface */ +writel_gicc (gic_ctx.cpu.ctlr,GICC_CTLR ); +} + +static void __init gicv2_alloc_context (void ) +{ +uint32_t blocks =DIV_ROUND_UP (gicv2_info.nr_lines,32 ); + + gic_ctx.dist.irqs = xzalloc_array(struct irq_block, blocks); +if ( !gic_ctx.dist.irqs ) +panic ("Failed to allocate memory for GICv2 suspend context\n" ); +} + +#endif /* CONFIG_SYSTEM_SUSPEND */ +#ifdef CONFIG_ACPI static unsigned long gicv2_get_hwdom_extra_madt_size (const struct domain *d) {
@@ -1302,6 +1419,11 @@ static int __init gicv2_init(void)spin_unlock (&gicv2.lock); +#ifdef CONFIG_SYSTEM_SUSPEND +/* Allocate memory to be used for saving GIC context during the suspend */ +gicv2_alloc_context (); +#endif /* CONFIG_SYSTEM_SUSPEND */ +return 0 ; }
@@ -1345,6 +1467,10 @@ static const struct gic_hw_operations gicv2_ops = { .map_hwdom_extra_mappings = gicv2_map_hwdom_extra_mappings, .iomem_deny_access = gicv2_iomem_deny_access, .do_LPI = gicv2_do_LPI, +#ifdef CONFIG_SYSTEM_SUSPEND + .suspend = gicv2_suspend, + .resume = gicv2_resume, +#endif /* CONFIG_SYSTEM_SUSPEND */ };/* Set up the GIC */
xen/arch/arm/gic.c +29 -0
@@ -432,6 +432,35 @@ int gic_iomem_deny_access(struct domain *d)return gic_hw_ops->iomem_deny_access (d); } +#ifdef CONFIG_SYSTEM_SUSPEND + +int gic_suspend (void ) +{ +/* Must be called by boot CPU#0 with interrupts disabled */ +ASSERT (!local_irq_is_enabled ()); +ASSERT (!smp_processor_id ()); + +if ( !gic_hw_ops->suspend || !gic_hw_ops->resume ) +return -ENOSYS ; + +return gic_hw_ops->suspend (); +} + +void gic_resume (void ) +{ +/* +* Must be called by boot CPU#0 with interrupts disabled after gic_suspend +* has returned successfully. +*/ +ASSERT (!local_irq_is_enabled ()); +ASSERT (!smp_processor_id ()); +ASSERT (gic_hw_ops->resume); + + gic_hw_ops->resume (); +} + +#endif /* CONFIG_SYSTEM_SUSPEND */ +static int cpu_gic_callback (struct notifier_block *nfb,unsigned long action,void *hcpu)
xen/arch/arm/include/asm/gic.h +12 -0
@@ -280,6 +280,12 @@ extern int gicv_setup(struct domain *d);extern void gic_save_state (struct vcpu *v);extern void gic_restore_state (struct vcpu *v); +#ifdef CONFIG_SYSTEM_SUSPEND +/* Suspend/resume */ +extern int gic_suspend (void ); +extern void gic_resume (void ); +#endif /* CONFIG_SYSTEM_SUSPEND */ +/* SGI (AKA IPIs) */ enum gic_sgi {GIC_SGI_EVENT_CHECK ,
@@ -423,6 +429,12 @@ struct gic_hw_operations {int (*iomem_deny_access)(struct domain *d);/* Handle LPIs, which require special handling */ void (*do_LPI)(unsigned int lpi); +#ifdef CONFIG_SYSTEM_SUSPEND +/* Save GIC configuration due to the system suspend */ +int (*suspend)(void ); +/* Restore GIC configuration due to the system resume */ +void (*resume)(void ); +#endif /* CONFIG_SYSTEM_SUSPEND */ };extern const struct gic_hw_operations *gic_hw_ops;
Signature · 1 line
2.43.0
Re: [PATCH v7 02/12] xen/arm: gic-v2: Implement GIC suspend/resume functions
Hi Mykola,
Quoted 21 lines · Mykola Kvach
xen/arch/arm/gic-v2.c +13
-0@@ -1098,6 +1098,123 @@ static int gicv2_iomem_deny_access(struct domain *d)return iomem_deny_access (d, mfn, mfn + nr); } +#ifdef CONFIG_SYSTEM_SUSPEND + +/* This struct represent block of 32 IRQs */ +struct irq_block { +uint32_t icfgr[2 ];/* 2 registers of 16 IRQs each */ +uint32_t ipriorityr[8 ]; +uint32_t isenabler; +uint32_t isactiver; +uint32_t itargetsr[8 ]; +}; + +/* GICv2 registers to be saved/restored on system suspend/resume */ +struct gicv2_context {
xen/arch/arm/gic-v2.c static int gicv2_iomem_deny_access(struct domain *d) · line 1123
Quoted 10 lines
xen/arch/arm/gic-v2.c +10
-0+/* GICC context */ + struct cpu_ctx {> + uint32_t ctlr; +uint32_t pmr; +uint32_t bpr; + } cpu; + +/* GICD context */ +struct dist_ctx { +uint32_t ctlr; +struct irq_block *irqs;
To confirm my understanding, this will also include the PPIs, SGIs for the boot CPU, am I correct? If so, I would suggest to add a comment.
Quoted 6 lines
xen/arch/arm/gic-v2.c +6
-0+ } dist; +}; + +static struct gicv2_context gic_ctx; + +static int gicv2_suspend (void )
xen/arch/arm/gic-v2.c static int gicv2_iomem_deny_access(struct domain *d) · line 1140
Quoted 10 lines
xen/arch/arm/gic-v2.c +10
-0+{ +unsigned int i, blocks =DIV_ROUND_UP (gicv2_info.nr_lines,32 ); + +/* Save GICC configuration */ + gic_ctx.cpu.ctlr =readl_gicc (GICC_CTLR ); + gic_ctx.cpu.pmr =readl_gicc (GICC_PMR ); + gic_ctx.cpu.bpr =readl_gicc (GICC_BPR ); + +/* Save GICD configuration */ + gic_ctx.dist.ctlr =readl_gicd (GICD_CTLR );
Do we want to disable the GIC distributor and CPU interface on suspend?
Quoted 26 lines
xen/arch/arm/gic-v2.c +26
-0+ +for ( i =0 ; i < blocks; i++ ) + { +struct irq_block *irqs = gic_ctx.dist.irqs + i; +size_t j, off = i *sizeof (irqs->isenabler); + + irqs->isenabler =readl_gicd (GICD_ISENABLER + off); + irqs->isactiver =readl_gicd (GICD_ISACTIVER + off); + + off = i *sizeof (irqs->ipriorityr); +for ( j =0 ; j <ARRAY_SIZE (irqs->ipriorityr); j++ ) + { + irqs->ipriorityr[j] =readl_gicd (GICD_IPRIORITYR + off + j *4 ); + irqs->itargetsr[j] =readl_gicd (GICD_ITARGETSR + off + j *4 ); + } + + off = i *sizeof (irqs->icfgr); +for ( j =0 ; j <ARRAY_SIZE (irqs->icfgr); j++ ) + irqs->icfgr[j] =readl_gicd (GICD_ICFGR + off + j *4 ); + } + +return 0 ; +} + +static void gicv2_resume (void ) +{
xen/arch/arm/gic-v2.c static int gicv2_iomem_deny_access(struct domain *d) · line 1178
Quoted 10 lines
xen/arch/arm/gic-v2.c +10
-0+unsigned int i, blocks =DIV_ROUND_UP (gicv2_info.nr_lines,32 ); + +gicv2_cpu_disable (); + /* Disable distributor */> + writel_gicd(0, GICD_CTLR); +> + for ( i = 0; i < blocks; i++ ) + { +struct irq_block *irqs = gic_ctx.dist.irqs + i; +size_t j, off = i *sizeof (irqs->isenabler); + +writel_gicd (0xffffffffU ,GICD_ICENABLER + off);
NIT: Can we use GENMASK? This will make easier to confirm we have the correct number of bits.
[...]
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v7 02/12] xen/arm: gic-v2: Implement GIC suspend/resume functions
Hi Julien,
Thanks for the review.
Quoted 30 lines · Julien Grall
Hi Mykola,
Quoted 26 lines · Mykola Kvach
xen/arch/arm/gic-v2.c +18
-0@@ -1098,6 +1098,123 @@ static int gicv2_iomem_deny_access(struct domain *d)return iomem_deny_access (d, mfn, mfn + nr); } +#ifdef CONFIG_SYSTEM_SUSPEND + +/* This struct represent block of 32 IRQs */ +struct irq_block { + uint32_t icfgr[2]; /* 2 registers of 16 IRQs each */ + uint32_t ipriorityr[8]; + uint32_t isenabler; + uint32_t isactiver; + uint32_t itargetsr[8]; +}; + +/* GICv2 registers to be saved/restored on system suspend/resume */ +struct gicv2_context { + /* GICC context */ + struct cpu_ctx {> + uint32_t ctlr; + uint32_t pmr; + uint32_t bpr; + } cpu;
Quoted 8 lines
xen/arch/arm/gic-v2.c static int gicv2_iomem_deny_access(struct domain *d) · line 1124
Quoted 5 lines
xen/arch/arm/gic-v2.c +5
-0+ +/* GICD context */ +struct dist_ctx { +uint32_t ctlr; +struct irq_block *irqs;To confirm my understanding, this will also include the PPIs, SGIs for the boot CPU, am I correct? If so, I would suggest to add a comment.
Yes, correct. I’ll add a comment to make it explicit that this includes SGIs/PPIs for the boot CPU.
Quoted 11 lines
Quoted 11 lines
xen/arch/arm/gic-v2.c +10
-0+ } dist; +}; + +static struct gicv2_context gic_ctx; + +static int gicv2_suspend (void ) +{ +unsigned int i, blocks =DIV_ROUND_UP (gicv2_info.nr_lines,32 ); + +/* Save GICC configuration */
Quoted 8 lines
xen/arch/arm/gic-v2.c static int gicv2_iomem_deny_access(struct domain *d) · line 1140
Quoted 6 lines
xen/arch/arm/gic-v2.c +6
-0+ gic_ctx.cpu.ctlr =readl_gicc (GICC_CTLR ); + gic_ctx.cpu.pmr =readl_gicc (GICC_PMR ); + gic_ctx.cpu.bpr =readl_gicc (GICC_BPR ); + +/* Save GICD configuration */ + gic_ctx.dist.ctlr =readl_gicd (GICD_CTLR );Do we want to disable the GIC distributor and CPU interface on suspend?
I think we should quiesce the CPU interface after saving state, but not disable the distributor globally.
I still prefer not to disable GICD globally for safety on platforms where the wake request is routed from the GIC to the PMU/SCP (e.g. via nIRQOUT/nFIQOUT). So I’d quiesce GICC, keep GICD enabled.
Are you OK with this approach?
Quoted 32 lines
Quoted 32 lines
xen/arch/arm/gic-v2.c +31
-0+ +for ( i =0 ; i < blocks; i++ ) + { +struct irq_block *irqs = gic_ctx.dist.irqs + i; +size_t j, off = i *sizeof (irqs->isenabler); + + irqs->isenabler =readl_gicd (GICD_ISENABLER + off); + irqs->isactiver =readl_gicd (GICD_ISACTIVER + off); + + off = i *sizeof (irqs->ipriorityr); +for ( j =0 ; j <ARRAY_SIZE (irqs->ipriorityr); j++ ) + { + irqs->ipriorityr[j] =readl_gicd (GICD_IPRIORITYR + off + j *4 ); + irqs->itargetsr[j] =readl_gicd (GICD_ITARGETSR + off + j *4 ); + } + + off = i *sizeof (irqs->icfgr); +for ( j =0 ; j <ARRAY_SIZE (irqs->icfgr); j++ ) + irqs->icfgr[j] =readl_gicd (GICD_ICFGR + off + j *4 ); + } + +return 0 ; +} + +static void gicv2_resume (void ) +{ +unsigned int i, blocks =DIV_ROUND_UP (gicv2_info.nr_lines,32 ); + +gicv2_cpu_disable (); + /* Disable distributor */> + writel_gicd(0, GICD_CTLR); +> + for ( i = 0; i < blocks; i++ )
Quoted 8 lines
xen/arch/arm/gic-v2.c static int gicv2_iomem_deny_access(struct domain *d) · line 1178
Quoted 5 lines
xen/arch/arm/gic-v2.c +5
-0+ { +struct irq_block *irqs = gic_ctx.dist.irqs + i; +size_t j, off = i *sizeof (irqs->isenabler); + +writel_gicd (0xffffffffU ,GICD_ICENABLER + off);NIT: Can we use GENMASK? This will make easier to confirm we have the correct number of bits.
Sure, I'll change it to GENMASK
Best regards,
Mykola
Quoted 8 lines
[...]
Cheers,
--
Julien Grall
Re: [PATCH v7 02/12] xen/arm: gic-v2: Implement GIC suspend/resume functions
Quoted 67 lines · Mykola Kvach
Hi Julien,
Thanks for the review.
Quoted 30 lines · Julien Grall
Hi Mykola,
Quoted 26 lines · Mykola Kvach
xen/arch/arm/gic-v2.c +18
-0@@ -1098,6 +1098,123 @@ static int gicv2_iomem_deny_access(struct domain *d)return iomem_deny_access (d, mfn, mfn + nr); } +#ifdef CONFIG_SYSTEM_SUSPEND + +/* This struct represent block of 32 IRQs */ +struct irq_block { + uint32_t icfgr[2]; /* 2 registers of 16 IRQs each */ + uint32_t ipriorityr[8]; + uint32_t isenabler; + uint32_t isactiver; + uint32_t itargetsr[8]; +}; + +/* GICv2 registers to be saved/restored on system suspend/resume */ +struct gicv2_context { + /* GICC context */ + struct cpu_ctx {> + uint32_t ctlr; + uint32_t pmr; + uint32_t bpr; + } cpu;Quoted 8 lines
xen/arch/arm/gic-v2.c static int gicv2_iomem_deny_access(struct domain *d) · line 1124
Quoted 5 lines
xen/arch/arm/gic-v2.c +5
-0+ +/* GICD context */ +struct dist_ctx { +uint32_t ctlr; +struct irq_block *irqs;To confirm my understanding, this will also include the PPIs, SGIs for the boot CPU, am I correct? If so, I would suggest to add a comment.
Yes, correct. I’ll add a comment to make it explicit that this includes SGIs/PPIs for the boot CPU.
Quoted 11 lines
Quoted 11 lines
xen/arch/arm/gic-v2.c +10
-0+ } dist; +}; + +static struct gicv2_context gic_ctx; + +static int gicv2_suspend (void ) +{ +unsigned int i, blocks =DIV_ROUND_UP (gicv2_info.nr_lines,32 ); + +/* Save GICC configuration */ Quoted 8 lines
xen/arch/arm/gic-v2.c static int gicv2_iomem_deny_access(struct domain *d) · line 1140
Quoted 6 lines
xen/arch/arm/gic-v2.c +6
-0+ gic_ctx.cpu.ctlr =readl_gicc (GICC_CTLR ); + gic_ctx.cpu.pmr =readl_gicc (GICC_PMR ); + gic_ctx.cpu.bpr =readl_gicc (GICC_BPR ); + +/* Save GICD configuration */ + gic_ctx.dist.ctlr =readl_gicd (GICD_CTLR );Do we want to disable the GIC distributor and CPU interface on suspend?
Quoted 8 lines
I think we should quiesce the CPU interface after saving state, but not disable the distributor globally.
I still prefer not to disable GICD globally for safety on platforms where the wake request is routed from the GIC to the PMU/SCP (e.g. via nIRQOUT/nFIQOUT). So I’d quiesce GICC, keep GICD enabled.
Are you OK with this approach?
I have revisited the documentation and could not find a normative PSCI requirement to disable the GIC distributor.
PSCI 1.3, section 6.8 ("Preserving the execution context"), only says that some systems may power down the GIC distributor as part of SYSTEM_SUSPEND or a deep CPU_SUSPEND, in which case the relevant GIC state must be saved and restored. So PSCI acknowledges this as a possible platform behavior, but it does not appear to mandate it.
The stronger guidance seems to come from BSA. In Arm BSA 1.2 (DEN0094E), section 3.10, semantic E allows the GIC to be powered off after system software has saved its state. Table 8 shows semantic E with the GIC distributor Off, and Table 9 states that the GIC Distributor must be Off if all PEs are in the Off state.
Best regards,
Mykola
Quoted 56 lines
Quoted 33 lines
Quoted 33 lines
xen/arch/arm/gic-v2.c +31
-0+ +for ( i =0 ; i < blocks; i++ ) + { +struct irq_block *irqs = gic_ctx.dist.irqs + i; +size_t j, off = i *sizeof (irqs->isenabler); + + irqs->isenabler =readl_gicd (GICD_ISENABLER + off); + irqs->isactiver =readl_gicd (GICD_ISACTIVER + off); + + off = i *sizeof (irqs->ipriorityr); +for ( j =0 ; j <ARRAY_SIZE (irqs->ipriorityr); j++ ) + { + irqs->ipriorityr[j] =readl_gicd (GICD_IPRIORITYR + off + j *4 ); + irqs->itargetsr[j] =readl_gicd (GICD_ITARGETSR + off + j *4 ); + } + + off = i *sizeof (irqs->icfgr); +for ( j =0 ; j <ARRAY_SIZE (irqs->icfgr); j++ ) + irqs->icfgr[j] =readl_gicd (GICD_ICFGR + off + j *4 ); + } + +return 0 ; +} + +static void gicv2_resume (void ) +{ +unsigned int i, blocks =DIV_ROUND_UP (gicv2_info.nr_lines,32 ); + +gicv2_cpu_disable (); + /* Disable distributor */> + writel_gicd(0, GICD_CTLR); +> + for ( i = 0; i < blocks; i++ )Quoted 8 lines
xen/arch/arm/gic-v2.c static int gicv2_iomem_deny_access(struct domain *d) · line 1178
Quoted 5 lines
xen/arch/arm/gic-v2.c +5
-0+ { +struct irq_block *irqs = gic_ctx.dist.irqs + i; +size_t j, off = i *sizeof (irqs->isenabler); + +writel_gicd (0xffffffffU ,GICD_ICENABLER + off);NIT: Can we use GENMASK? This will make easier to confirm we have the correct number of bits.
Sure, I'll change it to GENMASK
Best regards,
MykolaQuoted 8 lines
[...]
Cheers,
--
Julien Grall
PATCH v7 3/12 xen/arm: gic-v3: Implement GICv3 suspend/resume functions
In reply to Mykola KvachFrom: Mykola Kvach <[email protected]>
System suspend may lead to a state where GIC would be powered down. Therefore, Xen should save/restore the context of GIC on suspend/resume.
Note that the context consists of states of registers which are controlled by the hypervisor. Other GIC registers which are accessible by guests are saved/restored on context switch.
---
Changes in V7:
- restore LPI regs on resume
- add timeout during redist disabling
- squash with suspend/resume handling for GICv3 eSPI registers
- drop ITS guard paths so suspend/resume always runs; switch missing ctx allocation to panic
- trim TODO comments; narrow redistributor storage to PPI icfgr
- keep distributor context allocation even without ITS; adjust resume to use GENMASK(31, 0) for clearing enables
- drop storage of the SGI configuration register, as SGIs are always edge-triggered
--- xen/arch/arm/gic-v3-lpi.c | 3 + xen/arch/arm/gic-v3.c | 319 ++++++++++++++++++++++++- xen/arch/arm/include/asm/gic_v3_defs.h | 1 + 3 files changed, 320 insertions(+), 3 deletions(-)
xen/arch/arm/gic-v3-lpi.c +3 -0
@@ -391,6 +391,9 @@ static int cpu_callback(struct notifier_block *nfb, unsigned long action,switch ( action ) {case CPU_UP_PREPARE : +if ( system_state == SYS_STATE_resume ) +break ; + rc =gicv3_lpi_allocate_pendtable (cpu);if ( rc ) printk(XENLOG_ERR "Unable to allocate the pendtable for CPU%lu\n",
xen/arch/arm/gic-v3.c +316 -3
353 lines not on this page · raw message
xen/arch/arm/include/asm/gic_v3_defs.h +1 -0
@@ -94,6 +94,7 @@#define GICD_TYPE_LPIS (1U << 17)#define GICD_CTLR_RWP (1UL << 31) +#define GICD_CTLR_DS (1U << 6)#define GICD_CTLR_ARE_NS (1U << 4)#define GICD_CTLR_ENABLE_G1A (1U << 1)#define GICD_CTLR_ENABLE_G1 (1U << 0)
Signature · 1 line
2.43.0
Re: [PATCH v7 03/12] xen/arm: gic-v3: Implement GICv3 suspend/resume functions
Hi Mykola,
Quoted 33 lines · Mykola Kvach
From: Mykola Kvach <[email protected]>
System suspend may lead to a state where GIC would be powered down. Therefore, Xen should save/restore the context of GIC on suspend/resume.
Note that the context consists of states of registers which are controlled by the hypervisor. Other GIC registers which are accessible by guests are saved/restored on context switch.
Signed-off-by Mykola Kvach <[email protected]>---
Changes in V7:
- restore LPI regs on resume
- add timeout during redist disabling
- squash with suspend/resume handling for GICv3 eSPI registers
- drop ITS guard paths so suspend/resume always runs; switch missing ctx allocation to panic
- trim TODO comments; narrow redistributor storage to PPI icfgr
- keep distributor context allocation even without ITS; adjust resume to useGENMASK(31, 0)for clearing enables
- drop storage of the SGI configuration register, as SGIs are always edge-triggered--- xen/arch/arm/gic-v3-lpi.c | 3 + xen/arch/arm/gic-v3.c | 319 ++++++++++++++++++++++++- xen/arch/arm/include/asm/gic_v3_defs.h | 1 + 3 files changed, 320 insertions(+), 3 deletions(-)xen/arch/arm/gic-v3-lpi.c +0
-0
xen/arch/arm/gic-v3-lpi.c static int cpu_callback(struct notifier_block *nfb, unsigned long action, · line 395
Quoted 5 lines
xen/arch/arm/gic-v3-lpi.c +2
-0@@ -391,6 +391,9 @@ static int cpu_callback(struct notifier_block *nfb, unsigned long action,switch ( action ) {case CPU_UP_PREPARE : +if ( system_state == SYS_STATE_resume ) +break ;
Do we need this check because we don't free the LPI pending table when the CPU is turned off?
If so, don't we already have a problem for CPU hotplug because the percpu area will be freed but not the pending table?
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v7 03/12] xen/arm: gic-v3: Implement GICv3 suspend/resume functions
Hi,
Quoted 45 lines · Julien Grall
Hi Mykola,
Quoted 36 lines · Mykola Kvach
From: Mykola Kvach <[email protected]>
System suspend may lead to a state where GIC would be powered down. Therefore, Xen should save/restore the context of GIC on suspend/resume.
Note that the context consists of states of registers which are controlled by the hypervisor. Other GIC registers which are accessible by guests are saved/restored on context switch.
Signed-off-by Mykola Kvach <[email protected]>---
Changes in V7:
- restore LPI regs on resume
- add timeout during redist disabling
- squash with suspend/resume handling for GICv3 eSPI registers
- drop ITS guard paths so suspend/resume always runs; switch missing ctx allocation to panic
- trim TODO comments; narrow redistributor storage to PPI icfgr
- keep distributor context allocation even without ITS; adjust resume to useGENMASK(31, 0)for clearing enables
- drop storage of the SGI configuration register, as SGIs are always edge-triggered
---
xen/arch/arm/gic-v3-lpi.c | 3 + xen/arch/arm/gic-v3.c | 319 ++++++++++++++++++++++++-xen/arch/arm/include/asm/gic_v3_defs.h| 1 +3 files changed, 320 insertions(+), 3 deletions(-)xen/arch/arm/gic-v3-lpi.c +0
-0@@ -391,6 +391,9 @@ static int cpu_callback(struct notifier_block *nfb, unsigned long action, switch ( action ) {Quoted 3 lines
case
CPU_UP_PREPARE:
+ if (system_state==SYS_STATE_resume)
+ break;Do we need this check because we don't free the LPI pending table when the CPU is turned off?
Quoted 1 line
If so, don't we already have a problem for CPU hotplug because the percpu area will be freed but not the pending table?
Looking at [1], we don't seem to support CPU OFF when the GICv3 ITS is enabled. So this change could be delayed. But CC Mykyta for awareness.
Cheers,
Quoted 3 lines
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v7 03/12] xen/arm: gic-v3: Implement GICv3 suspend/resume functions
Quoted 50 lines · Julien Grall
Hi,
Quoted 46 lines · Julien Grall
Hi Mykola,
Quoted 33 lines · Mykola Kvach
From: Mykola Kvach <[email protected]>
System suspend may lead to a state where GIC would be powered down. Therefore, Xen should save/restore the context of GIC on suspend/resume.
Note that the context consists of states of registers which are controlled by the hypervisor. Other GIC registers which are accessible by guests are saved/restored on context switch.
Signed-off-by Mykola Kvach <[email protected]>---
Changes in V7:
- restore LPI regs on resume
- add timeout during redist disabling
- squash with suspend/resume handling for GICv3 eSPI registers
- drop ITS guard paths so suspend/resume always runs; switch missing ctx allocation to panic
- trim TODO comments; narrow redistributor storage to PPI icfgr
- keep distributor context allocation even without ITS; adjust resume to useGENMASK(31, 0)for clearing enables
- drop storage of the SGI configuration register, as SGIs are always edge-triggered--- xen/arch/arm/gic-v3-lpi.c | 3 + xen/arch/arm/gic-v3.c | 319 ++++++++++++++++++++++++- xen/arch/arm/include/asm/gic_v3_defs.h | 1 + 3 files changed, 320 insertions(+), 3 deletions(-)xen/arch/arm/gic-v3-lpi.c +0
-0xen/arch/arm/gic-v3-lpi.c static int cpu_callback(struct notifier_block · line 396
Quoted 6 lines
xen/arch/arm/gic-v3-lpi.c +2
-0@@ -391,6 +391,9 @@ static int cpu_callback(struct notifier_block *nfb, unsigned long action, switch ( action ) {case CPU_UP_PREPARE : +if ( system_state == SYS_STATE_resume ) +break ;Do we need this check because we don't free the LPI pending table when the CPU is turned off?
Quoted 5 lines
Quoted 2 lines
If so, don't we already have a problem for CPU hotplug because the percpu area will be freed but not the pending table?
Looking at [1], we don't seem to support CPU OFF when the GICv3 ITS is enabled. So this change could be delayed. But CC Mykyta for awareness.
Probably you are right. Another option is to move this system_state == SYS_STATE_resume handling out of this change and into the follow-up commit where ITS suspend/resume support is introduced, so the rationale and behavior stay co-located with the suspend implementation.
If you think the better approach is to avoid these changes for now, I’m fine with that as well and can drop them in the next revision of the series (and reintroduce them together with the ITS suspend).
Thanks,
Mykola
Quoted 13 lines
Cheers,
Quoted 3 lines
Cheers,
--
Julien Grall
Re: [PATCH v7 03/12] xen/arm: gic-v3: Implement GICv3 suspend/resume functions
In reply to Julien GrallHi Julien,
Thank you for the review.
Quoted 32 lines · Julien Grall
Hi Mykola,
Quoted 28 lines · Mykola Kvach
From: Mykola Kvach <[email protected]>
System suspend may lead to a state where GIC would be powered down. Therefore, Xen should save/restore the context of GIC on suspend/resume.
Note that the context consists of states of registers which are controlled by the hypervisor. Other GIC registers which are accessible by guests are saved/restored on context switch.
Signed-off-by Mykola Kvach <[email protected]>---
Changes in V7:
- restore LPI regs on resume
- add timeout during redist disabling
- squash with suspend/resume handling for GICv3 eSPI registers
- drop ITS guard paths so suspend/resume always runs; switch missing ctx allocation to panic
- trim TODO comments; narrow redistributor storage to PPI icfgr
- keep distributor context allocation even without ITS; adjust resume to useGENMASK(31, 0)for clearing enables
- drop storage of the SGI configuration register, as SGIs are always edge-triggered--- xen/arch/arm/gic-v3-lpi.c | 3 + xen/arch/arm/gic-v3.c | 319 ++++++++++++++++++++++++- xen/arch/arm/include/asm/gic_v3_defs.h | 1 + 3 files changed, 320 insertions(+), 3 deletions(-)
Quoted 13 lines
xen/arch/arm/gic-v3-lpi.c static int cpu_callback(struct notifier_block *nfb, unsigned long action, · line 395
Quoted 10 lines
xen/arch/arm/gic-v3-lpi.c +2
-0@@ -391,6 +391,9 @@ static int cpu_callback(struct notifier_block *nfb, unsigned long action,switch ( action ) {case CPU_UP_PREPARE : +if ( system_state == SYS_STATE_resume ) +break ;Do we need this check because we don't free the LPI pending table when the CPU is turned off?
Yes. In the system suspend/resume case we intentionally keep the LPI pending table in RAM and reuse it after wake-up/CPU bring-up. The state is still stored in memory, so we do not need to save/restore it elsewhere; we just need to avoid allocating a new table on resume.
Quoted 3 lines
If so, don't we already have a problem for CPU hotplug because the percpu area will be freed but not the pending table?
System suspend/resume is a special case in Xen: system_state is transitioned during suspend, and the generic percpu allocator does not free/allocate percpu areas in that state (see [1] and [2]). As a result, the percpu storage (including the pointer to the pending table) remains intact across the suspend/resume cycle, and reusing the existing table is safe.
CPU hotplug is different: system_state remains in the normal running state, so percpu areas can be freed on CPU offline. In that scenario we should not rely on the “reuse on resume” logic; the pending table needs to be explicitly freed as part of the CPU teardown (otherwise it would indeed be leaked once the percpu pointer is gone). The check in this change is intended for suspend/resume, not for hotplug semantics.
[1] https://elixir.bootlin.com/xen/v4.21.0/source/xen/common/percpu.c#L36
[2] https://elixir.bootlin.com/xen/v4.21.0/source/xen/common/percpu.c#L88
Thanks,
Mykola
Quoted 6 lines
Cheers,
--
Julien Grall
PATCH v7 4/12 xen/arm: gic-v3: add ITS suspend/resume support
In reply to Mykola KvachFrom: Mykola Kvach <[email protected]>
Handle system suspend/resume for GICv3 with an ITS present so LPIs keep working after firmware powers the GIC down. Snapshot the CPU interface, distributor and last-CPU redistributor state, disable the ITS to cache its CTLR/CBASER/BASER registers, then restore everything and re-arm the collection on resume.
Add list_for_each_entry_continue_reverse() in list.h for the ITS suspend error path that needs to roll back partially saved state.
Based on Linux commit: dba0bc7b76dc ("irqchip/gic-v3-its: Add ability to save/restore ITS state")
--- xen/arch/arm/gic-v3-its.c | 91 +++++++++++++++++++++++++++ xen/arch/arm/gic-v3.c | 15 ++++- xen/arch/arm/include/asm/gic_v3_its.h | 23 +++++++ xen/include/xen/list.h | 14 +++++ 4 files changed, 140 insertions(+), 3 deletions(-)
xen/arch/arm/gic-v3-its.c +91 -0
@@ -1209,6 +1209,97 @@ int gicv3_its_init(void)return 0 ; } +#ifdef CONFIG_SYSTEM_SUSPEND +int gicv3_its_suspend (void ) +{ +struct host_its *its; +int ret; + +list_for_each_entry (its, &host_its_list, entry) + { +unsigned int i; +void __iomem *base = its->its_base; + + its->suspend_ctx.ctlr =readl_relaxed (base +GITS_CTLR ); + ret =gicv3_disable_its (its); +if ( ret ) + { +writel_relaxed (its->suspend_ctx.ctlr, base +GITS_CTLR ); + goto err; + } + + its->suspend_ctx.cbaser =readq_relaxed (base +GITS_CBASER ); + +for (i =0 ; i <GITS_BASER_NR_REGS ; i++) { +uint64_t baser =readq_relaxed (base +GITS_BASER0 + i *8 ); + +if ( !(baser &GITS_VALID_BIT ) ) +continue ; + + its->suspend_ctx.baser[i] = baser; + } + } + +return 0 ; + + err: +list_for_each_entry_continue_reverse (its, &host_its_list, entry) +writel_relaxed (its->suspend_ctx.ctlr, its->its_base +GITS_CTLR ); + +return ret; +} + +void gicv3_its_resume (void ) +{ +struct host_its *its; +int ret; + +list_for_each_entry (its, &host_its_list, entry) + { +void __iomem *base; +unsigned int i; + + base = its->its_base; + +/* +* Make sure that the ITS is disabled. If it fails to quiesce, +* don't restore it since writing to CBASER or BASER<n> +* registers is undefined according to the GIC v3 ITS +* Specification. +* +* Firmware resuming with the ITS enabled is terminally broken. +*/ +WARN_ON (readl_relaxed (base +GITS_CTLR ) &GITS_CTLR_ENABLE ); + ret =gicv3_disable_its (its); +if ( ret ) +continue ; + +writeq_relaxed (its->suspend_ctx.cbaser, base +GITS_CBASER ); + +/* +* Writing CBASER resets CREADR to 0, so make CWRITER and +* cmd_write line up with it. +*/ +writeq_relaxed (0 , base +GITS_CWRITER ); + +/* Restore GITS_BASER from the value cache. */ +for (i =0 ; i <GITS_BASER_NR_REGS ; i++) { +uint64_t baser = its->suspend_ctx.baser[i]; + +if ( !(baser &GITS_VALID_BIT ) ) +continue ; + +writeq_relaxed (baser, base +GITS_BASER0 + i *8 ); + } +writel_relaxed (its->suspend_ctx.ctlr, base +GITS_CTLR ); + } + + ret =gicv3_its_setup_collection (smp_processor_id ()); +if ( ret ) +panic ("GICv3: ITS: resume setup collection failed: %d\n" , ret); +} + +#endif /* CONFIG_SYSTEM_SUSPEND */ /* * Local variables:
xen/arch/arm/gic-v3.c +12 -3
@@ -857,7 +857,7 @@ static bool gicv3_enable_lpis(void)return true; } -static int __init gicv3_populate_rdist (void ) +static int gicv3_populate_rdist (void ) {int i;uint32_t aff;
@@ -927,7 +927,7 @@ static int __init gicv3_populate_rdist(void) ret =gicv3_lpi_init_rdist (ptr);if ( ret && ret != -ENODEV ) { -printk ("GICv3: CPU%d: Cannot initialize LPIs: %u\n" , +printk ("GICv3: CPU%d: Cannot initialize LPIs: %d\n" ,smp_processor_id (), ret);break ; }
@@ -2096,9 +2096,13 @@ static int gicv3_suspend(void)gicv3_disable_interface (); + ret =gicv3_its_suspend (); +if ( ret ) + goto out_enable_iface; + ret =gicv3_disable_redist ();if ( ret ) -return out_enable_iface; + goto out_its_resume;/* Save GICR configuration */ gicv3_redist_wait_for_rwp ();
@@ -2133,6 +2137,9 @@ static int gicv3_suspend(void)return 0 ; + out_its_resume: +gicv3_its_resume (); + out_enable_iface:gicv3_hyp_enable (true);WRITE_SYSREG (gicv3_ctx.cpu.ctlr,ICC_CTLR_EL1 );
@@ -2205,6 +2212,8 @@ static void gicv3_resume(void)gicv3_redist_wait_for_rwp (); +gicv3_its_resume (); +WRITE_SYSREG (gicv3_ctx.cpu.sre_el2,ICC_SRE_EL2 );isb ();
xen/arch/arm/include/asm/gic_v3_its.h +23 -0
@@ -129,6 +129,13 @@ struct host_its {spinlock_t cmd_lock;void *cmd_buf;unsigned int flags; +#ifdef CONFIG_SYSTEM_SUSPEND +struct suspend_ctx { +uint32_t ctlr; +uint64_t cbaser; +uint64_t baser[GITS_BASER_NR_REGS ]; + } suspend_ctx; +#endif };/* Map a collection for this host CPU to each host ITS. */
@@ -204,6 +211,11 @@ uint64_t gicv3_its_get_cacheability(void);uint64_t gicv3_its_get_shareability (void );unsigned int gicv3_its_get_memflags (void ); +#ifdef CONFIG_SYSTEM_SUSPEND +int gicv3_its_suspend (void ); +void gicv3_its_resume (void ); +#endif +#else #ifdef CONFIG_ACPI
@@ -271,6 +283,17 @@ static inline int gicv3_its_make_hwdom_dt_nodes(const struct domain *d,return 0 ; } +#ifdef CONFIG_SYSTEM_SUSPEND +static inline int gicv3_its_suspend (void ) +{ +return 0 ; +} + +static inline void gicv3_its_resume (void ) +{ +} +#endif +#endif /* CONFIG_HAS_ITS */ #endif
xen/include/xen/list.h +14 -0
@@ -535,6 +535,20 @@ static inline void list_splice_init(struct list_head *list, &(pos)->member != (head); \ (pos) = list_entry((pos)->member.next, typeof(*(pos)), member)) +/** +* list_for_each_entry_continue_reverse - iterate backwards from the given point +* @pos: the type * to use as a loop cursor. +* @head: the head for your list. +* @member: the name of the list_head within the struct. +* +* Start to iterate over list of given type backwards, continuing after +* the current position. +*/ +#define list_for_each_entry_continue_reverse (pos, head, member) \ + for ((pos) = list_entry((pos)->member.prev, typeof(*(pos)), member); \ + &(pos)->member != (head); \ + (pos) = list_entry((pos)->member.prev, typeof(*(pos)), member)) +/** * list_for_each_entry_from - iterate over list of given type from the * current point
Signature · 1 line
2.43.0
Re: [PATCH v7 04/12] xen/arm: gic-v3: add ITS suspend/resume support
Quoted 13 lines · Mykola Kvach
xen/include/xen/list.h +7
-0@@ -535,6 +535,20 @@ static inline void list_splice_init(struct list_head *list, &(pos)->member != (head); \ (pos) = list_entry((pos)->member.next, typeof(*(pos)), member)) +/** +* list_for_each_entry_continue_reverse - iterate backwards from the given point +* @pos: the type * to use as a loop cursor. +* @head: the head for your list. +* @member: the name of the list_head within the struct. +* +* Start to iterate over list of given type backwards, continuing after
xen/include/xen/list.h static inline void list_splice_init(struct list_head *list, · line 554
Quoted 10 lines
xen/include/xen/list.h +7
-0+* the current position. +*/ +#define list_for_each_entry_continue_reverse (pos, head, member) \ + for ((pos) = list_entry((pos)->member.prev, typeof(*(pos)), member); \ + &(pos)->member != (head); \ + (pos) = list_entry((pos)->member.prev, typeof(*(pos)), member)) +/** * list_for_each_entry_from - iterate over list of given type from the * current point
While not said so anywhere, I understand this is taken from Linux. Maybe we should indeed take it verbatim (as far as possible, i.e. without the use of list_entry_is_head() which we don't have yet), but I'd like to point out that in the comment "continuing after the current position" is ambiguous. In list order, what is meant is "before the current position"; "after" is correct only when considering iteration direction. Personally I would much prefer if this was disambiguated.
Jan
Re: [PATCH v7 04/12] xen/arm: gic-v3: add ITS suspend/resume support
Hi Jan,
Thank you for the review.
Quoted 26 lines · Jan Beulich
Quoted 13 lines · Mykola Kvach
xen/include/xen/list.h +7
-0@@ -535,6 +535,20 @@ static inline void list_splice_init(struct list_head *list, &(pos)->member != (head); \ (pos) = list_entry((pos)->member.next, typeof(*(pos)), member)) +/** +* list_for_each_entry_continue_reverse - iterate backwards from the given point +* @pos: the type * to use as a loop cursor. +* @head: the head for your list. +* @member: the name of the list_head within the struct. +* +* Start to iterate over list of given type backwards, continuing after xen/include/xen/list.h static inline void list_splice_init(struct list_head *list, · line 554
Quoted 10 lines
xen/include/xen/list.h +7
-0+* the current position. +*/ +#define list_for_each_entry_continue_reverse (pos, head, member) \ + for ((pos) = list_entry((pos)->member.prev, typeof(*(pos)), member); \ + &(pos)->member != (head); \ + (pos) = list_entry((pos)->member.prev, typeof(*(pos)), member)) +/** * list_for_each_entry_from - iterate over list of given type from the * current point
Quoted 7 lines
While not said so anywhere, I understand this is taken from Linux. Maybe we should indeed take it verbatim (as far as possible, i.e. without the use of
list_entry_is_head()which we don't have yet), but I'd like to point out that in the comment "continuing after the current position" is ambiguous. In list order, what is meant is "before the current position"; "after" is correct only when considering iteration direction. Personally I would much prefer if this was disambiguated.
Got it. I’ll disambiguate the wording while keeping it close to the Linux text, e.g.:
“Start to iterate over list of given type backwards, continuing with the entry preceding the current position (i.e. starting from pos->member.prev).”
Best regards,
Mykola
Quoted 2 lines
Jan
Re: [PATCH v7 04/12] xen/arm: gic-v3: add ITS suspend/resume support
In reply to Mykola KvachOn 11.12.25 20:43, Mykola Kvach wrote:
Hello Mykola
Quoted 82 lines
From: Mykola Kvach <[email protected]>
Handle system suspend/resume for GICv3 with an ITS present so LPIs keep working after firmware powers the GIC down. Snapshot the CPU interface, distributor and last-CPU redistributor state, disable the ITS to cache its CTLR/CBASER/BASER registers, then restore everything and re-arm the collection on resume.
Add
list_for_each_entry_continue_reverse()inlist.hfor the ITS suspend error path that needs to roll back partially saved state.Based on Linux commit:
dba0bc7b76dc("irqchip/gic-v3-its: Add ability to save/restore ITS state")Signed-off-by Mykola Kvach <[email protected]>--- xen/arch/arm/gic-v3-its.c | 91 +++++++++++++++++++++++++++ xen/arch/arm/gic-v3.c | 15 ++++- xen/arch/arm/include/asm/gic_v3_its.h | 23 +++++++ xen/include/xen/list.h | 14 +++++ 4 files changed, 140 insertions(+), 3 deletions(-)xen/arch/arm/gic-v3-its.c +54
-0@@ -1209,6 +1209,97 @@ int gicv3_its_init(void)return 0 ; } +#ifdef CONFIG_SYSTEM_SUSPEND +int gicv3_its_suspend (void ) +{ +struct host_its *its; +int ret; + +list_for_each_entry (its, &host_its_list, entry) + { +unsigned int i; +void __iomem *base = its->its_base; + + its->suspend_ctx.ctlr =readl_relaxed (base +GITS_CTLR ); + ret =gicv3_disable_its (its); +if ( ret ) + { +writel_relaxed (its->suspend_ctx.ctlr, base +GITS_CTLR ); + goto err; + } + + its->suspend_ctx.cbaser =readq_relaxed (base +GITS_CBASER ); + +for (i =0 ; i <GITS_BASER_NR_REGS ; i++) { +uint64_t baser =readq_relaxed (base +GITS_BASER0 + i *8 ); + +if ( !(baser &GITS_VALID_BIT ) ) +continue ; + + its->suspend_ctx.baser[i] = baser; + } + } + +return 0 ; + + err: +list_for_each_entry_continue_reverse (its, &host_its_list, entry) +writel_relaxed (its->suspend_ctx.ctlr, its->its_base +GITS_CTLR ); + +return ret; +} + +void gicv3_its_resume (void ) +{ +struct host_its *its; +int ret; + +list_for_each_entry (its, &host_its_list, entry) + { +void __iomem *base; +unsigned int i; + + base = its->its_base; + +/* +* Make sure that the ITS is disabled. If it fails to quiesce,
xen/arch/arm/gic-v3-its.c int gicv3_its_init(void) · line 1275
Quoted 10 lines
xen/arch/arm/gic-v3-its.c +10
-0+* don't restore it since writing to CBASER or BASER<n> +* registers is undefined according to the GIC v3 ITS +* Specification. +* +* Firmware resuming with the ITS enabled is terminally broken. +*/ +WARN_ON (readl_relaxed (base +GITS_CTLR ) &GITS_CTLR_ENABLE ); + ret =gicv3_disable_its (its); +if ( ret ) +continue ;
If ITS fails to disable (quiesce), the code skips restoration and ITS remains in an unconfigured state. However, immediately after the loop ...
xen/arch/arm/gic-v3-its.c int gicv3_its_init(void) · line 1281
Quoted 6 lines
xen/arch/arm/gic-v3-its.c +6
-0+ +writeq_relaxed (its->suspend_ctx.cbaser, base +GITS_CBASER ); + +/* +* Writing CBASER resets CREADR to 0, so make CWRITER and +* cmd_write line up with it.
NIT: The variable "cmd_write" does not exist in the Xen driver. As I understand, this comment was ported from the Linux kernel driver as is, which maintains a software shadow copy of the write pointer named "cmd_write".
Quoted 6 lines
xen/arch/arm/gic-v3-its.c +6
-0+*/ +writeq_relaxed (0 , base +GITS_CWRITER ); + +/* Restore GITS_BASER from the value cache. */ +for (i =0 ; i <GITS_BASER_NR_REGS ; i++) { +uint64_t baser = its->suspend_ctx.baser[i];
xen/arch/arm/gic-v3-its.c int gicv3_its_init(void) · line 1297
Quoted 10 lines
xen/arch/arm/gic-v3-its.c +10
-0+ +if ( !(baser &GITS_VALID_BIT ) ) +continue ; + +writeq_relaxed (baser, base +GITS_BASER0 + i *8 ); + } +writel_relaxed (its->suspend_ctx.ctlr, base +GITS_CTLR ); + } + + ret =gicv3_its_setup_collection (smp_processor_id ());
... this function iterates over all host ITS instances (including the
one we skipped) and attempts to send MAPC commands. I am afraid, that
attempting to write to the command queue of an uninitialized/unrestored ITS might have bad consequences.
Quoted 6 lines
xen/arch/arm/gic-v3-its.c +5
-0+if ( ret ) + panic("GICv3: ITS: resume setup collection failed: %d\n", ret); +} + +#endif /* CONFIG_SYSTEM_SUSPEND */
[snip]
Re: [PATCH v7 04/12] xen/arm: gic-v3: add ITS suspend/resume support
Hi Oleksandr,
Thanks for the review.
Quoted 104 lines · Oleksandr Tyshchenko
On 11.12.25 20:43, Mykola Kvach wrote:
Hello Mykola
Quoted 82 lines
From: Mykola Kvach <[email protected]>
Handle system suspend/resume for GICv3 with an ITS present so LPIs keep working after firmware powers the GIC down. Snapshot the CPU interface, distributor and last-CPU redistributor state, disable the ITS to cache its CTLR/CBASER/BASER registers, then restore everything and re-arm the collection on resume.
Add
list_for_each_entry_continue_reverse()inlist.hfor the ITS suspend error path that needs to roll back partially saved state.Based on Linux commit:
dba0bc7b76dc("irqchip/gic-v3-its: Add ability to save/restore ITS state")Signed-off-by Mykola Kvach <[email protected]>--- xen/arch/arm/gic-v3-its.c | 91 +++++++++++++++++++++++++++ xen/arch/arm/gic-v3.c | 15 ++++- xen/arch/arm/include/asm/gic_v3_its.h | 23 +++++++ xen/include/xen/list.h | 14 +++++ 4 files changed, 140 insertions(+), 3 deletions(-)xen/arch/arm/gic-v3-its.c +54
-0@@ -1209,6 +1209,97 @@ int gicv3_its_init(void)return 0 ; } +#ifdef CONFIG_SYSTEM_SUSPEND +int gicv3_its_suspend (void ) +{ +struct host_its *its; +int ret; + +list_for_each_entry (its, &host_its_list, entry) + { +unsigned int i; +void __iomem *base = its->its_base; + + its->suspend_ctx.ctlr =readl_relaxed (base +GITS_CTLR ); + ret =gicv3_disable_its (its); +if ( ret ) + { +writel_relaxed (its->suspend_ctx.ctlr, base +GITS_CTLR ); + goto err; + } + + its->suspend_ctx.cbaser =readq_relaxed (base +GITS_CBASER ); + +for (i =0 ; i <GITS_BASER_NR_REGS ; i++) { +uint64_t baser =readq_relaxed (base +GITS_BASER0 + i *8 ); + +if ( !(baser &GITS_VALID_BIT ) ) +continue ; + + its->suspend_ctx.baser[i] = baser; + } + } + +return 0 ; + + err: +list_for_each_entry_continue_reverse (its, &host_its_list, entry) +writel_relaxed (its->suspend_ctx.ctlr, its->its_base +GITS_CTLR ); + +return ret; +} + +void gicv3_its_resume (void ) +{ +struct host_its *its; +int ret; + +list_for_each_entry (its, &host_its_list, entry) + { +void __iomem *base; +unsigned int i; + + base = its->its_base; + +/* +* Make sure that the ITS is disabled. If it fails to quiesce, xen/arch/arm/gic-v3-its.c int gicv3_its_init(void) · line 1275
Quoted 10 lines
xen/arch/arm/gic-v3-its.c +10
-0+* don't restore it since writing to CBASER or BASER<n> +* registers is undefined according to the GIC v3 ITS +* Specification. +* +* Firmware resuming with the ITS enabled is terminally broken. +*/ +WARN_ON (readl_relaxed (base +GITS_CTLR ) &GITS_CTLR_ENABLE ); + ret =gicv3_disable_its (its); +if ( ret ) +continue ;If ITS fails to disable (quiesce), the code skips restoration and ITS remains in an unconfigured state. However, immediately after the loop ...
Quoted 11 lines
xen/arch/arm/gic-v3-its.c int gicv3_its_init(void) · line 1281
Quoted 6 lines
xen/arch/arm/gic-v3-its.c +6
-0+ +writeq_relaxed (its->suspend_ctx.cbaser, base +GITS_CBASER ); + +/* +* Writing CBASER resets CREADR to 0, so make CWRITER and +* cmd_write line up with it. NIT: The variable "
cmd_write" does not exist in the Xen driver. As I understand, this comment was ported from the Linux kernel driver as is, which maintains a software shadow copy of the write pointer named "cmd_write".
Good catch, thanks.
You’re right - cmd_write doesn’t exist in the Xen driver; this comment was ported from Linux. I’ll drop the cmd_write mention and keep the comment focused on aligning CWRITER with the reset CREADR.
Quoted 15 lines
Quoted 15 lines
xen/arch/arm/gic-v3-its.c +13
-0+*/ +writeq_relaxed (0 , base +GITS_CWRITER ); + +/* Restore GITS_BASER from the value cache. */ +for (i =0 ; i <GITS_BASER_NR_REGS ; i++) { +uint64_t baser = its->suspend_ctx.baser[i]; + +if ( !(baser &GITS_VALID_BIT ) ) +continue ; + +writeq_relaxed (baser, base +GITS_BASER0 + i *8 ); + } +writel_relaxed (its->suspend_ctx.ctlr, base +GITS_CTLR );
Quoted 8 lines
xen/arch/arm/gic-v3-its.c int gicv3_its_init(void) · line 1297
Quoted 3 lines
xen/arch/arm/gic-v3-its.c +3
-0+ } + + ret =gicv3_its_setup_collection (smp_processor_id ());... this function iterates over all host ITS instances (including the
one we skipped) and attempts to send MAPC commands. I am afraid, that attempting to write to the command queue of an uninitialized/unrestored ITS might have bad consequences.
Good catch, thanks.
Since gicv3_its_setup_collection() iterates over all host ITS instances, it may send MAPC commands through an ITS that we intentionally skipped or failed to restore. That’s unsafe. I’ll fix this by invoking collection setup only for ITS instances successfully restored in this loop.
Best regards,
Mykola
Quoted 10 lines
Quoted 7 lines
xen/arch/arm/gic-v3-its.c +5
-0+if ( ret ) + panic("GICv3: ITS: resume setup collection failed: %d\n", ret); +} + +#endif /* CONFIG_SYSTEM_SUSPEND */ [snip]
PATCH v7 5/12 xen/arm: tee: keep init_tee_secondary() for hotplug and resume
In reply to Mykola KvachFrom: Mykola Kvach <[email protected]>
init_tee_secondary() was marked __init and freed after boot. Calling it from the CPU hotplug/resume path then executed discarded code, which could crash Xen. Drop __init so the TEE mediator secondary init can run safely on hotplugged and resumed CPUs.
--- xen/arch/arm/tee/tee.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/arm/tee/tee.c +1 -1
@@ -128,7 +128,7 @@ static int __init tee_init(void)presmp_initcall (tee_init); -void __init init_tee_secondary (void ) +void init_tee_secondary (void ) {if ( cur_mediator && cur_mediator->ops->init_secondary ) cur_mediator->ops->init_secondary ();
Signature · 1 line
2.43.0
PATCH v7 6/12 xen/arm: ffa: fix notification SRI across CPU hotplug/suspend
In reply to Mykola KvachFrom: Mykola Kvach <[email protected]>
The FF-A notification SRI interrupt handler was not correctly tied to CPU hotplug and suspend/resume. As a result, CPUs going offline and back online could end up with stale or missing handlers, breaking delivery of FF-A notifications.
--- xen/arch/arm/tee/ffa_notif.c | 63 ++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 13 deletions(-)
xen/arch/arm/tee/ffa_notif.c +50 -13
@@ -359,10 +359,28 @@ static int32_t ffa_notification_bitmap_destroy(uint16_t vm_id)return ffa_simple_call (FFA_NOTIFICATION_BITMAP_DESTROY , vm_id,0 ,0 ,0 ); } -void ffa_notif_init_interrupt (void ) +static DEFINE_PER_CPU_READ_MOSTLY(struct irqaction, sri_irq); + +static int request_sri_irq (void ) {int ret; +struct irqaction *sri_action = &this_cpu (sri_irq); + + sri_action->name ="FF-A notif" ; + sri_action->handler = notif_irq_handler; + sri_action->dev_id =NULL ; + sri_action->free_on_release =0 ; + + ret =setup_irq (notif_sri_irq,0 , sri_action); +if ( ret ) +printk (XENLOG_ERR "ffa: setup_irq irq %u failed: error %d\n" , + notif_sri_irq, ret); +return ret; +} + +void ffa_notif_init_interrupt (void ) +{if ( fw_notif_enabled && notif_sri_irq <NR_GIC_SGI ) {/*
@@ -375,14 +393,36 @@ void ffa_notif_init_interrupt(void)* pending, while the SPMC in the secure world will not notice that * the interrupt was lost. */ - ret =request_irq (notif_sri_irq,0 , notif_irq_handler,"FF-A notif" , -NULL ); -if ( ret ) -printk (XENLOG_ERR "ffa: request_irq irq %u failed: error %d\n" , - notif_sri_irq, ret); +request_sri_irq (); } } +static void deinit_ffa_notif_interrupt (void ) +{ +if ( fw_notif_enabled && notif_sri_irq <NR_GIC_SGI ) +release_irq (notif_sri_irq,NULL ); +} + +static int cpu_ffa_notif_callback (struct notifier_block *nfb, +unsigned long action, +void *hcpu) +{ +switch ( action ) + { +case CPU_DYING : +deinit_ffa_notif_interrupt (); +break ; +default : +break ; + } + +return NOTIFY_DONE ; +} + +static struct notifier_block cpu_ffa_notif_nfb = { + .notifier_call = cpu_ffa_notif_callback, +}; +void ffa_notif_init (void ) {const struct arm_smccc_1_2_regs arg = {
@@ -391,7 +431,6 @@ void ffa_notif_init(void) };struct arm_smccc_1_2_regs resp;unsigned int irq; -int ret;/* Only enable fw notification if all ABIs we need are supported */ if ( ffa_fw_supports_fid(FFA_NOTIFICATION_BITMAP_CREATE) &&
@@ -407,13 +446,11 @@ void ffa_notif_init(void) notif_sri_irq = irq;if ( irq >=NR_GIC_SGI )irq_set_type (irq,IRQ_TYPE_EDGE_RISING ); - ret =request_irq (irq,0 , notif_irq_handler,"FF-A notif" ,NULL ); -if ( ret ) - { -printk (XENLOG_ERR "ffa: request_irq irq %u failed: error %d\n" , - irq, ret); + +if (request_sri_irq () )return ; - } + +register_cpu_notifier (&cpu_ffa_notif_nfb); fw_notif_enabled = true; } }
Signature · 1 line
2.43.0
PATCH v7 7/12 iommu/ipmmu-vmsa: Implement suspend/resume callbacks
In reply to Mykola KvachFrom: Oleksandr Tyshchenko <[email protected]>
Store and restore active context and micro-TLB registers.
Tested on R-Car H3 Starter Kit.
---
Changes in V7:
- moved suspend context allocation before pci stuff
--- xen/drivers/passthrough/arm/ipmmu-vmsa.c | 305 ++++++++++++++++++++++- 1 file changed, 298 insertions(+), 7 deletions(-)
xen/drivers/passthrough/arm/ipmmu-vmsa.c +298 -7
@@ -71,6 +71,8 @@ })#endif +#define dev_dbg (dev, fmt, ...) \ + dev_print(dev, XENLOG_DEBUG, fmt, ## __VA_ARGS__)#define dev_info (dev, fmt, ...) \ dev_print(dev, XENLOG_INFO, fmt, ## __VA_ARGS__)#define dev_warn (dev, fmt, ...) \
@@ -130,6 +132,24 @@ struct ipmmu_features {unsigned int imuctr_ttsel_mask; }; +#ifdef CONFIG_SYSTEM_SUSPEND + +struct ipmmu_reg_ctx { +unsigned int imttlbr0; +unsigned int imttubr0; +unsigned int imttbcr; +unsigned int imctr; +}; + +struct ipmmu_vmsa_backup { +struct device *dev; +unsigned int *utlbs_val; +unsigned int *asids_val; +struct list_head list; +}; + +#endif +/* Root/Cache IPMMU device's information */ struct ipmmu_vmsa_device {struct device *dev;
@@ -142,6 +162,9 @@ struct ipmmu_vmsa_device {struct ipmmu_vmsa_domain *domains[IPMMU_CTX_MAX ];unsigned int utlb_refcount[IPMMU_UTLB_MAX ];const struct ipmmu_features *features; +#ifdef CONFIG_SYSTEM_SUSPEND +struct ipmmu_reg_ctx *reg_backup[IPMMU_CTX_MAX ]; +#endif };/*
@@ -547,6 +570,245 @@ static void ipmmu_domain_free_context(struct ipmmu_vmsa_device *mmu,spin_unlock_irqrestore (&mmu->lock, flags); } +#ifdef CONFIG_SYSTEM_SUSPEND + +static DEFINE_SPINLOCK (ipmmu_devices_backup_lock); +static LIST_HEAD (ipmmu_devices_backup); + +static struct ipmmu_reg_ctx root_pgtable[IPMMU_CTX_MAX ]; + +static uint32_t ipmmu_imuasid_read (struct ipmmu_vmsa_device *mmu, +unsigned int utlb) +{ +return ipmmu_read (mmu,ipmmu_utlb_reg (mmu,IMUASID (utlb))); +} + +static void ipmmu_utlbs_backup (struct ipmmu_vmsa_device *mmu) +{ +struct ipmmu_vmsa_backup *backup_data; + +dev_dbg (mmu->dev,"Handle micro-TLBs backup\n" ); + +spin_lock (&ipmmu_devices_backup_lock); + +list_for_each_entry ( backup_data, &ipmmu_devices_backup, list ) + { +struct iommu_fwspec *fwspec =dev_iommu_fwspec_get (backup_data->dev); +unsigned int i; + +if (to_ipmmu (backup_data->dev) != mmu ) +continue ; + +for ( i =0 ; i < fwspec->num_ids; i++ ) + { +unsigned int utlb = fwspec->ids[i]; + + backup_data->asids_val[i] =ipmmu_imuasid_read (mmu, utlb); + backup_data->utlbs_val[i] =ipmmu_imuctr_read (mmu, utlb); + } + } + +spin_unlock (&ipmmu_devices_backup_lock); +} + +static void ipmmu_utlbs_restore (struct ipmmu_vmsa_device *mmu) +{ +struct ipmmu_vmsa_backup *backup_data; + +dev_dbg (mmu->dev,"Handle micro-TLBs restore\n" ); + +spin_lock (&ipmmu_devices_backup_lock); + +list_for_each_entry ( backup_data, &ipmmu_devices_backup, list ) + { +struct iommu_fwspec *fwspec =dev_iommu_fwspec_get (backup_data->dev); +unsigned int i; + +if (to_ipmmu (backup_data->dev) != mmu ) +continue ; + +for ( i =0 ; i < fwspec->num_ids; i++ ) + { +unsigned int utlb = fwspec->ids[i]; + +ipmmu_imuasid_write (mmu, utlb, backup_data->asids_val[i]); +ipmmu_imuctr_write (mmu, utlb, backup_data->utlbs_val[i]); + } + } + +spin_unlock (&ipmmu_devices_backup_lock); +} + +static void ipmmu_domain_backup_context (struct ipmmu_vmsa_domain *domain) +{ +struct ipmmu_vmsa_device *mmu = domain->mmu->root; +struct ipmmu_reg_ctx *regs = mmu->reg_backup[domain->context_id]; + +dev_dbg (mmu->dev,"Handle domain context %u backup\n" , domain->context_id); + + regs->imttlbr0 =ipmmu_ctx_read_root (domain,IMTTLBR0 ); + regs->imttubr0 =ipmmu_ctx_read_root (domain,IMTTUBR0 ); + regs->imttbcr =ipmmu_ctx_read_root (domain,IMTTBCR ); + regs->imctr =ipmmu_ctx_read_root (domain,IMCTR ); +} + +static void ipmmu_domain_restore_context (struct ipmmu_vmsa_domain *domain) +{ +struct ipmmu_vmsa_device *mmu = domain->mmu->root; +struct ipmmu_reg_ctx *regs = mmu->reg_backup[domain->context_id]; + +dev_dbg (mmu->dev,"Handle domain context %u restore\n" , domain->context_id); + +ipmmu_ctx_write_root (domain,IMTTLBR0 , regs->imttlbr0); +ipmmu_ctx_write_root (domain,IMTTUBR0 , regs->imttubr0); +ipmmu_ctx_write_root (domain,IMTTBCR , regs->imttbcr); +ipmmu_ctx_write_all (domain,IMCTR , regs->imctr |IMCTR_FLUSH ); +} + +/* +* Xen: Unlike Linux implementation, Xen uses a single driver instance +* for handling all IPMMUs. There is no framework for ipmmu_suspend/resume +* callbacks to be invoked for each IPMMU device. So, we need to iterate +* through all registered IPMMUs performing required actions. +* +* Also take care of restoring special settings, such as translation +* table format, etc. +*/ +static int __must_check ipmmu_suspend (void ) +{ +struct ipmmu_vmsa_device *mmu; + +if ( !iommu_enabled ) +return 0 ; + +printk (XENLOG_DEBUG "ipmmu: Suspending...\n" ); + +spin_lock (&ipmmu_devices_lock); + +list_for_each_entry ( mmu, &ipmmu_devices, list ) + { +if (ipmmu_is_root (mmu) ) + { +unsigned int i; + +for ( i =0 ; i < mmu->num_ctx; i++ ) + { +if ( !mmu->domains[i] ) +continue ; +ipmmu_domain_backup_context (mmu->domains[i]); + } + } +else +ipmmu_utlbs_backup (mmu); + } + +spin_unlock (&ipmmu_devices_lock); + +return 0 ; +} + +static void ipmmu_resume (void ) +{ +struct ipmmu_vmsa_device *mmu; + +if ( !iommu_enabled ) +return ; + +printk (XENLOG_DEBUG "ipmmu: Resuming...\n" ); + +spin_lock (&ipmmu_devices_lock); + +list_for_each_entry ( mmu, &ipmmu_devices, list ) + { +uint32_t reg; + +/* Do not use security group function */ + reg =IMSCTLR + mmu->features->control_offset_base; +ipmmu_write (mmu, reg,ipmmu_read (mmu, reg) & ~IMSCTLR_USE_SECGRP ); + +if (ipmmu_is_root (mmu) ) + { +unsigned int i; + +/* Use stage 2 translation table format */ + reg =IMSAUXCTLR + mmu->features->control_offset_base; +ipmmu_write (mmu, reg,ipmmu_read (mmu, reg) |IMSAUXCTLR_S2PTE ); + +for ( i =0 ; i < mmu->num_ctx; i++ ) + { +if ( !mmu->domains[i] ) +continue ; +ipmmu_domain_restore_context (mmu->domains[i]); + } + } +else +ipmmu_utlbs_restore (mmu); + } + +spin_unlock (&ipmmu_devices_lock); +} + +static int ipmmu_alloc_ctx_suspend (struct device *dev) +{ +struct ipmmu_vmsa_backup *backup_data; +unsigned int *utlbs_val, *asids_val; +struct iommu_fwspec *fwspec =dev_iommu_fwspec_get (dev); + + utlbs_val = xzalloc_array(unsigned int, fwspec->num_ids); +if ( !utlbs_val ) +return -ENOMEM ; + + asids_val = xzalloc_array(unsigned int, fwspec->num_ids); +if ( !asids_val ) + { +xfree (utlbs_val); +return -ENOMEM ; + } + + backup_data = xzalloc(struct ipmmu_vmsa_backup); +if ( !backup_data ) + { +xfree (utlbs_val); +xfree (asids_val); +return -ENOMEM ; + } + + backup_data->dev = dev; + backup_data->utlbs_val = utlbs_val; + backup_data->asids_val = asids_val; + +spin_lock (&ipmmu_devices_backup_lock); +list_add (&backup_data->list, &ipmmu_devices_backup); +spin_unlock (&ipmmu_devices_backup_lock); + +return 0 ; +} + +#ifdef CONFIG_HAS_PCI +static void ipmmu_free_ctx_suspend (struct device *dev) +{ +struct ipmmu_vmsa_backup *backup_data, *tmp; + +spin_lock (&ipmmu_devices_backup_lock); + +list_for_each_entry_safe ( backup_data, tmp, &ipmmu_devices_backup, list ) + { +if ( backup_data->dev == dev ) + { +list_del (&backup_data->list); +xfree (backup_data->utlbs_val); +xfree (backup_data->asids_val); +xfree (backup_data); +break ; + } + } + +spin_unlock (&ipmmu_devices_backup_lock); +} +#endif /* CONFIG_HAS_PCI */ + +#endif /* CONFIG_SYSTEM_SUSPEND */ +static int ipmmu_domain_init_context (struct ipmmu_vmsa_domain *domain) {uint64_t ttbr;
@@ -559,6 +821,9 @@ static int ipmmu_domain_init_context(struct ipmmu_vmsa_domain *domain)return ret; domain->context_id = ret; +#ifdef CONFIG_SYSTEM_SUSPEND + domain->mmu->root->reg_backup[ret] = &root_pgtable[ret]; +#endif /* * TTBR0
@@ -615,6 +880,9 @@ static void ipmmu_domain_destroy_context(struct ipmmu_vmsa_domain *domain)ipmmu_ctx_write_root (domain,IMCTR ,IMCTR_FLUSH );ipmmu_tlb_sync (domain); +#ifdef CONFIG_SYSTEM_SUSPEND + domain->mmu->root->reg_backup[domain->context_id] =NULL ; +#endif ipmmu_domain_free_context (domain->mmu->root, domain->context_id); }
@@ -1340,10 +1608,11 @@ static int ipmmu_add_device(u8 devfn, struct device *dev)struct iommu_fwspec *fwspec;#ifdef CONFIG_HAS_PCI +int ret; +if (dev_is_pci (dev) ) {struct pci_dev *pdev =dev_to_pci (dev); -int ret;if ( devfn != pdev->devfn )return 0 ;
@@ -1371,6 +1640,15 @@ static int ipmmu_add_device(u8 devfn, struct device *dev)/* Let Xen know that the master device is protected by an IOMMU. */ dt_device_set_protected (dev_to_dt (dev)); } + +#ifdef CONFIG_SYSTEM_SUSPEND +if (ipmmu_alloc_ctx_suspend (dev) ) + { +dev_err (dev,"Failed to allocate context for suspend\n" ); +return -ENOMEM ; + } +#endif +#ifdef CONFIG_HAS_PCI if (dev_is_pci (dev) ) {
@@ -1379,26 +1657,28 @@ static int ipmmu_add_device(u8 devfn, struct device *dev)struct pci_host_bridge *bridge;struct iommu_fwspec *fwspec_bridge;unsigned int utlb_osid0 =0 ; -int ret; bridge =pci_find_host_bridge (pdev->seg, pdev->bus);if ( !bridge ) {dev_err (dev,"Failed to find host bridge\n" ); -return -ENODEV ; + ret = -ENODEV ; + goto free_suspend_ctx; } fwspec_bridge =dev_iommu_fwspec_get (dt_to_dev (bridge->dt_node));if ( fwspec_bridge->num_ids <1 ) {dev_err (dev,"Failed to find host bridge uTLB\n" ); -return -ENXIO ; + ret = -ENXIO ; + goto free_suspend_ctx; }if ( fwspec->num_ids <1 ) {dev_err (dev,"Failed to find uTLB" ); -return -ENXIO ; + ret = -ENXIO ; + goto free_suspend_ctx; }rcar4_pcie_osid_regs_init (bridge);
@@ -1407,7 +1687,7 @@ static int ipmmu_add_device(u8 devfn, struct device *dev)if ( ret <0 ) {dev_err (dev,"No unused OSID regs\n" ); -return ret; + goto free_suspend_ctx; } reg_id = ret;
@@ -1422,7 +1702,7 @@ static int ipmmu_add_device(u8 devfn, struct device *dev) {rcar4_pcie_osid_bdf_clear (bridge, reg_id);rcar4_pcie_osid_reg_free (bridge, reg_id); -return ret; + goto free_suspend_ctx; } }#endif
@@ -1431,6 +1711,13 @@ static int ipmmu_add_device(u8 devfn, struct device *dev) dev_name(fwspec->iommu_dev), fwspec->num_ids);return 0 ; +#ifdef CONFIG_HAS_PCI + free_suspend_ctx: +#ifdef CONFIG_SYSTEM_SUSPEND +ipmmu_free_ctx_suspend (dev ); +#endif +return ret; +#endif }static int ipmmu_iommu_domain_init (struct domain *d)
@@ -1492,6 +1779,10 @@ static const struct iommu_ops ipmmu_iommu_ops = .unmap_page = arm_iommu_unmap_page, .dt_xlate = ipmmu_dt_xlate, .add_device = ipmmu_add_device, +#ifdef CONFIG_SYSTEM_SUSPEND + .suspend = ipmmu_suspend, + .resume = ipmmu_resume, +#endif };static __init int ipmmu_init (struct dt_device_node *node,const void *data)
Signature · 1 line
2.43.0
Re: [PATCH v7 07/12] iommu/ipmmu-vmsa: Implement suspend/resume callbacks
On 11.12.25 20:43, Mykola Kvach wrote:
Hello Mykola
Quoted 11 lines
From: Oleksandr Tyshchenko <[email protected]>
Store and restore active context and micro-TLB registers.
Tested on R-Car H3 Starter Kit.
Signed-off-by Oleksandr Tyshchenko <[email protected]>Signed-off-by Mykola Kvach <[email protected]>---
Changes in V7:
- moved suspend context allocation before pci stuff
Thanks for making this change, one note below ...
Quoted 284 lines
--- xen/drivers/passthrough/arm/ipmmu-vmsa.c | 305 ++++++++++++++++++++++- 1 file changed, 298 insertions(+), 7 deletions(-)xen/drivers/passthrough/arm/ipmmu-vmsa.c +251
-0@@ -71,6 +71,8 @@ })#endif +#define dev_dbg (dev, fmt, ...) \ + dev_print(dev, XENLOG_DEBUG, fmt, ## __VA_ARGS__)#define dev_info (dev, fmt, ...) \ dev_print(dev, XENLOG_INFO, fmt, ## __VA_ARGS__)#define dev_warn (dev, fmt, ...) \@@ -130,6 +132,24 @@ struct ipmmu_features {unsigned int imuctr_ttsel_mask; }; +#ifdef CONFIG_SYSTEM_SUSPEND + +struct ipmmu_reg_ctx { +unsigned int imttlbr0; +unsigned int imttubr0; +unsigned int imttbcr; +unsigned int imctr; +}; + +struct ipmmu_vmsa_backup { +struct device *dev; +unsigned int *utlbs_val; +unsigned int *asids_val; +struct list_head list; +}; + +#endif +/* Root/Cache IPMMU device's information */ struct ipmmu_vmsa_device {struct device *dev;@@ -142,6 +162,9 @@ struct ipmmu_vmsa_device {struct ipmmu_vmsa_domain *domains[IPMMU_CTX_MAX ];unsigned int utlb_refcount[IPMMU_UTLB_MAX ];const struct ipmmu_features *features; +#ifdef CONFIG_SYSTEM_SUSPEND +struct ipmmu_reg_ctx *reg_backup[IPMMU_CTX_MAX ]; +#endif };/* @@ -547,6 +570,245 @@ static void ipmmu_domain_free_context(struct ipmmu_vmsa_device *mmu,spin_unlock_irqrestore (&mmu->lock, flags); } +#ifdef CONFIG_SYSTEM_SUSPEND + +static DEFINE_SPINLOCK(ipmmu_devices_backup_lock); +static LIST_HEAD(ipmmu_devices_backup); + +static struct ipmmu_reg_ctx root_pgtable[IPMMU_CTX_MAX]; + +static uint32_t ipmmu_imuasid_read(struct ipmmu_vmsa_device *mmu, + unsigned int utlb) +{ + return ipmmu_read(mmu, ipmmu_utlb_reg(mmu, IMUASID(utlb))); +} + +static void ipmmu_utlbs_backup(struct ipmmu_vmsa_device *mmu) +{ + struct ipmmu_vmsa_backup *backup_data; + + dev_dbg(mmu->dev, "Handle micro-TLBs backup\n"); + + spin_lock(&ipmmu_devices_backup_lock); + + list_for_each_entry( backup_data, &ipmmu_devices_backup, list ) + { + struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(backup_data->dev); + unsigned int i; + + if ( to_ipmmu(backup_data->dev) != mmu ) + continue; + + for ( i = 0; i < fwspec->num_ids; i++ ) + { + unsigned int utlb = fwspec->ids[i]; + + backup_data->asids_val[i] = ipmmu_imuasid_read(mmu, utlb); + backup_data->utlbs_val[i] = ipmmu_imuctr_read(mmu, utlb); + } + } + + spin_unlock(&ipmmu_devices_backup_lock); +} + +static void ipmmu_utlbs_restore(struct ipmmu_vmsa_device *mmu) +{ + struct ipmmu_vmsa_backup *backup_data; + + dev_dbg(mmu->dev, "Handle micro-TLBs restore\n"); + + spin_lock(&ipmmu_devices_backup_lock); + + list_for_each_entry( backup_data, &ipmmu_devices_backup, list ) + { + struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(backup_data->dev); + unsigned int i; + + if ( to_ipmmu(backup_data->dev) != mmu ) + continue; + + for ( i = 0; i < fwspec->num_ids; i++ ) + { + unsigned int utlb = fwspec->ids[i]; + + ipmmu_imuasid_write(mmu, utlb, backup_data->asids_val[i]); + ipmmu_imuctr_write(mmu, utlb, backup_data->utlbs_val[i]); + } + } + + spin_unlock(&ipmmu_devices_backup_lock); +} + +static void ipmmu_domain_backup_context(struct ipmmu_vmsa_domain *domain) +{ + struct ipmmu_vmsa_device *mmu = domain->mmu->root; + struct ipmmu_reg_ctx *regs = mmu->reg_backup[domain->context_id]; + + dev_dbg(mmu->dev, "Handle domain context %u backup\n", domain->context_id); + + regs->imttlbr0 = ipmmu_ctx_read_root(domain, IMTTLBR0); + regs->imttubr0 = ipmmu_ctx_read_root(domain, IMTTUBR0); + regs->imttbcr = ipmmu_ctx_read_root(domain, IMTTBCR); + regs->imctr = ipmmu_ctx_read_root(domain, IMCTR); +} + +static void ipmmu_domain_restore_context(struct ipmmu_vmsa_domain *domain) +{ + struct ipmmu_vmsa_device *mmu = domain->mmu->root; + struct ipmmu_reg_ctx *regs = mmu->reg_backup[domain->context_id]; + + dev_dbg(mmu->dev, "Handle domain context %u restore\n", domain->context_id); + + ipmmu_ctx_write_root(domain, IMTTLBR0, regs->imttlbr0); + ipmmu_ctx_write_root(domain, IMTTUBR0, regs->imttubr0); + ipmmu_ctx_write_root(domain, IMTTBCR, regs->imttbcr); + ipmmu_ctx_write_all(domain, IMCTR, regs->imctr | IMCTR_FLUSH); +} + +/* + * Xen: Unlike Linux implementation, Xen uses a single driver instance + * for handling all IPMMUs. There is no framework for ipmmu_suspend/resume + * callbacks to be invoked for each IPMMU device. So, we need to iterate + * through all registered IPMMUs performing required actions. + * + * Also take care of restoring special settings, such as translation + * table format, etc. + */ +static int __must_check ipmmu_suspend(void) +{ + struct ipmmu_vmsa_device *mmu; + + if ( !iommu_enabled ) + return 0; + + printk(XENLOG_DEBUG "ipmmu: Suspending...\n"); + + spin_lock(&ipmmu_devices_lock); + + list_for_each_entry( mmu, &ipmmu_devices, list ) + { + if ( ipmmu_is_root(mmu) ) + { + unsigned int i; + + for ( i = 0; i < mmu->num_ctx; i++ ) + { + if ( !mmu->domains[i] ) + continue; + ipmmu_domain_backup_context(mmu->domains[i]); + } + } + else + ipmmu_utlbs_backup(mmu); + } + + spin_unlock(&ipmmu_devices_lock); + + return 0; +} + +static void ipmmu_resume(void) +{ + struct ipmmu_vmsa_device *mmu; + + if ( !iommu_enabled ) + return; + + printk(XENLOG_DEBUG "ipmmu: Resuming...\n"); + + spin_lock(&ipmmu_devices_lock); + + list_for_each_entry( mmu, &ipmmu_devices, list ) + { + uint32_t reg; + + /* Do not use security group function */ + reg = IMSCTLR + mmu->features->control_offset_base; + ipmmu_write(mmu, reg, ipmmu_read(mmu, reg) & ~IMSCTLR_USE_SECGRP); + + if ( ipmmu_is_root(mmu) ) + { + unsigned int i; + + /* Use stage 2 translation table format */ + reg = IMSAUXCTLR + mmu->features->control_offset_base; + ipmmu_write(mmu, reg, ipmmu_read(mmu, reg) | IMSAUXCTLR_S2PTE); + + for ( i = 0; i < mmu->num_ctx; i++ ) + { + if ( !mmu->domains[i] ) + continue; + ipmmu_domain_restore_context(mmu->domains[i]); + } + } + else + ipmmu_utlbs_restore(mmu); + } + + spin_unlock(&ipmmu_devices_lock); +} + +static int ipmmu_alloc_ctx_suspend(struct device *dev) +{ + struct ipmmu_vmsa_backup *backup_data; + unsigned int *utlbs_val, *asids_val; + struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); + + utlbs_val = xzalloc_array(unsigned int, fwspec->num_ids); + if ( !utlbs_val ) + return -ENOMEM; + + asids_val = xzalloc_array(unsigned int, fwspec->num_ids); + if ( !asids_val ) + { + xfree(utlbs_val); + return -ENOMEM; + } + + backup_data = xzalloc(struct ipmmu_vmsa_backup); + if ( !backup_data ) + { + xfree(utlbs_val); + xfree(asids_val); + return -ENOMEM; + } + + backup_data->dev = dev; + backup_data->utlbs_val = utlbs_val; + backup_data->asids_val = asids_val; + + spin_lock(&ipmmu_devices_backup_lock); + list_add(&backup_data->list, &ipmmu_devices_backup); + spin_unlock(&ipmmu_devices_backup_lock); + + return 0; +} + +#ifdef CONFIG_HAS_PCI +static void ipmmu_free_ctx_suspend(struct device *dev) +{ + struct ipmmu_vmsa_backup *backup_data, *tmp; + + spin_lock(&ipmmu_devices_backup_lock); + + list_for_each_entry_safe( backup_data, tmp, &ipmmu_devices_backup, list ) + { + if ( backup_data->dev == dev ) + { + list_del(&backup_data->list); + xfree(backup_data->utlbs_val); + xfree(backup_data->asids_val);
xen/drivers/passthrough/arm/ipmmu-vmsa.c static void ipmmu_domain_free_context(struct ipmmu_vmsa_device *mmu, · line 810
Quoted 10 lines
xen/drivers/passthrough/arm/ipmmu-vmsa.c +10
-0+xfree (backup_data); +break ; + } + } + +spin_unlock (&ipmmu_devices_backup_lock); +} +#endif /* CONFIG_HAS_PCI */ + +#endif /* CONFIG_SYSTEM_SUSPEND */
... I noticed the Kconfig guards for ipmmu_alloc_ctx_suspend() andipmmu_free_ctx_suspend() are asymmetrical. This creates a configuration (CONFIG_SYSTEM_SUSPEND=y, CONFIG_HAS_PCI=n) where the allocation function exists but the deallocation function is compiled out.
While this feels a bit fragile, I understand this is necessary to avoid an "unused function" compiler error, as the only caller is within a CONFIG_HAS_PCI block. Since the alternative would break the build, I think the current implementation is acceptable. I have no further comments. The patch looks good now.
Quoted 129 lines
xen/drivers/passthrough/arm/ipmmu-vmsa.c +37
-7+static int ipmmu_domain_init_context (struct ipmmu_vmsa_domain *domain) {uint64_t ttbr;@@ -559,6 +821,9 @@ static int ipmmu_domain_init_context(struct ipmmu_vmsa_domain *domain)return ret; domain->context_id = ret; +#ifdef CONFIG_SYSTEM_SUSPEND + domain->mmu->root->reg_backup[ret] = &root_pgtable[ret]; +#endif /* * TTBR0 @@ -615,6 +880,9 @@ static void ipmmu_domain_destroy_context(struct ipmmu_vmsa_domain *domain)ipmmu_ctx_write_root (domain,IMCTR ,IMCTR_FLUSH );ipmmu_tlb_sync (domain); +#ifdef CONFIG_SYSTEM_SUSPEND + domain->mmu->root->reg_backup[domain->context_id] =NULL ; +#endif ipmmu_domain_free_context (domain->mmu->root, domain->context_id); }@@ -1340,10 +1608,11 @@ static int ipmmu_add_device(u8 devfn, struct device *dev)struct iommu_fwspec *fwspec;#ifdef CONFIG_HAS_PCI +int ret; +if (dev_is_pci (dev) ) {struct pci_dev *pdev =dev_to_pci (dev); -int ret;if ( devfn != pdev->devfn )return 0 ;@@ -1371,6 +1640,15 @@ static int ipmmu_add_device(u8 devfn, struct device *dev)/* Let Xen know that the master device is protected by an IOMMU. */ dt_device_set_protected (dev_to_dt (dev)); } + +#ifdef CONFIG_SYSTEM_SUSPEND +if (ipmmu_alloc_ctx_suspend (dev) ) + { +dev_err (dev,"Failed to allocate context for suspend\n" ); +return -ENOMEM ; + } +#endif +#ifdef CONFIG_HAS_PCI if (dev_is_pci (dev) ) {@@ -1379,26 +1657,28 @@ static int ipmmu_add_device(u8 devfn, struct device *dev)struct pci_host_bridge *bridge;struct iommu_fwspec *fwspec_bridge;unsigned int utlb_osid0 =0 ; -int ret; bridge =pci_find_host_bridge (pdev->seg, pdev->bus);if ( !bridge ) {dev_err (dev,"Failed to find host bridge\n" ); -return -ENODEV ; + ret = -ENODEV ; + goto free_suspend_ctx; } fwspec_bridge =dev_iommu_fwspec_get (dt_to_dev (bridge->dt_node));if ( fwspec_bridge->num_ids <1 ) {dev_err (dev,"Failed to find host bridge uTLB\n" ); -return -ENXIO ; + ret = -ENXIO ; + goto free_suspend_ctx; }if ( fwspec->num_ids <1 ) {dev_err (dev,"Failed to find uTLB" ); -return -ENXIO ; + ret = -ENXIO ; + goto free_suspend_ctx; }rcar4_pcie_osid_regs_init (bridge);@@ -1407,7 +1687,7 @@ static int ipmmu_add_device(u8 devfn, struct device *dev)if ( ret <0 ) {dev_err (dev,"No unused OSID regs\n" ); -return ret; + goto free_suspend_ctx; } reg_id = ret;@@ -1422,7 +1702,7 @@ static int ipmmu_add_device(u8 devfn, struct device *dev) {rcar4_pcie_osid_bdf_clear (bridge, reg_id);rcar4_pcie_osid_reg_free (bridge, reg_id); -return ret; + goto free_suspend_ctx; } }#endif @@ -1431,6 +1711,13 @@ static int ipmmu_add_device(u8 devfn, struct device *dev) dev_name(fwspec->iommu_dev), fwspec->num_ids);return 0 ; +#ifdef CONFIG_HAS_PCI + free_suspend_ctx: +#ifdef CONFIG_SYSTEM_SUSPEND +ipmmu_free_ctx_suspend (dev ); +#endif +return ret; +#endif }static int ipmmu_iommu_domain_init (struct domain *d)@@ -1492,6 +1779,10 @@ static const struct iommu_ops ipmmu_iommu_ops = .unmap_page = arm_iommu_unmap_page, .dt_xlate = ipmmu_dt_xlate, .add_device = ipmmu_add_device, +#ifdef CONFIG_SYSTEM_SUSPEND + .suspend = ipmmu_suspend, + .resume = ipmmu_resume, +#endif };static __init int ipmmu_init (struct dt_device_node *node,const void *data)
PATCH v7 8/12 arm/smmu-v3: add suspend/resume handlers
In reply to Mykola KvachFrom: Mykola Kvach <[email protected]>
Before we suspend SMMU, we want to ensure that all commands (especially ATC_INV) have been flushed by the CMDQ, i.e. the CMDQs are empty.
The suspend callback configures the SMMU to abort new transactions, disables the main translation unit and then drains the command queue to ensure completion of any in-flight commands.
The resume callback performs a full device reset via 'arm_smmu_device_reset' to bring the SMMU back to an operational state.
--- xen/drivers/passthrough/arm/smmu-v3.c | 170 ++++++++++++++++++++------ 1 file changed, 134 insertions(+), 36 deletions(-)
xen/drivers/passthrough/arm/smmu-v3.c +134 -36
@@ -1814,8 +1814,7 @@ static int arm_smmu_write_reg_sync(struct arm_smmu_device *smmu, u32 val, }/* GBPA is "special" */ -static int __init arm_smmu_update_gbpa (struct arm_smmu_device *smmu, -u32 set,u32 clr) +static int arm_smmu_update_gbpa (struct arm_smmu_device *smmu,u32 set,u32 clr) {int ret;u32 reg,__iomem *gbpa = smmu->base +ARM_SMMU_GBPA ;
@@ -1995,10 +1994,29 @@ err_free_evtq_irq:return ret; } +static int arm_smmu_enable_irqs (struct arm_smmu_device *smmu) +{ +int ret; +u32 irqen_flags =IRQ_CTRL_EVTQ_IRQEN |IRQ_CTRL_GERROR_IRQEN ; + +if ( smmu->features &ARM_SMMU_FEAT_PRI ) + irqen_flags |=IRQ_CTRL_PRIQ_IRQEN ; + +/* Enable interrupt generation on the SMMU */ + ret =arm_smmu_write_reg_sync (smmu, irqen_flags, +ARM_SMMU_IRQ_CTRL ,ARM_SMMU_IRQ_CTRLACK ); +if ( ret ) + { +dev_warn (smmu->dev,"failed to enable irqs\n" ); +return ret; + } + +return 0 ; +} +static int __init arm_smmu_setup_irqs (struct arm_smmu_device *smmu) {int ret, irq; -u32 irqen_flags =IRQ_CTRL_EVTQ_IRQEN |IRQ_CTRL_GERROR_IRQEN ;/* Disable IRQs first */ ret = arm_smmu_write_reg_sync(smmu, 0, ARM_SMMU_IRQ_CTRL,
@@ -2028,22 +2046,7 @@ static int __init arm_smmu_setup_irqs(struct arm_smmu_device *smmu) } } -if (smmu->features &ARM_SMMU_FEAT_PRI ) - irqen_flags |=IRQ_CTRL_PRIQ_IRQEN ; - -/* Enable interrupt generation on the SMMU */ - ret =arm_smmu_write_reg_sync (smmu, irqen_flags, -ARM_SMMU_IRQ_CTRL ,ARM_SMMU_IRQ_CTRLACK ); -if (ret) { -dev_warn (smmu->dev,"failed to enable irqs\n" ); - goto err_free_irqs; - } -return 0 ; - -err_free_irqs: -arm_smmu_free_irqs (smmu); -return ret; }static int arm_smmu_device_disable (struct arm_smmu_device *smmu)
@@ -2057,7 +2060,7 @@ static int arm_smmu_device_disable(struct arm_smmu_device *smmu)return ret; } -static int __init arm_smmu_device_reset (struct arm_smmu_device *smmu) +static int arm_smmu_device_reset (struct arm_smmu_device *smmu) {int ret;u32 reg, enables;
@@ -2163,17 +2166,9 @@ static int __init arm_smmu_device_reset(struct arm_smmu_device *smmu) } } - ret =arm_smmu_setup_irqs (smmu); -if (ret) { -dev_err (smmu->dev,"failed to setup irqs\n" ); + ret =arm_smmu_enable_irqs (smmu); +if ( ret )return ret; - } - -/* Initialize tasklets for threaded IRQs*/ -tasklet_init (&smmu->evtq_irq_tasklet, arm_smmu_evtq_tasklet, smmu); -tasklet_init (&smmu->priq_irq_tasklet, arm_smmu_priq_tasklet, smmu); -tasklet_init (&smmu->combined_irq_tasklet, arm_smmu_combined_irq_tasklet, - smmu);/* Enable the SMMU interface, or ensure bypass */ if (disable_bypass) {
@@ -2181,20 +2176,16 @@ static int __init arm_smmu_device_reset(struct arm_smmu_device *smmu) }else { ret =arm_smmu_update_gbpa (smmu,0 ,GBPA_ABORT );if (ret) - goto err_free_irqs; +return ret; } ret =arm_smmu_write_reg_sync (smmu, enables,ARM_SMMU_CR0 ,ARM_SMMU_CR0ACK );if (ret) {dev_err (smmu->dev,"failed to enable SMMU interface\n" ); - goto err_free_irqs; +return ret; }return 0 ; - -err_free_irqs: -arm_smmu_free_irqs (smmu); -return ret; }static int arm_smmu_device_hw_probe (struct arm_smmu_device *smmu)
@@ -2558,10 +2549,23 @@ static int __init arm_smmu_device_probe(struct platform_device *pdev)if (ret) goto out_free; + ret =arm_smmu_setup_irqs (smmu); +if ( ret ) + { +dev_err (smmu->dev,"failed to setup irqs\n" ); + goto out_free; + } + +/* Initialize tasklets for threaded IRQs*/ +tasklet_init (&smmu->evtq_irq_tasklet, arm_smmu_evtq_tasklet, smmu); +tasklet_init (&smmu->priq_irq_tasklet, arm_smmu_priq_tasklet, smmu); +tasklet_init (&smmu->combined_irq_tasklet, arm_smmu_combined_irq_tasklet, + smmu); +/* Reset the device */ ret =arm_smmu_device_reset (smmu);if (ret) - goto out_free; + goto out_free_irqs;/* * Keep a list of all probed devices. This will be used to query
@@ -2575,6 +2579,8 @@ static int __init arm_smmu_device_probe(struct platform_device *pdev)return 0 ; +out_free_irqs: +arm_smmu_free_irqs (smmu); out_free:arm_smmu_free_structures (smmu);
@@ -2855,6 +2861,94 @@ static void arm_smmu_iommu_xen_domain_teardown(struct domain *d)xfree (xen_domain); } +#ifdef CONFIG_SYSTEM_SUSPEND + +static int arm_smmu_suspend (void ) +{ +struct arm_smmu_device *smmu; +int ret =0 ; + +list_for_each_entry (smmu, &arm_smmu_devices, devices) + { +/* Abort all transactions before disable to avoid spurious bypass */ + ret =arm_smmu_update_gbpa (smmu,GBPA_ABORT ,0 ); +if ( ret ) + goto fail; + +/* Disable the SMMU via CR0.EN and all queues except CMDQ */ + ret =arm_smmu_write_reg_sync (smmu,CR0_CMDQEN ,ARM_SMMU_CR0 , +ARM_SMMU_CR0ACK ); +if ( ret ) + { +dev_err (smmu->dev,"Timed-out while disabling smmu\n" ); + goto fail; + } + +/* +* At this point the SMMU is completely disabled and won't access +* any translation/config structures, even speculative accesses +* aren't performed as per the IHI0070 spec (section 6.3.9.6). +*/ + +/* Wait for the CMDQs to be drained to flush any pending commands */ + ret =queue_poll_cons (&smmu->cmdq.q, true,0 ); +if ( ret ) + { +dev_err (smmu->dev,"Draining queues timed-out\n" ); + goto fail; + } + +/* Disable everything */ + ret =arm_smmu_device_disable (smmu); +if ( ret ) + goto fail; + +dev_dbg (smmu->dev,"Suspended smmu\n" ); + } + +return 0 ; + + fail: + { +int rc; + +/* Reset the device that failed as well as any already-suspended ones. */ + rc =arm_smmu_device_reset (smmu); +if ( rc ) +dev_err (smmu->dev,"Failed to reset during resume operation: %d\n" , rc); + +list_for_each_entry_continue_reverse (smmu, &arm_smmu_devices, devices) + { + rc =arm_smmu_device_reset (smmu); +if ( rc ) +dev_err (smmu->dev,"Failed to reset during resume operation: %d\n" , rc); + } + } + +return ret; +} + +static void arm_smmu_resume (void ) +{ +int ret; +struct arm_smmu_device *smmu; + +list_for_each_entry (smmu, &arm_smmu_devices, devices) + { +dev_dbg (smmu->dev,"Resuming device\n" ); + +/* +* The reset will re-initialize all the base addresses, queues, +* prod and cons maintained within struct arm_smmu_device as well as +* re-enable the interrupts. +*/ + ret =arm_smmu_device_reset (smmu); +if ( ret ) +dev_err (smmu->dev,"Failed to reset during resume operation: %d\n" , ret); + } +} +#endif +static const struct iommu_ops arm_smmu_iommu_ops = { .page_sizes =PAGE_SIZE_4K , .init = arm_smmu_iommu_xen_domain_init,
@@ -2867,6 +2961,10 @@ static const struct iommu_ops arm_smmu_iommu_ops = { .unmap_page = arm_iommu_unmap_page, .dt_xlate = arm_smmu_dt_xlate, .add_device = arm_smmu_add_device, +#ifdef CONFIG_SYSTEM_SUSPEND + .suspend = arm_smmu_suspend, + .resume = arm_smmu_resume, +#endif }; static __init int arm_smmu_dt_init(struct dt_device_node *dev,
Signature · 1 line
2.43.0
Re: [PATCH v7 08/12] arm/smmu-v3: add suspend/resume handlers
On 11.12.25 20:43, Mykola Kvach wrote:
Hello Mykola
Quoted 198 lines
From: Mykola Kvach <[email protected]>
Before we suspend SMMU, we want to ensure that all commands (especially
ATC_INV) have been flushed by the CMDQ, i.e. the CMDQs are empty.The suspend callback configures the SMMU to abort new transactions, disables the main translation unit and then drains the command queue to ensure completion of any in-flight commands.
The resume callback performs a full device reset via '
arm_smmu_device_reset' to bring the SMMU back to an operational state.Based-on-patch-by Pranjal Shrivastava <[email protected]>Signed-off-by Mykola Kvach <[email protected]>--- xen/drivers/passthrough/arm/smmu-v3.c | 170 ++++++++++++++++++++------ 1 file changed, 134 insertions(+), 36 deletions(-)xen/drivers/passthrough/arm/smmu-v3.c +63
-36@@ -1814,8 +1814,7 @@ static int arm_smmu_write_reg_sync(struct arm_smmu_device *smmu, u32 val, }/* GBPA is "special" */ -static int __init arm_smmu_update_gbpa (struct arm_smmu_device *smmu, -u32 set,u32 clr) +static int arm_smmu_update_gbpa (struct arm_smmu_device *smmu,u32 set,u32 clr) {int ret;u32 reg,__iomem *gbpa = smmu->base +ARM_SMMU_GBPA ;@@ -1995,10 +1994,29 @@ err_free_evtq_irq:return ret; } +static int arm_smmu_enable_irqs (struct arm_smmu_device *smmu) +{ +int ret; +u32 irqen_flags =IRQ_CTRL_EVTQ_IRQEN |IRQ_CTRL_GERROR_IRQEN ; + +if ( smmu->features &ARM_SMMU_FEAT_PRI ) + irqen_flags |=IRQ_CTRL_PRIQ_IRQEN ; + +/* Enable interrupt generation on the SMMU */ + ret =arm_smmu_write_reg_sync (smmu, irqen_flags, +ARM_SMMU_IRQ_CTRL ,ARM_SMMU_IRQ_CTRLACK ); +if ( ret ) + { +dev_warn (smmu->dev,"failed to enable irqs\n" ); +return ret; + } + +return 0 ; +} +static int __init arm_smmu_setup_irqs (struct arm_smmu_device *smmu) {int ret, irq; -u32 irqen_flags =IRQ_CTRL_EVTQ_IRQEN |IRQ_CTRL_GERROR_IRQEN ;/* Disable IRQs first */ ret = arm_smmu_write_reg_sync(smmu, 0, ARM_SMMU_IRQ_CTRL,@@ -2028,22 +2046,7 @@ static int __init arm_smmu_setup_irqs(struct arm_smmu_device *smmu) } } -if (smmu->features &ARM_SMMU_FEAT_PRI ) - irqen_flags |=IRQ_CTRL_PRIQ_IRQEN ; - -/* Enable interrupt generation on the SMMU */ - ret =arm_smmu_write_reg_sync (smmu, irqen_flags, -ARM_SMMU_IRQ_CTRL ,ARM_SMMU_IRQ_CTRLACK ); -if (ret) { -dev_warn (smmu->dev,"failed to enable irqs\n" ); - goto err_free_irqs; - } -return 0 ; - -err_free_irqs: -arm_smmu_free_irqs (smmu); -return ret; }static int arm_smmu_device_disable (struct arm_smmu_device *smmu)@@ -2057,7 +2060,7 @@ static int arm_smmu_device_disable(struct arm_smmu_device *smmu)return ret; } -static int __init arm_smmu_device_reset (struct arm_smmu_device *smmu) +static int arm_smmu_device_reset (struct arm_smmu_device *smmu) {int ret;u32 reg, enables;@@ -2163,17 +2166,9 @@ static int __init arm_smmu_device_reset(struct arm_smmu_device *smmu) } } - ret =arm_smmu_setup_irqs (smmu); -if (ret) { -dev_err (smmu->dev,"failed to setup irqs\n" ); + ret =arm_smmu_enable_irqs (smmu); +if ( ret )return ret; - } - -/* Initialize tasklets for threaded IRQs*/ -tasklet_init (&smmu->evtq_irq_tasklet, arm_smmu_evtq_tasklet, smmu); -tasklet_init (&smmu->priq_irq_tasklet, arm_smmu_priq_tasklet, smmu); -tasklet_init (&smmu->combined_irq_tasklet, arm_smmu_combined_irq_tasklet, - smmu);/* Enable the SMMU interface, or ensure bypass */ if (disable_bypass) {@@ -2181,20 +2176,16 @@ static int __init arm_smmu_device_reset(struct arm_smmu_device *smmu) }else { ret =arm_smmu_update_gbpa (smmu,0 ,GBPA_ABORT );if (ret) - goto err_free_irqs; +return ret; } ret =arm_smmu_write_reg_sync (smmu, enables,ARM_SMMU_CR0 ,ARM_SMMU_CR0ACK );if (ret) {dev_err (smmu->dev,"failed to enable SMMU interface\n" ); - goto err_free_irqs; +return ret; }return 0 ; - -err_free_irqs: -arm_smmu_free_irqs (smmu); -return ret; }static int arm_smmu_device_hw_probe (struct arm_smmu_device *smmu)@@ -2558,10 +2549,23 @@ static int __init arm_smmu_device_probe(struct platform_device *pdev)if (ret) goto out_free; + ret =arm_smmu_setup_irqs (smmu); +if ( ret ) + { +dev_err (smmu->dev,"failed to setup irqs\n" ); + goto out_free; + } + +/* Initialize tasklets for threaded IRQs*/ +tasklet_init (&smmu->evtq_irq_tasklet, arm_smmu_evtq_tasklet, smmu); +tasklet_init (&smmu->priq_irq_tasklet, arm_smmu_priq_tasklet, smmu); +tasklet_init (&smmu->combined_irq_tasklet, arm_smmu_combined_irq_tasklet, + smmu); +/* Reset the device */ ret =arm_smmu_device_reset (smmu);if (ret) - goto out_free; + goto out_free_irqs;/* * Keep a list of all probed devices. This will be used to query @@ -2575,6 +2579,8 @@ static int __init arm_smmu_device_probe(struct platform_device *pdev)return 0 ; +out_free_irqs: +arm_smmu_free_irqs (smmu); out_free:arm_smmu_free_structures (smmu);@@ -2855,6 +2861,94 @@ static void arm_smmu_iommu_xen_domain_teardown(struct domain *d)xfree (xen_domain); } +#ifdef CONFIG_SYSTEM_SUSPEND + +static int arm_smmu_suspend (void ) +{ +struct arm_smmu_device *smmu; +int ret =0 ; + +list_for_each_entry (smmu, &arm_smmu_devices, devices) + { +/* Abort all transactions before disable to avoid spurious bypass */ + ret =arm_smmu_update_gbpa (smmu,GBPA_ABORT ,0 ); +if ( ret ) + goto fail; + +/* Disable the SMMU via CR0.EN and all queues except CMDQ */ + ret =arm_smmu_write_reg_sync (smmu,CR0_CMDQEN ,ARM_SMMU_CR0 , +ARM_SMMU_CR0ACK ); +if ( ret ) + { +dev_err (smmu->dev,"Timed-out while disabling smmu\n" ); + goto fail;
xen/drivers/passthrough/arm/smmu-v3.c static void arm_smmu_iommu_xen_domain_teardown(struct domain *d) · line 2894
Quoted 10 lines
xen/drivers/passthrough/arm/smmu-v3.c +10
-0+ } + +/* +* At this point the SMMU is completely disabled and won't access +* any translation/config structures, even speculative accesses +* aren't performed as per the IHI0070 spec (section 6.3.9.6). +*/ + +/* Wait for the CMDQs to be drained to flush any pending commands */ + ret =queue_poll_cons (&smmu->cmdq.q, true,0 );
I wonder, why ignoring ARM_SMMU_FEAT_SEV in suspend? In the runtime function __arm_smmu_cmdq_issue_sync(), the driver checks if the SMMU supports ARM_SMMU_FEAT_SEV and passes this flag to queue_poll_cons(). However, here, this check is missing, and the wfe argument is hardcoded to 0.
Quoted 21 lines
xen/drivers/passthrough/arm/smmu-v3.c +21
-0+if ( ret ) + { +dev_err (smmu->dev,"Draining queues timed-out\n" ); + goto fail; + } + +/* Disable everything */ + ret =arm_smmu_device_disable (smmu); +if ( ret ) + goto fail; + +dev_dbg (smmu->dev,"Suspended smmu\n" ); + } + +return 0 ; + + fail: + { +int rc; + +/* Reset the device that failed as well as any already-suspended ones. */
xen/drivers/passthrough/arm/smmu-v3.c static void arm_smmu_iommu_xen_domain_teardown(struct domain *d) · line 2925
Quoted 10 lines
xen/drivers/passthrough/arm/smmu-v3.c +10
-0+ rc =arm_smmu_device_reset (smmu); +if ( rc ) +dev_err (smmu->dev,"Failed to reset during resume operation: %d\n" , rc); + +list_for_each_entry_continue_reverse (smmu, &arm_smmu_devices, devices) + { + rc =arm_smmu_device_reset (smmu); +if ( rc ) +dev_err (smmu->dev,"Failed to reset during resume operation: %d\n" , rc); + }
NIT: Could this duplicated reset call (and error message) be optimized somehow? Maybe, by using a do-while loop to manually walk back up the list from the current SMMU to the head, but not sure.
Quoted 12 lines
xen/drivers/passthrough/arm/smmu-v3.c +12
-0+ } + +return ret; +} + +static void arm_smmu_resume (void ) +{ +int ret; +struct arm_smmu_device *smmu; + +list_for_each_entry (smmu, &arm_smmu_devices, devices) + {
xen/drivers/passthrough/arm/smmu-v3.c static void arm_smmu_iommu_xen_domain_teardown(struct domain *d) · line 2947
Quoted 10 lines
xen/drivers/passthrough/arm/smmu-v3.c +10
-0+dev_dbg (smmu->dev,"Resuming device\n" ); + +/* +* The reset will re-initialize all the base addresses, queues, +* prod and cons maintained within struct arm_smmu_device as well as +* re-enable the interrupts. +*/ + ret =arm_smmu_device_reset (smmu); +if ( ret ) +dev_err (smmu->dev,"Failed to reset during resume operation: %d\n" , ret);
In your GICv3 ITS patch, a failure during resume triggers a panic(), but here only an error message that might go unnoticed. May I please ask, why such diverging? The IOMMU is as critical as the Interrupt Controller. I see that you configure Abort state during suspend, so if I understand the things correctly - if the SMMU fails to reset (e.g., remains in GBPA_ABORT), all DMA for for any passed-through devices behind it will be blocked after resuming.
Quoted 18 lines
xen/drivers/passthrough/arm/smmu-v3.c +8
-0+ } +} +#endif +static const struct iommu_ops arm_smmu_iommu_ops = { .page_sizes =PAGE_SIZE_4K , .init = arm_smmu_iommu_xen_domain_init,@@ -2867,6 +2961,10 @@ static const struct iommu_ops arm_smmu_iommu_ops = { .unmap_page = arm_iommu_unmap_page, .dt_xlate = arm_smmu_dt_xlate, .add_device = arm_smmu_add_device, +#ifdef CONFIG_SYSTEM_SUSPEND + .suspend = arm_smmu_suspend, + .resume = arm_smmu_resume, +#endif }; static __init int arm_smmu_dt_init(struct dt_device_node *dev,
Re: [PATCH v7 08/12] arm/smmu-v3: add suspend/resume handlers
Hi Oleksandr,
Thank you for the review.
Quoted 213 lines · Oleksandr Tyshchenko
On 11.12.25 20:43, Mykola Kvach wrote:
Hello Mykola
Quoted 206 lines
From: Mykola Kvach <[email protected]>
Before we suspend SMMU, we want to ensure that all commands (especially
ATC_INV) have been flushed by the CMDQ, i.e. the CMDQs are empty.The suspend callback configures the SMMU to abort new transactions, disables the main translation unit and then drains the command queue to ensure completion of any in-flight commands.
The resume callback performs a full device reset via '
arm_smmu_device_reset' to bring the SMMU back to an operational state.Based-on-patch-by Pranjal Shrivastava <[email protected]>Signed-off-by Mykola Kvach <[email protected]>--- xen/drivers/passthrough/arm/smmu-v3.c | 170 ++++++++++++++++++++------ 1 file changed, 134 insertions(+), 36 deletions(-)xen/drivers/passthrough/arm/smmu-v3.c +71
-36@@ -1814,8 +1814,7 @@ static int arm_smmu_write_reg_sync(struct arm_smmu_device *smmu, u32 val, }/* GBPA is "special" */ -static int __init arm_smmu_update_gbpa (struct arm_smmu_device *smmu, -u32 set,u32 clr) +static int arm_smmu_update_gbpa (struct arm_smmu_device *smmu,u32 set,u32 clr) {int ret;u32 reg,__iomem *gbpa = smmu->base +ARM_SMMU_GBPA ;@@ -1995,10 +1994,29 @@ err_free_evtq_irq:return ret; } +static int arm_smmu_enable_irqs (struct arm_smmu_device *smmu) +{ +int ret; +u32 irqen_flags =IRQ_CTRL_EVTQ_IRQEN |IRQ_CTRL_GERROR_IRQEN ; + +if ( smmu->features &ARM_SMMU_FEAT_PRI ) + irqen_flags |=IRQ_CTRL_PRIQ_IRQEN ; + +/* Enable interrupt generation on the SMMU */ + ret =arm_smmu_write_reg_sync (smmu, irqen_flags, +ARM_SMMU_IRQ_CTRL ,ARM_SMMU_IRQ_CTRLACK ); +if ( ret ) + { +dev_warn (smmu->dev,"failed to enable irqs\n" ); +return ret; + } + +return 0 ; +} +static int __init arm_smmu_setup_irqs (struct arm_smmu_device *smmu) {int ret, irq; -u32 irqen_flags =IRQ_CTRL_EVTQ_IRQEN |IRQ_CTRL_GERROR_IRQEN ;/* Disable IRQs first */ ret = arm_smmu_write_reg_sync(smmu, 0, ARM_SMMU_IRQ_CTRL,@@ -2028,22 +2046,7 @@ static int __init arm_smmu_setup_irqs(struct arm_smmu_device *smmu) } } -if (smmu->features &ARM_SMMU_FEAT_PRI ) - irqen_flags |=IRQ_CTRL_PRIQ_IRQEN ; - -/* Enable interrupt generation on the SMMU */ - ret =arm_smmu_write_reg_sync (smmu, irqen_flags, -ARM_SMMU_IRQ_CTRL ,ARM_SMMU_IRQ_CTRLACK ); -if (ret) { -dev_warn (smmu->dev,"failed to enable irqs\n" ); - goto err_free_irqs; - } -return 0 ; - -err_free_irqs: -arm_smmu_free_irqs (smmu); -return ret; }static int arm_smmu_device_disable (struct arm_smmu_device *smmu)@@ -2057,7 +2060,7 @@ static int arm_smmu_device_disable(struct arm_smmu_device *smmu)return ret; } -static int __init arm_smmu_device_reset (struct arm_smmu_device *smmu) +static int arm_smmu_device_reset (struct arm_smmu_device *smmu) {int ret;u32 reg, enables;@@ -2163,17 +2166,9 @@ static int __init arm_smmu_device_reset(struct arm_smmu_device *smmu) } } - ret =arm_smmu_setup_irqs (smmu); -if (ret) { -dev_err (smmu->dev,"failed to setup irqs\n" ); + ret =arm_smmu_enable_irqs (smmu); +if ( ret )return ret; - } - -/* Initialize tasklets for threaded IRQs*/ -tasklet_init (&smmu->evtq_irq_tasklet, arm_smmu_evtq_tasklet, smmu); -tasklet_init (&smmu->priq_irq_tasklet, arm_smmu_priq_tasklet, smmu); -tasklet_init (&smmu->combined_irq_tasklet, arm_smmu_combined_irq_tasklet, - smmu);/* Enable the SMMU interface, or ensure bypass */ if (disable_bypass) {@@ -2181,20 +2176,16 @@ static int __init arm_smmu_device_reset(struct arm_smmu_device *smmu) }else { ret =arm_smmu_update_gbpa (smmu,0 ,GBPA_ABORT );if (ret) - goto err_free_irqs; +return ret; } ret =arm_smmu_write_reg_sync (smmu, enables,ARM_SMMU_CR0 ,ARM_SMMU_CR0ACK );if (ret) {dev_err (smmu->dev,"failed to enable SMMU interface\n" ); - goto err_free_irqs; +return ret; }return 0 ; - -err_free_irqs: -arm_smmu_free_irqs (smmu); -return ret; }static int arm_smmu_device_hw_probe (struct arm_smmu_device *smmu)@@ -2558,10 +2549,23 @@ static int __init arm_smmu_device_probe(struct platform_device *pdev)if (ret) goto out_free; + ret =arm_smmu_setup_irqs (smmu); +if ( ret ) + { +dev_err (smmu->dev,"failed to setup irqs\n" ); + goto out_free; + } + +/* Initialize tasklets for threaded IRQs*/ +tasklet_init (&smmu->evtq_irq_tasklet, arm_smmu_evtq_tasklet, smmu); +tasklet_init (&smmu->priq_irq_tasklet, arm_smmu_priq_tasklet, smmu); +tasklet_init (&smmu->combined_irq_tasklet, arm_smmu_combined_irq_tasklet, + smmu); +/* Reset the device */ ret =arm_smmu_device_reset (smmu);if (ret) - goto out_free; + goto out_free_irqs;/* * Keep a list of all probed devices. This will be used to query @@ -2575,6 +2579,8 @@ static int __init arm_smmu_device_probe(struct platform_device *pdev)return 0 ; +out_free_irqs: +arm_smmu_free_irqs (smmu); out_free:arm_smmu_free_structures (smmu);@@ -2855,6 +2861,94 @@ static void arm_smmu_iommu_xen_domain_teardown(struct domain *d)xfree (xen_domain); } +#ifdef CONFIG_SYSTEM_SUSPEND + +static int arm_smmu_suspend (void ) +{ +struct arm_smmu_device *smmu; +int ret =0 ; + +list_for_each_entry (smmu, &arm_smmu_devices, devices) + { +/* Abort all transactions before disable to avoid spurious bypass */ + ret =arm_smmu_update_gbpa (smmu,GBPA_ABORT ,0 ); +if ( ret ) + goto fail; + +/* Disable the SMMU via CR0.EN and all queues except CMDQ */ + ret =arm_smmu_write_reg_sync (smmu,CR0_CMDQEN ,ARM_SMMU_CR0 , +ARM_SMMU_CR0ACK ); +if ( ret ) + { +dev_err (smmu->dev,"Timed-out while disabling smmu\n" ); + goto fail; + } + +/* +* At this point the SMMU is completely disabled and won't access +* any translation/config structures, even speculative accesses +* aren't performed as per the IHI0070 spec (section 6.3.9.6). +*/ +
Quoted 8 lines
xen/drivers/passthrough/arm/smmu-v3.c static void arm_smmu_iommu_xen_domain_teardown(struct domain *d) · line 2894
Quoted 2 lines
xen/drivers/passthrough/arm/smmu-v3.c +2
-0+/* Wait for the CMDQs to be drained to flush any pending commands */ + ret =queue_poll_cons (&smmu->cmdq.q, true,0 );I wonder, why ignoring
ARM_SMMU_FEAT_SEVin suspend? In the runtime function__arm_smmu_cmdq_issue_sync(), the driver checks if the SMMU supportsARM_SMMU_FEAT_SEVand passes this flag toqueue_poll_cons(). However, here, this check is missing, and the wfe argument is hardcoded to 0.
Good catch, that's an oversight on my side. The suspend path should indeed use the same SEV/WFE handling as the runtime CMD_SYNC path instead of hardcoding wfe = 0. I'll switch this to pass
!!(smmu->features & ARM_SMMU_FEAT_SEV) to queue_poll_cons().
Quoted 29 lines
Quoted 29 lines
xen/drivers/passthrough/arm/smmu-v3.c +27
-0+if ( ret ) + { +dev_err (smmu->dev,"Draining queues timed-out\n" ); + goto fail; + } + +/* Disable everything */ + ret =arm_smmu_device_disable (smmu); +if ( ret ) + goto fail; + +dev_dbg (smmu->dev,"Suspended smmu\n" ); + } + +return 0 ; + + fail: + { +int rc; + +/* Reset the device that failed as well as any already-suspended ones. */ + rc =arm_smmu_device_reset (smmu); +if ( rc ) +dev_err (smmu->dev,"Failed to reset during resume operation: %d\n" , rc); + +list_for_each_entry_continue_reverse (smmu, &arm_smmu_devices, devices) + {
Quoted 8 lines
xen/drivers/passthrough/arm/smmu-v3.c static void arm_smmu_iommu_xen_domain_teardown(struct domain *d) · line 2925
Quoted 4 lines
xen/drivers/passthrough/arm/smmu-v3.c +4
-0+ rc =arm_smmu_device_reset (smmu); +if ( rc ) +dev_err (smmu->dev,"Failed to reset during resume operation: %d\n" , rc); + }NIT: Could this duplicated reset call (and error message) be optimized somehow? Maybe, by using a do-while loop to manually walk back up the list from the current SMMU to the head, but not sure.
Yes, that can be cleaned up. The duplicated reset + error reporting is just rollback boilerplate, so I'll fold it into a small helper and reuse it for the failing SMMU and the reverse walk over the already-suspended ones. That should also let me fix the misleading "during resume operation" wording in this suspend rollback path.
Quoted 25 lines
Quoted 14 lines
xen/drivers/passthrough/arm/smmu-v3.c +12
-0+ } + +return ret; +} + +static void arm_smmu_resume (void ) +{ +int ret; +struct arm_smmu_device *smmu; + +list_for_each_entry (smmu, &arm_smmu_devices, devices) + {xen/drivers/passthrough/arm/smmu-v3.c static void arm_smmu_iommu_xen_domain_teardown(struct domain *d) · line 2947
Quoted 10 lines
xen/drivers/passthrough/arm/smmu-v3.c +10
-0+dev_dbg (smmu->dev,"Resuming device\n" ); + +/* +* The reset will re-initialize all the base addresses, queues, +* prod and cons maintained within struct arm_smmu_device as well as +* re-enable the interrupts. +*/ + ret =arm_smmu_device_reset (smmu); +if ( ret ) +dev_err (smmu->dev,"Failed to reset during resume operation: %d\n" , ret);
Quoted 7 lines
In your GICv3 ITS patch, a failure during resume triggers a
panic(), but here only an error message that might go unnoticed. May I please ask, why such diverging? The IOMMU is as critical as the Interrupt Controller. I see that you configure Abort state during suspend, so if I understand the things correctly - if the SMMU fails to reset (e.g., remains inGBPA_ABORT), all DMA for for any passed-through devices behind it will be blocked after resuming.
Fair point. Logging only is too weak here. Unlike the suspend failure path, resume has no recovery path, and iommu_ops.resume() currently cannot propagate an error upwards. If arm_smmu_device_reset() fails, the SMMU may remain unusable after resume (for example, with transactions still aborted or translation disabled), which can silently break DMA for devices behind it. I will therefore treat a resume reset failure as fatal rather than just logging it.
Best regards,
Mykola
Quoted 21 lines
Quoted 20 lines
xen/drivers/passthrough/arm/smmu-v3.c +8
-0+ } +} +#endif +static const struct iommu_ops arm_smmu_iommu_ops = { .page_sizes =PAGE_SIZE_4K , .init = arm_smmu_iommu_xen_domain_init,@@ -2867,6 +2961,10 @@ static const struct iommu_ops arm_smmu_iommu_ops = { .unmap_page = arm_iommu_unmap_page, .dt_xlate = arm_smmu_dt_xlate, .add_device = arm_smmu_add_device, +#ifdef CONFIG_SYSTEM_SUSPEND + .suspend = arm_smmu_suspend, + .resume = arm_smmu_resume, +#endif }; static __init int arm_smmu_dt_init(struct dt_device_node *dev,
PATCH v7 9/12 xen/arm: Resume memory management on Xen resume
In reply to Mykola KvachFrom: Mirela Simonovic <[email protected]>
The MMU must be enabled during the resume path before restoring context, as virtual addresses are used to access the saved context data.
This patch adds MMU setup during resume by reusing the existing enable_secondary_cpu_mm function, which enables data cache and the MMU. Before the MMU is enabled, the content of TTBR0_EL2 is changed to point to init_ttbr (page tables used at runtime).
---
Changes in v7:
- no functional changes, just moved commit
--- xen/arch/arm/arm64/head.S | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
xen/arch/arm/arm64/head.S +24 -0
@@ -561,6 +561,30 @@ END(efi_xen_start) #endif /* CONFIG_ARM_EFI */ +#ifdef CONFIG_SYSTEM_SUSPEND + +FUNC(hyp_resume) + /* Initialize the UART if earlyprintk has been enabled. */ +#ifdef CONFIG_EARLY_PRINTK + bl init_uart +#endif + PRINT_ID("- Xen resuming -\r\n") + + bl check_cpu_mode + bl cpu_init + + ldr x0, =start + adr x20, start /* x20 := paddr (start) */ + sub x20, x20, x0 /* x20 := phys-offset */ + ldr lr, =mmu_resumed + b enable_secondary_cpu_mm + +mmu_resumed: + b . +END(hyp_resume) + +#endif /* CONFIG_SYSTEM_SUSPEND */ + /* * Local variables: * mode: ASM
Signature · 1 line
2.43.0
PATCH v7 10/12 xen/arm: Save/restore context on suspend/resume
In reply to Mykola KvachFrom: Mirela Simonovic <[email protected]>
The context of CPU general purpose and system control registers must be saved on suspend and restored on resume. This is implemented in prepare_resume_ctx and before the return from the hyp_resume function. The prepare_resume_ctx must be invoked just before the PSCI system suspend call is issued to the ATF. The prepare_resume_ctx must return a non-zero value so that the calling 'if' statement evaluates to true, causing the system suspend to be invoked. Upon resume, the context saved on suspend will be restored, including the link register. Therefore, after restoring the context, the control flow will return to the address pointed to by the saved link register, which is the place from which prepare_resume_ctx was called. To ensure that the calling 'if' statement does not again evaluate to true and initiate system suspend, hyp_resume must return a zero value after restoring the context.
Note that the order of saving register context into cpu_context structure must match the order of restoring.
Support for ARM32 is not implemented. Instead, compilation fails with a build-time error if suspend is enabled for ARM32.
---
Changes in v7:
- no changes
--- xen/arch/arm/Makefile | 1 + xen/arch/arm/arm64/head.S | 90 +++++++++++++++++++++++++++++- xen/arch/arm/include/asm/suspend.h | 26 +++++++++ xen/arch/arm/suspend.c | 14 +++++ 4 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 xen/arch/arm/suspend.c
xen/arch/arm/Makefile +1 -0
@@ -51,6 +51,7 @@ obj-y += setup.o obj-y += shutdown.o obj-y += smp.o obj-y += smpboot.o +obj-$(CONFIG_SYSTEM_SUSPEND) += suspend.o obj-$(CONFIG_SYSCTL) += sysctl.o obj-y += time.o obj-y += traps.o
xen/arch/arm/arm64/head.S +89 -1
102 lines not on this page · raw message
xen/arch/arm/include/asm/suspend.h +26 -0
@@ -3,6 +3,8 @@#ifndef ARM_SUSPEND_H #define ARM_SUSPEND_H +#include <asm/types.h> +struct domain ;struct vcpu ;
@@ -14,6 +16,30 @@ struct resume_info {int arch_domain_resume (struct domain *d); +#ifdef CONFIG_SYSTEM_SUSPEND +#ifdef CONFIG_ARM_64 +struct cpu_context { +register_t callee_regs[12 ]; +register_t sp; +register_t vbar_el2; +register_t vtcr_el2; +register_t vttbr_el2; +register_t tpidr_el2; +register_t mdcr_el2; +register_t hstr_el2; +register_t cptr_el2; +register_t hcr_el2; +}__aligned(16) ; +#else +#error "Define cpu_context structure for arm32" +#endif + +extern struct cpu_context cpu_context; + +int prepare_resume_ctx (struct cpu_context *ptr); +void hyp_resume (void ); +#endif /* CONFIG_SYSTEM_SUSPEND */ +#endif /* ARM_SUSPEND_H */ /*
xen/arch/arm/suspend.c new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <asm/suspend.h> + +struct cpu_context cpu_context = {}; + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
2.43.0
PATCH v7 11/12 xen/arm: Implement PSCI SYSTEM_SUSPEND call (host interface)
In reply to Mykola KvachFrom: Mirela Simonovic <[email protected]>
Invoke PSCI SYSTEM_SUSPEND to finalize Xen's suspend sequence on ARM64 platforms. Pass the resume entry point (hyp_resume) as the first argument to EL3. The resume handler is currently a stub and will be implemented later in assembly. Ignore the context ID argument, as is done in Linux.
Only enable this path when CONFIG_SYSTEM_SUSPEND is set and PSCI version is >= 1.0.
---
Changes in v7:
- no changes
--- xen/arch/arm/include/asm/psci.h | 1 + xen/arch/arm/psci.c | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-)
xen/arch/arm/include/asm/psci.h +1 -0
@@ -23,6 +23,7 @@ int call_psci_cpu_on(int cpu);void call_psci_cpu_off (void );void call_psci_system_off (void );void call_psci_system_reset (void ); +int call_psci_system_suspend (void );/* Range of allocated PSCI function numbers */ #define PSCI_FNUM_MIN_VALUE _AC(0,U)
xen/arch/arm/psci.c +22 -1
@@ -17,17 +17,20 @@#include <asm/cpufeature.h> #include <asm/psci.h> #include <asm/acpi.h> +#include <asm/suspend.h> /* * While a 64-bit OS can make calls with SMC32 calling conventions, for * some calls it is necessary to use SMC64 to pass or return 64-bit values. -* For such calls PSCI_0_2_FN_NATIVE(x) will choose the appropriate +* For such calls PSCI_*_FN_NATIVE(x) will choose the appropriate * (native-width) function ID. */ #ifdef CONFIG_ARM_64 #define PSCI_0_2_FN_NATIVE (name) PSCI_0_2_FN64_##name +#define PSCI_1_0_FN_NATIVE (name) PSCI_1_0_FN64_##name#else #define PSCI_0_2_FN_NATIVE (name) PSCI_0_2_FN32_##name +#define PSCI_1_0_FN_NATIVE (name) PSCI_1_0_FN32_##name#endif uint32_t psci_ver;
@@ -60,6 +63,24 @@ void call_psci_cpu_off(void) } } +int call_psci_system_suspend (void ) +{ +#ifdef CONFIG_SYSTEM_SUSPEND +struct arm_smccc_res res; + +if ( psci_ver <PSCI_VERSION (1 ,0 ) ) +return PSCI_NOT_SUPPORTED ; + +/* 2nd argument (context ID) is not used */ +arm_smccc_smc (PSCI_1_0_FN_NATIVE (SYSTEM_SUSPEND ),__pa (hyp_resume), &res); +return PSCI_RET (res); +#else +dprintk (XENLOG_WARNING , +"SYSTEM_SUSPEND not supported (CONFIG_SYSTEM_SUSPEND disabled)\n" ); +return PSCI_NOT_SUPPORTED ; +#endif +} +void call_psci_system_off (void ) {if ( psci_ver >PSCI_VERSION (0 ,1 ) )
Signature · 1 line
2.43.0
PATCH v7 12/12 xen/arm: Add support for system suspend triggered by control domain
In reply to Mykola KvachFrom: Mirela Simonovic <[email protected]>
Trigger Xen suspend when the control domain initiates suspend via SHUTDOWN_suspend. Redirect system suspend to CPU#0 to ensure the suspend logic runs on the boot CPU, as required.
Introduce full suspend/resume infrastructure gated by CONFIG_SYSTEM_SUSPEND, including logic to:
- disable and enable non-boot physical CPUs
- freeze and thaw domains
- suspend and resume the GIC, timer, iommu and console
- maintain system state before and after suspend
On boot, init_ttbr is normally initialized during secondary CPU hotplug. On uniprocessor systems, this would leave init_ttbr uninitialized, causing resume to fail. To address this, the boot CPU now sets init_ttbr during suspend.
Select HAS_SYSTEM_SUSPEND for ARM_64.
Introduce CONFIG_HWDOM_SHUTDOWN_ON_SUSPEND (default y, disabled only on ARM_64 with SYSTEM_SUSPEND) so we skip hwdom_shutdown() for SHUTDOWN_suspend when the hardware domain survives suspend. Non-ARM behaviour is unchanged, and the ARM/system-suspend case no longer needs arch-specific checks in the code.
Note: the code is guarded by CONFIG_SYSTEM_SUSPEND, which is currently only selected when UNSUPPORTED is set, and thus the functionality is neither enabled by default nor even built.
---
Changes in V7:
- Control domain is responsible for host suspend
- Add an empty inline host_system_suspend() function when SYSTEM_SUSPEND config is disabled
- Use IS_ENABLED() for config checking instead of #ifdef
- Replace #ifdef checks in domain_shutdown() with IS_ENABLED() to simplify control flow.
- Factor hardware domain shutdown condition into a helper (need_hwdom_shutdown()) to avoid preprocessor directives inside the function.
- Squash with iommu suspend/resume commit
--- xen/arch/arm/Kconfig | 1 + xen/arch/arm/include/asm/mm.h | 2 + xen/arch/arm/include/asm/suspend.h | 7 +- xen/arch/arm/mmu/smpboot.c | 2 +- xen/arch/arm/suspend.c | 139 +++++++++++++++++++++++++++++ xen/arch/arm/vpsci.c | 12 ++- xen/common/Kconfig | 5 ++ xen/common/domain.c | 7 +- xen/drivers/passthrough/arm/smmu.c | 10 +++ 9 files changed, 180 insertions(+), 5 deletions(-)
xen/arch/arm/Kconfig +1 -0
@@ -8,6 +8,7 @@ config ARM_64 depends on !ARM_32 select 64BIT select HAS_FAST_MULTIPLY + select HAS_SYSTEM_SUSPEND if !MPU && UNSUPPORTED select HAS_VPCI_GUEST_SUPPORT if PCI_PASSTHROUGH config ARM
xen/arch/arm/include/asm/mm.h +2 -0
@@ -364,6 +364,8 @@ static inline void page_set_xenheap_gfn(struct page_info *p, gfn_t gfn) } while ( (y = cmpxchg(&p->u.inuse.type_info, x, nx)) != x ); } +void set_init_ttbr (lpae_t *root); +#endif /* __ARCH_ARM_MM__ */ /* * Local variables:
xen/arch/arm/include/asm/suspend.h +6 -1
@@ -38,7 +38,12 @@ extern struct cpu_context cpu_context;int prepare_resume_ctx (struct cpu_context *ptr);void hyp_resume (void ); -#endif /* CONFIG_SYSTEM_SUSPEND */ +void host_system_suspend (struct domain *d); + +#else /* !CONFIG_SYSTEM_SUSPEND */ + +static inline void host_system_suspend (struct domain *d) { (void )d; } +#endif #endif /* ARM_SUSPEND_H */
xen/arch/arm/mmu/smpboot.c +1 -1
@@ -72,7 +72,7 @@ static void clear_boot_pagetables(void)clear_table (boot_third); } -static void set_init_ttbr (lpae_t *root) +void set_init_ttbr (lpae_t *root) {/* * init_ttbr is part of the identity mapping which is read-only. So
xen/arch/arm/suspend.c +139 -0
148 lines not on this page · raw message
xen/arch/arm/vpsci.c +10 -2
@@ -4,6 +4,7 @@#include <xen/types.h> #include <asm/current.h> +#include <asm/suspend.h> #include <asm/vgic.h> #include <asm/vpsci.h> #include <asm/event.h>
@@ -210,6 +211,11 @@ static void do_psci_0_2_system_reset(void)domain_shutdown (d,SHUTDOWN_reboot); } +static bool can_trigger_host_suspend (struct domain *d) +{ +return is_control_domain (d); +} +static int32_t do_psci_1_0_system_suspend (register_t epoint,register_t cid) {int32_t rc;
@@ -221,8 +227,7 @@ static int32_t do_psci_1_0_system_suspend(register_t epoint, register_t cid)if (is_64bit_domain (d) && is_thumb )return PSCI_INVALID_ADDRESS ; -/* SYSTEM_SUSPEND is not supported for the hardware domain yet */ -if (is_hardware_domain (d) ) +if ( !IS_ENABLED (CONFIG_SYSTEM_SUSPEND ) &&can_trigger_host_suspend (d) )return PSCI_NOT_SUPPORTED ;/* Ensure that all CPUs other than the calling one are offline */
@@ -249,6 +254,9 @@ static int32_t do_psci_1_0_system_suspend(register_t epoint, register_t cid)"SYSTEM_SUSPEND requested, epoint=%#" PRIregister", cid=%#" PRIregister"\n" , epoint, cid); +if (can_trigger_host_suspend (d) ) +host_system_suspend (d); +return rc; }
xen/common/Kconfig +5 -0
@@ -137,6 +137,11 @@ config HAS_EX_TABLE config HAS_FAST_MULTIPLY bool +config HAS_HWDOM_SHUTDOWN_ON_SUSPEND + bool + default y + depends on !ARM_64 || !SYSTEM_SUSPEND + config HAS_IOPORTS bool
xen/common/domain.c +6 -1
@@ -1324,6 +1324,11 @@ void __domain_crash(struct domain *d)domain_shutdown (d, SHUTDOWN_crash); } +static inline bool need_hwdom_shutdown (uint8_t reason) +{ +return IS_ENABLED (CONFIG_HAS_HWDOM_SHUTDOWN_ON_SUSPEND ) || + reason != SHUTDOWN_suspend; +}int domain_shutdown (struct domain *d,u8 reason) {
@@ -1340,7 +1345,7 @@ int domain_shutdown(struct domain *d, u8 reason) d->shutdown_code = reason; reason = d->shutdown_code; -if (is_hardware_domain (d) ) +if (is_hardware_domain (d) &&need_hwdom_shutdown (reason) )hwdom_shutdown (reason);if ( d->is_shutting_down )
xen/drivers/passthrough/arm/smmu.c +10 -0
@@ -2947,6 +2947,13 @@ static void arm_smmu_iommu_domain_teardown(struct domain *d)xfree (xen_domain); } +#ifdef CONFIG_SYSTEM_SUSPEND +static int arm_smmu_suspend (void ) +{ +return -ENOSYS ; +} +#endif +static const struct iommu_ops arm_smmu_iommu_ops = { .page_sizes =PAGE_SIZE_4K , .init = arm_smmu_iommu_domain_init,
@@ -2960,6 +2967,9 @@ static const struct iommu_ops arm_smmu_iommu_ops = { .map_page = arm_iommu_map_page, .unmap_page = arm_iommu_unmap_page, .dt_xlate = arm_smmu_dt_xlate_generic, +#ifdef CONFIG_SYSTEM_SUSPEND + .suspend = arm_smmu_suspend, +#endif };static struct arm_smmu_device *find_smmu (const struct device *dev)
Signature · 1 line
2.43.0
Re: [PATCH v7 12/12] xen/arm: Add support for system suspend triggered by control domain
xen/common/Kconfig config HAS_EX_TABLE · line 143
Quoted 10 lines · Mykola Kvach
xen/common/Kconfig +4
-0@@ -137,6 +137,11 @@ config HAS_EX_TABLE config HAS_FAST_MULTIPLY bool +config HAS_HWDOM_SHUTDOWN_ON_SUSPEND + bool + default y + depends on !ARM_64 || !SYSTEM_SUSPEND
As written, this would want to be "def_bool y". However, I think I indicated previously that imo it would be nice if we could stop adding more "depends on" referencing particular architectures. Instead "select" or "imply" from xen/arch/<arch>/Kconfig appears more desirable to use in such cases. That way each arch can control what it wants without needing to touch common code.
As an aside, in the context of PV_SHIM_EXCLUSIVE it was also said several times that negative dependencies aren't very nice to have. Here we have no prompt, so the "allyesconfig" concern doesn't apply, but I still thought I'd mention this.
xen/common/domain.c void __domain_crash(struct domain *d) · line 1327
Quoted 7 lines
xen/common/domain.c +1
-0@@ -1324,6 +1324,11 @@ void __domain_crash(struct domain *d)domain_shutdown (d, SHUTDOWN_crash); } +static inline bool need_hwdom_shutdown (uint8_t reason)
Personally I think "want" would better express things, but I don't really mind "need".
xen/common/domain.c void __domain_crash(struct domain *d) · line 1331
Quoted 4 lines
xen/common/domain.c +4
-0+{ +return IS_ENABLED (CONFIG_HAS_HWDOM_SHUTDOWN_ON_SUSPEND ) || + reason != SHUTDOWN_suspend; +}
Seeing this in use, I wonder if HAS_ is really suitable here.
Jan
Re: [PATCH v7 12/12] xen/arm: Add support for system suspend triggered by control domain
Hi Jan,
Quoted 8 lines · Jan Beulich
Quoted 6 lines · Mykola Kvach
xen/common/Kconfig +0
-0@@ -137,6 +137,11 @@ config HAS_EX_TABLE config HAS_FAST_MULTIPLY bool
Quoted 6 lines
xen/common/Kconfig config HAS_EX_TABLE · line 143
Quoted 4 lines
xen/common/Kconfig +4
-0+config HAS_HWDOM_SHUTDOWN_ON_SUSPEND + bool + default y + depends on !ARM_64 || !SYSTEM_SUSPENDAs written, this would want to be "
def_booly". However, I think I indicated
OK, I’ll switch this to def_bool.
Quoted 9 lines
previously that imo it would be nice if we could stop adding more "depends on" referencing particular architectures. Instead "select" or "imply" from xen/arch/<arch>/Kconfig appears more desirable to use in such cases. That way each arch can control what it wants without needing to touch common code.
As an aside, in the context of
PV_SHIM_EXCLUSIVEit was also said several times that negative dependencies aren't very nice to have. Here we have no prompt, so the "allyesconfig" concern doesn't apply, but I still thought I'd mention this.
I used the common-level dependency only to avoid adding selects in every other arch Kconfig, as the only exception I need is
ARM_64 && SYSTEM_SUSPEND.
If you still prefer keeping all arch-specific handling under xen/arch/<arch>/Kconfig, I can rework it accordingly.
Quoted 11 lines
xen/common/domain.c void __domain_crash(struct domain *d) · line 1327
Quoted 8 lines
xen/common/domain.c +1
-0@@ -1324,6 +1324,11 @@ void __domain_crash(struct domain *d)domain_shutdown (d, SHUTDOWN_crash); } +static inline bool need_hwdom_shutdown (uint8_t reason)Personally I think "want" would better express things, but I don't really mind "need".
I'll change it to "want".
Quoted 7 lines
xen/common/domain.c void __domain_crash(struct domain *d) · line 1331
Quoted 5 lines
xen/common/domain.c +4
-0+{ +return IS_ENABLED (CONFIG_HAS_HWDOM_SHUTDOWN_ON_SUSPEND ) || + reason != SHUTDOWN_suspend; +}Seeing this in use, I wonder if
HAS_is really suitable here.
What name would you consider more suitable here?
Best regards,
Mykola
Quoted 2 lines
Jan
Re: [PATCH v7 12/12] xen/arm: Add support for system suspend triggered by control domain
Quoted 27 lines · Mykola Kvach
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Mykola Kvach
xen/common/Kconfig +0
-0@@ -137,6 +137,11 @@ config HAS_EX_TABLE config HAS_FAST_MULTIPLY boolQuoted 6 lines
xen/common/Kconfig config HAS_EX_TABLE · line 143
Quoted 4 lines
xen/common/Kconfig +4
-0+config HAS_HWDOM_SHUTDOWN_ON_SUSPEND + bool + default y + depends on !ARM_64 || !SYSTEM_SUSPENDAs written, this would want to be "
def_booly". However, I think I indicatedOK, I’ll switch this to
def_bool.Quoted 9 lines
previously that imo it would be nice if we could stop adding more "depends on" referencing particular architectures. Instead "select" or "imply" from xen/arch/<arch>/Kconfig appears more desirable to use in such cases. That way each arch can control what it wants without needing to touch common code.
As an aside, in the context of
PV_SHIM_EXCLUSIVEit was also said several times that negative dependencies aren't very nice to have. Here we have no prompt, so the "allyesconfig" concern doesn't apply, but I still thought I'd mention this.
Quoted 6 lines
I used the common-level dependency only to avoid adding selects in every other arch
Kconfig, as the only exception I need isARM_64 && SYSTEM_SUSPEND.If you still prefer keeping all arch-specific handling under xen/arch/<arch>/Kconfig, I can rework it accordingly.
Imo there are two options: Do as you suggest, but with an option not starting HAS_*. Or use HAS_ with per-arch selects (which I think I'd prefer).
To limit the number of selects needed, perhaps the sense of the option may want inverting? Otoh I don't think we know yet what RISC-V and PPC are going to want?
Quoted 14 lines
Quoted 10 lines
xen/common/domain.c void __domain_crash(struct domain *d) · line 1327
Quoted 7 lines
xen/common/domain.c +1
-0@@ -1324,6 +1324,11 @@ void __domain_crash(struct domain *d)domain_shutdown (d, SHUTDOWN_crash); } +static inline bool need_hwdom_shutdown (uint8_t reason)Personally I think "want" would better express things, but I don't really mind "need".
I'll change it to "want".
Quoted 1 line
Quoted 8 lines
Quoted 6 lines
xen/common/domain.c void __domain_crash(struct domain *d) · line 1331
Quoted 4 lines
xen/common/domain.c +4
-0+{ +return IS_ENABLED (CONFIG_HAS_HWDOM_SHUTDOWN_ON_SUSPEND ) || + reason != SHUTDOWN_suspend; +}Seeing this in use, I wonder if
HAS_is really suitable here.What name would you consider more suitable here?
As per above, HAS_ dropped would be an option. Yet that goes against my preference above. Maybe HAS_ really is okay-ish here, despite what I said earlier.
Jan