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: reintroduce vma_flags_test() as a singular flag test

Since we've now renamed vma_flags_test() to vma_flags_test_any() to be
very clear as to what we are in fact testing, we now have the opportunity
to bring vma_flags_test() back, but for explicitly testing a single VMA
flag.

This is useful, as often flag tests are against a single flag, and
vma_flags_test_any(flags, VMA_READ_BIT) reads oddly and potentially causes
confusion.

We use sparse to enforce that users won't accidentally pass vm_flags_t to
this function without it being flagged so this should make it harder to
get this wrong.

Of course, passing vma_flags_t to the function is impossible, as it is a
struct.

Also update the VMA tests to reflect this change.

Link: https://lkml.kernel.org/r/f33f8d7f16c3f3d286a1dc2cba12c23683073134.1772704455.git.ljs@kernel.org
Signed-off-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Reviewed-by: Pedro Falcato <pfalcato@suse.de>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Babu Moger <babu.moger@amd.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Chao Yu <chao@kernel.org>
Cc: Chatre, Reinette <reinette.chatre@intel.com>
Cc: Chunhai Guo <guochunhai@vivo.com>
Cc: Damien Le Maol <dlemoal@kernel.org>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Dave Jiang <dave.jiang@intel.com>
Cc: Dave Martin <dave.martin@arm.com>
Cc: Gao Xiang <xiang@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Hongbo Li <lihongbo22@huawei.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: James Morse <james.morse@arm.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Jann Horn <jannh@google.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Jeffle Xu <jefflexu@linux.alibaba.com>
Cc: Johannes Thumshirn <jth@kernel.org>
Cc: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: "Luck, Tony" <tony.luck@intel.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Naohiro Aota <naohiro.aota@wdc.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Sandeep Dhavale <dhavale@google.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vishal Verma <vishal.l.verma@intel.com>
Cc: Vlastimil Babka <vbabka@kernel.org>
Cc: Yue Hu <zbestahu@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Lorenzo Stoakes (Oracle) and committed by
Andrew Morton
5e6d45d7 a5eee112

+26 -5
+15 -2
include/linux/mm.h
··· 1051 1051 } 1052 1052 1053 1053 /* 1054 + * Test whether a specific VMA flag is set, e.g.: 1055 + * 1056 + * if (vma_flags_test(flags, VMA_READ_BIT)) { ... } 1057 + */ 1058 + static __always_inline bool vma_flags_test(const vma_flags_t *flags, 1059 + vma_flag_t bit) 1060 + { 1061 + const unsigned long *bitmap = flags->__vma_flags; 1062 + 1063 + return test_bit((__force int)bit, bitmap); 1064 + } 1065 + 1066 + /* 1054 1067 * Helper macro which bitwise-or combines the specified input flags into a 1055 1068 * vma_flags_t bitmap value. E.g.: 1056 1069 * ··· 1969 1956 { 1970 1957 const vma_flags_t *flags = &desc->vma_flags; 1971 1958 1972 - return vma_flags_test_any(flags, VMA_MAYWRITE_BIT) && 1973 - !vma_flags_test_any(flags, VMA_SHARED_BIT); 1959 + return vma_flags_test(flags, VMA_MAYWRITE_BIT) && 1960 + !vma_flags_test(flags, VMA_SHARED_BIT); 1974 1961 } 1975 1962 1976 1963 #ifndef CONFIG_MMU
+1 -1
mm/hugetlb.c
··· 6593 6593 * attempt will be made for VM_NORESERVE to allocate a page 6594 6594 * without using reserves 6595 6595 */ 6596 - if (vma_flags_test_any(&vma_flags, VMA_NORESERVE_BIT)) 6596 + if (vma_flags_test(&vma_flags, VMA_NORESERVE_BIT)) 6597 6597 return 0; 6598 6598 6599 6599 /*
+2 -2
mm/shmem.c
··· 3086 3086 spin_lock_init(&info->lock); 3087 3087 atomic_set(&info->stop_eviction, 0); 3088 3088 info->seals = F_SEAL_SEAL; 3089 - info->flags = vma_flags_test_any(&flags, VMA_NORESERVE_BIT) 3089 + info->flags = vma_flags_test(&flags, VMA_NORESERVE_BIT) 3090 3090 ? SHMEM_F_NORESERVE : 0; 3091 3091 info->i_crtime = inode_get_mtime(inode); 3092 3092 info->fsflags = (dir == NULL) ? 0 : ··· 5827 5827 unsigned int i_flags) 5828 5828 { 5829 5829 const unsigned long shmem_flags = 5830 - vma_flags_test_any(&flags, VMA_NORESERVE_BIT) ? SHMEM_F_NORESERVE : 0; 5830 + vma_flags_test(&flags, VMA_NORESERVE_BIT) ? SHMEM_F_NORESERVE : 0; 5831 5831 struct inode *inode; 5832 5832 struct file *res; 5833 5833
+8
tools/testing/vma/include/dup.h
··· 844 844 #define mk_vma_flags(...) __mk_vma_flags(COUNT_ARGS(__VA_ARGS__), \ 845 845 (const vma_flag_t []){__VA_ARGS__}) 846 846 847 + static __always_inline bool vma_flags_test(const vma_flags_t *flags, 848 + vma_flag_t bit) 849 + { 850 + const unsigned long *bitmap = flags->__vma_flags; 851 + 852 + return test_bit((__force int)bit, bitmap); 853 + } 854 + 847 855 static __always_inline bool vma_flags_test_any_mask(const vma_flags_t *flags, 848 856 vma_flags_t to_test) 849 857 {