From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CCD8CC4727D for ; Thu, 24 Sep 2020 14:45:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2DD222311A for ; Thu, 24 Sep 2020 14:45:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2DD222311A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 683BC6B005C; Thu, 24 Sep 2020 10:45:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6341E6B005D; Thu, 24 Sep 2020 10:45:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 54A336B0062; Thu, 24 Sep 2020 10:45:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0041.hostedemail.com [216.40.44.41]) by kanga.kvack.org (Postfix) with ESMTP id 3CB5B6B005C for ; Thu, 24 Sep 2020 10:45:34 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id EDFDA181AE865 for ; Thu, 24 Sep 2020 14:45:33 +0000 (UTC) X-FDA: 77298228546.27.stove94_430ed472715f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin27.hostedemail.com (Postfix) with ESMTP id 9EC133D668 for ; Thu, 24 Sep 2020 14:45:33 +0000 (UTC) X-HE-Tag: stove94_430ed472715f X-Filterd-Recvd-Size: 3145 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf18.hostedemail.com (Postfix) with ESMTP for ; Thu, 24 Sep 2020 14:45:32 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 94DDFAB0E; Thu, 24 Sep 2020 14:45:31 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 3E8711E12DD; Thu, 24 Sep 2020 16:45:31 +0200 (CEST) Date: Thu, 24 Sep 2020 16:45:31 +0200 From: Jan Kara To: Jason Gunthorpe Cc: Jan Kara , Peter Xu , John Hubbard , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Michal Hocko , Kirill Tkhai , Kirill Shutemov , Hugh Dickins , Christoph Hellwig , Andrea Arcangeli , Oleg Nesterov , Leon Romanovsky , Linus Torvalds , Jann Horn Subject: Re: [PATCH 1/5] mm: Introduce mm_struct.has_pinned Message-ID: <20200924144531.GA2364@quack2.suse.cz> References: <20200922151736.GD19098@xz-x1> <20200922161046.GB731578@ziepe.ca> <20200922175415.GI19098@xz-x1> <20200922191116.GK8409@ziepe.ca> <20200923002735.GN19098@xz-x1> <20200923131043.GA59978@xz-x1> <20200923142003.GB15875@quack2.suse.cz> <20200923171207.GB9916@ziepe.ca> <20200924074409.GB27019@quack2.suse.cz> <20200924140237.GD9916@ziepe.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200924140237.GD9916@ziepe.ca> User-Agent: Mutt/1.10.1 (2018-07-13) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu 24-09-20 11:02:37, Jason Gunthorpe wrote: > On Thu, Sep 24, 2020 at 09:44:09AM +0200, Jan Kara wrote: > > > After the page is pinned it is prevented from being freed and > > > recycled. After GUP has the pin it must check that the PTE still > > > points at the same page, otherwise it might have pinned a page that is > > > alreay free'd - and that would be a use-after-free issue. > > > > I don't think a page use-after-free is really the reason - we add page > > reference through page_ref_add_unless(page, x, 0) - i.e., it will fail for > > already freed page. > > I mean, the page could have been freed and already reallocated with a > positive refcount, so the add_unless check isn't protective. > > The add_unless prevents the page from being freed. The 2nd pte read > ensures it wasn't already freed/reassigned before the pin. Ah, right! > If something drives the page refcount to zero then it is already > synchronized with GUP fast because of the atomic add_unless, no need > to re-check the pte for that case?? But I don't know what the DAX case > is you mentioned. DAX needs to make sure no new references (including GUP-fast) can be created for a page before truncating page from a file and freeing it. Honza -- Jan Kara SUSE Labs, CR