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 X-Spam-Level: X-Spam-Status: No, score=-12.9 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10791C43461 for ; Thu, 17 Sep 2020 07:47:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 921CA21D41 for ; Thu, 17 Sep 2020 07:47:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Kmm0yesG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 921CA21D41 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B56BE8E0001; Thu, 17 Sep 2020 03:47:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B074E6B0037; Thu, 17 Sep 2020 03:47:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9F7B48E0001; Thu, 17 Sep 2020 03:47:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0190.hostedemail.com [216.40.44.190]) by kanga.kvack.org (Postfix) with ESMTP id 86AC36B0003 for ; Thu, 17 Sep 2020 03:47:29 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 3EDB28249980 for ; Thu, 17 Sep 2020 07:47:29 +0000 (UTC) X-FDA: 77271773418.03.shake90_560052227120 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin03.hostedemail.com (Postfix) with ESMTP id 08D6328A4E8 for ; Thu, 17 Sep 2020 07:47:29 +0000 (UTC) X-HE-Tag: shake90_560052227120 X-Filterd-Recvd-Size: 6693 Received: from mail-oi1-f193.google.com (mail-oi1-f193.google.com [209.85.167.193]) by imf21.hostedemail.com (Postfix) with ESMTP for ; Thu, 17 Sep 2020 07:47:28 +0000 (UTC) Received: by mail-oi1-f193.google.com with SMTP id i17so1416567oig.10 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=VOfavEr9Rhq87c+raznWqLjnIDKEVdPrtmh6lBAGgLaxzi7Y1cVzgRwj+fWiPoiF+d DpnepdX0ruVn0avTqEWi5qFewMPWv8BxS1pdsEO1L9Iy6ILNVUrXWOBnrF8e2CpwQbKV lI5fqy7XZiSR46G4SRycWMPik9NVI358OxfJEx3T9P0t16bD6CUqAGI5EpxuckXXVd8/ WYfNx1/v/pLlFIFVBzThN2nTc2OCMqg2HLIAyzLgocU+EU31ILPe6+DP5LFRjPYtcDZ/ AN0mpYFxcVl8YhAtbvomzCnO4d4sGIUleo7toMmkPGoEKBWIktEfnCd333OdN0kfMHHW Qtdw== X-Gm-Message-State: AOAM531OCiHZhz3/ljKleOB38L1I8znCaaNlHHYMeu0cna++AI1I4rpR Bg3C6yBxgMXrIp1nfIhX0qTlZQ== X-Google-Smtp-Source: ABdhPJyTkq2ud2gGkfCt3he+sXmBAD5xvV4TxEsvjI3/NSJz2fM5nyKi4a7W/xlBRROYMTE1qpNQrA== 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 X-Rspamd-Queue-Id: 08D6328A4E8 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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