David Daney | c52d0d3 | 2010-02-18 16:13:04 -0800 | [diff] [blame] | 1 | /* |
Alex Smith | ebb5e78 | 2015-10-21 09:54:38 +0100 | [diff] [blame^] | 2 | * Copyright (C) 2015 Imagination Technologies |
| 3 | * Author: Alex Smith <alex.smith@imgtec.com> |
David Daney | c52d0d3 | 2010-02-18 16:13:04 -0800 | [diff] [blame] | 4 | * |
Alex Smith | ebb5e78 | 2015-10-21 09:54:38 +0100 | [diff] [blame^] | 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License as published by the |
| 7 | * Free Software Foundation; either version 2 of the License, or (at your |
| 8 | * option) any later version. |
David Daney | c52d0d3 | 2010-02-18 16:13:04 -0800 | [diff] [blame] | 9 | */ |
| 10 | |
David Daney | c52d0d3 | 2010-02-18 16:13:04 -0800 | [diff] [blame] | 11 | #include <linux/binfmts.h> |
| 12 | #include <linux/elf.h> |
Alex Smith | ebb5e78 | 2015-10-21 09:54:38 +0100 | [diff] [blame^] | 13 | #include <linux/err.h> |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/mm.h> |
| 16 | #include <linux/sched.h> |
| 17 | #include <linux/slab.h> |
David Daney | c52d0d3 | 2010-02-18 16:13:04 -0800 | [diff] [blame] | 18 | |
Alex Smith | ebb5e78 | 2015-10-21 09:54:38 +0100 | [diff] [blame^] | 19 | #include <asm/abi.h> |
David Daney | c52d0d3 | 2010-02-18 16:13:04 -0800 | [diff] [blame] | 20 | #include <asm/vdso.h> |
Alex Smith | ebb5e78 | 2015-10-21 09:54:38 +0100 | [diff] [blame^] | 21 | |
| 22 | /* Kernel-provided data used by the VDSO. */ |
| 23 | static union mips_vdso_data vdso_data __page_aligned_data; |
David Daney | c52d0d3 | 2010-02-18 16:13:04 -0800 | [diff] [blame] | 24 | |
| 25 | /* |
Alex Smith | ebb5e78 | 2015-10-21 09:54:38 +0100 | [diff] [blame^] | 26 | * Mapping for the VDSO data pages. The real pages are mapped manually, as |
| 27 | * what we map and where within the area they are mapped is determined at |
| 28 | * runtime. |
David Daney | c52d0d3 | 2010-02-18 16:13:04 -0800 | [diff] [blame] | 29 | */ |
Alex Smith | ebb5e78 | 2015-10-21 09:54:38 +0100 | [diff] [blame^] | 30 | static struct page *no_pages[] = { NULL }; |
| 31 | static struct vm_special_mapping vdso_vvar_mapping = { |
| 32 | .name = "[vvar]", |
| 33 | .pages = no_pages, |
| 34 | }; |
David Daney | c52d0d3 | 2010-02-18 16:13:04 -0800 | [diff] [blame] | 35 | |
Alex Smith | ebb5e78 | 2015-10-21 09:54:38 +0100 | [diff] [blame^] | 36 | static void __init init_vdso_image(struct mips_vdso_image *image) |
David Daney | c52d0d3 | 2010-02-18 16:13:04 -0800 | [diff] [blame] | 37 | { |
Alex Smith | ebb5e78 | 2015-10-21 09:54:38 +0100 | [diff] [blame^] | 38 | unsigned long num_pages, i; |
| 39 | |
| 40 | BUG_ON(!PAGE_ALIGNED(image->data)); |
| 41 | BUG_ON(!PAGE_ALIGNED(image->size)); |
| 42 | |
| 43 | num_pages = image->size / PAGE_SIZE; |
| 44 | |
| 45 | for (i = 0; i < num_pages; i++) { |
| 46 | image->mapping.pages[i] = |
| 47 | virt_to_page(image->data + (i * PAGE_SIZE)); |
| 48 | } |
David Daney | c52d0d3 | 2010-02-18 16:13:04 -0800 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | static int __init init_vdso(void) |
| 52 | { |
Alex Smith | ebb5e78 | 2015-10-21 09:54:38 +0100 | [diff] [blame^] | 53 | init_vdso_image(&vdso_image); |
David Daney | c52d0d3 | 2010-02-18 16:13:04 -0800 | [diff] [blame] | 54 | |
Alex Smith | ebb5e78 | 2015-10-21 09:54:38 +0100 | [diff] [blame^] | 55 | #ifdef CONFIG_MIPS32_O32 |
| 56 | init_vdso_image(&vdso_image_o32); |
David Daney | c52d0d3 | 2010-02-18 16:13:04 -0800 | [diff] [blame] | 57 | #endif |
| 58 | |
Alex Smith | ebb5e78 | 2015-10-21 09:54:38 +0100 | [diff] [blame^] | 59 | #ifdef CONFIG_MIPS32_N32 |
| 60 | init_vdso_image(&vdso_image_n32); |
| 61 | #endif |
David Daney | c52d0d3 | 2010-02-18 16:13:04 -0800 | [diff] [blame] | 62 | |
David Daney | c52d0d3 | 2010-02-18 16:13:04 -0800 | [diff] [blame] | 63 | return 0; |
| 64 | } |
David Daney | 1ed8453 | 2010-06-16 15:00:28 -0700 | [diff] [blame] | 65 | subsys_initcall(init_vdso); |
David Daney | c52d0d3 | 2010-02-18 16:13:04 -0800 | [diff] [blame] | 66 | |
David Daney | c52d0d3 | 2010-02-18 16:13:04 -0800 | [diff] [blame] | 67 | int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) |
| 68 | { |
Alex Smith | ebb5e78 | 2015-10-21 09:54:38 +0100 | [diff] [blame^] | 69 | struct mips_vdso_image *image = current->thread.abi->vdso; |
David Daney | c52d0d3 | 2010-02-18 16:13:04 -0800 | [diff] [blame] | 70 | struct mm_struct *mm = current->mm; |
Alex Smith | ebb5e78 | 2015-10-21 09:54:38 +0100 | [diff] [blame^] | 71 | unsigned long base, vdso_addr; |
| 72 | struct vm_area_struct *vma; |
| 73 | int ret; |
David Daney | c52d0d3 | 2010-02-18 16:13:04 -0800 | [diff] [blame] | 74 | |
| 75 | down_write(&mm->mmap_sem); |
| 76 | |
Alex Smith | ebb5e78 | 2015-10-21 09:54:38 +0100 | [diff] [blame^] | 77 | base = get_unmapped_area(NULL, 0, PAGE_SIZE + image->size, 0, 0); |
| 78 | if (IS_ERR_VALUE(base)) { |
| 79 | ret = base; |
| 80 | goto out; |
David Daney | c52d0d3 | 2010-02-18 16:13:04 -0800 | [diff] [blame] | 81 | } |
| 82 | |
Alex Smith | ebb5e78 | 2015-10-21 09:54:38 +0100 | [diff] [blame^] | 83 | vdso_addr = base + PAGE_SIZE; |
David Daney | c52d0d3 | 2010-02-18 16:13:04 -0800 | [diff] [blame] | 84 | |
Alex Smith | ebb5e78 | 2015-10-21 09:54:38 +0100 | [diff] [blame^] | 85 | vma = _install_special_mapping(mm, base, PAGE_SIZE, |
| 86 | VM_READ | VM_MAYREAD, |
| 87 | &vdso_vvar_mapping); |
| 88 | if (IS_ERR(vma)) { |
| 89 | ret = PTR_ERR(vma); |
| 90 | goto out; |
| 91 | } |
| 92 | |
| 93 | /* Map data page. */ |
| 94 | ret = remap_pfn_range(vma, base, |
| 95 | virt_to_phys(&vdso_data) >> PAGE_SHIFT, |
| 96 | PAGE_SIZE, PAGE_READONLY); |
David Daney | c52d0d3 | 2010-02-18 16:13:04 -0800 | [diff] [blame] | 97 | if (ret) |
Alex Smith | ebb5e78 | 2015-10-21 09:54:38 +0100 | [diff] [blame^] | 98 | goto out; |
David Daney | c52d0d3 | 2010-02-18 16:13:04 -0800 | [diff] [blame] | 99 | |
Alex Smith | ebb5e78 | 2015-10-21 09:54:38 +0100 | [diff] [blame^] | 100 | /* Map VDSO image. */ |
| 101 | vma = _install_special_mapping(mm, vdso_addr, image->size, |
| 102 | VM_READ | VM_EXEC | |
| 103 | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC, |
| 104 | &image->mapping); |
| 105 | if (IS_ERR(vma)) { |
| 106 | ret = PTR_ERR(vma); |
| 107 | goto out; |
| 108 | } |
David Daney | c52d0d3 | 2010-02-18 16:13:04 -0800 | [diff] [blame] | 109 | |
Alex Smith | ebb5e78 | 2015-10-21 09:54:38 +0100 | [diff] [blame^] | 110 | mm->context.vdso = (void *)vdso_addr; |
| 111 | ret = 0; |
| 112 | |
| 113 | out: |
David Daney | c52d0d3 | 2010-02-18 16:13:04 -0800 | [diff] [blame] | 114 | up_write(&mm->mmap_sem); |
| 115 | return ret; |
| 116 | } |