4.14.71/x86_64 port (split series)
cover 4.14.71/x86_64 port (split series)
This is a port of the interrupt pipeline to kernel 4.14.71 for x86_64, 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.
The topmost patch disables native 32bit support which was not ported. Support for x32 and ia32 emulation ABIs over long mode is still there and working though.
[1] https://www.xenomai.org/pipermail/xenomai/2018-July/039302.html
[2] https://git.xenomai.org/ipipe-noarch
Henning Schild (2):
x86: fix include for drivers
x86: ipipe fpu support
Philippe Gerum (30):
x86: lockdep: ipipe: make the logic aware of interrupt pipelining
x86: ipipe: add pipeline core
x86: context_tracking: disable if CONFIG_IPIPE
x86: paravirt: disable if CONFIG_IPIPE
x86/iommu: enable interrupt pipelining
x86/htirq: ipipe: enable interrupt pipelining x86/i8259: ipipe: enable interrupt pipelining
x86/mm: enable PTE pinning
x86: ipipe: share context switch code with head domain x86/mtrr: ipipe: protect against preemption from head stage x86/tsc: ipipe: keep calibration accurate
x86: ipipe: notify about GTOD update
x86/kgdb: ipipe: enable support from head domain x86/vm86_32: ipipe: protect against preemption from head domain x86/kvm: ipipe: enable shared control with head domain x86/mmx32: ipipe: use slow copy from head domain x86/nmi: ipipe: disallow user copy from head domain
x86: ipipe: route traps to co-kernel
x86: ipipe: route syscalls to co-kernel
x86/irq: ipipe: map the cleanup vector to a legit IRQ number x86/fpu: ipipe: add inline qualifier to kernel_fpu_*() helpers
x86: ipipe: fix interrupt state in syscall routing x86/irq: ipipe: reconcile lockdep tracing with virtual IRQ state x86/mm: ipipe: fix lockdep tracing upon PF
x86/msi: ipipe: advertise pipelining support
x86: ipipe: fix stack overflow detection
x86: ipipe: restrict WARN_ON_IN_IRQ() to the root domain
x86: ipipe: remove 32bit support from shared context switch code
x86: ipipe: drop (obsolete) declarations
x86: ipipe: disable 32bit support
arch/x86/Kconfig | 10 +- arch/x86/entry/common.c | 98 +++++- arch/x86/entry/entry_64.S | 145 +++++++-- arch/x86/entry/thunk_32.S | 1 + arch/x86/entry/thunk_64.S | 1 + arch/x86/entry/vsyscall/vsyscall_gtod.c | 4 + 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/fpu/internal.h | 20 ++ arch/x86/include/asm/i8259.h | 2 +- arch/x86/include/asm/ipipe.h | 73 +++++ arch/x86/include/asm/ipipe_base.h | 151 +++++++++ arch/x86/include/asm/irq_vectors.h | 17 +- arch/x86/include/asm/irqflags.h | 198 +++++++++++- arch/x86/include/asm/mmu_context.h | 6 +- arch/x86/include/asm/thread_info.h | 14 + arch/x86/include/asm/tsc.h | 1 + arch/x86/include/asm/uaccess.h | 3 +- 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/htirq.c | 5 +- arch/x86/kernel/apic/io_apic.c | 182 ++++++++++- arch/x86/kernel/apic/ipi.c | 29 +- arch/x86/kernel/apic/msi.c | 20 +- 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/cpu/mtrr/cyrix.c | 12 +- arch/x86/kernel/cpu/mtrr/generic.c | 12 +- arch/x86/kernel/fpu/core.c | 58 ++-- arch/x86/kernel/i8259.c | 31 +- arch/x86/kernel/idt.c | 24 ++ arch/x86/kernel/ipipe.c | 528 ++++++++++++++++++++++++++++++++ arch/x86/kernel/irq.c | 5 +- arch/x86/kernel/irq_64.c | 12 +- arch/x86/kernel/kgdb.c | 4 +- arch/x86/kernel/process.c | 20 +- arch/x86/kernel/process_32.c | 2 +- arch/x86/kernel/process_64.c | 2 +- arch/x86/kernel/smp.c | 4 +- arch/x86/kernel/smpboot.c | 8 +- arch/x86/kernel/traps.c | 9 +- arch/x86/kernel/tsc.c | 12 +- arch/x86/kernel/vm86_32.c | 4 + arch/x86/kvm/svm.c | 5 +- arch/x86/kvm/vmx.c | 13 +- arch/x86/kvm/x86.c | 66 +++- arch/x86/lib/mmx_32.c | 2 +- arch/x86/lib/usercopy.c | 3 +- arch/x86/mm/fault.c | 53 ++++ arch/x86/mm/tlb.c | 14 +- drivers/iommu/irq_remapping.c | 2 +- drivers/pci/htirq.c | 2 +- include/linux/gpio.h | 1 + 58 files changed, 1787 insertions(+), 192 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
Signature · 1 line
2.14.4
PATCH 1/32 x86: lockdep: ipipe: make the logic aware of interrupt pipelining
Call trace_hardirqs_on_virt() on kernel exit path to userland. This makes sure that the interrupt state is only tracked for the root domain (i.e. by testing the virtual interrupt disable flag when applicable).
--- arch/x86/entry/entry_64.S | 2 +- arch/x86/entry/thunk_32.S | 1 + arch/x86/entry/thunk_64.S | 1 + arch/x86/include/asm/irqflags.h | 6 ++++++ 4 files changed, 9 insertions(+), 1 deletion(-)
arch/x86/entry/entry_64.S +1 -1
@@ -57,7 +57,7 @@ END(native_usergs_sysret64) #ifdef CONFIG_TRACE_IRQFLAGS bt $9, EFLAGS(%rsp) /* interrupts off? */ jnc 1f - TRACE_IRQS_ON + TRACE_IRQS_ON_VIRT 1: #endif .endm
arch/x86/entry/thunk_32.S +1 -0
@@ -31,6 +31,7 @@ #ifdef CONFIG_TRACE_IRQFLAGS THUNK trace_hardirqs_on_thunk,trace_hardirqs_on_caller,1 + THUNK trace_hardirqs_on_virt_thunk,trace_hardirqs_on_virt_caller,1 THUNK trace_hardirqs_off_thunk,trace_hardirqs_off_caller,1 #endif
arch/x86/entry/thunk_64.S +1 -0
@@ -40,6 +40,7 @@ #ifdef CONFIG_TRACE_IRQFLAGS THUNK trace_hardirqs_on_thunk,trace_hardirqs_on_caller,1 + THUNK trace_hardirqs_on_virt_thunk,trace_hardirqs_on_virt_caller,1 THUNK trace_hardirqs_off_thunk,trace_hardirqs_off_caller,1 #endif
arch/x86/include/asm/irqflags.h +6 -0
@@ -175,9 +175,15 @@ static inline int arch_irqs_disabled(void)#ifdef __ASSEMBLY__#ifdef CONFIG_TRACE_IRQFLAGS # define TRACE_IRQS_ON call trace_hardirqs_on_thunk; +#ifdef CONFIG_IPIPE +# define TRACE_IRQS_ON_VIRT call trace_hardirqs_on_virt_thunk; +#else +# define TRACE_IRQS_ON_VIRT TRACE_IRQS_ON +#endif # define TRACE_IRQS_OFF call trace_hardirqs_off_thunk;#else # define TRACE_IRQS_ON +# define TRACE_IRQS_ON_VIRT # define TRACE_IRQS_OFF #endif #ifdef CONFIG_DEBUG_LOCK_ALLOC
Signature · 1 line
2.14.4
PATCH 2/32 x86: ipipe: add pipeline core
In reply to Philippe GerumIntroduce 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
arch/x86/Kconfig +5 -0
@@ -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
arch/x86/entry/common.c +19 -3
@@ -17,6 +17,7 @@#include <linux/tracehook.h> #include <linux/audit.h> #include <linux/seccomp.h> +#include <linux/unistd.h> #include <linux/signal.h> #include <linux/export.h> #include <linux/context_tracking.h>
@@ -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. */
arch/x86/entry/entry_64.S +54 -2
127 lines not on this page · raw message
arch/x86/include/asm/apic.h +10 -0
@@ -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
arch/x86/include/asm/debugreg.h +1 -1
@@ -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 ) {
arch/x86/include/asm/desc.h +1 -1
@@ -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 ) {
arch/x86/include/asm/ipipe.h new file +68 -0
68 lines not on this page · raw message
arch/x86/include/asm/ipipe_base.h new file +151 -0
151 lines not on this page · raw message
arch/x86/include/asm/irq_vectors.h +11 -6
@@ -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
arch/x86/include/asm/irqflags.h +189 -3
255 lines not on this page · raw message
arch/x86/include/asm/thread_info.h +14 -0
@@ -52,10 +52,15 @@struct task_struct ;#include <asm/cpufeature.h> #include <linux/atomic.h> +#include <ipipe/thread_info.h> 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)/*
arch/x86/kernel/Makefile +1 -0
@@ -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
arch/x86/kernel/apic/apic.c +36 -10
134 lines not on this page · raw message
arch/x86/kernel/apic/apic_flat_64.c +2 -2
@@ -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)
arch/x86/kernel/apic/io_apic.c +166 -16
332 lines not on this page · raw message
arch/x86/kernel/apic/ipi.c +18 -11
@@ -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)
arch/x86/kernel/apic/msi.c +12 -0
@@ -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, };
arch/x86/kernel/apic/vector.c +11 -2
@@ -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,
arch/x86/kernel/apic/x2apic_cluster.c +2 -2
@@ -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)
arch/x86/kernel/apic/x2apic_phys.c +2 -2
@@ -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)
arch/x86/kernel/asm-offsets.c +3 -0
@@ -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 ();
arch/x86/kernel/cpu/common.c +2 -0
@@ -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 */
arch/x86/kernel/idt.c +14 -0
@@ -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);
arch/x86/kernel/ipipe.c new file +409 -0
409 lines not on this page · raw message
arch/x86/kernel/irq.c +3 -2
@@ -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 ();
arch/x86/kernel/process.c +9 -1
@@ -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 elselocal_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)
arch/x86/kernel/smp.c +2 -2
@@ -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); }/*
arch/x86/kernel/smpboot.c +5 -3
@@ -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 ();
Signature · 1 line
2.14.4
PATCH 3/32 x86: 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/x86/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/Kconfig +1 -1
@@ -123,7 +123,7 @@ config X86 select HAVE_CC_STACKPROTECTOR select HAVE_CMPXCHG_DOUBLE select HAVE_CMPXCHG_LOCAL - select HAVE_CONTEXT_TRACKING if X86_64 + select HAVE_CONTEXT_TRACKING if X86_64 && !IPIPE select HAVE_COPY_THREAD_TLS select HAVE_C_RECORDMCOUNT select HAVE_DEBUG_KMEMLEAK
Signature · 1 line
2.14.4
PATCH 4/32 x86: paravirt: disable if CONFIG_IPIPE
In reply to Philippe GerumSome changes introduced by the basic interrupt pipeline code for x86 break the paravirtualization code. Disable the latter.
--- arch/x86/Kconfig | 1 + 1 file changed, 1 insertion(+)
arch/x86/Kconfig +1 -0
@@ -743,6 +743,7 @@ if HYPERVISOR_GUEST config PARAVIRT bool "Enable paravirtualization code" + depends on !IPIPE ---help--- This changes the kernel so it can modify itself when it is run under a hypervisor, potentially improving performance significantly
Signature · 1 line
2.14.4
PATCH 5/32 x86/iommu: enable interrupt pipelining
In reply to Philippe GerumFix up the IRQ remapping code from the IOMMU controller driver in order to actually ack the APIC upon incoming edge interrupts. A previous change made ack_APIC_irq() a null placeholder, since the original interrupt handlers calling it should not ack the APIC anymore, once pipelining is in place.
We must revert this change in the acknowledge handler though, since the pipeline core needs it to issue such ack.
--- drivers/iommu/irq_remapping.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/irq_remapping.c +1 -1
@@ -158,7 +158,7 @@ void panic_if_irq_remap(const char *msg)void ir_ack_apic_edge (struct irq_data *data) { -ack_APIC_irq (); +__ack_APIC_irq (); }/**
Signature · 1 line
2.14.4
PATCH 6/32 x86/htirq: ipipe: enable interrupt pipelining
In reply to Philippe GerumThe Hypertransport handlers for masking/unmasking IRQs are invoked by the pipeline core for dealing with incoming PCI interrupts from an out-of-band context.
To this end, we have to turn the original spinlock into a hard pipeline lock for proper serialization.
In addition, make sure to fix up the HT irq_chip descriptor appropriately.
--- arch/x86/kernel/apic/htirq.c | 5 ++++- drivers/pci/htirq.c | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-)
arch/x86/kernel/apic/htirq.c +4 -1
@@ -59,7 +59,10 @@ static struct irq_chip ht_irq_chip = { .irq_ack = irq_chip_ack_parent, .irq_set_affinity = ht_set_affinity, .irq_retrigger = irq_chip_retrigger_hierarchy, - .flags = IRQCHIP_SKIP_SET_WAKE, +#if defined(CONFIG_IPIPE) && defined(CONFIG_SMP) + .irq_move = move_xxapic_irq, +#endif + .flags = IRQCHIP_SKIP_SET_WAKE|IRQCHIP_PIPELINE_SAFE, }; static int htirq_domain_alloc(struct irq_domain *domain, unsigned int virq,
drivers/pci/htirq.c +1 -1
@@ -22,7 +22,7 @@* With multiple simultaneous hypertransport irq devices it might pay * to make this more fine grained. But start with simple, stupid, and correct. */ -static DEFINE_SPINLOCK (ht_irq_lock); +static IPIPE_DEFINE_SPINLOCK (ht_irq_lock);void write_ht_irq_msg (unsigned int irq,struct ht_irq_msg *msg) {
Signature · 1 line
2.14.4
PATCH 7/32 x86/i8259: ipipe: enable interrupt pipelining
In reply to Philippe GerumFix up the legacy 8259 PIC driver to enable out-of-band calls from the pipeline core for acknowledging incoming IRQs.
--- arch/x86/include/asm/i8259.h | 2 +- arch/x86/kernel/i8259.c | 31 ++++++++++++++++++++++++------- 2 files changed, 25 insertions(+), 8 deletions(-)
arch/x86/include/asm/i8259.h +1 -1
@@ -26,7 +26,7 @@ extern unsigned int cached_irq_mask;#define SLAVE_ICW4_DEFAULT 0x01#define PIC_ICW4_AEOI 2 -extern raw_spinlock_t i8259A_lock; +IPIPE_DECLARE_RAW_SPINLOCK (i8259A_lock);/* the PIC may need a careful delay on some platforms, hence specific calls */ static inline unsigned char inb_pic (unsigned int port)
arch/x86/kernel/i8259.c +24 -7
@@ -33,7 +33,7 @@static void init_8259A (int auto_eoi);static int i8259A_auto_eoi; -DEFINE_RAW_SPINLOCK (i8259A_lock); +IPIPE_DEFINE_RAW_SPINLOCK (i8259A_lock);/* * 8259A PIC functions to handle ISA devices:
@@ -61,6 +61,7 @@ static void mask_8259A_irq(unsigned int irq)unsigned long flags;raw_spin_lock_irqsave (&i8259A_lock, flags); +ipipe_lock_irq (irq); cached_irq_mask |= mask;if (irq &8 )outb (cached_slave_mask,PIC_SLAVE_IMR );
@@ -76,15 +77,18 @@ static void disable_8259A_irq(struct irq_data *data)static void unmask_8259A_irq (unsigned int irq) { -unsigned int mask = ~(1 << irq); +unsigned int mask = (1 << irq);unsigned long flags;raw_spin_lock_irqsave (&i8259A_lock, flags); - cached_irq_mask &= mask; -if (irq &8 ) -outb (cached_slave_mask,PIC_SLAVE_IMR ); -else -outb (cached_master_mask,PIC_MASTER_IMR ); +if (cached_irq_mask & mask) { + cached_irq_mask &= ~mask; +if (irq &8 ) +outb (cached_slave_mask,PIC_SLAVE_IMR ); +else +outb (cached_master_mask,PIC_MASTER_IMR ); +ipipe_unlock_irq (irq); + }raw_spin_unlock_irqrestore (&i8259A_lock, flags); }
@@ -170,6 +174,18 @@ static void mask_and_ack_8259A(struct irq_data *data)*/ if (cached_irq_mask & irqmask) goto spurious_8259A_irq; +#ifdef CONFIG_IPIPE +if (irq ==0 ) { +/* +* Fast timer ack -- don't mask (unless supposedly +* spurious). We trace outb's in order to detect +* broken hardware inducing large delays. +*/ +outb (0x60 ,PIC_MASTER_CMD );/* Specific EOI to master. */ +raw_spin_unlock_irqrestore (&i8259A_lock, flags); +return ; + } +#endif /* CONFIG_IPIPE */ cached_irq_mask |= irqmask; handle_real_irq:
@@ -226,6 +242,7 @@ struct irq_chip i8259A_chip = { .irq_disable = disable_8259A_irq, .irq_unmask = enable_8259A_irq, .irq_mask_ack = mask_and_ack_8259A, + .flags = IRQCHIP_PIPELINE_SAFE, };static char irq_trigger[2 ];
Signature · 1 line
2.14.4
PATCH 8/32 x86/mm: enable PTE pinning
In reply to Philippe GerumAsk the generic pipeline core to call us for pre-loading page table entries upon ioremap/vmalloc, for preventing further minor faults accessing such memory due to PTE misses.
Revisit: a better way may be to make the code handling minor faults runnable safely and quickly from the head domain, by reorganizing a couple of code paths in the fault handler. All other I-pipe ports actually do just that.
--- arch/x86/Kconfig | 1 + arch/x86/mm/fault.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+)
arch/x86/Kconfig +1 -0
@@ -148,6 +148,7 @@ config X86 select HAVE_IPIPE_SUPPORT select HAVE_IPIPE_TRACER_SUPPORT select IPIPE_HAVE_SAFE_THREAD_INFO if IPIPE + select IPIPE_WANT_PTE_PINNING if IPIPE select HAVE_KERNEL_BZIP2 select HAVE_KERNEL_GZIP select HAVE_KERNEL_LZ4
arch/x86/mm/fault.c +47 -0
50 lines not on this page · raw message
Signature · 1 line
2.14.4
PATCH 9/32 x86: ipipe: share context switch code with 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/x86/include/asm/mmu_context.h | 6 +++++- arch/x86/kernel/process.c | 10 +++++++++- arch/x86/kernel/process_32.c | 7 ++++--- arch/x86/kernel/process_64.c | 2 +- arch/x86/mm/tlb.c | 14 ++++++++++---- 5 files changed, 29 insertions(+), 10 deletions(-)
arch/x86/include/asm/mmu_context.h +5 -1
@@ -177,7 +177,8 @@ static inline void switch_ldt(struct mm_struct *prev, struct mm_struct *next)load_mm_ldt (next);#endif -DEBUG_LOCKS_WARN_ON (preemptible ()); +DEBUG_LOCKS_WARN_ON (preemptible () && + (!IS_ENABLED (CONFIG_IPIPE ) || !hard_irqs_disabled ())); }void enter_lazy_tlb (struct mm_struct *mm,struct task_struct *tsk);
@@ -213,6 +214,9 @@ extern void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next, struct task_struct *tsk);#define switch_mm_irqs_off switch_mm_irqs_off +#define ipipe_switch_mm_head (prev, next, tsk) \ + switch_mm_irqs_off(prev, next, tsk) +#define activate_mm (prev, next) \ do { \ paravirt_activate_mm((prev), (next)); \
arch/x86/kernel/process.c +9 -1
@@ -114,8 +114,16 @@ void exit_thread(struct task_struct *tsk)if (bp) {struct tss_struct *tss = &per_cpu (cpu_tss_rw,get_cpu ()); - t->io_bitmap_ptr =NULL ; +/* +* The caller may be preempted via I-pipe: to make +* sure TIF_IO_BITMAP always denotes a valid I/O +* bitmap when set, we clear it _before_ the I/O +* bitmap pointer. No cache coherence issue ahead as +* migration is currently locked (the primary domain +* may never migrate either). +*/ clear_thread_flag (TIF_IO_BITMAP ); + t->io_bitmap_ptr =NULL ;/* * Careful, clear this in the TSS too: */
arch/x86/kernel/process_32.c +4 -3
@@ -233,12 +233,13 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p) *next = &next_p->thread;struct fpu *prev_fpu = &prev->fpu;struct fpu *next_fpu = &next->fpu; -int cpu =smp_processor_id (); +int cpu =raw_smp_processor_id ();struct tss_struct *tss = &per_cpu (cpu_tss_rw, cpu); +int slope =ipipe_get_domain_slope_hook (prev_p, next_p);/* never put a printk in __switch_to... printk() calls wake_up*() indirectly */ -switch_fpu_prepare (prev_fpu, cpu); +switch_fpu_prepare (prev_fpu, cpu, slot);/* * Save away %gs. No need to save %fs, as it was saved on the
@@ -299,7 +300,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)if (prev->gs | next->gs)lazy_load_gs (next->gs); -switch_fpu_finish (next_fpu, cpu); +switch_fpu_finish (next_fpu, cpu, slope);this_cpu_write (current_task, next_p);
arch/x86/kernel/process_64.c +1 -1
@@ -399,7 +399,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)struct thread_struct *next = &next_p->thread;struct fpu *prev_fpu = &prev->fpu;struct fpu *next_fpu = &next->fpu; -int cpu =smp_processor_id (); +int cpu =raw_smp_processor_id ();struct tss_struct *tss = &per_cpu (cpu_tss_rw, cpu); WARN_ON_ONCE(IS_ENABLED(CONFIG_DEBUG_ENTRY) &&
arch/x86/mm/tlb.c +10 -4
@@ -147,9 +147,9 @@ void switch_mm(struct mm_struct *prev, struct mm_struct *next, {unsigned long flags; -local_irq_save (flags); + flags =hard_local_irq_save ();switch_mm_irqs_off (prev, next, tsk); -local_irq_restore (flags); +hard_local_irq_restore (flags); }static void sync_current_stack_to_mm (struct mm_struct *mm)
@@ -185,7 +185,7 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next, {struct mm_struct *real_prev =this_cpu_read (cpu_tlbstate.loaded_mm);u16 prev_asid =this_cpu_read (cpu_tlbstate.loaded_mm_asid); -unsigned cpu =smp_processor_id (); +unsigned cpu =raw_smp_processor_id ();u64 next_tlb_gen;/*
@@ -197,8 +197,11 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next,* NB: leave_mm() calls us with prev == NULL and tsk == NULL. */ +WARN_ON_ONCE (IS_ENABLED (CONFIG_IPIPE_DEBUG_INTERNAL ) && + !hard_irqs_disabled ()); +/* We don't want flush_tlb_func_* to run concurrently with us. */ -if (IS_ENABLED (CONFIG_PROVE_LOCKING )) +if (!IS_ENABLED (CONFIG_IPIPE ) &&IS_ENABLED (CONFIG_PROVE_LOCKING ))WARN_ON_ONCE (!irqs_disabled ());/*
@@ -439,6 +442,7 @@ static void flush_tlb_func_common(const struct flush_tlb_info *f,u32 loaded_mm_asid =this_cpu_read (cpu_tlbstate.loaded_mm_asid);u64 mm_tlb_gen =atomic64_read (&loaded_mm->context.tlb_gen);u64 local_tlb_gen =this_cpu_read (cpu_tlbstate.ctxs[loaded_mm_asid].tlb_gen); +unsigned long flags;/* This code cannot presently handle being reentered. */ VM_WARN_ON (!irqs_disabled ());
@@ -456,7 +460,9 @@ static void flush_tlb_func_common(const struct flush_tlb_info *f,* garbage into our TLB. Since switching to init_mm is barely * slower than a minimal flush, just switch to init_mm. */ + flags =hard_cond_local_irq_save ();switch_mm_irqs_off (NULL , &init_mm,NULL ); +hard_cond_local_irq_restore (flags);return ; }
Signature · 1 line
2.14.4
PATCH 10/32 x86/mtrr: ipipe: protect against preemption from head stage
In reply to Philippe GerumWe don't want the co-kernel to get in the way while we are busy updating the MTRRs. Hard disable preemption around the critical sections.
--- arch/x86/kernel/cpu/mtrr/cyrix.c | 12 ++++++++++-- arch/x86/kernel/cpu/mtrr/generic.c | 12 +++++++----- 2 files changed, 17 insertions(+), 7 deletions(-)
arch/x86/kernel/cpu/mtrr/cyrix.c +10 -2
@@ -19,7 +19,7 @@ cyrix_get_arr(unsigned int reg, unsigned long *base, arr =CX86_ARR_BASE + (reg <<1 ) + reg;/* avoid multiplication by 3 */ -local_irq_save (flags); + flags =hard_local_irq_save (); ccr3 =getCx86 (CX86_CCR3 );setCx86 (CX86_CCR3 , (ccr3 &0x0f ) |0x10 );/* enable MAPEN */
@@ -29,7 +29,7 @@ cyrix_get_arr(unsigned int reg, unsigned long *base, rcr =getCx86 (CX86_RCR_BASE + reg);setCx86 (CX86_CCR3 , ccr3);/* disable MAPEN */ -local_irq_restore (flags); +hard_local_irq_restore (flags); shift = ((unsigned char *) base)[1 ] &0x0f ; *base >>=PAGE_SHIFT ;
@@ -179,6 +179,7 @@ static void cyrix_set_arr(unsigned int reg, unsigned long base, unsigned long size, mtrr_type type) {unsigned char arr, arr_type, arr_size; +unsigned long flags; arr =CX86_ARR_BASE + (reg <<1 ) + reg;/* avoid multiplication by 3 */
@@ -222,6 +223,8 @@ static void cyrix_set_arr(unsigned int reg, unsigned long base, } } + flags =hard_local_irq_save (); +prepare_set (); base <<=PAGE_SHIFT ;
@@ -231,6 +234,8 @@ static void cyrix_set_arr(unsigned int reg, unsigned long base,setCx86 (CX86_RCR_BASE + reg, arr_type);post_set (); + +hard_local_irq_restore (flags); } typedef struct {
@@ -248,8 +253,10 @@ static unsigned char ccr_state[7] = { 0, 0, 0, 0, 0, 0, 0 };static void cyrix_set_all (void ) { +unsigned long flags;int i; + flags =hard_local_irq_save ();prepare_set ();/* the CCRs are not contiguous */
@@ -264,6 +271,7 @@ static void cyrix_set_all(void) }post_set (); +hard_local_irq_restore (flags); }static const struct mtrr_ops cyrix_mtrr_ops = {
arch/x86/kernel/cpu/mtrr/generic.c +7 -5
@@ -785,7 +785,7 @@ static void generic_set_all(void)unsigned long mask, count;unsigned long flags; -local_irq_save (flags); + flags =hard_local_irq_save ();prepare_set ();/* Actually set the state */
@@ -795,7 +795,7 @@ static void generic_set_all(void)pat_init ();post_set (); -local_irq_restore (flags); +hard_local_irq_restore (flags);/* Use the atomic bitops to update the global mask */ for (count =0 ; count <sizeof mask *8 ; ++count) {
@@ -819,12 +819,13 @@ static void generic_set_all(void)static void generic_set_mtrr (unsigned int reg,unsigned long base,unsigned long size,mtrr_type type) { -unsigned long flags; +unsigned long rflags, vflags;struct mtrr_var_range *vr; vr = &mtrr_state.var_ranges[reg]; -local_irq_save (flags); +local_irq_save (vflags); + rflags =hard_local_irq_save ();prepare_set ();if (size ==0 ) {
@@ -845,7 +846,8 @@ static void generic_set_mtrr(unsigned int reg, unsigned long base, }post_set (); -local_irq_restore (flags); +hard_local_irq_restore (rflags); +local_irq_restore (vflags); } int generic_validate_add_page(unsigned long base, unsigned long size,
Signature · 1 line
2.14.4
PATCH 11/32 x86/tsc: ipipe: keep calibration accurate
In reply to Philippe GerumHard disable interrupts to keep the calibration accurate.
--- arch/x86/include/asm/tsc.h | 1 + arch/x86/kernel/tsc.c | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-)
arch/x86/include/asm/tsc.h +1 -0
@@ -15,6 +15,7 @@*/ typedef unsigned long long cycles_t ; +extern struct clocksource clocksource_tsc;extern unsigned int cpu_khz;extern unsigned int tsc_khz;
arch/x86/kernel/tsc.c +6 -6
@@ -683,9 +683,9 @@ unsigned long native_calibrate_cpu(void)if (fast_calibrate)return fast_calibrate; -local_irq_save (flags); + flags =hard_local_irq_save (); fast_calibrate =quick_pit_calibrate (); -local_irq_restore (flags); +hard_local_irq_restore (flags);if (fast_calibrate)return fast_calibrate;
@@ -728,11 +728,11 @@ unsigned long native_calibrate_cpu(void)* calibration, which will take at least 50ms, and * read the end value. */ -local_irq_save (flags); + flags =hard_local_irq_save (); tsc1 =tsc_read_refs (&ref1, hpet); tsc_pit_khz =pit_calibrate_tsc (latch, ms, loopmin); tsc2 =tsc_read_refs (&ref2, hpet); -local_irq_restore (flags); +hard_local_irq_restore (flags);/* Pick the lowest PIT TSC calibration so far */ tsc_pit_min =min (tsc_pit_min, tsc_pit_khz);
@@ -1006,7 +1006,7 @@ static void detect_art(void)/* clocksource code */ -static struct clocksource clocksource_tsc; +struct clocksource clocksource_tsc;static void tsc_resume (struct clocksource *cs) {
@@ -1058,7 +1058,7 @@ static void tsc_cs_tick_stable(struct clocksource *cs)/* * .mask MUST be CLOCKSOURCE_MASK(64). See comment above read_tsc() */ -static struct clocksource clocksource_tsc = { +struct clocksource clocksource_tsc = { .name ="tsc" , .rating =300 , .read = read_tsc,
Signature · 1 line
2.14.4
PATCH 12/32 x86: ipipe: notify about GTOD update
In reply to Philippe Gerum--- arch/x86/entry/vsyscall/vsyscall_gtod.c | 4 ++++ 1 file changed, 4 insertions(+)
arch/x86/entry/vsyscall/vsyscall_gtod.c +4 -0
@@ -14,6 +14,7 @@*/ #include <linux/timekeeper_internal.h> +#include <linux/ipipe_tickdev.h> #include <asm/vgtod.h> #include <asm/vvar.h>
@@ -75,4 +76,7 @@ void update_vsyscall(struct timekeeper *tk) }gtod_write_end (vdata); + +if (tk->tkr_mono.clock == &clocksource_tsc) +ipipe_update_hostrt (tk); }
Signature · 1 line
2.14.4
PATCH 13/32 x86/kgdb: ipipe: enable support from head domain
In reply to Philippe GerumMake sure the KGDB notifier can run over the head domain sanely by manipulating the hardware interrupt state (not the virtual one).
--- arch/x86/kernel/kgdb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/kgdb.c +2 -2
@@ -598,9 +598,9 @@ kgdb_notify(struct notifier_block *self, unsigned long cmd, void *ptr)unsigned long flags;int ret; -local_irq_save (flags); + flags =hard_local_irq_save (); ret =__kgdb_notify (ptr, cmd); -local_irq_restore (flags); +hard_local_irq_restore (flags);return ret; }
Signature · 1 line
2.14.4
PATCH 14/32 x86/vm86_32: ipipe: protect against preemption from head domain
In reply to Philippe Gerum--- arch/x86/kernel/vm86_32.c | 4 ++++ 1 file changed, 4 insertions(+)
arch/x86/kernel/vm86_32.c +4 -0
@@ -147,12 +147,14 @@ void save_v86_state(struct kernel_vm86_regs *regs, int retval) }preempt_disable (); +hard_cond_local_irq_disable (); tsk->thread.sp0 = vm86->saved_sp0; tsk->thread.sysenter_cs = __KERNEL_CS;update_sp0 (tsk);refresh_sysenter_cs (&tsk->thread); vm86->saved_sp0 =0 ;preempt_enable (); +hard_cond_local_irq_enable ();memcpy (®s->pt, &vm86->regs32,sizeof (struct pt_regs ));
@@ -365,6 +367,7 @@ static long do_sys_vm86(struct vm86plus_struct __user *user_vm86, bool plus) vm86->saved_sp0 = tsk->thread.sp0;lazy_save_gs (vm86->regs32.gs); +hard_cond_local_irq_disable ();/* make room for real-mode segments */ preempt_disable (); tsk->thread.sp0 +=16 ;
@@ -376,6 +379,7 @@ static long do_sys_vm86(struct vm86plus_struct __user *user_vm86, bool plus)update_sp0 (tsk);preempt_enable (); +hard_cond_local_irq_enable ();if (vm86->flags &VM86_SCREEN_BITMAP )mark_screen_rdonly (tsk->mm);
Signature · 1 line
2.14.4
PATCH 15/32 x86/kvm: ipipe: enable shared control with head domain
In reply to Philippe Gerum--- arch/x86/Kconfig | 1 + arch/x86/include/asm/ipipe.h | 5 ++++ arch/x86/kvm/svm.c | 5 ++-- arch/x86/kvm/vmx.c | 13 +++++++-- arch/x86/kvm/x86.c | 66 +++++++++++++++++++++++++++++++++++++------- 5 files changed, 76 insertions(+), 14 deletions(-)
arch/x86/Kconfig +1 -0
@@ -149,6 +149,7 @@ config X86 select HAVE_IPIPE_TRACER_SUPPORT select IPIPE_HAVE_SAFE_THREAD_INFO if IPIPE select IPIPE_WANT_PTE_PINNING if IPIPE + select IPIPE_HAVE_VM_NOTIFIER if IPIPE select HAVE_KERNEL_BZIP2 select HAVE_KERNEL_GZIP select HAVE_KERNEL_LZ4
arch/x86/include/asm/ipipe.h +5 -0
@@ -50,6 +50,11 @@ void __ipipe_enable_pipeline(void);#define __ipipe_root_tick_p (regs) ((regs)->flags & X86_EFLAGS_IF) +static inline void ipipe_notify_root_preemption (void ) +{ +__ipipe_notify_vm_preemption (); +} +#endif /* CONFIG_IPIPE */ #if defined(CONFIG_SMP ) && defined(CONFIG_IPIPE )
arch/x86/kvm/svm.c +3 -2
@@ -5075,7 +5075,7 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)*/ x86_spec_ctrl_set_guest (svm->spec_ctrl, svm->virt_spec_ctrl); -local_irq_enable (); +hard_local_irq_enable (); asmvolatile ( "push %%" _ASM_BP "; \n\t"
@@ -5201,7 +5201,7 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)reload_tss (vcpu); -local_irq_disable (); +hard_local_irq_disable ();x86_spec_ctrl_restore_host (svm->spec_ctrl, svm->virt_spec_ctrl);
@@ -5572,6 +5572,7 @@ static int svm_check_intercept(struct kvm_vcpu *vcpu,static void svm_handle_external_intr (struct kvm_vcpu *vcpu) { +hard_cond_local_irq_enable ();local_irq_enable ();/* * We must have an instruction with interrupts enabled, so
arch/x86/kvm/vmx.c +11 -2
@@ -2434,9 +2434,11 @@ static void __vmx_load_host_state(struct vcpu_vmx *vmx)static void vmx_load_host_state (struct vcpu_vmx *vmx) { -preempt_disable (); +unsigned long flags; + + flags =hard_preempt_disable ();__vmx_load_host_state (vmx); -preempt_enable (); +hard_preempt_enable (flags); }static void vmx_vcpu_pi_load (struct kvm_vcpu *vcpu,int cpu)
@@ -2809,6 +2811,7 @@ static void setup_msrs(struct vcpu_vmx *vmx) {int save_nmsrs, index; +hard_cond_local_irq_disable (); save_nmsrs =0 ;#ifdef CONFIG_X86_64 if (is_long_mode (&vmx->vcpu)) {
@@ -2838,6 +2841,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)move_msr_up (vmx, index, save_nmsrs++); vmx->save_nmsrs = save_nmsrs; +hard_cond_local_irq_enable ();if (cpu_has_vmx_msr_bitmap ())vmx_update_msr_bitmap (&vmx->vcpu);
@@ -10044,8 +10048,13 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id) cpu =get_cpu ();vmx_vcpu_load (&vmx->vcpu, cpu); vmx->vcpu.cpu = cpu; +#ifdef CONFIG_IPIPE + vmx->vcpu.ipipe_notifier.handler = __ipipe_handle_vm_preemption; +#endif err =vmx_vcpu_setup (vmx); +hard_cond_local_irq_disable ();vmx_vcpu_put (&vmx->vcpu); +hard_cond_local_irq_enable ();put_cpu ();if (err) goto free_vmcs;
arch/x86/kvm/x86.c +56 -10
130 lines not on this page · raw message
Signature · 1 line
2.14.4
PATCH 16/32 x86/mmx32: ipipe: use slow copy from head domain
In reply to Philippe GerumUsing the MMX unit from the head domain requires the co-kernel to deal with preemption of sections delimited by kernel_fpu_begin <-> kernel_fpu_end, which is a burden when it comes to scheduling its own fpu-enabled tasks in between. Branch to the generic memcpy instead.
--- arch/x86/lib/mmx_32.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/lib/mmx_32.c +1 -1
@@ -31,7 +31,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)void *p;int i; -if (unlikely (in_interrupt ())) +if (unlikely (!ipipe_root_p ||in_interrupt ()))return __memcpy (to, from, len); p = to;
Signature · 1 line
2.14.4
PATCH 17/32 x86/nmi: ipipe: disallow user copy from head domain
In reply to Philippe GerumCopying user memory from NMI context is deemed unsafe when the interrupt has preempted the head domain.
Revisit: why?
--- arch/x86/lib/usercopy.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/lib/usercopy.c +2 -1
@@ -5,6 +5,7 @@*/ #include <linux/uaccess.h> +#include <linux/ipipe.h> #include <linux/export.h> #include <asm/tlbflush.h>
@@ -18,7 +19,7 @@ copy_from_user_nmi(void *to, const void __user *from, unsigned long n) {unsigned long ret; -if (__range_not_ok (from, n,TASK_SIZE )) +if (!ipipe_root_p ||__range_not_ok (from, n,TASK_SIZE ))return n;if (!nmi_uaccess_okay ())
Signature · 1 line
2.14.4
PATCH 18/32 x86: 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/x86/entry/entry_64.S | 80 +++++++++++++++++++++-------- arch/x86/kernel/ipipe.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++ arch/x86/kernel/traps.c | 9 ++-- arch/x86/mm/fault.c | 4 ++ 4 files changed, 196 insertions(+), 24 deletions(-)
arch/x86/entry/entry_64.S +60 -20
@@ -899,7 +899,7 @@ ENTRY(switch_to_thread_stack) ret END(switch_to_thread_stack) -.macro idtentry sym do_sym has_error_code:req paranoid=0 shift_ist=-1 +.macro idtentry sym do_sym has_error_code:req paranoid=0 shift_ist=-1 trapnr=-1 ENTRY(\sym) UNWIND_HINT_IRET_REGS offset=\has_error_code*8
@@ -935,6 +935,21 @@ ENTRY(\sym) .endif .endif +#ifdef CONFIG_IPIPE + movq EFLAGS(%rsp), %r14 /* regs->flags */ + movq %rsp, %rdi /* pt_regs pointer */ + movl $\trapnr, %esi /* trap number */ + subq $8, %rsp + movq %rsp, %rdx /* &flags */ + call __ipipe_trap_prologue + popq %r13 + mov %rax, %r12 /* save propagation status */ + .if \paranoid == 0 /* paranoid may not skip handler */ + testl %eax, %eax + jg 98f /* skip regular handler if > 0 */ + .endif +#endif + movq %rsp, %rdi /* pt_regs pointer */ .if \has_error_code
@@ -950,6 +965,27 @@ ENTRY(\sym) call \do_sym +#ifdef CONFIG_IPIPE + testl %r12d, %r12d + jnz 97f + movq %rsp, %rdi /* pt_regs pointer */ + movq %r13, %rsi /* &flags from prologue */ + movq %r14, %rdx /* original regs->flags before fixup */ + call __ipipe_trap_epilogue +97: + .if \paranoid == 0 /* paranoid implies normal epilogue */ + testl %r12d, %r12d + jz 99f +98: + UNWIND_HINT_REGS + DISABLE_INTERRUPTS(CLBR_ANY) + testl %ebx, %ebx /* %ebx: return to kernel mode */ + jnz retint_kernel_early + jmp retint_user_early + .endif +99: +#endif + .if \shift_ist != -1 addq $EXCEPTION_STKSZ, CPU_TSS_IST(\shift_ist) .endif
@@ -986,19 +1022,19 @@ ENTRY(\sym) END(\sym) .endm -idtentry divide_error do_divide_error has_error_code=0 -idtentry overflow do_overflow has_error_code=0 -idtentry bounds do_bounds has_error_code=0 -idtentry invalid_op do_invalid_op has_error_code=0 -idtentry device_not_available do_device_not_available has_error_code=0 -idtentry double_fault do_double_fault has_error_code=1 paranoid=2 -idtentry coprocessor_segment_overrun do_coprocessor_segment_overrun has_error_code=0 -idtentry invalid_TSS do_invalid_TSS has_error_code=1 -idtentry segment_not_present do_segment_not_present has_error_code=1 -idtentry spurious_interrupt_bug do_spurious_interrupt_bug has_error_code=0 -idtentry coprocessor_error do_coprocessor_error has_error_code=0 -idtentry alignment_check do_alignment_check has_error_code=1 -idtentry simd_coprocessor_error do_simd_coprocessor_error has_error_code=0 +idtentry divide_error do_divide_error has_error_code=0 trapnr=0 +idtentry overflow do_overflow has_error_code=0 trapnr=4 +idtentry bounds do_bounds has_error_code=0 trapnr=5 +idtentry invalid_op do_invalid_op has_error_code=0 trapnr=6 +idtentry device_not_available do_device_not_available has_error_code=0 trapnr=7 +idtentry double_fault do_double_fault has_error_code=1 paranoid=2 trapnr=8 +idtentry coprocessor_segment_overrun do_coprocessor_segment_overrun has_error_code=0 trapnr=9 +idtentry invalid_TSS do_invalid_TSS has_error_code=1 trapnr=10 +idtentry segment_not_present do_segment_not_present has_error_code=1 trapnr=11 +idtentry spurious_interrupt_bug do_spurious_interrupt_bug has_error_code=0 trapnr=15 +idtentry coprocessor_error do_coprocessor_error has_error_code=0 trapnr=16 +idtentry alignment_check do_alignment_check has_error_code=1 trapnr=17 +idtentry simd_coprocessor_error do_simd_coprocessor_error has_error_code=0 trapnr=19 /*
@@ -1142,9 +1178,13 @@ apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \ hyperv_callback_vector hyperv_vector_handler #endif /* CONFIG_HYPERV */ +#ifdef CONFIG_IPIPE +idtentry debug do_debug has_error_code=0 paranoid=1 trapnr=1 +#else idtentry debug do_debug has_error_code=0 paranoid=1 shift_ist=DEBUG_STACK -idtentry int3 do_int3 has_error_code=0 -idtentry stack_segment do_stack_segment has_error_code=1 +#endif +idtentry int3 do_int3 has_error_code=0 trapnr=3 +idtentry stack_segment do_stack_segment has_error_code=1 trapnr=12 #ifdef CONFIG_XEN idtentry xennmi do_nmi has_error_code=0
@@ -1152,15 +1192,15 @@ idtentry xendebug do_debug has_error_code=0 idtentry xenint3 do_int3 has_error_code=0 #endif -idtentry general_protection do_general_protection has_error_code=1 -idtentry page_fault do_page_fault has_error_code=1 +idtentry general_protection do_general_protection has_error_code=1 trapnr=13 +idtentry page_fault do_page_fault has_error_code=1 trapnr=14 #ifdef CONFIG_KVM_GUEST -idtentry async_page_fault do_async_page_fault has_error_code=1 +idtentry async_page_fault do_async_page_fault has_error_code=1 trapnr=14 #endif #ifdef CONFIG_X86_MCE -idtentry machine_check do_mce has_error_code=0 paranoid=1 +idtentry machine_check do_mce has_error_code=0 paranoid=1 trapnr=18 #endif /*
arch/x86/kernel/ipipe.c +127 -0
133 lines not on this page · raw message
arch/x86/kernel/traps.c +5 -4
@@ -14,6 +14,7 @@#include <linux/context_tracking.h> #include <linux/interrupt.h> +#include <linux/ipipe.h> #include <linux/kallsyms.h> #include <linux/spinlock.h> #include <linux/kprobes.h>
@@ -76,13 +77,13 @@ DECLARE_BITMAP(used_vectors, NR_VECTORS);static inline void cond_local_irq_enable (struct pt_regs *regs) {if (regs->flags &X86_EFLAGS_IF ) -local_irq_enable (); +hard_local_irq_enable_notrace (); }static inline void cond_local_irq_disable (struct pt_regs *regs) {if (regs->flags &X86_EFLAGS_IF ) -local_irq_disable (); +hard_local_irq_disable_notrace (); }/*
@@ -537,7 +538,7 @@ do_general_protection(struct pt_regs *regs, long error_code)cond_local_irq_enable (regs);if (v8086_mode (regs)) { -local_irq_enable (); +hard_local_irq_enable ();handle_vm86_fault ((struct kernel_vm86_regs *) regs, error_code);return ; }
@@ -923,7 +924,7 @@ dotraplinkage void do_iret_error(struct pt_regs *regs, long error_code)siginfo_t info;RCU_LOCKDEP_WARN (!rcu_is_watching (),"entry code didn't wake RCU" ); -local_irq_enable (); +hard_local_irq_enable (); info.si_signo =SIGILL ; info.si_errno =0 ;
arch/x86/mm/fault.c +4 -0
@@ -1248,6 +1248,10 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,unsigned int flags =FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_KILLABLE ;u32 pkey; +#ifdef CONFIG_IPIPE +if (ipipe_root_domain != ipipe_head_domain) +hard_cond_local_irq_enable (); +#endif tsk = current; mm = tsk->mm;
Signature · 1 line
2.14.4
PATCH 19/32 x86: ipipe: route syscalls to co-kernel
In reply to Philippe GerumThis commit introduces the changes redirecting "foreign" system calls to the co-kernel.
--- arch/x86/entry/common.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 3 deletions(-)
arch/x86/entry/common.c +72 -3
@@ -274,7 +274,9 @@ __visible inline void syscall_return_slowpath(struct pt_regs *regs)* First do one-time work. If these work items are enabled, we * want to run them exactly once per syscall exit with IRQs on. */ -if (unlikely (cached_flags &SYSCALL_EXIT_WORK_FLAGS )) +if (unlikely ((!IS_ENABLED (CONFIG_IPIPE ) || +syscall_get_nr (current, regs) < NR_syscalls) && + (cached_flags &SYSCALL_EXIT_WORK_FLAGS )))syscall_slow_exit_work (regs, cached_flags);local_irq_disable ();
@@ -282,15 +284,74 @@ __visible inline void syscall_return_slowpath(struct pt_regs *regs)prepare_exit_to_usermode (regs); } +#ifdef CONFIG_IPIPE + +#ifdef CONFIG_X86_32 +static inline int pipeline_syscall_32 (struct thread_info *ti, +unsigned long nr,struct pt_regs *regs) +{ +return ipipe_handle_syscall (ti, nr, regs); +} +#else +static inline int pipeline_syscall_64 (struct thread_info *ti, +unsigned long nr,struct pt_regs *regs) +{ +return ipipe_handle_syscall (ti, nr, regs); +} + +static inline int pipeline_syscall_32 (struct thread_info *ti, +unsigned long nr,struct pt_regs *regs) +{ +struct pt_regs regs64 = *regs; +int ret; + + regs64.di = (unsigned int )regs->bx; + regs64.si = (unsigned int )regs->cx; + regs64.r10 = (unsigned int )regs->si; + regs64.r8 = (unsigned int )regs->di; + regs64.r9 = (unsigned int )regs->bp; + ret =ipipe_handle_syscall (ti, nr, ®s64); + regs->ax = (unsigned int )regs64.ax; + +return ret; +} +#endif /* CONFIG_X86_32 */ + +#else /* CONFIG_IPIPE */ + +static inline int pipeline_syscall_32 (struct thread_info *ti, +unsigned long nr,struct pt_regs *regs) +{ +return 0 ; +} + +static inline int pipeline_syscall_64 (struct thread_info *ti, +unsigned long nr,struct pt_regs *regs) +{ +return 0 ; +} + +#endif /* CONFIG_IPIPE */ +#ifdef CONFIG_X86_64 __visible void do_syscall_64(struct pt_regs *regs) {struct thread_info *ti =current_thread_info ();unsigned long nr = regs->orig_ax; +int ret;enter_from_user_mode ();local_irq_enable (); + ret =pipeline_syscall_64 (ti, nr, regs); +if (ret >0 ) { +local_irq_disable (); +hard_cond_local_irq_disable (); +return ; + } +if (ret <0 ) + goto done; +if (READ_ONCE (ti->flags) & _TIF_WORK_SYSCALL_ENTRY) nr =syscall_trace_enter (regs);
@@ -305,7 +366,7 @@ __visible void do_syscall_64(struct pt_regs *regs) regs->di, regs->si, regs->dx, regs->r10, regs->r8, regs->r9); } - +done:syscall_return_slowpath (regs); }#endif
@@ -321,11 +382,19 @@ static __always_inline void do_syscall_32_irqs_on(struct pt_regs *regs) {struct thread_info *ti =current_thread_info ();unsigned int nr = (unsigned int )regs->orig_ax; +int ret;#ifdef CONFIG_IA32_EMULATION ti->status |=TS_COMPAT ;#endif + ret =pipeline_syscall_32 (ti, nr, regs); +if (ret >0 ) +return ; + +if (ret <0 ) + goto done; +if (READ_ONCE (ti->flags) & _TIF_WORK_SYSCALL_ENTRY) {/* * Subtlety here: if ptrace pokes something larger than
@@ -349,7 +418,7 @@ static __always_inline void do_syscall_32_irqs_on(struct pt_regs *regs) (unsigned int )regs->dx, (unsigned int )regs->si, (unsigned int)regs->di, (unsigned int)regs->bp); } - +done:syscall_return_slowpath (regs); }
Signature · 1 line
2.14.4
PATCH 20/32 x86: fix include for drivers
In reply to Philippe GerumFrom: Henning Schild <[email protected]>
--- include/linux/gpio.h | 1 + 1 file changed, 1 insertion(+)
include/linux/gpio.h +1 -0
@@ -3,6 +3,7 @@#define __LINUX_GPIO_H#include <linux/errno.h> +#include <linux/ipipe.h> /* see Documentation/gpio/gpio-legacy.txt */
Signature · 1 line
2.14.4
Re: [PATCH 20/32] x86: fix include for drivers
Quoted 12 lines · Philippe Gerum
From: Henning Schild <[email protected]>
--- include/linux/gpio.h | 1 + 1 file changed, 1 insertion(+)include/linux/gpio.h +0
-0
include/linux/gpio.h line 9
Quoted 7 lines
include/linux/gpio.h +1
-0@@ -3,6 +3,7 @@#define __LINUX_GPIO_H#include <linux/errno.h> +#include <linux/ipipe.h> /* see Documentation/gpio/gpio-legacy.txt */
Where did this come from? It's also incorrectly tagged as "x86", though it's touching generic code.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux
Re: [PATCH 20/32] x86: fix include for drivers
Quoted 7 lines · Jan Kiszka
Quoted 6 lines · Philippe Gerum
From: Henning Schild <[email protected]>
---
include/linux/gpio.h| 1 +1 file changed, 1 insertion(+)
Quoted 14 lines
Quoted 10 lines
include/linux/gpio.h +1
-0@@ -3,6 +3,7 @@ #define __LINUX_GPIO_H #include <linux/errno.h> +#include <linux/ipipe.h> /* see Documentation/gpio/gpio-legacy.txt */Where did this come from? It's also incorrectly tagged as "x86", though it's touching generic code.
Cherry-picked from the x86 tree a year ago as far as I can remember since this stuff happened a year ago, as I was working on the split work:
https://gitlab.denx.de/Xenomai/ipipe-x86/commit/ac02dfb4d71462b8ac5cd0ae5cf14d89b125124e
This change can be dropped unless you have a specific issue to solve for x86 that you could not address in a better way, I did not pick it for -noarch AFAICT.
Signature · 1 line
Philippe.
Re: [PATCH 20/32] x86: fix include for drivers
Quoted 23 lines · Philippe Gerum
Quoted 7 lines · Jan Kiszka
Quoted 6 lines · Philippe Gerum
From: Henning Schild <[email protected]>
--- include/linux/gpio.h | 1 + 1 file changed, 1 insertion(+)Quoted 14 lines
include/linux/gpio.h line 7
Quoted 10 lines
include/linux/gpio.h +1
-0@@ -3,6 +3,7 @@ #define __LINUX_GPIO_H #include <linux/errno.h> +#include <linux/ipipe.h> /* see Documentation/gpio/gpio-legacy.txt */Where did this come from? It's also incorrectly tagged as "x86", though it's touching generic code.
Quoted 9 lines
Cherry-picked from the x86 tree a year ago as far as I can remember since this stuff happened a year ago, as I was working on the split work:
https://gitlab.denx.de/Xenomai/ipipe-x86/commit/ac02dfb4d71462b8ac5cd0ae5cf14d89b125124e
This change can be dropped unless you have a specific issue to solve for x86 that you could not address in a better way, I did not pick it for -noarch AFAICT.
Yeah, we are fine without it - dropped.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux
Re: [PATCH 20/32] x86: fix include for drivers
Quoted 29 lines · Jan Kiszka
Quoted 28 lines · Philippe Gerum
Quoted 7 lines · Jan Kiszka
Quoted 6 lines · Philippe Gerum
From: Henning Schild <[email protected]>
---
include/linux/gpio.h| 1 +1 file changed, 1 insertion(+)Quoted 13 lines
include/linux/gpio.h line 6
Quoted 9 lines
include/linux/gpio.h +1
-0@@ -3,6 +3,7 @@ #define __LINUX_GPIO_H #include <linux/errno.h> +#include <linux/ipipe.h> /* see Documentation/gpio/gpio-legacy.txt */Where did this come from? It's also incorrectly tagged as "x86", though it's touching generic code.
Cherry-picked from the x86 tree a year ago as far as I can remember since this stuff happened a year ago, as I was working on the split work:
https://gitlab.denx.de/Xenomai/ipipe-x86/commit/ac02dfb4d71462b8ac5cd0ae5cf14d89b125124e
Quoted 7 lines
Quoted 4 lines
This change can be dropped unless you have a specific issue to solve for x86 that you could not address in a better way, I did not pick it for -noarch AFAICT.
Yeah, we are fine without it - dropped.
Nah, too fast [1]: We are missing an include, but - obviously - not at that spot. Patch for noarch follows.
Jan
PS: Good that we have CI now...
[1] https://travis-ci.com/xenomai-ci/xenomai/jobs/212725223
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux
PATCH 21/32 x86: ipipe fpu support
In reply to Philippe GerumFrom: Henning Schild <[email protected]>
--- arch/x86/include/asm/fpu/internal.h | 20 +++++++++++++ arch/x86/kernel/fpu/core.c | 58 +++++++++++++++++++++---------------- 2 files changed, 53 insertions(+), 25 deletions(-)
arch/x86/include/asm/fpu/internal.h +20 -0
@@ -604,4 +604,24 @@ static inline void xsetbv(u32 index, u64 value) : : "a" (eax), "d" (edx), "c" (index)); } +DECLARE_PER_CPU (bool, in_kernel_fpu); + +static void kernel_fpu_disable (void ) +{ +WARN_ON_FPU (this_cpu_read (in_kernel_fpu)); +this_cpu_write (in_kernel_fpu, true); +} + +static void kernel_fpu_enable (void ) +{ +WARN_ON_FPU (!this_cpu_read (in_kernel_fpu)); +this_cpu_write (in_kernel_fpu, false); +} + +static bool kernel_fpu_disabled (void ) +{ +return this_cpu_read (in_kernel_fpu); +} + +#endif /* _ASM_X86_FPU_INTERNAL_H */
arch/x86/kernel/fpu/core.c +33 -25
157 lines not on this page · raw message
Signature · 1 line
2.14.4
PATCH 22/32 x86/irq: ipipe: map the cleanup vector to a legit IRQ number
In reply to Philippe GerumThe cleanup vector is not part of the system vector range but rather belongs to the external IRQ range, however we still need to map it early to a legit interrupt number for pipelining.
--- arch/x86/kernel/idt.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
arch/x86/kernel/idt.c +12 -2
@@ -317,11 +317,21 @@ void __init idt_setup_apic_and_irq_gates(void) {int i =FIRST_EXTERNAL_VECTOR ;void *entry; -unsigned int __maybe_unused cpu; +unsigned int __maybe_unused cpu, ret;idt_setup_from_table (idt_table, apic_idts,ARRAY_SIZE (apic_idts), true); -#ifdef CONFIG_SMP +#if defined(CONFIG_SMP ) && defined(CONFIG_IPIPE ) +/* +* The cleanup vector is not part of the system vector range +* but rather belongs to the external IRQ range, however we +* still need to map it early to a legit interrupt number for +* pipelining. Allocate a specific descriptor manually for it, +* using IRQ_MOVE_CLEANUP_VECTOR as both the vector number and +* interrupt number, so that we know the latter at build time. +*/ + ret =irq_alloc_descs (IRQ_MOVE_CLEANUP_VECTOR ,0 ,1 ,0 ); +BUG_ON (IRQ_MOVE_CLEANUP_VECTOR != ret);for_each_possible_cpu (cpu)per_cpu (vector_irq, cpu)[IRQ_MOVE_CLEANUP_VECTOR ] =irq_to_desc (IRQ_MOVE_CLEANUP_VECTOR );
Signature · 1 line
2.14.4
PATCH 23/32 x86/fpu: ipipe: add inline qualifier to kernel_fpu_*() helpers
In reply to Philippe Gerum--- arch/x86/include/asm/fpu/internal.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/include/asm/fpu/internal.h +3 -3
@@ -606,19 +606,19 @@ static inline void xsetbv(u32 index, u64 value)DECLARE_PER_CPU (bool, in_kernel_fpu); -static void kernel_fpu_disable (void ) +static inline void kernel_fpu_disable (void ) {WARN_ON_FPU (this_cpu_read (in_kernel_fpu));this_cpu_write (in_kernel_fpu, true); } -static void kernel_fpu_enable (void ) +static inline void kernel_fpu_enable (void ) {WARN_ON_FPU (!this_cpu_read (in_kernel_fpu));this_cpu_write (in_kernel_fpu, false); } -static bool kernel_fpu_disabled (void ) +static inline bool kernel_fpu_disabled (void ) {return this_cpu_read (in_kernel_fpu); }
Signature · 1 line
2.14.4
PATCH 24/32 x86: ipipe: fix interrupt state in syscall routing
In reply to Philippe Gerum--- arch/x86/entry/common.c | 147 ++++++++++++++++++++++-------------------------- 1 file changed, 66 insertions(+), 81 deletions(-)
arch/x86/entry/common.c +66 -81
@@ -47,6 +47,22 @@ __visible inline void enter_from_user_mode(void)static inline void enter_from_user_mode (void ) {}#endif +#ifdef CONFIG_IPIPE +#define disable_local_irqs () do { \ + hard_local_irq_disable(); \ + trace_hardirqs_off(); \ +} while (0) +#define enable_local_irqs () do { \ + trace_hardirqs_on(); \ + hard_local_irq_enable(); \ +} while (0) +#define check_irqs_disabled () hard_irqs_disabled() +#else +#define disable_local_irqs () local_irq_disable() +#define enable_local_irqs () local_irq_enable() +#define check_irqs_disabled () irqs_disabled() +#endif +static void do_audit_syscall_entry (struct pt_regs *regs,u32 arch) {#ifdef CONFIG_X86_64
@@ -147,7 +163,7 @@ static void exit_to_usermode_loop(struct pt_regs *regs, u32 cached_flags)*/ while (true) {/* We have work to do. */ -local_irq_enable ();/* IPIPE: hardirqs on too */ +enable_local_irqs ();if (cached_flags & _TIF_NEED_RESCHED)schedule ();
@@ -171,9 +187,7 @@ static void exit_to_usermode_loop(struct pt_regs *regs, u32 cached_flags)klp_update_patch_state (current);/* Disable IRQs and retry */ -local_irq_disable (); - -hard_cond_local_irq_disable (); +disable_local_irqs (); cached_flags =READ_ONCE (current_thread_info ()->flags);
@@ -187,17 +201,11 @@ __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 (); -if (IS_ENABLED (CONFIG_PROVE_LOCKING ) &&WARN_ON (!irqs_disabled ())) -local_irq_disable (); +if (IS_ENABLED (CONFIG_PROVE_LOCKING ) &&WARN_ON (!check_irqs_disabled ())) +disable_local_irqs ();lockdep_sys_exit ();
@@ -222,11 +230,6 @@ __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 \
@@ -267,8 +270,8 @@ __visible inline void syscall_return_slowpath(struct pt_regs *regs)CT_WARN_ON (ct_state () !=CONTEXT_KERNEL );if (IS_ENABLED (CONFIG_PROVE_LOCKING ) && -WARN (irqs_disabled (),"syscall %ld left IRQs disabled" , regs->orig_ax)) -local_irq_enable (); +WARN (check_irqs_disabled (),"syscall %ld left IRQs disabled" , regs->orig_ax)) +enable_local_irqs ();/* * First do one-time work. If these work items are enabled, we
@@ -279,60 +282,10 @@ __visible inline void syscall_return_slowpath(struct pt_regs *regs) (cached_flags & SYSCALL_EXIT_WORK_FLAGS)))syscall_slow_exit_work (regs, cached_flags); -local_irq_disable (); -hard_cond_local_irq_disable (); +disable_local_irqs ();prepare_exit_to_usermode (regs); } -#ifdef CONFIG_IPIPE - -#ifdef CONFIG_X86_32 -static inline int pipeline_syscall_32 (struct thread_info *ti, -unsigned long nr,struct pt_regs *regs) -{ -return ipipe_handle_syscall (ti, nr, regs); -} -#else -static inline int pipeline_syscall_64 (struct thread_info *ti, -unsigned long nr,struct pt_regs *regs) -{ -return ipipe_handle_syscall (ti, nr, regs); -} - -static inline int pipeline_syscall_32 (struct thread_info *ti, -unsigned long nr,struct pt_regs *regs) -{ -struct pt_regs regs64 = *regs; -int ret; - - regs64.di = (unsigned int )regs->bx; - regs64.si = (unsigned int )regs->cx; - regs64.r10 = (unsigned int )regs->si; - regs64.r8 = (unsigned int )regs->di; - regs64.r9 = (unsigned int )regs->bp; - ret =ipipe_handle_syscall (ti, nr, ®s64); - regs->ax = (unsigned int )regs64.ax; - -return ret; -} -#endif /* CONFIG_X86_32 */ - -#else /* CONFIG_IPIPE */ - -static inline int pipeline_syscall_32 (struct thread_info *ti, -unsigned long nr,struct pt_regs *regs) -{ -return 0 ; -} - -static inline int pipeline_syscall_64 (struct thread_info *ti, -unsigned long nr,struct pt_regs *regs) -{ -return 0 ; -} - -#endif /* CONFIG_IPIPE */ -#ifdef CONFIG_X86_64 __visible void do_syscall_64(struct pt_regs *regs) {
@@ -341,12 +294,11 @@ __visible void do_syscall_64(struct pt_regs *regs)int ret;enter_from_user_mode (); -local_irq_enable (); +enable_local_irqs (); - ret =pipeline_syscall_64 (ti, nr, regs); + ret =ipipe_handle_syscall (ti, nr & __SYSCALL_MASK, regs);if (ret >0 ) { -local_irq_disable (); -hard_cond_local_irq_disable (); +disable_local_irqs ();return ; }if (ret <0 )
@@ -372,6 +324,39 @@ __visible void do_syscall_64(struct pt_regs *regs)#endif #if defined(CONFIG_X86_32 ) || defined(CONFIG_IA32_EMULATION ) + +#ifdef CONFIG_IPIPE +#ifdef CONFIG_X86_32 +static inline int pipeline_syscall (struct thread_info *ti, +unsigned long nr,struct pt_regs *regs) +{ +return ipipe_handle_syscall (ti, nr, regs); +} +#else +static inline int pipeline_syscall (struct thread_info *ti, +unsigned long nr,struct pt_regs *regs) +{ +struct pt_regs regs64 = *regs; +int ret; + + regs64.di = (unsigned int )regs->bx; + regs64.si = (unsigned int )regs->cx; + regs64.r10 = (unsigned int )regs->si; + regs64.r8 = (unsigned int )regs->di; + regs64.r9 = (unsigned int )regs->bp; + ret =ipipe_handle_syscall (ti, nr, ®s64); + regs->ax = (unsigned int )regs64.ax; + +return ret; +} +#endif /* CONFIG_X86_32 */ +#else /* CONFIG_IPIPE */ +static inline int pipeline_syscall (struct thread_info *ti, +unsigned long nr,struct pt_regs *regs) +{ +return 0 ; +} +#endif /* CONFIG_IPIPE */ /* * Does a 32-bit syscall. Called with IRQs on in CONTEXT_KERNEL. Does * all entry and exit work and returns with IRQs off. This function is
@@ -388,10 +373,11 @@ static __always_inline void do_syscall_32_irqs_on(struct pt_regs *regs) ti->status |=TS_COMPAT ;#endif - ret =pipeline_syscall_32 (ti, nr, regs); -if (ret >0 ) + ret =pipeline_syscall (ti, nr, regs); +if (ret >0 ) { +disable_local_irqs ();return ; - + }if (ret <0 ) goto done;
@@ -426,7 +412,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 ();/* IPIPE: hardirqs on too */ +enable_local_irqs ();do_syscall_32_irqs_on (regs); }
@@ -450,7 +436,7 @@ __visible long do_fast_syscall_32(struct pt_regs *regs)enter_from_user_mode (); -local_irq_enable ();/* IPIPE: hardirqs on too */ +enable_local_irqs ();/* Fetch EBP from where the vDSO stashed it. */ if (
@@ -468,8 +454,7 @@ __visible long do_fast_syscall_32(struct pt_regs *regs) ) {/* User code screwed up. */ -local_irq_disable (); -hard_cond_local_irq_disable (); +disable_local_irqs (); regs->ax = -EFAULT ;prepare_exit_to_usermode (regs);return 0 ;/* Keep it simple: use IRET. */
Signature · 1 line
2.14.4
PATCH 25/32 x86/irq: ipipe: reconcile lockdep tracing with virtual IRQ state
In reply to Philippe Gerum--- arch/x86/entry/entry_64.S | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/x86/entry/entry_64.S +6 -1
@@ -557,8 +557,13 @@ END(irq_entries_start) 1: ENTER_IRQ_STACK old_rsp=%rdi - /* We entered an interrupt context - irqs are off: */ +#ifndef CONFIG_IPIPE + /* We entered an interrupt context - irqs are off unless + pipelining is enabled, in which case we defer tracing until + __ipipe_do_sync_stage() where the virtual IRQ state is + updated for the root stage. */ TRACE_IRQS_OFF +#endif call \func /* rdi points to pt_regs */ .endm
Signature · 1 line
2.14.4
PATCH 26/32 x86/mm: ipipe: fix lockdep tracing upon PF
In reply to Philippe Gerum--- arch/x86/mm/fault.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/mm/fault.c +4 -2
@@ -1249,8 +1249,10 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,u32 pkey;#ifdef CONFIG_IPIPE -if (ipipe_root_domain != ipipe_head_domain) -hard_cond_local_irq_enable (); +if (ipipe_root_domain != ipipe_head_domain) { +trace_hardirqs_on (); +hard_local_irq_enable (); + }#endif tsk = current; mm = tsk->mm;
Signature · 1 line
2.14.4
PATCH 27/32 x86/msi: ipipe: advertise pipelining support
In reply to Philippe Gerum--- arch/x86/kernel/apic/msi.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/x86/kernel/apic/msi.c +4 -4
@@ -68,7 +68,7 @@ static struct irq_chip pci_msi_controller = {#if defined(CONFIG_IPIPE ) && defined(CONFIG_SMP ) .irq_move = move_xxapic_irq, #endif - .flags = IRQCHIP_SKIP_SET_WAKE, + .flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_PIPELINE_SAFE, };int native_setup_msi_irqs (struct pci_dev *dev,int nvec,int type)
@@ -169,7 +169,7 @@ static struct irq_chip pci_msi_ir_controller = { #if defined(CONFIG_IPIPE) && defined(CONFIG_SMP) .irq_move = move_xxapic_irq, #endif - .flags = IRQCHIP_SKIP_SET_WAKE, + .flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_PIPELINE_SAFE, }; static struct msi_domain_info pci_msi_ir_domain_info = {
@@ -214,7 +214,7 @@ static struct irq_chip dmar_msi_controller = {#if defined(CONFIG_IPIPE ) && defined(CONFIG_SMP ) .irq_move = move_xxapic_irq, #endif - .flags = IRQCHIP_SKIP_SET_WAKE, + .flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_PIPELINE_SAFE, }; static irq_hw_number_t dmar_msi_get_hwirq(struct msi_domain_info *info,
@@ -314,7 +314,7 @@ static struct irq_chip hpet_msi_controller __ro_after_init = {#if defined(CONFIG_IPIPE ) && defined(CONFIG_SMP ) .irq_move = move_xxapic_irq, #endif - .flags = IRQCHIP_SKIP_SET_WAKE, + .flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_PIPELINE_SAFE, }; static irq_hw_number_t hpet_msi_get_hwirq(struct msi_domain_info *info,
Signature · 1 line
2.14.4
PATCH 28/32 x86: ipipe: fix stack overflow detection
In reply to Philippe GerumSince do_IRQ() may be called from a plain regular task context if the original interrupt was deferred by the pipeline core for the root stage, we cannot assume regs->sp should within the current task's stack page if it does not point within the IRQ stack.
Make sure to test the right stack pointer against the proper stack space, removing the previous attempt to force regs->sp to current_stack_pointer, which won't work if the static tick regs space is reused by another timer IRQ piling up on pipeline entry, preempting the do_IRQ() context.
--- arch/x86/kernel/ipipe.c | 1 - arch/x86/kernel/irq_64.c | 12 +++++++----- 2 files changed, 7 insertions(+), 6 deletions(-)
arch/x86/kernel/ipipe.c +0 -1
@@ -102,7 +102,6 @@ static void __ipipe_do_IRQ(unsigned int irq, void *cookie) 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); }
arch/x86/kernel/irq_64.c +7 -5
@@ -38,28 +38,30 @@ static inline void stack_overflow_check(struct pt_regs *regs)u64 irq_stack_top, irq_stack_bottom;u64 estack_top, estack_bottom;u64 curbase = (u64 )task_stack_page (current); +unsigned long sp;if (user_mode (regs))return ; -if (regs->sp >= curbase +sizeof (struct pt_regs ) +STACK_TOP_MARGIN && - regs->sp <= curbase +THREAD_SIZE ) + sp =IS_ENABLED (CONFIG_IPIPE ) ? current_stack_pointer : regs->sp; +if (sp >= curbase +sizeof (struct pt_regs ) +STACK_TOP_MARGIN && + sp <= curbase +THREAD_SIZE )return ; irq_stack_top = (u64 )this_cpu_ptr (irq_stack_union.irq_stack) +STACK_TOP_MARGIN ; irq_stack_bottom = (u64 )__this_cpu_read (irq_stack_ptr); -if (regs->sp >= irq_stack_top && regs->sp <= irq_stack_bottom) +if (sp >= irq_stack_top && sp <= irq_stack_bottom)return ; oist =this_cpu_ptr (&orig_ist); estack_top = (u64 )oist->ist[0 ] -EXCEPTION_STKSZ +STACK_TOP_MARGIN ; estack_bottom = (u64 )oist->ist[N_EXCEPTION_STACKS -1 ]; -if (regs->sp >= estack_top && regs->sp <= estack_bottom) +if (sp >= estack_top && sp <= estack_bottom)return ;WARN_ONCE (1 ,"do_IRQ(): %s has overflown the kernel stack (cur:%Lx,sp:%lx,irq stk top-bottom:%Lx-%Lx,exception stk top-bottom:%Lx-%Lx,ip:%pF)\n" , - current->comm, curbase, regs->sp, + current->comm, curbase, sp, irq_stack_top, irq_stack_bottom, estack_top, estack_bottom, (void *)regs->ip);
Signature · 1 line
2.14.4
PATCH 29/32 x86: ipipe: restrict WARN_ON_IN_IRQ() to the root domain
In reply to Philippe GerumWe have no way to figure out the current context unless the root domain is active. Make sure we won't trigger false positives with WARN_ON_IN_IRQ() which may be invoked through calls to access_ok() from the head domain.
--- arch/x86/include/asm/uaccess.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/include/asm/uaccess.h +2 -1
@@ -7,6 +7,7 @@#include <linux/compiler.h> #include <linux/kasan-checks.h> #include <linux/string.h> +#include <linux/ipipe.h> #include <asm/asm.h> #include <asm/page.h> #include <asm/smap.h>
@@ -70,7 +71,7 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un })#ifdef CONFIG_DEBUG_ATOMIC_SLEEP -# define WARN_ON_IN_IRQ () WARN_ON_ONCE(!in_task()) +# define WARN_ON_IN_IRQ () WARN_ON_ONCE(ipipe_root_p && !in_task())#else # define WARN_ON_IN_IRQ ()#endif
Signature · 1 line
2.14.4
PATCH 30/32 x86: ipipe: remove 32bit support from shared context switch code
In reply to Philippe Gerum--- arch/x86/kernel/process_32.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
arch/x86/kernel/process_32.c +2 -3
@@ -235,11 +235,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)struct fpu *next_fpu = &next->fpu;int cpu =raw_smp_processor_id ();struct tss_struct *tss = &per_cpu (cpu_tss_rw, cpu); -int slope =ipipe_get_domain_slope_hook (prev_p, next_p);/* never put a printk in __switch_to... printk() calls wake_up*() indirectly */ -switch_fpu_prepare (prev_fpu, cpu, slot); +switch_fpu_prepare (prev_fpu, cpu);/* * Save away %gs. No need to save %fs, as it was saved on the
@@ -300,7 +299,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)if (prev->gs | next->gs)lazy_load_gs (next->gs); -switch_fpu_finish (next_fpu, cpu, slope); +switch_fpu_finish (next_fpu, cpu);this_cpu_write (current_task, next_p);
Signature · 1 line
2.14.4
PATCH 31/32 x86: ipipe: drop (obsolete) declarations
In reply to Philippe Gerum--- arch/x86/kernel/ipipe.c | 7 ------- 1 file changed, 7 deletions(-)
arch/x86/kernel/ipipe.c +0 -7
@@ -88,13 +88,6 @@ int ipipe_get_sysinfo(struct ipipe_sysinfo *info) }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);
Signature · 1 line
2.14.4
PATCH 32/32 x86: ipipe: disable 32bit support
In reply to Philippe Gerum--- arch/x86/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/Kconfig +1 -1
@@ -145,7 +145,7 @@ 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_SUPPORT if X86_64 select HAVE_IPIPE_TRACER_SUPPORT select IPIPE_HAVE_SAFE_THREAD_INFO if IPIPE select IPIPE_WANT_PTE_PINNING if IPIPE
Signature · 1 line
2.14.4
Thanks! I just tried it on my test setup. All looking good except for one smokey test.
Quoted 1 line
./smokey --trace --run=sigdebug
Crashes the box without any further feedback, also nothing on the serial.
Will look into that.
Henning
Am Tue, 25 Sep 2018 12:37:37 +0200
schrieb Philippe Gerum <[email protected]>:
Quoted 115 lines
This is a port of the interrupt pipeline to kernel 4.14.71 for
x86_64, 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.
The topmost patch disables native 32bit support which was not ported. Support for x32 and ia32 emulation ABIs over long mode is still there and working though.
[1] https://www.xenomai.org/pipermail/xenomai/2018-July/039302.html
[2] https://git.xenomai.org/ipipe-noarchHenning Schild (2):
x86: fix include for drivers
x86: ipipe fpu supportPhilippe Gerum (30):
x86: lockdep: ipipe: make the logic aware of interrupt pipelining
x86: ipipe: add pipeline core
x86:context_tracking: disable ifCONFIG_IPIPE
x86: paravirt: disable ifCONFIG_IPIPE
x86/iommu: enable interrupt pipelining
x86/htirq: ipipe: enable interrupt pipelining x86/i8259: ipipe: enable interrupt pipelining
x86/mm: enable PTE pinning
x86: ipipe: share context switch code with head domain x86/mtrr: ipipe: protect against preemption from head stage x86/tsc: ipipe: keep calibration accurate
x86: ipipe: notify about GTOD update
x86/kgdb: ipipe: enable support from head domain x86/vm86_32: ipipe: protect against preemption from head domain x86/kvm: ipipe: enable shared control with head domain x86/mmx32: ipipe: use slow copy from head domain x86/nmi: ipipe: disallow user copy from head domain
x86: ipipe: route traps to co-kernel
x86: ipipe: route syscalls to co-kernel
x86/irq: ipipe: map the cleanup vector to a legit IRQ number x86/fpu: ipipe: add inline qualifier to kernel_fpu_*() helpers
x86: ipipe: fix interrupt state in syscall routing x86/irq: ipipe: reconcile lockdep tracing with virtual IRQ state x86/mm: ipipe: fix lockdep tracing upon PF
x86/msi: ipipe: advertise pipelining support
x86: ipipe: fix stack overflow detection
x86: ipipe: restrictWARN_ON_IN_IRQ()to the root domain
x86: ipipe: remove 32bit support from shared context switch code
x86: ipipe: drop (obsolete) declarations
x86: ipipe: disable 32bit supportarch/x86/Kconfig | 10 +- arch/x86/entry/common.c | 98 +++++- arch/x86/entry/entry_64.S | 145 +++++++-- arch/x86/entry/thunk_32.S | 1 + arch/x86/entry/thunk_64.S | 1 + arch/x86/entry/vsyscall/vsyscall_gtod.c | 4 + 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/fpu/internal.h | 20 ++ arch/x86/include/asm/i8259.h | 2 +- arch/x86/include/asm/ipipe.h | 73 +++++ arch/x86/include/asm/ipipe_base.h | 151 +++++++++ arch/x86/include/asm/irq_vectors.h | 17 +- arch/x86/include/asm/irqflags.h | 198 +++++++++++- arch/x86/include/asm/mmu_context.h | 6 +- arch/x86/include/asm/thread_info.h | 14 + arch/x86/include/asm/tsc.h | 1 + arch/x86/include/asm/uaccess.h | 3 +- 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/htirq.c | 5 +- arch/x86/kernel/apic/io_apic.c | 182 ++++++++++- arch/x86/kernel/apic/ipi.c | 29 +- arch/x86/kernel/apic/msi.c | 20 +- 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/cpu/mtrr/cyrix.c | 12 +- arch/x86/kernel/cpu/mtrr/generic.c | 12 +- arch/x86/kernel/fpu/core.c | 58 ++-- arch/x86/kernel/i8259.c | 31 +- arch/x86/kernel/idt.c | 24 ++ arch/x86/kernel/ipipe.c | 528 ++++++++++++++++++++++++++++++++ arch/x86/kernel/irq.c | 5 +- arch/x86/kernel/irq_64.c | 12 +- arch/x86/kernel/kgdb.c | 4 +- arch/x86/kernel/process.c | 20 +- arch/x86/kernel/process_32.c | 2 +- arch/x86/kernel/process_64.c | 2 +- arch/x86/kernel/smp.c | 4 +- arch/x86/kernel/smpboot.c | 8 +- arch/x86/kernel/traps.c | 9 +- arch/x86/kernel/tsc.c | 12 +- arch/x86/kernel/vm86_32.c | 4 + arch/x86/kvm/svm.c | 5 +- arch/x86/kvm/vmx.c | 13 +- arch/x86/kvm/x86.c | 66 +++- arch/x86/lib/mmx_32.c | 2 +- arch/x86/lib/usercopy.c | 3 +- arch/x86/mm/fault.c | 53 ++++ arch/x86/mm/tlb.c | 14 +- drivers/iommu/irq_remapping.c | 2 +- drivers/pci/htirq.c | 2 +- include/linux/gpio.h | 1 + 58 files changed,1787 insertions(+), 192 deletions(-) create mode 100644
arch/x86/include/asm/ipipe.hcreate mode 100644arch/x86/include/asm/ipipe_base.hcreate mode 100644arch/x86/kernel/ipipe.c
Am Thu, 27 Sep 2018 14:42:03 +0200
schrieb "[ext] Henning Schild" <[email protected]>:
Quoted 9 lines
Thanks! I just tried it on my test setup. All looking good except for one smokey test.
Quoted 1 line
./smokey --trace --run=sigdebug
Crashes the box without any further feedback, also nothing on the serial.
Will look into that.
I already found that the page-fault caused by sigdebug is causing the problem.
./smokey --verbose=42 --trace=42 --run=sigdebug
Gave me more output. The "*mem = 0xff;" is the last thing it does. Did not look into the kernel(s) and the page-fault handler yet.
Henning
Quoted 126 lines
Henning
Am Tue, 25 Sep 2018 12:37:37 +0200
schrieb Philippe Gerum <[email protected]>:Quoted 110 lines
This is a port of the interrupt pipeline to kernel 4.14.71 for
x86_64, 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.
The topmost patch disables native 32bit support which was not ported. Support for x32 and ia32 emulation ABIs over long mode is still there and working though.
[1] https://www.xenomai.org/pipermail/xenomai/2018-July/039302.html
[2] https://git.xenomai.org/ipipe-noarchHenning Schild (2):
x86: fix include for drivers
x86: ipipe fpu supportPhilippe Gerum (30):
x86: lockdep: ipipe: make the logic aware of interrupt pipelining
x86: ipipe: add pipeline core
x86:context_tracking: disable ifCONFIG_IPIPE
x86: paravirt: disable ifCONFIG_IPIPE
x86/iommu: enable interrupt pipelining
x86/htirq: ipipe: enable interrupt pipelining x86/i8259: ipipe: enable interrupt pipelining
x86/mm: enable PTE pinning
x86: ipipe: share context switch code with head domain x86/mtrr: ipipe: protect against preemption from head stage x86/tsc: ipipe: keep calibration accurate
x86: ipipe: notify about GTOD update
x86/kgdb: ipipe: enable support from head domain x86/vm86_32: ipipe: protect against preemption from head domain x86/kvm: ipipe: enable shared control with head domain x86/mmx32: ipipe: use slow copy from head domain x86/nmi: ipipe: disallow user copy from head domain
x86: ipipe: route traps to co-kernel
x86: ipipe: route syscalls to co-kernel
x86/irq: ipipe: map the cleanup vector to a legit IRQ number x86/fpu: ipipe: add inline qualifier to kernel_fpu_*() helpers
x86: ipipe: fix interrupt state in syscall routing x86/irq: ipipe: reconcile lockdep tracing with virtual IRQ state x86/mm: ipipe: fix lockdep tracing upon PF
x86/msi: ipipe: advertise pipelining support
x86: ipipe: fix stack overflow detection
x86: ipipe: restrictWARN_ON_IN_IRQ()to the root domain
x86: ipipe: remove 32bit support from shared context switch code
x86: ipipe: drop (obsolete) declarations
x86: ipipe: disable 32bit supportarch/x86/Kconfig | 10 +- arch/x86/entry/common.c | 98 +++++- arch/x86/entry/entry_64.S | 145 +++++++-- arch/x86/entry/thunk_32.S | 1 + arch/x86/entry/thunk_64.S | 1 + arch/x86/entry/vsyscall/vsyscall_gtod.c | 4 + 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/fpu/internal.h | 20 ++ arch/x86/include/asm/i8259.h | 2 +- arch/x86/include/asm/ipipe.h | 73 +++++ arch/x86/include/asm/ipipe_base.h | 151 +++++++++ arch/x86/include/asm/irq_vectors.h | 17 +- arch/x86/include/asm/irqflags.h | 198 +++++++++++- arch/x86/include/asm/mmu_context.h | 6 +- arch/x86/include/asm/thread_info.h | 14 + arch/x86/include/asm/tsc.h | 1 + arch/x86/include/asm/uaccess.h | 3 +- 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/htirq.c | 5 +- arch/x86/kernel/apic/io_apic.c | 182 ++++++++++- arch/x86/kernel/apic/ipi.c | 29 +- arch/x86/kernel/apic/msi.c | 20 +- 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/cpu/mtrr/cyrix.c | 12 +- arch/x86/kernel/cpu/mtrr/generic.c | 12 +- arch/x86/kernel/fpu/core.c | 58 ++-- arch/x86/kernel/i8259.c | 31 +- arch/x86/kernel/idt.c | 24 ++ arch/x86/kernel/ipipe.c | 528 ++++++++++++++++++++++++++++++++ arch/x86/kernel/irq.c | 5 +- arch/x86/kernel/irq_64.c | 12 +- arch/x86/kernel/kgdb.c | 4 +- arch/x86/kernel/process.c | 20 +- arch/x86/kernel/process_32.c | 2 +- arch/x86/kernel/process_64.c | 2 +- arch/x86/kernel/smp.c | 4 +- arch/x86/kernel/smpboot.c | 8 +- arch/x86/kernel/traps.c | 9 +- arch/x86/kernel/tsc.c | 12 +- arch/x86/kernel/vm86_32.c | 4 + arch/x86/kvm/svm.c | 5 +- arch/x86/kvm/vmx.c | 13 +- arch/x86/kvm/x86.c | 66 +++- arch/x86/lib/mmx_32.c | 2 +- arch/x86/lib/usercopy.c | 3 +- arch/x86/mm/fault.c | 53 ++++ arch/x86/mm/tlb.c | 14 +- drivers/iommu/irq_remapping.c | 2 +- drivers/pci/htirq.c | 2 +- include/linux/gpio.h | 1 + 58 files changed,Quoted 5 lines
1787 insertions(+), 192 deletions(-) create mode 100644
arch/x86/include/asm/ipipe.hcreate mode 100644arch/x86/include/asm/ipipe_base.hcreate mode 100644arch/x86/kernel/ipipe.c_______________________________________________
Xenomai mailing list
[email protected]
https://xenomai.org/mailman/listinfo/xenomai
Quoted 13 lines · Henning Schild
Am Thu, 27 Sep 2018 14:42:03 +0200
schrieb "[ext] Henning Schild" <[email protected]>:Quoted 9 lines
Thanks! I just tried it on my test setup. All looking good except for one smokey test.
Quoted 1 line
./smokey --trace --run=sigdebug
Crashes the box without any further feedback, also nothing on the serial.
Will look into that.
Quoted 7 lines
I already found that the page-fault caused by sigdebug is causing the problem.
./smokey --verbose=42 --trace=42 --run=sigdebug
Gave me more output. The "*mem =
0xff;" is the last thing it does. Did not look into the kernel(s) and the page-fault handler yet.
This looks like the PF event not being reported through the pipeline via the __ipipe_notify_trap() call. This points the finger to __ipipe_trap_prologue() (or whatever code should call it but does not).
Signature · 1 line
Philippe.
Am Mon, 1 Oct 2018 17:03:52 +0200
schrieb Philippe Gerum <[email protected]>:
Quoted 19 lines · Henning Schild
Quoted 18 lines
Am Thu, 27 Sep 2018 14:42:03 +0200
schrieb "[ext] Henning Schild" <[email protected]>:Quoted 9 lines
Thanks! I just tried it on my test setup. All looking good except for one smokey test.
Quoted 1 line
./smokey --trace --run=sigdebug
Crashes the box without any further feedback, also nothing on the serial.
Will look into that.
I already found that the page-fault caused by sigdebug is causing the problem.
./smokey --verbose=42 --trace=42 --run=sigdebug
Quoted 7 lines
Quoted 2 lines
Gave me more output. The "*mem =
0xff;" is the last thing it does. Did not look into the kernel(s) and the page-fault handler yet.This looks like the PF event not being reported through the pipeline via the
__ipipe_notify_trap()call. This points the finger to__ipipe_trap_prologue()(or whatever code should call it but does not).
I instrumented __ipipe_trap_prologue and did not even see the #PF there. So it is either in the assembly before that or we do not have the trap handler mapped or something like that. nopcid and nopti did not help.
For further analysis i would likely have to move my setup to kvm. Can anyone actually reproduce this?
Since i will be out of office in the next two weeks, i will not be able to investigate further before 10/22.
Henning
Quoted 4 lines
I instrumented
__ipipe_trap_prologueand did not even see the #PF there. So it is either in the assembly before that or we do not have the trap handler mapped or something like that. nopcid and nopti did not help.
I'm going to take a wild guess and say entry_64.S is where the issue is because I can't make heads or tails of the KPTI code.. I might as well be looking at Denuvo.
Alec
Quoted 7 lines · Alec Ari
Quoted 4 lines
I instrumented
__ipipe_trap_prologueand did not even see the #PF there. So it is either in the assembly before that or we do not have the trap handler mapped or something like that. nopcid and nopti did not help.I'm going to take a wild guess and say
entry_64.Sis where the issue is because I can't make heads or tails of the KPTI code.. I might as well be looking at Denuvo.
That guess was good: We fail to hook into the traps that are taken from userspace (identry -> from_usermode_switch_stack path). I'll look into how to address that best tomorrow.
Jan