Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) #include <linux/binfmts.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/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <asm/vdso.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <asm/cacheflush.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) static struct page *vdso_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) static int __init init_vdso(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) 	struct csky_vdso *vdso;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 	vdso_page = alloc_page(GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 	if (!vdso_page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 		panic("Cannot allocate vdso");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 	vdso = vmap(&vdso_page, 1, 0, PAGE_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 	if (!vdso)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 		panic("Cannot map vdso");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 	clear_page(vdso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 	err = setup_vdso_page(vdso->rt_signal_retcode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 		panic("Cannot set signal return code, err: %x.", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 	dcache_wb_range((unsigned long)vdso, (unsigned long)vdso + 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 	vunmap(vdso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) subsys_initcall(init_vdso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 	unsigned long addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 	struct mm_struct *mm = current->mm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 	mmap_write_lock(mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 	addr = get_unmapped_area(NULL, STACK_TOP, PAGE_SIZE, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 	if (IS_ERR_VALUE(addr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 		ret = addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 		goto up_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 	ret = install_special_mapping(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 			mm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 			addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 			PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 			VM_READ|VM_EXEC|VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 			&vdso_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 		goto up_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 	mm->context.vdso = (void *)addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) up_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) 	mmap_write_unlock(mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) const char *arch_vma_name(struct vm_area_struct *vma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) 	if (vma->vm_mm == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) 	if (vma->vm_start == (long)vma->vm_mm->context.vdso)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) 		return "[vdso]";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }