mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 14:53:58 -04:00
Convert the test code to utilise vma_flags_t as opposed to the deprecate vm_flags_t as much as possible. As part of this change, add VMA_STICKY_FLAGS and VMA_SPECIAL_FLAGS as early versions of what these defines will look like in the kernel logic once this logic is implemented. Link: https://lkml.kernel.org/r/df90efe29300bd899989f695be4ae3adc901a828.1774034900.git.ljs@kernel.org Signed-off-by: Lorenzo Stoakes (Oracle) <ljs@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: Vlastimil Babka (SUSE) <vbabka@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>
132 lines
2.7 KiB
C
132 lines
2.7 KiB
C
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#include "shared.h"
|
|
|
|
|
|
bool fail_prealloc;
|
|
unsigned long mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
|
|
unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
|
|
unsigned long stack_guard_gap = 256UL<<PAGE_SHIFT;
|
|
|
|
const struct vm_operations_struct vma_dummy_vm_ops;
|
|
struct anon_vma dummy_anon_vma;
|
|
struct task_struct __current;
|
|
|
|
struct vm_area_struct *alloc_vma(struct mm_struct *mm,
|
|
unsigned long start, unsigned long end,
|
|
pgoff_t pgoff, vma_flags_t vma_flags)
|
|
{
|
|
struct vm_area_struct *vma = vm_area_alloc(mm);
|
|
|
|
if (vma == NULL)
|
|
return NULL;
|
|
|
|
vma->vm_start = start;
|
|
vma->vm_end = end;
|
|
vma->vm_pgoff = pgoff;
|
|
vma->flags = vma_flags;
|
|
vma_assert_detached(vma);
|
|
|
|
return vma;
|
|
}
|
|
|
|
void detach_free_vma(struct vm_area_struct *vma)
|
|
{
|
|
vma_mark_detached(vma);
|
|
vm_area_free(vma);
|
|
}
|
|
|
|
struct vm_area_struct *alloc_and_link_vma(struct mm_struct *mm,
|
|
unsigned long start, unsigned long end,
|
|
pgoff_t pgoff, vma_flags_t vma_flags)
|
|
{
|
|
struct vm_area_struct *vma = alloc_vma(mm, start, end, pgoff, vma_flags);
|
|
|
|
if (vma == NULL)
|
|
return NULL;
|
|
|
|
if (attach_vma(mm, vma)) {
|
|
detach_free_vma(vma);
|
|
return NULL;
|
|
}
|
|
|
|
/*
|
|
* Reset this counter which we use to track whether writes have
|
|
* begun. Linking to the tree will have caused this to be incremented,
|
|
* which means we will get a false positive otherwise.
|
|
*/
|
|
vma->vm_lock_seq = UINT_MAX;
|
|
|
|
return vma;
|
|
}
|
|
|
|
void reset_dummy_anon_vma(void)
|
|
{
|
|
dummy_anon_vma.was_cloned = false;
|
|
dummy_anon_vma.was_unlinked = false;
|
|
}
|
|
|
|
int cleanup_mm(struct mm_struct *mm, struct vma_iterator *vmi)
|
|
{
|
|
struct vm_area_struct *vma;
|
|
int count = 0;
|
|
|
|
fail_prealloc = false;
|
|
reset_dummy_anon_vma();
|
|
|
|
vma_iter_set(vmi, 0);
|
|
for_each_vma(*vmi, vma) {
|
|
detach_free_vma(vma);
|
|
count++;
|
|
}
|
|
|
|
mtree_destroy(&mm->mm_mt);
|
|
mm->map_count = 0;
|
|
return count;
|
|
}
|
|
|
|
bool vma_write_started(struct vm_area_struct *vma)
|
|
{
|
|
int seq = vma->vm_lock_seq;
|
|
|
|
/* We reset after each check. */
|
|
vma->vm_lock_seq = UINT_MAX;
|
|
|
|
/* The vma_start_write() stub simply increments this value. */
|
|
return seq > -1;
|
|
}
|
|
|
|
void __vma_set_dummy_anon_vma(struct vm_area_struct *vma,
|
|
struct anon_vma_chain *avc, struct anon_vma *anon_vma)
|
|
{
|
|
vma->anon_vma = anon_vma;
|
|
INIT_LIST_HEAD(&vma->anon_vma_chain);
|
|
list_add(&avc->same_vma, &vma->anon_vma_chain);
|
|
avc->anon_vma = vma->anon_vma;
|
|
}
|
|
|
|
void vma_set_dummy_anon_vma(struct vm_area_struct *vma,
|
|
struct anon_vma_chain *avc)
|
|
{
|
|
__vma_set_dummy_anon_vma(vma, avc, &dummy_anon_vma);
|
|
}
|
|
|
|
struct task_struct *get_current(void)
|
|
{
|
|
return &__current;
|
|
}
|
|
|
|
unsigned long rlimit(unsigned int limit)
|
|
{
|
|
return (unsigned long)-1;
|
|
}
|
|
|
|
void vma_set_range(struct vm_area_struct *vma,
|
|
unsigned long start, unsigned long end,
|
|
pgoff_t pgoff)
|
|
{
|
|
vma->vm_start = start;
|
|
vma->vm_end = end;
|
|
vma->vm_pgoff = pgoff;
|
|
}
|