mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 14:53:58 -04:00
mm/vma: introduce vma_test[_any[_mask]](), and make inlining consistent
Introduce helper functions and macros to make it convenient to test flags and flag masks for VMAs, specifically: * vma_test() - determine if a single VMA flag is set in a VMA. * vma_test_any_mask() - determine if any flags in a vma_flags_t value are set in a VMA. * vma_test_any() - Helper macro to test if any of specific flags are set. Also, there are a mix of 'inline's and '__always_inline's in VMA helper function declarations, update to consistently use __always_inline. Finally, update the VMA tests to reflect the changes. Link: https://lkml.kernel.org/r/be1d71f08307d747a82232cbd8664a88c0f41419.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>
This commit is contained in:
committed by
Andrew Morton
parent
a8add93f80
commit
fb67bba5d9
@@ -764,7 +764,8 @@ static inline bool mm_flags_test(int flag, const struct mm_struct *mm)
|
||||
* IMPORTANT: This does not overwrite bytes past the first system word. The
|
||||
* caller must account for this.
|
||||
*/
|
||||
static inline void vma_flags_overwrite_word(vma_flags_t *flags, unsigned long value)
|
||||
static __always_inline void vma_flags_overwrite_word(vma_flags_t *flags,
|
||||
unsigned long value)
|
||||
{
|
||||
unsigned long *bitmap = flags->__vma_flags;
|
||||
|
||||
@@ -777,7 +778,8 @@ static inline void vma_flags_overwrite_word(vma_flags_t *flags, unsigned long va
|
||||
* IMPORTANT: This does not overwrite bytes past the first system word. The
|
||||
* caller must account for this.
|
||||
*/
|
||||
static inline void vma_flags_overwrite_word_once(vma_flags_t *flags, unsigned long value)
|
||||
static __always_inline void vma_flags_overwrite_word_once(vma_flags_t *flags,
|
||||
unsigned long value)
|
||||
{
|
||||
unsigned long *bitmap = flags->__vma_flags;
|
||||
|
||||
@@ -785,7 +787,8 @@ static inline void vma_flags_overwrite_word_once(vma_flags_t *flags, unsigned lo
|
||||
}
|
||||
|
||||
/* Update the first system word of VMA flags setting bits, non-atomically. */
|
||||
static inline void vma_flags_set_word(vma_flags_t *flags, unsigned long value)
|
||||
static __always_inline void vma_flags_set_word(vma_flags_t *flags,
|
||||
unsigned long value)
|
||||
{
|
||||
unsigned long *bitmap = flags->__vma_flags;
|
||||
|
||||
@@ -793,7 +796,8 @@ static inline void vma_flags_set_word(vma_flags_t *flags, unsigned long value)
|
||||
}
|
||||
|
||||
/* Update the first system word of VMA flags clearing bits, non-atomically. */
|
||||
static inline void vma_flags_clear_word(vma_flags_t *flags, unsigned long value)
|
||||
static __always_inline void vma_flags_clear_word(vma_flags_t *flags,
|
||||
unsigned long value)
|
||||
{
|
||||
unsigned long *bitmap = flags->__vma_flags;
|
||||
|
||||
@@ -1003,8 +1007,23 @@ static __always_inline bool vma_flags_same_mask(const vma_flags_t *flags,
|
||||
#define vma_flags_same(flags, ...) \
|
||||
vma_flags_same_mask(flags, mk_vma_flags(__VA_ARGS__))
|
||||
|
||||
static inline bool vma_test_all_mask(const struct vm_area_struct *vma,
|
||||
vma_flags_t flags)
|
||||
static __always_inline bool vma_test(const struct vm_area_struct *vma,
|
||||
vma_flag_t bit)
|
||||
{
|
||||
return vma_flags_test(&vma->flags, bit);
|
||||
}
|
||||
|
||||
static __always_inline bool vma_test_any_mask(const struct vm_area_struct *vma,
|
||||
vma_flags_t flags)
|
||||
{
|
||||
return vma_flags_test_any_mask(&vma->flags, flags);
|
||||
}
|
||||
|
||||
#define vma_test_any(vma, ...) \
|
||||
vma_test_any_mask(vma, mk_vma_flags(__VA_ARGS__))
|
||||
|
||||
static __always_inline bool vma_test_all_mask(const struct vm_area_struct *vma,
|
||||
vma_flags_t flags)
|
||||
{
|
||||
return vma_flags_test_all_mask(&vma->flags, flags);
|
||||
}
|
||||
@@ -1012,14 +1031,8 @@ static inline bool vma_test_all_mask(const struct vm_area_struct *vma,
|
||||
#define vma_test_all(vma, ...) \
|
||||
vma_test_all_mask(vma, mk_vma_flags(__VA_ARGS__))
|
||||
|
||||
static inline bool is_shared_maywrite_vm_flags(vm_flags_t vm_flags)
|
||||
{
|
||||
return (vm_flags & (VM_SHARED | VM_MAYWRITE)) ==
|
||||
(VM_SHARED | VM_MAYWRITE);
|
||||
}
|
||||
|
||||
static inline void vma_set_flags_mask(struct vm_area_struct *vma,
|
||||
vma_flags_t flags)
|
||||
static __always_inline void vma_set_flags_mask(struct vm_area_struct *vma,
|
||||
vma_flags_t flags)
|
||||
{
|
||||
vma_flags_set_mask(&vma->flags, flags);
|
||||
}
|
||||
@@ -1033,8 +1046,8 @@ static __always_inline bool vma_desc_test(const struct vm_area_desc *desc,
|
||||
return vma_flags_test(&desc->vma_flags, bit);
|
||||
}
|
||||
|
||||
static inline bool vma_desc_test_any_mask(const struct vm_area_desc *desc,
|
||||
vma_flags_t flags)
|
||||
static __always_inline bool vma_desc_test_any_mask(const struct vm_area_desc *desc,
|
||||
vma_flags_t flags)
|
||||
{
|
||||
return vma_flags_test_any_mask(&desc->vma_flags, flags);
|
||||
}
|
||||
@@ -1042,7 +1055,7 @@ static inline bool vma_desc_test_any_mask(const struct vm_area_desc *desc,
|
||||
#define vma_desc_test_any(desc, ...) \
|
||||
vma_desc_test_any_mask(desc, mk_vma_flags(__VA_ARGS__))
|
||||
|
||||
static inline bool vma_desc_test_all_mask(const struct vm_area_desc *desc,
|
||||
static __always_inline bool vma_desc_test_all_mask(const struct vm_area_desc *desc,
|
||||
vma_flags_t flags)
|
||||
{
|
||||
return vma_flags_test_all_mask(&desc->vma_flags, flags);
|
||||
@@ -1051,8 +1064,8 @@ static inline bool vma_desc_test_all_mask(const struct vm_area_desc *desc,
|
||||
#define vma_desc_test_all(desc, ...) \
|
||||
vma_desc_test_all_mask(desc, mk_vma_flags(__VA_ARGS__))
|
||||
|
||||
static inline void vma_desc_set_flags_mask(struct vm_area_desc *desc,
|
||||
vma_flags_t flags)
|
||||
static __always_inline void vma_desc_set_flags_mask(struct vm_area_desc *desc,
|
||||
vma_flags_t flags)
|
||||
{
|
||||
vma_flags_set_mask(&desc->vma_flags, flags);
|
||||
}
|
||||
@@ -1060,8 +1073,8 @@ static inline void vma_desc_set_flags_mask(struct vm_area_desc *desc,
|
||||
#define vma_desc_set_flags(desc, ...) \
|
||||
vma_desc_set_flags_mask(desc, mk_vma_flags(__VA_ARGS__))
|
||||
|
||||
static inline void vma_desc_clear_flags_mask(struct vm_area_desc *desc,
|
||||
vma_flags_t flags)
|
||||
static __always_inline void vma_desc_clear_flags_mask(struct vm_area_desc *desc,
|
||||
vma_flags_t flags)
|
||||
{
|
||||
vma_flags_clear_mask(&desc->vma_flags, flags);
|
||||
}
|
||||
@@ -1069,6 +1082,12 @@ static inline void vma_desc_clear_flags_mask(struct vm_area_desc *desc,
|
||||
#define vma_desc_clear_flags(desc, ...) \
|
||||
vma_desc_clear_flags_mask(desc, mk_vma_flags(__VA_ARGS__))
|
||||
|
||||
static inline bool is_shared_maywrite_vm_flags(vm_flags_t vm_flags)
|
||||
{
|
||||
return (vm_flags & (VM_SHARED | VM_MAYWRITE)) ==
|
||||
(VM_SHARED | VM_MAYWRITE);
|
||||
}
|
||||
|
||||
static inline bool is_shared_maywrite(const vma_flags_t *flags)
|
||||
{
|
||||
return vma_flags_test_all(flags, VMA_SHARED_BIT, VMA_MAYWRITE_BIT);
|
||||
|
||||
Reference in New Issue
Block a user