4.14.71/arm64 port (split series)
Subsystems (6)
cover 4.14.71/arm64 port (split series)
This is a port of the interrupt pipeline to kernel 4.14.71 for arm64, based on the split series published earlier this year [1].
The architecture-specific bits have been reworked to become a series of incremental changes on top of the -noarch tree [2], enabling a feature one at a time, which should ease future kernel upgrades.
As a by-product, the I-pipe/arm64 port now copes with lockdep.
This port is known to run on the following SoCs, using the current tip of Xenomai's -next branch:
- Zynq UltraScale+ (zcu102 evb)
- BCM2837 (Raspberry 3B)
- Kirin 620 (HiKey LeMaker)
NOTE: the change to the dts for the bcm2837 chip does not belong to the I-pipe port strictly speaking. It routes the serial output to the pl011 UART for rpi3, which may be useful for developers needing a serial console who can't cope with using the mini-uart.
[1] https://www.xenomai.org/pipermail/xenomai/2018-July/039302.html
[2] https://git.xenomai.org/ipipe-noarch
Dmitriy Cherkasov (1):
arm64: fpsimd: ipipe: enable sharing with head domain
Philippe Gerum (10):
arm64: ipipe: add pipeline core
arm64: context_tracking: disable if CONFIG_IPIPE
arm64: ipipe: share context switch code with the head domain
arm64: ipipe: route traps to co-kernel
arm64: ipipe: route syscalls to co-kernel
arm64: ipipe: turn hard irqs on when leaving the idle state
arm64: dts: bcm2837: provide for BT-less variant, re-enabling uart0 as
serial
arm64: ipipe: route debug exceptions to co-kernel
arm64: ipipe: route all access traps to co-kernel
arm64: ipipe: preserve the hard interrupt state across mayday trap
arch/arm64/Kconfig | 5 +- arch/arm64/boot/dts/broadcom/Makefile | 2 +- .../boot/dts/broadcom/bcm2837-rpi-3-b-nobt.dts | 12 + arch/arm64/include/asm/assembler.h | 12 + arch/arm64/include/asm/ipipe.h | 205 +++++++++++++++++ arch/arm64/include/asm/ipipe_base.h | 96 ++++++++ arch/arm64/include/asm/ipipe_hwirq.h | 191 ++++++++++++++++ arch/arm64/include/asm/irqflags.h | 18 +- arch/arm64/include/asm/mmu_context.h | 27 ++- arch/arm64/include/asm/percpu.h | 1 + arch/arm64/include/asm/thread_info.h | 14 ++ arch/arm64/include/asm/uaccess.h | 5 +- arch/arm64/include/asm/unistd.h | 2 + arch/arm64/kernel/Makefile | 1 + arch/arm64/kernel/asm-offsets.c | 3 + arch/arm64/kernel/entry.S | 113 ++++++++- arch/arm64/kernel/fpsimd.c | 138 +++++++++-- arch/arm64/kernel/ipipe.c | 254 +++++++++++++++++++++ arch/arm64/kernel/irq.c | 10 + arch/arm64/kernel/process.c | 2 +- arch/arm64/kernel/ptrace.c | 6 +- arch/arm64/kernel/signal.c | 13 +- arch/arm64/kernel/smp.c | 150 ++++++++++-- arch/arm64/kernel/traps.c | 9 +- arch/arm64/mm/context.c | 2 +- arch/arm64/mm/fault.c | 127 ++++++++++- 26 files changed, 1354 insertions(+), 64 deletions(-) create mode 100644 arch/arm64/boot/dts/broadcom/bcm2837-rpi-3-b-nobt.dts create mode 100644 arch/arm64/include/asm/ipipe.h create mode 100644 arch/arm64/include/asm/ipipe_base.h create mode 100644 arch/arm64/include/asm/ipipe_hwirq.h create mode 100644 arch/arm64/kernel/ipipe.c
Signature · 1 line
2.14.4
PATCH 1/11 arm64: ipipe: add pipeline core
Introduce the arm64-specific bits enabling the interrupt pipeline exclusively.
--- arch/arm64/Kconfig | 3 + arch/arm64/include/asm/assembler.h | 12 ++ arch/arm64/include/asm/ipipe.h | 205 +++++++++++++++++++++++++++++ arch/arm64/include/asm/ipipe_base.h | 86 ++++++++++++ arch/arm64/include/asm/ipipe_hwirq.h | 191 +++++++++++++++++++++++++++ arch/arm64/include/asm/irqflags.h | 18 ++- arch/arm64/include/asm/percpu.h | 1 + arch/arm64/include/asm/thread_info.h | 14 ++ arch/arm64/include/asm/uaccess.h | 5 +- arch/arm64/kernel/Makefile | 1 + arch/arm64/kernel/asm-offsets.c | 3 + arch/arm64/kernel/entry.S | 38 +++++- arch/arm64/kernel/ipipe.c | 246 +++++++++++++++++++++++++++++++++++ arch/arm64/kernel/irq.c | 10 ++ arch/arm64/kernel/process.c | 32 +++++ arch/arm64/kernel/signal.c | 13 +- arch/arm64/kernel/smp.c | 150 ++++++++++++++++++--- arch/arm64/mm/context.c | 2 +- 18 files changed, 998 insertions(+), 32 deletions(-) create mode 100644 arch/arm64/include/asm/ipipe.h create mode 100644 arch/arm64/include/asm/ipipe_base.h create mode 100644 arch/arm64/include/asm/ipipe_hwirq.h create mode 100644 arch/arm64/kernel/ipipe.c
arch/arm64/Kconfig +3 -0
@@ -108,6 +108,8 @@ config ARM64 select HAVE_SYSCALL_TRACEPOINTS select HAVE_KPROBES select HAVE_KRETPROBES + select HAVE_IPIPE_SUPPORT + select HAVE_IPIPE_TRACER_SUPPORT select IOMMU_DMA if IOMMU_SUPPORT select IRQ_DOMAIN select IRQ_FORCED_THREADING
@@ -694,6 +696,7 @@ config NEED_PER_CPU_EMBED_FIRST_CHUNK config HOLES_IN_ZONE def_bool y +source kernel/ipipe/Kconfig source kernel/Kconfig.preempt source kernel/Kconfig.hz
arch/arm64/include/asm/assembler.h +12 -0
@@ -51,6 +51,18 @@ msr daif, \flags .endm + .macro disable_irq_cond +#ifdef CONFIG_IPIPE + msr daifset, #2 +#endif + .endm + + .macro enable_irq_cond +#ifdef CONFIG_IPIPE + msr daifclr, #2 +#endif + .endm +/* * Enable and disable debug exceptions. */
arch/arm64/include/asm/ipipe.h new file +205 -0
205 lines not on this page · raw message
arch/arm64/include/asm/ipipe_base.h new file +86 -0
86 lines not on this page · raw message
arch/arm64/include/asm/ipipe_hwirq.h new file +191 -0
191 lines not on this page · raw message
arch/arm64/include/asm/irqflags.h +12 -6
@@ -20,6 +20,10 @@#include <asm/ptrace.h> +#include <asm/ipipe_hwirq.h> + +#ifndef CONFIG_IPIPE +/* * CPU interrupt mask handling. */
@@ -53,12 +57,6 @@ static inline void arch_local_irq_disable(void) : "memory"); } -#define local_fiq_enable () asm("msr daifclr, #1" : : : "memory") -#define local_fiq_disable () asm("msr daifset, #1" : : : "memory") - -#define local_async_enable () asm("msr daifclr, #4" : : : "memory") -#define local_async_disable () asm("msr daifset, #4" : : : "memory") -/* * Save the current interrupt enable state. */
@@ -90,6 +88,14 @@ static inline int arch_irqs_disabled_flags(unsigned long flags) return flags & PSR_I_BIT; } +#endif /* !IPIPE */ + +#define local_fiq_enable () asm("msr daifclr, #1" : : : "memory") +#define local_fiq_disable () asm("msr daifset, #1" : : : "memory") + +#define local_async_enable () asm("msr daifclr, #4" : : : "memory") +#define local_async_disable () asm("msr daifset, #4" : : : "memory") +/* * save and restore debug state */
arch/arm64/include/asm/percpu.h +1 -0
@@ -18,6 +18,7 @@#include <asm/alternative.h> #include <asm/stack_pointer.h> +#include <asm/ipipe_base.h> static inline void set_my_cpu_offset (unsigned long off) {
arch/arm64/include/asm/thread_info.h +14 -0
@@ -30,6 +30,7 @@ struct task_struct;#include <asm/memory.h> #include <asm/stack_pointer.h> #include <asm/types.h> +#include <ipipe/thread_info.h> typedef unsigned long mm_segment_t ;
@@ -43,6 +44,10 @@ struct thread_info {u64 ttbr0;/* saved TTBR0_EL1 */ #endif int preempt_count;/* 0 => preemptable, <0 => bug */ +#ifdef CONFIG_IPIPE +unsigned long ipipe_flags; +#endif +struct ipipe_threadinfo ipipe_data; };#define INIT_THREAD_INFO (tsk) \
@@ -115,5 +120,14 @@ void arch_setup_new_exec(void); _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \ _TIF_NOHZ) +/* ti->ipipe_flags */ +#define TIP_MAYDAY 0/* MAYDAY call is pending */ +#define TIP_NOTIFY 1/* Notify head domain about kernel events */ +#define TIP_HEAD 2/* Runs in head domain */ + +#define _TIP_MAYDAY (1 << TIP_MAYDAY) +#define _TIP_NOTIFY (1 << TIP_NOTIFY) +#define _TIP_HEAD (1 << TIP_HEAD) +#endif /* __KERNEL__ */ #endif /* __ASM_THREAD_INFO_H */
arch/arm64/include/asm/uaccess.h +3 -2
@@ -29,6 +29,7 @@#include <linux/kasan-checks.h> #include <linux/string.h> +#include <asm-generic/ipipe.h> #include <asm/cpufeature.h> #include <asm/ptrace.h> #include <asm/memory.h>
@@ -297,7 +298,7 @@ do { \#define __get_user_check (x, ptr, err) \ ({ \ __typeof__(*(ptr)) __user *__p = (ptr); \ - might_fault(); \ + __ipipe_uaccess_might_fault(); \ if (access_ok(VERIFY_READ, __p, sizeof(*__p))) { \ __p = uaccess_mask_ptr(__p); \ __get_user_err((x), __p, (err)); \
@@ -366,7 +367,7 @@ do { \#define __put_user_check (x, ptr, err) \ ({ \ __typeof__(*(ptr)) __user *__p = (ptr); \ - might_fault(); \ + __ipipe_uaccess_might_fault(); \ if (access_ok(VERIFY_WRITE, __p, sizeof(*__p))) { \ __p = uaccess_mask_ptr(__p); \ __put_user_err((x), __p, (err)); \
arch/arm64/kernel/Makefile +1 -0
@@ -62,6 +62,7 @@ endif obj-y += $(arm64-obj-y) vdso/ probes/ obj-m += $(arm64-obj-m) +obj-$(CONFIG_IPIPE) += ipipe.o head-y := head.o extra-y += $(head-y) vmlinux.lds
arch/arm64/kernel/asm-offsets.c +3 -0
@@ -38,6 +38,9 @@ int main(void)DEFINE (TSK_ACTIVE_MM , offsetof(struct task_struct , active_mm));BLANK (); DEFINE(TSK_TI_FLAGS, offsetof(struct task_struct, thread_info.flags)); +#ifdef CONFIG_IPIPE + DEFINE(TSK_TI_IPIPE, offsetof(struct task_struct, thread_info.ipipe_flags)); +#endif DEFINE(TSK_TI_PREEMPT, offsetof(struct task_struct, thread_info.preempt_count)); DEFINE(TSK_TI_ADDR_LIMIT, offsetof(struct task_struct, thread_info.addr_limit));#ifdef CONFIG_ARM64_SW_TTBR0_PAN
arch/arm64/kernel/entry.S +32 -6
@@ -416,7 +416,11 @@ tsk .req x28 // current thread_info * Interrupt handling. */ .macro irq_handler +#ifdef CONFIG_IPIPE + ldr x1, =handle_arch_irq_pipelined +#else ldr_l x1, handle_arch_irq +#endif mov x0, sp irq_stack_entry blr x1
@@ -629,12 +633,15 @@ ENDPROC(el1_sync) el1_irq: kernel_entry 1 enable_dbg -#ifdef CONFIG_TRACE_IRQFLAGS - bl trace_hardirqs_off -#endif irq_handler +#ifdef CONFIG_IPIPE + cbz w0, 2f +#endif +#ifdef CONFIG_TRACE_IRQFLAGS + bl trace_hardirqs_off +#endif #ifdef CONFIG_PREEMPT ldr w24, [tsk, #TSK_TI_PREEMPT] // get preempt count cbnz w24, 1f // preempt count != 0
@@ -644,15 +651,20 @@ el1_irq: 1: #endif #ifdef CONFIG_TRACE_IRQFLAGS - bl trace_hardirqs_on + bl trace_hardirqs_on_virt #endif +2: kernel_exit 1 ENDPROC(el1_irq) #ifdef CONFIG_PREEMPT el1_preempt: mov x24, lr +#ifdef CONFIG_IPIPE +1: bl __ipipe_preempt_schedule_irq +#else 1: bl preempt_schedule_irq // irq en/disable is done inside +#endif ldr x0, [tsk, #TSK_TI_FLAGS] // get new tasks TI_FLAGS tbnz x0, #TIF_NEED_RESCHED, 1b // needs rescheduling? ret x24
@@ -858,10 +870,13 @@ el0_irq_naked: #endif irq_handler +#ifdef CONFIG_IPIPE + cbz w0, work_done +#endif /* CONFIG_IPIPE */ #ifdef CONFIG_TRACE_IRQFLAGS - bl trace_hardirqs_on + bl trace_hardirqs_on_virt #endif - b ret_to_user + b ret_to_user_nocheck ENDPROC(el0_irq) /*
@@ -891,13 +906,23 @@ work_pending: #ifdef CONFIG_TRACE_IRQFLAGS bl trace_hardirqs_on // enabled while in userspace #endif +work_done: ldr x1, [tsk, #TSK_TI_FLAGS] // re-check for single-step b finish_ret_to_user /* * "slow" syscall return path. */ ret_to_user: +#ifdef CONFIG_IPIPE + disable_irq + ldr x0, [tsk, #TSK_TI_IPIPE] + tst x0, #_TIP_HEAD + b.eq ret_to_user_noirq + kernel_exit 0 +#endif +ret_to_user_nocheck: disable_irq // disable interrupts +ret_to_user_noirq: ldr x1, [tsk, #TSK_TI_FLAGS] and x2, x1, #_TIF_WORK_MASK cbnz x2, work_pending
@@ -1128,6 +1153,7 @@ NOKPROBE(cpu_switch_to) * This is how we return from a fork. */ ENTRY(ret_from_fork) + enable_irq_cond bl schedule_tail cbz x19, 1f // not a kernel thread mov x0, x20
arch/arm64/kernel/ipipe.c new file +246 -0
246 lines not on this page · raw message
arch/arm64/kernel/irq.c +10 -0
@@ -43,6 +43,16 @@ int arch_show_interrupts(struct seq_file *p, int prec)void (*handle_arch_irq)(struct pt_regs *) =NULL ; +#ifdef CONFIG_IPIPE + +asmlinkage int handle_arch_irq_pipelined(struct pt_regs *regs) +{ +handle_arch_irq (regs); +return __ipipe_root_p && !irqs_disabled (); +} + +#endif +void __init set_handle_irq (void (*handle_irq)(struct pt_regs *)) {if (handle_arch_irq)
arch/arm64/kernel/process.c +32 -0
@@ -73,6 +73,36 @@ EXPORT_SYMBOL_GPL(pm_power_off);void (*arm_pm_restart)(enum reboot_mode reboot_mode,const char *cmd); +#ifdef CONFIG_IPIPE +static void __ipipe_halt_root (void ) +{ +struct ipipe_percpu_domain_data *p; + +/* +* Emulate idle entry sequence over the root domain, which is +* stalled on entry. +*/ +hard_local_irq_disable (); + + p =ipipe_this_cpu_root_context (); +__clear_bit (IPIPE_STALL_FLAG , &p->status); + +if (unlikely (__ipipe_ipending_p (p))) +__ipipe_sync_stage (); +else { +cpu_do_idle (); + } +} + +#else /* !CONFIG_IPIPE */ + +static void __ipipe_halt_root (void ) +{ +cpu_do_idle (); +} + +#endif /* !CONFIG_IPIPE */ +/* * This is our default idle handler. */
@@ -83,6 +113,8 @@ void arch_cpu_idle(void)* tricks */ trace_cpu_idle_rcuidle (1 ,smp_processor_id ()); +if (!need_resched ()) +__ipipe_halt_root ();cpu_do_idle ();local_irq_enable ();trace_cpu_idle_rcuidle (PWR_EVENT_EXIT ,smp_processor_id ());
arch/arm64/kernel/signal.c +11 -2
@@ -745,6 +745,8 @@ static void do_signal(struct pt_regs *regs) asmlinkage void do_notify_resume(struct pt_regs *regs,unsigned int thread_flags) { +bool stalled =irqs_disabled (); +/* * The assembly code enters us with IRQs off, but it hasn't * informed the tracing code of that for efficiency reasons.
@@ -757,9 +759,13 @@ asmlinkage void do_notify_resume(struct pt_regs *regs,addr_limit_user_check ();if (thread_flags & _TIF_NEED_RESCHED) { +if (IS_ENABLED (CONFIG_IPIPE )) { +local_irq_disable (); +hard_local_irq_enable (); + }schedule (); }else { -local_irq_enable (); +local_irq_enable ();/* also hard enables IRQs */ if (thread_flags & _TIF_UPROBE)uprobe_notify_resume (regs);
@@ -776,7 +782,10 @@ asmlinkage void do_notify_resume(struct pt_regs *regs,fpsimd_restore_current_state (); } -local_irq_disable (); +hard_local_irq_disable (); thread_flags =READ_ONCE (current_thread_info ()->flags); }while (thread_flags & _TIF_WORK_MASK); + +if (IS_ENABLED (CONFIG_IPIPE ) && stalled) +local_irq_disable (); }
arch/arm64/kernel/smp.c +135 -15
198 lines not on this page · raw message
arch/arm64/mm/context.c +1 -1
@@ -28,7 +28,7 @@#include <asm/tlbflush.h> static u32 asid_bits; -static DEFINE_RAW_SPINLOCK (cpu_asid_lock); +static IPIPE_DEFINE_RAW_SPINLOCK (cpu_asid_lock);static atomic64_t asid_generation;static unsigned long *asid_map;
Signature · 1 line
2.14.4
PATCH 2/11 arm64: context_tracking: disable if CONFIG_IPIPE
In reply to Philippe GerumContext tracking does not cope well with interrupt pipelining
currently: disable the former for now.
--- arch/arm64/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/Kconfig +1 -1
@@ -82,7 +82,7 @@ config ARM64 select HAVE_CC_STACKPROTECTOR select HAVE_CMPXCHG_DOUBLE select HAVE_CMPXCHG_LOCAL - select HAVE_CONTEXT_TRACKING + select HAVE_CONTEXT_TRACKING if !IPIPE select HAVE_DEBUG_BUGVERBOSE select HAVE_DEBUG_KMEMLEAK select HAVE_DMA_API_DEBUG
Signature · 1 line
2.14.4
PATCH 3/11 arm64: ipipe: share context switch code with the head domain
In reply to Philippe GerumThis change enable a co-kernel to change the address space of a task using the common mm helpers. This is mainly a matter of strictly serializing context switching code among all callers regardless of their domain (head/root), by disabling hard irqs.
--- arch/arm64/include/asm/mmu_context.h | 27 ++++++++++++++++++++++++++- arch/arm64/kernel/entry.S | 24 +++++++++++++++++++++++- arch/arm64/kernel/ipipe.c | 7 +++++++ 3 files changed, 56 insertions(+), 2 deletions(-)
arch/arm64/include/asm/mmu_context.h +26 -1
@@ -30,6 +30,7 @@#include <asm/cpufeature.h> #include <asm/proc-fns.h> #include <asm-generic/mm_hooks.h> +#include <asm-generic/ipipe.h> #include <asm/cputype.h> #include <asm/pgtable.h> #include <asm/sysreg.h>
@@ -57,9 +58,13 @@ static inline void cpu_set_reserved_ttbr0(void)static inline void cpu_switch_mm (pgd_t *pgd,struct mm_struct *mm) { +unsigned long flags; +BUG_ON (pgd == swapper_pg_dir); + flags =hard_cond_local_irq_save ();cpu_set_reserved_ttbr0 ();cpu_do_switch_mm (virt_to_phys (pgd),mm); +hard_cond_local_irq_restore (flags); }/*
@@ -211,7 +216,7 @@ static inline void __switch_mm(struct mm_struct *next) }static inline void -switch_mm (struct mm_struct *prev,struct mm_struct *next, +do_switch_mm (struct mm_struct *prev,struct mm_struct *next,struct task_struct *tsk) {if (prev != next)
@@ -226,9 +231,29 @@ switch_mm(struct mm_struct *prev, struct mm_struct *next,update_saved_ttbr0 (tsk, next); } +static inline void +switch_mm (struct mm_struct *prev,struct mm_struct *next, +struct task_struct *tsk) +{ +unsigned long flags; + + flags =hard_cond_local_irq_save (); +do_switch_mm (prev, next, tsk); +hard_cond_local_irq_restore (flags); +} +#define deactivate_mm (tsk,mm) do { } while (0)#define activate_mm (prev,next) switch_mm(prev, next, current) +#ifdef CONFIG_IPIPE +static inline void +ipipe_switch_mm_head (struct mm_struct *prev,struct mm_struct *next, +struct task_struct *tsk) +{ +do_switch_mm (prev, next, tsk); +} +#endif +void verify_cpu_asid_bits (void );void post_ttbr_update_workaround (void );
arch/arm64/kernel/entry.S +23 -1
@@ -372,6 +372,21 @@ alternative_insn eret, nop, ARM64_UNMAP_KERNEL_AT_EL0 .macro irq_stack_entry mov x19, sp // preserve the original sp +#ifdef CONFIG_IPIPE + /* + * When the pipeline is enabled, context switches over the irq + * stack are allowed (for the co-kernel), and more interrupts + * can be taken over sibling stack contexts. So we need a not so + * subtle way of figuring out whether the irq stack was actually + * exited, which cannot depend on the current task pointer. + */ + adr_this_cpu x25, irq_nesting, x26 + ldr w26, [x25] + cmp w26, #0 + add w26, w26, #1 + str w26, [x25] + b.ne 9998f +#else /* * Compare sp with the base of the task stack. * If the top ~(THREAD_SIZE - 1) bits match, we are on a task stack,
@@ -381,6 +396,7 @@ alternative_insn eret, nop, ARM64_UNMAP_KERNEL_AT_EL0 eor x25, x25, x19 and x25, x25, #~(THREAD_SIZE - 1) cbnz x25, 9998f +#endif ldr_this_cpu x25, irq_stack_ptr, x26 mov x26, #IRQ_STACK_SIZE
@@ -393,10 +409,16 @@ alternative_insn eret, nop, ARM64_UNMAP_KERNEL_AT_EL0 /* * x19 should be preserved between irq_stack_entry and - * irq_stack_exit. + * irq_stack_exit. I-pipe: have to preserve w0 too. */ .macro irq_stack_exit mov sp, x19 +#ifdef CONFIG_IPIPE + adr_this_cpu x1, irq_nesting, x2 + ldr w2, [x1] + add w2, w2, #-1 + str w2, [x1] +#endif .endm /*
arch/arm64/kernel/ipipe.c +7 -0
@@ -53,6 +53,9 @@static void __ipipe_do_IRQ (unsigned irq,void *cookie); +/* irq_nesting tracks the interrupt nesting level for a CPU. */ +DEFINE_PER_CPU (int, irq_nesting); +#ifdef CONFIG_IPIPE_DEBUG_INTERNAL void (*__ipipe_mach_hrtimer_debug)(unsigned irq);#endif
@@ -237,6 +240,10 @@ void __ipipe_mach_get_tscinfo(struct __ipipe_tscinfo *info)EXPORT_SYMBOL_GPL (do_munmap);EXPORT_SYMBOL_GPL (show_stack); +EXPORT_SYMBOL_GPL (init_mm); +#ifndef MULTI_CPU +EXPORT_SYMBOL_GPL (cpu_do_switch_mm); +#endif #if defined(CONFIG_SMP ) || defined(CONFIG_DEBUG_SPINLOCK )EXPORT_SYMBOL_GPL (tasklist_lock);#endif /* CONFIG_SMP || CONFIG_DEBUG_SPINLOCK */
Signature · 1 line
2.14.4
PATCH 4/11 arm64: ipipe: route traps to co-kernel
In reply to Philippe GerumThis commit introduces the changes redirecting traps and exceptions to the interrupt pipeline, so that the co-kernel can be made aware early on. The co-kernel may then decide whether the fault should be propagated to the regular kernel for actual handling.
This is typically useful for allowing the co-kernel to downgrade the current context from the head domain to the root domain, when leaving the burden of handling major faults to the regular kernel makes more sense than expecting the co-kernel to reinvent such a wheel (e.g. memory violations, illegal instructions, divide by zero etc). As a matter of fact, optimizing latency upon such events would not make much sense anyway.
--- arch/arm64/include/asm/ipipe_base.h | 10 +++ arch/arm64/kernel/ptrace.c | 6 +- arch/arm64/kernel/traps.c | 9 ++- arch/arm64/mm/fault.c | 118 +++++++++++++++++++++++++++++++++--- 4 files changed, 131 insertions(+), 12 deletions(-)
arch/arm64/include/asm/ipipe_base.h +10 -0
@@ -80,6 +80,16 @@ unsigned __ipipe_processor_id(void);/* ARM64 traps */ #define IPIPE_TRAP_MAYDAY 0/* Internal recovery trap */ +#define IPIPE_TRAP_ACCESS 1/* Data or instruction access exception */ +#define IPIPE_TRAP_SECTION 2/* Section fault */ +#define IPIPE_TRAP_DABT 3/* Generic data abort */ +#define IPIPE_TRAP_UNKNOWN 4/* Unknown exception */ +#define IPIPE_TRAP_BREAK 5/* Instruction breakpoint */ +#define IPIPE_TRAP_FPU_ACC 6/* Floating point access */ +#define IPIPE_TRAP_FPU_EXC 7/* Floating point exception */ +#define IPIPE_TRAP_UNDEFINSTR 8/* Undefined instruction */ +#define IPIPE_TRAP_ALIGNMENT 9/* Unaligned access exception */ +#define IPIPE_NR_FAULTS 10#endif /* CONFIG_IPIPE */
arch/arm64/kernel/ptrace.c +4 -2
@@ -185,10 +185,12 @@ static void ptrace_hbptriggered(struct perf_event *bp, .si_code = TRAP_HWBKPT, .si_addr = (void __user *)(bkpt->trigger), }; +int i__maybe_unused ; -#ifdef CONFIG_COMPAT -int i; +if (__ipipe_report_trap (IPIPE_TRAP_BREAK , regs)) +return ; +#ifdef CONFIG_COMPAT if (!is_compat_task ()) goto send_sig;
arch/arm64/kernel/traps.c +8 -1
@@ -294,7 +294,7 @@ void arm64_notify_die(const char *str, struct pt_regs *regs, }static LIST_HEAD (undef_hook); -static DEFINE_RAW_SPINLOCK (undef_lock); +static IPIPE_DEFINE_RAW_SPINLOCK (undef_lock);void register_undef_hook (struct undef_hook *hook) {
@@ -418,6 +418,9 @@ asmlinkage void __exception do_undefinstr(struct pt_regs *regs)if (call_undef_hook (regs) ==0 )return ; +if (__ipipe_report_trap (IPIPE_TRAP_UNDEFINSTR , regs)) +return ; +force_signal_inject (SIGILL ,ILL_ILLOPC , regs,0 ); }
@@ -646,6 +649,10 @@ asmlinkage void bad_el0_sync(struct pt_regs *regs, int reason, unsigned int esr) {siginfo_t info;void __user *pc = (void __user *)instruction_pointer (regs); + +if (__ipipe_report_trap (IPIPE_TRAP_UNKNOWN , regs)) +return ; +console_verbose (); pr_crit("Bad EL0 synchronous exception detected on CPU%d, code 0x%08x -- %s\n",
arch/arm64/mm/fault.c +109 -9
258 lines not on this page · raw message
Signature · 1 line
2.14.4
PATCH 5/11 arm64: ipipe: route syscalls to co-kernel
In reply to Philippe GerumThis commit introduces the changes redirecting "foreign" system calls to the co-kernel.
--- arch/arm64/include/asm/unistd.h | 2 ++ arch/arm64/kernel/entry.S | 51 +++++++++++++++++++++++++++++++++++++++++ arch/arm64/kernel/ipipe.c | 14 +++++++++++ 3 files changed, 67 insertions(+)
arch/arm64/include/asm/unistd.h +2 -0
@@ -53,3 +53,5 @@#endif #define NR_syscalls (__NR_syscalls) + +#define __ARM_ipipe_syscall 0x10000000
arch/arm64/kernel/entry.S +51 -0
57 lines not on this page · raw message
arch/arm64/kernel/ipipe.c +14 -0
@@ -225,6 +225,20 @@ static void __ipipe_do_IRQ(unsigned irq, void *cookie)__handle_domain_irq (NULL , irq, false, regs); } +void __ipipe_root_sync (void ) +{ +struct ipipe_percpu_domain_data *p; +unsigned long flags; + + flags =hard_local_irq_save (); + + p =ipipe_this_cpu_root_context (); +if (__ipipe_ipending_p (p)) +__ipipe_sync_stage (); + +hard_local_irq_restore (flags); +} +static struct __ipipe_tscinfo tsc_info;void __init __ipipe_tsc_register (struct __ipipe_tscinfo *info)
Signature · 1 line
2.14.4
PATCH 6/11 arm64: fpsimd: ipipe: enable sharing with head domain
In reply to Philippe GerumFrom: Dmitriy Cherkasov <[email protected]>
Serialize accesses to the fpsimd so as to allow co-kernel activities (e.g. tasks) running in the head domain to share the unit with the host kernel.
--- arch/arm64/kernel/fpsimd.c | 138 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 123 insertions(+), 15 deletions(-)
arch/arm64/kernel/fpsimd.c +123 -15
@@ -26,6 +26,7 @@#include <linux/preempt.h> #include <linux/sched/signal.h> #include <linux/signal.h> +#include <linux/ipipe.h> #include <asm/fpsimd.h> #include <asm/cputype.h>
@@ -104,6 +105,9 @@ static DEFINE_PER_CPU(struct fpsimd_state *, fpsimd_last_state);*/ void do_fpsimd_acc (unsigned int esr,struct pt_regs *regs) { +if (__ipipe_report_trap (IPIPE_TRAP_FPU_ACC , regs)) +return ; +/* TODO: implement lazy context saving/restoring */ WARN_ON (1 ); }
@@ -116,6 +120,9 @@ void do_fpsimd_exc(unsigned int esr, struct pt_regs *regs)siginfo_t info;unsigned int si_code =0 ; +if (__ipipe_report_trap (IPIPE_TRAP_FPU_EXC , regs)) +return ; +if (esr &FPEXC_IOF ) si_code =FPE_FLTINV ;else if (esr &FPEXC_DZF )
@@ -135,7 +142,7 @@ void do_fpsimd_exc(unsigned int esr, struct pt_regs *regs)send_sig_info (SIGFPE , &info, current); } -void fpsimd_thread_switch (struct task_struct *next) +static void fpsimd_root_save (void ) {if (!system_supports_fpsimd ())return ;
@@ -146,7 +153,10 @@ void fpsimd_thread_switch(struct task_struct *next)*/ if (current->mm && !test_thread_flag (TIF_FOREIGN_FPSTATE ))fpsimd_save_state (¤t->thread.fpsimd_state); +} +static void fpsimd_root_restore (struct task_struct *next) +{if (next->mm) {/* * If we are switching to a task whose most recent userland
@@ -162,23 +172,112 @@ void fpsimd_thread_switch(struct task_struct *next)clear_ti_thread_flag (task_thread_info (next),TIF_FOREIGN_FPSTATE ); else +#ifdef CONFIG_IPIPE + { +fpsimd_load_state (st); +__this_cpu_write (fpsimd_last_state, st); + st->cpu =raw_smp_processor_id (); + } +#else set_ti_thread_flag (task_thread_info (next),TIF_FOREIGN_FPSTATE ); +#endif + } +} + +#if defined(CONFIG_IPIPE ) || defined(CONFIG_KERNEL_MODE_NEON ) +DEFINE_PER_CPU (bool, kernel_neon_busy); +#endif + +#if defined(CONFIG_IPIPE ) || defined(CONFIG_EFI ) +static DEFINE_PER_CPU(bool, efi_fpsimd_state_used); +#endif + +#ifdef CONFIG_IPIPE +static DEFINE_PER_CPU(struct fpsimd_state, fpsimd_kernel_state); +static DEFINE_PER_CPU(struct fpsimd_state, fpsimd_foreign_state); + +static void fpsimd_do_save (void ) +{ +struct fpsimd_state *st; + +if (__ipipe_root_p) { +fpsimd_root_save (); + }else { + st = ¤t->thread.fpsimd_state; + +if (__this_cpu_read (kernel_neon_busy) || +__this_cpu_read (efi_fpsimd_state_used)) + st =this_cpu_ptr (&fpsimd_kernel_state); + +if (test_thread_flag (TIF_FOREIGN_FPSTATE )) + st =this_cpu_ptr (&fpsimd_foreign_state); + +fpsimd_save_state (st); + } +} + +static void fpsimd_do_restore (struct task_struct *next) +{ +struct fpsimd_state *st; + +if (__ipipe_root_p) { +fpsimd_root_restore (next); + }else { + st = &next->thread.fpsimd_state; + +if (__this_cpu_read (kernel_neon_busy) || +__this_cpu_read (efi_fpsimd_state_used)) + st =this_cpu_ptr (&fpsimd_kernel_state); + +if (test_ti_thread_flag (task_thread_info (next), +TIF_FOREIGN_FPSTATE )) + st =this_cpu_ptr (&fpsimd_foreign_state); + +fpsimd_load_state (st); + st->cpu =raw_smp_processor_id (); +__this_cpu_write (fpsimd_last_state,NULL ); } } +#else /* !CONFIG_IPIPE */ + +static void fpsimd_do_save (void ) +{ +fpsimd_root_save (); +} + +static void fpsimd_do_restore (struct task_struct *next) +{ +fpsimd_root_restore (next); +} + +#endif /* CONFIG_IPIPE */ + +void fpsimd_thread_switch (struct task_struct *next) +{ +unsigned long flags; + + flags =hard_local_irq_save (); +fpsimd_do_save (); +fpsimd_do_restore (next); +hard_local_irq_restore (flags); +} +void fpsimd_flush_thread (void ) { +unsigned long flags; +if (!system_supports_fpsimd ())return ; -local_bh_disable (); + flags =hard_preempt_disable ();memset (¤t->thread.fpsimd_state,0 ,sizeof (struct fpsimd_state ));fpsimd_flush_task_state (current);set_thread_flag (TIF_FOREIGN_FPSTATE ); -local_bh_enable (); +hard_preempt_enable (flags); }/*
@@ -187,15 +286,15 @@ void fpsimd_flush_thread(void)*/ void fpsimd_preserve_current_state (void ) { +unsigned long flags; +if (!system_supports_fpsimd ())return ; -local_bh_disable (); - + flags =hard_preempt_disable ();if (!test_thread_flag (TIF_FOREIGN_FPSTATE ))fpsimd_save_state (¤t->thread.fpsimd_state); - -local_bh_enable (); +hard_preempt_enable (flags); }/*
@@ -205,10 +304,12 @@ void fpsimd_preserve_current_state(void)*/ void fpsimd_restore_current_state (void ) { +unsigned long flags; +if (!system_supports_fpsimd ())return ; -local_bh_disable (); + flags =hard_preempt_disable ();if (test_and_clear_thread_flag (TIF_FOREIGN_FPSTATE )) {struct fpsimd_state *st = ¤t->thread.fpsimd_state;
@@ -218,7 +319,7 @@ void fpsimd_restore_current_state(void) st->cpu =smp_processor_id (); } -local_bh_enable (); +hard_preempt_enable (flags); }/*
@@ -228,10 +329,12 @@ void fpsimd_restore_current_state(void)*/ void fpsimd_update_current_state (struct fpsimd_state *state) { +unsigned long flags; +if (!system_supports_fpsimd ())return ; -local_bh_disable (); + flags =hard_preempt_disable ();fpsimd_load_state (state);if (test_and_clear_thread_flag (TIF_FOREIGN_FPSTATE )) {
@@ -241,7 +344,7 @@ void fpsimd_update_current_state(struct fpsimd_state *state) st->cpu =smp_processor_id (); } -local_bh_enable (); +hard_preempt_enable (flags); }/*
@@ -254,7 +357,6 @@ void fpsimd_flush_task_state(struct task_struct *t)#ifdef CONFIG_KERNEL_MODE_NEON -DEFINE_PER_CPU (bool, kernel_neon_busy);EXPORT_PER_CPU_SYMBOL (kernel_neon_busy);/*
@@ -276,11 +378,15 @@ EXPORT_PER_CPU_SYMBOL(kernel_neon_busy);*/ void kernel_neon_begin (void ) { +unsigned long flags; +if (WARN_ON (!system_supports_fpsimd ()))return ;BUG_ON (!may_use_simd ()); + flags =hard_preempt_disable (); +local_bh_disable ();__this_cpu_write (kernel_neon_busy, true);
@@ -292,7 +398,7 @@ void kernel_neon_begin(void)/* Invalidate any task state remaining in the fpsimd regs: */ __this_cpu_write (fpsimd_last_state,NULL ); -preempt_disable (); +hard_local_irq_restore (flags);local_bh_enable (); }
@@ -310,21 +416,23 @@ EXPORT_SYMBOL(kernel_neon_begin);void kernel_neon_end (void ) {bool busy; +unsigned long flags;if (!system_supports_fpsimd ())return ; + flags =hard_local_irq_save (); busy =__this_cpu_xchg (kernel_neon_busy, false);WARN_ON (!busy);/* No matching kernel_neon_begin()? */ -preempt_enable (); +hard_preempt_enable (flags); +hard_local_irq_enable (); }EXPORT_SYMBOL (kernel_neon_end);#ifdef CONFIG_EFI static DEFINE_PER_CPU(struct fpsimd_state, efi_fpsimd_state); -static DEFINE_PER_CPU(bool, efi_fpsimd_state_used);/* * EFI runtime services support functions
Signature · 1 line
2.14.4
PATCH 7/11 arm64: ipipe: turn hard irqs on when leaving the idle state
In reply to Philippe GerumAs required to mimic the original behavior when interrupt pipelining is in effect.
--- arch/arm64/kernel/process.c | 34 +--------------------------------- 1 file changed, 1 insertion(+), 33 deletions(-)
arch/arm64/kernel/process.c +1 -33
@@ -73,36 +73,6 @@ EXPORT_SYMBOL_GPL(pm_power_off);void (*arm_pm_restart)(enum reboot_mode reboot_mode,const char *cmd); -#ifdef CONFIG_IPIPE -static void __ipipe_halt_root (void ) -{ -struct ipipe_percpu_domain_data *p; - -/* -* Emulate idle entry sequence over the root domain, which is -* stalled on entry. -*/ -hard_local_irq_disable (); - - p =ipipe_this_cpu_root_context (); -__clear_bit (IPIPE_STALL_FLAG , &p->status); - -if (unlikely (__ipipe_ipending_p (p))) -__ipipe_sync_stage (); -else { -cpu_do_idle (); - } -} - -#else /* !CONFIG_IPIPE */ - -static void __ipipe_halt_root (void ) -{ -cpu_do_idle (); -} - -#endif /* !CONFIG_IPIPE */ -/* * This is our default idle handler. */
@@ -113,10 +83,8 @@ void arch_cpu_idle(void)* tricks */ trace_cpu_idle_rcuidle (1 ,smp_processor_id ()); -if (!need_resched ()) -__ipipe_halt_root ();cpu_do_idle (); -local_irq_enable (); +local_irq_enable_full ();trace_cpu_idle_rcuidle (PWR_EVENT_EXIT ,smp_processor_id ()); }
Signature · 1 line
2.14.4
PATCH 8/11 arm64: dts: bcm2837: provide for BT-less variant, re-enabling uart0 as serial
In reply to Philippe GerumRaspberry 3 has two UARTs: uart0 is a full-fledged pl011 used for BT by default, uart1 is a poor-man's low throughput serial device dubbed as the "mini-uart". Unfortunately, uart1 is a massive pain, whose clock rate is based on the CPU clock rate: this makes it quite unstable as a serial console when a CPU frequency governor is enabled.
When BT is useless, we'd rather switch uart0 from BT to the serial pins, disabling uart1 in the same move, so that we recover a decent console device (*) with a stable clocking.
bcm2837-rpi-3-b-nobt.dtb is a fixed up blob doing exactly that.
(*) cmdline should mention console=ttyAMA0,<speed>
--- arch/arm64/boot/dts/broadcom/Makefile | 2 +- arch/arm64/boot/dts/broadcom/bcm2837-rpi-3-b-nobt.dts | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/boot/dts/broadcom/bcm2837-rpi-3-b-nobt.dts
arch/arm64/boot/dts/broadcom/Makefile +1 -1
@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -dtb-$(CONFIG_ARCH_BCM2835) += bcm2837-rpi-3-b.dtb +dtb-$(CONFIG_ARCH_BCM2835) += bcm2837-rpi-3-b.dtb bcm2837-rpi-3-b-nobt.dtb dts-dirs += northstar2 dts-dirs += stingray
arch/arm64/boot/dts/broadcom/bcm2837-rpi-3-b-nobt.dts new file +12 -0
@@ -0,0 +1,12 @@ +/dts-v1/; +#include "bcm2837-rpi-3-b.dts" + +&uart0 { + status = "okay"; + pinctrl-names = "default"; + pinctrl-0 = <&uart0_gpio32>; +}; + +&uart1 { + status = "disabled"; +};
Signature · 1 line
2.14.4
PATCH 9/11 arm64: ipipe: route debug exceptions to co-kernel
In reply to Philippe Gerum--- arch/arm64/mm/fault.c | 3 +++ 1 file changed, 3 insertions(+)
arch/arm64/mm/fault.c +3 -0
@@ -939,6 +939,9 @@ asmlinkage int __exception do_debug_exception(unsigned long addr,struct siginfo info;int rv; +if (__ipipe_report_trap (IPIPE_TRAP_BREAK , regs)) +return 1 ; +/* * Tell lockdep we disabled irqs in entry.S. Do nothing if they were * already disabled to preserve the last enabled/disabled addresses.
Signature · 1 line
2.14.4
PATCH 10/11 arm64: ipipe: route all access traps to co-kernel
In reply to Philippe GerumNotifying the co-kernel about major faults occurring in kernel context or user-space was overlooked. We need the co-kernel to restore the root stage whenever applicable before we may attempt to handle the fault.
--- arch/arm64/mm/fault.c | 6 ++++++ 1 file changed, 6 insertions(+)
arch/arm64/mm/fault.c +6 -0
@@ -401,6 +401,9 @@ static void do_bad_area(unsigned long addr, unsigned int esr, struct pt_regs *reconst struct fault_info *inf;unsigned long irqflags; +if (__ipipe_report_trap (IPIPE_TRAP_ACCESS , regs)) +return ; +/* * If we are in kernel mode at this point, we have no context to * handle this fault with.
@@ -473,6 +476,9 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr,unsigned long vm_flags =VM_READ |VM_WRITE , irqflags;unsigned int mm_flags =FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_KILLABLE ; +if (__ipipe_report_trap (IPIPE_TRAP_ACCESS , regs)) +return 0 ; + irqflags =fault_entry (regs);if (notify_page_fault (regs, esr))
Signature · 1 line
2.14.4
PATCH 11/11 arm64: ipipe: preserve the hard interrupt state across mayday trap
In reply to Philippe GerumThe mayday trap asks the co-kernel to deal with a runaway context which has been detected earlier. When doing so, the co-kernel might re-enable hard interrupts, which we have to disable again before unwinding the IRQ context which triggered the whole process (like a watchdog event).
Use __ipipe_call_mayday() to fire the notification to the co-kernel instead of the open coded version, so that we do restore the hard interrupt state properly before leaving __ipipe_exit_irq().
--- arch/arm64/kernel/ipipe.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-)
arch/arm64/kernel/ipipe.c +2 -15
@@ -165,21 +165,8 @@ void __ipipe_enable_pipeline(void)void __ipipe_exit_irq (struct pt_regs *regs) { -/* -* Testing for user_regs() eliminates foreign stack contexts, -* including from legacy domains which did not set the foreign -* stack bit (foreign stacks are always kernel-based). -*/ -if (user_mode (regs) && -ipipe_test_thread_flag (TIP_MAYDAY )) { -/* -* MAYDAY is never raised under normal circumstances, -* so prefer test then maybe clear over -* test_and_clear. -*/ -ipipe_clear_thread_flag (TIP_MAYDAY ); -__ipipe_notify_trap (IPIPE_TRAP_MAYDAY , regs); - } +if (user_mode (regs) &&ipipe_test_thread_flag (TIP_MAYDAY )) +__ipipe_call_mayday (regs); }/* hw irqs off */
Signature · 1 line
2.14.4