From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8745EC77B7F for ; Mon, 24 Apr 2023 13:41:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232782AbjDXNlJ (ORCPT ); Mon, 24 Apr 2023 09:41:09 -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> Precedence: bulk List-ID: X-Mailing-List: netdev@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