powerpc/64s: introduce call_realmode to run C code in real-mode
Nicholas Piggin
reviewerRFC PATCH 1/1 powerpc/64s: introduce call_realmode to run C code in real-mode
The regular kernel stack can not be accessed in real mode in hash guest kernels, which prevents the MMU from being disabled in general C code. Provide a helper that can call a function pointer in real mode using the emergency stack (accessable in real mode).
Signed-off-by Nicholas Piggin <[email protected]>
--- arch/powerpc/include/asm/asm-prototypes.h | 1 + arch/powerpc/include/asm/book3s/64/mmu.h | 2 + arch/powerpc/include/asm/thread_info.h | 16 ++++++++ arch/powerpc/kernel/irq.c | 16 -------- arch/powerpc/kernel/misc_64.S | 22 +++++++++++ arch/powerpc/mm/book3s64/pgtable.c | 48 +++++++++++++++++++++++ 6 files changed, 89 insertions(+), 16 deletions(-)
arch/powerpc/include/asm/asm-prototypes.h +1 -0
@@ -126,6 +126,7 @@ extern s64 __ashldi3(s64, int);extern s64 __ashrdi3 (s64 ,int );extern int __cmpdi2 (s64 ,s64 );extern int __ucmpdi2 (u64 ,u64 ); +int __call_realmode (int (*fn)(void *arg),void *arg,void *sp);/* tracing */ void _mcount (void );
arch/powerpc/include/asm/book3s/64/mmu.h +2 -0
@@ -274,5 +274,7 @@ static inline unsigned long get_user_vsid(mm_context_t *ctx,return get_vsid (context, ea, ssize); } +int call_realmode (int (*fn)(void *arg),void *arg); +#endif /* __ASSEMBLY__ */ #endif /* _ASM_POWERPC_BOOK3S_64_MMU_H_ */
arch/powerpc/include/asm/thread_info.h +16 -0
@@ -172,6 +172,22 @@ static inline bool test_thread_local_flags(unsigned int flags)#define is_elf2_task () (0)#endif +static inline void check_stack_overflow (void ) +{ +long sp; + +if (!IS_ENABLED (CONFIG_DEBUG_STACKOVERFLOW )) +return ; + + sp = current_stack_pointer & (THREAD_SIZE -1 ); + +/* check for stack overflow: is there less than 2KB free? */ +if (unlikely (sp <2048 )) { +pr_err ("do_IRQ: stack overflow: %ld\n" , sp); +dump_stack (); + } +} +#endif /* !__ASSEMBLY__ */ #endif /* __KERNEL__ */
arch/powerpc/kernel/irq.c +0 -16
@@ -620,22 +620,6 @@ u64 arch_irq_stat_cpu(unsigned int cpu)return sum; } -static inline void check_stack_overflow (void ) -{ -long sp; - -if (!IS_ENABLED (CONFIG_DEBUG_STACKOVERFLOW )) -return ; - - sp = current_stack_pointer & (THREAD_SIZE -1 ); - -/* check for stack overflow: is there less than 2KB free? */ -if (unlikely (sp <2048 )) { -pr_err ("do_IRQ: stack overflow: %ld\n" , sp); -dump_stack (); - } -} -void __do_irq (struct pt_regs *regs) {unsigned int irq;
arch/powerpc/kernel/misc_64.S +22 -0
@@ -27,6 +27,28 @@ .text +#ifdef CONFIG_PPC_BOOK3S_64 +_GLOBAL(__call_realmode) + mflr r0 + std r0,16(r1) + stdu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r5) + mr r1,r5 + mtctr r3 + mr r3,r4 + mfmsr r4 + xori r4,r4,(MSR_IR|MSR_DR) + mtmsrd r4 + bctrl + mfmsr r4 + xori r4,r4,(MSR_IR|MSR_DR) + mtmsrd r4 + ld r1,0(r1) + ld r0,16(r1) + mtlr r0 + blr + +#endif + _GLOBAL(call_do_softirq) mflr r0 std r0,16(r1)
arch/powerpc/mm/book3s64/pgtable.c +48 -0
54 lines not on this page · raw message
Signature · 1 line
2.23.0