]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
mm: add basic tests for lazy_mmu
authorKevin Brodsky <kevin.brodsky@arm.com>
Mon, 15 Dec 2025 15:03:23 +0000 (15:03 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 21 Jan 2026 03:24:35 +0000 (19:24 -0800)
Add basic KUnit tests for the generic aspects of the lazy MMU mode: ensure
that it appears active when it should, depending on how enable/disable and
pause/resume pairs are nested.

[akpm@linux-foundation.org: export ppc64_tlb_batch and __flush_tlb_pending to modules]
[ritesh.list@gmail.com: use EXPORT_SYMBOL_IF_KUNIT()]
Link: https://lkml.kernel.org/r/87a4zhkt6h.ritesh.list@gmail.com
[kevin.brodsky@arm.com: move MODULE_IMPORT_NS(), add comment]
Link: https://lkml.kernel.org/r/20251217163812.2633648-2-kevin.brodsky@arm.com
Link: https://lkml.kernel.org/r/20251215150323.2218608-15-kevin.brodsky@arm.com
Signed-off-by: Kevin Brodsky <kevin.brodsky@arm.com>
Reviewed-by: Yeoreum Yun <yeoreum.yun@arm.com>
Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
Acked-by: David Hildenbrand (Red Hat) <david@kernel.org>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Andreas Larsson <andreas@gaisler.com>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Borislav Betkov <bp@alien8.de>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: David S. Miller <davem@davemloft.net>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jann Horn <jannh@google.com>
Cc: Juegren Gross <jgross@suse.com>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@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: Peter Zijlstra <peterz@infradead.org>
Cc: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Thomas Gleinxer <tglx@linutronix.de>
Cc: Venkat Rao Bagalkote <venkat88@linux.ibm.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
arch/powerpc/mm/book3s64/hash_tlb.c
mm/Kconfig
mm/Makefile
mm/tests/lazy_mmu_mode_kunit.c [new file with mode: 0644]

index fbdeb8981ae7b0651b00cc69ae6be41a426a516c..ec2941cec815b565c9ff18a52efe723d2d037b07 100644 (file)
 #include <asm/tlb.h>
 #include <asm/bug.h>
 #include <asm/pte-walk.h>
-
+#include <kunit/visibility.h>
 
 #include <trace/events/thp.h>
 
 DEFINE_PER_CPU(struct ppc64_tlb_batch, ppc64_tlb_batch);
+EXPORT_SYMBOL_IF_KUNIT(ppc64_tlb_batch);
 
 /*
  * A linux PTE was changed and the corresponding hash table entry
@@ -154,6 +155,7 @@ void __flush_tlb_pending(struct ppc64_tlb_batch *batch)
                flush_hash_range(i, local);
        batch->index = 0;
 }
+EXPORT_SYMBOL_IF_KUNIT(__flush_tlb_pending);
 
 void hash__tlb_flush(struct mmu_gather *tlb)
 {
index 7c2520e6a6b3006935da36e2243cd51e64d2ab4c..5f4d6e5b5715903b169bb6f3cc4f7b59e346c73e 100644 (file)
@@ -1475,6 +1475,18 @@ config ARCH_HAS_LAZY_MMU_MODE
          MMU-related architectural state to be deferred until the mode is
          exited. See <linux/pgtable.h> for details.
 
+config LAZY_MMU_MODE_KUNIT_TEST
+       tristate "KUnit tests for the lazy MMU mode" if !KUNIT_ALL_TESTS
+       depends on ARCH_HAS_LAZY_MMU_MODE
+       depends on KUNIT
+       default KUNIT_ALL_TESTS
+       help
+         Enable this option to check that the lazy MMU mode interface behaves
+         as expected. Only tests for the generic interface are included (not
+         architecture-specific behaviours).
+
+         If unsure, say N.
+
 source "mm/damon/Kconfig"
 
 endmenu
index 2d0570a16e5beb9d9257cb6138a5977631c626ab..9175f8cc65658e2cf61d94831dadd58191cf5514 100644 (file)
@@ -147,3 +147,4 @@ obj-$(CONFIG_SHRINKER_DEBUG) += shrinker_debug.o
 obj-$(CONFIG_EXECMEM) += execmem.o
 obj-$(CONFIG_TMPFS_QUOTA) += shmem_quota.o
 obj-$(CONFIG_PT_RECLAIM) += pt_reclaim.o
+obj-$(CONFIG_LAZY_MMU_MODE_KUNIT_TEST) += tests/lazy_mmu_mode_kunit.o
diff --git a/mm/tests/lazy_mmu_mode_kunit.c b/mm/tests/lazy_mmu_mode_kunit.c
new file mode 100644 (file)
index 0000000..1c23456
--- /dev/null
@@ -0,0 +1,74 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include <kunit/test.h>
+#include <linux/pgtable.h>
+
+/* For some symbols referenced by arch_{enter,leave}_lazy_mmu_mode on powerpc */
+MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING");
+
+static void expect_not_active(struct kunit *test)
+{
+       KUNIT_EXPECT_FALSE(test, is_lazy_mmu_mode_active());
+}
+
+static void expect_active(struct kunit *test)
+{
+       KUNIT_EXPECT_TRUE(test, is_lazy_mmu_mode_active());
+}
+
+static void lazy_mmu_mode_active(struct kunit *test)
+{
+       expect_not_active(test);
+
+       lazy_mmu_mode_enable();
+       expect_active(test);
+
+       {
+               /* Nested section */
+               lazy_mmu_mode_enable();
+               expect_active(test);
+
+               lazy_mmu_mode_disable();
+               expect_active(test);
+       }
+
+       {
+               /* Paused section */
+               lazy_mmu_mode_pause();
+               expect_not_active(test);
+
+               {
+                       /* No effect (paused) */
+                       lazy_mmu_mode_enable();
+                       expect_not_active(test);
+
+                       lazy_mmu_mode_disable();
+                       expect_not_active(test);
+
+                       lazy_mmu_mode_pause();
+                       expect_not_active(test);
+
+                       lazy_mmu_mode_resume();
+                       expect_not_active(test);
+               }
+
+               lazy_mmu_mode_resume();
+               expect_active(test);
+       }
+
+       lazy_mmu_mode_disable();
+       expect_not_active(test);
+}
+
+static struct kunit_case lazy_mmu_mode_test_cases[] = {
+       KUNIT_CASE(lazy_mmu_mode_active),
+       {}
+};
+
+static struct kunit_suite lazy_mmu_mode_test_suite = {
+       .name = "lazy_mmu_mode",
+       .test_cases = lazy_mmu_mode_test_cases,
+};
+kunit_test_suite(lazy_mmu_mode_test_suite);
+
+MODULE_DESCRIPTION("Tests for the lazy MMU mode");
+MODULE_LICENSE("GPL");