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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7E8EC4167B for ; Wed, 6 Dec 2023 09:02:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377143AbjLFJCp (ORCPT ); Wed, 6 Dec 2023 04:02:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377108AbjLFJCo (ORCPT ); Wed, 6 Dec 2023 04:02:44 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C0BBFA; Wed, 6 Dec 2023 01:02:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=ESwEwJpMWsb1q1d00f+KoCLpSfEhMR+fcQ8QnG0nZoY=; b=zdO2H/GFM5zuA/L5PBl09vu4SX Nj1NPCIO6UpL1CS1ZiK7pZAgkEAouwfOHdWjaB/UIFvNCMcmrJzg3APPhDLPBs5EBJHDMwWrzKYQb YXmIEu+cyobQvPWugKFg1wrytc6fzHyAchYm/YclQc5hNhlB1ejYW+R8HC3rcO0QbfJf4IupBinJb o+Gy9bIuZuAG6iUsl02KdeBjw/2gDvuFrRBxpaGBlugOAhNAcWn79lMAgdFOOf4MKaZvaz1hA7gqT RXkliwsSHWURz6Sp/+N0ZdxyHmni68VHPgNY1K1gj2ixWQQJ7CDTkUboZgKMJM5GlVA+YZxcOIEjZ I8v77+EA==; Received: from hch by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1rAnnn-009VGi-1H; Wed, 06 Dec 2023 09:02:43 +0000 Date: Wed, 6 Dec 2023 01:02:43 -0800 From: Christoph Hellwig To: Dave Chinner Cc: Baokun Li , Jan Kara , linux-mm@kvack.org, linux-ext4@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, willy@infradead.org, akpm@linux-foundation.org, ritesh.list@gmail.com, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, yukuai3@huawei.com Subject: Re: [PATCH -RFC 0/2] mm/ext4: avoid data corruption when extending DIO write race with buffered read Message-ID: References: <20231202091432.8349-1-libaokun1@huawei.com> <20231204121120.mpxntey47rluhcfi@quack3> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Dec 06, 2023 at 07:35:35PM +1100, Dave Chinner wrote: > Mixing overlapping buffered read with direct writes - especially partial block > extending DIO writes - is a recipe for data corruption. It's not a > matter of if, it's a matter of when. > > Fundamentally, when you have overlapping write IO involving DIO, the > result of the overlapping IOs is undefined. One cannot control > submission order, the order that the overlapping IO hit the > media, or completion ordering that might clear flags like unwritten > extents. The only guarantee that we give in this case is that we > won't expose stale data from the disk to the user read. Btw, one thing we could do to kill these races forever is to track if there are any buffered openers for an inode and just fall back to buffered I/O for that case. With that and and inode_dio_wait for when opening for buffered I/O we'd avoid the races an various crazy workarounds entirely. nfs and ocfs2 do (or did, I haven't checked for a while) something like that.