Skip to content

Commit 69734b6

Browse files
committed
Merge branch 'x86-asm-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
* 'x86-asm-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (21 commits) x86: Fix atomic64_xxx_cx8() functions x86: Fix and improve cmpxchg_double{,_local}() x86_64, asm: Optimise fls(), ffs() and fls64() x86, bitops: Move fls64.h inside __KERNEL__ x86: Fix and improve percpu_cmpxchg{8,16}b_double() x86: Report cpb and eff_freq_ro flags correctly x86/i386: Use less assembly in strlen(), speed things up a bit x86: Use the same node_distance for 32 and 64-bit x86: Fix rflags in FAKE_STACK_FRAME x86: Clean up and extend do_int3() x86: Call do_notify_resume() with interrupts enabled x86/div64: Add a micro-optimization shortcut if base is power of two x86-64: Cleanup some assembly entry points x86-64: Slightly shorten line system call entry and exit paths x86-64: Reduce amount of redundant code generated for invalidate_interruptNN x86-64: Slightly shorten int_ret_from_sys_call x86, efi: Convert efi_phys_get_time() args to physical addresses x86: Default to vsyscall=emulate x86-64: Set siginfo and context on vsyscall emulation faults x86: consolidate xchg and xadd macros ...
2 parents 67b0243 + ceb7b40 commit 69734b6

26 files changed

Lines changed: 345 additions & 306 deletions

‎Documentation/kernel-parameters.txt‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2755,11 +2755,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
27552755
functions are at fixed addresses, they make nice
27562756
targets for exploits that can control RIP.
27572757

2758-
emulate Vsyscalls turn into traps and are emulated
2759-
reasonably safely.
2758+
emulate [default] Vsyscalls turn into traps and are
2759+
emulated reasonably safely.
27602760

2761-
native [default] Vsyscalls are native syscall
2762-
instructions.
2761+
native Vsyscalls are native syscall instructions.
27632762
This is a little bit faster than trapping
27642763
and makes a few dynamic recompilers work
27652764
better than they would in emulation mode.

‎arch/x86/ia32/ia32entry.S‎

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ ENTRY(ia32_sysenter_target)
134134
CFI_REL_OFFSET rsp,0
135135
pushfq_cfi
136136
/*CFI_REL_OFFSET rflags,0*/
137-
movl 8*3-THREAD_SIZE+TI_sysenter_return(%rsp), %r10d
137+
movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
138138
CFI_REGISTER rip,r10
139139
pushq_cfi $__USER32_CS
140140
/*CFI_REL_OFFSET cs,0*/
@@ -150,9 +150,8 @@ ENTRY(ia32_sysenter_target)
150150
.section __ex_table,"a"
151151
.quad 1b,ia32_badarg
152152
.previous
153-
GET_THREAD_INFO(%r10)
154-
orl $TS_COMPAT,TI_status(%r10)
155-
testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
153+
orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
154+
testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
156155
CFI_REMEMBER_STATE
157156
jnz sysenter_tracesys
158157
cmpq $(IA32_NR_syscalls-1),%rax
@@ -162,13 +161,12 @@ sysenter_do_call:
162161
sysenter_dispatch:
163162
call *ia32_sys_call_table(,%rax,8)
164163
movq %rax,RAX-ARGOFFSET(%rsp)
165-
GET_THREAD_INFO(%r10)
166164
DISABLE_INTERRUPTS(CLBR_NONE)
167165
TRACE_IRQS_OFF
168-
testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
166+
testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
169167
jnz sysexit_audit
170168
sysexit_from_sys_call:
171-
andl $~TS_COMPAT,TI_status(%r10)
169+
andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
172170
/* clear IF, that popfq doesn't enable interrupts early */
173171
andl $~0x200,EFLAGS-R11(%rsp)
174172
movl RIP-R11(%rsp),%edx /* User %eip */
@@ -205,7 +203,7 @@ sysexit_from_sys_call:
205203
.endm
206204

207205
.macro auditsys_exit exit
208-
testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
206+
testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
209207
jnz ia32_ret_from_sys_call
210208
TRACE_IRQS_ON
211209
sti
@@ -215,12 +213,11 @@ sysexit_from_sys_call:
215213
movzbl %al,%edi /* zero-extend that into %edi */
216214
inc %edi /* first arg, 0->1(AUDITSC_SUCCESS), 1->2(AUDITSC_FAILURE) */
217215
call audit_syscall_exit
218-
GET_THREAD_INFO(%r10)
219216
movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall return value */
220217
movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
221218
cli
222219
TRACE_IRQS_OFF
223-
testl %edi,TI_flags(%r10)
220+
testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
224221
jz \exit
225222
CLEAR_RREGS -ARGOFFSET
226223
jmp int_with_check
@@ -238,7 +235,7 @@ sysexit_audit:
238235

239236
sysenter_tracesys:
240237
#ifdef CONFIG_AUDITSYSCALL
241-
testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
238+
testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
242239
jz sysenter_auditsys
243240
#endif
244241
SAVE_REST
@@ -309,9 +306,8 @@ ENTRY(ia32_cstar_target)
309306
.section __ex_table,"a"
310307
.quad 1b,ia32_badarg
311308
.previous
312-
GET_THREAD_INFO(%r10)
313-
orl $TS_COMPAT,TI_status(%r10)
314-
testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
309+
orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
310+
testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
315311
CFI_REMEMBER_STATE
316312
jnz cstar_tracesys
317313
cmpq $IA32_NR_syscalls-1,%rax
@@ -321,13 +317,12 @@ cstar_do_call:
321317
cstar_dispatch:
322318
call *ia32_sys_call_table(,%rax,8)
323319
movq %rax,RAX-ARGOFFSET(%rsp)
324-
GET_THREAD_INFO(%r10)
325320
DISABLE_INTERRUPTS(CLBR_NONE)
326321
TRACE_IRQS_OFF
327-
testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
322+
testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
328323
jnz sysretl_audit
329324
sysretl_from_sys_call:
330-
andl $~TS_COMPAT,TI_status(%r10)
325+
andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
331326
RESTORE_ARGS 0,-ARG_SKIP,0,0,0
332327
movl RIP-ARGOFFSET(%rsp),%ecx
333328
CFI_REGISTER rip,rcx
@@ -355,7 +350,7 @@ sysretl_audit:
355350

356351
cstar_tracesys:
357352
#ifdef CONFIG_AUDITSYSCALL
358-
testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
353+
testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
359354
jz cstar_auditsys
360355
#endif
361356
xchgl %r9d,%ebp
@@ -420,9 +415,8 @@ ENTRY(ia32_syscall)
420415
/* note the registers are not zero extended to the sf.
421416
this could be a problem. */
422417
SAVE_ARGS 0,1,0
423-
GET_THREAD_INFO(%r10)
424-
orl $TS_COMPAT,TI_status(%r10)
425-
testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
418+
orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
419+
testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
426420
jnz ia32_tracesys
427421
cmpq $(IA32_NR_syscalls-1),%rax
428422
ja ia32_badsys
@@ -459,8 +453,8 @@ quiet_ni_syscall:
459453
CFI_ENDPROC
460454

461455
.macro PTREGSCALL label, func, arg
462-
.globl \label
463-
\label:
456+
ALIGN
457+
GLOBAL(\label)
464458
leaq \func(%rip),%rax
465459
leaq -ARGOFFSET+8(%rsp),\arg /* 8 for return address */
466460
jmp ia32_ptregs_common
@@ -477,7 +471,8 @@ quiet_ni_syscall:
477471
PTREGSCALL stub32_vfork, sys_vfork, %rdi
478472
PTREGSCALL stub32_iopl, sys_iopl, %rsi
479473

480-
ENTRY(ia32_ptregs_common)
474+
ALIGN
475+
ia32_ptregs_common:
481476
popq %r11
482477
CFI_ENDPROC
483478
CFI_STARTPROC32 simple

‎arch/x86/include/asm/alternative-asm.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
#ifdef CONFIG_SMP
66
.macro LOCK_PREFIX
7-
1: lock
7+
672: lock
88
.section .smp_locks,"a"
99
.balign 4
10-
.long 1b - .
10+
.long 672b - .
1111
.previous
1212
.endm
1313
#else

‎arch/x86/include/asm/bitops.h‎

Lines changed: 63 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ static inline unsigned long __fls(unsigned long word)
380380
return word;
381381
}
382382

383+
#undef ADDR
384+
383385
#ifdef __KERNEL__
384386
/**
385387
* ffs - find first set bit in word
@@ -395,10 +397,25 @@ static inline unsigned long __fls(unsigned long word)
395397
static inline int ffs(int x)
396398
{
397399
int r;
398-
#ifdef CONFIG_X86_CMOV
400+
401+
#ifdef CONFIG_X86_64
402+
/*
403+
* AMD64 says BSFL won't clobber the dest reg if x==0; Intel64 says the
404+
* dest reg is undefined if x==0, but their CPU architect says its
405+
* value is written to set it to the same as before, except that the
406+
* top 32 bits will be cleared.
407+
*
408+
* We cannot do this on 32 bits because at the very least some
409+
* 486 CPUs did not behave this way.
410+
*/
411+
long tmp = -1;
412+
asm("bsfl %1,%0"
413+
: "=r" (r)
414+
: "rm" (x), "0" (tmp));
415+
#elif defined(CONFIG_X86_CMOV)
399416
asm("bsfl %1,%0\n\t"
400417
"cmovzl %2,%0"
401-
: "=r" (r) : "rm" (x), "r" (-1));
418+
: "=&r" (r) : "rm" (x), "r" (-1));
402419
#else
403420
asm("bsfl %1,%0\n\t"
404421
"jnz 1f\n\t"
@@ -422,7 +439,22 @@ static inline int ffs(int x)
422439
static inline int fls(int x)
423440
{
424441
int r;
425-
#ifdef CONFIG_X86_CMOV
442+
443+
#ifdef CONFIG_X86_64
444+
/*
445+
* AMD64 says BSRL won't clobber the dest reg if x==0; Intel64 says the
446+
* dest reg is undefined if x==0, but their CPU architect says its
447+
* value is written to set it to the same as before, except that the
448+
* top 32 bits will be cleared.
449+
*
450+
* We cannot do this on 32 bits because at the very least some
451+
* 486 CPUs did not behave this way.
452+
*/
453+
long tmp = -1;
454+
asm("bsrl %1,%0"
455+
: "=r" (r)
456+
: "rm" (x), "0" (tmp));
457+
#elif defined(CONFIG_X86_CMOV)
426458
asm("bsrl %1,%0\n\t"
427459
"cmovzl %2,%0"
428460
: "=&r" (r) : "rm" (x), "rm" (-1));
@@ -434,11 +466,35 @@ static inline int fls(int x)
434466
#endif
435467
return r + 1;
436468
}
437-
#endif /* __KERNEL__ */
438-
439-
#undef ADDR
440469

441-
#ifdef __KERNEL__
470+
/**
471+
* fls64 - find last set bit in a 64-bit word
472+
* @x: the word to search
473+
*
474+
* This is defined in a similar way as the libc and compiler builtin
475+
* ffsll, but returns the position of the most significant set bit.
476+
*
477+
* fls64(value) returns 0 if value is 0 or the position of the last
478+
* set bit if value is nonzero. The last (most significant) bit is
479+
* at position 64.
480+
*/
481+
#ifdef CONFIG_X86_64
482+
static __always_inline int fls64(__u64 x)
483+
{
484+
long bitpos = -1;
485+
/*
486+
* AMD64 says BSRQ won't clobber the dest reg if x==0; Intel64 says the
487+
* dest reg is undefined if x==0, but their CPU architect says its
488+
* value is written to set it to the same as before.
489+
*/
490+
asm("bsrq %1,%0"
491+
: "+r" (bitpos)
492+
: "rm" (x));
493+
return bitpos + 1;
494+
}
495+
#else
496+
#include <asm-generic/bitops/fls64.h>
497+
#endif
442498

443499
#include <asm-generic/bitops/find.h>
444500

@@ -450,12 +506,6 @@ static inline int fls(int x)
450506

451507
#include <asm-generic/bitops/const_hweight.h>
452508

453-
#endif /* __KERNEL__ */
454-
455-
#include <asm-generic/bitops/fls64.h>
456-
457-
#ifdef __KERNEL__
458-
459509
#include <asm-generic/bitops/le.h>
460510

461511
#include <asm-generic/bitops/ext2-atomic-setbit.h>

0 commit comments

Comments
 (0)