[RFC PATCH v4 16/16] mm: Remove CONFIG_ARCH_HAS_HUGEPD

2024-05-27 Thread Christophe Leroy
powerpc was the only user of CONFIG_ARCH_HAS_HUGEPD and doesn't
use it anymore, so remove all related code.

Signed-off-by: Christophe Leroy 
---
v4: Rebased on v6.10-rc1
---
 arch/powerpc/mm/hugetlbpage.c |   1 -
 include/linux/hugetlb.h   |   6 --
 mm/Kconfig|  10 --
 mm/gup.c  | 183 +-
 mm/pagewalk.c |  57 +--
 5 files changed, 9 insertions(+), 248 deletions(-)

diff --git a/arch/powerpc/mm/hugetlbpage.c b/arch/powerpc/mm/hugetlbpage.c
index 76846c6014e4..6b043180220a 100644
--- a/arch/powerpc/mm/hugetlbpage.c
+++ b/arch/powerpc/mm/hugetlbpage.c
@@ -78,7 +78,6 @@ pte_t *huge_pte_alloc(struct mm_struct *mm, struct 
vm_area_struct *vma,
 
return pte_alloc_huge(mm, pmd, addr);
 }
-#endif
 
 #ifdef CONFIG_PPC_BOOK3S_64
 /*
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index 2b3c3a404769..58daf7d14bf4 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -20,12 +20,6 @@ struct user_struct;
 struct mmu_gather;
 struct node;
 
-#ifndef CONFIG_ARCH_HAS_HUGEPD
-typedef struct { unsigned long pd; } hugepd_t;
-#define is_hugepd(hugepd) (0)
-#define __hugepd(x) ((hugepd_t) { (x) })
-#endif
-
 void free_huge_folio(struct folio *folio);
 
 #ifdef CONFIG_HUGETLB_PAGE
diff --git a/mm/Kconfig b/mm/Kconfig
index b4cb45255a54..049d29ec6e20 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -1119,16 +1119,6 @@ config DMAPOOL_TEST
 config ARCH_HAS_PTE_SPECIAL
bool
 
-#
-# Some architectures require a special hugepage directory format that is
-# required to support multiple hugepage sizes. For example a4fe3ce76
-# "powerpc/mm: Allow more flexible layouts for hugepage pagetables"
-# introduced it on powerpc.  This allows for a more flexible hugepage
-# pagetable layouts.
-#
-config ARCH_HAS_HUGEPD
-   bool
-
 config MAPPING_DIRTY_HELPERS
 bool
 
diff --git a/mm/gup.c b/mm/gup.c
index 53ebb0ae53a0..f8e982a42bba 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -501,7 +501,7 @@ static inline void mm_set_has_pinned_flag(unsigned long 
*mm_flags)
 
 #ifdef CONFIG_MMU
 
-#if defined(CONFIG_ARCH_HAS_HUGEPD) || defined(CONFIG_HAVE_GUP_FAST)
+#ifdef CONFIG_HAVE_GUP_FAST
 static int record_subpages(struct page *page, unsigned long sz,
   unsigned long addr, unsigned long end,
   struct page **pages)
@@ -515,147 +515,7 @@ static int record_subpages(struct page *page, unsigned 
long sz,
 
return nr;
 }
-#endif /* CONFIG_ARCH_HAS_HUGEPD || CONFIG_HAVE_GUP_FAST */
-
-#ifdef CONFIG_ARCH_HAS_HUGEPD
-static unsigned long hugepte_addr_end(unsigned long addr, unsigned long end,
- unsigned long sz)
-{
-   unsigned long __boundary = (addr + sz) & ~(sz-1);
-   return (__boundary - 1 < end - 1) ? __boundary : end;
-}
-
-/*
- * Returns 1 if succeeded, 0 if failed, -EMLINK if unshare needed.
- *
- * NOTE: for the same entry, gup-fast and gup-slow can return different
- * results (0 v.s. -EMLINK) depending on whether vma is available.  This is
- * the expected behavior, where we simply want gup-fast to fallback to
- * gup-slow to take the vma reference first.
- */
-static int gup_hugepte(struct vm_area_struct *vma, pte_t *ptep, unsigned long 
sz,
-  unsigned long addr, unsigned long end, unsigned int 
flags,
-  struct page **pages, int *nr)
-{
-   unsigned long pte_end;
-   struct page *page;
-   struct folio *folio;
-   pte_t pte;
-   int refs;
-
-   pte_end = (addr + sz) & ~(sz-1);
-   if (pte_end < end)
-   end = pte_end;
-
-   pte = huge_ptep_get(vma->mm, addr, ptep);
-
-   if (!pte_access_permitted(pte, flags & FOLL_WRITE))
-   return 0;
-
-   /* hugepages are never "special" */
-   VM_BUG_ON(!pfn_valid(pte_pfn(pte)));
-
-   page = pte_page(pte);
-   refs = record_subpages(page, sz, addr, end, pages + *nr);
-
-   folio = try_grab_folio(page, refs, flags);
-   if (!folio)
-   return 0;
-
-   if (unlikely(pte_val(pte) != pte_val(ptep_get(ptep {
-   gup_put_folio(folio, refs, flags);
-   return 0;
-   }
-
-   if (!pte_write(pte) && gup_must_unshare(vma, flags, &folio->page)) {
-   gup_put_folio(folio, refs, flags);
-   return -EMLINK;
-   }
-
-   *nr += refs;
-   folio_set_referenced(folio);
-   return 1;
-}
-
-/*
- * NOTE: currently GUP for a hugepd is only possible on hugetlbfs file
- * systems on Power, which does not have issue with folio writeback against
- * GUP updates.  When hugepd will be extended to support non-hugetlbfs or
- * even anonymous memory, we need to do extra check as what we do with most
- * of the other folios. See writable_file_mapping_allowed() and
- * gup_fast_folio_allowed() for more information.
- */
-static int gup_hugepd(struct vm_area_struct *vma, hugepd_t hugepd,
- 

Re: [RFC PATCH v4 16/16] mm: Remove CONFIG_ARCH_HAS_HUGEPD

2024-05-29 Thread Oscar Salvador
On Mon, May 27, 2024 at 03:30:14PM +0200, Christophe Leroy wrote:
> powerpc was the only user of CONFIG_ARCH_HAS_HUGEPD and doesn't
> use it anymore, so remove all related code.
> 
> Signed-off-by: Christophe Leroy 

Acked-by: Oscar Salvador 


-- 
Oscar Salvador
SUSE Labs


Re: [RFC PATCH v4 16/16] mm: Remove CONFIG_ARCH_HAS_HUGEPD

2024-05-29 Thread Oscar Salvador
On Mon, May 27, 2024 at 03:30:14PM +0200, Christophe Leroy wrote:
> powerpc was the only user of CONFIG_ARCH_HAS_HUGEPD and doesn't
> use it anymore, so remove all related code.
> 
> Signed-off-by: Christophe Leroy 
> ---
> v4: Rebased on v6.10-rc1
> ---
>  arch/powerpc/mm/hugetlbpage.c |   1 -
>  include/linux/hugetlb.h   |   6 --
>  mm/Kconfig|  10 --
>  mm/gup.c  | 183 +-
>  mm/pagewalk.c |  57 +--
>  5 files changed, 9 insertions(+), 248 deletions(-)
> 
> diff --git a/arch/powerpc/mm/hugetlbpage.c b/arch/powerpc/mm/hugetlbpage.c
> index 76846c6014e4..6b043180220a 100644
> --- a/arch/powerpc/mm/hugetlbpage.c
> +++ b/arch/powerpc/mm/hugetlbpage.c
> @@ -78,7 +78,6 @@ pte_t *huge_pte_alloc(struct mm_struct *mm, struct 
> vm_area_struct *vma,
>  
>   return pte_alloc_huge(mm, pmd, addr);
>  }
> -#endif

Did not notice this before.
This belongs to the previous patch.


-- 
Oscar Salvador
SUSE Labs