Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp328284pxk; Thu, 24 Sep 2020 06:42:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQFt0eiFbo5rLHHmGfFDXZ6ckPS4xCrmDuS0+bt8lHRVk2th3sm4feSLQhSI3EXYmRBUK3 X-Received: by 2002:a50:bb62:: with SMTP id y89mr1147477ede.261.1600954974462; Thu, 24 Sep 2020 06:42:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600954974; cv=none; d=google.com; s=arc-20160816; b=dfNziJgl0+WzWi1fTxEjPzagHAA6xJX9gWclXi1aB2OXGcK1JF6edOXy4iIQNInIYa r1uANfEBhGJG6EENVUMFZV8qrYHQujrQMPZliy/EONorReJkqYtzCEQrO3/ZqiV5KQEA XFZfDl2p1RpvF5pPN/1ZEqNDkfUVrBpNgPKNPs2yD666mOZPCYkG9Vbvzi8Rftu1V/+v s9wynzNOppj0XXz7Lnw7LTPalRggDuj0KDrlZCLckXyrpXwfrYCcwMl7KrTxd++j4qgm TT+vmjX9+PJQmN6BTQerg0lcGUhuLPBCs5/1wAAIUsQPEojSU71KGdFJZFuPzxf6MafY AemA== 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=BCFRXO1NABi2KaJYhM1Nic/20tNv1Lr+yAmB1hLMb2g=; b=gXu9jFI7Q8CeetHkKHQDIeRRF6Kic2QgS1Wu9jCAHxuvvPjoKMhH4szOEbFz0Etqmb uE64rgXSdWY2JTlJXzNO4mwfLqKpm/9c6n7q1AfeMSp9fRf6k5w0xJiaFiaVw9jg+aEi bF+QdUyaQFNt90bIMIok1/Qi9EA9Ooti8AR2DGYhNuQykEtrZJhdqcIsnrXTkGaYfuIG NTwF+fnMvpKy684my+tqZMzEZ74byMfTH6IsvvsnjXvFiKukJxT3srAoRzHz7CzCHiDd Wb1xBM5LpQzwx7343eMa4wCFwXwtlX8jvm2o4DJxEU4lRDYY51sAR4/YADkM4DTiJCsv 8Lvw== 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 l2si1987956ejc.209.2020.09.24.06.42.30; Thu, 24 Sep 2020 06:42:54 -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 S1728103AbgIXNkl (ORCPT + 99 others); Thu, 24 Sep 2020 09:40:41 -0400 Received: from mx2.suse.de ([195.135.220.15]:55254 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727835AbgIXNkk (ORCPT ); Thu, 24 Sep 2020 09:40:40 -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 A9297AE44; Thu, 24 Sep 2020 13:40:38 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 667671E12E9; Thu, 24 Sep 2020 09:44:09 +0200 (CEST) Date: Thu, 24 Sep 2020 09:44:09 +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: <20200924074409.GB27019@quack2.suse.cz> References: <20200921211744.24758-2-peterx@redhat.com> <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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200923171207.GB9916@ziepe.ca> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed 23-09-20 14:12:07, Jason Gunthorpe wrote: > On Wed, Sep 23, 2020 at 04:20:03PM +0200, Jan Kara wrote: > > > I'd hate to take spinlock in the GUP-fast path. Also I don't think this is > > quite correct because GUP-fast-only can be called from interrupt context > > and page table locks are not interrupt safe. > > Yes, IIRC, that is a key element of GUP-fast. Was it something to do > with futexes? Honestly, I'm not sure. > > and then checking page_may_be_dma_pinned() during fork(). That should work > > just fine AFAICT... BTW note that GUP-fast code is (and this is deliberated > > because e.g. DAX depends on this) first updating page->_refcount and then > > rechecking PTE didn't change and the page->_refcount update is actually > > done using atomic_add_unless() so that it cannot be reordered wrt the PTE > > check. So the fork() code only needs to add barriers to pair with this. > > It is not just DAX, everything needs this check. > > 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. It's more about being able to make sure page is not accessible anymore - and for that modifying pte and then checking page refcount it *reliable* way to synchronize with GUP-fast... Honza -- Jan Kara SUSE Labs, CR