Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1556122

Re: [PATCH v2] mm: Respect FOLL_FORCE/FOLL_COW for thp

From David Rientjes <rientjes@google.com>
Newsgroups linux.kernel
Subject Re: [PATCH v2] mm: Respect FOLL_FORCE/FOLL_COW for thp
Date 2017-01-11 02:20 +0100
Message-ID <sYfK1-ig-3@gated-at.bofh.it> (permalink)
References <sWrYZ-2TE-11@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Thu, 5 Jan 2017, Keno Fischer wrote:

> In 19be0eaff ("mm: remove gup_flags FOLL_WRITE games from __get_user_pages()"),
> the mm code was changed from unsetting FOLL_WRITE after a COW was resolved to
> setting the (newly introduced) FOLL_COW instead. Simultaneously, the check in
> gup.c was updated to still allow writes with FOLL_FORCE set if FOLL_COW had
> also been set. However, a similar check in huge_memory.c was forgotten. As a
> result, remote memory writes to ro regions of memory backed by transparent huge
> pages cause an infinite loop in the kernel (handle_mm_fault sets FOLL_COW and
> returns 0 causing a retry, but follow_trans_huge_pmd bails out immidiately
> because `(flags & FOLL_WRITE) && !pmd_write(*pmd)` is true. While in this
> state the process is stil SIGKILLable, but little else works (e.g. no ptrace
> attach, no other signals). This is easily reproduced with the following
> code (assuming thp are set to always):
> 
>     #include <assert.h>
>     #include <fcntl.h>
>     #include <stdint.h>
>     #include <stdio.h>
>     #include <string.h>
>     #include <sys/mman.h>
>     #include <sys/stat.h>
>     #include <sys/types.h>
>     #include <sys/wait.h>
>     #include <unistd.h>
> 
>     #define TEST_SIZE 5 * 1024 * 1024
> 
>     int main(void) {
>       int status;
>       pid_t child;
>       int fd = open("/proc/self/mem", O_RDWR);
>       void *addr = mmap(NULL, TEST_SIZE, PROT_READ,
>                         MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
>       assert(addr != MAP_FAILED);
>       pid_t parent_pid = getpid();
>       if ((child = fork()) == 0) {
>         void *addr2 = mmap(NULL, TEST_SIZE, PROT_READ | PROT_WRITE,
>                            MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
>         assert(addr2 != MAP_FAILED);
>         memset(addr2, 'a', TEST_SIZE);
>         pwrite(fd, addr2, TEST_SIZE, (uintptr_t)addr);
>         return 0;
>       }
>       assert(child == waitpid(child, &status, 0));
>       assert(WIFEXITED(status) && WEXITSTATUS(status) == 0);
>       return 0;
>     }
> 
> Fix this by updating follow_trans_huge_pmd in huge_memory.c analogously to
> the update in gup.c in the original commit. The same pattern exists in
> follow_devmap_pmd. However, we should not be able to reach that check
> with FOLL_COW set, so add WARN_ONCE to make sure we notice if we ever
> do.
> 
> Signed-off-by: Keno Fischer <keno@juliacomputing.com>

Tested-by: David Rientjes <rientjes@google.com>

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

[PATCH v2] mm: Respect FOLL_FORCE/FOLL_COW for thp Keno Fischer <keno@juliacomputing.com> - 2017-01-06 03:00 +0100
  Re: [PATCH v2] mm: Respect FOLL_FORCE/FOLL_COW for thp "Kirill A. Shutemov" <kirill@shutemov.name> - 2017-01-06 09:30 +0100
    Re: [PATCH v2] mm: Respect FOLL_FORCE/FOLL_COW for thp Michal Hocko <mhocko@kernel.org> - 2017-01-10 10:30 +0100
      Re: [PATCH v2] mm: Respect FOLL_FORCE/FOLL_COW for thp "Kirill A. Shutemov" <kirill@shutemov.name> - 2017-01-10 13:30 +0100
        Re: [PATCH v2] mm: Respect FOLL_FORCE/FOLL_COW for thp Michal Hocko <mhocko@kernel.org> - 2017-01-10 13:30 +0100
  Re: [PATCH v2] mm: Respect FOLL_FORCE/FOLL_COW for thp David Rientjes <rientjes@google.com> - 2017-01-11 02:20 +0100

csiph-web