All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] riscv: Implement missing huge_ptep_get
       [not found] <20230723134822.617037-1-petko.manolov@konsulko.com>
@ 2023-07-23 13:48 ` Petko Manolov
  2023-07-24  8:30   ` Alexandre Ghiti
  0 siblings, 1 reply; 3+ messages in thread
From: Petko Manolov @ 2023-07-23 13:48 UTC (permalink / raw)
  To: leon.anavi
  Cc: Alexandre Ghiti, Andrew Jones, stable, Palmer Dabbelt,
	Petko Manolov

From: Alexandre Ghiti <alexghiti@rivosinc.com>

huge_ptep_get must be reimplemented in order to go through all the PTEs
of a NAPOT region: this is needed because the HW can update the A/D bits
of any of the PTE that constitutes the NAPOT region.

Fixes: 82a1a1f3bfb6 ("riscv: mm: support Svnapot in hugetlb page")
Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Link: https://lore.kernel.org/r/20230428120120.21620-2-alexghiti@rivosinc.com
Cc: stable@vger.kernel.org
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
Signed-off-by: Petko Manolov <petko.manolov@konsulko.com>
---
 arch/riscv/include/asm/hugetlb.h |  3 +++
 arch/riscv/mm/hugetlbpage.c      | 24 ++++++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/arch/riscv/include/asm/hugetlb.h b/arch/riscv/include/asm/hugetlb.h
index fe6f23006641..ce1ebda1a49a 100644
--- a/arch/riscv/include/asm/hugetlb.h
+++ b/arch/riscv/include/asm/hugetlb.h
@@ -36,6 +36,9 @@ int huge_ptep_set_access_flags(struct vm_area_struct *vma,
 			       unsigned long addr, pte_t *ptep,
 			       pte_t pte, int dirty);
 
+#define __HAVE_ARCH_HUGE_PTEP_GET
+pte_t huge_ptep_get(pte_t *ptep);
+
 pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags);
 #define arch_make_huge_pte arch_make_huge_pte
 
diff --git a/arch/riscv/mm/hugetlbpage.c b/arch/riscv/mm/hugetlbpage.c
index 238d00bdac14..e0ef56dc57b9 100644
--- a/arch/riscv/mm/hugetlbpage.c
+++ b/arch/riscv/mm/hugetlbpage.c
@@ -3,6 +3,30 @@
 #include <linux/err.h>
 
 #ifdef CONFIG_RISCV_ISA_SVNAPOT
+pte_t huge_ptep_get(pte_t *ptep)
+{
+	unsigned long pte_num;
+	int i;
+	pte_t orig_pte = ptep_get(ptep);
+
+	if (!pte_present(orig_pte) || !pte_napot(orig_pte))
+		return orig_pte;
+
+	pte_num = napot_pte_num(napot_cont_order(orig_pte));
+
+	for (i = 0; i < pte_num; i++, ptep++) {
+		pte_t pte = ptep_get(ptep);
+
+		if (pte_dirty(pte))
+			orig_pte = pte_mkdirty(orig_pte);
+
+		if (pte_young(pte))
+			orig_pte = pte_mkyoung(orig_pte);
+	}
+
+	return orig_pte;
+}
+
 pte_t *huge_pte_alloc(struct mm_struct *mm,
 		      struct vm_area_struct *vma,
 		      unsigned long addr,
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] riscv: Implement missing huge_ptep_get
  2023-07-23 13:48 ` [PATCH] riscv: Implement missing huge_ptep_get Petko Manolov
@ 2023-07-24  8:30   ` Alexandre Ghiti
  2023-07-24 10:21     ` Petko Manolov
  0 siblings, 1 reply; 3+ messages in thread
From: Alexandre Ghiti @ 2023-07-24  8:30 UTC (permalink / raw)
  To: Petko Manolov; +Cc: leon.anavi, Andrew Jones, stable, Palmer Dabbelt

Hi Petko,

On Sun, Jul 23, 2023 at 3:48 PM Petko Manolov
<petko.manolov@konsulko.com> wrote:
>
> From: Alexandre Ghiti <alexghiti@rivosinc.com>
>
> huge_ptep_get must be reimplemented in order to go through all the PTEs
> of a NAPOT region: this is needed because the HW can update the A/D bits
> of any of the PTE that constitutes the NAPOT region.
>
> Fixes: 82a1a1f3bfb6 ("riscv: mm: support Svnapot in hugetlb page")
> Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
> Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
> Link: https://lore.kernel.org/r/20230428120120.21620-2-alexghiti@rivosinc.com
> Cc: stable@vger.kernel.org
> Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
> Signed-off-by: Petko Manolov <petko.manolov@konsulko.com>
> ---
>  arch/riscv/include/asm/hugetlb.h |  3 +++
>  arch/riscv/mm/hugetlbpage.c      | 24 ++++++++++++++++++++++++
>  2 files changed, 27 insertions(+)
>
> diff --git a/arch/riscv/include/asm/hugetlb.h b/arch/riscv/include/asm/hugetlb.h
> index fe6f23006641..ce1ebda1a49a 100644
> --- a/arch/riscv/include/asm/hugetlb.h
> +++ b/arch/riscv/include/asm/hugetlb.h
> @@ -36,6 +36,9 @@ int huge_ptep_set_access_flags(struct vm_area_struct *vma,
>                                unsigned long addr, pte_t *ptep,
>                                pte_t pte, int dirty);
>
> +#define __HAVE_ARCH_HUGE_PTEP_GET
> +pte_t huge_ptep_get(pte_t *ptep);
> +
>  pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags);
>  #define arch_make_huge_pte arch_make_huge_pte
>
> diff --git a/arch/riscv/mm/hugetlbpage.c b/arch/riscv/mm/hugetlbpage.c
> index 238d00bdac14..e0ef56dc57b9 100644
> --- a/arch/riscv/mm/hugetlbpage.c
> +++ b/arch/riscv/mm/hugetlbpage.c
> @@ -3,6 +3,30 @@
>  #include <linux/err.h>
>
>  #ifdef CONFIG_RISCV_ISA_SVNAPOT
> +pte_t huge_ptep_get(pte_t *ptep)
> +{
> +       unsigned long pte_num;
> +       int i;
> +       pte_t orig_pte = ptep_get(ptep);
> +
> +       if (!pte_present(orig_pte) || !pte_napot(orig_pte))
> +               return orig_pte;
> +
> +       pte_num = napot_pte_num(napot_cont_order(orig_pte));
> +
> +       for (i = 0; i < pte_num; i++, ptep++) {
> +               pte_t pte = ptep_get(ptep);
> +
> +               if (pte_dirty(pte))
> +                       orig_pte = pte_mkdirty(orig_pte);
> +
> +               if (pte_young(pte))
> +                       orig_pte = pte_mkyoung(orig_pte);
> +       }
> +
> +       return orig_pte;
> +}
> +
>  pte_t *huge_pte_alloc(struct mm_struct *mm,
>                       struct vm_area_struct *vma,
>                       unsigned long addr,
> --
> 2.39.2
>

Not sure I understand why you propose this patch to stable since
svnapot support was introduced in 6.4 and this fix (and another one)
was merged in 6.4 too. Am I missing something?

Thanks,

Alex

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] riscv: Implement missing huge_ptep_get
  2023-07-24  8:30   ` Alexandre Ghiti
@ 2023-07-24 10:21     ` Petko Manolov
  0 siblings, 0 replies; 3+ messages in thread
From: Petko Manolov @ 2023-07-24 10:21 UTC (permalink / raw)
  To: Alexandre Ghiti; +Cc: leon.anavi, Andrew Jones, stable, Palmer Dabbelt

On 23-07-24 10:30:20, Alexandre Ghiti wrote:
> Hi Petko,
> 
> On Sun, Jul 23, 2023 at 3:48 PM Petko Manolov
> <petko.manolov@konsulko.com> wrote:
> >
> > From: Alexandre Ghiti <alexghiti@rivosinc.com>
> >
> > huge_ptep_get must be reimplemented in order to go through all the PTEs
> > of a NAPOT region: this is needed because the HW can update the A/D bits
> > of any of the PTE that constitutes the NAPOT region.
> >
> > Fixes: 82a1a1f3bfb6 ("riscv: mm: support Svnapot in hugetlb page")
> > Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
> > Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
> > Link: https://lore.kernel.org/r/20230428120120.21620-2-alexghiti@rivosinc.com
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
> > Signed-off-by: Petko Manolov <petko.manolov@konsulko.com>
> > ---
> >  arch/riscv/include/asm/hugetlb.h |  3 +++
> >  arch/riscv/mm/hugetlbpage.c      | 24 ++++++++++++++++++++++++
> >  2 files changed, 27 insertions(+)
> >
> > diff --git a/arch/riscv/include/asm/hugetlb.h b/arch/riscv/include/asm/hugetlb.h
> > index fe6f23006641..ce1ebda1a49a 100644
> > --- a/arch/riscv/include/asm/hugetlb.h
> > +++ b/arch/riscv/include/asm/hugetlb.h
> > @@ -36,6 +36,9 @@ int huge_ptep_set_access_flags(struct vm_area_struct *vma,
> >                                unsigned long addr, pte_t *ptep,
> >                                pte_t pte, int dirty);
> >
> > +#define __HAVE_ARCH_HUGE_PTEP_GET
> > +pte_t huge_ptep_get(pte_t *ptep);
> > +
> >  pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags);
> >  #define arch_make_huge_pte arch_make_huge_pte
> >
> > diff --git a/arch/riscv/mm/hugetlbpage.c b/arch/riscv/mm/hugetlbpage.c
> > index 238d00bdac14..e0ef56dc57b9 100644
> > --- a/arch/riscv/mm/hugetlbpage.c
> > +++ b/arch/riscv/mm/hugetlbpage.c
> > @@ -3,6 +3,30 @@
> >  #include <linux/err.h>
> >
> >  #ifdef CONFIG_RISCV_ISA_SVNAPOT
> > +pte_t huge_ptep_get(pte_t *ptep)
> > +{
> > +       unsigned long pte_num;
> > +       int i;
> > +       pte_t orig_pte = ptep_get(ptep);
> > +
> > +       if (!pte_present(orig_pte) || !pte_napot(orig_pte))
> > +               return orig_pte;
> > +
> > +       pte_num = napot_pte_num(napot_cont_order(orig_pte));
> > +
> > +       for (i = 0; i < pte_num; i++, ptep++) {
> > +               pte_t pte = ptep_get(ptep);
> > +
> > +               if (pte_dirty(pte))
> > +                       orig_pte = pte_mkdirty(orig_pte);
> > +
> > +               if (pte_young(pte))
> > +                       orig_pte = pte_mkyoung(orig_pte);
> > +       }
> > +
> > +       return orig_pte;
> > +}
> > +
> >  pte_t *huge_pte_alloc(struct mm_struct *mm,
> >                       struct vm_area_struct *vma,
> >                       unsigned long addr,
> > --
> > 2.39.2
> >
> 
> Not sure I understand why you propose this patch to stable since svnapot
> support was introduced in 6.4 and this fix (and another one) was merged in 6.4
> too. Am I missing something?

Hey there.  I've no idea how "Signed-off" with my email address appeared in this
patch.  I most certainly have not done so, nor i am in any way related to this
code.  Weird.


		Petko

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-07-24 10:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20230723134822.617037-1-petko.manolov@konsulko.com>
2023-07-23 13:48 ` [PATCH] riscv: Implement missing huge_ptep_get Petko Manolov
2023-07-24  8:30   ` Alexandre Ghiti
2023-07-24 10:21     ` Petko Manolov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.