mm/debug: Add tests for architecture exported page table helpers
Subsystems (8)
v3 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/
Testing:
Successfully build and boot tested on both arm64 and x86 platforms without any test failing. Only build tested on some other platforms. Build failed on some platforms (known) in pud_clear_tests() as there were no available __pgd() definitions.
- ARM32
- IA64
But I would really appreciate if folks can help validate this test on other architectures and report back problems. All suggestions, comments and inputs welcome. Thank you.
Changes in V3:
- 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/
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 | 14 + mm/Makefile | 1 + mm/arch_pgtable_test.c | 440 ++++++++++++++++++++++++++++++++ mm/hugetlb.c | 24 +- 6 files changed, 488 insertions(+), 2 deletions(-) create mode 100644 mm/arch_pgtable_test.c
Signature · 1 line
2.7.4
PATCH v3 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().
--- include/linux/hugetlb.h | 9 +++++++++ mm/hugetlb.c | 24 ++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-)
include/linux/hugetlb.h +9 -0
@@ -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
@@ -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.7.4
PATCH v3 2/2 mm/pgtable/debug: Add test validating architecture page table helpers
In reply to Anshuman KhandualThis 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 | 2 + mm/Kconfig.debug | 14 + mm/Makefile | 1 + mm/arch_pgtable_test.c | 440 ++++++++++++++++++++++++++++++++ 4 files changed, 457 insertions(+) create mode 100644 mm/arch_pgtable_test.c
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;
mm/Kconfig.debug +14 -0
@@ -117,3 +117,17 @@ 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 + 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
@@ -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.7.4
kbuild test robot
build botRe: [PATCH V3 2/2] mm/pgtable/debug: Add test validating architecture page table helpers
Thank you for the patch! Yet something to improve:
Hi Anshuman,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linus/master]
[cannot apply to v5.3 next-20190919]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Anshuman-Khandual/mm-debug-Add-tests-for-architecture-exported-page-table-helpers/20190920-143746
config: ia64-allmodconfig (attached as .config)
compiler: ia64-linux-gcc (GCC) 7.4.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=ia64
:::::: branch date: 3 hours ago
:::::: commit date: 3 hours ago
If you fix the issue, kindly add following tag
All error/warnings (new ones prefixed by >>):
In file included from include/asm-generic/pgtable-nopud.h:8:0,
from arch/ia64/include/asm/pgtable.h:591,
from include/linux/mm.h:99,
from include/linux/highmem.h:8,
from mm/arch_pgtable_test.c:14:
mm/arch_pgtable_test.c: In function 'pud_clear_tests':
>> include/asm-generic/pgtable-nop4d-hack.h:47:32: error: implicit declaration of function '__pgd'; did you mean '__p4d'? [-Werror=implicit-function-declaration]
#define __pud(x) ((pud_t) { __pgd(x) })
^
>> mm/arch_pgtable_test.c:162:8: note: in expansion of macro '__pud'
pud = __pud(pud_val(pud) | RANDOM_ORVALUE);
^~~~~
>> include/asm-generic/pgtable-nop4d-hack.h:47:22: warning: missing braces around initializer [-Wmissing-braces]
#define __pud(x) ((pud_t) { __pgd(x) })
^
>> mm/arch_pgtable_test.c:162:8: note: in expansion of macro '__pud'
pud = __pud(pud_val(pud) | RANDOM_ORVALUE);
^~~~~cc1: some warnings being treated as errors
# https://github.com/0day-ci/linux/commit/49047f93b076974eefa5b019311bd3b734d61f8c
git remote add linux-review https://github.com/0day-ci/linux
git remote update linux-review
git checkout 49047f93b076974eefa5b019311bd3b734d61f8c
vim +47 include/asm-generic/pgtable-nop4d-hack.h
30ec842660bd0d Kirill A. Shutemov 2017-03-09 4530ec842660bd0d Kirill A. Shutemov 2017-03-09 46 #define pud_val(x) (pgd_val((x).pgd))30ec842660bd0d Kirill A. Shutemov 2017-03-09 @47 #define __pud(x) ((pud_t) { __pgd(x) })30ec842660bd0d Kirill A. Shutemov 2017-03-09 48
:::::: The code at line 47 was first introduced by commit
:::::: 30ec842660bd0d056d4a7028ac5bd4a82b113d4f asm-generic: introduce __ARCH_USE_5LEVEL_HACK
:::::: TO: Kirill A. Shutemov <[email protected]> :::::: CC: Linus Torvalds <[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Re: [PATCH V3 2/2] mm/pgtable/debug: Add test validating architecture page table helpers
Quoted 52 lines · kbuild test robot
Hi Anshuman,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linus/master]
[cannot apply to v5.3 next-20190919]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]url: https://github.com/0day-ci/linux/commits/Anshuman-Khandual/mm-debug-Add-tests-for-architecture-exported-page-table-helpers/20190920-143746
config: ia64-allmodconfig (attached as .config)
compiler: ia64-linux-gcc (GCC) 7.4.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=ia64
:::::: branch date: 3 hours ago
:::::: commit date: 3 hours agoIf you fix the issue, kindly add following tag
Reported-by kbuild test robot <[email protected]>All error/warnings (new ones prefixed by >>):
In file included from include/asm-generic/pgtable-nopud.h:8:0, from arch/ia64/include/asm/pgtable.h:591, from include/linux/mm.h:99, from include/linux/highmem.h:8, from mm/arch_pgtable_test.c:14: mm/arch_pgtable_test.c: In function 'pud_clear_tests':Quoted 1 line
Quoted 1 line
include/asm-generic/pgtable-nop4d-hack.h:47:32: error: implicit declaration of function '__pgd'; did you mean '__p4d'? [-Werror=implicit-function-declaration]#define __pud(x) ((pud_t) { __pgd(x) }) ^Quoted 1 line
Quoted 1 line
mm/arch_pgtable_test.c:162:8: note: in expansion of macro '__pud'pud = __pud(pud_val(pud) | RANDOM_ORVALUE); ^~~~~Quoted 1 line
Quoted 1 line
include/asm-generic/pgtable-nop4d-hack.h:47:22: warning: missing braces around initializer [-Wmissing-braces]#define __pud(x) ((pud_t) { __pgd(x) }) ^Quoted 1 line
Quoted 1 line
mm/arch_pgtable_test.c:162:8: note: in expansion of macro '__pud'pud = __pud(pud_val(pud) | RANDOM_ORVALUE); ^~~~~cc1: some warnings being treated as errors
# https://github.com/0day-ci/linux/commit/49047f93b076974eefa5b019311bd3b734d61f8c
git remote add linux-review https://github.com/0day-ci/linux
git remote update linux-review
git checkout49047f93b076974eefa5b019311bd3b734d61f8c
vim +47include/asm-generic/pgtable-nop4d-hack.h
Quoted 3 lines
30ec842660bd0dKirill A. Shutemov 2017-03-09 4530ec842660bd0dKirill A. Shutemov 2017-03-09 46 #definepud_val(x)(pgd_val((x).pgd))30ec842660bd0dKirill A. Shutemov 2017-03-09 @47 #define__pud(x)((pud_t) {__pgd(x)})
I had mentioned about this build failure in the cover letter. The same problem also exists on arm32 platform.
- Anshuman
Quoted 14 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]/
Testing:
Quoted 7 lines
Successfully build and boot tested on both arm64 and x86 platforms without any test failing. Only build tested on some other platforms. Build failed on some platforms (known) in
pud_clear_tests()as there were no available__pgd()definitions.- ARM32
- IA64
Hm. Grep shows __pgd() definitions for both of them. Is it for specific config?
Signature · 1 line
Kirill A. Shutemov
Quoted 20 lines · Kirill A. Shutemov
Quoted 19 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]/
Testing:
Successfully build and boot tested on both arm64 and x86 platforms without any test failing. Only build tested on some other platforms. Build failed on some platforms (known) in
pud_clear_tests()as there were no available__pgd()definitions.
Quoted 5 lines
Quoted 2 lines
- ARM32
- IA64Hm. Grep shows
__pgd()definitions for both of them. Is it for specific config?
For ARM32 it's defined only for 3-lelel page tables, i.e with LPAE on. For IA64 it's defined for !STRICT_MM_TYPECHECKS which is even not a config option, but a define in arch/ia64/include/asm/page.h
Quoted 2 lines
Signature · 1 line
Kirill A. Shutemov
Signature · 2 lines
Sincerely yours, Mike.
Quoted 24 lines · Mike Rapoport
Quoted 23 lines · Kirill A. Shutemov
Quoted 21 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]/
Testing:
Successfully build and boot tested on both arm64 and x86 platforms without any test failing. Only build tested on some other platforms. Build failed on some platforms (known) in
pud_clear_tests()as there were no available__pgd()definitions.- ARM32
- IA64
Quoted 6 lines
Quoted 2 lines
Hm. Grep shows
__pgd()definitions for both of them. Is it for specific config?For ARM32 it's defined only for 3-lelel page tables, i.e with LPAE on. For IA64 it's defined for !STRICT_MM_TYPECHECKS which is even not a config option, but a define in
arch/ia64/include/asm/page.h
Right. So now where we go from here ! We will need help from platform folks to fix this unless its trivial. I did propose this on last thread (v2), wondering if it will be a better idea to restrict DEBUG_ARCH_PGTABLE_TEST among architectures which have fixed all pending issues whether build or run time. Though enabling all platforms where the test builds at the least might make more sense, we might have to just exclude arm32 and ia64 for now. Then run time problems can be fixed later platform by platform. Any thoughts ?
BTW the test is known to run successfully on arm64, x86, ppc32 platforms. Gerald has been trying to get it working on s390. in the meantime., if there are other volunteers to test this on ppc64, sparc, riscv, mips, m68k etc platforms, it will be really helpful.
- Anshuman