]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm: consolidate common checks in hugetlb_get_unmapped_area
authorOscar Salvador <osalvador@suse.de>
Mon, 7 Oct 2024 07:50:37 +0000 (09:50 +0200)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 1 Nov 2024 04:29:00 +0000 (21:29 -0700)
prepare_hugepage_range() performs almost the same checks for all
architectures that define it, with the exception of mips and loongarch
that also check for overflows.

The rest checks for the addr and len to be properly aligned, so we can
move that to hugetlb_get_unmapped_area() and get rid of a fair amount of
duplicated code.

Link: https://lkml.kernel.org/r/20241007075037.267650-10-osalvador@suse.de
Signed-off-by: Oscar Salvador <osalvador@suse.de>
Cc: David Hildenbrand <david@redhat.com>
Cc: Donet Tom <donettom@linux.ibm.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Peter Xu <peterx@redhat.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
arch/loongarch/include/asm/hugetlb.h
arch/mips/include/asm/hugetlb.h
arch/parisc/include/asm/hugetlb.h
arch/s390/include/asm/hugetlb.h
arch/sh/include/asm/hugetlb.h
fs/hugetlbfs/inode.c
include/asm-generic/hugetlb.h

index 5da32c00d483fbab845664373b950d45e98982bd..b837c65a4894ea5caa9d021fc0962e8838cd3748 100644 (file)
@@ -16,12 +16,7 @@ static inline int prepare_hugepage_range(struct file *file,
                                         unsigned long len)
 {
        unsigned long task_size = STACK_TOP;
-       struct hstate *h = hstate_file(file);
 
-       if (len & ~huge_page_mask(h))
-               return -EINVAL;
-       if (addr & ~huge_page_mask(h))
-               return -EINVAL;
        if (len > task_size)
                return -ENOMEM;
        if (task_size - len < addr)
index fd69c88085542e370b2a09df004a782fec48729d..6a63d82a8ab324c1c89664b12bf1bc0d21965540 100644 (file)
@@ -19,10 +19,6 @@ static inline int prepare_hugepage_range(struct file *file,
        unsigned long task_size = STACK_TOP;
        struct hstate *h = hstate_file(file);
 
-       if (len & ~huge_page_mask(h))
-               return -EINVAL;
-       if (addr & ~huge_page_mask(h))
-               return -EINVAL;
        if (len > task_size)
                return -ENOMEM;
        if (task_size - len < addr)
index 72daacc472a0a305772d7473aa8601a5316fbbe4..5b3a5429f71b31655012fd69e1724de8313a9591 100644 (file)
@@ -12,21 +12,6 @@ void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
 pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
                              pte_t *ptep);
 
-/*
- * If the arch doesn't supply something else, assume that hugepage
- * size aligned regions are ok without further preparation.
- */
-#define __HAVE_ARCH_PREPARE_HUGEPAGE_RANGE
-static inline int prepare_hugepage_range(struct file *file,
-                       unsigned long addr, unsigned long len)
-{
-       if (len & ~HPAGE_MASK)
-               return -EINVAL;
-       if (addr & ~HPAGE_MASK)
-               return -EINVAL;
-       return 0;
-}
-
 #define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH
 static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
                                          unsigned long addr, pte_t *ptep)
index 37e80a32623a7f88ecffbc719775159cfbf807ee..6f815d4ba0cabbf28dae0744dbc5754e23a9f15e 100644 (file)
@@ -25,23 +25,6 @@ extern pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, pte_t *ptep
 extern pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
                              unsigned long addr, pte_t *ptep);
 
-/*
- * If the arch doesn't supply something else, assume that hugepage
- * size aligned regions are ok without further preparation.
- */
-#define __HAVE_ARCH_PREPARE_HUGEPAGE_RANGE
-static inline int prepare_hugepage_range(struct file *file,
-                       unsigned long addr, unsigned long len)
-{
-       struct hstate *h = hstate_file(file);
-
-       if (len & ~huge_page_mask(h))
-               return -EINVAL;
-       if (addr & ~huge_page_mask(h))
-               return -EINVAL;
-       return 0;
-}
-
 static inline void arch_clear_hugetlb_flags(struct folio *folio)
 {
        clear_bit(PG_arch_1, &folio->flags);
index 75028bd568ba5e2ec16ab62f09654a19e54cbf0c..4a92e6e4d627e99f75e78f3b44fb6bd0c58d6a37 100644 (file)
@@ -5,21 +5,6 @@
 #include <asm/cacheflush.h>
 #include <asm/page.h>
 
-/*
- * If the arch doesn't supply something else, assume that hugepage
- * size aligned regions are ok without further preparation.
- */
-#define __HAVE_ARCH_PREPARE_HUGEPAGE_RANGE
-static inline int prepare_hugepage_range(struct file *file,
-                       unsigned long addr, unsigned long len)
-{
-       if (len & ~HPAGE_MASK)
-               return -EINVAL;
-       if (addr & ~HPAGE_MASK)
-               return -EINVAL;
-       return 0;
-}
-
 #define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH
 static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
                                          unsigned long addr, pte_t *ptep)
index 935c0ed3aa1ea8d27a9af21b17b73bd697c9aa7d..c6191a6118b83f40da4cb1e58c8c9c449c238839 100644 (file)
@@ -181,8 +181,12 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
 
        if (len & ~huge_page_mask(h))
                return -EINVAL;
-       if ((flags & MAP_FIXED) && prepare_hugepage_range(file, addr, len))
-               return -EINVAL;
+       if (flags & MAP_FIXED) {
+               if (addr & ~huge_page_mask(h))
+                       return -EINVAL;
+               if (prepare_hugepage_range(file, addr, len))
+                       return -EINVAL;
+       }
        if (addr)
                addr0 = ALIGN(addr, huge_page_size(h));
 
index 67bbdafcfc22456725bde43bf231866de745daff..f42133dae68e5aa44b820ca973679db1c87c1419 100644 (file)
@@ -123,13 +123,6 @@ static inline int huge_pte_none_mostly(pte_t pte)
 static inline int prepare_hugepage_range(struct file *file,
                unsigned long addr, unsigned long len)
 {
-       struct hstate *h = hstate_file(file);
-
-       if (len & ~huge_page_mask(h))
-               return -EINVAL;
-       if (addr & ~huge_page_mask(h))
-               return -EINVAL;
-
        return 0;
 }
 #endif