[DragonFlyBSD - Bug #3461] msdosfs: uiomovebp() makes sibling clusters read as zeros when the cluster size is smaller than a page

sigttou bugtracker-admin at leaf.dragonflybsd.org
Sat Nov 7 08:38:40 PST 2026


Issue #3461 has been updated by sigttou.

File 0001-msdosfs-bounce-reads-of-clusters-smaller-than-a-page.patch added
File 0002-msdosfs-stage-write-data-before-raising-the-file-siz.patch added
File 0003-ntfs-bounce-reads-of-clusters-smaller-than-a-page.patch added

Updated patches, following the discussion: they replace the series attached
earlier and need no new kernel API.

@uiomovebp()@ zero-fills and validates the whole last VM page of a held
buffer when that page is not fully valid.  That is right for UFS tail
fragments, where the rest of the page is past EOF.  With msdosfs or ntfs
clusters smaller than a page the rest of the page holds other clusters of
the same file that were simply not read yet, so later reads of those
clusters return the fabricated zeros from the buffer cache without I/O.

For clusters smaller than @PAGE_SIZE@, @msdosfs_read()@, @msdosfs_write()@ and
@ntfs_read()@ now copy through a kernel buffer instead of calling
@uiomovebp()@, so no user copy happens while a cluster buffer is held.
Page-in and page-out (@UIO_NOCOPY@) copy nothing and use plain @uiomove()@.
Clusters of a page or more and directory reads are unchanged, and
@uiomovebp()@ itself is untouched.

0002 msdosfs_write: the user data is staged before the file size is raised,
and the uio is rewound when the staging copy fails.

0003 ntfs_read.  NTFS only matters for volumes made with clusters smaller
than the default 4 KiB.


----------------------------------------
Bug #3461: msdosfs: uiomovebp() makes sibling clusters read as zeros when the cluster size is smaller than a page
http://bugs.dragonflybsd.org/issues/3461#change-14947

* Author: sigttou
* Status: New
* Priority: Normal
* Category: Driver
* Target version: 6.6
* Start date: 2026-11-04
----------------------------------------
@uiomovebp()@ (@sys/kern/kern_subr.c@) fixes up the last VM page of a buffer when it is not fully valid: @vm_page_zero_invalid(m, TRUE)@ zero-fills every invalid @DEV_BSIZE@ chunk and marks the whole page valid. With clusters smaller than a page (FAT16 with 512-byte clusters: 8 clusters per page) the first cluster read of a page therefore marks the other chunks of that page valid with zeros. Reads of the sibling clusters then find the VM backed buffer valid and are served the zeros from the cache without any I/O, although the data on disk is correct. Writes through the same path are affected the same way.

Symptom: single all-zero 512-byte clusters inside files after umount/mount, stuck until the page is evicted. Reproduced on real hardware (USB stick on xHCI, FAT16, 512-byte clusters).

Fix: for clusters smaller than a page, msdosfs no longer uses @uiomovebp()@ for the user copy and never touches user memory while a buffer is held (a fault into an mmap of the same file would recurse into the pager on the held buffer, which is the reason the fix-up exists).

read: copy the cluster out of the buffer, @bqrelse()@, then @uiomove()@ from the bounce buffer.

write: @uiomove()@ into a bounce buffer before @getblk()@/@bread()@, then @bcopy()@ into the buffer. On the @NOOFFSET@ and bread failure paths the uio offset and resid are rewound and the bounce is freed.

Not covered: @UIO_NOCOPY@ writes still use @uiomovebp()@. other callers of @uiomovebp()@ are untouched, a UFS fragment case with the same pattern is a guess, not tested yet. The generic alternative (what the TODO in the uiomovebp() header comment sketches: copy through a system buffer without holding the buffer or vnode lock) would fix all callers but is a larger change.


---Files--------------------------------
0001-msdosfs-bounce-reads-of-clusters-smaller-than-a-page.patch (2.24 KB)
0002-msdosfs-stage-write-data-before-raising-the-file-siz.patch (5.07 KB)
0003-ntfs-bounce-reads-of-clusters-smaller-than-a-page.patch (2.23 KB)


-- 
You have received this notification because you have either subscribed to it, or are involved in it.
To change your notification preferences, please click here: http://bugs.dragonflybsd.org/my/account


More information about the Bugs mailing list