From: Matt Mackall <mpm@selenic.com>

This only checks in the non-__ versions, as those are occassionally
called inside things like kmap_atomic pairs which take a spinlock in
with highmem. It's all conditional on CONFIG_DEBUG_SPINLOCK_SLEEP
(which isn't quite the right name) so there's no overhead for normal
builds.



 arch/i386/lib/usercopy.c   |    3 +++
 include/asm-i386/uaccess.h |    3 +++
 2 files changed, 6 insertions(+)

diff -puN arch/i386/lib/usercopy.c~usercopy-might_sleep-checks arch/i386/lib/usercopy.c
--- 25/arch/i386/lib/usercopy.c~usercopy-might_sleep-checks	2003-08-02 12:08:25.000000000 -0700
+++ 25-akpm/arch/i386/lib/usercopy.c	2003-08-02 12:08:25.000000000 -0700
@@ -149,6 +149,7 @@ do {									\
 unsigned long
 direct_clear_user(void __user *to, unsigned long n)
 {
+	might_sleep();
 	if (access_ok(VERIFY_WRITE, to, n))
 		__do_clear_user(to, n);
 	return n;
@@ -188,6 +189,8 @@ long direct_strnlen_user(const char __us
 	unsigned long mask = -__addr_ok(s);
 	unsigned long res, tmp;
 
+	might_sleep();
+
 	__asm__ __volatile__(
 		"	testl %0, %0\n"
 		"	jz 3f\n"
diff -puN include/asm-i386/uaccess.h~usercopy-might_sleep-checks include/asm-i386/uaccess.h
--- 25/include/asm-i386/uaccess.h~usercopy-might_sleep-checks	2003-08-02 12:08:25.000000000 -0700
+++ 25-akpm/include/asm-i386/uaccess.h	2003-08-02 12:08:25.000000000 -0700
@@ -299,6 +299,7 @@ extern void __put_user_bad(void);
 ({									\
 	long __pu_err = -EFAULT;					\
 	__typeof__(*(ptr)) *__pu_addr = (ptr);				\
+	might_sleep();						\
 	if (access_ok(VERIFY_WRITE,__pu_addr,size))			\
 		__put_user_size((x),__pu_addr,(size),__pu_err,-EFAULT);	\
 	__pu_err;							\
@@ -508,6 +509,7 @@ __direct_copy_from_user(void *to, const 
 static inline unsigned long
 direct_copy_to_user(void __user *to, const void *from, unsigned long n)
 {
+	might_sleep();
 	if (access_ok(VERIFY_WRITE, to, n))
 		n = __direct_copy_to_user(to, from, n);
 	return n;
@@ -532,6 +534,7 @@ direct_copy_to_user(void __user *to, con
 static inline unsigned long
 direct_copy_from_user(void *to, const void __user *from, unsigned long n)
 {
+	might_sleep();
 	if (access_ok(VERIFY_READ, from, n))
 		n = __direct_copy_from_user(to, from, n);
 	else

_