Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp7314095rwr; Tue, 2 May 2023 12:42:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5OaEGucJrGWp+G5msc8k1HI3Z1Af9nbw1rwGWiRGVYMIr4jth/sxTea9kgyoL+kW68Mq4p X-Received: by 2002:a17:90a:53e5:b0:24d:ee84:84d1 with SMTP id y92-20020a17090a53e500b0024dee8484d1mr10044216pjh.9.1683056559320; Tue, 02 May 2023 12:42:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683056559; cv=none; d=google.com; s=arc-20160816; b=hIIzbCW93/WuLS0egnKTWcRLvgyxuoo244+Mc4pAy2AgDN5K/v8/su0M8D2MsV7xwI QHmyw03/x5S4Mqqk5xEnt3YHqLrOukMdjevhaFHMGyHUmW5zgACvDYz381Nd0fT9yY3Y XgZY2D9XjFDpuFemUgo09RTqtj98MzBtwIn3K94GSoAksruuE7FvXuS+KGRd7ozJ+y/d IYdD3mgzx0rvR4HehxvDJFjyloIfW0XUuTpsvS/ZCkSq3Po8RIDCh5jnax3AzpUiiO94 LSfd9O5ASq3jtjCXufehQkPISYXIVsw+Px2DXC49I4cYMeAaBM+2i1wkLc8qxcWLK4Nn pcEg== 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=yAN6Tx0XQ5cbgXparCHR/XEVN6lZoL4POmuLsxZAKdE=; b=YMj9s/VfeLTmbap4GkFWmtgmBM6Kwb/1o4VwPjjMjrOMGuN/Ss/cN/QOH0br3SiftM jmg8twHY4vxRDUAlUhmteTy+8pzAcXeGHYsSQ5E9ZxIN9f9e8cAn/mRh3W269Wa01eYR 2Ncz0OefUCLE6oG5m6JmIymqOBfMTLsEG1+GnTstfKjF3FN2K+nfRVS29fraRYeRBTSu vZd4DgYJ4bUjGNqz8UtybTddLLJg00AXXmht7Y2wk4ZHBZVbWHOH7pGYpU1i+S7nINh2 T1SQW2nm7I8iSg1pBdnJr266n7z/rWTg7Lk6KquqX5smPHRkGYfhbLFnFG88twJwSlY3 0o7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=k8kErdOP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v13-20020a17090a520d00b0024e29660f61si2218194pjh.90.2023.05.02.12.42.25; Tue, 02 May 2023 12:42:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=k8kErdOP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229610AbjEBThK (ORCPT + 99 others); Tue, 2 May 2023 15:37:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbjEBThI (ORCPT ); Tue, 2 May 2023 15:37:08 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 967661BF9; Tue, 2 May 2023 12:37:07 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3f18dacd392so26600615e9.0; Tue, 02 May 2023 12:37:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683056226; x=1685648226; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=yAN6Tx0XQ5cbgXparCHR/XEVN6lZoL4POmuLsxZAKdE=; b=k8kErdOPVqPjXe1UVr8CE/r8s1h4neD6cqHotJu9TowY8FOBIbOn+5Ho9ZTcDCagRk /XQzmVQnTYSOtm4WXN+YcYgnIVypug7+S+yvYzavsLrJJaDl3qd8/9WwOTa/UoKghyGo NUlKZ6xBdsjrqeAlsaefz8tdfEVcA6NFDLZ5vh3zQUugFLoVs+e+0KHh9Lrp3le77uTF FVOS0g558WHu+VX3dSGsRy5SrfkcF3tIGvfwKbSTagyG/arJM13RThshZmv2XxHYpwAC AP9tdMAwmJwBH5VsPgI5xQ+ODO651sEuQ2Yj/V01JnjkBFUmuaF4qQDQuDmFV7hJ67aX LcPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683056226; x=1685648226; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=yAN6Tx0XQ5cbgXparCHR/XEVN6lZoL4POmuLsxZAKdE=; b=BLivDXTsNdfsBxe+oLRmLI5+9Gcc/aLDtZlXrF1StJ3xNWh2EMuevLyOB6fqrjkXTo VuMY7F1NKi0e7FFyWUhOOqJTLhbAy+kLCrzqHSXgKLQhgEbD3YD4aFe5QzPw2i6ztQo5 AIr7HL2K54rEq5yAMLUYRQb/9IGY6JYi2ljACHfvc6JFsJSHNX7DioZPBKAIzX6e4qz8 SdgQJupiwff8TZj2zgMdBjCyQuVBaiUl6Xx42/0/NP3NC3KHS/N+OcClsI40tNpLaXLM go4K4fdK7NlMoRO2/CBUCOQqE8ngLjmR+h8BR5vHQ+8cdptLSyh3G0y1tAwhHw5oIsE0 CFTA== X-Gm-Message-State: AC+VfDyn0bfCJ+6gXUD43knKfEgQtc5On0EQADe97MU5rr5IKr75xNPN 5A3hJU+/QVy+EzW5Rc3numg= X-Received: by 2002:a1c:7907:0:b0:3f1:8ef0:7e2f with SMTP id l7-20020a1c7907000000b003f18ef07e2fmr12767978wme.25.1683056225811; Tue, 02 May 2023 12:37:05 -0700 (PDT) Received: from localhost (host86-156-84-164.range86-156.btcentralplus.com. [86.156.84.164]) by smtp.gmail.com with ESMTPSA id t24-20020a1c7718000000b003f3195be0a0sm16618019wmi.31.2023.05.02.12.37.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 May 2023 12:37:05 -0700 (PDT) Date: Tue, 2 May 2023 20:37:04 +0100 From: Lorenzo Stoakes To: David Hildenbrand Cc: Jason Gunthorpe , Peter Zijlstra , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Jens Axboe , Matthew Wilcox , Dennis Dalessandro , Leon Romanovsky , Christian Benvenuti , Nelson Escobar , Bernard Metzler , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Bjorn Topel , Magnus Karlsson , Maciej Fijalkowski , Jonathan Lemon , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Brauner , Richard Cochran , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , linux-fsdevel@vger.kernel.org, linux-perf-users@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, Oleg Nesterov , John Hubbard , Jan Kara , "Kirill A . Shutemov" , Pavel Begunkov , Mika Penttila , Dave Chinner , Theodore Ts'o , Peter Xu , Matthew Rosato , "Paul E . McKenney" , Christian Borntraeger , Mike Rapoport Subject: Re: [PATCH v7 3/3] mm/gup: disallow FOLL_LONGTERM GUP-fast writing to file-backed mappings Message-ID: References: <1691115d-dba4-636b-d736-6a20359a67c3@redhat.com> <20230502172231.GH1597538@hirez.programming.kicks-ass.net> <406fd43a-a051-5fbe-6f66-a43f5e7e7573@redhat.com> <3a8c672d-4e6c-4705-9d6c-509d3733eb05@lucifer.local> <968fa174-6720-4adf-9107-c777ee0d8da4@lucifer.local> <434c60e6-7ac4-229b-5db0-5175afbcfff5@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <434c60e6-7ac4-229b-5db0-5175afbcfff5@redhat.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 02, 2023 at 09:33:45PM +0200, David Hildenbrand wrote: > On 02.05.23 21:25, Lorenzo Stoakes wrote: > > On Tue, May 02, 2023 at 04:07:50PM -0300, Jason Gunthorpe wrote: > > > On Tue, May 02, 2023 at 07:17:14PM +0100, Lorenzo Stoakes wrote: > > > > > > > On a specific point - if mapping turns out to be NULL after we confirm > > > > stable PTE, I'd be inclined to reject and let the slow path take care of > > > > it, would you agree that that's the correct approach? > > > > > > I think in general if GUP fast detects any kind of race it should bail > > > to the slow path. > > > > > > The races it tries to resolve itself should have really safe and > > > obvious solutions. > > > > > > I think this comment is misleading: > > > > > > > + /* > > > > + * GUP-fast disables IRQs - this prevents IPIs from causing page tables > > > > + * to disappear from under us, as well as preventing RCU grace periods > > > > + * from making progress (i.e. implying rcu_read_lock()). > > > > > > True, but that is not important here since we are not reading page > > > tables > > > > > > > + * This means we can rely on the folio remaining stable for all > > > > + * architectures, both those that set CONFIG_MMU_GATHER_RCU_TABLE_FREE > > > > + * and those that do not. > > > > > > Not really clear. We have a valid folio refcount here, that is all. > > > > Some of this is a product of mixed signals from different commenters and > > my being perhaps a little _too_ willing to just go with the flow. > > > > With interrupts disabled and IPI blocked, plus the assurances that > > interrupts being disabled implied the RCU version of page table > > manipulation is also blocked, my understanding was that remapping in this > > process to another page could not occur. > > > > Of course the folio is 'stable' in the sense we have a refcount on it, but > > it is unlocked so things can change. > > > > I'm guessing the RCU guarantees in the TLB logic are not as solid as IPI, > > because in the IPI case it seems to me you couldn't even clear the PTE > > entry before getting to the page table case. > > > > Otherwise, I'm a bit uncertain actually as to how we can get to the point > > where the folio->mapping is being manipulated. Is this why? > > I'll just stress again that I think there are cases where we unmap and free > a page without synchronizing against GUP-fast using an IPI or RCU. OK that explains why we need to be careful. Don't worry I am going to move the check after we confirm PTE entry hasn't changed. > > That's one of the reasons why we recheck if the PTE changed to back off, so > I've been told. > > I'm happy if someone proves me wrong and a page we just (temporarily) pinned > cannot have been freed+reused in the meantime. Let's play it safe for now :) > > -- > Thanks, > > David / dhildenb >