Skip to content

Commit 6f7e639

Browse files
committed
Merge tag 'x86_entry_for_7.0-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 entry code updates from Dave Hansen: "This is entirely composed of a set of long overdue VDSO cleanups. They makes the VDSO build much more logical and zap quite a bit of old cruft. It also results in a coveted net-code-removal diffstat" * tag 'x86_entry_for_7.0-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/entry/vdso: Add vdso2c to .gitignore x86/entry/vdso32: Omit '.cfi_offset eflags' for LLVM < 16 MAINTAINERS: Adjust vdso file entry in INTEL SGX x86/entry/vdso/selftest: Update location of vgetrandom-chacha.S x86/entry/vdso: Fix filtering of vdso compiler flags x86/entry/vdso: Update the object paths for "make vdso_install" x86/entry/vdso32: When using int $0x80, use it directly x86/cpufeature: Replace X86_FEATURE_SYSENTER32 with X86_FEATURE_SYSFAST32 x86/vdso: Abstract out vdso system call internals x86/entry/vdso: Include GNU_PROPERTY and GNU_STACK PHDRs x86/entry/vdso32: Remove open-coded DWARF in sigreturn.S x86/entry/vdso32: Remove SYSCALL_ENTER_KERNEL macro in sigreturn.S x86/entry/vdso32: Don't rely on int80_landing_pad for adjusting ip x86/entry/vdso: Refactor the vdso build x86/entry/vdso: Move vdso2c to arch/x86/tools x86/entry/vdso: Rename vdso_image_* to vdso*_image
2 parents ca8f421 + ce9b1c1 commit 6f7e639

50 files changed

Lines changed: 459 additions & 494 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

MAINTAINERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13032,7 +13032,7 @@ S: Supported
1303213032
Q: https://patchwork.kernel.org/project/intel-sgx/list/
1303313033
T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86/sgx
1303413034
F: Documentation/arch/x86/sgx.rst
13035-
F: arch/x86/entry/vdso/vsgx.S
13035+
F: arch/x86/entry/vdso/vdso64/vsgx.S
1303613036
F: arch/x86/include/asm/sgx.h
1303713037
F: arch/x86/include/uapi/asm/sgx.h
1303813038
F: arch/x86/kernel/cpu/sgx/*

arch/x86/Kconfig.cpufeatures

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ config X86_REQUIRED_FEATURE_MOVBE
5656
def_bool y
5757
depends on MATOM
5858

59+
config X86_REQUIRED_FEATURE_SYSFAST32
60+
def_bool y
61+
depends on X86_64 && !X86_FRED
62+
5963
config X86_REQUIRED_FEATURE_CPUID
6064
def_bool y
6165
depends on X86_64
@@ -120,6 +124,10 @@ config X86_DISABLED_FEATURE_CENTAUR_MCR
120124
def_bool y
121125
depends on X86_64
122126

127+
config X86_DISABLED_FEATURE_SYSCALL32
128+
def_bool y
129+
depends on !X86_64
130+
123131
config X86_DISABLED_FEATURE_PCID
124132
def_bool y
125133
depends on !X86_64

arch/x86/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ endif
252252

253253

254254
archscripts: scripts_basic
255-
$(Q)$(MAKE) $(build)=arch/x86/tools relocs
255+
$(Q)$(MAKE) $(build)=arch/x86/tools relocs vdso2c
256256

257257
###
258258
# Syscall table generation
@@ -318,9 +318,9 @@ PHONY += install
318318
install:
319319
$(call cmd,install)
320320

321-
vdso-install-$(CONFIG_X86_64) += arch/x86/entry/vdso/vdso64.so.dbg
322-
vdso-install-$(CONFIG_X86_X32_ABI) += arch/x86/entry/vdso/vdsox32.so.dbg
323-
vdso-install-$(CONFIG_COMPAT_32) += arch/x86/entry/vdso/vdso32.so.dbg
321+
vdso-install-$(CONFIG_X86_64) += arch/x86/entry/vdso/vdso64/vdso64.so.dbg
322+
vdso-install-$(CONFIG_X86_X32_ABI) += arch/x86/entry/vdso/vdso64/vdsox32.so.dbg
323+
vdso-install-$(CONFIG_COMPAT_32) += arch/x86/entry/vdso/vdso32/vdso32.so.dbg
324324

325325
archprepare: checkbin
326326
checkbin:

arch/x86/entry/syscall_32.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ __visible noinstr bool do_fast_syscall_32(struct pt_regs *regs)
319319
* convention. Adjust regs so it looks like we entered using int80.
320320
*/
321321
unsigned long landing_pad = (unsigned long)current->mm->context.vdso +
322-
vdso_image_32.sym_int80_landing_pad;
322+
vdso32_image.sym_int80_landing_pad;
323323

324324
/*
325325
* SYSENTER loses EIP, and even SYSCALL32 needs us to skip forward

arch/x86/entry/vdso/.gitignore

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# SPDX-License-Identifier: GPL-2.0-only
2-
vdso.lds
3-
vdsox32.lds
4-
vdso32-syscall-syms.lds
5-
vdso32-sysenter-syms.lds
6-
vdso32-int80-syms.lds
7-
vdso-image-*.c
8-
vdso2c
2+
*.lds
3+
*.so
4+
*.so.dbg
5+
vdso*-image.c

arch/x86/entry/vdso/Makefile

Lines changed: 6 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -3,160 +3,10 @@
33
# Building vDSO images for x86.
44
#
55

6-
# Include the generic Makefile to check the built vDSO:
7-
include $(srctree)/lib/vdso/Makefile.include
6+
# Regular kernel objects
7+
obj-y := vma.o extable.o
8+
obj-$(CONFIG_COMPAT_32) += vdso32-setup.o
89

9-
# Files to link into the vDSO:
10-
vobjs-y := vdso-note.o vclock_gettime.o vgetcpu.o vgetrandom.o vgetrandom-chacha.o
11-
vobjs32-y := vdso32/note.o vdso32/system_call.o vdso32/sigreturn.o
12-
vobjs32-y += vdso32/vclock_gettime.o vdso32/vgetcpu.o
13-
vobjs-$(CONFIG_X86_SGX) += vsgx.o
14-
15-
# Files to link into the kernel:
16-
obj-y += vma.o extable.o
17-
18-
# vDSO images to build:
19-
obj-$(CONFIG_X86_64) += vdso-image-64.o
20-
obj-$(CONFIG_X86_X32_ABI) += vdso-image-x32.o
21-
obj-$(CONFIG_COMPAT_32) += vdso-image-32.o vdso32-setup.o
22-
23-
vobjs := $(addprefix $(obj)/, $(vobjs-y))
24-
vobjs32 := $(addprefix $(obj)/, $(vobjs32-y))
25-
26-
$(obj)/vdso.o: $(obj)/vdso.so
27-
28-
targets += vdso.lds $(vobjs-y)
29-
targets += vdso32/vdso32.lds $(vobjs32-y)
30-
31-
targets += $(foreach x, 64 x32 32, vdso-image-$(x).c vdso$(x).so vdso$(x).so.dbg)
32-
33-
CPPFLAGS_vdso.lds += -P -C
34-
35-
VDSO_LDFLAGS_vdso.lds = -m elf_x86_64 -soname linux-vdso.so.1 \
36-
-z max-page-size=4096
37-
38-
$(obj)/vdso64.so.dbg: $(obj)/vdso.lds $(vobjs) FORCE
39-
$(call if_changed,vdso_and_check)
40-
41-
HOST_EXTRACFLAGS += -I$(srctree)/tools/include -I$(srctree)/include/uapi -I$(srctree)/arch/$(SUBARCH)/include/uapi
42-
hostprogs += vdso2c
43-
44-
quiet_cmd_vdso2c = VDSO2C $@
45-
cmd_vdso2c = $(obj)/vdso2c $< $(<:%.dbg=%) $@
46-
47-
$(obj)/vdso-image-%.c: $(obj)/vdso%.so.dbg $(obj)/vdso%.so $(obj)/vdso2c FORCE
48-
$(call if_changed,vdso2c)
49-
50-
#
51-
# Don't omit frame pointers for ease of userspace debugging, but do
52-
# optimize sibling calls.
53-
#
54-
CFL := $(PROFILING) -mcmodel=small -fPIC -O2 -fasynchronous-unwind-tables -m64 \
55-
$(filter -g%,$(KBUILD_CFLAGS)) -fno-stack-protector \
56-
-fno-omit-frame-pointer -foptimize-sibling-calls \
57-
-DDISABLE_BRANCH_PROFILING -DBUILD_VDSO
58-
59-
ifdef CONFIG_MITIGATION_RETPOLINE
60-
ifneq ($(RETPOLINE_VDSO_CFLAGS),)
61-
CFL += $(RETPOLINE_VDSO_CFLAGS)
62-
endif
63-
endif
64-
65-
$(vobjs): KBUILD_CFLAGS := $(filter-out $(PADDING_CFLAGS) $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) $(RANDSTRUCT_CFLAGS) $(KSTACK_ERASE_CFLAGS) $(GCC_PLUGINS_CFLAGS) $(RETPOLINE_CFLAGS),$(KBUILD_CFLAGS)) $(CFL)
66-
$(vobjs): KBUILD_AFLAGS += -DBUILD_VDSO
67-
68-
#
69-
# vDSO code runs in userspace and -pg doesn't help with profiling anyway.
70-
#
71-
CFLAGS_REMOVE_vclock_gettime.o = -pg
72-
CFLAGS_REMOVE_vdso32/vclock_gettime.o = -pg
73-
CFLAGS_REMOVE_vgetcpu.o = -pg
74-
CFLAGS_REMOVE_vdso32/vgetcpu.o = -pg
75-
CFLAGS_REMOVE_vsgx.o = -pg
76-
CFLAGS_REMOVE_vgetrandom.o = -pg
77-
78-
#
79-
# X32 processes use x32 vDSO to access 64bit kernel data.
80-
#
81-
# Build x32 vDSO image:
82-
# 1. Compile x32 vDSO as 64bit.
83-
# 2. Convert object files to x32.
84-
# 3. Build x32 VDSO image with x32 objects, which contains 64bit codes
85-
# so that it can reach 64bit address space with 64bit pointers.
86-
#
87-
88-
CPPFLAGS_vdsox32.lds = $(CPPFLAGS_vdso.lds)
89-
VDSO_LDFLAGS_vdsox32.lds = -m elf32_x86_64 -soname linux-vdso.so.1 \
90-
-z max-page-size=4096
91-
92-
# x32-rebranded versions
93-
vobjx32s-y := $(vobjs-y:.o=-x32.o)
94-
95-
# same thing, but in the output directory
96-
vobjx32s := $(addprefix $(obj)/, $(vobjx32s-y))
97-
98-
# Convert 64bit object file to x32 for x32 vDSO.
99-
quiet_cmd_x32 = X32 $@
100-
cmd_x32 = $(OBJCOPY) -O elf32-x86-64 $< $@
101-
102-
$(obj)/%-x32.o: $(obj)/%.o FORCE
103-
$(call if_changed,x32)
104-
105-
targets += vdsox32.lds $(vobjx32s-y)
106-
107-
$(obj)/%.so: OBJCOPYFLAGS := -S --remove-section __ex_table
108-
$(obj)/%.so: $(obj)/%.so.dbg FORCE
109-
$(call if_changed,objcopy)
110-
111-
$(obj)/vdsox32.so.dbg: $(obj)/vdsox32.lds $(vobjx32s) FORCE
112-
$(call if_changed,vdso_and_check)
113-
114-
CPPFLAGS_vdso32/vdso32.lds = $(CPPFLAGS_vdso.lds)
115-
VDSO_LDFLAGS_vdso32.lds = -m elf_i386 -soname linux-gate.so.1
116-
117-
KBUILD_AFLAGS_32 := $(filter-out -m64,$(KBUILD_AFLAGS)) -DBUILD_VDSO
118-
$(obj)/vdso32.so.dbg: KBUILD_AFLAGS = $(KBUILD_AFLAGS_32)
119-
$(obj)/vdso32.so.dbg: asflags-$(CONFIG_X86_64) += -m32
120-
121-
KBUILD_CFLAGS_32 := $(filter-out -m64,$(KBUILD_CFLAGS))
122-
KBUILD_CFLAGS_32 := $(filter-out -mcmodel=kernel,$(KBUILD_CFLAGS_32))
123-
KBUILD_CFLAGS_32 := $(filter-out -fno-pic,$(KBUILD_CFLAGS_32))
124-
KBUILD_CFLAGS_32 := $(filter-out -mfentry,$(KBUILD_CFLAGS_32))
125-
KBUILD_CFLAGS_32 := $(filter-out $(RANDSTRUCT_CFLAGS),$(KBUILD_CFLAGS_32))
126-
KBUILD_CFLAGS_32 := $(filter-out $(KSTACK_ERASE_CFLAGS),$(KBUILD_CFLAGS_32))
127-
KBUILD_CFLAGS_32 := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS_32))
128-
KBUILD_CFLAGS_32 := $(filter-out $(RETPOLINE_CFLAGS),$(KBUILD_CFLAGS_32))
129-
KBUILD_CFLAGS_32 := $(filter-out $(CC_FLAGS_LTO),$(KBUILD_CFLAGS_32))
130-
KBUILD_CFLAGS_32 := $(filter-out $(CC_FLAGS_CFI),$(KBUILD_CFLAGS_32))
131-
KBUILD_CFLAGS_32 := $(filter-out $(PADDING_CFLAGS),$(KBUILD_CFLAGS_32))
132-
KBUILD_CFLAGS_32 += -m32 -msoft-float -mregparm=0 -fpic
133-
KBUILD_CFLAGS_32 += -fno-stack-protector
134-
KBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls)
135-
KBUILD_CFLAGS_32 += -fno-omit-frame-pointer
136-
KBUILD_CFLAGS_32 += -DDISABLE_BRANCH_PROFILING
137-
KBUILD_CFLAGS_32 += -DBUILD_VDSO
138-
139-
ifdef CONFIG_MITIGATION_RETPOLINE
140-
ifneq ($(RETPOLINE_VDSO_CFLAGS),)
141-
KBUILD_CFLAGS_32 += $(RETPOLINE_VDSO_CFLAGS)
142-
endif
143-
endif
144-
145-
$(obj)/vdso32.so.dbg: KBUILD_CFLAGS = $(KBUILD_CFLAGS_32)
146-
147-
$(obj)/vdso32.so.dbg: $(obj)/vdso32/vdso32.lds $(vobjs32) FORCE
148-
$(call if_changed,vdso_and_check)
149-
150-
#
151-
# The DSO images are built using a special linker script.
152-
#
153-
quiet_cmd_vdso = VDSO $@
154-
cmd_vdso = $(LD) -o $@ \
155-
$(VDSO_LDFLAGS) $(VDSO_LDFLAGS_$(filter %.lds,$(^F))) \
156-
-T $(filter %.lds,$^) $(filter %.o,$^)
157-
158-
VDSO_LDFLAGS = -shared --hash-style=both --build-id=sha1 --no-undefined \
159-
$(call ld-option, --eh-frame-hdr) -Bsymbolic -z noexecstack
160-
161-
quiet_cmd_vdso_and_check = VDSO $@
162-
cmd_vdso_and_check = $(cmd_vdso); $(cmd_vdso_check)
10+
# vDSO directories
11+
obj-$(CONFIG_X86_64) += vdso64/
12+
obj-$(CONFIG_COMPAT_32) += vdso32/
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
#
3+
# Building vDSO images for x86.
4+
#
5+
6+
# Include the generic Makefile to check the built vDSO:
7+
include $(srctree)/lib/vdso/Makefile.include
8+
9+
obj-y += $(foreach x,$(vdsos-y),vdso$(x)-image.o)
10+
11+
targets += $(foreach x,$(vdsos-y),vdso$(x)-image.c vdso$(x).so vdso$(x).so.dbg vdso$(x).lds)
12+
targets += $(vobjs-y)
13+
14+
# vobjs-y with $(obj)/ prepended
15+
vobjs := $(addprefix $(obj)/,$(vobjs-y))
16+
17+
# Options for vdso*.lds
18+
CPPFLAGS_VDSO_LDS := -P -C -I$(src)/..
19+
$(obj)/%.lds : KBUILD_CPPFLAGS += $(CPPFLAGS_VDSO_LDS)
20+
21+
#
22+
# Options from KBUILD_[AC]FLAGS that should *NOT* be kept
23+
#
24+
flags-remove-y += \
25+
-D__KERNEL__ -mcmodel=kernel -mregparm=3 \
26+
-fno-pic -fno-PIC -fno-pie -fno-PIE \
27+
-mfentry -pg \
28+
$(RANDSTRUCT_CFLAGS) $(GCC_PLUGINS_CFLAGS) $(KSTACK_ERASE_CFLAGS) \
29+
$(RETPOLINE_CFLAGS) $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) \
30+
$(PADDING_CFLAGS)
31+
32+
#
33+
# Don't omit frame pointers for ease of userspace debugging, but do
34+
# optimize sibling calls.
35+
#
36+
flags-y += -D__DISABLE_EXPORTS
37+
flags-y += -DDISABLE_BRANCH_PROFILING
38+
flags-y += -DBUILD_VDSO
39+
flags-y += -I$(src)/.. -I$(srctree)
40+
flags-y += -O2 -fpic
41+
flags-y += -fno-stack-protector
42+
flags-y += -fno-omit-frame-pointer
43+
flags-y += -foptimize-sibling-calls
44+
flags-y += -fasynchronous-unwind-tables
45+
46+
# Reset cf protections enabled by compiler default
47+
flags-y += $(call cc-option, -fcf-protection=none)
48+
flags-$(X86_USER_SHADOW_STACK) += $(call cc-option, -fcf-protection=return)
49+
# When user space IBT is supported, enable this.
50+
# flags-$(CONFIG_USER_IBT) += $(call cc-option, -fcf-protection=branch)
51+
52+
flags-$(CONFIG_MITIGATION_RETPOLINE) += $(RETPOLINE_VDSO_CFLAGS)
53+
54+
# These need to be conditional on $(vobjs) as they do not apply to
55+
# the output vdso*-image.o files which are standard kernel objects.
56+
$(vobjs) : KBUILD_AFLAGS := \
57+
$(filter-out $(flags-remove-y),$(KBUILD_AFLAGS)) $(flags-y)
58+
$(vobjs) : KBUILD_CFLAGS := \
59+
$(filter-out $(flags-remove-y),$(KBUILD_CFLAGS)) $(flags-y)
60+
61+
#
62+
# The VDSO images are built using a special linker script.
63+
#
64+
VDSO_LDFLAGS := -shared --hash-style=both --build-id=sha1 --no-undefined \
65+
$(call ld-option, --eh-frame-hdr) -Bsymbolic -z noexecstack
66+
67+
quiet_cmd_vdso = VDSO $@
68+
cmd_vdso = $(LD) -o $@ \
69+
$(VDSO_LDFLAGS) $(VDSO_LDFLAGS_$*) \
70+
-T $(filter %.lds,$^) $(filter %.o,$^)
71+
quiet_cmd_vdso_and_check = VDSO $@
72+
cmd_vdso_and_check = $(cmd_vdso); $(cmd_vdso_check)
73+
74+
$(obj)/vdso%.so.dbg: $(obj)/vdso%.lds FORCE
75+
$(call if_changed,vdso_and_check)
76+
77+
$(obj)/%.so: OBJCOPYFLAGS := -S --remove-section __ex_table
78+
$(obj)/%.so: $(obj)/%.so.dbg FORCE
79+
$(call if_changed,objcopy)
80+
81+
VDSO2C = $(objtree)/arch/x86/tools/vdso2c
82+
83+
quiet_cmd_vdso2c = VDSO2C $@
84+
cmd_vdso2c = $(VDSO2C) $< $(<:%.dbg=%) $@
85+
86+
$(obj)/%-image.c: $(obj)/%.so.dbg $(obj)/%.so $(VDSO2C) FORCE
87+
$(call if_changed,vdso2c)
88+
89+
$(obj)/%-image.o: $(obj)/%-image.c
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
12
/*
23
* This supplies .note.* sections to go into the PT_NOTE inside the vDSO text.
34
* Here we can supply some information useful to userland.
45
*/
56

67
#include <linux/build-salt.h>
7-
#include <linux/uts.h>
88
#include <linux/version.h>
99
#include <linux/elfnote.h>
1010

11+
/* Ideally this would use UTS_NAME, but using a quoted string here
12+
doesn't work. Remember to change this when changing the
13+
kernel's name. */
1114
ELFNOTE_START(Linux, 0, "a")
1215
.long LINUX_VERSION_CODE
1316
ELFNOTE_END
File renamed without changes.

0 commit comments

Comments
 (0)