Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp378028pxk; Thu, 24 Sep 2020 07:47:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6ms4yF2IKBVNCwwcevG3+QBBdJQmJY4ULP6jGtmDXHy5hbHzwC5QXmG7VB/hi88R235/r X-Received: by 2002:a17:906:3ac5:: with SMTP id z5mr287681ejd.46.1600958875733; Thu, 24 Sep 2020 07:47:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600958875; cv=none; d=google.com; s=arc-20160816; b=t6iASw3p4IUGWp/M1sKuCTX7ducC5Oduo+a5cixjVuOWmONuQ+oBymLL+mk/ERmH1S EoHNAoLGCnwPlegHqDm76Zmi+UbDOPG8E/gM7jqG67Wk5gsxJLxnz73fdPuiGWz4nLif KgI8vVBR6beQ7ZVBr36q1a3TCxHkXulcCWqwdKEFXj1FN+YiAxwaYYWXUcLcPLyzWdwh TyllVwNSkSU3TUIa2MFpGHdfjSHwP407Yx87ZTnzlZci4RiZXlflUsYH6nxez2pfMYGJ L9awvo2mOMFeQVm6agvE+o6K+jga1vdGabt3Mi4MxQNRdSxayogM7i0xtxiM1E8IUTAU zJZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=NhiVL9WHbAPMWaOF6qP7noosbKK/eWP6hqvn2eVkB3U=; b=TKHMTbpoDnbcaZjSZhw55duayZVHDfjtUKbb8QejAK67qFduIcfPtV/pZ1d+8RlNJA sTNDpkJZfdJe+uZoa7LDQ82zsPoMFEJ+La2Q8yS3AG+m5PPoDfsYQQITIXynRK23UIH/ hGnDcvZAMDMTh3Tytl4NmfKRGE5XMvHYOFB3QkzHxrjXM+IOZqGrJquy7SOP59wfrt18 eNdgK/dyoeHcl4sZ0vCBsfZJyzM/Ey/FJe3xqXLIazlHtza6NBfEy9AHZc+wLvxeRaml l3/LSFTGS7/+ed3gDBq3be3nuORwGLHRHFzzqeaNJJxGDbDabIvcZ1Kz7oPGJPk+2jbI ClzQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 18si2983570edv.184.2020.09.24.07.47.29; Thu, 24 Sep 2020 07:47:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728213AbgIXOpd (ORCPT + 99 others); Thu, 24 Sep 2020 10:45:33 -0400 Received: from mx2.suse.de ([195.135.220.15]:38920 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727889AbgIXOpd (ORCPT ); Thu, 24 Sep 2020 10:45:33 -0400 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) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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