Commit Graph

140275 Commits

Author SHA1 Message Date
Andrew Turner
3ff0419450 Fix bracketing in the arm64 minidump code
When building with gcc10 it suggests the parentheses are wrong. Set them
to be the calculated physical address or'd with page table attributes.

Reviewed by:	mhorne, imp
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D33099
2021-11-24 15:31:56 +00:00
Andrew Turner
dd978721a2 Remove redundant declarations
These are already defined in the same file.

Sponsored by:	The FreeBSD Foundation
2021-11-24 15:31:50 +00:00
Warner Losh
a2b53e53a3 sys/file.h: Allow inclusion when compiling for a strict namespace
Although not part of the standard, this file is sometimes included with
-D_POSIX_C_SOURCE=<value> or -D_XOPEN_SOURCE=<value>. Limit those
sturctures that use types hidden by __BSD_VISIBLE to when they are
visible.

PR:			259975, 234205
Sponsored by:		Netflix
2021-11-24 02:38:09 -07:00
Warner Losh
b3fab41830 devctl.h: Spelling typo
Spell identifier correctly. While I'm here, further simplify.

Fixes:		ee2c52fd3f
Sponsored by:	Netflix
2021-11-24 02:37:51 -07:00
Warner Losh
1bc9ca3b35 cam: Unbreak CAM_IO_STATS build
Fixes:		6637b74600
Sponsored by:	Netflix
2021-11-24 02:36:48 -07:00
Hubert Mazur
26d6547567 Pcf85063: Add RTC driver
Add driver for pcf85063 real time clock. Register set and get time
methods. Parse data obtained from bus according to specification
and fill kernel structures.

Obtained from: Semihalf
Sponsored by: Alstom Group
Differential revision: https://reviews.freebsd.org/D32817
2021-11-24 07:40:38 +01:00
Hubert Mazur
cb35af13f9 TCA6408: Add driver for tca6408 gpio expander
Driver for tca6408 gpio expander over i2c bus. Expose API for
manipulating pin's direction, state and polarity inversion.

Obtained from: Semihalf
Sponsored by: Alstom Group
Differential revision: https://reviews.freebsd.org/D32819
2021-11-24 07:40:38 +01:00
Kornel Duleba
0f84feb9fb felix: Add support for PHY interrupts
- Replace miibus with newly created miibus_fdt.
- Use generic passthrough resource allocation devmethods.

Obtained from: Semihalf
Sponsored by: Alstom Group
2021-11-24 07:40:37 +01:00
Kornel Duleba
6802a86cb0 enetc: Add support for PHY interrupts
- Replace miibus with newly created miibus_fdt.
- Use generic passthrough resource allocation devmethods.

Obtained from: Semihalf
Sponsored by: Alstom Group
2021-11-24 07:40:37 +01:00
Kornel Duleba
89595c1791 vscphy: Add support for PHY interrupts
They're allocated using standard newbus API,
which means that we rely on miibus to handle the allocation.
Add VSC8504 to the list of supported PHYs, as it is similar enough
to the VSC8501 that is already supported by this driver.

Obtained from: Semihalf
Sponsored by: Alstom Group
Differential revision: https://reviews.freebsd.org/D32816
2021-11-24 07:40:37 +01:00
Kornel Duleba
0c9156faec Introduce DP83822 PHY driver
DP83822 is a 10/100 Texas Instruments PHY.
Link status change interrupts are supported by the driver,
however not all boards have the PHY interrupt wired.
Because of that if failure to allocate an IRQ is not treated as an error.

Obtained from: Semihalf
Sponsored by: Alstom Group
Differential revision: https://reviews.freebsd.org/D32815
2021-11-24 07:40:36 +01:00
Kornel Duleba
e85c94b8d6 Introduce DP83867 PHY driver
DP83867 is a 10/100/1000 Texas Instruments PHY.
Only SGMII mode is supported.
Link status changes can be checked through an interrupt generated by the PHY,
if available

Obtained from: Semihalf
Sponsored by: Alstom Group
Differential revision: https://reviews.freebsd.org/D32813
2021-11-24 07:40:36 +01:00
Kornel Duleba
9174eab414 miibus: Add support for mapping OFW nodes to PHY devices
Create a new miibus OFW specific layer leveraging miibus_fdt.c code.
PHY drivers can than read the properties using device_get_property(9) API.
Resource(interrupt) allocation is also supported.
In order to enable this each NIC/switch driver will have to be modified,
because of how miibus is attached to the parent driver.

Obtained from: Semihalf
Sponsored by: Alstom Group
Differential revision: https://reviews.freebsd.org/D32812
2021-11-24 07:40:36 +01:00
Kornel Duleba
89fb4802f9 vscphy: Fill in new mii_maxspeed field
It is used to limit the max advertised speed.
The value is read from DT by mii_fdt code.

Obtained from: Semihalf
Sponsored by: Alstom Group
Differential revision: https://reviews.freebsd.org/D32816
2021-11-24 07:40:35 +01:00
Kornel Duleba
b38de28a77 mii_physubr: Add support for limiting PHY max speed
In some cases we might want to limit the max speed advertised below of what
the PHY is capable of.
This is usually the case when we connect 1G capable PHY to 100M MAC, or when
some exotic physical connection is used.
Add a new mii_maxspeed field to mii_softc and parse it in mii_phy_dev_attach.
Speed limit is normally located in DT.
The property is already parsed in mii_fdt.c, but its value still has to be
passed by the PHY driver.

Obtained from: Semihalf
Sponsored by: Alstom Group
Differential revision: https://reviews.freebsd.org/D32727
2021-11-24 07:40:35 +01:00
Warner Losh
6637b74600 cam: Remove all the write-only variables
Delete all the write only variables in CAM. At worst, the only behavior
change would be to prevent core dumps from chasing NULL pointers (though
I think in all these cases the pointers can't be NULL).

Sponsored by:		Netflix
2021-11-23 21:21:18 -07:00
Warner Losh
ee2c52fd3f sys/devctl.h: Only declare kernel functions in kernel.
Also, while I'm here, switch to newer, shorter format and fix my
copyright to match the others in the tree.

Sponsored by:		Netflix
2021-11-23 21:21:18 -07:00
Warner Losh
76d6bb6a6e powerpc: Make machine/reg.h self-contained
Make powerpc*'s machine/reg.h self-contained so that sys/reg.h can be
self-contained.

Sponsored by:		Netflix
2021-11-23 21:21:18 -07:00
Warner Losh
d2bf8c544a riscv: Make machine/regs.h self-contained
Make sys/reg.h self-contained by making riscv's machine/reg.h
self-contained.

Sponsored by:		Netflix
2021-11-23 21:21:17 -07:00
Warner Losh
8ee8271e22 arm64: Make machine/reg.h self contained
Make sys/reg.h includable on aarch64 by making machine/reg.h
self-contained: Include sys/_types.h and use __uint* instead of uint*.

Sponsored by:		Netflix
2021-11-23 21:21:17 -07:00
Warner Losh
b57e0aa4ef arm: Make machine/reg.h self-contained
Allow inclusion of sys/reg.h w/o pre-requisites by making arm's machine/reg.h
self-contained.

Sponsored by:		Netflix
2021-11-23 21:21:17 -07:00
Ed Maste
c0aa5f6a32 mgb: remove set but not used variables
Sponsored by:	The FreeBSD Foundation
2021-11-23 20:56:53 -05:00
Piotr Kubaj
3a60869237 Add assembly optimized code for OpenSSL on powerpc, powerpc64 and powerpc64le
Summary:
1. 34ab13b7d8
needs to be merged for ELFv2 support on big-endian.
2. crypto/openssl/crypto/ppccap.c needs to be patched.
Same reason as in https://github.com/openssl/openssl/pull/17082.

Approved by:	jkim, jhibbits
MFC after:	1 month
Differential Revision: https://reviews.freebsd.org/D33076
2021-11-23 23:26:53 +01:00
Eric Joyner
9cf1841c4a
ice(4): Update to version 0.29.4-k
Includes various feature improvements and bug fixes.

Notable changes include:
- Firmware logging support
- Link management flow changes
- New sysctl to report aggregated error counts
- Health Status Event reporting from firmware (Use the new read-only
  tunables hw.ice.enable_health_events / dev.ice.#.enable_health_events
  to turn this off)

Signed-off-by: Eric Joyner <erj@FreeBSD.org>

Sponsored by:	Intel Corporation
2021-11-23 14:09:29 -08:00
Warner Losh
9109192197 kqueue: Define older kqueue event types better
struct kqueue is designed to live in a restricted namespace, but the
older compat versions are not. Shift to using unsigned short instead
of u_short, unsigned int instead of u_int and the __*int*_t types
instead of the unprefiexed versions.

Sponsored by:		Netflix
Reviewed by:		brooks
Differential Revision:	https://reviews.freebsd.org/D33056
2021-11-23 13:29:24 -07:00
Gleb Smirnoff
319e9fc642 ng_bridge: count item allocation failures as memory failures
Submitted by:	Dmitry Luhtionov <dmitryluhtionov gmail.com>
2021-11-23 10:05:36 -08:00
Kristof Provost
90c55481b2 pf: fix netpfil.common.dummynet:pf_nat test
This test failed if ipfw was loaded (as well as pf). pf used the same
tag as dummynet to indicate a packet had already gone through dummynet.
However, ipfw removes this tag, so pf didn't realise the packet had
already gone through dummynet.

Introduce a separate flag, in the existing pf mtag rather than re-using
the ipfw tag. There were no free flag bits, but PF_TAG_FRAGCACHE is no
longer used so its bit can be re-purposed.

MFC after:	2 weeks
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D33087
2021-11-23 16:46:35 +01:00
Kristof Provost
18d04cd2d4 pf: align IPv6 dummynet handling with IPv4
In e5c4987e3f we fixed issues with nat and dummynet, but only changed
the IPv4 code. Make the same change for IPv6 as well.

Reviewed by:	glebius
MFC after:	3 weeks
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D33086
2021-11-23 16:46:15 +01:00
Kristof Provost
c36f90417b pf: remove unused variables
No functional change intended.

Reviewed by:	glebius
MFC after:	2 weeks
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D33085
2021-11-23 16:44:37 +01:00
Andrew Turner
44ca369051 Move the arm64 identify_cpu SYSINIT earlier
It is used by late ifunc resolvers so needs to be at an earlier stage
of the boot. Previously it was at the same stage so may not have run
before the ifunc resolvers.

Sponsored by:	The FreeBSD Foundation
2021-11-23 15:03:51 +00:00
Gleb Smirnoff
3bc40f39fd if_free: add a comment explaining why ifindex_free() is performed here 2021-11-22 19:59:27 -08:00
Gleb Smirnoff
fe499a8452 ifnet: merge if_destroy() and if_free_internal() into one
New function has more meaningful name if_free_deferred() and has
its header comment fixed to reflect reality.  NFC
2021-11-22 19:53:12 -08:00
Gleb Smirnoff
4787572d05 ifnet: make if_alloc_domain() never fail
The last consumer of if_com_alloc() is firewire.  It never fails
to allocate.  Most likely the if_com_alloc() KPI will go away
together with if_fwip(), less likely new consumers of if_com_alloc()
will be added, but they would need to follow the no fail KPI.
2021-11-22 19:49:57 -08:00
Gleb Smirnoff
1e3ca25d92 ifnet: make if_alloc_domain() static 2021-11-22 19:49:57 -08:00
Gleb Smirnoff
ce40632a31 ifnet: append if_debug.c to if.c
With this change if_index can become static.  There is nothing
that if_debug.c would want to isolate from if.c.  Potentially
if.c wants to share everything with if_debug.c.

Move Bjoern's copyright to if.c.

Reviewed by:	bz
2021-11-22 19:49:57 -08:00
Gleb Smirnoff
8a6f38c8ac ifnet: garbage collect drbr_*_drv().
They were left in 62d76917b8 but after years proved not to be useful.
2021-11-22 19:49:57 -08:00
Brooks Davis
b92f4ae58a freebsd32: regen
There there are two changes here. First, ofreebsd32_sigreturn
is declared to take a struct osigcontext rather than a struct
ia32_sigcontext3. This type is incorrect, but harmlessly so.
Second, the name of the unimplemented ogetkerninfo changes in
freebsd32_syscallnames.
2021-11-22 22:36:58 +00:00
Brooks Davis
be67ea40c5 freebsd32: generate from sys/kern/syscalls.master
This avoids the need to keep a freebsd32-specific syscalls.master
in sync with the default ABI.  As evidenced by the number of commits
required to sync the two, it is extremely easy for them to get out
of sync due to misunderstandings and user errors.

Reviewed by:	kevans, kib
2021-11-22 22:36:58 +00:00
Brooks Davis
799ce8b8d2 syscalls: annotate args pointing to long, pointer, or time_t
Add _Contains_ annotations indicating that the data pointed to by a
pointer argument contains types that vary between FreeBSD ABIs. The
supported set is long (including size_t), pointer (including
intptr_t), and time_t.  The first two vary between 32- and 64-bit
ABIs.  The laste betwen i386 and everything else.

These will be used to detect which syscalls require handling on
particular ABIs.

Reviewed by:	kevans, kib
2021-11-22 22:36:58 +00:00
Brooks Davis
f260a69dec makesyscalls: strip _Contains_ argument annotations
Reviewed by:	kevans
2021-11-22 22:36:58 +00:00
Brooks Davis
64cc9803ab makesyscalls: add override of ABI change detection
While we can detect most ABI changes through analysis of
syscalls.master with suitable annotations, to cases are handled
in the core implementation and others have changes that can not be
infered.  Add two new config variables syscall_abi_change and
syscall_no_abi_change which override the detected value.  Both are
space-seperated lists of syscall names.

Reviewed by:	kevans
2021-11-22 22:36:58 +00:00
Brooks Davis
988e8db3c0 makesyscalls: automate detection of ABI changes
Use pattern matching including matches of _Contains_*_ argument
annotations to (mostly) determine which system calls require
ABI-specific handling.  Automatically treat syscalls as NOPROTO
if no ABI changes are present.

Reviewed by:	kevans
2021-11-22 22:36:58 +00:00
Brooks Davis
804a84fbf2 makesyscalls.lua: Add the ABI function prefix reliably.
The previous code mostly worked, but ended up adding bogus sys_<foo>()
declerations.

Reviewed by:	kevans
2021-11-22 22:36:58 +00:00
Brooks Davis
5e70931184 makesyscalls: allow config to force OBSOL and UNIMPL
The obsol and unimpl config variables are space-seperated lists of
syscalls that should treated as being declared OBSOL and UNIMPL.

The allows an ABI to exclude select system calls listed in
syscalls.master.

Reviewed by:	kevans
2021-11-22 22:36:57 +00:00
Brooks Davis
30bc335a05 freebsd32: regen 2021-11-22 22:36:57 +00:00
Brooks Davis
faa67c2b20 freebsd32: generate splits of 64-bit arguments
This eliminates the need for ifdefs in syscalls.master and contains the
largest set of diff to generated files on the way to switching to using
the default ABI's syscalls.master.

Reviewed by:	kevans
2021-11-22 22:36:57 +00:00
Brooks Davis
6b7c23a026 syscalls: regen 2021-11-22 22:36:57 +00:00
Brooks Davis
64007b000a makesyscalls: handle 64-bit args on 32-bit
On 32-bit architectures, 64-bit arguments are passed in pairs of
registers. On non-x86 architectures these arguments must be in evenly
aligned registers which necessiciates inserting a pad register into the
argument list. This has historically been supported by adding ifdefs
around padded and unpadded syscall defintions in syscalls.master.

In order to enable generation of 32-bit support files from the base
syscalls.master, pull this support in to makesyscalls.lua enabled by
adding pair_64bit to abi_flags.

The changes to sys_proto.h simply add #ifdef PAD64_REQUIRED
around pad arguments in struct <syscall>_args. In systrace_args(),
replace static syscall index values with post-incremented indexs
allowing a simple ifdef around the argument. Under -O1 or higher
code generation is identical. systrace_entry_setargdesc() is a bit
more complicated as we switch on argument indices.  Solve this
with some use of define/undef pairs to compute the correct indices.

Reviewed by:	kevans
2021-11-22 22:36:57 +00:00
Brooks Davis
79634eb90b makesyscalls: handle arrays of pointers
When the config variable abi_intptr_t is not "", transform arrays of
pointers to arrays of abi_intptr_t.

Reviewed by:	kevans
2021-11-22 22:36:57 +00:00
Brooks Davis
0a4e16446b makesyscalls: handle longs in ABI compat
Replace long-derived types with their abi equivalent where
required by the target ABI. There are two cases:
 - All pointers to types that go from 64-bit to 32-bit between the
   default ABI and the target ABI.
 - Signed arguments that go from 64-bit to 32-bit (these require
   sign-extension before passing to general kernel ABIs).

This adds four new config variables: abi_long, semid_t, abi_size_t,
and abi_u_long which default to long, size_t, and u_long respectively.

Reviewed by:	kevans
2021-11-22 22:36:57 +00:00
Brooks Davis
b85fb39047 makesyscalls.lua: Allow translation of intptr_t arguments
Translate instances of intptr_t to the config value abi_intptr_t
(defaults to "intptr_t").  Used in CheriABI to translate intptr_t
to intcap_t for hybrid kernels.

Reviewed by:	kevans
2021-11-22 22:36:57 +00:00
Brooks Davis
f0cfbffc36 syscalls: regen 2021-11-22 22:36:56 +00:00
Brooks Davis
37b425bd05 makesyscalls: intptr_t arguments are pointers
Match intptr_t arguments as pointers.  Currently this is a no-op
change to systrace_args.c.

Reviewed by:	kevans
2021-11-22 22:36:56 +00:00
Brooks Davis
3f8f46a0ae makesyscalls: Add a way to include per-ABI headers
When the string %%ABI_HEADERS%% is found in syscalls.master, replace
it with the contents of the abi_headers config variable.  This allows
an ABI-specific syscalls.conf to add lines like:

	#include <compat/freebsd32/freebsd32.h>

when working from a shared syscalls.master.

Reviewed by:	kevans
2021-11-22 22:36:56 +00:00
Brooks Davis
ed8a4423fb makesyscalls: allow multiple expressions for each abi change
Limitations in lua patterns means we need to be able to match more
than one possible expression.

Reviewed by:	kevans
2021-11-22 22:36:56 +00:00
Brooks Davis
818aa9543d makesyscalls: Fix expression for time_t_size
Reviewed by:	kevans
2021-11-22 22:36:56 +00:00
Brooks Davis
5203efead7 makesyscalls: Remove _native suffix handling
This supported a hack we used in CheriBSD which has been removed.

Reviewed by:	kevans
2021-11-22 22:36:56 +00:00
Brooks Davis
97fdcfcaf7 freebsd32: remove unnecessicary headers
Reviewed by:	kib
2021-11-22 22:36:56 +00:00
Brooks Davis
bcd07aaa4e freebsd32: regen 2021-11-22 22:36:56 +00:00
Brooks Davis
6eefabd4ca syscalls: improve nstat, nfstat, nlstat
Optionally return errors when truncating dev_t, ino_t, and nlink_t.
In the interest of code reuse, use freebsd11_cvtstat() to perform the
truncation and error handling and then convert the resulting struct
freebsd11_stat to struct nstat.

Add missing freebsd32 compat syscalls. These syscalls require
translation because struct nstat contains four instances of struct
timespec which in turn contains a time_t and a long.

Reviewed by:	kib
2021-11-22 22:36:56 +00:00
Brooks Davis
8460d3e9e6 freebsd32: regen 2021-11-22 22:36:55 +00:00
Brooks Davis
151ddfec6f freebsd32: add _'s to _umtx_(un)lock
This aligns with the default ABI's configuration.

Reviewed by:	kib
2021-11-22 22:36:55 +00:00
Brooks Davis
b2be098e52 freebsd32: enable orecvfrom
It requires no translation, just a correct decleration.

Reviewed by:	kib
2021-11-22 22:36:55 +00:00
Brooks Davis
2d691434d5 freebsd32: declare ogetsockname correctly
Reviewed by:	kib
2021-11-22 22:36:55 +00:00
Brooks Davis
6f5eb383bd freebsd32: sync some osig* audit flags with default ABI
Discussed with:	rwatson

Reviewed by:	kib
2021-11-22 22:36:55 +00:00
Brooks Davis
802280ada8 freebsd32: sctp syscalls take struct iovec32
Reviewed by:	kib
2021-11-22 22:36:55 +00:00
Brooks Davis
06759303ec freebsd32: aio_cancel takes a struct aiocb32
Strictly speaking, it takes a virtual address and doesn't touch the
object directly, but this is consistant with other aio_*() syscalls.

Reviewed by:	kib
2021-11-22 22:36:55 +00:00
Brooks Davis
e11f2743ff freebsd32: [gs]etgroups take an int gidsetsize
Reviewed by:	kib
2021-11-22 22:36:55 +00:00
Brooks Davis
e54a870e35 freebsd32: make semsys take int arguments
This matches the default ABI.

Reviewed by:	kib
2021-11-22 22:36:54 +00:00
Brooks Davis
1eacca4397 freebsd32: make fcntl's arg argument int32_t
It's a long in the default ABI so this is consistant with other caes.

Reviewed by:	kib
2021-11-22 22:36:54 +00:00
Brooks Davis
d330857439 syscalls: regen 2021-11-22 22:36:54 +00:00
Brooks Davis
00e0a4c0d7 syscalls: abort2 doesn't return so declare as void
Reviewed by:	kib
2021-11-22 22:36:54 +00:00
Brooks Davis
4b2e1f1480 syscalls: umask returns a mode_t
Reviewed by:	kib
2021-11-22 22:36:54 +00:00
Brooks Davis
27f5b514a0 syscalls: update a few return types to ssize_t
Reviewed by:	kib
2021-11-22 22:36:54 +00:00
Brooks Davis
717e7fb27a syscalls: struct ucontext4 -> struct freebsd4_ucontext
This aligns with struct freebsd4_ucontext32 in freebsd32.

Reviewed by:	kib
2021-11-22 22:36:54 +00:00
Brooks Davis
e58e9a8cbd syscalls: regen 2021-11-22 22:36:54 +00:00
Brooks Davis
d8bd949beb sys___sysctl: regularize argument struct
Let makesyscalls generate the normal struct __sysctl_args structure.
It works fine.

Reviewed by:	kib
2021-11-22 22:36:54 +00:00
Brooks Davis
97e4bec56d syscalls: regen 2021-11-22 22:36:53 +00:00
Brooks Davis
88dfcfa2a0 sys_sigaltstack: use struct sigaltstack arg
This is idential to stack_t and more amenable to prepending "32" to
for freebsd32.

Reviewed by:	kib
2021-11-22 22:36:53 +00:00
N.J. Mann
a11983366e pchtherm: Let the driver be compiled into the kernel
PR:		259776
MFC after:	1 week
2021-11-22 12:12:37 -05:00
Alexander Motin
06bd74e1e3 GEOM: Switch g_io_deliver() locking from cp to pp.
Single provider may have multiple consumers, and locking one of consumers
is not sufficient to protect the provider.  Though the only part of the
provider this locking protects now is its statistics.

Reported by:	Arka Sharma <arka.sw1988@gmail.com>
MFC after:	2 weeks
2021-11-21 18:50:59 -05:00
Warner Losh
a8837c77ef mpr: fix freeze / release mismatch in timeout code
So, if we're processing a timeout, and we've sent an ABORT to the
firmware for that timeout, but not yet received the response from the
firmware, AND we get another timeout, we queue the timeout and freeze
the queue. However, when we've finally processed them all, we only
release the queue once. This causes all I/O to halt as the devq remains
frozen forever.

Instead, only freeze the queue when we start the process (eg set INRESET
on the target). This will allow the release when all the timed out I/Os
have finished ABORTing.

Sponsored by:		Netflix
Reviewed by:		mav
Differential Revision:	https://reviews.freebsd.org/D33054
2021-11-21 08:54:45 -07:00
Robert Wing
8981a100e6 mount: retire kernel_vmount()
The last usage of this function was removed in e3b1c847a4.

There are no in-tree consumers of kernel_vmount().

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D32607
2021-11-20 10:22:28 -09:00
Kristof Provost
b46512f704 if_stf: add dtrace probe points
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D33038
2021-11-20 19:29:01 +01:00
Kristof Provost
19dc644511 if_stf: add 6rd support
Implement IPv6 Rapid Deployment (RFC5969) on top of the existing 6to4
(RFC3056) if_stf code.

PR:		253328
Reviewed by:	hrs
Obtained from:	pfSense
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D33037
2021-11-20 19:29:01 +01:00
Mark Johnston
705a6ee2b6 zfs: Fix a deadlock between page busy and the teardown lock
When rolling back a dataset, ZFS has to purge file data resident in the
system page cache.  To do this, it loops over all vnodes for the
mountpoint and calls vn_pages_remove() to purge pages associated with
the vnode's VM object.  Each page is thus exclusively busied while the
dataset's teardown write lock is held.

When handling a page fault on a mapped ZFS file, FreeBSD's page fault
handler busies newly allocated pages and then uses VOP_GETPAGES to fill
them.  The ZFS getpages VOP acquires the teardown read lock with vnode
pages already busied.  This represents a lock order reversal which can
lead to deadlock.

To break the deadlock, observe that zfs_rezget() need only purge those
pages marked valid, and that pages busied by the page fault handler are,
by definition, invalid.  Furthermore, ZFS pages always transition from
invalid to valid with the teardown lock held, and ZFS never creates
partially valid pages.  Thus, zfs_rezget() can use the new
vn_pages_remove_valid() to skip over pages busied by the fault handler.

PR:		258208
Tested by:	pho
Reviewed by:	avg, sef, kib
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D32931
2021-11-20 11:21:25 -05:00
Mark Johnston
ed6a9452be hyperv: Register the MSR-based timecounter during SI_SUB_HYPERVISOR
This reverts commit 9ef7df022a ("hyperv: Register hyperv_timecounter
later during boot") and adds a comment explaining why the timecounter
needs to be registered as early as it is.

PR:		259878
Fixes:	9ef7df022a ("hyperv: Register hyperv_timecounter later during boot")
Reviewed by:	kib
MFC after:	3 days
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33014
2021-11-19 17:30:05 -05:00
Mark Johnston
3339950117 timecounter: Initialize tc_lock earlier
Hyper-V wants to register its MSR-based timecounter during
SI_SUB_HYPERVISOR, before SI_SUB_LOCK, since an emulated 8254 may not be
available for DELAY().  So we cannot use MTX_SYSINIT to initialize the
timecounter lock.

PR:		259878
Reviewed by:	kib
MFC after:	3 days
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33014
2021-11-19 17:29:28 -05:00
Kristof Provost
3142d4f622 lagg: fix unused-but-set-variable
MFC after:	1 week
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2021-11-19 22:01:27 +01:00
Mitchell Horne
588ab3c774 Allow minidumps to be performed on the live system
Add a boolean parameter to minidumpsys(), to indicate a live dump. When
requested, take a snapshot of important global state, and pass this to
the machine-dependent minidump function. For now this includes the
kernel message buffer, and the bitset of pages to be dumped. Beyond
this, we don't take much action to protect the integrity of the dump
from changes in the running system.

A new function msgbuf_duplicate() is added for snapshotting the message
buffer. msgbuf_copy() is insufficient for this purpose since it marks
any new characters it finds as read.

For now, nothing can actually trigger a live minidump. A future patch
will add the mechanism for this. For simplicity and safety, live dumps
are disallowed for mips.

Reviewed by:	markj, jhb
MFC after:	2 weeks
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D31993
2021-11-19 15:05:53 -04:00
Mitchell Horne
10fe6f80a6 minidump: Use the provided dump bitset
When constructing the set of dumpable pages, use the bitset provided by
the state argument, rather than assuming vm_page_dump invariably. For
normal kernel minidumps this will be a pointer to vm_page_dump, but when
dumping the live system it will not.

To do this, the functions in vm_dumpset.h are extended to accept the
desired bitset as an argument. Note that this provided bitset is assumed
to be derived from vm_page_dump, and therefore has the same size.

Reviewed by:	kib, markj, jhb
MFC after:	2 weeks
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D31992
2021-11-19 15:05:52 -04:00
Mitchell Horne
1d2d1418b4 minidump: Use provided msgbuf pointer
Don't assume we are dumping the global message buffer, but use the one
provided by the state argument. While here, drop superfluous
cast to char *.

Reviewed by:	markj, jhb
MFC after:	2 weeks
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D31991
2021-11-19 15:05:52 -04:00
Mitchell Horne
681bd71047 minidump: reduce the amount direct accesses to page tables
During a live dump, we may race with updates to the kernel page tables.
This is generally okay; we accept that the state of the system while
dumping may be somewhat inconsistent with its state when the dump was
invoked. However, when walking the kernel page tables, it is important
that we load each PDE/PTE only once while operating on it. Otherwise, it
is possible to have the relevant PTE change underneath us. For example,
after checking the valid bit, but before reading the physical address.

Convert the loads to atomics, and add some validation around the
physical addresses, to ensure that we do not try to dump a non-existent
or non-canonical physical address.

Similarly, don't read kernel_vm_end more than once, on the off chance
that pmap_growkernel() is called between the two page table walks.

Reviewed by:	kib, markj
MFC after:	2 weeks
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D31990
2021-11-19 15:05:52 -04:00
Mitchell Horne
90d4da6225 amd64: provide PHYS_IN_DMAP() and VIRT_IN_DMAP()
It is useful for quickly checking an address against the DMAP region.
These definitions exist already on arm64 and riscv.

Reviewed by:	kib, markj
MFC after:	3 days
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D32962
2021-11-19 15:05:52 -04:00
Mitchell Horne
1adebe3cd6 minidump: Parameterize minidumpsys()
The minidump code is written assuming that certain global state will not
change, and rightly so, since it executes from a kernel debugger
context. In order to support taking minidumps of a live system, we
should allow copies of relevant global state that is likely to change to
be passed as parameters to the minidumpsys() function.

This patch does the work of parameterizing this function, by adding a
struct minidumpstate argument. For now, this struct allows for copies of
the kernel message buffer, and the bitset that tracks which pages should
be dumped (vm_page_dump). Follow-up changes will actually make use of
these arguments.

Notably, dump_avail[] does not need a snapshot, since it is not expected
to change after system initialization.

The existing minidumpsys() definitions are renamed, and a thin MI
wrapper is added to kern_dump.c, which handles the construction of
the state struct. Thus, calling minidumpsys() remains as simple as
before.

Reviewed by:	kib, markj, jhb
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D31989
2021-11-19 15:05:52 -04:00
Gordon Bergling
d7125850f0 ixl(4): Fix a typo in a sysctl description
MFC after:	3 days
2021-11-19 19:59:28 +01:00
Gordon Bergling
8acb662126 iwm(4): Fix a typo in a source code comment
- s/availabe/available/

MFC after:	3 days
2021-11-19 19:51:55 +01:00
Gordon Bergling
3e5ddef0fd firewire(4): Fix a typo in a source code comment
- s/unavailabe/unavailable/

MFC after:	3 days
2021-11-19 19:50:56 +01:00
Gordon Bergling
5e21882bb4 iscsi(4): Fix a typo in a source code comment
- s/conditon/condition/

MFC after:	3 days
2021-11-19 19:29:21 +01:00
Gordon Bergling
8b11850f9d TWL: Fix a typo in a source code comment
- s/maxium/maximum/

MFC after:	3 days
2021-11-19 19:26:34 +01:00
Gordon Bergling
975e2e3f84 ppbus(4): Fix a typo in source code comment
- s/quering/querying/

Obtained from:	NetBSD
MFC after:	3 days
2021-11-19 19:19:36 +01:00
Gordon Bergling
bebff61587 ffs_softdep: Fix a typo in a source code comment
- s/conditonally/conditionally/

MFC after:	3 days
2021-11-19 19:17:41 +01:00
Gordon Bergling
b4fbc855a5 cc_newreno(4): Fix a typo in a source code comment
- s/conditons/conditions/

MFC after:	3 days
2021-11-19 19:16:02 +01:00
Gordon Bergling
15b5c347f1 sched_ule(4): Fix two typo in source code comments
- s/conditons/conditions/
- s/unconditonally/unconditionally/

MFC after:	3 days
2021-11-19 19:13:28 +01:00
Andriy Gapon
1bfdb812c7 iflib_stop: drain rx tasks to prevent any data races
iflib_stop modifies iflib data structures that are used by _task_fn_rx,
most prominently the free lists.  So, iflib_stop has to ensure that the
rx task threads are not active.

This should help to fix a crash seen when iflib_if_ioctl (e.g.,
SIOCSIFCAP) is called while there is already traffic flowing.

The crash has been seen on VMWare guests with vmxnet3 driver.

My guess is that on physical hardware the couple of 1ms delays that
iflib_stop has after disabling interrupts are enough for the queued work
to be completed before any iflib state is touched.

But on busy hypervisors the guests might not get enough CPU time to
complete the work, thus there can be a race between the taskqueue
threads and the work done to handle an ioctl, specifically in iflib_stop
and iflib_init_locked.

PR:		259458
Reviewed by:	markj
MFC after:	3 weeks
Differential Revision:	https://reviews.freebsd.org/D32926
2021-11-19 10:00:38 +02:00
Wuyang Chung
8587d75255 Correct the name of the second parameter of biowait to wmesg
This parameter is passed directly to msleep, and the name of the msleep
parameter is wmesg. Make them match.

Pull Request: https://github.com/freebsd/freebsd-src/pull/557
2021-11-18 23:26:33 -07:00
betterentley
f7c32ed617 Fix 'take effect' spelling in menus and comments.
Signed-off-by: John Bentley <johnbentley.public@gmail.com>
Pull Request: https://github.com/freebsd/freebsd-src/pull/559
2021-11-18 23:22:12 -07:00
Wuyang Chung
9cb485d18f geom: Remove g_class.config
g_class.config is write only, remove it.
2021-11-18 23:17:07 -07:00
Elyes HAOUAS
9097ac9af4 Fix typo on "Celsius"
"Celcius" --> "Celsius"

Signed-off-by: Elyes HAOUAS <ehaouas@noos.fr>
Pull Request: https://github.com/freebsd/freebsd-src/pull/551/files
2021-11-18 23:05:32 -07:00
Gleb Smirnoff
ff94500855 Add tcp_freecb() - single place to free tcpcb.
Until this change there were two places where we would free tcpcb -
tcp_discardcb() in case if all timers are drained and tcp_timer_discard()
otherwise.  They were pretty much copy-n-paste, except that in the
default case we would run tcp_hc_update().  Merge this into single
function tcp_freecb() and move new short version of tcp_timer_discard()
to tcp_timer.c and make it static.

Reviewed by:		rrs, hselasky
Differential revision:	https://reviews.freebsd.org/D32965
2021-11-18 20:27:45 -08:00
Gleb Smirnoff
fb8588d2cb tcp_timewait: use on stack struct tcptw as last resort
In case we failed to uma_zalloc() and also failed to reuse with
tcp_tw_2msl_scan(), then just use on stack tcptw.  This will allow
to run through tcp_twrespond() and standard tcpcb discard routine.

Reviewed by:		rrs
Differential revision:	https://reviews.freebsd.org/D32965
2021-11-18 20:27:45 -08:00
Bjoern A. Zeeb
ae2268efd5 LinuxKPI: make bcd.h use libkern
Rather than having code to re-define bcd2bin() for the LinuxKPI
make sure libkern.h is always included before the LinuxKPI version.
Then only re-define our local LinuxKPI implementation.  [1]

From the argument truncating wrapper call the libkern version.
If we change our libkern implementation in the future we can save
us the remainder of the hassle. [2]  Given I need this to MFC,
which I am not sure we can with libkern, commit this intermediate
step.

Suggested by:	Johannes Berg (johannes sipsolutions.net) [1]
Suggested by:	ian [2]
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
X-MFC with:	548ada00e5
Differential Revision: https://reviews.freebsd.org/D32695
2021-11-18 23:10:34 +00:00
Neel Chauhan
be60d8f276 ext2fs: check for eh_depth in ext4_ext_check_header()
PR:			259112
Reported by:		Robert Morris <rtm@lcs.mit.edu>
Reviewed by:		fsu
MFC after:		3 days
Differential Revision:	https://reviews.freebsd.org/D33030
2021-11-18 09:54:42 -08:00
Bjoern A. Zeeb
f7c526ab3f net80211: radiotap add another define
Add a define needed by latest iwlwifi-next.

Sponsored by:	The FreeBSD Foundation
2021-11-18 14:59:04 +00:00
Konstantin Belousov
0d7a6199b6 kmod_syms.awk: fix removal of the export list from the symbol table
Print some warning when export is requested for non-existing symbol.

Reviewed by:	emaste
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D32878
2021-11-18 15:56:24 +02:00
Konstantin Belousov
a7e4eb1422 Kernel linkers: some style
Reviewed by:	emaste
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Differential revision:	https://reviews.freebsd.org/D32878
2021-11-18 15:56:23 +02:00
Konstantin Belousov
5bb3134a8c Fix some modules to export more used symbols
and remove non-present symbols that are now reported by kmod_syms.awk.

Reviewed by:	emaste
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D32878
2021-11-18 15:56:23 +02:00
Gleb Smirnoff
3850d1837b in6_rmx: remove unnecessary TCP includes 2021-11-18 00:54:29 -08:00
Gleb Smirnoff
0dff875fa9 ipfw: remove unnecessary TCP related includes 2021-11-18 00:54:28 -08:00
Roger Pau Monné
50d7d967bb xen/privcmd: fix MMAP_RESOURCE ioctl to copy out results
The current definition for the MMAP_RESOURCE ioctl was wrong as it
didn't copy back the result to the caller. Fix the definition and also
remove the bogus attempt to copy the result in the implementation.

Note such copy back is only needed when querying the size of a
resource.

Sponsored by: Citrix Systems R&D
2021-11-18 09:46:44 +01:00
Konstantin Belousov
4fdc5b8494 g_vfs_close(): vp is unused
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2021-11-18 05:02:59 +02:00
Brooks Davis
fea4a9aff1 fspacectl: remove unneeded freebsd32 wrapper
fspacectl(2) does not require special handling on freebsd32. The
presence of off_t in a struct does not cause it's size to change
between the native ABI and the 32-bit ABI supported by freebsd32
because off_t is always int64_t on BSD systems.  Further, byte
order only requires handling for paired argument or return registers.

(32-byte alignment of 64-bit objects on i386 can require special
handling, but that situtation does not apply here.)

Reviewed by:	kib, khng, emaste, delphij
Differential Revision:	https://reviews.freebsd.org/D32994
2021-11-18 01:02:06 +00:00
Alex Richardson
4082b189d2 elf*_brand_inuse: Change return type to bool.
Reviewed by:	kib
Obtained from:	CheriBSD
Sponsored by:	The University of Cambridge, Google Inc.
Differential Revision:	https://reviews.freebsd.org/D33052
2021-11-17 15:51:40 -08:00
Alex Richardson
1962164584 imgact_elf: Use bool instead of boolean_t.
Reviewed by:	kib
Obtained from:	CheriBSD
Sponsored by:	The University of Cambridge, Google Inc.
Differential Revision:	https://reviews.freebsd.org/D33051
2021-11-17 15:51:29 -08:00
John Baldwin
8b2ce7a3bb linux_name_to_handle_at: Support AT_EMPTY_PATH.
Reviewed by:	kib
Sponsored by:	The University of Cambridge, Google Inc.
Differential Revision:	https://reviews.freebsd.org/D33050
2021-11-17 15:51:18 -08:00
John Baldwin
a8d885296a linux_linkat: Don't invert AT_* flags.
Reviewed by:	kib
Sponsored by:	The University of Cambridge, Google Inc.
Differential Revision:	https://reviews.freebsd.org/D33048
2021-11-17 15:51:06 -08:00
Brooks Davis
572be9c8ae freebsd32: sync some audit types with default ABI
Reviewed by:	kevans
2021-11-17 20:12:27 +00:00
Brooks Davis
67fb0300ae freebsd32: sync return types with default ABI
This consists of int -> ssize_t where required and one int -> mode_t.
As a rule, return types are informative rather than functional as the
actual return is in a register.

Reviewed by:	kevans
2021-11-17 20:12:26 +00:00
Brooks Davis
265a4b8341 freebsd32: semid_t -> int32_t
semid_t is historically an intptr_t so it should be an int32_t.

Reviewed by:	kevans
2021-11-17 20:12:26 +00:00
Brooks Davis
1a7a780bf4 freebsd32: update unimplemented syscall comments
These were out of sync with sys/kern/syscalls.master

Reviewed by:	kevans
2021-11-17 20:12:26 +00:00
Brooks Davis
aef154d3f2 freebsd32: use __socklen_t consistently
Reviewed by:	kevans
2021-11-17 20:12:26 +00:00
Brooks Davis
738ec2ed66 freebsd32: tag RESERVED syscalls
This reduces diffs when generating freebsd32 files from the default
ABI's syscalls.master.

Reviewed by:	kevans
2021-11-17 20:12:26 +00:00
Brooks Davis
a016320dfb freebsd32: rename 32-bit compat pads to _pad
Some 32-bit architectures pass 64-bit values in aligned
register pairs (a0,a1), (a2,a3) etc.  In freebsd32 we add these pads
explicitly from compat code.  We also sometimes add pads in the default
ABI.  Differentiate the two by making the freebsd32 ones int _pad.
In a future commit the 32-bit ones will be automatically generated.

Reviewed by:	kevans
2021-11-17 20:12:26 +00:00
Brooks Davis
158dcd7395 freebsd32: have sigqueue take a void *
This matches the default ABI and we work around issues with
union sigval by extracting the bottom 32-bits in a manual handler.

Reviewed by:	kevans
2021-11-17 20:12:26 +00:00
Brooks Davis
2b9d052d3e freebsd32: fix getfsstat sign extension bugs
Add freebsd32 versions of getfsstat and freebsd11_getfsstat so that
bufsize is properly sign-extended if a negative value is passed.
Reject negative values before passing to kern_getfsstat as a size_t.

Reviewed by:	kevans
2021-11-17 20:12:26 +00:00
Brooks Davis
f19e3fd206 freebsd32: signed long corrections
Syscalls that take signed longs need to treat the 32-bit versions as
signed int so that sign extension happens correctly.  Improve
decleration quality and add a few minimal syscall implementations.

Reviewed by:	kevans
2021-11-17 20:12:26 +00:00
Brooks Davis
d257e57d18 freebsd32: add missing pads to preadv and pwritev
Reviewed by:	kevans
2021-11-17 20:12:25 +00:00
Brooks Davis
f089a2f3d1 freebsd32: add stubs for ofreebsd32_(send|recv)msg
The upcoming change to generate freebsd32 generated files from
sys/kern/syscalls.master doesn't have a way to handle disabling
this one without disabling the non-COMPAT counterpart so just add
a stub for now.

Reviewed by:	kevans
2021-11-17 20:12:25 +00:00
Brooks Davis
e02f64d9b8 freebsd32: add real abort2
Previously, the code would copy twice as many pointers as specified
and print pairs of them a single 64-bit pointer.

abort2 doesn't return so make the return type void

freebsd32_abort2 is in it's own file with a 2-clause BSD license
based on a discussion with Wojciech many years ago.

Reviewed by:	kevans
2021-11-17 20:12:25 +00:00
Brooks Davis
e3e811a3f8 freebsd32: add feed foward clock syscalls
These are required when supporting i386 because time_t is 32-bit which
reduces struct bintime to 12-bytes when combined with the fact that 64-bit
integers only requiring 32-bit alignment on i386.  Reusing the default
ABI version resulted in 4-byte overreads or overwrites to userspace.

Reviewed by:	kevans
2021-11-17 20:12:25 +00:00
Brooks Davis
7bd795650f freebsd32: enable trivial syscalls
These syscalls require no translation.  They were simply missing
from compat/freebsd32/syscalls.master.

Reviewed by:	kevans
2021-11-17 20:12:25 +00:00
Brooks Davis
91301e6ea5 freebsd32: don't implement kldsym
Previously we fell back to sys_kldsym, but because we'd always
mismatch on the version field we'd return EINVAL.  A freebsd32
implementation is impossible with the current ABI as there simply
isn't space to store a kernel virtual address in a uint32_t.

Reviewed by:	kevans
2021-11-17 20:12:25 +00:00
Brooks Davis
25fec55b86 freebsd32: remove freebsd11_freebsd32_getdents
It's exactly the same as freebsd11_getdents.

Reviewed by:	kevans
2021-11-17 20:12:25 +00:00
Brooks Davis
1de34945f4 freebsd32: remove redundent osig*() implementations
ofreebsd32_sigprocmask, ofreebsd32_sigblock, ofreebsd32_sigsetmask,
and ofreebsd32_sigsuspend were all duplicates of the default ABI
versions and there are no type concerns as all arguments are the
same.

Reviewed by:	kevans
2021-11-17 20:12:25 +00:00
Brooks Davis
dbb47e9264 freebsd32: remove freebsd32_recvfrom
The freebsd32_recvfrom() serves no purpose as no arguments require
translation.  The prototype was mis-declared and the implementation
contained (relatively harmless) errors.

Reviewed by:	kevans
2021-11-17 20:12:24 +00:00
Brooks Davis
ad58266704 freebsd32: remove redundant no-arg syscalls
pipe requires no special handling.

ofreebsd32_sigpending did differ from osigpending in that it acted
on the siglist rather than the sigqueue, but this appears to be an
oversight in 3fbdb3c215.

ogetpagesize could theoretically have ABI-dependent results, but in
practice does not. If it does it would be easy handle in the central
implementation and be the least of the problems in changing the value of
PAGE_SIZE.

Reviewed by:	kevans
2021-11-17 20:12:24 +00:00
Brooks Davis
5b5a48c787 freebsd32: simplify memrange translation
Assume we've been passed a valid argument and use _IOC_NEWTYPE to
translate the command as we do elsewhere.

Reviewed by:	kevans
2021-11-17 20:12:24 +00:00
Brooks Davis
ab3ccb7583 freebsd32: rename fstat() stat buffer argument
Reviewed by:	kevans
2021-11-17 20:12:24 +00:00
Brooks Davis
b35c2bca9f freebsd32: rename struct wrusage32 to struct __wrusage32
This matches struct __wrusage

Reviewed by:	kevans
2021-11-17 20:12:24 +00:00
Brooks Davis
0ebea13928 freebsd32: include __ in semctl names
This mirrors sys/kern/syscall.master and will simplify generation
of freebsd32 files.

Reviewed by:	kevans
2021-11-17 20:12:24 +00:00
Brooks Davis
d35a771660 freebsd32: sync _umtx_op args with default ABI
Reviewed by:	kevans
2021-11-17 20:12:24 +00:00
Brooks Davis
f1a1411089 freebsd32: rename fstat argument to match default abi
Reviewed by:	kevans
2021-11-17 20:12:24 +00:00
Brooks Davis
3b0cd7e503 freebsd32: rename old SysV IPC types
Move the 32 from ...32_old to ..._old32 to aid automatic generation.

Reviewed by:	kevans
2021-11-17 20:12:23 +00:00
Brooks Davis
5d0d686940 freebsd32: struct kld32_file_stat -> struct kld_file_stat32
Follow common convention and put the `32` on the end of the struct
name.  This is a step toward generating freebsd32 syscall files
from sys/kern/syscalls.master.

Reviewed by:	kevans
2021-11-17 20:12:23 +00:00
Brooks Davis
e5b0997650 freebsd32: add a union semun_old32
Use this for COMPAT7 support.  In practice it's the same as
union semun32 since the pointers become uint32_t's the it's more
symetric and is the logical thing to generate from semun_old.

Reviewed by:	kevans
2021-11-17 20:12:23 +00:00
Brooks Davis
6dcd7db176 freebsd32: fix type size of pointer array args
Make pointers to arrays of pointers `uint32_t *` so the sizes of the
array elements are correct.  In an ideal world we'd use something
like __ptr32 annotations instead.

Reviewed by:	kevans
2021-11-17 20:12:23 +00:00
Brooks Davis
465b80c04a freebsd32: thread IDs are int32_t
Thread IDs are of type long which means int32_t on 32-bit systems.
While this detail is handled without compat functions, expose it
here as code to generate prototypes from the default syscalls.master
will do so.

Reviewed by:	kevans
2021-11-17 20:12:23 +00:00
Brooks Davis
2e89f95d6a freebsd32: fix types on statfs syscalls
Rename struct statfs32 to struct ostatfs32 to mirror struct ostatfs.
These structs are use for COMPAT4 support.  Stop using struct statfs32
for modern implementations as struct statfs uses fixed-width types
and it the same on all architectures.

Reviewed by:	kevans
2021-11-17 20:12:23 +00:00
Brooks Davis
381f6804ec freebsd32: fix type of olstat arg
Reviewed by:	kevans
2021-11-17 20:12:23 +00:00
Brooks Davis
9946c920a4 freebsd32: wait6 and procctl take idtype_t
Reviewed by:	kevans
2021-11-17 20:12:23 +00:00
Brooks Davis
ddae7b9aaa freebsd32: use size_t where the default ABI does
While the caller will never pass a larger value, we can use size_t
due to it being unsigned.

Reviewed by:	kevans
2021-11-17 20:12:23 +00:00
Brooks Davis
70c9698f40 freebsd32: match ioctl type to default ABI
The command is a u_long and unsigned integers do not require special
handling. The data argument isn't a special structure, just use char *.

Reviewed by:	kevans
2021-11-17 20:12:22 +00:00
Brooks Davis
8ba369ed74 freebsd32: [gs]etitimer's which arg is an int
Reviewed by:	kevans
2021-11-17 20:12:22 +00:00
Brooks Davis
a944d28d0e freebsd32: sprinkle in missing consts
A number of syscalls have missing consts on their arguments relative to
the default syscalls.master.

Also, use timespec32 and timeval32 where appropriate.

No functional change.

Reviewed by:	kevans
2021-11-17 20:12:22 +00:00
Brooks Davis
43227e4c83 freebsd32: prototype gssd_syscall()
Nothing about the interface should prevent this from working so
go ahead and prototype it for consistency.

Reviewed by:	kevans
2021-11-17 20:12:22 +00:00
Brooks Davis
6de7c05379 freebsd32: name the ucontext struct __ucontext32
This matches the default ABI's struct __ucontext.

Reviewed by:	kevans
2021-11-17 20:12:22 +00:00
Brooks Davis
5fdbd21d08 freebsd32: rename freebsd4_freebsd32_sigreturn arg
Rename struct freebsd4_freebsd32_ucontext to struct freebsd4_ucontext32
allowing conversion from the default ABI's struct freebsd4_ucontext
by appending "32".  This has no practical effect as this type does not
actually exist.

Give freebsd4_freebsd32_sigreturn an ANSI C prototype.

Reviewed by:	kevans
2021-11-17 20:12:22 +00:00
Brooks Davis
85d1d2a675 syscalls: use struct siginfo rather than siginfo_t
This allows freebsd32 to use struct siginfo32 with an automatable
conversion.

Reviewed by:	kevans
2021-11-17 20:12:22 +00:00
Brooks Davis
f503288262 syscalls: fix type of osendmsg
osendmsg takes an struct omsghdr * not a void *.

Reviewed by:	kevans
2021-11-17 20:12:22 +00:00
Brooks Davis
2385f4d172 syscalls: use __socklen_t as appropriate
No functional change as __socklen_t is an int.

Obtained from:	CheriBSD

Reviewed by:	kevans
2021-11-17 20:12:22 +00:00
Brooks Davis
b64f3dc26c syscalls: [gs]etitimer takes an int which
Match the function decleration which takes an int not a signed int.
No functional change as the range of valid values is 0-2.

Obtained from: CheriBSD

Reviewed by:	kevans
2021-11-17 20:12:21 +00:00
Brooks Davis
b7fd86118f syscalls: sprinkle in const values
Add missing const qualifiers to a number of syscall arguments.

Obtained from:	CheriBSD

Reviewed by:	kevans
2021-11-17 20:12:21 +00:00
Brooks Davis
1739de97af makesyscalls: make strip_abi_prefix more robust
Allow strip_abi_prefix() to be called with nil and return nil in that
case.  This simplifies handling of RESERVED entries.

Reviewed by:	kevans
2021-11-17 20:12:21 +00:00
Mark Johnston
8a693ccf86 Export symbols from opensolaris.ko and dtrace.ko
Both modules provide many symbols used by various DTrace provider
modules, so just export everything.

MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2021-11-17 13:51:10 -05:00
Allan Jude
2e946f8705 Fix ZFS module build
resolves: link_elf_obj: symbol abd_checksum_edonr_native undefined

The required module-build bits were originally identified in the
upstream pull request: https://github.com/openzfs/zfs/pull/12735
But were missed when the code was imported (since they are not
committed upstream).

X-MFC-With:	dae1713419, 09cd634160
Submitted by:	freqlabs
Sponsored by:	Klara Inc.
2021-11-17 15:07:05 +00:00
Randall Stewart
97e28f0f58 tcp: Rack ack war with a mis-behaving firewall or nat with resets.
Previously we added ack-war prevention for misbehaving firewalls. This is
where the f/w or nat messes up its sequence numbers and causes an ack-war.
There is yet another type of ack war that we have found in the wild that is
like unto this. Basically the f/w or nat gets a ack (keep-alive probe or such)
and instead of turning the ack/seq around and adding a TH_RST it does something
real stupid and sends a new packet with seq=0. This of course triggers the challenge
ack in the reset processing which then sends in a challenge ack (if the seq=0 is within
the range of possible sequence numbers allowed by the challenge) and then we rinse-repeat.

This will add the needed tweaks (similar to the last ack-war prevention using the same sysctls and counters)
to prevent it and allow say 5 per second by default.

Reviewed by: Michael Tuexen
Sponsored by: Netflix Inc.
Differential Revision: https://reviews.freebsd.org/D32938
2021-11-17 09:45:51 -05:00
Stefan Eßer
09cd634160 zfs: fix commit dae1713419 merge openzfs/zfs@269b5dadc into main
Commit dae1713419 did not add two required lines for edonr specific
functionality to this file, causing kernel build failures if ZFS is
compiled in.

This commit should be included in an eventual MFC of dae1713419.
2021-11-17 13:16:39 +01:00
Martin Matuska
dae1713419 zfs: merge openzfs/zfs@269b5dadc (master) into main
Notable upstream pull request merges:
  #12285 Introduce a tunable to exclude special class buffers from L2ARC
  #12689 Check l2cache vdevs pending list inside the vdev_inuse()
  #12735 Enable edonr in FreeBSD
  #12743 FreeBSD: fix world build after de198f2
  #12745 Restore dirty dnode detection logic

Obtained from:	OpenZFS
OpenZFS commit:	269b5dadcf
2021-11-17 09:39:40 +01:00
Kristof Provost
b6cbbcae40 m_get3(): actually use the selected zone
Reported by:	markj
2021-11-17 03:09:20 +01:00
Kristof Provost
8e492101ec pf: add COMPAT_FREEBSD13 for DIOCKEEPCOUNTERS
DIOCKEEPCOUNTERS used to overlap with DIOCGIFSPEEDV0, which has been
fixed in 14, but remains in stable/12 and stable/13.
Support the old, overlapping, call under COMPAT_FREEBSD13.

Reviewed by:	jhb
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D33001
2021-11-17 03:09:20 +01:00
Kristof Provost
4e85b64890 Add a COMPAT_FREEBSD13 kernel option
Use it wherever COMPAT_FREEBSD11 is currently specified.

Reviewed by:	jhb (previous version)
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D33005
2021-11-17 03:08:40 +01:00
Kristof Provost
23e1961e78 riscv: add COMPAT_FREEBSD12 option
Turn on compat option for older FreeBSD versions (i.e. 12). We do not
enable the compat options for 11 or older because riscv was never
supported in those versions.

Reviewed by:	jrtc27 (previous version)
MFC after:	1 week
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D33015
2021-11-17 03:08:14 +01:00
Marcin Wojtas
b014e0f15b Enable ASLR by default for 64-bit executables
Address Space Layout Randomization (ASLR) is an exploit mitigation
technique implemented in the majority of modern operating systems.
It involves randomly positioning the base address of an executable
and the position of libraries, heap, and stack, in a process's address
space. Although over the years ASLR proved to not guarantee full OS
security on its own, this mechanism can make exploitation more difficult.

Tests on the tier 1 64-bit architectures demonstrated that the ASLR is
stable and does not result in noticeable performance degradation,
therefore it should be safe to enable this mechanism by default.
Moreover its effectiveness is increased for PIE (Position Independent
Executable) binaries. Thanks to commit 9a227a2fd6 ("Enable PIE by
default on 64-bit architectures"), building from src is not necessary
to have PIE binaries. It is enough to control usage of ASLR in the
OS solely by setting the appropriate sysctls.

This patch toggles the kernel settings to use address map randomization
for PIE & non-PIE 64-bit binaries. It also disables SBRK, in order
to allow utilization of the bss grow region for mappings. The latter
has no effect if ASLR is disabled, so apply it to all architectures.

As for the drawbacks, a consequence of using the ASLR is more
significant VM fragmentation, hence the issues may be encountered
in the systems with a limited address space in high memory consumption
cases, such as buildworld. As a result, although the tests on 32-bit
architectures with ASLR enabled were mostly on par with what was
observed on 64-bit ones, the defaults for the former are not changed
at this time. Also, for the sake of safety keep the feature disabled
for 32-bit executables on 64-bit machines, too.

The committed change affects the overall OS operation, so the
following should be taken into consideration:
* Address space fragmentation.
* A changed ABI due to modified layout of address space.
* More complicated debugging due to:
  * Non-reproducible address space layout between runs.
  * Some debuggers automatically disable ASLR for spawned processes,
    making target's environment different between debug and
    non-debug runs.

In order to confirm/rule-out the dependency of any encountered issue
on ASLR it is strongly advised to re-run the test with the feature
disabled - it can be done by setting the following sysctls
in the /etc/sysctl.conf file:
kern.elf64.aslr.enable=0
kern.elf64.aslr.pie_enable=0

Co-developed by: Dawid Gorecki <dgr@semihalf.com>
Reviewed by: emaste, kib
Obtained from: Semihalf
Sponsored by: Stormshield
MFC after: 1 month
Differential revision: https://reviews.freebsd.org/D27666
2021-11-16 23:16:09 +01:00
Mark Johnston
32854e528a mbuf: Properly set the default value for mb_use_ext_pgs
Reported by:	Jenkins
Fixes:	fcaa890c44 ("mbuf: Only allow extpg mbufs if the system has a direct map")
Pointy hat:	markj
2021-11-16 16:23:11 -05:00
Mark Johnston
756bb50b6a sctp: Remove now-unneeded mb_unmapped_to_ext() calls
sctp_delayed_checksum() now handles unmapped mbufs, thanks to m_apply().

No functional change intended.

Reviewed by:	tuexen
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D32942
2021-11-16 13:38:09 -05:00
Mark Johnston
b4d758a0cc sctp: Use m_apply() to calcuate a checksum for an mbuf chain
m_apply() works on unmapped mbufs, so this will let us elide
mb_unmapped_to_ext() calls preceding sctp_calculate_cksum() calls in
the network stack.

Modify sctp_calculate_cksum() to assume it's passed an mbuf header.
This assumption appears to be true in practice, and we need to know the
full length of the chain.

No functional change intended.

Reviewed by:	tuexen, jhb
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D32941
2021-11-16 13:36:30 -05:00
Mark Johnston
fcaa890c44 mbuf: Only allow extpg mbufs if the system has a direct map
Some upcoming changes will modify software checksum routines like
in_cksum() to operate using m_apply(), which uses the direct map to
access packet data for unmapped mbufs.  This approach of course does not
work on platforms without a direct map, so we have to disallow the use
of unmapped mbufs on such platforms.

I believe this is the right tradeoff: we only configure KTLS on amd64
and arm64 today (and one KTLS consumer, NFS TLS, requires a direct map
already), and the use of unmapped mbufs with plain sendfile is a recent
optimization.  If need be, m_apply() could be modified to create
CPU-private mappings of extpg mbuf pages as a fallback.

So, change mb_use_ext_pgs to be hard-wired to zero on systems without a
direct map.  Note that PMAP_HAS_DMAP is not a compile-time constant on
some systems, so the default value of mb_use_ext_pgs has to be
determined during boot.

Reviewed by:	jhb
Discussed with:	gallatin
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D32940
2021-11-16 13:31:04 -05:00
Mark Johnston
42188bb5c1 unix: Remove a write-only local variable
Reported by:	clang
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2021-11-16 13:30:22 -05:00
Mark Johnston
4285655adb aesni: Avoid a potential out-of-bounds load in AES_GCM_encrypt()
Reported by:	Jenkins (KASAN job)
Reviewed by:	cem, jhb
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33012
2021-11-16 13:30:22 -05:00
Colin Percival
57a8fa6f01 kvmclock: Expose implied TSC frequency via sysctl
An interface was added to derive an implied TSC frequency from pvclock
in 2015, but this interface was never exposed anywhere user-visible.

Reviewed by:	kib, bryanv
Differential Revision:	https://reviews.freebsd.org/D32974
2021-11-16 10:27:27 -08:00
Colin Percival
1580afcd6e randomdev: Remove 100 ms sleep from write routine
This was introduced in 2014 along with the comment (which has since
been deleted):
	/* Introduce an annoying delay to stop swamping */

Modern cryptographic random number generators can ingest arbitrarily
large amounts of non-random (or even maliciously selected) input
without losing their security.

Depending on the number of "boot entropy files" present on the system,
this can speed up the boot process by up to 1 second.

Reviewed by:	cem
MFC ater:	1 week
Sponsored by:	https://www.patreon.com/cperciva
Differential Revision:	https://reviews.freebsd.org/D32984
2021-11-16 10:27:27 -08:00
Konstantin Belousov
c34a5148e8 ffs: fix newly introduced LOR between mntfs vnode lock and topology lock
The mntfs vnode lock should be before topology, as established in
ffs_mountfs().  Extend the locked region in ffs_unmount().

Reported and reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D33013
2021-11-16 20:01:31 +02:00
John Baldwin
16bea05ac3 ktls: Split encrypt vs decrypt OCF counters.
Reviewed by:	gallatin, markj
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D33006
2021-11-16 09:58:52 -08:00
Konstantin Belousov
8ef0c11e7c nfsclient: upgrade vnode lock in VOP_OPEN()/VOP_CLOSE() if we need to flush buffers
VOP_FSYNC() asserts that the vnode is exclusively locked for NFS.
If we try to execute file with recently modified content, the assert is
triggered.

Reviewed by:	rmacklem
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D32999
2021-11-16 19:13:29 +02:00
Warner Losh
2bbaed4d7f mpr: Minor formatting changes to match mps.
Minor reformatting nits to make mprsas_scsiio_timeout match
mpssas_scsiio_timeout more closely. The differences aren't necessary and
are distracting when comparing the routines. No functional changes.

Sponsored by:		Netflix
2021-11-15 21:27:15 -07:00
Warner Losh
b086bc0bf1 mps: Fix debugging line
Print cm instead of sc here, as is done in mpr. We can get the sc from
cm, but not vice versa.

Sponsored by:		Netflix
2021-11-15 21:27:14 -07:00
Kirk McKusick
9b8eb1c5b6 Followup to f2b391528a to improve printed message.
Sponsored by: Netflix
2021-11-15 16:10:02 -08:00
Kirk McKusick
9e9dcac95a Allow forced r/w mount of UFS/FFS filesystem with a bad check hash.
Normally a UFS/FFS filesystem with a bad check hash can only be
mounted read only. With this commit the mount(8) -f (force) option
can be used to force a read-write mount of a UFS/FFS filesystem with
a bad check hash. Conveniently the filesystem will proceed to
update its on-disk superblock with a corrected check hash.

Sponsored by: Netflix
2021-11-15 16:03:47 -08:00
Kirk McKusick
f10a8d0971 Allow the MNT_FORCE flag to be passed through to an initial mount.
When doing an initial mount(8) with its -f (force) flag, the MNT_FORCE
flag is not passed through to the underlying filesystem mount routine.
MNT_FORCE is only passed through on later updates to an existing
mount. With this commit the MNT_FORCE flag is now passed through on the
initial mount.

Sanity check: kib
Sponsored by: Netflix
2021-11-15 15:45:56 -08:00
Mark Johnston
22875f8879 x86: Implement deferred TSC calibration
There is no universal way to find the TSC frequency.  Newer Intel CPUs
may report it via CPUID leaves 0x15 and 0x16.  Sometimes it can be
obtained from the PLATFORM_INFO MSR as well, though we never use that.
On older platforms we derive the frequency using a DELAY(1000000) call,
which uses the 8254 PIT.  On some newer platforms the 8254 is apparently
non-functional, leading to bogus calibration results.  On such platforms
the TSC frequency must be available from CPUID.  It is also possible to
disable calibration with a tunable, in which case we try to parse the
brand string if the TSC freq is not available from CPUID.

CPUID 0x15 provides an authoritative TSC frequency value, but even that
is not always available on new Intel platforms.  CPUID 0x16 provides the
specified processor base frequency, which is not the same as the TSC
frequency.  Empirically, it is close enough for early boot, but too far
off for timekeeping: on a Comet Lake NUC, CPUID 0x16 yields 1600MHz but
the TSC frequency is rougly 1608MHz, leading to frequent clock stepping
when NTP is in use.

Thus we have a situation where we cannot calibrate using the PIT and
cannot obtain a precise frequency from CPUID (or MSRs).  This change
seeks to address that by using the CPUID 0x16 value during early boot
and refining the calibration later once ACPI-based timecounters are
available.  TSC frequency detection is thus split into two phases:

Early phase:
- On Intel platforms, query CPUID 0x15 and 0x16 and use that value
  initially if available.
- Otherwise, get an estimate using the PIT, reducing the delay loop to
  100ms from 1s.
- Continue to register the TSC as the CPU ticks provider early, even
  though the frequency may be off.  Otherwise any code executed during
  boot that uses cpu_ticks() (e.g., context switching) gets tripped up
  when the ticks provider changes.

Later phase:
- In SI_SUB_CLOCKS, once the timehands are initialized, load the current
  TSC and timecounter (sbinuptime()) values at the beginning and end of
  a 1s interval and use the timecounter frequency (typically from
  kvmclock, HPET or the ACPI PM timer) to estimate the TSC frequency.
- Update the TSC timecounter, global tsc_freq and CPU ticker with the
  new frequency and finally register the TSC as a timecounter.

Reviewed by:	kib, jhb (previous version)
Discussed with:	imp, cperciva
MFC after:	6 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D32512
2021-11-15 16:13:24 -05:00