Skip to content

Commit 19d402c

Browse files
committed
Merge branches 'x86-build-for-linus', 'x86-cleanups-for-linus' and 'x86-debug-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 build/cleanup/debug updates from Ingo Molnar: "Robustify the build process with a quirk to avoid GCC reordering related bugs. Two code cleanups. Simplify entry_64.S CFI annotations, by Jan Beulich" * 'x86-build-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86, build: Change code16gcc.h from a C header to an assembly header * 'x86-cleanups-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86: Simplify __HAVE_ARCH_CMPXCHG tests x86/tsc: Get rid of custom DIV_ROUND() macro * 'x86-debug-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/debug: Drop several unnecessary CFI annotations
4 parents 9895994 + a9cfcce + b08ee5f + 3bab13b commit 19d402c

10 files changed

Lines changed: 47 additions & 75 deletions

File tree

‎arch/x86/Makefile‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,9 @@ endif
1515
# that way we can complain to the user if the CPU is insufficient.
1616
#
1717
# The -m16 option is supported by GCC >= 4.9 and clang >= 3.5. For
18-
# older versions of GCC, we need to play evil and unreliable tricks to
19-
# attempt to ensure that our asm(".code16gcc") is first in the asm
20-
# output.
21-
CODE16GCC_CFLAGS := -m32 -include $(srctree)/arch/x86/boot/code16gcc.h \
22-
$(call cc-option, -fno-toplevel-reorder,\
23-
$(call cc-option, -fno-unit-at-a-time))
18+
# older versions of GCC, include an *assembly* header to make sure that
19+
# gcc doesn't play any games behind our back.
20+
CODE16GCC_CFLAGS := -m32 -Wa,$(srctree)/arch/x86/boot/code16gcc.h
2421
M16_CFLAGS := $(call cc-option, -m16, $(CODE16GCC_CFLAGS))
2522

2623
REALMODE_CFLAGS := $(M16_CFLAGS) -g -Os -D__KERNEL__ \

‎arch/x86/boot/code16gcc.h‎

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
/*
2-
* code16gcc.h
3-
*
4-
* This file is -include'd when compiling 16-bit C code.
5-
* Note: this asm() needs to be emitted before gcc emits any code.
6-
* Depending on gcc version, this requires -fno-unit-at-a-time or
7-
* -fno-toplevel-reorder.
8-
*
9-
* Hopefully gcc will eventually have a real -m16 option so we can
10-
* drop this hack long term.
11-
*/
1+
#
2+
# code16gcc.h
3+
#
4+
# This file is added to the assembler via -Wa when compiling 16-bit C code.
5+
# This is done this way instead via asm() to make sure gcc does not reorder
6+
# things around us.
7+
#
8+
# gcc 4.9+ has a real -m16 option so we can drop this hack long term.
9+
#
1210

13-
#ifndef __ASSEMBLY__
14-
asm(".code16gcc");
15-
#endif
11+
.code16gcc

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <linux/compiler.h>
55
#include <asm/alternative.h> /* Provides LOCK_PREFIX */
66

7+
#define __HAVE_ARCH_CMPXCHG 1
8+
79
/*
810
* Non-existant functions to indicate usage errors at link time
911
* (or compile-time if the compiler implements __compiletime_error().
@@ -143,7 +145,6 @@ extern void __add_wrong_size(void)
143145
# include <asm/cmpxchg_64.h>
144146
#endif
145147

146-
#ifdef __HAVE_ARCH_CMPXCHG
147148
#define cmpxchg(ptr, old, new) \
148149
__cmpxchg(ptr, old, new, sizeof(*(ptr)))
149150

@@ -152,7 +153,6 @@ extern void __add_wrong_size(void)
152153

153154
#define cmpxchg_local(ptr, old, new) \
154155
__cmpxchg_local(ptr, old, new, sizeof(*(ptr)))
155-
#endif
156156

157157
/*
158158
* xadd() adds "inc" to "*ptr" and atomically returns the previous

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ static inline void set_64bit(volatile u64 *ptr, u64 value)
3434
: "memory");
3535
}
3636

37-
#define __HAVE_ARCH_CMPXCHG 1
38-
3937
#ifdef CONFIG_X86_CMPXCHG64
4038
#define cmpxchg64(ptr, o, n) \
4139
((__typeof__(*(ptr)))__cmpxchg64((ptr), (unsigned long long)(o), \

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ static inline void set_64bit(volatile u64 *ptr, u64 val)
66
*ptr = val;
77
}
88

9-
#define __HAVE_ARCH_CMPXCHG 1
10-
119
#define cmpxchg64(ptr, o, n) \
1210
({ \
1311
BUILD_BUG_ON(sizeof(*(ptr)) != 8); \

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#define RTC_ALWAYS_BCD 1 /* RTC operates in binary mode */
1414
#endif
1515

16-
#if defined(CONFIG_X86_32) && defined(__HAVE_ARCH_CMPXCHG)
16+
#if defined(CONFIG_X86_32)
1717
/*
1818
* This lock provides nmi access to the CMOS/RTC registers. It has some
1919
* special properties. It is owned by a CPU and stores the index register

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

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,23 +100,11 @@ do { \
100100
static inline int __mutex_fastpath_trylock(atomic_t *count,
101101
int (*fail_fn)(atomic_t *))
102102
{
103-
/*
104-
* We have two variants here. The cmpxchg based one is the best one
105-
* because it never induce a false contention state. It is included
106-
* here because architectures using the inc/dec algorithms over the
107-
* xchg ones are much more likely to support cmpxchg natively.
108-
*
109-
* If not we fall back to the spinlock based variant - that is
110-
* just as efficient (and simpler) as a 'destructive' probing of
111-
* the mutex state would be.
112-
*/
113-
#ifdef __HAVE_ARCH_CMPXCHG
103+
/* cmpxchg because it never induces a false contention state. */
114104
if (likely(atomic_cmpxchg(count, 1, 0) == 1))
115105
return 1;
106+
116107
return 0;
117-
#else
118-
return fail_fn(count);
119-
#endif
120108
}
121109

122110
#endif /* _ASM_X86_MUTEX_32_H */

‎arch/x86/kernel/acpi/boot.c‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,6 @@ int acpi_fix_pin2_polarity __initdata;
7474
static u64 acpi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
7575
#endif
7676

77-
#ifndef __HAVE_ARCH_CMPXCHG
78-
#warning ACPI uses CMPXCHG, i486 and later hardware
79-
#endif
80-
8177
/* --------------------------------------------------------------------------
8278
Boot-time Configuration
8379
-------------------------------------------------------------------------- */

‎arch/x86/kernel/entry_64.S‎

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ ENDPROC(native_usergs_sysret64)
207207
*/
208208
.macro XCPT_FRAME start=1 offset=0
209209
INTR_FRAME \start, RIP+\offset-ORIG_RAX
210-
/*CFI_REL_OFFSET orig_rax, ORIG_RAX-ORIG_RAX*/
211210
.endm
212211

213212
/*
@@ -287,21 +286,21 @@ ENDPROC(native_usergs_sysret64)
287286
ENTRY(save_paranoid)
288287
XCPT_FRAME 1 RDI+8
289288
cld
290-
movq_cfi rdi, RDI+8
291-
movq_cfi rsi, RSI+8
289+
movq %rdi, RDI+8(%rsp)
290+
movq %rsi, RSI+8(%rsp)
292291
movq_cfi rdx, RDX+8
293292
movq_cfi rcx, RCX+8
294293
movq_cfi rax, RAX+8
295-
movq_cfi r8, R8+8
296-
movq_cfi r9, R9+8
297-
movq_cfi r10, R10+8
298-
movq_cfi r11, R11+8
294+
movq %r8, R8+8(%rsp)
295+
movq %r9, R9+8(%rsp)
296+
movq %r10, R10+8(%rsp)
297+
movq %r11, R11+8(%rsp)
299298
movq_cfi rbx, RBX+8
300-
movq_cfi rbp, RBP+8
301-
movq_cfi r12, R12+8
302-
movq_cfi r13, R13+8
303-
movq_cfi r14, R14+8
304-
movq_cfi r15, R15+8
299+
movq %rbp, RBP+8(%rsp)
300+
movq %r12, R12+8(%rsp)
301+
movq %r13, R13+8(%rsp)
302+
movq %r14, R14+8(%rsp)
303+
movq %r15, R15+8(%rsp)
305304
movl $1,%ebx
306305
movl $MSR_GS_BASE,%ecx
307306
rdmsr
@@ -1387,21 +1386,21 @@ ENTRY(error_entry)
13871386
CFI_ADJUST_CFA_OFFSET 15*8
13881387
/* oldrax contains error code */
13891388
cld
1390-
movq_cfi rdi, RDI+8
1391-
movq_cfi rsi, RSI+8
1392-
movq_cfi rdx, RDX+8
1393-
movq_cfi rcx, RCX+8
1394-
movq_cfi rax, RAX+8
1395-
movq_cfi r8, R8+8
1396-
movq_cfi r9, R9+8
1397-
movq_cfi r10, R10+8
1398-
movq_cfi r11, R11+8
1389+
movq %rdi, RDI+8(%rsp)
1390+
movq %rsi, RSI+8(%rsp)
1391+
movq %rdx, RDX+8(%rsp)
1392+
movq %rcx, RCX+8(%rsp)
1393+
movq %rax, RAX+8(%rsp)
1394+
movq %r8, R8+8(%rsp)
1395+
movq %r9, R9+8(%rsp)
1396+
movq %r10, R10+8(%rsp)
1397+
movq %r11, R11+8(%rsp)
13991398
movq_cfi rbx, RBX+8
1400-
movq_cfi rbp, RBP+8
1401-
movq_cfi r12, R12+8
1402-
movq_cfi r13, R13+8
1403-
movq_cfi r14, R14+8
1404-
movq_cfi r15, R15+8
1399+
movq %rbp, RBP+8(%rsp)
1400+
movq %r12, R12+8(%rsp)
1401+
movq %r13, R13+8(%rsp)
1402+
movq %r14, R14+8(%rsp)
1403+
movq %r15, R15+8(%rsp)
14051404
xorl %ebx,%ebx
14061405
testl $3,CS+8(%rsp)
14071406
je error_kernelspace
@@ -1419,6 +1418,7 @@ error_sti:
14191418
* compat mode. Check for these here too.
14201419
*/
14211420
error_kernelspace:
1421+
CFI_REL_OFFSET rcx, RCX+8
14221422
incl %ebx
14231423
leaq native_irq_return_iret(%rip),%rcx
14241424
cmpq %rcx,RIP+8(%rsp)

‎arch/x86/kernel/tsc.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,6 @@ static inline unsigned long long cycles_2_ns(unsigned long long cyc)
234234
return ns;
235235
}
236236

237-
/* XXX surely we already have this someplace in the kernel?! */
238-
#define DIV_ROUND(n, d) (((n) + ((d) / 2)) / (d))
239-
240237
static void set_cyc2ns_scale(unsigned long cpu_khz, int cpu)
241238
{
242239
unsigned long long tsc_now, ns_now;
@@ -259,7 +256,9 @@ static void set_cyc2ns_scale(unsigned long cpu_khz, int cpu)
259256
* time function is continuous; see the comment near struct
260257
* cyc2ns_data.
261258
*/
262-
data->cyc2ns_mul = DIV_ROUND(NSEC_PER_MSEC << CYC2NS_SCALE_FACTOR, cpu_khz);
259+
data->cyc2ns_mul =
260+
DIV_ROUND_CLOSEST(NSEC_PER_MSEC << CYC2NS_SCALE_FACTOR,
261+
cpu_khz);
263262
data->cyc2ns_shift = CYC2NS_SCALE_FACTOR;
264263
data->cyc2ns_offset = ns_now -
265264
mul_u64_u32_shr(tsc_now, data->cyc2ns_mul, CYC2NS_SCALE_FACTOR);

0 commit comments

Comments
 (0)