git: 9ecde173624c - stable/13 - linuxkpi: Add __copy_to_user_inatomic and __copy_from_user_inatomic

From: Emmanuel Vadot <manu_at_FreeBSD.org>
Date: Wed, 07 Sep 2022 15:10:37 UTC
The branch stable/13 has been updated by manu:

URL: https://cgit.FreeBSD.org/src/commit/?id=9ecde173624c892a2b9aba2a1b4ca977b63fd513

commit 9ecde173624c892a2b9aba2a1b4ca977b63fd513
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2022-08-10 06:44:14 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2022-09-07 15:09:06 +0000

    linuxkpi: Add __copy_to_user_inatomic and __copy_from_user_inatomic
    
    Reviewed by:    bz
    Obtained from:  drm-kmod
    Sponsored by:   Beckhoff Automation GmbH & Co. KG
    Differential Revision:  https://reviews.freebsd.org/D36113
    
    (cherry picked from commit 76d93395c522e28cfa329ba57ca235929462412c)
---
 sys/compat/linuxkpi/common/include/linux/uaccess.h | 25 ++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/sys/compat/linuxkpi/common/include/linux/uaccess.h b/sys/compat/linuxkpi/common/include/linux/uaccess.h
index c62a94e8e044..3fa16dbcd261 100644
--- a/sys/compat/linuxkpi/common/include/linux/uaccess.h
+++ b/sys/compat/linuxkpi/common/include/linux/uaccess.h
@@ -89,4 +89,29 @@ pagefault_disabled(void)
 	return ((curthread->td_pflags & TDP_NOFAULTING) != 0);
 }
 
+static inline int
+__copy_to_user_inatomic(void __user *to, const void *from, unsigned n)
+{
+
+	return (copyout_nofault(from, to, n) != 0 ? n : 0);
+}
+#define	__copy_to_user_inatomic_nocache(to, from, n)	\
+	__copy_to_user_inatomic((to), (from), (n))
+
+static inline unsigned long
+__copy_from_user_inatomic(void *to, const void __user *from,
+    unsigned long n)
+{
+	/*
+	 * XXXKIB.  Equivalent Linux function is implemented using
+	 * MOVNTI for aligned moves.  For unaligned head and tail,
+	 * normal move is performed.  As such, it is not incorrect, if
+	 * only somewhat slower, to use normal copyin.  All uses
+	 * except shmem_pwrite_fast() have the destination mapped WC.
+	 */
+	return ((copyin_nofault(__DECONST(void *, from), to, n) != 0 ? n : 0));
+}
+#define	__copy_from_user_inatomic_nocache(to, from, n)	\
+	__copy_from_user_inatomic((to), (from), (n))
+
 #endif					/* _LINUXKPI_LINUX_UACCESS_H_ */