lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CADrL8HW4C=b_5Ryaz+g3+9KTkwTxoHT0YrCy28Y00J9kwwYvtQ@mail.gmail.com>
Date:   Mon, 27 Feb 2023 11:31:33 -0800
From:   James Houghton <jthoughton@...gle.com>
To:     Mike Kravetz <mike.kravetz@...cle.com>
Cc:     Muchun Song <songmuchun@...edance.com>,
        Peter Xu <peterx@...hat.com>,
        Andrew Morton <akpm@...ux-foundation.org>,
        David Hildenbrand <david@...hat.com>,
        David Rientjes <rientjes@...gle.com>,
        Axel Rasmussen <axelrasmussen@...gle.com>,
        Mina Almasry <almasrymina@...gle.com>,
        "Zach O'Keefe" <zokeefe@...gle.com>,
        Manish Mishra <manish.mishra@...anix.com>,
        Naoya Horiguchi <naoya.horiguchi@....com>,
        "Dr . David Alan Gilbert" <dgilbert@...hat.com>,
        "Matthew Wilcox (Oracle)" <willy@...radead.org>,
        Vlastimil Babka <vbabka@...e.cz>,
        Baolin Wang <baolin.wang@...ux.alibaba.com>,
        Miaohe Lin <linmiaohe@...wei.com>,
        Yang Shi <shy828301@...il.com>,
        Frank van der Linden <fvdl@...gle.com>,
        Jiaqi Yan <jiaqiyan@...gle.com>, linux-mm@...ck.org,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 12/46] hugetlb: add hugetlb_alloc_pmd and hugetlb_alloc_pte

"

On Mon, Feb 27, 2023 at 11:17 AM Mike Kravetz <mike.kravetz@...cle.com> wrote:
>
> On 02/18/23 00:27, James Houghton wrote:
> > These functions are used to allocate new PTEs below the hstate PTE. This
> > will be used by hugetlb_walk_step, which implements stepping forwards in
> > a HugeTLB high-granularity page table walk.
> >
> > The reasons that we don't use the standard pmd_alloc/pte_alloc*
> > functions are:
> >  1) This prevents us from accidentally overwriting swap entries or
> >     attempting to use swap entries as present non-leaf PTEs (see
> >     pmd_alloc(); we assume that !pte_none means pte_present and
> >     non-leaf).
> >  2) Locking hugetlb PTEs can different than regular PTEs. (Although, as
> >     implemented right now, locking is the same.)
> >  3) We can maintain compatibility with CONFIG_HIGHPTE. That is, HugeTLB
> >     HGM won't use HIGHPTE, but the kernel can still be built with it,
> >     and other mm code will use it.
> >
> > When GENERAL_HUGETLB supports P4D-based hugepages, we will need to
> > implement hugetlb_pud_alloc to implement hugetlb_walk_step.
> >
> > Signed-off-by: James Houghton <jthoughton@...gle.com>
> >
> > diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
> > index eeacadf3272b..9d839519c875 100644
> > --- a/include/linux/hugetlb.h
> > +++ b/include/linux/hugetlb.h
> > @@ -72,6 +72,11 @@ unsigned long hugetlb_pte_mask(const struct hugetlb_pte *hpte)
> >
> >  bool hugetlb_pte_present_leaf(const struct hugetlb_pte *hpte, pte_t pte);
> >
> > +pmd_t *hugetlb_alloc_pmd(struct mm_struct *mm, struct hugetlb_pte *hpte,
> > +             unsigned long addr);
> > +pte_t *hugetlb_alloc_pte(struct mm_struct *mm, struct hugetlb_pte *hpte,
> > +             unsigned long addr);
> > +
> >  struct hugepage_subpool {
> >       spinlock_t lock;
> >       long count;
> > diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> > index 6c74adff43b6..bb424cdf79e4 100644
> > --- a/mm/hugetlb.c
> > +++ b/mm/hugetlb.c
> > @@ -483,6 +483,120 @@ static bool has_same_uncharge_info(struct file_region *rg,
> >  #endif
> >  }
> >
> > +/*
> > + * hugetlb_alloc_pmd -- Allocate or find a PMD beneath a PUD-level hpte.
> > + *
> > + * This is meant to be used to implement hugetlb_walk_step when one must go to
> > + * step down to a PMD. Different architectures may implement hugetlb_walk_step
> > + * differently, but hugetlb_alloc_pmd and hugetlb_alloc_pte are architecture-
> > + * independent.
> > + *
> > + * Returns:
> > + *   On success: the pointer to the PMD. This should be placed into a
> > + *               hugetlb_pte. @hpte is not changed.
> > + *   ERR_PTR(-EINVAL): hpte is not PUD-level
> > + *   ERR_PTR(-EEXIST): there is a non-leaf and non-empty PUD in @hpte
>
> I often get this confused, should this really be 'non-leaf'?  Because, ...

This comment is wrong, it should be "non-empty PUD that is not
pointing to page tables". Maybe it would be better to say "-EEXIST
unless @hpte is pud_none() or already points to page tables".

In this commit, PTEs containing PTE markers are treated as non-empty
here (and not pointing to page tables), but after the commit "hugetlb:
split PTE markers when doing HGM walks", they are treated as empty.
I'll update the comment in that commit as well.

>
> > + *   ERR_PTR(-ENOMEM): could not allocate the new PMD
> > + */
> > +pmd_t *hugetlb_alloc_pmd(struct mm_struct *mm, struct hugetlb_pte *hpte,
> > +             unsigned long addr)
> > +{
> > +     spinlock_t *ptl = hugetlb_pte_lockptr(hpte);
> > +     pmd_t *new;
> > +     pud_t *pudp;
> > +     pud_t pud;
> > +
> > +     if (hpte->level != HUGETLB_LEVEL_PUD)
> > +             return ERR_PTR(-EINVAL);
> > +
> > +     pudp = (pud_t *)hpte->ptep;
> > +retry:
> > +     pud = READ_ONCE(*pudp);
> > +     if (likely(pud_present(pud)))
> > +             return unlikely(pud_leaf(pud))
> > +                     ? ERR_PTR(-EEXIST)
> > +                     : pmd_offset(pudp, addr);
>
> ... it seems we return -EEXIST in the pud_leaf case.

This code is correct. :) We don't want to overwrite a leaf. Sorry for
the confusion!

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ