1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
4 #include <linux/binfmts.h>
8 #include <linux/slab.h>
11 #ifdef GENERIC_TIME_VSYSCALL
12 #include <vdso/datapage.h>
17 extern char vdso_start[], vdso_end[];
19 static unsigned int vdso_pages;
20 static struct page **vdso_pagelist;
26 struct vdso_data data;
28 } vdso_data_store __page_aligned_data;
29 struct vdso_data *vdso_data = &vdso_data_store.data;
31 static int __init vdso_init(void)
35 vdso_pages = (vdso_end - vdso_start) >> PAGE_SHIFT;
37 kcalloc(vdso_pages + 1, sizeof(struct page *), GFP_KERNEL);
38 if (unlikely(vdso_pagelist == NULL)) {
39 pr_err("vdso: pagelist allocation failed\n");
43 for (i = 0; i < vdso_pages; i++) {
46 pg = virt_to_page(vdso_start + (i << PAGE_SHIFT));
47 vdso_pagelist[i] = pg;
49 vdso_pagelist[i] = virt_to_page(vdso_data);
53 arch_initcall(vdso_init);
55 int arch_setup_additional_pages(struct linux_binprm *bprm,
58 struct mm_struct *mm = current->mm;
59 unsigned long vdso_base, vdso_len;
62 vdso_len = (vdso_pages + 1) << PAGE_SHIFT;
65 vdso_base = get_unmapped_area(NULL, 0, vdso_len, 0, 0);
66 if (IS_ERR_VALUE(vdso_base)) {
72 * Put vDSO base into mm struct. We need to do this before calling
73 * install_special_mapping or the perf counter mmap tracking code
74 * will fail to recognise it as a vDSO (since arch_vma_name fails).
76 mm->context.vdso = (void *)vdso_base;
79 install_special_mapping(mm, vdso_base, vdso_pages << PAGE_SHIFT,
80 (VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC),
84 mm->context.vdso = NULL;
88 vdso_base += (vdso_pages << PAGE_SHIFT);
89 ret = install_special_mapping(mm, vdso_base, PAGE_SIZE,
90 (VM_READ | VM_MAYREAD), &vdso_pagelist[vdso_pages]);
93 mm->context.vdso = NULL;
95 mmap_write_unlock(mm);
99 const char *arch_vma_name(struct vm_area_struct *vma)
101 if (vma->vm_mm && (vma->vm_start == (long)vma->vm_mm->context.vdso))
103 if (vma->vm_mm && (vma->vm_start ==
104 (long)vma->vm_mm->context.vdso + PAGE_SIZE))
105 return "[vdso_data]";