Skip to content

Commit

Permalink
Merge tag 'x86_vdso_for_v6.3_rc1' of git://git.kernel.org/pub/scm/lin…
Browse files Browse the repository at this point in the history
…ux/kernel/git/tip/tip

Pull x86 vdso updates from Borislav Petkov:

 - Add getcpu support for the 32-bit version of the vDSO

 - Some smaller fixes

* tag 'x86_vdso_for_v6.3_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  x86/vdso: Fix -Wmissing-prototypes warnings
  x86/vdso: Fake 32bit VDSO build on 64bit compile for vgetcpu
  selftests: Emit a warning if getcpu() is missing on 32bit
  x86/vdso: Provide getcpu for x86-32.
  x86/cpu: Provide the full setup for getcpu() on x86-32
  x86/vdso: Move VDSO image init to vdso2c generated code
  • Loading branch information
Linus Torvalds committed Feb 21, 2023
2 parents efebca0 + dac0da4 commit 3f0b090
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 68 deletions.
3 changes: 2 additions & 1 deletion arch/x86/entry/vdso/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ VDSO32-$(CONFIG_IA32_EMULATION) := y
# files to link into the vdso
vobjs-y := vdso-note.o vclock_gettime.o vgetcpu.o
vobjs32-y := vdso32/note.o vdso32/system_call.o vdso32/sigreturn.o
vobjs32-y += vdso32/vclock_gettime.o
vobjs32-y += vdso32/vclock_gettime.o vdso32/vgetcpu.o
vobjs-$(CONFIG_X86_SGX) += vsgx.o

# files to link into kernel
Expand Down Expand Up @@ -104,6 +104,7 @@ $(vobjs): KBUILD_AFLAGS += -DBUILD_VDSO
CFLAGS_REMOVE_vclock_gettime.o = -pg
CFLAGS_REMOVE_vdso32/vclock_gettime.o = -pg
CFLAGS_REMOVE_vgetcpu.o = -pg
CFLAGS_REMOVE_vdso32/vgetcpu.o = -pg
CFLAGS_REMOVE_vsgx.o = -pg

#
Expand Down
6 changes: 6 additions & 0 deletions arch/x86/entry/vdso/vdso2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ static void BITSFUNC(go)(void *raw_addr, size_t raw_len,

fprintf(outfile, "/* AUTOMATICALLY GENERATED -- DO NOT EDIT */\n\n");
fprintf(outfile, "#include <linux/linkage.h>\n");
fprintf(outfile, "#include <linux/init.h>\n");
fprintf(outfile, "#include <asm/page_types.h>\n");
fprintf(outfile, "#include <asm/vdso.h>\n");
fprintf(outfile, "\n");
Expand Down Expand Up @@ -218,5 +219,10 @@ static void BITSFUNC(go)(void *raw_addr, size_t raw_len,
fprintf(outfile, "\t.sym_%s = %" PRIi64 ",\n",
required_syms[i].name, (int64_t)syms[i]);
}
fprintf(outfile, "};\n\n");
fprintf(outfile, "static __init int init_%s(void) {\n", image_name);
fprintf(outfile, "\treturn init_vdso_image(&%s);\n", image_name);
fprintf(outfile, "};\n");
fprintf(outfile, "subsys_initcall(init_%s);\n", image_name);

}
9 changes: 0 additions & 9 deletions arch/x86/entry/vdso/vdso32-setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,8 @@ __setup("vdso32=", vdso32_setup);
__setup_param("vdso=", vdso_setup, vdso32_setup, 0);
#endif

int __init sysenter_setup(void)
{
init_vdso_image(&vdso_image_32);

return 0;
}

#ifdef CONFIG_X86_64

subsys_initcall(sysenter_setup);

#ifdef CONFIG_SYSCTL
/* Register vsyscall32 into the ABI table */
#include <linux/sysctl.h>
Expand Down
25 changes: 25 additions & 0 deletions arch/x86/entry/vdso/vdso32/fake_32bit_build.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* SPDX-License-Identifier: GPL-2.0 */
#ifdef CONFIG_X86_64

/*
* in case of a 32 bit VDSO for a 64 bit kernel fake a 32 bit kernel
* configuration
*/
#undef CONFIG_64BIT
#undef CONFIG_X86_64
#undef CONFIG_COMPAT
#undef CONFIG_PGTABLE_LEVELS
#undef CONFIG_ILLEGAL_POINTER_VALUE
#undef CONFIG_SPARSEMEM_VMEMMAP
#undef CONFIG_NR_CPUS
#undef CONFIG_PARAVIRT_XXL

#define CONFIG_X86_32 1
#define CONFIG_PGTABLE_LEVELS 2
#define CONFIG_PAGE_OFFSET 0
#define CONFIG_ILLEGAL_POINTER_VALUE 0
#define CONFIG_NR_CPUS 1

#define BUILD_VDSO32_64

#endif
27 changes: 1 addition & 26 deletions arch/x86/entry/vdso/vdso32/vclock_gettime.c
Original file line number Diff line number Diff line change
@@ -1,29 +1,4 @@
// SPDX-License-Identifier: GPL-2.0
#define BUILD_VDSO32

#ifdef CONFIG_X86_64

/*
* in case of a 32 bit VDSO for a 64 bit kernel fake a 32 bit kernel
* configuration
*/
#undef CONFIG_64BIT
#undef CONFIG_X86_64
#undef CONFIG_COMPAT
#undef CONFIG_PGTABLE_LEVELS
#undef CONFIG_ILLEGAL_POINTER_VALUE
#undef CONFIG_SPARSEMEM_VMEMMAP
#undef CONFIG_NR_CPUS
#undef CONFIG_PARAVIRT_XXL

#define CONFIG_X86_32 1
#define CONFIG_PGTABLE_LEVELS 2
#define CONFIG_PAGE_OFFSET 0
#define CONFIG_ILLEGAL_POINTER_VALUE 0
#define CONFIG_NR_CPUS 1

#define BUILD_VDSO32_64

#endif

#include "fake_32bit_build.h"
#include "../vclock_gettime.c"
1 change: 1 addition & 0 deletions arch/x86/entry/vdso/vdso32/vdso32.lds.S
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ VERSION
__vdso_time;
__vdso_clock_getres;
__vdso_clock_gettime64;
__vdso_getcpu;
};

LINUX_2.5 {
Expand Down
3 changes: 3 additions & 0 deletions arch/x86/entry/vdso/vdso32/vgetcpu.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// SPDX-License-Identifier: GPL-2.0
#include "fake_32bit_build.h"
#include "../vgetcpu.c"
3 changes: 1 addition & 2 deletions arch/x86/entry/vdso/vgetcpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

#include <linux/kernel.h>
#include <linux/getcpu.h>
#include <linux/time.h>
#include <asm/vgtod.h>
#include <asm/segment.h>

notrace long
__vdso_getcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *unused)
Expand Down
19 changes: 4 additions & 15 deletions arch/x86/entry/vdso/vma.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,16 @@ unsigned int vclocks_used __read_mostly;
unsigned int __read_mostly vdso64_enabled = 1;
#endif

void __init init_vdso_image(const struct vdso_image *image)
int __init init_vdso_image(const struct vdso_image *image)
{
BUILD_BUG_ON(VDSO_CLOCKMODE_MAX >= 32);
BUG_ON(image->size % PAGE_SIZE != 0);

apply_alternatives((struct alt_instr *)(image->data + image->alt),
(struct alt_instr *)(image->data + image->alt +
image->alt_len));

return 0;
}

static const struct vm_special_mapping vvar_mapping;
Expand Down Expand Up @@ -418,18 +421,4 @@ static __init int vdso_setup(char *s)
return 1;
}
__setup("vdso=", vdso_setup);

static int __init init_vdso(void)
{
BUILD_BUG_ON(VDSO_CLOCKMODE_MAX >= 32);

init_vdso_image(&vdso_image_64);

#ifdef CONFIG_X86_X32_ABI
init_vdso_image(&vdso_image_x32);
#endif

return 0;
}
subsys_initcall(init_vdso);
#endif /* CONFIG_X86_64 */
1 change: 0 additions & 1 deletion arch/x86/include/asm/processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,6 @@ enum idle_boot_override {IDLE_NO_OVERRIDE=0, IDLE_HALT, IDLE_NOMWAIT,
IDLE_POLL};

extern void enable_sep_cpu(void);
extern int sysenter_setup(void);


/* Defined in head.S */
Expand Down
8 changes: 4 additions & 4 deletions arch/x86/include/asm/segment.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
*
* 26 - ESPFIX small SS
* 27 - per-cpu [ offset to per-cpu data area ]
* 28 - unused
* 28 - VDSO getcpu
* 29 - unused
* 30 - unused
* 31 - TSS for double fault handler
Expand All @@ -119,6 +119,7 @@

#define GDT_ENTRY_ESPFIX_SS 26
#define GDT_ENTRY_PERCPU 27
#define GDT_ENTRY_CPUNODE 28

#define GDT_ENTRY_DOUBLEFAULT_TSS 31

Expand Down Expand Up @@ -159,6 +160,8 @@
# define __KERNEL_PERCPU 0
#endif

#define __CPUNODE_SEG (GDT_ENTRY_CPUNODE*8 + 3)

#else /* 64-bit: */

#include <asm/cache.h>
Expand Down Expand Up @@ -226,8 +229,6 @@
#define GDT_ENTRY_TLS_ENTRIES 3
#define TLS_SIZE (GDT_ENTRY_TLS_ENTRIES* 8)

#ifdef CONFIG_X86_64

/* Bit size and mask of CPU number stored in the per CPU data (and TSC_AUX) */
#define VDSO_CPUNODE_BITS 12
#define VDSO_CPUNODE_MASK 0xfff
Expand Down Expand Up @@ -265,7 +266,6 @@ static inline void vdso_read_cpunode(unsigned *cpu, unsigned *node)
}

#endif /* !__ASSEMBLY__ */
#endif /* CONFIG_X86_64 */

#ifdef __KERNEL__

Expand Down
2 changes: 1 addition & 1 deletion arch/x86/include/asm/vdso.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ extern const struct vdso_image vdso_image_x32;
extern const struct vdso_image vdso_image_32;
#endif

extern void __init init_vdso_image(const struct vdso_image *image);
extern int __init init_vdso_image(const struct vdso_image *image);

extern int map_vdso_once(const struct vdso_image *image, unsigned long addr);

Expand Down
2 changes: 2 additions & 0 deletions arch/x86/include/asm/vdso/gettimeofday.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ u64 vdso_calc_delta(u64 cycles, u64 last, u64 mask, u32 mult)
}
#define vdso_calc_delta vdso_calc_delta

int __vdso_clock_gettime64(clockid_t clock, struct __kernel_timespec *ts);

#endif /* !__ASSEMBLY__ */

#endif /* __ASM_VDSO_GETTIMEOFDAY_H */
4 changes: 4 additions & 0 deletions arch/x86/include/asm/vdso/processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ static __always_inline void cpu_relax(void)
rep_nop();
}

struct getcpu_cache;

notrace long __vdso_getcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *unused);

#endif /* __ASSEMBLY__ */

#endif /* __ASM_VDSO_PROCESSOR_H */
5 changes: 1 addition & 4 deletions arch/x86/kernel/cpu/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1958,7 +1958,6 @@ void __init identify_boot_cpu(void)
if (HAS_KERNEL_IBT && cpu_feature_enabled(X86_FEATURE_IBT))
pr_info("CET detected: Indirect Branch Tracking enabled\n");
#ifdef CONFIG_X86_32
sysenter_setup();
enable_sep_cpu();
#endif
cpu_detect_tlb(&boot_cpu_data);
Expand Down Expand Up @@ -2130,7 +2129,6 @@ static void wait_for_master_cpu(int cpu)
#endif
}

#ifdef CONFIG_X86_64
static inline void setup_getcpu(int cpu)
{
unsigned long cpudata = vdso_encode_cpunode(cpu, early_cpu_to_node(cpu));
Expand All @@ -2152,6 +2150,7 @@ static inline void setup_getcpu(int cpu)
write_gdt_entry(get_cpu_gdt_rw(cpu), GDT_ENTRY_CPUNODE, &d, DESCTYPE_S);
}

#ifdef CONFIG_X86_64
static inline void ucode_cpu_init(int cpu)
{
if (cpu)
Expand All @@ -2171,8 +2170,6 @@ static inline void tss_setup_ist(struct tss_struct *tss)

#else /* CONFIG_X86_64 */

static inline void setup_getcpu(int cpu) { }

static inline void ucode_cpu_init(int cpu)
{
show_ucode_info_early();
Expand Down
7 changes: 2 additions & 5 deletions tools/testing/selftests/x86/test_vsyscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,8 @@ static void init_vdso(void)
printf("[WARN]\tfailed to find time in vDSO\n");

vdso_getcpu = (getcpu_t)dlsym(vdso, "__vdso_getcpu");
if (!vdso_getcpu) {
/* getcpu() was never wired up in the 32-bit vDSO. */
printf("[%s]\tfailed to find getcpu in vDSO\n",
sizeof(long) == 8 ? "WARN" : "NOTE");
}
if (!vdso_getcpu)
printf("[WARN]\tfailed to find getcpu in vDSO\n");
}

static int init_vsys(void)
Expand Down

0 comments on commit 3f0b090

Please sign in to comment.