Fix NMI backtrace for Inforce IFC6410
cover Fix NMI backtrace for Inforce IFC6410
After spotting some problems with the SysRq-L on Inforce IFC6410 I ran some tests (see patch 2) and concluded that certain SGI IDs cannot be used by Linux on these platforms because they have been reserved for use by the secure world.
This patchset includes both a patch to resolve the problem on Inforce IFC6410 and a patch to detect and report reserved SGI IDs during boot. The patch (deliberately) keeps quiet on platforms where the kernel's world is not subject to any restrictions.
Daniel Thompson (2):
arm: Fix "NMI" backtrace for Inforce IFC6410 irqchip/gic: Identify and report any reserved SGI IDs
arch/arm/kernel/smp.c | 3 ++- drivers/irqchip/irq-gic.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-)
--
2.5.0
PATCH 1/2 arm: Fix "NMI" backtrace for Inforce IFC6410
SysRq-L does not generate a backtrace from all CPUs when I test it on my Inforce IFC6410 platform (Snapdragon 600). The stack dump code, triggered by IPI_CPU_BACKTRACE, never runs on the other CPUs. Eventually we hit the 10 second timeout and a subset of the expected stack dumps on are shown on the console.
It is likely this is because SGI IDs 14 and 15 have been reserved for use by secure world on this platform. For IFC6410 platform the code works as expected when IPI_CPU_BACKTRACE is set to any value in the interval 9..13.
--- arch/arm/kernel/smp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm/kernel/smp.c +2 -1
@@ -73,7 +73,8 @@ enum ipi_msg_type {IPI_CPU_STOP ,IPI_IRQ_WORK ,IPI_COMPLETION , - IPI_CPU_BACKTRACE = 15, + IPI_CPU_BACKTRACE = 13, + /* 14 and 15 are reserved; they do not work on some Krait CPUs */ };static DECLARE_COMPLETION (cpu_running);
Signature · 1 line
2.5.0
PATCH 2/2 irqchip/gic: Identify and report any reserved SGI IDs
In reply to Daniel ThompsonIt is possible for the secure world to reserve certain SGI IDs for itself. Currently we have limited visibility of which IDs are safe to use for IPIs.
Modify the GIC initialization code to actively search for reserved SGI IDs and report if any are found. Warn even more loudly if the reserved SGIs overlap with the normal IPI range.
When run on an Inforce IFC6410 (Snapdragon 600) this code produces the following messages:
~~~ cut here ~~~
CPU0: Detected reserved SGI IDs: 14-15
CPU1: Detected reserved SGI IDs: 15
CPU2: Detected reserved SGI IDs: 15
CPU3: Detected reserved SGI IDs: 15
~~~ cut here ~~~
--- drivers/irqchip/irq-gic.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+)
drivers/irqchip/irq-gic.c +53 -0
@@ -490,6 +490,7 @@ static void gic_cpu_init(struct gic_chip_data *gic)void __iomem *base =gic_data_cpu_base (gic);unsigned int cpu_mask, cpu =smp_processor_id ();int i; +DECLARE_BITMAP (sgi_mask,16 );/* * Setting up the CPU map is only relevant for the primary GIC
@@ -511,6 +512,58 @@ static void gic_cpu_init(struct gic_chip_data *gic)for (i =0 ; i <NR_GIC_CPU_IF ; i++)if (i != cpu) gic_cpu_map[i] &= ~cpu_mask; + +/* +* Fiddle with the SGI set/clear registers to try identify +* any IPIs that are reserved for secure world. +*/ +bitmap_fill (sgi_mask,16 ); + +for (i =0 ; i <16 ; i++) { +void __iomem *set_reg = + dist_base +GIC_DIST_SGI_PENDING_SET + (i & ~3 ); +void __iomem *clear_reg = + dist_base +GIC_DIST_SGI_PENDING_CLEAR + (i & ~3 ); +unsigned long mask = cpu_mask << (8 *(i%4 )); +unsigned long flags, pending, after_clear, after_set; + +local_irq_save (flags); + +/* record original value */ + pending =readl_relaxed (set_reg); + +/* clear, test, set, and test again */ +writel_relaxed (mask, clear_reg); + after_clear =readl_relaxed (set_reg); +writel_relaxed (mask, set_reg); + after_set =readl_relaxed (set_reg); + +/* restore original value */ +writel_relaxed (mask & ~pending, clear_reg); + +local_irq_restore (flags); + +if (mask & ~after_clear && mask & after_set) +clear_bit (i, sgi_mask); + } + +/* +* Show the SGI mask if it is "interesting". Here interesting +* means that the set/clear register is implemented +* (mask is not full) and it tells us that the secure world +* has reserved some SGIs (mask is not empty). +*/ +if (!bitmap_full (sgi_mask,16 ) && !bitmap_empty (sgi_mask,16 )) +pr_info ("CPU%d: Detected reserved SGI IDs: %*pbl\n" , + cpu,16 , sgi_mask); + +/* +* Yell if the reserved IDs make the system unviable. +*/ +if (!bitmap_full (sgi_mask,16 ) && +find_first_bit (sgi_mask,16 ) <NR_IPI ) +pr_crit ("CPU%d: Not enough SGI IDs; expect failure\n" , + cpu); }gic_cpu_config (dist_base,NULL );
Signature · 1 line
2.5.0
Re: [PATCH 2/2] irqchip/gic: Identify and report any reserved SGI IDs
Hi Daniel,
Quoted 41 lines · Daniel Thompson
It is possible for the secure world to reserve certain SGI IDs for itself. Currently we have limited visibility of which IDs are safe to use for IPIs.
Modify the GIC initialization code to actively search for reserved SGI IDs and report if any are found. Warn even more loudly if the reserved SGIs overlap with the normal IPI range.
When run on an Inforce IFC6410 (Snapdragon 600) this code produces the following messages:
~~~ cut here ~~~
CPU0: Detected reserved SGI IDs: 14-15
CPU1: Detected reserved SGI IDs: 15
CPU2: Detected reserved SGI IDs: 15
CPU3: Detected reserved SGI IDs: 15
~~~ cut here ~~~Signed-off-by Daniel Thompson <[email protected]>--- drivers/irqchip/irq-gic.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+)drivers/irqchip/irq-gic.c +5
-0@@ -490,6 +490,7 @@ static void gic_cpu_init(struct gic_chip_data *gic)void __iomem *base =gic_data_cpu_base (gic);unsigned int cpu_mask, cpu =smp_processor_id ();int i; +DECLARE_BITMAP (sgi_mask,16 );/* * Setting up the CPU map is only relevant for the primary GIC @@ -511,6 +512,58 @@ static void gic_cpu_init(struct gic_chip_data *gic)for (i =0 ; i <NR_GIC_CPU_IF ; i++)if (i != cpu) gic_cpu_map[i] &= ~cpu_mask; + +/* +* Fiddle with the SGI set/clear registers to try identify +* any IPIs that are reserved for secure world.
drivers/irqchip/irq-gic.c static void gic_cpu_init(struct gic_chip_data *gic) · line 528
Quoted 10 lines
drivers/irqchip/irq-gic.c +10
-0+*/ +bitmap_fill (sgi_mask,16 ); + +for (i =0 ; i <16 ; i++) { +void __iomem *set_reg = + dist_base +GIC_DIST_SGI_PENDING_SET + (i & ~3 ); +void __iomem *clear_reg = + dist_base +GIC_DIST_SGI_PENDING_CLEAR + (i & ~3 ); +unsigned long mask = cpu_mask << (8 *(i%4 )); +unsigned long flags, pending, after_clear, after_set;
Please make these u32, as unsigned long is 64bit on arm64. Another thing to note is that GICD_CPEND{S,C}SGIRn are byte accessible, so you can save yourself some this hassle shifting things around and just write a single byte. You're already writing 16 times anyway...
Another thing to consider is that these locations are only defined on GICv2 and not GICv1, so this patch is likely to cause trouble on older HW.
drivers/irqchip/irq-gic.c static void gic_cpu_init(struct gic_chip_data *gic) · line 530
Quoted 2 lines
drivers/irqchip/irq-gic.c +2
-0+ +local_irq_save (flags);
Why do you need to do this? The CPU interface is not enabled yet, so I can't see how you could get an interrupt on this CPU.
drivers/irqchip/irq-gic.c static void gic_cpu_init(struct gic_chip_data *gic) · line 539
Quoted 9 lines
drivers/irqchip/irq-gic.c +9
-0+ +/* record original value */ + pending =readl_relaxed (set_reg); + +/* clear, test, set, and test again */ +writel_relaxed (mask, clear_reg); + after_clear =readl_relaxed (set_reg); +writel_relaxed (mask, set_reg); + after_set =readl_relaxed (set_reg);
It should be enough to write to the SET register, and read back, as the bit is RAZ/WI when the interrupt is Group-0.
Quoted 21 lines
drivers/irqchip/irq-gic.c +20
-0+ +/* restore original value */ +writel_relaxed (mask & ~pending, clear_reg); + +local_irq_restore (flags); + +if (mask & ~after_clear && mask & after_set) +clear_bit (i, sgi_mask); + } + +/* +* Show the SGI mask if it is "interesting". Here interesting +* means that the set/clear register is implemented +* (mask is not full) and it tells us that the secure world +* has reserved some SGIs (mask is not empty). +*/ +if (!bitmap_full (sgi_mask,16 ) && !bitmap_empty (sgi_mask,16 )) +pr_info ("CPU%d: Detected reserved SGI IDs: %*pbl\n" , + cpu,16 , sgi_mask); +
drivers/irqchip/irq-gic.c static void gic_cpu_init(struct gic_chip_data *gic) · line 569
Quoted 10 lines
drivers/irqchip/irq-gic.c +7
-0+/* +* Yell if the reserved IDs make the system unviable. +*/ +if (!bitmap_full (sgi_mask,16 ) && +find_first_bit (sgi_mask,16 ) <NR_IPI ) +pr_crit ("CPU%d: Not enough SGI IDs; expect failure\n" , + cpu); }gic_cpu_config (dist_base,NULL );
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH 2/2] irqchip/gic: Identify and report any reserved SGI IDs
Quoted 1 line · Marc Zyngier
Hi Daniel,
Hi Marc
Thanks for the review.
Quoted 17 lines · Daniel Thompson
Quoted 16 lines
It is possible for the secure world to reserve certain SGI IDs for itself. Currently we have limited visibility of which IDs are safe to use for IPIs.
Modify the GIC initialization code to actively search for reserved SGI IDs and report if any are found. Warn even more loudly if the reserved SGIs overlap with the normal IPI range.
When run on an Inforce IFC6410 (Snapdragon 600) this code produces the following messages:
~~~ cut here ~~~
CPU0: Detected reserved SGI IDs: 14-15
CPU1: Detected reserved SGI IDs: 15
CPU2: Detected reserved SGI IDs: 15
CPU3: Detected reserved SGI IDs: 15
~~~ cut here ~~~
Quoted 1 line
Quoted 1 line
Signed-off-by Daniel Thompson <[email protected]>
BTW you *didn't* say "this code is pointless and I hate it"...
Does that mean I should be looking at adding similar code for GICv3+? I wanted to guage reactions to this sort of diagnostics before getting carried away!
Quoted 11 lines
Quoted 11 lines
drivers/irqchip/irq-gic.c +11
-0+ +/* +* Fiddle with the SGI set/clear registers to try identify +* any IPIs that are reserved for secure world. +*/ +bitmap_fill (sgi_mask,16 ); + +for (i =0 ; i <16 ; i++) { +void __iomem *set_reg = + dist_base +GIC_DIST_SGI_PENDING_SET + (i & ~3 ); + void __iomem *clear_reg =
Quoted 8 lines
drivers/irqchip/irq-gic.c static void gic_cpu_init(struct gic_chip_data *gic) · line 528
Quoted 3 lines
drivers/irqchip/irq-gic.c +3
-0+ dist_base +GIC_DIST_SGI_PENDING_CLEAR + (i & ~3 ); +unsigned long mask = cpu_mask << (8 *(i%4 )); +unsigned long flags, pending, after_clear, after_set;Please make these u32, as unsigned long is 64bit on arm64. Another thing to note is that GICD_CPEND{S,C}SGIRn are byte accessible, so you can save yourself some this hassle shifting things around and just write a single byte. You're already writing 16 times anyway...
Will do both.
Quoted 2 lines
Another thing to consider is that these locations are only defined on GICv2 and not GICv1, so this patch is likely to cause trouble on older HW.
As presented the code relies on the RAZ/WI property of reserved registers to avoid issues on GICv1; it does not report anything if there appear to be know working SGIs on the assumption we are actually running on a GICv1.
You'd prefer an explicit version check?
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ + local_irq_save(flags);Why do you need to do this? The CPU interface is not enabled yet, so I can't see how you could get an interrupt on this CPU.
Agreed. Can get rid of these.
Quoted 4 lines
Quoted 4 lines
drivers/irqchip/irq-gic.c +4
-0+ +/* record original value */ + pending =readl_relaxed (set_reg); +
Quoted 8 lines
drivers/irqchip/irq-gic.c static void gic_cpu_init(struct gic_chip_data *gic) · line 539
Quoted 5 lines
drivers/irqchip/irq-gic.c +5
-0+/* clear, test, set, and test again */ +writel_relaxed (mask, clear_reg); + after_clear =readl_relaxed (set_reg); +writel_relaxed (mask, set_reg); + after_set =readl_relaxed (set_reg);It should be enough to write to the SET register, and read back, as the bit is RAZ/WI when the interrupt is Group-0.
Good point. Will simplify.
Daniel.
Re: [PATCH 2/2] irqchip/gic: Identify and report any reserved SGI IDs
Quoted 25 lines · On Thu, 17 Dec 2015 19:26:10 +0000 Daniel Thompson…
Quoted 1 line · Marc Zyngier
Hi Daniel,
Hi Marc
Thanks for the review.
Quoted 17 lines · Daniel Thompson
Quoted 16 lines
It is possible for the secure world to reserve certain SGI IDs for itself. Currently we have limited visibility of which IDs are safe to use for IPIs.
Modify the GIC initialization code to actively search for reserved SGI IDs and report if any are found. Warn even more loudly if the reserved SGIs overlap with the normal IPI range.
When run on an Inforce IFC6410 (Snapdragon 600) this code produces the following messages:
~~~ cut here ~~~
CPU0: Detected reserved SGI IDs: 14-15
CPU1: Detected reserved SGI IDs: 15
CPU2: Detected reserved SGI IDs: 15
CPU3: Detected reserved SGI IDs: 15
~~~ cut here ~~~
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Signed-off-by Daniel Thompson <[email protected]>BTW you *didn't* say "this code is pointless and I hate it"...
Well, this was obviously used to detect another issue (patch #1), so I can't see any harm in trying to sanitize things, as long as it doesn't break anything else. I imagine this patch will also trigger on my sunxi platforms, which use a SGI to implement PSCI in secure mode.
Quoted 3 lines
Does that mean I should be looking at adding similar code for GICv3+? I wanted to guage reactions to this sort of diagnostics before getting carried away!
Could be useful as well.
Quoted 28 lines
Quoted 13 lines
Quoted 13 lines
drivers/irqchip/irq-gic.c +11
-0+ +/* +* Fiddle with the SGI set/clear registers to try identify +* any IPIs that are reserved for secure world. +*/ +bitmap_fill (sgi_mask,16 ); + +for (i =0 ; i <16 ; i++) { +void __iomem *set_reg = + dist_base +GIC_DIST_SGI_PENDING_SET + (i & ~3 ); + void __iomem *clear_reg =Quoted 8 lines
drivers/irqchip/irq-gic.c static void gic_cpu_init(struct gic_chip_data *gic) · line 528
Quoted 3 lines
drivers/irqchip/irq-gic.c +3
-0+ dist_base +GIC_DIST_SGI_PENDING_CLEAR + (i & ~3 ); +unsigned long mask = cpu_mask << (8 *(i%4 )); +unsigned long flags, pending, after_clear, after_set;Please make these u32, as unsigned long is 64bit on arm64. Another thing to note is that GICD_CPEND{S,C}SGIRn are byte accessible, so you can save yourself some this hassle shifting things around and just write a single byte. You're already writing 16 times anyway...
Will do both.
Quoted 2 lines
Another thing to consider is that these locations are only defined on GICv2 and not GICv1, so this patch is likely to cause trouble on older HW.
Quoted 6 lines
As presented the code relies on the RAZ/WI property of reserved registers to avoid issues on GICv1; it does not report anything if there appear to be know working SGIs on the assumption we are actually running on a GICv1.
You'd prefer an explicit version check?
I'd rather be cautious and check for the architecture version, specially if you settle for the byte access mentioned above (a GICv1 may not support byte access and explode unexpectedly). ICPIDR2.ArchRev should be the right thing to check.
Quoted 24 lines
Quoted 7 lines
Review
Quoted 4 lines
(quoted diff) +2
-0+ + local_irq_save(flags);Why do you need to do this? The CPU interface is not enabled yet, so I can't see how you could get an interrupt on this CPU.
Agreed. Can get rid of these.
Quoted 4 lines
Quoted 4 lines
drivers/irqchip/irq-gic.c +4
-0+ +/* record original value */ + pending =readl_relaxed (set_reg); +Quoted 8 lines
drivers/irqchip/irq-gic.c static void gic_cpu_init(struct gic_chip_data *gic) · line 539
Quoted 5 lines
drivers/irqchip/irq-gic.c +5
-0+/* clear, test, set, and test again */ +writel_relaxed (mask, clear_reg); + after_clear =readl_relaxed (set_reg); +writel_relaxed (mask, set_reg); + after_set =readl_relaxed (set_reg);It should be enough to write to the SET register, and read back, as the bit is RAZ/WI when the interrupt is Group-0.
Quoted 1 line
Good point. Will simplify.
I'd also suggest moving the whole thing to a separate function that'd get called from gic_cpu_init().
Thanks,
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Re: [PATCH 1/2] arm: Fix "NMI" backtrace for Inforce IFC6410
In reply to Daniel ThompsonQuoted 22 lines · Daniel Thompson
SysRq-L does not generate a backtrace from all CPUs when I test it on my Inforce IFC6410 platform (Snapdragon 600). The stack dump code, triggered by
IPI_CPU_BACKTRACE, never runs on the other CPUs. Eventually we hit the 10 second timeout and a subset of the expected stack dumps on are shown on the console.It is likely this is because SGI IDs 14 and 15 have been reserved for use by secure world on this platform. For IFC6410 platform the code works as expected when
IPI_CPU_BACKTRACEis set to any value in the interval 9..13.Signed-off-by Daniel Thompson <[email protected]>--- arch/arm/kernel/smp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)arch/arm/kernel/smp.c +0
-0
arch/arm/kernel/smp.c enum ipi_msg_type { · line 80
Quoted 9 lines
arch/arm/kernel/smp.c +2
-1@@ -73,7 +73,8 @@ enum ipi_msg_type {IPI_CPU_STOP ,IPI_IRQ_WORK ,IPI_COMPLETION , - IPI_CPU_BACKTRACE = 15, + IPI_CPU_BACKTRACE = 13, + /* 14 and 15 are reserved; they do not work on some Krait CPUs */ };static DECLARE_COMPLETION (cpu_running);
It looks to me that we're just moving the goal posts and keep using a SGI that is likely to be reserved by the secure side. Quoting the GIC spec:
In any system that implements the ARM Security Extensions, to support a consistent model for message passing between processors, ARM strongly recommends that all processors reserve:
* ID0-ID7 for Non-secure interrupts
* ID8-ID15 for Secure interrupts.
Of course, this is only a recommendation, but it is one that is likely to be followed...
Now, we are already using our 8 "non-secure" SGIs, but we can immediately reclaim one (IPI_CALL_FUNC_SINGLE is not that useful anymore). I'll cook a patch for that.
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH 2/2] irqchip/gic: Identify and report any reserved SGI IDs
In reply to Marc ZyngierQuoted 18 lines · Marc Zyngier
Quoted 18 lines
Quoted 18 lines · Daniel Thompson
Quoted 17 lines
It is possible for the secure world to reserve certain SGI IDs for itself. Currently we have limited visibility of which IDs are safe to use for IPIs.
Modify the GIC initialization code to actively search for reserved SGI IDs and report if any are found. Warn even more loudly if the reserved SGIs overlap with the normal IPI range.
When run on an Inforce IFC6410 (Snapdragon 600) this code produces the following messages:
~~~ cut here ~~~
CPU0: Detected reserved SGI IDs: 14-15
CPU1: Detected reserved SGI IDs: 15
CPU2: Detected reserved SGI IDs: 15
CPU3: Detected reserved SGI IDs: 15
~~~ cut here ~~~Signed-off-by Daniel Thompson <[email protected]>
...
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
Another thing to consider is that these locations are only defined on GICv2 and not GICv1, so this patch is likely to cause trouble on older HW.
As presented the code relies on the RAZ/WI property of reserved registers to avoid issues on GICv1; it does not report anything if there appear to be know working SGIs on the assumption we are actually running on a GICv1.
Quoted 6 lines
Quoted 1 line
You'd prefer an explicit version check?
I'd rather be cautious and check for the architecture version, specially if you settle for the byte access mentioned above (a GICv1 may not support byte access and explode unexpectedly). ICPIDR2.ArchRev should be the right thing to check.
Will do.
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
drivers/irqchip/irq-gic.c static void gic_cpu_init(struct gic_chip_data *gic) · line 539
Quoted 9 lines
drivers/irqchip/irq-gic.c +9
-0+ +/* record original value */ + pending =readl_relaxed (set_reg); + +/* clear, test, set, and test again */ +writel_relaxed (mask, clear_reg); + after_clear =readl_relaxed (set_reg); +writel_relaxed (mask, set_reg); + after_set =readl_relaxed (set_reg);It should be enough to write to the SET register, and read back, as the bit is RAZ/WI when the interrupt is Group-0.
Quoted 4 lines
Quoted 1 line
Good point. Will simplify.
I'd also suggest moving the whole thing to a separate function that'd get called from
gic_cpu_init().
Will do.
I think I will also upgrade the pr_crit() to a WARN_ON() and hard code the check to 8 rather than NR_IPI.
Currently NR_IPI is small on arm64 so it would be good for us to shout loudly about latent firmware/secure-zone misconfiguration.
Daniel.