mm: Make vm_get_page_prot arch specific.
Subsystems (11)
PATCH 1/2 mm: Make vm_get_page_prot arch specific.
With next generation power processor, we are having a new mmu model
[1] that require us to maintain a different linux page table format.
Inorder to support both current and future ppc64 systems with a single kernel we need to make sure kernel can select between different page table format at runtime. With the new MMU (radix MMU) added, we will have to dynamically switch between different protection map. Hence override vm_get_page_prot instead of using arch_vm_get_page_prot. We also drop arch_vm_get_page_prot since only powerpc used it.
[1] http://ibm.biz/power-isa3 (Needs registration).
--- arch/powerpc/include/asm/book3s/64/hash.h | 3 +++ arch/powerpc/include/asm/mman.h | 6 ------ arch/powerpc/mm/hash_utils_64.c | 19 +++++++++++++++++++ include/linux/mman.h | 4 ---- mm/mmap.c | 9 ++++++--- 5 files changed, 28 insertions(+), 13 deletions(-)
arch/powerpc/include/asm/book3s/64/hash.h +3 -0
@@ -538,6 +538,9 @@ static inline pgprot_t pgprot_writecombine(pgprot_t prot)return pgprot_noncached_wc (prot); } +extern pgprot_t vm_get_page_prot (unsigned long vm_flags); +#define vm_get_page_prot vm_get_page_prot +#ifdef CONFIG_TRANSPARENT_HUGEPAGE extern void hpte_do_hugepage_flush (struct mm_struct *mm,unsigned long addr,pmd_t *pmdp,unsigned long old_pmd);
arch/powerpc/include/asm/mman.h +0 -6
@@ -24,12 +24,6 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot) }#define arch_calc_vm_prot_bits (prot) arch_calc_vm_prot_bits(prot) -static inline pgprot_t arch_vm_get_page_prot (unsigned long vm_flags) -{ -return (vm_flags &VM_SAO ) ?__pgprot (_PAGE_SAO) :__pgprot (0 ); -} -#define arch_vm_get_page_prot (vm_flags) arch_vm_get_page_prot(vm_flags) -static inline int arch_validate_prot (unsigned long prot) {if (prot & ~(PROT_READ |PROT_WRITE |PROT_EXEC |PROT_SEM |PROT_SAO ))
arch/powerpc/mm/hash_utils_64.c +19 -0
@@ -1564,3 +1564,22 @@ void setup_initial_memory_limit(phys_addr_t first_memblock_base,/* Finally limit subsequent allocations */ memblock_set_current_limit (ppc64_rma_size); } + +static pgprot_t hash_protection_map[16 ] = { + __P000, __P001, __P010, __P011, __P100, + __P101, __P110, __P111, __S000, __S001, + __S010, __S011, __S100, __S101, __S110, __S111 +}; + +pgprot_t vm_get_page_prot (unsigned long vm_flags) +{ +pgprot_t prot_soa =__pgprot (0 ); + +if (vm_flags &VM_SAO ) + prot_soa =__pgprot (_PAGE_SAO); + +return __pgprot (pgprot_val (hash_protection_map[vm_flags & + (VM_READ |VM_WRITE |VM_EXEC |VM_SHARED )]) | +pgprot_val (prot_soa)); +} +EXPORT_SYMBOL (vm_get_page_prot);
include/linux/mman.h +0 -4
@@ -38,10 +38,6 @@ static inline void vm_unacct_memory(long pages)#define arch_calc_vm_prot_bits (prot) 0#endif -#ifndef arch_vm_get_page_prot -#define arch_vm_get_page_prot (vm_flags) __pgprot(0) -#endif -#ifndef arch_validate_prot/* * This is called from mprotect(). PROT_GROWSDOWN and PROT_GROWSUP have
mm/mmap.c +6 -3
@@ -92,6 +92,10 @@ static void unmap_region(struct mm_struct *mm,* x: (no) no x: (no) yes x: (no) yes x: (yes) yes * */ +/* +* Give arch an option to override the below in dynamic matter +*/ +#ifndef vm_get_page_protpgprot_t protection_map[16 ] = { __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111, __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
@@ -99,11 +103,10 @@ pgprot_t protection_map[16] = {pgprot_t vm_get_page_prot (unsigned long vm_flags) { -return __pgprot (pgprot_val (protection_map[vm_flags & - (VM_READ |VM_WRITE |VM_EXEC |VM_SHARED )]) | -pgprot_val (arch_vm_get_page_prot (vm_flags))); +return protection_map[vm_flags & (VM_READ |VM_WRITE |VM_EXEC |VM_SHARED )]; }EXPORT_SYMBOL (vm_get_page_prot); +#endif static pgprot_t vm_pgprot_modify (pgprot_t oldprot,unsigned long vm_flags) {
Signature · 7 lines
2.5.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 2/2 mm: Some arch may want to use HPAGE_PMD related values as variables
With next generation power processor, we are having a new mmu model
[1] that require us to maintain a different linux page table format.
Inorder to support both current and future ppc64 systems with a single kernel we need to make sure kernel can select between different page table format at runtime. With the new MMU (radix MMU) added, we will have two different pmd hugepage size 16MB for hash model and 2MB for Radix model. Hence make HPAGE_PMD related values as a variable.
[1] http://ibm.biz/power-isa3 (Needs registration).
--- arch/arm/include/asm/pgtable-3level.h | 8 ++++++++ arch/arm64/include/asm/pgtable.h | 7 +++++++ arch/mips/include/asm/pgtable.h | 8 ++++++++ arch/powerpc/mm/pgtable_64.c | 7 +++++++ arch/s390/include/asm/pgtable.h | 8 ++++++++ arch/sparc/include/asm/pgtable_64.h | 7 +++++++ arch/tile/include/asm/pgtable.h | 9 +++++++++ arch/x86/include/asm/pgtable.h | 8 ++++++++ include/linux/huge_mm.h | 3 --- mm/huge_memory.c | 8 +++++--- 10 files changed, 67 insertions(+), 6 deletions(-)
arch/arm/include/asm/pgtable-3level.h +8 -0
@@ -281,6 +281,14 @@ static inline void set_pmd_at(struct mm_struct *mm, unsigned long addr,flush_pmd_entry (pmdp); } +#if HPAGE_PMD_ORDER >=MAX_ORDER +#error "hugepages can't be allocated by the buddy allocator" +#endif + +#if HPAGE_PMD_ORDER <2 +#error "We need more than 2 pages to do deferred thp split" +#endif +static inline int has_transparent_hugepage (void ) {return 1 ;
arch/arm64/include/asm/pgtable.h +7 -0
@@ -378,6 +378,13 @@ static inline pgprot_t mk_sect_prot(pgprot_t prot)#define set_pmd_at (mm, addr, pmdp, pmd) set_pte_at(mm, addr, (pte_t *)pmdp, pmd_pte(pmd)) +#if HPAGE_PMD_ORDER >=MAX_ORDER +#error "hugepages can't be allocated by the buddy allocator" +#endif + +#if HPAGE_PMD_ORDER <2 +#error "We need more than 2 pages to do deferred thp split" +#endif static inline int has_transparent_hugepage (void ) {return 1 ;
arch/mips/include/asm/pgtable.h +8 -0
@@ -468,6 +468,14 @@ static inline int io_remap_pfn_range(struct vm_area_struct *vma,#ifdef CONFIG_TRANSPARENT_HUGEPAGE +#if HPAGE_PMD_ORDER >=MAX_ORDER +#error "hugepages can't be allocated by the buddy allocator" +#endif + +#if HPAGE_PMD_ORDER <2 +#error "We need more than 2 pages to do deferred thp split" +#endif +extern int has_transparent_hugepage (void );static inline int pmd_trans_huge (pmd_t pmd)
arch/powerpc/mm/pgtable_64.c +7 -0
@@ -818,6 +818,13 @@ pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm,int has_transparent_hugepage (void ) { + +BUILD_BUG_ON_MSG ((PMD_SHIFT -PAGE_SHIFT ) >=MAX_ORDER , +"hugepages can't be allocated by the buddy allocator" ); + +BUILD_BUG_ON_MSG ((PMD_SHIFT -PAGE_SHIFT ) <2 , +"We need more than 2 pages to do deferred thp split" ); +if (!mmu_has_feature (MMU_FTR_16M_PAGE ))return 0 ;/*
arch/s390/include/asm/pgtable.h +8 -0
@@ -1617,6 +1617,14 @@ static inline int pmd_trans_huge(pmd_t pmd)return pmd_val (pmd) & _SEGMENT_ENTRY_LARGE; } +#if HPAGE_PMD_ORDER >=MAX_ORDER +#error "hugepages can't be allocated by the buddy allocator" +#endif + +#if HPAGE_PMD_ORDER <2 +#error "We need more than 2 pages to do deferred thp split" +#endif +static inline int has_transparent_hugepage (void ) {return MACHINE_HAS_HPAGE ?1 :0 ;
arch/sparc/include/asm/pgtable_64.h +7 -0
@@ -681,6 +681,13 @@ static inline unsigned long pmd_trans_huge(pmd_t pmd)return pte_val (pte) & _PAGE_PMD_HUGE; } +#if HPAGE_PMD_ORDER >=MAX_ORDER +#error "hugepages can't be allocated by the buddy allocator" +#endif + +#if HPAGE_PMD_ORDER <2 +#error "We need more than 2 pages to do deferred thp split" +#endif #define has_transparent_hugepage () 1static inline pmd_t pmd_mkold (pmd_t pmd)
arch/tile/include/asm/pgtable.h +9 -0
@@ -487,6 +487,15 @@ static inline pmd_t pmd_modify(pmd_t pmd, pgprot_t newprot) }#ifdef CONFIG_TRANSPARENT_HUGEPAGE + +#if HPAGE_PMD_ORDER >=MAX_ORDER +#error "hugepages can't be allocated by the buddy allocator" +#endif + +#if HPAGE_PMD_ORDER <2 +#error "We need more than 2 pages to do deferred thp split" +#endif +#define has_transparent_hugepage () 1#define pmd_trans_huge pmd_huge_page#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
arch/x86/include/asm/pgtable.h +8 -0
@@ -178,6 +178,14 @@ static inline int pmd_devmap(pmd_t pmd)return !!(pmd_val (pmd) & _PAGE_DEVMAP); }#endif + +#if HPAGE_PMD_ORDER >=MAX_ORDER +#error "hugepages can't be allocated by the buddy allocator" +#endif + +#if HPAGE_PMD_ORDER <2 +#error "We need more than 2 pages to do deferred thp split" +#endif #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ static inline pte_t pte_set_flags (pte_t pte,pteval_t set)
include/linux/huge_mm.h +0 -3
@@ -111,9 +111,6 @@ void __split_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,__split_huge_pmd (__vma, __pmd, __address); \ }while (0 ) -#if HPAGE_PMD_ORDER >=MAX_ORDER -#error "hugepages can't be allocated by the buddy allocator" -#endif extern int hugepage_madvise(struct vm_area_struct *vma,unsigned long *vm_flags,int advice); extern void vma_adjust_trans_huge(struct vm_area_struct *vma,
mm/huge_memory.c +5 -3
@@ -83,7 +83,7 @@ unsigned long transparent_hugepage_flags __read_mostly = (1 <<TRANSPARENT_HUGEPAGE_USE_ZERO_PAGE_FLAG );/* default scan 8*512 pte (or vmas) every 30 second */ -static unsigned int khugepaged_pages_to_scan__read_mostly =HPAGE_PMD_NR *8 ; +static unsigned int khugepaged_pages_to_scan__read_mostly ;static unsigned int khugepaged_pages_collapsed;static unsigned int khugepaged_full_scans;static unsigned int khugepaged_scan_sleep_millisecs__read_mostly =10000 ;
@@ -98,7 +98,7 @@ static DECLARE_WAIT_QUEUE_HEAD(khugepaged_wait);* it would have happened if the vma was large enough during page * fault. */ -static unsigned int khugepaged_max_ptes_none__read_mostly =HPAGE_PMD_NR -1 ; +static unsigned int khugepaged_max_ptes_none__read_mostly ;static int khugepaged (void *none);static int khugepaged_slab_init (void );
@@ -655,6 +655,9 @@ static int __init hugepage_init(void)int err;struct kobject *hugepage_kobj; + khugepaged_pages_to_scan =HPAGE_PMD_NR *8 ; + khugepaged_max_ptes_none =HPAGE_PMD_NR -1 ; +if (!has_transparent_hugepage ()) { transparent_hugepage_flags =0 ;return -EINVAL ;
@@ -764,7 +767,6 @@ void prep_transhuge_page(struct page *page)* we use page->mapping and page->indexlru in second tail page * as list_head: assuming THP order >= 2 */ -BUILD_BUG_ON (HPAGE_PMD_ORDER <2 );INIT_LIST_HEAD (page_deferred_list (page));set_compound_page_dtor (page,TRANSHUGE_PAGE_DTOR );
Signature · 7 lines
2.5.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 2/2] mm: Some arch may want to use HPAGE_PMD related values as variables
Quoted 12 lines · Aneesh Kumar K.V
With next generation power processor, we are having a new mmu model
[1] that require us to maintain a different linux page table format.Inorder to support both current and future ppc64 systems with a single kernel we need to make sure kernel can select between different page table format at runtime. With the new MMU (radix MMU) added, we will have two different pmd hugepage size 16MB for hash model and 2MB for Radix model. Hence make
HPAGE_PMDrelated values as a variable.[1] http://ibm.biz/power-isa3 (Needs registration).
Signed-off-by Aneesh Kumar K.V <[email protected]>
Quoted 12 lines
--- arch/arm/include/asm/pgtable-3level.h | 8 ++++++++ arch/arm64/include/asm/pgtable.h | 7 +++++++ arch/mips/include/asm/pgtable.h | 8 ++++++++ arch/powerpc/mm/pgtable_64.c | 7 +++++++ arch/s390/include/asm/pgtable.h | 8 ++++++++ arch/sparc/include/asm/pgtable_64.h | 7 +++++++ arch/tile/include/asm/pgtable.h | 9 +++++++++ arch/x86/include/asm/pgtable.h | 8 ++++++++ include/linux/huge_mm.h | 3 --- mm/huge_memory.c | 8 +++++--- 10 files changed, 67 insertions(+), 6 deletions(-)
That is ugly. What about this:
include/linux/huge_mm.h +0 -3
@@ -111,9 +111,6 @@ void __split_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,__split_huge_pmd (__vma, __pmd, __address); \ }while (0 ) -#if HPAGE_PMD_ORDER >=MAX_ORDER -#error "hugepages can't be allocated by the buddy allocator" -#endif extern int hugepage_madvise(struct vm_area_struct *vma,unsigned long *vm_flags,int advice); extern void vma_adjust_trans_huge(struct vm_area_struct *vma,
mm/huge_memory.c +22 -8
@@ -83,7 +83,7 @@ unsigned long transparent_hugepage_flags __read_mostly = (1 <<TRANSPARENT_HUGEPAGE_USE_ZERO_PAGE_FLAG );/* default scan 8*512 pte (or vmas) every 30 second */ -static unsigned int khugepaged_pages_to_scan__read_mostly =HPAGE_PMD_NR *8 ; +static unsigned int khugepaged_pages_to_scan__read_mostly ;static unsigned int khugepaged_pages_collapsed;static unsigned int khugepaged_full_scans;static unsigned int khugepaged_scan_sleep_millisecs__read_mostly =10000 ;
@@ -98,7 +98,7 @@ static DECLARE_WAIT_QUEUE_HEAD(khugepaged_wait);* it would have happened if the vma was large enough during page * fault. */ -static unsigned int khugepaged_max_ptes_none__read_mostly =HPAGE_PMD_NR -1 ; +static unsigned int khugepaged_max_ptes_none__read_mostly ;static int khugepaged (void *none);static int khugepaged_slab_init (void );
@@ -650,16 +650,36 @@ static inline void hugepage_exit_sysfs(struct kobject *hugepage_kobj) }#endif /* CONFIG_SYSFS */ +#define MAYBE_BUILD_BUG_ON (cond) \ +({ \ + if (__builtin_constant_p((cond))) \ + BUILD_BUG_ON(cond); \ + else \ + BUG_ON(cond); \ +}) +static int __init hugepage_init (void ) {int err;struct kobject *hugepage_kobj; + khugepaged_pages_to_scan =HPAGE_PMD_NR *8 ; + khugepaged_max_ptes_none =HPAGE_PMD_NR -1 ; +if (!has_transparent_hugepage ()) { transparent_hugepage_flags =0 ;return -EINVAL ; } +/* hugepages can't be allocated by the buddy allocator */ +MAYBE_BUILD_BUG_ON (HPAGE_PMD_ORDER >=MAX_ORDER ); + +/* +* we use page->mapping and page->index in second tail page +* as list_head: assuming THP order >= 2 +*/ +MAYBE_BUILD_BUG_ON (HPAGE_PMD_ORDER <2 ); + err =hugepage_init_sysfs (&hugepage_kobj);if (err) goto err_sysfs;
@@ -760,12 +780,6 @@ static inline struct list_head *page_deferred_list(struct page *page)void prep_transhuge_page (struct page *page) { -/* -* we use page->mapping and page->indexlru in second tail page -* as list_head: assuming THP order >= 2 -*/ -BUILD_BUG_ON (HPAGE_PMD_ORDER <2 ); -INIT_LIST_HEAD (page_deferred_list (page));set_compound_page_dtor (page,TRANSHUGE_PAGE_DTOR ); }
Signature · 7 lines
Kirill A. Shutemov -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 10 lines · Aneesh Kumar K.V
With next generation power processor, we are having a new mmu model
[1] that require us to maintain a different linux page table format.Inorder to support both current and future ppc64 systems with a single kernel we need to make sure kernel can select between different page table format at runtime. With the new MMU (radix MMU) added, we will have to dynamically switch between different protection map. Hence override
vm_get_page_protinstead of usingarch_vm_get_page_prot. We also droparch_vm_get_page_protsince only powerpc used it.
Quoted 3 lines
[1] http://ibm.biz/power-isa3 (Needs registration).
Signed-off-by Aneesh Kumar K.V <[email protected]>
Signature · 7 lines
Kirill A. Shutemov -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>