blob: 3f435d7fca5e62bc999e48c6a4f3e1c0fc86def9 [file] [log] [blame]
Robert Richter1ac2e6c2011-06-07 11:49:55 +02001/*
2 * User address space access functions.
3 *
4 * For licencing details see kernel-base/COPYING
5 */
6
Al Virobeba3a22017-03-25 19:33:21 -04007#include <linux/uaccess.h>
Paul Gortmakere6830142016-07-13 20:18:57 -04008#include <linux/export.h>
Robert Richter1ac2e6c2011-06-07 11:49:55 +02009
Andy Lutomirski4012e772018-08-29 08:47:18 -070010#include <asm/tlbflush.h>
11
Robert Richter1ac2e6c2011-06-07 11:49:55 +020012/*
Peter Zijlstrae00b12e2013-10-24 12:52:06 +020013 * 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 Richter1ac2e6c2011-06-07 11:49:55 +020015 */
16unsigned long
17copy_from_user_nmi(void *to, const void __user *from, unsigned long n)
18{
Peter Zijlstrae00b12e2013-10-24 12:52:06 +020019 unsigned long ret;
Robert Richter1ac2e6c2011-06-07 11:49:55 +020020
Stephane Eranian25f42982012-06-11 15:44:26 +020021 if (__range_not_ok(from, n, TASK_SIZE))
Yann Droneaudebf2d262015-06-22 21:38:43 +020022 return n;
Arun Sharmadb0dc752012-04-20 15:41:36 -070023
Andy Lutomirski4012e772018-08-29 08:47:18 -070024 if (!nmi_uaccess_okay())
25 return n;
26
Peter Zijlstrae00b12e2013-10-24 12:52:06 +020027 /*
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 Richter1ac2e6c2011-06-07 11:49:55 +020035
Peter Zijlstra0a196842013-10-30 21:16:22 +010036 return ret;
Robert Richter1ac2e6c2011-06-07 11:49:55 +020037}
38EXPORT_SYMBOL_GPL(copy_from_user_nmi);