Merge branch 'akpm'
[linux-2.6/next.git] / arch / x86 / lib / usercopy.c
blob97be9cb54483a05f8c5e9510d563f129ea863966
1 /*
2 * User address space access functions.
4 * For licencing details see kernel-base/COPYING
5 */
7 #include <linux/highmem.h>
8 #include <linux/module.h>
11 * best effort, GUP based copy_from_user() that is NMI-safe
13 unsigned long
14 copy_from_user_nmi(void *to, const void __user *from, unsigned long n)
16 unsigned long offset, addr = (unsigned long)from;
17 unsigned long size, len = 0;
18 struct page *page;
19 void *map;
20 int ret;
22 do {
23 ret = __get_user_pages_fast(addr, 1, 0, &page);
24 if (!ret)
25 break;
27 offset = addr & (PAGE_SIZE - 1);
28 size = min(PAGE_SIZE - offset, n - len);
30 map = kmap_atomic(page);
31 memcpy(to, map+offset, size);
32 kunmap_atomic(map);
33 put_page(page);
35 len += size;
36 to += size;
37 addr += size;
39 } while (len < n);
41 return len;
43 EXPORT_SYMBOL_GPL(copy_from_user_nmi);