xtensa: enable context tracking and VIRT_CPU_ACCOUNTING_GEN
Subsystems (2)
Max Filippov
maintainercover xtensa: enable context tracking and VIRT_CPU_ACCOUNTING_GEN
Hello,
this series adds context tracking on xtensa and enables HAVE_VIRT_CPU_ACCOUNTING_GEN allowing to build full tickless kernel.
Max Filippov (5):
xtensa: drop dead code from entry.S
xtensa: move trace_hardirqs_off call back to entry.S
xtensa: use abi_* register names in the kernel exit code
xtensa: enable context tracking
xtensa: enable HAVE_VIRT_CPU_ACCOUNTING_GEN
.../time/context-tracking/arch-support.txt | 2 +- .../time/virt-cpuacct/arch-support.txt | 2 +- arch/xtensa/Kconfig | 2 + arch/xtensa/kernel/entry.S | 120 +++++++++--------- arch/xtensa/kernel/traps.c | 11 +- 5 files changed, 66 insertions(+), 71 deletions(-)
Signature · 1 line
2.30.2
Max Filippov
maintainerPATCH 1/5 xtensa: drop dead code from entry.S
KERNEL_STACK_OVERFLOW_CHECK is incomplete and have never been enabled. Remove it.
--- arch/xtensa/kernel/entry.S | 18 ------------------ 1 file changed, 18 deletions(-)
arch/xtensa/kernel/entry.S +0 -18
@@ -28,15 +28,6 @@ #include <asm/tlbflush.h> #include <variant/tie-asm.h> -/* Unimplemented features. */ - -#undef KERNEL_STACK_OVERFLOW_CHECK - -/* Not well tested. - * - * - fast_coprocessor - */ - /* * Macro to find first bit set in WINDOWBASE from the left + 1 *
@@ -350,15 +341,6 @@ KABI_W _bbsi.l a2, 3, 1f l32i a0, a1, PT_AREG0 # restore saved a0 wsr a0, depc -#ifdef KERNEL_STACK_OVERFLOW_CHECK - - /* Stack overflow check, for debugging */ - extui a2, a1, TASK_SIZE_BITS,XX - movi a3, SIZE?? - _bge a2, a3, out_of_stack_panic - -#endif - /* * This is the common exception handler. * We get here from the user exception handler or simply by falling through
Signature · 1 line
2.30.2
Max Filippov
maintainerPATCH 2/5 xtensa: move trace_hardirqs_off call back to entry.S
In reply to Max FilippovContext tracking call must be done after hardirq tracking call, otherwise lockdep_assert_irqs_disabled called from rcu_eqs_exit gives a warning. To avoid context tracking logic duplication for IRQ/exception entry paths move trace_hardirqs_off call back to common entry code.
--- arch/xtensa/kernel/entry.S | 19 +++++++++++++------ arch/xtensa/kernel/traps.c | 11 ++--------- 2 files changed, 15 insertions(+), 15 deletions(-)
arch/xtensa/kernel/entry.S +13 -6
@@ -424,7 +424,6 @@ KABI_W or a3, a3, a0 moveqz a3, a0, a2 # a3 = LOCKLEVEL iff interrupt KABI_W movi a2, PS_WOE_MASK KABI_W or a3, a3, a2 - rsr a2, exccause #endif /* restore return address (or 0 if return to userspace) */
@@ -451,19 +450,27 @@ KABI_W or a3, a3, a2 save_xtregs_opt a1 a3 a4 a5 a6 a7 PT_XTREGS_OPT +#ifdef CONFIG_TRACE_IRQFLAGS + rsr abi_tmp0, ps + extui abi_tmp0, abi_tmp0, PS_INTLEVEL_SHIFT, PS_INTLEVEL_WIDTH + beqz abi_tmp0, 1f + abi_call trace_hardirqs_off +1: +#endif + /* Go to second-level dispatcher. Set up parameters to pass to the * exception handler and call the exception handler. */ - rsr a4, excsave1 - addx4 a4, a2, a4 - l32i a4, a4, EXC_TABLE_DEFAULT # load handler - mov abi_arg1, a2 # pass EXCCAUSE + l32i abi_arg1, a1, PT_EXCCAUSE # pass EXCCAUSE + rsr abi_tmp0, excsave1 + addx4 abi_tmp0, abi_arg1, abi_tmp0 + l32i abi_tmp0, abi_tmp0, EXC_TABLE_DEFAULT # load handler mov abi_arg0, a1 # pass stack frame /* Call the second-level handler */ - abi_callx a4 + abi_callx abi_tmp0 /* Jump here for exception exit */ .global common_exception_return
arch/xtensa/kernel/traps.c +2 -9
@@ -242,12 +242,8 @@ DEFINE_PER_CPU(unsigned long, nmi_count);void do_nmi (struct pt_regs *regs) { -struct pt_regs *old_regs; +struct pt_regs *old_regs =set_irq_regs (regs); -if ((regs->ps &PS_INTLEVEL_MASK ) <LOCKLEVEL ) -trace_hardirqs_off (); - - old_regs =set_irq_regs (regs);nmi_enter (); ++*this_cpu_ptr (&nmi_count);check_valid_nmi ();
@@ -269,12 +265,9 @@ void do_interrupt(struct pt_regs *regs)XCHAL_INTLEVEL6_MASK , XCHAL_INTLEVEL7_MASK, }; -struct pt_regs *old_regs; +struct pt_regs *old_regs =set_irq_regs (regs);unsigned unhandled = ~0u ; -trace_hardirqs_off (); - - old_regs =set_irq_regs (regs);irq_enter ();for (;;) {
Signature · 1 line
2.30.2
Max Filippov
maintainerPATCH 3/5 xtensa: use abi_* register names in the kernel exit code
In reply to Max FilippovUsing plain register names is prone to errors when code is changed and new calls are added between the register load and use. Change plain register names to abi_* names in the call-heavy part of the kernel exit code to clearly indicate what's supposed to be preserved and what's not. Re-align code while at it.
--- arch/xtensa/kernel/entry.S | 82 +++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 40 deletions(-)
arch/xtensa/kernel/entry.S +42 -40
@@ -462,11 +462,11 @@ KABI_W or a3, a3, a2 * exception handler and call the exception handler. */ - l32i abi_arg1, a1, PT_EXCCAUSE # pass EXCCAUSE - rsr abi_tmp0, excsave1 - addx4 abi_tmp0, abi_arg1, abi_tmp0 - l32i abi_tmp0, abi_tmp0, EXC_TABLE_DEFAULT # load handler - mov abi_arg0, a1 # pass stack frame + l32i abi_arg1, a1, PT_EXCCAUSE # pass EXCCAUSE + rsr abi_tmp0, excsave1 + addx4 abi_tmp0, abi_arg1, abi_tmp0 + l32i abi_tmp0, abi_tmp0, EXC_TABLE_DEFAULT # load handler + mov abi_arg0, a1 # pass stack frame /* Call the second-level handler */
@@ -477,23 +477,23 @@ KABI_W or a3, a3, a2 common_exception_return: #if XTENSA_FAKE_NMI - l32i abi_tmp0, a1, PT_EXCCAUSE - movi abi_tmp1, EXCCAUSE_MAPPED_NMI - l32i abi_saved1, a1, PT_PS - beq abi_tmp0, abi_tmp1, .Lrestore_state + l32i abi_tmp0, a1, PT_EXCCAUSE + movi abi_tmp1, EXCCAUSE_MAPPED_NMI + l32i abi_saved1, a1, PT_PS + beq abi_tmp0, abi_tmp1, .Lrestore_state #endif .Ltif_loop: - irq_save a2, a3 + irq_save abi_tmp0, abi_tmp1 #ifdef CONFIG_TRACE_IRQFLAGS abi_call trace_hardirqs_off #endif /* Jump if we are returning from kernel exceptions. */ - l32i abi_saved1, a1, PT_PS - GET_THREAD_INFO(a2, a1) - l32i a4, a2, TI_FLAGS - _bbci.l abi_saved1, PS_UM_BIT, .Lexit_tif_loop_kernel + l32i abi_saved1, a1, PT_PS + GET_THREAD_INFO(abi_tmp0, a1) + l32i abi_saved0, abi_tmp0, TI_FLAGS + _bbci.l abi_saved1, PS_UM_BIT, .Lexit_tif_loop_kernel /* Specific to a user exception exit: * We need to check some flags for signal handling and rescheduling,
@@ -502,75 +502,77 @@ common_exception_return: * Note that we don't disable interrupts here. */ - _bbsi.l a4, TIF_NEED_RESCHED, .Lresched - movi a2, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NOTIFY_SIGNAL - bnone a4, a2, .Lexit_tif_loop_user + _bbsi.l abi_saved0, TIF_NEED_RESCHED, .Lresched + movi abi_tmp0, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NOTIFY_SIGNAL + bnone abi_saved0, abi_tmp0, .Lexit_tif_loop_user - l32i a4, a1, PT_DEPC - bgeui a4, VALID_DOUBLE_EXCEPTION_ADDRESS, .Lrestore_state + l32i abi_tmp0, a1, PT_DEPC + bgeui abi_tmp0, VALID_DOUBLE_EXCEPTION_ADDRESS, .Lrestore_state /* Call do_signal() */ #ifdef CONFIG_TRACE_IRQFLAGS abi_call trace_hardirqs_on #endif - rsil a2, 0 - mov abi_arg0, a1 + rsil abi_tmp0, 0 + mov abi_arg0, a1 abi_call do_notify_resume # int do_notify_resume(struct pt_regs*) - j .Ltif_loop + j .Ltif_loop .Lresched: #ifdef CONFIG_TRACE_IRQFLAGS abi_call trace_hardirqs_on #endif - rsil a2, 0 + rsil abi_tmp0, 0 abi_call schedule # void schedule (void) - j .Ltif_loop + j .Ltif_loop .Lexit_tif_loop_kernel: #ifdef CONFIG_PREEMPTION - _bbci.l a4, TIF_NEED_RESCHED, .Lrestore_state + _bbci.l abi_saved0, TIF_NEED_RESCHED, .Lrestore_state /* Check current_thread_info->preempt_count */ - l32i a4, a2, TI_PRE_COUNT - bnez a4, .Lrestore_state + l32i abi_tmp1, abi_tmp0, TI_PRE_COUNT + bnez abi_tmp1, .Lrestore_state abi_call preempt_schedule_irq #endif - j .Lrestore_state + j .Lrestore_state .Lexit_tif_loop_user: #ifdef CONFIG_HAVE_HW_BREAKPOINT - _bbci.l a4, TIF_DB_DISABLED, 1f + _bbci.l abi_saved0, TIF_DB_DISABLED, 1f abi_call restore_dbreak 1: #endif #ifdef CONFIG_DEBUG_TLB_SANITY - l32i a4, a1, PT_DEPC - bgeui a4, VALID_DOUBLE_EXCEPTION_ADDRESS, .Lrestore_state + l32i abi_tmp0, a1, PT_DEPC + bgeui abi_tmp0, VALID_DOUBLE_EXCEPTION_ADDRESS, .Lrestore_state abi_call check_tlb_sanity #endif .Lrestore_state: #ifdef CONFIG_TRACE_IRQFLAGS - extui a4, abi_saved1, PS_INTLEVEL_SHIFT, PS_INTLEVEL_WIDTH - bgei a4, LOCKLEVEL, 1f + extui abi_tmp0, abi_saved1, PS_INTLEVEL_SHIFT, PS_INTLEVEL_WIDTH + bgei abi_tmp0, LOCKLEVEL, 1f abi_call trace_hardirqs_on 1: #endif - /* Restore optional registers. */ + /* + * Restore optional registers. + * abi_arg* are used as temporary registers here. + */ - load_xtregs_opt a1 a2 a4 a5 a6 a7 PT_XTREGS_OPT + load_xtregs_opt a1 abi_tmp0 abi_arg0 abi_arg1 abi_arg2 abi_arg3 PT_XTREGS_OPT /* Restore SCOMPARE1 */ #if XCHAL_HAVE_S32C1I - l32i a2, a1, PT_SCOMPARE1 - wsr a2, scompare1 + l32i abi_tmp0, a1, PT_SCOMPARE1 + wsr abi_tmp0, scompare1 #endif - wsr abi_saved1, ps /* disable interrupts */ - - _bbci.l abi_saved1, PS_UM_BIT, kernel_exception_exit + wsr abi_saved1, ps /* disable interrupts */ + _bbci.l abi_saved1, PS_UM_BIT, kernel_exception_exit user_exception_exit:
Signature · 1 line
2.30.2
Max Filippov
maintainerPATCH 4/5 xtensa: enable context tracking
In reply to Max FilippovPut user exit context tracking call on the common kernel entry/exit path (function calls are impossible at earlier kernel entry stages because PS.EXCM is not cleared yet). Put user entry context tracking call on the user exit path. Syscalls go through this common code too, so nothing specific needs to be done for them.
--- .../features/time/context-tracking/arch-support.txt | 2 +- arch/xtensa/Kconfig | 1 + arch/xtensa/kernel/entry.S | 9 +++++++++ 3 files changed, 11 insertions(+), 1 deletion(-)
Documentation/features/time/context-tracking/arch-support.txt +1 -1
@@ -27,5 +27,5 @@ | sparc: | ok | | um: | TODO | | x86: | ok | - | xtensa: | TODO | + | xtensa: | ok | -----------------------
arch/xtensa/Kconfig +1 -0
@@ -31,6 +31,7 @@ config XTENSA select HAVE_ARCH_KASAN if MMU && !XIP_KERNEL select HAVE_ARCH_SECCOMP_FILTER select HAVE_ARCH_TRACEHOOK + select HAVE_CONTEXT_TRACKING select HAVE_DEBUG_KMEMLEAK select HAVE_DMA_CONTIGUOUS select HAVE_EXIT_THREAD
arch/xtensa/kernel/entry.S +9 -0
@@ -456,6 +456,12 @@ KABI_W or a3, a3, a2 beqz abi_tmp0, 1f abi_call trace_hardirqs_off 1: +#endif +#ifdef CONFIG_CONTEXT_TRACKING + l32i abi_tmp0, a1, PT_PS + bbci.l abi_tmp0, PS_UM_BIT, 1f + abi_call context_tracking_user_exit +1: #endif /* Go to second-level dispatcher. Set up parameters to pass to the
@@ -540,6 +546,9 @@ common_exception_return: j .Lrestore_state .Lexit_tif_loop_user: +#ifdef CONFIG_CONTEXT_TRACKING + abi_call context_tracking_user_enter +#endif #ifdef CONFIG_HAVE_HW_BREAKPOINT _bbci.l abi_saved0, TIF_DB_DISABLED, 1f abi_call restore_dbreak
Signature · 1 line
2.30.2
Max Filippov
maintainerPATCH 5/5 xtensa: enable HAVE_VIRT_CPU_ACCOUNTING_GEN
In reply to Max FilippovThere's no direct cputime_t manipulation in the xtensa arch code, so generic virt CPU accounting may be enabled.
--- Documentation/features/time/virt-cpuacct/arch-support.txt | 2 +- arch/xtensa/Kconfig | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
Documentation/features/time/virt-cpuacct/arch-support.txt +1 -1
@@ -27,5 +27,5 @@ | sparc: | ok | | um: | TODO | | x86: | ok | - | xtensa: | TODO | + | xtensa: | ok | -----------------------
arch/xtensa/Kconfig +1 -0
@@ -43,6 +43,7 @@ config XTENSA select HAVE_PERF_EVENTS select HAVE_STACKPROTECTOR select HAVE_SYSCALL_TRACEPOINTS + select HAVE_VIRT_CPU_ACCOUNTING_GEN select IRQ_DOMAIN select MODULES_USE_ELF_RELA select PERF_USE_VMALLOC
Signature · 1 line
2.30.2