Robert Richter | 1ac2e6c | 2011-06-07 11:49:55 +0200 | [diff] [blame] | 1 | /* |
| 2 | * User address space access functions. |
| 3 | * |
| 4 | * For licencing details see kernel-base/COPYING |
| 5 | */ |
| 6 | |
Al Viro | beba3a2 | 2017-03-25 19:33:21 -0400 | [diff] [blame] | 7 | #include <linux/uaccess.h> |
Paul Gortmaker | e683014 | 2016-07-13 20:18:57 -0400 | [diff] [blame] | 8 | #include <linux/export.h> |
Robert Richter | 1ac2e6c | 2011-06-07 11:49:55 +0200 | [diff] [blame] | 9 | |
Andy Lutomirski | 4012e77 | 2018-08-29 08:47:18 -0700 | [diff] [blame] | 10 | #include <asm/tlbflush.h> |
| 11 | |
Robert Richter | 1ac2e6c | 2011-06-07 11:49:55 +0200 | [diff] [blame] | 12 | /* |
Peter Zijlstra | e00b12e | 2013-10-24 12:52:06 +0200 | [diff] [blame] | 13 | * We rely on the nested NMI work to allow atomic faults from the NMI path; the |
| 14 | * nested NMI paths are careful to preserve CR2. |
Robert Richter | 1ac2e6c | 2011-06-07 11:49:55 +0200 | [diff] [blame] | 15 | */ |
| 16 | unsigned long |
| 17 | copy_from_user_nmi(void *to, const void __user *from, unsigned long n) |
| 18 | { |
Peter Zijlstra | e00b12e | 2013-10-24 12:52:06 +0200 | [diff] [blame] | 19 | unsigned long ret; |
Robert Richter | 1ac2e6c | 2011-06-07 11:49:55 +0200 | [diff] [blame] | 20 | |
Stephane Eranian | 25f4298 | 2012-06-11 15:44:26 +0200 | [diff] [blame] | 21 | if (__range_not_ok(from, n, TASK_SIZE)) |
Yann Droneaud | ebf2d26 | 2015-06-22 21:38:43 +0200 | [diff] [blame] | 22 | return n; |
Arun Sharma | db0dc75 | 2012-04-20 15:41:36 -0700 | [diff] [blame] | 23 | |
Andy Lutomirski | 4012e77 | 2018-08-29 08:47:18 -0700 | [diff] [blame] | 24 | if (!nmi_uaccess_okay()) |
| 25 | return n; |
| 26 | |
Peter Zijlstra | e00b12e | 2013-10-24 12:52:06 +0200 | [diff] [blame] | 27 | /* |
| 28 | * Even though this function is typically called from NMI/IRQ context |
| 29 | * disable pagefaults so that its behaviour is consistent even when |
| 30 | * called form other contexts. |
| 31 | */ |
| 32 | pagefault_disable(); |
| 33 | ret = __copy_from_user_inatomic(to, from, n); |
| 34 | pagefault_enable(); |
Robert Richter | 1ac2e6c | 2011-06-07 11:49:55 +0200 | [diff] [blame] | 35 | |
Peter Zijlstra | 0a19684 | 2013-10-30 21:16:22 +0100 | [diff] [blame] | 36 | return ret; |
Robert Richter | 1ac2e6c | 2011-06-07 11:49:55 +0200 | [diff] [blame] | 37 | } |
| 38 | EXPORT_SYMBOL_GPL(copy_from_user_nmi); |