mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-05-16 11:21:26 -04:00
Update the mmap() implementation logic implemented in __mmap_region() and functions invoked by it. The mmap_region() function converts its input vm_flags_t parameter to a vma_flags_t value which it then passes to __mmap_region() which uses the vma_flags_t value consistently from then on. As part of the change, we convert map_deny_write_exec() to using vma_flags_t (it was incorrectly using unsigned long before), and place it in vma.h, as it is only used internal to mm. With this change, we eliminate the legacy is_shared_maywrite_vm_flags() helper function which is now no longer required. We are also able to update the MMAP_STATE() and VMG_MMAP_STATE() macros to use the vma_flags_t value. Finally, we update the VMA tests to reflect the change. Link: https://lkml.kernel.org/r/1fc33a404c962f02da778da100387cc19bd62153.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>
52 lines
1.3 KiB
C
52 lines
1.3 KiB
C
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
static bool test_mmap_region_basic(void)
|
|
{
|
|
const vma_flags_t vma_flags = mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT,
|
|
VMA_MAYREAD_BIT, VMA_MAYWRITE_BIT);
|
|
struct mm_struct mm = {};
|
|
unsigned long addr;
|
|
struct vm_area_struct *vma;
|
|
VMA_ITERATOR(vmi, &mm, 0);
|
|
|
|
current->mm = &mm;
|
|
|
|
/* Map at 0x300000, length 0x3000. */
|
|
addr = __mmap_region(NULL, 0x300000, 0x3000, vma_flags, 0x300, NULL);
|
|
ASSERT_EQ(addr, 0x300000);
|
|
|
|
/* Map at 0x250000, length 0x3000. */
|
|
addr = __mmap_region(NULL, 0x250000, 0x3000, vma_flags, 0x250, NULL);
|
|
ASSERT_EQ(addr, 0x250000);
|
|
|
|
/* Map at 0x303000, merging to 0x300000 of length 0x6000. */
|
|
addr = __mmap_region(NULL, 0x303000, 0x3000, vma_flags, 0x303, NULL);
|
|
ASSERT_EQ(addr, 0x303000);
|
|
|
|
/* Map at 0x24d000, merging to 0x250000 of length 0x6000. */
|
|
addr = __mmap_region(NULL, 0x24d000, 0x3000, vma_flags, 0x24d, NULL);
|
|
ASSERT_EQ(addr, 0x24d000);
|
|
|
|
ASSERT_EQ(mm.map_count, 2);
|
|
|
|
for_each_vma(vmi, vma) {
|
|
if (vma->vm_start == 0x300000) {
|
|
ASSERT_EQ(vma->vm_end, 0x306000);
|
|
ASSERT_EQ(vma->vm_pgoff, 0x300);
|
|
} else if (vma->vm_start == 0x24d000) {
|
|
ASSERT_EQ(vma->vm_end, 0x253000);
|
|
ASSERT_EQ(vma->vm_pgoff, 0x24d);
|
|
} else {
|
|
ASSERT_FALSE(true);
|
|
}
|
|
}
|
|
|
|
cleanup_mm(&mm, &vmi);
|
|
return true;
|
|
}
|
|
|
|
static void run_mmap_tests(int *num_tests, int *num_fail)
|
|
{
|
|
TEST(mmap_region_basic);
|
|
}
|