Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp7309583rwr; Tue, 2 May 2023 12:37:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5tCIC49r7VFViPZaQ95/vOdZBpUH0406wBvuc2JKwOmXJ2tBJUyaF/2EocOPkKkQaky+ma X-Received: by 2002:a05:6a00:1749:b0:63d:287f:fdf5 with SMTP id j9-20020a056a00174900b0063d287ffdf5mr26340926pfc.27.1683056245501; Tue, 02 May 2023 12:37:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683056245; cv=none; d=google.com; s=arc-20160816; b=LZyDfXD/NH9cL6KimwIA4TIFDsrwODg7dZ++Gz72MJJdEVaoi7ym+8AFanGuTiD9vX gxDLRI+bmvzqPV4kEEgQPqbH97wKRziYOa754hlLCL3gUPX3GeQbz4aMtKZ1Rrf6oRYl O1W7O2rRUnxKQoE9J9GI+IzUX4QyortMIzaOXUJC8nqostJQ5LsoRhQd+2bgFQtVh9gT w1KuP/C8+Zyfa+t4H/LSu0+xcE0776/4InbZJ9Lh+k+SXh04m83ttUG8AgRxzckGgunW r9HQaXdaxswUBGlZ1EFfXmDf147+CkHvU9aTlIM/SxttDVkHQ78HC1pOMp5zz6P7NqFQ bL4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=L7V+bKkAFuye2MRxx4y1CCTYTgcYyMX5mEQB4XsE6J8=; b=O5L9WkyxvJRyTqsIAYx3fXvxGexZlcO7eafxkD8U+w8siVPucVyxLJB10+/gjbGEp6 VMTugY2T/OueMbwM+4ig7r2k2wDbE19c7EsiC9gsob24goJ5CQ4yh7paXp/NxmPZgdqk nVCe9YXWWPRRmd1v4vpTof4+j8n3ovZZsUr+oqm4+JCzy+R3IShoLcXGg3/Gqyg4+MOx 6FD3hgpf3crMUMmlU4l0K8rZJB2qe4+quBLZhr1NAYyMax65LojT8sBHw9SLEt8WBzIh cVpP07UYjdlcbuRtbRKsMAFXvvKE2qMCqgdAg8nUBK0ToHg+jq6YjMQbMNYQ+2lhsyEa Ckmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZoWFPZPU; 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=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bs9-20020a632809000000b00517f0c53076si30374350pgb.463.2023.05.02.12.37.13; Tue, 02 May 2023 12:37:25 -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=@redhat.com header.s=mimecast20190719 header.b=ZoWFPZPU; 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=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229675AbjEBTeo (ORCPT + 99 others); Tue, 2 May 2023 15:34:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbjEBTek (ORCPT ); Tue, 2 May 2023 15:34:40 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B591B1FC3 for ; Tue, 2 May 2023 12:33:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683056032; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=L7V+bKkAFuye2MRxx4y1CCTYTgcYyMX5mEQB4XsE6J8=; b=ZoWFPZPUtiOSJ300lU2kzthKoEuN+vIm3v+4+lZv7pkxtSiOzHT0/fzPfzF0g+R0XvJWxP kT/VYSBsa9bYedBRiE8ACrQktf5c6n3RQYIS0DglZUSMkCgcsYubtrQee7q32kO5yAiuBm PgjUcCQHXwXXBO3TUf1lgDFQdbSqb1M= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-295-5h40_OCVPKauqFuHc1aD8w-1; Tue, 02 May 2023 15:33:49 -0400 X-MC-Unique: 5h40_OCVPKauqFuHc1aD8w-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-3f18c2b2110so13377485e9.3 for ; Tue, 02 May 2023 12:33:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683056028; x=1685648028; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=L7V+bKkAFuye2MRxx4y1CCTYTgcYyMX5mEQB4XsE6J8=; b=k0rwpOkU2lNV31cRUq6NhYb93eX4EKORgJfLvvDddLzy7I4D7/l0xAiu4anSJ4nKHV /+Wedx9x5oPo4klf/rdQxZRP2+jI6lNOZIwUhDVsHi/wtq++GSR9jfLlMxIkJdZU/1c+ 4hJuSB9PbGZDoSVVhxS/SBAZEwfHBFrahAMsZzcUPvzYe72Rob5XwY0PMqGGTBQwyg0d ENWV2fYI+70IZkDJgjPdTpb8BEdhe+UQW2G9p1tAC91g3z+vWcw58ORubyeccFecA3GU tNkxcNwxCWMKINVquHWk1XwwETr1HYllkafG/mxwpDcQxdFDTJ5/xiCDO9HHTedPN25j ZcCg== X-Gm-Message-State: AC+VfDx3/a7NgyA4jIE7YA03rPSm7x7zYZ0vM354U2GlLFVJE8cAAdZw HarvMkx9GdKpbbGOZIq1+ymtaZgpPfvurNqwQnoqdJPj3gp/q4AB2f687th4PQfQPWp4xFtVkmh W2Nr707RY/Lus7e4zxWbIwPpd X-Received: by 2002:a1c:7718:0:b0:3ef:8b0:dbb1 with SMTP id t24-20020a1c7718000000b003ef08b0dbb1mr12952276wmi.7.1683056028362; Tue, 02 May 2023 12:33:48 -0700 (PDT) X-Received: by 2002:a1c:7718:0:b0:3ef:8b0:dbb1 with SMTP id t24-20020a1c7718000000b003ef08b0dbb1mr12952237wmi.7.1683056028021; Tue, 02 May 2023 12:33:48 -0700 (PDT) Received: from ?IPV6:2003:cb:c700:2400:6b79:2aa:9602:7016? (p200300cbc70024006b7902aa96027016.dip0.t-ipconnect.de. [2003:cb:c700:2400:6b79:2aa:9602:7016]) by smtp.gmail.com with ESMTPSA id 3-20020a05600c22c300b003f31d44f0cbsm15442227wmg.29.2023.05.02.12.33.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 02 May 2023 12:33:47 -0700 (PDT) Message-ID: <434c60e6-7ac4-229b-5db0-5175afbcfff5@redhat.com> Date: Tue, 2 May 2023 21:33:45 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH v7 3/3] mm/gup: disallow FOLL_LONGTERM GUP-fast writing to file-backed mappings Content-Language: en-US To: Lorenzo Stoakes , Jason Gunthorpe Cc: 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 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> From: David Hildenbrand Organization: Red Hat In-Reply-To: <968fa174-6720-4adf-9107-c777ee0d8da4@lucifer.local> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 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. 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. -- Thanks, David / dhildenb