Commit Graph

292283 Commits

Author SHA1 Message Date
Pedro F. Giffuni
1a968da448 fparseln: Update NetBSD version strings
The correponding changes (mostly ANSIfication) were done long ago locally.
No functional change.

Obtained from:	NetBSD (libutil CVS Attic)
2024-06-15 15:32:06 -05:00
Wei Hu
d0cb4674df Hyper-V: move memory alloc call for tlb hypercall out of smp_rendezvous
The allocation call could result in sleep lock violation if it is in
smp_rendezvous. Move it out. Also move the pcpu memory pointer to
vmbus_pcpu_data since it is only used on Hyper-V.

PR:		279738
Reported by:	gbe
Fixes:		2b887687ed
MFC after:	2 weeks
Sponsored by:	Microsoft
2024-06-15 14:07:58 +00:00
Peter Holm
d26c565597 stress2: Revert change accidentally added in ff4a72c159 2024-06-15 08:33:14 +02:00
Chuck Tuffli
ad9cc86bf6 linux: Translate Linux NVME ioctls to the lower layers.
The lower layers implement a ABI compatible Linux ioctl for a few of the
Linux IOCTLs. Translate them and pass them down. Since they are ABI
compatible, just use the nvme ioctl name.

Co-Authored-by: Warner Losh <imp@bsdimp.com>
Reviewed by:	chuck
Differential Revision:	https://reviews.freebsd.org/D45416
2024-06-14 16:40:20 -06:00
Warner Losh
1bce7cd885 nvme: Add Linux copatible ioctls
Add the NVME_IOCTL_ID, NVME_IOCTL_ADMIN_CMD, and NVME_IOCTL_IO_CMD Linux
compatible ioctls. These may be run on either an I/O (ns) dev or a nvme
(admin) dev. Linux allows both on either device, and programs use this
and aren't careful about having the right device open. Emulate this
feature, and implement these ioctls. The data is passed in into the
kernel in host byte order (not converted to le). Results are returned in
host order.

The timeout field is ignore, and the metadata and metadata_len fields
must be zero.

The addr field can be null, even when the data_len is non zero (FreeBSD's
ioctl interface prohibits this, Linux's just ignores the inconsistency).

Only the cdw10 is returned from the command: the status is not returned
in 'result' field. XXX need to verify that this is what Linux does on an
error signaled from the drive.

No external include file is yet available for this: most programs that
call this interface either use a linux-specific path <linux/nvme.h> or
have their own private copy of the data. It's unclear the best thing to
do.

Also, create a /dev/nvmeXnY as an alias for /dev/nvmeXnsY.

These changes allow a native build of nvme-cli to work for everything
that doesn't depend on sysfs entries in /sys, calls that use metadata,
send / receive drive data and sed functionality not in our nvme driver.

Sponsored by:		Netflix
Co-Authored-by:		Chuck Tuffli <chuck@freebsd.org>
Reviewed by:		chuck
Differential Revision:	https://reviews.freebsd.org/D45415
2024-06-14 16:40:08 -06:00
Warner Losh
5198178f3e cdefs.h: Add POSIX.1-2024 values
Sponsored by:		Netflix
2024-06-14 16:38:55 -06:00
Mark Johnston
517c585458 vm_phys: Make sure that vm_phys_enq_chunk() stays in bounds
vm_phys_enq_chunk() inserts a run of pages into the buddy queues.  When
lazy initialization is enabled, only the first page of each run is
initialized; vm_phys_enq_chunk() thus initializes the page following the
just-inserted run.

This fails to account for the possibility that the page following the
run doesn't belong to the segment.  Handle that in vm_phys_enq_chunk().

Reported by:	KASAN
Reported by:	syzbot+1097ef4cee8dfb240e31@syzkaller.appspotmail.com
Fixes:	b16b4c22d2 ("vm_page: Implement lazy page initialization")
2024-06-14 15:55:02 -04:00
Alexander Motin
80b4232924 nvme: Fix panic on detach after ce75bfcac9
MFC after: 2 weeks
2024-06-14 15:32:10 -04:00
Alexander Leidinger
2d08f6b577 rc.subr: add some sanity checks for service jails
Add some sanity checks when service jails are used in jails:
 - children.max > 0
 - children.max - children.cur > 0

The nesting is too deep at those places to have a sane formatting, so no
line wrapping at the usual column.
If someone has a better idea how to format this: feel free to go ahead.
2024-06-14 20:15:46 +02:00
Alexander Leidinger
a70ecfb117 rc.subr: add new sysv option for service jails
Clarify that the "sysvipc" svcj option inherits from the host / parent.
Add "sysvipcnew" which creates a new SysV namespace for the service
jail.
Sanity check that only one of them is used.
2024-06-14 20:15:45 +02:00
Alan Somers
2909ddd17c ctld: plug memory leaks
MFC after:	2 weeks
Reviewed by:	mav
Sponsored by:	Axcient
Reported by:	valgrind
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1288
2024-06-14 12:08:38 -06:00
Mitchell Horne
134f7b5fa9 riscv: improve commentary around initial stvec
Make it explicit why we must set the trap vector before enabling virtual
memory.

Reviewed by:	br, jhb, markj
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D45474
2024-06-14 15:02:05 -03:00
Mitchell Horne
3ff981587f riscv: Don't handle missing kernel L3 pages
This code path should never be hit, if it does it means we did not
bootstrap correctly. Turn it into a panic like we do on amd64 and arm64.

Reviewed by:	markj, jhb
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D45326
2024-06-14 15:02:05 -03:00
Mitchell Horne
0e4e77072f riscv: adjust physmem reservation
Make sure we do this BEFORE pmap_bootstrap().

Reviewed by:	markj, jhb
MFC after:	3 days
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D45325
2024-06-14 15:02:05 -03:00
John F. Carr
cadc9c7db7 boot/efi: Fix warning for non-standard formats when debugging
Add -Wno-format for zfs_module and regroup. This fixes warnings when
EFI_DEBUG is defined.

PR: 279071
Reviewed-by: imp
2024-06-14 11:11:05 -06:00
John F. Carr
97ab935d56 rk_pinctrl: fix error check
The parse_bias method returns a signed int, with a value of -1 when
the device tree reports nothing of the bias configuration. Convert the
local 'bias' from unsigned to signed to properly check this condition.

PR:		229721
Reviewed by:	mhorne
MFC after:	3 days
2024-06-14 13:42:27 -03:00
Adam Retter
fb1028dcd4 hda: add support for Tiger Lake-H
PR:		272682
Reported by:	Miguel Salcedo
Reviewed by:	emaste
2024-06-14 12:24:59 -04:00
Ed Maste
aa6fb1d277 tzsetup: ask local/UTC question only on x86
Storing local time in the RTC is a legacy of 1990s PCs; it's not
relevant on other platforms of interest to FreeBSD.

While here switch to C99 bool.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	allanjude (earlier), imp (earlier)
Differential Revision: https://reviews.freebsd.org/D45575
2024-06-14 12:15:48 -04:00
Warner Losh
4fd5b8aed8 boot1.chrp: Include memset
Normally, memset isn't used. However for OPT_INIT_ALL=zero it is. Always
include it since we're not space constrained and latter-day loaders won't
include a copy if it's not actually used.

Reviewed by: emaste
Sponsored by: Netflix
2024-06-14 09:34:05 -06:00
Warner Losh
ec7358885d libkern.h: Make more self-sufficient
libkern.h uses KASSERT, which fails when building in the boot
loader. This is hacked around in a number of other places, but it's
easier to just include sys/kassert.h here. Those other hacks still work,
but are no longer really needed and can be torn down over time.

Reviewed by: emaste
Sponsored by: Netflix
2024-06-14 09:34:05 -06:00
Reid Linnemann
de4bfd6b99 udp_var: correct intoudpcb macro unintended identifier dependency
Change 483fe9651 embedded struct inpcb into struct udpcb and updated the
intoudpcb macro to use __containerof to locate it. This change accidentally
introduced a dependency on the identifier inp being defined in the block the
macro is expanded in. This should have been the macro argument ip. This change
makes this simple correction.

No functional change intended.

Reviewed by:	kp
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-06-14 17:28:28 +02:00
Ed Maste
70e3e1bde9 tzsetup: add detail for -s option
Skipping the UTC question via -s will not create or delete
/etc/wall_cmos_clock.

Reported by:	Tomoaki AOKI
Reviewed by:	imp, allanjude, jrm
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D45576
2024-06-14 10:02:31 -04:00
Doug Moore
2a21cfe60f pctrie: avoid typecast
Have PCTRIE_RECLAIM_CALLBACK typecast one function pointer type to
another, to relieve the writer of the call back function from having
to cast its first argument from void* to member type.

Reviewed by:	rlibby
Differential Revision:	https://reviews.freebsd.org/D45586
2024-06-14 02:19:03 -05:00
Mark Johnston
fbff6d54da vm_phys: Fix vm_phys_find_range() after commit 69cbb18746
vm_phys_seg_paddr_to_vm_page() expects a PA that's in bounds, but
vm_phys_find_range() purposefully returns a pointer to the end of the
last page in a segment.

Fixes:	69cbb18746 ("vm_phys: Add a vm_phys_seg_paddr_to_vm_page() helper")
2024-06-14 00:18:26 -04:00
Mark Johnston
aede0d3bad amd64/vmm: Make vmm.h more self-contained
CTASSERT is defined in kassert.h, so include that here.  No functional
change intended.

MFC after:	1 week
2024-06-13 21:19:00 -04:00
Mark Johnston
d730cdea2a arm64/vmm: Avoid unnecessary indirection in vmmops_modinit()
Most of vmm.h is machine-independent.  Simplify merging amd64 and arm64
vmm code by removing this machine-dependent routine from arm64's vmm.h.
No functional change intended.

Reviewed by:	andrew
Differential Revision:	https://reviews.freebsd.org/D45557
2024-06-13 21:19:00 -04:00
Mark Johnston
a03354b002 arm64/vmm: Implement vm_disable_vcpu_creation()
No functional change intended.

Reviewed by:	andrew
Differential Revision:	https://reviews.freebsd.org/D45556
2024-06-13 21:19:00 -04:00
Mark Johnston
b16b4c22d2 vm_page: Implement lazy page initialization
FreeBSD's boot times have decreased to the point where vm_page array
initialization represents a significant fraction of the total boot time.
For example, when booting FreeBSD in Firecracker (a VMM designed to
support lightweight VMs) with 128MB and 1GB of RAM, vm_page
initialization consumes 9% (3ms) and 37% (21.5ms) of the kernel boot
time, respectively.  This is generally relevant in cloud environments,
where one wants to be able to spin up VMs as quickly as possible.

This patch implements lazy initialization of (most) page structures,
following a suggestion from cperciva@.  The idea is to introduce a new
free pool, VM_FREEPOOL_LAZYINIT, into which all vm_page structures are
initially placed.  For this to work, we need only initialize the first
free page of each chunk placed into the buddy allocator.  Then, early
page allocations draw from the lazy init pool and initialize vm_page
chunks (up to 16MB, 4096 pages) on demand.  Once APs are started, an
idle-priority thread drains the lazy init pool in the background to
avoid introducing extra latency in the allocator.  With this scheme,
almost all of the initialization work is moved out of the critical path.

A couple of vm_phys operations require the pool to be drained before
they can run: vm_phys_find_range() and vm_phys_unfree_page().  However,
these are rare operations.  I believe that
vm_phys_find_freelist_contig() does not require any special treatment,
as it only ever accesses the first page in a power-of-2-sized free page
chunk, which is always initialized.

For now the new pool is only used on amd64 and arm64, since that's where
I can easily test and those platforms would get the most benefit.

Reviewed by:	alc, kib
Differential Revision:	https://reviews.freebsd.org/D40403
2024-06-13 21:19:00 -04:00
Mark Johnston
69cbb18746 vm_phys: Add a vm_phys_seg_paddr_to_vm_page() helper
No functional change intended.

Suggested by:	alc
Reviewed by:	dougm, alc, kib
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D43636
2024-06-13 21:18:59 -04:00
Mark Johnston
d7ec4a8859 vm_phys: Factor out some calls to vm_freelist_add()
A subsequent patch will make this factoring more worthwhile.

No functional change intended.

Reviewed by:	dougm, alc, kib, emaste
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D40400
2024-06-13 21:18:59 -04:00
Mark Johnston
69ccea1c89 vm_page: Let vm_page_init_page() take a pool parameter
This is useful for a subsequent patch which implements lazy
initialization of vm_page structures using a dedicate vm_phys free page
pool.

No functional change intended.

Reviewed by:	alc, kib, emaste
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D40399
2024-06-13 21:18:59 -04:00
Mark Johnston
ab250b02ba bnxt: Use a simpler test for 32-bit platforms
Suggested by:	jrtc27
Fixes:		c867ba7288 ("bnxt: Do not compile on 32-bit platforms")
2024-06-13 21:18:26 -04:00
Mark Johnston
d9220f64da uniq tests: Make uniq_test:stdout more reliable
When running regression tests in paralle, this one occasionally fails
because uniq exits with status 0.  I believe this is because the test is
a bit racy: it assumes that true(1) will exit before uniq writes to
standard out.

Just sleep for a bit to give the other end of the pipe to exit.

Reviewed by:	des
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D45534
2024-06-13 20:00:47 -04:00
Doug Moore
d19851f002 subr_pctrie: add a word to a comment
No functional changes.
Reported by:	alc
2024-06-13 15:28:15 -05:00
Alan Cox
268f19aacc vm: Reduce address space fragmentation
jemalloc performs two types of virtual memory allocations: (1) large
chunks of virtual memory, where the chunk size is a multiple of a
superpage and explicitly aligned, and (2) small allocations, mostly
128KB, where no alignment is requested.  Typically, it starts with a
small allocation, and over time it makes both types of allocation.

With anon_loc being updated on every allocation, we wind up with a
repeating pattern of a small allocation, a large gap, and a large,
aligned allocation.  (As an aside, we wind up allocating a reservation
for these small allocations, but it will never fill because the next
large, aligned allocation updates anon_loc, leaving a gap that will
never be filled with other small allocations.)

With this change, anon_loc isn't updated on every allocation.  So, the
small allocations will be clustered together, the large allocations will
be clustered together, and there will be fewer gaps between the
anonymous memory allocations.  In addition, I see a small reduction in
reservations allocated (e.g., 1.6% during buildworld), fewer partially
populated reservations, and a small increase in 64KB page promotions on
arm64.

Reviewed by:	kib
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D39845
2024-06-13 15:13:45 -05:00
Doug Moore
a7f67ebd82 subr_rangeset: use pctrie_reclaim_cb in remove_all
Replace the lookup-remove loop in rangeet_remove_all with a call
to SWAP_PCTRIE_RECLAIM_CALLBACK, to eliminate repeated trie searches.

Reviewed by:	rlibby
Differential Revision:	https://reviews.freebsd.org/D45584
2024-06-13 13:52:25 -05:00
Doug Moore
d2acf0a447 swap_pager: pctrie_reclaim_cb in meta_free_all
Replace the lookup-remove loop in swp_pager_meta_free_all with a call
to SWAP_PCTRIE_RECLAIM_CALLBACK, to eliminate repeated trie searches.

Reviewed by:	rlibby
Differential Revision:	https://reviews.freebsd.org/D45583
2024-06-13 13:52:25 -05:00
Doug Moore
c0d0bc2bed subr_pctrie: add leaf callbacks to pctrie_reclaim
PCTRIE_RECLAIM frees all the interior nodes in a pctrie, but is little
used because most trie-destroyers want to free leaves of the tree
too. Add PCTRIE_RECLAIM_CALLBACK, with two extra arguments, a callback
function and an auxiliary argument, that is invoked on every non-NULL
leaf in the tree as the tree is destroyed.

Reviewed by:	rlibby, kib (previous version)
Differential Revision:	https://reviews.freebsd.org/D45565
2024-06-13 11:48:09 -05:00
Ed Maste
a16cb8709d tzsetup: Correct UTC description
UTC is Coordinated Universal Time, not Greenwich Mean Time.

Reviewed by:	imp, allanjude
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D45573
2024-06-12 20:24:49 -04:00
Rick Macklem
bb53f071e8 nfscl: Add support for read delegations and atomic upgrade
For NFSv4.1/4.2, an atomic upgrade of a delegation from a
read delegation to a write delegation is allowed and can
result in significantly improved performance.
This patch adds this upgrade to the NFSv4.1/4.2 client and
enables use of read delegations.

For a test case of building a FreeBSD kernel (sources and
output objects) over a NFSv4.2 mount, these changes reduced
the elapsed time by 30% and included a reduction of 80% for
RPC counts when delegations were enabled.  As such, with this
patch there are at least certain cases where enabling
delegations seems to be worth the increased complexity they
bring.

This patch should only affect the NFSv4.1/4.2 behaviour
when delegations are enabled, which is not the default.

MFC after:	1 month
2024-06-12 16:41:12 -07:00
Rick Macklem
4308d6e0fc nfscl: Add a check for VREG for delegations
Since delegations are only issued for regular files, check
v_type to see if the query is for a regular file.  This is
a simple optimization for the non-VREG case.
While here, fix a couple of global variable declarations.

This patch should only affect the NFSv4.1/4.2 behaviour
when delegations are enabled, which is not the default.

MFC after:	1 month
2024-06-12 16:17:23 -07:00
Rick Macklem
ec1f285f2e nfscl: Add support for the NFSv4.1/4.2 WANT_xxx flags
NFSv4.1/4.2 defined new OPEN_WANT_xxx flags that a client
can use to hint to the server that delegations are or are
not wanted.  This patch adds use of those delegations to
the client.

This patch should only affect the NFSv4.1/4.2 behaviour
when delegations are enabled, which is not the default.

MFC after:	1 month
2024-06-12 16:11:10 -07:00
Kristof Provost
07ed239698 pf: make TCP sequence number tracking less strict by one octet for FIN packets
The data of a TCP packet must fit into the announced window, but this is not
required for the sequence number of the FIN.  A packet with the FIN bit set and
containing data that fits exactly into the announced window was blocked. Our
stack generates such packets when the receive buffer size is set to 1024. Now
pf uses only the data lenght for window comparison.
OK henning@

Obtained From:	OpenBSD
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-06-12 23:33:11 +02:00
Kristof Provost
20a2fe68fa pf: correctly reset max_win if the SYN-ACK lacks a wscale option.
pf was setting max_win to 0 and discarded retransmitted SYN-ACK segments without
wscale if the original SYN contained a wscale option. with gerhard@, ok
henning@

Obtained From:	OpenBSD
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-06-12 23:33:11 +02:00
Michael Gmelin
8a9f0fa42b ifconfig: Fix default netmask calculation
Reported by:	phk
Reviewed by:	emaste, kp
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D45570
2024-06-12 20:10:13 +02:00
Andrew Turner
a30149b2a9 arm64: Create a version of vfp_save_state for cpu_switch
This will be used when we add SVE support to reduce the registers
needed to be saved on context switch.

Reviewed by:	imp
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D43305
2024-06-12 14:09:14 +01:00
Andrew Turner
4eec584d79 arm64: Clear td_frame when returning to userspace
When returning from an exception to userspace clear the saved td_frame.
On the next exception this should point to the frame, however this is
not guaranteed.

To ensure the trap frame pointer is either valid or NULL clear it
before returning to userspace in the EL0 synchronous exception handler.

Reviewed by:	kib, markj
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D44807
2024-06-12 14:08:13 +01:00
Andrew Turner
19782e5bef ibcore: Mark write-only variables
Some LinuxKPI lock macros pass need a flags field passed in. This is
written to but never read from so gcc complains.

Fix this by marking the flags variables as unused to quieten the
compiler.

Reviewed by:	brooks (earlier version), kib
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D45303
2024-06-12 14:04:45 +01:00
Andrew Turner
a7ae78caaa cdefs: Add __writeonly to mark write only vars
When a variable in write only and can't be removed, e.g. for API
reasons, it is useful to document this fact similar to __diagused
and __witness_used.

Add __writeonly to tell the compiler and anyone looking at the code
that this variable is expected to only be written to, and to not
raise and error.

Reviewed by:	imp, kib
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D45561
2024-06-12 14:04:13 +01:00
Ruslan Bukin
62cb671705 riscv: include ahci device to GENERIC.
This is needed for bhyve guest VM.

Reviewed by:	mhorne
Sponsored by:	UKRI
Differential Revision:	https://reviews.freebsd.org/D45497
2024-06-12 13:40:50 +01:00