selftest/mremap_test: Update the test to handle pagesize other than 4K
Subsystems (7)
RFC PATCH 3/6 mm/mremap: Use pmd/pud_poplulate to update page table entries
In reply to Aneesh Kumar K.Vpmd/pud_populate is the right interface to be used to set the respective page table entries. Some architectures do assume that set_pmd/pud_at can only be used to set a hugepage PTE. Since we are not setting up a hugepage PTE here, use the pmd/pud_populate interface.
--- mm/mremap.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
mm/mremap.c +3 -4
@@ -27,6 +27,7 @@#include <asm/cacheflush.h> #include <asm/tlbflush.h> +#include <asm/pgalloc.h> #include "internal.h"
@@ -258,9 +259,8 @@ static bool move_normal_pmd(struct vm_area_struct *vma, unsigned long old_addr,pmd_clear (old_pmd);VM_BUG_ON (!pmd_none (*new_pmd)); +pmd_populate (mm, new_pmd, (pgtable_t )pmd_page_vaddr (pmd)); -/* Set the new pmd */ -set_pmd_at (mm, new_addr, new_pmd, pmd);flush_tlb_range (vma, old_addr, old_addr +PMD_SIZE );if (new_ptl != old_ptl)spin_unlock (new_ptl);
@@ -307,8 +307,7 @@ static bool move_normal_pud(struct vm_area_struct *vma, unsigned long old_addr,VM_BUG_ON (!pud_none (*new_pud)); -/* Set the new pud */ -set_pud_at (mm, new_addr, new_pud, pud); +pud_populate (mm, new_pud, (pmd_t *)pud_page_vaddr (pud));flush_tlb_range (vma, old_addr, old_addr +PUD_SIZE );if (new_ptl != old_ptl)spin_unlock (new_ptl);
Signature · 1 line
2.29.2
RFC PATCH 2/6 selftest/mremap_test: Avoid crash with static build
In reply to Aneesh Kumar K.VWith a large mmap map size, we can overlap with the text area and using MAP_FIXED results in unmapping that area. Switch to MAP_FIXED_NOREPLACE and handle the EEXIST error.
--- tools/testing/selftests/vm/mremap_test.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
tools/testing/selftests/vm/mremap_test.c +3 -2
@@ -75,9 +75,10 @@ static void *get_source_mapping(struct config c) retry: addr += c.src_alignment; src_addr =mmap ((void *) addr, c.region_size,PROT_READ |PROT_WRITE , -MAP_FIXED |MAP_ANONYMOUS |MAP_SHARED ,-1 ,0 ); +MAP_FIXED_NOREPLACE |MAP_ANONYMOUS |MAP_SHARED , +-1 ,0 );if (src_addr ==MAP_FAILED ) { -if (errno ==EPERM ) +if (errno ==EPERM || errno ==EEXIST ) goto retry; goto error; }
Signature · 1 line
2.29.2
RFC PATCH 4/6 mm/mremap: Use mmu gather interface instead of flush_tlb_range
In reply to Aneesh Kumar K.VSome architectures do have the concept of page walk cache and only mmu gather interface supports flushing them. A fast mremap that involves moving page table pages instead of copying pte entries should flush page walk cache since the old translation cache is no more valid. Hence switch to mm gather to flush TLB and mark tlb.freed_tables = 1. No page table pages need to be freed here. With this the tlb flush is done outside page table lock (ptl).
--- mm/mremap.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-)
mm/mremap.c +29 -4
@@ -217,6 +217,7 @@ static bool move_normal_pmd(struct vm_area_struct *vma, unsigned long old_addr, {spinlock_t *old_ptl, *new_ptl;struct mm_struct *mm = vma->vm_mm; +struct mmu_gather tlb;pmd_t pmd;/*
@@ -245,11 +246,12 @@ static bool move_normal_pmd(struct vm_area_struct *vma, unsigned long old_addr,if (WARN_ON_ONCE (!pmd_none (*new_pmd)))return false; +tlb_gather_mmu (&tlb, mm, old_addr,PMD_SIZE );/* * We don't have to worry about the ordering of src and dst * ptlocks because exclusive mmap_lock prevents deadlock. */ - old_ptl =pmd_lock (vma->vm_mm, old_pmd); + old_ptl =pmd_lock (mm, old_pmd); new_ptl =pmd_lockptr (mm, new_pmd);if (new_ptl != old_ptl)spin_lock_nested (new_ptl,SINGLE_DEPTH_NESTING );
@@ -258,13 +260,23 @@ static bool move_normal_pmd(struct vm_area_struct *vma, unsigned long old_addr, pmd = *old_pmd;pmd_clear (old_pmd); +/* +* Mark the range. We are not freeing page table pages nor +* regular pages. Hence we don't need to call tlb_remove_table() +* or tlb_remove_page(). +*/ +tlb_flush_pte_range (&tlb, old_addr,PMD_SIZE ); + tlb.freed_tables =1 ;VM_BUG_ON (!pmd_none (*new_pmd));pmd_populate (mm, new_pmd, (pgtable_t )pmd_page_vaddr (pmd)); -flush_tlb_range (vma, old_addr, old_addr +PMD_SIZE );if (new_ptl != old_ptl)spin_unlock (new_ptl);spin_unlock (old_ptl); +/* +* This will invalidate both the old TLB and page table walk caches. +*/ +tlb_finish_mmu (&tlb, old_addr,PMD_SIZE );return true; }
@@ -283,6 +295,7 @@ static bool move_normal_pud(struct vm_area_struct *vma, unsigned long old_addr, {spinlock_t *old_ptl, *new_ptl;struct mm_struct *mm = vma->vm_mm; +struct mmu_gather tlb;pud_t pud;/*
@@ -292,11 +305,12 @@ static bool move_normal_pud(struct vm_area_struct *vma, unsigned long old_addr,if (WARN_ON_ONCE (!pud_none (*new_pud)))return false; +tlb_gather_mmu (&tlb, mm, old_addr,PUD_SIZE );/* * We don't have to worry about the ordering of src and dst * ptlocks because exclusive mmap_lock prevents deadlock. */ - old_ptl =pud_lock (vma->vm_mm, old_pud); + old_ptl =pud_lock (mm, old_pud); new_ptl =pud_lockptr (mm, new_pud);if (new_ptl != old_ptl)spin_lock_nested (new_ptl,SINGLE_DEPTH_NESTING );
@@ -305,14 +319,25 @@ static bool move_normal_pud(struct vm_area_struct *vma, unsigned long old_addr, pud = *old_pud;pud_clear (old_pud); +/* +* Mark the range. We are not freeing page table pages nor +* regular pages. Hence we don't need to call tlb_remove_table() +* or tlb_remove_page(). +*/ +tlb_flush_pte_range (&tlb, old_addr,PUD_SIZE ); + tlb.freed_tables =1 ;VM_BUG_ON (!pud_none (*new_pud));pud_populate (mm, new_pud, (pmd_t *)pud_page_vaddr (pud)); -flush_tlb_range (vma, old_addr, old_addr +PUD_SIZE ); +if (new_ptl != old_ptl)spin_unlock (new_ptl);spin_unlock (old_ptl); +/* +* This will invalidate both the old TLB and page table walk caches. +*/ +tlb_finish_mmu (&tlb, old_addr,PUD_SIZE ); return true; }#else
Signature · 1 line
2.29.2
RFC PATCH 5/6 mm/mremap: Allow arch runtime override
In reply to Aneesh Kumar K.VArchitectures like ppc64 can only support faster mremap only with radix translation. Hence allow a runtime check w.r.t support for fast mremap.
--- arch/arm64/include/asm/tlb.h | 6 ++++++ arch/powerpc/include/asm/tlb.h | 6 ++++++ arch/x86/include/asm/tlb.h | 5 +++++ mm/mremap.c | 14 +++++++++++++- 4 files changed, 30 insertions(+), 1 deletion(-)
arch/arm64/include/asm/tlb.h +6 -0
@@ -94,4 +94,10 @@ static inline void __pud_free_tlb(struct mmu_gather *tlb, pud_t *pudp, }#endif +#define arch_supports_page_tables_move arch_supports_page_tables_move +static inline bool arch_supports_page_tables_move (void ) +{ +return true; +} +#endif
arch/powerpc/include/asm/tlb.h +6 -0
@@ -83,5 +83,11 @@ static inline int mm_is_thread_local(struct mm_struct *mm) }#endif +#define arch_supports_page_tables_move arch_supports_page_tables_move +static inline bool arch_supports_page_tables_move (void ) +{ +return radix_enabled (); +} +#endif /* __KERNEL__ */ #endif /* __ASM_POWERPC_TLB_H */
arch/x86/include/asm/tlb.h +5 -0
@@ -38,4 +38,9 @@ static inline void __tlb_remove_table(void *table) free_page_and_swap_cache(table); } +#define arch_supports_page_tables_move arch_supports_page_tables_move +static inline bool arch_supports_page_tables_move (void ) +{ +return true; +}#endif /* _ASM_X86_TLB_H */
mm/mremap.c +13 -1
@@ -26,7 +26,7 @@#include <linux/userfaultfd_k.h> #include <asm/cacheflush.h> -#include <asm/tlbflush.h> +#include <asm/tlb.h> #include <asm/pgalloc.h> #include "internal.h"
@@ -211,6 +211,14 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,drop_rmap_locks (vma); } +#ifndef arch_supports_page_tables_move +#define arch_supports_page_tables_move arch_supports_page_tables_move +static inline bool arch_supports_page_tables_move (void ) +{ +return false; +} +#endif +#ifdef CONFIG_HAVE_MOVE_PMD static bool move_normal_pmd (struct vm_area_struct *vma,unsigned long old_addr,unsigned long new_addr,pmd_t *old_pmd,pmd_t *new_pmd)
@@ -220,6 +228,8 @@ static bool move_normal_pmd(struct vm_area_struct *vma, unsigned long old_addr,struct mmu_gather tlb;pmd_t pmd; +if (!arch_supports_page_tables_move ()) +return false;/* * The destination pmd shouldn't be established, free_pgtables() * should have released it.
@@ -298,6 +308,8 @@ static bool move_normal_pud(struct vm_area_struct *vma, unsigned long old_addr,struct mmu_gather tlb;pud_t pud; +if (!arch_supports_page_tables_move ()) +return false;/* * The destination pud shouldn't be established, free_pgtables() * should have released it.
Signature · 1 line
2.29.2
RFC PATCH 6/6 powerpc/mm: Enable move pmd/pud
In reply to Aneesh Kumar K.Vmremap HAVE_MOVE_PMD/PUD optimization time comparison for 1GB region:
1GB mremap - Source PTE-aligned, Destination PTE-aligned
mremap time: 1114318ns
1GB mremap - Source PMD-aligned, Destination PMD-aligned
mremap time: 1097715ns1GB mremap - Source PUD-aligned, Destination PUD-aligned
mremap time: 26851ns
--- arch/powerpc/platforms/Kconfig.cputype | 2 ++ 1 file changed, 2 insertions(+)
arch/powerpc/platforms/Kconfig.cputype +2 -0
@@ -97,6 +97,8 @@ config PPC_BOOK3S_64 select PPC_HAVE_PMU_SUPPORT select SYS_SUPPORTS_HUGETLBFS select HAVE_ARCH_TRANSPARENT_HUGEPAGE + select HAVE_MOVE_PMD + select HAVE_MOVE_PUD select ARCH_ENABLE_THP_MIGRATION if TRANSPARENT_HUGEPAGE select ARCH_SUPPORTS_NUMA_BALANCING select IRQ_WORK
Signature · 1 line
2.29.2
RFC PATCH 1/6 selftest/mremap_test: Update the test to handle pagesize other than 4K
Instead of hardcoding 4K page size fetch it using sysconf(). For the performance measurements test still assume 2M and 1G are hugepage sizes.
--- tools/testing/selftests/vm/mremap_test.c | 113 ++++++++++++----------- 1 file changed, 61 insertions(+), 52 deletions(-)
tools/testing/selftests/vm/mremap_test.c +61 -52
@@ -45,14 +45,15 @@ enum { _4MB =4ULL <<20 , _1GB =1ULL <<30 , _2GB =2ULL <<30 , -PTE = _4KB,PMD = _2MB, PUD = _1GB, }; +#define PTE page_size +#define MAKE_TEST (source_align, destination_align, size, \ overlaps, should_fail, test_name) \ -{ \ +(struct test){ \ .name = test_name, \ .config = { \ .src_alignment = source_align, \
@@ -252,12 +253,17 @@ static int parse_args(int argc, char **argv, unsigned int *threshold_mb,return 0 ; } +#define MAX_TEST 13 +#define MAX_PERF_TEST 3int main (int argc,char **argv) {int failures =0 ;int i, run_perf_tests;unsigned int threshold_mb =VALIDATION_DEFAULT_THRESHOLD ;unsigned int pattern_seed; +struct test test_cases[MAX_TEST ]; +struct test perf_test_cases[MAX_PERF_TEST ]; +int page_size;time_t t; pattern_seed = (unsigned int )time (&t);
@@ -268,56 +274,59 @@ int main(int argc, char **argv)ksft_print_msg ("Test configs:\n\tthreshold_mb=%u\n\tpattern_seed=%u\n\n" , threshold_mb, pattern_seed); -struct test test_cases[] = { -/* Expected mremap failures */ -MAKE_TEST (_4KB, _4KB, _4KB,OVERLAPPING ,EXPECT_FAILURE , -"mremap - Source and Destination Regions Overlapping" ), -MAKE_TEST (_4KB, _1KB, _4KB,NON_OVERLAPPING ,EXPECT_FAILURE , -"mremap - Destination Address Misaligned (1KB-aligned)" ), -MAKE_TEST (_1KB, _4KB, _4KB,NON_OVERLAPPING ,EXPECT_FAILURE , -"mremap - Source Address Misaligned (1KB-aligned)" ), - -/* Src addr PTE aligned */ -MAKE_TEST (PTE ,PTE , _8KB,NON_OVERLAPPING ,EXPECT_SUCCESS , -"8KB mremap - Source PTE-aligned, Destination PTE-aligned" ), - -/* Src addr 1MB aligned */ -MAKE_TEST (_1MB,PTE , _2MB,NON_OVERLAPPING ,EXPECT_SUCCESS , -"2MB mremap - Source 1MB-aligned, Destination PTE-aligned" ), -MAKE_TEST (_1MB, _1MB, _2MB,NON_OVERLAPPING ,EXPECT_SUCCESS , -"2MB mremap - Source 1MB-aligned, Destination 1MB-aligned" ), - -/* Src addr PMD aligned */ -MAKE_TEST (PMD ,PTE , _4MB,NON_OVERLAPPING ,EXPECT_SUCCESS , -"4MB mremap - Source PMD-aligned, Destination PTE-aligned" ), -MAKE_TEST (PMD , _1MB, _4MB,NON_OVERLAPPING ,EXPECT_SUCCESS , -"4MB mremap - Source PMD-aligned, Destination 1MB-aligned" ), -MAKE_TEST (PMD ,PMD , _4MB,NON_OVERLAPPING ,EXPECT_SUCCESS , -"4MB mremap - Source PMD-aligned, Destination PMD-aligned" ), - -/* Src addr PUD aligned */ -MAKE_TEST (PUD ,PTE , _2GB,NON_OVERLAPPING ,EXPECT_SUCCESS , -"2GB mremap - Source PUD-aligned, Destination PTE-aligned" ), -MAKE_TEST (PUD , _1MB, _2GB,NON_OVERLAPPING ,EXPECT_SUCCESS , -"2GB mremap - Source PUD-aligned, Destination 1MB-aligned" ), -MAKE_TEST (PUD ,PMD , _2GB,NON_OVERLAPPING ,EXPECT_SUCCESS , -"2GB mremap - Source PUD-aligned, Destination PMD-aligned" ), -MAKE_TEST (PUD ,PUD , _2GB,NON_OVERLAPPING ,EXPECT_SUCCESS , -"2GB mremap - Source PUD-aligned, Destination PUD-aligned" ), - }; - -struct test perf_test_cases[] = { -/* -* mremap 1GB region - Page table level aligned time -* comparison. -*/ -MAKE_TEST (PTE ,PTE , _1GB,NON_OVERLAPPING ,EXPECT_SUCCESS , -"1GB mremap - Source PTE-aligned, Destination PTE-aligned" ), -MAKE_TEST (PMD ,PMD , _1GB,NON_OVERLAPPING ,EXPECT_SUCCESS , -"1GB mremap - Source PMD-aligned, Destination PMD-aligned" ), -MAKE_TEST (PUD ,PUD , _1GB,NON_OVERLAPPING ,EXPECT_SUCCESS , -"1GB mremap - Source PUD-aligned, Destination PUD-aligned" ), - }; + page_size =sysconf (_SC_PAGESIZE); + +/* Expected mremap failures */ + test_cases[0 ] =MAKE_TEST (page_size, page_size, page_size, +OVERLAPPING ,EXPECT_FAILURE , +"mremap - Source and Destination Regions Overlapping" ); + + test_cases[1 ] =MAKE_TEST (page_size, page_size/4 , page_size, +NON_OVERLAPPING ,EXPECT_FAILURE , +"mremap - Destination Address Misaligned (1KB-aligned)" ); + test_cases[2 ] =MAKE_TEST (page_size/4 , page_size, page_size, +NON_OVERLAPPING ,EXPECT_FAILURE , +"mremap - Source Address Misaligned (1KB-aligned)" ); + +/* Src addr PTE aligned */ + test_cases[3 ] =MAKE_TEST (PTE ,PTE ,PTE *2 , +NON_OVERLAPPING ,EXPECT_SUCCESS , +"8KB mremap - Source PTE-aligned, Destination PTE-aligned" ); + +/* Src addr 1MB aligned */ + test_cases[4 ] =MAKE_TEST (_1MB,PTE , _2MB,NON_OVERLAPPING ,EXPECT_SUCCESS , +"2MB mremap - Source 1MB-aligned, Destination PTE-aligned" ); + test_cases[5 ] =MAKE_TEST (_1MB, _1MB, _2MB,NON_OVERLAPPING ,EXPECT_SUCCESS , +"2MB mremap - Source 1MB-aligned, Destination 1MB-aligned" ); + +/* Src addr PMD aligned */ + test_cases[6 ] =MAKE_TEST (PMD ,PTE , _4MB,NON_OVERLAPPING ,EXPECT_SUCCESS , +"4MB mremap - Source PMD-aligned, Destination PTE-aligned" ); + test_cases[7 ] =MAKE_TEST (PMD , _1MB, _4MB,NON_OVERLAPPING ,EXPECT_SUCCESS , +"4MB mremap - Source PMD-aligned, Destination 1MB-aligned" ); + test_cases[8 ] =MAKE_TEST (PMD ,PMD , _4MB,NON_OVERLAPPING ,EXPECT_SUCCESS , +"4MB mremap - Source PMD-aligned, Destination PMD-aligned" ); + +/* Src addr PUD aligned */ + test_cases[9 ] =MAKE_TEST (PUD ,PTE , _2GB,NON_OVERLAPPING ,EXPECT_SUCCESS , +"2GB mremap - Source PUD-aligned, Destination PTE-aligned" ); + test_cases[10 ] =MAKE_TEST (PUD , _1MB, _2GB,NON_OVERLAPPING ,EXPECT_SUCCESS , +"2GB mremap - Source PUD-aligned, Destination 1MB-aligned" ); + test_cases[11 ] =MAKE_TEST (PUD ,PMD , _2GB,NON_OVERLAPPING ,EXPECT_SUCCESS , +"2GB mremap - Source PUD-aligned, Destination PMD-aligned" ); + test_cases[12 ] =MAKE_TEST (PUD ,PUD , _2GB,NON_OVERLAPPING ,EXPECT_SUCCESS , +"2GB mremap - Source PUD-aligned, Destination PUD-aligned" ); + + perf_test_cases[0 ] =MAKE_TEST (page_size, page_size, _1GB,NON_OVERLAPPING ,EXPECT_SUCCESS , +"1GB mremap - Source PTE-aligned, Destination PTE-aligned" ); +/* +* mremap 1GB region - Page table level aligned time +* comparison. +*/ + perf_test_cases[1 ] =MAKE_TEST (PMD ,PMD , _1GB,NON_OVERLAPPING ,EXPECT_SUCCESS , +"1GB mremap - Source PMD-aligned, Destination PMD-aligned" ); + perf_test_cases[2 ] =MAKE_TEST (PUD ,PUD , _1GB,NON_OVERLAPPING ,EXPECT_SUCCESS , +"1GB mremap - Source PUD-aligned, Destination PUD-aligned" ); run_perf_tests = (threshold_mb ==VALIDATION_NO_THRESHOLD ) || (threshold_mb * _1MB >= _1GB);
Signature · 1 line
2.29.2
Peter Zijlstra
maintainerRe: [RFC PATCH 3/6] mm/mremap: Use pmd/pud_poplulate to update page table entries
In reply to Aneesh Kumar K.VQuoted 4 lines · Aneesh Kumar K.V
pmd/pud_populate is the right interface to be used to set the respective page table entries. Some architectures do assume that set_pmd/pud_at can only be used to set a hugepage PTE. Since we are not setting up a hugepage PTE here, use the pmd/pud_populate interface.
Since you did the audit, it might be nice to record which architectures that are. Also, how much work to fix them?
what is the overall purpose of this patch set? maybe need a cover letter?
Quoted 159 lines · Aneesh Kumar K.V
Instead of hardcoding 4K page size fetch it using
sysconf(). For the performance measurements test still assume 2M and 1G are hugepage sizes.Signed-off-by Aneesh Kumar K.V <[email protected]>--- tools/testing/selftests/vm/mremap_test.c | 113 ++++++++++++----------- 1 file changed, 61 insertions(+), 52 deletions(-)tools/testing/selftests/vm/mremap_test.c +61
-52@@ -45,14 +45,15 @@ enum { _4MB =4ULL <<20 , _1GB =1ULL <<30 , _2GB =2ULL <<30 , -PTE = _4KB,PMD = _2MB, PUD = _1GB, }; +#define PTE page_size +#define MAKE_TEST (source_align, destination_align, size, \ overlaps, should_fail, test_name) \ -{ \ +(struct test){ \ .name = test_name, \ .config = { \ .src_alignment = source_align, \@@ -252,12 +253,17 @@ static int parse_args(int argc, char **argv, unsigned int *threshold_mb,return 0 ; } +#define MAX_TEST 13 +#define MAX_PERF_TEST 3int main (int argc,char **argv) {int failures =0 ;int i, run_perf_tests;unsigned int threshold_mb =VALIDATION_DEFAULT_THRESHOLD ;unsigned int pattern_seed; +struct test test_cases[MAX_TEST ]; +struct test perf_test_cases[MAX_PERF_TEST ]; +int page_size;time_t t; pattern_seed = (unsigned int )time (&t);@@ -268,56 +274,59 @@ int main(int argc, char **argv)ksft_print_msg ("Test configs:\n\tthreshold_mb=%u\n\tpattern_seed=%u\n\n" , threshold_mb, pattern_seed); -struct test test_cases[] = { -/* Expected mremap failures */ -MAKE_TEST (_4KB, _4KB, _4KB,OVERLAPPING ,EXPECT_FAILURE , -"mremap - Source and Destination Regions Overlapping" ), -MAKE_TEST (_4KB, _1KB, _4KB,NON_OVERLAPPING ,EXPECT_FAILURE , -"mremap - Destination Address Misaligned (1KB-aligned)" ), -MAKE_TEST (_1KB, _4KB, _4KB,NON_OVERLAPPING ,EXPECT_FAILURE , -"mremap - Source Address Misaligned (1KB-aligned)" ), - -/* Src addr PTE aligned */ -MAKE_TEST (PTE ,PTE , _8KB,NON_OVERLAPPING ,EXPECT_SUCCESS , -"8KB mremap - Source PTE-aligned, Destination PTE-aligned" ), - -/* Src addr 1MB aligned */ -MAKE_TEST (_1MB,PTE , _2MB,NON_OVERLAPPING ,EXPECT_SUCCESS , -"2MB mremap - Source 1MB-aligned, Destination PTE-aligned" ), -MAKE_TEST (_1MB, _1MB, _2MB,NON_OVERLAPPING ,EXPECT_SUCCESS , -"2MB mremap - Source 1MB-aligned, Destination 1MB-aligned" ), - -/* Src addr PMD aligned */ -MAKE_TEST (PMD ,PTE , _4MB,NON_OVERLAPPING ,EXPECT_SUCCESS , -"4MB mremap - Source PMD-aligned, Destination PTE-aligned" ), -MAKE_TEST (PMD , _1MB, _4MB,NON_OVERLAPPING ,EXPECT_SUCCESS , -"4MB mremap - Source PMD-aligned, Destination 1MB-aligned" ), -MAKE_TEST (PMD ,PMD , _4MB,NON_OVERLAPPING ,EXPECT_SUCCESS , -"4MB mremap - Source PMD-aligned, Destination PMD-aligned" ), - -/* Src addr PUD aligned */ -MAKE_TEST (PUD ,PTE , _2GB,NON_OVERLAPPING ,EXPECT_SUCCESS , -"2GB mremap - Source PUD-aligned, Destination PTE-aligned" ), -MAKE_TEST (PUD , _1MB, _2GB,NON_OVERLAPPING ,EXPECT_SUCCESS , -"2GB mremap - Source PUD-aligned, Destination 1MB-aligned" ), -MAKE_TEST (PUD ,PMD , _2GB,NON_OVERLAPPING ,EXPECT_SUCCESS , -"2GB mremap - Source PUD-aligned, Destination PMD-aligned" ), -MAKE_TEST (PUD ,PUD , _2GB,NON_OVERLAPPING ,EXPECT_SUCCESS , -"2GB mremap - Source PUD-aligned, Destination PUD-aligned" ), - }; - -struct test perf_test_cases[] = { -/* -* mremap 1GB region - Page table level aligned time -* comparison. -*/ -MAKE_TEST (PTE ,PTE , _1GB,NON_OVERLAPPING ,EXPECT_SUCCESS , -"1GB mremap - Source PTE-aligned, Destination PTE-aligned" ), -MAKE_TEST (PMD ,PMD , _1GB,NON_OVERLAPPING ,EXPECT_SUCCESS , -"1GB mremap - Source PMD-aligned, Destination PMD-aligned" ), -MAKE_TEST (PUD ,PUD , _1GB,NON_OVERLAPPING ,EXPECT_SUCCESS , -"1GB mremap - Source PUD-aligned, Destination PUD-aligned" ), - }; + page_size =sysconf (_SC_PAGESIZE); + +/* Expected mremap failures */ + test_cases[0 ] =MAKE_TEST (page_size, page_size, page_size, +OVERLAPPING ,EXPECT_FAILURE , +"mremap - Source and Destination Regions Overlapping" ); + + test_cases[1 ] =MAKE_TEST (page_size, page_size/4 , page_size, +NON_OVERLAPPING ,EXPECT_FAILURE , +"mremap - Destination Address Misaligned (1KB-aligned)" ); + test_cases[2 ] =MAKE_TEST (page_size/4 , page_size, page_size, +NON_OVERLAPPING ,EXPECT_FAILURE , +"mremap - Source Address Misaligned (1KB-aligned)" ); + +/* Src addr PTE aligned */ + test_cases[3 ] =MAKE_TEST (PTE ,PTE ,PTE *2 , +NON_OVERLAPPING ,EXPECT_SUCCESS , +"8KB mremap - Source PTE-aligned, Destination PTE-aligned" ); + +/* Src addr 1MB aligned */ + test_cases[4 ] =MAKE_TEST (_1MB,PTE , _2MB,NON_OVERLAPPING ,EXPECT_SUCCESS , +"2MB mremap - Source 1MB-aligned, Destination PTE-aligned" ); + test_cases[5 ] =MAKE_TEST (_1MB, _1MB, _2MB,NON_OVERLAPPING ,EXPECT_SUCCESS , +"2MB mremap - Source 1MB-aligned, Destination 1MB-aligned" ); + +/* Src addr PMD aligned */ + test_cases[6 ] =MAKE_TEST (PMD ,PTE , _4MB,NON_OVERLAPPING ,EXPECT_SUCCESS , +"4MB mremap - Source PMD-aligned, Destination PTE-aligned" ); + test_cases[7 ] =MAKE_TEST (PMD , _1MB, _4MB,NON_OVERLAPPING ,EXPECT_SUCCESS , +"4MB mremap - Source PMD-aligned, Destination 1MB-aligned" ); + test_cases[8 ] =MAKE_TEST (PMD ,PMD , _4MB,NON_OVERLAPPING ,EXPECT_SUCCESS , +"4MB mremap - Source PMD-aligned, Destination PMD-aligned" ); + +/* Src addr PUD aligned */ + test_cases[9 ] =MAKE_TEST (PUD ,PTE , _2GB,NON_OVERLAPPING ,EXPECT_SUCCESS , +"2GB mremap - Source PUD-aligned, Destination PTE-aligned" ); + test_cases[10 ] =MAKE_TEST (PUD , _1MB, _2GB,NON_OVERLAPPING ,EXPECT_SUCCESS , +"2GB mremap - Source PUD-aligned, Destination 1MB-aligned" ); + test_cases[11 ] =MAKE_TEST (PUD ,PMD , _2GB,NON_OVERLAPPING ,EXPECT_SUCCESS , +"2GB mremap - Source PUD-aligned, Destination PMD-aligned" ); + test_cases[12 ] =MAKE_TEST (PUD ,PUD , _2GB,NON_OVERLAPPING ,EXPECT_SUCCESS , +"2GB mremap - Source PUD-aligned, Destination PUD-aligned" ); + + perf_test_cases[0 ] =MAKE_TEST (page_size, page_size, _1GB,NON_OVERLAPPING ,EXPECT_SUCCESS , +"1GB mremap - Source PTE-aligned, Destination PTE-aligned" ); +/* +* mremap 1GB region - Page table level aligned time +* comparison. +*/ + perf_test_cases[1 ] =MAKE_TEST (PMD ,PMD , _1GB,NON_OVERLAPPING ,EXPECT_SUCCESS , +"1GB mremap - Source PMD-aligned, Destination PMD-aligned" ); + perf_test_cases[2 ] =MAKE_TEST (PUD ,PUD , _1GB,NON_OVERLAPPING ,EXPECT_SUCCESS , +"1GB mremap - Source PUD-aligned, Destination PUD-aligned" ); run_perf_tests = (threshold_mb ==VALIDATION_NO_THRESHOLD ) || (threshold_mb * _1MB >= _1GB);
Re: [RFC PATCH 3/6] mm/mremap: Use pmd/pud_poplulate to update page table entries
In reply to Peter ZijlstraQuoted 9 lines · Peter Zijlstra
Quoted 4 lines · Aneesh Kumar K.V
pmd/pud_populate is the right interface to be used to set the respective page table entries. Some architectures do assume that set_pmd/pud_at can only be used to set a hugepage PTE. Since we are not setting up a hugepage PTE here, use the pmd/pud_populate interface.
Since you did the audit, it might be nice to record which architectures that are. Also, how much work to fix them?
I didn't audit them completely primarily because I don't follow the page table format of other archs. But I guess arm64, s390 appears to make that assumption.
Moreover set_pmd_at was added as part of THP patch series.
BTW why should we fix those architectures ? isn't pmd_populate the right interface for updating pmd entries other than hugepage pte ?
-aneesh
Quoted 3 lines · Li Xinhai
what is the overall purpose of this patch set? maybe need a cover letter?
The goal of the patch series was to enable MOVE_PMD/PUD on ppc64. But the series itself achieves that by fixing the existing code rather than adding changes to arch/ppc64. With that we could consider the series as a bug fix series.
-aneesh
kernel test robot
build botRe: [RFC PATCH 3/6] mm/mremap: Use pmd/pud_poplulate to update page table entries
In reply to Aneesh Kumar K.V[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
Hi "Aneesh,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on kselftest/next]
[also build test WARNING on powerpc/next v5.11-rc6 next-20210125] [cannot apply to hnaz-linux-mm/master]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Aneesh-Kumar-K-V/selftest-mremap_test-Update-the-test-to-handle-pagesize-other-than-4K/20210202-173010 base: https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git next config: i386-randconfig-s001-20210202 (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0 reproduce: # apt-get install sparse # sparse version: v0.6.3-215-g0fb77bb6-dirty # https://github.com/0day-ci/linux/commit/e3237cf6d75a40d5736e26dc623b34e9a89cfdc9 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Aneesh-Kumar-K-V/selftest-mremap_test-Update-the-test-to-handle-pagesize-other-than-4K/20210202-173010 git checkout e3237cf6d75a40d5736e26dc623b34e9a89cfdc9 # save the attached .config to linux build tree make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=i386
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
mm/mremap.c: In function 'move_normal_pud':
>> mm/mremap.c:286:8: warning: variable 'pud' set but not used [-Wunused-but-set-variable]
286 | pud_t pud;
| ^~~vim +/pud +286 mm/mremap.c
2c91bd4a4e2e53 Joel Fernandes (Google 2019-01-03 279)
c49dd340180260 Kalesh Singh 2020-12-14 280 #ifdef CONFIG_HAVE_MOVE_PUD
c49dd340180260 Kalesh Singh 2020-12-14 281 static bool move_normal_pud(struct vm_area_struct *vma, unsigned long old_addr,
c49dd340180260 Kalesh Singh 2020-12-14 282 unsigned long new_addr, pud_t *old_pud, pud_t *new_pud)
c49dd340180260 Kalesh Singh 2020-12-14 283 {
c49dd340180260 Kalesh Singh 2020-12-14 284 spinlock_t *old_ptl, *new_ptl;
c49dd340180260 Kalesh Singh 2020-12-14 285 struct mm_struct *mm = vma->vm_mm;
c49dd340180260 Kalesh Singh 2020-12-14 @286 pud_t pud;
c49dd340180260 Kalesh Singh 2020-12-14 287
c49dd340180260 Kalesh Singh 2020-12-14 288 /*
c49dd340180260 Kalesh Singh 2020-12-14 289 * The destination pud shouldn't be established, free_pgtables()
c49dd340180260 Kalesh Singh 2020-12-14 290 * should have released it.
c49dd340180260 Kalesh Singh 2020-12-14 291 */
c49dd340180260 Kalesh Singh 2020-12-14 292 if (WARN_ON_ONCE(!pud_none(*new_pud)))
c49dd340180260 Kalesh Singh 2020-12-14 293 return false;
c49dd340180260 Kalesh Singh 2020-12-14 294
c49dd340180260 Kalesh Singh 2020-12-14 295 /*
c49dd340180260 Kalesh Singh 2020-12-14 296 * We don't have to worry about the ordering of src and dst
c49dd340180260 Kalesh Singh 2020-12-14 297 * ptlocks because exclusive mmap_lock prevents deadlock.
c49dd340180260 Kalesh Singh 2020-12-14 298 */
c49dd340180260 Kalesh Singh 2020-12-14 299 old_ptl = pud_lock(vma->vm_mm, old_pud);
c49dd340180260 Kalesh Singh 2020-12-14 300 new_ptl = pud_lockptr(mm, new_pud);
c49dd340180260 Kalesh Singh 2020-12-14 301 if (new_ptl != old_ptl)
c49dd340180260 Kalesh Singh 2020-12-14 302 spin_lock_nested(new_ptl, SINGLE_DEPTH_NESTING);
c49dd340180260 Kalesh Singh 2020-12-14 303
c49dd340180260 Kalesh Singh 2020-12-14 304 /* Clear the pud */
c49dd340180260 Kalesh Singh 2020-12-14 305 pud = *old_pud;
c49dd340180260 Kalesh Singh 2020-12-14 306 pud_clear(old_pud);
c49dd340180260 Kalesh Singh 2020-12-14 307
c49dd340180260 Kalesh Singh 2020-12-14 308 VM_BUG_ON(!pud_none(*new_pud));
c49dd340180260 Kalesh Singh 2020-12-14 309
e3237cf6d75a40 Aneesh Kumar K.V 2021-02-02 310 pud_populate(mm, new_pud, (pmd_t *)pud_page_vaddr(pud));
c49dd340180260 Kalesh Singh 2020-12-14 311 flush_tlb_range(vma, old_addr, old_addr + PUD_SIZE);
c49dd340180260 Kalesh Singh 2020-12-14 312 if (new_ptl != old_ptl)
c49dd340180260 Kalesh Singh 2020-12-14 313 spin_unlock(new_ptl);
c49dd340180260 Kalesh Singh 2020-12-14 314 spin_unlock(old_ptl);
c49dd340180260 Kalesh Singh 2020-12-14 315
c49dd340180260 Kalesh Singh 2020-12-14 316 return true;
c49dd340180260 Kalesh Singh 2020-12-14 317 }
c49dd340180260 Kalesh Singh 2020-12-14 318 #else
c49dd340180260 Kalesh Singh 2020-12-14 319 static inline bool move_normal_pud(struct vm_area_struct *vma,
c49dd340180260 Kalesh Singh 2020-12-14 320 unsigned long old_addr, unsigned long new_addr, pud_t *old_pud,
c49dd340180260 Kalesh Singh 2020-12-14 321 pud_t *new_pud)
c49dd340180260 Kalesh Singh 2020-12-14 322 {
c49dd340180260 Kalesh Singh 2020-12-14 323 return false;
c49dd340180260 Kalesh Singh 2020-12-14 324 }
c49dd340180260 Kalesh Singh 2020-12-14 325 #endif
c49dd340180260 Kalesh Singh 2020-12-14 326 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org