From: Viacheslav Dubeyko <slava@dubeyko.com>
To: Hengyu Liang <hengyul@cs.unc.edu>
Cc: glaubitz@physik.fu-berlin.de, frank.li@vivo.com,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH] hfsplus: fall back to buffered I/O for direct writes past phys_size
Date: Mon, 02 Nov 2026 14:13:26 -0800 [thread overview]
Message-ID: <fe42fc7c1a7b357d614947b844698c5a0abb78f4.camel@dubeyko.com> (raw)
In-Reply-To: <20261030043252.4163173-1-hengyul@cs.unc.edu>
On Fri, 2026-10-30 at 00:32 -0400, Hengyu Liang wrote:
> hfsplus_direct_IO() passes direct writes to blockdev_direct_IO(),
> which
> does not go through hfsplus_write_begin(). phys_size only grows by
> the
> block size when hfsplus_get_block() allocates a new block. It starts
> at
> i_size when the inode is read, which does not have to be block
> aligned,
> so after a direct write past the end of the file phys_size is smaller
> than i_size.
>
> However, at the last close, hfsplus_file_truncate() sees i_size
> larger
> than phys_size and calls hfsplus_write_begin() at i_size, which
> zeroes
> the file from phys_size up to i_size. As of now, part of the data
> that
> a direct write has just written past the old end of the file is lost,
> and fsck reports no error. Commit 5f63ac80aef2 ("hfsplus: fix issue
> of
> direct writes beyond end-of-file") avoids this only for writes that
> start past the end of the file.
>
> The issue can be reproduced with:
>
> truncate -s 32M hfsplus.img
> mkfs.hfsplus hfsplus.img
> mount -o loop hfsplus.img /mnt
> printf 'A%.0s' $(seq 100) > /mnt/f
> umount /mnt
> mount -o loop hfsplus.img /mnt
> xfs_io -d -c 'pwrite -S 0x42 0 1024' /mnt/f
> umount /mnt
> mount -o loop hfsplus.img /mnt
> od -An -tx1 -j 100 -N 924 /mnt/f
>
> Bytes 100 to 1023 read back as zeros instead of 0x42.
>
> This patch will make the other direct writes that end past phys_size
> fall back to a buffered write, as fat_direct_IO() and
> affs_direct_IO()
> do.
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Cc: stable@vger.kernel.org
> Signed-off-by: Hengyu Liang <hengyul@cs.unc.edu>
> ---
> Slava, you mentioned that you are rebuilding the HFS+ direct I/O path
> [1]. This patch fixes the current code, also for stable, and may
> conflict with that work.
>
> Writes that start past EOF still expand the file first, as in
> 5f63ac80aef2. Only the other writes that end past phys_size fall
> back.
>
> Tested in KVM with KASAN: the reproducer above, and all 805 fstests
> on
> HFS+: 10 failures without the patch, 7 with it (generic/521, 617 and
> 760 now pass), no new failures.
>
> [1]
> https://lore.kernel.org/linux-fsdevel/161fab786f919adb384fbf22dc19f3289bf5f24d.camel@dubeyko.com/
>
> fs/hfsplus/inode.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c
> index aed0866499b2..70c13dcdcd8e 100644
> --- a/fs/hfsplus/inode.c
> +++ b/fs/hfsplus/inode.c
> @@ -169,6 +169,15 @@ static ssize_t hfsplus_direct_IO(struct kiocb
> *iocb, struct iov_iter *iter)
> end_page = end_off >> PAGE_SHIFT;
>
> invalidate_inode_pages2_range(mapping, start_page,
> end_page);
> + } else if (iov_iter_rw(iter) == WRITE &&
> + end > HFSPLUS_I(inode)->phys_size) {
> + /*
> + * blockdev_direct_IO() does not go through -
> >write_begin(),
> + * so it neither zeroes the file from phys_size up
> to the
> + * write nor keeps phys_size in step with i_size.
> Return 0,
> + * so that the write falls back to a buffered write.
> + */
> + return 0;
> }
>
> ret = blockdev_direct_IO(iocb, inode, iter,
> hfsplus_get_block);
>
> base-commit: a804c5742bff224d4cb4d25dd383554d598be32b
I think this modification will be wiped out by my pathset [1] because
hfsplus_direct_IO() will be completely removed. I am going to renew my
work on this pathset now because 7.4-rc1 has been released already. So,
thanks a lot for the patch but I assume that this issue is already
fixed in the patchset. If not, then let's double check it after my
pathset has been finished.
Thanks,
Slava.
[1]
https://lore.kernel.org/linux-fsdevel/20260914233941.2966421-1-slava@dubeyko.com/
prev parent reply other threads:[~2026-11-02 22:13 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-30 4:32 Hengyu Liang
2026-11-02 22:13 ` Viacheslav Dubeyko [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fe42fc7c1a7b357d614947b844698c5a0abb78f4.camel@dubeyko.com \
--to=slava@dubeyko.com \
--cc=frank.li@vivo.com \
--cc=glaubitz@physik.fu-berlin.de \
--cc=hengyul@cs.unc.edu \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®