[2/4] riscv: tlb: convert __p*d_free_tlb() to inline functions

Message ID 20231219175046.2496-3-jszhang@kernel.org
State New
Headers
Series riscv: support fast gup |

Commit Message

Jisheng Zhang Dec. 19, 2023, 5:50 p.m. UTC
  This is to prepare for enabling MMU_GATHER_RCU_TABLE_FREE.
No functionality changes.

Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
---
 arch/riscv/include/asm/pgalloc.h | 54 +++++++++++++++++++-------------
 1 file changed, 32 insertions(+), 22 deletions(-)
  

Comments

yunhui cui Dec. 20, 2023, 2:59 a.m. UTC | #1
Hi Jisheng,

On Wed, Dec 20, 2023 at 2:04 AM Jisheng Zhang <jszhang@kernel.org> wrote:
>
> This is to prepare for enabling MMU_GATHER_RCU_TABLE_FREE.
> No functionality changes.
>
> Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
> ---
>  arch/riscv/include/asm/pgalloc.h | 54 +++++++++++++++++++-------------
>  1 file changed, 32 insertions(+), 22 deletions(-)
>
> diff --git a/arch/riscv/include/asm/pgalloc.h b/arch/riscv/include/asm/pgalloc.h
> index a12fb83fa1f5..3c5e3bd15f46 100644
> --- a/arch/riscv/include/asm/pgalloc.h
> +++ b/arch/riscv/include/asm/pgalloc.h
> @@ -95,13 +95,16 @@ static inline void pud_free(struct mm_struct *mm, pud_t *pud)
>                 __pud_free(mm, pud);
>  }
>
> -#define __pud_free_tlb(tlb, pud, addr)                                 \
> -do {                                                                   \
> -       if (pgtable_l4_enabled) {                                       \
> -               pagetable_pud_dtor(virt_to_ptdesc(pud));                \
> -               tlb_remove_page_ptdesc((tlb), virt_to_ptdesc(pud));     \
> -       }                                                               \
> -} while (0)
> +static inline void __pud_free_tlb(struct mmu_gather *tlb, pud_t *pud,
> +                                 unsigned long addr)
> +{
> +       if (pgtable_l4_enabled) {
> +               struct ptdesc *ptdesc = virt_to_ptdesc(pud);
> +
> +               pagetable_pud_dtor(ptdesc);
> +               tlb_remove_page_ptdesc(tlb, ptdesc);
> +       }
> +}
>
>  #define p4d_alloc_one p4d_alloc_one
>  static inline p4d_t *p4d_alloc_one(struct mm_struct *mm, unsigned long addr)
> @@ -130,11 +133,12 @@ static inline void p4d_free(struct mm_struct *mm, p4d_t *p4d)
>                 __p4d_free(mm, p4d);
>  }
>
> -#define __p4d_free_tlb(tlb, p4d, addr)                                 \
> -do {                                                                   \
> -       if (pgtable_l5_enabled)                                         \
> -               tlb_remove_page_ptdesc((tlb), virt_to_ptdesc(p4d));     \
> -} while (0)
> +static inline void __p4d_free_tlb(struct mmu_gather *tlb, p4d_t *p4d,
> +                                 unsigned long addr)
> +{
> +       if (pgtable_l5_enabled)
> +               tlb_remove_page_ptdesc(tlb, virt_to_ptdesc(p4d));
> +}
>  #endif /* __PAGETABLE_PMD_FOLDED */
>
>  static inline void sync_kernel_mappings(pgd_t *pgd)
> @@ -159,19 +163,25 @@ static inline pgd_t *pgd_alloc(struct mm_struct *mm)
>
>  #ifndef __PAGETABLE_PMD_FOLDED
>
> -#define __pmd_free_tlb(tlb, pmd, addr)                         \
> -do {                                                           \
> -       pagetable_pmd_dtor(virt_to_ptdesc(pmd));                \
> -       tlb_remove_page_ptdesc((tlb), virt_to_ptdesc(pmd));     \
> -} while (0)
> +static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
> +                                 unsigned long addr)
> +{
> +       struct ptdesc *ptdesc = virt_to_ptdesc(pmd);
> +
> +       pagetable_pmd_dtor(ptdesc);
> +       tlb_remove_page_ptdesc(tlb, ptdesc);
> +}
>
>  #endif /* __PAGETABLE_PMD_FOLDED */
>
> -#define __pte_free_tlb(tlb, pte, buf)                  \
> -do {                                                   \
> -       pagetable_pte_dtor(page_ptdesc(pte));           \
> -       tlb_remove_page_ptdesc((tlb), page_ptdesc(pte));\
> -} while (0)
> +static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t pte,
> +                                 unsigned long addr)
> +{
> +       struct ptdesc *ptdesc = page_ptdesc(pte);
> +
> +       pagetable_pte_dtor(ptdesc);
> +       tlb_remove_page_ptdesc(tlb, ptdesc);
> +}
>  #endif /* CONFIG_MMU */
>
>  #endif /* _ASM_RISCV_PGALLOC_H */
> --
> 2.40.0
>

Why is it necessary to convert to inline functions?

Thanks,
Yunhui
  
Jisheng Zhang Dec. 20, 2023, 12:57 p.m. UTC | #2
On Wed, Dec 20, 2023 at 10:59:22AM +0800, yunhui cui wrote:
> Hi Jisheng,

Hi,

> 
> On Wed, Dec 20, 2023 at 2:04 AM Jisheng Zhang <jszhang@kernel.org> wrote:
> >
> > This is to prepare for enabling MMU_GATHER_RCU_TABLE_FREE.
> > No functionality changes.
> >
> > Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
> > ---
> >  arch/riscv/include/asm/pgalloc.h | 54 +++++++++++++++++++-------------
> >  1 file changed, 32 insertions(+), 22 deletions(-)
> >
> > diff --git a/arch/riscv/include/asm/pgalloc.h b/arch/riscv/include/asm/pgalloc.h
> > index a12fb83fa1f5..3c5e3bd15f46 100644
> > --- a/arch/riscv/include/asm/pgalloc.h
> > +++ b/arch/riscv/include/asm/pgalloc.h
> > @@ -95,13 +95,16 @@ static inline void pud_free(struct mm_struct *mm, pud_t *pud)
> >                 __pud_free(mm, pud);
> >  }
> >
> > -#define __pud_free_tlb(tlb, pud, addr)                                 \
> > -do {                                                                   \
> > -       if (pgtable_l4_enabled) {                                       \
> > -               pagetable_pud_dtor(virt_to_ptdesc(pud));                \
> > -               tlb_remove_page_ptdesc((tlb), virt_to_ptdesc(pud));     \
> > -       }                                                               \
> > -} while (0)
> > +static inline void __pud_free_tlb(struct mmu_gather *tlb, pud_t *pud,
> > +                                 unsigned long addr)
> > +{
> > +       if (pgtable_l4_enabled) {
> > +               struct ptdesc *ptdesc = virt_to_ptdesc(pud);
> > +
> > +               pagetable_pud_dtor(ptdesc);
> > +               tlb_remove_page_ptdesc(tlb, ptdesc);
> > +       }
> > +}
> >
> >  #define p4d_alloc_one p4d_alloc_one
> >  static inline p4d_t *p4d_alloc_one(struct mm_struct *mm, unsigned long addr)
> > @@ -130,11 +133,12 @@ static inline void p4d_free(struct mm_struct *mm, p4d_t *p4d)
> >                 __p4d_free(mm, p4d);
> >  }
> >
> > -#define __p4d_free_tlb(tlb, p4d, addr)                                 \
> > -do {                                                                   \
> > -       if (pgtable_l5_enabled)                                         \
> > -               tlb_remove_page_ptdesc((tlb), virt_to_ptdesc(p4d));     \
> > -} while (0)
> > +static inline void __p4d_free_tlb(struct mmu_gather *tlb, p4d_t *p4d,
> > +                                 unsigned long addr)
> > +{
> > +       if (pgtable_l5_enabled)
> > +               tlb_remove_page_ptdesc(tlb, virt_to_ptdesc(p4d));
> > +}
> >  #endif /* __PAGETABLE_PMD_FOLDED */
> >
> >  static inline void sync_kernel_mappings(pgd_t *pgd)
> > @@ -159,19 +163,25 @@ static inline pgd_t *pgd_alloc(struct mm_struct *mm)
> >
> >  #ifndef __PAGETABLE_PMD_FOLDED
> >
> > -#define __pmd_free_tlb(tlb, pmd, addr)                         \
> > -do {                                                           \
> > -       pagetable_pmd_dtor(virt_to_ptdesc(pmd));                \
> > -       tlb_remove_page_ptdesc((tlb), virt_to_ptdesc(pmd));     \
> > -} while (0)
> > +static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
> > +                                 unsigned long addr)
> > +{
> > +       struct ptdesc *ptdesc = virt_to_ptdesc(pmd);
> > +
> > +       pagetable_pmd_dtor(ptdesc);
> > +       tlb_remove_page_ptdesc(tlb, ptdesc);
> > +}
> >
> >  #endif /* __PAGETABLE_PMD_FOLDED */
> >
> > -#define __pte_free_tlb(tlb, pte, buf)                  \
> > -do {                                                   \
> > -       pagetable_pte_dtor(page_ptdesc(pte));           \
> > -       tlb_remove_page_ptdesc((tlb), page_ptdesc(pte));\
> > -} while (0)
> > +static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t pte,
> > +                                 unsigned long addr)
> > +{
> > +       struct ptdesc *ptdesc = page_ptdesc(pte);
> > +
> > +       pagetable_pte_dtor(ptdesc);
> > +       tlb_remove_page_ptdesc(tlb, ptdesc);
> > +}
> >  #endif /* CONFIG_MMU */
> >
> >  #endif /* _ASM_RISCV_PGALLOC_H */
> > --
> > 2.40.0
> >
> 
> Why is it necessary to convert to inline functions?

Hmm, it's not necessary but a plus, the inline version's readability and
maintainability is better than macros

Regards
  
Alexandre Ghiti Dec. 31, 2023, 6:24 a.m. UTC | #3
On 19/12/2023 18:50, Jisheng Zhang wrote:
> This is to prepare for enabling MMU_GATHER_RCU_TABLE_FREE.
> No functionality changes.
>
> Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
> ---
>   arch/riscv/include/asm/pgalloc.h | 54 +++++++++++++++++++-------------
>   1 file changed, 32 insertions(+), 22 deletions(-)
>
> diff --git a/arch/riscv/include/asm/pgalloc.h b/arch/riscv/include/asm/pgalloc.h
> index a12fb83fa1f5..3c5e3bd15f46 100644
> --- a/arch/riscv/include/asm/pgalloc.h
> +++ b/arch/riscv/include/asm/pgalloc.h
> @@ -95,13 +95,16 @@ static inline void pud_free(struct mm_struct *mm, pud_t *pud)
>   		__pud_free(mm, pud);
>   }
>   
> -#define __pud_free_tlb(tlb, pud, addr)					\
> -do {									\
> -	if (pgtable_l4_enabled) {					\
> -		pagetable_pud_dtor(virt_to_ptdesc(pud));		\
> -		tlb_remove_page_ptdesc((tlb), virt_to_ptdesc(pud));	\
> -	}								\
> -} while (0)
> +static inline void __pud_free_tlb(struct mmu_gather *tlb, pud_t *pud,
> +				  unsigned long addr)
> +{
> +	if (pgtable_l4_enabled) {
> +		struct ptdesc *ptdesc = virt_to_ptdesc(pud);
> +
> +		pagetable_pud_dtor(ptdesc);
> +		tlb_remove_page_ptdesc(tlb, ptdesc);
> +	}
> +}
>   
>   #define p4d_alloc_one p4d_alloc_one
>   static inline p4d_t *p4d_alloc_one(struct mm_struct *mm, unsigned long addr)
> @@ -130,11 +133,12 @@ static inline void p4d_free(struct mm_struct *mm, p4d_t *p4d)
>   		__p4d_free(mm, p4d);
>   }
>   
> -#define __p4d_free_tlb(tlb, p4d, addr)					\
> -do {									\
> -	if (pgtable_l5_enabled)						\
> -		tlb_remove_page_ptdesc((tlb), virt_to_ptdesc(p4d));	\
> -} while (0)
> +static inline void __p4d_free_tlb(struct mmu_gather *tlb, p4d_t *p4d,
> +				  unsigned long addr)
> +{
> +	if (pgtable_l5_enabled)
> +		tlb_remove_page_ptdesc(tlb, virt_to_ptdesc(p4d));
> +}
>   #endif /* __PAGETABLE_PMD_FOLDED */
>   
>   static inline void sync_kernel_mappings(pgd_t *pgd)
> @@ -159,19 +163,25 @@ static inline pgd_t *pgd_alloc(struct mm_struct *mm)
>   
>   #ifndef __PAGETABLE_PMD_FOLDED
>   
> -#define __pmd_free_tlb(tlb, pmd, addr)				\
> -do {								\
> -	pagetable_pmd_dtor(virt_to_ptdesc(pmd));		\
> -	tlb_remove_page_ptdesc((tlb), virt_to_ptdesc(pmd));	\
> -} while (0)
> +static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
> +				  unsigned long addr)
> +{
> +	struct ptdesc *ptdesc = virt_to_ptdesc(pmd);
> +
> +	pagetable_pmd_dtor(ptdesc);
> +	tlb_remove_page_ptdesc(tlb, ptdesc);
> +}
>   
>   #endif /* __PAGETABLE_PMD_FOLDED */
>   
> -#define __pte_free_tlb(tlb, pte, buf)			\
> -do {							\
> -	pagetable_pte_dtor(page_ptdesc(pte));		\
> -	tlb_remove_page_ptdesc((tlb), page_ptdesc(pte));\
> -} while (0)
> +static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t pte,
> +				  unsigned long addr)
> +{
> +	struct ptdesc *ptdesc = page_ptdesc(pte);
> +
> +	pagetable_pte_dtor(ptdesc);
> +	tlb_remove_page_ptdesc(tlb, ptdesc);
> +}
>   #endif /* CONFIG_MMU */
>   
>   #endif /* _ASM_RISCV_PGALLOC_H */


You can add:

Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>

Thanks,

Alex
  

Patch

diff --git a/arch/riscv/include/asm/pgalloc.h b/arch/riscv/include/asm/pgalloc.h
index a12fb83fa1f5..3c5e3bd15f46 100644
--- a/arch/riscv/include/asm/pgalloc.h
+++ b/arch/riscv/include/asm/pgalloc.h
@@ -95,13 +95,16 @@  static inline void pud_free(struct mm_struct *mm, pud_t *pud)
 		__pud_free(mm, pud);
 }
 
-#define __pud_free_tlb(tlb, pud, addr)					\
-do {									\
-	if (pgtable_l4_enabled) {					\
-		pagetable_pud_dtor(virt_to_ptdesc(pud));		\
-		tlb_remove_page_ptdesc((tlb), virt_to_ptdesc(pud));	\
-	}								\
-} while (0)
+static inline void __pud_free_tlb(struct mmu_gather *tlb, pud_t *pud,
+				  unsigned long addr)
+{
+	if (pgtable_l4_enabled) {
+		struct ptdesc *ptdesc = virt_to_ptdesc(pud);
+
+		pagetable_pud_dtor(ptdesc);
+		tlb_remove_page_ptdesc(tlb, ptdesc);
+	}
+}
 
 #define p4d_alloc_one p4d_alloc_one
 static inline p4d_t *p4d_alloc_one(struct mm_struct *mm, unsigned long addr)
@@ -130,11 +133,12 @@  static inline void p4d_free(struct mm_struct *mm, p4d_t *p4d)
 		__p4d_free(mm, p4d);
 }
 
-#define __p4d_free_tlb(tlb, p4d, addr)					\
-do {									\
-	if (pgtable_l5_enabled)						\
-		tlb_remove_page_ptdesc((tlb), virt_to_ptdesc(p4d));	\
-} while (0)
+static inline void __p4d_free_tlb(struct mmu_gather *tlb, p4d_t *p4d,
+				  unsigned long addr)
+{
+	if (pgtable_l5_enabled)
+		tlb_remove_page_ptdesc(tlb, virt_to_ptdesc(p4d));
+}
 #endif /* __PAGETABLE_PMD_FOLDED */
 
 static inline void sync_kernel_mappings(pgd_t *pgd)
@@ -159,19 +163,25 @@  static inline pgd_t *pgd_alloc(struct mm_struct *mm)
 
 #ifndef __PAGETABLE_PMD_FOLDED
 
-#define __pmd_free_tlb(tlb, pmd, addr)				\
-do {								\
-	pagetable_pmd_dtor(virt_to_ptdesc(pmd));		\
-	tlb_remove_page_ptdesc((tlb), virt_to_ptdesc(pmd));	\
-} while (0)
+static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
+				  unsigned long addr)
+{
+	struct ptdesc *ptdesc = virt_to_ptdesc(pmd);
+
+	pagetable_pmd_dtor(ptdesc);
+	tlb_remove_page_ptdesc(tlb, ptdesc);
+}
 
 #endif /* __PAGETABLE_PMD_FOLDED */
 
-#define __pte_free_tlb(tlb, pte, buf)			\
-do {							\
-	pagetable_pte_dtor(page_ptdesc(pte));		\
-	tlb_remove_page_ptdesc((tlb), page_ptdesc(pte));\
-} while (0)
+static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t pte,
+				  unsigned long addr)
+{
+	struct ptdesc *ptdesc = page_ptdesc(pte);
+
+	pagetable_pte_dtor(ptdesc);
+	tlb_remove_page_ptdesc(tlb, ptdesc);
+}
 #endif /* CONFIG_MMU */
 
 #endif /* _ASM_RISCV_PGALLOC_H */