[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Ya7HN5N/5Po/x28Y@xz-m1.local>
Date: Tue, 7 Dec 2021 10:30:15 +0800
From: Peter Xu <peterx@...hat.com>
To: Alistair Popple <apopple@...dia.com>
Cc: linux-mm@...ck.org, linux-kernel@...r.kernel.org,
Axel Rasmussen <axelrasmussen@...gle.com>,
Nadav Amit <nadav.amit@...il.com>,
Mike Rapoport <rppt@...ux.vnet.ibm.com>,
Hugh Dickins <hughd@...gle.com>,
Mike Kravetz <mike.kravetz@...cle.com>,
"Kirill A . Shutemov" <kirill@...temov.name>,
Jerome Glisse <jglisse@...hat.com>,
Matthew Wilcox <willy@...radead.org>,
Andrew Morton <akpm@...ux-foundation.org>,
David Hildenbrand <david@...hat.com>,
Andrea Arcangeli <aarcange@...hat.com>
Subject: Re: [PATCH v6 01/23] mm: Introduce PTE_MARKER swap entry
On Tue, Dec 07, 2021 at 01:12:23PM +1100, Alistair Popple wrote:
> On Friday, 3 December 2021 5:45:37 PM AEDT Peter Xu wrote:
> > On Fri, Dec 03, 2021 at 04:35:38PM +1100, Alistair Popple wrote:
> > > > > > +static inline pte_marker pte_marker_get(swp_entry_t entry)
> > > > > > +{
> > > > > > + return swp_offset(entry) & PTE_MARKER_MASK;
> > > > >
> > > > > I'm not sure the PTE_MARKER_MASK adds much, especially as we only have one
> > > > > user. I don't see a problem with open-coding these kind of checks (ie.
> > > >
> > > > It's more or less a safety belt to make sure anything pte_marker_get() returned
> > > > will be pte_marker defined bits only.
> > > >
> > > > > swp_offset(entry) & PTE_MARKER_UFFD_WP) as you kind of end up doing that anyway.
> > > > > Alternatively if you want helper functions I think it would be better to define
> > > > > them for each marker. Eg: is_pte_marker_uffd_wp().
> > > >
> > > > Yes we can have something like is_pte_marker_uffd_wp(), I didn't do that
> > > > explicitly because I want us to be clear that pte_marker is a bitmask, so
> > > > calling "is_*" will be slightly opaque - strictly speaking it should be
> > > > "pte_marker_has_uffd_wp_bit()" if there will be more bits defined, but then the
> > > > name of the helper will look a bit odd too. Hence I just keep the only
> > > > interface to fetch the whole marker and use "&" in the call sites to check.
> > >
> > > Why does a caller need to care if it's a bitmask or not though? Isn't that an
> > > implementation detail that could be left to the "is_*" functions? I must admit
> > > I'm still working through the rest of this series though - is it because you
> > > end up storing some kind of value in the upper bits of the PTE marker?
> >
> > Nop. I'm just afraid the caller could overlook the fact that it's a bitmask,
> > then there can be code like:
> >
> > if (is_pte_marker_uffd_wp(*ptep) && drop_uffd_wp)
> > pte_clear(ptep)
> >
> > While we should only do:
> >
> > if (is_pte_marker_uffd_wp(*ptep) && drop_uffd_wp)
> > // remove uffd-wp bit in the pte_marker, keep the reset bitmask
>
> I'm not sure how having the helper function prevents or changes this though? In
> fact I just noticed this in patch 8:
>
> if (uffd_wp_resolve &&
> (pte_marker_get(entry) & PTE_MARKER_UFFD_WP)) {
> pte_clear(vma->vm_mm, addr, pte);
> pages++;
> }
>
> And if I'm understanding your point correctly isn't that wrong because if there
> were other users of pte markers they would inadvertently get cleared? Unless of
> course I've missed something - I haven't looked at patch 8 yet for context. To
> help with the above situation I think you would need a helper for clearing
> ptes.
What I wanted to say is pte_marker_get() will make sure the caller will be
aware of the fact that the marker is a bitmask. But it's true at least my
example might make it even more confusing..
>
> > I could be worrying too much, there's no real user of it. If you prefer the
> > helper a lot I can add it in the new version. Thanks,
>
> It's not a massive issue, but I do think either defining a helper or open
> coding the bit check is clearer. I think we can worry about other users if/when
> they appear.
OK, I'll add it. Thanks,
--
Peter Xu
Powered by blists - more mailing lists