Commit 677b2a8c authored by Christophe Leroy's avatar Christophe Leroy Committed by Linus Torvalds

gup: avoid multiple user access locking/unlocking in fault_in_{read/write}able

fault_in_readable() and fault_in_writeable() perform __get_user() and
__put_user() in a loop, implying multiple user access locking/unlocking.

To avoid that, use user access blocks.

Link: https://lkml.kernel.org/r/720dcf79314acca1a78fae56d478cc851952149d.1637084492.git.christophe.leroy@csgroup.euSigned-off-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
Reviewed-by: default avatarAndreas Gruenbacher <agruenba@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 43b93121
...@@ -1672,21 +1672,22 @@ size_t fault_in_writeable(char __user *uaddr, size_t size) ...@@ -1672,21 +1672,22 @@ size_t fault_in_writeable(char __user *uaddr, size_t size)
if (unlikely(size == 0)) if (unlikely(size == 0))
return 0; return 0;
if (!PAGE_ALIGNED(uaddr)) { if (!user_write_access_begin(uaddr, size))
if (unlikely(__put_user(0, uaddr) != 0))
return size; return size;
if (!PAGE_ALIGNED(uaddr)) {
unsafe_put_user(0, uaddr, out);
uaddr = (char __user *)PAGE_ALIGN((unsigned long)uaddr); uaddr = (char __user *)PAGE_ALIGN((unsigned long)uaddr);
} }
end = (char __user *)PAGE_ALIGN((unsigned long)start + size); end = (char __user *)PAGE_ALIGN((unsigned long)start + size);
if (unlikely(end < start)) if (unlikely(end < start))
end = NULL; end = NULL;
while (uaddr != end) { while (uaddr != end) {
if (unlikely(__put_user(0, uaddr) != 0)) unsafe_put_user(0, uaddr, out);
goto out;
uaddr += PAGE_SIZE; uaddr += PAGE_SIZE;
} }
out: out:
user_write_access_end();
if (size > uaddr - start) if (size > uaddr - start)
return size - (uaddr - start); return size - (uaddr - start);
return 0; return 0;
...@@ -1771,21 +1772,22 @@ size_t fault_in_readable(const char __user *uaddr, size_t size) ...@@ -1771,21 +1772,22 @@ size_t fault_in_readable(const char __user *uaddr, size_t size)
if (unlikely(size == 0)) if (unlikely(size == 0))
return 0; return 0;
if (!PAGE_ALIGNED(uaddr)) { if (!user_read_access_begin(uaddr, size))
if (unlikely(__get_user(c, uaddr) != 0))
return size; return size;
if (!PAGE_ALIGNED(uaddr)) {
unsafe_get_user(c, uaddr, out);
uaddr = (const char __user *)PAGE_ALIGN((unsigned long)uaddr); uaddr = (const char __user *)PAGE_ALIGN((unsigned long)uaddr);
} }
end = (const char __user *)PAGE_ALIGN((unsigned long)start + size); end = (const char __user *)PAGE_ALIGN((unsigned long)start + size);
if (unlikely(end < start)) if (unlikely(end < start))
end = NULL; end = NULL;
while (uaddr != end) { while (uaddr != end) {
if (unlikely(__get_user(c, uaddr) != 0)) unsafe_get_user(c, uaddr, out);
goto out;
uaddr += PAGE_SIZE; uaddr += PAGE_SIZE;
} }
out: out:
user_read_access_end();
(void)c; (void)c;
if (size > uaddr - start) if (size > uaddr - start)
return size - (uaddr - start); return size - (uaddr - start);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment