mirror of
https://github.com/torvalds/linux.git
synced 2026-05-13 00:28:54 +02:00
vma_flags_count() determines how many bits are set in VMA flags, using bitmap_weight(). vma_flags_test_single_mask() determines if a vma_flags_t set of flags contains a single flag specified as another vma_flags_t value, or if the sought flag mask is empty, it is defined to return false. This is useful when we want to declare a VMA flag as optionally a single flag in a mask or empty depending on kernel configuration. This allows us to have VM_NONE-like semantics when checking whether the flag is set. In a subsequent patch, we introduce the use of VMA_DROPPABLE of type vma_flags_t using precisely these semantics. It would be actively confusing to use vma_flags_test_any_single_mask() for this (and vma_flags_test_all_mask() is not correct to use here, as it trivially returns true when tested against an empty vma flags mask). We introduce vma_flags_count() to be able to assert that the compared flag mask is singular or empty, checked when CONFIG_DEBUG_VM is enabled. Also update the VMA tests as part of this change. Link: https://lkml.kernel.org/r/cd778dd02b9f2a01eb54d25a49dea8ec2ddf7753.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>
65 lines
1.6 KiB
C
65 lines
1.6 KiB
C
/* SPDX-License-Identifier: GPL-2.0+ */
|
|
/*
|
|
* vma_internal.h
|
|
*
|
|
* Header providing userland wrappers and shims for the functionality provided
|
|
* by mm/vma_internal.h.
|
|
*
|
|
* We make the header guard the same as mm/vma_internal.h, so if this shim
|
|
* header is included, it precludes the inclusion of the kernel one.
|
|
*/
|
|
|
|
#ifndef __MM_VMA_INTERNAL_H
|
|
#define __MM_VMA_INTERNAL_H
|
|
|
|
#include <stdlib.h>
|
|
|
|
#define CONFIG_MMU
|
|
#define CONFIG_PER_VMA_LOCK
|
|
|
|
#ifdef __CONCAT
|
|
#undef __CONCAT
|
|
#endif
|
|
|
|
#include <linux/args.h>
|
|
#include <linux/atomic.h>
|
|
#include <linux/bitmap.h>
|
|
#include <linux/list.h>
|
|
#include <linux/maple_tree.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/rbtree.h>
|
|
#include <linux/refcount.h>
|
|
#include <linux/slab.h>
|
|
|
|
/*
|
|
* DUPLICATE typedef definitions from kernel source that have to be declared
|
|
* ahead of all other headers.
|
|
*/
|
|
#define __private
|
|
/* NUM_MM_FLAG_BITS defined by test code. */
|
|
typedef struct {
|
|
__private DECLARE_BITMAP(__mm_flags, NUM_MM_FLAG_BITS);
|
|
} mm_flags_t;
|
|
/* NUM_VMA_FLAG_BITS defined by test code. */
|
|
typedef struct {
|
|
DECLARE_BITMAP(__vma_flags, NUM_VMA_FLAG_BITS);
|
|
} __private vma_flags_t;
|
|
|
|
typedef unsigned long vm_flags_t;
|
|
#define pgoff_t unsigned long
|
|
typedef unsigned long pgprotval_t;
|
|
typedef struct pgprot { pgprotval_t pgprot; } pgprot_t;
|
|
typedef __bitwise unsigned int vm_fault_t;
|
|
|
|
#define VM_WARN_ON(_expr) (WARN_ON(_expr))
|
|
#define VM_WARN_ON_ONCE(_expr) (WARN_ON_ONCE(_expr))
|
|
#define VM_WARN_ON_VMG(_expr, _vmg) (WARN_ON(_expr))
|
|
#define VM_BUG_ON(_expr) (BUG_ON(_expr))
|
|
#define VM_BUG_ON_VMA(_expr, _vma) (BUG_ON(_expr))
|
|
|
|
#include "include/stubs.h"
|
|
#include "include/dup.h"
|
|
#include "include/custom.h"
|
|
|
|
#endif /* __MM_VMA_INTERNAL_H */
|