x86/asm changes for v3.3
Subsystems (9)
Linus,
Please pull the latest x86-asm-for-linus git tree from:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86-asm-for-linus
out-of-topic modifications in x86-asm-for-linus:
------------------------------------------------drivers/lguest/x86/core.c # 1cf8343: x86: Fix rflags in FAKE_STACK_FRAmm/slub.c # cdcd629: x86: Fix and improve cmpxchg_doub
Thanks,
Ingo
------------------>
Alexey Dobriyan (1):
x86/i386: Use less assembly in strlen(), speed things up a bit
Andy Lutomirski (2):
x86-64: Set siginfo and context on vsyscall emulation faults
x86: Default to vsyscall=emulate
David Howells (1):
x86_64, asm: Optimise fls(), ffs() and fls64()
Eric Dumazet (1):
x86: Fix atomic64_xxx_cx8() functions
H Hartley Sweeten (1):
x86: Use the same node_distance for 32 and 64-bit
H. Peter Anvin (1):
x86, bitops: Move fls64.h inside __KERNEL__
Jan Beulich (6):
x86-64: Slightly shorten int_ret_from_sys_call
x86-64: Reduce amount of redundant code generated for invalidate_interruptNN
x86-64: Slightly shorten line system call entry and exit paths
x86-64: Cleanup some assembly entry points
x86: Fix and improve percpu_cmpxchg{8,16}b_double()
x86: Fix and improve cmpxchg_double{,_local}()
Jeremy Fitzhardinge (2):
x86/cmpxchg: add a locked add() helper
x86: consolidate xchg and xadd macros
Joerg Roedel (1):
x86: Report cpb and eff_freq_ro flags correctly
Maurice Ma (1):
x86, efi: Convert efi_phys_get_time() args to physical addresses
Sebastian Andrzej Siewior (1):
x86/div64: Add a micro-optimization shortcut if base is power of two
Seiichi Ikarashi (1):
x86: Fix rflags in FAKE_STACK_FRAME
Srikar Dronamraju (2):
x86: Call do_notify_resume() with interrupts enabled
x86: Clean up and extend do_int3()
Documentation/kernel-parameters.txt | 7 +- arch/x86/ia32/ia32entry.S | 43 ++++----- arch/x86/include/asm/alternative-asm.h | 4 +- arch/x86/include/asm/bitops.h | 76 ++++++++++++--- arch/x86/include/asm/cmpxchg.h | 163 ++++++++++++++++++-------------- arch/x86/include/asm/cmpxchg_32.h | 46 --------- arch/x86/include/asm/cmpxchg_64.h | 43 --------- arch/x86/include/asm/div64.h | 22 +++-- arch/x86/include/asm/percpu.h | 53 ++++------ arch/x86/include/asm/processor-flags.h | 1 + arch/x86/include/asm/spinlock.h | 15 +--- arch/x86/include/asm/thread_info.h | 9 ++- arch/x86/include/asm/topology.h | 2 - arch/x86/include/asm/uaccess.h | 2 +- arch/x86/kernel/cpu/powerflags.c | 3 +- arch/x86/kernel/entry_32.S | 4 + arch/x86/kernel/entry_64.S | 31 ++++--- arch/x86/kernel/process.c | 2 +- arch/x86/kernel/traps.c | 7 +- arch/x86/kernel/vsyscall_64.c | 77 +++++++++++++-- arch/x86/lib/string_32.c | 8 +- arch/x86/mm/extable.c | 2 +- arch/x86/mm/fault.c | 22 +++- arch/x86/platform/efi/efi.c | 3 +- drivers/lguest/x86/core.c | 2 +- mm/slub.c | 4 +- 26 files changed, 345 insertions(+), 306 deletions(-)
Documentation/kernel-parameters.txt +3 -4
@@ -2750,11 +2750,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted. functions are at fixed addresses, they make nice targets for exploits that can control RIP. - emulate Vsyscalls turn into traps and are emulated - reasonably safely. + emulate [default] Vsyscalls turn into traps and are + emulated reasonably safely. - native [default] Vsyscalls are native syscall - instructions. + native Vsyscalls are native syscall instructions. This is a little bit faster than trapping and makes a few dynamic recompilers work better than they would in emulation mode.
arch/x86/ia32/ia32entry.S +19 -24
127 lines not on this page · raw message
arch/x86/include/asm/alternative-asm.h +2 -2
@@ -4,10 +4,10 @@#ifdef CONFIG_SMP .macro LOCK_PREFIX -1: lock +672: lock .section .smp_locks,"a" .balign 4 - .long 1b - . + .long 672b - . .previous .endm#else
arch/x86/include/asm/bitops.h +63 -13
109 lines not on this page · raw message
arch/x86/include/asm/cmpxchg.h +93 -70
205 lines not on this page · raw message
arch/x86/include/asm/cmpxchg_32.h +0 -46
52 lines not on this page · raw message
arch/x86/include/asm/cmpxchg_64.h +0 -43
49 lines not on this page · raw message
arch/x86/include/asm/div64.h +14 -8
@@ -4,6 +4,7 @@#ifdef CONFIG_X86_32 #include <linux/types.h> +#include <linux/log2.h> /* * do_div() is NOT a C function. It wants to return
@@ -21,15 +22,20 @@ ({ \unsigned long __upper, __low, __high, __mod, __base; \ __base = (base); \ - asm("" :"=a" (__low),"=d" (__high) :"A" (n)); \ - __upper = __high; \ -if (__high) { \ - __upper = __high % (__base); \ - __high = __high / (__base); \ +if (__builtin_constant_p (__base) &&is_power_of_2 (__base)) { \ + __mod = n & (__base -1 ); \ + n >>=ilog2 (__base); \ + }else { \ + asm("" :"=a" (__low),"=d" (__high) :"A" (n));\ + __upper = __high; \ +if (__high) { \ + __upper = __high % (__base); \ + __high = __high / (__base); \ + } \ + asm("divl %2" :"=a" (__low),"=d" (__mod) \ + :"rm" (__base),"0" (__low),"1" (__upper)); \ + asm("" :"=A" (n) :"a" (__low),"d" (__high)); \ } \ - asm("divl %2" :"=a" (__low),"=d" (__mod) \ - :"rm" (__base),"0" (__low),"1" (__upper)); \ - asm("" :"=A" (n) :"a" (__low),"d" (__high)); \ __mod; \ })
arch/x86/include/asm/percpu.h +21 -32
75 lines not on this page · raw message
arch/x86/include/asm/processor-flags.h +1 -0
@@ -6,6 +6,7 @@* EFLAGS bits */ #define X86_EFLAGS_CF 0x00000001/* Carry Flag */ +#define X86_EFLAGS_BIT1 0x00000002/* Bit 1 - always on */ #define X86_EFLAGS_PF 0x00000004/* Parity Flag */ #define X86_EFLAGS_AF 0x00000010/* Auxiliary carry Flag */ #define X86_EFLAGS_ZF 0x00000040/* Zero Flag */
arch/x86/include/asm/spinlock.h +1 -14
@@ -79,23 +79,10 @@ static __always_inline int __ticket_spin_trylock(arch_spinlock_t *lock)return cmpxchg (&lock->head_tail, old.head_tail, new.head_tail) == old.head_tail; } -#if (NR_CPUS <256 ) static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock) { - asmvolatile (UNLOCK_LOCK_PREFIX "incb %0" - :"+m" (lock->head_tail) - : - :"memory" ,"cc" ); +__add (&lock->tickets.head,1 ,UNLOCK_LOCK_PREFIX ); } -#else -static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock) -{ - asmvolatile (UNLOCK_LOCK_PREFIX "incw %0" - :"+m" (lock->head_tail) - : - :"memory" ,"cc" ); -} -#endif static inline int __ticket_spin_is_locked (arch_spinlock_t *lock) {
arch/x86/include/asm/thread_info.h +8 -1
@@ -40,7 +40,8 @@ struct thread_info {*/ __u8 supervisor_stack[0 ];#endif -int uaccess_err; + int sig_on_uaccess_error:1; + int uaccess_err:1; /* uaccess failed */ };#define INIT_THREAD_INFO (tsk) \
@@ -231,6 +232,12 @@ static inline struct thread_info *current_thread_info(void)movq PER_CPU_VAR (kernel_stack ),reg ; \ subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg +/* +* Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in +* a certain register (to be used in assembler memory operands). +*/ +#define THREAD_INFO (reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg) +#endif #endif /* !X86_32 */
arch/x86/include/asm/topology.h +0 -2
@@ -130,10 +130,8 @@ extern void setup_node_to_cpumask_map(void); .balance_interval = 1, \ } -#ifdef CONFIG_X86_64 extern int __node_distance (int ,int );#define node_distance (a, b) __node_distance(a, b) -#endif #else /* !CONFIG_NUMA */
arch/x86/include/asm/uaccess.h +1 -1
@@ -462,7 +462,7 @@ struct __large_struct { unsigned long buf[100]; };barrier ();#define uaccess_catch (err) \ - (err) |= current_thread_info()->uaccess_err; \ + (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \ current_thread_info()->uaccess_err = prev_err; \ } while (0)
arch/x86/kernel/cpu/powerflags.c +2 -1
@@ -16,5 +16,6 @@ const char *const x86_power_flags[32] = {"100mhzsteps" ,"hwpstate" ,"" ,/* tsc invariant mapped to constant_tsc */ - /* nothing */ +"cpb" ,/* core performance boost */ + "eff_freq_ro", /* Readonly aperf/mperf */ };
arch/x86/kernel/entry_32.S +4 -0
@@ -625,6 +625,8 @@ work_notifysig: # deal with pending signals and movl %esp, %eax jne work_notifysig_v86 # returning to kernel-space or # vm86-space + TRACE_IRQS_ON + ENABLE_INTERRUPTS(CLBR_NONE) xorl %edx, %edx call do_notify_resume jmp resume_userspace_sig
@@ -638,6 +640,8 @@ work_notifysig_v86: #else movl %esp, %eax #endif + TRACE_IRQS_ON + ENABLE_INTERRUPTS(CLBR_NONE) xorl %edx, %edx call do_notify_resume jmp resume_userspace_sig
arch/x86/kernel/entry_64.S +18 -13
@@ -221,7 +221,7 @@ ENDPROC(native_usergs_sysret64) /*CFI_REL_OFFSET ss,0*/ pushq_cfi %rax /* rsp */ CFI_REL_OFFSET rsp,0 - pushq_cfi $X86_EFLAGS_IF /* eflags - interrupts on */ + pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_BIT1) /* eflags - interrupts on */ /*CFI_REL_OFFSET rflags,0*/ pushq_cfi $__KERNEL_CS /* cs */ /*CFI_REL_OFFSET cs,0*/
@@ -411,7 +411,7 @@ ENTRY(ret_from_fork) RESTORE_REST testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread? - je int_ret_from_sys_call + jz retint_restore_args testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET jnz int_ret_from_sys_call
@@ -465,7 +465,7 @@ ENTRY(system_call) * after the swapgs, so that it can do the swapgs * for the guest and jump here on syscall. */ -ENTRY(system_call_after_swapgs) +GLOBAL(system_call_after_swapgs) movq %rsp,PER_CPU_VAR(old_rsp) movq PER_CPU_VAR(kernel_stack),%rsp
@@ -478,8 +478,7 @@ ENTRY(system_call_after_swapgs) movq %rax,ORIG_RAX-ARGOFFSET(%rsp) movq %rcx,RIP-ARGOFFSET(%rsp) CFI_REL_OFFSET rip,RIP-ARGOFFSET - GET_THREAD_INFO(%rcx) - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx) + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET) jnz tracesys system_call_fastpath: cmpq $__NR_syscall_max,%rax
@@ -496,10 +495,9 @@ ret_from_sys_call: /* edi: flagmask */ sysret_check: LOCKDEP_SYS_EXIT - GET_THREAD_INFO(%rcx) DISABLE_INTERRUPTS(CLBR_NONE) TRACE_IRQS_OFF - movl TI_flags(%rcx),%edx + movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx andl %edi,%edx jnz sysret_careful CFI_REMEMBER_STATE
@@ -583,7 +581,7 @@ sysret_audit: /* Do syscall tracing */ tracesys: #ifdef CONFIG_AUDITSYSCALL - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx) + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET) jz auditsys #endif SAVE_REST
@@ -612,8 +610,6 @@ tracesys: GLOBAL(int_ret_from_sys_call) DISABLE_INTERRUPTS(CLBR_NONE) TRACE_IRQS_OFF - testl $3,CS-ARGOFFSET(%rsp) - je retint_restore_args movl $_TIF_ALLWORK_MASK,%edi /* edi: mask to check */ GLOBAL(int_with_check)
@@ -953,6 +949,7 @@ END(common_interrupt) ENTRY(\sym) INTR_FRAME pushq_cfi $~(\num) +.Lcommon_\sym: interrupt \do_sym jmp ret_from_intr CFI_ENDPROC
@@ -976,13 +973,21 @@ apicinterrupt X86_PLATFORM_IPI_VECTOR \ x86_platform_ipi smp_x86_platform_ipi #ifdef CONFIG_SMP -.irp idx,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, \ + ALIGN + INTR_FRAME +.irp idx,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, \ 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 .if NUM_INVALIDATE_TLB_VECTORS > \idx -apicinterrupt (INVALIDATE_TLB_VECTOR_START)+\idx \ - invalidate_interrupt\idx smp_invalidate_interrupt +ENTRY(invalidate_interrupt\idx) + pushq_cfi $~(INVALIDATE_TLB_VECTOR_START+\idx) + jmp .Lcommon_invalidate_interrupt0 + CFI_ADJUST_CFA_OFFSET -8 +END(invalidate_interrupt\idx) .endif .endr + CFI_ENDPROC +apicinterrupt INVALIDATE_TLB_VECTOR_START, \ + invalidate_interrupt0, smp_invalidate_interrupt #endif apicinterrupt THRESHOLD_APIC_VECTOR \
arch/x86/kernel/process.c +1 -1
@@ -293,7 +293,7 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags) regs.orig_ax =-1 ; regs.ip = (unsigned long ) kernel_thread_helper; regs.cs = __KERNEL_CS |get_kernel_rpl (); - regs.flags =X86_EFLAGS_IF |0x2 ; + regs.flags =X86_EFLAGS_IF |X86_EFLAGS_BIT1 ;/* Ok, create the new process.. */ return do_fork (flags |CLONE_VM |CLONE_UNTRACED ,0 , ®s,0 ,NULL ,NULL );
arch/x86/kernel/traps.c +1 -6
@@ -306,15 +306,10 @@ dotraplinkage void __kprobes do_int3(struct pt_regs *regs, long error_code) == NOTIFY_STOP)return ;#endif /* CONFIG_KGDB_LOW_LEVEL_TRAP */ -#ifdef CONFIG_KPROBES +if (notify_die (DIE_INT3 ,"int3" , regs, error_code,3 ,SIGTRAP ) ==NOTIFY_STOP )return ; -#else -if (notify_die (DIE_TRAP ,"int3" , regs, error_code,3 ,SIGTRAP ) - ==NOTIFY_STOP ) -return ; -#endif preempt_conditional_sti (regs);do_trap (3 ,SIGTRAP ,"int3" , regs, error_code,NULL );
arch/x86/kernel/vsyscall_64.c +68 -9
121 lines not on this page · raw message
arch/x86/lib/string_32.c +3 -5
@@ -164,15 +164,13 @@ EXPORT_SYMBOL(strchr);size_t strlen (const char *s) {int d0; -int res; +size_t res; asmvolatile ("repne\n\t" -"scasb\n\t" -"notl %0\n\t" -"decl %0" +"scasb" :"=c" (res),"=&D" (d0) :"1" (s),"a" (0 ),"0" (0xffffffffu ) :"memory" ); -return res; +return ~res -1 ; }EXPORT_SYMBOL (strlen);#endif
arch/x86/mm/extable.c +1 -1
@@ -25,7 +25,7 @@ int fixup_exception(struct pt_regs *regs)if (fixup) {/* If fixup is less than 16, it means uaccess error */ if (fixup->fixup <16 ) { -current_thread_info ()->uaccess_err = -EFAULT ; +current_thread_info ()->uaccess_err =1 ; regs->ip += fixup->fixup;return 1 ; }
arch/x86/mm/fault.c +16 -6
@@ -626,7 +626,7 @@ pgtable_bad(struct pt_regs *regs, unsigned long error_code, static noinline voidno_context (struct pt_regs *regs,unsigned long error_code, -unsigned long address) +unsigned long address,int signal,int si_code) {struct task_struct *tsk = current;unsigned long *stackend;
@@ -634,8 +634,17 @@ no_context(struct pt_regs *regs, unsigned long error_code,int sig;/* Are we prepared to handle this kernel fault? */ -if (fixup_exception (regs)) +if (fixup_exception (regs)) { +if (current_thread_info ()->sig_on_uaccess_error && signal) { + tsk->thread.trap_no =14 ; + tsk->thread.error_code = error_code |PF_USER ; + tsk->thread.cr2 = address; + +/* XXX: hwpoison faults will set the wrong code. */ +force_sig_info_fault (signal, si_code, address, tsk,0 ); + }return ; + }/* * 32-bit:
@@ -755,7 +764,7 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,if (is_f00f_bug (regs, address))return ; -no_context (regs, error_code, address); +no_context (regs, error_code, address,SIGSEGV , si_code); }static noinline void
@@ -819,7 +828,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,/* Kernel mode? Handle exceptions or die: */ if (!(error_code &PF_USER )) { -no_context (regs, error_code, address); +no_context (regs, error_code, address,SIGBUS ,BUS_ADRERR );return ; }
@@ -854,7 +863,7 @@ mm_fault_error(struct pt_regs *regs, unsigned long error_code,if (!(fault &VM_FAULT_RETRY ))up_read (¤t->mm->mmap_sem);if (!(error_code &PF_USER )) -no_context (regs, error_code, address); +no_context (regs, error_code, address,0 ,0 );return 1 ; }if (!(fault &VM_FAULT_ERROR ))
@@ -864,7 +873,8 @@ mm_fault_error(struct pt_regs *regs, unsigned long error_code,/* Kernel mode? Handle exceptions or die: */ if (!(error_code &PF_USER )) {up_read (¤t->mm->mmap_sem); -no_context (regs, error_code, address); +no_context (regs, error_code, address, +SIGSEGV ,SEGV_MAPERR );return 1 ; }
arch/x86/platform/efi/efi.c +2 -1
@@ -238,7 +238,8 @@ static efi_status_t __init phys_efi_get_time(efi_time_t *tm,spin_lock_irqsave (&rtc_lock, flags);efi_call_phys_prelog (); - status =efi_call_phys2 (efi_phys.get_time, tm, tc); + status =efi_call_phys2 (efi_phys.get_time,virt_to_phys (tm), +virt_to_phys (tc));efi_call_phys_epilog ();spin_unlock_irqrestore (&rtc_lock, flags);return status;
drivers/lguest/x86/core.c +1 -1
@@ -697,7 +697,7 @@ void lguest_arch_setup_regs(struct lg_cpu *cpu, unsigned long start)* interrupts are enabled. We always leave interrupts enabled while * running the Guest. */ - regs->eflags =X86_EFLAGS_IF |0x2 ; + regs->eflags =X86_EFLAGS_IF |X86_EFLAGS_BIT1 ;/* * The "Extended Instruction Pointer" register says where the Guest is
mm/slub.c +2 -2
@@ -368,7 +368,7 @@ static inline bool __cmpxchg_double_slab(struct kmem_cache *s, struct page *pageVM_BUG_ON (!irqs_disabled ());#ifdef CONFIG_CMPXCHG_DOUBLE if (s->flags & __CMPXCHG_DOUBLE) { -if (cmpxchg_double (&page->freelist, +if (cmpxchg_double (&page->freelist, &page->counters, freelist_old, counters_old, freelist_new, counters_new))return 1 ;
@@ -402,7 +402,7 @@ static inline bool cmpxchg_double_slab(struct kmem_cache *s, struct page *page, {#ifdef CONFIG_CMPXCHG_DOUBLE if (s->flags & __CMPXCHG_DOUBLE) { -if (cmpxchg_double (&page->freelist, +if (cmpxchg_double (&page->freelist, &page->counters, freelist_old, counters_old, freelist_new, counters_new))return 1 ;