mirror of
https://github.com/torvalds/linux.git
synced 2026-11-27 17:02:17 +00: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) <[email protected]> Acked-by: Vlastimil Babka (SUSE) <[email protected]> Cc: Albert Ou <[email protected]> Cc: Alexander Gordeev <[email protected]> Cc: Alexandre Ghiti <[email protected]> Cc: Al Viro <[email protected]> Cc: Anton Ivanov <[email protected]> Cc: "Borislav Petkov (AMD)" <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Chengming Zhou <[email protected]> Cc: Christian Borntraeger <[email protected]> Cc: Christian Brauner <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Dinh Nguyen <[email protected]> Cc: Heiko Carstens <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: Huacai Chen <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jan Kara <[email protected]> Cc: Jann Horn <[email protected]> Cc: Johannes Berg <[email protected]> Cc: Kees Cook <[email protected]> Cc: Liam Howlett <[email protected]> Cc: Madhavan Srinivasan <[email protected]> Cc: Michael Ellerman <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Mike Rapoport <[email protected]> Cc: Nicholas Piggin <[email protected]> Cc: Ondrej Mosnacek <[email protected]> Cc: Palmer Dabbelt <[email protected]> Cc: Paul Moore <[email protected]> Cc: Pedro Falcato <[email protected]> Cc: Richard Weinberger <[email protected]> Cc: Russell King <[email protected]> Cc: Stephen Smalley <[email protected]> Cc: Suren Baghdasaryan <[email protected]> Cc: Sven Schnelle <[email protected]> Cc: Thomas Bogendoerfer <[email protected]> Cc: Vasily Gorbik <[email protected]> Cc: Vineet Gupta <[email protected]> Cc: WANG Xuerui <[email protected]> Cc: Will Deacon <[email protected]> Cc: xu xin <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
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);
|
|
}
|