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=-5.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 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 3F7CFC43461 for ; Thu, 17 Sep 2020 07:40:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A68DC2083B for ; Thu, 17 Sep 2020 07:40:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A68DC2083B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B69676B0003; Thu, 17 Sep 2020 03:40:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AF3BE6B0037; Thu, 17 Sep 2020 03:40:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9BCC86B005C; Thu, 17 Sep 2020 03:40:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0137.hostedemail.com [216.40.44.137]) by kanga.kvack.org (Postfix) with ESMTP id 831616B0003 for ; Thu, 17 Sep 2020 03:40:33 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 37AFC181AEF07 for ; Thu, 17 Sep 2020 07:40:33 +0000 (UTC) X-FDA: 77271755946.29.show06_110ac7327120 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin29.hostedemail.com (Postfix) with ESMTP id 0306C180868F7 for ; Thu, 17 Sep 2020 07:40:32 +0000 (UTC) X-HE-Tag: show06_110ac7327120 X-Filterd-Recvd-Size: 3997 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf07.hostedemail.com (Postfix) with ESMTP for ; Thu, 17 Sep 2020 07:40:32 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 50DC9AC92; Thu, 17 Sep 2020 07:40:46 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 647241E12E1; Thu, 17 Sep 2020 09:40:30 +0200 (CEST) Date: Thu, 17 Sep 2020 09:40:30 +0200 From: Jan Kara To: Nikolay Borisov Cc: Dave Chinner , 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: <20200917074030.GA9555@quack2.suse.cz> 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=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Rspamd-Queue-Id: 0306C180868F7 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 Content-Transfer-Encoding: quoted-printable 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-09-20 08:37:17, Nikolay Borisov wrote: > On 17.09.20 =D0=B3. 4:44 =D1=87., Dave Chinner wrote: > > On Wed, Sep 16, 2020 at 05:58:51PM +0200, Jan Kara wrote: > >> On Sat 12-09-20 09:19:11, Amir Goldstein wrote: > >>> On Tue, Jun 23, 2020 at 8:21 AM Dave Chinner = wrote: >=20 > >=20 > >=20 > > So.... > >=20 > > P0 p1 > >=20 > > 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 > > > >=20 > > That doesn't seem good to me. > >=20 > > Sure, maybe the page hasn't been freed back to the free lists > > because of elevated refcounts. But it's been released by the > > filesystem and not longer in the page cache so nothing good can come > > of this situation... > >=20 > > AFAICT, this race condition exists for the truncate case as well > > as filemap_map_pages() doesn't have a "page beyond inode size" check > > in it.=20 >=20 > (It's not relevant to the discussion at hand but for the sake of > completeness): >=20 > It does have a check: >=20 > max_idx =3D DIV_ROUND_UP(i_size_read(mapping->host), PAGE_SIZE); > if (page->index >=3D max_idx) > goto unlock; Yes, but this does something meaningful only for truncate. For other operations such as hole punch this check doesn't bring anything. That's w= hy only filesystems supporting hole punching and similar advanced operations need an equivalent of mmap_lock. Honza --=20 Jan Kara SUSE Labs, CR