Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp345287pxk; Thu, 24 Sep 2020 07:04:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxd0PxMfbBq9OaTdGyO5ALLEMWLaxzJCwesu7Q1AvVzDxD0xZMtc/hXQWkVS5cRyAaC/cHH X-Received: by 2002:a17:906:9718:: with SMTP id k24mr4619ejx.365.1600956253938; Thu, 24 Sep 2020 07:04:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600956253; cv=none; d=google.com; s=arc-20160816; b=E6oh2T0I+I7RVw4+fsbSRHHpjk6kVfToFteSwgQhBQOkE4RtWMrTpltcRCJ8ZS933w QKZC+LoqV8LPuYn8xULPgyoLHUk+pRSpqRGFQNX6XICturE3RxJZgpmz79XZBvD0yqiz 7mohlwzweHGgDw9T7Kf3WjVvOQkg/CaGgdWLAnY5afmVsLj5fbsuq+6YxJwOQXivxQkZ xguO4cCsJFoABenp0zF4c+lohXF3WJ+07ikcPfoOHNs2CETF4wGLQohoU+69+TPPuzwl KnHXQhxmME1VIo6Cm5iAxvjLrhGDeu6RQu2ZfwS5JYNwzf52wU/S174hc+rKkzp0sW4Z fW+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=DX2HQBWGuaee0luRYYI4yMH5TJumhhW2wtpCA8Ku7VM=; b=WF61NJjh39A8NRPjw1afkufmvn9jy6sPiCUiRttVFQz3BzB2X8egcLiLnCZQbm8ssy H8CzeIlEjiWj0S5YiBiAeZIEKnbRkq4a7IXvuxX8VCvwM6VKjs7dMKc5NblJ3ifeHO+h al/SqoZfiq038p9rzm8O/xe6YB9J40u/5MNQCJRSfTJpudpiXCtPgrx1HiXe4keqH45D Pa8qE8qQ19q2mY5Qu1XCAL+jvONaWv8wSq6fUhh1wFdREJ4B7bbDiOGKCAhjyxxLa1zQ C9pV+6NTiObXXjYV2rsYezTiffO0zFm/JCxfrgoYUQ59nJOVyJR6/9jzpRcqfSDHH9aD F+iQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=HpQfoeid; 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 a14si2357407edk.57.2020.09.24.07.03.45; Thu, 24 Sep 2020 07:04:13 -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; dkim=pass header.i=@ziepe.ca header.s=google header.b=HpQfoeid; 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 S1728103AbgIXOCl (ORCPT + 99 others); Thu, 24 Sep 2020 10:02:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727859AbgIXOCk (ORCPT ); Thu, 24 Sep 2020 10:02:40 -0400 Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8ED9EC0613CE for ; Thu, 24 Sep 2020 07:02:40 -0700 (PDT) Received: by mail-qk1-x72e.google.com with SMTP id t138so3373567qka.0 for ; Thu, 24 Sep 2020 07:02:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=DX2HQBWGuaee0luRYYI4yMH5TJumhhW2wtpCA8Ku7VM=; b=HpQfoeidFIVPg4nNWvc99Nd1mzrQYL7G5U3CfwQS6NtRbSZ6TWjV3NaFirSAgay8+7 qPkj9wN/8HI6zi4hV92cb3wmwVKvcf9IjHpyIeZCPvsu5/oWGU90Z1mn4GI2RiC1FvW/ fQ+okKbI4dzzb0R6+cL3CgVL5ymexsRNylv6jWp7s88HQ7JfFjYL+vA98LXH9JudhEWI nBlZW41T72JraFIFMo+xcmWAfOnU18KTBrBdI/STIvlPMxSm+PtoRaMfTSdq9dQjU061 BPy+5vdnYnZFad3cQQ7Sk95i6VXk5j0vi9xBRE5JreeisjZhgq5OAOrjWs7jANCNWsjk boPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=DX2HQBWGuaee0luRYYI4yMH5TJumhhW2wtpCA8Ku7VM=; b=nogHKzYfRUcjlfPtJ20TQV/+WgliGqCHzwpqySjV+1BX9fIjN6PBm9bh+6OZ8dmCP1 n9Y3fd+wkATrYv104DQwsZXFoqUq78Zmkkw0Wgam/G4uKslzUwZhy2V+fAUxMX8YmpX8 jK5dmwgdWybIhikMcftK3zyndAxvwsIcSyyP0p1dyL2RX05VM3ZruNOXdF4D1SQThHp3 AQU2rjiv2X3EENSiW3nYCEay/3NxPfT+YPmXW9a9sfk1dpDxkTxP79dccnW0s+bjtPc/ 3RgpqISYe8MvrLVMb2JP1a4FYAPQgYM6eBX9CoNr+DgvQTKcbtZQVq3Le94BOTNY5s3V tHRA== X-Gm-Message-State: AOAM530a2GuB5uXEh/fj8NI8GHC9ktcx+8/S5aAMeY7gLc14dNhf1y6R aBCcs3Oj1lNYUriGTJOAqxz2OA== X-Received: by 2002:ae9:e84c:: with SMTP id a73mr4721002qkg.61.1600956159787; Thu, 24 Sep 2020 07:02:39 -0700 (PDT) Received: from ziepe.ca ([206.223.160.26]) by smtp.gmail.com with ESMTPSA id x43sm2375131qtx.40.2020.09.24.07.02.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2020 07:02:38 -0700 (PDT) Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1kLRpV-000LQR-Ov; Thu, 24 Sep 2020 11:02:37 -0300 Date: Thu, 24 Sep 2020 11:02:37 -0300 From: Jason Gunthorpe To: Jan Kara Cc: 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: <20200924140237.GD9916@ziepe.ca> References: <224908c1-5d0f-8e01-baa9-94ec2374971f@nvidia.com> <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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200924074409.GB27019@quack2.suse.cz> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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. Jason