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=-2.5 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_MUTT autolearn=unavailable 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 CF790C46470 for ; Tue, 4 Jun 2019 07:57:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A916A24D3F for ; Tue, 4 Jun 2019 07:57:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727100AbfFDH5x (ORCPT ); Tue, 4 Jun 2019 03:57:53 -0400 Received: from mx2.suse.de ([195.135.220.15]:60184 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727011AbfFDH5w (ORCPT ); Tue, 4 Jun 2019 03:57:52 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 651CDAE21; Tue, 4 Jun 2019 07:57:51 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 0F6A11E3C24; Tue, 4 Jun 2019 09:57:51 +0200 (CEST) Date: Tue, 4 Jun 2019 09:57:51 +0200 From: Jan Kara To: Amir Goldstein Cc: Jan Kara , Ext4 , Ted Tso , Linux MM , linux-fsdevel , stable Subject: Re: [PATCH 2/2] ext4: Fix stale data exposure when read races with hole punch Message-ID: <20190604075751.GK27933@quack2.suse.cz> References: <20190603132155.20600-1-jack@suse.cz> <20190603132155.20600-3-jack@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Mon 03-06-19 19:33:50, Amir Goldstein wrote: > On Mon, Jun 3, 2019 at 4:22 PM Jan Kara wrote: > > > > Hole puching currently evicts pages from page cache and then goes on to > > remove blocks from the inode. This happens under both i_mmap_sem and > > i_rwsem held exclusively which provides appropriate serialization with > > racing page faults. However there is currently nothing that prevents > > ordinary read(2) from racing with the hole punch and instantiating page > > cache page after hole punching has evicted page cache but before it has > > removed blocks from the inode. This page cache page will be mapping soon > > to be freed block and that can lead to returning stale data to userspace > > or even filesystem corruption. > > > > Fix the problem by protecting reads as well as readahead requests with > > i_mmap_sem. > > > > So ->write_iter() does not take i_mmap_sem right? > and therefore mixed randrw workload is not expected to regress heavily > because of this change? Yes. i_mmap_sem is taken in exclusive mode only for truncate, punch hole, and similar operations removing blocks from file. So reads will now be more serialized with such operations. But not with writes. There may be some regression still visible due to the fact that although readers won't block one another or with writers, they'll still contend on updating the cacheline with i_mmap_sem and that's going to be visible for cache hot readers running from multiple NUMA nodes. > Did you test performance diff? No, not really. But I'll queue up some test to see the difference. > Here [1] I posted results of fio test that did x5 worse in xfs vs. > ext4, but I've seen much worse cases. Honza -- Jan Kara SUSE Labs, CR