From: Philippe Gerum Date: Tue, 25 Sep 2018 12:37:39 +0200 Message-Id: <20180925103809.4932-3-rpm@xenomai.org> In-Reply-To: <20180925103809.4932-1-rpm@xenomai.org> References: <20180925103809.4932-1-rpm@xenomai.org> Subject: [Xenomai] [PATCH 02/32] x86: ipipe: add pipeline core List-Id: Discussions about the Xenomai project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: xenomai@xenomai.org Introduce the x86-specific bits enabling the interrupt pipeline exclusively. --- arch/x86/Kconfig | 5 + arch/x86/entry/common.c | 22 +- arch/x86/entry/entry_64.S | 56 ++++- arch/x86/include/asm/apic.h | 10 + arch/x86/include/asm/debugreg.h | 2 +- arch/x86/include/asm/desc.h | 2 +- arch/x86/include/asm/ipipe.h | 68 ++++++ arch/x86/include/asm/ipipe_base.h | 151 +++++++++++++ arch/x86/include/asm/irq_vectors.h | 17 +- arch/x86/include/asm/irqflags.h | 192 +++++++++++++++- arch/x86/include/asm/thread_info.h | 14 ++ arch/x86/kernel/Makefile | 1 + arch/x86/kernel/apic/apic.c | 46 +++- arch/x86/kernel/apic/apic_flat_64.c | 4 +- arch/x86/kernel/apic/io_apic.c | 182 +++++++++++++-- arch/x86/kernel/apic/ipi.c | 29 ++- arch/x86/kernel/apic/msi.c | 12 + arch/x86/kernel/apic/vector.c | 13 +- arch/x86/kernel/apic/x2apic_cluster.c | 4 +- arch/x86/kernel/apic/x2apic_phys.c | 4 +- arch/x86/kernel/asm-offsets.c | 3 + arch/x86/kernel/cpu/common.c | 2 + arch/x86/kernel/idt.c | 14 ++ arch/x86/kernel/ipipe.c | 409 ++++++++++++++++++++++++++++++++++ arch/x86/kernel/irq.c | 5 +- arch/x86/kernel/process.c | 10 +- arch/x86/kernel/smp.c | 4 +- arch/x86/kernel/smpboot.c | 8 +- 28 files changed, 1220 insertions(+), 69 deletions(-) create mode 100644 arch/x86/include/asm/ipipe.h create mode 100644 arch/x86/include/asm/ipipe_base.h create mode 100644 arch/x86/kernel/ipipe.c diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 2af0af33362a..607c73288a16 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -145,6 +145,9 @@ config X86 select HAVE_IOREMAP_PROT select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64 select HAVE_IRQ_TIME_ACCOUNTING + select HAVE_IPIPE_SUPPORT + select HAVE_IPIPE_TRACER_SUPPORT + select IPIPE_HAVE_SAFE_THREAD_INFO if IPIPE select HAVE_KERNEL_BZIP2 select HAVE_KERNEL_GZIP select HAVE_KERNEL_LZ4 @@ -999,6 +1002,8 @@ config SCHED_MC_PRIO source "kernel/Kconfig.preempt" +source "kernel/ipipe/Kconfig" + config UP_LATE_INIT def_bool y depends on !SMP && X86_LOCAL_APIC diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c index 60e21ccfb6d6..5cc2f617a2e3 100644 --- a/arch/x86/entry/common.c +++ b/arch/x86/entry/common.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -146,7 +147,7 @@ static void exit_to_usermode_loop(struct pt_regs *regs, u32 cached_flags) */ while (true) { /* We have work to do. */ - local_irq_enable(); + local_irq_enable(); /* IPIPE: hardirqs on too */ if (cached_flags & _TIF_NEED_RESCHED) schedule(); @@ -172,6 +173,8 @@ static void exit_to_usermode_loop(struct pt_regs *regs, u32 cached_flags) /* Disable IRQs and retry */ local_irq_disable(); + hard_cond_local_irq_disable(); + cached_flags = READ_ONCE(current_thread_info()->flags); if (!(cached_flags & EXIT_TO_USERMODE_LOOP_FLAGS)) @@ -184,6 +187,12 @@ __visible inline void prepare_exit_to_usermode(struct pt_regs *regs) { struct thread_info *ti = current_thread_info(); u32 cached_flags; +#ifdef CONFIG_IPIPE + unsigned long flags; + + local_irq_save(flags); + hard_local_irq_enable(); +#endif addr_limit_user_check(); @@ -213,6 +222,11 @@ __visible inline void prepare_exit_to_usermode(struct pt_regs *regs) #endif user_enter_irqoff(); + +#ifdef CONFIG_IPIPE + local_irq_restore(flags); + hard_local_irq_disable(); +#endif } #define SYSCALL_EXIT_WORK_FLAGS \ @@ -264,6 +278,7 @@ __visible inline void syscall_return_slowpath(struct pt_regs *regs) syscall_slow_exit_work(regs, cached_flags); local_irq_disable(); + hard_cond_local_irq_disable(); prepare_exit_to_usermode(regs); } @@ -342,7 +357,7 @@ static __always_inline void do_syscall_32_irqs_on(struct pt_regs *regs) __visible void do_int80_syscall_32(struct pt_regs *regs) { enter_from_user_mode(); - local_irq_enable(); + local_irq_enable(); /* IPIPE: hardirqs on too */ do_syscall_32_irqs_on(regs); } @@ -366,7 +381,7 @@ __visible long do_fast_syscall_32(struct pt_regs *regs) enter_from_user_mode(); - local_irq_enable(); + local_irq_enable(); /* IPIPE: hardirqs on too */ /* Fetch EBP from where the vDSO stashed it. */ if ( @@ -385,6 +400,7 @@ __visible long do_fast_syscall_32(struct pt_regs *regs) /* User code screwed up. */ local_irq_disable(); + hard_cond_local_irq_disable(); regs->ax = -EFAULT; prepare_exit_to_usermode(regs); return 0; /* Keep it simple: use IRET. */ diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index 92a7471a5e7b..4f29114cb2a1 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -73,7 +74,8 @@ END(native_usergs_sysret64) * make sure the stack pointer does not get reset back to the top * of the debug stack, and instead just reuses the current stack. */ -#if defined(CONFIG_DYNAMIC_FTRACE) && defined(CONFIG_TRACE_IRQFLAGS) +#if defined(CONFIG_DYNAMIC_FTRACE) && defined(CONFIG_TRACE_IRQFLAGS) \ + && !defined(CONFIG_IPIPE) .macro TRACE_IRQS_OFF_DEBUG call debug_stack_set_zero @@ -383,6 +385,7 @@ END(__switch_to_asm) */ ENTRY(ret_from_fork) UNWIND_HINT_EMPTY + HARD_COND_ENABLE_INTERRUPTS movq %rax, %rdi call schedule_tail /* rdi: 'prev' task parameter */ @@ -568,7 +571,17 @@ END(irq_entries_start) common_interrupt: ASM_CLAC addq $-0x80, (%rsp) /* Adjust vector to [-256, -1] range */ +#ifdef CONFIG_IPIPE + interrupt __ipipe_handle_irq + testl %eax, %eax + jnz ret_from_intr + LEAVE_IRQ_STACK + testb $3, CS(%rsp) + jz retint_kernel_early + jmp retint_user_early +#else interrupt do_IRQ +#endif /* 0(%rsp): old RSP */ ret_from_intr: DISABLE_INTERRUPTS(CLBR_ANY) @@ -583,6 +596,7 @@ ret_from_intr: GLOBAL(retint_user) mov %rsp,%rdi call prepare_exit_to_usermode +retint_user_early: TRACE_IRQS_IRETQ GLOBAL(swapgs_restore_regs_and_return_to_usermode) @@ -634,13 +648,18 @@ retint_kernel: jnc 1f 0: cmpl $0, PER_CPU_VAR(__preempt_count) jnz 1f +#ifdef CONFIG_IPIPE + call __ipipe_preempt_schedule_irq +#else call preempt_schedule_irq +#endif jmp 0b 1: #endif /* * The iretq could re-enable interrupts: - */ + */ +retint_kernel_early: TRACE_IRQS_IRETQ GLOBAL(restore_regs_and_return_to_kernel) @@ -754,6 +773,26 @@ END(common_interrupt) /* * APIC interrupts. */ +#ifdef CONFIG_IPIPE +.macro apicinterrupt2 num sym +ENTRY(\sym) + UNWIND_HINT_IRET_REGS + ASM_CLAC + pushq $~(\num) +.Lcommon_\sym: + interrupt __ipipe_handle_irq + testl %eax, %eax + jnz ret_from_intr + LEAVE_IRQ_STACK + testb $3, CS(%rsp) + jz retint_kernel_early + jmp retint_user_early +END(\sym) +.endm +.macro apicinterrupt3 num sym do_sym +apicinterrupt2 \num \sym +.endm +#else /* !CONFIG_IPIPE */ .macro apicinterrupt3 num sym do_sym ENTRY(\sym) UNWIND_HINT_IRET_REGS @@ -764,6 +803,7 @@ ENTRY(\sym) jmp ret_from_intr END(\sym) .endm +#endif /* !CONFIG_IPIPE */ /* Make sure APIC interrupt handlers end up in the irqentry section: */ #define PUSH_SECTION_IRQENTRY .pushsection .irqentry.text, "ax" @@ -809,6 +849,14 @@ apicinterrupt THERMAL_APIC_VECTOR thermal_interrupt smp_thermal_interrupt apicinterrupt CALL_FUNCTION_SINGLE_VECTOR call_function_single_interrupt smp_call_function_single_interrupt apicinterrupt CALL_FUNCTION_VECTOR call_function_interrupt smp_call_function_interrupt apicinterrupt RESCHEDULE_VECTOR reschedule_interrupt smp_reschedule_interrupt +#ifdef CONFIG_IPIPE +apicinterrupt2 IPIPE_RESCHEDULE_VECTOR ipipe_reschedule_interrupt +apicinterrupt2 IPIPE_CRITICAL_VECTOR ipipe_critical_interrupt +#endif +#endif + +#ifdef CONFIG_IPIPE +apicinterrupt2 IPIPE_HRTIMER_VECTOR ipipe_hrtimer_interrupt #endif apicinterrupt ERROR_APIC_VECTOR error_interrupt smp_error_interrupt @@ -992,10 +1040,14 @@ bad_gs: ENTRY(do_softirq_own_stack) pushq %rbp mov %rsp, %rbp + HARD_COND_DISABLE_INTERRUPTS ENTER_IRQ_STACK regs=0 old_rsp=%r11 + HARD_COND_ENABLE_INTERRUPTS call __do_softirq + HARD_COND_DISABLE_INTERRUPTS LEAVE_IRQ_STACK regs=0 leaveq + HARD_COND_ENABLE_INTERRUPTS ret ENDPROC(do_softirq_own_stack) diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h index a1ed92aae12a..80f9ff840d9b 100644 --- a/arch/x86/include/asm/apic.h +++ b/arch/x86/include/asm/apic.h @@ -435,7 +435,17 @@ static inline void apic_set_eoi_write(void (*eoi_write)(u32 reg, u32 v)) {} #endif /* CONFIG_X86_LOCAL_APIC */ +#ifdef CONFIG_IPIPE +#ifdef CONFIG_SMP +struct irq_data; +void move_xxapic_irq(struct irq_data *data); +#endif +#define ack_APIC_irq() do { } while(0) +static inline void __ack_APIC_irq(void) +#else /* !CONFIG_IPIPE */ +#define __ack_APIC_irq() ack_APIC_irq() static inline void ack_APIC_irq(void) +#endif /* CONFIG_IPIPE */ { /* * ack_APIC_irq() actually gets compiled as a single instruction diff --git a/arch/x86/include/asm/debugreg.h b/arch/x86/include/asm/debugreg.h index 4505ac2735ad..c547c0efdaa9 100644 --- a/arch/x86/include/asm/debugreg.h +++ b/arch/x86/include/asm/debugreg.h @@ -94,7 +94,7 @@ extern void aout_dump_debugregs(struct user *dump); extern void hw_breakpoint_restore(void); -#ifdef CONFIG_X86_64 +#if defined(CONFIG_X86_64) && !defined(CONFIG_IPIPE) DECLARE_PER_CPU(int, debug_stack_usage); static inline void debug_stack_usage_inc(void) { diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h index 85e23bb7b34e..0e3758c0c954 100644 --- a/arch/x86/include/asm/desc.h +++ b/arch/x86/include/asm/desc.h @@ -391,7 +391,7 @@ void alloc_intr_gate(unsigned int n, const void *addr); extern unsigned long used_vectors[]; -#ifdef CONFIG_X86_64 +#if defined(CONFIG_X86_64) && !defined(CONFIG_IPIPE) DECLARE_PER_CPU(u32, debug_idt_ctr); static inline bool is_debug_idt_enabled(void) { diff --git a/arch/x86/include/asm/ipipe.h b/arch/x86/include/asm/ipipe.h new file mode 100644 index 000000000000..280f173dd004 --- /dev/null +++ b/arch/x86/include/asm/ipipe.h @@ -0,0 +1,68 @@ +/* -*- linux-c -*- + * arch/x86/include/asm/ipipe.h + * + * Copyright (C) 2007 Philippe Gerum. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139, + * USA; either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __X86_IPIPE_H +#define __X86_IPIPE_H + +#ifdef CONFIG_IPIPE + +#define IPIPE_CORE_RELEASE 2112 + +struct ipipe_domain; + +struct ipipe_arch_sysinfo { +}; + +#define ipipe_processor_id() raw_smp_processor_id() + +/* Private interface -- Internal use only */ + +#define __ipipe_early_core_setup() do { } while(0) + +#define __ipipe_enable_irq(irq) irq_to_desc(irq)->chip->enable(irq) +#define __ipipe_disable_irq(irq) irq_to_desc(irq)->chip->disable(irq) + +#ifdef CONFIG_SMP +void __ipipe_hook_critical_ipi(struct ipipe_domain *ipd); +#else +#define __ipipe_hook_critical_ipi(ipd) do { } while(0) +#endif + +void __ipipe_enable_pipeline(void); + +#define __ipipe_root_tick_p(regs) ((regs)->flags & X86_EFLAGS_IF) + +#endif /* CONFIG_IPIPE */ + +#if defined(CONFIG_SMP) && defined(CONFIG_IPIPE) +#define __ipipe_move_root_irq(__desc) \ + do { \ + if (!IS_ERR_OR_NULL(__desc)) { \ + struct irq_chip *__chip = irq_desc_get_chip(__desc); \ + if (__chip->irq_move) \ + __chip->irq_move(irq_desc_get_irq_data(__desc)); \ + } \ + } while (0) +#else /* !(CONFIG_SMP && CONFIG_IPIPE) */ +#define __ipipe_move_root_irq(irq) do { } while (0) +#endif /* !(CONFIG_SMP && CONFIG_IPIPE) */ + +#endif /* !__X86_IPIPE_H */ diff --git a/arch/x86/include/asm/ipipe_base.h b/arch/x86/include/asm/ipipe_base.h new file mode 100644 index 000000000000..e0debe840abd --- /dev/null +++ b/arch/x86/include/asm/ipipe_base.h @@ -0,0 +1,151 @@ +/* -*- linux-c -*- + * arch/x86/include/asm/ipipe_base.h + * + * Copyright (C) 2007-2012 Philippe Gerum. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139, + * USA; either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __X86_IPIPE_BASE_H +#define __X86_IPIPE_BASE_H + +#include +#include + +#ifdef CONFIG_X86_32 +/* 32 from IDT + iret_error + mayday trap */ +#define IPIPE_TRAP_MAYDAY 33 /* Internal recovery trap */ +#define IPIPE_NR_FAULTS 34 +#else +/* 32 from IDT + mayday trap */ +#define IPIPE_TRAP_MAYDAY 32 /* Internal recovery trap */ +#define IPIPE_NR_FAULTS 33 +#endif + +#ifdef CONFIG_X86_LOCAL_APIC +/* + * Special APIC interrupts are mapped above the last defined external + * IRQ number. + */ +#define nr_apic_vectors (NR_VECTORS - FIRST_SYSTEM_VECTOR) +#define IPIPE_FIRST_APIC_IRQ NR_IRQS +#define IPIPE_HRTIMER_IPI ipipe_apic_vector_irq(IPIPE_HRTIMER_VECTOR) +#ifdef CONFIG_SMP +#define IPIPE_RESCHEDULE_IPI ipipe_apic_vector_irq(IPIPE_RESCHEDULE_VECTOR) +#define IPIPE_CRITICAL_IPI ipipe_apic_vector_irq(IPIPE_CRITICAL_VECTOR) +#endif /* CONFIG_SMP */ +#define IPIPE_NR_XIRQS (NR_IRQS + nr_apic_vectors) +#define ipipe_apic_irq_vector(irq) ((irq) - IPIPE_FIRST_APIC_IRQ + FIRST_SYSTEM_VECTOR) +#define ipipe_apic_vector_irq(vec) ((vec) - FIRST_SYSTEM_VECTOR + IPIPE_FIRST_APIC_IRQ) +#else +#define IPIPE_NR_XIRQS NR_IRQS +#endif /* !CONFIG_X86_LOCAL_APIC */ + +#ifndef __ASSEMBLY__ + +#include + +extern unsigned int cpu_khz; + +static inline const char *ipipe_clock_name(void) +{ + return "tsc"; +} + +#define __ipipe_cpu_freq ({ u64 __freq = 1000ULL * cpu_khz; __freq; }) +#define __ipipe_hrclock_freq __ipipe_cpu_freq + +#ifdef CONFIG_X86_32 + +#define ipipe_read_tsc(t) \ + __asm__ __volatile__("rdtsc" : "=A"(t)) + +#define ipipe_tsc2ns(t) \ +({ \ + unsigned long long delta = (t) * 1000000ULL; \ + unsigned long long freq = __ipipe_hrclock_freq; \ + do_div(freq, 1000); \ + do_div(delta, (unsigned)freq + 1); \ + (unsigned long)delta; \ +}) + +#define ipipe_tsc2us(t) \ +({ \ + unsigned long long delta = (t) * 1000ULL; \ + unsigned long long freq = __ipipe_hrclock_freq; \ + do_div(freq, 1000); \ + do_div(delta, (unsigned)freq + 1); \ + (unsigned long)delta; \ +}) + +static inline unsigned long __ipipe_ffnz(unsigned long ul) +{ + __asm__("bsrl %1, %0":"=r"(ul) : "r"(ul)); + return ul; +} + +#else /* X86_64 */ + +#define ipipe_read_tsc(t) do { \ + unsigned int __a,__d; \ + asm volatile("rdtsc" : "=a" (__a), "=d" (__d)); \ + (t) = ((unsigned long)__a) | (((unsigned long)__d)<<32); \ +} while(0) + +#define ipipe_tsc2ns(t) (((t) * 1000UL) / (__ipipe_hrclock_freq / 1000000UL)) +#define ipipe_tsc2us(t) ((t) / (__ipipe_hrclock_freq / 1000000UL)) + +static inline unsigned long __ipipe_ffnz(unsigned long ul) +{ + __asm__("bsrq %1, %0":"=r"(ul) + : "rm"(ul)); + return ul; +} + +#endif /* X86_64 */ + +struct pt_regs; +struct irq_desc; +struct ipipe_vm_notifier; + +static inline unsigned __ipipe_get_irq_vector(int irq) +{ +#ifdef CONFIG_X86_IO_APIC + unsigned int __ipipe_get_ioapic_irq_vector(int irq); + return __ipipe_get_ioapic_irq_vector(irq); +#elif defined(CONFIG_X86_LOCAL_APIC) + return irq >= IPIPE_FIRST_APIC_IRQ ? + ipipe_apic_irq_vector(irq) : ISA_IRQ_VECTOR(irq); +#else + return ISA_IRQ_VECTOR(irq); +#endif +} + +void ipipe_hrtimer_interrupt(void); + +void ipipe_reschedule_interrupt(void); + +void ipipe_critical_interrupt(void); + +int __ipipe_handle_irq(struct pt_regs *regs); + +void __ipipe_handle_vm_preemption(struct ipipe_vm_notifier *nfy); + +extern int __ipipe_hrtimer_irq; + +#endif /* !__ASSEMBLY__ */ + +#endif /* !__X86_IPIPE_BASE_H */ diff --git a/arch/x86/include/asm/irq_vectors.h b/arch/x86/include/asm/irq_vectors.h index c20ffca8fef1..45dcbf59a592 100644 --- a/arch/x86/include/asm/irq_vectors.h +++ b/arch/x86/include/asm/irq_vectors.h @@ -102,6 +102,11 @@ #define POSTED_INTR_NESTED_VECTOR 0xf0 #endif +/* Interrupt pipeline IPIs */ +#define IPIPE_HRTIMER_VECTOR 0xee +#define IPIPE_RESCHEDULE_VECTOR 0xed +#define IPIPE_CRITICAL_VECTOR 0xec + /* * Local APIC timer IRQ vector is on a different priority level, * to work around the 'lost local interrupt if more than 2 IRQ @@ -109,13 +114,13 @@ */ #define LOCAL_TIMER_VECTOR 0xef -#define NR_VECTORS 256 +/* + * I-pipe: Lowest vector number which may be assigned to a special + * APIC IRQ. We must know this at build time. + */ +#define FIRST_SYSTEM_VECTOR IPIPE_CRITICAL_VECTOR -#ifdef CONFIG_X86_LOCAL_APIC -#define FIRST_SYSTEM_VECTOR LOCAL_TIMER_VECTOR -#else -#define FIRST_SYSTEM_VECTOR NR_VECTORS -#endif +#define NR_VECTORS 256 #define FPU_IRQ 13 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h index 63d29a6eabce..8aa809f92a61 100644 --- a/arch/x86/include/asm/irqflags.h +++ b/arch/x86/include/asm/irqflags.h @@ -6,6 +6,10 @@ #ifndef __ASSEMBLY__ +#include +#include +#include + /* Provide __cpuidle; we can't safely include */ #define __cpuidle __attribute__((__section__(".cpuidle.text"))) @@ -62,14 +66,76 @@ static inline __cpuidle void native_halt(void) asm volatile("hlt": : :"memory"); } +static inline int native_irqs_disabled(void) +{ + unsigned long flags = native_save_fl(); + + return !(flags & X86_EFLAGS_IF); +} + #endif #ifdef CONFIG_PARAVIRT #include +#define HARD_COND_ENABLE_INTERRUPTS +#define HARD_COND_DISABLE_INTERRUPTS #else #ifndef __ASSEMBLY__ #include +#ifdef CONFIG_IPIPE + +void __ipipe_halt_root(int use_mwait); + +static inline notrace unsigned long arch_local_save_flags(void) +{ + unsigned long flags; + + flags = (!ipipe_test_root()) << 9; + barrier(); + return flags; +} + +static inline notrace void arch_local_irq_restore(unsigned long flags) +{ + barrier(); + ipipe_restore_root(!(flags & X86_EFLAGS_IF)); +} + +static inline notrace void arch_local_irq_disable(void) +{ + ipipe_stall_root(); + barrier(); +} + +static inline notrace void arch_local_irq_enable(void) +{ + barrier(); + ipipe_unstall_root(); +} + +static inline __cpuidle void arch_safe_halt(void) +{ + barrier(); + __ipipe_halt_root(0); +} + +/* Merge virtual+real interrupt mask bits into a single word. */ +static inline unsigned long arch_mangle_irq_bits(int virt, unsigned long real) +{ + return (real & ~(1L << 31)) | ((unsigned long)(virt != 0) << 31); +} + +/* Converse operation of arch_mangle_irq_bits() */ +static inline int arch_demangle_irq_bits(unsigned long *x) +{ + int virt = (*x & (1L << 31)) != 0; + *x &= ~(1L << 31); + return virt; +} + +#else /* !CONFIG_IPIPE */ + static inline notrace unsigned long arch_local_save_flags(void) { return native_save_fl(); @@ -99,6 +165,8 @@ static inline __cpuidle void arch_safe_halt(void) native_safe_halt(); } +#endif /* !CONFIG_IPIPE */ + /* * Used when interrupts are already enabled or to * shutdown the processor: @@ -122,6 +190,14 @@ static inline notrace unsigned long arch_local_irq_save(void) #define ENABLE_INTERRUPTS(x) sti #define DISABLE_INTERRUPTS(x) cli +#ifdef CONFIG_IPIPE +#define HARD_COND_ENABLE_INTERRUPTS sti +#define HARD_COND_DISABLE_INTERRUPTS cli +#else /* !CONFIG_IPIPE */ +#define HARD_COND_ENABLE_INTERRUPTS +#define HARD_COND_DISABLE_INTERRUPTS +#endif /* !CONFIG_IPIPE */ + #ifdef CONFIG_X86_64 #define SWAPGS swapgs /* @@ -170,6 +246,111 @@ static inline int arch_irqs_disabled(void) return arch_irqs_disabled_flags(flags); } + +#ifdef CONFIG_IPIPE + +static inline unsigned long hard_local_irq_save_notrace(void) +{ + unsigned long flags; + + flags = native_save_fl(); + native_irq_disable(); + + return flags; +} + +static inline void hard_local_irq_restore_notrace(unsigned long flags) +{ + native_restore_fl(flags); +} + +static inline void hard_local_irq_disable_notrace(void) +{ + native_irq_disable(); +} + +static inline void hard_local_irq_enable_notrace(void) +{ + native_irq_enable(); +} + +static inline int hard_irqs_disabled(void) +{ + return native_irqs_disabled(); +} + +#define hard_irqs_disabled_flags(flags) arch_irqs_disabled_flags(flags) + +#ifdef CONFIG_IPIPE_TRACE_IRQSOFF + +static inline void hard_local_irq_disable(void) +{ + if (!native_irqs_disabled()) { + native_irq_disable(); + ipipe_trace_begin(0x80000000); + } +} + +static inline void hard_local_irq_enable(void) +{ + if (native_irqs_disabled()) { + ipipe_trace_end(0x80000000); + native_irq_enable(); + } +} + +static inline unsigned long hard_local_irq_save(void) +{ + unsigned long flags; + + flags = native_save_fl(); + if (flags & X86_EFLAGS_IF) { + native_irq_disable(); + ipipe_trace_begin(0x80000001); + } + + return flags; +} + +static inline void hard_local_irq_restore(unsigned long flags) +{ + if (flags & X86_EFLAGS_IF) + ipipe_trace_end(0x80000001); + + native_restore_fl(flags); +} + +#else /* !CONFIG_IPIPE_TRACE_IRQSOFF */ + +static inline unsigned long hard_local_irq_save(void) +{ + return hard_local_irq_save_notrace(); +} + +static inline void hard_local_irq_restore(unsigned long flags) +{ + hard_local_irq_restore_notrace(flags); +} + +static inline void hard_local_irq_enable(void) +{ + hard_local_irq_enable_notrace(); +} + +static inline void hard_local_irq_disable(void) +{ + hard_local_irq_disable_notrace(); +} + +#endif /* CONFIG_IPIPE_TRACE_IRQSOFF */ + +static inline unsigned long hard_local_save_flags(void) +{ + return native_save_fl(); +} + +#endif /* CONFIG_IPIPE */ + #endif /* !__ASSEMBLY__ */ #ifdef __ASSEMBLY__ @@ -188,28 +369,33 @@ static inline int arch_irqs_disabled(void) #endif #ifdef CONFIG_DEBUG_LOCK_ALLOC # ifdef CONFIG_X86_64 -# define LOCKDEP_SYS_EXIT call lockdep_sys_exit_thunk +# define LOCKDEP_SYS_EXIT call lockdep_sys_exit_thunk # define LOCKDEP_SYS_EXIT_IRQ \ TRACE_IRQS_ON; \ sti; \ call lockdep_sys_exit_thunk; \ cli; \ TRACE_IRQS_OFF; + # else -# define LOCKDEP_SYS_EXIT \ +# define LOCKDEP_SYS_EXIT \ pushl %eax; \ pushl %ecx; \ pushl %edx; \ + pushfl; \ + sti; \ call lockdep_sys_exit; \ + popfl; \ popl %edx; \ popl %ecx; \ popl %eax; + # define LOCKDEP_SYS_EXIT_IRQ # endif #else # define LOCKDEP_SYS_EXIT # define LOCKDEP_SYS_EXIT_IRQ #endif -#endif /* __ASSEMBLY__ */ +#endif /* __ASSEMBLY__ */ #endif diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h index 95ff2d7f553f..28622abbd84b 100644 --- a/arch/x86/include/asm/thread_info.h +++ b/arch/x86/include/asm/thread_info.h @@ -52,10 +52,15 @@ struct task_struct; #include #include +#include struct thread_info { unsigned long flags; /* low level flags */ u32 status; /* thread synchronous flags */ +#ifdef CONFIG_IPIPE + unsigned long ipipe_flags; + struct ipipe_threadinfo ipipe_data; +#endif }; #define INIT_THREAD_INFO(tsk) \ @@ -153,6 +158,15 @@ struct thread_info { #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY) #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW) +/* ti->ipipe_flags */ +#define TIP_HEAD 0 /* Runs in head domain */ +#define TIP_NOTIFY 1 /* Notify head domain about kernel events */ +#define TIP_MAYDAY 2 /* MAYDAY call is pending */ + +#define _TIP_HEAD (1 << TIP_HEAD) +#define _TIP_NOTIFY (1 << TIP_NOTIFY) +#define _TIP_MAYDAY (1 << TIP_MAYDAY) + #define STACK_WARN (THREAD_SIZE/8) /* diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index 4137f7ba0f88..3d8a0fb3ae7a 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile @@ -75,6 +75,7 @@ obj-y += reboot.o obj-$(CONFIG_X86_MSR) += msr.o obj-$(CONFIG_X86_CPUID) += cpuid.o obj-$(CONFIG_PCI) += early-quirks.o +obj-$(CONFIG_IPIPE) += ipipe.o apm-y := apm_32.o obj-$(CONFIG_APM) += apm.o obj-$(CONFIG_SMP) += smp.o diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c index 2e64178f284d..e7a95a22aa4b 100644 --- a/arch/x86/kernel/apic/apic.c +++ b/arch/x86/kernel/apic/apic.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -269,10 +270,10 @@ void native_apic_icr_write(u32 low, u32 id) { unsigned long flags; - local_irq_save(flags); + flags = hard_local_irq_save(); apic_write(APIC_ICR2, SET_APIC_DEST_FIELD(id)); apic_write(APIC_ICR, low); - local_irq_restore(flags); + hard_local_irq_restore(flags); } u64 native_apic_icr_read(void) @@ -482,16 +483,20 @@ static int lapic_next_deadline(unsigned long delta, static int lapic_timer_shutdown(struct clock_event_device *evt) { + unsigned long flags; unsigned int v; /* Lapic used as dummy for broadcast ? */ if (evt->features & CLOCK_EVT_FEAT_DUMMY) return 0; + flags = hard_local_irq_save(); v = apic_read(APIC_LVTT); v |= (APIC_LVT_MASKED | LOCAL_TIMER_VECTOR); apic_write(APIC_LVTT, v); apic_write(APIC_TMICT, 0); + hard_local_irq_restore(flags); + return 0; } @@ -526,6 +531,17 @@ static void lapic_timer_broadcast(const struct cpumask *mask) #endif } +#ifdef CONFIG_IPIPE +static void lapic_itimer_ack(void) +{ + __ack_APIC_irq(); +} + +static DEFINE_PER_CPU(struct ipipe_timer, lapic_itimer) = { + .irq = ipipe_apic_vector_irq(LOCAL_TIMER_VECTOR), + .ack = lapic_itimer_ack, +}; +#endif /* CONFIG_IPIPE */ /* * The local apic timer can be used for any function which is CPU local. @@ -656,6 +672,16 @@ static void setup_APIC_timer(void) memcpy(levt, &lapic_clockevent, sizeof(*levt)); levt->cpumask = cpumask_of(smp_processor_id()); +#ifdef CONFIG_IPIPE + if (!(lapic_clockevent.features & CLOCK_EVT_FEAT_DUMMY)) + levt->ipipe_timer = this_cpu_ptr(&lapic_itimer); + else { + static atomic_t once = ATOMIC_INIT(-1); + if (atomic_inc_and_test(&once)) + printk(KERN_INFO + "I-pipe: cannot use LAPIC as a tick device\n"); + } +#endif /* CONFIG_IPIPE */ if (this_cpu_has(X86_FEATURE_TSC_DEADLINE_TIMER)) { levt->name = "lapic-deadline"; @@ -1199,7 +1225,7 @@ void lapic_shutdown(void) if (!boot_cpu_has(X86_FEATURE_APIC) && !apic_from_smp_config()) return; - local_irq_save(flags); + flags = hard_local_irq_save(); #ifdef CONFIG_X86_32 if (!enabled_via_apicbase) @@ -1209,7 +1235,7 @@ void lapic_shutdown(void) disable_local_APIC(); - local_irq_restore(flags); + hard_local_irq_restore(flags); } /** @@ -1411,7 +1437,7 @@ void setup_local_APIC(void) value = apic_read(APIC_ISR + i*0x10); for (j = 31; j >= 0; j--) { if (value & (1<> 1)); if (v & (1 << (vector & 0x1f))) - ack_APIC_irq(); + __ack_APIC_irq(); inc_irq_stat(irq_spurious_count); @@ -2474,12 +2500,12 @@ static int lapic_suspend(void) apic_pm_state.apic_cmci = apic_read(APIC_LVTCMCI); #endif - local_irq_save(flags); + flags = hard_local_irq_save(); disable_local_APIC(); irq_remapping_disable(); - local_irq_restore(flags); + hard_local_irq_restore(flags); return 0; } @@ -2492,7 +2518,7 @@ static void lapic_resume(void) if (!apic_pm_state.active) return; - local_irq_save(flags); + flags = hard_local_irq_save(); /* * IO-APIC and PIC have their own resume routines. @@ -2550,7 +2576,7 @@ static void lapic_resume(void) irq_remapping_reenable(x2apic_mode); - local_irq_restore(flags); + hard_local_irq_restore(flags); } /* diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c index dedd5a41ba48..61fdc0d54584 100644 --- a/arch/x86/kernel/apic/apic_flat_64.c +++ b/arch/x86/kernel/apic/apic_flat_64.c @@ -57,9 +57,9 @@ static void _flat_send_IPI_mask(unsigned long mask, int vector) { unsigned long flags; - local_irq_save(flags); + flags = hard_local_irq_save(); __default_send_IPI_dest_field(mask, vector, apic->dest_logical); - local_irq_restore(flags); + hard_local_irq_restore(flags); } static void flat_send_IPI_mask(const struct cpumask *cpumask, int vector) diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c index 96a8a68f9c79..a003624e33cf 100644 --- a/arch/x86/kernel/apic/io_apic.c +++ b/arch/x86/kernel/apic/io_apic.c @@ -77,7 +77,7 @@ #define for_each_irq_pin(entry, head) \ list_for_each_entry(entry, &head, list) -static DEFINE_RAW_SPINLOCK(ioapic_lock); +static IPIPE_DEFINE_RAW_SPINLOCK(ioapic_lock); static DEFINE_MUTEX(ioapic_mutex); static unsigned int ioapic_dynirq_base; static int ioapic_initialized; @@ -465,13 +465,19 @@ static void io_apic_sync(struct irq_pin_list *entry) readl(&io_apic->data); } +static inline void __mask_ioapic(struct mp_chip_data *data) +{ + io_apic_modify_irq(data, ~0, IO_APIC_REDIR_MASKED, &io_apic_sync); +} + static void mask_ioapic_irq(struct irq_data *irq_data) { struct mp_chip_data *data = irq_data->chip_data; unsigned long flags; raw_spin_lock_irqsave(&ioapic_lock, flags); - io_apic_modify_irq(data, ~0, IO_APIC_REDIR_MASKED, &io_apic_sync); + ipipe_lock_irq(irq_data->irq); + __mask_ioapic(data); raw_spin_unlock_irqrestore(&ioapic_lock, flags); } @@ -487,6 +493,7 @@ static void unmask_ioapic_irq(struct irq_data *irq_data) raw_spin_lock_irqsave(&ioapic_lock, flags); __unmask_ioapic(data); + ipipe_unlock_irq(irq_data->irq); raw_spin_unlock_irqrestore(&ioapic_lock, flags); } @@ -530,14 +537,20 @@ static void __eoi_ioapic_pin(int apic, int pin, int vector) } } -static void eoi_ioapic_pin(int vector, struct mp_chip_data *data) +static void _eoi_ioapic_pin(int vector, struct mp_chip_data *data) { - unsigned long flags; struct irq_pin_list *entry; - raw_spin_lock_irqsave(&ioapic_lock, flags); for_each_irq_pin(entry, data->irq_2_pin) __eoi_ioapic_pin(entry->apic, entry->pin, vector); +} + +void eoi_ioapic_pin(int vector, struct mp_chip_data *data) +{ + unsigned long flags; + + raw_spin_lock_irqsave(&ioapic_lock, flags); + _eoi_ioapic_pin(vector, data); raw_spin_unlock_irqrestore(&ioapic_lock, flags); } @@ -1202,6 +1215,19 @@ EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector); static struct irq_chip ioapic_chip, ioapic_ir_chip; +#ifdef CONFIG_IPIPE +static void startup_legacy_irq(unsigned irq) +{ + unsigned long flags; + legacy_pic->mask(irq); + flags = hard_local_irq_save(); + __ipipe_unlock_irq(irq); + hard_local_irq_restore(flags); +} +#else /* !CONFIG_IPIPE */ +#define startup_legacy_irq(irq) legacy_pic->mask(irq) +#endif /* !CONFIG_IPIPE */ + static void __init setup_IO_APIC_irqs(void) { unsigned int ioapic, pin; @@ -1652,11 +1678,12 @@ static unsigned int startup_ioapic_irq(struct irq_data *data) raw_spin_lock_irqsave(&ioapic_lock, flags); if (irq < nr_legacy_irqs()) { - legacy_pic->mask(irq); + startup_legacy_irq(irq); if (legacy_pic->irq_pending(irq)) was_pending = 1; } __unmask_ioapic(data->chip_data); + ipipe_unlock_irq(irq); raw_spin_unlock_irqrestore(&ioapic_lock, flags); return was_pending; @@ -1664,7 +1691,7 @@ static unsigned int startup_ioapic_irq(struct irq_data *data) atomic_t irq_mis_count; -#ifdef CONFIG_GENERIC_PENDING_IRQ +#if defined(CONFIG_GENERIC_PENDING_IRQ) || (defined(CONFIG_IPIPE) && defined(CONFIG_SMP)) static bool io_apic_level_ack_pending(struct mp_chip_data *data) { struct irq_pin_list *entry; @@ -1746,9 +1773,9 @@ static void ioapic_ack_level(struct irq_data *irq_data) { struct irq_cfg *cfg = irqd_cfg(irq_data); unsigned long v; - bool masked; int i; - +#ifndef CONFIG_IPIPE + bool masked; irq_complete_move(cfg); masked = ioapic_irqd_mask(irq_data); @@ -1806,6 +1833,24 @@ static void ioapic_ack_level(struct irq_data *irq_data) } ioapic_irqd_unmask(irq_data, masked); +#else /* CONFIG_IPIPE */ + /* + * Prevent low priority IRQs grabbed by high priority domains + * from being delayed, waiting for a high priority interrupt + * handler running in a low priority domain to complete. + * This code assumes hw interrupts off. + */ + i = cfg->vector; + v = apic_read(APIC_TMR + ((i & ~0x1f) >> 1)); + if (unlikely(!(v & (1 << (i & 0x1f))))) { + /* IO-APIC erratum: see comment above. */ + atomic_inc(&irq_mis_count); + raw_spin_lock(&ioapic_lock); + _eoi_ioapic_pin(cfg->vector, irq_data->chip_data); + raw_spin_unlock(&ioapic_lock); + } + __ack_APIC_irq(); +#endif /* CONFIG_IPIPE */ } static void ioapic_ir_ack_level(struct irq_data *irq_data) @@ -1818,7 +1863,7 @@ static void ioapic_ir_ack_level(struct irq_data *irq_data) * intr-remapping table entry. Hence for the io-apic * EOI we use the pin number. */ - ack_APIC_irq(); + __ack_APIC_irq(); eoi_ioapic_pin(data->entry.vector, data); } @@ -1847,6 +1892,69 @@ static int ioapic_set_affinity(struct irq_data *irq_data, return ret; } +#ifdef CONFIG_IPIPE + +#ifdef CONFIG_SMP + +void move_xxapic_irq(struct irq_data *irq_data) +{ + unsigned int irq = irq_data->irq; + struct irq_desc *desc = irq_to_desc(irq); + struct mp_chip_data *data = irq_data->chip_data; + struct irq_cfg *cfg = irqd_cfg(irq_data); + + if (desc->handle_irq == &handle_edge_irq) { + raw_spin_lock(&desc->lock); + irq_complete_move(cfg); + irq_move_irq(irq_data); + raw_spin_unlock(&desc->lock); + } else if (desc->handle_irq == &handle_fasteoi_irq) { + raw_spin_lock(&desc->lock); + irq_complete_move(cfg); + if (unlikely(irqd_is_setaffinity_pending(irq_data))) { + if (!io_apic_level_ack_pending(data)) + irq_move_masked_irq(irq_data); + unmask_ioapic_irq(irq_data); + } + raw_spin_unlock(&desc->lock); + } else + WARN_ON_ONCE(1); +} + +#endif /* CONFIG_SMP */ + +static void hold_ioapic_irq(struct irq_data *irq_data) +{ + struct mp_chip_data *data = irq_data->chip_data; + + raw_spin_lock(&ioapic_lock); + __mask_ioapic(data); + raw_spin_unlock(&ioapic_lock); + ioapic_ack_level(irq_data); +} + +static void hold_ioapic_ir_irq(struct irq_data *irq_data) +{ + struct mp_chip_data *data = irq_data->chip_data; + + raw_spin_lock(&ioapic_lock); + __mask_ioapic(data); + raw_spin_unlock(&ioapic_lock); + ioapic_ir_ack_level(irq_data); +} + +static void release_ioapic_irq(struct irq_data *irq_data) +{ + struct mp_chip_data *data = irq_data->chip_data; + unsigned long flags; + + raw_spin_lock_irqsave(&ioapic_lock, flags); + __unmask_ioapic(data); + raw_spin_unlock_irqrestore(&ioapic_lock, flags); +} + +#endif /* CONFIG_IPIPE */ + static struct irq_chip ioapic_chip __read_mostly = { .name = "IO-APIC", .irq_startup = startup_ioapic_irq, @@ -1856,6 +1964,13 @@ static struct irq_chip ioapic_chip __read_mostly = { .irq_eoi = ioapic_ack_level, .irq_set_affinity = ioapic_set_affinity, .irq_retrigger = irq_chip_retrigger_hierarchy, +#ifdef CONFIG_IPIPE +#ifdef CONFIG_SMP + .irq_move = move_xxapic_irq, +#endif + .irq_hold = hold_ioapic_irq, + .irq_release = release_ioapic_irq, +#endif .flags = IRQCHIP_SKIP_SET_WAKE, }; @@ -1868,6 +1983,13 @@ static struct irq_chip ioapic_ir_chip __read_mostly = { .irq_eoi = ioapic_ir_ack_level, .irq_set_affinity = ioapic_set_affinity, .irq_retrigger = irq_chip_retrigger_hierarchy, +#ifdef CONFIG_IPIPE +#ifdef CONFIG_SMP + .irq_move = move_xxapic_irq, +#endif + .irq_hold = hold_ioapic_ir_irq, + .irq_release = release_ioapic_irq, +#endif .flags = IRQCHIP_SKIP_SET_WAKE, }; @@ -1899,23 +2021,29 @@ static inline void init_IO_APIC_traps(void) static void mask_lapic_irq(struct irq_data *data) { - unsigned long v; + unsigned long v, flags; + flags = hard_cond_local_irq_save(); + ipipe_lock_irq(data->irq); v = apic_read(APIC_LVT0); apic_write(APIC_LVT0, v | APIC_LVT_MASKED); + hard_cond_local_irq_restore(flags); } static void unmask_lapic_irq(struct irq_data *data) { - unsigned long v; + unsigned long v, flags; + flags = hard_cond_local_irq_save(); v = apic_read(APIC_LVT0); apic_write(APIC_LVT0, v & ~APIC_LVT_MASKED); + ipipe_unlock_irq(data->irq); + hard_cond_local_irq_restore(flags); } static void ack_lapic_irq(struct irq_data *data) { - ack_APIC_irq(); + __ack_APIC_irq(); } static struct irq_chip lapic_chip __read_mostly = { @@ -1923,6 +2051,9 @@ static struct irq_chip lapic_chip __read_mostly = { .irq_mask = mask_lapic_irq, .irq_unmask = unmask_lapic_irq, .irq_ack = ack_lapic_irq, +#if defined(CONFIG_IPIPE) && defined(CONFIG_SMP) + .irq_move = move_xxapic_irq, +#endif }; static void lapic_register_intr(int irq) @@ -2042,7 +2173,7 @@ static inline void __init check_timer(void) /* * get/set the timer IRQ vector: */ - legacy_pic->mask(0); + startup_legacy_irq(0); /* * As IRQ0 is to be enabled in the 8259A, the virtual @@ -2139,6 +2270,10 @@ static inline void __init check_timer(void) "...trying to set up timer as Virtual Wire IRQ...\n"); lapic_register_intr(0); +#if defined(CONFIG_IPIPE) && defined(CONFIG_X86_64) + irq_to_desc(0)->ipipe_ack = __ipipe_ack_edge_irq; + irq_to_desc(0)->ipipe_end = __ipipe_nop_irq; +#endif apic_write(APIC_LVT0, APIC_DM_FIXED | cfg->vector); /* Fixed mode */ legacy_pic->unmask(0); @@ -2147,7 +2282,7 @@ static inline void __init check_timer(void) goto out; } local_irq_disable(); - legacy_pic->mask(0); + startup_legacy_irq(0); apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_FIXED | cfg->vector); apic_printk(APIC_QUIET, KERN_INFO "..... failed.\n"); @@ -2513,6 +2648,21 @@ int acpi_get_override_irq(u32 gsi, int *trigger, int *polarity) return 0; } +#ifdef CONFIG_IPIPE +unsigned int __ipipe_get_ioapic_irq_vector(int irq) +{ + if (irq >= IPIPE_FIRST_APIC_IRQ && irq < IPIPE_NR_XIRQS) + return ipipe_apic_irq_vector(irq); + else if (irq == IRQ_MOVE_CLEANUP_VECTOR) + return irq; + else { + if (irq_cfg(irq) == NULL) + return ISA_IRQ_VECTOR(irq); /* Assume ISA. */ + return irq_cfg(irq)->vector; + } +} +#endif /* CONFIG_IPIPE */ + /* * This function currently is only a helper for the i386 smp boot process where * we need to reprogram the ioredtbls to cater for the cpus which have come online @@ -2950,7 +3100,7 @@ int mp_irqdomain_alloc(struct irq_domain *domain, unsigned int virq, mp_setup_entry(cfg, data, info->ioapic_entry); mp_register_handler(virq, data->trigger); if (virq < nr_legacy_irqs()) - legacy_pic->mask(virq); + startup_legacy_irq(virq); local_irq_restore(flags); apic_printk(APIC_VERBOSE, KERN_DEBUG diff --git a/arch/x86/kernel/apic/ipi.c b/arch/x86/kernel/apic/ipi.c index 82f9244fe61f..39d9bc68361b 100644 --- a/arch/x86/kernel/apic/ipi.c +++ b/arch/x86/kernel/apic/ipi.c @@ -28,7 +28,9 @@ void __default_send_IPI_shortcut(unsigned int shortcut, int vector, unsigned int * to the APIC. */ unsigned int cfg; + unsigned long flags; + flags = hard_cond_local_irq_save(); /* * Wait for idle. */ @@ -43,6 +45,8 @@ void __default_send_IPI_shortcut(unsigned int shortcut, int vector, unsigned int * Send the IPI. The write to APIC_ICR fires this off. */ native_apic_mem_write(APIC_ICR, cfg); + + hard_cond_local_irq_restore(flags); } /* @@ -51,8 +55,9 @@ void __default_send_IPI_shortcut(unsigned int shortcut, int vector, unsigned int */ void __default_send_IPI_dest_field(unsigned int mask, int vector, unsigned int dest) { - unsigned long cfg; + unsigned long cfg, flags; + flags = hard_cond_local_irq_save(); /* * Wait for idle. */ @@ -76,6 +81,8 @@ void __default_send_IPI_dest_field(unsigned int mask, int vector, unsigned int d * Send the IPI. The write to APIC_ICR fires this off. */ native_apic_mem_write(APIC_ICR, cfg); + + hard_cond_local_irq_restore(flags); } void default_send_IPI_single_phys(int cpu, int vector) @@ -98,12 +105,12 @@ void default_send_IPI_mask_sequence_phys(const struct cpumask *mask, int vector) * to an arbitrary mask, so I do a unicast to each CPU instead. * - mbligh */ - local_irq_save(flags); + flags = hard_local_irq_save(); for_each_cpu(query_cpu, mask) { __default_send_IPI_dest_field(per_cpu(x86_cpu_to_apicid, query_cpu), vector, APIC_DEST_PHYSICAL); } - local_irq_restore(flags); + hard_local_irq_restore(flags); } void default_send_IPI_mask_allbutself_phys(const struct cpumask *mask, @@ -115,14 +122,14 @@ void default_send_IPI_mask_allbutself_phys(const struct cpumask *mask, /* See Hack comment above */ - local_irq_save(flags); + flags = hard_local_irq_save(); for_each_cpu(query_cpu, mask) { if (query_cpu == this_cpu) continue; __default_send_IPI_dest_field(per_cpu(x86_cpu_to_apicid, query_cpu), vector, APIC_DEST_PHYSICAL); } - local_irq_restore(flags); + hard_local_irq_restore(flags); } /* @@ -147,12 +154,12 @@ void default_send_IPI_mask_sequence_logical(const struct cpumask *mask, * should be modified to do 1 message per cluster ID - mbligh */ - local_irq_save(flags); + flags = hard_local_irq_save(); for_each_cpu(query_cpu, mask) __default_send_IPI_dest_field( early_per_cpu(x86_cpu_to_logical_apicid, query_cpu), vector, apic->dest_logical); - local_irq_restore(flags); + hard_local_irq_restore(flags); } void default_send_IPI_mask_allbutself_logical(const struct cpumask *mask, @@ -164,7 +171,7 @@ void default_send_IPI_mask_allbutself_logical(const struct cpumask *mask, /* See Hack comment above */ - local_irq_save(flags); + flags = hard_local_irq_save(); for_each_cpu(query_cpu, mask) { if (query_cpu == this_cpu) continue; @@ -172,7 +179,7 @@ void default_send_IPI_mask_allbutself_logical(const struct cpumask *mask, early_per_cpu(x86_cpu_to_logical_apicid, query_cpu), vector, apic->dest_logical); } - local_irq_restore(flags); + hard_local_irq_restore(flags); } /* @@ -186,10 +193,10 @@ void default_send_IPI_mask_logical(const struct cpumask *cpumask, int vector) if (!mask) return; - local_irq_save(flags); + flags = hard_local_irq_save(); WARN_ON(mask & ~cpumask_bits(cpu_online_mask)[0]); __default_send_IPI_dest_field(mask, vector, apic->dest_logical); - local_irq_restore(flags); + hard_local_irq_restore(flags); } void default_send_IPI_allbutself(int vector) diff --git a/arch/x86/kernel/apic/msi.c b/arch/x86/kernel/apic/msi.c index f10e7f93b0e2..5a1006a8e66d 100644 --- a/arch/x86/kernel/apic/msi.c +++ b/arch/x86/kernel/apic/msi.c @@ -65,6 +65,9 @@ static struct irq_chip pci_msi_controller = { .irq_ack = irq_chip_ack_parent, .irq_retrigger = irq_chip_retrigger_hierarchy, .irq_compose_msi_msg = irq_msi_compose_msg, +#if defined(CONFIG_IPIPE) && defined(CONFIG_SMP) + .irq_move = move_xxapic_irq, +#endif .flags = IRQCHIP_SKIP_SET_WAKE, }; @@ -163,6 +166,9 @@ static struct irq_chip pci_msi_ir_controller = { .irq_ack = irq_chip_ack_parent, .irq_retrigger = irq_chip_retrigger_hierarchy, .irq_set_vcpu_affinity = irq_chip_set_vcpu_affinity_parent, +#if defined(CONFIG_IPIPE) && defined(CONFIG_SMP) + .irq_move = move_xxapic_irq, +#endif .flags = IRQCHIP_SKIP_SET_WAKE, }; @@ -205,6 +211,9 @@ static struct irq_chip dmar_msi_controller = { .irq_retrigger = irq_chip_retrigger_hierarchy, .irq_compose_msi_msg = irq_msi_compose_msg, .irq_write_msi_msg = dmar_msi_write_msg, +#if defined(CONFIG_IPIPE) && defined(CONFIG_SMP) + .irq_move = move_xxapic_irq, +#endif .flags = IRQCHIP_SKIP_SET_WAKE, }; @@ -302,6 +311,9 @@ static struct irq_chip hpet_msi_controller __ro_after_init = { .irq_retrigger = irq_chip_retrigger_hierarchy, .irq_compose_msi_msg = irq_msi_compose_msg, .irq_write_msi_msg = hpet_msi_write_msg, +#if defined(CONFIG_IPIPE) && defined(CONFIG_SMP) + .irq_move = move_xxapic_irq, +#endif .flags = IRQCHIP_SKIP_SET_WAKE, }; diff --git a/arch/x86/kernel/apic/vector.c b/arch/x86/kernel/apic/vector.c index b958082c74a7..032f667c75b3 100644 --- a/arch/x86/kernel/apic/vector.c +++ b/arch/x86/kernel/apic/vector.c @@ -31,7 +31,7 @@ struct apic_chip_data { struct irq_domain *x86_vector_domain; EXPORT_SYMBOL_GPL(x86_vector_domain); -static DEFINE_RAW_SPINLOCK(vector_lock); +static IPIPE_DEFINE_RAW_SPINLOCK(vector_lock); static cpumask_var_t vector_cpumask, vector_searchmask, searched_cpumask; static struct irq_chip lapic_controller; #ifdef CONFIG_X86_IO_APIC @@ -487,8 +487,13 @@ static void __setup_vector_irq(int cpu) vector = data->cfg.vector; per_cpu(vector_irq, cpu)[vector] = desc; } + /* Mark the free vectors */ for (vector = 0; vector < NR_VECTORS; ++vector) { + /* I-pipe requires initialized vector_irq for system vectors */ + if (test_bit(vector, used_vectors)) + continue; + desc = per_cpu(vector_irq, cpu)[vector]; if (IS_ERR_OR_NULL(desc)) continue; @@ -506,7 +511,9 @@ void setup_vector_irq(int cpu) { int irq; +#ifndef CONFIG_IPIPE lockdep_assert_held(&vector_lock); +#endif /* * On most of the platforms, legacy PIC delivers the interrupts on the * boot cpu. But there are certain platforms where PIC interrupts are @@ -536,9 +543,11 @@ static int apic_retrigger_irq(struct irq_data *irq_data) void apic_ack_edge(struct irq_data *data) { +#ifndef CONFIG_IPIPE irq_complete_move(irqd_cfg(data)); irq_move_irq(data); - ack_APIC_irq(); +#endif /* !CONFIG_IPIPE */ + __ack_APIC_irq(); } static int apic_set_affinity(struct irq_data *irq_data, diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c index e216cf3d64d2..e258b974640e 100644 --- a/arch/x86/kernel/apic/x2apic_cluster.c +++ b/arch/x86/kernel/apic/x2apic_cluster.c @@ -44,7 +44,7 @@ __x2apic_send_IPI_mask(const struct cpumask *mask, int vector, int apic_dest) x2apic_wrmsr_fence(); - local_irq_save(flags); + flags = hard_local_irq_save(); this_cpu = smp_processor_id(); @@ -81,7 +81,7 @@ __x2apic_send_IPI_mask(const struct cpumask *mask, int vector, int apic_dest) cpumask_andnot(ipi_mask_ptr, ipi_mask_ptr, cpus_in_cluster_ptr); } - local_irq_restore(flags); + hard_local_irq_restore(flags); } static void x2apic_send_IPI_mask(const struct cpumask *mask, int vector) diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c index b94d35320f85..af41eac09077 100644 --- a/arch/x86/kernel/apic/x2apic_phys.c +++ b/arch/x86/kernel/apic/x2apic_phys.c @@ -54,7 +54,7 @@ __x2apic_send_IPI_mask(const struct cpumask *mask, int vector, int apic_dest) x2apic_wrmsr_fence(); - local_irq_save(flags); + flags = hard_local_irq_save(); this_cpu = smp_processor_id(); for_each_cpu(query_cpu, mask) { @@ -63,7 +63,7 @@ __x2apic_send_IPI_mask(const struct cpumask *mask, int vector, int apic_dest) __x2apic_send_IPI_dest(per_cpu(x86_cpu_to_apicid, query_cpu), vector, APIC_DEST_PHYSICAL); } - local_irq_restore(flags); + hard_local_irq_restore(flags); } static void x2apic_send_IPI_mask(const struct cpumask *mask, int vector) diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c index 76417a9aab73..10b751560ab0 100644 --- a/arch/x86/kernel/asm-offsets.c +++ b/arch/x86/kernel/asm-offsets.c @@ -38,6 +38,9 @@ void common(void) { BLANK(); OFFSET(TASK_TI_flags, task_struct, thread_info.flags); +#ifdef CONFIG_IPIPE + OFFSET(TASK_TI_ipipe, task_struct, thread_info.ipipe_flags); +#endif OFFSET(TASK_addr_limit, task_struct, thread.addr_limit); BLANK(); diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 7d2a7890a823..89a3d3f7b5ae 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1505,6 +1505,7 @@ void syscall_init(void) DEFINE_PER_CPU(struct orig_ist, orig_ist); static DEFINE_PER_CPU(unsigned long, debug_stack_addr); +#ifndef CONFIG_IPIPE DEFINE_PER_CPU(int, debug_stack_usage); int is_debug_stack(unsigned long addr) @@ -1532,6 +1533,7 @@ void debug_stack_reset(void) load_current_idt(); } NOKPROBE_SYMBOL(debug_stack_reset); +#endif /* !CONFIG_IPIPE */ #else /* CONFIG_X86_64 */ diff --git a/arch/x86/kernel/idt.c b/arch/x86/kernel/idt.c index 38c3d5790970..8cecfe939f20 100644 --- a/arch/x86/kernel/idt.c +++ b/arch/x86/kernel/idt.c @@ -116,6 +116,10 @@ static const __initconst struct idt_data apic_idts[] = { INTG(CALL_FUNCTION_SINGLE_VECTOR, call_function_single_interrupt), INTG(IRQ_MOVE_CLEANUP_VECTOR, irq_move_cleanup_interrupt), INTG(REBOOT_VECTOR, reboot_interrupt), +#ifdef CONFIG_IPIPE + INTG(IPIPE_RESCHEDULE_VECTOR, ipipe_reschedule_interrupt), + INTG(IPIPE_CRITICAL_VECTOR, ipipe_critical_interrupt), +#endif #endif #ifdef CONFIG_X86_THERMAL_VECTOR @@ -146,6 +150,9 @@ static const __initconst struct idt_data apic_idts[] = { #endif INTG(SPURIOUS_APIC_VECTOR, spurious_interrupt), INTG(ERROR_APIC_VECTOR, error_interrupt), +#ifdef CONFIG_IPIPE + INTG(IPIPE_HRTIMER_VECTOR, ipipe_hrtimer_interrupt), +#endif #endif }; @@ -310,9 +317,16 @@ void __init idt_setup_apic_and_irq_gates(void) { int i = FIRST_EXTERNAL_VECTOR; void *entry; + unsigned int __maybe_unused cpu; idt_setup_from_table(idt_table, apic_idts, ARRAY_SIZE(apic_idts), true); +#ifdef CONFIG_SMP + for_each_possible_cpu(cpu) + per_cpu(vector_irq, cpu)[IRQ_MOVE_CLEANUP_VECTOR] = + irq_to_desc(IRQ_MOVE_CLEANUP_VECTOR); +#endif + for_each_clear_bit_from(i, used_vectors, FIRST_SYSTEM_VECTOR) { entry = irq_entries_start + 8 * (i - FIRST_EXTERNAL_VECTOR); set_intr_gate(i, entry); diff --git a/arch/x86/kernel/ipipe.c b/arch/x86/kernel/ipipe.c new file mode 100644 index 000000000000..6ee39d76e173 --- /dev/null +++ b/arch/x86/kernel/ipipe.c @@ -0,0 +1,409 @@ +/* -*- linux-c -*- + * linux/arch/x86/kernel/ipipe.c + * + * Copyright (C) 2002-2012 Philippe Gerum. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139, + * USA; either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * Architecture-dependent I-PIPE support for x86. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef CONFIG_X86_LOCAL_APIC +#include +#include +#include +#include +#ifdef CONFIG_X86_IO_APIC +#include +#endif /* CONFIG_X86_IO_APIC */ +#include +#endif /* CONFIG_X86_LOCAL_APIC */ +#include +#include +#include +#include +#include + +void smp_apic_timer_interrupt(struct pt_regs *regs); +void smp_kvm_posted_intr_wakeup_ipi(struct pt_regs *regs); +void smp_kvm_posted_intr_ipi(struct pt_regs *regs); +void smp_spurious_interrupt(struct pt_regs *regs); +void smp_error_interrupt(struct pt_regs *regs); +void smp_x86_platform_ipi(struct pt_regs *regs); +void smp_irq_work_interrupt(struct pt_regs *regs); +void smp_reschedule_interrupt(struct pt_regs *regs); +void smp_call_function_interrupt(struct pt_regs *regs); +void smp_call_function_single_interrupt(struct pt_regs *regs); +void smp_irq_move_cleanup_interrupt(struct pt_regs *regs); +void smp_reboot_interrupt(void); +void smp_thermal_interrupt(void); +void smp_threshold_interrupt(void); + +DEFINE_PER_CPU(unsigned long, __ipipe_cr2); +EXPORT_PER_CPU_SYMBOL_GPL(__ipipe_cr2); + +int ipipe_get_sysinfo(struct ipipe_sysinfo *info) +{ + info->sys_nr_cpus = num_online_cpus(); + info->sys_cpu_freq = __ipipe_cpu_freq; + info->sys_hrtimer_irq = per_cpu(ipipe_percpu.hrtimer_irq, 0); + info->sys_hrtimer_freq = __ipipe_hrtimer_freq; + info->sys_hrclock_freq = __ipipe_hrclock_freq; + + return 0; +} +EXPORT_SYMBOL_GPL(ipipe_get_sysinfo); + +#ifdef CONFIG_X86_UV +asmlinkage void uv_bau_message_interrupt(struct pt_regs *regs); +#endif +#ifdef CONFIG_X86_MCE_THRESHOLD +asmlinkage void smp_threshold_interrupt(void); +#endif + +static void __ipipe_do_IRQ(unsigned int irq, void *cookie) +{ + void (*handler)(struct pt_regs *regs); + struct pt_regs *regs; + + regs = raw_cpu_ptr(&ipipe_percpu.tick_regs); + regs->orig_ax = ~__ipipe_get_irq_vector(irq); + regs->sp = current_stack_pointer; /* stack_overflow_check(). */ + handler = (typeof(handler))cookie; + handler(regs); +} + +#ifdef CONFIG_X86_LOCAL_APIC + +static void __ipipe_noack_apic(struct irq_desc *desc) +{ +} + +static void __ipipe_ack_apic(struct irq_desc *desc) +{ + __ack_APIC_irq(); +} + +#endif /* CONFIG_X86_LOCAL_APIC */ + +/* + * __ipipe_enable_pipeline() -- We are running on the boot CPU, hw + * interrupts are off, and secondary CPUs are still lost in space. + */ +void __init __ipipe_enable_pipeline(void) +{ + unsigned int irq; + +#ifdef CONFIG_X86_LOCAL_APIC + + /* Map the APIC system vectors. */ + + ipipe_request_irq(ipipe_root_domain, + ipipe_apic_vector_irq(LOCAL_TIMER_VECTOR), + __ipipe_do_IRQ, smp_apic_timer_interrupt, + __ipipe_ack_apic); + +#ifdef CONFIG_HAVE_KVM + ipipe_request_irq(ipipe_root_domain, + ipipe_apic_vector_irq(POSTED_INTR_WAKEUP_VECTOR), + __ipipe_do_IRQ, smp_kvm_posted_intr_wakeup_ipi, + __ipipe_ack_apic); + + ipipe_request_irq(ipipe_root_domain, + ipipe_apic_vector_irq(POSTED_INTR_VECTOR), + __ipipe_do_IRQ, smp_kvm_posted_intr_ipi, + __ipipe_ack_apic); +#endif + +#if defined(CONFIG_X86_MCE_AMD) && defined(CONFIG_X86_64) + ipipe_request_irq(ipipe_root_domain, + ipipe_apic_vector_irq(DEFERRED_ERROR_VECTOR), + __ipipe_do_IRQ, smp_deferred_error_interrupt, + __ipipe_ack_apic); +#endif + +#ifdef CONFIG_X86_UV + ipipe_request_irq(ipipe_root_domain, + ipipe_apic_vector_irq(UV_BAU_MESSAGE), + __ipipe_do_IRQ, uv_bau_message_interrupt, + __ipipe_ack_apic); +#endif /* CONFIG_X86_UV */ + + ipipe_request_irq(ipipe_root_domain, + ipipe_apic_vector_irq(SPURIOUS_APIC_VECTOR), + __ipipe_do_IRQ, smp_spurious_interrupt, + __ipipe_noack_apic); + + ipipe_request_irq(ipipe_root_domain, + ipipe_apic_vector_irq(ERROR_APIC_VECTOR), + __ipipe_do_IRQ, smp_error_interrupt, + __ipipe_ack_apic); + +#ifdef CONFIG_X86_THERMAL_VECTOR + ipipe_request_irq(ipipe_root_domain, + ipipe_apic_vector_irq(THERMAL_APIC_VECTOR), + __ipipe_do_IRQ, smp_thermal_interrupt, + __ipipe_ack_apic); +#endif /* CONFIG_X86_THERMAL_VECTOR */ + +#ifdef CONFIG_X86_MCE_THRESHOLD + ipipe_request_irq(ipipe_root_domain, + ipipe_apic_vector_irq(THRESHOLD_APIC_VECTOR), + __ipipe_do_IRQ, smp_threshold_interrupt, + __ipipe_ack_apic); +#endif /* CONFIG_X86_MCE_THRESHOLD */ + + ipipe_request_irq(ipipe_root_domain, + ipipe_apic_vector_irq(X86_PLATFORM_IPI_VECTOR), + __ipipe_do_IRQ, smp_x86_platform_ipi, + __ipipe_ack_apic); + + /* + * We expose two high priority APIC vectors the head domain + * may use respectively for hires timing and SMP rescheduling. + * We should never receive them in the root domain. + */ + ipipe_request_irq(ipipe_root_domain, + ipipe_apic_vector_irq(IPIPE_HRTIMER_VECTOR), + __ipipe_do_IRQ, smp_spurious_interrupt, + __ipipe_ack_apic); + + ipipe_request_irq(ipipe_root_domain, + ipipe_apic_vector_irq(IPIPE_RESCHEDULE_VECTOR), + __ipipe_do_IRQ, smp_spurious_interrupt, + __ipipe_ack_apic); + +#ifdef CONFIG_IRQ_WORK + ipipe_request_irq(ipipe_root_domain, + ipipe_apic_vector_irq(IRQ_WORK_VECTOR), + __ipipe_do_IRQ, smp_irq_work_interrupt, + __ipipe_ack_apic); +#endif /* CONFIG_IRQ_WORK */ + +#endif /* CONFIG_X86_LOCAL_APIC */ + +#ifdef CONFIG_SMP + ipipe_request_irq(ipipe_root_domain, + ipipe_apic_vector_irq(RESCHEDULE_VECTOR), + __ipipe_do_IRQ, smp_reschedule_interrupt, + __ipipe_ack_apic); + + ipipe_request_irq(ipipe_root_domain, + ipipe_apic_vector_irq(CALL_FUNCTION_VECTOR), + __ipipe_do_IRQ, smp_call_function_interrupt, + __ipipe_ack_apic); + + ipipe_request_irq(ipipe_root_domain, + ipipe_apic_vector_irq(CALL_FUNCTION_SINGLE_VECTOR), + __ipipe_do_IRQ, smp_call_function_single_interrupt, + __ipipe_ack_apic); + + ipipe_request_irq(ipipe_root_domain, + IRQ_MOVE_CLEANUP_VECTOR, + __ipipe_do_IRQ, smp_irq_move_cleanup_interrupt, + __ipipe_ack_apic); + + ipipe_request_irq(ipipe_root_domain, + ipipe_apic_vector_irq(REBOOT_VECTOR), + __ipipe_do_IRQ, smp_reboot_interrupt, + __ipipe_ack_apic); +#endif /* CONFIG_SMP */ + + /* + * Finally, request the remaining ISA and IO-APIC + * interrupts. Interrupts which have already been requested + * will just beget a silent -EBUSY error, that's ok. + */ + for (irq = 0; irq < IPIPE_NR_XIRQS; irq++) + ipipe_request_irq(ipipe_root_domain, irq, + __ipipe_do_IRQ, do_IRQ, + NULL); +} + +#ifdef CONFIG_SMP + +void ipipe_set_irq_affinity(unsigned int irq, cpumask_t cpumask) +{ + if (ipipe_virtual_irq_p(irq) || + irq_get_chip(irq)->irq_set_affinity == NULL) + return; + + cpumask_and(&cpumask, &cpumask, cpu_online_mask); + if (WARN_ON_ONCE(cpumask_empty(&cpumask))) + return; + + irq_get_chip(irq)->irq_set_affinity(irq_get_irq_data(irq), &cpumask, true); +} +EXPORT_SYMBOL_GPL(ipipe_set_irq_affinity); + +void ipipe_send_ipi(unsigned int ipi, cpumask_t cpumask) +{ + unsigned long flags; + + flags = hard_local_irq_save(); + + cpumask_clear_cpu(ipipe_processor_id(), &cpumask); + if (likely(!cpumask_empty(&cpumask))) + apic->send_IPI_mask(&cpumask, ipipe_apic_irq_vector(ipi)); + + hard_local_irq_restore(flags); +} +EXPORT_SYMBOL_GPL(ipipe_send_ipi); + +void __ipipe_hook_critical_ipi(struct ipipe_domain *ipd) +{ + unsigned int ipi = IPIPE_CRITICAL_IPI; + + ipd->irqs[ipi].ackfn = __ipipe_ack_apic; + ipd->irqs[ipi].handler = __ipipe_do_critical_sync; + ipd->irqs[ipi].cookie = NULL; + ipd->irqs[ipi].control = IPIPE_HANDLE_MASK|IPIPE_STICKY_MASK; +} + +#endif /* CONFIG_SMP */ + +void __ipipe_halt_root(int use_mwait) +{ + struct ipipe_percpu_domain_data *p; + + /* Emulate sti+hlt sequence over the root domain. */ + + hard_local_irq_disable(); + + p = ipipe_this_cpu_root_context(); + + trace_hardirqs_on(); + __clear_bit(IPIPE_STALL_FLAG, &p->status); + + if (unlikely(__ipipe_ipending_p(p))) { + __ipipe_sync_stage(); + hard_local_irq_enable(); + } else { +#ifdef CONFIG_IPIPE_TRACE_IRQSOFF + ipipe_trace_end(0x8000000E); +#endif /* CONFIG_IPIPE_TRACE_IRQSOFF */ + if (use_mwait) + asm volatile("sti; .byte 0x0f, 0x01, 0xc9;" + :: "a" (0), "c" (0)); + else + asm volatile("sti; hlt": : :"memory"); + } +} +EXPORT_SYMBOL_GPL(__ipipe_halt_root); + +int __ipipe_handle_irq(struct pt_regs *regs) +{ + struct ipipe_percpu_data *p = __ipipe_raw_cpu_ptr(&ipipe_percpu); + int irq, vector = regs->orig_ax, flags = 0; + struct pt_regs *tick_regs; + struct irq_desc *desc; + + if (likely(vector < 0)) { + vector = ~vector; + if (vector >= FIRST_SYSTEM_VECTOR) + irq = ipipe_apic_vector_irq(vector); + else { + desc = __this_cpu_read(vector_irq[vector]); + BUG_ON(IS_ERR_OR_NULL(desc)); + irq = irq_desc_get_irq(desc); + } + } else { /* Software-generated. */ + irq = vector; + flags = IPIPE_IRQF_NOACK; + } + + ipipe_trace_irqbegin(irq, regs); + + /* + * Given our deferred dispatching model for regular IRQs, we + * only record CPU regs for the last timer interrupt, so that + * the timer handler charges CPU times properly. It is assumed + * that no other interrupt handler cares for such information. + */ + if (irq == p->hrtimer_irq || p->hrtimer_irq == -1) { + tick_regs = &p->tick_regs; + tick_regs->flags = regs->flags; + tick_regs->cs = regs->cs; + tick_regs->ip = regs->ip; + tick_regs->bp = regs->bp; +#ifdef CONFIG_X86_64 + tick_regs->ss = regs->ss; + tick_regs->sp = regs->sp; +#endif + if (!__ipipe_root_p) + tick_regs->flags &= ~X86_EFLAGS_IF; + } + + __ipipe_dispatch_irq(irq, flags); + + if (user_mode(regs) && ipipe_test_thread_flag(TIP_MAYDAY)) + __ipipe_call_mayday(regs); + + ipipe_trace_irqend(irq, regs); + + if (!__ipipe_root_p || + test_bit(IPIPE_STALL_FLAG, &__ipipe_root_status)) + return 0; + + return 1; +} + +void __ipipe_arch_share_current(int flags) +{ + struct task_struct *p = current; + + /* + * Setup a clean extended FPU state for kernel threads. + */ + if (p->mm == NULL) + memcpy(&p->thread.fpu.state, + &init_fpstate, fpu_kernel_xstate_size); +} + +struct task_struct *__switch_to(struct task_struct *prev_p, + struct task_struct *next_p); +EXPORT_SYMBOL_GPL(do_munmap); +EXPORT_SYMBOL_GPL(__switch_to); +EXPORT_SYMBOL_GPL(show_stack); + +#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK) +EXPORT_SYMBOL(tasklist_lock); +#endif /* CONFIG_SMP || CONFIG_DEBUG_SPINLOCK */ + +#if defined(CONFIG_CC_STACKPROTECTOR) && defined(CONFIG_X86_64) +EXPORT_PER_CPU_SYMBOL_GPL(irq_stack_union); +#endif diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c index 3c2326b59820..8ad974529024 100644 --- a/arch/x86/kernel/irq.c +++ b/arch/x86/kernel/irq.c @@ -48,7 +48,7 @@ void ack_bad_irq(unsigned int irq) * completely. * But only ack when the APIC is enabled -AK */ - ack_APIC_irq(); + __ack_APIC_irq(); } #define irq_stats(x) (&per_cpu(irq_stat, x)) @@ -220,12 +220,13 @@ __visible unsigned int __irq_entry do_IRQ(struct pt_regs *regs) /* high bit used in ret_from_ code */ unsigned vector = ~regs->orig_ax; + desc = __this_cpu_read(vector_irq[vector]); + __ipipe_move_root_irq(desc); entering_irq(); /* entering_irq() tells RCU that we're not quiescent. Check it. */ RCU_LOCKDEP_WARN(!rcu_is_watching(), "IRQ failed to wake up RCU"); - desc = __this_cpu_read(vector_irq[vector]); if (!handle_irq(desc, regs)) { ack_APIC_irq(); diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c index 988a98f34c66..705335bea02a 100644 --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -518,7 +518,7 @@ bool xen_set_default_idle(void) void stop_this_cpu(void *dummy) { - local_irq_disable(); + hard_local_irq_disable(); /* * Remove this CPU: */ @@ -614,7 +614,11 @@ static __cpuidle void mwait_idle(void) __monitor((void *)¤t_thread_info()->flags, 0, 0); if (!need_resched()) +#ifdef CONFIG_IPIPE + __ipipe_halt_root(1); +#else __sti_mwait(0, 0); +#endif else local_irq_enable(); trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, smp_processor_id()); @@ -674,6 +678,10 @@ void __init arch_post_acpi_subsys_init(void) if (!boot_cpu_has(X86_FEATURE_NONSTOP_TSC)) mark_tsc_unstable("TSC halt in AMD C1E"); pr_info("System has AMD C1E enabled\n"); +#ifdef CONFIG_IPIPE + pr_info("I-pipe: will not be able to use LAPIC as a tick device\n" + "I-pipe: disable C1E power state in your BIOS\n"); +#endif } static int __init idle_setup(char *str) diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c index 04adc8d60aed..30f972f33e9d 100644 --- a/arch/x86/kernel/smp.c +++ b/arch/x86/kernel/smp.c @@ -247,10 +247,10 @@ static void native_stop_other_cpus(int wait) } finish: - local_irq_save(flags); + flags = hard_local_irq_save(); disable_local_APIC(); mcheck_cpu_clear(this_cpu_ptr(&cpu_info)); - local_irq_restore(flags); + hard_local_irq_restore(flags); } /* diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index 30447d210f37..57ce9135dd97 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -1097,7 +1097,7 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle) { int apicid = apic->cpu_present_to_apicid(cpu); int cpu0_nmi_registered = 0; - unsigned long flags; + unsigned long vflags, rflags; int err, ret = 0; WARN_ON(irqs_disabled()); @@ -1146,9 +1146,11 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle) * Check TSC synchronization with the AP (keep irqs disabled * while doing so): */ - local_irq_save(flags); + local_irq_save(vflags); + rflags = hard_local_irq_save(); check_tsc_sync_source(cpu); - local_irq_restore(flags); + hard_local_irq_restore(rflags); + local_irq_restore(vflags); while (!cpu_online(cpu)) { cpu_relax(); -- 2.14.4