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: <2807E5FD2F6FDA4886F6618EAC48510E79E7F453@CRSMSX101.amr.corp.intel.com>
Date:   Fri, 9 Aug 2019 18:22:07 +0000
From:   "Weiny, Ira" <ira.weiny@...el.com>
To:     John Hubbard <jhubbard@...dia.com>
CC:     Vlastimil Babka <vbabka@...e.cz>, Michal Hocko <mhocko@...nel.org>,
        "Andrew Morton" <akpm@...ux-foundation.org>,
        Christoph Hellwig <hch@...radead.org>, Jan Kara <jack@...e.cz>,
        Jason Gunthorpe <jgg@...pe.ca>,
        Jerome Glisse <jglisse@...hat.com>,
        LKML <linux-kernel@...r.kernel.org>,
        "linux-mm@...ck.org" <linux-mm@...ck.org>,
        "linux-fsdevel@...r.kernel.org" <linux-fsdevel@...r.kernel.org>,
        "Williams, Dan J" <dan.j.williams@...el.com>,
        Daniel Black <daniel@...ux.ibm.com>,
        "Matthew Wilcox" <willy@...radead.org>,
        Mike Kravetz <mike.kravetz@...cle.com>
Subject: RE: [PATCH 1/3] mm/mlock.c: convert put_page() to put_user_page*()

> 
> On 8/8/19 4:41 PM, Ira Weiny wrote:
> > On Thu, Aug 08, 2019 at 03:59:15PM -0700, John Hubbard wrote:
> >> On 8/8/19 12:20 PM, John Hubbard wrote:
> >>> On 8/8/19 4:09 AM, Vlastimil Babka wrote:
> >>>> On 8/8/19 8:21 AM, Michal Hocko wrote:
> >>>>> On Wed 07-08-19 16:32:08, John Hubbard wrote:
> >>>>>> On 8/7/19 4:01 AM, Michal Hocko wrote:
> >>>>>>> On Mon 05-08-19 15:20:17, john.hubbard@...il.com wrote:
> ...
> >> Oh, and meanwhile, I'm leaning toward a cheap fix: just use
> >> gup_fast() instead of get_page(), and also fix the releasing code. So
> >> this incremental patch, on top of the existing one, should do it:
> >>
> >> diff --git a/mm/mlock.c b/mm/mlock.c
> >> index b980e6270e8a..2ea272c6fee3 100644
> >> --- a/mm/mlock.c
> >> +++ b/mm/mlock.c
> >> @@ -318,18 +318,14 @@ static void __munlock_pagevec(struct pagevec
> *pvec, struct zone *zone)
> >>                 /*
> >>                  * We won't be munlocking this page in the next phase
> >>                  * but we still need to release the follow_page_mask()
> >> -                * pin. We cannot do it under lru_lock however. If it's
> >> -                * the last pin, __page_cache_release() would deadlock.
> >> +                * pin.
> >>                  */
> >> -               pagevec_add(&pvec_putback, pvec->pages[i]);
> >> +               put_user_page(pages[i]);
> 
> correction, make that:
>                    put_user_page(pvec->pages[i]);
> 
> (This is not fully tested yet.)
> 
> >>                 pvec->pages[i] = NULL;
> >>         }
> >>         __mod_zone_page_state(zone, NR_MLOCK, delta_munlocked);
> >>         spin_unlock_irq(&zone->zone_pgdat->lru_lock);
> >>
> >> -       /* Now we can release pins of pages that we are not munlocking */
> >> -       pagevec_release(&pvec_putback);
> >> -
> >
> > I'm not an expert but this skips a call to lru_add_drain().  Is that ok?
> 
> Yes: unless I'm missing something, there is no reason to go through
> lru_add_drain in this case. These are gup'd pages that are not going to get
> any further processing.
> 
> >
> >>         /* Phase 2: page munlock */
> >>         for (i = 0; i < nr; i++) {
> >>                 struct page *page = pvec->pages[i]; @@ -394,6 +390,8
> >> @@ static unsigned long __munlock_pagevec_fill(struct pagevec *pvec,
> >>         start += PAGE_SIZE;
> >>         while (start < end) {
> >>                 struct page *page = NULL;
> >> +               int ret;
> >> +
> >>                 pte++;
> >>                 if (pte_present(*pte))
> >>                         page = vm_normal_page(vma, start, *pte); @@
> >> -411,7 +409,13 @@ static unsigned long __munlock_pagevec_fill(struct
> pagevec *pvec,
> >>                 if (PageTransCompound(page))
> >>                         break;
> >>
> >> -               get_page(page);
> >> +               /*
> >> +                * Use get_user_pages_fast(), instead of get_page() so that the
> >> +                * releasing code can unconditionally call put_user_page().
> >> +                */
> >> +               ret = get_user_pages_fast(start, 1, 0, &page);
> >> +               if (ret != 1)
> >> +                       break;
> >
> > I like the idea of making this a get/put pair but I'm feeling uneasy
> > about how this is really supposed to work.
> >
> > For sure the GUP/PUP was supposed to be separate from [get|put]_page.
> >
> 
> Actually, they both take references on the page. And it is absolutely OK to call
> them both on the same page.
> 
> But anyway, we're not mixing them up here. If you follow the code paths,
> either gup or follow_page_mask() is used, and then put_user_page()
> releases.
> 
> So...you haven't actually pointed to a bug here, right? :)

No...  no bug.

sorry this was just a general comment on semantics.  But in keeping with the semantics discussion it is further confusing that follow_page_mask() is also mixed in here...

Which is where my comment was driving toward.  If you call GUP there should be a PUP.  Get_page/put_page...  follow_page/unfollow_page...  ???  ;-)  Ok now I'm off the rails...  but that was the point...

I think Jan and Michal are onto something here WRT internal vs external interfaces.

Ira

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ