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=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 78DC2C3276C for ; Thu, 2 Jan 2020 22:54:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 49FB3222C3 for ; Thu, 2 Jan 2020 22:54:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578005671; bh=zOMB2vb0NBpO4gPvywUOIcaE5uvtxmH8H97oowLidJ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=1RZgNT1q6AHuBE3s33pi1co+pC2GV+zuy4JY+t9DOCk1ifW/s18nWdXYQUsQDDBMQ lgDZX386a/GzWFhgS7cB1xoszjTWpIUcag6wlWIm1C5qJPepT6YRmdZhGLNI+MNOFM ia0xLPwftpvAhGV0H4ov4yK3OeUNgZHOoOFMHLU4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728291AbgABWUd (ORCPT ); Thu, 2 Jan 2020 17:20:33 -0500 Received: from mail.kernel.org ([198.145.29.99]:38218 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728609AbgABWUc (ORCPT ); Thu, 2 Jan 2020 17:20:32 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DC72421D7D; Thu, 2 Jan 2020 22:20:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578003632; bh=zOMB2vb0NBpO4gPvywUOIcaE5uvtxmH8H97oowLidJ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NpYkW6GtjLwEYaAMVcNfQLdfjfcucCX/OdD3Ncgyaitabf7s6uMjBlqBnGkmIVDyH wzIdIK9J9T7d/rROB2QjC1Hc3SAn1PwROX7yAgWSHtFs004sUbKZJHMeA6H5pPkBOt YMM/q1trt2HpLDMqPEExlmuYpr9DjJIyCQ/hGhNU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Matthew Bobrowski , Jan Kara , Ritesh Harjani , Theodore Tso , Sasha Levin Subject: [PATCH 4.19 023/114] ext4: iomap that extends beyond EOF should be marked dirty Date: Thu, 2 Jan 2020 23:06:35 +0100 Message-Id: <20200102220031.481358640@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102220029.183913184@linuxfoundation.org> References: <20200102220029.183913184@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Matthew Bobrowski [ Upstream commit 2e9b51d78229d5145725a481bb5464ebc0a3f9b2 ] This patch addresses what Dave Chinner had discovered and fixed within commit: 7684e2c4384d. This changes does not have any user visible impact for ext4 as none of the current users of ext4_iomap_begin() that extend files depend on IOMAP_F_DIRTY. When doing a direct IO that spans the current EOF, and there are written blocks beyond EOF that extend beyond the current write, the only metadata update that needs to be done is a file size extension. However, we don't mark such iomaps as IOMAP_F_DIRTY to indicate that there is IO completion metadata updates required, and hence we may fail to correctly sync file size extensions made in IO completion when O_DSYNC writes are being used and the hardware supports FUA. Hence when setting IOMAP_F_DIRTY, we need to also take into account whether the iomap spans the current EOF. If it does, then we need to mark it dirty so that IO completion will call generic_write_sync() to flush the inode size update to stable storage correctly. Signed-off-by: Matthew Bobrowski Reviewed-by: Jan Kara Reviewed-by: Ritesh Harjani Link: https://lore.kernel.org/r/8b43ee9ee94bee5328da56ba0909b7d2229ef150.1572949325.git.mbobrowski@mbobrowski.org Signed-off-by: Theodore Ts'o Signed-off-by: Sasha Levin --- fs/ext4/inode.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 00d0c4b8fa30..950e3dcff7b0 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3544,8 +3544,14 @@ retry: return ret; } + /* + * Writes that span EOF might trigger an I/O size update on completion, + * so consider them to be dirty for the purposes of O_DSYNC, even if + * there is no other metadata changes being made or are pending here. + */ iomap->flags = 0; - if (ext4_inode_datasync_dirty(inode)) + if (ext4_inode_datasync_dirty(inode) || + offset + length > i_size_read(inode)) iomap->flags |= IOMAP_F_DIRTY; iomap->bdev = inode->i_sb->s_bdev; iomap->dax_dev = sbi->s_daxdev; -- 2.20.1