tsearch.3: Clarify node vs. key and improve markup
Pull in clarifications from Apple's libc: describe the comparison
function's arguments as key pointers, refer to the nodes returned by
tfind() and tsearch() rather than to the "datum", explain how to get a
node's key, note that the action function is called only once for leaf
nodes, and note about how VISIT names don't map to the usual traversal
order nomenclature.
The paragraph about the first member of a node being a pointer to its
key was rewritten, as Apple's wording was not strictly accurate.
Apple's Libc also has a paragraph describing what each traversal order
does, but it is mostly redundant, so it is not included here.
While here, mark up NULL and the VISIT values with .Dv, move the VISIT
typedef into a literal block, and fix mandoc lint warnings.
MFC after: 3 days
[4 lines not shown]
tsearch.3: Fix tdestroy(3) entries in NAME and SYNOPSIS
Add tdestroy to the NAME section, remove a stray opening parenthesis
from its node_free argument in the SYNOPSIS, and small grammar fix in
STANDARDS.
Fixes: b0d4b059cf84 ("tdestroy(3) man page")
MFC after: 3 days
Sponsored by: Klara, Inc.
mpr(4)/mps(4): Fix build on 32-bit platforms
bus_addr_t is 32-bit on armv7, so >> 32 triggers -Wshift-count-overflow.
Widen it to uint64_t before shifting, as the other high-address writes
in the same files.
Fixes: 866760ff8338 ("mps(4): add support for hostboot")
Sponsored by: The FreeBSD Foundation
sound: Hold the topology lock across the remaining registration checks
sysctl_dev_pcm_bitperfect(), sysctl_dev_pcm_eq() and
sysctl_dev_pcm_eq_preamp() check PCM_REGISTERED() and then busy the
device with nothing held in between, so pcm_unregister() can run and
destroy the sx before PCM_ACQUIRE() takes it. These sysctls are
registered in the device's newbus context, so they outlive
pcm_unregister().
Hold the topology lock across the check and the busy, as the other
handlers do.
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D61224
sound: Fix a LOR between AIOGCAP and SNDCTL_DSP_SYNCGROUP
AIOGCAP locks a dsp_cdevpriv's record channel and then its play channel,
while dsp_oss_syncgroup() locked them the other way round. Verified the
LOR and deadlock by exercising both paths using a duplex FD
concurrently.
Lock the record channel first in dsp_oss_syncgroup() too, and document
the order in sound.h.
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D60519
sound: Busy the device in mixer_oss_mixerinfo()
Rather than hold the topology lock across the whole handler, which
blocks detach of every device in the system, busy the one being selected
and used, and drop the topology lock, as the other SNDCTL_*INFO handlers
do.
The mutex now covers only the mixer fields. mixer->cdev is set once in
mixer_init() and never cleared, so reading does not need the lock.
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D60518
sound: Retire PCM_LOCK in sound_oss_card_info()
The handler reads the device name, its description and the status
string. All three are set before pcm_register() makes the device
visible, and never change afterwards. The topology lock, which is held
across the whole function, makes sure the device is not freed.
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D60515
sound: Busy the device in SNDCTL_DSP_GETCAPS
The handler read the device flags under PCM_LOCK, but those flags are
written while holding the device busy, so busy it instead.
The CHN_F_VIRTUAL checks do not need a lock. The flag is set once in
vchan_init() when the channel is created and never cleared.
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D60514
sound: Protect channels.pcm.opened with the sx alone
This list is initialized in pcm_init() and only accessed by dsp_open()
and dsp_close(), and we are under sx already, so the PCM_LOCK does not
add anything.
PCM_LOCK is also held around playcount/reccount reads, which are also
under sx now.
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D60513
sound: Stop taking PCM_LOCK to create and destroy channels
chn_init() and chn_kill() took PCM_LOCK around the channel lists and the
per-direction counts, so that readers which cannot sleep could inspect
them. There are none left anymore, so drop it. The few remaining
unlocked readers never took the mutex in the first place.
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D60512
sound: Busy the device in sysctl_dev_pcm_mode()
PCM_LOCK does not keep the device alive, so it does not protect this
handler racing with pcm_unregister(). The sysctl is registered in the
device's newbus context which outlives pcm_unregister().
Busy the device instead, as the other handlers do, and hold the topology
lock across the registration check so that the device cannot start
detaching between the check and the busy.
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D60509
sound: Busy devices before giving up the topology lock
The SNDCTL_*INFO ioctls can report info about any device in the system,
not only the one they were issued on. Both the dsp and mixer dispatchers
unnecessarily busy the caller's device first. The caller's device is
kept alive anyway, until destroy_dev() drains the cdev threadcount.
Busying the wrong device also prevents the handlers from busying the one
they actually want to report info on, because this would recurse on the
sx whenever the two were the same, so they walk the channel lists under
PCM_LOCK instead.
Busy each device as it is being inspected, and give up the topology lock
once it is busied rather than holding it across the walks.
The vchan sysctls have the same problem. They look the device up under
the topology lock, drop it, and then busy the device, leaving a window
where the device can disappear. Busy it before dropping the lock there
too.
[4 lines not shown]
snd_maestro3: Do not hold sc_lock across the hwvol handlers
mixer_hwvol_*() can end up taking sound(4)'s channel lock through
mixer_set_softpcmvol() or mixer_set_eq(). m3_pchan_trigger() takes
sc_lock with the channel lock already held, which can cause a LOR. Drop
sc_lock for the duration of the hwvol handlers, as snd_uaudio(4) does
for the same reason.
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D60464
sound: Move channel teardown functions from sound.c to channel.c
This was a layering violation.
No functional change intended.
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D60129
sound: Convert the SD_F_BUSY cv to an sx
SD_F_BUSY was essentially a custom sleepable lock, which was invisible
to WITNESS. Replace it with an sx lock. This simplifies and removes some
of the PCM macros, and gives us WITNESS coverage.
PCM_WAIT(), PCM_ACQUIRE() and PCM_RELEASE() all asserted that PCM_LOCK
is held, which forced callers to take the mutex just to use the macros.
chn_vpc_proc() and sysctl_hw_snd_feeder_rate_quality() are two such
callers. Simplify this.
Changes to snddev_info->flags are now serialized by the sx alone, which
makes the protocol uniform. Previously some writers held the busy flag,
some held busy and the mutex, and others just the mutex.
snddev_info->eqpreamp was consistent, but its only writer held the mutex
needlessly, so drop that too. Document this above the sx definition in
sound.h, and assert the flags protocol in pcm_setflags().
Name both locks after what they are rather than after the device unit,
[6 lines not shown]
sound: Retire pcm_channel->sleeping
This field and the pause_sbt() in pcm_shutdownchans() are redundant now,
because pcm_shutdownchans() (previously part of pcm_killchans()) is now
only responsible for waking up and stopping the channel, and
destroy_dev() will not return until the threads have returned from their
cdev methods.
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D60121
sound: Drain the dsp cdev before freeing resources
pcm_unregister() freed various resources before destroying the dsp cdev.
A thread that had already passed DSP_REGISTERED() could potentially
dereference those after they were freed. This was easily triggered by
the test case introduced in this commit.
Factor out pcm_killchans()'s channel wakeup/drain loop into a new
pcm_shutdownchans(), which is called before destroy_dev(), so that the
channels are freed only when destroy_dev() has returned.
Mark all channels dead, not only the active ones. An operation started
on an idle channel after pcm_shutdownchans() returned would never
complete, and destroy_dev() would wait for the thread forever.
Check PCM_REGISTERED() in vchan_create(), since it is the only place
where channels are created at runtime.
MFC after: 2 weeks
[3 lines not shown]
pam_xdg.8: Mechanical polish
+ convert license to SPDX only
+ belatedly bump date for last content change
+ rewrite in semantic line breaks to fix one sentence per line
Reviewed by: manu
Fixes: ecd6631b19d9 ("pam_xdg: Add linger option")
Differential Revision: https://reviews.freebsd.org/D61703
linuxkpi: Release the "from" device in pci_get_class() and pci_get_base_class()
On Linux the pci_get_*() iterators drop the reference of the device passed
as "from" once the next one has been looked up, so a loop like
while ((pch = pci_get_class(class, pch)))
does not leak anything. LinuxKPI allocates a new pci_dev for every device
it returns but never released "from", so each device but the last one was
leaked together with its kobject, its name and its path name. i915 does
exactly this in intel_detect_pch() and leaked a device at every load.
Drop the reference, but only for the devices created by lkpinew_pci_dev();
the pci_dev of a device attached to a driver belongs to the bus.
Differential Revision: https://reviews.freebsd.org/D61222
lindebugfs: Free the kcov symlink when the module is unloaded
lindebugfs_init() creates the "kcov" symlink with debugfs_create_symlink(),
which allocates a node and a copy of the destination, but passed no destroy
callback to pfs_create_link(). pseudofs therefore never released them and
the "debugfsint" malloc type was reported as leaking memory each time the
module was unloaded.
Use debugfs_destroy(), as done for the other nodes.
Differential Revision: https://reviews.freebsd.org/D61221
linuxkpi: Release devres when the probe of a PCI driver fails
When the probe method of a driver fails, linux_pci_attach_device() only
dropped its reference on the device. Like on detach (see the previous
change), the devres actions are then not run if one of them holds a
reference on the device, which is what devm_drm_dev_alloc() does through the
drm_device. The device is never released, the drm_device is leaked with its
minor, its managed memory and its debugfs entries: unloading the driver
after a failed load (e.g. a missing firmware) printed
"WARNING !xa_empty(&drm_minors_xa)" and leaked memory.
Linux releases the devres resources of a device whose probe failed, so do the
same.
Differential Reivision: https://reviews.freebsd.org/D61223
pam_xdg: Add linger option
The pam_xdg module deletes a user's XDG_RUNTIME_DIR when the last
interactive session logs out. If the user leaves background processes
running on the system, like a terminal multiplexer, that puts state or
domain sockets in XDG_RUNTIME_DIR, then that state gets destroyed and
the processes become effectively orphaned.
On Linux, systemd-logind not only unlinks XDG_RUNTIME_DIR but also kills
all user processes on logout. To allow long-lived background processes,
it implements a per-user "linger" mode to disable the unlink and kill.
Because FreeBSD's pam_xdg does not implement process killing, this
"linger" option implementation skips only XDG_RUNTIME_DIR unlinking
when the user still has running processes after the last session logs
out.
Differential Revision: https://reviews.freebsd.org/D61332
aw_thermal: Add support for the H6
Add the thermal sensor controller of the H6, which has two sensors, for
the CPU and the GPU.
The controller has other registers than the one of the supported SoCs.
The efuse has the temperature of the factory test and the value of each
sensor at this temperature, from which the calibration value of each
sensor is computed and written to the controller.
The alarm and shutdown thresholds and the interrupts are not supported
yet.
Tested on: Pine H64 (CPU and GPU temperatures, idle and under load)