kern.post.mk: Further refine ports module build
A handful of kmod ports have NO_PACKAGE set, which disables the package
target, which means the previous commit made things worse for those
ports rather than better. Work around this by explicitly building the
stage target first.
Fixes: b393df657811 ("kern.post.mk: Fix unprivileged ports module build")
rtwn: (RTL8192FU) fix init, with_ucode build and tx power handling
- added noop for RTWN_WITHOUT_UCODE builds on sc_set_media_status
- fixed upper bound of power delta for MCS for HT20/HT40 in tx power
- moved reading per channel bb trim values after efuse and bb initialization
- use 256 bytes per TX pages as per vendor and linux rtl8xxxu
- added tab character instead of spaces in share/misc/usb_vendors after the device name
Tested on RTL8192FU
Sponsored by: Alchemilla Ventures Private Limited
Reviewed by: adrian
Differential Revision: https://reviews.freebsd.org/D62241
Reported by: llm-postcr
Fixes: 1f0e186e1832 ("rtwn: added support for Realtek RTL8192FU...")
rge(4): Fix build without INET
rge_tx_pad() calls in_delayed_cksum_o() and in_cksum_skip()
unconditionally. in_delayed_cksum_o() lives in netinet/ip_output.c
(optional inet) and in_cksum_skip() lives in netinet/in_cksum.c
(optional inet | inet6). So kernels with "device rge" and no
INET fail to link. This breaks LINT-NOINET and LINT-NOIP.
Include opt_inet.h, add it to the module's SRCS, and wrap the IPv4
software checksum block in #ifdef INET.
Fixes: e3ded948ad41 ("rge(4): Implement RTL8125 UDP hardware workaround")
Reported by: llm-postcr
Differential Revision: https://reviews.freebsd.org/D62240
libsys: Split out a new libsys_private.h from libc's libc_private.h
Downstream we have accidentally ended up referencing libc symbols from
within libsys, which went unnoticed because in practice libc is always
loaded whenever libsys is. Split out a new header to detect such cases
at build time, without relying solely on the test recently added in
493c84741c45 ("libsys: add test checking that -lsys alone is linkable").
Note we still add libc to the compiler's include path for compat.h and
(un-)namespace.h, but none of these provide declarations. Ideally that
would also be refactored, but that is a more invasive change.
Copyright header copied from those added by kib@ in 8495e8b1e9e1 ("Fix
known issues which blow up the process after dlopen("libthr.so") (or
loading a dso linked to libthr.so into process which was not linked
against threading library)."), the commit that introduced what is almost
all the code in this header; none of this code originates from jb@, to
whom libc_private.h is attributed.
[3 lines not shown]
libfetch: Fix buffer overruns in FTP code
* When parsing the reply to a CWD, PWD, or CDUP command, if we ran out
of space in the destination buffer, we would correctly terminate the
loop, but then incorrectly see the remaining length as non-zero,
causing us to write a terminating NUL one past the end of the buffer
and report success instead of a protocol error. Additionally, the
code would fail to notice an improperly terminated pathname, and was
hard to follow, so rewrite the entire loop.
* When comparing the current working directory to the intended working
directory to calculate the minimal operation to get from one to the
other, if the current working directory was an empty string, we would
improperly read one byte below the start of the intended working
directory.
MFC after: 1 week
Reported by: Laam Alif at Ibteda Digital Library
Differential Revision: https://reviews.freebsd.org/D61502
[2 lines not shown]
libfetch: Fix buffer overruns in FTP code
* When parsing the reply to a CWD, PWD, or CDUP command, if we ran out
of space in the destination buffer, we would correctly terminate the
loop, but then incorrectly see the remaining length as non-zero,
causing us to write a terminating NUL one past the end of the buffer
and report success instead of a protocol error. Additionally, the
code would fail to notice an improperly terminated pathname, and was
hard to follow, so rewrite the entire loop.
* When comparing the current working directory to the intended working
directory to calculate the minimal operation to get from one to the
other, if the current working directory was an empty string, we would
improperly read one byte below the start of the intended working
directory.
MFC after: 1 week
Reported by: Laam Alif at Ibteda Digital Library
Differential Revision: https://reviews.freebsd.org/D61502
[2 lines not shown]
kern.post.mk: Fix unprivileged ports module build
When building ports modules along with the kernel, we run the build
target during buildkernel, and the install target during installkernel.
This was fine back in the day when we installed ports straight from the
working directory, but these days we stage them first, then build a
package, and install the package. This staging and packaging should be
seen as part of the build process, not the installation process, so we
should use the package target, rather than the build target, during
buildkernel.
This fixes an issue where doing buildkernel as an unprivileged user,
then installkernel as root, left a root-owned staging directory in the
kernel object tree which the next unprivileged buildkernel would be
unable to remove or replace.
MFC after: 1 week
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D62195
linuxkpi: Make list_sort stable
Linux's list_sort() is intended to be stable, but linuxkpi implemented
it as a wrapper around qsort(), which is not. This used to work because
our qsort() had a bug that effectively turned it into insertion sort,
but this is no longer the case. Replace the qsort() call with an inline
implementation of insertion sort.
MFC after: 1 week
Reviewed by: bz, markj
Differential Revision: https://reviews.freebsd.org/D62194
Fix typo in comment describing `feature_present(3)`
feature_present(3) checks `kern.features`, not `kern.feature`, for
feature existence.
Extremely naive readers, like GitHub's Copilot (Lite effort) take
comments at face value without actually looking at the code to make sure
the comment is correct. This can lead to very incorrect conclusions [1].
1. https://github.com/freebsd/atf/pull/242#discussion_r4746930972
MFC after: 1 week
libiconv/gbk2k: Handle GB18030SUPP correctly.
According to https://en.wikipedia.org/wiki/GB_18030#Mapping, the code
above 0x90308130 is mapped linearly to unicode 0x10000 to 0x10FFFF. It
is not handled in our iconv implemenation. We implement such mapping in
here and add some tests.
Reviewed by: kevans
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D61153
libiconv: Respect RFC 3629
RFC 3629 limits UTF-8 to U+10FFFF, which our iconv doesn't follow but
has been correctly handled in libc. As iconv is the default locale
implementation now. We should respect the standard in here.
Reviewed by: kevans
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D61152
acpi/tz: Resync cooler device after resume
A acpi_fan under tz domain can inconisist after resume. The device now
switch between D3 and D0 in suspend and resume. However, if a tz turn
off the cooler before resume, the device will still run after resume as
there is no mechanism in tz to resync activity and the cooler can
by default enter D0.
Reported by: llm-postcr
membarrier(2): do not call smp_rendezvous_cpus() with an empty mask
If the caller migrates while the mask is computed and no other thread
of the process is running, the mask is empty, and smp_rendezvous_cpus()
panics.
PR: 301240
Fixes: 4a69fc16a583 ("Add membarrier(2)")
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
membarrier(2): issue the leading fence before reading other CPUs' state
There are two problems:
- The old fence ran after the mask was computed, so a store the caller
made before the syscall could still be in its store buffer when it read
another CPU's state. A thread switched in right after that read then got
neither the IPI nor the store.
- MEMBARRIER_CMD_GLOBAL had no fence before its first pass, which marks
idle CPUs done immediately.
Fixes: 4a69fc16a583 ("Add membarrier(2)")
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
acpi/fan: Always call _FSL
Fan device can adjust the fan level itself and propogate to the APCI
Table. This however is opaque to the driver as there is no interrupt
to notify us that the fan level is chaged.
This can cause problem if we want to set the same value as the cached
one, which is all in all short-circuited.
As a result, we call _FSL unconditionally. Also, the condition is also
racy if two writes reach kernel. The value doesn't reflect the last
one. Therefore, we enlarge the critical section and use sx to protect
frequently read case.
Reported by: llm-postcr
Fixes: 116216477e8a ("acpi: Add acpi_fan")
snp(4): for snp_read(), check tty_gone() under tty lock before cv_wait()
Otherwise snp_read() might lose the wakeup from a gone tty.
Keep the unlocked tty_gone() check on entry, so that a non-blocking
read on a gone tty with an empty snoop queue returns EIO instead of
EWOULDBLOCK.
A sleeping reader whose wakeup races with the tty going away now returns
the output captured before that, instead of EIO.
Reported by: llm-postcr
Fixes: d8569724dc0d ("snp(4): wake up the readers and pollers when the tty is gone")
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
xprt_verbs.c: Add reconnect support for 2 additional cm events
This patch adds RDMA_CM_EVENT_DEVICE_REMOVAL and
RDMA_CM_EVENT_ADDR_CHANGE to RDMA_CM_EVENT_DISCONNECTED
to force a new QP.
Reported by: llm-postcr
MFC after: 1 month
Fixes: 80bee4d83637 ("nfsclrdma: Add code to support client side NFS over RDMA")
tests/sys/kern/procdesc: test pddupfd(PD_DUPFD_EXECUTABLE)
Check that the returned file descriptor references the process binary,
both for the calling process and for a child whose binary was unlinked
after exec, and that it is close-on-exec, readable and lacks the write
capability right.
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D61314
tests/sys/kern/procdesc: test pddupfd(PD_DUPFD_ME)
Check that the descriptor of the calling process is duplicated with
O_CLOEXEC set and the file shared, and that a closed descriptor
gives EBADF.
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D61314
ptrace_test: use PD_NOWAITPID in procdesc_reparent_wait_child
The test expects that, after a debugger collected the exit status of
a child created by pdfork(2), the parent cannot collect the child with
wait(2). With the zombie references, a child created without
PD_NOWAITPID is waitable by its parent, and the test only passed
because the debugger's waitpid(2) dropped the parent's reference.
proc_reap() no longer lets the debugger take the exit status away
from the parent, so the parent's wait(2) now collects the child.
Create the child with PD_NOWAITPID, which is what hides it from
wait(2) now. Since waitpid(2) does not see it either, wait for its
stop with pdwait(2). The debugger's waitpid(2) in the test then also
covers collecting a tracee that has no waitpid reference.
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D62051
procfdcat(1): utility to read content of a file opened by process
It reads the content of a regular file opened by another process, or of
its executable, using pddupfd(2) and pread(2).
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D61314
tmpfs: VOP_OPEN() should be allowed on unlinked files
There is no reason for such restriction, and other file systems do not
impose it.
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D61314
pddupfd(2): allow to open the executable
One of the common uses for sysctl kern.proc.<pid>.pathname is to
immediately open(2) the returned path to parse the image, e.g. to read
the symbols. This operation was made more reliable since introduction
of p_textdvp, but still rename or unlink of the binary cause unnecessary
failures for that.
Introduce pddupfd(pfd, PD_DUPFD_EXECUTABLE) special case that returns
read-only file descriptor to the process executable image.
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D61314