mm: Merge pte_mkhuge() call into arch_make_huge_pte()
Subsystems (8)
PATCH v2 1/1 mm: Merge pte_mkhuge() call into arch_make_huge_pte()
Each call into pte_mkhuge() is invariably followed by arch_make_huge_pte(). Instead arch_make_huge_pte() can accommodate pte_mkhuge() at the beginning. This updates generic fallback stub for arch_make_huge_pte() and available platforms definitions. This makes huge pte creation much cleaner and easier to follow.
---
This applies on v5.17-rc2
Changes in V2:
- Direct PTE encode in arch_make_huge_pte() on powerpc platform per Christophe
Changes in V1:
https://lore.kernel.org/all/[email protected]/
arch/arm64/mm/hugetlbpage.c | 1 + arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h | 4 ++-- arch/sparc/mm/hugetlbpage.c | 1 + include/linux/hugetlb.h | 2 +- mm/hugetlb.c | 3 +-- mm/vmalloc.c | 1 - 6 files changed, 6 insertions(+), 6 deletions(-)
arch/arm64/mm/hugetlbpage.c +1 -0
@@ -347,6 +347,7 @@ pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags) {size_t pagesize =1UL << shift; + entry =pte_mkhuge (entry);if (pagesize ==CONT_PTE_SIZE ) { entry =pte_mkcont (entry); }else if (pagesize ==CONT_PMD_SIZE ) {
arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h +2 -2
@@ -71,9 +71,9 @@ static inline pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flagssize_t size =1UL << shift;if (size ==SZ_16K ) -return __pte (pte_val (entry) & ~_PAGE_HUGE); +return __pte (pte_val (entry) | _PAGE_SPS);else - return entry; + return __pte(pte_val(entry) | _PAGE_SPS | _PAGE_HUGE); }#define arch_make_huge_pte arch_make_huge_pte#endif
arch/sparc/mm/hugetlbpage.c +1 -0
@@ -181,6 +181,7 @@ pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags) {pte_t pte; + entry =pte_mkhuge (entry); pte =hugepage_shift_to_tte (entry, shift);#ifdef CONFIG_SPARC64
include/linux/hugetlb.h +1 -1
@@ -754,7 +754,7 @@ static inline void arch_clear_hugepage_flags(struct page *page) { }static inline pte_t arch_make_huge_pte (pte_t entry,unsigned int shift,vm_flags_t flags) { -return entry; +return pte_mkhuge (entry); }#endif
mm/hugetlb.c +1 -2
@@ -4637,7 +4637,6 @@ static pte_t make_huge_pte(struct vm_area_struct *vma, struct page *page, vma->vm_page_prot)); } entry =pte_mkyoung (entry); - entry =pte_mkhuge (entry); entry =arch_make_huge_pte (entry, shift, vma->vm_flags);return entry;
@@ -6172,7 +6171,7 @@ unsigned long hugetlb_change_protection(struct vm_area_struct *vma,unsigned int shift =huge_page_shift (hstate_vma (vma)); old_pte =huge_ptep_modify_prot_start (vma, address, ptep); - pte =pte_mkhuge (huge_pte_modify (old_pte, newprot)); + pte =huge_pte_modify (old_pte, newprot); pte =arch_make_huge_pte (pte, shift, vma->vm_flags);huge_ptep_modify_prot_commit (vma, address, ptep, old_pte, pte); pages++;
mm/vmalloc.c +0 -1
@@ -118,7 +118,6 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,if (size !=PAGE_SIZE ) {pte_t entry =pfn_pte (pfn, prot); - entry =pte_mkhuge (entry); entry =arch_make_huge_pte (entry,ilog2 (size),0 );set_huge_pte_at (&init_mm, addr, pte, entry); pfn +=PFN_DOWN (size);
Signature · 1 line
2.25.1
Quoted 6 lines · Anshuman Khandual
Each call into
pte_mkhuge()is invariably followed byarch_make_huge_pte(). Insteadarch_make_huge_pte()can accommodatepte_mkhuge()at the beginning. This updates generic fallback stub forarch_make_huge_pte()and available platforms definitions. This makes huge pte creation much cleaner and easier to follow.
Quoted 15 lines
Cc Catalin Marinas <[email protected]>Cc Will Deacon <[email protected]>Cc Michael Ellerman <[email protected]>Cc Paul Mackerras <[email protected]>Cc "David S. Miller" <[email protected]>Cc Mike Kravetz <[email protected]>Cc Andrew Morton <[email protected]>Reviewed-by Christophe Leroy <[email protected]>Acked-by Mike Kravetz <[email protected]>Signed-off-by Anshuman Khandual <[email protected]>
Acking v2 as well:
Hi,
Le 03/02/2022 à 04:57, Anshuman Khandual a écrit :
Quoted 5 lines
Each call into
pte_mkhuge()is invariably followed byarch_make_huge_pte(). Insteadarch_make_huge_pte()can accommodatepte_mkhuge()at the beginning. This updates generic fallback stub forarch_make_huge_pte()and available platforms definitions. This makes huge pte creation much cleaner and easier to follow.
I can't remember, what was the reason for not doing it in remove_migration_pte() as well ?
Looking at it, I have the feeling that we now have a redundant pte_mkhuge() there.
Also, could we get rid of the one in mm/debug_vm_pgtable.c ?
Also, shouldn't arch_make_huge_pte() be documented in Documentation/vm/arch_pgtable_helpers.rst instead of pte_mkhuge() ?
Christophe
Quoted 121 lines
Cc Catalin Marinas <[email protected]>Cc Will Deacon <[email protected]>Cc Michael Ellerman <[email protected]>Cc Paul Mackerras <[email protected]>Cc "David S. Miller" <[email protected]>Cc Mike Kravetz <[email protected]>Cc Andrew Morton <[email protected]>Reviewed-by Christophe Leroy <[email protected]>Acked-by Mike Kravetz <[email protected]>Signed-off-by Anshuman Khandual <[email protected]>---
This applies on v5.17-rc2Changes in V2:
- Direct PTE encode in
arch_make_huge_pte()on powerpc platform per ChristopheChanges in V1:
https://lore.kernel.org/all/[email protected]/
arch/arm64/mm/hugetlbpage.c | 1 + arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h | 4 ++-- arch/sparc/mm/hugetlbpage.c | 1 + include/linux/hugetlb.h | 2 +- mm/hugetlb.c | 3 +-- mm/vmalloc.c | 1 - 6 files changed, 6 insertions(+), 6 deletions(-)arch/arm64/mm/hugetlbpage.c +1
-0@@ -347,6 +347,7 @@ pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags) {size_t pagesize =1UL << shift; + entry =pte_mkhuge (entry);if (pagesize ==CONT_PTE_SIZE ) { entry =pte_mkcont (entry); }else if (pagesize ==CONT_PMD_SIZE ) {arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h +2
-2@@ -71,9 +71,9 @@ static inline pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flagssize_t size =1UL << shift;if (size ==SZ_16K ) -return __pte (pte_val (entry) & ~_PAGE_HUGE); +return __pte (pte_val (entry) | _PAGE_SPS);else - return entry; + return __pte(pte_val(entry) | _PAGE_SPS | _PAGE_HUGE); }#define arch_make_huge_pte arch_make_huge_pte#endif arch/sparc/mm/hugetlbpage.c +1
-0@@ -181,6 +181,7 @@ pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags) {pte_t pte; + entry =pte_mkhuge (entry); pte =hugepage_shift_to_tte (entry, shift);#ifdef CONFIG_SPARC64 include/linux/hugetlb.h +1
-1@@ -754,7 +754,7 @@ static inline void arch_clear_hugepage_flags(struct page *page) { }static inline pte_t arch_make_huge_pte (pte_t entry,unsigned int shift,vm_flags_t flags) { -return entry; +return pte_mkhuge (entry); }#endif mm/hugetlb.c +1
-2@@ -4637,7 +4637,6 @@ static pte_t make_huge_pte(struct vm_area_struct *vma, struct page *page, vma->vm_page_prot)); } entry =pte_mkyoung (entry); - entry =pte_mkhuge (entry); entry =arch_make_huge_pte (entry, shift, vma->vm_flags);return entry;@@ -6172,7 +6171,7 @@ unsigned long hugetlb_change_protection(struct vm_area_struct *vma,unsigned int shift =huge_page_shift (hstate_vma (vma)); old_pte =huge_ptep_modify_prot_start (vma, address, ptep); - pte =pte_mkhuge (huge_pte_modify (old_pte, newprot)); + pte =huge_pte_modify (old_pte, newprot); pte =arch_make_huge_pte (pte, shift, vma->vm_flags);huge_ptep_modify_prot_commit (vma, address, ptep, old_pte, pte); pages++;mm/vmalloc.c +0
-1@@ -118,7 +118,6 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,if (size !=PAGE_SIZE ) {pte_t entry =pfn_pte (pfn, prot); - entry =pte_mkhuge (entry); entry =arch_make_huge_pte (entry,ilog2 (size),0 );set_huge_pte_at (&init_mm, addr, pte, entry); pfn +=PFN_DOWN (size);
Quoted 9 lines · Christophe Leroy
Hi,
Le 03/02/2022 à 04:57, Anshuman Khandual a écrit :
Quoted 5 lines
Each call into
pte_mkhuge()is invariably followed byarch_make_huge_pte(). Insteadarch_make_huge_pte()can accommodatepte_mkhuge()at the beginning. This updates generic fallback stub forarch_make_huge_pte()and available platforms definitions. This makes huge pte creation much cleaner and easier to follow.
Quoted 4 lines
I can't remember, what was the reason for not doing it in
remove_migration_pte()as well ?
Looking at it, I have the feeling that we now have a redundantpte_mkhuge()there.
I guess it just got missed out, but you are right, there seems to be a redundant pte_mkhuge() in remove_migration_pte(), I will send out a patch dropping it off.
Quoted 2 lines
Also, could we get rid of the one in
mm/debug_vm_pgtable.c?
After this patch, arch_make_huge_pte() should be used instead in generic MM for all cases. So you are suggesting arch_make_huge_pte() should be tested instead ?
mm/debug_vm_pgtable.c +1 -1
@@ -909,7 +909,7 @@ static void __init hugetlb_basic_tests(struct pgtable_debug_args *args)#ifdef CONFIG_ARCH_WANT_GENERAL_HUGETLB pte =pfn_pte (args->fixed_pmd_pfn, args->page_prot); -WARN_ON (!pte_huge (pte_mkhuge (pte))); +WARN_ON (!pte_huge (arch_make_huge_pte (pte))); #endif /* CONFIG_ARCH_WANT_GENERAL_HUGETLB */ }#else /* !CONFIG_HUGETLB_PAGE */
Quoted 3 lines
Also, shouldn't
arch_make_huge_pte()be documented inDocumentation/vm/arch_pgtable_helpers.rstinstead ofpte_mkhuge()?
Documentation/mm/arch_pgtable_helpers.rst +1 -1
@@ -216,7 +216,7 @@ HugeTLB Page Table Helpers +---------------------------+--------------------------------------------------+ | pte_huge | Tests a HugeTLB | +---------------------------+--------------------------------------------------+ -| pte_mkhuge | Creates a HugeTLB | +| arch_make_huge_pte | Creates a HugeTLB | +---------------------------+--------------------------------------------------+ | huge_pte_dirty | Tests a dirty HugeTLB | +---------------------------+--------------------------------------------------+
I will send out a patch implementing the above changes. I guess pte_mkhuge() now will just be a platform helper, which can be folded into arch_make_huge_pte() if and when required.
- Anshuman
Quoted 124 lines
Christophe
Quoted 121 lines
Cc Catalin Marinas <[email protected]>Cc Will Deacon <[email protected]>Cc Michael Ellerman <[email protected]>Cc Paul Mackerras <[email protected]>Cc "David S. Miller" <[email protected]>Cc Mike Kravetz <[email protected]>Cc Andrew Morton <[email protected]>Reviewed-by Christophe Leroy <[email protected]>Acked-by Mike Kravetz <[email protected]>Signed-off-by Anshuman Khandual <[email protected]>---
This applies on v5.17-rc2Changes in V2:
- Direct PTE encode in
arch_make_huge_pte()on powerpc platform per ChristopheChanges in V1:
https://lore.kernel.org/all/[email protected]/
arch/arm64/mm/hugetlbpage.c | 1 + arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h | 4 ++-- arch/sparc/mm/hugetlbpage.c | 1 + include/linux/hugetlb.h | 2 +- mm/hugetlb.c | 3 +-- mm/vmalloc.c | 1 - 6 files changed, 6 insertions(+), 6 deletions(-)arch/arm64/mm/hugetlbpage.c +1
-0@@ -347,6 +347,7 @@ pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags) {size_t pagesize =1UL << shift; + entry =pte_mkhuge (entry);if (pagesize ==CONT_PTE_SIZE ) { entry =pte_mkcont (entry); }else if (pagesize ==CONT_PMD_SIZE ) {arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h +2
-2@@ -71,9 +71,9 @@ static inline pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flagssize_t size =1UL << shift;if (size ==SZ_16K ) -return __pte (pte_val (entry) & ~_PAGE_HUGE); +return __pte (pte_val (entry) | _PAGE_SPS);else - return entry; + return __pte(pte_val(entry) | _PAGE_SPS | _PAGE_HUGE); }#define arch_make_huge_pte arch_make_huge_pte#endif arch/sparc/mm/hugetlbpage.c +1
-0@@ -181,6 +181,7 @@ pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags) {pte_t pte; + entry =pte_mkhuge (entry); pte =hugepage_shift_to_tte (entry, shift);#ifdef CONFIG_SPARC64 include/linux/hugetlb.h +1
-1@@ -754,7 +754,7 @@ static inline void arch_clear_hugepage_flags(struct page *page) { }static inline pte_t arch_make_huge_pte (pte_t entry,unsigned int shift,vm_flags_t flags) { -return entry; +return pte_mkhuge (entry); }#endif mm/hugetlb.c +1
-2@@ -4637,7 +4637,6 @@ static pte_t make_huge_pte(struct vm_area_struct *vma, struct page *page, vma->vm_page_prot)); } entry =pte_mkyoung (entry); - entry =pte_mkhuge (entry); entry =arch_make_huge_pte (entry, shift, vma->vm_flags);return entry;@@ -6172,7 +6171,7 @@ unsigned long hugetlb_change_protection(struct vm_area_struct *vma,unsigned int shift =huge_page_shift (hstate_vma (vma)); old_pte =huge_ptep_modify_prot_start (vma, address, ptep); - pte =pte_mkhuge (huge_pte_modify (old_pte, newprot)); + pte =huge_pte_modify (old_pte, newprot); pte =arch_make_huge_pte (pte, shift, vma->vm_flags);huge_ptep_modify_prot_commit (vma, address, ptep, old_pte, pte); pages++;mm/vmalloc.c +0
-1@@ -118,7 +118,6 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,if (size !=PAGE_SIZE ) {pte_t entry =pfn_pte (pfn, prot); - entry =pte_mkhuge (entry); entry =arch_make_huge_pte (entry,ilog2 (size),0 );set_huge_pte_at (&init_mm, addr, pte, entry); pfn +=PFN_DOWN (size);