DragonFlyBSD/src e17b917 — usr.bin/dsynth build.c

dsynth(1): Use defined(PROC_REAP_KILL) instead of __DragonFly_version

This is a follow-up change to my previous commit
53c96f5130f5e530674e5d7ac2f32f3cd16e8352.
DeltaFile
+1-1usr.bin/dsynth/build.c
+1-11 files

DragonFlyBSD/src 41e72fd — sys/dev/drm drm_gem.c drm_vm.c

drm: fix a panic on mmap() at an unknown offset

mmap(2) of a DRM device node at an offset that is not a GEM mmap
offset panicked the kernel.  drm_gem_mmap_single() returns ENODEV for
such an offset, which makes vm_mmap() fall back to the device pager,
and the pager calls drm_mmap() without a file; drm_mmap() dereferenced
the NULL file pointer (page fault at address 0x78 in drm_mmap(), called
from dev_dmmap()).  Any user who can open /dev/dri/card0 could trigger
it.

The device pager never has a file for drm_mmap(), so the fallback
cannot work: fail with EINVAL as Linux does, and make drm_mmap() refuse
a call without a file.

Bug: https://bugs.dragonflybsd.org/issues/3484
DeltaFile
+2-4sys/dev/drm/drm_vm.c
+1-1sys/dev/drm/drm_gem.c
+3-52 files

DragonFlyBSD/src 1c63779 — sys/vfs/ntfs ntfs_vnops.c

ntfs: bounce reads of clusters smaller than a page

Same defect as msdosfs: uiomovebp() zero-fills and validates the whole
last VM page of the held buffer when that page is not fully valid, and
with clusters smaller than a page the unread sibling clusters of the
same file are later served the fabricated zeros from the buffer cache.

For such clusters ntfs_read() copies the requested bytes into a kernel
buffer and releases the cluster before copying to user space.  The
ntfs_subr.c copy sites are left alone: they transfer to and from device
buffers and do not check the result.  Clusters of a page or more keep
uiomovebp().  Page-in reads (UIO_NOCOPY) copy nothing and use plain
uiomove().

Bug: https://bugs.dragonflybsd.org/issues/3461
Discussed-with: dillon
DeltaFile
+24-4sys/vfs/ntfs/ntfs_vnops.c
+24-41 files

DragonFlyBSD/src 65518a3 — sys/vfs/msdosfs msdosfs_vnops.c

msdosfs: bounce reads of clusters smaller than a page

uiomovebp() zero-fills and validates the whole last VM page of a held
buffer when that page is not fully valid.  With clusters smaller than a
page the unread sibling clusters of the same file share that page, and
later reads of those clusters return the fabricated zeros from the
buffer cache without I/O.

For such clusters msdosfs_read() copies the requested bytes into a
kernel buffer and releases the cluster before copying to user space.
Clusters of a page or more keep uiomovebp().  Directory reads keep
uiomovebp(): their buffers are on the device vnode, so the VREG-only
fix-up never fires for them.  Page-in reads (UIO_NOCOPY) copy nothing
and use plain uiomove().

Bug: https://bugs.dragonflybsd.org/issues/3461
Discussed-with: dillon
DeltaFile
+16-2sys/vfs/msdosfs/msdosfs_vnops.c
+16-21 files

DragonFlyBSD/src 6d13c66 — sys/vfs/msdosfs msdosfs_vnops.c

msdosfs: stage write data before raising the file size

A write whose source is a mapping of the same file can fault on the
user side; the copy cannot be retried while the cluster is locked, and
uiomovebp() would also zero-fill and validate the whole last VM page,
destroying sibling clusters of the same file.

For clusters smaller than a page, copy the user data into a kernel
buffer before the file size is raised (de_FileSize and
vnode_pager_setsize; the cluster allocation in extendfile() and
deextend() still happens before the loop), then copy from that buffer
into the cluster.  A failure of that copy rewinds the uio by what it
consumed.  The bmap and bread failure paths also rewind the uio and
free the buffer, but they run after the size is raised and rely on the
existing IO_UNIT rollback.  UIO_NOCOPY writes copy nothing and use
plain uiomove(), which cannot fail for NOCOPY, for every cluster size;
clusters of a page or more otherwise keep uiomovebp().

Bug: https://bugs.dragonflybsd.org/issues/3461
Discussed-with: dillon
DeltaFile
+54-17sys/vfs/msdosfs/msdosfs_vnops.c
+54-171 files

DragonFlyBSD/src efcec89 — sys/dev/misc/syscons syscons.c

syscons: let VT_WAITACTIVE wait for a vty that was never opened

VT_WAITACTIVE slept on the target vty's scr_stat, which exists only
once something has opened the vty.  Since 8aefdd25a3 (bug #2481) a
NULL scr_stat makes it return 0 at once, so waiting for an unopened
vty reported it as active right away.

Do as FreeBSD's syscons: compare the vty index with the current one
and sleep on a per-index channel, &sc->dev[i], which exists whether
or not the vty was opened.  The switch code wakes that channel.

Bug: https://bugs.dragonflybsd.org/issues/3472
Reviewed-by: @dillon
DeltaFile
+7-11sys/dev/misc/syscons/syscons.c
+7-111 files

DragonFlyBSD/src 3ee2330 — sys/cpu/x86_64/include atomic.h cpumask.h, sys/platform/pc64/apic apic_vector.s

kernel - Make stop_cpus()/restart_cpus() much more reliable

* Wait for cpus to not be inside an interrupt or to be initiating a
  TLB shootdown while stopping them.  This is better than trying to
  fixup causes where the stop interrupts special interrupts (or any
  interrupt, really).

  Note that in DragonFly, stopped CPUs are still allowed to take
  interrupts.  We do not completely crowbar the CPU while it is
  stopped, that just creates too many problems.

* Make DDB and crash-dump entry a lot more reliable.

* With analysis and testing by claude.  However, we didn't really
  use the primary recommendations and instead did it a slightly
  different way.

Reported-by: tuxillo
Debugging-by: tuxillo
Bug: https://bugs.dragonflybsd.org/issues/3475
DeltaFile
+70-13sys/platform/pc64/x86_64/mp_machdep.c
+29-0sys/platform/pc64/apic/apic_vector.s
+7-0sys/cpu/x86_64/include/cpumask.h
+3-0sys/platform/pc64/x86_64/global.s
+3-0sys/cpu/x86_64/include/atomic.h
+1-0sys/platform/pc64/x86_64/genassym.cf
+113-136 files

DragonFlyBSD/src e9a3645 — sys/dev/drm drm_ioctl.c

drm: return a positive errno when drm_ioctl_permit() fails

Since 908aca8817 drm_ioctl() hands drm_ioctl_permit()'s Linux-style
negative error code to userland unchanged, so a refused ioctl sets
errno to -13 (-EACCES) instead of 13. The handler results below are
already negated (retcode = -func(...)). The same commit also changed
"return ENODEV" to "return -ENODEV" for an unplugged device; restore the
positive value (nothing reaches it today, drm_dev_unplug() is only
called from code that is not built).

drmAuthMagic() returns -errno, i.e. +13, which never equals -EACCES,
so libdrm's drmIsMaster() reports non-master fds as master. wlroots
then calls drmDropMaster() on a cloned non-master fd, logs "Failed to
drop master", closes the fd, and the DRM lease manager skips the card.

Negate the value, as is done for the handlers.

Tested on 6.5-DEVELOPMENT (i915): AUTH_MAGIC on a non-master fd now
fails with errno 13 instead of -13, sway no longer logs "Failed to drop
master" or skips the card for leasing, and X starts.
DeltaFile
+2-2sys/dev/drm/drm_ioctl.c
+2-21 files

DragonFlyBSD/src d23da7d — sys/dev/drm drm_file.c

drm: return a positive errno or zero from drm_read()

drm_read() is the d_read method of drm_cdevsw, which returns zero or a
positive errno; the amount read is in uio_resid.  It returned the
Linux-style negative values instead: -EAGAIN for an O_NONBLOCK read
without events, -EFAULT, -EINTR from mutex_lock_interruptible() and
-ERESTARTSYS from wait_event_interruptible().  It also returned the
number of bytes read when the next event did not fit in the buffer;
read(2) then failed with that number as the errno and the events
already copied were lost.

Negate the errno values, map -ERESTARTSYS to EINTR as drm_ioctl() does,
and return zero when data was read.

Tested on 6.5-DEVELOPMENT (i915): an O_NONBLOCK read without events now
fails with errno 35 (EAGAIN) instead of -35, a read interrupted by a
signal with errno 4 (EINTR) instead of -512, and read(2) of 40 bytes
with three 32-byte vblank events queued returns 32 instead of failing
with errno 32 (EPIPE) and losing the event.
DeltaFile
+3-3sys/dev/drm/drm_file.c
+3-31 files

DragonFlyBSD/src 4d09039 — sys/dev/drm drm_file.c

drm: return a positive errno from drm_open()

drm_open() is the d_open method of drm_cdevsw, which returns a
positive errno, but its failure paths return the Linux-style negative
values: -ENODEV from drm_minor_acquire(), -EBUSY for O_EXCL and the
negative errors of drm_open_helper() and drm_setup().  A failed open()
therefore hands a negative errno to userland, as drm_ioctl() did.

Negate the value on both error returns.

Tested on 6.5-DEVELOPMENT (i915): open(2) of /dev/dri/card0 with O_EXCL
now fails with errno 16 (EBUSY) instead of -16.
DeltaFile
+2-2sys/dev/drm/drm_file.c
+2-21 files

DragonFlyBSD/src a993d9b — sys/dev/drm drm_auth.c

drm: remove debug kprintf()s from drm_auth.c

drm_setmaster_ioctl() and drm_dropmaster_ioctl() print unconditional
kprintf()s: every DRM_IOCTL_DROP_MASTER, and every SET_MASTER that does
not return early, leaves a line in dmesg (seen at the end of every sway
session started through seatd). They were added as debugging aids in
4ec80808ee. Remove them; the setmaster workaround itself is unchanged.
DeltaFile
+0-5sys/dev/drm/drm_auth.c
+0-51 files

DragonFlyBSD/src 9f0e625 — sys/platform/pc64/apic lapic.h lapic.c, sys/platform/pc64/x86_64 mp_machdep.c

kernel - Move mfence into selected_apic_ipi() and single_apic_ipi()

* Make sure pending writes are flushed before issuing APIC IPIs.
  Probably only needed for MSR-based IPIs, but do it for both
  MEM and MSR.

* Remove explicit mfence prior to issuing IPI.
DeltaFile
+25-2sys/platform/pc64/apic/lapic.c
+1-1sys/platform/pc64/x86_64/mp_machdep.c
+1-0sys/platform/pc64/apic/lapic.h
+27-33 files

DragonFlyBSD/src cb7c913 — sys/vfs/hammer hammer_inode.c, sys/vfs/hammer2 hammer2_inode.c

vfs: drop S_ISGID on create when not a member of the group

A new file on tmpfs, HAMMER or HAMMER2 gets the directory's group and
the mode the caller asked for.  If the creator was not a member of
that group, S_ISGID was kept, so any user who can write to a
directory owned by another group could create a set-group-ID
executable for that group; with /tmp on tmpfs (root:wheel 1777) that
is wheel.  UFS and ext2fs already drop the bit when they create the
inode.

Do the same check as ufs_makeinode() in tmpfs_alloc_file(),
hammer_create_inode() and hammer2_inode_create_normal(), after the
group has been chosen: keep S_ISGID only for a member of the group or
with SYSCAP_NOVFS_SETGID.  As in FreeBSD's fix for tmpfs, this covers
every node type.

Same issue as FreeBSD-SA-26:94.tmpfs (CVE-2026-127749).

Tested on tmpfs, UFS, HAMMER and HAMMER2: a file created with mode

    [6 lines not shown]
DeltaFile
+13-1sys/vfs/tmpfs/tmpfs_subr.c
+10-0sys/vfs/hammer2/hammer2_inode.c
+10-0sys/vfs/hammer/hammer_inode.c
+33-13 files

DragonFlyBSD/src 208afa3 — sys/cpu/x86_64/include cpufunc.h, sys/kern kern_shutdown.c

kernel - Fix cpustop/resume (debugger, kernel core)

* Make cpu_halt() just do the basic instruction, remove halt()
  on naming semantics.

* Add cpu_halt_forever() that halts forever.

* Add cpu_halt_and_enable_intr() to do "sti; halt" sequence.

* Fix stop race in loop test, and restart signaling issues when
  using HLT instead of MONITOR/MWAIT.

* mfence() prior to resume IPI (MSR/LAPIC does not flush pending writes)

Reported-by: tuxillo and Claud
Bug: https://bugs.dragonflybsd.org/issues/3476
Testing-by: tuxillo
DeltaFile
+12-7sys/platform/pc64/x86_64/machdep.c
+9-2sys/cpu/x86_64/include/cpufunc.h
+7-2sys/platform/pc64/x86_64/mp_machdep.c
+2-2sys/kern/kern_shutdown.c
+1-1sys/sys/systm.h
+1-1sys/platform/vkernel64/platform/init.c
+32-156 files

DragonFlyBSD/src d46c840 — sys/dev/powermng/corecstat corecstat.c

corecstat(4): Add Goldmont, Goldmont Plus, and Tremont CPU support.

* This should cover Apollo Lake, Denverton, Gemini Lake,
  Elkhart Lake, and Jasper Lake models.

* These last Atom CPU cores use the same MSR registers for the same
  states as "Core" CPUs.
DeltaFile
+40-3sys/dev/powermng/corecstat/corecstat.c
+40-31 files

DragonFlyBSD/src 305deb5 — sys/dev/powermng/corepower corepower.c

corepower(4): Add Goldmont, Goldmont Plus, and Tremont CPU support.

* This should cover Apollo Lake, Denverton, Gemini Lake,
  Elkhart Lake, and Jasper Lake models.
DeltaFile
+13-0sys/dev/powermng/corepower/corepower.c
+13-01 files

DragonFlyBSD/src 64a78ae — sys/kern subr_prf.c

kern: Remove obsolete 'consintr' static from subr_prf.c

This code was inherited from FreeBSD and it was already an obsolete
static then.
DeltaFile
+0-9sys/kern/subr_prf.c
+0-91 files

DragonFlyBSD/src 4d91abe — sys/dev/virtual/nvmm/x86 nvmm_x86.c nvmm_x86_internal.h

nvmm: Clarify the XSAVE state handling

Obtained-from: NVMM Reference Implementation
DeltaFile
+10-9sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c
+10-9sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c
+8-3sys/dev/virtual/nvmm/x86/nvmm_x86_internal.h
+2-2sys/dev/virtual/nvmm/x86/nvmm_x86.c
+30-234 files

DragonFlyBSD/src d2d715a — sys/dev/virtual/nvmm/x86 nvmm_x86_internal.h

nvmm: Merge one #ifdef with NetBSD in ASM code handling

Since commit 9bd9bca17d53c0f7d7bcd6cd3e029bb77ccb13a6 the ASM code has
become more OS-independent, so <machine/asm.h> is no longer needed in
both OSes.

Since commit b94dd9242808203c854242a803f484ff25f76e32 DragonFly migrated
to use the new "assym.h" as NetBSD, so this #ifdef can be merged for
both OSes.
DeltaFile
+1-6sys/dev/virtual/nvmm/x86/nvmm_x86_internal.h
+1-61 files

DragonFlyBSD/src 8d0618b — lib/libnvmm libnvmm_x86.c, sys/dev/virtual/nvmm/x86 nvmm_x86_vmx.c nvmm_x86_svm.c

nvmm,libnvmm: Stop relying on the PSL_* macros from <machine/psl.h>

Define RFLAGS_* instead.

Obtained-from: NVMM Reference Implementation
DeltaFile
+43-33lib/libnvmm/libnvmm_x86.c
+18-0sys/dev/virtual/nvmm/x86/nvmm_x86_internal.h
+3-3sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c
+3-3sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c
+67-394 files

DragonFlyBSD/src e2619a1 — sys/dev/virtual/nvmm Makefile, sys/platform/pc64/x86_64 genassym.cf

pc64,vkernel64: Prune includes in genassym.cf

In addition, remove the obsolete "opt_nfs.h" header dependency of
genassym.cf in sys/dev/virtual/nvmm/Makefile.
DeltaFile
+3-24sys/platform/vkernel64/x86_64/genassym.cf
+3-18sys/platform/pc64/x86_64/genassym.cf
+1-1sys/dev/virtual/nvmm/Makefile
+7-433 files

DragonFlyBSD/src b94dd92 — sys/kern genassym.sh, sys/platform/pc64/x86_64 genassym.cf genassym.c

Migrate to the newly imported genassym.sh and generated assym.h

* Remove the old sys/kern/genassym.sh, sys/sys/assym.h and genassym.c
  files.
* Migrate the genassym.c code to genassym.cf configs for genassym.sh.
* Update all sources to include the new generated "assym.h" instead of
  the old "assym.s".
* Update the kernel makefiles in sys/conf to call genassym.sh to
  generate "assym.h".
* Update libc to use genassym.sh to generate "asmcontext.h".
DeltaFile
+0-270sys/platform/pc64/x86_64/genassym.c
+269-0sys/platform/pc64/x86_64/genassym.cf
+0-121sys/platform/vkernel64/x86_64/genassym.c
+118-0sys/platform/vkernel64/x86_64/genassym.cf
+0-71sys/kern/genassym.sh
+0-52sys/sys/assym.h
+387-51431 files not shown
+486-62337 files

DragonFlyBSD/src 264f8eb — sys/conf kern.post.mk kmod.mk

sys/conf: Share compiler flags and rules between kernel and modules

* Move the common CFLAGS to bsd.kern.mk, and include it earlier in
  kern.pre.mk and kmod.sh, so the flags ordering in CFLAGS is mostly
  preserved.
* Clear the suffix rules and CFLAGS from <sys.mk> and explicitly define
  them in bsd.kern.mk, for use in the kernel and modules building.
DeltaFile
+39-1sys/conf/bsd.kern.mk
+6-16sys/conf/kern.pre.mk
+2-16sys/conf/kmod.mk
+0-2sys/conf/kern.post.mk
+47-354 files

DragonFlyBSD/src 0a4a8bc — sys/conf kmod.mk kern.pre.mk

sys/conf: Propapage CONF_CFLAGS (from makeoptions) to module build

Obtained-from: FreeBSD (commit 627693305a95135ca1ade92b4827e5f3c8208e61)
DeltaFile
+3-0sys/conf/kern.pre.mk
+1-0sys/conf/kmod.mk
+4-02 files

DragonFlyBSD/src f04e0bd — sys/platform/pc64/x86_64 genassym.c

pc64: Remove redundant symbol exports in genassym.c

The MSR_GSBASE, MSR_KGSBASE and MSR_FSBASE are constants defined in
<machine/specialreg.h> and can be used in assembly code, so no need to
redefine them.

Caught by the new genassym.sh, whose output has different value format
(e.g., `#define MSR_GSBASE 3221225729`) and thus caused redefinition
error in compilation.

While there, remove a few commented symbols as well.
DeltaFile
+0-9sys/platform/pc64/x86_64/genassym.c
+0-91 files

DragonFlyBSD/src 5717c5b — share/man/man5 Makefile genassym.cf.5, share/man/man8 Makefile genassym.sh.8

kernel: Import OpenBSD's genassym.sh tool

The new genassym.sh tool uses special inlined assembly code to create
the "assym.h" (ours named "assym.s") from constant C expressions.  It
will replace the current sys/kern/genassym.sh tool, which relies on
the special macros in <sys/assym.h> and a custom CC compilation, and
will help simplify the "assym.s" generation code in kern.post.mk and
kmod.mk.

I compared the genassym.sh tool in both NetBSD and OpenBSD and found
OpenBSD version is better maintained, so I chose their version.

I placed this tool in sys/tools/ directory instead of sys/kern/; I think
the former is a better location as there are already some awk tools, and
this genassym.sh will also be used by libc.
DeltaFile
+187-0sys/tools/genassym.sh
+139-0share/man/man5/genassym.cf.5
+93-0share/man/man8/genassym.sh.8
+1-0share/man/man8/Makefile
+1-0share/man/man5/Makefile
+421-05 files

DragonFlyBSD/src 9ce46dc — sys/conf kmod.mk bsd.kern.mk

sys/conf: Improve ${NORMAL_FWO} command for reuse in kmod.mk

The kmod.mk previously invented its own commands to link a firmware blob
(.fwo). Given that NORMAL_FWO is available through bsd.kern.mk, improve
it and reuse it in kmod.mk.
DeltaFile
+1-10sys/conf/kmod.mk
+7-4sys/conf/bsd.kern.mk
+8-142 files

DragonFlyBSD/src 2897023 — sys/conf bsd.kern.mk kern.post.mk

sys/conf: Clean up makefiles

* Minor logic and code simplifications.
* Remove non-existent 'freebsd/net/ifdi_if.m' from MFILES, and sort the
  list.
* Remove obsolete and commented stale contents.
* Simplify the 'hack.So' generation to save a temp file.
* Move -Wno-unused-but-set-variable out of the GCC scope as it's also
  supported by Clang.
* Style and whitespace cleanups.
DeltaFile
+53-52sys/conf/kmod.mk
+25-32sys/conf/kern.pre.mk
+24-27sys/conf/kern.post.mk
+4-4sys/conf/bsd.kern.mk
+106-1154 files

DragonFlyBSD/src f0a0671 — sys/conf kern.pre.mk, sys/platform/vkernel64/conf kern.mk

vkernel64: Move hack.So handling to kern.pre.mk

That's where the SYSTEM_OBJS is defined, so it makes it easier to
maintain.
DeltaFile
+5-1sys/conf/kern.pre.mk
+0-3sys/platform/vkernel64/conf/kern.mk
+5-42 files

DragonFlyBSD/src 5a60e0b — sys/tools genassym.sh

genassym.cf: Tweak for DragonFly

* Don't always define `_KERNEL`, which would cause trouble for libc
  where only `_KERNEL_STRUCTURES` should be defined. So just remove this
  and rely on the command to define the wanted macro.
* Don't define `offsetof` to avoid redefinition error, because our
  <sys/stdint.h> always defines this macro.
DeltaFile
+0-2sys/tools/genassym.sh
+0-21 files