Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp17893727ybl; Thu, 2 Jan 2020 14:15:01 -0800 (PST) X-Google-Smtp-Source: APXvYqwlFzhnPabvv24HbGOvc8CJKVNz1mhSIL2/mpQHfCzb5KpY+sm3vgiAMwY0AZTd3qAxXah6 X-Received: by 2002:aca:3182:: with SMTP id x124mr3230395oix.170.1578003301436; Thu, 02 Jan 2020 14:15:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578003301; cv=none; d=google.com; s=arc-20160816; b=d5+6kvemSrSfX4KERVZPxmqlSo+Lp/vGLS8TffgIXiUS2L/AdRuqqjquTMtomm0Et3 uXAck6G9/iKY/nFSLYVVrkyUZou7YpKQTbwXbUvBKNwrWfSk8u1A742apAzekd8HRvTw i6sWUXZFvfHgSzKMf0GnocKZHUBKsrEBIKwcGeyPU/H6ZJTHpuMKFdnpFO9DJBTSEuw1 0Pab+4qDRAvIBdGhQpK4SXulGj25SSo+fuxR0bVgSfqlCyFmvaJYjKwYKdBhHNeL2lry 5C3MXNDINdOCKsX91CrkBF6iGDC+6kTeXXudlny6MX7+v6/Z1APSiiFKwexhRvCtqLBx oYPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mfjqe0i0cr9gpQHxChws+pIX4XR1ipJ9h/4QJxaNRqo=; b=jxVOiNbTSY/cCkJDoegMfYe8MgahARqbW0wporn09cWYkVPxHHO13iJUvP0p4xLzo0 x0Hd4ftloTQJPwyJvimV1y30f/Z68n7fYnjn5QQaytyo69H2P3UTXo5CJbYV+1CkJ6Me hFUimFncHJnt6mcShGYm9p6Z1ZPNs/6X02xPT0ACcDDVQz9YrBb6RgcdPJwITkbtbINo XkvlIjGmNmzlx4EIAmKXFL5mD5kSJ5uIH7QBqGH0PYJpA49N05rN4KuAT1OL6FIH0grN EvGilKVMSqKnAyXWdXoZRZgrjLwhCfCWzOs4tK1GnsuFJgJcUkvAqCl6HE56zISeChPy T4EA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uFxL10Wq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j71si26997283oib.213.2020.01.02.14.14.50; Thu, 02 Jan 2020 14:15:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uFxL10Wq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727516AbgABWMi (ORCPT + 99 others); Thu, 2 Jan 2020 17:12:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:51848 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727506AbgABWMg (ORCPT ); Thu, 2 Jan 2020 17:12:36 -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 4CBB222314; Thu, 2 Jan 2020 22:12:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578003155; bh=fqZruyXarBHH1x9rF6kKDbJK5w2LbZ8EyRy8jEHQrps=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uFxL10Wq+OOOk9O8F9cjyqEph84+T+Ym9JGC4WX2Y4KXoBT0o8Eev/3iioVsur7yM hszhPzprnW4AIwJEyVHfm1/0VQdj6ql3fcpFKXfAfJv6egWIFyUYN/sQHXHSLOEPWs 7VqUnYJ51SGj9S1tIFjQEt0UkVBbolnMJ4FbrFB4= 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 5.4 043/191] ext4: iomap that extends beyond EOF should be marked dirty Date: Thu, 2 Jan 2020 23:05:25 +0100 Message-Id: <20200102215834.545756785@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102215829.911231638@linuxfoundation.org> References: <20200102215829.911231638@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 b10aa115eade..8bba6cd5e870 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3532,8 +3532,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