Skip to content

Commit 3234282

Browse files
Jan BeulichH. Peter Anvin
authored andcommitted
x86, asm: Fix CFI macro invocations to deal with shortcomings in gas
gas prior to (perhaps) 2.16.90 has problems with passing non- parenthesized expressions containing spaces to macros. Spaces, however, get inserted by cpp between any macro expanding to a number and a subsequent + or -. For the +, current x86 gas then removes the space again (future gas may not do so), but for the - the space gets retained and is then considered a separator between macro arguments. Fix the respective definitions for both the - and + cases, so that they neither contain spaces nor make cpp insert any (the latter by adding seemingly redundant parentheses). Signed-off-by: Jan Beulich <jbeulich@novell.com> LKML-Reference: <4CBDBEBA020000780001E05A@vpn.id2.novell.com> Cc: Alexander van Heukelum <heukelum@fastmail.fm> Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
1 parent d0ed0c3 commit 3234282

7 files changed

Lines changed: 56 additions & 79 deletions

File tree

‎Kbuild‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ targets += arch/$(SRCARCH)/kernel/asm-offsets.s
5353
# Default sed regexp - multiline due to syntax constraints
5454
define sed-y
5555
"/^->/{s:->#\(.*\):/* \1 */:; \
56-
s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
56+
s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 (\2) /* \3 */:; \
5757
s:->::; p;}"
5858
endef
5959

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

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -48,36 +48,38 @@ For 32-bit we have the following conventions - kernel is built with
4848

4949

5050
/*
51-
* 64-bit system call stack frame layout defines and helpers,
52-
* for assembly code:
51+
* 64-bit system call stack frame layout defines and helpers, for
52+
* assembly code (note that the seemingly unnecessary parentheses
53+
* are to prevent cpp from inserting spaces in expressions that get
54+
* passed to macros):
5355
*/
5456

55-
#define R15 0
56-
#define R14 8
57-
#define R13 16
58-
#define R12 24
59-
#define RBP 32
60-
#define RBX 40
57+
#define R15 (0)
58+
#define R14 (8)
59+
#define R13 (16)
60+
#define R12 (24)
61+
#define RBP (32)
62+
#define RBX (40)
6163

6264
/* arguments: interrupts/non tracing syscalls only save up to here: */
63-
#define R11 48
64-
#define R10 56
65-
#define R9 64
66-
#define R8 72
67-
#define RAX 80
68-
#define RCX 88
69-
#define RDX 96
70-
#define RSI 104
71-
#define RDI 112
72-
#define ORIG_RAX 120 /* + error_code */
65+
#define R11 (48)
66+
#define R10 (56)
67+
#define R9 (64)
68+
#define R8 (72)
69+
#define RAX (80)
70+
#define RCX (88)
71+
#define RDX (96)
72+
#define RSI (104)
73+
#define RDI (112)
74+
#define ORIG_RAX (120) /* + error_code */
7375
/* end of arguments */
7476

7577
/* cpu exception frame or undefined in case of fast syscall: */
76-
#define RIP 128
77-
#define CS 136
78-
#define EFLAGS 144
79-
#define RSP 152
80-
#define SS 160
78+
#define RIP (128)
79+
#define CS (136)
80+
#define EFLAGS (144)
81+
#define RSP (152)
82+
#define SS (160)
8183

8284
#define ARGOFFSET R11
8385
#define SWFRAME ORIG_RAX
@@ -111,7 +113,7 @@ For 32-bit we have the following conventions - kernel is built with
111113
.endif
112114
.endm
113115

114-
#define ARG_SKIP 9*8
116+
#define ARG_SKIP (9*8)
115117

116118
.macro RESTORE_ARGS skiprax=0, addskip=0, skiprcx=0, skipr11=0, \
117119
skipr8910=0, skiprdx=0
@@ -169,7 +171,7 @@ For 32-bit we have the following conventions - kernel is built with
169171
.endif
170172
.endm
171173

172-
#define REST_SKIP 6*8
174+
#define REST_SKIP (6*8)
173175

174176
.macro SAVE_REST
175177
subq $REST_SKIP, %rsp

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

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,11 @@ BUILD_INTERRUPT(call_function_single_interrupt,CALL_FUNCTION_SINGLE_VECTOR)
1616
BUILD_INTERRUPT(irq_move_cleanup_interrupt,IRQ_MOVE_CLEANUP_VECTOR)
1717
BUILD_INTERRUPT(reboot_interrupt,REBOOT_VECTOR)
1818

19-
BUILD_INTERRUPT3(invalidate_interrupt0,INVALIDATE_TLB_VECTOR_START+0,
20-
smp_invalidate_interrupt)
21-
BUILD_INTERRUPT3(invalidate_interrupt1,INVALIDATE_TLB_VECTOR_START+1,
22-
smp_invalidate_interrupt)
23-
BUILD_INTERRUPT3(invalidate_interrupt2,INVALIDATE_TLB_VECTOR_START+2,
24-
smp_invalidate_interrupt)
25-
BUILD_INTERRUPT3(invalidate_interrupt3,INVALIDATE_TLB_VECTOR_START+3,
26-
smp_invalidate_interrupt)
27-
BUILD_INTERRUPT3(invalidate_interrupt4,INVALIDATE_TLB_VECTOR_START+4,
28-
smp_invalidate_interrupt)
29-
BUILD_INTERRUPT3(invalidate_interrupt5,INVALIDATE_TLB_VECTOR_START+5,
30-
smp_invalidate_interrupt)
31-
BUILD_INTERRUPT3(invalidate_interrupt6,INVALIDATE_TLB_VECTOR_START+6,
32-
smp_invalidate_interrupt)
33-
BUILD_INTERRUPT3(invalidate_interrupt7,INVALIDATE_TLB_VECTOR_START+7,
19+
.irpc idx, "01234567"
20+
BUILD_INTERRUPT3(invalidate_interrupt\idx,
21+
(INVALIDATE_TLB_VECTOR_START)+\idx,
3422
smp_invalidate_interrupt)
23+
.endr
3524
#endif
3625

3726
BUILD_INTERRUPT(x86_platform_ipi, X86_PLATFORM_IPI_VECTOR)

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,31 +73,31 @@
7373

7474
#define GDT_ENTRY_DEFAULT_USER_DS 15
7575

76-
#define GDT_ENTRY_KERNEL_BASE 12
76+
#define GDT_ENTRY_KERNEL_BASE (12)
7777

78-
#define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE + 0)
78+
#define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
7979

80-
#define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE + 1)
80+
#define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
8181

82-
#define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE + 4)
83-
#define GDT_ENTRY_LDT (GDT_ENTRY_KERNEL_BASE + 5)
82+
#define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
83+
#define GDT_ENTRY_LDT (GDT_ENTRY_KERNEL_BASE+5)
8484

85-
#define GDT_ENTRY_PNPBIOS_BASE (GDT_ENTRY_KERNEL_BASE + 6)
86-
#define GDT_ENTRY_APMBIOS_BASE (GDT_ENTRY_KERNEL_BASE + 11)
85+
#define GDT_ENTRY_PNPBIOS_BASE (GDT_ENTRY_KERNEL_BASE+6)
86+
#define GDT_ENTRY_APMBIOS_BASE (GDT_ENTRY_KERNEL_BASE+11)
8787

88-
#define GDT_ENTRY_ESPFIX_SS (GDT_ENTRY_KERNEL_BASE + 14)
89-
#define __ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)
88+
#define GDT_ENTRY_ESPFIX_SS (GDT_ENTRY_KERNEL_BASE+14)
89+
#define __ESPFIX_SS (GDT_ENTRY_ESPFIX_SS*8)
9090

91-
#define GDT_ENTRY_PERCPU (GDT_ENTRY_KERNEL_BASE + 15)
91+
#define GDT_ENTRY_PERCPU (GDT_ENTRY_KERNEL_BASE+15)
9292
#ifdef CONFIG_SMP
9393
#define __KERNEL_PERCPU (GDT_ENTRY_PERCPU * 8)
9494
#else
9595
#define __KERNEL_PERCPU 0
9696
#endif
9797

98-
#define GDT_ENTRY_STACK_CANARY (GDT_ENTRY_KERNEL_BASE + 16)
98+
#define GDT_ENTRY_STACK_CANARY (GDT_ENTRY_KERNEL_BASE+16)
9999
#ifdef CONFIG_CC_STACKPROTECTOR
100-
#define __KERNEL_STACK_CANARY (GDT_ENTRY_STACK_CANARY * 8)
100+
#define __KERNEL_STACK_CANARY (GDT_ENTRY_STACK_CANARY*8)
101101
#else
102102
#define __KERNEL_STACK_CANARY 0
103103
#endif
@@ -182,10 +182,10 @@
182182

183183
#endif
184184

185-
#define __KERNEL_CS (GDT_ENTRY_KERNEL_CS * 8)
186-
#define __KERNEL_DS (GDT_ENTRY_KERNEL_DS * 8)
187-
#define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS* 8 + 3)
188-
#define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS* 8 + 3)
185+
#define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
186+
#define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
187+
#define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
188+
#define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
189189
#ifndef CONFIG_PARAVIRT
190190
#define get_kernel_rpl() 0
191191
#endif

‎arch/x86/kernel/asm-offsets_32.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ void foo(void)
9999

100100
DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
101101
DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
102-
DEFINE(PTRS_PER_PTE, PTRS_PER_PTE);
103-
DEFINE(PTRS_PER_PMD, PTRS_PER_PMD);
104-
DEFINE(PTRS_PER_PGD, PTRS_PER_PGD);
102+
DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
105103

106104
OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
107105

‎arch/x86/kernel/entry_32.S‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,20 +382,20 @@ sysenter_past_esp:
382382
* enough kernel state to call TRACE_IRQS_OFF can be called - but
383383
* we immediately enable interrupts at that point anyway.
384384
*/
385-
pushl_cfi $(__USER_DS)
385+
pushl_cfi $__USER_DS
386386
/*CFI_REL_OFFSET ss, 0*/
387387
pushl_cfi %ebp
388388
CFI_REL_OFFSET esp, 0
389389
pushfl_cfi
390390
orl $X86_EFLAGS_IF, (%esp)
391-
pushl_cfi $(__USER_CS)
391+
pushl_cfi $__USER_CS
392392
/*CFI_REL_OFFSET cs, 0*/
393393
/*
394394
* Push current_thread_info()->sysenter_return to the stack.
395395
* A tiny bit of offset fixup is necessary - 4*4 means the 4 words
396396
* pushed above; +8 corresponds to copy_thread's esp0 setting.
397397
*/
398-
pushl_cfi (TI_sysenter_return-THREAD_SIZE+8+4*4)(%esp)
398+
pushl_cfi TI_sysenter_return-THREAD_SIZE_asm+8+4*4(%esp)
399399
CFI_REL_OFFSET eip, 0
400400

401401
pushl_cfi %eax

‎arch/x86/kernel/entry_64.S‎

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -963,22 +963,10 @@ apicinterrupt X86_PLATFORM_IPI_VECTOR \
963963
x86_platform_ipi smp_x86_platform_ipi
964964

965965
#ifdef CONFIG_SMP
966-
apicinterrupt INVALIDATE_TLB_VECTOR_START+0 \
967-
invalidate_interrupt0 smp_invalidate_interrupt
968-
apicinterrupt INVALIDATE_TLB_VECTOR_START+1 \
969-
invalidate_interrupt1 smp_invalidate_interrupt
970-
apicinterrupt INVALIDATE_TLB_VECTOR_START+2 \
971-
invalidate_interrupt2 smp_invalidate_interrupt
972-
apicinterrupt INVALIDATE_TLB_VECTOR_START+3 \
973-
invalidate_interrupt3 smp_invalidate_interrupt
974-
apicinterrupt INVALIDATE_TLB_VECTOR_START+4 \
975-
invalidate_interrupt4 smp_invalidate_interrupt
976-
apicinterrupt INVALIDATE_TLB_VECTOR_START+5 \
977-
invalidate_interrupt5 smp_invalidate_interrupt
978-
apicinterrupt INVALIDATE_TLB_VECTOR_START+6 \
979-
invalidate_interrupt6 smp_invalidate_interrupt
980-
apicinterrupt INVALIDATE_TLB_VECTOR_START+7 \
981-
invalidate_interrupt7 smp_invalidate_interrupt
966+
.irpc idx, "01234567"
967+
apicinterrupt (INVALIDATE_TLB_VECTOR_START)+\idx \
968+
invalidate_interrupt\idx smp_invalidate_interrupt
969+
.endr
982970
#endif
983971

984972
apicinterrupt THRESHOLD_APIC_VECTOR \

0 commit comments

Comments
 (0)