IPv6: rc boot time improvements
If IPv6 is enabled we call rtsol on that interface so waiting in
rtsold is counterproductive; if one was to just use rtsold -F then
they are on their own for having the addresses usable during the
remaining startup time.
Rather than sleeping dad_count + 1 seconds we are now checking for
any tentative addresses on the interface and only then sleep
dad_count up-to 2 times. This should save us at least a dad_count
with the seconds with Optimistic DAD enabled (default) but there
are too many assumptions invovled anyway.
(RETRANS_TIMER in the kernel being 1000ms being one).
The reason why we need to sleep more than dad_count (1s default)
seems to be that first DAD for the link-local address clears and
only then solicited (or other global) addresses are handled.
Co-authored-by: Pouria Mousavizadeh Tehrani <pouria at FreeBSD.org>
[3 lines not shown]
amd64/vmm: Do not fall back to the VMCS for vmxctx registers
vmx_setreg() first calls vmxctx_setreg() and, if that fails, handles the
register as a VMCS field. This relies on vmxctx_setreg() failing only
for registers that are not kept in the vCPU context. Were it to reject
a value for one of its own registers, the error would be dropped and
the request passed on to vmcs_setreg(), which would fail it only
because the register has no VMCS field.
Check whether the register is kept in the vCPU context instead, and if
so return the result of vmxctx_setreg() directly. This lets
vmxctx_setreg() validate values and have its error returned as is. Do
the same in vmx_getreg(), so that the two functions read alike.
No functional change intended.
Reviewed by: markj
Approved by: markj
Sponsored by: Alchemilla Ventures Private Limited
Differential Revision: https://reviews.freebsd.org/D61954
amd64/vmm: Restore vmxctx registers through vmxctx_setreg()
vmx_vcpu_snapshot() copies the guest registers kept in the vCPU context
straight between the context and the snapshot buffer, while
VM_SET_REGISTER stores them through vmxctx_setreg(). A check added to
vmxctx_setreg() would thus not apply to values restored from a
snapshot.
Add vmxctx_snapshot_reg(), modelled on vmcs_snapshot_reg(), and use it
for every register in the vCPU context, so that both paths store values
the same way. The snapshot format does not change.
No functional change intended.
Reviewed by: markj
Approved by: markj
Sponsored by: Alchemilla Ventures Private Limited
Differential Revision: https://reviews.freebsd.org/D61953
amd64/vmm: Reject reserved DR6 bits supplied by userspace
On Intel hosts the guest's DR6 is kept in the vCPU context and loaded
into the host's register before guest entry. VM_SET_REGISTER and the
snapshot restore path store any value there. Loading a value with any
of bits 63:32 set raises #GP, which panics the host.
Fail with EINVAL instead.
Reviewed by: markj
Approved by: markj
Fixes: 65eefbe42218 (Save and restore guest debug registers.)
MFC after: 1 week
Sponsored by: Alchemilla Ventures Private Limited
Differential Revision: https://reviews.freebsd.org/D61732
libvmmapi: Compare mapping lengths in vm_mmap_memseg()
vm_mmap_memseg() returns success without mapping anything when a
mapping with the same segment, offset, protection and flags already
starts at the requested address, but it does not compare the length.
A longer request then reports success for pages it did not map, and a
shorter one for a mapping that vm_munmap_memseg() cannot remove with
the same range. No caller in the tree makes such a request.
Fail with EEXIST when the length differs, as for the other attributes,
and document that behavior. Read the existing mapping into its own
structure rather than over the arguments.
Reviewed by: markj
Approved by: markj
Fixes: 9b1aa8d622e8 (Restructure memory allocation in bhyve to support "devmem".)
Sponsored by: Alchemilla Ventures Private Limited
Differential Revision: https://reviews.freebsd.org/D61530
bhyve: Preserve string I/O registers on faults before progress
When a string I/O instruction faults on its first transfer, the emulator
injects the exception but still writes the masked index and count back
to the guest. With a 32-bit address size in 64-bit mode this clears
the upper halves of RSI or RDI and of RCX, although no transfer
completed and the processor reports such a fault with the registers
unchanged.
Return before updating the registers whenever no transfer completed,
whether an error, a guest fault or an injected exception stopped the
first one. Exception injection has already restarted the instruction.
A repeated instruction with a zero count is handled as before.
Reviewed by: markj
Approved by: markj
Sponsored by: Alchemilla Ventures Private Limited
Differential Revision: https://reviews.freebsd.org/D61499
bhyve: Preserve upper RAX bits for byte and word input
Scalar IN merges the input into a 32-bit EAX temporary and writes that
value to RAX. This clears bits 63:32 for byte and word inputs, which
must preserve the bits outside AL or AX.
Use vie_update_register() to update the accumulator at the operand
width. This preserves the remaining bits for byte and word inputs and
retains zero-extension for dword inputs.
Reviewed by: markj
Approved by: markj
Sponsored by: Alchemilla Ventures Private Limited
Differential Revision: https://reviews.freebsd.org/D61498
route/fib_algo: Fix nexthop reference leak on FLM_BATCH
handle_rtable_change_cb() references the new nexthop before calling
the algorithm. If the algorithm asks to batch the change by
returning FLM_BATCH, queue_rtable_change() references the same
nexthop again for the queued entry, while apply_rtable_changes()
only unreferences the old nexthop of each entry.
Reference new nhop once in handle_rtable_change_cb(), before
deciding whether the change is queued or passed to the algorithm,
and do not reference it again in fill_change_entry(). This also
leaves the queue reallocation as the only way for
queue_rtable_change() to fail.
Currently, dxr is the only algorithm returning FLM_BATCH.
Fixes: 6b8ef0d428c9 ("Add batched update support for the fib algo.")
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D61577
[2 lines not shown]
rtnetlink: Use default weight for unset weights in NHA_GROUP
newnhg() copied the weights of a nhgrp as is and a group
whose members all have a zero weight, which is what
userland sends when it leaves the weight unset, made
calc_min_mpath_slots_fast() divide by zero.
Therefore replace weight of zero with RT_DEFAULT_WEIGHT.
While here, return early from calc_min_mpath_slots_fast()
if all weights are zero.
MFC after: 3 days
Fixes: 7e5bf68495cc ("netlink: add netlink support")
(cherry picked from commit 1db6e2c6c3554efe5acdcc20bc7aa889e1efe372)
route/fib_algo: Fix nexthop reference leak on FLM_BATCH
handle_rtable_change_cb() references the new nexthop before calling
the algorithm. If the algorithm asks to batch the change by
returning FLM_BATCH, queue_rtable_change() references the same
nexthop again for the queued entry, while apply_rtable_changes()
only unreferences the old nexthop of each entry.
Reference new nhop once in handle_rtable_change_cb(), before
deciding whether the change is queued or passed to the algorithm,
and do not reference it again in fill_change_entry(). This also
leaves the queue reallocation as the only way for
queue_rtable_change() to fail.
Currently, dxr is the only algorithm returning FLM_BATCH.
Fixes: 6b8ef0d428c9 ("Add batched update support for the fib algo.")
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D61577
[2 lines not shown]
rtnetlink: Use default weight for unset weights in NHA_GROUP
newnhg() copied the weights of a nhgrp as is and a group
whose members all have a zero weight, which is what
userland sends when it leaves the weight unset, made
calc_min_mpath_slots_fast() divide by zero.
Therefore replace weight of zero with RT_DEFAULT_WEIGHT.
While here, return early from calc_min_mpath_slots_fast()
if all weights are zero.
MFC after: 3 days
Fixes: 7e5bf68495cc ("netlink: add netlink support")
(cherry picked from commit 1db6e2c6c3554efe5acdcc20bc7aa889e1efe372)
routing: Fix nhop double free in rib_copy_route()
add_route_flags() consumes the nexthop reference on every
failure path, so nhop_free() in rib_copy_route() releases it for
the second time.
This is reachable when growing net.fibs while two existing fibs
hold the same pinned prefix.
MFC after: 3 days
Fixes: 40503b792f7e ("routing: populate fibs with interface...")
(cherry picked from commit efa14ab698fe5c3a1586aec006f98e3781f4af78)
bcm2835_fbd: Use the pixel order to choose the 32 bpp palette
Recent Raspberry Pi firmware acts on the pixel order requested through
the mailbox, which older firmware ignored. The order that ends up in
the framebuffer is the requested one combined with framebuffer_swap in
config.txt: when they are the same the red component is in bits 0-7 of
a 32 bpp pixel, when they differ it is in bits 16-23. framebuffer_swap
defaults to on and the firmware reports it as bcm2708_fb.fbswap=1 in
the bootargs.
U-Boot always requests RGB, so with the default config.txt the pixels
have red in bits 0-7. The driver however always configured vt(4) with
red in bits 16-23 for 32 bpp, so red and blue were swapped on the
console.
The firmware does not report the resulting order, only the requested
one, so read the pixel order with GET_PIXEL_ORDER and combine it with
fbswap. If the pixel order cannot be read the previous behavior is
kept. The 24 bpp case is unchanged.
[6 lines not shown]
arm64: Reject user-mode faults on kernel addresses
On a CPU without FEAT_E0PD, a user-mode store to a mapped kernel
address takes a permission fault, which data_abort() passes to
pmap_fault() with the process's pmap. pmap_pte() then finds the user
mapping whose address has the same low-order bits. If that mapping is
writable, pmap_fault() marks it dirty, although nothing wrote it, and
returns KERN_SUCCESS. The store is retried and faults again, so the
thread spins instead of receiving SIGSEGV. Access flag faults, which
loads also take, have the same flaw when a kernel mapping lacks
ATTR_AF.
Like amd64's trap_pfault(), send SIGSEGV for a user-mode fault in the
kernel address space without calling pmap_fault() or vm_fault_trap().
Also, in pmap_fault(), assert that a kernel address comes with the
kernel pmap and a user address with a user pmap.
Found by: Claude Code (Opus 5.5)
[3 lines not shown]
contrib/lutok: upgrade to 0.7.0
This is a large cleanup release which has a number of changes that
should be largely transparent to end-users of lutok.
Please see NEWS for more details, as well as the vendor import commit.
MFC after: 1 week
Merge commit 'a1e3c85b0684e1a1896fbf811a894a45e658ec83'
lutok: import lutok-0.7.0
This change adds lutok lutok-0.7.0 from [upstream][1].
The lutok-0.7.0 artifact was been verified by [SHA256 checksum][3].
This is a major cleanup release. A lot of credit goes to mchoo@ for all of the
hard work submitted in #13 🎉.
The API should not change in a noticeable way to consumers, e.g., a number of
"transparent" changes like const poisoning was done with methods, etc.
Iterative builds will require rebuilding lutok from scratch--which should
happen naturally, given how header dependencies [should] be treated with make.
More information about the release (from a high level) can be found in
the [release notes][4].
Updated via [`update_lutok.sh`][4] like: `update_lutok.sh 0.7.0 lutok-0.7.0`.
[4 lines not shown]
rtwn: move rtwn_get_qmap + write register to rtwn_set_qmap
Upcoming chipset support changes the definition of the register.
So instead of having the abstraction be "return the qmap to write
to the register", change it to "set the qmap however the chipset
wants it to be."
Reviewed by: adrian
Differential Revision: https://reviews.freebsd.org/D61928
Tested on: RTL8821AU (adrian)
syslogd: Create one forwarding socket per address pair
For each address a forwarding destination resolves to,
make_forw_socket_array() creates a socket bound to the address of each
listening socket and connects it to the destination. The same
<laddr, raddr> pair can come up more than once for one rule: the
resolver may return an address twice, e.g. when a host name appears on
several /etc/hosts lines for one IP, and several listening sockets may
be bound to one address. connect() then fails with EADDRINUSE.
maybe_dup_forw_socket() only searches the rules parsed earlier, so the
casper process exits and syslogd dies with "Failed to xfer
configuration nvlist" on every start and reload.
Skip address pairs the rule already has a socket for. A second socket
would add nothing, and with -A it would send each message twice.
Reported by: Marcos Mendoza
Reviewed by: markj
Fixes: ae4f708f0b38 ("syslogd: Ensure that forwarded...")
[4 lines not shown]
tzcode: Avoid integer truncation resulting in wrong weekday
From a report[1] on the tz mailing list:
In timesub() the weekday is stored in (int) tm_wday before reduction
modulo seven (DAYSPERWEEK). Previously this could overflow a 32-bit
int, resulting in an incorrect weekday calculation.
Calculate two additional intermediate terms modulo seven to avoid an
intermediate value that does not fit in 32 bits.
We're committing this patch now so we can have something in place for
FreeBSD 15.2. If a different change is committed upstream we will
replace this.
[1] https://lists.iana.org/hyperkitty/list/tz@iana.org/thread/O3RZGBKSO5GXBFDZKW2JXO3OQIIGYBF3/
Approved by: re (cperciva)
PR: 300977
[6 lines not shown]
tcp: count only the SACK blocks that fit in tcp_maxseg()
tcp_addoptions() sends only the SACK blocks that fit in TCP_MAXOLEN.
tcp_maxseg() counted every pending block and clamped the total, so
without timestamps and with five or more blocks pending it came out 4
bytes below the segment tcp_output() sends. Limited transmit after an
RTO then sent one full segment and failed the "sent too much" KASSERT.
Approved by: re (cperciva)
PR: 282605
Approved by: adrian (mentor)
Signed-off-by: Nick Price <nprice at FreeBSD.org>
Reviewed by: tuexen, glebius, adrian
Differential Revision: https://reviews.freebsd.org/D60460
(cherry picked from commit d3b02115d4b373c719d9a716da38d94511de3f07)
(cherry picked from commit aacae7b35a22a56e187a0a41db231d63ca9cefb6)
tcp: improve consistency
Use an inline function tcp_adapt_iss_check() to perform the check
consistently instead of replicating the code multiple times. These
checks already became inconsistent.
A fix for PR 298560 requires more calls to tcp_adapt_iss_check().
Approved by: re (cperciva)
Reviewed by: Peter Lei
Fixes: fa2ad70a4511 ("tcp: make ghost ACK handling more conformant")
Sponsored by: Netflix, Inc.
Differential Revision: https://reviews.freebsd.org/D61685
(cherry picked from commit e3483dbc91b59b5b2c73a4bc792fbb834c3dc111)
(cherry picked from commit 73929d1dc3b4116ca12cc3fe08fa3a9b66bf3318)
tcp: make ghost ACK handling more conformant
The latest version of draft-ietf-tcpm-tcp-ghost-acks changed
a condition. This should make no substantial difference, but makei
it compliant to the latest version of the specification.
Approved by: re (cperciva)
Reviewed by: rscheff, Peter Lei
Sponsored by: Netflix, Inc.
Differential Revision: https://reviews.freebsd.org/D58411
(cherry picked from commit fa2ad70a4511e7b379e81de82c9e51b2e0994295)
(cherry picked from commit a170546cb8d13a67ee3062114228d3df4744bbee)
tcp: improve sender side SWS avoidance
When checking for a full sized segment, take all TCP options that will
be included into account. This fixes a bug which can trigger the
"sent too much" KASSERT related to limited transmit.
Approved by: re (cperciva)
Reported by: olivier
Reviewed by: rscheff, Peter Lei
Sponsored by: Netflix, Inc.
Differential Revision: https://reviews.freebsd.org/D61605
(cherry picked from commit d174085f9f895ed444bd95120da3eff481a58f1a)
(cherry picked from commit 13357c1ee34f9f8655375714c60da8bf4881493a)
tcp bbr: improve handling of retransmissions in LAST-ACK
When performing a timer based retransmission, clear the
BBR_RWND_COLLAPSED flag. If it sticks, t_rxtshift is never incremented
resulting in unlimited retransmissions in the LAST-ACK state.
Approved by: re (cperciva)
Reported by: Illia Vynohradov
Reviewed by: Peter Lei
Sponsored by: Netflix, Inc.
Differential Revision: https://reviews.freebsd.org/D61586
(cherry picked from commit 3c6fd437b1824caeddb5f0d4570d43cf0c999c14)
(cherry picked from commit cbd17b66e64e9bdf025200c4993b8aeae6a0ebe9)
tcp bbr: improve retransmit timout calculation
The retransmission timeout should the srtt + 4 * rttvar.
The srtt is using 5 bits of fractions and rttvar is using 4 bits of
fractions, some specific shifting is required.
Approved by: re (cperciva)
Reviewed by: Peter Lei
Sponsored by: Netflix, Inc.
Differential Revision: https://reviews.freebsd.org/D61581
(cherry picked from commit 2f98793a13fe3e69cf6b698fa469550b4ba0fea1)
(cherry picked from commit ccf8e3762c3948446263ae3ef0dd98391ef9f97e)
tzcode: Avoid integer truncation resulting in wrong weekday
From a report[1] on the tz mailing list:
In timesub() the weekday is stored in (int) tm_wday before reduction
modulo seven (DAYSPERWEEK). Previously this could overflow a 32-bit
int, resulting in an incorrect weekday calculation.
Calculate two additional intermediate terms modulo seven to avoid an
intermediate value that does not fit in 32 bits.
We're committing this patch now so we can have something in place for
FreeBSD 15.2. If a different change is committed upstream we will
replace this.
[1] https://lists.iana.org/hyperkitty/list/tz@iana.org/thread/O3RZGBKSO5GXBFDZKW2JXO3OQIIGYBF3/
PR: 300977
Requested by: re (cperciva)
[4 lines not shown]