Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp17925388ybl; Thu, 2 Jan 2020 14:56:48 -0800 (PST) X-Google-Smtp-Source: APXvYqyasjbSplHcUXxHmSLrSRLkZv0BxvDQ1b0H7N+l8qgxKRsSxvuce1dQHfAcNo8l/5Z4tIHa X-Received: by 2002:a05:6830:151a:: with SMTP id k26mr78245314otp.74.1578005807956; Thu, 02 Jan 2020 14:56:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578005807; cv=none; d=google.com; s=arc-20160816; b=gLH+K8/yIYexa5jfyM3ELgyZNu5J6/qsP7u1xUsyG/aaYAEXNluwih7tg5yUej0D7/ ixkxlIrVJWeNjXvfcap/+w1z2OoBisFhFa2Xg8Ob/x4Qw9HOObsaKdK+kecywVNr6ScU voPXiuoar+NXdrn5P41cs944WUpayecZplPKjb9Q9q402gxnCyrOS+SIuOAJkSodASvQ bV8jz1pLXjkzsKxjQVtdxnDQUFJw9Lkr0ICLLVg0qxYuWMMlSZQnwukney5EA2v1zWYT BHFhf/P/smuuNEdx9Yuq8ye4x8z7FtAU/T1NZOBAZ5jrp6tArQfTZ8MHolZdGu+OtpbY 7IyQ== 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=gKKjPNoy/NeLuPwfZer6md43XM/CNk0WIf+nwgUhvYA=; b=nPyUYIX8/PEDbyiRL/buqVKKzQTXQXGaN5WRkPpA57UwYfa4I6QPDwIgQyslQLzrHH 9LADzubbcTT+DEBeG0/6He45fWSbZNnhbY9KKmwHCRDCdhyV/P4QGqW8iEi7a5LUusn/ BjtA/9qfikrmqTyQyxTXghR5OiJkNYLi1Cpcphf1uhoyiYBzLhFzGGJq0irQ5CcoCnUH /Ccmxasb60gjx/DelmrLi4M2noCO8aTwXI9/ec2rKD5ypGkEs6XUF4a5AA4psLNcBWv9 MNEDAkKQudOvb+U6Q6C5H9KHSet1+7OXD/pORCVVM8FwLScq0hyXI+Y2Pl2zyq/+nbjB IZvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NpYkW6Gt; 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 f187si27669777oia.218.2020.01.02.14.56.35; Thu, 02 Jan 2020 14:56:47 -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=NpYkW6Gt; 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 S1728820AbgABWUe (ORCPT + 99 others); Thu, 2 Jan 2020 17:20:34 -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: 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 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