Re: [PATCH] mm/debug: Add tests validating arch page table helpers for core features

2020-03-01 Thread Anshuman Khandual
On 02/27/2020 04:59 PM, Christophe Leroy wrote:
> 
> 
> Le 27/02/2020 à 11:33, Anshuman Khandual a écrit :
>> This adds new tests validating arch page table helpers for these following
>> core memory features. These tests create and test specific mapping types at
>> various page table levels.
>>
>> * SPECIAL mapping
>> * PROTNONE mapping
>> * DEVMAP mapping
>> * SOFTDIRTY mapping
>> * SWAP mapping
>> * MIGRATION mapping
>> * HUGETLB mapping
>> * THP mapping
>>
>> Cc: Andrew Morton 
>> Cc: Mike Rapoport 
>> Cc: Vineet Gupta 
>> Cc: Catalin Marinas 
>> Cc: Will Deacon 
>> Cc: Benjamin Herrenschmidt 
>> Cc: Paul Mackerras 
>> Cc: Michael Ellerman 
>> Cc: Heiko Carstens 
>> Cc: Vasily Gorbik 
>> Cc: Christian Borntraeger 
>> Cc: Thomas Gleixner 
>> Cc: Ingo Molnar 
>> Cc: Borislav Petkov 
>> Cc: "H. Peter Anvin" 
>> Cc: Kirill A. Shutemov 
>> Cc: Paul Walmsley 
>> Cc: Palmer Dabbelt 
>> Cc: linux-snps-arc@lists.infradead.org
>> Cc: linux-arm-ker...@lists.infradead.org
>> Cc: linuxppc-...@lists.ozlabs.org
>> Cc: linux-s...@vger.kernel.org
>> Cc: linux-ri...@lists.infradead.org
>> Cc: x...@kernel.org
>> Cc: linux-a...@vger.kernel.org
>> Cc: linux-ker...@vger.kernel.org
>> Suggested-by: Catalin Marinas 
>> Signed-off-by: Anshuman Khandual 
>> ---
>> Tested on arm64 and x86 platforms without any test failures. But this has
>> only been built tested on several other platforms. Individual tests need
>> to be verified on all current enabling platforms for the test i.e s390,
>> ppc32, arc etc.
>>
>> This patch must be applied on v5.6-rc3 after these patches
>>
>> 1. https://patchwork.kernel.org/patch/11385057/
>> 2. https://patchwork.kernel.org/patch/11407715/
>>
>> OR
>>
>> This patch must be applied on linux-next (next-20200227) after this patch
>>
>> 2. https://patchwork.kernel.org/patch/11407715/
>>
>>   mm/debug_vm_pgtable.c | 310 +-
>>   1 file changed, 309 insertions(+), 1 deletion(-)
>>
>> diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c
>> index 96dd7d574cef..3fb90d5b604e 100644
>> --- a/mm/debug_vm_pgtable.c
>> +++ b/mm/debug_vm_pgtable.c
>> @@ -41,6 +41,44 @@
>>    * wrprotect(entry)    = A write protected and not a write entry
>>    * pxx_bad(entry)    = A mapped and non-table entry
>>    * pxx_same(entry1, entry2)    = Both entries hold the exact same value
>> + *
>> + * Specific feature operations
>> + *
>> + * pte_mkspecial(entry)    = Creates a special entry at PTE level
>> + * pte_special(entry)    = Tests a special entry at PTE level
>> + *
>> + * pte_protnone(entry)    = Tests a no access entry at PTE level
>> + * pmd_protnone(entry)    = Tests a no access entry at PMD level
>> + *
>> + * pte_mkdevmap(entry)    = Creates a device entry at PTE level
>> + * pmd_mkdevmap(entry)    = Creates a device entry at PMD level
>> + * pud_mkdevmap(entry)    = Creates a device entry at PUD level
>> + * pte_devmap(entry)    = Tests a device entry at PTE level
>> + * pmd_devmap(entry)    = Tests a device entry at PMD level
>> + * pud_devmap(entry)    = Tests a device entry at PUD level
>> + *
>> + * pte_mksoft_dirty(entry)    = Creates a soft dirty entry at PTE level
>> + * pmd_mksoft_dirty(entry)    = Creates a soft dirty entry at PMD level
>> + * pte_swp_mksoft_dirty(entry)    = Creates a soft dirty swap entry at PTE 
>> level
>> + * pmd_swp_mksoft_dirty(entry)    = Creates a soft dirty swap entry at PMD 
>> level
>> + * pte_soft_dirty(entry)    = Tests a soft dirty entry at PTE level
>> + * pmd_soft_dirty(entry)    = Tests a soft dirty entry at PMD level
>> + * pte_swp_soft_dirty(entry)    = Tests a soft dirty swap entry at PTE level
>> + * pmd_swp_soft_dirty(entry)    = Tests a soft dirty swap entry at PMD level
>> + * pte_clear_soft_dirty(entry)   = Clears a soft dirty entry at PTE 
>> level
>> + * pmd_clear_soft_dirty(entry)   = Clears a soft dirty entry at PMD 
>> level
>> + * pte_swp_clear_soft_dirty(entry) = Clears a soft dirty swap entry at PTE 
>> level
>> + * pmd_swp_clear_soft_dirty(entry) = Clears a soft dirty swap entry at PMD 
>> level
>> + *
>> + * pte_mkhuge(entry)    = Creates a HugeTLB entry at given level
>> + * pte_huge(entry)    = Tests a HugeTLB entry at given level
>> + *
>> + * pmd_trans_huge(entry)    = Tests a trans huge page at PMD level
>> + * pud_trans_huge(entry)    = Tests a trans huge page at PUD level
>> + * pmd_present(entry)    = Tests an entry points to memory at PMD level
>> + * pud_present(entry)    = Tests an entry points to memory at PUD level
>> + * pmd_mknotpresent(entry)    = Invalidates an PMD entry for MMU
>> + * pud_mknotpresent(entry)    = Invalidates an PUD entry for MMU
>>    */
>>   #define VMFLAGS    (VM_READ|VM_WRITE|VM_EXEC)
>>   @@ -287,6 +325,233 @@ static void __init pmd_populate_tests(struct 
>> mm_struct *mm, pmd_t *pmdp,
>>   WARN_ON(pmd_bad(pmd));
>>   }
>>   +#ifdef CONFIG_ARCH_HAS_PTE_SPECIAL
> 
> Can we avoid ifdefs unless nece

[RFC 1/3] mm/vma: Define a default value for VM_DATA_DEFAULT_FLAGS

2020-03-01 Thread Anshuman Khandual
There are many platforms with exact same value for VM_DATA_DEFAULT_FLAGS
This creates a default value for VM_DATA_DEFAULT_FLAGS in line with the
existing VM_STACK_DEFAULT_FLAGS. While here, also define some more macros
with standard VMA access flag combinations that are used frequently across
many platforms. Apart from simplification, this reduces code duplication
as well.

Cc: Richard Henderson 
Cc: Vineet Gupta 
Cc: Russell King 
Cc: Catalin Marinas 
Cc: Mark Salter 
Cc: Guo Ren 
Cc: Yoshinori Sato 
Cc: Brian Cain 
Cc: Tony Luck 
Cc: Geert Uytterhoeven 
Cc: Michal Simek 
Cc: Ralf Baechle 
Cc: Paul Burton 
Cc: Nick Hu 
Cc: Ley Foon Tan 
Cc: Jonas Bonn 
Cc: "James E.J. Bottomley" 
Cc: Michael Ellerman 
Cc: Paul Walmsley 
Cc: Heiko Carstens 
Cc: Rich Felker 
Cc: "David S. Miller" 
Cc: Guan Xuetao 
Cc: Thomas Gleixner 
Cc: Jeff Dike 
Cc: Chris Zankel 
Cc: Andrew Morton 
Cc: linux-al...@vger.kernel.org
Cc: linux-ker...@vger.kernel.org
Cc: linux-snps-arc@lists.infradead.org
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-c6x-...@linux-c6x.org
Cc: uclinux-h8-de...@lists.sourceforge.jp
Cc: linux-hexa...@vger.kernel.org
Cc: linux-i...@vger.kernel.org
Cc: linux-m...@lists.linux-m68k.org
Cc: linux-m...@vger.kernel.org
Cc: nios2-...@lists.rocketboards.org
Cc: openr...@lists.librecores.org
Cc: linux-par...@vger.kernel.org
Cc: linuxppc-...@lists.ozlabs.org
Cc: linux-ri...@lists.infradead.org
Cc: linux-s...@vger.kernel.org
Cc: linux...@vger.kernel.org
Cc: sparcli...@vger.kernel.org
Cc: linux...@lists.infradead.org
Cc: linux-xte...@linux-xtensa.org
Cc: linux...@kvack.org
Signed-off-by: Anshuman Khandual 
---
 arch/alpha/include/asm/page.h  |  3 ---
 arch/arc/include/asm/page.h|  2 +-
 arch/arm/include/asm/page.h|  4 +---
 arch/arm64/include/asm/page.h  |  4 +---
 arch/c6x/include/asm/page.h|  5 +
 arch/csky/include/asm/page.h   |  3 ---
 arch/h8300/include/asm/page.h  |  2 --
 arch/hexagon/include/asm/page.h|  3 +--
 arch/ia64/include/asm/page.h   |  5 +
 arch/m68k/include/asm/page.h   |  3 ---
 arch/microblaze/include/asm/page.h |  2 --
 arch/mips/include/asm/page.h   |  5 +
 arch/nds32/include/asm/page.h  |  3 ---
 arch/nios2/include/asm/page.h  |  3 +--
 arch/openrisc/include/asm/page.h   |  5 -
 arch/parisc/include/asm/page.h |  3 ---
 arch/powerpc/include/asm/page.h|  9 ++---
 arch/powerpc/include/asm/page_64.h |  7 ++-
 arch/riscv/include/asm/page.h  |  3 +--
 arch/s390/include/asm/page.h   |  3 +--
 arch/sh/include/asm/page.h |  3 ---
 arch/sparc/include/asm/page_32.h   |  3 ---
 arch/sparc/include/asm/page_64.h   |  3 ---
 arch/unicore32/include/asm/page.h  |  3 ---
 arch/x86/include/asm/page_types.h  |  4 +---
 arch/x86/um/asm/vm-flags.h | 10 ++
 arch/xtensa/include/asm/page.h |  3 ---
 include/linux/mm.h | 15 +++
 28 files changed, 32 insertions(+), 89 deletions(-)

diff --git a/arch/alpha/include/asm/page.h b/arch/alpha/include/asm/page.h
index f3fb2848470a..e241bd0f 100644
--- a/arch/alpha/include/asm/page.h
+++ b/arch/alpha/include/asm/page.h
@@ -90,9 +90,6 @@ typedef struct page *pgtable_t;
 #define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
 #endif /* CONFIG_DISCONTIGMEM */
 
-#define VM_DATA_DEFAULT_FLAGS  (VM_READ | VM_WRITE | VM_EXEC | \
-VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
-
 #include 
 #include 
 
diff --git a/arch/arc/include/asm/page.h b/arch/arc/include/asm/page.h
index 0a32e8cfd074..b0dfed0f12be 100644
--- a/arch/arc/include/asm/page.h
+++ b/arch/arc/include/asm/page.h
@@ -102,7 +102,7 @@ typedef pte_t * pgtable_t;
 #define virt_addr_valid(kaddr)  pfn_valid(virt_to_pfn(kaddr))
 
 /* Default Permissions for stack/heaps pages (Non Executable) */
-#define VM_DATA_DEFAULT_FLAGS   (VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE 
| VM_MAYEXEC)
+#define VM_DATA_DEFAULT_FLAGS  VM_DATA_FLAGS_NON_EXEC
 
 #define WANT_PAGE_VIRTUAL   1
 
diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
index c2b75cba26df..11b058a72a5b 100644
--- a/arch/arm/include/asm/page.h
+++ b/arch/arm/include/asm/page.h
@@ -161,9 +161,7 @@ extern int pfn_valid(unsigned long);
 
 #endif /* !__ASSEMBLY__ */
 
-#define VM_DATA_DEFAULT_FLAGS \
-   (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
-VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
+#define VM_DATA_DEFAULT_FLAGS  VM_DATA_FLAGS_TSK_EXEC
 
 #include 
 
diff --git a/arch/arm64/include/asm/page.h b/arch/arm64/include/asm/page.h
index d39ddb258a04..cb4e1e6ca385 100644
--- a/arch/arm64/include/asm/page.h
+++ b/arch/arm64/include/asm/page.h
@@ -32,9 +32,7 @@ extern int pfn_valid(unsigned long);
 
 #endif /* !__ASSEMBLY__ */
 
-#define VM_DATA_DEFAULT_FLAGS \
-   (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
-VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)

[RFC 0/3] mm/vma: some new flags and helpers

2020-03-01 Thread Anshuman Khandual
The motivation here is to consolidate VMA flag combinations commonly used
across platforms and reduce code duplication while making it uncluttered
in general.

This first introduces a default VM_DATA_DEFAULT_FLAGS which platforms can
easily fall back on without requiring to define any similar data flag
combinations as they currently do. This also adds some more common data
flag combinations which are generally used when the platforms decide to
override the default.

The second patch consolidates VM_READ, VM_WRITE, VM_EXEC as VM_ACCESS_FLAGS
extending the existing VMA accessibility concept via vma_is_accessibility().
VM_ACCESS_FLAGS replaces many other instances which used check all three
VMA access flags simultaneously.

While here, this also adds some more special VMA flag based helpers which
wraps around similar checks at various places thus improving readability.
This series intentionally limits these new helpers which are applicable 
only for special purpose VM flags than the more common ones like VM_READ,
VM_WRITE, VM_EXEC, VM_SHARED etc just to limit code churn. But if there is
common agreement that every flag should have it's own wrapper here, we can
do that as well. Otherwise if this patch seems really unnecessary with much
code churn, will be happy to drop it.

Reviews, comments, suggestions and concerns welcome. Thank you.

This series is based on v5.6-r4 after applying these patches.

1. https://patchwork.kernel.org/cover/11399319/
2. https://patchwork.kernel.org/patch/11399379/

This series is build tested across multiple architectures but boot tested
only on arm64 and x86 platforms.

Cc: linux-al...@vger.kernel.org
Cc: linux-ker...@vger.kernel.org
Cc: linux-snps-arc@lists.infradead.org
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-c6x-...@linux-c6x.org
Cc: uclinux-h8-de...@lists.sourceforge.jp
Cc: linux-hexa...@vger.kernel.org
Cc: linux-i...@vger.kernel.org
Cc: linux-m...@lists.linux-m68k.org
Cc: linux-m...@vger.kernel.org
Cc: nios2-...@lists.rocketboards.org
Cc: openr...@lists.librecores.org
Cc: linux-par...@vger.kernel.org
Cc: linuxppc-...@lists.ozlabs.org
Cc: linux-ri...@lists.infradead.org
Cc: linux-s...@vger.kernel.org
Cc: linux...@vger.kernel.org
Cc: sparcli...@vger.kernel.org
Cc: linux...@lists.infradead.org
Cc: linux-xte...@linux-xtensa.org
Cc: linux...@kvack.org

Anshuman Khandual (3):
  mm/vma: Define a default value for VM_DATA_DEFAULT_FLAGS
  mm/vma: Introduce VM_ACCESS_FLAGS
  mm/vma: Introduce some more VMA flag wrappers

 arch/alpha/include/asm/page.h|  3 --
 arch/arc/include/asm/page.h  |  2 +-
 arch/arm/include/asm/page.h  |  4 +-
 arch/arm/mm/fault.c  |  2 +-
 arch/arm64/include/asm/page.h|  4 +-
 arch/arm64/mm/fault.c|  2 +-
 arch/c6x/include/asm/page.h  |  5 +--
 arch/c6x/include/asm/processor.h |  2 +-
 arch/csky/include/asm/page.h |  3 --
 arch/h8300/include/asm/page.h|  2 -
 arch/hexagon/include/asm/page.h  |  3 +-
 arch/ia64/include/asm/page.h |  5 +--
 arch/m68k/include/asm/page.h |  3 --
 arch/microblaze/include/asm/page.h   |  2 -
 arch/mips/include/asm/page.h |  5 +--
 arch/nds32/include/asm/page.h|  3 --
 arch/nds32/mm/fault.c|  2 +-
 arch/nios2/include/asm/page.h|  3 +-
 arch/nios2/include/asm/processor.h   |  2 +-
 arch/openrisc/include/asm/page.h |  5 ---
 arch/parisc/include/asm/page.h   |  3 --
 arch/powerpc/include/asm/page.h  |  9 +
 arch/powerpc/include/asm/page_64.h   |  7 +---
 arch/powerpc/mm/book3s64/pkeys.c |  2 +-
 arch/riscv/include/asm/page.h|  3 +-
 arch/s390/include/asm/page.h |  3 +-
 arch/s390/mm/fault.c |  2 +-
 arch/sh/include/asm/page.h   |  3 --
 arch/sh/include/asm/processor_64.h   |  2 +-
 arch/sparc/include/asm/mman.h|  2 +-
 arch/sparc/include/asm/page_32.h |  3 --
 arch/sparc/include/asm/page_64.h |  3 --
 arch/unicore32/include/asm/page.h|  3 --
 arch/unicore32/mm/fault.c|  2 +-
 arch/x86/include/asm/page_types.h|  4 +-
 arch/x86/mm/pkeys.c  |  2 +-
 arch/x86/um/asm/vm-flags.h   | 10 +
 arch/xtensa/include/asm/page.h   |  3 --
 drivers/staging/gasket/gasket_core.c |  2 +-
 fs/binfmt_elf.c  |  2 +-
 fs/proc/task_mmu.c   | 14 +++
 include/linux/huge_mm.h  |  4 +-
 include/linux/mm.h   | 58 +++-
 kernel/events/core.c |  2 +-
 kernel/events/uprobes.c  |  2 +-
 mm/gup.c |  2 +-
 mm/huge_memory.c |  6 +--
 mm/hugetlb.c |  4 +-
 mm/ksm.c |  8 ++--
 mm/madvise.c |  4 +-
 mm/memory.c  |  4 +-
 mm/migrate.c |  4 +-
 mm/mlock.c   |  4 +-
 mm/mmap.c