Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1584314pxy; Fri, 23 Apr 2021 11:32:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzv+kj0vs1eFiMyQiCzzz0+XL51oH3gySyeiqo/IB0DvE3RVj89xRAHLPP3HMkpzqFshwY4 X-Received: by 2002:a05:6402:94c:: with SMTP id h12mr6074069edz.148.1619202746611; Fri, 23 Apr 2021 11:32:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619202746; cv=none; d=google.com; s=arc-20160816; b=pD0+Xac/37sc4ZW1ggnnUhBIEShjhNOshSPu9W3959jnvEVRBByo5s+W/ItJho+8Q2 jYBM/QvhxPO9S3Saa8zO2OE9QI3buZb73CLIGITCl0yyimS4U0D50q/xfJLFIyfGeJCj E3SnsmNIN6dIBGgiiXHgoJKMlWuIphHaXBUbHb2xlcQeokQOQCGXNYm8sr0/UqH/DIH5 uU5tPUYOluwYuNPas5wCKO9dira4s6q9KIoYiP2RKbIL/nJ2C8mM21jFrNKlsmpxs5QY H5xwdhwHF/vJzRmI0MhuADaVg8Zu+poZJzt/Pjfx2tOda1G4n4mJ1Jeox0dFCjb46ywY WP6g== 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:dkim-signature; bh=19MC/ECN3OWEttJSfNKYhsEBI3DWNTT+3puFZa754BA=; b=PxZd9NdWMnf80a6Y3+jUuBDJWp51gt55dHXaM2Ima756pYjlcCAgEdYRECiuxE18o2 i9aMLqj046vB5OnI7IDP3qMUtln6eQR0ekez4drOYer7KgdetzU//qc8+fCMFPCWczep 2N8tmQHY7Cn/JKVTC/c5LA48ayPz1XirRwqMU3b0mOGwhA8tOmRiWNsiNCLdVpWaF7Ac SjTZ/ep1bTlz6sJ6XvZ3LFMHAKMvgd6ClAFqzBAT+sTtVGpyPQhh5N0Tq3raI1kQY5PN CpxKjsqqhUCSCxXhK+Aqh3MoRnL8eMDDIomVwozR5/IV3bTMRisXT2xiQ6IBF+1wPxoC 0zrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=q2fnOVoW; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-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 j22si6310326eds.145.2021.04.23.11.31.34; Fri, 23 Apr 2021 11:32:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-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=@infradead.org header.s=casper.20170209 header.b=q2fnOVoW; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232244AbhDWScF (ORCPT + 99 others); Fri, 23 Apr 2021 14:32:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229691AbhDWScE (ORCPT ); Fri, 23 Apr 2021 14:32:04 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3610EC061574; Fri, 23 Apr 2021 11:31:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=19MC/ECN3OWEttJSfNKYhsEBI3DWNTT+3puFZa754BA=; b=q2fnOVoW6AVeExxSOF8pr+ERGP yfxbQCEhL3SoJ9S4pecr6zRB0GmmsCxrZukyAdiAMif6SHNvdOE1E7U120Ij1sP+Z3+wdrWsoURWi PmYCkHgT1eriQFe7P0ERXjHBCO+9JlTYV8aQVmtgIJjR8lvgL3cyavi3FEjHoHFTxc21WAQ4f2Zz+ sV1Z4B6IbOjs6KU46Pmsh7fntCFyTamR96j2R8oTTo7FP6sAhPbe7AQKxieTOEdSvtIYQdjJzcTxN +xIAsRybN9Pq4T5YBkQNFpvPqSZSTBjscy226S2phOUwKGDjVYieWIwk09t7BsYB4/T18YLR5tOTh NjjW6VQg==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1la0Zc-002EBZ-Af; Fri, 23 Apr 2021 18:30:48 +0000 Date: Fri, 23 Apr 2021 19:30:40 +0100 From: Matthew Wilcox To: Jan Kara Cc: linux-fsdevel@vger.kernel.org, Christoph Hellwig , Amir Goldstein , Dave Chinner , Ted Tso , ceph-devel@vger.kernel.org, Chao Yu , Damien Le Moal , "Darrick J. Wong" , Hugh Dickins , Jaegeuk Kim , Jeff Layton , Johannes Thumshirn , linux-cifs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-mm@kvack.org, linux-xfs@vger.kernel.org, Miklos Szeredi , Steve French Subject: Re: [PATCH 02/12] mm: Protect operations adding pages to page cache with invalidate_lock Message-ID: <20210423183040.GD235567@casper.infradead.org> References: <20210423171010.12-1-jack@suse.cz> <20210423173018.23133-2-jack@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210423173018.23133-2-jack@suse.cz> Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Fri, Apr 23, 2021 at 07:29:31PM +0200, Jan Kara wrote: > Currently, serializing operations such as page fault, read, or readahead > against hole punching is rather difficult. The basic race scheme is > like: > > fallocate(FALLOC_FL_PUNCH_HOLE) read / fault / .. > truncate_inode_pages_range() > cache here> > > > Now the problem is in this way read / page fault / readahead can > instantiate pages in page cache with potentially stale data (if blocks > get quickly reused). Avoiding this race is not simple - page locks do > not work because we want to make sure there are *no* pages in given > range. One of the things I've had in mind for a while is moving the DAX locked entry concept into the page cache proper. It would avoid creating the new semaphore, at the cost of taking the i_pages lock twice (once to insert the entries that cover the range, and once to delete the entries). It'd have pretty much the same effect, though -- read/fault/... would block until the entry was deleted from the page cache.