arm64: ipipe: add pipeline core
Subsystems (2)
PATCH 1/7 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
@@ -695,6 +697,7 @@ config HOLES_IN_ZONE def_bool y depends on NUMA +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