Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm: update hugetlbfs to use VMA flags on mmap_prepare

In order to update all mmap_prepare users to utilising the new VMA flags
type vma_flags_t and associated helper functions, we start by updating
hugetlbfs which has a lot of additional logic that requires updating to
make this change.

This is laying the groundwork for eliminating the vm_flags_t from struct
vm_area_desc and using vma_flags_t only, which further lays the ground for
removing the deprecated vm_flags_t type altogether.

No functional changes intended.

Link: https://lkml.kernel.org/r/9226bec80c9aa3447cc2b83354f733841dba8a50.1769097829.git.lorenzo.stoakes@oracle.com
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Barry Song <baohua@kernel.org>
Cc: David Hildenbrand <david@kernel.org>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Jason Gunthorpe <jgg@nvidia.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Zi Yan <ziy@nvidia.com>
Cc: Damien Le Moal <dlemoal@kernel.org>
Cc: "Darrick J. Wong" <djwong@kernel.org>
Cc: Jarkko Sakkinen <jarkko@kernel.org>
Cc: Yury Norov <ynorov@nvidia.com>
Cc: Chris Mason <clm@fb.com>
Cc: Pedro Falcato <pfalcato@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Lorenzo Stoakes and committed by
Andrew Morton
097e8db5 bae0ba7c

+41 -29
+7 -7
fs/hugetlbfs/inode.c
··· 109 109 loff_t len, vma_len; 110 110 int ret; 111 111 struct hstate *h = hstate_file(file); 112 - vm_flags_t vm_flags; 112 + vma_flags_t vma_flags; 113 113 114 114 /* 115 115 * vma address alignment (but not the pgoff alignment) has ··· 119 119 * way when do_mmap unwinds (may be important on powerpc 120 120 * and ia64). 121 121 */ 122 - desc->vm_flags |= VM_HUGETLB | VM_DONTEXPAND; 122 + vma_desc_set_flags(desc, VMA_HUGETLB_BIT, VMA_DONTEXPAND_BIT); 123 123 desc->vm_ops = &hugetlb_vm_ops; 124 124 125 125 /* ··· 148 148 149 149 ret = -ENOMEM; 150 150 151 - vm_flags = desc->vm_flags; 151 + vma_flags = desc->vma_flags; 152 152 /* 153 153 * for SHM_HUGETLB, the pages are reserved in the shmget() call so skip 154 154 * reserving here. Note: only for SHM hugetlbfs file, the inode 155 155 * flag S_PRIVATE is set. 156 156 */ 157 157 if (inode->i_flags & S_PRIVATE) 158 - vm_flags |= VM_NORESERVE; 158 + vma_flags_set(&vma_flags, VMA_NORESERVE_BIT); 159 159 160 160 if (hugetlb_reserve_pages(inode, 161 161 desc->pgoff >> huge_page_order(h), 162 162 len >> huge_page_shift(h), desc, 163 - vm_flags) < 0) 163 + vma_flags) < 0) 164 164 goto out; 165 165 166 166 ret = 0; 167 - if ((desc->vm_flags & VM_WRITE) && inode->i_size < len) 167 + if (vma_desc_test_flags(desc, VMA_WRITE_BIT) && inode->i_size < len) 168 168 i_size_write(inode, len); 169 169 out: 170 170 inode_unlock(inode); ··· 1527 1527 * otherwise hugetlb_reserve_pages reserves one less hugepages than intended. 1528 1528 */ 1529 1529 struct file *hugetlb_file_setup(const char *name, size_t size, 1530 - vm_flags_t acctflag, int creat_flags, 1530 + vma_flags_t acctflag, int creat_flags, 1531 1531 int page_size_log) 1532 1532 { 1533 1533 struct inode *inode;
+3 -3
include/linux/hugetlb.h
··· 150 150 struct folio **foliop); 151 151 #endif /* CONFIG_USERFAULTFD */ 152 152 long hugetlb_reserve_pages(struct inode *inode, long from, long to, 153 - struct vm_area_desc *desc, vm_flags_t vm_flags); 153 + struct vm_area_desc *desc, vma_flags_t vma_flags); 154 154 long hugetlb_unreserve_pages(struct inode *inode, long start, long end, 155 155 long freed); 156 156 bool folio_isolate_hugetlb(struct folio *folio, struct list_head *list); ··· 529 529 } 530 530 531 531 extern const struct vm_operations_struct hugetlb_vm_ops; 532 - struct file *hugetlb_file_setup(const char *name, size_t size, vm_flags_t acct, 532 + struct file *hugetlb_file_setup(const char *name, size_t size, vma_flags_t acct, 533 533 int creat_flags, int page_size_log); 534 534 535 535 static inline bool is_file_hugepages(const struct file *file) ··· 545 545 546 546 #define is_file_hugepages(file) false 547 547 static inline struct file * 548 - hugetlb_file_setup(const char *name, size_t size, vm_flags_t acctflag, 548 + hugetlb_file_setup(const char *name, size_t size, vma_flags_t acctflag, 549 549 int creat_flags, int page_size_log) 550 550 { 551 551 return ERR_PTR(-ENOSYS);
+10
include/linux/hugetlb_inline.h
··· 11 11 return !!(vm_flags & VM_HUGETLB); 12 12 } 13 13 14 + static inline bool is_vma_hugetlb_flags(const vma_flags_t *flags) 15 + { 16 + return vma_flags_test(flags, VMA_HUGETLB_BIT); 17 + } 18 + 14 19 #else 15 20 16 21 static inline bool is_vm_hugetlb_flags(vm_flags_t vm_flags) 22 + { 23 + return false; 24 + } 25 + 26 + static inline bool is_vma_hugetlb_flags(const vma_flags_t *flags) 17 27 { 18 28 return false; 19 29 }
+7 -5
ipc/shm.c
··· 707 707 int error; 708 708 struct shmid_kernel *shp; 709 709 size_t numpages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT; 710 + const bool has_no_reserve = shmflg & SHM_NORESERVE; 710 711 struct file *file; 711 712 char name[13]; 712 - vm_flags_t acctflag = 0; 713 713 714 714 if (size < SHMMIN || size > ns->shm_ctlmax) 715 715 return -EINVAL; ··· 738 738 739 739 sprintf(name, "SYSV%08x", key); 740 740 if (shmflg & SHM_HUGETLB) { 741 + vma_flags_t acctflag = EMPTY_VMA_FLAGS; 741 742 struct hstate *hs; 742 743 size_t hugesize; 743 744 ··· 750 749 hugesize = ALIGN(size, huge_page_size(hs)); 751 750 752 751 /* hugetlb_file_setup applies strict accounting */ 753 - if (shmflg & SHM_NORESERVE) 754 - acctflag = VM_NORESERVE; 752 + if (has_no_reserve) 753 + vma_flags_set(&acctflag, VMA_NORESERVE_BIT); 755 754 file = hugetlb_file_setup(name, hugesize, acctflag, 756 755 HUGETLB_SHMFS_INODE, (shmflg >> SHM_HUGE_SHIFT) & SHM_HUGE_MASK); 757 756 } else { 757 + vm_flags_t acctflag = 0; 758 + 758 759 /* 759 760 * Do not allow no accounting for OVERCOMMIT_NEVER, even 760 761 * if it's asked for. 761 762 */ 762 - if ((shmflg & SHM_NORESERVE) && 763 - sysctl_overcommit_memory != OVERCOMMIT_NEVER) 763 + if (has_no_reserve && sysctl_overcommit_memory != OVERCOMMIT_NEVER) 764 764 acctflag = VM_NORESERVE; 765 765 file = shmem_kernel_file_setup(name, size, acctflag); 766 766 }
+11 -11
mm/hugetlb.c
··· 1193 1193 1194 1194 static void set_vma_desc_resv_map(struct vm_area_desc *desc, struct resv_map *map) 1195 1195 { 1196 - VM_WARN_ON_ONCE(!is_vm_hugetlb_flags(desc->vm_flags)); 1197 - VM_WARN_ON_ONCE(desc->vm_flags & VM_MAYSHARE); 1196 + VM_WARN_ON_ONCE(!is_vma_hugetlb_flags(&desc->vma_flags)); 1197 + VM_WARN_ON_ONCE(vma_desc_test_flags(desc, VMA_MAYSHARE_BIT)); 1198 1198 1199 1199 desc->private_data = map; 1200 1200 } 1201 1201 1202 1202 static void set_vma_desc_resv_flags(struct vm_area_desc *desc, unsigned long flags) 1203 1203 { 1204 - VM_WARN_ON_ONCE(!is_vm_hugetlb_flags(desc->vm_flags)); 1205 - VM_WARN_ON_ONCE(desc->vm_flags & VM_MAYSHARE); 1204 + VM_WARN_ON_ONCE(!is_vma_hugetlb_flags(&desc->vma_flags)); 1205 + VM_WARN_ON_ONCE(vma_desc_test_flags(desc, VMA_MAYSHARE_BIT)); 1206 1206 1207 1207 desc->private_data = (void *)((unsigned long)desc->private_data | flags); 1208 1208 } ··· 1216 1216 1217 1217 static bool is_vma_desc_resv_set(struct vm_area_desc *desc, unsigned long flag) 1218 1218 { 1219 - VM_WARN_ON_ONCE(!is_vm_hugetlb_flags(desc->vm_flags)); 1219 + VM_WARN_ON_ONCE(!is_vma_hugetlb_flags(&desc->vma_flags)); 1220 1220 1221 1221 return ((unsigned long)desc->private_data) & flag; 1222 1222 } ··· 6571 6571 long hugetlb_reserve_pages(struct inode *inode, 6572 6572 long from, long to, 6573 6573 struct vm_area_desc *desc, 6574 - vm_flags_t vm_flags) 6574 + vma_flags_t vma_flags) 6575 6575 { 6576 6576 long chg = -1, add = -1, spool_resv, gbl_resv; 6577 6577 struct hstate *h = hstate_inode(inode); ··· 6592 6592 * attempt will be made for VM_NORESERVE to allocate a page 6593 6593 * without using reserves 6594 6594 */ 6595 - if (vm_flags & VM_NORESERVE) 6595 + if (vma_flags_test(&vma_flags, VMA_NORESERVE_BIT)) 6596 6596 return 0; 6597 6597 6598 6598 /* ··· 6601 6601 * to reserve the full area even if read-only as mprotect() may be 6602 6602 * called to make the mapping read-write. Assume !desc is a shm mapping 6603 6603 */ 6604 - if (!desc || desc->vm_flags & VM_MAYSHARE) { 6604 + if (!desc || vma_desc_test_flags(desc, VMA_MAYSHARE_BIT)) { 6605 6605 /* 6606 6606 * resv_map can not be NULL as hugetlb_reserve_pages is only 6607 6607 * called for inodes for which resv_maps were created (see ··· 6635 6635 if (err < 0) 6636 6636 goto out_err; 6637 6637 6638 - if (desc && !(desc->vm_flags & VM_MAYSHARE) && h_cg) { 6638 + if (desc && !vma_desc_test_flags(desc, VMA_MAYSHARE_BIT) && h_cg) { 6639 6639 /* For private mappings, the hugetlb_cgroup uncharge info hangs 6640 6640 * of the resv_map. 6641 6641 */ ··· 6672 6672 * consumed reservations are stored in the map. Hence, nothing 6673 6673 * else has to be done for private mappings here 6674 6674 */ 6675 - if (!desc || desc->vm_flags & VM_MAYSHARE) { 6675 + if (!desc || vma_desc_test_flags(desc, VMA_MAYSHARE_BIT)) { 6676 6676 add = region_add(resv_map, from, to, regions_needed, h, h_cg); 6677 6677 6678 6678 if (unlikely(add < 0)) { ··· 6727 6727 hugetlb_cgroup_uncharge_cgroup_rsvd(hstate_index(h), 6728 6728 chg * pages_per_huge_page(h), h_cg); 6729 6729 out_err: 6730 - if (!desc || desc->vm_flags & VM_MAYSHARE) 6730 + if (!desc || vma_desc_test_flags(desc, VMA_MAYSHARE_BIT)) 6731 6731 /* Only call region_abort if the region_chg succeeded but the 6732 6732 * region_add failed or didn't run. 6733 6733 */
+2 -2
mm/memfd.c
··· 86 86 gfp_mask &= ~(__GFP_HIGHMEM | __GFP_MOVABLE); 87 87 idx >>= huge_page_order(h); 88 88 89 - nr_resv = hugetlb_reserve_pages(inode, idx, idx + 1, NULL, 0); 89 + nr_resv = hugetlb_reserve_pages(inode, idx, idx + 1, NULL, EMPTY_VMA_FLAGS); 90 90 if (nr_resv < 0) 91 91 return ERR_PTR(nr_resv); 92 92 ··· 463 463 int err = 0; 464 464 465 465 if (flags & MFD_HUGETLB) { 466 - file = hugetlb_file_setup(name, 0, VM_NORESERVE, 466 + file = hugetlb_file_setup(name, 0, mk_vma_flags(VMA_NORESERVE_BIT), 467 467 HUGETLB_ANONHUGE_INODE, 468 468 (flags >> MFD_HUGE_SHIFT) & 469 469 MFD_HUGE_MASK);
+1 -1
mm/mmap.c
··· 594 594 * taken when vm_ops->mmap() is called 595 595 */ 596 596 file = hugetlb_file_setup(HUGETLB_ANON_FILE, len, 597 - VM_NORESERVE, 597 + mk_vma_flags(VMA_NORESERVE_BIT), 598 598 HUGETLB_ANONHUGE_INODE, 599 599 (flags >> MAP_HUGE_SHIFT) & MAP_HUGE_MASK); 600 600 if (IS_ERR(file))