callout: optionally spread callouts to all CPUs
By default, if the caller has not used one of the _on() or _cpucpu()
variants of the callout API, the system assigns the callout to CPU0.
Having most callouts running on CPU0 can be problematic in terms of
the amount of CPU time spent executing callouts can have an unfair
impact to CPU0, and a critical callout (like lacp_tick) is certain
to land on the same CPU as everything else, so it is more likely
to be delayed.
This change introduces a change to callout_init* where if
kern.callout_spread is non-zero, callouts initialized after SMP startup
are distributed among CPUs.
This is left as disabled by default, as it may reveal any latent
synchronization bugs that were previously hidden, e.g., two callout handlers
which were always accidentally serialized against each other before may now
run concurrently. It also may cause a slight increase in power consumption
[6 lines not shown]
ip6_forward: Free the ICMPv6 copy on all error paths
ip6_forward() keeps a copy of the start of the packet in case it has
to send an ICMPv6 error. Every exit must either pass the copy to
icmp6_error() or icmp6_redirect_output(), or free it. Three exits did
neither and leaked the copy:
- the destination scope check, when a packet would leave the zone of
its destination address;
- a packet that a pfil hook redirected to a local address, which is
queued for local input;
- a packet whose checksum has to be computed here and whose last
header offset is not valid.
Free the copy in these three cases.
Reviewed by: tuexen, pouria
Fixes: 8a006adb2441 ("Add support for IPv6 to ipfw fwd...")
Fixes: bcb298fa9e23 ("sctp, tcp, udp: improve deferred computation...")
[3 lines not shown]
if_geneve: Read the outer IP header from the start of the packet
The offset passed to geneve_udp_input() points at the UDP header,
which for IPv6 comes after any extension headers.
The outer header is always at the start of the mbuf.
Reported by: llm-postcr
Fixes: e44d2e941e8e ("if_geneve: Add Support for Geneve (RFC8926)")
vmm: Route MMIO-to-MMIO MOVS by GPA
emulate_movs() uses the memread and memwrite callbacks selected from
the faulting GPA for both operands of an MMIO-to-MMIO MOVS. A guest
can therefore make the local APIC handler write to a GPA outside the
APIC page, which trips the offset assertion in vlapic_write() on
INVARIANTS kernels.
Dispatch each MMIO read and write according to its GPA. This allows
MOVS between in-kernel devices. During in-kernel emulation, return
EINVAL if an MMIO operand lies outside those devices' ranges.
Reported by: llm-postcr
Reviewed by: markj
MFC after: 1 week
Sponsored by: Alchemilla Ventures Private Limited
Differential Revision: https://reviews.freebsd.org/D61495
ure: Initialize ifm_active in ure_ifmedia_sts
Most ure(4) devices use mii; 8156 and 8156B do not and have special
cases throughout the driver.
ifmedia_ioctl() sets ifmr->ifm_active to ifm_cur->ifm_media before
calling the status callback. The 8156 case in ure_ifmedia_sts ORs in
the subtype and duplex flags to the existing value, which may result in
garbage values.
Instead, start by setting ifm_active to just IFM_ETHER before ORing in
other bits.
Reported by: llm-postcr
Reviewed by: kbowling, pouria
Fixes: d4cf41a99b40 ("Add support for RTL8153B, RTL8156 and RTL8156B to if_ure(4).")
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D61158
nuageinit; Skip SSH keys and doas/sudo if adduser fails
Previously we would still try to add SSH keys after a failed adduser,
which would result in an uncaught Lua error, causing the remainder of
the setup to be skipped.
Reported by: llm-postcr
Reviewed by: dtxdf, bapt
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D61441
kern_revoke: remove always UIO_USERSPACE pathseg argument
In FreeBSD and CheriBSD pathseg was always UIO_USERSPACE and when I
extracted the patch for FreeBSD, I failed to propogate it to NAMEI.
Since it's always the same, remove it as needless generality.
Reported by: netchild
Sponsored by: Innovate UK
Fixes: 7273d80ba18c ("vfs_syscalls.c: add kern_ and user_ implementations")
clock_gettime: Add capability mode check
clock_gettime is permitted in capability mode, and it calls get_cputime
if clock_id is negative. get_cputime did not check the target pid in
capability mode.
Reported by: llm-postcr
Reviewed by: markj, Osvaldo Janeri Filho <ojanerif at amd.com>
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D61469
hwpmc: switch in process PMCs on a thread's first run
A new thread starts in fork_exit(), not mi_switch(), so its PMCs are
not loaded until its next context switch. Call the switch-in hook
there.
Reviewed by: kib, Osvaldo Janeri Filho <ojanerif at amd.com>, mhorne
MFC after: 1 week
Sponsored by: Advanced Micro Devices, Inc.
Differential Revision: https://reviews.freebsd.org/D60565
lan867xphy: Add silicon rev D0 configuration
Apply hardware revision D0 configuration from Microchip AN1699
(Revision G). The LSCTL (0x0012) write is deferred until link state
reporting is implemented.
Sponsored by: The FreeBSD Foundation
Sponsored by: Microchip (Hardware)
Differential Revision: https://reviews.freebsd.org/D61269
bhyve/riscv: fix PCIe FDT interrupt-map entry stride
In bhyve arm64, each PCIe interrupt-map entry spans 10 cells because the
ARM GIC specifies #interrupt-cells = 3. On RISC-V, the APLIC uses
#interrupt-cells = 2, so each entry spans only 9 cells.
When the PCIe FDT code was originally adapted from arm64, the property
allocation size and cell assignments were reduced to 9 cells per entry,
but the loop multiplier retained the 10-cell stride. This caused the
interrupt-map array to be packed incorrectly with gaps, breaking PCI
interrupt routing in guest operating systems and overflowing the
allocation by 16 cells.
Correct the loop stride to 9 cells so the interrupt map is properly
formed.
Reviewed by: jrtc27
Fixes: 7ab1a32cd43c ("bhyve/riscv: Initial import")
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D61473
if_geneve: Ignore reserved bits on receive
RFC 8926 section 3.4 requires the reserved fields of geneve header
to be ignored on receipt.
While here, remove the needless htons() from the version check, as
geneve_ver is a 2-bit bitfield with no byte order.
Fixes: e44d2e941e8e ("if_geneve: Add Support for Geneve (RFC8926)")
if_geneve: Do not byte-swap the option length
geneve_optlen is a 6-bit bitfield within a single byte, so it has no
byte order. Applying ntohs() to it on little-endian machines turned
an option length of 1 into 256, causing every received packet carrying
options to dropped.
PR: 300453
Reviewed by: pouria
Fixes: e44d2e941e8e ("if_geneve: Add Support for Geneve (RFC8926)")
Revert "sound/midi: Drain the mpu401 callout before device teardown"
This was committed to main by accident, but was also buggy.
This reverts commit 91539591d7f8dd8ca24ced875bd16c3ba3c7d201.
aw_sid: Add support for the H6
Add the SID of the H6. The efuse starts at 0x200 like on the other
64 bits SoCs and starts with the 16 bytes of the chip ID, which awg(4)
uses to create a MAC address when the firmware did not give it one.
The thermal sensor calibration data is not added, there is no driver
for the thermal sensors of the H6.
Tested on: H6
axp81x: Honor the enable delay of the regulators
axp8xx_regnode_enable() always reported a delay of 0, so the
regulator-enable-ramp-delay property of the FDT was ignored. On the
Pine H64 model B the Ethernet PHY is supplied by ALDO2, which has a
delay of 100ms, and awg(4) resets the controller right after enabling
it, before the PHY is ready: the soft reset timed out and the interface
did not attach. Return the delay when enabling a regulator, like the
fixed regulator driver does.
Fixes: c175fd0fe8a3 ("axp81x: Add support for AXP803")
Tested on: H6
awg: Use the MAC address of the FDT
The firmware gives the MAC address of the controller in the FDT, in the
mac-address or local-mac-address property. awg(4) only used the address
in the registers, which is set when the firmware used the controller,
and the one created from the SID. On the Pine H64 the firmware does not
initialise the Ethernet and the SID driver does not support the H6, so a
random address was created and it changed at every boot.
Use fdt_ether_get_addr(), it takes the address of the FDT and keeps the
current one when there is none.
Tested on: H6
sound/midi: Drain the mpu401 callout before device teardown
midi_uninit() frees the snd_midi that mpu401_intr() reaches through
midi_in() and midi_out(), but the callout that calls it was drained
afterwards. Drain it first, and clear M_TXPEND so that a firing handler
does not re-arm itself.
Fixes: f960b33d35da ("sound/midi: Drain the mpu401 callout")
MFC with: f960b33d35da
Sponsored by: The FreeBSD Foundation
modstat: check errno before calling feature_present
feature_present will overwrite errno if COMPAT_FREEBSD13 is not present.
Reported by: llm-postcr
Fixes: ef726c645300 ("modstat: allow compat support to fail in tests")
swapoff: don't leak vnode pointer to device
After looking up the device path, we compare the vnode to the vnode of
each swap device. Prior to this change we leaked a vnode reference to
the device we're trying to remove from the swap pool.
Effort: CHERI upstreaming
Reviewed by: kib, markj
Reported by: llm-postcr
MFC after: 3 days
Sponsored by: Innovate UK
Differential Revision: https://reviews.freebsd.org/D61464
modstat: allow compat support to fail in tests
v1 and v2 versions of stuct module_stat are now gated by COMPAT_ ifdefs
so allow the otherwise valid query to fail with EINVAL.
Effort: CHERI upstreaming
Reviewed by: markj
Reported by: llm-postcr
Sponsored by: Innovate UK
Fixes: 1ebf46ecb627 ("modstat: don't copyout while holding a lock")
Differential Revision: https://reviews.freebsd.org/D61460
amd64/vmm: Don't advertise AMD PerfMonV2 or performance counters
vmm does not handle CPUID leaf 0x80000022, so a FreeBSD guest on a
Family 19h or later host panics on "kldload hwpmc", which trusts the
PerfMonV2 bit and writes AMD_PMC_GLOBAL_CTL.
Tested by: Osvaldo Janeri Filho <ojanerif at amd.com>
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Reviewed by: markj, kib
Differential Revision: https://reviews.freebsd.org/D61141
(cherry picked from commit 8fb539b081dbfe3e93e607a5d4d36184c53c8aaf)
amd64/vmm: Don't advertise AMD PerfMonV2 or performance counters
vmm does not handle CPUID leaf 0x80000022, so a FreeBSD guest on a
Family 19h or later host panics on "kldload hwpmc", which trusts the
PerfMonV2 bit and writes AMD_PMC_GLOBAL_CTL.
Tested by: Osvaldo Janeri Filho <ojanerif at amd.com>
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Reviewed by: markj, kib
Differential Revision: https://reviews.freebsd.org/D61141
(cherry picked from commit 8fb539b081dbfe3e93e607a5d4d36184c53c8aaf)