Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp6539711rwr; Tue, 2 May 2023 01:45:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6wbpyfNk/nabKKugfIxBRs0qjjZ6s8TYPH2WYj6UXWihcy8QZYApQu4koxx166koFut03j X-Received: by 2002:a05:6a20:9596:b0:ef:e240:b55d with SMTP id iu22-20020a056a20959600b000efe240b55dmr18217711pzb.55.1683017144905; Tue, 02 May 2023 01:45:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683017144; cv=none; d=google.com; s=arc-20160816; b=pPRRIICIiUfkeJyX5OwsChNNDgSwqLwa8+MOjZJ+4mS7/z+q/BHRqmp2UIQCE15CiA pIOQKEHXeRqyNw/8Wi46Ceb/E/dyfwV6LnTupwql4/KqJNsMQ0PSggmC0Gypr31bXmSZ L7XA6wB2s7zzUhRkc2OLMvl9/Z3daiBmzr1wF6g5p2KEVO1MZHu3fCjMW0Ga3JBa54ZQ wOELeRpB1B/6xQNXHgkaJWn09hZnduhEPicS+gc4Px+oHmEn/flkHT7TxPfjJFasB9YG XkdfGPKolSB78urTIqKHc2ma9HkxZE2Wz9m2C8XjqK8xEGtTyZbooLY9TGI54lyoXuIR dxkQ== 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=gMkzwyLT/Xyxf8is/5S3+NSRKbTsmvleiqsCtxbzf8o=; b=DTCIGZgg7rvFhu0s+zcswugEBSNz/JiDbW2hoyGyTRXKPoRatm7DRgfPrqbyVivkzp E3NGKL++ohkIRk26n9vf7zpjZ/iVy/vFdlqYwRKqFpgP4RXrBfsADFlfzaXCRkij0cYf zVAGa0enxNViRqQw0y1h0m8pIQnISc6dLGn3+eQ8xZE7hV4vqMbOZWtRYWjXQo6K4efX jkk4HBzi9nGZt2GY7twKJecxXHWoBCinhxIxuB0BJUzguIzHMOz4EC8MtddKRe87O084 cPgvjJq99Q7ZahmVLDCHivPghGAQUkxTp6neL02VafZ85kyFqCacfg+CX7UkOz2DWX3y 12Bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=lDgKY8pW; 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 v10-20020a63610a000000b00528d90d40e2si7393009pgb.891.2023.05.02.01.45.32; Tue, 02 May 2023 01:45:44 -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=lDgKY8pW; 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 S233878AbjEBIlR (ORCPT + 99 others); Tue, 2 May 2023 04:41:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233867AbjEBIlP (ORCPT ); Tue, 2 May 2023 04:41:15 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 600771BEF; Tue, 2 May 2023 01:41:12 -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=gMkzwyLT/Xyxf8is/5S3+NSRKbTsmvleiqsCtxbzf8o=; b=lDgKY8pWgvaQIksEJVeLu2NKWR Jlz7kaZrEA+JA08BM+1VseVQkG441GBvgR24tACB+EBymntVCAzDbXHNJs1PdwckLuCJlKBb+QCyx nY3snqpW8fW+ykTn+5iqEC6yhVNvhO30scPF0Od5GxTNLIqtOuKQBQ3Y8tZ/aUANje1j7rD4QOWGm mK9OYMECjI/W9QFLwtxockb7D8sXqbrgXFHkY0udMrbB3iCKl2XYmFt4cVbywBY6fMcyDnepaIgTN /xT2sCi2HHWkHPLOoGNVEm439P3xjVSCTT4r9HimGel44cnWCXtAhsIEx24kI82KFIbVFnX4V6N7x aYOzgNfQ==; 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 1ptlY8-00892R-Q5; Tue, 02 May 2023 08:39:52 +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) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id C18EE3002BF; Tue, 2 May 2023 10:39:47 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 3061A23C5C347; Tue, 2 May 2023 10:39:47 +0200 (CEST) Date: Tue, 2 May 2023 10:39:47 +0200 From: Peter Zijlstra To: Jan Kara Cc: "Kirill A . Shutemov" , David Hildenbrand , Peter Xu , Lorenzo Stoakes , Jason Gunthorpe , 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 , Pavel Begunkov , Mika Penttila , David Howells , Christoph Hellwig Subject: Re: [PATCH v5] mm/gup: disallow GUP writing to file-backed mappings by default Message-ID: <20230502083947.GE1597476@hirez.programming.kicks-ass.net> References: <6ddc7ac4-4091-632a-7b2c-df2005438ec4@redhat.com> <20230428160925.5medjfxkyvmzfyhq@box.shutemov.name> <39cc0f26-8fc2-79dd-2e84-62238d27fd98@redhat.com> <20230428162207.o3ejmcz7rzezpt6n@box.shutemov.name> <173337c0-14f4-3246-15ff-7fbf03861c94@redhat.com> <20230428165623.pqchgi5gtfhxd5b5@box.shutemov.name> <1039c830-acec-d99b-b315-c2a6e26c34ca@redhat.com> <20230428234332.2vhprztuotlqir4x@box.shutemov.name> <20230502080016.4tgmqb4sy2ztfgrd@quack3> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230502080016.4tgmqb4sy2ztfgrd@quack3> 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=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 10:00:16AM +0200, Jan Kara wrote: > On Sat 29-04-23 02:43:32, Kirill A . Shutemov wrote: > > I think I found relevant snippet of code that solves similar issue. > > get_futex_key() uses RCU to stabilize page->mapping after GUP_fast: > > > > > > /* > > * The associated futex object in this case is the inode and > > * the page->mapping must be traversed. Ordinarily this should > > * be stabilised under page lock but it's not strictly > > * necessary in this case as we just want to pin the inode, not > > * update the radix tree or anything like that. > > * > > * The RCU read lock is taken as the inode is finally freed > > * under RCU. If the mapping still matches expectations then the > > * mapping->host can be safely accessed as being a valid inode. > > */ > > rcu_read_lock(); > > > > if (READ_ONCE(page->mapping) != mapping) { > > rcu_read_unlock(); > > put_page(page); > > > > goto again; > > } > > > > inode = READ_ONCE(mapping->host); > > if (!inode) { > > rcu_read_unlock(); > > put_page(page); > > > > goto again; > > } > > > > I think something similar can be used inside GUP_fast too. > > Yeah, inodes (and thus struct address_space) is RCU protected these days so > grabbing RCU lock in gup_fast() will get you enough protection for checking > aops if you are careful (like the futex code is). GUP_fast has IRQs disabled per definition, there is no need to then also use rcu_read_lock().