Skip to contentSkip to conversation

mm/debug: Add tests for architecture exported page table helpers

PATCH Superseded Anshuman Khandual 3 participants 9 messages Oct 7, 2019 – Oct 8, 2019

Subsystems (8)
Memory management x86 MIPS MM core +4 more subsystems

v4 of 18 Superseded Latest is v18 →

lore
Share & tools
lore
#0 lore raw

v4 cover mm/debug: Add tests for architecture exported page table helpers

This series adds a test validation for architecture exported page table helpers. Patch in the series adds basic transformation tests at various levels of the page table. Before that it exports gigantic page allocation function from HugeTLB.

This test was originally suggested by Catalin during arm64 THP migration RFC discussion earlier. Going forward it can include more specific tests with respect to various generic MM functions like THP, HugeTLB etc and platform specific tests.

https://lore.kernel.org/linux-mm/20190628102003.GA56463 at arrakis.emea.arm.com/

Changes in V4:

- Disable DEBUG_ARCH_PGTABLE_TEST for ARM and IA64 platforms

Changes in V3: (https://lore.kernel.org/patchwork/project/lkml/list/?series=411216)

- Changed test trigger from module format into late_initcall()
- Marked all functions with __init to be freed after completion
- Changed all __PGTABLE_PXX_FOLDED checks as mm_pxx_folded()
- Folded in PPC32 fixes from Christophe

Changes in V2:

https://lore.kernel.org/linux-mm/1568268173-31302-1-git-send-email-anshuman.khandual at arm.com/T/#t

- Fixed small typo error in MODULE_DESCRIPTION()
- Fixed m64k build problems for lvalue concerns in pmd_xxx_tests()
- Fixed dynamic page table level folding problems on x86 as per Kirril
- Fixed second pointers during pxx_populate_tests() per Kirill and Gerald
- Allocate and free pte table with pte_alloc_one/pte_free per Kirill
- Modified pxx_clear_tests() to accommodate s390 lower 12 bits situation
- Changed RANDOM_NZVALUE value from 0xbe to 0xff
- Changed allocation, usage, free sequence for saved_ptep
- Renamed VMA_FLAGS as VMFLAGS
- Implemented a new method for random vaddr generation
- Implemented some other cleanups
- Dropped extern reference to mm_alloc()
- Created and exported new alloc_gigantic_page_order()
- Dropped the custom allocator and used new alloc_gigantic_page_order()

Changes in V1:

https://lore.kernel.org/linux-mm/1567497706-8649-1-git-send-email-anshuman.khandual at arm.com/

- Added fallback mechanism for PMD aligned memory allocation failure

Changes in RFC V2:

https://lore.kernel.org/linux-mm/1565335998-22553-1-git-send-email-anshuman.khandual at arm.com/T/#u

- Moved test module and it's config from lib/ to mm/
- Renamed config TEST_ARCH_PGTABLE as DEBUG_ARCH_PGTABLE_TEST
- Renamed file from test_arch_pgtable.c to arch_pgtable_test.c
- Added relevant MODULE_DESCRIPTION() and MODULE_AUTHOR() details
- Dropped loadable module config option
- Basic tests now use memory blocks with required size and alignment
- PUD aligned memory block gets allocated with alloc_contig_range()
- If PUD aligned memory could not be allocated it falls back on PMD aligned memory block from page allocator and pud_* tests are skipped
- Clear and populate tests now operate on real in memory page table entries
- Dummy mm_struct gets allocated with mm_alloc()
- Dummy page table entries get allocated with [pud|pmd|pte]_alloc_[map]()
- Simplified [p4d|pgd]_basic_tests(), now has random values in the entries

Original RFC V1:

https://lore.kernel.org/linux-mm/1564037723-26676-1-git-send-email-anshuman.khandual at arm.com/

Cc Andrew Morton <akpm at linux-foundation.org>
Cc Vlastimil Babka <vbabka at suse.cz>
Cc Greg Kroah-Hartman <gregkh at linuxfoundation.org>
Cc Thomas Gleixner <tglx at linutronix.de>
Cc Mike Rapoport <rppt at linux.vnet.ibm.com>
Cc Jason Gunthorpe <jgg at ziepe.ca>
Cc Dan Williams <dan.j.williams at intel.com>
Cc Peter Zijlstra <peterz at infradead.org>
Cc Michal Hocko <mhocko at kernel.org>
Cc Mark Rutland <mark.rutland at arm.com>
Cc Mark Brown <broonie at kernel.org>
Cc Steven Price <Steven.Price at arm.com>
Cc Ard Biesheuvel <ard.biesheuvel at linaro.org>
Cc Masahiro Yamada <yamada.masahiro at socionext.com>
Cc Kees Cook <keescook at chromium.org>
Cc Tetsuo Handa <penguin-kernel at i-love.sakura.ne.jp>
Cc Matthew Wilcox <willy at infradead.org>
Cc Sri Krishna chowdary <schowdary at nvidia.com>
Cc Dave Hansen <dave.hansen at intel.com>
Cc Russell King - ARM Linux <linux at armlinux.org.uk>
Cc Michael Ellerman <mpe at ellerman.id.au>
Cc Paul Mackerras <paulus at samba.org>
Cc Martin Schwidefsky <schwidefsky at de.ibm.com>
Cc Heiko Carstens <heiko.carstens at de.ibm.com>
Cc "David S. Miller" <davem at davemloft.net>
Cc Vineet Gupta <vgupta at synopsys.com>
Cc James Hogan <jhogan at kernel.org>
Cc Paul Burton <paul.burton at mips.com>
Cc Ralf Baechle <ralf at linux-mips.org>
Cc Kirill A. Shutemov <kirill at shutemov.name>
Cc Gerald Schaefer <gerald.schaefer at de.ibm.com>
Cc Christophe Leroy <christophe.leroy at c-s.fr>
Cc Mike Kravetz <mike.kravetz at oracle.com>
Cc linux-snps-arc at lists.infradead.org
Cc linux-mips at vger.kernel.org
Cc linux-arm-kernel at lists.infradead.org
Cc linux-ia64 at vger.kernel.org
Cc linuxppc-dev at lists.ozlabs.org
Cc linux-s390 at vger.kernel.org
Cc linux-sh at vger.kernel.org
Cc sparclinux at vger.kernel.org
Cc x86 at kernel.org
Cc linux-kernel at vger.kernel.org

Anshuman Khandual (2):
mm/hugetlb: Make alloc_gigantic_page() available for general use mm/pgtable/debug: Add test validating architecture page table helpers

 arch/x86/include/asm/pgtable_64_types.h |   2 +
 include/linux/hugetlb.h                 |   9 +
 mm/Kconfig.debug                        |  15 +
 mm/Makefile                             |   1 +
 mm/arch_pgtable_test.c                  | 440 ++++++++++++++++++++++++
 mm/hugetlb.c                            |  24 +-
 6 files changed, 489 insertions(+), 2 deletions(-)
 create mode 100644 mm/arch_pgtable_test.c
Signature · 1 line
2.20.1
#1 lore raw

PATCH v4 1/2 mm/hugetlb: Make alloc_gigantic_page() available for general use

alloc_gigantic_page() implements an allocation method where it scans over various zones looking for a large contiguous memory block which could not have been allocated through the buddy allocator. A subsequent patch which tests arch page table helpers needs such a method to allocate PUD_SIZE sized memory block. In the future such methods might have other use cases as well. So alloc_gigantic_page() has been split carving out actual memory allocation method and made available via new alloc_gigantic_page_order().

Cc Andrew Morton <akpm at linux-foundation.org>
Cc Vlastimil Babka <vbabka at suse.cz>
Cc Greg Kroah-Hartman <gregkh at linuxfoundation.org>
Cc Thomas Gleixner <tglx at linutronix.de>
Cc Mike Rapoport <rppt at linux.vnet.ibm.com>
Cc Mike Kravetz <mike.kravetz at oracle.com>
Cc Jason Gunthorpe <jgg at ziepe.ca>
Cc Dan Williams <dan.j.williams at intel.com>
Cc Peter Zijlstra <peterz at infradead.org>
Cc Michal Hocko <mhocko at kernel.org>
Cc Mark Rutland <mark.rutland at arm.com>
Cc Mark Brown <broonie at kernel.org>
Cc Steven Price <Steven.Price at arm.com>
Cc Ard Biesheuvel <ard.biesheuvel at linaro.org>
Cc Masahiro Yamada <yamada.masahiro at socionext.com>
Cc Kees Cook <keescook at chromium.org>
Cc Tetsuo Handa <penguin-kernel at i-love.sakura.ne.jp>
Cc Matthew Wilcox <willy at infradead.org>
Cc Sri Krishna chowdary <schowdary at nvidia.com>
Cc Dave Hansen <dave.hansen at intel.com>
Cc Russell King - ARM Linux <linux at armlinux.org.uk>
Cc Michael Ellerman <mpe at ellerman.id.au>
Cc Paul Mackerras <paulus at samba.org>
Cc Martin Schwidefsky <schwidefsky at de.ibm.com>
Cc Heiko Carstens <heiko.carstens at de.ibm.com>
Cc "David S. Miller" <davem at davemloft.net>
Cc Vineet Gupta <vgupta at synopsys.com>
Cc James Hogan <jhogan at kernel.org>
Cc Paul Burton <paul.burton at mips.com>
Cc Ralf Baechle <ralf at linux-mips.org>
Cc Kirill A. Shutemov <kirill at shutemov.name>
Cc Gerald Schaefer <gerald.schaefer at de.ibm.com>
Cc Christophe Leroy <christophe.leroy at c-s.fr>
Cc linux-snps-arc at lists.infradead.org
Cc linux-mips at vger.kernel.org
Cc linux-arm-kernel at lists.infradead.org
Cc linux-ia64 at vger.kernel.org
Cc linuxppc-dev at lists.ozlabs.org
Cc linux-s390 at vger.kernel.org
Cc linux-sh at vger.kernel.org
Cc sparclinux at vger.kernel.org
Cc x86 at kernel.org
Cc linux-kernel at vger.kernel.org
Signed-off-by Anshuman Khandual <anshuman.khandual at arm.com>
---
 include/linux/hugetlb.h |  9 +++++++++
 mm/hugetlb.c            | 24 ++++++++++++++++++++++--
 2 files changed, 31 insertions(+), 2 deletions(-)
include/linux/hugetlb.h +9 -0
index 53fc34f930d0..cc50d5ad4885 100644
@@ -299,6 +299,9 @@ static inline bool is_file_hugepages(struct file *file)
 }
 
 
+struct page *
+alloc_gigantic_page_order(unsigned int order, gfp_t gfp_mask,
+			  int nid, nodemask_t *nodemask);
 #else /* !CONFIG_HUGETLBFS */
 
 #define is_file_hugepages(file)			false
@@ -310,6 +313,12 @@ hugetlb_file_setup(const char *name, size_t size, vm_flags_t acctflag,
 	return ERR_PTR(-ENOSYS);
 }
 
+static inline struct page *
+alloc_gigantic_page_order(unsigned int order, gfp_t gfp_mask,
+			  int nid, nodemask_t *nodemask)
+{
+	return NULL;
+}
 #endif /* !CONFIG_HUGETLBFS */
 
 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
mm/hugetlb.c +22 -2
index ef37c85423a5..3fb81252f52b 100644
@@ -1112,10 +1112,9 @@ static bool zone_spans_last_pfn(const struct zone *zone,
 	return zone_spans_pfn(zone, last_pfn);
 }
 
-static struct page *alloc_gigantic_page(struct hstate *h, gfp_t gfp_mask,
+struct page *alloc_gigantic_page_order(unsigned int order, gfp_t gfp_mask,
 		int nid, nodemask_t *nodemask)
 {
-	unsigned int order = huge_page_order(h);
 	unsigned long nr_pages = 1 << order;
 	unsigned long ret, pfn, flags;
 	struct zonelist *zonelist;
@@ -1151,6 +1150,14 @@ static struct page *alloc_gigantic_page(struct hstate *h, gfp_t gfp_mask,
 	return NULL;
 }
 
+static struct page *alloc_gigantic_page(struct hstate *h, gfp_t gfp_mask,
+					int nid, nodemask_t *nodemask)
+{
+	unsigned int order = huge_page_order(h);
+
+	return alloc_gigantic_page_order(order, gfp_mask, nid, nodemask);
+}
+
 static void prep_new_huge_page(struct hstate *h, struct page *page, int nid);
 static void prep_compound_gigantic_page(struct page *page, unsigned int order);
 #else /* !CONFIG_CONTIG_ALLOC */
@@ -1159,6 +1166,12 @@ static struct page *alloc_gigantic_page(struct hstate *h, gfp_t gfp_mask,
 {
 	return NULL;
 }
+
+struct page *alloc_gigantic_page_order(unsigned int order, gfp_t gfp_mask,
+				       int nid, nodemask_t *nodemask)
+{
+	return NULL;
+}
 #endif /* CONFIG_CONTIG_ALLOC */
 
 #else /* !CONFIG_ARCH_HAS_GIGANTIC_PAGE */
@@ -1167,6 +1180,13 @@ static struct page *alloc_gigantic_page(struct hstate *h, gfp_t gfp_mask,
 {
 	return NULL;
 }
+
+struct page *alloc_gigantic_page_order(unsigned int order, gfp_t gfp_mask,
+				       int nid, nodemask_t *nodemask)
+{
+	return NULL;
+}
+
 static inline void free_gigantic_page(struct page *page, unsigned int order) { }
 static inline void destroy_compound_gigantic_page(struct page *page,
 						unsigned int order) { }
Signature · 1 line
2.20.1
#2 lore raw

PATCH v4 2/2 mm/pgtable/debug: Add test validating architecture page table helpers

In reply to Anshuman Khandual

This adds a test module which will validate architecture page table helpers and accessors regarding compliance with generic MM semantics expectations. This will help various architectures in validating changes to the existing page table helpers or addition of new ones.

Test page table and memory pages creating it's entries at various level are all allocated from system memory with required alignments. If memory pages with required size and alignment could not be allocated, then all depending individual tests are skipped.

Cc Andrew Morton <akpm at linux-foundation.org>
Cc Vlastimil Babka <vbabka at suse.cz>
Cc Greg Kroah-Hartman <gregkh at linuxfoundation.org>
Cc Thomas Gleixner <tglx at linutronix.de>
Cc Mike Rapoport <rppt at linux.vnet.ibm.com>
Cc Jason Gunthorpe <jgg at ziepe.ca>
Cc Dan Williams <dan.j.williams at intel.com>
Cc Peter Zijlstra <peterz at infradead.org>
Cc Michal Hocko <mhocko at kernel.org>
Cc Mark Rutland <mark.rutland at arm.com>
Cc Mark Brown <broonie at kernel.org>
Cc Steven Price <Steven.Price at arm.com>
Cc Ard Biesheuvel <ard.biesheuvel at linaro.org>
Cc Masahiro Yamada <yamada.masahiro at socionext.com>
Cc Kees Cook <keescook at chromium.org>
Cc Tetsuo Handa <penguin-kernel at i-love.sakura.ne.jp>
Cc Matthew Wilcox <willy at infradead.org>
Cc Sri Krishna chowdary <schowdary at nvidia.com>
Cc Dave Hansen <dave.hansen at intel.com>
Cc Russell King - ARM Linux <linux at armlinux.org.uk>
Cc Michael Ellerman <mpe at ellerman.id.au>
Cc Paul Mackerras <paulus at samba.org>
Cc Martin Schwidefsky <schwidefsky at de.ibm.com>
Cc Heiko Carstens <heiko.carstens at de.ibm.com>
Cc "David S. Miller" <davem at davemloft.net>
Cc Vineet Gupta <vgupta at synopsys.com>
Cc James Hogan <jhogan at kernel.org>
Cc Paul Burton <paul.burton at mips.com>
Cc Ralf Baechle <ralf at linux-mips.org>
Cc Kirill A. Shutemov <kirill at shutemov.name>
Cc Gerald Schaefer <gerald.schaefer at de.ibm.com>
Cc Christophe Leroy <christophe.leroy at c-s.fr>
Cc linux-snps-arc at lists.infradead.org
Cc linux-mips at vger.kernel.org
Cc linux-arm-kernel at lists.infradead.org
Cc linux-ia64 at vger.kernel.org
Cc linuxppc-dev at lists.ozlabs.org
Cc linux-s390 at vger.kernel.org
Cc linux-sh at vger.kernel.org
Cc sparclinux at vger.kernel.org
Cc x86 at kernel.org
Cc linux-kernel at vger.kernel.org
Suggested-by Catalin Marinas <catalin.marinas at arm.com>
Signed-off-by Christophe Leroy <christophe.leroy at c-s.fr>
Tested-by Christophe Leroy <christophe.leroy at c-s.fr> #PPC32
Signed-off-by Anshuman Khandual <anshuman.khandual at arm.com>
---
 arch/x86/include/asm/pgtable_64_types.h |   2 +
 mm/Kconfig.debug                        |  15 +
 mm/Makefile                             |   1 +
 mm/arch_pgtable_test.c                  | 440 ++++++++++++++++++++++++
 4 files changed, 458 insertions(+)
 create mode 100644 mm/arch_pgtable_test.c
arch/x86/include/asm/pgtable_64_types.h +2 -0
index 52e5f5f2240d..b882792a3999 100644
@@ -40,6 +40,8 @@ static inline bool pgtable_l5_enabled(void)
 #define pgtable_l5_enabled() 0
 #endif /* CONFIG_X86_5LEVEL */
 
+#define mm_p4d_folded(mm) (!pgtable_l5_enabled())
+
 extern unsigned int pgdir_shift;
 extern unsigned int ptrs_per_p4d;
 
mm/Kconfig.debug +15 -0
index 327b3ebf23bf..683131b1ee7d 100644
@@ -117,3 +117,18 @@ config DEBUG_RODATA_TEST
     depends on STRICT_KERNEL_RWX
     ---help---
       This option enables a testcase for the setting rodata read-only.
+
+config DEBUG_ARCH_PGTABLE_TEST
+	bool "Test arch page table helpers for semantics compliance"
+	depends on MMU
+	depends on DEBUG_KERNEL
+	depends on !(ARM || IA64)
+	help
+	  This options provides a kernel module which can be used to test
+	  architecture page table helper functions on various platform in
+	  verifying if they comply with expected generic MM semantics. This
+	  will help architectures code in making sure that any changes or
+	  new additions of these helpers will still conform to generic MM
+	  expected semantics.
+
+	  If unsure, say N.
mm/Makefile +1 -0
index d996846697ef..bb572c5aa8c5 100644
@@ -86,6 +86,7 @@ obj-$(CONFIG_HWPOISON_INJECT) += hwpoison-inject.o
 obj-$(CONFIG_DEBUG_KMEMLEAK) += kmemleak.o
 obj-$(CONFIG_DEBUG_KMEMLEAK_TEST) += kmemleak-test.o
 obj-$(CONFIG_DEBUG_RODATA_TEST) += rodata_test.o
+obj-$(CONFIG_DEBUG_ARCH_PGTABLE_TEST) += arch_pgtable_test.o
 obj-$(CONFIG_PAGE_OWNER) += page_owner.o
 obj-$(CONFIG_CLEANCACHE) += cleancache.o
 obj-$(CONFIG_MEMORY_ISOLATION) += page_isolation.o
mm/arch_pgtable_test.c new file +440 -0

440 lines not on this page · raw message

Signature · 1 line
2.20.1
#3 lore raw

Re: [PATCH V4 2/2] mm/pgtable/debug: Add test validating architecture page table helpers

Quoted 15 lines · Anshuman Khandual

This adds a test module which will validate architecture page table helpers and accessors regarding compliance with generic MM semantics expectations. This will help various architectures in validating changes to the existing page table helpers or addition of new ones.

Test page table and memory pages creating it's entries at various level are all allocated from system memory with required alignments. If memory pages with required size and alignment could not be allocated, then all depending individual tests are skipped.

arch/x86/include/asm/pgtable_64_types.h +0 -0
index 52e5f5f2240d..b882792a3999 100644

arch/x86/include/asm/pgtable_64_types.h static inline bool pgtable_l5_enabled(void) · line 46

Quoted 7 lines
arch/x86/include/asm/pgtable_64_types.h +2 -0
@@ -40,6 +40,8 @@ static inline bool pgtable_l5_enabled(void)
 #define pgtable_l5_enabled() 0
 #endif /* CONFIG_X86_5LEVEL */
 
+#define mm_p4d_folded(mm) (!pgtable_l5_enabled())
+
 extern unsigned int pgdir_shift;
 extern unsigned int ptrs_per_p4d;

Any deep reason this has to be a macro instead of proper C?

Quoted 5 lines
mm/Kconfig.debug +0 -0
index 327b3ebf23bf..683131b1ee7d 100644

mm/Kconfig.debug config DEBUG_RODATA_TEST · line 125

Quoted 9 lines
mm/Kconfig.debug +6 -0
@@ -117,3 +117,18 @@ config DEBUG_RODATA_TEST
     depends on STRICT_KERNEL_RWX
     ---help---
       This option enables a testcase for the setting rodata read-only.
+
+config DEBUG_ARCH_PGTABLE_TEST
+	bool "Test arch page table helpers for semantics compliance"
+	depends on MMU
+	depends on DEBUG_KERNEL
+	depends on !(ARM || IA64)

Please add a proper enabling switch for architectures to opt in.

Please also add it to Documentation/features/list-arch.sh so that it's listed as a 'TODO' entry on architectures where the tests are not enabled yet.

mm/Kconfig.debug config DEBUG_RODATA_TEST · line 132

Quoted 7 lines
mm/Kconfig.debug +7 -0
+	help
+	  This options provides a kernel module which can be used to test
+	  architecture page table helper functions on various platform in
+	  verifying if they comply with expected generic MM semantics. This
+	  will help architectures code in making sure that any changes or
+	  new additions of these helpers will still conform to generic MM
+	  expected semantics.

Typos and grammar fixed:

help
This option provides a kernel module which can be used to test architecture page table helper functions on various platforms in verifying if they comply with expected generic MM semantics. This will help architecture code in making sure that any changes or new additions of these helpers still conform to expected semantics of the generic MM.

Also, more fundamentally: isn't a kernel module too late for such a debug check, should something break due to a core MM change? Have these debug checks caught any bugs or inconsistencies before?

Why not call this as some earlier MM debug check, after enabling paging but before executing user-space binaries or relying on complex MM ops within the kernel, called at a stage when those primitives are all expected to work fine?

It seems to me that arch_pgtable_tests_init) won't even context-switch normally, right?

Finally, instead of inventing yet another randomly named .config debug switch, please fit it into the regular MM debug options which go along the CONFIG_DEBUG_VM* naming scheme.

Might even make sense to enable these new debug checks by default if CONFIG_DEBUG_VM=y, that way we'll get a *lot* more debug coverage than some random module somewhere that few people will know about, let alone run.

Thanks,

Ingo

#4 lore raw

Re: [PATCH V4 2/2] mm/pgtable/debug: Add test validating architecture page table helpers

Quoted 21 lines · Ingo Molnar
Quoted 18 lines · Anshuman Khandual

This adds a test module which will validate architecture page table helpers and accessors regarding compliance with generic MM semantics expectations. This will help various architectures in validating changes to the existing page table helpers or addition of new ones.

Test page table and memory pages creating it's entries at various level are all allocated from system memory with required alignments. If memory pages with required size and alignment could not be allocated, then all depending individual tests are skipped.

arch/x86/include/asm/pgtable_64_types.h +0 -0
index 52e5f5f2240d..b882792a3999 100644
@@ -40,6 +40,8 @@ static inline bool pgtable_l5_enabled(void)
 #define pgtable_l5_enabled() 0
 #endif /* CONFIG_X86_5LEVEL */
 
Quoted 6 lines

arch/x86/include/asm/pgtable_64_types.h static inline bool pgtable_l5_enabled(void) · line 46

Quoted 4 lines
arch/x86/include/asm/pgtable_64_types.h +2 -0
+#define mm_p4d_folded(mm) (!pgtable_l5_enabled())
+
 extern unsigned int pgdir_shift;
 extern unsigned int ptrs_per_p4d;

Any deep reason this has to be a macro instead of proper C?

It's a way to override the generic mm_p4d_folded(). It can be rewritten as inline function + define. Something like:

#define mm_p4d_folded mm_p4d_folded
static inline bool mm_p4d_folded(struct mm_struct *mm)

{
	return !pgtable_l5_enabled();
}

But I don't see much reason to be more verbose here than needed.

Signature · 1 line
 Kirill A. Shutemov
#5 lore raw

Re: [PATCH V4 2/2] mm/pgtable/debug: Add test validating architecture page table helpers

Quoted 32 lines · Kirill A. Shutemov
Quoted 21 lines · Ingo Molnar
Quoted 18 lines · Anshuman Khandual

This adds a test module which will validate architecture page table helpers and accessors regarding compliance with generic MM semantics expectations. This will help various architectures in validating changes to the existing page table helpers or addition of new ones.

Test page table and memory pages creating it's entries at various level are all allocated from system memory with required alignments. If memory pages with required size and alignment could not be allocated, then all depending individual tests are skipped.

arch/x86/include/asm/pgtable_64_types.h +0 -0
index 52e5f5f2240d..b882792a3999 100644
@@ -40,6 +40,8 @@ static inline bool pgtable_l5_enabled(void)
 #define pgtable_l5_enabled() 0
 #endif /* CONFIG_X86_5LEVEL */
 
Quoted 6 lines

arch/x86/include/asm/pgtable_64_types.h static inline bool pgtable_l5_enabled(void) · line 46

Quoted 4 lines
arch/x86/include/asm/pgtable_64_types.h +2 -0
+#define mm_p4d_folded(mm) (!pgtable_l5_enabled())
+
 extern unsigned int pgdir_shift;
 extern unsigned int ptrs_per_p4d;

Any deep reason this has to be a macro instead of proper C?

It's a way to override the generic mm_p4d_folded(). It can be rewritten as inline function + define. Something like:

Quoted 7 lines

#define mm_p4d_folded mm_p4d_folded
static inline bool mm_p4d_folded(struct mm_struct *mm)

{
	return !pgtable_l5_enabled();
}

But I don't see much reason to be more verbose here than needed.

C type checking? Documentation? Yeah, I know it's just a one-liner, but the principle of the death by a thousand cuts applies here.

BTW., any reason this must be in the low level pgtable_64_types.h type header, instead of one of the API level header files?

Thanks,

Ingo

#6 lore raw

Re: [PATCH V4 2/2] mm/pgtable/debug: Add test validating architecture page table helpers

Quoted 41 lines · Ingo Molnar
Quoted 38 lines · Kirill A. Shutemov
Quoted 21 lines · Ingo Molnar
Quoted 18 lines · Anshuman Khandual

This adds a test module which will validate architecture page table helpers and accessors regarding compliance with generic MM semantics expectations. This will help various architectures in validating changes to the existing page table helpers or addition of new ones.

Test page table and memory pages creating it's entries at various level are all allocated from system memory with required alignments. If memory pages with required size and alignment could not be allocated, then all depending individual tests are skipped.

arch/x86/include/asm/pgtable_64_types.h +0 -0
index 52e5f5f2240d..b882792a3999 100644
@@ -40,6 +40,8 @@ static inline bool pgtable_l5_enabled(void)
 #define pgtable_l5_enabled() 0
 #endif /* CONFIG_X86_5LEVEL */
 
Quoted 6 lines

arch/x86/include/asm/pgtable_64_types.h static inline bool pgtable_l5_enabled(void) · line 46

Quoted 4 lines
arch/x86/include/asm/pgtable_64_types.h +2 -0
+#define mm_p4d_folded(mm) (!pgtable_l5_enabled())
+
 extern unsigned int pgdir_shift;
 extern unsigned int ptrs_per_p4d;

Any deep reason this has to be a macro instead of proper C?

It's a way to override the generic mm_p4d_folded(). It can be rewritten as inline function + define. Something like:

#define mm_p4d_folded mm_p4d_folded
static inline bool mm_p4d_folded(struct mm_struct *mm)

{
	return !pgtable_l5_enabled();
}
Quoted 4 lines
Quoted 1 line

But I don't see much reason to be more verbose here than needed.

C type checking? Documentation? Yeah, I know it's just a one-liner, but the principle of the death by a thousand cuts applies here.

Okay, if you think it worth it. Anshuman, could you fix it up for the next submission?

Quoted 2 lines

BTW., any reason this must be in the low level pgtable_64_types.h type header, instead of one of the API level header files?

I defined it next pgtable_l5_enabled(). What is more appropriate place to you? pgtable_64.h? Yeah, it makes sense.

Signature · 1 line
 Kirill A. Shutemov
#7 lore raw

Re: [PATCH V4 2/2] mm/pgtable/debug: Add test validating architecture page table helpers

Quoted 42 lines · Kirill A. Shutemov
Quoted 41 lines · Ingo Molnar
Quoted 38 lines · Kirill A. Shutemov
Quoted 21 lines · Ingo Molnar
Quoted 18 lines · Anshuman Khandual

This adds a test module which will validate architecture page table helpers and accessors regarding compliance with generic MM semantics expectations. This will help various architectures in validating changes to the existing page table helpers or addition of new ones.

Test page table and memory pages creating it's entries at various level are all allocated from system memory with required alignments. If memory pages with required size and alignment could not be allocated, then all depending individual tests are skipped.

arch/x86/include/asm/pgtable_64_types.h +0 -0
index 52e5f5f2240d..b882792a3999 100644
@@ -40,6 +40,8 @@ static inline bool pgtable_l5_enabled(void)
 #define pgtable_l5_enabled() 0
 #endif /* CONFIG_X86_5LEVEL */
 
Quoted 6 lines

arch/x86/include/asm/pgtable_64_types.h static inline bool pgtable_l5_enabled(void) · line 46

Quoted 4 lines
arch/x86/include/asm/pgtable_64_types.h +2 -0
+#define mm_p4d_folded(mm) (!pgtable_l5_enabled())
+
 extern unsigned int pgdir_shift;
 extern unsigned int ptrs_per_p4d;

Any deep reason this has to be a macro instead of proper C?

It's a way to override the generic mm_p4d_folded(). It can be rewritten as inline function + define. Something like:

#define mm_p4d_folded mm_p4d_folded
static inline bool mm_p4d_folded(struct mm_struct *mm)

{
	return !pgtable_l5_enabled();
}
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

But I don't see much reason to be more verbose here than needed.

C type checking? Documentation? Yeah, I know it's just a one-liner, but the principle of the death by a thousand cuts applies here.

Okay, if you think it worth it. Anshuman, could you fix it up for the next submission?

Sure, will do.

Quoted 7 lines
Quoted 4 lines

BTW., any reason this must be in the low level pgtable_64_types.h type header, instead of one of the API level header files?

I defined it next pgtable_l5_enabled(). What is more appropriate place to you? pgtable_64.h? Yeah, it makes sense.

Needs to be moved to arch/x86/include/asm/pgtable_64.h as well ?

#8 lore raw

Re: [PATCH V4 2/2] mm/pgtable/debug: Add test validating architecture page table helpers

In reply to Ingo Molnar
Quoted 28 lines · Ingo Molnar
Quoted 15 lines · Anshuman Khandual

This adds a test module which will validate architecture page table helpers and accessors regarding compliance with generic MM semantics expectations. This will help various architectures in validating changes to the existing page table helpers or addition of new ones.

Test page table and memory pages creating it's entries at various level are all allocated from system memory with required alignments. If memory pages with required size and alignment could not be allocated, then all depending individual tests are skipped.

arch/x86/include/asm/pgtable_64_types.h +0 -0
index 52e5f5f2240d..b882792a3999 100644

arch/x86/include/asm/pgtable_64_types.h static inline bool pgtable_l5_enabled(void) · line 46

Quoted 7 lines
arch/x86/include/asm/pgtable_64_types.h +2 -0
@@ -40,6 +40,8 @@ static inline bool pgtable_l5_enabled(void)
 #define pgtable_l5_enabled() 0
 #endif /* CONFIG_X86_5LEVEL */
 
+#define mm_p4d_folded(mm) (!pgtable_l5_enabled())
+
 extern unsigned int pgdir_shift;
 extern unsigned int ptrs_per_p4d;

Any deep reason this has to be a macro instead of proper C?

Quoted 16 lines
Quoted 5 lines
mm/Kconfig.debug +0 -0
index 327b3ebf23bf..683131b1ee7d 100644

mm/Kconfig.debug config DEBUG_RODATA_TEST · line 125

Quoted 9 lines
mm/Kconfig.debug +6 -0
@@ -117,3 +117,18 @@ config DEBUG_RODATA_TEST
     depends on STRICT_KERNEL_RWX
     ---help---
       This option enables a testcase for the setting rodata read-only.
+
+config DEBUG_ARCH_PGTABLE_TEST
+	bool "Test arch page table helpers for semantics compliance"
+	depends on MMU
+	depends on DEBUG_KERNEL
+	depends on !(ARM || IA64)

Please add a proper enabling switch for architectures to opt in.

Sure, will do.

Quoted 4 lines

Please also add it to Documentation/features/list-arch.sh so that it's listed as a 'TODO' entry on architectures where the tests are not enabled yet.

Will do.

Quoted 11 lines

mm/Kconfig.debug config DEBUG_RODATA_TEST · line 132

Quoted 8 lines
mm/Kconfig.debug +7 -0
+	help
+	  This options provides a kernel module which can be used to test
+	  architecture page table helper functions on various platform in
+	  verifying if they comply with expected generic MM semantics. This
+	  will help architectures code in making sure that any changes or
+	  new additions of these helpers will still conform to generic MM
+	  expected semantics.

Typos and grammar fixed:

Quoted 7 lines

help
This option provides a kernel module which can be used to test architecture page table helper functions on various platforms in verifying if they comply with expected generic MM semantics. This will help architecture code in making sure that any changes or new additions of these helpers still conform to expected semantics of the generic MM.

Sure, will update except the 'kernel module' part. Thank you.

Quoted 2 lines

Also, more fundamentally: isn't a kernel module too late for such a debug

Its not a kernel module any more, my bad that the description has still these words left on from previous versions, will fix it. The test now gets invoked through a late_initcall().

Quoted 2 lines

check, should something break due to a core MM change? Have these debug checks caught any bugs or inconsistencies before?

Gerald Schaefer had reported earlier about a bug found on s390 with this test.

https://lkml.org/lkml/2019/9/4/1718

Quoted 5 lines

Why not call this as some earlier MM debug check, after enabling paging but before executing user-space binaries or relying on complex MM ops within the kernel, called at a stage when those primitives are all expected to work fine?

At minimum we need buddy allocator to be initialized for the allocations to work. Just after pgtable_init() or kmem_cache_init() in mm_init() will be a good place ?

Quoted 3 lines

It seems to me that arch_pgtable_tests_init) won't even context-switch normally, right?

Not sure whether I got this. Why would you expect it to context switch ?

Quoted 9 lines

Finally, instead of inventing yet another randomly named .config debug switch, please fit it into the regular MM debug options which go along the CONFIG_DEBUG_VM* naming scheme.

Might even make sense to enable these new debug checks by default if CONFIG_DEBUG_VM=y, that way we'll get a *lot* more debug coverage than some random module somewhere that few people will know about, let alone run.

All the configs with respect to memory debugging is generated from lib/Kconfig.debug after fetching all that is in "mm/Kconfig.debug". There are only three configs which depend on CONFIG_DEBUG_VM like a package.

1. CONFIG_DEBUG_VM_VMACACHE
2. CONFIG_DEBUG_VM_RB
3. CONFIG_DEBUG_VM_PGFLAGS
4. CONFIG_DEBUG_VM_PGTABLE [proposed for this]

Before that, just trying to understand whether the reason of making this arch page table test as part of DEBUG_VM_* package than a just a stand alone config as many others, is that it is directly related to virtual memory enablement in kernel. Or is there something else I am missing.

But this looks better and will make this depend on a selectable arch config like ARCH_HAS_DEBUG_VM_PGTABLE or something.

Quoted 5 lines

Thanks,

Ingo