gup: avoid stack expansion warning for known-good case

JIRA: https://issues.redhat.com/browse/RHEL-27742

This patch is a backport of the following upstream commit:
commit eee9c708cc89b4600c6e6cdda5bc2b8b4dad96cb
Author: Linus Torvalds <torvalds@linux-foundation.org>
Date:   Thu Jun 29 12:36:47 2023 -0700

    gup: avoid stack expansion warning for known-good case

    In commit a425ac5365f6 ("gup: add warning if some caller would seem to
    want stack expansion") I added a temporary warning to catch any strange
    GUP users that would be impacted by the fact that GUP no longer extends
    the stack.

    But it turns out that the warning is most easily triggered through
    __access_remote_vm(), that already knows to expand the stack - it just
    does it *after* calling GUP.  So the warning is easy to trigger by just
    running gdb (or similar) and accessing things remotely under the stack.

    This just adds a temporary extra "expand stack early" to avoid the
    warning for the already converted case - not because the warning is bad,
    but because getting the warning for this known good case would then hide
    any subsequent warnings for any actually interesting cases.

    Let's try to remember to revert this change when we remove the warnings.

    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Signed-off-by: Rafael Aquini <raquini@redhat.com>
This commit is contained in:
Rafael Aquini 2024-09-05 20:32:59 -04:00
parent aa0d8fc3b2
commit 0f4ac0e1b7
1 changed files with 4 additions and 0 deletions

View File

@ -5728,6 +5728,10 @@ int __access_remote_vm(struct mm_struct *mm, unsigned long addr, void *buf,
if (mmap_read_lock_killable(mm))
return 0;
/* Avoid triggering the temporary warning in __get_user_pages */
if (!vma_lookup(mm, addr) && !expand_stack(mm, addr))
return 0;
/* ignore errors, just check how much was successfully transferred */
while (len) {
int bytes, offset;