Merge tag 'sched-urgent-2020-12-27' of git://git.kernel.org/pub/scm/linux/kernel...
[linux/fpc-iii.git] / arch / x86 / mm / maccess.c
blob92ec176a729375b993d8c3a2393c7b1489f1b5cd
1 // SPDX-License-Identifier: GPL-2.0-only
3 #include <linux/uaccess.h>
4 #include <linux/kernel.h>
6 #ifdef CONFIG_X86_64
7 static __always_inline u64 canonical_address(u64 vaddr, u8 vaddr_bits)
9 return ((s64)vaddr << (64 - vaddr_bits)) >> (64 - vaddr_bits);
12 bool copy_from_kernel_nofault_allowed(const void *unsafe_src, size_t size)
14 unsigned long vaddr = (unsigned long)unsafe_src;
17 * Range covering the highest possible canonical userspace address
18 * as well as non-canonical address range. For the canonical range
19 * we also need to include the userspace guard page.
21 return vaddr >= TASK_SIZE_MAX + PAGE_SIZE &&
22 canonical_address(vaddr, boot_cpu_data.x86_virt_bits) == vaddr;
24 #else
25 bool copy_from_kernel_nofault_allowed(const void *unsafe_src, size_t size)
27 return (unsigned long)unsafe_src >= TASK_SIZE_MAX;
29 #endif