Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp220126pxk; Thu, 17 Sep 2020 00:48:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKbC7hRoLPVZaF5ChE3tj/hMv7VncwT4EzptK6t5arnFwIhz38FPpFFsFiCoRMiSkJu/Cv X-Received: by 2002:a17:906:e4c:: with SMTP id q12mr28792082eji.425.1600328934804; Thu, 17 Sep 2020 00:48:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600328934; cv=none; d=google.com; s=arc-20160816; b=hX2w0yHhPDqX9Y5gpRXD+U4M559JLCHb7ljmHo9lna0c7OPqlqkaP5CizFdO+8j2eS NhoMmU1K0HPuQMYYa3LwEqIB4iWtuDKjvbDIvJPb+jhaSRwW3BNVdJKKv0MZhveJeKz6 V7jowHyHL2WhgEv1fHvtSM7tK3Thy3xFu0HWAaYqDgO38mfuhbDXkRmRxSp7pQdtDXQk MHnzDTv1lPZmI4nG3xwMjdHoc8bfie0vFkdEHr0QFh/6KLf8N8zGgoLBD7u467LHPFSU 9dUCTnhIUHioah0idRbWbIP49bMtbvQTnRZXmgzBRxO6kg+yjgZkjCRC+ArIiJcrCUNI ygmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date:dkim-signature; bh=xuE7LaGJOi9kZU8SLjYfHhU0NXKHscTySoakr/Q5V18=; b=QRuItRtkryVxn+InCxc5+e94f9s8bWZyIKODeAhE63QDehuIoYmOIDdyzLfYyPh8eK G6kfRCl4G3A21g4Otms0xJJRqrymaj0ymFGGS4e7CTTGYasd21sdNY0h9Nmu3xUwooCN Tjw63XkhpUlVdUpTHWlSOuVNFniUfOAQCLoATxgxJdLYYu2zF45h7Q1b3i0GLXZYWEgl eN3aPxydAznYUvktog27YAK7e6ohZCLxvi6kBVWZNR9ujEcBR6OOtosTCSvVJSFtJRWx QoibU4sBM0IQl/X3180mGP3ignpLGpmR66/L3gCUigVxsSJuSNM/5gt3zy93iN8/o0l3 aMPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Kmm0yesG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f4si13354120ejw.300.2020.09.17.00.48.31; Thu, 17 Sep 2020 00:48:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Kmm0yesG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726269AbgIQHrg (ORCPT + 99 others); Thu, 17 Sep 2020 03:47:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726336AbgIQHrf (ORCPT ); Thu, 17 Sep 2020 03:47:35 -0400 Received: from mail-oi1-x243.google.com (mail-oi1-x243.google.com [IPv6:2607:f8b0:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18BA5C061788 for ; Thu, 17 Sep 2020 00:47:28 -0700 (PDT) Received: by mail-oi1-x243.google.com with SMTP id c13so1436083oiy.6 for ; Thu, 17 Sep 2020 00:47:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=xuE7LaGJOi9kZU8SLjYfHhU0NXKHscTySoakr/Q5V18=; b=Kmm0yesG94IF9RUJc3KzwoLFkkmMbiP2V0JRQdz32bJsss5TJ1VsW8Ku2YtLStENzq sV8OWVJOiwzBpugNB/bIoDZGqQDfixpIVEu5kr+YJJiT52j3BGruFBwc8GzvLhs2Mok/ rIRQKMp9IDiG9pcwohHPg3m+6oZGF6A5+sVZExpSn4+caMuFmkDeOfbn464Jspgx7dp2 muNvmI3kWT4XFDVQPXFOdPjew8H0ZRbJn1CphOVfdBtuW8AV7Gj94ZK1fKkuAUXYR1R9 7wjp1zAo/8haxWZHNBLW7a+uJTox2YNchnH9SP85CHnBt3M++Lcduhxw7S7XApi+2Vls LaJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=xuE7LaGJOi9kZU8SLjYfHhU0NXKHscTySoakr/Q5V18=; b=fhWDFH/xRa1s/zs+Vtl7fSY6Hw1uu/WD1tCVltA0nQ1GaAkzuvXilGA87U659Lydkf 0GlCJOA6su1jbqNw/0hw4pcYAl1nguQcfoeXXg3sAI92jk5V65aVCnO84oOh0eleTzWx nKRp1kSIgchsA3FOKR4CqGE5utKRzyJe1QQ3fuGwZ8lX/R2wheP9ekDlUQQwncDa8Y5i oFDNkEELnVcB5DK8OJwEKj2JJaCuRnQ+igiyHp+Yp2kxp5EkjefLcuZrLceuRJkvPgmM k9E2hd2/flltJDSrkoLhaX/iG1jeUnyTVW0e0QlmIIujfsNRMfGkzlOT5dPuHnFtdg22 T4CQ== X-Gm-Message-State: AOAM533jBTrcp/S1NGVBlnMNd5VT/1OJjb0tmE0R605AeDX0CxlqHo5C peMw21YxEjONXJFidaoo77RSPw== X-Received: by 2002:aca:d0c:: with SMTP id 12mr5250119oin.178.1600328847618; Thu, 17 Sep 2020 00:47:27 -0700 (PDT) Received: from eggly.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id w12sm12496765oow.22.2020.09.17.00.47.23 (version=TLS1 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Thu, 17 Sep 2020 00:47:24 -0700 (PDT) Date: Thu, 17 Sep 2020 00:47:10 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Dave Chinner cc: Hugh Dickins , Jan Kara , Amir Goldstein , Andreas Gruenbacher , Theodore Tso , Martin Brandenburg , Mike Marshall , Damien Le Moal , Jaegeuk Kim , Qiuyang Sun , linux-xfs , linux-fsdevel , Linux MM , linux-kernel , Matthew Wilcox , Linus Torvalds , "Kirill A. Shutemov" , Andrew Morton , Al Viro , nborisov@suse.de Subject: Re: More filesystem need this fix (xfs: use MMAPLOCK around filemap_map_pages()) In-Reply-To: <20200917064532.GI12131@dread.disaster.area> Message-ID: References: <20200623052059.1893966-1-david@fromorbit.com> <20200916155851.GA1572@quack2.suse.cz> <20200917014454.GZ12131@dread.disaster.area> <20200917064532.GI12131@dread.disaster.area> User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 17 Sep 2020, Dave Chinner wrote: > On Wed, Sep 16, 2020 at 07:04:46PM -0700, Hugh Dickins wrote: > > On Thu, 17 Sep 2020, Dave Chinner wrote: > > > > > > > No. filemap_map_pages() checks page->mapping after trylock_page(), > > before setting up the pte; and truncate_cleanup_page() does a one-page > > unmap_mapping_range() if page_mapped(), while holding page lock. > > Ok, fair, I missed that. > > So why does truncate_pagecache() talk about fault races and require > a second unmap range after the invalidation "for correctness" if > this sort of race cannot happen? I thought the comment * unmap_mapping_range is called twice, first simply for * efficiency so that truncate_inode_pages does fewer * single-page unmaps. However after this first call, and * before truncate_inode_pages finishes, it is possible for * private pages to be COWed, which remain after * truncate_inode_pages finishes, hence the second * unmap_mapping_range call must be made for correctness. explains it fairly well. It's because POSIX demanded that when a file is truncated, the user will get SIGBUS on trying to access even the COWed pages beyond EOF in a MAP_PRIVATE mapping. Page lock on the cache page does not serialize the pages COWed from it very well. But there's no such SIGBUS requirement in the case of hole-punching, and trying to unmap those pages racily instantiated just after the punching cursor passed, would probably do more harm than good. > > Why is that different to truncate_pagecache_range() which -doesn't-i > do that second removal? It's called for more than just hole_punch - > from the filesystem's persepective holepunch should do exactly the > same as truncate to the page cache, and for things like > COLLAPSE_RANGE it is absolutely essential because the data in that > range is -not zero- and will be stale if the mappings are not > invalidated completely.... I can't speak to COLLAPSE_RANGE. > > Also, if page->mapping == NULL is sufficient to detect an invalidated > page in all cases, then why does page_cache_delete() explicitly > leave page->index intact: > > page->mapping = NULL; > /* Leave page->index set: truncation lookup relies upon it */ Because there was, and I think still is (but might it now be xarrayed away?), code (mainly in mm/truncate.c) which finds it convenient to check page->index for end of range, without necessitating the overhead of getting page lock. I've no doubt it's an (minor) optimization that could be discarded if there were ever a need to invalidate page->index when deleting; but nobody has required that yet. Hugh