[v2,15/46] hugetlb: add make_huge_pte_with_shift

Message ID 20230218002819.1486479-16-jthoughton@google.com
State New
Headers
Series hugetlb: introduce HugeTLB high-granularity mapping |

Commit Message

James Houghton Feb. 18, 2023, 12:27 a.m. UTC
  This allows us to make huge PTEs at shifts other than the hstate shift,
which will be necessary for high-granularity mappings.

Acked-by: Mike Kravetz <mike.kravetz@oracle.com>
Signed-off-by: James Houghton <jthoughton@google.com>
  

Comments

Mina Almasry Feb. 22, 2023, 9:14 p.m. UTC | #1
On Fri, Feb 17, 2023 at 4:28 PM James Houghton <jthoughton@google.com> wrote:
>
> This allows us to make huge PTEs at shifts other than the hstate shift,
> which will be necessary for high-granularity mappings.
>
> Acked-by: Mike Kravetz <mike.kravetz@oracle.com>
> Signed-off-by: James Houghton <jthoughton@google.com>
>

Reviewed-by: Mina Almasry <almasrymina@google.com>

> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index f74183acc521..ed1d806020de 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -5110,11 +5110,11 @@ const struct vm_operations_struct hugetlb_vm_ops = {
>         .pagesize = hugetlb_vm_op_pagesize,
>  };
>
> -static pte_t make_huge_pte(struct vm_area_struct *vma, struct page *page,
> -                               int writable)
> +static pte_t make_huge_pte_with_shift(struct vm_area_struct *vma,
> +                                     struct page *page, int writable,
> +                                     int shift)

Nit: can this be 'unsigned int shift'. Because you're actually passing
it an unsigned int below and there is an implicit cast there. Yes it
will never matter, I know...

>  {
>         pte_t entry;
> -       unsigned int shift = huge_page_shift(hstate_vma(vma));
>
>         if (writable) {
>                 entry = huge_pte_mkwrite(huge_pte_mkdirty(mk_pte(page,
> @@ -5128,6 +5128,14 @@ static pte_t make_huge_pte(struct vm_area_struct *vma, struct page *page,
>         return entry;
>  }
>
> +static pte_t make_huge_pte(struct vm_area_struct *vma, struct page *page,
> +                          int writable)
> +{
> +       unsigned int shift = huge_page_shift(hstate_vma(vma));
> +
> +       return make_huge_pte_with_shift(vma, page, writable, shift);
> +}
> +
>  static void set_huge_ptep_writable(struct vm_area_struct *vma,
>                                    unsigned long address, pte_t *ptep)
>  {
> --
> 2.39.2.637.g21b0678d19-goog
>
  
James Houghton Feb. 22, 2023, 10:53 p.m. UTC | #2
On Wed, Feb 22, 2023 at 1:15 PM Mina Almasry <almasrymina@google.com> wrote:
>
> On Fri, Feb 17, 2023 at 4:28 PM James Houghton <jthoughton@google.com> wrote:
> >
> > This allows us to make huge PTEs at shifts other than the hstate shift,
> > which will be necessary for high-granularity mappings.
> >
> > Acked-by: Mike Kravetz <mike.kravetz@oracle.com>
> > Signed-off-by: James Houghton <jthoughton@google.com>
> >
>
> Reviewed-by: Mina Almasry <almasrymina@google.com>

Thank you :)

>
> > diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> > index f74183acc521..ed1d806020de 100644
> > --- a/mm/hugetlb.c
> > +++ b/mm/hugetlb.c
> > @@ -5110,11 +5110,11 @@ const struct vm_operations_struct hugetlb_vm_ops = {
> >         .pagesize = hugetlb_vm_op_pagesize,
> >  };
> >
> > -static pte_t make_huge_pte(struct vm_area_struct *vma, struct page *page,
> > -                               int writable)
> > +static pte_t make_huge_pte_with_shift(struct vm_area_struct *vma,
> > +                                     struct page *page, int writable,
> > +                                     int shift)
>
> Nit: can this be 'unsigned int shift'. Because you're actually passing
> it an unsigned int below and there is an implicit cast there. Yes it
> will never matter, I know...

Yes I think it should be unsigned int. Thanks for the catch.

>
> >  {
> >         pte_t entry;
> > -       unsigned int shift = huge_page_shift(hstate_vma(vma));
> >
> >         if (writable) {
> >                 entry = huge_pte_mkwrite(huge_pte_mkdirty(mk_pte(page,
> > @@ -5128,6 +5128,14 @@ static pte_t make_huge_pte(struct vm_area_struct *vma, struct page *page,
> >         return entry;
> >  }
> >
> > +static pte_t make_huge_pte(struct vm_area_struct *vma, struct page *page,
> > +                          int writable)
> > +{
> > +       unsigned int shift = huge_page_shift(hstate_vma(vma));
> > +
> > +       return make_huge_pte_with_shift(vma, page, writable, shift);
> > +}
> > +
> >  static void set_huge_ptep_writable(struct vm_area_struct *vma,
> >                                    unsigned long address, pte_t *ptep)
> >  {
> > --
> > 2.39.2.637.g21b0678d19-goog
> >
  

Patch

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index f74183acc521..ed1d806020de 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -5110,11 +5110,11 @@  const struct vm_operations_struct hugetlb_vm_ops = {
 	.pagesize = hugetlb_vm_op_pagesize,
 };
 
-static pte_t make_huge_pte(struct vm_area_struct *vma, struct page *page,
-				int writable)
+static pte_t make_huge_pte_with_shift(struct vm_area_struct *vma,
+				      struct page *page, int writable,
+				      int shift)
 {
 	pte_t entry;
-	unsigned int shift = huge_page_shift(hstate_vma(vma));
 
 	if (writable) {
 		entry = huge_pte_mkwrite(huge_pte_mkdirty(mk_pte(page,
@@ -5128,6 +5128,14 @@  static pte_t make_huge_pte(struct vm_area_struct *vma, struct page *page,
 	return entry;
 }
 
+static pte_t make_huge_pte(struct vm_area_struct *vma, struct page *page,
+			   int writable)
+{
+	unsigned int shift = huge_page_shift(hstate_vma(vma));
+
+	return make_huge_pte_with_shift(vma, page, writable, shift);
+}
+
 static void set_huge_ptep_writable(struct vm_area_struct *vma,
 				   unsigned long address, pte_t *ptep)
 {