Generic IRQ entry/exit support for powerpc
Subsystems (2)
v2 cover Generic IRQ entry/exit support for powerpc
Adding support for the generic irq entry/exit handling for PowerPC. The goal is to bring PowerPC in line with other architectures that already use the common irq entry infrastructure, reducing duplicated code and making it easier to share future changes in entry/exit paths.
This is slightly tested on ppc64le.
The performance benchmarks from perf bench basic syscall are below:
| Metric | W/O Generic Framework | With Generic Framework | Improvement | | ---------- | --------------------- | ---------------------- | ----------- | | Total time | 0.885 [sec] | 0.880 [sec] | ~0.56% | | usecs/op | 0.088518 | 0.088005 | ~0.58% | | ops/sec | 1,12,97,086 | 1,13,62,977 | ~0.58% |
Thats close to 0.6% improvement with this.
Changelog:
V1 -> V2: Support added for irq with generic framework.
Mukesh Kumar Chaurasiya (8):
powerpc: rename arch_irq_disabled_regs
powerpc: Prepare to build with generic entry/exit framework
powerpc: introduce arch_enter_from_user_mode
powerpc: Introduce syscall exit arch functions
powerpc: add exit_flags field in pt_regs
powerpc: Prepare for IRQ entry exit
powerpc: Enable IRQ generic entry/exit path.
powerpc: Enable Generic Entry/Exit for syscalls.
arch/powerpc/Kconfig | 2 + arch/powerpc/include/asm/entry-common.h | 550 ++++++++++++++++++++++++ arch/powerpc/include/asm/hw_irq.h | 4 +- arch/powerpc/include/asm/interrupt.h | 393 +++-------------- arch/powerpc/include/asm/ptrace.h | 2 + arch/powerpc/include/asm/stacktrace.h | 8 + arch/powerpc/include/asm/syscall.h | 5 + arch/powerpc/include/asm/thread_info.h | 1 + arch/powerpc/include/uapi/asm/ptrace.h | 14 +- arch/powerpc/kernel/asm-offsets.c | 1 + arch/powerpc/kernel/interrupt.c | 251 ++--------- arch/powerpc/kernel/interrupt_64.S | 2 - arch/powerpc/kernel/ptrace/ptrace.c | 142 +----- arch/powerpc/kernel/signal.c | 8 + arch/powerpc/kernel/syscall.c | 119 +---- arch/powerpc/kernel/traps.c | 2 +- arch/powerpc/kernel/watchdog.c | 2 +- arch/powerpc/perf/core-book3s.c | 2 +- 18 files changed, 698 insertions(+), 810 deletions(-) create mode 100644 arch/powerpc/include/asm/entry-common.h
Signature · 1 line
2.51.0
RFC v2 1/8 powerpc: rename arch_irq_disabled_regs
Renaming arch_irq_disabled_regs to regs_irqs_disabled to be used commonly in generic entry exit framework and ppc arch code.
--- arch/powerpc/include/asm/hw_irq.h | 4 ++-- arch/powerpc/include/asm/interrupt.h | 12 ++++++------ arch/powerpc/kernel/interrupt.c | 4 ++-- arch/powerpc/kernel/syscall.c | 2 +- arch/powerpc/kernel/traps.c | 2 +- arch/powerpc/kernel/watchdog.c | 2 +- arch/powerpc/perf/core-book3s.c | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-)
arch/powerpc/include/asm/hw_irq.h +2 -2
@@ -393,7 +393,7 @@ static inline void do_hard_irq_enable(void)__hard_irq_enable (); } -static inline bool arch_irq_disabled_regs (struct pt_regs *regs) +static inline bool regs_irqs_disabled (struct pt_regs *regs) {return (regs->softe &IRQS_DISABLED ); }
@@ -466,7 +466,7 @@ static inline bool arch_irqs_disabled(void)#define hard_irq_disable () arch_local_irq_disable() -static inline bool arch_irq_disabled_regs (struct pt_regs *regs) +static inline bool regs_irqs_disabled (struct pt_regs *regs) {return !(regs->msr &MSR_EE ); }
arch/powerpc/include/asm/interrupt.h +6 -6
@@ -172,7 +172,7 @@ static inline void interrupt_enter_prepare(struct pt_regs *regs)/* Enable MSR[RI] early, to support kernel SLB and hash faults */ #endif -if (!arch_irq_disabled_regs (regs)) +if (!regs_irqs_disabled (regs))trace_hardirqs_off ();if (user_mode (regs)) {
@@ -192,10 +192,10 @@ static inline void interrupt_enter_prepare(struct pt_regs *regs)CT_WARN_ON (ct_state () !=CT_STATE_KERNEL &&ct_state () !=CT_STATE_IDLE );INT_SOFT_MASK_BUG_ON (regs,is_implicit_soft_masked (regs)); -INT_SOFT_MASK_BUG_ON (regs,arch_irq_disabled_regs (regs) && +INT_SOFT_MASK_BUG_ON (regs,regs_irqs_disabled (regs) &&search_kernel_restart_table (regs->nip)); } -INT_SOFT_MASK_BUG_ON (regs, !arch_irq_disabled_regs (regs) && +INT_SOFT_MASK_BUG_ON (regs, !regs_irqs_disabled (regs) && !(regs->msr &MSR_EE ));booke_restore_dbcr0 ();
@@ -298,7 +298,7 @@ static inline void interrupt_nmi_enter_prepare(struct pt_regs *regs, struct inte* Adjust regs->softe to be soft-masked if it had not been * reconcied (e.g., interrupt entry with MSR[EE]=0 but softe * not yet set disabled), or if it was in an implicit soft -* masked state. This makes arch_irq_disabled_regs(regs) +* masked state. This makes regs_irqs_disabled(regs) * behave as expected. */ regs->softe =IRQS_ALL_DISABLED ;
@@ -372,7 +372,7 @@ static inline void interrupt_nmi_exit_prepare(struct pt_regs *regs, struct inter #ifdef CONFIG_PPC64 #ifdef CONFIG_PPC_BOOK3S - if (arch_irq_disabled_regs(regs)) { + if (regs_irqs_disabled(regs)) { unsigned long rst = search_kernel_restart_table(regs->nip); if (rst) regs_set_return_ip(regs, rst);
@@ -661,7 +661,7 @@ void replay_soft_interrupts(void);static inline void interrupt_cond_local_irq_enable (struct pt_regs *regs) { -if (!arch_irq_disabled_regs (regs)) +if (!regs_irqs_disabled (regs))local_irq_enable (); }
arch/powerpc/kernel/interrupt.c +2 -2
@@ -347,7 +347,7 @@ notrace unsigned long interrupt_exit_user_prepare(struct pt_regs *regs)unsigned long ret;BUG_ON (regs_is_unrecoverable (regs)); -BUG_ON (arch_irq_disabled_regs (regs)); +BUG_ON (regs_irqs_disabled (regs));CT_WARN_ON (ct_state () ==CT_STATE_USER );/*
@@ -396,7 +396,7 @@ notrace unsigned long interrupt_exit_kernel_prepare(struct pt_regs *regs)local_irq_disable (); -if (!arch_irq_disabled_regs (regs)) { +if (!regs_irqs_disabled (regs)) {/* Returning to a kernel context with local irqs enabled. */ WARN_ON_ONCE (!(regs->msr &MSR_EE )); again:
arch/powerpc/kernel/syscall.c +1 -1
@@ -32,7 +32,7 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0)BUG_ON (regs_is_unrecoverable (regs));BUG_ON (!user_mode (regs)); -BUG_ON (arch_irq_disabled_regs (regs)); +BUG_ON (regs_irqs_disabled (regs));#ifdef CONFIG_PPC_PKEY if (mmu_has_feature (MMU_FTR_PKEY )) {
arch/powerpc/kernel/traps.c +1 -1
@@ -1956,7 +1956,7 @@ DEFINE_INTERRUPT_HANDLER_RAW(performance_monitor_exception)* prevent hash faults on user addresses when reading callchains (and * looks better from an irq tracing perspective). */ -if (IS_ENABLED (CONFIG_PPC64 ) &&unlikely (arch_irq_disabled_regs (regs))) +if (IS_ENABLED (CONFIG_PPC64 ) &&unlikely (regs_irqs_disabled (regs)))performance_monitor_exception_nmi (regs);else performance_monitor_exception_async (regs);
arch/powerpc/kernel/watchdog.c +1 -1
@@ -373,7 +373,7 @@ DEFINE_INTERRUPT_HANDLER_NMI(soft_nmi_interrupt)u64 tb;/* should only arrive from kernel, with irqs disabled */ -WARN_ON_ONCE (!arch_irq_disabled_regs (regs)); +WARN_ON_ONCE (!regs_irqs_disabled (regs));if (!cpumask_test_cpu (cpu, &wd_cpus_enabled))return 0 ;
arch/powerpc/perf/core-book3s.c +1 -1
@@ -2482,7 +2482,7 @@ static void __perf_event_interrupt(struct pt_regs *regs)* will trigger a PMI after waking up from idle. Since counter values are _not_ * saved/restored in idle path, can lead to below "Can't find PMC" message. */ -if (unlikely (!found) && !arch_irq_disabled_regs (regs)) +if (unlikely (!found) && !regs_irqs_disabled (regs))printk_ratelimited (KERN_WARNING "Can't find PMC that caused IRQ\n" );/*
Signature · 1 line
2.51.0
RFC v2 2/8 powerpc: Prepare to build with generic entry/exit framework
In reply to Mukesh Kumar ChaurasiyaEnabling build with generic entry/exit framework for powerpc architecture requires few necessary steps.
Introducing minor infrastructure updates to prepare for future generic framework handling:
- Add syscall_work field to struct thread_info for SYSCALL_WORK_* flags.
- Provide arch_syscall_is_vdso_sigreturn() stub, returning false.
- Add on_thread_stack() helper to test whether the current stack pointer lies within the task’s kernel stack.
No functional change is intended with this patch.
--- arch/powerpc/include/asm/entry-common.h | 11 +++++++++++ arch/powerpc/include/asm/stacktrace.h | 8 ++++++++ arch/powerpc/include/asm/syscall.h | 5 +++++ arch/powerpc/include/asm/thread_info.h | 1 + 4 files changed, 25 insertions(+) create mode 100644 arch/powerpc/include/asm/entry-common.h
arch/powerpc/include/asm/entry-common.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _ASM_PPC_ENTRY_COMMON_H +#define _ASM_PPC_ENTRY_COMMON_H + +#ifdef CONFIG_GENERIC_IRQ_ENTRY + +#include <asm/stacktrace.h> + +#endif /* CONFIG_GENERIC_IRQ_ENTRY */ +#endif /* _ASM_PPC_ENTRY_COMMON_H */
arch/powerpc/include/asm/stacktrace.h +8 -0
@@ -8,6 +8,14 @@#ifndef _ASM_POWERPC_STACKTRACE_H#define _ASM_POWERPC_STACKTRACE_H +#include <linux/sched.h> +void show_user_instructions (struct pt_regs *regs); +static inline bool on_thread_stack (void ) +{ +return !(((unsigned long )(current->stack) ^ current_stack_pointer) + & ~(THREAD_SIZE -1 )); +} +#endif /* _ASM_POWERPC_STACKTRACE_H */
arch/powerpc/include/asm/syscall.h +5 -0
@@ -139,4 +139,9 @@ static inline int syscall_get_arch(struct task_struct *task) else return AUDIT_ARCH_PPC64; } + +static inline bool arch_syscall_is_vdso_sigreturn (struct pt_regs *regs) +{ +return false; +}#endif /* _ASM_SYSCALL_H */
arch/powerpc/include/asm/thread_info.h +1 -0
@@ -54,6 +54,7 @@struct thread_info {int preempt_count;/* 0 => preemptable, <0 => BUG */ +unsigned long syscall_work;/* SYSCALL_WORK_ flags */ #ifdef CONFIG_SMP unsigned int cpu;#endif
Signature · 1 line
2.51.0
RFC v2 3/8 powerpc: introduce arch_enter_from_user_mode
In reply to Mukesh Kumar Chaurasiya- Implement the hook arch_enter_from_user_mode for syscall entry.
- Move booke_load_dbcr0 from interrupt.c to interrupt.h
No functional change intended.
--- arch/powerpc/include/asm/entry-common.h | 96 +++++++++++++++++++++++++ arch/powerpc/include/asm/interrupt.h | 23 ++++++ arch/powerpc/kernel/interrupt.c | 22 ------ 3 files changed, 119 insertions(+), 22 deletions(-)
arch/powerpc/include/asm/entry-common.h +96 -0
@@ -5,7 +5,103 @@#ifdef CONFIG_GENERIC_IRQ_ENTRY +#include <asm/cputime.h> +#include <asm/interrupt.h> #include <asm/stacktrace.h> +#include <asm/tm.h> + +static __always_inline void arch_enter_from_user_mode(struct pt_regs *regs) +{ +if (IS_ENABLED (CONFIG_PPC_IRQ_SOFT_MASK_DEBUG )) +BUG_ON (irq_soft_mask_return () !=IRQS_ALL_DISABLED ); + +BUG_ON (regs_is_unrecoverable (regs)); +BUG_ON (!user_mode (regs)); +BUG_ON (regs_irqs_disabled (regs)); + +#ifdef CONFIG_PPC_PKEY +if (mmu_has_feature (MMU_FTR_PKEY )) { +unsigned long amr, iamr; +bool flush_needed = false; +/* +* When entering from userspace we mostly have the AMR/IAMR +* different from kernel default values. Hence don't compare. +*/ + amr =mfspr (SPRN_AMR ); + iamr =mfspr (SPRN_IAMR ); + regs->amr = amr; + regs->iamr = iamr; +if (mmu_has_feature (MMU_FTR_KUAP )) { +mtspr (SPRN_AMR ,AMR_KUAP_BLOCKED ); + flush_needed = true; + } +if (mmu_has_feature (MMU_FTR_BOOK3S_KUEP )) { +mtspr (SPRN_IAMR ,AMR_KUEP_BLOCKED ); + flush_needed = true; + } +if (flush_needed) +isync (); + } else +#endif +kuap_assert_locked (); + +booke_restore_dbcr0 (); + +account_cpu_user_entry (); + +account_stolen_time (); + +/* +* This is not required for the syscall exit path, but makes the +* stack frame look nicer. If this was initialised in the first stack +* frame, or if the unwinder was taught the first stack frame always +* returns to user with IRQS_ENABLED, this store could be avoided! +*/ +irq_soft_mask_regs_set_state (regs,IRQS_ENABLED ); + +/* +* If system call is called with TM active, set _TIF_RESTOREALL to +* prevent RFSCV being used to return to userspace, because POWER9 +* TM implementation has problems with this instruction returning to +* transactional state. Final register values are not relevant because +* the transaction will be aborted upon return anyway. Or in the case +* of unsupported_scv SIGILL fault, the return state does not much +* matter because it's an edge case. +*/ +if (IS_ENABLED (CONFIG_PPC_TRANSACTIONAL_MEM ) && +unlikely (MSR_TM_TRANSACTIONAL (regs->msr))) +set_bits (_TIF_RESTOREALL, ¤t_thread_info ()->flags); + +/* +* If the system call was made with a transaction active, doom it and +* return without performing the system call. Unless it was an +* unsupported scv vector, in which case it's treated like an illegal +* instruction. +*/ +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM +if (unlikely (MSR_TM_TRANSACTIONAL (regs->msr)) && + !trap_is_unsupported_scv (regs)) { +/* Enable TM in the kernel, and disable EE (for scv) */ +hard_irq_disable (); +mtmsr (mfmsr () |MSR_TM ); + +/* tabort, this dooms the transaction, nothing else */ + asmvolatile (".long 0x7c00071d | ((%0) << 16)" + ::"r" (TM_CAUSE_SYSCALL |TM_CAUSE_PERSISTENT )); + +/* +* Userspace will never see the return value. Execution will +* resume after the tbegin. of the aborted transaction with the +* checkpointed register state. A context switch could occur +* or signal delivered to the process before resuming the +* doomed transaction context, but that should all be handled +* as expected. +*/ +return ; + } +#endif // CONFIG_PPC_TRANSACTIONAL_MEM +} +#define arch_enter_from_user_mode arch_enter_from_user_mode#endif /* CONFIG_GENERIC_IRQ_ENTRY */ #endif /* _ASM_PPC_ENTRY_COMMON_H */
arch/powerpc/include/asm/interrupt.h +23 -0
@@ -138,6 +138,29 @@ static inline void nap_adjust_return(struct pt_regs *regs)#endif } +static inline void booke_load_dbcr0 (void ) +{ +#ifdef CONFIG_PPC_ADV_DEBUG_REGS +unsigned long dbcr0 = current->thread.debug.dbcr0; + +if (likely (!(dbcr0 &DBCR0_IDM ))) +return ; + +/* +* Check to see if the dbcr0 register is set up to debug. +* Use the internal debug mode bit to do this. +*/ +mtmsr (mfmsr () & ~MSR_DE ); +if (IS_ENABLED (CONFIG_PPC32 )) { +isync (); + global_dbcr0[smp_processor_id ()] =mfspr (SPRN_DBCR0 ); + } +mtspr (SPRN_DBCR0 , dbcr0); +mtspr (SPRN_DBSR ,-1 ); +#endif +} + +static inline void booke_restore_dbcr0 (void ) {#ifdef CONFIG_PPC_ADV_DEBUG_REGS
arch/powerpc/kernel/interrupt.c +0 -22
@@ -78,28 +78,6 @@ static notrace __always_inline bool prep_irq_for_enabled_exit(bool restartable)return true; } -static notrace void booke_load_dbcr0(void) -{ -#ifdef CONFIG_PPC_ADV_DEBUG_REGS -unsigned long dbcr0 = current->thread.debug.dbcr0; - -if (likely (!(dbcr0 &DBCR0_IDM ))) -return ; - -/* -* Check to see if the dbcr0 register is set up to debug. -* Use the internal debug mode bit to do this. -*/ -mtmsr (mfmsr () & ~MSR_DE ); -if (IS_ENABLED (CONFIG_PPC32 )) { -isync (); - global_dbcr0[smp_processor_id ()] =mfspr (SPRN_DBCR0 ); - } -mtspr (SPRN_DBCR0 , dbcr0); -mtspr (SPRN_DBSR ,-1 ); -#endif -} - static notrace void check_return_regs_valid(struct pt_regs *regs) {#ifdef CONFIG_PPC_BOOK3S_64
Signature · 1 line
2.51.0
RFC v2 4/8 powerpc: Introduce syscall exit arch functions
In reply to Mukesh Kumar ChaurasiyaIntroducing following functions for syscall exit
- arch_exit_to_user_mode_work
- arch_exit_to_user_mode_work_prepare
--- arch/powerpc/include/asm/entry-common.h | 46 ++++++++++++++ arch/powerpc/include/asm/interrupt.h | 82 +++++++++++++++++++++++++ arch/powerpc/kernel/interrupt.c | 81 ------------------------ arch/powerpc/kernel/signal.c | 14 +++++ 4 files changed, 142 insertions(+), 81 deletions(-)
arch/powerpc/include/asm/entry-common.h +46 -0
@@ -8,6 +8,7 @@#include <asm/cputime.h> #include <asm/interrupt.h> #include <asm/stacktrace.h> +#include <asm/switch_to.h> #include <asm/tm.h> static __always_inline void arch_enter_from_user_mode(struct pt_regs *regs)
@@ -101,7 +102,52 @@ static __always_inline void arch_enter_from_user_mode(struct pt_regs *regs) }#endif // CONFIG_PPC_TRANSACTIONAL_MEM } +#define arch_enter_from_user_mode arch_enter_from_user_mode +static inline void arch_exit_to_user_mode_prepare (struct pt_regs *regs, +unsigned long ti_work) +{ +unsigned long mathflags; + +if (IS_ENABLED (CONFIG_PPC_BOOK3S_64 ) &&IS_ENABLED (CONFIG_PPC_FPU )) { +if (IS_ENABLED (CONFIG_PPC_TRANSACTIONAL_MEM ) && +unlikely ((ti_work & _TIF_RESTORE_TM))) { +restore_tm_state (regs); + }else { + mathflags =MSR_FP ; + +if (cpu_has_feature (CPU_FTR_VSX )) + mathflags |=MSR_VEC |MSR_VSX ; +else if (cpu_has_feature (CPU_FTR_ALTIVEC )) + mathflags |=MSR_VEC ; + +/* +* If userspace MSR has all available FP bits set, +* then they are live and no need to restore. If not, +* it means the regs were given up and restore_math +* may decide to restore them (to avoid taking an FP +* fault). +*/ +if ((regs->msr & mathflags) != mathflags) +restore_math (regs); + } + } + +check_return_regs_valid (regs); +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM + local_paca->tm_scratch = regs->msr; +#endif +} +#define arch_exit_to_user_mode_prepare arch_exit_to_user_mode_prepare + +static __always_inline void arch_exit_to_user_mode(void) +{ +booke_load_dbcr0 (); + +account_cpu_user_exit (); +} +#define arch_exit_to_user_mode arch_exit_to_user_mode +#endif /* CONFIG_GENERIC_IRQ_ENTRY */ #endif /* _ASM_PPC_ENTRY_COMMON_H */
arch/powerpc/include/asm/interrupt.h +82 -0
94 lines not on this page · raw message
arch/powerpc/kernel/interrupt.c +0 -81
93 lines not on this page · raw message
arch/powerpc/kernel/signal.c +14 -0
@@ -22,6 +22,11 @@#include "signal.h" +/* This will be removed */ +#ifdef CONFIG_GENERIC_ENTRY +#include <linux/entry-common.h> +#endif /* CONFIG_GENERIC_ENTRY */ +#ifdef CONFIG_VSX unsigned long copy_fpr_to_user (void __user *to,struct task_struct *task)
@@ -368,3 +373,12 @@ void signal_fault(struct task_struct *tsk, struct pt_regs *regs,printk_ratelimited (regs->msr &MSR_64BIT ? fm64 : fm32, tsk->comm,task_pid_nr (tsk), where, ptr, regs->nip, regs->link); } + +#ifdef CONFIG_GENERIC_ENTRY +void arch_do_signal_or_restart (struct pt_regs *regs) +{ +BUG_ON (regs != current->thread.regs); + local_paca->generic_fw_flags |=GFW_RESTORE_ALL ; +do_signal (current); +} +#endif /* CONFIG_GENERIC_ENTRY */
Signature · 1 line
2.51.0
RFC v2 5/8 powerpc: add exit_flags field in pt_regs
In reply to Mukesh Kumar ChaurasiyaAdd field exit_flags in the pt_regs. This will hold the flags while executing interrupt or syscall which is required during exit to user.
--- arch/powerpc/include/asm/ptrace.h | 2 ++ arch/powerpc/include/uapi/asm/ptrace.h | 14 +++++++++----- arch/powerpc/kernel/asm-offsets.c | 1 + arch/powerpc/kernel/ptrace/ptrace.c | 1 + 4 files changed, 13 insertions(+), 5 deletions(-)
arch/powerpc/include/asm/ptrace.h +2 -0
@@ -53,6 +53,8 @@ struct pt_regsunsigned long esr; };unsigned long result; +unsigned long exit_flags; +unsigned long __pt_regs_pad[1 ];/* Maintain 16 byte interrupt stack alignment */ }; };#if defined(CONFIG_PPC64 ) || defined(CONFIG_PPC_KUAP )
arch/powerpc/include/uapi/asm/ptrace.h +9 -5
@@ -55,6 +55,8 @@ struct pt_regsunsigned long dar;/* Fault registers */ unsigned long dsisr;/* on 4xx/Book-E used for ESR */ unsigned long result;/* Result of a system call */ +unsigned long exit_flags;/* System call exit flags */ + unsigned long __pt_regs_pad[1]; /* Maintain 16 byte interrupt stack alignment */ };#endif /* __ASSEMBLY__ */
@@ -114,10 +116,12 @@ struct pt_regs#define PT_DAR 41#define PT_DSISR 42#define PT_RESULT 43 -#define PT_DSCR 44 -#define PT_REGS_COUNT 44 +#define PT_EXIT_FLAGS 44 +#define PT_PAD 45 +#define PT_DSCR 46 +#define PT_REGS_COUNT 46 -#define PT_FPR0 48/* each FP reg occupies 2 slots in this space */ +#define PT_FPR0 (PT_REGS_COUNT + 4)/* each FP reg occupies 2 slots in this space */ #ifndef __powerpc64__
@@ -129,7 +133,7 @@ struct pt_regs#define PT_FPSCR (PT_FPR0 + 32)/* each FP reg occupies 1 slot in 64-bit space */ -#define PT_VR0 82/* each Vector reg occupies 2 slots in 64-bit */ +#define PT_VR0 (PT_FPSCR + 2)/* <82> each Vector reg occupies 2 slots in 64-bit */ #define PT_VSCR (PT_VR0 + 32*2 + 1)#define PT_VRSAVE (PT_VR0 + 33*2)
@@ -137,7 +141,7 @@ struct pt_regs/* * Only store first 32 VSRs here. The second 32 VSRs in VR0-31 */ -#define PT_VSR0 150/* each VSR reg occupies 2 slots in 64-bit */ +#define PT_VSR0 (PT_VRSAVE + 2)/* each VSR reg occupies 2 slots in 64-bit */ #define PT_VSR31 (PT_VSR0 + 2*31)#endif /* __powerpc64__ */
arch/powerpc/kernel/asm-offsets.c +1 -0
@@ -291,6 +291,7 @@ int main(void)STACK_PT_REGS_OFFSET (_ESR, esr);STACK_PT_REGS_OFFSET (ORIG_GPR3 , orig_gpr3);STACK_PT_REGS_OFFSET (RESULT , result); +STACK_PT_REGS_OFFSET (EXIT_FLAGS , exit_flags);STACK_PT_REGS_OFFSET (_TRAP, trap);#ifdef CONFIG_PPC64 STACK_PT_REGS_OFFSET (SOFTE , softe);
arch/powerpc/kernel/ptrace/ptrace.c +1 -0
@@ -432,6 +432,7 @@ void __init pt_regs_check(void)CHECK_REG (PT_DAR , dar);CHECK_REG (PT_DSISR , dsisr);CHECK_REG (PT_RESULT , result); +CHECK_REG (PT_EXIT_FLAGS , exit_flags);#undef CHECK_REGBUILD_BUG_ON (PT_REGS_COUNT !=sizeof (struct user_pt_regs ) /sizeof (unsigned long ));
Signature · 1 line
2.51.0
RFC v2 6/8 powerpc: Prepare for IRQ entry exit
In reply to Mukesh Kumar ChaurasiyaCopy all the functions from interrupt.h to arch specific entry-common.h file as it will be a part of common now.
No functional change intended here.
--- arch/powerpc/include/asm/entry-common.h | 420 ++++++++++++++++++++++++ 1 file changed, 420 insertions(+)
arch/powerpc/include/asm/entry-common.h +420 -0
@@ -7,10 +7,430 @@#include <asm/cputime.h> #include <asm/interrupt.h> +#include <asm/runlatch.h> #include <asm/stacktrace.h> #include <asm/switch_to.h> #include <asm/tm.h> +#ifdef CONFIG_PPC_IRQ_SOFT_MASK_DEBUG +/* +* WARN/BUG is handled with a program interrupt so minimise checks here to +* avoid recursion and maximise the chance of getting the first oops handled. +*/ +#define INT_SOFT_MASK_BUG_ON (regs, cond) \ +do { \ + if ((user_mode(regs) || (TRAP(regs) != INTERRUPT_PROGRAM))) \ + BUG_ON(cond); \ +} while (0) +#else +#define INT_SOFT_MASK_BUG_ON (regs, cond) +#endif + +#ifdef CONFIG_PPC_BOOK3S_64 +extern char __end_soft_masked[]; +bool search_kernel_soft_mask_table (unsigned long addr); +unsigned long search_kernel_restart_table (unsigned long addr); + +DECLARE_STATIC_KEY_FALSE (interrupt_exit_not_reentrant); + +static inline bool is_implicit_soft_masked (struct pt_regs *regs) +{ +if (user_mode (regs)) +return false; + +if (regs->nip >= (unsigned long )__end_soft_masked) +return false; + +return search_kernel_soft_mask_table (regs->nip); +} + +static inline void srr_regs_clobbered (void ) +{ + local_paca->srr_valid =0 ; + local_paca->hsrr_valid =0 ; +} +#else +static inline unsigned long search_kernel_restart_table (unsigned long addr) +{ +return 0 ; +} + +static inline bool is_implicit_soft_masked (struct pt_regs *regs) +{ +return false; +} + +static inline void srr_regs_clobbered (void ) +{ +} +#endif + +static inline void nap_adjust_return (struct pt_regs *regs) +{ +#ifdef CONFIG_PPC_970_NAP +if (unlikely (test_thread_local_flags (_TLF_NAPPING))) { +/* Can avoid a test-and-clear because NMIs do not call this */ +clear_thread_local_flags (_TLF_NAPPING); +regs_set_return_ip (regs, (unsigned long )power4_idle_nap_return); + } +#endif +} + +static inline void booke_load_dbcr0 (void ) +{ +#ifdef CONFIG_PPC_ADV_DEBUG_REGS +unsigned long dbcr0 = current->thread.debug.dbcr0; + +if (likely (!(dbcr0 &DBCR0_IDM ))) +return ; + +/* +* Check to see if the dbcr0 register is set up to debug. +* Use the internal debug mode bit to do this. +*/ +mtmsr (mfmsr () & ~MSR_DE ); +if (IS_ENABLED (CONFIG_PPC32 )) { +isync (); + global_dbcr0[smp_processor_id ()] =mfspr (SPRN_DBCR0 ); + } +mtspr (SPRN_DBCR0 , dbcr0); +mtspr (SPRN_DBSR ,-1 ); +#endif +} + + +static inline void booke_restore_dbcr0 (void ) +{ +#ifdef CONFIG_PPC_ADV_DEBUG_REGS +unsigned long dbcr0 = current->thread.debug.dbcr0; + +if (IS_ENABLED (CONFIG_PPC32 ) &&unlikely (dbcr0 &DBCR0_IDM )) { +mtspr (SPRN_DBSR ,-1 ); +mtspr (SPRN_DBCR0 , global_dbcr0[smp_processor_id ()]); + } +#endif +} + +static inline void check_return_regs_valid (struct pt_regs *regs) +{ +#ifdef CONFIG_PPC_BOOK3S_64 +unsigned long trap, srr0, srr1; +static bool warned; +u8 *validp; +char *h; + +if (trap_is_scv (regs)) +return ; + + trap =TRAP (regs); +// EE in HV mode sets HSRRs like 0xea0 +if (cpu_has_feature (CPU_FTR_HVMODE ) && trap ==INTERRUPT_EXTERNAL ) + trap =0xea0 ; + +switch (trap) { +case 0x980 : +case INTERRUPT_H_DATA_STORAGE : +case 0xe20 : +case 0xe40 : +case INTERRUPT_HMI : +case 0xe80 : +case 0xea0 : +case INTERRUPT_H_FAC_UNAVAIL : +case 0x1200 : +case 0x1500 : +case 0x1600 : +case 0x1800 : + validp = &local_paca->hsrr_valid; +if (!READ_ONCE (*validp)) +return ; + + srr0 =mfspr (SPRN_HSRR0 ); + srr1 =mfspr (SPRN_HSRR1 ); + h ="H" ; + +break ; +default : + validp = &local_paca->srr_valid; +if (!READ_ONCE (*validp)) +return ; + + srr0 =mfspr (SPRN_SRR0 ); + srr1 =mfspr (SPRN_SRR1 ); + h ="" ; +break ; + } + +if (srr0 == regs->nip && srr1 == regs->msr) +return ; + +/* +* A NMI / soft-NMI interrupt may have come in after we found +* srr_valid and before the SRRs are loaded. The interrupt then +* comes in and clobbers SRRs and clears srr_valid. Then we load +* the SRRs here and test them above and find they don't match. +* +* Test validity again after that, to catch such false positives. +* +* This test in general will have some window for false negatives +* and may not catch and fix all such cases if an NMI comes in +* later and clobbers SRRs without clearing srr_valid, but hopefully +* such things will get caught most of the time, statistically +* enough to be able to get a warning out. +*/ +if (!READ_ONCE (*validp)) +return ; + +if (!data_race (warned)) { +data_race (warned = true); +printk ("%sSRR0 was: %lx should be: %lx\n" , h, srr0, regs->nip); +printk ("%sSRR1 was: %lx should be: %lx\n" , h, srr1, regs->msr); +show_regs (regs); + } + +WRITE_ONCE (*validp,0 );/* fixup */ +#endif +} + +static inline void interrupt_enter_prepare (struct pt_regs *regs) +{ +#ifdef CONFIG_PPC64 +irq_soft_mask_set (IRQS_ALL_DISABLED ); + +/* +* If the interrupt was taken with HARD_DIS clear, then enable MSR[EE]. +* Asynchronous interrupts get here with HARD_DIS set (see below), so +* this enables MSR[EE] for synchronous interrupts. IRQs remain +* soft-masked. The interrupt handler may later call +* interrupt_cond_local_irq_enable() to achieve a regular process +* context. +*/ +if (!(local_paca->irq_happened &PACA_IRQ_HARD_DIS )) { +INT_SOFT_MASK_BUG_ON (regs, !(regs->msr &MSR_EE )); +__hard_irq_enable (); + }else { +__hard_RI_enable (); + } +/* Enable MSR[RI] early, to support kernel SLB and hash faults */ +#endif + +if (!regs_irqs_disabled (regs)) +trace_hardirqs_off (); + +if (user_mode (regs)) { +kuap_lock (); +CT_WARN_ON (ct_state () !=CT_STATE_USER ); +user_exit_irqoff (); + +account_cpu_user_entry (); +account_stolen_time (); + }else { +kuap_save_and_lock (regs); +/* +* CT_WARN_ON comes here via program_check_exception, +* so avoid recursion. +*/ +if (TRAP (regs) !=INTERRUPT_PROGRAM ) +CT_WARN_ON (ct_state () !=CT_STATE_KERNEL && +ct_state () !=CT_STATE_IDLE ); +INT_SOFT_MASK_BUG_ON (regs,is_implicit_soft_masked (regs)); +INT_SOFT_MASK_BUG_ON (regs,regs_irqs_disabled (regs) && +search_kernel_restart_table (regs->nip)); + } +INT_SOFT_MASK_BUG_ON (regs, !regs_irqs_disabled (regs) && + !(regs->msr &MSR_EE )); + +booke_restore_dbcr0 (); +} + +/* +* Care should be taken to note that interrupt_exit_prepare and +* interrupt_async_exit_prepare do not necessarily return immediately to +* regs context (e.g., if regs is usermode, we don't necessarily return to +* user mode). Other interrupts might be taken between here and return, +* context switch / preemption may occur in the exit path after this, or a +* signal may be delivered, etc. +* +* The real interrupt exit code is platform specific, e.g., +* interrupt_exit_user_prepare / interrupt_exit_kernel_prepare for 64s. +* +* However interrupt_nmi_exit_prepare does return directly to regs, because +* NMIs do not do "exit work" or replay soft-masked interrupts. +*/ +static inline void interrupt_exit_prepare (struct pt_regs *regs) +{ +} + +static inline void interrupt_async_enter_prepare (struct pt_regs *regs) +{ +#ifdef CONFIG_PPC64 +/* Ensure interrupt_enter_prepare does not enable MSR[EE] */ + local_paca->irq_happened |=PACA_IRQ_HARD_DIS ; +#endif +interrupt_enter_prepare (regs); +#ifdef CONFIG_PPC_BOOK3S_64 +/* +* RI=1 is set by interrupt_enter_prepare, so this thread flags access +* has to come afterward (it can cause SLB faults). +*/ +if (cpu_has_feature (CPU_FTR_CTRL ) && + !test_thread_local_flags (_TLF_RUNLATCH)) +__ppc64_runlatch_on (); +#endif +irq_enter (); +} + +static inline void interrupt_async_exit_prepare (struct pt_regs *regs) +{ +/* +* Adjust at exit so the main handler sees the true NIA. This must +* come before irq_exit() because irq_exit can enable interrupts, and +* if another interrupt is taken before nap_adjust_return has run +* here, then that interrupt would return directly to idle nap return. +*/ +nap_adjust_return (regs); + +irq_exit (); +interrupt_exit_prepare (regs); +} + +struct interrupt_nmi_state { +#ifdef CONFIG_PPC64 +u8 irq_soft_mask; +u8 irq_happened; +u8 ftrace_enabled; +u64 softe; +#endif +}; + +static inline bool nmi_disables_ftrace (struct pt_regs *regs) +{ +/* Allow DEC and PMI to be traced when they are soft-NMI */ +if (IS_ENABLED (CONFIG_PPC_BOOK3S_64 )) { +if (TRAP (regs) ==INTERRUPT_DECREMENTER ) +return false; +if (TRAP (regs) ==INTERRUPT_PERFMON ) +return false; + } +if (IS_ENABLED (CONFIG_PPC_BOOK3E_64 )) { +if (TRAP (regs) ==INTERRUPT_PERFMON ) +return false; + } + +return true; +} + +static inline void interrupt_nmi_enter_prepare (struct pt_regs *regs,struct interrupt_nmi_state *state) +{ +#ifdef CONFIG_PPC64 + state->irq_soft_mask = local_paca->irq_soft_mask; + state->irq_happened = local_paca->irq_happened; + state->softe = regs->softe; + +/* +* Set IRQS_ALL_DISABLED unconditionally so irqs_disabled() does +* the right thing, and set IRQ_HARD_DIS. We do not want to reconcile +* because that goes through irq tracing which we don't want in NMI. +*/ + local_paca->irq_soft_mask =IRQS_ALL_DISABLED ; + local_paca->irq_happened |=PACA_IRQ_HARD_DIS ; + +if (!(regs->msr &MSR_EE ) ||is_implicit_soft_masked (regs)) { +/* +* Adjust regs->softe to be soft-masked if it had not been +* reconcied (e.g., interrupt entry with MSR[EE]=0 but softe +* not yet set disabled), or if it was in an implicit soft +* masked state. This makes regs_irqs_disabled(regs) +* behave as expected. +*/ + regs->softe =IRQS_ALL_DISABLED ; + } + +__hard_RI_enable (); + +/* Don't do any per-CPU operations until interrupt state is fixed */ + +if (nmi_disables_ftrace (regs)) { + state->ftrace_enabled =this_cpu_get_ftrace_enabled (); +this_cpu_set_ftrace_enabled (0 ); + } +#endif + +/* If data relocations are enabled, it's safe to use nmi_enter() */ +if (mfmsr () &MSR_DR ) { +nmi_enter (); +return ; + } + +/* +* But do not use nmi_enter() for pseries hash guest taking a real-mode +* NMI because not everything it touches is within the RMA limit. +*/ +if (IS_ENABLED (CONFIG_PPC_BOOK3S_64 ) && +firmware_has_feature (FW_FEATURE_LPAR ) && + !radix_enabled ()) +return ; + +/* +* Likewise, don't use it if we have some form of instrumentation (like +* KASAN shadow) that is not safe to access in real mode (even on radix) +*/ +if (IS_ENABLED (CONFIG_KASAN )) +return ; + +/* +* Likewise, do not use it in real mode if percpu first chunk is not +* embedded. With CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK enabled there +* are chances where percpu allocation can come from vmalloc area. +*/ +if (percpu_first_chunk_is_paged) +return ; + +/* Otherwise, it should be safe to call it */ +nmi_enter (); +} + +static inline void interrupt_nmi_exit_prepare (struct pt_regs *regs,struct interrupt_nmi_state *state) +{ +if (mfmsr () &MSR_DR ) { +// nmi_exit if relocations are on +nmi_exit (); + }else if (IS_ENABLED (CONFIG_PPC_BOOK3S_64 ) && +firmware_has_feature (FW_FEATURE_LPAR ) && + !radix_enabled ()) { +// no nmi_exit for a pseries hash guest taking a real mode exception + }else if (IS_ENABLED (CONFIG_KASAN )) { +// no nmi_exit for KASAN in real mode + }else if (percpu_first_chunk_is_paged) { +// no nmi_exit if percpu first chunk is not embedded + }else { +nmi_exit (); + } + +/* +* nmi does not call nap_adjust_return because nmi should not create +* new work to do (must use irq_work for that). +*/ + +#ifdef CONFIG_PPC64 +#ifdef CONFIG_PPC_BOOK3S +if (regs_irqs_disabled (regs)) { +unsigned long rst =search_kernel_restart_table (regs->nip); +if (rst) +regs_set_return_ip (regs, rst); + } +#endif + +if (nmi_disables_ftrace (regs)) +this_cpu_set_ftrace_enabled (state->ftrace_enabled); + +/* Check we didn't change the pending interrupt mask. */ +WARN_ON_ONCE ((state->irq_happened |PACA_IRQ_HARD_DIS ) != local_paca->irq_happened); + regs->softe = state->softe; + local_paca->irq_happened = state->irq_happened; + local_paca->irq_soft_mask = state->irq_soft_mask; +#endif +} + static __always_inline void arch_enter_from_user_mode(struct pt_regs *regs) {if (IS_ENABLED (CONFIG_PPC_IRQ_SOFT_MASK_DEBUG ))
Signature · 1 line
2.51.0
RFC v2 7/8 powerpc: Enable IRQ generic entry/exit path.
In reply to Mukesh Kumar ChaurasiyaEnable generic entry/exit path for ppc irq.
--- arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/entry-common.h | 93 ++--- arch/powerpc/include/asm/interrupt.h | 492 +++--------------------- arch/powerpc/kernel/interrupt.c | 9 +- arch/powerpc/kernel/interrupt_64.S | 2 - 5 files changed, 92 insertions(+), 505 deletions(-)
arch/powerpc/Kconfig +1 -0
@@ -202,6 +202,7 @@ config PPC select GENERIC_GETTIMEOFDAY select GENERIC_IDLE_POLL_SETUP select GENERIC_IOREMAP + select GENERIC_IRQ_ENTRY select GENERIC_IRQ_SHOW select GENERIC_IRQ_SHOW_LEVEL select GENERIC_PCI_IOMAP if PCI
arch/powerpc/include/asm/entry-common.h +35 -58
147 lines not on this page · raw message
arch/powerpc/include/asm/interrupt.h +54 -438
534 lines not on this page · raw message
arch/powerpc/kernel/interrupt.c +2 -7
@@ -297,13 +297,8 @@ notrace unsigned long interrupt_exit_kernel_prepare(struct pt_regs *regs)/* Returning to a kernel context with local irqs enabled. */ WARN_ON_ONCE (!(regs->msr &MSR_EE )); again: -if (need_irq_preemption ()) { -/* Return to preemptible kernel context */ -if (unlikely (read_thread_flags () & _TIF_NEED_RESCHED)) { -if (preempt_count () ==0 ) -preempt_schedule_irq (); - } - } +if (need_irq_preemption ()) +irqentry_exit_cond_resched ();check_return_regs_valid (regs);
arch/powerpc/kernel/interrupt_64.S +0 -2
@@ -418,8 +418,6 @@ _ASM_NOKPROBE_SYMBOL(interrupt_return_\srr\()) beq interrupt_return_\srr\()_kernel interrupt_return_\srr\()_user: /* make backtraces match the _kernel variant */ _ASM_NOKPROBE_SYMBOL(interrupt_return_\srr\()_user) - addi r3,r1,STACK_INT_FRAME_REGS - bl CFUNC(interrupt_exit_user_prepare) #ifndef CONFIG_INTERRUPT_SANITIZE_REGISTERS cmpdi r3,0 bne- .Lrestore_nvgprs_\srr
Signature · 1 line
2.51.0
RFC v2 8/8 powerpc: Enable Generic Entry/Exit for syscalls.
In reply to Mukesh Kumar ChaurasiyaEnable the syscall entry and exit path from generic framework.
--- arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/entry-common.h | 2 +- arch/powerpc/kernel/interrupt.c | 135 +++++++---------------- arch/powerpc/kernel/ptrace/ptrace.c | 141 ------------------------ arch/powerpc/kernel/signal.c | 10 +- arch/powerpc/kernel/syscall.c | 119 +------------------- 6 files changed, 49 insertions(+), 359 deletions(-)
arch/powerpc/Kconfig +1 -0
@@ -199,6 +199,7 @@ config PPC select GENERIC_CPU_AUTOPROBE select GENERIC_CPU_VULNERABILITIES if PPC_BARRIER_NOSPEC select GENERIC_EARLY_IOREMAP + select GENERIC_ENTRY select GENERIC_GETTIMEOFDAY select GENERIC_IDLE_POLL_SETUP select GENERIC_IOREMAP
arch/powerpc/include/asm/entry-common.h +1 -1
@@ -3,7 +3,7 @@#ifndef _ASM_PPC_ENTRY_COMMON_H#define _ASM_PPC_ENTRY_COMMON_H -#ifdef CONFIG_GENERIC_IRQ_ENTRY +#ifdef CONFIG_GENERIC_ENTRY #include <asm/cputime.h> #include <asm/interrupt.h>
arch/powerpc/kernel/interrupt.c +42 -93
191 lines not on this page · raw message
arch/powerpc/kernel/ptrace/ptrace.c +0 -141
153 lines not on this page · raw message
arch/powerpc/kernel/signal.c +2 -8
@@ -6,6 +6,7 @@* Extracted from signal_32.c and signal_64.c */ +#include <linux/entry-common.h> #include <linux/resume_user_mode.h> #include <linux/signal.h> #include <linux/uprobes.h>
@@ -22,11 +23,6 @@#include "signal.h" -/* This will be removed */ -#ifdef CONFIG_GENERIC_ENTRY -#include <linux/entry-common.h> -#endif /* CONFIG_GENERIC_ENTRY */ -#ifdef CONFIG_VSX unsigned long copy_fpr_to_user (void __user *to,struct task_struct *task)
@@ -374,11 +370,9 @@ void signal_fault(struct task_struct *tsk, struct pt_regs *regs, task_pid_nr(tsk), where, ptr, regs->nip, regs->link); } -#ifdef CONFIG_GENERIC_ENTRY void arch_do_signal_or_restart (struct pt_regs *regs) {BUG_ON (regs != current->thread.regs); - local_paca->generic_fw_flags |=GFW_RESTORE_ALL ; + regs->exit_flags |= _TIF_RESTOREALL;do_signal (current); } -#endif /* CONFIG_GENERIC_ENTRY */
arch/powerpc/kernel/syscall.c +3 -116
133 lines not on this page · raw message
Signature · 1 line
2.51.0
Shrikanth Hegde
reviewerRe: [RFC V2 8/8] powerpc: Enable Generic Entry/Exit for syscalls.
Quoted 4 lines · Mukesh Kumar Chaurasiya
Enable the syscall entry and exit path from generic framework.
Signed-off-by Mukesh Kumar Chaurasiya <[email protected]>---
Hi Mukesh.
Thanks for working on this and getting it to better shape.
Quoted 24 lines
arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/entry-common.h | 2 +- arch/powerpc/kernel/interrupt.c | 135 +++++++---------------- arch/powerpc/kernel/ptrace/ptrace.c | 141 ------------------------ arch/powerpc/kernel/signal.c | 10 +- arch/powerpc/kernel/syscall.c | 119 +------------------- 6 files changed, 49 insertions(+), 359 deletions(-)arch/powerpc/Kconfig +1
-0@@ -199,6 +199,7 @@ config PPC select GENERIC_CPU_AUTOPROBE select GENERIC_CPU_VULNERABILITIES if PPC_BARRIER_NOSPEC select GENERIC_EARLY_IOREMAP + select GENERIC_ENTRY select GENERIC_GETTIMEOFDAY select GENERIC_IDLE_POLL_SETUP select GENERIC_IOREMAParch/powerpc/include/asm/entry-common.h +0
-0
Quoted 1 line
@@ -3,7 +3,7
There could be some of the configs we need to take care while enabling generic entry. Since powerpc didn't have it earlier, there could areas which needs cleanup. One for example dynamic preemption. There could be more. Do some git history checks and see.
Issue with dynamic preemption:
ld: kernel/entry/common.o:/home/shrikanth/sched_tip/kernel/entry/common.c:161: multiple definition of `sk_dynamic_irqentry_exit_cond_resched'; arch/powerpc/kernel/interrupt.o:/home/shrikanth/sched_tip/arch/powerpc/kernel/interrupt.c:29: first defined here
Below diff helps to fix and changing preemption modes help. Also verified preempt lazy works too.
---
arch/powerpc/kernel/interrupt.c +0 -4
@@ -25,10 +25,6 @@unsigned long global_dbcr0[NR_CPUS ];#endif -#if defined(CONFIG_PREEMPT_DYNAMIC ) -DEFINE_STATIC_KEY_TRUE (sk_dynamic_irqentry_exit_cond_resched); -#endif -#ifdef CONFIG_PPC_BOOK3S_64 DEFINE_STATIC_KEY_FALSE (interrupt_exit_not_reentrant);static inline bool exit_must_hard_disable (void )
----
Though ideal thing is move them to sched/core instead of being in generic code. Like below.
https://lore.kernel.org/all/[email protected]/
Re: [RFC V2 8/8] powerpc: Enable Generic Entry/Exit for syscalls.
Quoted 56 lines · Shrikanth Hegde
Quoted 4 lines · Mukesh Kumar Chaurasiya
Enable the syscall entry and exit path from generic framework.
Signed-off-by Mukesh Kumar Chaurasiya <[email protected]>---
Hi Mukesh.
Thanks for working on this and getting it to better shape.Quoted 24 lines
arch/powerpc/Kconfig| 1 +arch/powerpc/include/asm/entry-common.h| 2 +- arch/powerpc/kernel/interrupt.c | 135 +++++++---------------- arch/powerpc/kernel/ptrace/ptrace.c | 141 ------------------------ arch/powerpc/kernel/signal.c | 10 +- arch/powerpc/kernel/syscall.c | 119 +-------------------6 files changed, 49 insertions(+), 359 deletions(-)arch/powerpc/Kconfig +0
-0@@ -199,6 +199,7 @@ config PPCselect
GENERIC_CPU_AUTOPROBE
select GENERIC_CPU_VULNERABILITIES ifPPC_BARRIER_NOSPECselectGENERIC_EARLY_IOREMAP
+ selectGENERIC_ENTRY
selectGENERIC_GETTIMEOFDAY
selectGENERIC_IDLE_POLL_SETUP
selectGENERIC_IOREMAParch/powerpc/include/asm/entry-common.h +0
-0Quoted 1 line
@@ -3,7 +3,7
There could be some of the configs we need to take care while enabling generic entry. Since powerpc didn't have it earlier, there could areas which needs cleanup. One for example dynamic preemption. There could be more. Do some git history checks and see.
Issue with dynamic preemption:
ld: kernel/entry/common.o:/home/shrikanth/sched_tip/kernel/entry/common.c:161: multiple definition of `sk_dynamic_irqentry_exit_cond_resched'; arch/powerpc/kernel/interrupt.o:/home/shrikanth/sched_tip/arch/powerpc/kernel/interrupt.c:29: first defined here
Below diff helps to fix and changing preemption modes help. Also verified preempt lazy works too.
---
arch/powerpc/kernel/interrupt.c +0
-0
arch/powerpc/kernel/interrupt.c line 30
Quoted 10 lines
arch/powerpc/kernel/interrupt.c +0
-4@@ -25,10 +25,6 @@ unsigned long global_dbcr0[NR_CPUS]; #endif -#if defined(CONFIG_PREEMPT_DYNAMIC ) -DEFINE_STATIC_KEY_TRUE (sk_dynamic_irqentry_exit_cond_resched); -#endif - #ifdef CONFIG_PPC_BOOK3S_64 DEFINE_STATIC_KEY_FALSE(interrupt_exit_not_reentrant); static inline bool exit_must_hard_disable(void)
Hey Srikanth,
Thanks for this. I will add this in next revision.
Mukesh
Quoted 5 lines
----
Though ideal thing is move them to sched/core instead of being in generic code. Like below.
https://lore.kernel.org/all/[email protected]/
Quoted 9 lines · Mukesh Kumar Chaurasiya
Adding support for the generic irq entry/exit handling for PowerPC. The goal is to bring PowerPC in line with other architectures that already use the common irq entry infrastructure, reducing duplicated code and making it easier to share future changes in entry/exit paths.
This is slightly tested on ppc64le.
The performance benchmarks from perf bench basic syscall are below:
Quoted 7 lines
| Metric | W/O Generic Framework | With Generic Framework | Improvement | | ---------- | --------------------- | ---------------------- | ----------- | | Total time | 0.885 [sec] | 0.880 [sec] | ~0.56% | | usecs/op | 0.088518 | 0.088005 | ~0.58% | | ops/sec | 1,12,97,086 | 1,13,62,977 | ~0.58% |Thats close to 0.6% improvement with this.
Cool!
Quoted 1 line
18 files changed, 698 insertions(+), 810 deletions(-)
Thanks for moving ppc over to this. Makes everyones life easier!
tglx
Shrikanth Hegde
reviewerRe: [RFC V2 2/8] powerpc: Prepare to build with generic entry/exit framework
In reply to Mukesh Kumar ChaurasiyaQuoted 44 lines · Mukesh Kumar Chaurasiya
Enabling build with generic entry/exit framework for powerpc architecture requires few necessary steps.
Introducing minor infrastructure updates to prepare for future generic framework handling:
- Add
syscall_workfield to structthread_infofor SYSCALL_WORK_* flags.
- Providearch_syscall_is_vdso_sigreturn()stub, returning false.
- Addon_thread_stack()helper to test whether the current stack pointer lies within the task’s kernel stack.No functional change is intended with this patch.
Signed-off-by Mukesh Kumar Chaurasiya <[email protected]>--- arch/powerpc/include/asm/entry-common.h | 11 +++++++++++ arch/powerpc/include/asm/stacktrace.h | 8 ++++++++ arch/powerpc/include/asm/syscall.h | 5 +++++ arch/powerpc/include/asm/thread_info.h | 1 + 4 files changed, 25 insertions(+)create mode 100644
arch/powerpc/include/asm/entry-common.harch/powerpc/include/asm/entry-common.h new file +11
-0@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _ASM_PPC_ENTRY_COMMON_H +#define _ASM_PPC_ENTRY_COMMON_H + +#ifdef CONFIG_GENERIC_IRQ_ENTRY + +#include <asm/stacktrace.h> + +#endif /* CONFIG_GENERIC_IRQ_ENTRY */ +#endif /* _ASM_PPC_ENTRY_COMMON_H */ arch/powerpc/include/asm/stacktrace.h +0
-0
arch/powerpc/include/asm/stacktrace.h line 11
Quoted 4 lines
arch/powerpc/include/asm/stacktrace.h +1
-0@@ -8,6 +8,14 @@#ifndef _ASM_POWERPC_STACKTRACE_H#define _ASM_POWERPC_STACKTRACE_H +#include <linux/sched.h>
nit:
Is sched.h needed? I don't see any reference here. It compiled for me without it.
Quoted 29 lines
arch/powerpc/include/asm/stacktrace.h +7
-0+void show_user_instructions (struct pt_regs *regs); +static inline bool on_thread_stack (void ) +{ +return !(((unsigned long )(current->stack) ^ current_stack_pointer) + & ~(THREAD_SIZE -1 )); +} +#endif /* _ASM_POWERPC_STACKTRACE_H */ arch/powerpc/include/asm/syscall.h +5
-0@@ -139,4 +139,9 @@ static inline int syscall_get_arch(struct task_struct *task) else return AUDIT_ARCH_PPC64; } + +static inline bool arch_syscall_is_vdso_sigreturn (struct pt_regs *regs) +{ +return false; +}#endif /* _ASM_SYSCALL_H */ arch/powerpc/include/asm/thread_info.h +0
-0
arch/powerpc/include/asm/thread_info.h line 57
Quoted 4 lines
arch/powerpc/include/asm/thread_info.h +1
-0@@ -54,6 +54,7 @@struct thread_info {int preempt_count;/* 0 => preemptable, <0 => BUG */ +unsigned long syscall_work;/* SYSCALL_WORK_ flags */
Can this go after cpu ? it would be 8 byte aligned then. Since it is in fast path, might help.
Quoted 3 lines
arch/powerpc/include/asm/thread_info.h +0
-0#ifdef CONFIG_SMP unsigned int cpu;#endif
Re: [RFC V2 1/8] powerpc: rename arch_irq_disabled_regs
In reply to Mukesh Kumar ChaurasiyaQuoted 14 lines · Mukesh Kumar Chaurasiya
Renaming
arch_irq_disabled_regstoregs_irqs_disabledto be used commonly in generic entry exit framework and ppc arch code.Signed-off-by Mukesh Kumar Chaurasiya <[email protected]>--- arch/powerpc/include/asm/hw_irq.h | 4 ++-- arch/powerpc/include/asm/interrupt.h | 12 ++++++------ arch/powerpc/kernel/interrupt.c | 4 ++-- arch/powerpc/kernel/syscall.c | 2 +- arch/powerpc/kernel/traps.c | 2 +- arch/powerpc/kernel/watchdog.c | 2 +- arch/powerpc/perf/core-book3s.c | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-)
...
Quoted 6 lines
return 0;
arch/powerpc/perf/core-book3s.c +0
-0
arch/powerpc/perf/core-book3s.c static void __perf_event_interrupt(struct pt_regs *regs) · line 2488
Quoted 8 lines
arch/powerpc/perf/core-book3s.c +1
-1@@ -2482,7 +2482,7 @@ static void __perf_event_interrupt(struct pt_regs *regs)* will trigger a PMI after waking up from idle. Since counter values are _not_ * saved/restored in idle path, can lead to below "Can't find PMC" message. */ -if (unlikely (!found) && !arch_irq_disabled_regs (regs)) +if (unlikely (!found) && !regs_irqs_disabled (regs))printk_ratelimited (KERN_WARNING "Can't find PMC that caused IRQ\n" );/*
Shrikanth Hegde
reviewerRe: [RFC V2 3/8] powerpc: introduce arch_enter_from_user_mode
In reply to Mukesh Kumar ChaurasiyaQuoted 1 line · Mukesh Kumar Chaurasiya
- Implement the hook
arch_enter_from_user_modefor syscall entry.
nit: for generic syscall infra.
Quoted 104 lines
- Move
booke_load_dbcr0frominterrupt.ctointerrupt.hNo functional change intended.
Signed-off-by Mukesh Kumar Chaurasiya <[email protected]>--- arch/powerpc/include/asm/entry-common.h | 96 +++++++++++++++++++++++++ arch/powerpc/include/asm/interrupt.h | 23 ++++++ arch/powerpc/kernel/interrupt.c | 22 ------ 3 files changed, 119 insertions(+), 22 deletions(-)arch/powerpc/include/asm/entry-common.h +84
-0@@ -5,7 +5,103 @@#ifdef CONFIG_GENERIC_IRQ_ENTRY +#include <asm/cputime.h> +#include <asm/interrupt.h> #include <asm/stacktrace.h> +#include <asm/tm.h> + +static __always_inline void arch_enter_from_user_mode(struct pt_regs *regs) +{ +if (IS_ENABLED (CONFIG_PPC_IRQ_SOFT_MASK_DEBUG )) +BUG_ON (irq_soft_mask_return () !=IRQS_ALL_DISABLED ); + +BUG_ON (regs_is_unrecoverable (regs)); +BUG_ON (!user_mode (regs)); +BUG_ON (regs_irqs_disabled (regs)); + +#ifdef CONFIG_PPC_PKEY +if (mmu_has_feature (MMU_FTR_PKEY )) { +unsigned long amr, iamr; +bool flush_needed = false; +/* +* When entering from userspace we mostly have the AMR/IAMR +* different from kernel default values. Hence don't compare. +*/ + amr =mfspr (SPRN_AMR ); + iamr =mfspr (SPRN_IAMR ); + regs->amr = amr; + regs->iamr = iamr; +if (mmu_has_feature (MMU_FTR_KUAP )) { +mtspr (SPRN_AMR ,AMR_KUAP_BLOCKED ); + flush_needed = true; + } +if (mmu_has_feature (MMU_FTR_BOOK3S_KUEP )) { +mtspr (SPRN_IAMR ,AMR_KUEP_BLOCKED ); + flush_needed = true; + } +if (flush_needed) +isync (); + } else +#endif +kuap_assert_locked (); + +booke_restore_dbcr0 (); + +account_cpu_user_entry (); + +account_stolen_time (); + +/* +* This is not required for the syscall exit path, but makes the +* stack frame look nicer. If this was initialised in the first stack +* frame, or if the unwinder was taught the first stack frame always +* returns to user with IRQS_ENABLED, this store could be avoided! +*/ +irq_soft_mask_regs_set_state (regs,IRQS_ENABLED ); + +/* +* If system call is called with TM active, set _TIF_RESTOREALL to +* prevent RFSCV being used to return to userspace, because POWER9 +* TM implementation has problems with this instruction returning to +* transactional state. Final register values are not relevant because +* the transaction will be aborted upon return anyway. Or in the case +* of unsupported_scv SIGILL fault, the return state does not much +* matter because it's an edge case. +*/ +if (IS_ENABLED (CONFIG_PPC_TRANSACTIONAL_MEM ) && +unlikely (MSR_TM_TRANSACTIONAL (regs->msr))) +set_bits (_TIF_RESTOREALL, ¤t_thread_info ()->flags); + +/* +* If the system call was made with a transaction active, doom it and +* return without performing the system call. Unless it was an +* unsupported scv vector, in which case it's treated like an illegal +* instruction. +*/ +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM +if (unlikely (MSR_TM_TRANSACTIONAL (regs->msr)) && + !trap_is_unsupported_scv (regs)) { +/* Enable TM in the kernel, and disable EE (for scv) */ +hard_irq_disable (); +mtmsr (mfmsr () |MSR_TM ); + +/* tabort, this dooms the transaction, nothing else */ + asmvolatile (".long 0x7c00071d | ((%0) << 16)" + ::"r" (TM_CAUSE_SYSCALL |TM_CAUSE_PERSISTENT )); + +/*
arch/powerpc/include/asm/entry-common.h line 102
Quoted 10 lines
arch/powerpc/include/asm/entry-common.h +10
-0+* Userspace will never see the return value. Execution will +* resume after the tbegin. of the aborted transaction with the +* checkpointed register state. A context switch could occur +* or signal delivered to the process before resuming the +* doomed transaction context, but that should all be handled +* as expected. +*/ + return; + } +#endif // CONFIG_PPC_TRANSACTIONAL_MEM
nit: Better to follow standard comment practices.
/* CONFIG_PPC_TRANSACTIONAL_MEM */
Quoted 25 lines
arch/powerpc/include/asm/entry-common.h +2
-0+} +#define arch_enter_from_user_mode arch_enter_from_user_mode#endif /* CONFIG_GENERIC_IRQ_ENTRY */ #endif /* _ASM_PPC_ENTRY_COMMON_H */ arch/powerpc/include/asm/interrupt.h +12
-0@@ -138,6 +138,29 @@ static inline void nap_adjust_return(struct pt_regs *regs)#endif } +static inline void booke_load_dbcr0 (void ) +{ +#ifdef CONFIG_PPC_ADV_DEBUG_REGS +unsigned long dbcr0 = current->thread.debug.dbcr0; + +if (likely (!(dbcr0 &DBCR0_IDM ))) +return ; + +/* +* Check to see if the dbcr0 register is set up to debug. +* Use the internal debug mode bit to do this. +*/
arch/powerpc/include/asm/interrupt.h static inline void nap_adjust_return(struct pt_regs *regs) · line 162
Quoted 10 lines
arch/powerpc/include/asm/interrupt.h +10
-0+mtmsr (mfmsr () & ~MSR_DE ); +if (IS_ENABLED (CONFIG_PPC32 )) { +isync (); + global_dbcr0[smp_processor_id ()] =mfspr (SPRN_DBCR0 ); + } +mtspr (SPRN_DBCR0 , dbcr0); +mtspr (SPRN_DBSR ,-1 ); +#endif +} +
Please run checkpatch.pl --strict on the series and fix the simple ones such as need to using tabs, spaces and alignments, extra lines etc.
Quoted 37 lines
arch/powerpc/include/asm/interrupt.h +1
-0+static inline void booke_restore_dbcr0 (void ) {#ifdef CONFIG_PPC_ADV_DEBUG_REGS arch/powerpc/kernel/interrupt.c +0
-22@@ -78,28 +78,6 @@ static notrace __always_inline bool prep_irq_for_enabled_exit(bool restartable)return true; } -static notrace void booke_load_dbcr0(void) -{ -#ifdef CONFIG_PPC_ADV_DEBUG_REGS -unsigned long dbcr0 = current->thread.debug.dbcr0; - -if (likely (!(dbcr0 &DBCR0_IDM ))) -return ; - -/* -* Check to see if the dbcr0 register is set up to debug. -* Use the internal debug mode bit to do this. -*/ -mtmsr (mfmsr () & ~MSR_DE ); -if (IS_ENABLED (CONFIG_PPC32 )) { -isync (); - global_dbcr0[smp_processor_id ()] =mfspr (SPRN_DBCR0 ); - } -mtspr (SPRN_DBCR0 , dbcr0); -mtspr (SPRN_DBSR ,-1 ); -#endif -} - static notrace void check_return_regs_valid(struct pt_regs *regs) {#ifdef CONFIG_PPC_BOOK3S_64
Re: [RFC V2 2/8] powerpc: Prepare to build with generic entry/exit framework
In reply to Shrikanth HegdeQuoted 53 lines · Shrikanth Hegde
Quoted 46 lines · Mukesh Kumar Chaurasiya
Enabling build with generic entry/exit framework for powerpc architecture requires few necessary steps.
Introducing minor infrastructure updates to prepare for future generic framework handling:
- Add
syscall_workfield to structthread_infofor SYSCALL_WORK_* flags.
- Providearch_syscall_is_vdso_sigreturn()stub, returning false.
- Addon_thread_stack()helper to test whether the current stack pointer lies within the task’s kernel stack.No functional change is intended with this patch.
Signed-off-by Mukesh Kumar Chaurasiya <[email protected]>---
arch/powerpc/include/asm/entry-common.h| 11 +++++++++++ arch/powerpc/include/asm/stacktrace.h | 8 ++++++++ arch/powerpc/include/asm/syscall.h | 5 +++++ arch/powerpc/include/asm/thread_info.h | 1 +4 files changed, 25 insertions(+)create mode 100644
arch/powerpc/include/asm/entry-common.harch/powerpc/include/asm/entry-common.h new file +11
-0@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _ASM_PPC_ENTRY_COMMON_H +#define _ASM_PPC_ENTRY_COMMON_H + +#ifdef CONFIG_GENERIC_IRQ_ENTRY + +#include <asm/stacktrace.h> + +#endif /* CONFIG_GENERIC_IRQ_ENTRY */ +#endif /* _ASM_PPC_ENTRY_COMMON_H */ arch/powerpc/include/asm/stacktrace.h +0
-0@@ -8,6 +8,14 @@ #ifndef _ASM_POWERPC_STACKTRACE_H #define _ASM_POWERPC_STACKTRACE_HQuoted 1 line
+#include <
linux/sched.h>nit:
Quoted 3 lines
Is
sched.hneeded? I don't see any reference here. It compiled for me without it.
Will remove this in next revision.
Quoted 27 lines
Quoted 27 lines
+
voidshow_user_instructions(struct pt_regs *regs); +static inline boolon_thread_stack(void)arch/powerpc/include/asm/stacktrace.h +5
-0+{ + return !(((unsigned long)(current->stack) ^ current_stack_pointer) + & ~(THREAD_SIZE -1)); +} +#endif /*
_ASM_POWERPC_STACKTRACE_H*/arch/powerpc/include/asm/syscall.h +0
-0@@ -139,4 +139,9 @@ static inline int syscall_get_arch(struct task_struct *task)else
returnAUDIT_ARCH_PPC64;
}arch/powerpc/include/asm/syscall.h +5
-0+ +static inline bool arch_syscall_is_vdso_sigreturn (struct pt_regs *regs) +{ + return false; +}#endif /*
_ASM_SYSCALL_H*/arch/powerpc/include/asm/thread_info.h +0
-1--- a/arch/powerpc/include/asm/thread_info.h
Quoted 9 lines
Quoted 6 lines
+++
b/arch/powerpc/include/asm/thread_info.harch/powerpc/include/asm/thread_info.h +0
-0@@ -54,6 +54,7 @@ struct thread_info { int preempt_count; /* 0 => preemptable,<0 => BUG */
+ unsigned long syscall_work; /*SYSCALL_WORK_flags */Can this go after cpu ? it would be 8 byte aligned then. Since it is in fast path, might help.
Oh yeah, will move this in next revision.
Thanks,
Mukesh
Quoted 4 lines
Quoted 3 lines
#ifdef
CONFIG_SMP
unsigned int cpu;
#endif
Shrikanth Hegde
reviewerRe: [RFC V2 7/8] powerpc: Enable IRQ generic entry/exit path.
In reply to Mukesh Kumar ChaurasiyaQuoted 11 lines · Mukesh Kumar Chaurasiya
Enable generic entry/exit path for ppc irq.
Signed-off-by Mukesh Kumar Chaurasiya <[email protected]>--- arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/entry-common.h | 93 ++--- arch/powerpc/include/asm/interrupt.h | 492 +++--------------------- arch/powerpc/kernel/interrupt.c | 9 +- arch/powerpc/kernel/interrupt_64.S | 2 - 5 files changed, 92 insertions(+), 505 deletions(-)
\
Quoted 7 lines
arch/powerpc/kernel/interrupt.c +0
-0@@ -297,13 +297,8 @@ notrace unsigned long interrupt_exit_kernel_prepare(struct pt_regs *regs)/* Returning to a kernel context with local irqs enabled. */ WARN_ON_ONCE (!(regs->msr &MSR_EE ));
arch/powerpc/kernel/interrupt.c notrace unsigned long interrupt_exit_kernel_prepare(struct pt_regs *regs) · line 301
Quoted 10 lines
arch/powerpc/kernel/interrupt.c +2
-7again: -if (need_irq_preemption ()) { -/* Return to preemptible kernel context */ -if (unlikely (read_thread_flags () & _TIF_NEED_RESCHED)) { -if (preempt_count () ==0 ) -preempt_schedule_irq (); - } - } +if (need_irq_preemption ()) +irqentry_exit_cond_resched ();
irqentry_exit_cond_resched is also called in irqentry_exit. It would be better if we can find ways to avoid calling it again.
I see a loop here. But comment says it is not enabling irq again. so the loop is bounded. So might be okay to remove cond_resched here. do run preemptirq, irq tracers to ensure that is case.
Also, what is this "soft_interrupts"?
Quoted 16 lines
arch/powerpc/kernel/interrupt.c +0
-0check_return_regs_valid (regs);arch/powerpc/kernel/interrupt_64.S +0
-2@@ -418,8 +418,6 @@ _ASM_NOKPROBE_SYMBOL(interrupt_return_\srr\()) beq interrupt_return_\srr\()_kernel interrupt_return_\srr\()_user: /* make backtraces match the _kernel variant */ _ASM_NOKPROBE_SYMBOL(interrupt_return_\srr\()_user) - addi r3,r1,STACK_INT_FRAME_REGS - bl CFUNC(interrupt_exit_user_prepare) #ifndef CONFIG_INTERRUPT_SANITIZE_REGISTERS cmpdi r3,0 bne- .Lrestore_nvgprs_\srr
Re: [RFC V2 3/8] powerpc: introduce arch_enter_from_user_mode
In reply to Shrikanth HegdeQuoted 6 lines · Shrikanth Hegde
Quoted 1 line · Mukesh Kumar Chaurasiya
- Implement the hook
arch_enter_from_user_modefor syscall entry.nit: for generic syscall infra.
Cool, will change this.
Quoted 116 lines
Quoted 116 lines
- Move
booke_load_dbcr0frominterrupt.ctointerrupt.hNo functional change intended.
Signed-off-by Mukesh Kumar Chaurasiya <[email protected]>---
arch/powerpc/include/asm/entry-common.h| 96 +++++++++++++++++++++++++ arch/powerpc/include/asm/interrupt.h | 23 ++++++ arch/powerpc/kernel/interrupt.c | 22 ------3 files changed, 119 insertions(+), 22 deletions(-)arch/powerpc/include/asm/entry-common.h +0
-0@@ -5,7 +5,103 @@ #ifdef CONFIG_GENERIC_IRQ_ENTRY+#include <
asm/cputime.h>
+#include <asm/interrupt.h>
#include <asm/stacktrace.h>arch/powerpc/include/asm/entry-common.h +3
-0+#include <asm/tm.h> + +static __always_inline void arch_enter_from_user_mode(struct pt_regs*regs)
arch/powerpc/include/asm/entry-common.h +43
-0+{ + if (IS_ENABLED(CONFIG_PPC_IRQ_SOFT_MASK_DEBUG)) + BUG_ON(irq_soft_mask_return() != IRQS_ALL_DISABLED); + + BUG_ON(regs_is_unrecoverable(regs)); + BUG_ON(!user_mode(regs)); + BUG_ON(regs_irqs_disabled(regs)); + +#ifdef CONFIG_PPC_PKEY + if (mmu_has_feature(MMU_FTR_PKEY)) { + unsigned long amr, iamr; + bool flush_needed = false; + /* + * When entering from userspace we mostly have the AMR/IAMR + * different from kernel default values. Hence don't compare. + */ + amr = mfspr(SPRN_AMR); + iamr = mfspr(SPRN_IAMR); + regs->amr = amr; + regs->iamr = iamr; + if (mmu_has_feature(MMU_FTR_KUAP)) { + mtspr(SPRN_AMR, AMR_KUAP_BLOCKED); + flush_needed = true; + } + if (mmu_has_feature(MMU_FTR_BOOK3S_KUEP)) { + mtspr(SPRN_IAMR, AMR_KUEP_BLOCKED); + flush_needed = true; + } + if (flush_needed) + isync(); + } else +#endif + kuap_assert_locked(); + + booke_restore_dbcr0(); + + account_cpu_user_entry(); + + account_stolen_time(); + + /* +* This is not required for the syscall exit path, but makes the +* stack frame look nicer. If this was initialised in the first stack
+ * frame, or if the unwinder was taught the first stack frame always
+ * returns to user withIRQS_ENABLED, this store could be avoided! + */
+irq_soft_mask_regs_set_state(regs, IRQS_ENABLED);
+
+ /*
+ * If system call is called with TM active, set_TIF_RESTOREALLto + * prevent RFSCV being used to return to userspace, because POWER9 + * TM implementation has problems with this instruction returning to
+ * transactional state. Final register values are not relevant because
+ * the transaction will be aborted upon return anyway. Or in the case
+ * ofunsupported_scvSIGILL fault, the return state does not much + * matter because it's an edge case.
+ */
+ if (IS_ENABLED(CONFIG_PPC_TRANSACTIONAL_MEM)&&
+ unlikely(MSR_TM_TRANSACTIONAL(regs->msr)))
+set_bits(_TIF_RESTOREALL, ¤t_thread_info()->flags); +
+ /*
+ * If the system call was made with a transaction active, doom it and
+ * return without performing the system call. Unless it was an + * unsupported scv vector, in which case it's treated like an illegal
+ * instruction.
+ */arch/powerpc/include/asm/entry-common.h +17
-0+#ifdef CONFIG_PPC_TRANSACTIONAL_MEM + if (unlikely(MSR_TM_TRANSACTIONAL(regs->msr)) && + !trap_is_unsupported_scv(regs)) { + /* Enable TM in the kernel, and disable EE (for scv) */ + hard_irq_disable(); + mtmsr(mfmsr() | MSR_TM); + + /* tabort, this dooms the transaction, nothing else */ + asm volatile(".long 0x7c00071d | ((%0) << 16)" + :: "r"(TM_CAUSE_SYSCALL|TM_CAUSE_PERSISTENT)); + + /* +* Userspace will never see the return value. Execution will +* resume after the tbegin. of the aborted transaction with the +* checkpointed register state. A context switch could occur +* or signal delivered to the process before resuming the +* doomed transaction context, but that should all be handled
Quoted 9 lines
Quoted 5 lines
+ * as expected.
+ */
+ return;
+ }
+#endif //CONFIG_PPC_TRANSACTIONAL_MEMnit: Better to follow standard comment practices.
/*CONFIG_PPC_TRANSACTIONAL_MEM*/
Sure.
Quoted 29 lines
Quoted 29 lines
arch/powerpc/include/asm/entry-common.h +2
-0+} +#define arch_enter_from_user_mode arch_enter_from_user_mode#endif /*
CONFIG_GENERIC_IRQ_ENTRY*/
#endif /*_ASM_PPC_ENTRY_COMMON_H*/arch/powerpc/include/asm/interrupt.h +16
-0@@ -138,6 +138,29 @@ static inline void nap_adjust_return(struct pt_regs *regs) #endif } +static inline void booke_load_dbcr0(void) +{ +#ifdef CONFIG_PPC_ADV_DEBUG_REGS + unsigned long dbcr0 = current->thread.debug.dbcr0; + + if (likely(!(dbcr0 & DBCR0_IDM))) + return; + + /* + * Check to see if the dbcr0 register is set up to debug. + * Use the internal debug mode bit to do this. + */ + mtmsr(mfmsr() & ~MSR_DE); + if (IS_ENABLED(CONFIG_PPC32)) { + isync(); + global_dbcr0[smp_processor_id()] = mfspr(SPRN_DBCR0); + }
Quoted 9 lines
arch/powerpc/include/asm/interrupt.h static inline void nap_adjust_return(struct pt_regs *regs) · line 162
Quoted 5 lines
arch/powerpc/include/asm/interrupt.h +5
-0+ mtspr(SPRN_DBCR0, dbcr0); + mtspr(SPRN_DBSR, -1); +#endif +} +Please run checkpatch.pl --strict on the series and fix the simple ones such as need to using tabs, spaces and alignments, extra lines etc.
Sure, will fix these.
Thanks,
Mukesh
Quoted 38 lines
Quoted 37 lines
arch/powerpc/include/asm/interrupt.h +1
-0+ static inline void booke_restore_dbcr0(void) {#ifdef
CONFIG_PPC_ADV_DEBUG_REGSarch/powerpc/kernel/interrupt.c +0
-21@@ -78,28 +78,6 @@ static notrace __always_inline bool prep_irq_for_enabled_exit(bool restartable) return true; } -static notrace void booke_load_dbcr0(void) -{ -#ifdef CONFIG_PPC_ADV_DEBUG_REGS - unsigned long dbcr0 = current->thread.debug.dbcr0; - - if (likely(!(dbcr0 & DBCR0_IDM))) - return; - - /* - * Check to see if the dbcr0 register is set up to debug. - * Use the internal debug mode bit to do this. - */ - mtmsr(mfmsr() & ~MSR_DE); - if (IS_ENABLED(CONFIG_PPC32)) { - isync(); - global_dbcr0[smp_processor_id()] = mfspr(SPRN_DBCR0); - } - mtspr(SPRN_DBCR0, dbcr0); - mtspr(SPRN_DBSR, -1); -#endif -} - static notrace void check_return_regs_valid(struct pt_regs *regs) {#ifdef
CONFIG_PPC_BOOK3S_64
Re: [RFC V2 7/8] powerpc: Enable IRQ generic entry/exit path.
In reply to Shrikanth HegdeQuoted 36 lines · Shrikanth Hegde
Quoted 11 lines · Mukesh Kumar Chaurasiya
Enable generic entry/exit path for ppc irq.
Signed-off-by Mukesh Kumar Chaurasiya <[email protected]>---
arch/powerpc/Kconfig | 1 +arch/powerpc/include/asm/entry-common.h| 93 ++--- arch/powerpc/include/asm/interrupt.h | 492 +++--------------------- arch/powerpc/kernel/interrupt.c | 9 +- arch/powerpc/kernel/interrupt_64.S | 2 -5 files changed, 92 insertions(+), 505 deletions(-)\
Quoted 10 lines
arch/powerpc/kernel/interrupt.c +0
-0@@ -297,13 +297,8 @@ notrace unsigned long interrupt_exit_kernel_prepare(struct pt_regs *regs) /* Returning to a kernel context with local irqs enabled. */ WARN_ON_ONCE(!(regs->msr & MSR_EE));again:
- if (need_irq_preemption()) {Quoted 8 lines
- /* Return to preemptible kernel context */
- if (unlikely(read_thread_flags() & _TIF_NEED_RESCHED)) { - if (preempt_count()== 0)
-preempt_schedule_irq();
- }
- }
+ if (need_irq_preemption())
+irqentry_exit_cond_resched();
irqentry_exit_cond_reschedis also called inirqentry_exit. It would be better if we can find ways to avoid calling it again.
Quoted 3 lines
I see a loop here. But comment says it is not enabling irq again. so the loop is bounded. So might be okay to remove
cond_reschedhere. do run preemptirq, irq tracers to ensure that is case.
Sure.
Quoted 1 line
Also, what is this "
soft_interrupts"?
You mean soft masked interrupts?
It's a mechanism to buffer interrupts without disabling the ee bit so that we can replay those interrupts later.
Quoted 15 lines
Quoted 14 lines
check_return_regs_valid(regs);
diff --gita/arch/powerpc/kernel/interrupt_64.Sb/arch/powerpc/kernel/interrupt_64.Sindex1ad059a9e2fef..6aa88fe91fb6a100644arch/powerpc/kernel/interrupt_64.S +0
-0@@ -418,8 +418,6 @@ _ASM_NOKPROBE_SYMBOL(interrupt_return_\srr\())beq interrupt_return_\srr\()_kernel interrupt_return_\srr\()_user: /* make backtraces match the
_kernelvariant */ _ASM_NOKPROBE_SYMBOL(interrupt_return_\srr\()_user)
- addi r3,r1,STACK_INT_FRAME_REGS
- blCFUNC(interrupt_exit_user_prepare)
#ifndefCONFIG_INTERRUPT_SANITIZE_REGISTERS
cmpdi r3,0
bne- .Lrestore_nvgprs_\srr
Re: [RFC V2 8/8] powerpc: Enable Generic Entry/Exit for syscalls.
In reply to Shrikanth HegdeQuoted 67 lines · Shrikanth Hegde
Quoted 4 lines · Mukesh Kumar Chaurasiya
Enable the syscall entry and exit path from generic framework.
Signed-off-by Mukesh Kumar Chaurasiya <[email protected]>---
Hi Mukesh.
Thanks for working on this and getting it to better shape.Quoted 24 lines
arch/powerpc/Kconfig| 1 +arch/powerpc/include/asm/entry-common.h| 2 +- arch/powerpc/kernel/interrupt.c | 135 +++++++---------------- arch/powerpc/kernel/ptrace/ptrace.c | 141 ------------------------ arch/powerpc/kernel/signal.c | 10 +- arch/powerpc/kernel/syscall.c | 119 +-------------------6 files changed, 49 insertions(+), 359 deletions(-)arch/powerpc/Kconfig +0
-0@@ -199,6 +199,7 @@ config PPCselect
GENERIC_CPU_AUTOPROBE
select GENERIC_CPU_VULNERABILITIES ifPPC_BARRIER_NOSPECselectGENERIC_EARLY_IOREMAP
+ selectGENERIC_ENTRY
selectGENERIC_GETTIMEOFDAY
selectGENERIC_IDLE_POLL_SETUP
selectGENERIC_IOREMAParch/powerpc/include/asm/entry-common.h +0
-0Quoted 1 line
@@ -3,7 +3,7
There could be some of the configs we need to take care while enabling generic entry. Since powerpc didn't have it earlier, there could areas which needs cleanup. One for example dynamic preemption. There could be more. Do some git history checks and see.
Issue with dynamic preemption:
ld: kernel/entry/common.o:/home/shrikanth/sched_tip/kernel/entry/common.c:161: multiple definition of `sk_dynamic_irqentry_exit_cond_resched'; arch/powerpc/kernel/interrupt.o:/home/shrikanth/sched_tip/arch/powerpc/kernel/interrupt.c:29: first defined here
Below diff helps to fix and changing preemption modes help. Also verified preempt lazy works too.
---
arch/powerpc/kernel/interrupt.c +0
-5@@ -25,10 +25,6 @@ unsigned long global_dbcr0[NR_CPUS]; #endif -#if defined(CONFIG_PREEMPT_DYNAMIC ) -DEFINE_STATIC_KEY_TRUE (sk_dynamic_irqentry_exit_cond_resched); -#endif - #ifdef CONFIG_PPC_BOOK3S_64 DEFINE_STATIC_KEY_FALSE(interrupt_exit_not_reentrant); static inline bool exit_must_hard_disable(void) ----
Quoted 4 lines
Though ideal thing is move them to sched/core instead of being in generic code. Like below.
https://lore.kernel.org/all/[email protected]/
Sure.
Quoted 49 lines · Mukesh Kumar Chaurasiya
Adding support for the generic irq entry/exit handling for PowerPC. The goal is to bring PowerPC in line with other architectures that already use the common irq entry infrastructure, reducing duplicated code and making it easier to share future changes in entry/exit paths.
This is slightly tested on ppc64le.
The performance benchmarks from perf bench basic syscall are below:
| Metric | W/O Generic Framework | With Generic Framework | Improvement | | ---------- | --------------------- | ---------------------- | ----------- | | Total time | 0.885 [sec] | 0.880 [sec] | ~0.56% | | usecs/op | 0.088518 | 0.088005 | ~0.58% | | ops/sec | 1,12,97,086 | 1,13,62,977 | ~0.58% |Thats close to 0.6% improvement with this.
Changelog:
V1 -> V2: Support added for irq with generic framework.Mukesh Kumar Chaurasiya (8):
powerpc: renamearch_irq_disabled_regs
powerpc: Prepare to build with generic entry/exit framework
powerpc: introducearch_enter_from_user_mode
powerpc: Introduce syscall exit arch functions
powerpc: addexit_flagsfield inpt_regs
powerpc: Prepare for IRQ entry exit
powerpc: Enable IRQ generic entry/exit path.
powerpc: Enable Generic Entry/Exit for syscalls.arch/powerpc/Kconfig | 2 + arch/powerpc/include/asm/entry-common.h | 550 ++++++++++++++++++++++++ arch/powerpc/include/asm/hw_irq.h | 4 +- arch/powerpc/include/asm/interrupt.h | 393 +++-------------- arch/powerpc/include/asm/ptrace.h | 2 + arch/powerpc/include/asm/stacktrace.h | 8 + arch/powerpc/include/asm/syscall.h | 5 + arch/powerpc/include/asm/thread_info.h | 1 + arch/powerpc/include/uapi/asm/ptrace.h | 14 +- arch/powerpc/kernel/asm-offsets.c | 1 + arch/powerpc/kernel/interrupt.c | 251 ++--------- arch/powerpc/kernel/interrupt_64.S | 2 - arch/powerpc/kernel/ptrace/ptrace.c | 142 +----- arch/powerpc/kernel/signal.c | 8 + arch/powerpc/kernel/syscall.c | 119 +---- arch/powerpc/kernel/traps.c | 2 +- arch/powerpc/kernel/watchdog.c | 2 +- arch/powerpc/perf/core-book3s.c | 2 +- 18 files changed, 698 insertions(+), 810 deletions(-)
Quoted 2 lines
create mode 100644
arch/powerpc/include/asm/entry-common.h
Hi,
I have reviewed and tested the generic IRQ entry/exist patch series. Below are my observations:
Test Coverage
• Successfully ran LTP (specially syscall) and entire LTP test suite, without observing any regressions or issues related to the implementation.
System Configuration
• CPUs: 640
• Kernel: v6.17.0-rc6+
• Processor mode: Shared (uncapped)
Performance Evaluation
• Conducted benchmarking using perf bench syscall basic -l.
• No functional regressions observed, and results were consistent with expectations.
The performance benchmarks from perf bench basic syscall are below:
Loops = 100,000 | Metric | W/O Generic Framework | With Generic Framework | Improvement | |----------|-----------------------:|-----------------------:|------------:| | usecs/op | 0.124562 | 0.124253 | ~0.25% | | ops/sec | 8,028,471 | 8,048,158 | ~0.25% | Loops = 1,000,000 | Metric | W/O Generic Framework | With Generic Framework | Improvement | |----------|-----------------------:|-----------------------:|------------:| | usecs/op | 0.125389 | 0.124374 | ~0.81% | | ops/sec | 7,977,511 | 8,040,330 | ~0.79% | Loops = 10,000,000 | Metric | W/O Generic Framework | With Generic Framework | Improvement | |----------|-----------------------:|-----------------------:|------------:| | usecs/op | 0.124626 | 0.123928 | ~0.56% | | ops/sec | 8,024,058 | 8,069,182 | ~0.56% | **Overall (aggregated across all runs)** | Metric | W/O Generic Framework | With Generic Framework | Improvement | | ---------- | ---------------------:|-----------------------:|------------:| | Total time | 1.384 [sec] | 1.376 [sec] | ~0.58% | | usecs/op | 0.124694 | 0.123971 | ~0.58% | | ops/sec | 8,019,904 | 8,066,393 | ~0.58% |
Here with this benchmarking we can see the improvement close to 0.6%.
Overall, the patch series works as intended in my testing.
Please add below tag for the patch set.
Thank You !!