mm: add basic tests for lazy_mmu

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.

[[email protected]: export ppc64_tlb_batch and __flush_tlb_pending to modules]
[[email protected]: use EXPORT_SYMBOL_IF_KUNIT()]
  Link: https://lkml.kernel.org/r/[email protected]
[[email protected]: move MODULE_IMPORT_NS(), add comment]
  Link: https://lkml.kernel.org/r/[email protected]
Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Kevin Brodsky <[email protected]>
Reviewed-by: Yeoreum Yun <[email protected]>
Signed-off-by: Ritesh Harjani (IBM) <[email protected]>
Acked-by: David Hildenbrand (Red Hat) <[email protected]>
Cc: Alexander Gordeev <[email protected]>
Cc: Andreas Larsson <[email protected]>
Cc: Anshuman Khandual <[email protected]>
Cc: Borislav Betkov <[email protected]>
Cc: Boris Ostrovsky <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Christophe Leroy <[email protected]>
Cc: David S. Miller <[email protected]>
Cc: David Woodhouse <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Jann Horn <[email protected]>
Cc: Juegren Gross <[email protected]>
Cc: Liam Howlett <[email protected]>
Cc: Lorenzo Stoakes <[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: Peter Zijlstra <[email protected]>
Cc: Ritesh Harjani (IBM) <[email protected]>
Cc: Ryan Roberts <[email protected]>
Cc: Suren Baghdasaryan <[email protected]>
Cc: Thomas Gleinxer <[email protected]>
Cc: Venkat Rao Bagalkote <[email protected]>
Cc: Vlastimil Babka <[email protected]>
Cc: Will Deacon <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
This commit is contained in:
Kevin Brodsky authored and Andrew Morton committed 2026-01-20 19:24:35 -08:00
1 parent 291b3abed6
commit ee628d9cc8
4 files changed
+90 -1

No files matched your search

+3 -1
View File
@@ -25,11 +25,12 @@
#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)
{
+12
View 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
+1
View 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
+74
View File
@@ -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");