mm/balloon_compaction: redesign ballooned pages management
[linux-2.6/btrfs-unstable.git] / include / linux / uaccess.h
blobecd3319dac33140a21a7c8fd89a2c95c18ce9e42
1 #ifndef __LINUX_UACCESS_H__
2 #define __LINUX_UACCESS_H__
4 #include <linux/preempt.h>
5 #include <asm/uaccess.h>
7 /*
8 * These routines enable/disable the pagefault handler in that
9 * it will not take any locks and go straight to the fixup table.
11 * They have great resemblance to the preempt_disable/enable calls
12 * and in fact they are identical; this is because currently there is
13 * no other way to make the pagefault handlers do this. So we do
14 * disable preemption but we don't necessarily care about that.
16 static inline void pagefault_disable(void)
18 preempt_count_inc();
20 * make sure to have issued the store before a pagefault
21 * can hit.
23 barrier();
26 static inline void pagefault_enable(void)
28 #ifndef CONFIG_PREEMPT
30 * make sure to issue those last loads/stores before enabling
31 * the pagefault handler again.
33 barrier();
34 preempt_count_dec();
35 #else
36 preempt_enable();
37 #endif
40 #ifndef ARCH_HAS_NOCACHE_UACCESS
42 static inline unsigned long __copy_from_user_inatomic_nocache(void *to,
43 const void __user *from, unsigned long n)
45 return __copy_from_user_inatomic(to, from, n);
48 static inline unsigned long __copy_from_user_nocache(void *to,
49 const void __user *from, unsigned long n)
51 return __copy_from_user(to, from, n);
54 #endif /* ARCH_HAS_NOCACHE_UACCESS */
56 /**
57 * probe_kernel_address(): safely attempt to read from a location
58 * @addr: address to read from - its type is type typeof(retval)*
59 * @retval: read into this variable
61 * Safely read from address @addr into variable @revtal. If a kernel fault
62 * happens, handle that and return -EFAULT.
63 * We ensure that the __get_user() is executed in atomic context so that
64 * do_page_fault() doesn't attempt to take mmap_sem. This makes
65 * probe_kernel_address() suitable for use within regions where the caller
66 * already holds mmap_sem, or other locks which nest inside mmap_sem.
67 * This must be a macro because __get_user() needs to know the types of the
68 * args.
70 * We don't include enough header files to be able to do the set_fs(). We
71 * require that the probe_kernel_address() caller will do that.
73 #define probe_kernel_address(addr, retval) \
74 ({ \
75 long ret; \
76 mm_segment_t old_fs = get_fs(); \
78 set_fs(KERNEL_DS); \
79 pagefault_disable(); \
80 ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
81 pagefault_enable(); \
82 set_fs(old_fs); \
83 ret; \
87 * probe_kernel_read(): safely attempt to read from a location
88 * @dst: pointer to the buffer that shall take the data
89 * @src: address to read from
90 * @size: size of the data chunk
92 * Safely read from address @src to the buffer at @dst. If a kernel fault
93 * happens, handle that and return -EFAULT.
95 extern long probe_kernel_read(void *dst, const void *src, size_t size);
96 extern long __probe_kernel_read(void *dst, const void *src, size_t size);
99 * probe_kernel_write(): safely attempt to write to a location
100 * @dst: address to write to
101 * @src: pointer to the data that shall be written
102 * @size: size of the data chunk
104 * Safely write to address @dst from the buffer at @src. If a kernel fault
105 * happens, handle that and return -EFAULT.
107 extern long notrace probe_kernel_write(void *dst, const void *src, size_t size);
108 extern long notrace __probe_kernel_write(void *dst, const void *src, size_t size);
110 #endif /* __LINUX_UACCESS_H__ */