Commit graph

152111 commits

Author SHA1 Message Date
Zhenlei Huang
99e3bb555c subr_bus: Stop checking for failures from malloc(M_WAITOK)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D45852
2024-09-03 18:25:17 +08:00
Zhenlei Huang
f444db950e boottrace: Stop checking for failures from realloc(M_WAITOK)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D45852
2024-09-03 18:25:17 +08:00
Zhenlei Huang
6a2a385507 kern_fail: Stop checking for failures from fp_malloc(M_WAITOK)
`fp_malloc` is defined as a macro that redirects to `malloc`.

MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D45852
2024-09-03 18:25:16 +08:00
Jessica Clarke
b162fc3f30 gpart: Add u-boot-env alias for U-Boot's environment GPT partition UUID
This is a platform-independent UUID, and this is the name U-Boot uses.

MFC after:	1 week
2024-09-02 23:21:18 +01:00
Zhenlei Huang
3e76d05231 kernel: Add defination of .init_array and .fini_array for all other platforms
Currently these sections are not used but defined only for amd64 and
i386. Added them for all other platforms to keep all platforms in sync.
There should be no functional change.

This change is extracted from a bigger patch [1] of hselasky, with
additional fix for the order of .fini_array section.

1. https://reviews.freebsd.org/D40467

Obtained from:	hselasky
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D45214
2024-09-02 12:26:48 +08:00
Zhenlei Huang
e15b5ba77d kernel: Fix defining of .init_array and .fini_array sections
These input sections can have decimal numbers as the priority suffix.
Clang emits the '%u' form, while SORT is an alias for SORT_BY_NAME,
hence will result in wrong order of constructors / destructors in
output sections. Fix by using the correct sorting command
SORT_BY_INIT_PRIORITY instead [1].

The functions referenced by section .fini_array is in the normal order,
but been executed in the reverse order. The order is same with
.init_array section.

Currently these sections are not used, there should be no functional
change.

Note: As for the .ctors and .dtors sections, both Clang and GCC emit
the priority suffix in the form of '%05u', so there is no semantic
difference between SORT_BY_NAME and SORT_BY_INIT_PRIORITY for those
sections [2].

This fix is extracted from a bigger patch [3] of hselasky, with
additional fix for .fini_array section.

1. https://sourceware.org/binutils/docs/ld/Input-Section-Wildcards.html
2. https://reviews.llvm.org/D91187
3. https://reviews.freebsd.org/D40467

Reviewed by:	imp (previous version)
Obtained from:	hselasky
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D45194
2024-09-02 12:26:47 +08:00
Kristof Provost
0578fe4922 pf: rework pf_icmp_state_lookup() failure mode
If pf_icmp_state_lookup() finds a state but rejects it for not matching the
expected direction we should unlock the state (and NULL out *state). This
simplifies life for callers, and also ensures there's no confusion about what a
non-NULL returned state means.

Previously it could have been left in there by the caller, resulting in callers
unlocking the same state twice.

MFC after:	1 week
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-09-01 17:05:29 +02:00
Kristof Provost
3da3eb6081 pf: be less strict about icmp state checking for sloppy state tracking
Sloppy state tracking renders ICMP direction check useless
and harmful as we might see only half of the connection in
the asymmetric setups but ignore the state match.  The bug
was reported and fix was verified by Insan Praja <insan ()
ims-solusi ! com>.  Thanks!  OK mcbride, henning

MFC after:	1 week
Obtained from:	OpenBSD, mikeb <mikeb@openbsd.org>, 538596657140
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-09-01 17:05:29 +02:00
Kristof Provost
b8cd169efa pf: try to lookup the icmp state based on a correct packet descriptor
MFC after:	1 week
Obtained from:	OpenBSD, mikeb <mikeb@openbsd.org>, e467ea25dcd3
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-09-01 17:05:28 +02:00
Kristof Provost
5ab1e5f7e5 pf: improve the ICMPv6 direction check
Following bluhm's advice this changes the way we setup state keys and
perform state lookups for ICMPv6 Neighbor Discovery packets:
  - replace the NS-dst with ND target address;
  - replace the NA-src with ND target address;
  - replace the NA-dst with unspecified address if it is a multicast.

This allows pf to match Address Resolution, Neighbor Unreachability
Detection and Duplicate Address Detection packets to the corresponding
states without the need to create new ones or match unrelated ones.
As a side effect we're doing now one state table lookup for ND packets
instead of two.

Fixes a bug uncovered by one of the previous commits that virtually
breaks IPv6 connectivity after few minutes of use.

ok stsp henning, with and ok bluhm

PR:		280701
MFC after:	1 week
Obtained from:	OpenBSD, mikeb <mikeb@openbsd.org>, 2633ae8c4c8a
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-09-01 17:05:28 +02:00
Mark Johnston
61295e0985 dummymbuf: Avoid copyout of uninitialized memory from the sysctl handler
If *rulesp was initially unset, we'll allocate a new buffer and pass it
to sysctl_handle_string(), which copies the existing string out and then
copies in the new string.  We need to make sure the buffer containing
the existing rules is initialized, otherwise we leak kernel memory to
userspace.

Fix some nearby style nits while here.

Reported by:	KMSAN
Reviewed by:	igoro, kp
Fixes:		8aaffd78c0 ("Add dummymbuf module for testing purposes")
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D46493
2024-09-01 14:09:53 +00:00
Mark Johnston
7d508464f5 carp: Fix pullup checks
The conditions used to test whether a pullup is needed were inverted.

While here:
- Fix a bogus assignment to "iplen": it's already initialized to *offp.
- Use in_cksum_skip() instead of manually adjusting the data pointer.
  Otherwise the mbuf is temporarily in an invalid state, since m_len
  isn't updated to match.

Reported by:	KMSAN
Reviewed by:	kp
Sponsored by:	Klara, Inc.
Fixes:		3711515467 ("carp: support VRRPv3")
Differential Revision:	https://reviews.freebsd.org/D46492
2024-09-01 14:09:53 +00:00
Mark Johnston
cef5f43f81 vmm: Use make_dev_s() to create vmm devices
This avoids creating windows where a device file is accessible but the
device-specific field is not set.

Now that vmmdev_mtx is a sleepable lock, avoid dropping it while
creating devices files.  This makes it easier to handle races and
simplifies some code; for example, the VSC_LINKED flag is no longer
needed.

Suggested by:	jhb
Reviewed by:	imp, jhb
Differential Revision:	https://reviews.freebsd.org/D46488
2024-09-01 14:09:17 +00:00
Mark Johnston
887c0877a6 vmm: Use an sx lock for vmmdev_mtx
This will make it easier to atomically create the device file and set
its si_drv1 member.

Reviewed by:	jhb
Differential Revision:	https://reviews.freebsd.org/D46487
2024-09-01 14:03:16 +00:00
Mark Johnston
4008758105 vmm: Validate credentials when opening a vmmdev
Rather than performing privilege checks after a specific VM's device
file is opened, do it once at the time the device file is opened.  This
means that one can continue to access a VM via its device fd after
attaching to a jail which does not have vmm enabled, but this seems like
a reasonable semantic to have anyway.

Reviewed by:	jhb
Differential Revision:	https://reviews.freebsd.org/D46486
2024-09-01 14:03:16 +00:00
Mark Johnston
133a513ddc vmm: Make vmm_dev.h more self-contained
vmm.h is required for VM_MAX_SUFFIXLEN.  vmm_snapshot.h is required for
struct vm_snapshot_meta.

This is a prerequisite for including vmm_dev.h in the headers parsed by
libsysdecode.

Reviewed by:	jhb
Differential Revision:	https://reviews.freebsd.org/D46485
2024-09-01 14:03:15 +00:00
Mark Johnston
780675e1be arm64: Fix the VM_MAX_NAMELEN definition
The maximum VM name length has changed since the arm64 vmm code was
forked.  For now, just sync with the amd64 definitions, since they
permit longer VM names.  As arm64/vmm is implemented only in main, I
won't bother dealing with backward compat.

Reviewed by:	jhb
Differential Revision:	https://reviews.freebsd.org/D46484
2024-09-01 14:03:15 +00:00
Bjoern A. Zeeb
a800b5bcd1 sdiodevs: add more vendors and devices
Add IDs for Realtek, Atheros (QCA), and Mediatek.
While I am not sure we'll ever support the ath10k and possibly mt76
SDIO devices, rtw88 ones can be found with SoCs (e.g. r2s-plus) and
are actively being worked on.

Update Broadcom/Cypress entries.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D46460
2024-08-31 21:38:57 +00:00
Bjoern A. Zeeb
b4ef1b1be7 tools/sdiodevs2h.awk: introduce palias
Some of the defined names are not the direct 1:1 mapping with vendor
and device names used by Linux device drivers.
Introduce a p(roduct)alias so we can map the one device entry I came
across without much extra hassle and generate a name device drivers
know about:
palias BROADCOM_CYPRESS_43439  CYPRESS_43439

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D46455
2024-08-31 21:37:53 +00:00
Bjoern A. Zeeb
1847e63d63 LinuxKPI: add no_printk
Add a version of no_printk(), which seems to be there to have format
string checking while never calling the printk.  It seems a very weird
thing and it needs a return code and for some reason my initial
while (0) { } version hadn't worked while porting over new code but
could have been further downstream format string problems.
if (0) seems to do the job though I would have expected that to more
likely simply get optimised out without any futher format checking.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D46463
2024-08-31 21:36:01 +00:00
Bjoern A. Zeeb
273cf7d363 LinuxKPI: add eth_hdr()
Add an implementation of eth_hdr() needed by a wireless driver.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D46462
2024-08-31 21:35:02 +00:00
Bjoern A. Zeeb
8adb745dc9 LinuxKPI: add ENAVAIL error code
Used by an updated wireless driver.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D46461
2024-08-31 21:34:01 +00:00
Bjoern A. Zeeb
f29e915bc0 LinuxKPI: add get_random_u8()
Add a get_random_u8() implementation following the u36 and u64 versions.
We'll likely want to macro-ify them in the future and add all the types
which makes sense just to be done.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D46464
2024-08-31 21:32:11 +00:00
Jean-François Hren
d7c87526b1 tpm: Register TPM as entropy source
TPM is defined as an entropy and is called every 10 seconds. However it
was not registered and calls were discarded.

Signed-off-by: Jean-François Hren <jean-francois.hren@stormshield.eu>

MFC after:	1 week
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1398
2024-08-31 10:53:02 -07:00
Mitchell Horne
38a08e45f1 arm64: fix L1 pindex calculation in pmap_growkernel()
Use the pmap_l1_pindex() macro which accounts for the NUL2E offset.
While here, use pmap_l2_pindex() macro further down (no change).

Prompted by pull request and commit 2e33abc354, making the change for
the riscv pmap.
2024-08-30 16:39:56 -03:00
Jose Luis Duran
973bbdab47 mk: Add a BTI-report linker feature
Add support for specifying how to report the missing Branch Target
Identification (BTI) linker feature on AArch64.

For:

Kernel:    bti-report on when the linker supports it
Userspace: bti-report on when the linker supports it and
           BTI_REPORT_ERROR is defined

Fixes:	43e8849bc2 ("conf: Enable BTI checking in the arm64 kernel")
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1393
2024-08-30 16:03:17 +00:00
Navdeep Parhar
9fdb683d92 cxgbe/iw_cxgbe: Fail early in some callbacks when the RNIC is stopped.
Stop allocating new resources when the RNIC is stopped but continue to
allow previously allocated resources to be freed.  Note that t4_tom's
uld_stop tears down all TOE connections, including those being used for
iWARP, and that triggers the cleanup of iWARP resources.

Fail post_send/post_recv early too to avoid the SQ doorbell.

MFC after:	1 week
Sponsored by:	Chelsio Communications
2024-08-30 08:31:45 -07:00
Mark Johnston
28294dc924 Revert "ipsec: Drain async ipsec_offload work when destroying a vnet"
This change can cause a deadlock in some cases, since it's possible for
VNET teardown to happen in the context of taskqueue_thread, and
ipsec_accel_sync() drains taskqueue_thread's work queue.

This reverts commit e196b12f4d.
2024-08-30 15:00:16 +00:00
Mark Johnston
e196b12f4d ipsec: Drain async ipsec_offload work when destroying a vnet
The ipsec_offload code in some cases releases object references in an
asynchronous context where it needs to set the current VNET.  Make sure
that all such work completes before the VNET is actually destroyed,
otherwise a use-after-free is possible.

Reported by:	KASAN
Reviewed by:	kib
Fixes:		ef2a572bf6 ("ipsec_offload: kernel infrastructure")
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D46483
2024-08-30 13:08:20 +00:00
Zhenlei Huang
356be1348d kernel: Make some compile time constant variables const
Those variables are not going to be changed at runtime. Make them const
to avoid potential overwriting. This will also help spotting accidental
global variables shadowing, since the variable's name such as `version`
is short and commonly used.

This change was inspired by reviewing khng's work D44760.

No functional change intended.

MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D45227
2024-08-30 18:26:30 +08:00
Michael Tuexen
b2044c4557 tcp rack, bbr: improve handling of soft errors
Do not report an error, if it is stored as a soft error. This avoids,
for example, the dropping of TCP connections using an interface,
while enabling or disabling LRO on that interface.

Reviewed by:		cc
MFC after:		1 week
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D46427
2024-08-30 09:26:41 +02:00
Franco Fichtner
4b6e76eff8 u3g: add SIERRA AC340U
Pull request:	https://github.com/freebsd/freebsd-src/pull/1397
MFC after:	3 days
2024-08-30 00:05:30 -07:00
Navdeep Parhar
3b4dcc0feb cxgbe/iw_cxgbe: c4iw_connect should return a negative errno.
Avoid a pointless assignment while here.

MFC after:	1 week
Sponsored by:	Chelsio Communications
2024-08-29 17:58:36 -07:00
Konstantin Belousov
7e49f04c88 rangelocks: stop caching per-thread rl_q_entry
This should reduce the frequency of smr_synchronize() calls, that
otherwise occur on almost each rangelock unlock.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
Differential revision:	https://reviews.freebsd.org/D46482
2024-08-30 00:32:48 +03:00
Wuyang Chung
835cd17f87 riscv: use pmap_l1_pindex to calculate the pindex of the l2 page table page
Reviewed by:	mhorne
MFC after:	1 week
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1360
2024-08-29 12:20:29 -03:00
Wuyang Chung
2e33abc354 riscv: fix a bug in calculating the pindex for L1 page
pmap_l1_pindex(va) expands to: ((va >> L1_SHIFT) + NUL2E)

Reviewed by:	mhorne
MFC after:	1 week
Fixes:		a4667e09e6 ("Convert vm_page_alloc() callers to...")
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1360
2024-08-29 12:20:28 -03:00
Wuyang Chung
05cf677bb8 riscv: remove a redundant MPASS test in _pmap_unwire_ptp()
It is guaranteed by the else if condition.

Reviewed by:	mhorne
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1355
2024-08-29 12:20:28 -03:00
Mark Johnston
12500c1428 agp: Set the driver-specific field correctly
PR:		281035
Reviewed by:	mhorne
MFC after:	1 week
Fixes:		437ea82ce7 ("agp: Handle multiple devices more gracefully")
2024-08-29 13:12:19 +00:00
Mark Johnston
0c605af3f9 netinet: Explicitly disallow connections to the unspecified address
If the V_connect_ifaddr_wild sysctl says that we shouldn't infer a
destination address, return an error.  Otherwise it's possible for use
of an unspecified foreign address to trigger a subsequent assertion
failure, for example in in_pcblookup_hash_locked().

Similarly, if no interface addresses are assigned, fail quickly upon an
attempt to connect to the unspecified address.

Reported by:	Shawn Webb <shawn.webb@hardenedbsd.org>
MFC after:	2 weeks
Reviewed by:	zlei, allanjude, emaste
Differential Revision:	https://reviews.freebsd.org/D46454
2024-08-29 13:11:15 +00:00
Andrew Turner
8b01728431 arm64: Fix the ESR_EL1_op2 value
This leads to an unallocated register. Fix the value to point to
ESR_EL1.

Sponsored by:	Arm Ltd
2024-08-29 10:42:34 +00:00
Navdeep Parhar
3f250bb6f0 cxgbe/iw_cxgbe: Tidy up a couple of CTRs in c4iw_create_listen.
backlog is an int and not a string.  While here, fix an adjacent CTR
that was spread over two lines even though it fits in one.

MFC after:	1 week
Sponsored by:	Chelsio Communications
2024-08-28 19:40:04 -07:00
Kevin Bowling
f622dc5dae x86: Detect NVMM hypervisor
MFC after:	1 week
2024-08-28 13:39:07 -07:00
Mark Johnston
cb91dc5095 atomic: Fix the cast in the atomic_load_consume() interceptor
As in commit c7a7e997d2, we should permit loading from a pointer to
uintptr_t.

Note that the other atomic_*_ptr() interfaces currently require casting
regardless, only those defined in atomic_common.h try to be generic.

Reported by:	jrtc27
MFC after:	1 week
2024-08-28 19:31:03 +00:00
Navdeep Parhar
8254a276ad cxgbe/iw_cxgbe: Replace the fatal error flag with a stopped flag.
Now that suspend/resume is supported by the base driver, a fatal error
isn't the only reason that the RNIC can stop abruptly.  Also, this state
is no longer permanent as it's possible to resume operations after a
stop.  Rename the flag and associated routines to match the new state of
affairs.

MFC after:	1 week
Sponsored by:	Chelsio Communications
2024-08-28 12:19:23 -07:00
Mark Johnston
a852dc580c vmm: Harmonize compat ioctl definitions
For compat ioctls and structures, we use a mix of suffixes: _old,
_fbsd<version>, _<version>.  Standardize on _<version> to make things
more consistent.  No functional change intended.

Reported by:	jhb
Reviewed by:	corvink, jhb
Differential Revision:	https://reviews.freebsd.org/D46449
2024-08-28 19:12:32 +00:00
Mark Johnston
72ea8f41e1 vmm: Let devmem devices reference the VM credential
Otherwise they are globally visible (in jails with allow.vmm set),
instead of being restricted to the jail to which the VM belongs.

Reviewed by:	corvink, jhb
Differential Revision:	https://reviews.freebsd.org/D46448
2024-08-28 19:12:16 +00:00
Mark Johnston
c23da668fa vmm: Be more consistent with the credential used for VM lookup
vmmdev_lookup() is used from sysctl context to find a VM by name.
There, a reference credential is already passed, so use that instead of
assuming that it's the same as curthread->td_ucred, even though that's
true today.  No functional change intended.

Reviewed by:	corvink, jhb
Differential Revision:	https://reviews.freebsd.org/D46447
2024-08-28 18:57:33 +00:00
Mark Johnston
f4002135a2 vmm: Remove an unneeded lookup in devmem_create_cdev()
The sole caller of this function already holds a pointer to the VM's
softc, so rather than passing the VM name and looking it up again, just
pass the softc pointer directly.  This function is only called from an
ioctl context, so the softc structure will remain live.

Reviewed by:	corvink, jhb
Differential Revision:	https://reviews.freebsd.org/D46446
2024-08-28 18:57:21 +00:00
Mark Johnston
063a8bd908 vmm: Factor most of sysctl_vmm_destroy() into a separate function
This will make it easy to share code with an ioctl handler which creates
VMs.  No functional change intended.

Reviewed by:	corvink, jhb
Differential Revision:	https://reviews.freebsd.org/D46445
2024-08-28 18:57:12 +00:00
Mark Johnston
d581970976 vmm: Factor most of sysctl_vmm_create() out into a separate function
This will make it easy to share code with an ioctl handler which creates
VMs.  No functional change intended.

Reviewed by:	corvink, jhb
Differential Revision:	https://reviews.freebsd.org/D46444
2024-08-28 18:57:03 +00:00