1. 27 9月, 2022 17 次提交
  2. 12 9月, 2022 1 次提交
  3. 21 8月, 2022 1 次提交
    • D
      mm/hugetlb: fix hugetlb not supporting softdirty tracking · f96f7a40
      David Hildenbrand 提交于
      Patch series "mm/hugetlb: fix write-fault handling for shared mappings", v2.
      
      I observed that hugetlb does not support/expect write-faults in shared
      mappings that would have to map the R/O-mapped page writable -- and I
      found two case where we could currently get such faults and would
      erroneously map an anon page into a shared mapping.
      
      Reproducers part of the patches.
      
      I propose to backport both fixes to stable trees.  The first fix needs a
      small adjustment.
      
      
      This patch (of 2):
      
      Staring at hugetlb_wp(), one might wonder where all the logic for shared
      mappings is when stumbling over a write-protected page in a shared
      mapping.  In fact, there is none, and so far we thought we could get away
      with that because e.g., mprotect() should always do the right thing and
      map all pages directly writable.
      
      Looks like we were wrong:
      
      --------------------------------------------------------------------------
       #include <stdio.h>
       #include <stdlib.h>
       #include <string.h>
       #include <fcntl.h>
       #include <unistd.h>
       #include <errno.h>
       #include <sys/mman.h>
      
       #define HUGETLB_SIZE (2 * 1024 * 1024u)
      
       static void clear_softdirty(void)
       {
               int fd = open("/proc/self/clear_refs", O_WRONLY);
               const char *ctrl = "4";
               int ret;
      
               if (fd < 0) {
                       fprintf(stderr, "open(clear_refs) failed\n");
                       exit(1);
               }
               ret = write(fd, ctrl, strlen(ctrl));
               if (ret != strlen(ctrl)) {
                       fprintf(stderr, "write(clear_refs) failed\n");
                       exit(1);
               }
               close(fd);
       }
      
       int main(int argc, char **argv)
       {
               char *map;
               int fd;
      
               fd = open("/dev/hugepages/tmp", O_RDWR | O_CREAT);
               if (!fd) {
                       fprintf(stderr, "open() failed\n");
                       return -errno;
               }
               if (ftruncate(fd, HUGETLB_SIZE)) {
                       fprintf(stderr, "ftruncate() failed\n");
                       return -errno;
               }
      
               map = mmap(NULL, HUGETLB_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
               if (map == MAP_FAILED) {
                       fprintf(stderr, "mmap() failed\n");
                       return -errno;
               }
      
               *map = 0;
      
               if (mprotect(map, HUGETLB_SIZE, PROT_READ)) {
                       fprintf(stderr, "mmprotect() failed\n");
                       return -errno;
               }
      
               clear_softdirty();
      
               if (mprotect(map, HUGETLB_SIZE, PROT_READ|PROT_WRITE)) {
                       fprintf(stderr, "mmprotect() failed\n");
                       return -errno;
               }
      
               *map = 0;
      
               return 0;
       }
      --------------------------------------------------------------------------
      
      Above test fails with SIGBUS when there is only a single free hugetlb page.
       # echo 1 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
       # ./test
       Bus error (core dumped)
      
      And worse, with sufficient free hugetlb pages it will map an anonymous page
      into a shared mapping, for example, messing up accounting during unmap
      and breaking MAP_SHARED semantics:
       # echo 2 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
       # ./test
       # cat /proc/meminfo | grep HugePages_
       HugePages_Total:       2
       HugePages_Free:        1
       HugePages_Rsvd:    18446744073709551615
       HugePages_Surp:        0
      
      Reason in this particular case is that vma_wants_writenotify() will
      return "true", removing VM_SHARED in vma_set_page_prot() to map pages
      write-protected. Let's teach vma_wants_writenotify() that hugetlb does not
      support softdirty tracking.
      
      Link: https://lkml.kernel.org/r/20220811103435.188481-1-david@redhat.com
      Link: https://lkml.kernel.org/r/20220811103435.188481-2-david@redhat.com
      Fixes: 64e45507 ("mm: softdirty: enable write notifications on VMAs after VM_SOFTDIRTY cleared")
      Signed-off-by: NDavid Hildenbrand <david@redhat.com>
      Reviewed-by: NMike Kravetz <mike.kravetz@oracle.com>
      Cc: Peter Feiner <pfeiner@google.com>
      Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
      Cc: Cyrill Gorcunov <gorcunov@openvz.org>
      Cc: Pavel Emelyanov <xemul@parallels.com>
      Cc: Jamie Liu <jamieliu@google.com>
      Cc: Hugh Dickins <hughd@google.com>
      Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
      Cc: Bjorn Helgaas <bhelgaas@google.com>
      Cc: Muchun Song <songmuchun@bytedance.com>
      Cc: Peter Xu <peterx@redhat.com>
      Cc: <stable@vger.kernel.org>	[3.18+]
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      f96f7a40
  4. 30 7月, 2022 2 次提交
    • P
      mm/mprotect: fix soft-dirty check in can_change_pte_writable() · 76aefad6
      Peter Xu 提交于
      Patch series "mm/mprotect: Fix soft-dirty checks", v4.
      
      
      This patch (of 3):
      
      The check wanted to make sure when soft-dirty tracking is enabled we won't
      grant write bit by accident, as a page fault is needed for dirty tracking.
      The intention is correct but we didn't check it right because
      VM_SOFTDIRTY set actually means soft-dirty tracking disabled.  Fix it.
      
      There's another thing tricky about soft-dirty is that, we can't check the
      vma flag !(vma_flags & VM_SOFTDIRTY) directly but only check it after we
      checked CONFIG_MEM_SOFT_DIRTY because otherwise VM_SOFTDIRTY will be
      defined as zero, and !(vma_flags & VM_SOFTDIRTY) will constantly return
      true.  To avoid misuse, introduce a helper for checking whether vma has
      soft-dirty tracking enabled.
      
      We can easily verify this with any exclusive anonymous page, like program
      below:
      
      =======8<======
        #include <stdio.h>
        #include <unistd.h>
        #include <stdlib.h>
        #include <assert.h>
        #include <inttypes.h>
        #include <stdint.h>
        #include <sys/types.h>
        #include <sys/mman.h>
        #include <sys/types.h>
        #include <sys/stat.h>
        #include <unistd.h>
        #include <fcntl.h>
        #include <stdbool.h>
      
        #define BIT_ULL(nr)                   (1ULL << (nr))
        #define PM_SOFT_DIRTY                 BIT_ULL(55)
      
        unsigned int psize;
        char *page;
      
        uint64_t pagemap_read_vaddr(int fd, void *vaddr)
        {
            uint64_t value;
            int ret;
      
            ret = pread(fd, &value, sizeof(uint64_t),
                        ((uint64_t)vaddr >> 12) * sizeof(uint64_t));
            assert(ret == sizeof(uint64_t));
      
            return value;
        }
      
        void clear_refs_write(void)
        {
            int fd = open("/proc/self/clear_refs", O_RDWR);
      
            assert(fd >= 0);
            write(fd, "4", 2);
            close(fd);
        }
      
        #define  check_soft_dirty(str, expect)  do {                            \
                bool dirty = pagemap_read_vaddr(fd, page) & PM_SOFT_DIRTY;      \
                if (dirty != expect) {                                          \
                    printf("ERROR: %s, soft-dirty=%d (expect: %d)
      ", str, dirty, expect); \
                    exit(-1);                                                   \
                }                                                               \
        } while (0)
      
        int main(void)
        {
            int fd = open("/proc/self/pagemap", O_RDONLY);
      
            assert(fd >= 0);
            psize = getpagesize();
            page = mmap(NULL, psize, PROT_READ|PROT_WRITE,
                        MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
            assert(page != MAP_FAILED);
      
            *page = 1;
            check_soft_dirty("Just faulted in page", 1);
            clear_refs_write();
            check_soft_dirty("Clear_refs written", 0);
            mprotect(page, psize, PROT_READ);
            check_soft_dirty("Marked RO", 0);
            mprotect(page, psize, PROT_READ|PROT_WRITE);
            check_soft_dirty("Marked RW", 0);
            *page = 2;
            check_soft_dirty("Wrote page again", 1);
      
            munmap(page, psize);
            close(fd);
            printf("Test passed.
      ");
      
            return 0;
        }
      =======8<======
      
      Here we attach a Fixes to commit 64fe24a3 only for easy tracking, as
      this patch won't apply to a tree before that point.  However the commit
      wasn't the source of problem, but instead 64e45507.  It's just that
      after 64fe24a3 anonymous memory will also suffer from this problem
      with mprotect().
      
      Link: https://lkml.kernel.org/r/20220725142048.30450-1-peterx@redhat.com
      Link: https://lkml.kernel.org/r/20220725142048.30450-2-peterx@redhat.com
      Fixes: 64e45507 ("mm: softdirty: enable write notifications on VMAs after VM_SOFTDIRTY cleared")
      Fixes: 64fe24a3 ("mm/mprotect: try avoiding write faults for exclusive anonymous pages when changing protection")
      Signed-off-by: NPeter Xu <peterx@redhat.com>
      Reviewed-by: NDavid Hildenbrand <david@redhat.com>
      Cc: Nadav Amit <nadav.amit@gmail.com>
      Cc: Andrea Arcangeli <aarcange@redhat.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      76aefad6
    • M
      mm/mmap.c: fix missing call to vm_unacct_memory in mmap_region · 7f82f922
      Miaohe Lin 提交于
      Since the beginning, charged is set to 0 to avoid calling vm_unacct_memory
      twice because vm_unacct_memory will be called by above unmap_region.  But
      since commit 4f74d2c8 ("vm: remove 'nr_accounted' calculations from
      the unmap_vmas() interfaces"), unmap_region doesn't call vm_unacct_memory
      anymore.  So charged shouldn't be set to 0 now otherwise the calling to
      paired vm_unacct_memory will be missed and leads to imbalanced account.
      
      Link: https://lkml.kernel.org/r/20220618082027.43391-1-linmiaohe@huawei.com
      Fixes: 4f74d2c8 ("vm: remove 'nr_accounted' calculations from the unmap_vmas() interfaces")
      Signed-off-by: NMiaohe Lin <linmiaohe@huawei.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      7f82f922
  5. 18 7月, 2022 5 次提交
    • M
      mm/mmap: fix obsolete comment of find_extend_vma · cdb5c9e5
      Miaohe Lin 提交于
      mmget_still_valid() has already been removed via commit 4d45e75a ("mm:
      remove the now-unnecessary mmget_still_valid() hack").  Update the
      corresponding comment.
      
      Link: https://lkml.kernel.org/r/20220709092527.47778-1-linmiaohe@huawei.comSigned-off-by: NMiaohe Lin <linmiaohe@huawei.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      cdb5c9e5
    • A
      mm/mmap: drop ARCH_HAS_VM_GET_PAGE_PROT · 3d923c5f
      Anshuman Khandual 提交于
      Now all the platforms enable ARCH_HAS_GET_PAGE_PROT.  They define and
      export own vm_get_page_prot() whether custom or standard
      DECLARE_VM_GET_PAGE_PROT.  Hence there is no need for default generic
      fallback for vm_get_page_prot().  Just drop this fallback and also
      ARCH_HAS_GET_PAGE_PROT mechanism.
      
      Link: https://lkml.kernel.org/r/20220711070600.2378316-27-anshuman.khandual@arm.comSigned-off-by: NAnshuman Khandual <anshuman.khandual@arm.com>
      Reviewed-by: NGeert Uytterhoeven <geert@linux-m68k.org>
      Reviewed-by: NChristoph Hellwig <hch@lst.de>
      Reviewed-by: NChristophe Leroy <christophe.leroy@csgroup.eu>
      Acked-by: NGeert Uytterhoeven <geert@linux-m68k.org>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Brian Cain <bcain@quicinc.com>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Christoph Hellwig <hch@infradead.org>
      Cc: Chris Zankel <chris@zankel.net>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Dinh Nguyen <dinguyen@kernel.org>
      Cc: Guo Ren <guoren@kernel.org>
      Cc: Heiko Carstens <hca@linux.ibm.com>
      Cc: Huacai Chen <chenhuacai@kernel.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
      Cc: Jeff Dike <jdike@addtoit.com>
      Cc: Jonas Bonn <jonas@southpole.se>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Michal Simek <monstr@monstr.eu>
      Cc: Nicholas Piggin <npiggin@gmail.com>
      Cc: Palmer Dabbelt <palmer@dabbelt.com>
      Cc: Paul Mackerras <paulus@samba.org>
      Cc: Paul Walmsley <paul.walmsley@sifive.com>
      Cc: Richard Henderson <rth@twiddle.net>
      Cc: Rich Felker <dalias@libc.org>
      Cc: Russell King <linux@armlinux.org.uk>
      Cc: Sam Ravnborg <sam@ravnborg.org>
      Cc: Stafford Horne <shorne@gmail.com>
      Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Vasily Gorbik <gor@linux.ibm.com>
      Cc: Vineet Gupta <vgupta@kernel.org>
      Cc: WANG Xuerui <kernel@xen0n.name>
      Cc: Will Deacon <will@kernel.org>
      Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      3d923c5f
    • A
      mm/mmap: build protect protection_map[] with ARCH_HAS_VM_GET_PAGE_PROT · 09095f74
      Anshuman Khandual 提交于
      Now that protection_map[] has been moved inside those platforms that
      enable ARCH_HAS_VM_GET_PAGE_PROT.  Hence generic protection_map[] array
      now can be protected with CONFIG_ARCH_HAS_VM_GET_PAGE_PROT intead of
      __P000.
      
      Link: https://lkml.kernel.org/r/20220711070600.2378316-8-anshuman.khandual@arm.comSigned-off-by: NAnshuman Khandual <anshuman.khandual@arm.com>
      Reviewed-by: NChristophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Brian Cain <bcain@quicinc.com>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Christoph Hellwig <hch@infradead.org>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: Chris Zankel <chris@zankel.net>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Dinh Nguyen <dinguyen@kernel.org>
      Cc: Geert Uytterhoeven <geert@linux-m68k.org>
      Cc: Guo Ren <guoren@kernel.org>
      Cc: Heiko Carstens <hca@linux.ibm.com>
      Cc: Huacai Chen <chenhuacai@kernel.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
      Cc: Jeff Dike <jdike@addtoit.com>
      Cc: Jonas Bonn <jonas@southpole.se>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Michal Simek <monstr@monstr.eu>
      Cc: Nicholas Piggin <npiggin@gmail.com>
      Cc: Palmer Dabbelt <palmer@dabbelt.com>
      Cc: Paul Mackerras <paulus@samba.org>
      Cc: Paul Walmsley <paul.walmsley@sifive.com>
      Cc: Richard Henderson <rth@twiddle.net>
      Cc: Rich Felker <dalias@libc.org>
      Cc: Russell King <linux@armlinux.org.uk>
      Cc: Sam Ravnborg <sam@ravnborg.org>
      Cc: Stafford Horne <shorne@gmail.com>
      Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Vasily Gorbik <gor@linux.ibm.com>
      Cc: Vineet Gupta <vgupta@kernel.org>
      Cc: WANG Xuerui <kernel@xen0n.name>
      Cc: Will Deacon <will@kernel.org>
      Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      09095f74
    • A
      mm/mmap: define DECLARE_VM_GET_PAGE_PROT · 43957b5d
      Anshuman Khandual 提交于
      This just converts the generic vm_get_page_prot() implementation into a
      new macro i.e DECLARE_VM_GET_PAGE_PROT which later can be used across
      platforms when enabling them with ARCH_HAS_VM_GET_PAGE_PROT.  This does
      not create any functional change.
      
      Link: https://lkml.kernel.org/r/20220711070600.2378316-3-anshuman.khandual@arm.comSigned-off-by: NAnshuman Khandual <anshuman.khandual@arm.com>
      Reviewed-by: NChristophe Leroy <christophe.leroy@csgroup.eu>
      Suggested-by: NChristoph Hellwig <hch@infradead.org>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Brian Cain <bcain@quicinc.com>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: Chris Zankel <chris@zankel.net>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Dinh Nguyen <dinguyen@kernel.org>
      Cc: Geert Uytterhoeven <geert@linux-m68k.org>
      Cc: Guo Ren <guoren@kernel.org>
      Cc: Heiko Carstens <hca@linux.ibm.com>
      Cc: Huacai Chen <chenhuacai@kernel.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
      Cc: Jeff Dike <jdike@addtoit.com>
      Cc: Jonas Bonn <jonas@southpole.se>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Michal Simek <monstr@monstr.eu>
      Cc: Nicholas Piggin <npiggin@gmail.com>
      Cc: Palmer Dabbelt <palmer@dabbelt.com>
      Cc: Paul Mackerras <paulus@samba.org>
      Cc: Paul Walmsley <paul.walmsley@sifive.com>
      Cc: Richard Henderson <rth@twiddle.net>
      Cc: Rich Felker <dalias@libc.org>
      Cc: Russell King <linux@armlinux.org.uk>
      Cc: Sam Ravnborg <sam@ravnborg.org>
      Cc: Stafford Horne <shorne@gmail.com>
      Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Vasily Gorbik <gor@linux.ibm.com>
      Cc: Vineet Gupta <vgupta@kernel.org>
      Cc: WANG Xuerui <kernel@xen0n.name>
      Cc: Will Deacon <will@kernel.org>
      Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      43957b5d
    • A
      mm/mmap: build protect protection_map[] with __P000 · 84053271
      Anshuman Khandual 提交于
      Patch series "mm/mmap: Drop __SXXX/__PXXX macros from across platforms",
      v7.
      
      __SXXX/__PXXX macros are unnecessary abstraction layer in creating the
      generic protection_map[] array which is used for vm_get_page_prot().  This
      abstraction layer can be avoided, if the platforms just define the array
      protection_map[] for all possible vm_flags access permission combinations
      and also export vm_get_page_prot() implementation.
      
      This series drops __SXXX/__PXXX macros from across platforms in the tree. 
      First it build protects generic protection_map[] array with '#ifdef
      __P000' and moves it inside platforms which enable
      ARCH_HAS_VM_GET_PAGE_PROT.  Later this build protects same array with
      '#ifdef ARCH_HAS_VM_GET_PAGE_PROT' and moves inside remaining platforms
      while enabling ARCH_HAS_VM_GET_PAGE_PROT.  This adds a new macro
      DECLARE_VM_GET_PAGE_PROT defining the current generic vm_get_page_prot(),
      in order for it to be reused on platforms that do not require custom
      implementation.  Finally, ARCH_HAS_VM_GET_PAGE_PROT can just be dropped,
      as all platforms now define and export vm_get_page_prot(), via looking up
      a private and static protection_map[] array.  protection_map[] data type
      has been changed as 'static const' on all platforms that do not change it
      during boot.
      
      
      This patch (of 26):
      
      Build protect generic protection_map[] array with __P000, so that it can
      be moved inside all the platforms one after the other.  Otherwise there
      will be build failures during this process. 
      CONFIG_ARCH_HAS_VM_GET_PAGE_PROT cannot be used for this purpose as only
      certain platforms enable this config now.
      
      Link: https://lkml.kernel.org/r/20220711070600.2378316-1-anshuman.khandual@arm.com
      Link: https://lkml.kernel.org/r/20220711070600.2378316-2-anshuman.khandual@arm.comSigned-off-by: NAnshuman Khandual <anshuman.khandual@arm.com>
      Reviewed-by: NChristoph Hellwig <hch@lst.de>
      Reviewed-by: NChristophe Leroy <christophe.leroy@csgroup.eu>
      Suggested-by: NChristophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Brian Cain <bcain@quicinc.com>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Christoph Hellwig <hch@infradead.org>
      Cc: Chris Zankel <chris@zankel.net>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Dinh Nguyen <dinguyen@kernel.org>
      Cc: Geert Uytterhoeven <geert@linux-m68k.org>
      Cc: Guo Ren <guoren@kernel.org>
      Cc: Heiko Carstens <hca@linux.ibm.com>
      Cc: Huacai Chen <chenhuacai@kernel.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
      Cc: Jeff Dike <jdike@addtoit.com>
      Cc: Jonas Bonn <jonas@southpole.se>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Michal Simek <monstr@monstr.eu>
      Cc: Nicholas Piggin <npiggin@gmail.com>
      Cc: Palmer Dabbelt <palmer@dabbelt.com>
      Cc: Paul Mackerras <paulus@samba.org>
      Cc: Paul Walmsley <paul.walmsley@sifive.com>
      Cc: Richard Henderson <rth@twiddle.net>
      Cc: Rich Felker <dalias@libc.org>
      Cc: Russell King <linux@armlinux.org.uk>
      Cc: Sam Ravnborg <sam@ravnborg.org>
      Cc: Stafford Horne <shorne@gmail.com>
      Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Vasily Gorbik <gor@linux.ibm.com>
      Cc: Vineet Gupta <vgupta@kernel.org>
      Cc: WANG Xuerui <kernel@xen0n.name>
      Cc: Will Deacon <will@kernel.org>
      Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      84053271
  6. 28 6月, 2022 1 次提交
  7. 20 5月, 2022 2 次提交
  8. 13 5月, 2022 1 次提交
  9. 05 5月, 2022 2 次提交
  10. 29 4月, 2022 6 次提交
  11. 22 4月, 2022 1 次提交
    • C
      mm, hugetlb: allow for "high" userspace addresses · 5f24d5a5
      Christophe Leroy 提交于
      This is a fix for commit f6795053 ("mm: mmap: Allow for "high"
      userspace addresses") for hugetlb.
      
      This patch adds support for "high" userspace addresses that are
      optionally supported on the system and have to be requested via a hint
      mechanism ("high" addr parameter to mmap).
      
      Architectures such as powerpc and x86 achieve this by making changes to
      their architectural versions of hugetlb_get_unmapped_area() function.
      However, arm64 uses the generic version of that function.
      
      So take into account arch_get_mmap_base() and arch_get_mmap_end() in
      hugetlb_get_unmapped_area().  To allow that, move those two macros out
      of mm/mmap.c into include/linux/sched/mm.h
      
      If these macros are not defined in architectural code then they default
      to (TASK_SIZE) and (base) so should not introduce any behavioural
      changes to architectures that do not define them.
      
      For the time being, only ARM64 is affected by this change.
      
      Catalin (ARM64) said
       "We should have fixed hugetlb_get_unmapped_area() as well when we added
        support for 52-bit VA. The reason for commit f6795053 was to
        prevent normal mmap() from returning addresses above 48-bit by default
        as some user-space had hard assumptions about this.
      
        It's a slight ABI change if you do this for hugetlb_get_unmapped_area()
        but I doubt anyone would notice. It's more likely that the current
        behaviour would cause issues, so I'd rather have them consistent.
      
        Basically when arm64 gained support for 52-bit addresses we did not
        want user-space calling mmap() to suddenly get such high addresses,
        otherwise we could have inadvertently broken some programs (similar
        behaviour to x86 here). Hence we added commit f6795053. But we
        missed hugetlbfs which could still get such high mmap() addresses. So
        in theory that's a potential regression that should have bee addressed
        at the same time as commit f6795053 (and before arm64 enabled
        52-bit addresses)"
      
      Link: https://lkml.kernel.org/r/ab847b6edb197bffdfe189e70fb4ac76bfe79e0d.1650033747.git.christophe.leroy@csgroup.eu
      Fixes: f6795053 ("mm: mmap: Allow for "high" userspace addresses")
      Signed-off-by: NChristophe Leroy <christophe.leroy@csgroup.eu>
      Reviewed-by: NCatalin Marinas <catalin.marinas@arm.com>
      Cc: Steve Capper <steve.capper@arm.com>
      Cc: Will Deacon <will.deacon@arm.com>
      Cc: <stable@vger.kernel.org>	[5.0.x]
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      5f24d5a5
  12. 23 3月, 2022 1 次提交