diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c index c416c7d3242fe5..e28284c927614a 100644 --- a/arch/arm/lib/uaccess_with_memcpy.c +++ b/arch/arm/lib/uaccess_with_memcpy.c @@ -153,12 +153,27 @@ __copy_to_user_memcpy(void __user *to, const void *from, unsigned long n) pte_t *pte; spinlock_t *ptl; int tocopy; + bool retried = false; while (!pin_page_for_write(to, &pte, &ptl)) { if (!atomic) mmap_read_unlock(current->mm); + if (retried) { + /* + * Faulting the page in succeeded but it still + * can't be pinned, as happens when the young bit + * was cleared without a TLB flush. Retrying would + * spin forever, so let the standard routine, which + * handles faults, do the rest. + */ + ua_flags = uaccess_save_and_enable(); + n = __copy_to_user_std(to, from, n); + uaccess_restore(ua_flags); + goto out; + } if (__put_user(0, (char __user *)to)) goto out; + retried = true; if (!atomic) mmap_read_lock(current->mm); } @@ -202,13 +217,22 @@ __copy_from_user_memcpy(void *to, const void __user *from, unsigned long n) pte_t *pte; spinlock_t *ptl; int tocopy; + bool retried = false; while (!pin_page_for_read(from, &pte, &ptl)) { char temp; if (!atomic) mmap_read_unlock(current->mm); + if (retried) { + /* See __copy_to_user_memcpy(). */ + ua_flags = uaccess_save_and_enable(); + n = __copy_from_user_std(to, from, n); + uaccess_restore(ua_flags); + goto out; + } if (__get_user(temp, (char __user *)from)) goto out; + retried = true; if (!atomic) mmap_read_lock(current->mm); } @@ -291,11 +315,33 @@ __clear_user_memset(void __user *addr, unsigned long n) pte_t *pte; spinlock_t *ptl; int tocopy; + bool retried = false; while (!pin_page_for_write(addr, &pte, &ptl)) { mmap_read_unlock(current->mm); + if (retried) { + /* + * See __copy_to_user_memcpy(). On a fault, + * __clear_user_std() returns the whole length + * it was given, so go a page at a time to keep + * the count of bytes not cleared accurate. + */ + ua_flags = uaccess_save_and_enable(); + while (n) { + tocopy = (~(unsigned long)addr & ~PAGE_MASK) + 1; + if (tocopy > n) + tocopy = n; + if (__clear_user_std(addr, tocopy)) + break; + addr += tocopy; + n -= tocopy; + } + uaccess_restore(ua_flags); + goto out; + } if (__put_user(0, (char __user *)addr)) goto out; + retried = true; mmap_read_lock(current->mm); }