Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp5615453rwr; Mon, 24 Apr 2023 06:49:18 -0700 (PDT) X-Google-Smtp-Source: AKy350YF6H7K2FZWezVkoQ83eN9w8ERmEBUapodvuAmmM8AUERAfM1NlWrS/nE1uE41TPKkpr3r8 X-Received: by 2002:a05:6a20:3ca8:b0:ee:9272:73f8 with SMTP id b40-20020a056a203ca800b000ee927273f8mr18020396pzj.36.1682344158155; Mon, 24 Apr 2023 06:49:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682344158; cv=none; d=google.com; s=arc-20160816; b=QIyB34AJzcsftTnaQ1iCzypnButYyZwEHd4/5vLZMmVV11M+tpylcDQ6Fah3mZRNRt L4AeAmkbldSqKR9zFo5Pqam/aTTzAZD3t07sL9c2vTHjCJL8WKX1OkSVj6OOBxSLgFTc 1R4u+f4ema66FAXCo9aW1AtdeBjqcoUAUYniJi5PuNreTXSICKrrNh0LHsKeqrYmLzcb rM/JfQTdhymwEo3bSxIfvv69YmaK8PsQPK63kQNiAGd4GrMdd6TP6xbZYtN7KXV1IEe7 cg+4K/52hVk7aOw62qUl+f0dR0kiaUWJmIJKNQjPdXbdlrOikiQUkrp3z9jy3375Nh9F GmAA== 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:feedback-id :dkim-signature:dkim-signature; bh=Ae/BNl3LeeeGteor4m6cLa4HqXB1SG9Nq2ztdS5OqH8=; b=kvcpXv2+2Qs1uxH4/1g1hSQOE/eeieFpucGLIJ1JBAqMix6B+8z5tLzDfg0YV5c8jO Yhdmy0ivhImX4TayX2YE79MPfYX26v2k3ieNIF7hg2v2BJpDqr7A8HdHbnNRWriLCcvD VQ8KpCBJ30o6i/29HABKnjvP1En/4OpYpxFL/jBS1hztesLiEeHex39OlIzacRgQxahh DukssPKoLabjQNeILsu3Pz9pK0R3GArbuYnw2oidJtFJYDVUGOnJ+VlFcEQ53pZR5HAJ hmmJ2hHdo/ap4h9SIqHKGagbskG7Hskl/fVmEbrYDoaF0+xGOniJwpbIo8yjyuk7pVwo jMxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov.name header.s=fm1 header.b=ZIEUFOnD; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=gOOdk0uB; 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 z31-20020a630a5f000000b0051372ef848fsi11350611pgk.697.2023.04.24.06.49.04; Mon, 24 Apr 2023 06:49:18 -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=@shutemov.name header.s=fm1 header.b=ZIEUFOnD; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=gOOdk0uB; 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 S232787AbjDXNlK (ORCPT + 99 others); Mon, 24 Apr 2023 09:41:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232791AbjDXNkw (ORCPT ); Mon, 24 Apr 2023 09:40:52 -0400 Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D686902E; Mon, 24 Apr 2023 06:40:33 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 2A7675C0109; Mon, 24 Apr 2023 09:40:31 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Mon, 24 Apr 2023 09:40:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov.name; h=cc:cc:content-type:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1682343631; x= 1682430031; bh=Ae/BNl3LeeeGteor4m6cLa4HqXB1SG9Nq2ztdS5OqH8=; b=Z IEUFOnDXaFpaAbVZW/zEe8y7Z/TuozWTuA3mFbj46/Ot5wmR6YkgHbgZG56Qe3Ja 91zRF2Y9tzrsHu48HVkhD0ofMy4iuFHuNGFNpHddSyHSz7SzEbKj5QsxdAC/qB+A T5vwPSPeLnuhBSbM5ZeXZfcgxO0UW1HiROj+8rwdh2T3gb4CTr1714mKBZoA/RlQ 5uLbkxe8wYOABGzZofN1kQ4vHVum2IiwDhFe64bjDk89dsaSdGVW3M+gysx/y/aj /yAV85ZruGyscTM6RRz9v5IUAIh37rFUJBBSCzBFOoErcMYcjobfwKZVLPcs6IDh oe1uQRj3DLmJOXEc2L89w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; t=1682343631; x=1682430031; bh=Ae/BNl3LeeeGt eor4m6cLa4HqXB1SG9Nq2ztdS5OqH8=; b=gOOdk0uBtKcnNXlTtdMxOXqPxiRJo TprOv1B+Vjm071ggSgIPpTomPFhjjWCJ3b95faKZ0ZzQQT7NqWPhWwRBm2trenyd slmophLu7fzj2SYyI9b6X/MgKe8lpSBfoAjthMIqa4XewrP6squLQJD2NcNhpgGr ceMq9mz6YyLe+sPiJAMlEa0kUmhrAhNrii0+MYEQQfyKWtH4FyIzfeWeCQegdPnh CatvVjKKk707PQGAXqIqOlex23j4OnzwbrMzgjDDU+vK6on1/ZbY8LwW8J6UtJmG g7Xl3Yb2BHPt6sAEOqtTMT0q7fOglrViLtupF14NahGJILW2V12WoruFA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfedutddgieejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdttddttddtvdenucfhrhhomhepfdfmihhr ihhllhcutedrucfuhhhuthgvmhhovhdfuceokhhirhhilhhlsehshhhuthgvmhhovhdrnh grmhgvqeenucggtffrrghtthgvrhhnpefhieeghfdtfeehtdeftdehgfehuddtvdeuheet tddtheejueekjeegueeivdektdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpehkihhrihhllhesshhhuhhtvghmohhvrdhnrghmvg X-ME-Proxy: Feedback-ID: ie3994620:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 24 Apr 2023 09:40:29 -0400 (EDT) Received: by box.shutemov.name (Postfix, from userid 1000) id E05E310A0FA; Mon, 24 Apr 2023 16:40:26 +0300 (+03) Date: Mon, 24 Apr 2023 16:40:26 +0300 From: "Kirill A. Shutemov" To: Lorenzo Stoakes Cc: 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 , Peter Zijlstra , 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 Subject: Re: [PATCH] mm/gup: disallow GUP writing to file-backed mappings by default Message-ID: <20230424134026.di6nf2an3a2g63a6@box.shutemov.name> References: <20230424120247.k7cjmncmov32yv5r@box.shutemov.name> <3273f5f3-65d9-4366-9424-c688264992f9@lucifer.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3273f5f3-65d9-4366-9424-c688264992f9@lucifer.local> X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,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 Mon, Apr 24, 2023 at 01:31:56PM +0100, Lorenzo Stoakes wrote: > On Mon, Apr 24, 2023 at 03:02:47PM +0300, Kirill A. Shutemov wrote: > > On Sat, Apr 22, 2023 at 02:37:05PM +0100, Lorenzo Stoakes wrote: > > > @@ -959,16 +959,46 @@ static int faultin_page(struct vm_area_struct *vma, > > > return 0; > > > } > > > > > > +/* > > > + * Writing to file-backed mappings using GUP is a fundamentally broken operation > > > + * as kernel write access to GUP mappings may not adhere to the semantics > > > + * expected by a file system. > > > + * > > > + * In most instances we disallow this broken behaviour, however there are some > > > + * exceptions to this enforced here. > > > + */ > > > +static inline bool can_write_file_mapping(struct vm_area_struct *vma, > > > + unsigned long gup_flags) > > > +{ > > > + struct file *file = vma->vm_file; > > > + > > > + /* If we aren't pinning then no problematic write can occur. */ > > > + if (!(gup_flags & (FOLL_GET | FOLL_PIN))) > > > + return true; > > > + > > > + /* Special mappings should pose no problem. */ > > > + if (!file) > > > + return true; > > > + > > > + /* Has the caller explicitly indicated this case is acceptable? */ > > > + if (gup_flags & FOLL_ALLOW_BROKEN_FILE_MAPPING) > > > + return true; > > > + > > > + /* shmem and hugetlb mappings do not have problematic semantics. */ > > > + return vma_is_shmem(vma) || is_file_hugepages(file); > > > > Can this be generalized to any fs that doesn't have vm_ops->page_mkwrite()? > > > > Something more general would be preferable, however I believe there were > concerns broader than write notify, for instance not correctly marking the > folio dirty after writing to it, though arguably the caller should > certainly be ensuring that (and in many cases, do). It doesn't make much sense to me. Shared writable mapping without page_mkwrite (or pfn_write) will setup writeable PTE even on read faults[1], so you will not get the page dirty, unless you scan page table entries for dirty bit. [1] See logic around vm_page_prot vs. vma_wants_writenotify(). -- Kiryl Shutsemau / Kirill A. Shutemov