Skip to contentSkip to conversation

mm/debug: Add tests validating architecture page table helpers

PATCH Superseded Anshuman Khandual 4 participants 20 messages Oct 15, 2019 – Oct 16, 2019

Subsystems (13)

v6 of 18 Superseded Latest is v18 →

lore
Share & tools
lore
#0 lore raw

v6 cover mm/debug: Add tests validating architecture 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/[email protected]/

Changes in V6:

- Moved alloc_gigantic_page_order() into mm/page_alloc.c per Michal
- Moved alloc_gigantic_page_order() within CONFIG_CONTIG_ALLOC in the test
- Folded Andrew's include/asm-generic/pgtable.h fix into the test patch 2/2

Changes in V5: (https://patchwork.kernel.org/project/linux-mm/list/?series=185991)

- Redefined and moved X86 mm_p4d_folded() into a different header per Kirill/Ingo
- Updated the config option comment per Ingo and dropped 'kernel module' reference
- Updated the commit message and dropped 'kernel module' reference
- Changed DEBUG_ARCH_PGTABLE_TEST into DEBUG_VM_PGTABLE per Ingo
- Moved config option from mm/Kconfig.debug into lib/Kconfig.debug
- Renamed core test function arch_pgtable_tests() as debug_vm_pgtable()
- Renamed mm/arch_pgtable_test.c as mm/debug_vm_pgtable.c
- debug_vm_pgtable() gets called from kernel_init_freeable() after init_mm_internals()
- Added an entry in Documentation/features/debug/ per Ingo
- Enabled the test on arm64 and x86 platforms for now

Changes in V4: (https://patchwork.kernel.org/project/linux-mm/list/?series=183465)

- 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/[email protected]/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/[email protected]/

- Added fallback mechanism for PMD aligned memory allocation failure

Changes in RFC V2:

https://lore.kernel.org/linux-mm/[email protected]/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/[email protected]/

Cc Andrew Morton <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc Dan Williams <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Mark Brown <[email protected]>
Cc Steven Price <[email protected]>
Cc Ard Biesheuvel <[email protected]>
Cc Masahiro Yamada <[email protected]>
Cc Kees Cook <[email protected]>
Cc Tetsuo Handa <[email protected]>
Cc Matthew Wilcox <[email protected]>
Cc Sri Krishna chowdary <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Russell King - ARM Linux <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Martin Schwidefsky <[email protected]>
Cc Heiko Carstens <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Vineet Gupta <[email protected]>
Cc James Hogan <[email protected]>
Cc Paul Burton <[email protected]>
Cc Ralf Baechle <[email protected]>
Cc Kirill A. Shutemov <[email protected]>
Cc Gerald Schaefer <[email protected]>
Cc Christophe Leroy <[email protected]>
Cc Mike Kravetz <[email protected]>

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

 .../debug/debug-vm-pgtable/arch-support.txt   |  34 ++
 arch/arm64/Kconfig                            |   1 +
 arch/x86/Kconfig                              |   1 +
 arch/x86/include/asm/pgtable_64.h             |   6 +
 include/asm-generic/pgtable.h                 |   6 +
 include/linux/gfp.h                           |   3 +
 init/main.c                                   |   1 +
 lib/Kconfig.debug                             |  21 +
 mm/Makefile                                   |   1 +
 mm/debug_vm_pgtable.c                         | 450 ++++++++++++++++++
 mm/hugetlb.c                                  |  76 +--
 mm/page_alloc.c                               |  98 ++++
 12 files changed, 623 insertions(+), 75 deletions(-)
 create mode 100644 Documentation/features/debug/debug-vm-pgtable/arch-support.txt
 create mode 100644 mm/debug_vm_pgtable.c
Signature · 1 line
2.20.1
#1 lore raw

PATCH v6 1/2 mm/page_alloc: 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() which is wrapped under CONFIG_CONTIG_ALLOC.

Cc Andrew Morton <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Mike Kravetz <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc Dan Williams <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Mark Brown <[email protected]>
Cc Steven Price <[email protected]>
Cc Ard Biesheuvel <[email protected]>
Cc Masahiro Yamada <[email protected]>
Cc Kees Cook <[email protected]>
Cc Tetsuo Handa <[email protected]>
Cc Matthew Wilcox <[email protected]>
Cc Sri Krishna chowdary <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Russell King - ARM Linux <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Martin Schwidefsky <[email protected]>
Cc Heiko Carstens <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Vineet Gupta <[email protected]>
Cc James Hogan <[email protected]>
Cc Paul Burton <[email protected]>
Cc Ralf Baechle <[email protected]>
Cc Kirill A. Shutemov <[email protected]>
Cc Gerald Schaefer <[email protected]>
Cc Christophe Leroy <[email protected]>
Cc David Rientjes <[email protected]>
Cc Andrea Arcangeli <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Mel Gorman <[email protected]>
---
 include/linux/gfp.h |  3 ++
 mm/hugetlb.c        | 76 +----------------------------------
 mm/page_alloc.c     | 98 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 102 insertions(+), 75 deletions(-)
include/linux/gfp.h +3 -0
index fb07b503dc45..379ad23437d1 100644
@@ -589,6 +589,9 @@ static inline bool pm_suspended_storage(void)
 /* The below functions must be run on a range from a single zone. */
 extern int alloc_contig_range(unsigned long start, unsigned long end,
 			      unsigned migratetype, gfp_t gfp_mask);
+extern struct page *alloc_gigantic_page_order(unsigned int order,
+					      gfp_t gfp_mask, int nid,
+					      nodemask_t *nodemask);
 #endif
 void free_contig_range(unsigned long pfn, unsigned int nr_pages);
 
mm/hugetlb.c +1 -75

87 lines not on this page · raw message

mm/page_alloc.c +98 -0

104 lines not on this page · raw message

Signature · 1 line
2.20.1
#2 lore raw

Re: [PATCH V6 1/2] mm/page_alloc: Make alloc_gigantic_page() available for general use

On Tue 15-10-19 14:51:41, Anshuman Khandual wrote:
[...]

Quoted 8 lines
mm/page_alloc.c +8 -0
+/**
+ * alloc_gigantic_page_order() -- tries to allocate given order of pages
+ * @order:	allocation order (greater than MAX_ORDER)
+ * @gfp_mask:	GFP mask to use during compaction
+ * @nid:	allocation node
+ * @nodemask:	allocation nodemask
+ *
+ * This routine is an wrapper around alloc_contig_range() which scans over

mm/page_alloc.c int alloc_contig_range(unsigned long start, unsigned long end, · line 8562

Quoted 10 lines
mm/page_alloc.c +10 -0
+ * all zones on an applicable zonelist to find a contiguous pfn range which
+ * can the be allocated with alloc_contig_range(). This routine is intended
+ * to be used for allocations greater than MAX_ORDER.
+ *
+ * Return: page on success or NULL on failure. On success a memory block
+ * of 'order' starting with 'page' has been allocated successfully. Memory
+ * allocated here needs to be freed with free_contig_range().
+ */
+struct page *alloc_gigantic_page_order(unsigned int order, gfp_t gfp_mask,
+				       int nid, nodemask_t *nodemask)

One of the objections when Mike has proposed a similar thing last year was that the interface shouldn't be order bases
http://lkml.kernel.org/r/[email protected]

Order based API makes sense for the buddy allocator but why should we restrict sizes like that for an allocator that is capable to allocate arbitrary page sized requests?

Signature · 2 lines
Michal Hocko
SUSE Labs
#3 lore raw

Re: [PATCH V6 1/2] mm/page_alloc: Make alloc_gigantic_page() available for general use

Quoted 25 lines · Michal Hocko

On Tue 15-10-19 14:51:41, Anshuman Khandual wrote:
[...]

Quoted 8 lines
mm/page_alloc.c +8 -0
+/**
+ * alloc_gigantic_page_order() -- tries to allocate given order of pages
+ * @order:	allocation order (greater than MAX_ORDER)
+ * @gfp_mask:	GFP mask to use during compaction
+ * @nid:	allocation node
+ * @nodemask:	allocation nodemask
+ *
+ * This routine is an wrapper around alloc_contig_range() which scans over

mm/page_alloc.c int alloc_contig_range(unsigned long start, unsigned long end, · line 8562

Quoted 10 lines
mm/page_alloc.c +10 -0
+ * all zones on an applicable zonelist to find a contiguous pfn range which
+ * can the be allocated with alloc_contig_range(). This routine is intended
+ * to be used for allocations greater than MAX_ORDER.
+ *
+ * Return: page on success or NULL on failure. On success a memory block
+ * of 'order' starting with 'page' has been allocated successfully. Memory
+ * allocated here needs to be freed with free_contig_range().
+ */
+struct page *alloc_gigantic_page_order(unsigned int order, gfp_t gfp_mask,
+				       int nid, nodemask_t *nodemask)

One of the objections when Mike has proposed a similar thing last year was that the interface shouldn't be order bases
http://lkml.kernel.org/r/[email protected]

Quoted 3 lines

Order based API makes sense for the buddy allocator but why should we restrict sizes like that for an allocator that is capable to allocate arbitrary page sized requests?

Fair enough, will change it. Anyways we calculate nr_pages from the order argument at the very beginning.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#4 lore raw

Re: [PATCH V6 1/2] mm/page_alloc: Make alloc_gigantic_page() available for general use

In reply to Anshuman Khandual
Quoted 94 lines · Anshuman Khandual

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() which is wrapped under CONFIG_CONTIG_ALLOC.

Cc Andrew Morton <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Mike Kravetz <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc Dan Williams <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Mark Brown <[email protected]>
Cc Steven Price <[email protected]>
Cc Ard Biesheuvel <[email protected]>
Cc Masahiro Yamada <[email protected]>
Cc Kees Cook <[email protected]>
Cc Tetsuo Handa <[email protected]>
Cc Matthew Wilcox <[email protected]>
Cc Sri Krishna chowdary <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Russell King - ARM Linux <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Martin Schwidefsky <[email protected]>
Cc Heiko Carstens <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Vineet Gupta <[email protected]>
Cc James Hogan <[email protected]>
Cc Paul Burton <[email protected]>
Cc Ralf Baechle <[email protected]>
Cc Kirill A. Shutemov <[email protected]>
Cc Gerald Schaefer <[email protected]>
Cc Christophe Leroy <[email protected]>
Cc David Rientjes <[email protected]>
Cc Andrea Arcangeli <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Mel Gorman <[email protected]>
---
  include/linux/gfp.h |  3 ++
  mm/hugetlb.c        | 76 +----------------------------------
  mm/page_alloc.c     | 98 +++++++++++++++++++++++++++++++++++++++++++++
  3 files changed, 102 insertions(+), 75 deletions(-)
include/linux/gfp.h +3 -0
index fb07b503dc45..379ad23437d1 100644
@@ -589,6 +589,9 @@ static inline bool pm_suspended_storage(void)
  /* The below functions must be run on a range from a single zone. */
  extern int alloc_contig_range(unsigned long start, unsigned long end,
  			      unsigned migratetype, gfp_t gfp_mask);
+extern struct page *alloc_gigantic_page_order(unsigned int order,
+					      gfp_t gfp_mask, int nid,
+					      nodemask_t *nodemask);
  #endif
  void free_contig_range(unsigned long pfn, unsigned int nr_pages);
 
mm/hugetlb.c +0 -9
index 977f9a323a7a..d199556a4a2c 100644
@@ -1023,86 +1023,12 @@ static void free_gigantic_page(struct page *page, unsigned int order)
  }
 
  #ifdef CONFIG_CONTIG_ALLOC
-static int __alloc_gigantic_page(unsigned long start_pfn,
-				unsigned long nr_pages, gfp_t gfp_mask)
-{
-	unsigned long end_pfn = start_pfn + nr_pages;
-	return alloc_contig_range(start_pfn, end_pfn, MIGRATE_MOVABLE,
-				  gfp_mask);
-}
-
-static bool pfn_range_valid_gigantic(struct zone *z,

mm/hugetlb.c static void free_gigantic_page(struct page *page, unsigned int order) · line 1044

Quoted 10 lines
mm/hugetlb.c +0 -10
-			unsigned long start_pfn, unsigned long nr_pages)
-{
-	unsigned long i, end_pfn = start_pfn + nr_pages;
-	struct page *page;
-
-	for (i = start_pfn; i < end_pfn; i++) {
-		if (!pfn_valid(i))
-			return false;
-
-		page = pfn_to_page(i);

Am I missing something or should here really be a pfn_to_online_page() here instead of a pfn_valid() ?

Signature · 3 lines
Thanks,

David / dhildenb
#5 lore raw

Re: [PATCH V6 1/2] mm/page_alloc: Make alloc_gigantic_page() available for general use

On Tue 15-10-19 13:42:03, David Hildenbrand wrote:
[...]

Quoted 6 lines
Quoted 6 lines
mm/hugetlb.c +0 -6
-static bool pfn_range_valid_gigantic(struct zone *z,
-			unsigned long start_pfn, unsigned long nr_pages)
-{
-	unsigned long i, end_pfn = start_pfn + nr_pages;
-	struct page *page;
-
Quoted 8 lines

mm/hugetlb.c static void free_gigantic_page(struct page *page, unsigned int order) · line 1044

Quoted 5 lines
mm/hugetlb.c +0 -5
-	for (i = start_pfn; i < end_pfn; i++) {
-		if (!pfn_valid(i))
-			return false;
-
-		page = pfn_to_page(i);

Am I missing something or should here really be a pfn_to_online_page() here instead of a pfn_valid() ?

http://lkml.kernel.org/r/[email protected]

Signature · 2 lines
Michal Hocko
SUSE Labs
#6 lore raw

Re: [PATCH V6 1/2] mm/page_alloc: Make alloc_gigantic_page() available for general use

Quoted 17 lines · Michal Hocko

On Tue 15-10-19 13:42:03, David Hildenbrand wrote:
[...]

Quoted 6 lines
Quoted 6 lines
mm/hugetlb.c +0 -6
-static bool pfn_range_valid_gigantic(struct zone *z,
-			unsigned long start_pfn, unsigned long nr_pages)
-{
-	unsigned long i, end_pfn = start_pfn + nr_pages;
-	struct page *page;
-
Quoted 8 lines

mm/hugetlb.c static void free_gigantic_page(struct page *page, unsigned int order) · line 1044

Quoted 5 lines
mm/hugetlb.c +0 -5
-	for (i = start_pfn; i < end_pfn; i++) {
-		if (!pfn_valid(i))
-			return false;
-
-		page = pfn_to_page(i);

Am I missing something or should here really be a pfn_to_online_page() here instead of a pfn_valid() ?

Quoted 2 lines

http://lkml.kernel.org/r/[email protected]

So we managed to add PageReserved(page) but not pfn_to_online_page(). But it is the right thing to do? (or am I missing something?)

Signature · 3 lines
Thanks,

David / dhildenb
#7 lore raw

Re: [PATCH V6 1/2] mm/page_alloc: Make alloc_gigantic_page() available for general use

Quoted 18 lines · David Hildenbrand
Quoted 17 lines · Michal Hocko

On Tue 15-10-19 13:42:03, David Hildenbrand wrote:
[...]

Quoted 14 lines

mm/hugetlb.c static void free_gigantic_page(struct page *page, unsigned int order) · line 1044

Quoted 11 lines
mm/hugetlb.c +0 -11
-static bool pfn_range_valid_gigantic(struct zone *z,
-			unsigned long start_pfn, unsigned long nr_pages)
-{
-	unsigned long i, end_pfn = start_pfn + nr_pages;
-	struct page *page;
-
-	for (i = start_pfn; i < end_pfn; i++) {
-		if (!pfn_valid(i))
-			return false;
-
-		page = pfn_to_page(i);

Am I missing something or should here really be a pfn_to_online_page() here instead of a pfn_valid() ?

Quoted 6 lines
Quoted 2 lines

http://lkml.kernel.org/r/[email protected]

So we managed to add PageReserved(page) but not pfn_to_online_page(). But it is the right thing to do? (or am I missing something?)

Will send a patch.

Signature · 3 lines
Thanks,

David / dhildenb
#8 lore raw

Re: [PATCH V6 1/2] mm/page_alloc: Make alloc_gigantic_page() available for general use

In reply to David Hildenbrand
Quoted 18 lines · David Hildenbrand
Quoted 17 lines · Michal Hocko

On Tue 15-10-19 13:42:03, David Hildenbrand wrote:
[...]

Quoted 14 lines

mm/hugetlb.c static void free_gigantic_page(struct page *page, unsigned int order) · line 1044

Quoted 11 lines
mm/hugetlb.c +0 -11
-static bool pfn_range_valid_gigantic(struct zone *z,
-			unsigned long start_pfn, unsigned long nr_pages)
-{
-	unsigned long i, end_pfn = start_pfn + nr_pages;
-	struct page *page;
-
-	for (i = start_pfn; i < end_pfn; i++) {
-		if (!pfn_valid(i))
-			return false;
-
-		page = pfn_to_page(i);

Am I missing something or should here really be a pfn_to_online_page() here instead of a pfn_valid() ?

Quoted 5 lines
Quoted 2 lines

http://lkml.kernel.org/r/[email protected]

So we managed to add PageReserved(page) but not pfn_to_online_page(). But it is the right thing to do? (or am I missing something?)

Yeah, pfn_to_online_page is better. But please note that this is an optimistic check. The real check has to be done when isolating the pageblock because things might change in the meantime.

Signature · 2 lines
Michal Hocko
SUSE Labs
#9 lore raw

Re: [PATCH V6 1/2] mm/page_alloc: Make alloc_gigantic_page() available for general use

Quoted 22 lines · Michal Hocko
Quoted 21 lines · David Hildenbrand
Quoted 19 lines · Michal Hocko

On Tue 15-10-19 13:42:03, David Hildenbrand wrote:
[...]

Quoted 6 lines
Quoted 6 lines
mm/hugetlb.c +0 -6
-static bool pfn_range_valid_gigantic(struct zone *z,
-			unsigned long start_pfn, unsigned long nr_pages)
-{
-	unsigned long i, end_pfn = start_pfn + nr_pages;
-	struct page *page;
-
Quoted 8 lines

mm/hugetlb.c static void free_gigantic_page(struct page *page, unsigned int order) · line 1044

Quoted 5 lines
mm/hugetlb.c +0 -5
-	for (i = start_pfn; i < end_pfn; i++) {
-		if (!pfn_valid(i))
-			return false;
-
-		page = pfn_to_page(i);

Am I missing something or should here really be a pfn_to_online_page() here instead of a pfn_valid() ?

http://lkml.kernel.org/r/[email protected]

Quoted 6 lines
Quoted 2 lines

So we managed to add PageReserved(page) but not pfn_to_online_page(). But it is the right thing to do? (or am I missing something?)

Yeah, pfn_to_online_page is better. But please note that this is an optimistic check. The real check has to be done when isolating the pageblock because things might change in the meantime.

Except I have missed that we do get zone from the page and other undefined state. Scratch my above comment.

Signature · 2 lines
Michal Hocko
SUSE Labs
#10 lore raw

PATCH v6 2/2 mm/debug: Add tests validating architecture page table helpers

In reply to Anshuman Khandual

This adds tests which will validate architecture page table helpers and other accessors in their compliance with expected generic MM semantics. This will help various architectures in validating changes to 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 size and alignments. But if memory pages with required size and alignment could not be allocated, then all depending individual tests are just skipped afterwards. This test gets called right after init_mm_internals() required for alloc_contig_range() to work correctly.

This gets build and run when CONFIG_DEBUG_VM_PGTABLE is selected along with CONFIG_VM_DEBUG. Architectures willing to subscribe this test also need to select CONFIG_ARCH_HAS_DEBUG_VM_PGTABLE which for now is limited to x86 and arm64. Going forward, other architectures too can enable this after fixing build or runtime problems (if any) with their page table helpers.

Cc Andrew Morton <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc Dan Williams <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Mark Brown <[email protected]>
Cc Steven Price <[email protected]>
Cc Ard Biesheuvel <[email protected]>
Cc Masahiro Yamada <[email protected]>
Cc Kees Cook <[email protected]>
Cc Tetsuo Handa <[email protected]>
Cc Matthew Wilcox <[email protected]>
Cc Sri Krishna chowdary <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Russell King - ARM Linux <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Martin Schwidefsky <[email protected]>
Cc Heiko Carstens <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Vineet Gupta <[email protected]>
Cc James Hogan <[email protected]>
Cc Paul Burton <[email protected]>
Cc Ralf Baechle <[email protected]>
Cc Kirill A. Shutemov <[email protected]>
Cc Gerald Schaefer <[email protected]>
Cc Christophe Leroy <[email protected]>
---
 .../debug/debug-vm-pgtable/arch-support.txt   |  34 ++
 arch/arm64/Kconfig                            |   1 +
 arch/x86/Kconfig                              |   1 +
 arch/x86/include/asm/pgtable_64.h             |   6 +
 include/asm-generic/pgtable.h                 |   6 +
 init/main.c                                   |   1 +
 lib/Kconfig.debug                             |  21 +
 mm/Makefile                                   |   1 +
 mm/debug_vm_pgtable.c                         | 450 ++++++++++++++++++
 9 files changed, 521 insertions(+)
 create mode 100644 Documentation/features/debug/debug-vm-pgtable/arch-support.txt
 create mode 100644 mm/debug_vm_pgtable.c
Documentation/features/debug/debug-vm-pgtable/arch-support.txt new file +34 -0
new file mode 100644
index 000000000000..d6b8185dcf1e
@@ -0,0 +1,34 @@
+#
+# Feature name:          debug-vm-pgtable
+#         Kconfig:       ARCH_HAS_DEBUG_VM_PGTABLE
+#         description:   arch supports pgtable tests for semantics compliance
+#
+    -----------------------
+    |         arch |status|
+    -----------------------
+    |       alpha: | TODO |
+    |         arc: | TODO |
+    |         arm: | TODO |
+    |       arm64: |  ok  |
+    |         c6x: | TODO |
+    |        csky: | TODO |
+    |       h8300: | TODO |
+    |     hexagon: | TODO |
+    |        ia64: | TODO |
+    |        m68k: | TODO |
+    |  microblaze: | TODO |
+    |        mips: | TODO |
+    |       nds32: | TODO |
+    |       nios2: | TODO |
+    |    openrisc: | TODO |
+    |      parisc: | TODO |
+    |     powerpc: | TODO |
+    |       riscv: | TODO |
+    |        s390: | TODO |
+    |          sh: | TODO |
+    |       sparc: | TODO |
+    |          um: | TODO |
+    |   unicore32: | TODO |
+    |         x86: |  ok  |
+    |      xtensa: | TODO |
+    -----------------------
arch/arm64/Kconfig +1 -0
index 950a56b71ff0..8a3b3eaa49e9 100644
@@ -11,6 +11,7 @@ config ARM64
 	select ACPI_PPTT if ACPI
 	select ARCH_CLOCKSOURCE_DATA
 	select ARCH_HAS_DEBUG_VIRTUAL
+	select ARCH_HAS_DEBUG_VM_PGTABLE
 	select ARCH_HAS_DEVMEM_IS_ALLOWED
 	select ARCH_HAS_DMA_COHERENT_TO_PFN
 	select ARCH_HAS_DMA_PREP_COHERENT
arch/x86/Kconfig +1 -0
index abe822d52167..13c9bd950256 100644
@@ -61,6 +61,7 @@ config X86
 	select ARCH_CLOCKSOURCE_INIT
 	select ARCH_HAS_ACPI_TABLE_UPGRADE	if ACPI
 	select ARCH_HAS_DEBUG_VIRTUAL
+	select ARCH_HAS_DEBUG_VM_PGTABLE
 	select ARCH_HAS_DEVMEM_IS_ALLOWED
 	select ARCH_HAS_ELF_RANDOMIZE
 	select ARCH_HAS_FAST_MULTIPLIER
arch/x86/include/asm/pgtable_64.h +6 -0
index 0b6c4042942a..fb0e76d254b3 100644
@@ -53,6 +53,12 @@ static inline void sync_initial_page_table(void) { }
 
 struct mm_struct;
 
+#define mm_p4d_folded mm_p4d_folded
+static inline bool mm_p4d_folded(struct mm_struct *mm)
+{
+	return !pgtable_l5_enabled();
+}
+
 void set_pte_vaddr_p4d(p4d_t *p4d_page, unsigned long vaddr, pte_t new_pte);
 void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte);
 
include/asm-generic/pgtable.h +6 -0
index 818691846c90..7f97b7a4a9e2 100644
@@ -1157,6 +1157,12 @@ static inline bool arch_has_pfn_modify_check(void)
 # define PAGE_KERNEL_EXEC PAGE_KERNEL
 #endif
 
+#ifdef CONFIG_DEBUG_VM_PGTABLE
+extern void debug_vm_pgtable(void);
+#else
+static inline void debug_vm_pgtable(void) { }
+#endif
+
 #endif /* !__ASSEMBLY__ */
 
 #ifndef io_remap_pfn_range
init/main.c +1 -0
index 91f6ebb30ef0..676d8020dd29 100644
@@ -1177,6 +1177,7 @@ static noinline void __init kernel_init_freeable(void)
 	workqueue_init();
 
 	init_mm_internals();
+	debug_vm_pgtable();
 
 	do_pre_smp_initcalls();
 	lockup_detector_init();
lib/Kconfig.debug +21 -0
index cb1fc48e61e3..b9b8fe1e2180 100644
@@ -698,6 +698,27 @@ config DEBUG_VM_PGFLAGS
 
 	  If unsure, say N.
 
+config ARCH_HAS_DEBUG_VM_PGTABLE
+	bool
+	help
+	  An architecture should select this when it can successfully
+	  build and run DEBUG_VM_PGTABLE.
+
+config DEBUG_VM_PGTABLE
+	bool "Debug arch page table for semantics compliance"
+	depends on MMU
+	depends on DEBUG_VM
+	depends on ARCH_HAS_DEBUG_VM_PGTABLE
+	help
+	  This option provides a debug method 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.
+
+	  If unsure, say N.
+
 config ARCH_HAS_DEBUG_VIRTUAL
 	bool
 
mm/Makefile +1 -0
index d996846697ef..2f085b971d34 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_VM_PGTABLE) += debug_vm_pgtable.o
 obj-$(CONFIG_PAGE_OWNER) += page_owner.o
 obj-$(CONFIG_CLEANCACHE) += cleancache.o
 obj-$(CONFIG_MEMORY_ISOLATION) += page_isolation.o
mm/debug_vm_pgtable.c new file +450 -0

450 lines not on this page · raw message

Signature · 1 line
2.20.1
#11 lore raw
Quoted 12 lines · Anshuman Khandual

This adds tests which will validate architecture page table helpers and other accessors in their compliance with expected generic MM semantics. This will help various architectures in validating changes to 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 size and alignments. But if memory pages with required size and alignment could not be allocated, then all depending individual tests are just skipped afterwards. This test gets called right after init_mm_internals() required for alloc_contig_range() to work correctly.

Quoted 5 lines

This gets build and run when CONFIG_DEBUG_VM_PGTABLE is selected along with CONFIG_VM_DEBUG. Architectures willing to subscribe this test also need to select CONFIG_ARCH_HAS_DEBUG_VM_PGTABLE which for now is limited to x86 and arm64. Going forward, other architectures too can enable this after fixing build or runtime problems (if any) with their page table helpers.

A highlevel description of tests and what they are testing for would be really appreciated. Who wants to run these tests and why/when? What kind of bugs would get detected? In short why do we really need/want this code in the tree?

Signature · 2 lines
Michal Hocko
SUSE Labs
#12 lore raw
Quoted 19 lines · Michal Hocko
Quoted 12 lines · Anshuman Khandual

This adds tests which will validate architecture page table helpers and other accessors in their compliance with expected generic MM semantics. This will help various architectures in validating changes to 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 size and alignments. But if memory pages with required size and alignment could not be allocated, then all depending individual tests are just skipped afterwards. This test gets called right after init_mm_internals() required for alloc_contig_range() to work correctly.

Quoted 5 lines

This gets build and run when CONFIG_DEBUG_VM_PGTABLE is selected along with CONFIG_VM_DEBUG. Architectures willing to subscribe this test also need to select CONFIG_ARCH_HAS_DEBUG_VM_PGTABLE which for now is limited to x86 and arm64. Going forward, other architectures too can enable this after fixing build or runtime problems (if any) with their page table helpers.

Quoted 4 lines

A highlevel description of tests and what they are testing for would be really appreciated. Who wants to run these tests and why/when? What kind of bugs would get detected? In short why do we really need/want this code in the tree?

Sure, will do.

#13 lore raw
In reply to Anshuman Khandual

mm/debug_vm_pgtable.c line 371

Quoted 11 lines · Anshuman Khandual
mm/debug_vm_pgtable.c new file +11 -0
+static unsigned long __init get_random_vaddr(void)
+{
+	unsigned long random_vaddr, random_pages, total_user_pages;
+
+	total_user_pages = (TASK_SIZE - FIRST_USER_ADDRESS) / PAGE_SIZE;
+
+	random_pages = get_random_long() % total_user_pages;
+	random_vaddr = FIRST_USER_ADDRESS + random_pages * PAGE_SIZE;
+
+	WARN_ON(random_vaddr > TASK_SIZE);
+	WARN_ON(random_vaddr < FIRST_USER_ADDRESS);

It would be nice if this patch does not introduce a new W=1 GCC warning here on x86 because FIRST_USER_ADDRESS is 0, and GCC think the code is dumb because "random_vaddr" is unsigned,

In file included from ./arch/x86/include/asm/bug.h:83,
                 from ./include/linux/bug.h:5,
                 from ./include/linux/mmdebug.h:5,
                 from ./include/linux/gfp.h:5,
                 from mm/debug_vm_pgtable.c:13:
mm/debug_vm_pgtable.c: In function ‘get_random_vaddr’:
mm/debug_vm_pgtable.c:359:23: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
  WARN_ON(random_vaddr < FIRST_USER_ADDRESS);
                       ^
./include/asm-generic/bug.h:113:25: note: in definition of macro ‘WARN_ON’ int __ret_warn_on = !!(condition);    \
                         ^~~~~~~~~

#14 lore raw
Quoted 17 lines · Qian Cai

mm/debug_vm_pgtable.c line 371

Quoted 11 lines · Anshuman Khandual
mm/debug_vm_pgtable.c new file +11 -0
+static unsigned long __init get_random_vaddr(void)
+{
+	unsigned long random_vaddr, random_pages, total_user_pages;
+
+	total_user_pages = (TASK_SIZE - FIRST_USER_ADDRESS) / PAGE_SIZE;
+
+	random_pages = get_random_long() % total_user_pages;
+	random_vaddr = FIRST_USER_ADDRESS + random_pages * PAGE_SIZE;
+
+	WARN_ON(random_vaddr > TASK_SIZE);
+	WARN_ON(random_vaddr < FIRST_USER_ADDRESS);

It would be nice if this patch does not introduce a new W=1 GCC warning here on x86 because FIRST_USER_ADDRESS is 0, and GCC think the code is dumb because "random_vaddr" is unsigned,

Quoted 13 lines

In file included from ./arch/x86/include/asm/bug.h:83,
                 from ./include/linux/bug.h:5,
                 from ./include/linux/mmdebug.h:5,
                 from ./include/linux/gfp.h:5,
                 from mm/debug_vm_pgtable.c:13:
mm/debug_vm_pgtable.c: In function ‘get_random_vaddr’:
mm/debug_vm_pgtable.c:359:23: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
  WARN_ON(random_vaddr < FIRST_USER_ADDRESS);
                       ^
./include/asm-generic/bug.h:113:25: note: in definition of macro ‘WARN_ON’ int __ret_warn_on = !!(condition);    \
                         ^~~~~~~~~

The test checks against an erroneous unsigned long overflow when FIRST_USER_ADDRESS is not 0 but a positive number. Wondering if the compiler will still complain if we merge both the WARN_ON() checks as || on a single statement.

#15 lore raw
In reply to Anshuman Khandual

The x86 will crash with linux-next during boot due to this series (v5) with the config below plus CONFIG_DEBUG_VM_PGTABLE=y. I am not sure if v6 would address it.

https://raw.githubusercontent.com/cailca/linux-mm/master/x86.config

[   33.862600][    T1] page:ffffea0009000000 is uninitialized and poisoned [   33.862608][    T1] raw: ffffffffffffffff ffffffffffffffff ffffffffffffffff ffffff871140][    T1]  ? _raw_spin_unlock_irq+0x27/0x40
[   33.871140][    T1]  ? rest_init+0x307/0x307
[   33.871140][    T1]  kernel_init+0x11/0x139
[   33.871140][    T1]  ? rest_init+0x307/0x307
[   33.871140][    T1]  ret_from_fork+0x27/0x50
[   33.871140][    T1] Modules linked in:
[   33.871140][    T1] ---[ end trace e99d392b0f7befbd ]---
[   33.871140][    T1] RIP: 0010:alloc_gigantic_page_order+0x3fe/0x490

Quoted 154 lines · Anshuman Khandual

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/[email protected]/

Changes in V6:

- Moved alloc_gigantic_page_order() into mm/page_alloc.c per Michal
- Moved alloc_gigantic_page_order() within CONFIG_CONTIG_ALLOC in the test
- Folded Andrew's include/asm-generic/pgtable.h fix into the test patch 2/2

Changes in V5: (https://patchwork.kernel.org/project/linux-mm/list/?series5991)

- Redefined and moved X86 mm_p4d_folded() into a different header per Kirill/Ingo
- Updated the config option comment per Ingo and dropped 'kernel module' reference
- Updated the commit message and dropped 'kernel module' reference
- Changed DEBUG_ARCH_PGTABLE_TEST into DEBUG_VM_PGTABLE per Ingo
- Moved config option from mm/Kconfig.debug into lib/Kconfig.debug
- Renamed core test function arch_pgtable_tests() as debug_vm_pgtable()
- Renamed mm/arch_pgtable_test.c as mm/debug_vm_pgtable.c
- debug_vm_pgtable() gets called from kernel_init_freeable() after init_mm_internals()
- Added an entry in Documentation/features/debug/ per Ingo
- Enabled the test on arm64 and x86 platforms for now

Changes in V4: (https://patchwork.kernel.org/project/linux-mm/list/?series3465)

- Disable DEBUG_ARCH_PGTABLE_TEST for ARM and IA64 platforms

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

- 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/[email protected]/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/[email protected]/

- Added fallback mechanism for PMD aligned memory allocation failure

Changes in RFC V2:

https://lore.kernel.org/linux-mm/[email protected]/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/[email protected]/

Cc Andrew Morton <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc Dan Williams <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Mark Brown <[email protected]>
Cc Steven Price <[email protected]>
Cc Ard Biesheuvel <[email protected]>
Cc Masahiro Yamada <[email protected]>
Cc Kees Cook <[email protected]>
Cc Tetsuo Handa <[email protected]>
Cc Matthew Wilcox <[email protected]>
Cc Sri Krishna chowdary <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Russell King - ARM Linux <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Martin Schwidefsky <[email protected]>
Cc Heiko Carstens <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Vineet Gupta <[email protected]>
Cc James Hogan <[email protected]>
Cc Paul Burton <[email protected]>
Cc Ralf Baechle <[email protected]>
Cc Kirill A. Shutemov <[email protected]>
Cc Gerald Schaefer <[email protected]>
Cc Christophe Leroy <[email protected]>
Cc Mike Kravetz <[email protected]>

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

 .../debug/debug-vm-pgtable/arch-support.txt   |  34 ++
 arch/arm64/Kconfig                            |   1 +
 arch/x86/Kconfig                              |   1 +
 arch/x86/include/asm/pgtable_64.h             |   6 +
 include/asm-generic/pgtable.h                 |   6 +
 include/linux/gfp.h                           |   3 +
 init/main.c                                   |   1 +
 lib/Kconfig.debug                             |  21 +
 mm/Makefile                                   |   1 +
 mm/debug_vm_pgtable.c                         | 450 ++++++++++++++++++
 mm/hugetlb.c                                  |  76 +--
 mm/page_alloc.c                               |  98 ++++
 12 files changed, 623 insertions(+), 75 deletions(-)
 create mode 100644 Documentation/features/debug/debug-vm-pgtable/arch-support.txt
 create mode 100644 mm/debug_vm_pgtable.c
#16 lore raw
Quoted 6 lines · Qian Cai

The x86 will crash with linux-next during boot due to this series (v5) with the config below plus CONFIG_DEBUG_VM_PGTABLE=y. I am not sure if v6 would address it.

https://raw.githubusercontent.com/cailca/linux-mm/master/x86.config

Quoted 10 lines

[   33.862600][    T1] page:ffffea0009000000 is uninitialized and poisoned [   33.862608][    T1] raw: ffffffffffffffff ffffffffffffffff ffffffffffffffff ffffff871140][    T1]  ? _raw_spin_unlock_irq+0x27/0x40
[   33.871140][    T1]  ? rest_init+0x307/0x307
[   33.871140][    T1]  kernel_init+0x11/0x139
[   33.871140][    T1]  ? rest_init+0x307/0x307
[   33.871140][    T1]  ret_from_fork+0x27/0x50
[   33.871140][    T1] Modules linked in:
[   33.871140][    T1] ---[ end trace e99d392b0f7befbd ]---
[   33.871140][    T1] RIP: 0010:alloc_gigantic_page_order+0x3fe/0x490

Hmm, with defconfig (DEBUG_VM=y and DEBUG_VM_PGTABLE=y) it does not crash but with the config above, it does. Just wondering if it is possible that these pages might not been initialized yet because DEFERRED_STRUCT_PAGE_INIT=y ?

[   13.898549][    T1] page:ffffea0005000000 is uninitialized and poisoned
[   13.898549][    T1] raw: ffffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffff
[   13.898549][    T1] raw: ffffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffff
[   13.898549][    T1] page dumped because: VM_BUG_ON_PAGE(PagePoisoned(p))
[   13.898549][    T1] ------------[ cut here ]------------
[   13.898549][    T1] kernel BUG at ./include/linux/mm.h:1107!
[   13.898549][    T1] invalid opcode: 0000 [#1] SMP DEBUG_PAGEALLOC KASAN PTI
[   13.898549][    T1] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.4.0-rc3-next-20191015+ #
#17 lore raw
Quoted 19 lines · Anshuman Khandual
Quoted 6 lines · Qian Cai

The x86 will crash with linux-next during boot due to this series (v5) with the config below plus CONFIG_DEBUG_VM_PGTABLE=y. I am not sure if v6 would address it.

https://raw.githubusercontent.com/cailca/linux-mm/master/x86.config

Quoted 10 lines

[   33.862600][    T1] page:ffffea0009000000 is uninitialized and poisoned [   33.862608][    T1] raw: ffffffffffffffff ffffffffffffffff ffffffffffffffff ffffff871140][    T1]  ? _raw_spin_unlock_irq+0x27/0x40
[   33.871140][    T1]  ? rest_init+0x307/0x307
[   33.871140][    T1]  kernel_init+0x11/0x139
[   33.871140][    T1]  ? rest_init+0x307/0x307
[   33.871140][    T1]  ret_from_fork+0x27/0x50
[   33.871140][    T1] Modules linked in:
[   33.871140][    T1] ---[ end trace e99d392b0f7befbd ]---
[   33.871140][    T1] RIP: 0010:alloc_gigantic_page_order+0x3fe/0x490

Quoted 3 lines

Hmm, with defconfig (DEBUG_VM=y and DEBUG_VM_PGTABLE=y) it does not crash but with the config above, it does. Just wondering if it is possible that these pages might not been initialized yet because DEFERRED_STRUCT_PAGE_INIT=y ?

Yes, this patch works fine.

init/main.c +0 -0
index 676d8020dd29..591be8f9e8e0 100644
@@ -1177,7 +1177,6 @@ static noinline void __init kernel_init_freeable(void)

        workqueue_init();

        init_mm_internals();
-       debug_vm_pgtable();

        do_pre_smp_initcalls();
        lockup_detector_init();
@@ -1186,6 +1185,8 @@ static noinline void __init kernel_init_freeable(void) sched_init_smp();

        page_alloc_init_late();
+       debug_vm_pgtable();
+
        /* Initialize page ext after all struct pages are initialized. */ page_ext_init();

Quoted 9 lines
[   13.898549][    T1] page:ffffea0005000000 is uninitialized and poisoned
[   13.898549][    T1] raw: ffffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffff
[   13.898549][    T1] raw: ffffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffff
[   13.898549][    T1] page dumped because: VM_BUG_ON_PAGE(PagePoisoned(p))
[   13.898549][    T1] ------------[ cut here ]------------
[   13.898549][    T1] kernel BUG at ./include/linux/mm.h:1107!
[   13.898549][    T1] invalid opcode: 0000 [#1] SMP DEBUG_PAGEALLOC KASAN PTI
[   13.898549][    T1] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.4.0-rc3-next-20191015+ #
#18 lore raw
Quoted 40 lines · Qian Cai
Quoted 19 lines · Anshuman Khandual
Quoted 6 lines · Qian Cai

The x86 will crash with linux-next during boot due to this series (v5) with the config below plus CONFIG_DEBUG_VM_PGTABLE=y. I am not sure if v6 would address it.

https://raw.githubusercontent.com/cailca/linux-mm/master/x86.config

Quoted 10 lines

[   33.862600][    T1] page:ffffea0009000000 is uninitialized and poisoned [   33.862608][    T1] raw: ffffffffffffffff ffffffffffffffff ffffffffffffffff ffffff871140][    T1]  ? _raw_spin_unlock_irq+0x27/0x40
[   33.871140][    T1]  ? rest_init+0x307/0x307
[   33.871140][    T1]  kernel_init+0x11/0x139
[   33.871140][    T1]  ? rest_init+0x307/0x307
[   33.871140][    T1]  ret_from_fork+0x27/0x50
[   33.871140][    T1] Modules linked in:
[   33.871140][    T1] ---[ end trace e99d392b0f7befbd ]---
[   33.871140][    T1] RIP: 0010:alloc_gigantic_page_order+0x3fe/0x490

Quoted 3 lines

Hmm, with defconfig (DEBUG_VM=y and DEBUG_VM_PGTABLE=y) it does not crash but with the config above, it does. Just wondering if it is possible that these pages might not been initialized yet because DEFERRED_STRUCT_PAGE_INIT=y ?

Yes, this patch works fine.

init/main.c +0 -0
index 676d8020dd29..591be8f9e8e0 100644
@@ -1177,7 +1177,6 @@ static noinline void __init kernel_init_freeable(void)
         workqueue_init();


        init_mm_internals();
-       debug_vm_pgtable();

        do_pre_smp_initcalls();
        lockup_detector_init();

init/main.c +0 -0
@@ -1186,6 +1185,8 @@ static noinline void __init kernel_init_freeable(void)
         sched_init_smp();
Quoted 7 lines


        page_alloc_init_late();
+       debug_vm_pgtable();
+
        /* Initialize page ext after all struct pages are initialized. */ page_ext_init();

Sure, will keep this in mind if we at all end up with memory allocation approach for this test.

Quoted 10 lines
Quoted 9 lines
[   13.898549][    T1] page:ffffea0005000000 is uninitialized and poisoned
[   13.898549][    T1] raw: ffffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffff
[   13.898549][    T1] raw: ffffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffff
[   13.898549][    T1] page dumped because: VM_BUG_ON_PAGE(PagePoisoned(p))
[   13.898549][    T1] ------------[ cut here ]------------
[   13.898549][    T1] kernel BUG at ./include/linux/mm.h:1107!
[   13.898549][    T1] invalid opcode: 0000 [#1] SMP DEBUG_PAGEALLOC KASAN PTI
[   13.898549][    T1] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.4.0-rc3-next-20191015+ #
#19 lore raw
In reply to Anshuman Khandual
Quoted 20 lines · Anshuman Khandual
Quoted 6 lines · Qian Cai

The x86 will crash with linux-next during boot due to this series (v5) with the config below plus CONFIG_DEBUG_VM_PGTABLE=y. I am not sure if v6 would address it.

https://raw.githubusercontent.com/cailca/linux-mm/master/x86.config

Quoted 10 lines

[   33.862600][    T1] page:ffffea0009000000 is uninitialized and poisoned [   33.862608][    T1] raw: ffffffffffffffff ffffffffffffffff ffffffffffffffff ffffff871140][    T1]  ? _raw_spin_unlock_irq+0x27/0x40
[   33.871140][    T1]  ? rest_init+0x307/0x307
[   33.871140][    T1]  kernel_init+0x11/0x139
[   33.871140][    T1]  ? rest_init+0x307/0x307
[   33.871140][    T1]  ret_from_fork+0x27/0x50
[   33.871140][    T1] Modules linked in:
[   33.871140][    T1] ---[ end trace e99d392b0f7befbd ]---
[   33.871140][    T1] RIP: 0010:alloc_gigantic_page_order+0x3fe/0x490

Quoted 3 lines

Hmm, with defconfig (DEBUG_VM=y and DEBUG_VM_PGTABLE=y) it does not crash but with the config above, it does. Just wondering if it is possible that these pages might not been initialized yet because DEFERRED_STRUCT_PAGE_INIT=y ?

Quite likely. You need to wait for page_alloc_init_late to finish.

Quoted 9 lines
[   13.898549][    T1] page:ffffea0005000000 is uninitialized and poisoned
[   13.898549][    T1] raw: ffffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffff
[   13.898549][    T1] raw: ffffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffff
[   13.898549][    T1] page dumped because: VM_BUG_ON_PAGE(PagePoisoned(p))
[   13.898549][    T1] ------------[ cut here ]------------
[   13.898549][    T1] kernel BUG at ./include/linux/mm.h:1107!
[   13.898549][    T1] invalid opcode: 0000 [#1] SMP DEBUG_PAGEALLOC KASAN PTI
[   13.898549][    T1] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.4.0-rc3-next-20191015+ #
Signature · 2 lines
Michal Hocko
SUSE Labs