Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp7184524rwr; Tue, 2 May 2023 10:36:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5AObvSHFozeEmpDpgG0Y0Zi2X1ZbNhdPl8PvzGGPzPjoplCxypXFc+eoR9QPqDFxVTYftG X-Received: by 2002:a17:902:cec4:b0:1aa:e425:2527 with SMTP id d4-20020a170902cec400b001aae4252527mr12472755plg.21.1683048992372; Tue, 02 May 2023 10:36:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683048992; cv=none; d=google.com; s=arc-20160816; b=aEzd2e5MkYSKZTqYlJtAhDzR9j/60FlpCcS51MzMsbvQI5XETwXkx0IfUcb+h4Q98U ngCeWbUL7XrOpeEdOu3IBOlGRyw3exnQaFKuK1e2a65MqXXjunQbgA3fNXGmEvwpEpls zcrgjsEXLM0dJM9xP1DJi2R4pMjcIxaa9B0quwlHyFJIBehlfi1oSwCF9lz5JLmHj4Hg b9iOy0NLhi57hECnjWbynpYwBEh6B//pn+4NepQcJx11ytWfqt+trjXNgn3431PxvvhD yeermA5c0mMI8YlK7FZZj3hrWAXbCeSa015OloCIK9+cM08v2a61zmhhvOY6IcBFJ44+ Zt8Q== 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=C6e/8ch2eiLA3MhI/SDDmmseytmUgb05EwRd/AY6faE=; b=PYGvwA90wwnoGvaCYwS69IMSFOpZAG0YjYH012VaNccYhmeZUcGomDp9XkqNIpTa4h E3clVmddir43ROoPlfCQFwUpDwnftf95riomnKueblPlTsOAZvHx/W4vtrN1fx4z55Ow W1UooXcLOxok6MsH2GMCIGs1HpiQr7j6CbkEydWjqKh859JF+X9lpyUDso2v+eMtX6rD JUTktgAH0G1F960FR8yL+xEKNDw8AxQ4Ygi56sd9e+CJmX9at9qCJf/3ubMUyR+fAc66 HwxHrBrgby+T3QKEAs0mEVoyyXPOKi27hrVhy292ANp44N6nWLyvaIwXyjZGZCl++ZxR yKRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="lYH/Im62"; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q12-20020a170902dacc00b001a98e569e33si19988648plx.588.2023.05.02.10.36.17; Tue, 02 May 2023 10:36:32 -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=@infradead.org header.s=casper.20170209 header.b="lYH/Im62"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234026AbjEBRX1 (ORCPT + 99 others); Tue, 2 May 2023 13:23:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232402AbjEBRX0 (ORCPT ); Tue, 2 May 2023 13:23:26 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28606E43; Tue, 2 May 2023 10:23:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=C6e/8ch2eiLA3MhI/SDDmmseytmUgb05EwRd/AY6faE=; b=lYH/Im62obo8CLQo3d1z7OxM7G zg20c66BCFqbOPkxy7fYV/VkvAd9TfywyQ9BqaGqllwMiqAMKqdwKmqUe9D6QDk9TGEaDNfLGHdvQ QhrXDgYDf5e4zXRxjfxjBHIHVnSZhzAJ6eKr2M1mEhiD+JJCRcMOFSNBo9S9vPZ9PpioWTkDWybas vo+c2F+r6FMmmafjil3/fr+u4sZJ6Y6ahyjePqfI6e54HOd+Ho2lChGO9p6QcxJY2stOHsGkkhj+e T5FjO7EWYn9pLEQv6lJFMKuughpqndTY0ADrd8LMAXZM3CGr6e4q00jkFAPORv4mtWidTcXEIOLQp 7OWTpSKg==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1ptti1-008YU3-7O; Tue, 02 May 2023 17:22:37 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 20013300379; Tue, 2 May 2023 19:22:32 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 92DB726941AA0; Tue, 2 May 2023 19:22:32 +0200 (CEST) Date: Tue, 2 May 2023 19:22:32 +0200 From: Peter Zijlstra To: David Hildenbrand Cc: Lorenzo Stoakes , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Jason Gunthorpe , 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 , Jason Gunthorpe , 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: <20230502172231.GH1597538@hirez.programming.kicks-ass.net> References: <1691115d-dba4-636b-d736-6a20359a67c3@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1691115d-dba4-636b-d736-6a20359a67c3@redhat.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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 Tue, May 02, 2023 at 07:13:49PM +0200, David Hildenbrand wrote: > [...] > > > +{ > > + struct address_space *mapping; > > + > > + /* > > + * 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()). > > + * > > + * 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. > > + * > > + * We get the added benefit that given inodes, and thus address_space, > > + * objects are RCU freed, we can rely on the mapping remaining stable > > + * here with no risk of a truncation or similar race. > > + */ > > + lockdep_assert_irqs_disabled(); > > + > > + /* > > + * If no mapping can be found, this implies an anonymous or otherwise > > + * non-file backed folio so in this instance we permit the pin. > > + * > > + * shmem and hugetlb mappings do not require dirty-tracking so we > > + * explicitly whitelist these. > > + * > > + * Other non dirty-tracked folios will be picked up on the slow path. > > + */ > > + mapping = folio_mapping(folio); > > + return !mapping || shmem_mapping(mapping) || folio_test_hugetlb(folio); > > "Folios in the swap cache return the swap mapping" -- you might disallow > pinning anonymous pages that are in the swap cache. > > I recall that there are corner cases where we can end up with an anon page > that's mapped writable but still in the swap cache ... so you'd fallback to > the GUP slow path (acceptable for these corner cases, I guess), however > especially the comment is a bit misleading then. > > So I'd suggest not dropping the folio_test_anon() check, or open-coding it > ... which will make this piece of code most certainly easier to get when > staring at folio_mapping(). Or to spell it out in the comment (usually I > prefer code over comments). So how stable is folio->mapping at this point? Can two subsequent reads get different values? (eg. an actual mapping and NULL) If so, folio_mapping() itself seems to be missing a READ_ONCE() to avoid the compiler from emitting the load multiple times.