Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp191753pxk; Wed, 16 Sep 2020 23:47:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8MHHdzoAdMbQKBWdRjara8JyG+/gGFRkXArgpsVpCSLXtGVWJisPsN/oHon2qOX34+lWF X-Received: by 2002:a17:907:948b:: with SMTP id dm11mr6279470ejc.399.1600325238508; Wed, 16 Sep 2020 23:47:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600325238; cv=none; d=google.com; s=arc-20160816; b=k8RPZFCsiAjGRaA3baX55pu3y5K64H+R5j4fkrxtjyRyaSbEGZlvERyJw34OkV1gVf 2B1k6sx0wkEYwSj1ldCX9NKFRviGeSVmG1HGrhHh1EO0/HMpDjzn0x/jv0H3ng0x+YLL RO5tjnGBMtFGy6LodRbmsdkzyNJwREVlpbuxuuDt8gB3/R0k62Cf3I1sknn5CS6MdMW9 r7EWmfZQDzsT7T82k/uFFkTLmhdaSoAZAAOOERB1zYUckrbWpmt/rEg4364hMFhFrB2l zBP3xDH/Ektyb2s9v2douA42jQDuZXEczfMc5/MQsgJs0My0dKt4WH0lUrAIJL7dMltR 8FWg== 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; bh=wC1amSnEzSh3ioeljx7NsDcevjAEU6v54u+70WPggE0=; b=Dnlon6NH8OHocTlfho2JjakdcNUpRl07GK4rrm+FKsZVkgA+t5C5goQjWuQdlhG43F UbZM7eMphhQ2xAhjFfVXEEatGGY3WRTFNUll+daFviY5FzvJEz45b3atqqRUbUeC4k4O iur+0tSUS9Fjqjr0KpbvYKNiq5Iv1lN5OIEDQmYYyHko6ZOOFkBdxRFLDWT4Zw4VXI5N 7nKZLsFOO6tW60qp1zNyCTSZyhqyjdJ2YKr1w0AHy9ERLzRjcvGBZtUqvX2LCSBwv2uN 2Ug/cOOAN5nIcR5LH11RGwqUISINEyswpEFd6bDFURY3LqQK5lx7Z3de5WFpcx+W+zBl BP/A== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z23si13799279edx.215.2020.09.16.23.46.54; Wed, 16 Sep 2020 23:47:18 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726198AbgIQGpp (ORCPT + 99 others); Thu, 17 Sep 2020 02:45:45 -0400 Received: from mail105.syd.optusnet.com.au ([211.29.132.249]:56699 "EHLO mail105.syd.optusnet.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726109AbgIQGpm (ORCPT ); Thu, 17 Sep 2020 02:45:42 -0400 Received: from dread.disaster.area (pa49-195-191-192.pa.nsw.optusnet.com.au [49.195.191.192]) by mail105.syd.optusnet.com.au (Postfix) with ESMTPS id 463313ABB8A; Thu, 17 Sep 2020 16:45:34 +1000 (AEST) Received: from dave by dread.disaster.area with local (Exim 4.92.3) (envelope-from ) id 1kInfg-0001hZ-Oc; Thu, 17 Sep 2020 16:45:32 +1000 Date: Thu, 17 Sep 2020 16:45:32 +1000 From: Dave Chinner To: Hugh Dickins Cc: 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()) Message-ID: <20200917064532.GI12131@dread.disaster.area> References: <20200623052059.1893966-1-david@fromorbit.com> <20200916155851.GA1572@quack2.suse.cz> <20200917014454.GZ12131@dread.disaster.area> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.3 cv=XJ9OtjpE c=1 sm=1 tr=0 cx=a_idp_d a=vvDRHhr1aDYKXl+H6jx2TA==:117 a=vvDRHhr1aDYKXl+H6jx2TA==:17 a=kj9zAlcOel0A:10 a=reM5J-MqmosA:10 a=7-415B0cAAAA:8 a=x_xy7cVlXMNUeJvnttQA:9 a=CjuIK1q_8ugA:10 a=biEYGPWJfzWAr4FL6Ov7:22 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 16, 2020 at 07:04:46PM -0700, Hugh Dickins wrote: > On Thu, 17 Sep 2020, Dave Chinner wrote: > > > > So.... > > > > P0 p1 > > > > hole punch starts > > takes XFS_MMAPLOCK_EXCL > > truncate_pagecache_range() > > unmap_mapping_range(start, end) > > > > > > do_fault_around() > > ->map_pages > > filemap_map_pages() > > page mapping valid, > > page is up to date > > maps PTEs > > > > truncate_inode_pages_range() > > truncate_cleanup_page(page) > > invalidates page > > delete_from_page_cache_batch(page) > > frees page > > > > 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? 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.... 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 */ Cheers, Dave. -- Dave Chinner david@fromorbit.com