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/vma: introduce vma_flags_same[_mask/_pair]()

Add helpers to determine if two sets of VMA flags are precisely the same,
that is - that every flag set one is set in another, and neither contain
any flags not set in the other.

We also introduce vma_flags_same_pair() for cases where we want to compare
two sets of VMA flags which are both non-const values.

Also update the VMA tests to reflect the change, we already implicitly
test that this functions correctly having used it for testing purposes
previously.

Link: https://lkml.kernel.org/r/4f764bf619e77205837c7c819b62139ef6337ca3.1774034900.git.ljs@kernel.org
Signed-off-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
Acked-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Alexandre Ghiti <alex@ghiti.fr>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Anton Ivanov <anton.ivanov@cambridgegreys.com>
Cc: "Borislav Petkov (AMD)" <bp@alien8.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Chengming Zhou <chengming.zhou@linux.dev>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Christian Brauner <brauner@kernel.org>
Cc: David Hildenbrand <david@kernel.org>
Cc: Dinh Nguyen <dinguyen@kernel.org>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Jann Horn <jannh@google.com>
Cc: Johannes Berg <johannes@sipsolutions.net>
Cc: Kees Cook <kees@kernel.org>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Ondrej Mosnacek <omosnace@redhat.com>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Paul Moore <paul@paul-moore.com>
Cc: Pedro Falcato <pfalcato@suse.de>
Cc: Richard Weinberger <richard@nod.at>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Stephen Smalley <stephen.smalley.work@gmail.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.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: xu xin <xu.xin16@zte.com.cn>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Lorenzo Stoakes (Oracle) and committed by
Andrew Morton
3ee58453 5fb55e95

+49 -11
+28
include/linux/mm.h
··· 1202 1202 return dst; 1203 1203 } 1204 1204 1205 + /* Determine if flags and flags_other have precisely the same flags set. */ 1206 + static __always_inline bool vma_flags_same_pair(const vma_flags_t *flags, 1207 + const vma_flags_t *flags_other) 1208 + { 1209 + const unsigned long *bitmap = flags->__vma_flags; 1210 + const unsigned long *bitmap_other = flags_other->__vma_flags; 1211 + 1212 + return bitmap_equal(bitmap, bitmap_other, NUM_VMA_FLAG_BITS); 1213 + } 1214 + 1215 + /* Determine if flags and flags_other have precisely the same flags set. */ 1216 + static __always_inline bool vma_flags_same_mask(const vma_flags_t *flags, 1217 + vma_flags_t flags_other) 1218 + { 1219 + const unsigned long *bitmap = flags->__vma_flags; 1220 + const unsigned long *bitmap_other = flags_other.__vma_flags; 1221 + 1222 + return bitmap_equal(bitmap, bitmap_other, NUM_VMA_FLAG_BITS); 1223 + } 1224 + 1225 + /* 1226 + * Helper macro to determine if only the specific flags are set, e.g.: 1227 + * 1228 + * if (vma_flags_same(&flags, VMA_WRITE_BIT) { ... } 1229 + */ 1230 + #define vma_flags_same(flags, ...) \ 1231 + vma_flags_same_mask(flags, mk_vma_flags(__VA_ARGS__)) 1232 + 1205 1233 /* 1206 1234 * Helper to test that ALL specified flags are set in a VMA. 1207 1235 *
-11
tools/testing/vma/include/custom.h
··· 102 102 return PAGE_SIZE; 103 103 } 104 104 105 - /* Place here until needed in the kernel code. */ 106 - static __always_inline bool vma_flags_same_mask(vma_flags_t *flags, 107 - vma_flags_t flags_other) 108 - { 109 - const unsigned long *bitmap = flags->__vma_flags; 110 - const unsigned long *bitmap_other = flags_other.__vma_flags; 111 - 112 - return bitmap_equal(bitmap, bitmap_other, NUM_VMA_FLAG_BITS); 113 - } 114 - #define vma_flags_same(flags, ...) \ 115 - vma_flags_same_mask(flags, mk_vma_flags(__VA_ARGS__)) 116 105 #define VMA_SPECIAL_FLAGS mk_vma_flags(VMA_IO_BIT, VMA_DONTEXPAND_BIT, \ 117 106 VMA_PFNMAP_BIT, VMA_MIXEDMAP_BIT)
+21
tools/testing/vma/include/dup.h
··· 954 954 return dst; 955 955 } 956 956 957 + static __always_inline bool vma_flags_same_pair(const vma_flags_t *flags, 958 + const vma_flags_t *flags_other) 959 + { 960 + const unsigned long *bitmap = flags->__vma_flags; 961 + const unsigned long *bitmap_other = flags_other->__vma_flags; 962 + 963 + return bitmap_equal(bitmap, bitmap_other, NUM_VMA_FLAG_BITS); 964 + } 965 + 966 + static __always_inline bool vma_flags_same_mask(const vma_flags_t *flags, 967 + vma_flags_t flags_other) 968 + { 969 + const unsigned long *bitmap = flags->__vma_flags; 970 + const unsigned long *bitmap_other = flags_other.__vma_flags; 971 + 972 + return bitmap_equal(bitmap, bitmap_other, NUM_VMA_FLAG_BITS); 973 + } 974 + 975 + #define vma_flags_same(flags, ...) \ 976 + vma_flags_same_mask(flags, mk_vma_flags(__VA_ARGS__)) 977 + 957 978 static inline bool vma_test_all_mask(const struct vm_area_struct *vma, 958 979 vma_flags_t flags) 959 980 {