drm/modes: Fix drm_mode_vrefres() docs
[drm/drm-misc.git] / arch / x86 / mm / maccess.c
blob42115ac079cfe617b76199a167c61e5b3c7de10f
1 // SPDX-License-Identifier: GPL-2.0-only
3 #include <linux/uaccess.h>
4 #include <linux/kernel.h>
6 #include <asm/vsyscall.h>
8 #ifdef CONFIG_X86_64
9 bool copy_from_kernel_nofault_allowed(const void *unsafe_src, size_t size)
11 unsigned long vaddr = (unsigned long)unsafe_src;
14 * Do not allow userspace addresses. This disallows
15 * normal userspace and the userspace guard page:
17 if (vaddr < TASK_SIZE_MAX + PAGE_SIZE)
18 return false;
21 * Reading from the vsyscall page may cause an unhandled fault in
22 * certain cases. Though it is at an address above TASK_SIZE_MAX, it is
23 * usually considered as a user space address.
25 if (is_vsyscall_vaddr(vaddr))
26 return false;
29 * Allow everything during early boot before 'x86_virt_bits'
30 * is initialized. Needed for instruction decoding in early
31 * exception handlers.
33 if (!boot_cpu_data.x86_virt_bits)
34 return true;
36 return __is_canonical_address(vaddr, boot_cpu_data.x86_virt_bits);
38 #else
39 bool copy_from_kernel_nofault_allowed(const void *unsafe_src, size_t size)
41 return (unsigned long)unsafe_src >= TASK_SIZE_MAX;
43 #endif