^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Adapted from arm64 version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2012 ARM Limited
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2015 Mentor Graphics Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/cache.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/elf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/printk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/timekeeper_internal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <asm/arch_timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <asm/barrier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <asm/cacheflush.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <asm/page.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <asm/vdso.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <asm/vdso_datapage.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <clocksource/arm_arch_timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <vdso/helpers.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <vdso/vsyscall.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define MAX_SYMNAME 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) static struct page **vdso_text_pagelist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) extern char vdso_start[], vdso_end[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /* Total number of pages needed for the data and text portions of the VDSO. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) unsigned int vdso_total_pages __ro_after_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * The VDSO data page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) static union vdso_data_store vdso_data_store __page_aligned_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct vdso_data *vdso_data = vdso_data_store.data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static struct page *vdso_data_page __ro_after_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static const struct vm_special_mapping vdso_data_mapping = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) .name = "[vvar]",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) .pages = &vdso_data_page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static int vdso_mremap(const struct vm_special_mapping *sm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct vm_area_struct *new_vma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) unsigned long new_size = new_vma->vm_end - new_vma->vm_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) unsigned long vdso_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) /* without VVAR page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) vdso_size = (vdso_total_pages - 1) << PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) if (vdso_size != new_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) current->mm->context.vdso = new_vma->vm_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static struct vm_special_mapping vdso_text_mapping __ro_after_init = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) .name = "[vdso]",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) .mremap = vdso_mremap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct elfinfo {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) Elf32_Ehdr *hdr; /* ptr to ELF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) Elf32_Sym *dynsym; /* ptr to .dynsym section */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) unsigned long dynsymsize; /* size of .dynsym section */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) char *dynstr; /* ptr to .dynstr section */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) /* Cached result of boot-time check for whether the arch timer exists,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * and if so, whether the virtual counter is useable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) bool cntvct_ok __ro_after_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) static bool __init cntvct_functional(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) bool ret = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if (!IS_ENABLED(CONFIG_ARM_ARCH_TIMER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) /* The arm_arch_timer core should export
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * arch_timer_use_virtual or similar so we don't have to do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) np = of_find_compatible_node(NULL, NULL, "arm,armv7-timer");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) if (!np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) np = of_find_compatible_node(NULL, NULL, "arm,armv8-timer");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) if (!np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) goto out_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) if (of_property_read_bool(np, "arm,cpu-registers-not-fw-configured"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) goto out_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) ret = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) out_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static void * __init find_section(Elf32_Ehdr *ehdr, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) unsigned long *size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) Elf32_Shdr *sechdrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) char *secnames;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) /* Grab section headers and strings so we can tell who is who */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) sechdrs = (void *)ehdr + ehdr->e_shoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) secnames = (void *)ehdr + sechdrs[ehdr->e_shstrndx].sh_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) /* Find the section they want */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) for (i = 1; i < ehdr->e_shnum; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) if (strcmp(secnames + sechdrs[i].sh_name, name) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) if (size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) *size = sechdrs[i].sh_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) return (void *)ehdr + sechdrs[i].sh_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) if (size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) *size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static Elf32_Sym * __init find_symbol(struct elfinfo *lib, const char *symname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) for (i = 0; i < (lib->dynsymsize / sizeof(Elf32_Sym)); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) char name[MAX_SYMNAME], *c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) if (lib->dynsym[i].st_name == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) strlcpy(name, lib->dynstr + lib->dynsym[i].st_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) MAX_SYMNAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) c = strchr(name, '@');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) if (c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) *c = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) if (strcmp(symname, name) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) return &lib->dynsym[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static void __init vdso_nullpatch_one(struct elfinfo *lib, const char *symname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) Elf32_Sym *sym;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) sym = find_symbol(lib, symname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if (!sym)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) sym->st_name = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static void __init patch_vdso(void *ehdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) struct elfinfo einfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) einfo = (struct elfinfo) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) .hdr = ehdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) einfo.dynsym = find_section(einfo.hdr, ".dynsym", &einfo.dynsymsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) einfo.dynstr = find_section(einfo.hdr, ".dynstr", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) /* If the virtual counter is absent or non-functional we don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * want programs to incur the slight additional overhead of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) * dispatching through the VDSO only to fall back to syscalls.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if (!cntvct_ok) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) vdso_nullpatch_one(&einfo, "__vdso_gettimeofday");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) vdso_nullpatch_one(&einfo, "__vdso_clock_gettime");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) vdso_nullpatch_one(&einfo, "__vdso_clock_gettime64");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) static int __init vdso_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) unsigned int text_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (memcmp(vdso_start, "\177ELF", 4)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) pr_err("VDSO is not a valid ELF object!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) return -ENOEXEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) text_pages = (vdso_end - vdso_start) >> PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) /* Allocate the VDSO text pagelist */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) vdso_text_pagelist = kcalloc(text_pages, sizeof(struct page *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) if (vdso_text_pagelist == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) /* Grab the VDSO data page. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) vdso_data_page = virt_to_page(vdso_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) /* Grab the VDSO text pages. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) for (i = 0; i < text_pages; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) page = virt_to_page(vdso_start + i * PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) vdso_text_pagelist[i] = page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) vdso_text_mapping.pages = vdso_text_pagelist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) vdso_total_pages = 1; /* for the data/vvar page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) vdso_total_pages += text_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) cntvct_ok = cntvct_functional();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) patch_vdso(vdso_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) arch_initcall(vdso_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) static int install_vvar(struct mm_struct *mm, unsigned long addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) struct vm_area_struct *vma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) vma = _install_special_mapping(mm, addr, PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) VM_READ | VM_MAYREAD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) &vdso_data_mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) return PTR_ERR_OR_ZERO(vma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) /* assumes mmap_lock is write-locked */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) void arm_install_vdso(struct mm_struct *mm, unsigned long addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) struct vm_area_struct *vma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) unsigned long len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) mm->context.vdso = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) if (vdso_text_pagelist == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if (install_vvar(mm, addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) /* Account for vvar page. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) addr += PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) len = (vdso_total_pages - 1) << PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) vma = _install_special_mapping(mm, addr, len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) &vdso_text_mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) if (!IS_ERR(vma))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) mm->context.vdso = addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)