mount_fusefs(8): accept and ignore the "nempty" option
ntfs-3g mounts with "nonempty" by default and libfuse passes it to
mount_fusefs. getmntopts() treats the leading "no" as negation and
looks up "nempty", which is not in the option table, so the mount fails
with "-o nempty: option not supported". Add the ignore entry that
FreeBSD's mount_fusefs(8) has.
Bug: https://bugs.dragonflybsd.org/issues/3459
fuse: fix a lost wakeup in the I/O helper
fuse_io_thread() slept first and drained the queue only after waking.
After draining it released helper_spin and called tsleep()
unconditionally. fuse_vop_strategy() queues a bio under helper_spin,
drops the lock and then calls wakeup(), so a wakeup that arrived
between that final spin_unlock() and the interlock taken inside
tsleep() was lost. The helper then slept forever with the bio queued
and the caller hung in biowait().
Hold helper_spin while checking the queue and use ssleep(), which
takes the sleep-queue interlock and drops the spinlock in one step,
so the wakeup cannot be lost.
Bug: https://bugs.dragonflybsd.org/issues/3459
fuse: honor an explicit ftruncate() size
An earlier write extension sets fnp->sizeoverride, which made
fuse_set_attr() keep the old size and ignore an explicit
ftruncate(). Clear the override for FATTR_SIZE setattrs.
Bug: https://bugs.dragonflybsd.org/issues/3459
fuse: zero-fill the tail of a short read
A short FUSE_READ reply copied only the returned bytes into the 4 KiB
BIO buffer, leaving the rest stale, so an mmap read of an unwritten
hole returned old data. Clamp the copy to b_bcount and zero the
remainder.
Bug: https://bugs.dragonflybsd.org/issues/3459
fuse: treat a zero file handle as a valid handle
ntfs-3g returns file handle 0 for regular files. The driver used
fh == 0 as its "no handle" state, so it reopened the file on every
open and skipped FUSE_RELEASE and FUSE_FSYNC. The userspace daemon
then still considered the file open and renamed unlinked files to
.fuse_hidden*.
Add an explicit fh_valid flag to struct fuse_node and use it instead
of the fh value.
Bug: https://bugs.dragonflybsd.org/issues/3459
u4b: Do not assume page-aligned busdma segments in the DMA page table
usb_pc_common_mem_cb() walked the busdma segment list assuming every
segment after the first begins on a page boundary (rem reset to 0 and
the next entry always taken from the new segment's base address).
busdma splits segments at physical page boundaries, at physical
discontinuities and at maxsegsz; the first two begin a new segment on
a page boundary, but when a buffer starts mid-page and consecutive
pages are physically adjacent, the maxsegsz split ends a segment in
the middle of a page and its continuation begins mid-page. When that
happened, the walk recorded the continuation's frame a second time
under the next page index, shifting every later entry by one page.
usbd_get_page() then handed the host controller wrong bus addresses
for all pages after the duplicated entry, so multi-page USB storage
reads returned the content of the following page and left the tail of
the transfer with unrelated memory. This needs a buffer whose first
byte is not page aligned together with such a mid-page split, which is
why 1 KiB and 2 KiB block filesystems on USB storage were affected
[17 lines not shown]
kernel: Skip oversized loader environment entries
kenv_init() copies every loader environment string into the dynamic
kenv without a length limit, and kgetenv() later copies the value
into a 258-byte stack buffer with strcpy(). A long value overflows
the buffer when it is read, for example by an unprivileged kenv(1)
call, and causes a fatal trap.
Skip entries longer than KENV_MNAMELEN + KENV_MVALLEN + 2 bytes and
print a warning, like FreeBSD's init_dynamic_kenv() does. An entry
(name, '=' and value) of up to 257 characters keeps working.
Bug: https://bugs.dragonflybsd.org/issues/3466
cc120: Include all tree codes in all-tree.def to fix LTO compatibility
Before this fix, the base GCC 12 and the lang/gcc12 package couldn't
link each other's LTO objects. This was caused by the enumeration
mismatch of LTO tags, because the two compilers had different
all-tree.def: the base GCC 12 removed ada-tree.def, d-tree.def and
objc-tree.def because those languages are disabled.
Fix this LTO compatibility issue by adding back the removed tree codes,
and thus generate the same all-tree.def as the GCC's own configure does.
Bug: https://bugs.dragonflybsd.org/issues/3470
nvmm: Improve CPUID handling
- If the emulator wants to exit on a leaf, don't overwrite the
registers.
- On AMD, out-of-range leaves return zero, not the highest supported
leaf, so return zero.
Obtained-from: NVMM Reference Implementation
nvmm: Change the meaning of TPR_CHANGED
Currently we return TPR_CHANGED if the guest changes its TPR. But the only
change the emulator is interested in is if the TPR is lowered, as that
unblocks certain classes of interrupts; the emulator doesn't care if the
TPR is increased.
Change the behavior to return TPR_CHANGED only if the TPR is lowered.
Then, implement an optimization on SVM: instead of intercepting all
writes to CR8 and returning to userland, use a TPR trap to get VMEXITs
only when the guest lowers its TPR.
This effectively eliminates VMEXITs on TPR increases, which significantly
improves the performance of Windows guests (because they frequently
increase and decrease the TPR).
Update the libnvmm.3 man page and the test cases as well.
Obtained-from: NVMM Reference Implementation
libnvmm: Fix -Winline warnings (2)
Rework the fix by by removing the `inline` keyword on `x86_gva_to_gpa()`,
because it has grown much bigger than the initial version.
Obtained-from: NVMM Reference Implementation
nvmm: Use dynamic cr4_valid/efer_valid values in VMX
Implement the same feature like SVM. Also filter out EFER in setstate().
Obtained-from: NVMM Reference Implementation
nvmm: Fix the handling of CR0.NE in VMX
CR0.NE must be forced to 1, so add it to CR0_STATIC_MASK. Otherwise
a #GP can be raised in the guest.
Bug: https://bugs.dragonflybsd.org/issues/3452
nvmm: Fix the filtering on event injections
The code wants to forbid the INT3/INTO vectors. These are vectors
3/4, not 3/0. Fix this.
Obtained-from: NVMM Reference Implementation
nvmm: Harmonize event reinjection
Never reinject a SW event, just let the guest re-execute the instruction
that caused it. Apply the same behavior to both SVM and VMX.
Obtained-from: NVMM Reference Implementation
nvmm: Misc changes
The introduction of OS_ASSERT_MTX_OWNED() is to help port to Haiku OS
that doesn't have a mtx_owned() or lockstatus() API for a mutex.
Obtained-from: NVMM Reference Implementation
kernel: reset the tty drain timeout after a session exits
exit1() forces t_timeout to one second while it drains the
controlling terminal of an exiting session leader, and leaves it
there. The tty outlives the session, so the next session on it (a
reused pty) gets EIO from any write that waits more than a second for
output space. dsynth runs into this, with gmake failing with "write
error: stdout".
Reset it to 0, the default, after ttywait(). Restoring the old value
would also carry over a timeout the session set with TIOCSDRAINWAIT.
Bug: https://bugs.dragonflybsd.org/issues/3469
contrib/file: Fix the DragonFly ABI note version decoding
The ABI note stores __DragonFly_version, which is encoded as
major * 100000 + minor * 100 + rev. file(1) decoded the minor and bump
fields as major * 100000 + minor * 10000 + bump, so a 6.5.22 binary was
reported as "for DragonFly 6.0.522".
Fix the version decoding, similar to my previous patch to readelf(1) in
commit c0de80f6b41e2add4684d84fa92d7abb0fc9b656.
Before:
% file /usr/bin/file
/usr/bin/file: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /libexec/ld-elf.so.2, for DragonFly 6.0.522, stripped
After:
% file /usr/bin/file
/usr/bin/file: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /libexec/ld-elf.so.2, for DragonFly 6.5.22, stripped
testcases: Add regression tests for open() and openat()
With the previous open(2) fixes, all the tests pass:
vfs/dotdot testcase:
```
--- open() of dot/dotdot ---
ok: open(.) O_WRONLY|O_CREAT Is a directory (21)
ok: open(.) O_RDWR|O_CREAT Is a directory (21)
ok: open(.) O_RDONLY|O_CREAT Is a directory (21)
ok: open(.) O_WRONLY Is a directory (21)
ok: open(.) O_RDONLY OK
ok: open(.) O_WRONLY|O_TRUNC|O_CREAT Is a directory (21)
ok: open(.) O_WRONLY|O_CREAT|O_EXCL File exists (17)
ok: open(.) O_RDONLY|O_CREAT|O_EXCL File exists (17)
ok: open(.) O_RDONLY|O_CREAT|O_DIRECTORY Is a directory (21)
ok: open(..) O_WRONLY|O_CREAT Is a directory (21)
ok: open(..) O_RDONLY|O_CREAT Is a directory (21)
ok: open(..) O_WRONLY|O_CREAT|O_EXCL File exists (17)
[54 lines not shown]
open(2): Fix open(O_CREAT) to correctly return EISDIR
* Skip "." and ".." terminating paths in nlookup() for NLC_OPEN, so
they'll be handled in vn_open() to correctly return EISDIR instead of
EEXIST.
* Let open("/", O_CREAT) through in nlookup(), so this case can be
handled in vn_open() to return EISDIR.
* Fix vn_open() to return EISDIR if the target is a directory and is
opened with O_CREAT or O_RDWR/O_TRUNC.
* Fix vn_open() to handle the mount-point target normally when the
target already exists, instead of simply return EINVAL.
Bug: https://bugs.dragonflybsd.org/issues/3282
Tested-by: pjdfstest (https://github.com/pjd/pjdfstest)
Assisted-by: DeepSeek-v4.1-flash (with Pi Coding Agent)
rename(2): Fix permission check on cross-parent directory rename
Cross-parent directory rename did not require write permission on the
source directory, although its ".." entry is modified. POSIX requires
EACCES there. UFS already performs this check, but HAMMER2 and tmpfs
don't. Fix the bug by adding a generic check in kern_rename().
To reproduce the bug:
```
$ d=$(mktemp -d)
$ mkdir -p ${d}/p1/dir1 ${d}/p2
$ touch ${d}/p1/dir1/file1
$ chmod 0444 ${d}/p1/dir1
$ mv ${d}/p1/dir1 ${d}/p2
```
Before the fix, the last "mv" command succeeded; after the fix, it would
fail with "Permission denied" (EACCES).
[2 lines not shown]
stat(2): Fix 'st_rdev' to report correct (major, minor) numbers
* Fix vn_stat() to fill 'st_rdev' with makeudev() for character and
block devices that have a valid device number.
* In addition, fix devfs_vop_getattr() to fill 'va_rmajor' in addition to
'va_rminor', and fix hammer2_vop_getattr() to fill 'va_rmajor' and
'va_rminor'.
Before the fix, a manually mknod()-created device would have a 'st_rdev'
of NODEV (i.e., -1), for example:
```
$ ~/mknod /tmp/dev-1-2 1 2
dev: 0x102 (major=1, minor=2)
$ ls -l /tmp/dev-1-2
crw------- 1 root wheel 255, 0xffff00ff Nov 7 18:34 dev-1-2
$ stat -f '%Z' /tmp/dev-1-2
255,4294902015
```
[12 lines not shown]
unlink(2): Fail with EPERM when trying to unlink a directory
As specified by POSIX and documented in the unlink(2) man page,
unlinking a directory fails with EPERM instead of EISDIR. Fix
kern_unlink() to return EPERM when trying to unlink a directory.
Found-by: pjdfstest (https://github.com/pjd/pjdfstest)
Assisted-by: DeepSeek-v4.1-flash (with Pi Coding Agent)