acpi: Tasks: Precisely report the maximum number of slots used
To this end, store the actual number of busy slots instead of the index
of the final slot selected (off by one), and fix races when updating
'acpi_tasks_hiwater'.
The race is that it could happen that a first thread enqueued a task at
a higher index than the current maximum, followed by a second one
enqueuing at some even higher index, with the first thread updating
'acpi_tasks_hiwater' while the second was exactly after the 'if (i >
acpi_tasks_hiwater)' but just before attempting the atomic_cmpset_int()
that updates 'acpi_task_hiwater', which then would fail silently (the
return value was ignored) leading to the real maximum not being
recorded.
Fix the race by simply testing the return value of atomic_cmpset_int()
and retrying. Use an explicit atomic_load_int() for the guard (that
compiles to a regular load, so this change is cosmetic).
[6 lines not shown]
dwc: fix DEBUG macro name
It conflicts with the general "DEBUG" macro defined as an option in LINT
builds. Since this is actually unused, just rename it to GMAC_DEBUG.
Reviewed by: manu
MFC after: 3 days
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D44102
(cherry picked from commit fae39d8da9d5ddf4239fc2143522340c941f6612)
hwpmc: tidy pcd_finalize methods
Make them a little bit more consistent with one another in terms of what
is done:
- Add/reduce assertions to what is most useful: a loop to ensure
pcpu_fini freed everything
- Add PMCDBG trace entries
The exception is the dmc620/cmn600 classes, which behave a little
differently, so leave them untouched.
Reviewed by: jkoshy
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D41270
(cherry picked from commit 90a6ea5ca0b1b578e265d2479511bd04347f9510)
mmc_fdt: handle broken-cd property
The documented properties [1] for card-detection are one of:
- cd-gpios
- non-removable
- broken-cd
In cd_setup() we handle the first two, but not the latter, resulting in
a silently undetected card on an affected system.
To work around this, force cd_disabled when broken-cd is specified, so
that the card detect helper function gets to run. A more complete
solution would implement some kind of polling mechanism to detect the
card's presence or removal.
Some variants of the Allwinner D1, such as the Lichee Rv, specify this
property in the mmc0 device node.
[1] sys/contrib/device-tree/Bindings/mmc/mmc-controller.yaml
[9 lines not shown]
amd64: use pc_is_full() helper function
This seems to have been missed in a few places. No functional change
intended.
Reviewed by: kib
MFC after: 1 week
Fixes: 4d90a5afc51b ("sys: Consolidate common implementation details...")
Differential Revision: https://reviews.freebsd.org/D45920
(cherry picked from commit e7f849e25bbca9a74c9d3a5b633f9cd01ba95a55)
acpi: Tasks: Ensure sane values for number of tasks and threads
Make sure that these are set to sane values even on silly tunables:
- There must be at least one thread to process the 'acpi_taskq'.
- Use the ACPI_MAX_TASKS default when a negative number of tasks was
specified. This avoids common pilot errors causing a bogus huge memory
allocation for acpi_tasks[].
Reviewed by: obiwac (older version)
Differential Revision: https://reviews.freebsd.org/D60373
acpi: Tasks: Use M_WAITOK to allocate the taskqueue
Memory failure at this point normally does not happen except if the
kernel is running on a machine with a too tiny amount of memory, in
which case it is likely to panic or to be unusable anyway. However,
letting it panic here with a NULL pointer dereference is not very
helpful. Instead, use M_WAITOK, hoping the memory allocator itself will
indicate the low memory condition if it cannot succeed (if it does not,
it should be changed to).
Reviewed by: obiwac
Differential revision: https://reviews.freebsd.org/D60379
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]
vtnet: honor the advertised MTU limit on attach
When VIRTIO_NET_F_MTU is negotiated, virtio_net_config.mtu specifies
the maximum MTU the driver may use. vtnet_ioctl_mtu() enforces this
limit for subsequent MTU changes, but ether_ifattach() unconditionally
initializes the interface MTU to ETHERMTU (1500).
So a device advertising a maximum below 1500 starts with an MTU above
its limit. So make sure to set the initial MTU no larger than
vtnet_max_mtu. That is, for vtnet_max_mtu less than 1500
interface MTU will be set to this value, otherwise the current behaviour
is preserved, MTU will be set to 1500.
Reviewed by: kfv, tuexen
Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D60980
(cherry picked from commit 0974ef03b43f279f16289ad4d5be3a03923983ea)
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