From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0FA3B4FECE6; Mon, 31 Aug 2026 13:41:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788183705; cv=none; b=HJEGOIs1r3vUvzfRL9mXhR0AFAEb3ptEsxjAxa7R0yTrxyCCvVpKrNZGiuWnBp/PReKa3wxLfjrH6/siFiJP62o0Mia9WMgzoceUQxs2cyDKecNIchxUB60jt4qWSuANZVsTpicQHe7c3AQ9DHQ6jBcK+JJacZ42ekbaQ5SYIbI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788183705; c=relaxed/simple; bh=J163yWzIWFIddH9EEarC9zCDrPCG7tyyx09ioAg1hTY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c+P0TLpMuWXyy/I14ONWArw53kuEeJIvNyDT0673IZ/PcRJyX7AisHzbWmj+ULBuJML440tHyKW9Y/z2JsGFeTRm0sJSboLEMQyFxht/L4Hsw09SoZLtT6Cwdphf/bJpsNGu2uXguSP1dOcjnMe2je/hKEn7bTpsA2/tSj/Q+rc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=qpLy8U1Y; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="qpLy8U1Y" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6A9D61F00A3E; Mon, 31 Aug 2026 13:41:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1788183704; bh=o7NpynS3F0whS0tZuLhXFQDgzU93Mp82E4hSQyIFq9o=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=qpLy8U1YO1vFGhezJwmWMAOLtw4PtpUOAKiqGB4LEpf1Oto7uiZp0eSrY7WYcIuQG WiROzMMtmJ+rXz9nDftG6eW4lxuXaFTdhNUOcGogvpqwmHQPz5aTLJWDE55epSFnpA fevNDGal/WAWjPPtsEC0x4C3FbZMhIz8nN1lFCX8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zhang Yi , Jan Kara , Theodore Tso , Sasha Levin Subject: [PATCH 7.1 15/76] ext4: write back partial-zeroed edges in WRITE_ZEROES Date: Mon, 31 Aug 2026 15:33:47 +0200 Message-ID: <20260831133359.976936929@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260831133359.185608553@linuxfoundation.org> References: <20260831133359.185608553@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zhang Yi [ Upstream commit d19d239ada9b7c92d086a1f051b7566538ee0089 ] FALLOC_FL_WRITE_ZEROES requires that all blocks in the requested range end up as written extents with zeroed content. For unaligned edges that were partial-zeroed in dirty unwritten or delalloc state, the buffer is left dirty while the underlying extent may not yet be converted to written. As a result, a subsequent SYNC write to this range would still trigger metadata changes, which violates the semantics of WRITE_ZEROES. Fix this by calling filemap_write_and_wait_range() for partial-zeroed edges to flush out the zeroed data and ensure the extent conversion is complete. Fixes: f4265b8d32c4 ("ext4: add FALLOC_FL_WRITE_ZEROES support") Cc: stable@vger.kernel.org Signed-off-by: Zhang Yi Reviewed-by: Jan Kara Link: https://patch.msgid.link/20260714080044.4038124-9-yi.zhang@huaweicloud.com Signed-off-by: Theodore Ts'o Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/ext4/extents.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -4838,7 +4838,15 @@ static long ext4_zero_range(struct file if (IS_ALIGNED(offset | end, blocksize)) return ret; - if (((file->f_flags & O_SYNC) || IS_SYNC(inode)) && partial_zeroed) { + /* + * In FALLOC_FL_WRITE_ZEROES mode, edges that have been partially + * zeroed must be written back to ensure the entire zeroed range + * is converted to the written state. In SYNC mode, writeback is + * also required to persist the zeroed data to disk. + */ + if (partial_zeroed && + ((mode & FALLOC_FL_WRITE_ZEROES) || + (file->f_flags & O_SYNC) || IS_SYNC(inode))) { ret = filemap_write_and_wait_range(inode->i_mapping, offset, end - 1); if (ret)