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] [day] [month] [year] [list]
Message-ID: <2167899.OcvonqYCbN@nvdebian>
Date:   Fri, 12 Mar 2021 15:42:44 +1100
From:   Alistair Popple <apopple@...dia.com>
To:     Matthew Wilcox <willy@...radead.org>
CC:     <linux-mm@...ck.org>, <nouveau@...ts.freedesktop.org>,
        <bskeggs@...hat.com>, <akpm@...ux-foundation.org>,
        <linux-doc@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
        <kvm-ppc@...r.kernel.org>, <dri-devel@...ts.freedesktop.org>,
        <jhubbard@...dia.com>, <rcampbell@...dia.com>, <jglisse@...hat.com>
Subject: Re: [PATCH v5 1/8] mm: Remove special swap entry functions

On Tuesday, 9 March 2021 11:49:49 PM AEDT Matthew Wilcox wrote:
> On Tue, Mar 09, 2021 at 11:14:58PM +1100, Alistair Popple wrote:
> > -static inline struct page *migration_entry_to_page(swp_entry_t entry)
> > -{
> > -	struct page *p = pfn_to_page(swp_offset(entry));
> > -	/*
> > -	 * Any use of migration entries may only occur while the
> > -	 * corresponding page is locked
> > -	 */
> > -	BUG_ON(!PageLocked(compound_head(p)));
> > -	return p;
> > -}
> 
> > +static inline struct page *pfn_swap_entry_to_page(swp_entry_t entry)
> > +{
> > +	struct page *p = pfn_to_page(swp_offset(entry));
> > +
> > +	/*
> > +	 * Any use of migration entries may only occur while the
> > +	 * corresponding page is locked
> > +	 */
> > +	BUG_ON(is_migration_entry(entry) && !PageLocked(compound_head(p)));
> > +
> > +	return p;
> > +}
> 
> I appreciate you're only moving this code, but PageLocked includes an
> implicit compound_head():

I am happy to clean this up at the same time. It did seem a odd when I added 
it and I had meant to follow up on it some more.

> 1. __PAGEFLAG(Locked, locked, PF_NO_TAIL)
> 
> 2. #define __PAGEFLAG(uname, lname, policy)                                \
>         TESTPAGEFLAG(uname, lname, policy)                              \
> 
> 3. #define TESTPAGEFLAG(uname, lname, policy)                              \
> static __always_inline int Page##uname(struct page *page)               \
>         { return test_bit(PG_##lname, &policy(page, 0)->flags); }
> 
> 4. #define PF_NO_TAIL(page, enforce) ({                                    \
>                 VM_BUG_ON_PGFLAGS(enforce && PageTail(page), page);     \
>                 PF_POISONED_CHECK(compound_head(page)); })
> 
> 5. #define PF_POISONED_CHECK(page) ({                                      \
>                 VM_BUG_ON_PGFLAGS(PagePoisoned(page), page);            \
>                 page; })
> 
> 
> This macrology isn't easy to understand the first time you read it (nor,
> indeed, the tenth time), so let me decode it:
> 
> Substitute 5 into 4 and remove irrelevancies:
> 
> 6. #define PF_NO_TAIL(page, enforce) compound_head(page)
> 
> Expand 1 in 2:
> 
> 7.	TESTPAGEFLAG(Locked, locked, PF_NO_TAIL)
> 
> Expand 7 in 3:
> 
> 8. static __always_inline int PageLocked(struct page *page)
> 	{ return test_bit(PG_locked, &PF_NO_TAIL(page, 0)->flags); }
> 
> Expand 6 in 8:
> 
> 9. static __always_inline int PageLocked(struct page *page)
> 	{ return test_bit(PG_locked, &compound_head(page)->flags); }

Thanks for expanding that out, makes sense and matches my reading as well. 
Will remove the redundant compound_head() call in PageLocked() for the next 
revision.

> (in case it's not clear, compound_head() is idempotent.  that is:
> 	f(f(a)) == f(a))





Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ