mm/debug: Add tests for architecture exported page table helpers
Subsystems (6)
v2 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.
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/
Questions:
Should alloc_gigantic_page() be made available as an interface for general use in the kernel. The test module here uses very similar implementation from HugeTLB to allocate a PUD aligned memory block. Similar for mm_alloc() which needs to be exported through a header.
Testing:
Build and boot tested on arm64 and x86 platforms. While arm64 clears all these tests, following errors were reported on x86.
1. WARN_ON(pud_bad(pud)) in pud_populate_tests()
2. WARN_ON(p4d_bad(p4d)) in p4d_populate_tests()
I would really appreciate if folks can help validate this test on other platforms and report back problems if any. Suggestions, comments and inputs welcome. Thank you.
Changes in V2:
- 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
RFC V1:
https://lore.kernel.org/linux-mm/1564037723-26676-1-git-send-email-anshuman.khandual at arm.com/
Anshuman Khandual (1):
mm/pgtable/debug: Add test validating architecture page table helpers
mm/Kconfig.debug | 14 ++ mm/Makefile | 1 + mm/arch_pgtable_test.c | 400 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 415 insertions(+) create mode 100644 mm/arch_pgtable_test.c
Signature · 1 line
2.20.1
RFC v2 1/1 mm/pgtable/debug: Add test validating architecture page table helpers
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.
--- mm/Kconfig.debug | 14 ++ mm/Makefile | 1 + mm/arch_pgtable_test.c | 400 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 415 insertions(+) create mode 100644 mm/arch_pgtable_test.c
mm/Kconfig.debug +14 -0
@@ -115,3 +115,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
@@ -84,6 +84,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 +400 -0
400 lines not on this page · raw message
Signature · 1 line
2.20.1
Quoted 4 lines · Anshuman Khandual
Should
alloc_gigantic_page()be made available as an interface for general use in the kernel. The test module here uses very similar implementation from HugeTLB to allocate a PUD aligned memory block. Similar formm_alloc()which needs to be exported through a header.
Why are you allocating memory at all instead of just using some known-to-exist PFNs like I suggested?
Quoted 8 lines · Matthew Wilcox
Quoted 4 lines · Anshuman Khandual
Should
alloc_gigantic_page()be made available as an interface for general use in the kernel. The test module here uses very similar implementation from HugeTLB to allocate a PUD aligned memory block. Similar formm_alloc()which needs to be exported through a header.Why are you allocating memory at all instead of just using some known-to-exist PFNs like I suggested?
We needed PFN to be PUD aligned for pfn_pud() and PMD aligned for mk_pmd(). Now walking the kernel page table for a known symbol like kernel_init() as you had suggested earlier we might encounter page table page entries at PMD and PUD which might not be PMD or PUD aligned respectively. It seemed to me that alignment requirement is applicable only for mk_pmd() and pfn_pud() which create large mappings at those levels but that requirement does not exist for page table pages pointing to next level. Is not that correct ? Or I am missing something here ?
Quoted 7 lines · Anshuman Khandual
Quoted 6 lines · Matthew Wilcox
Quoted 4 lines · Anshuman Khandual
Should
alloc_gigantic_page()be made available as an interface for general use in the kernel. The test module here uses very similar implementation from HugeTLB to allocate a PUD aligned memory block. Similar formm_alloc()which needs to be exported through a header.
Quoted 5 lines
Quoted 2 lines
Why are you allocating memory at all instead of just using some known-to-exist PFNs like I suggested?
We needed PFN to be PUD aligned for
pfn_pud()and PMD aligned formk_pmd(). Now walking the kernel page table for a known symbol likekernel_init()
I didn't say to walk the kernel page table. I said to call virt_to_pfn() for a known symbol like kernel_init().
Quoted 6 lines
as you had suggested earlier we might encounter page table page entries at PMD and PUD which might not be PMD or PUD aligned respectively. It seemed to me that alignment requirement is applicable only for
mk_pmd()andpfn_pud()which create large mappings at those levels but that requirement does not exist for page table pages pointing to next level. Is not that correct ? Or I am missing something here ?
Just clear the bottom bits off the PFN until you get a PMD or PUD aligned PFN. It's really not hard.
Quoted 24 lines · Matthew Wilcox
Quoted 7 lines · Anshuman Khandual
Quoted 6 lines · Matthew Wilcox
Quoted 4 lines · Anshuman Khandual
Should
alloc_gigantic_page()be made available as an interface for general use in the kernel. The test module here uses very similar implementation from HugeTLB to allocate a PUD aligned memory block. Similar formm_alloc()which needs to be exported through a header.Quoted 5 lines
Quoted 2 lines
Why are you allocating memory at all instead of just using some known-to-exist PFNs like I suggested?
We needed PFN to be PUD aligned for
pfn_pud()and PMD aligned formk_pmd(). Now walking the kernel page table for a known symbol likekernel_init()I didn't say to walk the kernel page table. I said to call
virt_to_pfn()for a known symbol likekernel_init().Quoted 6 lines
as you had suggested earlier we might encounter page table page entries at PMD and PUD which might not be PMD or PUD aligned respectively. It seemed to me that alignment requirement is applicable only for
mk_pmd()andpfn_pud()which create large mappings at those levels but that requirement does not exist for page table pages pointing to next level. Is not that correct ? Or I am missing something here ?
Quoted 2 lines
Just clear the bottom bits off the PFN until you get a PMD or PUD aligned PFN. It's really not hard.
As Mark pointed out earlier that might end up being just a synthetic PFN which might not even exist on a given system.
Quoted 25 lines · Anshuman Khandual
Quoted 24 lines · Matthew Wilcox
Quoted 7 lines · Anshuman Khandual
Quoted 6 lines · Matthew Wilcox
Quoted 4 lines · Anshuman Khandual
Should
alloc_gigantic_page()be made available as an interface for general use in the kernel. The test module here uses very similar implementation from HugeTLB to allocate a PUD aligned memory block. Similar formm_alloc()which needs to be exported through a header.Quoted 5 lines
Quoted 2 lines
Why are you allocating memory at all instead of just using some known-to-exist PFNs like I suggested?
We needed PFN to be PUD aligned for
pfn_pud()and PMD aligned formk_pmd(). Now walking the kernel page table for a known symbol likekernel_init()I didn't say to walk the kernel page table. I said to call
virt_to_pfn()for a known symbol likekernel_init().Quoted 6 lines
as you had suggested earlier we might encounter page table page entries at PMD and PUD which might not be PMD or PUD aligned respectively. It seemed to me that alignment requirement is applicable only for
mk_pmd()andpfn_pud()which create large mappings at those levels but that requirement does not exist for page table pages pointing to next level. Is not that correct ? Or I am missing something here ?
Quoted 5 lines
Quoted 2 lines
Just clear the bottom bits off the PFN until you get a PMD or PUD aligned PFN. It's really not hard.
As Mark pointed out earlier that might end up being just a synthetic PFN which might not even exist on a given system.
And why would that matter?
Quoted 26 lines · Matthew Wilcox
Quoted 25 lines · Anshuman Khandual
Quoted 24 lines · Matthew Wilcox
Quoted 7 lines · Anshuman Khandual
Quoted 6 lines · Matthew Wilcox
Quoted 4 lines · Anshuman Khandual
Should
alloc_gigantic_page()be made available as an interface for general use in the kernel. The test module here uses very similar implementation from HugeTLB to allocate a PUD aligned memory block. Similar formm_alloc()which needs to be exported through a header.Quoted 5 lines
Quoted 2 lines
Why are you allocating memory at all instead of just using some known-to-exist PFNs like I suggested?
We needed PFN to be PUD aligned for
pfn_pud()and PMD aligned formk_pmd(). Now walking the kernel page table for a known symbol likekernel_init()I didn't say to walk the kernel page table. I said to call
virt_to_pfn()for a known symbol likekernel_init().Quoted 6 lines
as you had suggested earlier we might encounter page table page entries at PMD and PUD which might not be PMD or PUD aligned respectively. It seemed to me that alignment requirement is applicable only for
mk_pmd()andpfn_pud()which create large mappings at those levels but that requirement does not exist for page table pages pointing to next level. Is not that correct ? Or I am missing something here ?
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Just clear the bottom bits off the PFN until you get a PMD or PUD aligned PFN. It's really not hard.
As Mark pointed out earlier that might end up being just a synthetic PFN which might not even exist on a given system.
And why would that matter?
To start with the test uses struct page with mk_pte() and mk_pmd() while pfn gets used in pfn_pud() during pXX_basic_tests(). So we will not be able to derive a valid struct page from a synthetic pfn. Also if synthetic pfn is going to be used anyway then why derive it from a real kernel symbol like kernel_init(). Could not one be just made up with right alignment ?
Currently the test allocates 'mm_struct' and other page table pages from real memory then why should it use synthetic pfn while creating actual page table entries ? Couple of benefits going with synthetic pfn will be..
- It simplifies the test a bit removing PUD_SIZE allocation helpers
- It might enable the test to be run on systems without adequate memory
In the current proposal the allocation happens during boot making it much more likely to succeed than not and when it fails, respective tests will be skipped.
I am just wondering if being able to run complete set of tests on smaller systems with less memory weighs lot more in favor of going with synthetic pfn instead.
Quoted 8 lines · Matthew Wilcox
Quoted 4 lines · Anshuman Khandual
Should
alloc_gigantic_page()be made available as an interface for general use in the kernel. The test module here uses very similar implementation from HugeTLB to allocate a PUD aligned memory block. Similar formm_alloc()which needs to be exported through a header.Why are you allocating memory at all instead of just using some known-to-exist PFNs like I suggested?
IIUC the issue is that there aren't necessarily known-to-exist PFNs that are sufficiently aligned -- they may not even exist.
For example, with 64K pages, a PMD covers 512M. The kernel image is (generally) smaller than 512M, and will be mapped at page granularity. In that case, any PMD entry for a kernel symbol address will point to the PTE level table, and that will only necessarily be page-aligned, as any P?D level table is only necessarily page-aligned.
In the same configuration, you could have less than 512M of total memory, and none of this memory is necessarily aligned to 512M. So beyond the PTE level, I don't think you can guarantee a known-to-exist valid PFN.
I also believe that synthetic PFNs could fail pfn_valid(), so that might cause us pain too...
Thanks,
Mark.
Quoted 10 lines · Mark Rutland
Quoted 8 lines · Matthew Wilcox
Quoted 4 lines · Anshuman Khandual
Should
alloc_gigantic_page()be made available as an interface for general use in the kernel. The test module here uses very similar implementation from HugeTLB to allocate a PUD aligned memory block. Similar formm_alloc()which needs to be exported through a header.Why are you allocating memory at all instead of just using some known-to-exist PFNs like I suggested?
Quoted 8 lines
IIUC the issue is that there aren't necessarily known-to-exist PFNs that are sufficiently aligned -- they may not even exist.
For example, with 64K pages, a PMD covers 512M. The kernel image is (generally) smaller than 512M, and will be mapped at page granularity. In that case, any PMD entry for a kernel symbol address will point to the PTE level table, and that will only necessarily be page-aligned, as any P?D level table is only necessarily page-aligned.
Right.
Quoted 5 lines
In the same configuration, you could have less than 512M of total memory, and none of this memory is necessarily aligned to 512M. So beyond the PTE level, I don't think you can guarantee a known-to-exist valid PFN.
Right a PMD aligned valid PFN might not even exist. This proposed patch which attempts to allocate memory chunk with required alignment will just fail indicating that such a valid PFN does not exist and hence will skip any relevant tests. At present this is done for PUD aligned allocation failure but we can similarly skip PMD relevant tests as well if PMD aligned memory chunk is not allocated.
Quoted 3 lines
I also believe that synthetic PFNs could fail
pfn_valid(), so that might cause us pain too...
Agreed. So do we have an agreement that it is better to use allocated memory with required alignment for the tests than known-to-exist PFNs ?
- Anshuman