Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp474391pxb; Thu, 21 Jan 2021 11:31:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJz+mn8lKy2qiFTdrusQUZ83Cu2cFlXZn/CRNenZ+WVsX9zNk+OtLqYDrdagyRoSWfhkncL9 X-Received: by 2002:a05:6402:2694:: with SMTP id w20mr566427edd.200.1611257461690; Thu, 21 Jan 2021 11:31:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611257461; cv=none; d=google.com; s=arc-20160816; b=dmMTSWXzd/SVn1Y42JTtjKVZ3gPOtJgRjmnokbUjUQVH2oX6D4Cy+HrauUUyvv/AgD DWGsLNN4Zbc+eFyJoD7fbKpOyHTeY9ZO3Lzc1p0N0qo3agYv2OG1GV+F6JwV75oZGVxf cLMS/puFwNgqNSa7/idITcnJSWWQkS/q4NzcbFeXyrnfSIthIjeJWloW7irF8p+tcHvB 2aF0EJRanyMBpN1ABNsWGTMOp5gvvHcBM27zEDPlrEuiut9ZbUZbpr89HRaGWRb31E/G +CX4XS2gD1lPsNAUpCVXQ9a7XPQs0dnO1Gp5EaCT3O3jBzM8v+cV4FHKj10hKTuRGSxb 7thg== 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=i1zxz8vASWRHLxesy1rO5fxiDd7lfVOB0Kd0jdtsmCA=; b=vad2+pYY6MdQ9mcp5/Tb5/BZznaxvOJEbtT7fI/w4pJewn8HSQF8qy5IQCMEN2GeZY EISLGfs3ZiSWbXfk0yIOMuEGniZv5VFhF6Tk8cEQT2ooJxF6RvYntd0DbbWqlBYCBB89 kRHsr3TiKy7wCmVCMYTggAQt8T+mkdlRLhY5GiN6foCbNVHgWDcy4VlvC3DKsgQIshm0 h2YeZ7ZNUey5K2jlRhR4yhzKWIRJYhQQY/PZDTiFlWtziCAzBq1C8lxo0Fhef2UrdQjB yaTqxicVJl+YKnUKUqkg3Vid4ei0jpQ2lutyA7J9h/MAUpss1kyuXUCcqK8hu1rz/YX9 BvcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=TiWmVlnR; 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 h9si2613164edt.236.2021.01.21.11.30.16; Thu, 21 Jan 2021 11:31:01 -0800 (PST) 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=TiWmVlnR; 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 S1726304AbhAUT3u (ORCPT + 99 others); Thu, 21 Jan 2021 14:29:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726989AbhAUT3E (ORCPT ); Thu, 21 Jan 2021 14:29:04 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C12FC06174A; Thu, 21 Jan 2021 11:28:08 -0800 (PST) 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=i1zxz8vASWRHLxesy1rO5fxiDd7lfVOB0Kd0jdtsmCA=; b=TiWmVlnRNRpl3k1fc6a7iL5LGC prg+qFh/jLfikAviMB9uncuW06NSsekhPIdfm3CW93gMh5i2aj1KmCFqxMo+xpdOph3lJ8k9r7jk7 +YmzLil60j3IwF55dXjAlx5PDHqzHpS/Ce89Dzj6UjniN855XSKoPlcVHo064TQGffU4xXkmJVmmf TPDL/iH2/emDkxLnniPB0adm3KwqgxHGIV5Gl6Jg6GRMhJcwTO+vWR9dQAAWIG9CWqHifD8DqIjwZ qzYamwherXXeCx6cUfoJXR/ALQ4HjNj1RNcm7y1DfPckn4CMijalvip3LZ+05rNR0/67jpvSz/cmO 3QinD+ew==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1l2fcZ-00HQxN-4v; Thu, 21 Jan 2021 19:27:59 +0000 Date: Thu, 21 Jan 2021 19:27:55 +0000 From: Matthew Wilcox To: Jan Kara Cc: linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org Subject: Re: [PATCH 0/3 RFC] fs: Hole punch vs page cache filling races Message-ID: <20210121192755.GC4127393@casper.infradead.org> References: <20210120160611.26853-1-jack@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210120160611.26853-1-jack@suse.cz> Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Wed, Jan 20, 2021 at 05:06:08PM +0100, Jan Kara wrote: > Hello, > > Amir has reported [1] a that ext4 has a potential issues when reads can race > with hole punching possibly exposing stale data from freed blocks or even > corrupting filesystem when stale mapping data gets used for writeout. The > problem is that during hole punching, new page cache pages can get instantiated > in a punched range after truncate_inode_pages() has run but before the > filesystem removes blocks from the file. In principle any filesystem > implementing hole punching thus needs to implement a mechanism to block > instantiating page cache pages during hole punching to avoid this race. This is > further complicated by the fact that there are multiple places that can > instantiate pages in page cache. We can have regular read(2) or page fault > doing this but fadvise(2) or madvise(2) can also result in reading in page > cache pages through force_page_cache_readahead(). Doesn't this indicate that we're doing truncates in the wrong order? ie first we should deallocate the blocks, then we should free the page cache that was caching the contents of those blocks. We'd need to make sure those pages in the page cache don't get written back to disc (either by taking pages in the page cache off the lru list or having the filesystem handle writeback of pages to a freed extent as a no-op).