/*1* User address space access functions.2*3* For licencing details see kernel-base/COPYING4*/56#include <linux/uaccess.h>7#include <linux/export.h>8#include <linux/instrumented.h>910#include <asm/tlbflush.h>1112/**13* copy_from_user_nmi - NMI safe copy from user14* @to: Pointer to the destination buffer15* @from: Pointer to a user space address of the current task16* @n: Number of bytes to copy17*18* Returns: The number of not copied bytes. 0 is success, i.e. all bytes copied19*20* Contrary to other copy_from_user() variants this function can be called21* from NMI context. Despite the name it is not restricted to be called22* from NMI context. It is safe to be called from any other context as23* well. It disables pagefaults across the copy which means a fault will24* abort the copy.25*26* For NMI context invocations this relies on the nested NMI work to allow27* atomic faults from the NMI path; the nested NMI paths are careful to28* preserve CR2.29*/30unsigned long31copy_from_user_nmi(void *to, const void __user *from, unsigned long n)32{33unsigned long ret;3435if (!__access_ok(from, n))36return n;3738if (!nmi_uaccess_okay())39return n;4041/*42* Even though this function is typically called from NMI/IRQ context43* disable pagefaults so that its behaviour is consistent even when44* called from other contexts.45*/46pagefault_disable();47instrument_copy_from_user_before(to, from, n);48ret = raw_copy_from_user(to, from, n);49instrument_copy_from_user_after(to, from, n, ret);50pagefault_enable();5152return ret;53}54EXPORT_SYMBOL_GPL(copy_from_user_nmi);555657