Commit graph

21781 commits

Author SHA1 Message Date
Corvin Köhne
346876412a bhyve: add ROM emulation
Some PCI devices especially GPUs require a ROM to work properly.
The ROM is executed by boot firmware to initialize the device.
To add a ROM to a device use the new ROM option for passthru device
(e.g. -s passthru,0/2/0,rom=<path>/<to>/<rom>).

It's necessary that the ROM is executed by the boot firmware.
It won't be executed by any OS.
Additionally, the boot firmware should be configured to execute the
ROM file.
For that reason, it's only possible to use a ROM when using
OVMF with enabled bus enumeration.

Differential Revision:	https://reviews.freebsd.org/D33129
Sponsored by:   Beckhoff Automation GmbH & Co. KG
MFC after:      1 month

(cherry picked from commit e47fe3183e)
2022-05-16 14:41:14 +02:00
Ed Maste
72bcf2fe90 libutil: eliminate one syscall from kinfo_getproc
Previously we invoked the sysctl with a NULL buffer to query the size,
allocated a buffer, then invoked it again to fetch the data.

As we only handle the case where the sysctl provides data of the
expected size we can just allocate a correctly-sized buffer to begin
with.

Reported by:	Thomas Hurst via Twitter
Reviewed by:	kevans
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D35140

(cherry picked from commit 904c148f1c)
2022-05-16 08:28:24 -04:00
Andrew Turner
658631a37d Add PT_GETREGSET
This adds the PT_GETREGSET and PT_SETREGSET ptrace types. These can be
used to access all the registers from a specified core dump note type.
The NT_PRSTATUS and NT_FPREGSET notes are initially supported. Other
machine-dependant types are expected to be added in the future.

The ptrace addr points to a struct iovec pointing at memory to hold the
registers along with its length. On success the length in the iovec is
updated to tell userspace the actual length the kernel wrote or, if the
base address is NULL, the length the kernel would have written.

Because the data field is an int the arguments are backwards when
compared to the Linux PTRACE_GETREGSET call.

Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D19831

(cherry picked from commit 548a2ec49b)
2022-05-12 15:12:59 -07:00
John Baldwin
c1ccbc7f51 libpmcstat: Fix a few ARM-specific issues with function symbols.
- Refine the checks for ARM mapping symbols and apply them on arm64 as
  well as 32-bit arm.  In particular, mapping symbols can have
  additional characters and are not strictly limited to just "$a" but
  can append additional characters (e.g. "$a.1").  Add "$x" to the
  list of mapping symbol prefixes.

- Clear the LSB of function symbol addresses.  Thumb function
  addresses set the LSB to enable Thumb mode.  However, the actual
  function starts at the aligned address with LSB clear.  Not clearing
  the LSB can cause pmcannotate to pass misaligned addresses to
  objdump when extracting disassembly.

Reviewed by:	andrew
Obtained from:	CheriBSD
Sponsored by:	University of Cambridge, Google, Inc.
Differential Revision:	https://reviews.freebsd.org/D34416

(cherry picked from commit a6db407f15)
2022-05-11 11:57:17 -07:00
Alexander Motin
217a0796fb GEOM: Fix regression after 7f16b501e2.
find_geom() in some classes trim leading "/dev/" from geom names.
Lack of that in geom_gettree_geom() broke some existing scripts.

PR:		262554
MFC after:	2 months

(cherry picked from commit bd0f3d34fa)
2022-05-10 21:20:25 -04:00
Alexander Motin
5f6a3a81f6 GEOM: Introduce partial confxml API
Traditionally the GEOM's primary channel of information from kernel to
user-space was confxml, fetched by libgeom through kern.geom.confxml
sysctl.  It is convenient and informative, representing full state of
GEOM in a single XML document.  But problems start to arise on systems
with hundreds of disks, where the full confxml size reaches many
megabytes, taking significant time to first write it and then parse.

This patch introduces alternative solution, allowing to fetch much
smaller XML document, subset of the full confxml, limited to 64KB and
representing only one specified geom and optionally its parents.  It
uses existing GEOM control interface, extended with new "getxml" verb.
In case of any error, such as the buffer overflow, it just transparently
falls back to traditional full confxml.  This patch uses the new API in
user-space GEOM tools where it is possible.

Reviewed by:	imp
MFC after:	2 month
Sponsored by:	iXsystems, Inc.
Differential Revision:	https://reviews.freebsd.org/D34529

(cherry picked from commit 7f16b501e2)
2022-05-10 21:20:25 -04:00
John Baldwin
56152f833b Remove an always-true check.
This fixes a -Wtype-limits error from GCC 9.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D31936

(cherry picked from commit 5ac4ac85ca)
2022-05-10 15:51:49 -07:00
Alex Richardson
afab9d5ffe Export _mmap and __sys_mmap from libc.so
Unlike the other syscalls these two symbols were missing from the
version script. I noticed this while looking into the compiler-rt
runtime libraries for CHERI.

Reviewed by:	brooks
Obtained from:	https://github.com/CTSRD-CHERI/cheribsd/pull/1063
MFC after:	3 days

(cherry picked from commit 395db99f32)
2022-05-07 12:55:00 +01:00
Kristof Provost
03f6d8361a libpfctl: grow request buffer on ENOSPC
When we issue a request to pf and expect a serialised nvlist as a reply
we have to supply a suitable buffer to the kernel.
The required size for this buffer is difficult to predict, and may be
(slightly) different from request to request.
If it's insufficient the kernel will return ENOSPC. Teach libpfctl to
catch this and send the request again with a larger buffer.

MFC after:	2 weeks
Sponsored by:   Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D34908

(cherry picked from commit 7ed19f5c77)
2022-05-04 08:22:37 +02:00
Andrew Turner
3935c58c21 Have stpncpy tests ask the kernel for the page size
It may be dynamic so we can't rely on PAGE_SIZE being present or
correct.

(cherry picked from commit 748f7c8db7)
2022-05-03 15:04:04 +01:00
Konstantin Belousov
aca70bd01e sched_getaffinity(3): more compatibility with Linux
(cherry picked from commit 67fc95025c)
2022-05-02 21:08:44 +03:00
Stefan Eßer
6e1f0f8006 libfetch: remove a set-but-not-used variable
(cherry picked from commit ce700f78f7)
2022-04-30 09:55:31 +02:00
John Baldwin
ffd150099c Extend the VMM stats interface to support a dynamic count of statistics.
- Add a starting index to 'struct vmstats' and change the
  VM_STATS ioctl to fetch the 64 stats starting at that index.
  A compat shim for <= 13 continues to fetch only the first 64
  stats.

- Extend vm_get_stats() in libvmmapi to use a loop and a static
  thread local buffer which grows to hold the stats needed.

Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D27463

(cherry picked from commit 6426978617)
2022-04-29 16:08:17 -07:00
John Baldwin
c4ec1f6efb libthr: Use TLS_TCB_* in _tcb_[cd]tor.
This matches libc and rtld in using the alignment (TLS_TCB_ALIGN) from
machine/tls.h instead of hardcoding 16.

Reviewed by:	kib
Sponsored by:	The University of Cambridge, Google Inc.
Differential Revision:	https://reviews.freebsd.org/D34023

(cherry picked from commit 8de1a8131e)
2022-04-29 16:05:18 -07:00
John Baldwin
1d290d36d8 iscsi: Handle large Text responses.
Text requests and responses can span multiple PDUs.  In that case, the
sender sets the Continue bit in non-final PDUs and the Final bit in
the last PDU.  The receiver responds to non-final PDUs with an empty
text PDU.

To support this, add a more abstract API in libiscsi which accepts and
receives key sets rather than PDUs.  These routines internally send or
receive one or more PDUs.  Use these new functions to replace the
handling of TextRequest and TextResponse PDUs in discovery sessions in
both ctld and iscsid.

Note that there is not currently a use case for large Text requests
and those are still always sent as a single PDU.  However, discovery
sessions can return a text response listing targets that spans
multiple PDUs, so the new API supports sending and receiving multi-PDU
responses.

Reported by:	Jithesh Arakkan @ Chelsio
Reviewed by:	mav
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D33548

(cherry picked from commit b406897911)
2022-04-29 14:17:43 -07:00
John Baldwin
54262b09e5 libiscsiutil: Change keys_load/save to operate on data buffers.
This will be used in future changes to support large text requests
spanning multiple PDUs.

Provide wrapper functions keys_load/save_pdu that operate use a PDU's
data buffer.

Reviewed by:	mav
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D33547

(cherry picked from commit 25700db366)
2022-04-29 14:15:45 -07:00
John Baldwin
a96064b669 libiscsiutil: Fix a memory leak with negotiation keys.
When keys are loaded from a received PDU, a copy of the received keys
block is saved in the keys struct and the name and value pointers
point into that saved block.  Freeing the keys frees this block.

However, when keys are added to a keys struct to build a set of keys
later sent in a PDU, the keys data block pointer is not used and
individual key names and values hold allocated strings.  When the keys
structure was freed, all of these individual key name and value
strings were leaked.

Instead, allocate copies of strings for names and values when parsing
a set of keys from a received PDU and free all of the individual key
name and value strings when deleting a set of keys.

Reviewed by:	mav
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D33545

(cherry picked from commit fd99905b45)
2022-04-29 14:15:38 -07:00
John Baldwin
f5a4ae2539 libiscsiutil: Use open_memstream to build the outgoing block of keys.
Reviewed by:	mav
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D33546

(cherry picked from commit 2ccb8fde5e)
2022-04-29 14:14:37 -07:00
John Baldwin
ec79933e61 Add an internal libiscsiutil library.
Move some of the code duplicated between ctld(8) and iscsid(8) into a
libiscsiutil library.

Sharing the low-level PDU code did require having a
'struct connection' base class with a method table to permit separate
initiator vs target behavior (e.g. in handling proxy PDUs).

Reviewed by:	mav, emaste
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D33544

(cherry picked from commit 6378393308)
2022-04-29 14:13:00 -07:00
John Baldwin
a641444939 TLS: Use <machine/tls.h> for libc and rtld.
- Include <machine/tls.h> in MD rtld_machdep.h headers.

- Remove local definitions of TLS_* constants from rtld_machdep.h
  headers and libc using the values from <machine/tls.h> instead.

- Use _tcb_set() instead of inlined versions in MD
  allocate_initial_tls() routines in rtld.  The one exception is amd64
  whose _tcb_set() invokes the amd64_set_fsbase ifunc.  rtld cannot
  use ifuncs, so amd64 inlines the logic to optionally write to fsbase
  directly.

- Use _tcb_set() instead of _set_tp() in libc.

- Use '&_tcb_get()->tcb_dtv' instead of _get_tp() in both rtld and libc.
  This permits removing _get_tp.c from rtld.

- Use TLS_TCB_SIZE and TLS_TCB_ALIGN with allocate_tls() in MD
  allocate_initial_tls() routines in rtld.

Reviewed by:	kib, jrtc27 (earlier version)
Differential Revision:	https://reviews.freebsd.org/D33353

(cherry picked from commit 8bcdb144eb)
2022-04-29 13:50:05 -07:00
John Baldwin
34e70df37a libthr: Use <machine/tls.h> for most MD TLS details.
Note that on amd64 this effectively removes the unused tcb_spare field
from the end of struct tcb since the definition of struct tcb in
<x86/tls.h> does not include that field.

Reviewed by:	kib, jrtc27
Sponsored by:	The University of Cambridge, Google Inc.
Differential Revision:	https://reviews.freebsd.org/D33352

(cherry picked from commit 75395023ff)
2022-04-29 13:50:05 -07:00
John Baldwin
374ca4a3dd libc: Fix the alignment of the TCB to match rtld for several architectures.
- Use 16 byte alignment rather than 8 for aarch64, powerpc64, and RISC-V.

- Use 8 byte alignment rather than 4 for 32-bit arm, mips, and powerpc.

I suspect that mips64 should be using 16 byte alignment, but both libc
and rtld currently use 8 byte alignment.

Reviewed by:	kib, jrtc27
Sponsored by:	The University of Cambridge, Google Inc.
Differential Revision:	https://reviews.freebsd.org/D33350

(cherry picked from commit 4c2f5bfbfa)
2022-04-29 13:50:05 -07:00
John Baldwin
5c1667e8be mips _libc_get_static_tls_base: Narrow scope of #ifdef.
Reviewed by:	kib, emaste, jrtc27
Sponsored by:	The University of Cambridge, Google Inc.
Differential Revision:	https://reviews.freebsd.org/D33348

(cherry picked from commit 9952b82b39)
2022-04-29 13:50:05 -07:00
John Baldwin
efc500573f libthr: Remove the DTV_OFFSET macro.
This macro is confusing as it is not related to the similarly named
TLS_DTV_OFFSET.  Instead, replace its one use with the desired
expression which is the same on all platforms.

Reviewed by:	kib, emaste, jrtc27
Sponsored by:	The University of Cambridge, Google Inc.
Differential Revision:	https://reviews.freebsd.org/D33345

(cherry picked from commit 5d8176337e)
2022-04-29 13:50:04 -07:00
Mark Johnston
cb613da916 libsysdecode: Add regression tests for sysdecode_cap_rights(3)
Reviewed by:	jhb, emaste
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit d0f245d21f)
2022-04-22 10:36:37 -04:00
Mark Johnston
6e1a003ffc libsysdecode: Include required headers in sysdecode.h
Make sysdecode.h self-contained rather than forcing all consumers to
include dependencies.  No functional change intended.

Reviewed by:	pauamma_gundo.com, jhb, emaste
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 354efc4c94)
2022-04-22 10:36:29 -04:00
Mark Johnston
91d3f40d93 libsysdecode: Fix decoding of Capsicum rights
Capsicum rights are a bit tricky since some of them are subsets of
others, and one can have rights R1 and R2 such that R1 is a subset of
R2, but there is no collection of named rights whose union is R2.  So,
they don't behave like most other flag sets.  sysdecode_cap_rights(3)
does not handle this properly and so can emit misleading decodings.

Try to fix all of these problems:
- Include composite rights in the caprights table.
- Use a constructor to sort the caprights table such that "larger"
  rights appear first and thus are matched first.
- Don't print rights that are a subset of rights already printed, so as
  to minimize the length of the output.
- Print a trailing message if some of the specific rights are not
  matched by the table.

PR:		263165
Reviewed by:	pauamma_gundo.com (doc), jhb, emaste
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 869199d992)
2022-04-22 10:36:22 -04:00
Gordon Bergling
dd19f0e9c0 time(3): Refine history in the manual page
The time() system call first appeared in Version 1 AT&T UNIX.  Through
the Version 3 AT&T UNIX, it returned 60 Hz ticks since an epoch that
changed occasionally, because it was a 32-bit value that overflowed in a
little over 2 years.

In Version 4 AT&T UNIX the granularity of the return value was reduced to
whole seconds, delaying the aforementioned overflow until 2038.

Version 7 AT&T UNIX introduced the ftime() system call, which returned
time at a millisecond level, though retained the gtime() system call
(exposed as time() in userland).  time() could have been implemented as a
wrapper around ftime(), but that wasn't done.

4.1cBSD implemented a higher-precision time function gettimeofday() to
replace ftime() and reimplemented time() in terms of that.

Since FreeBSD 9 the implementation of time() uses
clock_gettime(CLOCK_SECOND) instead of gettimeofday() for performance
reasons.

With most valuable input from Warner (imp@).

Reviewed by:	0mp, jilles, imp
Differential Revision:	https://reviews.freebsd.org/D34751

(cherry picked from commit 3e0f3678ec)
2022-04-21 08:26:31 +02:00
Konstantin Belousov
6daddc54de Mostly revert a5970a529c: Make files opened with O_PATH to not block non-forced unmount
(cherry picked from commit bf13db086b)
2022-04-19 23:22:54 +03:00
Andrew Turner
2e38975e5a Add an implementation of .mcount on arm64
To support cc -pg on arm64 we need to implement .mcount. As clang and
gcc think it is function like it just needs to load the arguments
to _mcount and call it.

On gcc the first argument is passed in x0, however this is missing on
clang so we need to load it from the stack. As it's the caller return
address this will be at a known location.

PR:		262709
Reviewed by:	emaste (earlier version)
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D34634

(cherry picked from commit 16d5f9a164)
2022-04-19 10:18:02 +01:00
Konstantin Belousov
c0a4963941 libprocstat: document procstat_getadvlock(3)
(cherry picked from commit 50d3c72558)
2022-04-16 05:18:18 +03:00
Konstantin Belousov
c649ead622 libprocstat: add procstat_getadvlock(3)
(cherry picked from commit 039d1496b0)
2022-04-16 05:18:18 +03:00
Gordon Bergling
eafea71138 resolver(3): Fix a typo in a source code comment
- s/psuedo/pseudo/

(cherry picked from commit b4ce0ff19a)
2022-04-14 08:10:32 +02:00
Gordon Bergling
3b44bcea52 libipsec: Fix a typo in a source code comment
- s/proccessing/processing/

(cherry picked from commit 38dd27d21e)
2022-04-14 08:05:53 +02:00
Gordon Bergling
f7ed8a5a7f getenv(3): Fix two typos in source code comments
- s/peform/perform/

(cherry picked from commit 8dcf5860b3)
2022-04-14 08:03:09 +02:00
Gordon Bergling
9faf4f3007 math(3): Remove a double word in a source code comment
- s/is is/is/

(cherry picked from commit 29fea59e78)
2022-04-14 07:59:12 +02:00
Greg Lehey
01f095a355 chroot.2: Correct grammar errors.
No functional change.

MFC after:	1 week

(cherry picked from commit 4044083079)
2022-04-14 10:03:36 +10:00
Reid Linnemann
14c4c1d01e libpfctl: relocate implementations of pfr_add/get/set_addrs
Reviewed by:	kp
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D34740

(cherry picked from commit 4823489ab6)
2022-04-11 16:52:34 +02:00
Ganael LAPLANCHE
e66bbe6e02 libc: Check for readdir(2) errors in fts(3)
Previously, such errors were not distinguished from the end-of-directory
condition.

With improvements from Mahmoud Abumandour <ma.mandourr@gmail.com>.

Reviewed by:	markj
PR:		262038

(cherry picked from commit 0cff70ca66)
2022-04-11 09:43:28 -04:00
Martin Matuska
3caf7dd45d libarchive: fix zstd compression support
The commit 833a452e9 introduced a change that detached
the zstd compression (not decompression) support from base build.

Reported by:	kevans

(cherry picked from commit 7f815d4f12)
2022-04-11 00:35:29 +02:00
Gordon Bergling
28612e5934 if_indextoname(3): Correct the RFC in a comment
RFC 2533 refers to 'A Syntax for Describing Media Feature Sets',
which is wrong since the correct reference should be
RFC 2553 'Basic Socket Interface Extensions for IPv6'.

Obtained from:	OpenBSD

(cherry picked from commit fa556e83be)
2022-04-10 07:52:14 +02:00
Gordon Bergling
745e044fe2 rpc(3): Fix two typos in source code comments
- s/alloctaed/allocated/

Obtained from:	NetBSD

(cherry picked from commit 5c49e1cbea)
2022-04-09 08:17:17 +02:00
Gordon Bergling
cec2f59d28 libnetbsd: Fix a typo in a source code comment
- s/accomodate/accommodate/

(cherry picked from commit 49f2bb3676)
2022-04-09 08:15:54 +02:00
Gordon Bergling
b8169da741 mt(3): Fix a typo in the manual page
- s/mulitple/multiple/

(cherry picked from commit 656d68a711)
2022-04-09 07:48:20 +02:00
Kyle Evans
227e52a9c0 bectl: push space-in-name check down into libbe
This check was previously in `create` only, not applying to renames.  It
should really be applied at the libbe level, so that we can avoid
writing about this restriction over and over again.

While we're here: `bectl rename` always succeeds, even when it doesn't.
Start returning the error.

Reported By:	Christian McDonald <cmcdonald netgate com>

(cherry picked from commit dadb9c7093)
2022-04-05 22:37:07 -05:00
Kyle Evans
6ce8e35cea libbe: fix be_mounted_at() with props after bootonce
propinfo.bootonce was filled with garbage, leading to a segfault later
during prop building.  Initialize it to NULL.

(cherry picked from commit d155d8e138)
2022-04-05 22:37:03 -05:00
Kyle Evans
bed9c972ae libbe: pull props for the correct dataset in be_mounted_at()
The props feature to this API was added as a "just in case", with no
planned consumer.  It turns out that it was implemented incorrectly,
tapping out props for the BE root (BE's parent) rather than the BE
itself in all cases.

Fetch properties for the dataset that's actually mounted at the queried
path.

Reported by:	Christian McDonald <cmcdonald netgate com>

(cherry picked from commit 31190aa02e)
2022-04-05 22:36:10 -05:00
Alexander Motin
e3b3dfa779 gpart: Avoid geom_gettree() call in "bootcode -b".
geom_gettree() may be pretty expensive on large systems, and it is
not needed if only -b flag specified, that is processed by kernel.

MFC after:	1 month

(cherry picked from commit 5c20bfc787)
2022-04-05 22:07:40 -04:00
Alexander Motin
4340533721 GEOM: Introduce gctl_add_param() API.
Make gctl_add_param() API public, allowing more precise control over
parameter flags.  Previously it was impossible to properly declare
write-only ASCII parameters, used for result reporting, they were
declared as read-write binary instead, that was not nice.

MFC after:	1 month

(cherry picked from commit 2117cdd4b4)
2022-04-05 22:07:40 -04:00
Xin LI
c4727a47f1 lib/libz: remove ZLIBprivate_1.0 namespace.
These symbols were hidden and no longer exposed, and were never exposed in headers.

MFC after:	3 days

(cherry picked from commit a7f127b653)
2022-04-04 15:30:18 -04:00