Thread (30 messages) flat view 30 messages, 2 authors, 2d ago

Re: [PATCH v5 3/3] kselftest: mm: introduce alloc_isolated_mem()

From: "David Hildenbrand (Arm)" <david@kernel.org>
Date: 2026-09-10 11:55:08
Also in: linux-mm, lkml
Subsystem: kernel selftest framework, memory management - misc, the rest · Maintainers: Shuah Khan, Shuah Khan, Andrew Morton, David Hildenbrand, Linus Torvalds

On 9/10/26 13:30, Yeoreum Yun wrote:
quoted
On 9/10/26 13:22, Yeoreum Yun wrote:
quoted
As I mentioned in my previous reply, what I’m trying to prevent here is
a failure when checking, immediately after memory allocation,
that a specific vm_flag is not set.

Yes, I agree that this could have been a problem even before
the internal changes to memalign(). An unwanted VMA merge could already
occur at the time of memory allocation.

So what I’m trying to avoid is a test failure where, due to such an
unexpected VMA merge during allocation, the subsequent check that
a specific vm_flag is not present fails.
Which is only a guard-region marker problem?
Yes. so if we remove ASSERT_FALSE(check_vmflag_guard(ptr)), TBH
we don't need this patch unless other usage comes up to prevent unwanted
VMA merge.

Would it be better to drop ASSERT_FALSE(check_vmflag_guard(ptr)) in
guard test?
I guess there is value in asserting that not all VMAs by accident start
with an over-indication of maybe having guard pages, which is why Lorenzo
added that check :)

But I think even alloc_isolated_mem() is wrong in that regard: if the
original VMA gets merged, we could inherit the guard-marker, no?

Maybe the following would be good enough?
diff --git a/tools/testing/selftests/mm/guard-regions.c b/tools/testing/selftests/mm/guard-regions.c
index 5c8ec3ca75d7d..791bf6a68b9e6 100644
--- a/tools/testing/selftests/mm/guard-regions.c
+++ b/tools/testing/selftests/mm/guard-regions.c
@@ -2257,10 +2257,20 @@ TEST_F(guard_regions, smaps)
        char *ptr, *ptr2;
        int i;

-       /* Map a region. */
-       ptr = mmap_(self, variant, NULL, 10 * page_size, PROT_READ | PROT_WRITE, 0, 0);
+       /* Reserve a 10 page region with 1 page space to both sides. */
+       ptr = mmap_(self, variant, NULL, 12 * page_size, PROT_NONE, 0, 0);
        ASSERT_NE(ptr, MAP_FAILED);

+       /* Map a new region that is guaranteed to not get merged in any way. */
+       ptr = mmap_(self, variant | MAP_FIXED, ptr + pagesize, 10 * page_size,
+                   PROT_READ | PROT_WRITE, 0, 0);
+       ASSERT_EQ(ptr, ptr + pagesize);
+
+       /* Clean up the excess pages left and right. */
+       munmap(ptr, pagesize);
+       munmap(ptr + 11, pagesize);
+       ptr + = pagesize;
+
        /* We shouldn't yet see a guard flag. */
        ASSERT_FALSE(check_vmflag_guard(ptr));
-- 
Cheers,

David
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help