@@ -615,6 +615,24 @@ void __init exc_lvl_early_init(void)
615615}
616616#endif
617617
618+ /*
619+ * Emergency stacks are used for a range of things, from asynchronous
620+ * NMIs (system reset, machine check) to synchronous, process context.
621+ * We set preempt_count to zero, even though that isn't necessarily correct. To
622+ * get the right value we'd need to copy it from the previous thread_info, but
623+ * doing that might fault causing more problems.
624+ * TODO: what to do with accounting?
625+ */
626+ static void emerg_stack_init_thread_info (struct thread_info * ti , int cpu )
627+ {
628+ ti -> task = NULL ;
629+ ti -> cpu = cpu ;
630+ ti -> preempt_count = 0 ;
631+ ti -> local_flags = 0 ;
632+ ti -> flags = 0 ;
633+ klp_init_thread_info (ti );
634+ }
635+
618636/*
619637 * Stack space used when we detect a bad kernel stack pointer, and
620638 * early in SMP boots before relocation is enabled. Exclusive emergency
@@ -633,24 +651,31 @@ void __init emergency_stack_init(void)
633651 * Since we use these as temporary stacks during secondary CPU
634652 * bringup, we need to get at them in real mode. This means they
635653 * must also be within the RMO region.
654+ *
655+ * The IRQ stacks allocated elsewhere in this file are zeroed and
656+ * initialized in kernel/irq.c. These are initialized here in order
657+ * to have emergency stacks available as early as possible.
636658 */
637659 limit = min (safe_stack_limit (), ppc64_rma_size );
638660
639661 for_each_possible_cpu (i ) {
640662 struct thread_info * ti ;
641663 ti = __va (memblock_alloc_base (THREAD_SIZE , THREAD_SIZE , limit ));
642- klp_init_thread_info (ti );
664+ memset (ti , 0 , THREAD_SIZE );
665+ emerg_stack_init_thread_info (ti , i );
643666 paca [i ].emergency_sp = (void * )ti + THREAD_SIZE ;
644667
645668#ifdef CONFIG_PPC_BOOK3S_64
646669 /* emergency stack for NMI exception handling. */
647670 ti = __va (memblock_alloc_base (THREAD_SIZE , THREAD_SIZE , limit ));
648- klp_init_thread_info (ti );
671+ memset (ti , 0 , THREAD_SIZE );
672+ emerg_stack_init_thread_info (ti , i );
649673 paca [i ].nmi_emergency_sp = (void * )ti + THREAD_SIZE ;
650674
651675 /* emergency stack for machine check exception handling. */
652676 ti = __va (memblock_alloc_base (THREAD_SIZE , THREAD_SIZE , limit ));
653- klp_init_thread_info (ti );
677+ memset (ti , 0 , THREAD_SIZE );
678+ emerg_stack_init_thread_info (ti , i );
654679 paca [i ].mc_emergency_sp = (void * )ti + THREAD_SIZE ;
655680#endif
656681 }
0 commit comments