Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions arch/arm/lib/uaccess_with_memcpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

Expand Down