linuxkpi: Do not wait for a disabled tasklet in tasklet_unlock_wait()
tasklet_unlock_wait() waited for the tasklet state to become idle. Linux
only waits for TASKLET_STATE_RUN, i.e. for a tasklet that is currently
executing. A tasklet which is scheduled but disabled does not run until
it is enabled again, so in LinuxKPI it stays in the BUSY (queued) state and
the waiter never returns.
This is what happens when unloading i915: execlists_reset_prepare()
disables the engine tasklet with __tasklet_disable_sync_once() while the
tasklet is queued and kldunload loops forever in pause().
Do not wait if the tasklet is only queued and disabled.
Reviewed by: bz
Sponsored by: Beckhoff Automation GmbH & Co. KG
linuxkpi: Fix lkpi_i2c_del_adapter() leaving the devices behind
lkpi_i2c_del_adapter() looked for the lkpi_iic or lkpi_iicbb device to
delete with device_find_child() on increasing unit numbers, and stopped at
the first unit that does not exist. Units are allocated globally per
devclass, so as soon as one adapter was removed (leaving a hole) or when the
units of a parent do not start at 0, the adapter was not found and its
device was never deleted. The i2c devices of a driver such as i915 then
accumulate, with a new set of unit numbers, each time it is loaded.
Walk the children of the parent instead and match on the adapter.
Sponsored by: Beckhoff Automation GmbH & Co. KG
linuxkpi: Release devres on PCI driver detach
linux_pci_detach_device() called the driver remove method and then only
dropped its reference on the device, expecting the devres list to be
released from lkpi_pci_dev_release() once the last reference is gone.
That never happens when a devres action itself holds a reference on the
device. The typical case is devm_drm_dev_alloc(): the drm_device takes a
reference on its parent and the matching drm_dev_put() is a devres
action. The device is thus never released, drm_dev_release() is never
called and the DRM device and everything it owns is leaked, which makes
unloading drm-kmod drivers fail ("failed due to N other pending
references on the LinuxKPI device") and leaves the module unloadable or
crashing.
Linux releases the devres resources when a driver is unbound, so do the
same: call lkpi_devres_release_free_list() right after the remove method.
The list is empty when lkpi_pci_dev_release() runs later.
[2 lines not shown]
linuxkpi: Fix sysfs_remove_group() for groups without a name
sysfs_create_group() handles a group with a NULL name by creating its
attributes directly under the object node, but sysfs_remove_group() passed
the NULL name to sysctl_remove_name(), which then panics in strcmp().
Mirror the creation path: for an unnamed group, remove each attribute and
binary attribute individually.
This was not hit before because the devres actions of a PCI device
(e.g. the one registered by devm_device_add_group()) were not run when
the driver was detached.
Sponsored by: Beckhoff Automation Gmbh & Co. KG
libc/locale: Check EILSEQ return
_citrus_iconv_std_iconv_convert can return EILSEQ without setting
invlen. As a result, we should check EILSEQ in the return value or it
will incorrectly return -2
Reviewed by: kevans
Fixes: e2030ca246a7 ("libc: fix c*rtomb/mbrtoc*")
MFC after: 2 days
Differential Revision: https://reviews.freebsd.org/D61151
sched: Fix building kernel independently of world
Regular '-I' directives must be passed to ${CPP} so that when
pre-processed, 'sched_ns.h' can find the files it includes in the proper
places, instead of relying on what is in ${WORLDTMP}, i.e., nothing if
'_includes' was not executed, which happens, e.g., when using 'make
kernel-toolchain' and then 'make buildkernel' without having executed
a 'make buildworld', or possibly some outdated copy not matching an
updated source.
Reported by: Claude Opus 5.5, imp
Fixes: 510331fa3763 ("sched: Automatically namespace schedulers' implementation functions")
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D61167
Makefile.inc1: Fix bare $ characters
The '$' characters inside awk commands need to be $$ when appearing
inside a Makefile. Without this, we generate empty src and src-sys
packages.
Reported by: Stefan Grundmann
Fixes: a8be89928930 ("build: Support got")
MFC after: 1 day
bnxt: correct more mappings for 400G optics and 100G LR
- Support 400G-DR4 optics
- Support 400G-CR8 and -SR8 with their types, rather than generic 400G-AUI8
- Use the generic 400G-AUI8 for 400G-SR4, rather than mislabeling it -DR4
(We probably should add a 400G-SR media type, but I don't have any to test ATM)
- Add missing legacy PAM4 100G LR entry and matching media-selection cases.
Reviewed by: sumit.saxena_broadcom.com
Differential Revision: https://reviews.freebsd.org/D61162
Sponsored by: Netflix
sched: Automatically namespace schedulers' implementation functions
This renames back scheduler implementation functions to their old names,
i.e., the same name as the interface functions, in the source code,
while providing the infrastructure to still produce from them C symbols
namespaced by the scheduler implementation, in order to avoid symbol
collisions with interface dispatching functions and other scheduler
implementations when multiple ones are compiled in. In a nutshell, the
implementation consists in re-routing interface names to implementation
names via the C preprocessor.
The main reasons for this change are that different implementation names:
1. Break navigating code with ctags-like tools like in-tree ctags,
Global and Universal Ctags.
2. Spoils inlining opportunities in internal scheduler code if not
careful. This alternatively could be regained by changing call
points to use scheduler-specific names, but that does not prevent
people from inadvertently adding more calls to interface functions.
Also, having to namespace calls with the implementation name in the
[75 lines not shown]
critical_exit_preempt(): Re-check for preemption locked
Once we have the thread lock, we are in a spinlock section and thus will
not be preempted, which ensures stability of 'td_owepreempt'. Check it
again for the improbable case where we were already preempted before
entering that section (after 'td_critnest' reached 0 in critical_exit()
but before clearing 'td_owepreempt', because of an IPI_PREEMPT received
in the meantime or any interrupt whose handler uses critical sections),
in which case there is no need to switch to another thread.
It is however still necessary to temporarily raise 'td_critnest' around
the thread_lock() call, and that is not an optimization contrary to what
the old comment stated. As explained in the new comment, thread_lock()
can lead to entering and exiting a spinlock section multiple times,
which would cause recursion with critical_exit_preempt() in some
circumstances.
Reviewed by: kib, markj
MFC after: 3 days
[2 lines not shown]
iichid: keep a fixed sampling cadence in polled mode
Touchpads using sampling mode have a sampling task which is run at
a certain polling rate. When the system is under load this task may
not complete quickly which might stretch the time taken beyond what
the polling rate should be, leading to dropped touchpad motion.
On my laptop this causes the touchpad to be barely useable when
the system is under heavy load, and it is really difficult to move
the cursor since so many events are dropped.
This change adjusts the sampling loop to schedule the next polling
event to take place at a specific time in the future, based on the
polling period. If servicing the poll takes longer due to load then
the next sample will still be scheduled at its original time.
Approved by: wulf, khng (mentor)
Differential Revision: https://reviews.freebsd.org/D0914
Broadcom tester's were able to trigger a KASSERT in rack due to an accounting issue.
The recently added code to rack to help minimize reordering issues had a KASSERT for protection of its counting field. This
was consistently. Triggered in broadcom's testing lab. They came up with a partial solution.. but one of their fixes was
also incorrect causing the counter to increase incorrectly as well. I worked with them to give them an updated patch (the one
attached in this review). They have tested that in their same repro environment and confirm this fixes the issue.
Reviewed by:tuexen, nickbanks_netflix.com
Differential Revision: <https://reviews.freebsd.org/D61136>
hwpmc/amd: prime UMC perfmon block before programming counter registers
UMC counter register writes do not take effect while no counter in the
channel is enabled. Reserve the last counter slot of each UMC channel
and keep it enabled with EventSelect=0 so writes to the remaining slots
take effect. Reserved slots are not exposed to MI code.
UMC perfmon MSRs are package-scoped. A per-socket reference count arms
the reserved slots on the first amd_pcpu_init() for a socket and
disarms them on the last amd_pcpu_fini().
Reviewed by: mhorne
Sponsored by: AMD
Signed-off-by: Osvaldo Janeri Filho <ojanerif at amd.com>
Pull Request: https://github.com/freebsd/freebsd-src/pull/2422
riscv: Map the DTB when it is outside the kernel's 1GB region
When the kernel is started directly by SBI firmware, locore.S maps only
the 1GB region that contains the kernel, and initriscv() reads the DTB
through that mapping at the physical address passed in a1. If the
firmware put the DTB in another 1GB region, as QEMU does with more than
1GB of RAM, fake_preload_metadata() faults before the console is up and
the kernel hangs.
Also map the 1GB region that contains the DTB.
This fixes direct kernel booting without FreeBSD loader(8).
PR: 299088
Reviewed by: mhorne
Fixes: bfb857546984 ("riscv: Construct an identity map in locore.S")
MFC after: 1 week
Signed-off-by: Rick Richard <rick at sloservers.com>
(cherry picked from commit 509d65fae512c24fc755d6a8b3b41bb967e6c5e1)
libpmc: Fix AMD L3 counter parameter parsing
Fix two small bugs affecting the event parsing of AMD L3 counters.
AMD's manual and JSON disagree about the naming scheme on recent
processors. I use the naming scheme present in the recent PPRs to be
consistent, so in the JSON parser we rename 'allslices' to 'allsources'
just as we already do with sliceid and sourceid. Also ensure that we
parse the 0x prefix present in the newer JSON files.
Reviewed by: mhorne
Sponsored by: Netflix
MFC after: 1 week
Pull Request: https://github.com/freebsd/freebsd-src/pull/2180
(cherry picked from commit d38b3a5ead0d3507080da5321144219b13d43aa9)
libpmc/pmu-events: Add support for new json fields
This change adds support for three new Intel fields to jevents.c:
- MetricThreshold
- MetricgroupNoGroup
- DefaultMetricgroupName
Reviewed by: ali_mashtizadeh.com, mhorne
Differential Revision: https://reviews.freebsd.org/D56017
MFC after: 1 week
(cherry picked from commit 6ad94d549eb2286d791abd5634400d8ef36d8259)
libpmc: Explicitly whitelist json fields
Adds all missing Intel fields and turns jevents.c into an explicit white
list mechanism so that we no longer ignore important fields that often
invalidate the counter. The json event parser must now parse every
field on each architecture that we support. This has been tested by
running tinderbox and manually running jevent against our current json
repository. As a bonus I fixed spelling errors in the AMD JSON
definitions.
Sponsored by: Netflix
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/2055
(cherry picked from commit bfb2fd5f66183454cfe8771595df09c0f23c7efb)
hastd: Add full lifecycle test
Add a test case that creates and starts two nodes, has one assume the
primary role and the other the secondary role, writes to the device,
verifies that the data is synced to both nodes, then switches the roles,
and finally shuts both nodes down and compares their backing stores.
Differential Revision: https://reviews.freebsd.org/D59676
hastd: Allow overriding the node name
Normally, hastd will use the hostname, hostuuid, or hostid as node name.
Allow overriding this with a new -n command-line option. The argument
is treated as a replacement for the hostname, but also disables the
hostuuid and hostid logic. This allows running multiple nodes on the
same system, which is useful for testing.
Differential Revision: https://reviews.freebsd.org/D59675
FDT, clk_fixed: add gated-fixed-clock support and deferred initialization
- Add CLK_TYPE_GATED_FIXED with GPIO-based gate control.
- Support optional vdd-supply regulator.
- Delay clknode registration until parent clock and other dependencies
are present (via new_pass).
While I'm in, switch license header to the new SPDX format.
MFC after: 2 weeks
Reviewed by: manu
Differential Revision: https://reviews.freebsd.org/D58103
sound: Let pcm_unregister() tear down a partially initialized device
Since 3107b952f534 ("sound: Merge PCM_ALIVE() with PCM_REGISTERED()"),
pcm_unregister() is gated on PCM_REGISTERED(), so it cannot run unless
pcm_register() has already succeeded, which means drivers will leak
resources if a failure happened prior to this.
Reintroduce PCM_ALIVE(), but test dev rather than the lock. pcm_init()
assigns dev before anything else, so it can tell us whether pcm_init()
has run or not. Make sure to clear it in pcm_unregister() so that a
second call to pcm_unregister() cannot double-free.
While here, publish to sndstat(4) only once pcm_register() has
succeeded.
Reported by: jah
Fixes: 3107b952f534 ("sound: Merge PCM_ALIVE() with PCM_REGISTERED()")
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
[4 lines not shown]