John Baldwin [Wed, 28 Sep 2022 21:01:36 +0000 (14:01 -0700)]
libc rpc: Fix mismatches in prototypes for array bounds.
Various RPC functions used a bare pointer in function prototypes to
describe fixed-length buffer arguments but used a fixed-length array
in the function definition. The manual page for these functions
describes the parameters as being fixed-length buffers, so update
the prototypes to match the definitions.
John Baldwin [Wed, 28 Sep 2022 21:00:27 +0000 (14:00 -0700)]
zlib crc32: Add prototypes for recently-added static functions.
This appeases -Wstrict-prototypes with GCC. Using a separate
prototype using the OF macro seems to be consistent with the rest of
this file which still supports pre-ANSI C.
Math Ieu [Thu, 27 Oct 2022 17:01:57 +0000 (12:01 -0500)]
split: reset errno prior to getline()
Something else may have set errno, breaking the post-getline() logic
that tries to detect the getline() error. This was initially noted in
a jail on a system that has HPET, in a jail that does not expose
/dev/hpet0 -- we see an earlier error in libc's vdso bits.
Kyle Evans [Tue, 23 Aug 2022 02:08:03 +0000 (21:08 -0500)]
split: add some tests
This should cover all of the basic functionality, as well as the recent
enhancement to use a dynamic buffer size rather than limiting patterns
and lines to MAXBSIZE.
Kyle Evans [Tue, 23 Aug 2022 02:05:58 +0000 (21:05 -0500)]
split: switch to getline() for line/pattern matching
Get rid of split's home-grown logic for growing the buffer; arbitrarily
breaking at LONG_MAX bytes instead of 65536 bytes gives us much more
wiggle room. Additionally, we'll actually fail out entirely if we can't
fit a line, which makes noticing this class of problem much easier.
Reviewed by: bapt, emaste, pauamma
Sponsored by: Klara, Inc.
13361 bhyve should mask RDT cpuid info
Reviewed by: Andy Fiddaman <andy@omnios.org>
Reviewed by: Toomas Soome <tsoome@me.com>
Approved by: Robert Mustacchi <rm@fingolfin.org>
John Baldwin [Mon, 26 Sep 2022 21:58:06 +0000 (14:58 -0700)]
cxgbe: Use secq(9) to manage the timestamp generations.
This is mostly cosmetic, but it also doesn't leave a gap of time where
no structures are valid. Instead, we permit the ISR to continue to
use the previous structure if the write to update cal_current isn't
yet visible.
John Baldwin [Mon, 26 Sep 2022 21:57:26 +0000 (14:57 -0700)]
cxgbe: Compute timestamps via sbintime_t.
This uses fixed-point math already used elsewhere in the kernel for
sub-second time values. To avoid overflows this does require updating
the calibration once a second rather than once every 30 seconds. Note
that the cxgbe driver already queries multiple registers once a second
for the statistics timers. This version also uses fewer instructions
with no branches (for the math portion) in the per-packet fast path.
cxgbe(4): Fix potential integer overflow in t4_tstmp_to_ns.
Coverity flagged this in its latest run but it is not a problem in
practice as the card's core clock would have to be > 4.2GHz for any
overflow to occur.
CID 1498303: Integer handling issues (OVERFLOW_BEFORE_WIDEN)
Potentially overflowing expression "sc->params.vpd.cclk * 1000U" with type "unsigned int" (32 bits, unsigned) is evaluated using 32-bit arithmetic, and then used in a context that expects an expression of type "uint64_t" (64 bits, unsigned).
Randall Stewart [Tue, 20 Sep 2022 19:13:16 +0000 (15:13 -0400)]
Enable M_TSTMP in Chelsio cxgbe driver by creating a mechanism that can sync the time.
Chelsio has always been recording a timestamp in the mbuf (rcv_tstmp) but
not setting the M_TSTMP bit in the mbuf flags. This is because the timestamp
was just the free running 60bit clock. This change fixes that so that
we keep a synchronization by periodically (every 30 seconds after startup)
getting the timestamp and the current nanosecond time. We always keep
several sets around and the current one we always keep the current pair
and the previous pair of timestamps. This allows us to setup a ratio
between the two so we can correctly translate the time. Note that
we use special care to split the timestamp into seconds (per the clock tick)
and nanoseconds otherwise 64bit math would overflow.
John Baldwin [Mon, 29 Aug 2022 22:35:15 +0000 (15:35 -0700)]
bhyve e1000: Sanitize transmit ring indices.
When preparing to transmit pending packets, ensure that the head (TDH)
and tail (TDT) indices are in bounds. Note that validating values
when they are written is not sufficient along as the transmit length
(TDLEN) could be changed turning a value that was valid when written
into an out of bounds value.
While here, add further restrictions to the head register (TDH). The
manual states that writing to this value while transmit is enabled can
cause unexpected behavior and that it should only be written after a
reset. As such, ignore attempts to write while transmit is active,
and also ignore writes of non-zero values. Later e1000 chipsets have
this register as read-only.
Also ignore any attempts to transmit packets if the transmit ring's
size is zero.
PR: 264567
Reported by: Robert Morris <rtm@lcs.mit.edu>
Reviewed by: emaste
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D36269
John Baldwin [Mon, 8 Aug 2022 18:21:54 +0000 (11:21 -0700)]
cxgbe: Handle requests for TLS key allocations with no TLS key storage.
If an adapter advertises support for TLS keys but an empty TLS key
storage area in on-board memory, fail the request rather than invoking
vmem_alloc on an uninitialized vmem.
John Baldwin [Tue, 8 Jun 2021 18:11:51 +0000 (11:11 -0700)]
cxgbe: De-duplicate some of the code for managing TLS key contexts.
The NIC TLS and TOE TLS modes in cxgbe(4) both work with TLS key
contexts. Previously, TOE TLS supported TLS key contexts created by
two different methods, and NIC TLS had a separate bit of code copied
from NIC TLS but specific to KTLS. Now that TOE TLS only supports
KTLS, pull common code for creating TLS key contexts and programming
them into on-card memory into t4_keyctx.c.
John Baldwin [Fri, 28 May 2021 23:49:56 +0000 (16:49 -0700)]
cxgbe tom: Remove support for non-KTLS TLS offload.
TOE TLS offload was first supported via a customized OpenSSL developed
by Chelsio with proprietary socket options prior to KTLS being present
either in FreeBSD or upstream OpenSSL. With the addition of KTLS in
both places, cxgbe's TOE driver was extended to support TLS offload
via KTLS as well. This change removes the older interface leaving
only the KTLS bindings for TOE TLS.
Since KTLS was added to TOE TLS second, it was somehat shoe-horned
into the existing code. In addition to removing the non-KTLS TLS
offload, refactor and simplify the code to assume KTLS, e.g. not
copying keys into a helper structure that mimic'ed the non-KTLS mode,
but using the KTLS session object directly when constructing key
contexts.
This also removes some unused code to send TX keys inline in work
requests for TOE TLS. This code was never enabled, and was arguably
sending the wrong thing (it was not sending the raw key context as we
do for NIC TLS when using inline keys).
John Baldwin [Thu, 14 Jul 2022 20:03:59 +0000 (13:03 -0700)]
depend-cleanup.sh: Handle kqtest being renamed to kqueue_test.
bmake will not think that object files such as read.o are out of date
due to common.h changing since the dependency is only recorded in
.depend.kqtest.read.o in an old object directory.
Reviewed by: markj
Fixes: 68fe988a40ca kqueue tests: Simplify the test runner
Sponsored by: DARPA
Differential Revision: https://reviews.freebsd.org/D35820
Yan Ka Chiu [Thu, 30 Jun 2022 17:29:45 +0000 (10:29 -0700)]
bhyve virtio-net: Allow backend type to be explicitly specified.
Surrently virtio-net uses the prefix of the backing interface to
choose the backend. This patch adds an additional option "type" to
choose the backend type explicitly. This allows greater flexibility
for end users to manage bhyve specific resources (such as by naming
the tap interfaces to more descriptive names). The option "type" is
optional. When it is not presented, the backend is derived from the
name of the backend interface.
For example, the line `-s 3,virtio-net,bsdvm0,type=tap` will create a
virtio-net device for the guest using the tap interface "bsdvm0".
Adding a new "type" option preserves the current legacy format in which
the first value after virtio-net names an instance of a backend.
Note that tap interfaces not following the pattern "tap*" will not be
created on demand via devfs cloning but must be created explicitly.
John Baldwin [Mon, 18 Apr 2022 19:48:42 +0000 (12:48 -0700)]
iscsi: Fetch limits based on a socket rather than assuming global limits.
cxgbei needs the ability to return different limits based on the
connection (e.g. if the connection is over a T5 adapter or a T6
adapter as well as factoring in the MTU).
This change plumbs through the changes in the ioctls without changing
any of the backends. The limits callback passed to icl_register now
accepts a second socket argument which holds the integer file
descriptor. To support ABI compatiblity for old binaries, the
callback should return "global" values if the socket fd is zero.
The CTL_ISCSI_LIMITS argument used with CTL_ISCSI by ctld(8) now
accepts the socket fd in a field that was previously part of a
reserved spare field. Old binaries zero this request which results in
passing a socket fd of 0 to the limits callback.
The ISCSIDREQUEST ioctl no longer returns limits. Instead, iscsid(8)
invokes a new ISCSIDLIMITS ioctl after establishing the connection via
connect(2). For ABI compat, if the old ISCSIDREQUEST is invoked, the
global limits are still fetched (with a socket fd of 0) and returned.
Ed Maste [Fri, 4 Nov 2022 15:59:49 +0000 (11:59 -0400)]
Clang: Add Diags for targets pre to i686 for -fcf-protection
Intel Control-flow Enforcement Technology (CET) provides new
instructions `endbr32/64` for the indirect branch control.
They are NOPs on i686 and new targets. We need to check for that
in case it crashes on older targets.
PR: 264497, 267401
Reviewed by: dim
MFC after: 1 week
Obtained from: LLVM commit 52516782972730ff065a34123a9d8876da08c254
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D37268
Ed Maste [Mon, 31 Oct 2022 20:38:46 +0000 (16:38 -0400)]
mount_unionfs: remove jokey cautions from man page
There are known issues with unionfs, and the mount_unionfs man page has
a cautionary statement about its use. The caution had additional
"humourous" statements like "BEWARE OF DOG" but they served only to
confuse the situation. Remove them.
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
John Baldwin [Fri, 11 Mar 2022 19:29:45 +0000 (11:29 -0800)]
arm64 hwpmc: Support restricting counters to user or kernel mode.
Support the "usr" and "os" qualifiers on arm64 events to restrict
event counting to either usermode or the kernel, respectively. If
neither qualifier is given, events are counted in both.
Reviewed by: emaste
Sponsored by: University of Cambridge, Google, Inc.
Differential Revision: https://reviews.freebsd.org/D34527
John Baldwin [Wed, 5 May 2021 20:58:23 +0000 (13:58 -0700)]
Rework compat shims in ifioctl().
Centralize logic for handling compat ioctls into two blocks of code at
the start and end of the ioctl routine. This avoids the conversion
logic being spread out both in multiple blocks in ifioctl as well as
various helper functions.
Jose Luis Duran [Wed, 2 Nov 2022 11:43:40 +0000 (08:43 -0300)]
ping_test: Fix tests ping_46 and ping6_46
If no IPv4-host, IPv4-mcast-group or IPv6-host is passed, it will
display the usage. The tests are passing because they are just checking
that the exit code is 1.
Fix the tests by checking the appropriate output message.
While here, change the description to match the output and add the
missing requirements.
Jose Luis Duran [Tue, 1 Nov 2022 08:01:36 +0000 (05:01 -0300)]
ping: Remove a vestigial notdef
It was once a function on 4.3BSD, pr_type() [1], used to convert an ICMP
"type" field to a printable string. In 4.4BSD it was superseded by
pr_icmph() [2].
NetBSD [3] and OpenBSD [4] have already removed it.
ipfw: Have NAT steal the TH_RES1 bit, instead of the TH_AE bit
The NAT module use of the tcphdr.th_x2 field now collides with the
use of this TCP header flag as AccECN (AE) bit. Use the topmost
bit instead to allow negotiation of AccECN across a NAT device.
Event: IETF 115 Hackathon
Reviewed By: #transport, tuexen
MFC after: 3 days
Approved by: re (gjb, early-MFC)
Sponsored by: NetApp, Inc.
Differential Revision: https://reviews.freebsd.org/D37300
Gordon Bergling [Mon, 7 Nov 2022 10:34:00 +0000 (11:34 +0100)]
intro.3: Document 'libstdthreads' (the ISO C11 '<threads.h>' library).
It's still relatively uncommon to see C11 '<threads.h>' being used,
but it's worth documenting, especially since FreeBSD requires a
different library for C11 threads compared to glibc (part of '-lpthread')
or musl libc (included by default).
PR: 267551
Submitted by: Alois Klink <alois plus freebsd at aloisklink dot com>
Reviewed by: pauamma
Differential Revision: https://reviews.freebsd.org/D37284
Kristof Provost [Wed, 2 Nov 2022 10:58:04 +0000 (11:58 +0100)]
bridge tests: re-enable span test
The root cause of the intermittent span test failures has been
identified as a race between sending the packet and starting the bpf
capture.
This is now resolved, so the test can be re-enabled.
Kristof Provost [Wed, 2 Nov 2022 10:55:39 +0000 (11:55 +0100)]
tests: make sniffer more robust
The Sniffer class is often used by test tools such as pft_ping to verify
that packets actually get sent where they're expected.
It starts a background thread to capture packets, but this thread needs
some time to start, leading to intermittent test failures when the
capture doesn't start before the relevant packet is sent.
Add a semaphore to ensure the Sniffer constructor doesn't return until
the capture is actually running.
Vitaliy Gusev [Sun, 23 Oct 2022 18:47:56 +0000 (14:47 -0400)]
bhyve: Handle snapshots of unconfigured virtio-net devices
In case of device reset or not configured - features_negotiated is not
set, calling calling pci_vtnet_neg_features is wrong and resume gets
"Segmentation fault".
Mitchell Horne [Fri, 28 Oct 2022 21:20:05 +0000 (18:20 -0300)]
ddb: print the actual syscall name
Some architectures will pretty-print a system call trap in the
backtrace. Rather than printing the symbol, use the syscallname()
function to pull the string from the sv_syscallnames array corresponding
to the process. This simplifies the function somewhat.
Mostly, this will result in dropping the "sys" prefix, e.g. "sys_exit"
will now be printed simply as "exit".
Make two minor tweaks to the function signature: use a u_int for the
syscall number since this is a more correct type (see the 'code' member
of struct syscall_args), and make the thread pointer the first argument.
The latter is more natural and conventional.
Suggested by: jrtc27
Reviewed by: jrtc27, markj, jhb
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D37200
Mitchell Horne [Sat, 29 Oct 2022 15:28:16 +0000 (12:28 -0300)]
linux, linux64: improve SRCS formatting
Sort the entries alphabetically, and list them with one entry per line.
This makes the diffs much cleaner when adding or removing a new entry,
as I will do in the next commit.
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Olivier Houchard [Thu, 27 Oct 2022 21:25:59 +0000 (23:25 +0200)]
arm64: Implement cpu_ptrace().
Add a minimal implementation of cpu_ptrace() for arm64. It is only used to
get/set VFP registers for 32bits binaries, as it is apparently what we use
there, instead of the MI PT_GETFPREGS/PT_SETFPREGS.
Tetsuya Uemura [Fri, 4 Nov 2022 21:49:52 +0000 (15:49 -0600)]
nxprtc: Fix timing issue with register access.
My Adafruit PCF8523 RTC on either RPi2B or RPi3B+ failed to work around
80 ~ 90 % of boot-ups, by printing the following log lines.
nxprtc0: <NXP PCF8523 RTC> at addr 0xd0 on iicbus0
nxprtc0: cannot set up timer
Warning: no time-of-day clock registered, system time will not be set accurately
This is due to pcf8523_start_timer(sc) returned non-zero in
nxprtc_start() due to a register read failure of PCF8523_R_TMR_A_FREQ or
PCF8523_R_TMR_CLKOUT or a failure to program a new value.
The pause_sbt("nxpbat") sleep was too short and caused the register
access failures.
Ed Maste [Thu, 20 Oct 2022 13:04:37 +0000 (09:04 -0400)]
Increase MAX_APIC_ID safeguard to 0x800
MAX_APIC_ID must be at least twice MAXCPU. Increase it to 0x800 so that
it is possible to set MAXCPU to 512 or 1024 in a custom kernel config
file.
Note that increasing this limit does not itself cause any allocations
to be larger; it just allows madt_parse_cpu() to process higher APIC
IDs.
APIC IDs may be sparse and so we can waste memory. This is independent
of this change, but becomes more of an issue as the maximum APIC ID
grows. This should be addressed with future work.
Reviewed by: royger
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D37067
The regnode interface is currently only built for FDT, thus not
applicable to ACPI-only kernels. Move the "regnode_if.h" include
underneath a previously existing FDT cpp segment.
syscon currently includes sys/malloc.h via header pollution from
dev/ofw/ofw_bus.h -> dev/ofw/openfirm.h. Fix the build without FDT
defined by including sys/malloc.h directly.
clang 14 doesn't properly determine that we're unconditionally returning
if we have ACPI but not FDT. Push FDT setup entirely into a new
function, much like we currently do with ACPI, and just return ENXIO if
that doesn't succeed.
The SAN interceptors simply take a bus_space_tag_t, so we're
dropping qualifiers here. const semantics with a ptr typedef mean we'd
have to drop or change the bus_space_tag_t abstraction used in the SAN
sanitizers in order to make a compatible change there, which likely
isn't worth it.
Reviewed by: andrew, markj
Sponsored by: Juniper Networks, Inc.
Sponsored by: Klara, Inc.
Specifically, when we receive a violation and we're configured to panic,
kasan_enabled gets unset before we descend into panic(). At this point,
there's no longer any reason to allow marking as kasan_shadow_check() is
disabled -- we have some inherent risk of faulting or panicking if the
system's in a bad enough state with no benefit.
Reviewed by: markj
Sponsored by: Juniper Networks, Inc.
Sponsored by: Klara, Inc.