1 From 1ba9968246337836bf0acdbf7733a628da5c5e42 Mon Sep 17 00:00:00 2001
2 From: Alison Wang <b18965@freescale.com>
3 Date: Thu, 4 Aug 2011 09:59:42 +0800
4 Subject: [PATCH 12/52] Add vDSO support for Coldfire platform
6 This patch adds vDSO support for Coldfire platform.
8 Signed-off-by: Alison Wang <b18965@freescale.com>
10 arch/m68k/coldfire/common/entry.S | 36 ++++++++++
11 arch/m68k/coldfire/vdso/Makefile | 46 +++++++++++++
12 arch/m68k/coldfire/vdso/vdso-bin.S | 14 ++++
13 arch/m68k/coldfire/vdso/vdso-lib.S | 57 ++++++++++++++++
14 arch/m68k/coldfire/vdso/vdso-note.S | 27 ++++++++
15 arch/m68k/coldfire/vdso/vdso.c | 124 +++++++++++++++++++++++++++++++++++
16 arch/m68k/coldfire/vdso/vdso.lds.S | 89 +++++++++++++++++++++++++
17 arch/m68k/include/asm/auxvec.h | 9 +++
18 arch/m68k/mm/init.c | 3 +
19 9 files changed, 405 insertions(+), 0 deletions(-)
20 create mode 100644 arch/m68k/coldfire/vdso/Makefile
21 create mode 100644 arch/m68k/coldfire/vdso/vdso-bin.S
22 create mode 100644 arch/m68k/coldfire/vdso/vdso-lib.S
23 create mode 100644 arch/m68k/coldfire/vdso/vdso-note.S
24 create mode 100644 arch/m68k/coldfire/vdso/vdso.c
25 create mode 100644 arch/m68k/coldfire/vdso/vdso.lds.S
27 --- a/arch/m68k/coldfire/common/entry.S
28 +++ b/arch/m68k/coldfire/common/entry.S
29 @@ -69,6 +69,9 @@ ENTRY(buserr)
30 movew #0x2700,%sr /* lock interrupts */
34 + jsr check_vdso_atomic_cmpxchg_32
36 #ifdef CONFIG_COLDFIRE_FOO
37 movew PT_0FF_SR(%sp),%d3 /* get original %sr */
38 oril #0x2000,%d3 /* set supervisor mode in it */
39 @@ -82,6 +85,9 @@ ENTRY(buserr)
44 + jsr check_vdso_atomic_cmpxchg_32
47 movel %sp,%sp@- /* stack frame pointer argument */
49 @@ -213,6 +219,9 @@ do_delayed_trace:
54 + jsr check_vdso_atomic_cmpxchg_32
57 movel %curptr@(TASK_INFO+TINFO_PREEMPT),%d0
59 @@ -398,8 +407,35 @@ resume:
60 movew %a1@(TASK_THREAD+THREAD_SR),%d0
64 + /* save thread pointer */
67 + movel %a1@(TASK_INFO+TINFO_TP_VALUE),(%a0)
72 +/* if interrupted PC is between 0x5fffe40c to 0x5ffffe412 */
73 +/* then set PC back to 0x5fffe40c (start addr of __kernel_atomic_cmpxchg_32) */
74 +/* note: these absolute addresses depend on vdso-lib.S and vdso.lds.S */
75 +ENTRY(check_vdso_atomic_cmpxchg_32)
76 + movel %sp@(PT_OFF_PC),%d0
77 + cmpil #0x5fffe414,%d0 /* __kernel_atomic_cmpxchg_32: line 4 */
79 + cmpil #0x5fffe412,%d0 /* __kernel_atomic_cmpxchg_32: line 3 */
81 + cmpil #0x5fffe40e,%d0 /* __kernel_atomic_cmpxchg_32: line 2 */
85 + /* __kernel_atomic_cmpxchg_32: line 1 */
86 + movel #0x5fffe40c,%d0
87 + movel %d0,%sp@(PT_OFF_PC)
96 +++ b/arch/m68k/coldfire/vdso/Makefile
99 +# Makefile for arch/m68k/coldfire/vdso with special rules
100 +# for building the DSO lib
102 +# Based on arch/sh/kernel/vsyscall/Makefile
104 +# Kurt Mahan <kmahan@freescale.com>
107 +obj-y := vdso.o vdso-bin.o
109 +$(obj)/vdso-bin.o: $(obj)/vdso.lds $(obj)/vdso-lib.so
115 +# special linker script for building DSO images
116 +quiet_cmd_vdso = VDSO $@
117 + cmd_vdso = $(LD) -nostdlib --eh-frame-hdr $(SYSCFLAGS_$(@F)) \
118 + -T $(obj)/vdso.lds $^ -o $@
120 +vdso-flags = -shared -s -soname=linux-gate.so.1
122 +SYSCFLAGS_vdso-lib.so = $(vdso-flags)
124 +$(obj)/vdso-lib.so: $(obj)/vdso-lib.o $(obj)/vdso-note.o
125 + $(call if_changed,vdso)
127 +$(obj)/vdso.lds: $(srctree)/arch/m68k/coldfire/vdso/vdso.lds.S
131 +# Create a special relocatable object that should mirror the
132 +# symbol table and layout of the linked DSO lib. With ld -R
133 +# these symbols can be refered to in the kernel code rather
134 +# than as hand-coded addresses
136 +# extra-y += vdso-syms.o
137 +# $(obj)/built-in.o: $(obj)/vdso-syms.o
138 +# $(obj)/built-in.o: ld_flags += -R (obj)/vdso-syms.o
140 +# SYSCFLAGS_vdso-syms.o = -r
141 +# $(obj)/vdso-syms.o: $(src)/vdso.lds \
142 +# $(obj)/vdso-lib.o $(obj)/vdso-note.o FORCE
143 +# $(call if_changed,vdso)
145 +++ b/arch/m68k/coldfire/vdso/vdso-bin.S
148 + * Setup vdso lib (.so) as binary image.
151 +#include <linux/init.h>
155 + .globl vdso_bin_start, vdso_bin_end
157 + .incbin "arch/m68k/coldfire/vdso/vdso-lib.so"
162 +++ b/arch/m68k/coldfire/vdso/vdso-lib.S
165 + * VDSO userspace code
167 + * Copyright (C) 2008-2011 Freescale Semiconductor, Inc. All Rights Reserved.
168 + * Kurt Mahan <kmahan@freescale.com>
170 + * This is free software; you can redistribute it and/or modify
171 + * it under the terms of the GNU General Public License as published by
172 + * the Free Software Foundation; either version 2 of the License, or
173 + * (at your option) any later version.
176 +#include <linux/linkage.h>
177 +#include <asm/unistd.h>
181 + * Read the thread pointer into A0 (and D0, for compatibility).
183 +ENTRY(__kernel_read_tp)
185 + lea kuser_vdso_tp,%a0
190 + .size __kernel_read_tp,.-__kernel_read_tp
193 + * Atomic compare exchange. Can not clobber any registers
194 + * other than conditional codes.
196 +ENTRY(__kernel_atomic_cmpxchg_32)
207 + .size __kernel_atomic_cmpxchg_32,.-__kernel_atomic_cmpxchg_32
210 + * Atomic memory barrier. Can not clobber any registers
211 + * other than condition codes.
213 +ENTRY(__kernel_atomic_barrier)
215 + /* no code needed for uniprocs */
218 + .size __kernel_atomic_barrier,.-__kernel_atomic_barrier
222 +++ b/arch/m68k/coldfire/vdso/vdso-note.S
225 + * This supplies .note.* sections to go into the PT_NOTE inside the vDSO text.
226 + * Here we can supply some information useful to userland.
228 + * Based on arch/sh/kernel/vsyscall/vsyscall-note.S
231 +#include <linux/uts.h>
232 +#include <linux/version.h>
234 +#define ASM_ELF_NOTE_BEGIN(name, flags, vendor, type) \
235 + .section name, flags; \
237 + .long 1f - 0f; /* name length */ \
238 + .long 3f - 2f; /* data length */ \
239 + .long type; /* note type */ \
240 +0: .asciz vendor; /* vendor name */ \
244 +#define ASM_ELF_NOTE_END \
245 +3: .balign 4; /* pad out section */ \
248 + ASM_ELF_NOTE_BEGIN(".note.kernel-version", "a", UTS_SYSNAME, 0)
249 + .long LINUX_VERSION_CODE
252 +++ b/arch/m68k/coldfire/vdso/vdso.c
255 + * arch/m68k/coldfire/vdso/vdso.c
257 + * Based on arch/sh/kernel/vsyscall/vsyscall.c
259 + * Copyright (C) 2008-2011 Freescale Semiconductor, Inc. All Rights Reserved.
260 + * Kurt Mahan <kmahan@freescale.com>
262 + * This is free software; you can redistribute it and/or modify
263 + * it under the terms of the GNU General Public License as published by
264 + * the Free Software Foundation; either version 2 of the License, or
265 + * (at your option) any later version.
268 +#include <linux/mm.h>
269 +#include <linux/slab.h>
270 +#include <linux/kernel.h>
271 +#include <linux/init.h>
272 +#include <linux/gfp.h>
273 +#include <linux/module.h>
274 +#include <linux/elf.h>
275 +#include <linux/sched.h>
276 +#include <linux/err.h>
278 +/* Mapping vDSO at the default address (what would've been returned
279 + * if VDSO_MBASE was 0) makes it impossible to extend data segment
280 + * (through brk()) for static binaries. The vDSO fits into one page,
281 + * so map it just before TASK_UNMAPPED_BASE.
283 +#define VDSO_MBASE (TASK_UNMAPPED_BASE - PAGE_SIZE)
284 +#define VDSO_VAR_OFFSET 4096
286 +unsigned int vdso_enabled = 1;
287 +EXPORT_SYMBOL_GPL(vdso_enabled);
289 +static struct page *vdso_pages[1];
291 +/* _vdso_var_start: vdso_page_start + offset_4K */
292 +/* it's used to save key values from kernel */
293 +void *_vdso_var_start;
296 +extern const char vdso_bin_start, vdso_bin_end;
298 +int __init vdso_init(void)
300 + void *vdso_page = (void *)get_zeroed_page(GFP_ATOMIC);
301 + vdso_pages[0] = virt_to_page(vdso_page);
303 + _vdso_var_start = (void *)(vdso_page + VDSO_VAR_OFFSET);
304 + _vdso_tp = _vdso_var_start;
306 + printk(KERN_INFO "** VDSO_INIT\n");
308 + /* copy dso bin in */
310 + &vdso_bin_start, &vdso_bin_end - &vdso_bin_start);
315 +/* setup VMA at program startup for the vdso page */
316 +int arch_setup_additional_pages(struct linux_binprm *bprm,
317 + int executable_stack)
319 + struct mm_struct *mm = current->mm;
320 + unsigned long addr;
323 + current->mm->context.vdso = 0;
325 + down_write(&mm->mmap_sem);
326 + addr = get_unmapped_area(NULL, VDSO_MBASE, PAGE_SIZE, 0, 0);
327 + if (IS_ERR_VALUE(addr)) {
332 + ret = install_special_mapping(mm, addr, PAGE_SIZE,
333 + VM_READ | VM_EXEC |
334 + VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC |
341 + current->mm->context.vdso = (void *)addr;
345 + printk(KERN_DEBUG "arch_setup_additional_pages: addr: %lx; ret: %d\n",
349 + up_write(&mm->mmap_sem);
356 +const char *arch_vma_name(struct vm_area_struct *vma)
358 + if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
364 +struct vm_area_struct *get_gate_vma(struct task_struct *task)
369 +int in_gate_area(struct task_struct *task, unsigned long address)
374 +int in_gate_area_no_task(unsigned long address)
379 +++ b/arch/m68k/coldfire/vdso/vdso.lds.S
382 + * Linker script for vdso DSO. The vdso page is an ELF shared
383 + * object prelinked to its virtual address, and with only one read-only
384 + * segment (that fits in one page). This script controls its layout.
386 + * Based on arch/sh/kernel/vsyscall/vsyscall.lds.S
388 + * Copyright (C) 2008-2011 Freescale Semiconductor, Inc. All Rights Reserved.
389 + * Kurt Mahan <kmahan@freescale.com>
391 + * This is free software; you can redistribute it and/or modify
392 + * it under the terms of the GNU General Public License as published by
393 + * the Free Software Foundation; either version 2 of the License, or
394 + * (at your option) any later version.
397 +OUTPUT_FORMAT("elf32-m68k", "elf32-m68k", "elf32-m68k")
400 +/* The ELF entry point can be used to set the AT_SYSINFO value. */
401 +ENTRY(__kernel_read_tp);
402 +ENTRY(__kernel_atomic_cmpxchg_32);
403 +ENTRY(__kernel_atomic_barrier);
407 + . = 0x5fffe000 + SIZEOF_HEADERS;
409 + .hash : { *(.hash) } :text
410 + .gnu.hash : { *(.gnu.hash) }
411 + .dynsym : { *(.dynsym) }
412 + .dynstr : { *(.dynstr) }
413 + .gnu.version : { *(.gnu.version) }
414 + .gnu.version_d : { *(.gnu.version_d) }
415 + .gnu.version_r : { *(.gnu.version_r) }
418 + * This linker script is used both with -r and with -shared.
419 + * For the layouts to match, we need to skip more than enough
420 + * space for the dynamic symbol table et al. If this amount
421 + * is insufficient, ld -shared will barf. Just increase it here.
423 + . = 0x5fffe000 + 0x400;
425 + .text : { *(.text) } :text
426 + .note : { *(.note.*) } :text :note
427 + .eh_frame_hdr : { *(.eh_frame_hdr ) } :text :eh_frame_hdr
429 + KEEP (*(.eh_frame))
432 + .dynamic : { *(.dynamic) } :text :dynamic
434 + *(.got.plt) *(.got)
435 + *(.data .data.* .gnu.linkonce.d.*)
437 + *(.bss .bss.* .gnu.linkonce.b.*)
440 + . = 0x5fffe000 + 0x1000;
445 + * We must supply the ELF program headers explicitly to get just one
446 + * PT_LOAD segment, and set the flags explicitly to make segments read-only.
450 + text PT_LOAD FILEHDR PHDRS FLAGS(5); /* PF_R|PF_X */
451 + dynamic PT_DYNAMIC FLAGS(4); /* PF_R */
452 + note PT_NOTE FLAGS(4); /* PF_R */
453 + eh_frame_hdr PT_GNU_EH_FRAME;
457 + * This controls what symbols we export from the DSO.
464 + __kernel_atomic_cmpxchg_32;
465 + __kernel_atomic_barrier;
470 --- a/arch/m68k/include/asm/auxvec.h
471 +++ b/arch/m68k/include/asm/auxvec.h
473 #ifndef __ASMm68k_AUXVEC_H
474 #define __ASMm68k_AUXVEC_H
476 + * Architecture-neutral AT_ values in 0-17, leave some room
477 + * for more of them.
481 +/* Entry point to the vdso page */
482 +#define AT_SYSINFO_EHDR 33
486 --- a/arch/m68k/mm/init.c
487 +++ b/arch/m68k/mm/init.c
489 #include <asm/sections.h>
493 +int vdso_init(void);
496 DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);