tests: add UFS synchronous write durability tests
Check that once fsync(2), fdatasync(2), or a write(2) with O_SYNC or
O_DSYNC returns, the new data, the file size and every block pointer
leading to the data are on disk. The cases append a block, fill a hole,
append the first block that needs an indirect block and append below an
existing indirect block. Two more append after another write left a
new direct block unsynced, which with soft updates cuts the size and the
later pointers of an inode written meanwhile. With O_SYNC and O_DSYNC
on soft updates, those also check that the open already made the
unsynced block durable.
Each case runs on UFS without soft updates, with soft updates and with
SU+J.
The file systems live on md(4) and the checks read the inode, the
indirect block and the data block straight from the device with libufs
right after the synchronous call returns. There is no cache in front
of the disk device, so this shows what would survive a crash at that
moment without having to crash anything.
[8 lines not shown]
ufs: make fdatasync(2) and O_DSYNC writes update the inode
ffs_syncvnode() in the DATA_ONLY case and ffs_write() for IO_DATASYNC
decide whether the inode has to be written by testing IN_SIZEMOD and
IN_IBLKDATA against ip->i_flags, the chflags(2) word, instead of the
in-core state ip->i_flag. IN_SIZEMOD and IN_IBLKDATA alias UF_READONLY
and UF_ARCHIVE, so for ordinary files the test was always false: after
an fdatasync() or an O_DSYNC write that extended a file or filled a
hole, the data blocks were on disk but the inode size and block pointers
were not, and a crash before the syncer got to the inode lost the
"synced" data. Files with uarchive or urdonly set got a synchronous
inode write on every call instead.
journal_mount() has the same mixup and sets IN_MODIFIED in i_flags,
which leaves UF_OPAQUE set on the in-core .sujournal inode. The
synchronous ffs_update() that follows writes the inode regardless, so
only the stray flag is fixed here.
Fixes: 7428630b757 ("UFS: write inode block for fdatasync(2) if pointers in inode where allocated")
[11 lines not shown]
stress2: add a test for forced unmount racing mkdir at UFS_LINK_MAX
On a soft updates file system, keep a directory at UFS_LINK_MAX with
workers removing and recreating subdirectories in it, so that mkdir(2)
keeps going through ufs_sync_nlink(), and force-unmount, check and
remount the file system in a loop. The workers work relative to the
directory: a lookup through the mount point would wait for the unmount
on the covered vnode lock and never race with it. Before the fix, the
first forced unmount deadlocked with mkdir(2) sleeping in vfs_busy().
With dtrace=1, count the vfs_busy() calls made during an unmount by
caller, and the mkdir(2) calls that synced and restarted with ERELOOKUP
during an unmount, which shows that the race was hit.
Sponsored by: Sippy Software, Inc.
Reviewed by: pho
Tested by: pho
Differential Revision: https://reviews.freebsd.org/D60204
MFC after: 1 month
[2 lines not shown]
ufs: flush soft updates dependencies for O_SYNC and O_DSYNC writes
For a synchronous write, ffs_write() writes the data buffers with
bwrite() and then the inode with ffs_update(vp, 1). With soft updates,
a new block pointer can only reach the disk after the dependencies of
the block, such as the cylinder group map that allocates it, are
written. Until then initiate_write_inodeblock_ufs[12]() and
initiate_write_indirdep() roll the pointer, and for an extending write
the size, back in the buffer being written. Nothing in the write path
flushes those dependencies, so the inode went out with the old size and
pointers, ffs_update() cleared IN_SIZEMOD and IN_IBLKDATA, and a crash
before the syncer rewrote the inode lost data that O_SYNC or O_DSYNC
promised was on stable storage. The same held for a new block below an
indirect block, which ffs_balloc() writes synchronously but with the
pointer rolled back.
When soft updates are enabled and the write allocated blocks, finish it
with ffs_syncvnode(), as fsync(2) and fdatasync(2) do: it flushes the
dependencies, rewrites the rolled back indirect blocks and writes the
[32 lines not shown]
ufs: make fdatasync(2) write dirty indirect blocks
A data-only ffs_syncvnode() skips dirty indirect blocks on file systems
without soft updates, and with soft updates stops making passes once
only indirect blocks are left dirty. Indirect blocks only get dirty
when the block pointers in them change, and those pointers are what
makes a newly allocated block reachable. So when fdatasync() follows
a write that extended the file or filled a hole past the direct blocks,
the data and the inode size reached the disk but the pointer to the new
block did not, and a crash lost the "synced" data. With soft updates
the indirect block was usually written once, with the new pointer
rolled back, and never rewritten.
POSIX requires fdatasync() to write the metadata needed to retrieve the
data, which 52488b51489 already acknowledged for the inode, so treat
dirty indirect blocks the same way for a data-only sync as for a full
one. This restores the loop to what it was before 2f514f92cf0. Plain
overwrites, the case data-only sync is meant to speed up, do not dirty
indirect blocks and still write neither them nor the inode.
[10 lines not shown]
ufs: do not let a rolled back inode write end a data-only sync
With soft updates, ffs_syncvnode() writes the inode between its passes
while buffers are still dirty. That write can go out with new block
pointers rolled back, for instance a new indirect block whose contents
are only written in a later pass, yet ffs_update() clears IN_SIZEMOD
and IN_IBLKDATA because the write was synchronous. A data-only sync
then decides at the end that the inode need not be written, and
fdatasync(2) or an O_DSYNC write that allocated the first indirect
block returned with the on-disk inode not pointing to it.
Note on entry whether a data-only sync has to write the inode, and base
the final write, done once all dependencies are flushed, on that alone:
nothing else can set IN_SIZEMOD or IN_IBLKDATA meanwhile, as the vnode
is locked. A full sync always writes the inode last and was not
affected.
Sponsored by: Sippy Software, Inc.
Reviewed by: kib
[5 lines not shown]
stress2: Fix script bugs in gnop6.sh, gnop7.sh and fdatasync*.sh
gnop6.sh recorded the checkfs result with "checkfs ... || s=1 && s=0",
which the shell parses as "(checkfs || s=1) && s=0", so the test passed
even when the file system check failed.
gnop7.sh only sets s when unmount or fsck_ffs fails and ends with
"exit $s". On a clean run s is unset, and the script exits with the
status of the preceding "[ $notloaded ] && gnop unload", which is 1
whenever geom_nop was already loaded, for instance by an earlier test.
fdatasync.sh and fdatasync2.sh ran "df -i $RUNDIR" before creating the
directory. With a RUNDIR that does not exist yet, df failed, the test
printed "[: -lt: unexpected operator" and the free inode check was
skipped.
Reviewed by: pho
Differential Revision: https://reviews.freebsd.org/D60136
Sponsored by: Sippy Software, Inc.
[3 lines not shown]
ufs: report a mismatched ".." in ufs_dirrewrite()
When ufs_rename() moves a directory to a new parent and ufs_dirrewrite()
fails to rewrite its ".." entry, it reports "bad dir ... rename: missing
.. entry" whatever the error. ufs_dirrewrite() never finds a missing
"..", though: it fails with EIDRM when the ".." entry names another inode
than the expected one, and otherwise only when the directory block cannot
be read or written. The latter happens for every directory rename in
flight when the device goes away under a forcibly unmounted file system,
and the log then fills with reports of directories that are intact on
disk.
Report the EIDRM case with ufs_dirbad() in ufs_dirrewrite() itself, so
that all of its callers get the same diagnostic, and drop the report
from ufs_rename(). Errors from the lower layers are not reported, as
usual for an I/O initiator.
Reviewed by: kib
MFC after: 2 weeks
[3 lines not shown]
ufs: do not busy or reference the mount in ufs_sync_nlink()
With soft updates, mkdir(2), link(2) and rename(2) into a directory
whose i_nlink is at UFS_LINK_MAX while i_effnlink is below it call
ufs_sync_nlink1() to sync the file system and restart. It busied the
mount with vfs_busy(mp, 0), which sleeps for as long as an unmount is in
progress. The caller is still between vn_start_write() and
vn_finished_write() there, and the unmount, once it has set
MNTK_UNMOUNT, goes on to suspend writes in VFS_UNMOUNT() and waits in
vfs_write_suspend() for that write to end. Neither could make progress,
and every later vfs_busy() of the mount, such as from getfsstat(2) or a
lookup crossing the mount point, hung behind them.
The window is wide: after setting MNTK_UNMOUNT, the unmount waits for
the busy references to drain, which includes another thread already
syncing in ufs_sync_nlink1(), and for vfs_periodic(). A forced unmount
of a file system with a directory at the link limit under mkdir/rmdir
load hits it within seconds.
[21 lines not shown]
stress2: add a reproducer for the flush_newblk_dep() "Bad newblk" panic
flush_pagedep_deps() drops the soft updates lock to obtain the vnode of
a new directory. If its MKDIR_BODY dependency completes in that window,
the lookup of the directory's first block in flush_newblk_dep() can find
a stale allocindir left behind by a previous owner of the same block,
relocated by ffs_reallocblks() and freed, and panic.
The test grows interleaved files past UFS_NDADDR to keep clusters being
relocated, while other workers create subdirectories in a parent with
IN_ENDOFF set, so that ffs_vput_pair() syncs it, and fsync() them to
complete the mkdir dependencies. The file system layout and the way
the writers put their blocks on disk are arranged so that a new
directory takes over a freed block whose dependency is still retained;
the details are in the script. With dtrace=1, the test also counts how
often this precondition is met, which works on a fixed kernel too.
PR: 297976
Reviewed by: kib, pho
[5 lines not shown]
ffs: revalidate mkdir dependencies after vnode lookup
flush_pagedep_deps() drops the soft updates lock while obtaining the
vnode of a newly created directory with get_parent_vp(). The
MKDIR_BODY dependency may complete during this interval, invalidating
the diradd selected before the lock was dropped.
Once the directory's allocdirect is retired, the lookup of its first
block by block number in flush_newblk_dep() can find an older
dependency for a previous use of the same physical block. The newblk
hash is not unique by block number: when ffs_reallocblks() relocates a
cluster, the completed allocindirs of the old blocks stay on the
indirdep's ir_completehd until the indirect block pointer in the inode
is written, while the old blocks are already free and may be allocated
to a new directory. flush_newblk_dep() then finds a D_ALLOCINDIR where
it expects a D_ALLOCDIRECT and panics with "flush_newblk_dep: Bad
newblk".
Retain the vnode returned by get_parent_vp(), reacquire the soft
[35 lines not shown]
crypto/openssl: update to 3.5.10
This change updates the OpenSSL source to 3.5.10. This is a security
bugfix release which addresses several issues--Medium being the highest
severity issue. Users are strongly encouraged to update to this
release.
Please see the original vendor commit for more details.
Merge commit '7ee6425d9f3b6d5fba45b5b525953e4d0b662eff'
libthr: Skip unwinding for thread normal returrn
For a thread returns normally, there is no needeed to unwind the stack.
We split the exit code with a common implementation and pass unwind
to check whether we need to unwind the stack or not.
Reviewed by: kib
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D62265
ufshci: remove the unused phase field
The hardware queue kept a phase field for MCQ mode. A UFS completion
queue has no phase bit, and MCQ completion handling will read the CQ
tail pointer register instead. Nothing reads the field.
Remove it.
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D62313
Sponsored by: Samsung Electronics
ufshci: take the recovery lock when an abort fails
The watchdog runs the recovery steps with the queue's recovery lock
held. A failed Abort Task ran the same steps from its completion
callback without the lock, so it could race the watchdog over the
queue's recovery state.
Take the recovery lock around the recovery steps in the abort
completion, and assert it in the recovery function.
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D62312
Sponsored by: Samsung Electronics
ufshci: use one interrupt vector on PCI
The PCI attach code came from nvme(4) and asks for one MSI-X or MSI
vector per queue. It installs an interrupt handler only when it ends
up with a single vector, though. With the default settings it asks
for two vectors, so a controller that grants two gets no handler at
all. The controller attaches, but its interrupts go unhandled and a
request completes only when the watchdog finds it past its timeout.
The driver has a single interrupt handler, which scans every queue.
Ask for one vector, trying MSI-X, then MSI, then INTx, and install
that handler in every case.
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D62311
Sponsored by: Samsung Electronics
ufshci: give CAM every slot that I/O can use
Commit c41be266147f ("ufshci: keep a slot for admin requests") left
one slot out of the CAM openings besides the admin slot, because
letting CAM fill every I/O slot cut the throughput. The cause was the
completion path, which called back into CAM before it freed the slot.
The completion path now frees the slot first, so the spare slot only
sits idle.
Give CAM every slot that I/O can use again. On QEMU with 4k random
I/O from 4 jobs at depth 16, the throughput stayed the same and no
request came back with EBUSY. A request sent outside CAM, such as a
passthrough command, can still make CAM find the queue full. CAM
requeues its request then, so log a full queue only for the task
management queue, where it means that aborts piled up.
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D62309
Sponsored by: Samsung Electronics
ufshci: free the slot before the completion callback
The completion path called the request's callback before it freed the
slot. CAM sends its next request from inside that callback, so that
request could find every slot taken and bounce back with EBUSY until
the slot was freed. The spare slot left out of the CAM openings hid
this. With CAM allowed to fill every I/O slot, the bouncing cut the
throughput to a fifth on QEMU.
Free the slot first, and call the callback after dropping the queue
lock. The callback uses only the copied completion and its own
argument.
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D62308
Sponsored by: Samsung Electronics
powerpc/altivec: initialize vrsave to all regs active
libunwind uses vrsave to determine which registers to restore, but
vrsave is never actually updated in modern OSs including FreeBSD. This
leads to libunwind not restoring any altivec registers, resulting in
strange behaviors.
With this change gdb can now print a backtrace without crashing.
Patch originally provided by pkubaj.
MFC after: 3 days
bxe: Always return uint64_t from bxe_hilo
The interface counters are always uint64_t, so truncating to a signed
long only results in weird sign-extension errors on 32-bit platforms.
Reported by: llm-postcr
Fixes: df3601781d3e ("- Use if_inc_counter() to increment...")
imgact_binmisc: fix validation of new entries
The magic offset and size are both uint32_t, so their sum may wrap and
pass the IBE_MATCH_MAX check with an offset far outside of the image
header. Any exec that's checked against such an entry will then read
well beyond the header.
The name and interpreter length checks also read the byte following the
string before checking its index, so either one may fill its field
without a terminating NUL as long as the next field starts with one. A
full-length interpreter then overflows the normalization buffer in
imgact_binmisc_populate_interp() by a byte. An unterminated name is
instead truncated, which lets the same name be added more than once
since the duplicate check compares against the truncated copy.
Avoid the wrap and require both strings to be terminated within their
fields, and add regression tests for each. Note that these are only
reachable by root on the host.
[2 lines not shown]
imgact_binmisc: fix matching of magic bytes >= 0x80 without a mask
The image header is a char *, so on platforms with a signed char each
header byte is sign-extended before it's compared against the unsigned
magic. Any magic byte >= 0x80 then fails to match unless IBF_USE_MASK
is set, as the mask happens to strip the sign extension.
Compare the header as uint8_t instead, and add a regression test.
Reviewed by: imp, kib, markj
Differential Revision: https://reviews.freebsd.org/D62130
binmiscctl.8: restructure the 'add' definition, note short options
The previous version just used long prose to describe the different
options available, which makes it hard to work in the short options that
are defined. It's debatably also a less effective way to describe this.
Use a more standard option list and describe each option individually.
While we're here, fix the spelling of 'indent' later on.
Note that the descriptions are largely unchanged.
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D62150
imgact_binmisc: enforce IBE_MAX_ENTRIES under the list lock
The sysctl handler checked the entry count without the list lock, but
the handlers are MPSAFE so concurrent adds may push the count past
IBE_MAX_ENTRIES. Once past, the == check never matches again and the
limit stops being enforced at all.
Add a check under the lock in imgact_binmisc_add_entry() and use >=,
drop the stale comment claiming that sysctl serializes us, and add a
test that fills the table. The test can't reliably hit the race, but
it at least covers the limit.
Reviewed by: kib, markj
Differential Revision: https://reviews.freebsd.org/D62129