Skip to contentSkip to conversation

x86/vdso changes for v3.16

GIT PULL H. Peter Anvin 7 participants 25 messages Jun 4, 2014 – Jun 10, 2014

Subsystems (12)
Memory management x86 VFS MM core +8 more subsystems
lore
Share & tools
lore
#0 lore raw

Hi Linus,

Vdso cleanups and improvements largely from Andy Lutomirski. This makes the vdso a lot less "special".

This patchset depends on the x86/espfix changes and should be applied *after* that patchset.

The following changes since commit 368b69a5b010cb00fc9ea04d588cff69af1a1359:

x86, vdso: Fix an OOPS accessing the HPET mapping w/o an HPET (2014-05-21 16:14:04 -0700)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86/vdso

for you to fetch changes up to c191920f737a09a7252088f018f6747f0d2f484d:

x86/vdso, build: Make LE access macros clearer, host-safe (2014-05-31 03:35:27 -0700)

----------------------------------------------------------------
Andy Lutomirski (13):
x86, mm: Ensure correct alignment of the fixmap
x86, vdso: Clean up 32-bit vs 64-bit vdso params
x86, vdso: Move syscall and sysenter setup into kernel/cpu/common.c x86, vdso: Reimplement vdso.so preparation in build-time C x86, vdso: Move the 32-bit vdso special pages after the text x86, vdso: Move the vvar and hpet mappings next to the 64-bit vDSO x86, vdso: Remove vestiges of VDSO_PRELINK and some outdated comments x86, vdso: Fix an OOPS accessing the HPET mapping w/o an HPET mm, fs: Add vm_ops->name as an alternative to arch_vma_name x86, mm: Improve _install_special_mapping and fix x86 vdso naming x86, mm: Replace arch_vma_name with vm_ops->name for vsyscalls x86/vdso, build: When vdso2c fails, unlink the output x86/vdso, build: Fix cross-compilation from big-endian architectures

H. Peter Anvin (3):
Merge remote-tracking branch 'origin/x86/espfix' into x86/vdso Merge remote-tracking branch 'origin/x86/urgent' into x86/vdso x86/vdso, build: Make LE access macros clearer, host-safe

 arch/x86/ia32/ia32_signal.c          |   8 +-
 arch/x86/include/asm/elf.h           |  35 +++---
 arch/x86/include/asm/fixmap.h        |  11 +-
 arch/x86/include/asm/mmu.h           |   2 +-
 arch/x86/include/asm/proto.h         |   2 -
 arch/x86/include/asm/vdso.h          |  78 +++++-------
 arch/x86/include/asm/vdso32.h        |  11 --
 arch/x86/include/asm/vvar.h          |  20 +--
 arch/x86/include/uapi/asm/vsyscall.h |   7 +-
 arch/x86/kernel/cpu/common.c         |  33 +++++
 arch/x86/kernel/hpet.c               |   3 -
 arch/x86/kernel/signal.c             |   6 +-
 arch/x86/kernel/vsyscall_64.c        |  15 +--
 arch/x86/mm/fault.c                  |   5 +-
 arch/x86/mm/init_64.c                |  29 +++--
 arch/x86/mm/ioremap.c                |   6 +
 arch/x86/mm/pgtable.c                |   6 +-
 arch/x86/um/vdso/vma.c               |   2 +-
 arch/x86/vdso/.gitignore             |   5 +-
 arch/x86/vdso/Makefile               |  90 +++++--------
 arch/x86/vdso/vclock_gettime.c       |  26 ++--
 arch/x86/vdso/vdso-layout.lds.S      |  40 +++---
 arch/x86/vdso/vdso.S                 |   3 -
 arch/x86/vdso/vdso.lds.S             |   7 +-
 arch/x86/vdso/vdso2c.c               | 173 +++++++++++++++++++++++++
 arch/x86/vdso/vdso2c.h               | 163 ++++++++++++++++++++++++
 arch/x86/vdso/vdso32-setup.c         | 204 ++++--------------------------
 arch/x86/vdso/vdso32.S               |   9 --
 arch/x86/vdso/vdso32/vdso32.lds.S    |  15 +--
 arch/x86/vdso/vdsox32.S              |   3 -
 arch/x86/vdso/vdsox32.lds.S          |   7 +-
 arch/x86/vdso/vma.c                  | 236 +++++++++++++++++++----------------
 arch/x86/xen/mmu.c                   |   8 +-
 arch/x86/xen/setup.c                 |  11 +-
 fs/binfmt_elf.c                      |   8 ++
 fs/proc/task_mmu.c                   |   6 +
 include/linux/mm.h                   |  10 +-
 include/linux/mm_types.h             |   6 +
 kernel/sysctl.c                      |   5 +
 mm/mmap.c                            |  89 ++++++++-----
 40 files changed, 794 insertions(+), 609 deletions(-)
arch/x86/ia32/ia32_signal.c +4 -4
index 2206757..f9e181a 100644
@@ -383,8 +383,8 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
 	} else {
 		/* Return stub is in 32bit vsyscall page */
 		if (current->mm->context.vdso)
-			restorer = VDSO32_SYMBOL(current->mm->context.vdso,
-						 sigreturn);
+			restorer = current->mm->context.vdso +
+				selected_vdso32->sym___kernel_sigreturn;
 		else
 			restorer = &frame->retcode;
 	}
@@ -462,8 +462,8 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
 		if (ksig->ka.sa.sa_flags & SA_RESTORER)
 			restorer = ksig->ka.sa.sa_restorer;
 		else
-			restorer = VDSO32_SYMBOL(current->mm->context.vdso,
-						 rt_sigreturn);
+			restorer = current->mm->context.vdso +
+				selected_vdso32->sym___kernel_rt_sigreturn;
 		put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
 
 		/*
arch/x86/include/asm/elf.h +20 -15
index 2c71182..1a055c8 100644
@@ -75,7 +75,12 @@ typedef struct user_fxsr_struct elf_fpxregset_t;
 
 #include <asm/vdso.h>
 
-extern unsigned int vdso_enabled;
+#ifdef CONFIG_X86_64
+extern unsigned int vdso64_enabled;
+#endif
+#if defined(CONFIG_X86_32) || defined(CONFIG_COMPAT)
+extern unsigned int vdso32_enabled;
+#endif
 
 /*
  * This is used to ensure we don't load something for the wrong architecture.
@@ -269,9 +274,9 @@ extern int force_personality32;
 
 struct task_struct;
 
-#define	ARCH_DLINFO_IA32(vdso_enabled)					\
+#define	ARCH_DLINFO_IA32						\
 do {									\
-	if (vdso_enabled) {						\
+	if (vdso32_enabled) {						\
 		NEW_AUX_ENT(AT_SYSINFO,	VDSO_ENTRY);			\
 		NEW_AUX_ENT(AT_SYSINFO_EHDR, VDSO_CURRENT_BASE);	\
 	}								\
@@ -281,7 +286,7 @@ do {									\
 
 #define STACK_RND_MASK (0x7ff)
 
-#define ARCH_DLINFO		ARCH_DLINFO_IA32(vdso_enabled)
+#define ARCH_DLINFO		ARCH_DLINFO_IA32
 
 /* update AT_VECTOR_SIZE_ARCH if the number of NEW_AUX_ENT entries changes */
 
@@ -292,16 +297,17 @@ do {									\
 
 #define ARCH_DLINFO							\
 do {									\
-	if (vdso_enabled)						\
+	if (vdso64_enabled)						\
 		NEW_AUX_ENT(AT_SYSINFO_EHDR,				\
-			    (unsigned long)current->mm->context.vdso);	\
+			    (unsigned long __force)current->mm->context.vdso); \
 } while (0)
 
+/* As a historical oddity, the x32 and x86_64 vDSOs are controlled together. */
 #define ARCH_DLINFO_X32							\
 do {									\
-	if (vdso_enabled)						\
+	if (vdso64_enabled)						\
 		NEW_AUX_ENT(AT_SYSINFO_EHDR,				\
-			    (unsigned long)current->mm->context.vdso);	\
+			    (unsigned long __force)current->mm->context.vdso); \
 } while (0)
 
 #define AT_SYSINFO		32
@@ -310,7 +316,7 @@ do {									\
 if (test_thread_flag(TIF_X32))						\
 	ARCH_DLINFO_X32;						\
 else									\
-	ARCH_DLINFO_IA32(sysctl_vsyscall32)
+	ARCH_DLINFO_IA32
 
 #define COMPAT_ELF_ET_DYN_BASE	(TASK_UNMAPPED_BASE + 0x1000000)
 
@@ -319,18 +325,17 @@ else									\
 #define VDSO_CURRENT_BASE	((unsigned long)current->mm->context.vdso)
 
 #define VDSO_ENTRY							\
-	((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
+	((unsigned long)current->mm->context.vdso +			\
+	 selected_vdso32->sym___kernel_vsyscall)
 
 struct linux_binprm;
 
 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
 				       int uses_interp);
-extern int x32_setup_additional_pages(struct linux_binprm *bprm,
-				      int uses_interp);
-
-extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
-#define compat_arch_setup_additional_pages	syscall32_setup_pages
+extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
+					      int uses_interp);
+#define compat_arch_setup_additional_pages compat_arch_setup_additional_pages
 
 extern unsigned long arch_randomize_brk(struct mm_struct *mm);
 #define arch_randomize_brk arch_randomize_brk
arch/x86/include/asm/fixmap.h +4 -7
index 43f482a..b0910f9 100644
@@ -24,7 +24,7 @@
 #include <linux/threads.h>
 #include <asm/kmap_types.h>
 #else
-#include <asm/vsyscall.h>
+#include <uapi/asm/vsyscall.h>
 #endif
 
 /*
@@ -41,7 +41,8 @@
 extern unsigned long __FIXADDR_TOP;
 #define FIXADDR_TOP	((unsigned long)__FIXADDR_TOP)
 #else
-#define FIXADDR_TOP	(VSYSCALL_END-PAGE_SIZE)
+#define FIXADDR_TOP	(round_up(VSYSCALL_ADDR + PAGE_SIZE, 1<<PMD_SHIFT) - \
+			 PAGE_SIZE)
 #endif
 
 
@@ -68,11 +69,7 @@ enum fixed_addresses {
 #ifdef CONFIG_X86_32
 	FIX_HOLE,
 #else
-	VSYSCALL_LAST_PAGE,
-	VSYSCALL_FIRST_PAGE = VSYSCALL_LAST_PAGE
-			    + ((VSYSCALL_END-VSYSCALL_START) >> PAGE_SHIFT) - 1,
-	VVAR_PAGE,
-	VSYSCALL_HPET,
+	VSYSCALL_PAGE = (FIXADDR_TOP - VSYSCALL_ADDR) >> PAGE_SHIFT,
 #ifdef CONFIG_PARAVIRT_CLOCK
 	PVCLOCK_FIXMAP_BEGIN,
 	PVCLOCK_FIXMAP_END = PVCLOCK_FIXMAP_BEGIN+PVCLOCK_VSYSCALL_NR_PAGES-1,
arch/x86/include/asm/mmu.h +1 -1
index 5f55e69..876e74e 100644
@@ -18,7 +18,7 @@ typedef struct {
 #endif
 
 	struct mutex lock;
-	void *vdso;
+	void __user *vdso;
 } mm_context_t;
 
 #ifdef CONFIG_SMP
arch/x86/include/asm/proto.h +0 -2
index 6fd3fd7..a90f897 100644
@@ -12,8 +12,6 @@ void ia32_syscall(void);
 void ia32_cstar_target(void);
 void ia32_sysenter_target(void);
 
-void syscall32_cpu_init(void);
-
 void x86_configure_nx(void);
 void x86_report_nx(void);
 
arch/x86/include/asm/vdso.h +33 -45

96 lines not on this page · raw message

arch/x86/include/asm/vdso32.h deleted +0 -11
deleted file mode 100644
index 7efb701..0000000
@@ -1,11 +0,0 @@
-#ifndef _ASM_X86_VDSO32_H
-#define _ASM_X86_VDSO32_H
-
-#define VDSO_BASE_PAGE	0
-#define VDSO_VVAR_PAGE	1
-#define VDSO_HPET_PAGE	2
-#define VDSO_PAGES	3
-#define VDSO_PREV_PAGES	2
-#define VDSO_OFFSET(x)	((x) * PAGE_SIZE)
-
-#endif
arch/x86/include/asm/vvar.h +1 -19
index 081d909..5d2b9ad 100644
@@ -29,31 +29,13 @@
 
 #else
 
-#ifdef BUILD_VDSO32
+extern char __vvar_page;
 
 #define DECLARE_VVAR(offset, type, name)				\
 	extern type vvar_ ## name __attribute__((visibility("hidden")));
 
 #define VVAR(name) (vvar_ ## name)
 
-#else
-
-extern char __vvar_page;
-
-/* Base address of vvars.  This is not ABI. */
-#ifdef CONFIG_X86_64
-#define VVAR_ADDRESS (-10*1024*1024 - 4096)
-#else
-#define VVAR_ADDRESS (&__vvar_page)
-#endif
-
-#define DECLARE_VVAR(offset, type, name)				\
-	static type const * const vvaraddr_ ## name =			\
-		(void *)(VVAR_ADDRESS + (offset));
-
-#define VVAR(name) (*vvaraddr_ ## name)
-#endif
-
 #define DEFINE_VVAR(type, name)						\
 	type name							\
 	__attribute__((section(".vvar_" #name), aligned(16))) __visible
arch/x86/include/uapi/asm/vsyscall.h +1 -6
index 85dc1b3..b97dd6e 100644
@@ -7,11 +7,6 @@ enum vsyscall_num {
 	__NR_vgetcpu,
 };
 
-#define VSYSCALL_START (-10UL << 20)
-#define VSYSCALL_SIZE 1024
-#define VSYSCALL_END (-2UL << 20)
-#define VSYSCALL_MAPPED_PAGES 1
-#define VSYSCALL_ADDR(vsyscall_nr) (VSYSCALL_START+VSYSCALL_SIZE*(vsyscall_nr))
-
+#define VSYSCALL_ADDR (-10UL << 20)
 
 #endif /* _UAPI_ASM_X86_VSYSCALL_H */
arch/x86/kernel/cpu/common.c +33 -0
index a135239..2cbbf88 100644
@@ -20,6 +20,7 @@
 #include <asm/processor.h>
 #include <asm/debugreg.h>
 #include <asm/sections.h>
+#include <asm/vsyscall.h>
 #include <linux/topology.h>
 #include <linux/cpumask.h>
 #include <asm/pgtable.h>
@@ -953,6 +954,38 @@ static void vgetcpu_set_mode(void)
 	else
 		vgetcpu_mode = VGETCPU_LSL;
 }
+
+/* May not be __init: called during resume */
+static void syscall32_cpu_init(void)
+{
+	/* Load these always in case some future AMD CPU supports
+	   SYSENTER from compat mode too. */
+	wrmsrl_safe(MSR_IA32_SYSENTER_CS, (u64)__KERNEL_CS);
+	wrmsrl_safe(MSR_IA32_SYSENTER_ESP, 0ULL);
+	wrmsrl_safe(MSR_IA32_SYSENTER_EIP, (u64)ia32_sysenter_target);
+
+	wrmsrl(MSR_CSTAR, ia32_cstar_target);
+}
+#endif
+
+#ifdef CONFIG_X86_32
+void enable_sep_cpu(void)
+{
+	int cpu = get_cpu();
+	struct tss_struct *tss = &per_cpu(init_tss, cpu);
+
+	if (!boot_cpu_has(X86_FEATURE_SEP)) {
+		put_cpu();
+		return;
+	}
+
+	tss->x86_tss.ss1 = __KERNEL_CS;
+	tss->x86_tss.sp1 = sizeof(struct tss_struct) + (unsigned long) tss;
+	wrmsr(MSR_IA32_SYSENTER_CS, __KERNEL_CS, 0);
+	wrmsr(MSR_IA32_SYSENTER_ESP, tss->x86_tss.sp1, 0);
+	wrmsr(MSR_IA32_SYSENTER_EIP, (unsigned long) ia32_sysenter_target, 0);
+	put_cpu();
+}
 #endif
 
 void __init identify_boot_cpu(void)
arch/x86/kernel/hpet.c +0 -3
index 4177bfb..a9777bb 100644
@@ -74,9 +74,6 @@ static inline void hpet_writel(unsigned int d, unsigned int a)
 static inline void hpet_set_mapping(void)
 {
 	hpet_virt_address = ioremap_nocache(hpet_address, HPET_MMAP_SIZE);
-#ifdef CONFIG_X86_64
-	__set_fixmap(VSYSCALL_HPET, hpet_address, PAGE_KERNEL_VVAR_NOCACHE);
-#endif
 }
 
 static inline void hpet_clear_mapping(void)
arch/x86/kernel/signal.c +4 -2
index 9e5de68..a0da58d 100644
@@ -298,7 +298,8 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
 	}
 
 	if (current->mm->context.vdso)
-		restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
+		restorer = current->mm->context.vdso +
+			selected_vdso32->sym___kernel_sigreturn;
 	else
 		restorer = &frame->retcode;
 	if (ksig->ka.sa.sa_flags & SA_RESTORER)
@@ -361,7 +362,8 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
 		save_altstack_ex(&frame->uc.uc_stack, regs->sp);
 
 		/* Set up to return from userspace.  */
-		restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
+		restorer = current->mm->context.vdso +
+			selected_vdso32->sym___kernel_sigreturn;
 		if (ksig->ka.sa.sa_flags & SA_RESTORER)
 			restorer = ksig->ka.sa.sa_restorer;
 		put_user_ex(restorer, &frame->pretcode);
arch/x86/kernel/vsyscall_64.c +4 -11
index 8b3b3eb..ea5b570 100644
@@ -91,7 +91,7 @@ static int addr_to_vsyscall_nr(unsigned long addr)
 {
 	int nr;
 
-	if ((addr & ~0xC00UL) != VSYSCALL_START)
+	if ((addr & ~0xC00UL) != VSYSCALL_ADDR)
 		return -EINVAL;
 
 	nr = (addr & 0xC00UL) >> 10;
@@ -330,24 +330,17 @@ void __init map_vsyscall(void)
 {
 	extern char __vsyscall_page;
 	unsigned long physaddr_vsyscall = __pa_symbol(&__vsyscall_page);
-	unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
 
-	__set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
+	__set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall,
 		     vsyscall_mode == NATIVE
 		     ? PAGE_KERNEL_VSYSCALL
 		     : PAGE_KERNEL_VVAR);
-	BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
-		     (unsigned long)VSYSCALL_START);
-
-	__set_fixmap(VVAR_PAGE, physaddr_vvar_page, PAGE_KERNEL_VVAR);
-	BUILD_BUG_ON((unsigned long)__fix_to_virt(VVAR_PAGE) !=
-		     (unsigned long)VVAR_ADDRESS);
+	BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_PAGE) !=
+		     (unsigned long)VSYSCALL_ADDR);
 }
 
 static int __init vsyscall_init(void)
 {
-	BUG_ON(VSYSCALL_ADDR(0) != __fix_to_virt(VSYSCALL_FIRST_PAGE));
-
 	cpu_notifier_register_begin();
 
 	on_each_cpu(cpu_vsyscall_init, NULL, 1);
arch/x86/mm/fault.c +3 -2
index 8e57229..858b47b 100644
@@ -18,7 +18,8 @@
 #include <asm/traps.h>			/* dotraplinkage, ...		*/
 #include <asm/pgalloc.h>		/* pgd_*(), ...			*/
 #include <asm/kmemcheck.h>		/* kmemcheck_*(), ...		*/
-#include <asm/fixmap.h>			/* VSYSCALL_START		*/
+#include <asm/fixmap.h>			/* VSYSCALL_ADDR		*/
+#include <asm/vsyscall.h>		/* emulate_vsyscall		*/
 
 #define CREATE_TRACE_POINTS
 #include <asm/trace/exceptions.h>
@@ -771,7 +772,7 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
 		 * emulation.
 		 */
 		if (unlikely((error_code & PF_INSTR) &&
-			     ((address & ~0xfff) == VSYSCALL_START))) {
+			     ((address & ~0xfff) == VSYSCALL_ADDR))) {
 			if (emulate_vsyscall(regs, address))
 				return;
 		}
arch/x86/mm/init_64.c +14 -15
index f35c66c..bdcde58 100644
@@ -1055,8 +1055,8 @@ void __init mem_init(void)
 	after_bootmem = 1;
 
 	/* Register memory areas for /proc/kcore */
-	kclist_add(&kcore_vsyscall, (void *)VSYSCALL_START,
-			 VSYSCALL_END - VSYSCALL_START, KCORE_OTHER);
+	kclist_add(&kcore_vsyscall, (void *)VSYSCALL_ADDR,
+			 PAGE_SIZE, KCORE_OTHER);
 
 	mem_init_print_info(NULL);
 }
@@ -1185,11 +1185,19 @@ int kern_addr_valid(unsigned long addr)
  * covers the 64bit vsyscall page now. 32bit has a real VMA now and does
  * not need special handling anymore:
  */
+static const char *gate_vma_name(struct vm_area_struct *vma)
+{
+	return "[vsyscall]";
+}
+static struct vm_operations_struct gate_vma_ops = {
+	.name = gate_vma_name,
+};
 static struct vm_area_struct gate_vma = {
-	.vm_start	= VSYSCALL_START,
-	.vm_end		= VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
+	.vm_start	= VSYSCALL_ADDR,
+	.vm_end		= VSYSCALL_ADDR + PAGE_SIZE,
 	.vm_page_prot	= PAGE_READONLY_EXEC,
-	.vm_flags	= VM_READ | VM_EXEC
+	.vm_flags	= VM_READ | VM_EXEC,
+	.vm_ops		= &gate_vma_ops,
 };
 
 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
@@ -1218,16 +1226,7 @@ int in_gate_area(struct mm_struct *mm, unsigned long addr)
  */
 int in_gate_area_no_mm(unsigned long addr)
 {
-	return (addr >= VSYSCALL_START) && (addr < VSYSCALL_END);
-}
-
-const char *arch_vma_name(struct vm_area_struct *vma)
-{
-	if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
-		return "[vdso]";
-	if (vma == &gate_vma)
-		return "[vsyscall]";
-	return NULL;
+	return (addr & PAGE_MASK) == VSYSCALL_ADDR;
 }
 
 #ifdef CONFIG_X86_UV
arch/x86/mm/ioremap.c +6 -0
index 597ac15..6ef98c5 100644
@@ -355,6 +355,12 @@ void __init early_ioremap_init(void)
 {
 	pmd_t *pmd;
 
+#ifdef CONFIG_X86_64
+	BUILD_BUG_ON((fix_to_virt(0) + PAGE_SIZE) & ((1 << PMD_SHIFT) - 1));
+#else
+	WARN_ON((fix_to_virt(0) + PAGE_SIZE) & ((1 << PMD_SHIFT) - 1));
+#endif
+
 	early_ioremap_setup();
 
 	pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
arch/x86/mm/pgtable.c +3 -3
index c96314a..5f8bdda 100644
@@ -449,9 +449,9 @@ void __init reserve_top_address(unsigned long reserve)
 {
 #ifdef CONFIG_X86_32
 	BUG_ON(fixmaps_set > 0);
-	printk(KERN_INFO "Reserving virtual address space above 0x%08x\n",
-	       (int)-reserve);
-	__FIXADDR_TOP = -reserve - PAGE_SIZE;
+	__FIXADDR_TOP = round_down(-reserve, 1 << PMD_SHIFT) - PAGE_SIZE;
+	printk(KERN_INFO "Reserving virtual address space above 0x%08lx (rounded to 0x%08lx)\n",
+	       -reserve, __FIXADDR_TOP + PAGE_SIZE);
 #endif
 }
 
arch/x86/um/vdso/vma.c +1 -1
index af91901..916cda4 100644
@@ -12,7 +12,7 @@
 #include <asm/page.h>
 #include <linux/init.h>
 
-unsigned int __read_mostly vdso_enabled = 1;
+static unsigned int __read_mostly vdso_enabled = 1;
 unsigned long um_vdso_addr;
 
 extern unsigned long task_size;
arch/x86/vdso/.gitignore +2 -3
index 3282874..aae8ffd 100644
@@ -1,8 +1,7 @@
 vdso.lds
-vdso-syms.lds
 vdsox32.lds
-vdsox32-syms.lds
-vdso32-syms.lds
 vdso32-syscall-syms.lds
 vdso32-sysenter-syms.lds
 vdso32-int80-syms.lds
+vdso-image-*.c
+vdso2c
arch/x86/vdso/Makefile +32 -58

152 lines not on this page · raw message

arch/x86/vdso/vclock_gettime.c +7 -19
index 16d6861..b2e4f49 100644
@@ -30,9 +30,12 @@ extern int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz);
 extern time_t __vdso_time(time_t *t);
 
 #ifdef CONFIG_HPET_TIMER
-static inline u32 read_hpet_counter(const volatile void *addr)
+extern u8 hpet_page
+	__attribute__((visibility("hidden")));
+
+static notrace cycle_t vread_hpet(void)
 {
-	return *(const volatile u32 *) (addr + HPET_COUNTER);
+	return *(const volatile u32 *)(&hpet_page + HPET_COUNTER);
 }
 #endif
 
@@ -43,11 +46,6 @@ static inline u32 read_hpet_counter(const volatile void *addr)
 #include <asm/fixmap.h>
 #include <asm/pvclock.h>
 
-static notrace cycle_t vread_hpet(void)
-{
-	return read_hpet_counter((const void *)fix_to_virt(VSYSCALL_HPET));
-}
-
 notrace static long vdso_fallback_gettime(long clock, struct timespec *ts)
 {
 	long ret;
@@ -137,16 +135,6 @@ static notrace cycle_t vread_pvclock(int *mode)
 
 #else
 
-extern u8 hpet_page
-	__attribute__((visibility("hidden")));
-
-#ifdef CONFIG_HPET_TIMER
-static notrace cycle_t vread_hpet(void)
-{
-	return read_hpet_counter((const void *)(&hpet_page));
-}
-#endif
-
 notrace static long vdso_fallback_gettime(long clock, struct timespec *ts)
 {
 	long ret;
@@ -154,7 +142,7 @@ notrace static long vdso_fallback_gettime(long clock, struct timespec *ts)
 	asm(
 		"mov %%ebx, %%edx \n"
 		"mov %2, %%ebx \n"
-		"call VDSO32_vsyscall \n"
+		"call __kernel_vsyscall \n"
 		"mov %%edx, %%ebx \n"
 		: "=a" (ret)
 		: "0" (__NR_clock_gettime), "g" (clock), "c" (ts)
@@ -169,7 +157,7 @@ notrace static long vdso_fallback_gtod(struct timeval *tv, struct timezone *tz)
 	asm(
 		"mov %%ebx, %%edx \n"
 		"mov %2, %%ebx \n"
-		"call VDSO32_vsyscall \n"
+		"call __kernel_vsyscall \n"
 		"mov %%edx, %%ebx \n"
 		: "=a" (ret)
 		: "0" (__NR_gettimeofday), "g" (tv), "c" (tz)
arch/x86/vdso/vdso-layout.lds.S +24 -16
index 9df017a..2ec72f6 100644
@@ -1,3 +1,5 @@
+#include <asm/vdso.h>
+
 /*
  * Linker script for vDSO.  This is an ELF shared object prelinked to
  * its virtual address, and with only one read-only segment.
@@ -6,20 +8,6 @@
 
 SECTIONS
 {
-#ifdef BUILD_VDSO32
-#include <asm/vdso32.h>
-
-	hpet_page = . - VDSO_OFFSET(VDSO_HPET_PAGE);
-
-	vvar = . - VDSO_OFFSET(VDSO_VVAR_PAGE);
-
-	/* Place all vvars at the offsets in asm/vvar.h. */
-#define EMIT_VVAR(name, offset) vvar_ ## name = vvar + offset;
-#define __VVAR_KERNEL_LDS
-#include <asm/vvar.h>
-#undef __VVAR_KERNEL_LDS
-#undef EMIT_VVAR
-#endif
 	. = SIZEOF_HEADERS;
 
 	.hash		: { *(.hash) }			:text
@@ -60,10 +48,30 @@ SECTIONS
 	.text		: { *(.text*) }			:text	=0x90909090,
 
 	/*
-	 * The comma above works around a bug in gold:
-	 * https://sourceware.org/bugzilla/show_bug.cgi?id=16804
+	 * The remainder of the vDSO consists of special pages that are
+	 * shared between the kernel and userspace.  It needs to be at the
+	 * end so that it doesn't overlap the mapping of the actual
+	 * vDSO image.
 	 */
 
+	. = ALIGN(PAGE_SIZE);
+	vvar_page = .;
+
+	/* Place all vvars at the offsets in asm/vvar.h. */
+#define EMIT_VVAR(name, offset) vvar_ ## name = vvar_page + offset;
+#define __VVAR_KERNEL_LDS
+#include <asm/vvar.h>
+#undef __VVAR_KERNEL_LDS
+#undef EMIT_VVAR
+
+	. = vvar_page + PAGE_SIZE;
+
+	hpet_page = .;
+	. = . + PAGE_SIZE;
+
+	. = ALIGN(PAGE_SIZE);
+	end_mapping = .;
+
 	/DISCARD/ : {
 		*(.discard)
 		*(.discard.*)
arch/x86/vdso/vdso.S deleted +0 -3
deleted file mode 100644
index be3f23b..0000000
@@ -1,3 +0,0 @@
-#include <asm/vdso.h>
-
-DEFINE_VDSO_IMAGE(vdso, "arch/x86/vdso/vdso.so")
arch/x86/vdso/vdso.lds.S +1 -6
index b96b267..75e3404 100644
@@ -1,14 +1,11 @@
 /*
  * Linker script for 64-bit vDSO.
  * We #include the file to define the layout details.
- * Here we only choose the prelinked virtual address.
  *
  * This file defines the version script giving the user-exported symbols in
- * the DSO.  We can define local symbols here called VDSO* to make their
- * values visible using the asm-x86/vdso.h macros from the kernel proper.
+ * the DSO.
  */
 
-#define VDSO_PRELINK 0xffffffffff700000
 #include "vdso-layout.lds.S"
 
 /*
@@ -28,5 +25,3 @@ VERSION {
 	local: *;
 	};
 }
-
-VDSO64_PRELINK = VDSO_PRELINK;
arch/x86/vdso/vdso2c.c new file +173 -0

173 lines not on this page · raw message

arch/x86/vdso/vdso2c.h new file +163 -0

163 lines not on this page · raw message

arch/x86/vdso/vdso32-setup.c +22 -182

269 lines not on this page · raw message

arch/x86/vdso/vdso32.S deleted +0 -9
deleted file mode 100644
index 018bcd9..0000000
@@ -1,9 +0,0 @@
-#include <asm/vdso.h>
-
-DEFINE_VDSO_IMAGE(vdso32_int80, "arch/x86/vdso/vdso32-int80.so")
-
-#ifdef CONFIG_COMPAT
-DEFINE_VDSO_IMAGE(vdso32_syscall, "arch/x86/vdso/vdso32-syscall.so")
-#endif
-
-DEFINE_VDSO_IMAGE(vdso32_sysenter, "arch/x86/vdso/vdso32-sysenter.so")
arch/x86/vdso/vdso32/vdso32.lds.S +1 -14
index aadb8b9..31056cf 100644
@@ -1,17 +1,14 @@
 /*
  * Linker script for 32-bit vDSO.
  * We #include the file to define the layout details.
- * Here we only choose the prelinked virtual address.
  *
  * This file defines the version script giving the user-exported symbols in
- * the DSO.  We can define local symbols here called VDSO* to make their
- * values visible using the asm-x86/vdso.h macros from the kernel proper.
+ * the DSO.
  */
 
 #include <asm/page.h>
 
 #define BUILD_VDSO32
-#define VDSO_PRELINK 0
 
 #include "../vdso-layout.lds.S"
 
@@ -38,13 +35,3 @@ VERSION
 	local: *;
 	};
 }
-
-/*
- * Symbols we define here called VDSO* get their values into vdso32-syms.h.
- */
-VDSO32_vsyscall		= __kernel_vsyscall;
-VDSO32_sigreturn	= __kernel_sigreturn;
-VDSO32_rt_sigreturn	= __kernel_rt_sigreturn;
-VDSO32_clock_gettime	= clock_gettime;
-VDSO32_gettimeofday	= gettimeofday;
-VDSO32_time		= time;
arch/x86/vdso/vdsox32.S deleted +0 -3
deleted file mode 100644
index f4aa34e..0000000
@@ -1,3 +0,0 @@
-#include <asm/vdso.h>
-
-DEFINE_VDSO_IMAGE(vdsox32, "arch/x86/vdso/vdsox32.so")
arch/x86/vdso/vdsox32.lds.S +1 -6
index 62272aa..46b991b 100644
@@ -1,14 +1,11 @@
 /*
  * Linker script for x32 vDSO.
  * We #include the file to define the layout details.
- * Here we only choose the prelinked virtual address.
  *
  * This file defines the version script giving the user-exported symbols in
- * the DSO.  We can define local symbols here called VDSO* to make their
- * values visible using the asm-x86/vdso.h macros from the kernel proper.
+ * the DSO.
  */
 
-#define VDSO_PRELINK 0
 #include "vdso-layout.lds.S"
 
 /*
@@ -24,5 +21,3 @@ VERSION {
 	local: *;
 	};
 }
-
-VDSOX32_PRELINK = VDSO_PRELINK;
arch/x86/vdso/vma.c +130 -106

306 lines not on this page · raw message

arch/x86/xen/mmu.c +3 -5
index 86e02ea..3060568 100644
@@ -1494,7 +1494,7 @@ static int xen_pgd_alloc(struct mm_struct *mm)
 		page->private = (unsigned long)user_pgd;
 
 		if (user_pgd != NULL) {
-			user_pgd[pgd_index(VSYSCALL_START)] =
+			user_pgd[pgd_index(VSYSCALL_ADDR)] =
 				__pgd(__pa(level3_user_vsyscall) | _PAGE_TABLE);
 			ret = 0;
 		}
@@ -2062,8 +2062,7 @@ static void xen_set_fixmap(unsigned idx, phys_addr_t phys, pgprot_t prot)
 	case FIX_KMAP_BEGIN ... FIX_KMAP_END:
 # endif
 #else
-	case VSYSCALL_LAST_PAGE ... VSYSCALL_FIRST_PAGE:
-	case VVAR_PAGE:
+	case VSYSCALL_PAGE:
 #endif
 	case FIX_TEXT_POKE0:
 	case FIX_TEXT_POKE1:
@@ -2104,8 +2103,7 @@ static void xen_set_fixmap(unsigned idx, phys_addr_t phys, pgprot_t prot)
 #ifdef CONFIG_X86_64
 	/* Replicate changes to map the vsyscall page into the user
 	   pagetable vsyscall mapping. */
-	if ((idx >= VSYSCALL_LAST_PAGE && idx <= VSYSCALL_FIRST_PAGE) ||
-	    idx == VVAR_PAGE) {
+	if (idx == VSYSCALL_PAGE) {
 		unsigned long vaddr = __fix_to_virt(idx);
 		set_pte_vaddr_pud(level3_user_vsyscall, vaddr, pte);
 	}
arch/x86/xen/setup.c +9 -2
index 0982233..7225a95 100644
@@ -516,10 +516,17 @@ char * __init xen_memory_setup(void)
 static void __init fiddle_vdso(void)
 {
 #ifdef CONFIG_X86_32
+	/*
+	 * This could be called before selected_vdso32 is initialized, so
+	 * just fiddle with both possible images.  vdso_image_32_syscall
+	 * can't be selected, since it only exists on 64-bit systems.
+	 */
 	u32 *mask;
-	mask = VDSO32_SYMBOL(&vdso32_int80_start, NOTE_MASK);
+	mask = vdso_image_32_int80.data +
+		vdso_image_32_int80.sym_VDSO32_NOTE_MASK;
 	*mask |= 1 << VDSO_NOTE_NONEGSEG_BIT;
-	mask = VDSO32_SYMBOL(&vdso32_sysenter_start, NOTE_MASK);
+	mask = vdso_image_32_sysenter.data +
+		vdso_image_32_sysenter.sym_VDSO32_NOTE_MASK;
 	*mask |= 1 << VDSO_NOTE_NONEGSEG_BIT;
 #endif
 }
fs/binfmt_elf.c +8 -0
index aa3cb62..df9ea41 100644
@@ -1108,6 +1108,14 @@ static bool always_dump_vma(struct vm_area_struct *vma)
 	/* Any vsyscall mappings? */
 	if (vma == get_gate_vma(vma->vm_mm))
 		return true;
+
+	/*
+	 * Assume that all vmas with a .name op should always be dumped.
+	 * If this changes, a new vm_ops field can easily be added.
+	 */
+	if (vma->vm_ops && vma->vm_ops->name && vma->vm_ops->name(vma))
+		return true;
+
 	/*
 	 * arch_vma_name() returns non-NULL for special architecture mappings,
 	 * such as vDSO sections.
fs/proc/task_mmu.c +6 -0
index 442177b..9b2f5d6 100644
@@ -300,6 +300,12 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
 		goto done;
 	}
 
+	if (vma->vm_ops && vma->vm_ops->name) {
+		name = vma->vm_ops->name(vma);
+		if (name)
+			goto done;
+	}
+
 	name = arch_vma_name(vma);
 	if (!name) {
 		pid_t tid;
include/linux/mm.h +9 -1
index d677706..fb27946 100644
@@ -239,6 +239,12 @@ struct vm_operations_struct {
 	 */
 	int (*access)(struct vm_area_struct *vma, unsigned long addr,
 		      void *buf, int len, int write);
+
+	/* Called by the /proc/PID/maps code to ask the vma whether it
+	 * has a special name.  Returning non-NULL will also cause this
+	 * vma to be dumped unconditionally. */
+	const char *(*name)(struct vm_area_struct *vma);
+
 #ifdef CONFIG_NUMA
 	/*
 	 * set_policy() op must add a reference to any non-NULL @new mempolicy
@@ -1778,7 +1784,9 @@ extern struct file *get_mm_exe_file(struct mm_struct *mm);
 extern int may_expand_vm(struct mm_struct *mm, unsigned long npages);
 extern struct vm_area_struct *_install_special_mapping(struct mm_struct *mm,
 				   unsigned long addr, unsigned long len,
-				   unsigned long flags, struct page **pages);
+				   unsigned long flags,
+				   const struct vm_special_mapping *spec);
+/* This is an obsolete alternative to _install_special_mapping. */
 extern int install_special_mapping(struct mm_struct *mm,
 				   unsigned long addr, unsigned long len,
 				   unsigned long flags, struct page **pages);
include/linux/mm_types.h +6 -0
index 8967e20..22c6f4e 100644
@@ -510,4 +510,10 @@ static inline void clear_tlb_flush_pending(struct mm_struct *mm)
 }
 #endif
 
+struct vm_special_mapping
+{
+	const char *name;
+	struct page **pages;
+};
+
 #endif /* _LINUX_MM_TYPES_H */
kernel/sysctl.c +5 -0
index 74f5b58..420d77a 100644
@@ -1418,8 +1418,13 @@ static struct ctl_table vm_table[] = {
    (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
 	{
 		.procname	= "vdso_enabled",
+#ifdef CONFIG_X86_32
+		.data		= &vdso32_enabled,
+		.maxlen		= sizeof(vdso32_enabled),
+#else
 		.data		= &vdso_enabled,
 		.maxlen		= sizeof(vdso_enabled),
+#endif
 		.mode		= 0644,
 		.proc_handler	= proc_dointvec,
 		.extra1		= &zero,
mm/mmap.c +60 -29

123 lines not on this page · raw message

maintainer
#1 lore raw
Quoted 1 line · On Wed, 4 Jun 2014 15:35:42 -0700 "H. Peter Anvin" <[email protected]> wrote:

Vdso cleanups and improvements largely from Andy Lutomirski.

arch/x86/vdso/vdso2c.h: In function 'go64':
arch/x86/vdso/vdso2c.h:21: warning: implicit declaration of function 'le64toh' arch/x86/vdso/vdso2c.h:21: warning: implicit declaration of function 'le32toh' arch/x86/vdso/vdso2c.h:21: warning: implicit declaration of function 'le16toh' arch/x86/vdso/vdso2c.h:119: warning: implicit declaration of function 'htole16'

My Fedora Core 6 (lol gotcha) test box doesn't have these.

http://www.unix.com/man-page/linux/3/le64toh/ has some details. I don't appear to have letoh64 and friends either.

#2 lore raw
Quoted 10 lines · Andrew Morton
Quoted 1 line · On Wed, 4 Jun 2014 15:35:42 -0700 "H. Peter Anvin" <[email protected]> wrote:

Vdso cleanups and improvements largely from Andy Lutomirski.

arch/x86/vdso/vdso2c.h: In function 'go64':
arch/x86/vdso/vdso2c.h:21: warning: implicit declaration of function 'le64toh' arch/x86/vdso/vdso2c.h:21: warning: implicit declaration of function 'le32toh' arch/x86/vdso/vdso2c.h:21: warning: implicit declaration of function 'le16toh' arch/x86/vdso/vdso2c.h:119: warning: implicit declaration of function 'htole16'

Quoted 5 lines

My Fedora Core 6 (lol gotcha) test box doesn't have these.

http://www.unix.com/man-page/linux/3/le64toh/ has some details. I don't appear to have letoh64 and friends either.

OK... so now we have a tools baseline problem. It isn't that we couldn't open-code these functions, but of course we'd also like to not *have* to do so... but also we don't want to have the kernel build rely on autoconf ;)

So we have a few options, here:

1. We could use the unaligned macros defined in
tools/include/tools/*_byteshift.h.

2. Open-code it.

3. Define a baseline which includes these kinds of functions.

I guess I would be leaning toward #1, but would also wonder if that also means we should add -I$(srctree)/tools/include to the global settings ... we are *already* adding it to HOSTCFLAGS_sortextable.o.

Thoughs?

-hpa

#3 lore raw
Quoted 27 lines · H. Peter Anvin
Quoted 10 lines · Andrew Morton
Quoted 1 line · On Wed, 4 Jun 2014 15:35:42 -0700 "H. Peter Anvin" <[email protected]> wrote:

Vdso cleanups and improvements largely from Andy Lutomirski.

arch/x86/vdso/vdso2c.h: In function 'go64':
arch/x86/vdso/vdso2c.h:21: warning: implicit declaration of function 'le64toh' arch/x86/vdso/vdso2c.h:21: warning: implicit declaration of function 'le32toh' arch/x86/vdso/vdso2c.h:21: warning: implicit declaration of function 'le16toh' arch/x86/vdso/vdso2c.h:119: warning: implicit declaration of function 'htole16'

Quoted 5 lines

My Fedora Core 6 (lol gotcha) test box doesn't have these.

http://www.unix.com/man-page/linux/3/le64toh/ has some details. I don't appear to have letoh64 and friends either.

OK... so now we have a tools baseline problem. It isn't that we couldn't open-code these functions, but of course we'd also like to not *have* to do so... but also we don't want to have the kernel build rely on autoconf ;)

So we have a few options, here:

1. We could use the unaligned macros defined in
tools/include/tools/*_byteshift.h.

Quoted 7 lines

2. Open-code it.

3. Define a baseline which includes these kinds of functions.

I guess I would be leaning toward #1, but would also wonder if that also means we should add -I$(srctree)/tools/include to the global settings ... we are *already* adding it to HOSTCFLAGS_sortextable.o.

I would say that tools/include/tools/* should be considered the baseline for programs running on the host.
So therefore unconditionally adding -I$(srctree)/tools/include should then be OK.

Sam

#4 lore raw
Quoted 8 lines · Sam Ravnborg

I would say that tools/include/tools/* should be considered the baseline for programs running on the host.
So therefore unconditionally adding -I$(srctree)/tools/include should then be OK.

Sam

I think we should do this, but I didn't yet because linux/types.h in that directory shadows uapi/linux/types.h which probably should be fixed first.

#5 lore raw
In reply to Andrew Morton
Quoted 8 lines · Andrew Morton

arch/x86/vdso/vdso2c.h: In function 'go64':
arch/x86/vdso/vdso2c.h:21: warning: implicit declaration of function 'le64toh' arch/x86/vdso/vdso2c.h:21: warning: implicit declaration of function 'le32toh' arch/x86/vdso/vdso2c.h:21: warning: implicit declaration of function 'le16toh' arch/x86/vdso/vdso2c.h:119: warning: implicit declaration of function 'htole16'

My Fedora Core 6 (lol gotcha) test box doesn't have these.

Suggested fix: only use the helper functions on non-x86 (or non-little-endian) platforms.

Peter, Andy?

Linus

#6 lore raw
Quoted 8 lines · Linus Torvalds
Quoted 7 lines · Andrew Morton

arch/x86/vdso/vdso2c.h: In function 'go64':
arch/x86/vdso/vdso2c.h:21: warning: implicit declaration of function 'le64toh' arch/x86/vdso/vdso2c.h:21: warning: implicit declaration of function 'le32toh' arch/x86/vdso/vdso2c.h:21: warning: implicit declaration of function 'le16toh' arch/x86/vdso/vdso2c.h:119: warning: implicit declaration of function 'htole16'

Quoted 6 lines
Quoted 1 line

My Fedora Core 6 (lol gotcha) test box doesn't have these.

Suggested fix: only use the helper functions on non-x86 (or non-little-endian) platforms.

Peter, Andy?

The only real downside to that would be the chance of bitrot if that code isn't getting used on native builds.

Blech.

--Andy

#7 lore raw
Quoted 3 lines · Andy Lutomirski

The only real downside to that would be the chance of bitrot if that code isn't getting used on native builds.

Sure. Does anybody really care?

You could obviously just open-code the things, but the fact is, "le64toh()" isn't exactly a standard function anyway, so now that I see it needed I go "yeah, that's clearly completely unacceptable".

I'd much rather say "screw cross-compiling" (because let's face it, nobody sane cross-compiles x86 on anything else) than say "screw old machines".

Linus

#8 lore raw
Quoted 7 lines · Linus Torvalds
Quoted 3 lines · Andy Lutomirski

The only real downside to that would be the chance of bitrot if that code isn't getting used on native builds.

Sure. Does anybody really care?

Quoted 7 lines

You could obviously just open-code the things, but the fact is, "le64toh()" isn't exactly a standard function anyway, so now that I see it needed I go "yeah, that's clearly completely unacceptable".

I'd much rather say "screw cross-compiling" (because let's face it, nobody sane cross-compiles x86 on anything else) than say "screw old machines".

Tell that to Stephen Rothwell, who apparently cross-compiles x86 on ppc on a regular basis :)

I'll send a patch.

--Andy

#9 lore raw
In reply to Linus Torvalds
Quoted 7 lines · Linus Torvalds
Quoted 3 lines · Andy Lutomirski

The only real downside to that would be the chance of bitrot if that code isn't getting used on native builds.

Sure. Does anybody really care?

Quoted 8 lines

You could obviously just open-code the things, but the fact is, "le64toh()" isn't exactly a standard function anyway, so now that I see it needed I go "yeah, that's clearly completely unacceptable".

I'd much rather say "screw cross-compiling" (because let's face it, nobody sane cross-compiles x86 on anything else) than say "screw old machines".

I'm thinking we should just carry the support functions with us, we already have some of those in tools/include. Working on a patchset for this.

-hpa

#10 lore raw
Quoted 12 lines · H. Peter Anvin
Quoted 11 lines · Linus Torvalds
Quoted 3 lines · Andy Lutomirski

The only real downside to that would be the chance of bitrot if that code isn't getting used on native builds.

Sure. Does anybody really care?

You could obviously just open-code the things, but the fact is, "le64toh()" isn't exactly a standard function anyway, so now that I see it needed I go "yeah, that's clearly completely unacceptable".

Quoted 8 lines
Quoted 4 lines

I'd much rather say "screw cross-compiling" (because let's face it, nobody sane cross-compiles x86 on anything else) than say "screw old machines".

I'm thinking we should just carry the support functions with us, we already have some of those in tools/include. Working on a patchset for this.

Sounds good.

In the mean time, a trivial fix is here:

https://git.kernel.org/cgit/linux/kernel/git/luto/linux.git/commit/?h=vdso/cleanup_fixes&id=cf780a0dc71f7cbd9a417e6ce2d5ddf56abccb74

(or it will be once the mirrors sync)

--Andy

#12 lore raw
Quoted 6 lines · H. Peter Anvin
Quoted 5 lines · Andy Lutomirski

Sounds good.

In the mean time, a trivial fix is here:

Quoted 7 lines
Quoted 4 lines

https://git.kernel.org/cgit/linux/kernel/git/luto/linux.git/commit/?h=vdso/cleanup_fixes&id=cf780a0dc71f7cbd9a417e6ce2d5ddf56abccb74

(or it will be once the mirrors sync)

Unfortunately gcc didn't introduce __BYTE_ORDER__ at the compiler level until 2010. This makes it harder to do this in a portable manner.

Is there anything wrong with using __get_unaligned_leNN directly?

Quoted 4 lines

-hpa

Signature · 2 lines
Andy Lutomirski
AMA Capital Management, LLC
#13 lore raw
Quoted 9 lines · Andy Lutomirski
Quoted 8 lines · H. Peter Anvin
Quoted 7 lines · Andy Lutomirski

Sounds good.

In the mean time, a trivial fix is here:

https://git.kernel.org/cgit/linux/kernel/git/luto/linux.git/commit/?h=vdso/cleanup_fixes&id=cf780a0dc71f7cbd9a417e6ce2d5ddf56abccb74

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

(or it will be once the mirrors sync)

Unfortunately gcc didn't introduce __BYTE_ORDER__ at the compiler level until 2010. This makes it harder to do this in a portable manner.

Is there anything wrong with using __get_unaligned_leNN directly?

Minus the double underscore (these files need to be cleaned up), not really, and that is what my patch does.

For accessing memory members doing it via a pointer is pretty much TRT, but for things that might be in register it is undesirable to force it out to memory.

-hpa

#14 lore raw
Quoted 19 lines · H. Peter Anvin
Quoted 9 lines · Andy Lutomirski
Quoted 8 lines · H. Peter Anvin
Quoted 7 lines · Andy Lutomirski

Sounds good.

In the mean time, a trivial fix is here:

https://git.kernel.org/cgit/linux/kernel/git/luto/linux.git/commit/?h=vdso/cleanup_fixes&id=cf780a0dc71f7cbd9a417e6ce2d5ddf56abccb74

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

(or it will be once the mirrors sync)

Unfortunately gcc didn't introduce __BYTE_ORDER__ at the compiler level until 2010. This makes it harder to do this in a portable manner.

Is there anything wrong with using __get_unaligned_leNN directly?

Quoted 6 lines

Minus the double underscore (these files need to be cleaned up), not really, and that is what my patch does.

For accessing memory members doing it via a pointer is pretty much TRT, but for things that might be in register it is undesirable to force it out to memory.

Do you also believe in the folklore that GCC can optimize code sequences like the things in that header? Because I'm pretty sure that no clang or gcc version I've ever seen can do it.

On the other hand, even a factor of ten in the time it takes to run vdso2c is completely irrelevant.

--Andy

#15 lore raw
Quoted 9 lines · Andy Lutomirski
Quoted 4 lines

For accessing memory members doing it via a pointer is pretty much TRT, but for things that might be in register it is undesirable to force it out to memory.

Do you also believe in the folklore that GCC can optimize code sequences like the things in that header? Because I'm pretty sure that no clang or gcc version I've ever seen can do it.

I have seen gcc do some pretty sophisticated memory elision lately. Don't know if that includes byte swaps.

Quoted 2 lines

On the other hand, even a factor of ten in the time it takes to run vdso2c is completely irrelevant.

Yep, as I noted in the patch I sent (which is broken - updated one included here.)

-hpa

Quoted 1 line

From 627dd886af4aff858af22288bdbd674deb3339b1 Mon Sep 17 00:00:00 2001

From: "H. Peter Anvin" <[email protected]>
Date: Fri, 6 Jun 2014 14:30:37 -0700
Subject: [PATCH] x86, vdso: Use <tools/le_byteshift.h> for littleendian access

There are no standard functions for littleendian data (unlike bigendian data.) Thus, use <tools/le_byteshift.h> to access littleendian data members. Those are fairly inefficient, but it doesn't matter for this purpose (and can be optimized later.) This avoids portability problems.

---
 arch/x86/vdso/Makefile |  1 +
 arch/x86/vdso/vdso2c.c | 10 ++++----
 arch/x86/vdso/vdso2c.h | 62 +++++++++++++++++++++++++-------------------------
 3 files changed, 38 insertions(+), 35 deletions(-)
arch/x86/vdso/Makefile +1 -0
index 895d4b1..9769df0 100644
@@ -59,6 +59,7 @@ VDSO_LDFLAGS_vdso.lds = -m64 -Wl,-soname=linux-vdso.so.1 \
 $(obj)/vdso64.so.dbg: $(src)/vdso.lds $(vobjs) FORCE
 	$(call if_changed,vdso)
 
+HOST_EXTRACFLAGS += -I$(srctree)/tools/include
 hostprogs-y			+= vdso2c
 
 quiet_cmd_vdso2c = VDSO2C  $@
arch/x86/vdso/vdso2c.c +6 -4
index deabaf5..450ac6e 100644
@@ -11,6 +11,8 @@
 #include <sys/mman.h>
 #include <sys/types.h>
 
+#include <tools/le_byteshift.h>
+
 #include <linux/elf.h>
 #include <linux/types.h>
 
@@ -56,12 +58,12 @@ static void fail(const char *format, ...)
  */
 #define GLE(x, bits, ifnot)						\
 	__builtin_choose_expr(						\
-		(sizeof(x) == bits/8),					\
-		(__typeof__(x))le##bits##toh(x), ifnot)
+		(sizeof(*(x)) == bits/8),				\
+		(__typeof__(*(x)))get_unaligned_le##bits(x), ifnot)
 
-extern void bad_get_le(uint64_t);
+extern void bad_get_le(void);
 #define LAST_LE(x)							\
-	__builtin_choose_expr(sizeof(x) == 1, (x), bad_get_le(x))
+	__builtin_choose_expr(sizeof(*(x)) == 1, *(x), bad_get_le())
 
 #define GET_LE(x)							\
 	GLE(x, 64, GLE(x, 32, GLE(x, 16, LAST_LE(x))))
arch/x86/vdso/vdso2c.h +31 -31

116 lines not on this page · raw message

Signature · 1 line
1.9.3
#16 lore raw
Quoted 11 lines · H. Peter Anvin
Quoted 9 lines · Andy Lutomirski
Quoted 4 lines

For accessing memory members doing it via a pointer is pretty much TRT, but for things that might be in register it is undesirable to force it out to memory.

Do you also believe in the folklore that GCC can optimize code sequences like the things in that header? Because I'm pretty sure that no clang or gcc version I've ever seen can do it.

Quoted 8 lines

I have seen gcc do some pretty sophisticated memory elision lately. Don't know if that includes byte swaps.

Quoted 2 lines

On the other hand, even a factor of ten in the time it takes to run vdso2c is completely irrelevant.

Yep, as I noted in the patch I sent (which is broken - updated one included here.)

The generated vdso-image-*.c files are identical.

--Andy

Quoted 3 lines

-hpa

Signature · 2 lines
Andy Lutomirski
AMA Capital Management, LLC
#17 lore raw
In reply to Andy Lutomirski

Want to help test this?

I dropped the idea of adding -I$(srctree)/tools/include globally for right now, because there is a linux/types.h in that directory which shadows the uapi definition, and that could break some libcs. That should almost certainly be fixed.

-hpa

Quoted 1 line

From 37848b0fcf39503e357b0879553d9a7b24a000fd Mon Sep 17 00:00:00 2001

From: "H. Peter Anvin" <[email protected]>
Date: Fri, 6 Jun 2014 14:30:37 -0700
Subject: [PATCH] x86, vdso: Use <tools/le_byteshift.h> for littleendian access

There are no standard functions for littleendian data (unlike bigendian data.) Thus, use <tools/le_byteshift.h> to access littleendian data members. Those are fairly inefficient, but it doesn't matter for this purpose (and can be optimized later.) This avoids portability problems.

---
 arch/x86/vdso/Makefile |  1 +
 arch/x86/vdso/vdso2c.c |  8 ++++---
 arch/x86/vdso/vdso2c.h | 62 +++++++++++++++++++++++++-------------------------
 3 files changed, 37 insertions(+), 34 deletions(-)
arch/x86/vdso/Makefile +1 -0
index 895d4b1..9769df0 100644
@@ -59,6 +59,7 @@ VDSO_LDFLAGS_vdso.lds = -m64 -Wl,-soname=linux-vdso.so.1 \
 $(obj)/vdso64.so.dbg: $(src)/vdso.lds $(vobjs) FORCE
 	$(call if_changed,vdso)
 
+HOST_EXTRACFLAGS += -I$(srctree)/tools/include
 hostprogs-y			+= vdso2c
 
 quiet_cmd_vdso2c = VDSO2C  $@
arch/x86/vdso/vdso2c.c +5 -3
index deabaf5..d5042c6 100644
@@ -11,6 +11,8 @@
 #include <sys/mman.h>
 #include <sys/types.h>
 
+#include <tools/le_byteshift.h>
+
 #include <linux/elf.h>
 #include <linux/types.h>
 
@@ -56,12 +58,12 @@ static void fail(const char *format, ...)
  */
 #define GLE(x, bits, ifnot)						\
 	__builtin_choose_expr(						\
-		(sizeof(x) == bits/8),					\
-		(__typeof__(x))le##bits##toh(x), ifnot)
+		(sizeof(*(x)) == bits/8),				\
+		(__typeof__(*(x)))get_unaligned_le##bits(x), ifnot)
 
 extern void bad_get_le(uint64_t);
 #define LAST_LE(x)							\
-	__builtin_choose_expr(sizeof(x) == 1, (x), bad_get_le(x))
+	__builtin_choose_expr(sizeof(*(x)) == 1, *(x), bad_get_le(x))
 
 #define GET_LE(x)							\
 	GLE(x, 64, GLE(x, 32, GLE(x, 16, LAST_LE(x))))
arch/x86/vdso/vdso2c.h +31 -31

116 lines not on this page · raw message

Signature · 1 line
1.9.3
#18 lore raw

[tip:x86/vdso] x86, vdso: Use <tools/le_byteshift.h> for littleendian access

In reply to Andrew Morton
x86, vdso: Use <tools/le_byteshift.h> for littleendian access
Commit-ID:  bdfb9bcc25005d06a9c301830bdeb7ca5a0b6ef7
Gitweb:     http://git.kernel.org/tip/bdfb9bcc25005d06a9c301830bdeb7ca5a0b6ef7
Author:     H. Peter Anvin <[email protected]>
AuthorDate: Fri, 6 Jun 2014 14:30:37 -0700
Committer:  H. Peter Anvin <[email protected]>
CommitDate: Fri, 6 Jun 2014 14:54:54 -0700

x86, vdso: Use <tools/le_byteshift.h> for littleendian access

There are no standard functions for littleendian data (unlike bigendian data.) Thus, use <tools/le_byteshift.h> to access littleendian data members. Those are fairly inefficient, but it doesn't matter for this purpose (and can be optimized later.) This avoids portability problems.

---
 arch/x86/vdso/Makefile |  1 +
 arch/x86/vdso/vdso2c.c | 10 ++++----
 arch/x86/vdso/vdso2c.h | 62 +++++++++++++++++++++++++-------------------------
 3 files changed, 38 insertions(+), 35 deletions(-)
arch/x86/vdso/Makefile +1 -0
index 895d4b1..9769df0 100644
@@ -59,6 +59,7 @@ VDSO_LDFLAGS_vdso.lds = -m64 -Wl,-soname=linux-vdso.so.1 \
 $(obj)/vdso64.so.dbg: $(src)/vdso.lds $(vobjs) FORCE
 	$(call if_changed,vdso)
 
+HOST_EXTRACFLAGS += -I$(srctree)/tools/include
 hostprogs-y			+= vdso2c
 
 quiet_cmd_vdso2c = VDSO2C  $@
arch/x86/vdso/vdso2c.c +6 -4
index deabaf5..450ac6e 100644
@@ -11,6 +11,8 @@
 #include <sys/mman.h>
 #include <sys/types.h>
 
+#include <tools/le_byteshift.h>
+
 #include <linux/elf.h>
 #include <linux/types.h>
 
@@ -56,12 +58,12 @@ static void fail(const char *format, ...)
  */
 #define GLE(x, bits, ifnot)						\
 	__builtin_choose_expr(						\
-		(sizeof(x) == bits/8),					\
-		(__typeof__(x))le##bits##toh(x), ifnot)
+		(sizeof(*(x)) == bits/8),				\
+		(__typeof__(*(x)))get_unaligned_le##bits(x), ifnot)
 
-extern void bad_get_le(uint64_t);
+extern void bad_get_le(void);
 #define LAST_LE(x)							\
-	__builtin_choose_expr(sizeof(x) == 1, (x), bad_get_le(x))
+	__builtin_choose_expr(sizeof(*(x)) == 1, *(x), bad_get_le())
 
 #define GET_LE(x)							\
 	GLE(x, 64, GLE(x, 32, GLE(x, 16, LAST_LE(x))))
arch/x86/vdso/vdso2c.h +31 -31

116 lines not on this page · raw message

maintainer
#19 lore raw

Re: [tip:x86/vdso] x86, vdso: Use <tools/le_byteshift.h> for littleendian access

Quoted 8 lines · On Fri, 6 Jun 2014 15:00:29 -0700 "tip-bot for H. Peter Anvin"…
Commit-ID:  bdfb9bcc25005d06a9c301830bdeb7ca5a0b6ef7
Gitweb:     http://git.kernel.org/tip/bdfb9bcc25005d06a9c301830bdeb7ca5a0b6ef7
Author:     H. Peter Anvin <[email protected]>
AuthorDate: Fri, 6 Jun 2014 14:30:37 -0700
Committer:  H. Peter Anvin <[email protected]>
CommitDate: Fri, 6 Jun 2014 14:54:54 -0700

x86, vdso: Use <tools/le_byteshift.h> for littleendian access

Getting closer.

In file included from arch/x86/vdso/vdso2c.c:80:
arch/x86/vdso/vdso2c.h: In function 'go64':
arch/x86/vdso/vdso2c.h:119: warning: implicit declaration of function 'htole16' /tmp/cc04m2KE.o: In function `go':
vdso2c.c:(.text+0xf69): undefined reference to htole16' vdso2c.c:(.text+0x12e6): undefined reference to htole16'

#20 lore raw

Re: [tip:x86/vdso] x86, vdso: Use <tools/le_byteshift.h> for littleendian access

Quoted 11 lines · Andrew Morton
Quoted 8 lines · On Fri, 6 Jun 2014 15:00:29 -0700 "tip-bot for H. Peter Anvin"…
Commit-ID:  bdfb9bcc25005d06a9c301830bdeb7ca5a0b6ef7
Gitweb:     http://git.kernel.org/tip/bdfb9bcc25005d06a9c301830bdeb7ca5a0b6ef7
Author:     H. Peter Anvin <[email protected]>
AuthorDate: Fri, 6 Jun 2014 14:30:37 -0700
Committer:  H. Peter Anvin <[email protected]>
CommitDate: Fri, 6 Jun 2014 14:54:54 -0700

x86, vdso: Use <tools/le_byteshift.h> for littleendian access

Quoted 9 lines

Getting closer.

In file included from arch/x86/vdso/vdso2c.c:80:
arch/x86/vdso/vdso2c.h: In function 'go64':
arch/x86/vdso/vdso2c.h:119: warning: implicit declaration of function 'htole16' /tmp/cc04m2KE.o: In function `go':
vdso2c.c:(.text+0xf69): undefined reference to htole16' vdso2c.c:(.text+0x12e6): undefined reference to htole16'

Want to test this patch before I commit it?

-hpa

Quoted 1 line

From 15ea1a528e08c6bc322f10686ec8d73ba413b941 Mon Sep 17 00:00:00 2001

From: "H. Peter Anvin" <[email protected]>
Date: Tue, 10 Jun 2014 14:25:26 -0700
Subject: [PATCH] x86, vdso: Remove one final use of htole16()

One final use of the macros from <endian.h> which are not available on older system. In this case we had one sole case of *writing* a littleendian number, but the number is SHN_UNDEF which is the constant zero, so rather than dealing with the general case of littleendian puts here, just document that the constant is zero and be done with it.

---
 arch/x86/vdso/vdso2c.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/vdso/vdso2c.h +1 -1
index 8a074637a576..d9f6f61aef1c 100644
@@ -116,7 +116,7 @@ static void GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
 	hdr->e_shoff = 0;
 	hdr->e_shentsize = 0;
 	hdr->e_shnum = 0;
-	hdr->e_shstrndx = htole16(SHN_UNDEF);
+	hdr->e_shstrndx = SHN_UNDEF; /* SHN_UNDEF == 0 */
 
 	if (!name) {
 		fwrite(addr, load_size, 1, outfile);
Signature · 1 line
1.9.3
#21 lore raw

Re: [tip:x86/vdso] x86, vdso: Use <tools/le_byteshift.h> for littleendian access

Quoted 22 lines · H. Peter Anvin
Quoted 11 lines · Andrew Morton
Quoted 8 lines · On Fri, 6 Jun 2014 15:00:29 -0700 "tip-bot for H. Peter Anvin"…
Commit-ID:  bdfb9bcc25005d06a9c301830bdeb7ca5a0b6ef7
Gitweb:     http://git.kernel.org/tip/bdfb9bcc25005d06a9c301830bdeb7ca5a0b6ef7
Author:     H. Peter Anvin <[email protected]>
AuthorDate: Fri, 6 Jun 2014 14:30:37 -0700
Committer:  H. Peter Anvin <[email protected]>
CommitDate: Fri, 6 Jun 2014 14:54:54 -0700

x86, vdso: Use <tools/le_byteshift.h> for littleendian access

Quoted 9 lines

Getting closer.

In file included from arch/x86/vdso/vdso2c.c:80:
arch/x86/vdso/vdso2c.h: In function 'go64':
arch/x86/vdso/vdso2c.h:119: warning: implicit declaration of function 'htole16' /tmp/cc04m2KE.o: In function `go':
vdso2c.c:(.text+0xf69): undefined reference to htole16' vdso2c.c:(.text+0x12e6): undefined reference to htole16'

Quoted 2 lines

Want to test this patch before I commit it?

Nice :) I guess I was a bit unnecessarily zealous in the endian conversion stuff.

--Andy

maintainer
#22 lore raw

Re: [tip:x86/vdso] x86, vdso: Use <tools/le_byteshift.h> for littleendian access

In reply to H. Peter Anvin
Quoted 9 lines · On Tue, 10 Jun 2014 14:28:37 -0700 "H. Peter Anvin" <[email protected]> wrote:

Want to test this patch before I commit it?

...

Quoted 1 line

From 15ea1a528e08c6bc322f10686ec8d73ba413b941 Mon Sep 17 00:00:00 2001

From: "H. Peter Anvin" <[email protected]>
Date: Tue, 10 Jun 2014 14:25:26 -0700
Subject: [PATCH] x86, vdso: Remove one final use of htole16()

Quoted 6 lines

One final use of the macros from <endian.h> which are not available on older system. In this case we had one sole case of *writing* a littleendian number, but the number is SHN_UNDEF which is the constant zero, so rather than dealing with the general case of littleendian puts here, just document that the constant is zero and be done with it.

Compiles and boots, thanks.

#23 lore raw

[tip:x86/vdso] x86, vdso: Remove one final use of htole16()

In reply to Andrew Morton
x86, vdso: Remove one final use of htole16()
Commit-ID:  15ea1a528e08c6bc322f10686ec8d73ba413b941
Gitweb:     http://git.kernel.org/tip/15ea1a528e08c6bc322f10686ec8d73ba413b941
Author:     H. Peter Anvin <[email protected]>
AuthorDate: Tue, 10 Jun 2014 14:25:26 -0700
Committer:  H. Peter Anvin <[email protected]>
CommitDate: Tue, 10 Jun 2014 14:25:26 -0700

x86, vdso: Remove one final use of htole16()

One final use of the macros from <endian.h> which are not available on older system. In this case we had one sole case of *writing* a littleendian number, but the number is SHN_UNDEF which is the constant zero, so rather than dealing with the general case of littleendian puts here, just document that the constant is zero and be done with it.

---
 arch/x86/vdso/vdso2c.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/vdso/vdso2c.h +1 -1
index 8a07463..d9f6f61 100644
@@ -116,7 +116,7 @@ static void GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
 	hdr->e_shoff = 0;
 	hdr->e_shentsize = 0;
 	hdr->e_shnum = 0;
-	hdr->e_shstrndx = htole16(SHN_UNDEF);
+	hdr->e_shstrndx = SHN_UNDEF; /* SHN_UNDEF == 0 */
 
 	if (!name) {
 		fwrite(addr, load_size, 1, outfile);
#24 lore raw

[tip:x86/vdso] x86, vdso: Remove one final use of htole16()

In reply to Andrew Morton
x86, vdso: Remove one final use of htole16()
Commit-ID:  4d048b0255e3dd4fb001c5f1f609fb67463d04d6
Gitweb:     http://git.kernel.org/tip/4d048b0255e3dd4fb001c5f1f609fb67463d04d6
Author:     H. Peter Anvin <[email protected]>
AuthorDate: Tue, 10 Jun 2014 14:25:26 -0700
Committer:  H. Peter Anvin <[email protected]>
CommitDate: Tue, 10 Jun 2014 15:55:05 -0700

x86, vdso: Remove one final use of htole16()

One final use of the macros from <endian.h> which are not available on older system. In this case we had one sole case of *writing* a littleendian number, but the number is SHN_UNDEF which is the constant zero, so rather than dealing with the general case of littleendian puts here, just document that the constant is zero and be done with it.

---
 arch/x86/vdso/vdso2c.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/vdso/vdso2c.h +1 -1
index 8a07463..d9f6f61 100644
@@ -116,7 +116,7 @@ static void GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
 	hdr->e_shoff = 0;
 	hdr->e_shentsize = 0;
 	hdr->e_shnum = 0;
-	hdr->e_shstrndx = htole16(SHN_UNDEF);
+	hdr->e_shstrndx = SHN_UNDEF; /* SHN_UNDEF == 0 */
 
 	if (!name) {
 		fwrite(addr, load_size, 1, outfile);