]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
2 years agoAdd kern.elf{32,64}.vdso knobs to enable/disable vdso preloading
Konstantin Belousov [Thu, 25 Nov 2021 01:31:27 +0000 (03:31 +0200)]
Add kern.elf{32,64}.vdso knobs to enable/disable vdso preloading

(cherry picked from commit eb029587481e8d6f610eb31d7f50d34b9240f2f2)

2 years agovdso for ia32 on amd64
Konstantin Belousov [Sun, 14 Nov 2021 00:26:55 +0000 (02:26 +0200)]
vdso for ia32 on amd64

(cherry picked from commit 98c8b6252496e874d337d9a7b565d9037609168f)

2 years agortld: load preloaded vdso
Konstantin Belousov [Thu, 11 Nov 2021 18:07:44 +0000 (20:07 +0200)]
rtld: load preloaded vdso

(cherry picked from commit c210ef1347929cb3a0f46cdfdb3d4ad738e3af74)

2 years agoFix assert check for SV_DSO_SIG in exec_sysvec_init_secondary()
Justin Hibbits [Thu, 9 Dec 2021 04:50:10 +0000 (22:50 -0600)]
Fix assert check for SV_DSO_SIG in exec_sysvec_init_secondary()

(cherry picked from commit d2de68811a80bffe20040592dca194238c5a5c86)

2 years agoPass vdso address to userspace
Konstantin Belousov [Thu, 11 Nov 2021 17:29:24 +0000 (19:29 +0200)]
Pass vdso address to userspace

(cherry picked from commit 01c77a436e35d6dc9660ec7bac477946f563c99d)

2 years agoamd64: wrap 64bit sigtramp into vdso
Konstantin Belousov [Fri, 5 Nov 2021 08:07:24 +0000 (10:07 +0200)]
amd64: wrap 64bit sigtramp into vdso

(cherry picked from commit ab4524b3d7fba872a143b03c9346cb04c3670efa)

2 years agoRemove bogus cast from exec_sysvec_init().
Dmitry Chagin [Tue, 20 Jul 2021 06:54:09 +0000 (09:54 +0300)]
Remove bogus cast from exec_sysvec_init().

(cherry picked from commit b39fa4770dd19ff32b2d70622521135dd384c7c1)

2 years agoModify exec_sysvec_init() to allow non-native abi to setup their sysentvecs.
Dmitry Chagin [Tue, 20 Jul 2021 06:53:21 +0000 (09:53 +0300)]
Modify exec_sysvec_init() to allow non-native abi to setup their sysentvecs.

(cherry picked from commit 21629e2a456446bff101813a16f8cba046f44176)

2 years agoamd64 get_mcontext(): third argument to get_fpcontext() is a pointer
Konstantin Belousov [Sat, 1 Jan 2022 03:55:59 +0000 (05:55 +0200)]
amd64 get_mcontext(): third argument to get_fpcontext() is a pointer

(cherry picked from commit 76ef4f6348ccad73317ce2d10ab7a78d8591ba1a)

2 years agoitimers: strip unused bits from struct itimer and struct itimers
Konstantin Belousov [Mon, 27 Dec 2021 18:29:22 +0000 (20:29 +0200)]
itimers: strip unused bits from struct itimer and struct itimers

(cherry picked from commit 23ba59fbfb6ad580c4f185ffea2fa8a32b4d131d)

2 years agoitimers_alloc: no need to initialize its_timers array
Konstantin Belousov [Mon, 27 Dec 2021 18:32:01 +0000 (20:32 +0200)]
itimers_alloc: no need to initialize its_timers array

(cherry picked from commit 3f1570847831e6dbcafc1f416f96404bf66048f2)

2 years agoAvoid emitting popcnt in libclang_rt.fuzzer*.a if unsupported
Dimitry Andric [Thu, 30 Dec 2021 09:53:25 +0000 (10:53 +0100)]
Avoid emitting popcnt in libclang_rt.fuzzer*.a if unsupported

Since popcnt is only supported by CPUTYPE=nehalem and later, ensure that
this instruction is only emitted when appropriate. Otherwise, programs
using the library can abort with SIGILL.

See also: https://github.com/llvm/llvm-project/issues/52893

PR: 258156
Reported by: Eric Rucker <bhtooefr@bhtooefr.org>
MFC after: 3 days

(cherry picked from commit 133180557479cd9676758e6f3f93a9d3e1c6b532)

2 years agolibc: Fix build with -DNS_REREAD_CONF.
Alexander Motin [Wed, 29 Dec 2021 22:00:17 +0000 (17:00 -0500)]
libc: Fix build with -DNS_REREAD_CONF.

MFC after: 3 days

(cherry picked from commit 62ed2d0152dce6da883fef753e0995e6d85e0cf1)

2 years agofd: Initialize more export_fd_buf fields in kern_proc_cwd_out()
Mark Johnston [Thu, 16 Dec 2021 21:53:59 +0000 (16:53 -0500)]
fd: Initialize more export_fd_buf fields in kern_proc_cwd_out()

In particular, we need to initialize efbuf->flags, since
export_vnode_to_sb() loads that field.  This was mostly harmless since
the flag only determines whether the output kinfo_file is packed, and
KERN_PROC_CWD only ever emits a single kinfo_file anyway.

Sponsored by: The FreeBSD Foundation

(cherry picked from commit 327060bd7799e5d4376693fba770a17b79e5a38d)

2 years agounix: Increase the default datagram recv buffer size
Mark Johnston [Fri, 17 Dec 2021 15:59:29 +0000 (10:59 -0500)]
unix: Increase the default datagram recv buffer size

syslog(3) was recently change to support larger messages, up to 8KB.
Our syslogd handles this fine, as it adjusts /dev/log's recv buffer to a
large size.  rsyslog, however, uses the system default of 4KB.  This
leads to problems since our syslog(3) retries indefinitely when a send()
returns ENOBUFS, but if the message is large enough this will never
succeed.

Increase the default recv buffer size for datagram sockets to support
8KB syslog messages without requiring the logging daemon to adjust its
buffers.

PR: 260126
Reviewed by: asomers
Sponsored by: The FreeBSD Foundation

(cherry picked from commit d157f2627b238ba38d1cad36f1aa165c42ce91ee)

2 years agoktls: Add a regression test to exercise socket error handling
Mark Johnston [Fri, 17 Dec 2021 16:00:19 +0000 (11:00 -0500)]
ktls: Add a regression test to exercise socket error handling

Prior to commit 916c61a5ed37 ("Fix handling of errors from
pru_send(PRUS_NOTREADY)") this test triggered a kernel panic due to an
mbuf double free.

Reviewed by: jhb
Sponsored by: The FreeBSD Foundation

(cherry picked from commit ee5686c614ba7e11e8586b2e5b02dfc550679e96)

2 years agoiwlwifi: attach to the build
Bjoern A. Zeeb [Mon, 27 Dec 2021 18:46:04 +0000 (18:46 +0000)]
iwlwifi: attach to the build

Add iwlwifi and iwlwififw to the module builds.

Sponsored by: The FreeBSD Foundation

(cherry picked from commit 7d4394cbe7072fff75a8fb94e0871c1408213f09)

2 years agoiwlwifi: plug memory modified after free
Bjoern A. Zeeb [Mon, 27 Dec 2021 17:42:51 +0000 (17:42 +0000)]
iwlwifi: plug memory modified after free

In certain situations we saw a memory modified after free.  This was
tracked down to a pointer not NULLed after free and used in a different
code path.  It is unclear how the race happens pending further
investigation but setting the pointer to NULL after free and adding a
check in the 2nd code path handling the case gracefully helps for now.

While here improve another debug messge in sta handling.

Sponsored by: The FreeBSD Foundation

(cherry picked from commit 586c8e32330591693c5fca4e089d90340b313f5d)

2 years agoiwlwifi: cherry-pick fixes from upstream iwlwifi-next
Bjoern A. Zeeb [Mon, 27 Dec 2021 17:41:19 +0000 (17:41 +0000)]
iwlwifi: cherry-pick fixes from upstream iwlwifi-next

Cherry-pick f973795a8d19cbf3d03807704eb7c6ff65788d5a (Fix a double free
in iwl_txq_dyn_alloc_dma), db66abeea3aefed481391ecc564fb7b7fb31d742
(synchronize with FW after multicast commands),
d5d8ee526d1401173ad1261c3b6388a4f947e0a3 (remove session protection
upon station removal), and 8e967c137df3b236d2075f9538cb888129425d1a
(avoid clearing a just saved session protection id).

Sponsored by: The FreeBSD Foundation

(cherry picked from commit 8f06a2b550c6288b48996036c325a1999780cb6a)

2 years agoiwlwifi: add man pages
Bjoern A. Zeeb [Mon, 27 Dec 2021 17:40:02 +0000 (17:40 +0000)]
iwlwifi: add man pages

Add and hook up man pages for iwlwifi and iwlwififw and install a copy
of the firmware license to /usr/share/docs/legal so it will always be
shipped with the installed system.

Sponsored by: The FreeBSD Foundation

(cherry picked from commit 5a02ae5e8f2d74b7ac20fa2e0cd98c66d934905b)

2 years agoiwlwifi: turn off broadcast filtering for now
Bjoern A. Zeeb [Mon, 27 Dec 2021 17:37:41 +0000 (17:37 +0000)]
iwlwifi: turn off broadcast filtering for now

Turn off broadcast filtering in iwlwifi for now as it gives me
or rather the firmware headaches.

Sponsored by: The FreeBSD Foundation

(cherry picked from commit c6ea5aed79a33ce3482c4e3fa2bf56a9ee495815)

2 years agoiwlwifi: also depend on linuxkpi_wlan
Bjoern A. Zeeb [Mon, 27 Dec 2021 17:36:04 +0000 (17:36 +0000)]
iwlwifi: also depend on linuxkpi_wlan

The 802.11 compat code is split off linuxkpi.ko into linuxkpi_wlan.ko
in case it is built as a module.  Depend on that.
While here adjust our module to a longer version to avoid conflicts.

Sponsored by: The FreeBSD Foundation

(cherry picked from commit 81ff67ffbec066bc5014a64e67de0219d943156a)

2 years agoiwlwifi: remove copyright and license from Makefiles
Bjoern A. Zeeb [Mon, 27 Dec 2021 17:34:40 +0000 (17:34 +0000)]
iwlwifi: remove copyright and license from Makefiles

We do not generally protect the Makefiles like this.
Remove the details and go with project style.

Sponsored by: The FreeBSD Foundation

(cherry picked from commit ca8bf0e8d68398b1f1f50dad1432130360b0bbdc)

2 years agoLinuxKPI: add 802.11 compat code
Bjoern A. Zeeb [Sun, 26 Dec 2021 18:52:51 +0000 (18:52 +0000)]
LinuxKPI: add 802.11 compat code

Add 802.11 compat code for mac80211 and to a minimal degree cfg80211.
This allows us to compile and use basic functionality of wireless
drivers such as iwlwifi.

This is a constant work in progress but having it in the tree will
allow others to test and more easy to track changes and avoid having
snapshots no longer applying to branches.

Sponsored by: The FreeBSD Foundation

(cherry picked from commit 6b4cac814e32f3b307720d6b880939fb1f21f3ac)

2 years agoLinuxKPI: import beginning of a new version of netdevice.h
Bjoern A. Zeeb [Sun, 26 Dec 2021 18:29:29 +0000 (18:29 +0000)]
LinuxKPI: import beginning of a new version of netdevice.h

Import a netdevice update complementing the last remaining bits of
the old ifnet derived implementation.  Along add a (for now) task
based NAPI implementation.

This is the minimal set of chnages which are needed for the initial
support of wireless drivers.  The NAPI implementation has an option to
still switch to "direct dispatch" as it had been used by these drivers
before not relying on a deferred context along with some printf tracing.
This has been helpful in the last weeks for debugging and will be
cleaned once we have had broader testing and are sure this is fine as-is.
Should we need a more time-sensitive or load-sensitive response
in the future we can always switch to something more sophisticated.

Sponsored by: The FreeBSD Foundation
X-Differential Revision: D33075 (abandoned without feedback a while ago)

(cherry picked from commit d105895844848ddba85d686e03e0d14c03ad4eb4)

2 years agoLinuxKPI: add a work-in-progress skbuff implementation
Bjoern A. Zeeb [Sun, 26 Dec 2021 18:26:26 +0000 (18:26 +0000)]
LinuxKPI: add a work-in-progress skbuff implementation

This is a work-in-progress implementation of sk_buff compat code
used for wireless drivers only currently.
Bring in this version of the code as it has proven to be good enough
to have packets going for a few months.

The current implementation has several drawbacks including the need
for us to copy data between sk_buffs and mbufs.
Do not rely on the internals of this implementation.  They are highly
likely to change as we will improve the integration to FreeBSD mbufs.

Sponsored by: The FreeBSD Foundation

(cherry picked from commit 49ed6e979c3b327ae466a559884802d901aa5792)

2 years agonet80211: adjust a printf to toeee80211_note
Bjoern A. Zeeb [Sun, 26 Dec 2021 17:26:58 +0000 (17:26 +0000)]
net80211: adjust a printf to toeee80211_note

Throughout net80211 there are multiple ways to log (debugging)
information.  Start to clenaup one as I kept hitting it to harmonize
the output.  The more we get away from printfs into either wrapper
functions or macros the more likely we can use holistic systematic
tracing in the future.

Sponsored by: The FreeBSD Foundation

(cherry picked from commit 2e59c9c7f01e9e8878664f59438d1ed6c27d0e2b)

2 years agonet80211: add debugging information
Bjoern A. Zeeb [Sun, 26 Dec 2021 17:25:57 +0000 (17:25 +0000)]
net80211: add debugging information

Add more STATE / DEBUG probes and enhance the output of one in order
to track state changes triggered by "ack" (or not).
This helped to narrow down causes from drivers or the LinuxKPI 802.11
compat framework which kept us in a scan -> auth -> scan loop.

Sponsored by: The FreeBSD Foundation

(cherry picked from commit 04efa18f83d12dca2b69dd4cdb626f92e5ce64f0)

2 years agonet80211: format debug functions as single line
Bjoern A. Zeeb [Sun, 26 Dec 2021 17:24:04 +0000 (17:24 +0000)]
net80211: format debug functions as single line

Making use of the debug output was hard given debug lines were run in
parts through vlog (if_printf) and in (multiple) parts through printf(s).

Like some of the functions alreay have, use a local buffer to format
the string and then use a single if_printf;  in addition given these
functions are debug-only, add an extra printf in case we find our
buffers still to be too small so we can adjust for the future.
We already found that 128 characters are to short for some log messages.
Bump the buffer sizes collectively to 256 characters which also is
the maximum of if_vlog() so getting longer would need further changes
elsewhere.

Sponsored by: The FreeBSD Foundation

(cherry picked from commit 04435a1b145b310f8be62dd453e2f0c69d764cca)

2 years agonet80211: fix debug printf
Bjoern A. Zeeb [Thu, 23 Dec 2021 15:21:32 +0000 (15:21 +0000)]
net80211: fix debug printf

We are printing %p in _db_show_sta(), there is no need to prefix it
with 0x again to get a 0x0x...

Spsonsored by: The FreeBSD Foundation

(cherry picked from commit e51b46cefbfaab08f6e5cb402ebecbf1c0cba3c8)

2 years agomodules: increase MAXMODNAME and provide backward compat
Bjoern A. Zeeb [Wed, 17 Nov 2021 19:35:46 +0000 (19:35 +0000)]
modules: increase MAXMODNAME and provide backward compat

With various firmware files used by graphics and wireless drivers
we are exceeding the current 32 character module name (file path
in kldxref) length.
In order to overcome this issue bump it to the maximum path length
for the next version.
To be able to MFC provide backward compat support for another version
of the struct as the offsets for the second half change due to the
array size increase.

MAXMODNAME being defined to MAXPATHLEN needs param.h to be
included first.  With only 7 modules (or LinuxKPI module.h) not
doing that adjust them rather than including param.h in module.h [1].

Reported by: Greg V (greg unrelenting.technology)
Sponsored by: The FreeBSD Foundation
Suggested by: imp [1]
Reviewed by: imp (and others to different level)
Differential Revision: https://reviews.freebsd.org/D32383

(cherry picked from commit df38ada2931f95d07b65b19fcfb4c9845d656ba9)

2 years agoiwlwifi: import Intel's iwlwifi/mvm driver.
Bjoern A. Zeeb [Sun, 28 Nov 2021 18:35:53 +0000 (18:35 +0000)]
iwlwifi: import Intel's iwlwifi/mvm driver.

Over the past few months we published multiple snapshots for this
Linux derived driver and it has become fairly stable in terms of
minimal local changes needed for new updates.

The current version is based on iwlwifi-next update at
cbaa6aeedee5f92dafa5982eceea2a1f98ce4f7d with the addition of
a hand full of files replaced for FreeBSD.

Given the lack of full license texts on non-local files this is
imported under the draft policy for handling SPDX files (D29226). [1]

Do not yet hook this to the build until the remaining compat code
is all in.  Along with the firmware import this will make publishing
the last bits and final testing a lot easier.

Sponsored by:   The FreeBSD Foundation
Approved by:    core (imp) [1]

(cherry picked from commit bfcc09ddd422c95a1a2e4e794b63ee54c4902398)

2 years agoiwlwifi: import firmware for Intel iwlwifi/mvm supported chipsets.
Bjoern A. Zeeb [Sun, 28 Nov 2021 18:34:19 +0000 (18:34 +0000)]
iwlwifi: import firmware for Intel iwlwifi/mvm supported chipsets.

Import the most recent versions of the firmware images for iwlwifi
chipsets supported by the "mvm" sub-driver.
This is based on linux-firmware at f5d519563ac9d2d1f382a817aae5ec5473811ac8.
The license of the firmware matches the previous iwnfw(4) and
iwmfw(4) firmware files and you can find a copy in
sys/contrib/dev/iwlwififw/LICENCE.iwlwifi_firmware .

Add build infrastructure to create the .ko files but do not yet hook
it up to the build until all parts are in the tree.
There is an open issue concerning kldxref that we need to resolve
(D32383).

Sponsored by: The FreeBSD Foundation

(cherry picked from commit f4c129f5fb1669b284d76a838b1e509f97c2d299)

2 years agoLinuxKPI: USB return possible error from suspend/resume
Bjoern A. Zeeb [Wed, 24 Nov 2021 21:28:46 +0000 (21:28 +0000)]
LinuxKPI: USB return possible error from suspend/resume

USB suspend/resume cannot fail so we never returned the error which
resulted in a -Wunused-but-set-variable warning.
Initialize the return variable and return a possible error possibly
triggering a printf upstream to at least have a trace of the problem.
This also fixes the warning.

Suggested by: hselasky
Sponsored by: The FreeBSD Foundation
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D33107

(cherry picked from commit 943df073a348bcb1e701c3677536f913761d4123)

2 years agoLinuxKPI: fix -Wunused-but-set-variable warnings
Bjoern A. Zeeb [Wed, 24 Nov 2021 21:20:52 +0000 (21:20 +0000)]
LinuxKPI: fix -Wunused-but-set-variable warnings

Handle write-only variables by removing the unused return value from void
functions or removing the unused variables entirely.

Sponsored by: The FreeBSD Foundation
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D33107

(cherry picked from commit 7043359ce3c1e56ed55c8b41867a14a418511a05)

2 years agostd.nodebug: turn off net80211 debugging as well
Bjoern A. Zeeb [Wed, 24 Nov 2021 18:03:48 +0000 (18:03 +0000)]
std.nodebug: turn off net80211 debugging as well

Add IEEE80211_DEBUG to turn off some net80211 debbugging for
no-debug builds.

Sponsored by: The FreeBSD Foundation

(cherry picked from commit 1c55b0ce1c944c0b1b7657b7efa151cd25a74f5b)

2 years agonet80211: fix -Wunused-but-set-variable warnings
Bjoern A. Zeeb [Wed, 24 Nov 2021 17:36:48 +0000 (17:36 +0000)]
net80211: fix -Wunused-but-set-variable warnings

Put the offending variables under the appropriate #ifdefs
(mostly IEEE80211_DEBUG, in one case IEEE80211_SUPPORT_SUPERG, and
in two cases under __notyet__ to revisit why these had been left
there but not used).

Sponsored by: The FreeBSD Foundation

(cherry picked from commit 05ea7a3e5e748547a0229efa80be0e71eaf84f52)

2 years agonet80211: radiotap add another define
Bjoern A. Zeeb [Thu, 18 Nov 2021 14:57:09 +0000 (14:57 +0000)]
net80211: radiotap add another define

Add a define needed by latest iwlwifi-next.

Sponsored by: The FreeBSD Foundation

(cherry picked from commit f7c526ab3f23e5663cb8477c3dfb41a89de2d4cd)

2 years agolibthr: Use kern.stacktop for thread stack calculation.
Dawid Gorecki [Wed, 13 Oct 2021 19:06:05 +0000 (21:06 +0200)]
libthr: Use kern.stacktop for thread stack calculation.

Use the new kern.stacktop sysctl to retrieve the address of stack top
instead of kern.usrstack. kern.usrstack does not have any knowledge
of the stack gap, so this can cause problems with thread stacks.
Using kern.stacktop sysctl should fix most of those problems.
kern.usrstack is used as a fallback when kern.stacktop cannot be read.

Rename usrstack variables to stacktop to reflect this change.

Fixes problems with firefox and thunderbird not starting with
stack gap enabled.

PR: 239873
Reviewed by: kib
Obtained from: Semihalf
Sponsored by: Stormshield
MFC after: 1 month
Differential Revision: https://reviews.freebsd.org/D31898

(cherry picked from commit 78df56ccfcb40013a3e6904bd6d39836220c3550)

2 years agokern_exec: Add kern.stacktop sysctl.
Dawid Gorecki [Wed, 13 Oct 2021 19:03:37 +0000 (21:03 +0200)]
kern_exec: Add kern.stacktop sysctl.

With stack gap enabled top of the stack is moved down by a random
amount of bytes. Because of that some multithreaded applications
which use kern.usrstack sysctl to calculate address of stacks for
their threads can fail. Add kern.stacktop sysctl, which can be used
to retrieve address of the stack after stack gap is applied to it.
Returns value identical to kern.usrstack for processes which have
no stack gap.

Reviewed by: kib
Obtained from: Semihalf
Sponsored by: Stormshield
MFC after: 1 month
Differential Revision: https://reviews.freebsd.org/D31897

(cherry picked from commit a97d697122da2bfb0baae5f0939d118d119dae33)

2 years agosetrlimit: Take stack gap into account.
Dawid Gorecki [Wed, 13 Oct 2021 19:01:08 +0000 (21:01 +0200)]
setrlimit: Take stack gap into account.

Calling setrlimit with stack gap enabled and with low values of stack
resource limit often caused the program to abort immediately after
exiting the syscall. This happened due to the fact that the resource
limit was calculated assuming that the stack started at sv_usrstack,
while with stack gap enabled the stack is moved by a random number
of bytes.

Save information about stack size in struct vmspace and adjust the
rlim_cur value. If the rlim_cur and stack gap is bigger than rlim_max,
then the value is truncated to rlim_max.

PR: 253208
Reviewed by: kib
Obtained from: Semihalf
Sponsored by: Stormshield
MFC after: 1 month
Differential Revision: https://reviews.freebsd.org/D31516

(cherry picked from commit 889b56c8cd84c9a9f2d9e3b019c154d6f14d9021)

2 years agobsdinstall: zfsboot: Prompt user for zpool name if the pool already exists
Emmanuel Vadot [Wed, 8 Dec 2021 10:37:50 +0000 (11:37 +0100)]
bsdinstall: zfsboot: Prompt user for zpool name if the pool already exists

If one install FreeBSD on multiple disks (say 13 and CURRENT) the first created
pool will always be used.
Prompt the user for a new pool name if we detect that the default or supplied one
already exists.

Reviewed by: imp
MFC after:      2 weeks
Sponsored by:   Beckhoff Automation GmbH & Co. KG
Differential Revision: https://reviews.freebsd.org/D33331

(cherry picked from commit 9935b0e8ea41804b32576987531be4d31ba705f1)

2 years agobsdinstall: bootconfig: Try to clean old efi boot entries
Emmanuel Vadot [Wed, 8 Dec 2021 09:37:54 +0000 (10:37 +0100)]
bsdinstall: bootconfig: Try to clean old efi boot entries

If one install FreeBSD on the same machine multiple times in a row or
on different harddrive they have a lot of 'FreeBSD' efi boot entries added.
With this patch we now do :
- If there is no 'FreeBSD' entry we add one like before
- If there is one or more entries we ask the user if they want to delete
  them all and add a new one
  - If they say yes we do that
  - If they say no we prompt them an inputbox so they can enter a different
    entry name if they want, it defaults to 'FreeBSD'

Reviewed by: bapt, imp
MFC after: 2 weeks
Sponsored by: Beckhoff Automation GmbH & Co. KG
Differential Revision: https://reviews.freebsd.org/D33330

(cherry picked from commit 40c928e7b80a7e2ba3652f7c3dc1d30fe92e5b48)

2 years agonfscl: Handle CB_SEQUENCE not first op correctly
Rick Macklem [Thu, 16 Dec 2021 00:36:40 +0000 (16:36 -0800)]
nfscl: Handle CB_SEQUENCE not first op correctly

The check for "not first operation" in CB_SEQUENCE
was done after the slot, etc. was updated. This patch
moves the check to the beginning of CB_SEQUENCE
processing.

While here, also fix the check for "no CB_SEQUENCE operation first"
by moving the check to the beginning of callback operation parsing,
since the check was in a couple of the other operations, but
not all of them.

PR: 260412

(cherry picked from commit e0861304a7b6b9c410db69be6148a5510c6b2d23)

2 years agorpc: Delete AUTH_NEEDS_TLS(_MUTUAL_HOST) auth_stat values
Rick Macklem [Thu, 23 Dec 2021 22:31:53 +0000 (14:31 -0800)]
rpc: Delete AUTH_NEEDS_TLS(_MUTUAL_HOST) auth_stat values

I thought that these new auth_stat values had been agreed
upon by the IETF NFSv4 working group, but that no longer
is the case.  As such, delete them and use AUTH_TOOWEAK
instead.  Leave the code that uses these new auth_stat
values in the sources #ifdef notnow, in case they are
defined in the future.

(cherry picked from commit 744c2dc7dde4ee1e1efc9630439682ea0dc338db)

2 years agogetfh: clarify that it is a privileged operation
Ed Maste [Thu, 23 Dec 2021 15:24:27 +0000 (10:24 -0500)]
getfh: clarify that it is a privileged operation

Reviewed by: kib
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D33629

(cherry picked from commit 5bc2e6e22774f4663c971a4b5b7eaf4cb9a2485e)

2 years agoMFC: Improve readahead in loader
Colin Percival [Sun, 19 Sep 2021 22:24:00 +0000 (15:24 -0700)]
MFC: Improve readahead in loader

style: Fix leading whitespace in bcache.c
loader: Refactor readahead adjustment in bcache
loader bcache: Track unconsumed readahead
loader bcache: Allow readahead up to 256 kB I/Os

Sponsored by: https://www.patreon.com/cperciva

(cherry picked from commit 5a01dea7e8c9640605e5731a9fc7f600c07ace61)
(cherry picked from commit b841148bbbdc967c871e8742a6f0b7b17b2d1d91)
(cherry picked from commit 04b9b7c507c52daf7b2999329a50825db098151f)
(cherry picked from commit 248682a589159619aa5f2019e415a423e849e327)

2 years agoOnly trigger read-ahead if two adjacent blocks have been requested.
Maxim Sobolev [Fri, 20 Aug 2021 19:33:51 +0000 (12:33 -0700)]
Only trigger read-ahead if two adjacent blocks have been requested.

The change makes block caching algorithm to work better for remote
media on low-BW/high-delay links.

This cuts boot time over IP KVMs noticeably, since the initialization
stage reads bunch of small 4th (and now lua) files that are not in
the same cache stripe (usually), thus wasting lot of bandwidth and
increasing latency even further.

The original regression came in 2017 with revision 87ed2b7f5. We've
seen increase of time it takes for the loader to get to the kernel
loading from under a minute to 10-15 minutes in many cases.

Reviewed by: tsoome
MFC after: 1 month
Differential Revision: https://reviews.freebsd.org/D31623

(cherry picked from commit 0d13f5343fafbf3067ffc33a507ffca0375c4417)

2 years agoEFI loader: Don't free bcache for DEVT_DISK devs
Colin Percival [Thu, 30 Sep 2021 21:48:14 +0000 (14:48 -0700)]
EFI loader: Don't free bcache for DEVT_DISK devs

Booting on an EC2 c5.xlarge instance, this reduces the number of I/Os
performed from 609 to 432, reduces the total number of blocks read
from 61963 to 60797, and reduces the time spent in the loader by 39 ms.

Note that b4cb3fe0e39a allowed the bcache to be retained for most of
the boot process, but relies on mounting filesystems; this commit
allows the bcache to be retained at the start of the boot process,
before the root filesystem has been located.

Sponsored by: https://www.patreon.com/cperciva
Differential Revision: https://reviews.freebsd.org/D32239

(cherry picked from commit ce73f768b76486b1562f207a6fc1cef87065418a)

2 years agoMFC: Add TSLOG to loader sprintf
Colin Percival [Sat, 25 Sep 2021 03:19:38 +0000 (20:19 -0700)]
MFC: Add TSLOG to loader sprintf

loader tslog: Don't use sprintf
loader printf: Profile with TSLOG

Sponsored by: https://www.patreon.com/cperciva

(cherry picked from commit 242923eb848a94d657344c2ff45c4f15433cdf3c)
(cherry picked from commit 0a35c4b3cab563e3ab1bf5b7b49bf26e0bb7cb04)

2 years agoAdd _sleep to TSLOG
Colin Percival [Sun, 5 Sep 2021 19:50:15 +0000 (12:50 -0700)]
Add _sleep to TSLOG

Most of the nvme initialization time in my tests is being spent here
(via pause_sbt).

Sponsored by: https://www.patreon.com/cperciva

(cherry picked from commit bd11e253a9a459c9a7b69ebb1c68f0162eb6119f)

2 years agoloader: Set twiddle globaldiv to 16 by default
Colin Percival [Tue, 28 Sep 2021 18:39:59 +0000 (11:39 -0700)]
loader: Set twiddle globaldiv to 16 by default

Booting FreeBSD on an EC2 c5.xlarge instance, the loader "twiddles"
810 times over the course of 510 ms, a rate of 1.59 kHz. Even accepting
that many systems are slower than this particular VM and will take
longer to boot (especially if using spinning-rust disks), this seems
like an unhelpfully large amount of twiddling when compared to the
~60 Hz frame rate of many displays; printing the twiddles also consumes
roughly 10% of the boot time on the aforementioned VM.

Setting the default globaldiv to 16 dramatically reduces the time spent
printing twiddles to the console while still twiddling at roughly 100
Hz; this should be ample even for systems which take longer to boot and
consequently twiddle slower.

Note that this can adjusted via the twiddle_divisor variable in
loader.conf, but that file is not processed until nearly halfway
through the loader's runtime.

Sponsored by: https://www.patreon.com/cperciva
Differential Revision: https://reviews.freebsd.org/D32163

(cherry picked from commit 7457840230c5a470ee5df8abed6ab59c4d008a45)

2 years agoMFC: arm64 fixes for TSLOG
Colin Percival [Thu, 24 Jun 2021 05:10:26 +0000 (22:10 -0700)]
MFC: arm64 fixes for TSLOG

arm64: Disable early printf if TSLOG
arm64: Instrument initarm with TSLOG
libsa: Add tslog support for arm64

Sponsored by: https://www.patreon.com/cperciva

(cherry picked from commit 0acc529dc35f88836dbcbe75940954c75595b058)
(cherry picked from commit ccadcb8f3343562f22a426e845dba640319d4355)
(cherry picked from commit e6caac717b4fc2b87cf93f67109884e768253e77)

2 years agoMFC loader+userland TSLOG support
Colin Percival [Sun, 30 May 2021 20:17:11 +0000 (20:17 +0000)]
MFC loader+userland TSLOG support

stand/common: Add file_addbuf()
libsa: Add support for timestamp logging (tslog)
stand/common: Add support for timestamp logging (tslog)
i386/loader: Call tslog_init
efi/loader: Call tslog_init (+ bugfix)
stand/common command_boot: Pass tslog to kernel
kern_tslog: Include tslog data from loader
loader: Use tslog to instrument some functions
Add userland boot profiling to TSLOG (+ bugfix)

Sponsored by: https://www.patreon.com/cperciva

(cherry picked from commit 60a978bec9123fcb9c74bd925e06dd3f4faddac6)
(cherry picked from commit e193d3ba337757a27148a38494d3df106b826d1c)
(cherry picked from commit c8dfc327db2373c721a35efe857cf07262fd7dd0)
(cherry picked from commit c4b65e954f0f4754941f5b37436231f611b76d67)
(cherry picked from commit f49381ccb6bc8a5733f1aa505e716eddae299986)
(cherry picked from commit 537a44bf281559d304850b5e28b6f8b8e44fd593)
(cherry picked from commit fe51b5a76de38d20cddc05a4c6cb1103d1a0547e)
(cherry picked from commit 313724bab940c1844fda3d797cf88cd46780e62a)
(cherry picked from commit 46dd801acb2318c8464b185893bb111f09b71138)
(cherry picked from commit 52e125c2bd302982c179ecc920cc9a6e166033d6)
(cherry picked from commit 19e4f2f289fb8d2b14576a65ca9e6f931dbb6a02)

2 years agoEliminate key press requirement "show vmopag" command output.
Stephen J. Kiernan [Fri, 17 Dec 2021 21:39:51 +0000 (16:39 -0500)]
Eliminate key press requirement "show vmopag" command output.

Summary:
One was required to press a key to continue after every 18 lines of
output. This requirement had been in the "show vmopag" command since it
was introduced, which was many years before paging was added to DDB.
With paging, this explict key check is no longer necessary.

Obtained from: Juniper Networks, Inc.
MFC after: 1 week

Test Plan:
Run "show vmopag" from db> prompt and see that it does not need additional
keypresses other than the ones needed for the pager.

Subscribers: imp, #contributor_reviews_base

Differential Revision: https://reviews.freebsd.org/D33550

(cherry picked from commit 18048b6e3cb647f2a18e1e51df1cf86a90fc6802)

2 years agovm_reserv: fix zero-boundary error
Doug Moore [Sun, 26 Dec 2021 17:40:27 +0000 (11:40 -0600)]
vm_reserv: fix zero-boundary error

Handle specially the boundary==0 case of vm_reserv_reclaim_config,
by turning off boundary adjustment in that case.

Reviewed by: alc
Tested by: pho, madpilot

(cherry picked from commit 49fd2d51f07fb29af3fd239f83f249c00cd84123)

2 years agoUSB dwc3 controller: add quirk snps,dis_rxdet_inp3_quirk
Bjoern A. Zeeb [Wed, 10 Nov 2021 00:22:20 +0000 (00:22 +0000)]
USB dwc3 controller: add quirk snps,dis_rxdet_inp3_quirk

Add support for the "snps,dis_rxdet_inp3_quirk" quirk needed
at least on SolidRun's HoneyComb.

Reviewed by: manu, mw
Differential Revision: https://reviews.freebsd.org/D32921

(cherry picked from commit 3987e506112a7e8af6f09966792fb8656d630496)

2 years agoUSB: add CYUSB330x to usbdevs
Bjoern A. Zeeb [Fri, 15 Oct 2021 10:46:58 +0000 (10:46 +0000)]
USB: add CYUSB330x to usbdevs

Add the Cypress dual USB3/2 HUB CYUSB330x as found in SolidRun's
HoneyComb to usbdevs.

(cherry picked from commit 1910048eb931bb749c42534a8f252d772c0719de)

2 years agofw_stub: fix -Wunused-but-set-variable for firmware files
Bjoern A. Zeeb [Tue, 30 Nov 2021 14:23:18 +0000 (14:23 +0000)]
fw_stub: fix -Wunused-but-set-variable for firmware files

In case we are only embedding a single firmware image the variable
"parent" gets set but never used.  Add checks for the number of files
for it and only print it out if we are exceeding the single file count.
This fixes -Wunused-but-set-variable warnings for the majority of
firmware files in the tree.

Sponsored by: The FreeBSD Foundation

(cherry picked from commit b394e16ef0b5ad0da5e029bcdd3a01e361724d8d)

2 years agorc: network.subr improve network6_getladdr()
Bjoern A. Zeeb [Mon, 13 Dec 2021 22:10:25 +0000 (22:10 +0000)]
rc: network.subr improve network6_getladdr()

In network6_getladdr() we are iterating over inet6 lines and are not
interested in any others.  So tell ifconfig to limit output to "inet6"
as much as possible.
This is probably a micro-optimisation but was noticed while looking
at other IPv6-related boot-time improvements.

(cherry picked from commit e448ff6f0e8035c3dd5b7bd0872f3f0d91c4e0d0)

2 years agox86: Do not attempt to calibrate the LAPIC timer if no APIC is present
Mark Johnston [Tue, 28 Dec 2021 22:44:57 +0000 (17:44 -0500)]
x86: Do not attempt to calibrate the LAPIC timer if no APIC is present

Reported and tested by: Michael Butler <imb@protected-networks.net>
Reviewed by: jhb, kib
Fixes: 62d09b46ad75 ("x86: Defer LAPIC calibration until after timecounters are available")
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 0ecda8d5ae896b229f13bfe73ffa3a7fc81cc550)

2 years agox86: Perform late TSC calibration before LAPIC timer calibration
Mark Johnston [Mon, 6 Dec 2021 15:42:19 +0000 (10:42 -0500)]
x86: Perform late TSC calibration before LAPIC timer calibration

This ensures that LAPIC calibration is done using the correct tsc_freq
value, i.e., the one associated with the TSC timecounter.  It does mean
though that TSC calibration cannot use sbinuptime() to read the
reference timecounter, as timehands are not yet set up.

Reviewed by: kib, jhb
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 553af8f1ec71d397b5b4fd5876622b9269936e63)

2 years agox86: Defer LAPIC calibration until after timecounters are available
Mark Johnston [Mon, 6 Dec 2021 15:42:10 +0000 (10:42 -0500)]
x86: Defer LAPIC calibration until after timecounters are available

This ensures that we have a good reference timecounter for performing
calibration.

Change lapic_setup to avoid configuring the timer when booting, and move
calibration and initial configuration to a new lapic routine,
lapic_calibrate_timer.  This calibration will be initiated from
cpu_initclocks(), before an eventtimer is selected.

Reviewed by: kib, jhb
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 62d09b46ad7508ae74d462e49234f0a80f91ff69)

2 years agox86: Implement deferred TSC calibration
Mark Johnston [Mon, 15 Nov 2021 20:31:21 +0000 (15:31 -0500)]
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
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 22875f88799e1684febf79b5049541e0f825aaa1)

2 years agoAdd assembly optimized code for OpenSSL on powerpc, powerpc64 and powerpc64le
Piotr Kubaj [Mon, 22 Nov 2021 02:28:46 +0000 (03:28 +0100)]
Add assembly optimized code for OpenSSL on powerpc, powerpc64 and powerpc64le

Summary:
1. https://github.com/openssl/openssl/commit/34ab13b7d8e3e723adb60be8142e38b7c9cd382a
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, alfredo (MFC to stable/13)
MFC after: 1 month
Differential Revision: https://reviews.freebsd.org/D33076

(cherry picked from commit 3a60869237b8b315fe66497cf5299ec08b688533)

2 years agoIPv4: fix redirect sending conditions
Bjoern A. Zeeb [Sun, 26 Dec 2021 15:33:48 +0000 (15:33 +0000)]
IPv4: fix redirect sending conditions

RFC792,1009,1122 state the original conditions for sending a redirect.
RFC1812 further refine these.
ip_forward() still sepcifies the checks originally implemented for these
(we do slightly more/different than suggested as makes sense).
The implementation added in 8ad114c082a159c0dde95aa35d2e3e108aa30a75
to ip_tryforward() however is flawed and may send a "multi-hop"
redirects (to a host not on the directly connected network).

Do proper checks in ip_tryforward() to stop us from sending redirects
in situations we may not.  Keep as much logic out of ip_tryforward()
and in ip_redir_alloc() and only do the mbuf copy once we are sure we
will send a redirect.

While here enhance and fix comments as to which conditions are handled
for sending redirects in various places.

Reported by: pi (on net@ 2021-12-04)
Sponsored by: Dr.-Ing. Nepustil & Co. GmbH
Reviewed by: cy, others (earlier versions)
Differential Revision: https://reviews.freebsd.org/D33274

(cherry picked from commit f389439f50fc4c27d15d3017b622270e25ba71c7)

2 years agoFix dtrace fbt return probes on arm64
Andrew Turner [Tue, 14 Dec 2021 15:49:07 +0000 (15:49 +0000)]
Fix dtrace fbt return probes on arm64

As with arm and riscv fix return fbt probes on arm64. arg0 should be
the offset within the function of the return instruction and arg1
should be the return value.

Reviewed by: kp, markj
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D33440

(cherry picked from commit e3ccf4f9dee9ae39774639407264199a07fa41ff)

2 years agoAdd accelerated arm64 sha512 to libmd
Andrew Turner [Fri, 19 Nov 2021 11:32:58 +0000 (11:32 +0000)]
Add accelerated arm64 sha512 to libmd

As with sha256 add support for accelerated sha512 support to libmd on
arm64. This depends on clang 13+ to build as this is the first release
with the needed intrinsics. Gcc should also support them, however from
a currently unknown release.

Reviewed by: cem
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D33373

(cherry picked from commit 71bf1c4cc5b21e7e5740514c1bc6ad751f312eea)

2 years agoFix a set but not used warning in the arm64 pmap
Andrew Turner [Tue, 7 Dec 2021 14:32:11 +0000 (14:32 +0000)]
Fix a set but not used warning in the arm64 pmap

In pmap_ts_referenced we read the virtual address from pv->pv_va,
but then continue to use the pv struct to get the same value later
in the function.

Use the virtual address value we initially read rather than loading
from the pv struct each time.

(cherry picked from commit 1c643b721bed48ba795b42cdc5e8b5818f30ed14)

2 years agoHandle table attributes in the arm64 kernel map
Andrew Turner [Tue, 7 Dec 2021 14:23:13 +0000 (14:23 +0000)]
Handle table attributes in the arm64 kernel map

When getting the arm64 kernel maps sysctl we should look at the table
attributes as well as the block/page attributes. These attributes are
different to the last level attributes so need to be translated.

The previous code assumed the table and block/page attributes are
identical, however this is not the case. Handle the difference by
extracting the code into new helper functions & calling them as needed
based on the entry type being checked.

Reviewed by: markj
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D33321

(cherry picked from commit 8d0b41b058795dcb0270ca0abcbf92289563c3ed)

2 years agoTeach vm.pmap.kernel_maps about both XN bits
Andrew Turner [Mon, 6 Dec 2021 13:08:39 +0000 (13:08 +0000)]
Teach vm.pmap.kernel_maps about both XN bits

The arm64 vm.pmap.kernel_maps sysctl would only check the kernel XN bit
when printing the kernel mapping. It can also be useful to check none
of the mappings allow userspace to execute from a given virtual address.
To check for this add the user XN bit when getting the kernel maps.

While here fix the ATTR_S1_AP_USER check to use ATTR_S1_AP to shift the
value to the correct offset.

Reviewed by: kib (earlier version), markj
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D33304

(cherry picked from commit 38dbca724335fec679e79b72d91a8e36b2624fe1)

2 years agoDon't fail changing props for unmapped DMAP memory
Andrew Turner [Tue, 14 Dec 2021 18:09:47 +0000 (18:09 +0000)]
Don't fail changing props for unmapped DMAP memory

When recursing in pmap_change_props_locked we may fail because there is
no pte. This shouldn't be considered a fail as it may happen in a few
cases, e.g. there are multiple normal memory ranges with device memory
between them.

Reported by: cperciva
Tested by: cperciva
Reviewed by: alc, kib
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D33459

(cherry picked from commit 69cfbd669e34aaaa49f4caed49bd7df93d4115b2)

2 years agoOnly change DMAP props on DMAP covered memory
Andrew Turner [Tue, 14 Dec 2021 10:05:15 +0000 (10:05 +0000)]
Only change DMAP props on DMAP covered memory

When changing memory properties in the arm64 pmap we need to keep both
the kernel address and DMAP mappings in sync.

To keep the kernel and DMAP memory in sync we recurse when updating the
former to also update the latter. There was insuffucuent checking around
this recursion. It would check if the virtual address is not within the
DMAP region, but not if the physical address is covered.

Add the missing check as without it the recursion may return an error.

Sponsored by: The FreeBSD Foundation

(cherry picked from commit 6238905c5b253c5b8c6a4b66796819c3a0bed637)

2 years agosys/queue.h: move trashing from SLIST_REMOVE to REMOVE_AFTER, REMOVE_HEAD
Andriy Gapon [Wed, 15 Dec 2021 11:27:49 +0000 (13:27 +0200)]
sys/queue.h: move trashing from SLIST_REMOVE to REMOVE_AFTER, REMOVE_HEAD

SLIST_REMOVE calls either REMOVE_AFTER or REMOVE_HEAD to do the job.
But those two macros can be used independently as well.

(cherry picked from commit 5dab06a003189ebb017810bdbf3b3c2f074afd3e)

2 years agovm_fault: Fix vm_fault_populate()'s handling of VM_FAULT_WIRE
Mark Johnston [Tue, 14 Dec 2021 20:10:46 +0000 (15:10 -0500)]
vm_fault: Fix vm_fault_populate()'s handling of VM_FAULT_WIRE

vm_map_wire() works by calling vm_fault(VM_FAULT_WIRE) on each page in
the rage.  (For largepage mappings, it calls vm_fault() once per large
page.)

A pager's populate method may return more than one page to be mapped.
If VM_FAULT_WIRE is also specified, we'd wire each page in the run, not
just the fault page.  Consider an object with two pages mapped in a
vm_map_entry, and suppose vm_map_wire() is called on the entry.  Then,
the first vm_fault() would allocate and wire both pages, and the second
would encounter a valid page upon lookup and wire it again in the
regular fault handler.  So the second page is wired twice and will be
leaked when the object is destroyed.

Fix the problem by modify vm_fault_populate() to wire only the fault
page.  Also modify the error handler for pmap_enter(psind=1) to not test
fs->wired, since it must be false.

PR: 260347
Reviewed by: alc, kib
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 88642d978a999aaa3752e86d2f54b1a6aba7fc85)

2 years agoClean up a couple of MD warts in vm_fault_populate():
Jason A. Harmening [Sat, 27 Mar 2021 03:10:46 +0000 (20:10 -0700)]
Clean up a couple of MD warts in vm_fault_populate():

--Eliminate a big ifdef that encompassed all currently-supported
architectures except mips and powerpc32.  This applied to the case
in which we've allocated a superpage but the pager-populated range
is insufficient for a superpage mapping.  For platforms that don't
support superpages the check should be inexpensive as we shouldn't
get a superpage in the first place.  Make the normal-page fallback
logic identical for all platforms and provide a simple implementation
of pmap_ps_enabled() for MIPS and Book-E/AIM32 powerpc.

--Apply the logic for handling pmap_enter() failure if a superpage
mapping can't be supported due to additional protection policy.
Use KERN_PROTECTION_FAILURE instead of KERN_FAILURE for this case,
and note Intel PKU on amd64 as the first example of such protection
policy.

Reviewed by: kib, markj, bdragon

(cherry picked from commit 8dc8feb53da0c1a2301cb21c87b17a09d12e8fa7)

2 years agox86: Deduplicate clock.h
Mark Johnston [Mon, 6 Dec 2021 15:39:08 +0000 (10:39 -0500)]
x86: Deduplicate clock.h

The headers were mostly identical on amd64 and i386.

No functional change intended.

Reviewed by: cperciva, mav, imp, kib, jhb
Sponsored by: The FreeBSD Foundation

(cherry picked from commit f06f1d1fdb969fa7a0a6eefa030d8536f365eb6e)

2 years agoaesni: Fix an out-of-bounds read in AES_GCM_decrypt()
Mark Johnston [Thu, 16 Dec 2021 14:08:16 +0000 (09:08 -0500)]
aesni: Fix an out-of-bounds read in AES_GCM_decrypt()

This is the same as 4285655adb74 ("aesni: Avoid a potential
out-of-bounds load in AES_GCM_encrypt()") except for the decryption
path.

Reported by: Jenkins (KASAN job)
Reviewed by: cem
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 4a61d8ef42cb44c337dfdc17424cc2e2f1d67fd5)

2 years agoamdsbwd: always enable watchdog register decoding
Andriy Gapon [Wed, 27 May 2020 10:15:54 +0000 (13:15 +0300)]
amdsbwd: always enable watchdog register decoding

This seems to be required even if the watchdog is accessed via the common
MMIO space.

Tested on:
- Ryzen 3 3200U APU;
- Ryzen 7 5800X CPU with X570 chipset.

(cherry picked from commit cca0d3bbd8c9f8b50c6940c33704a6c8c464b68f)

2 years agovmxnet3: skip zero-length descriptor in the middle of a packet
Andriy Gapon [Mon, 6 Dec 2021 07:59:28 +0000 (09:59 +0200)]
vmxnet3: skip zero-length descriptor in the middle of a packet

Passing up such descriptors to iflib is obviously wasteful.
But the main conern is that we may overrun iri_frags array because of
them.  That's been observed in practice.

Also, assert that the number of fragments / descriptors / segments is
less than IFLIB_MAX_RX_SEGS.

Sponsored by: Panzura LLC

(cherry picked from commit 9c612a5d0af17021abc6e1bb2a8baa5a4c97d05f)

2 years agoApply clang fix for crash or assertion failure compiling part of llvm
Dimitry Andric [Fri, 24 Dec 2021 11:46:00 +0000 (12:46 +0100)]
Apply clang fix for crash or assertion failure compiling part of llvm

Merge commit 77e8f4eeeeed from llvm git (by David Green):

  [ARM] Define ComplexPatternFuncMutatesDAG

  Some of the Arm complex pattern functions call canExtractShiftFromMul,
  which can modify the DAG in-place. For this to be valid and handled
  successfully we need to define ComplexPatternFuncMutatesDAG.

  Differential Revision: https://reviews.llvm.org/D107476

When building parts of llvm targeting armv6 on stable/12, the following
assertion can appear (or if assertions are disabled, clang is likely to
crash):

Assertion failed: (NodeToMatch->getOpcode() != ISD::DELETED_NODE && "NodeToMatch was removed partway through selection"), function SelectCodeCommon, file /usr/src/contrib/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp, line 3573.
PLEASE submit a bug report to https://bugs.freebsd.org/submit/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: /usr/obj/usr/src/freebsd12-amd64/tmp/usr/bin/c++ -cc1 -triple armv6kz-unknown-freebsd12.3-gnueabihf -S --mrelax-relocations -disable-free -disable-llvm-verifier -discard-value-names -mrelocation-model static -mconstructor-aliases -target-cpu arm1176jzf-s -target-feature +vfp2 -target-feature +vfp2sp -target-feature -vfp3 -target-feature -vfp3d16 -target-feature -vfp3d16sp -target-feature -vfp3sp -target-feature -fp16 -target-feature -vfp4 -target-feature -vfp4d16 -target-feature -vfp4d16sp -target-feature -vfp4sp -target-feature -fp-armv8 -target-feature -fp-armv8d16 -target-feature -fp-armv8d16sp -target-feature -fp-armv8sp -target-feature -fullfp16 -target-feature +fp64 -target-feature -d32 -target-feature -neon -target-feature -sha2 -target-feature -aes -target-feature -fp16fml -target-feature +strict-align -target-abi aapcs-linux -mfloat-abi hard -fallow-half-arguments-and-returns -ffunction-sections -fdata-sections -O1 -std=c++14 -fdeprecated-macro -fno-rtti -fno-signed-char -faddrsig -fexperimental-new-pass-manager PPCISelLowering-009095.ii
1. <eof> parser at end of file
2. Code generation
3. Running pass 'Function Pass Manager' on module 'PPCISelLowering-009095.cpp'.
4. Running pass 'ARM Instruction Selection' on function '@_ZN4llvm17PPCTargetLoweringC2ERKNS_16PPCTargetMachineERKNS_12PPCSubtargetE'

This crash or assertion is fixed by the upstream commit.

MFC after: 3 days

(cherry picked from commit ada8b24d48d93f0b13209b555b64f3d355ef61d9)

2 years agotests/libalias: Make inline functions static inline
Dimitry Andric [Mon, 20 Dec 2021 09:52:02 +0000 (10:52 +0100)]
tests/libalias: Make inline functions static inline

In C, plain inline functions should never be used: they should be
declared either static inline or extern inline. In this case, they are
clearly meant to be static inline.

MFC after: 3 days

(cherry picked from commit 46aec7fae47ed46368f95338741b4daffa5cbc94)

2 years agoipfilter userland: Revert the ipmon part of a6fb9bbea731
Cy Schubert [Mon, 27 Dec 2021 09:10:52 +0000 (01:10 -0800)]
ipfilter userland: Revert the ipmon part of a6fb9bbea731

a6fb9bbea731 caused incorrect formatting of ipmon log output.

Fixes: a6fb9bbea7318e993dfe0f8a7f00821f79850b26

(cherry picked from commit d740faa30a4a2b300da0b2f2af4680a2cb260828)

2 years agosys/dev/arcmsr: Update Areca RAID driver to fix some issues on ARC-1886.
黃清隆 [Mon, 13 Dec 2021 16:09:15 +0000 (08:09 -0800)]
sys/dev/arcmsr: Update Areca RAID driver to fix some issues on ARC-1886.

1. Doorbell interrupt status may arrive lately when doorbell interrupt on
   ARC-1886.
2. System boot up hung when ARC-1886 with no volume created or no device
   attached.

Many thanks to Areca for continuing to support FreeBSD.

(cherry picked from commit 6964b77e598597789764ab6949a8031c14075a25)

2 years agonfscl: add a filesize limit check to nfs_allocate()
Rick Macklem [Mon, 13 Dec 2021 23:32:19 +0000 (15:32 -0800)]
nfscl: add a filesize limit check to nfs_allocate()

As reported in PR#260343, nfs_allocate() did not check
the filesize rlimit. This patch adds that check.

PR: 260343

(cherry picked from commit fe04c91184e9e82609a657c4e6e70e213ed3a859)

2 years agonfsd: Limit parsing of layout errors to maxcnt bytes
Rick Macklem [Mon, 13 Dec 2021 23:21:31 +0000 (15:21 -0800)]
nfsd: Limit parsing of layout errors to maxcnt bytes

This patch decrements maxcnt by the appropriate
number of bytes during parsing and checks to see
if there is data remaining.  If not, it just returns
from nfsrv_flexlayouterr() without further processing.
This prevents the tl pointer from running off the end
of the error data pointed at by layp, if there are
flaws in the data.

PR: 260293

(cherry picked from commit c302f889e21f73746a3b0917df5246e639df1481)

2 years agoqat: Address -Wunused-but-set-variable warnings
Mark Johnston [Fri, 10 Dec 2021 15:52:30 +0000 (10:52 -0500)]
qat: Address -Wunused-but-set-variable warnings

(cherry picked from commit 8fcf230c1377c4598a7aa6560ec43ff46662fbaa)

2 years agodtrace: Disable getf() as it is broken on FreeBSD
Domagoj Stolfa [Fri, 17 Dec 2021 16:01:54 +0000 (11:01 -0500)]
dtrace: Disable getf() as it is broken on FreeBSD

getf() on FreeBSD calls _sx_slock(), _sx_sunlock() and fget_locked().
Furthermore, it does not set the per-core fault flag, meaning it
usually ends up in a double fault panic once getf() does get called,
especially from fbt.

Reviewing the DTrace Toolkit + a number of other scripts scattered
around FreeBSD, I have not been able to find one use of getf(). Given
how broken the implementation currently is, we disable it until it
can be implemented properly.

Also comment out a test in aggs/tst.subr.d for getf().

Reviewed by: markj

(cherry picked from commit 30ec3138edc9d491446409910f52ccb1b158253e)

2 years agobhyve: Only snapshot initialized VirtIO queues
Vitaliy Gusev [Thu, 16 Dec 2021 16:06:08 +0000 (11:06 -0500)]
bhyve: Only snapshot initialized VirtIO queues

If the virtio device is not fully initialized, then suspend fails with:

  vi_pci_snapshot_queues: invalid address: vq->vq_desc
  Failed to snapshot virtio-rnd; ret=14

Reviewed by: jhb

(cherry picked from commit d079fc197aca951c7918276922038852167dd39f)

2 years agotwsi: use twsi_error() to handle wrong bus status when starting
Andriy Gapon [Sun, 19 Dec 2021 09:28:02 +0000 (11:28 +0200)]
twsi: use twsi_error() to handle wrong bus status when starting

(cherry picked from commit 46e0c03795443675f95db6da2195825d24a9fb7c)

2 years agonfscl: Fix must_commit handling for mirrored pNFS mounts
Rick Macklem [Sun, 12 Dec 2021 23:40:30 +0000 (15:40 -0800)]
nfscl: Fix must_commit handling for mirrored pNFS mounts

For pNFS mounts to mirrored Flexible File layout pNFS servers,
the "must_commit" component in the nfsclwritedsdorpc
structure must be checked and the "must_commit" argument passed
into nfscl_doiods() must be updated.  Technically, only writes to
the DS with a writeverf change must be redone, but since this
occurrence will be rare, the must_commit argument to nfscl_doiosd()
is set to 1, so all writes to all DSs will be redone.

This bug would affect few, since use of mirrored pNFS servers
is rare and "writeverf" rarely changes. Normally "writeverf"
only changes when a NFS server reboots.

(cherry picked from commit 24947b701d07634434b3208b0a0c970235f9d16e)

2 years agohwpmc: Add IDs for Intel Comet/Ice/Tiger/Rocketlake CPUs.
Alexander Motin [Fri, 26 Nov 2021 00:17:58 +0000 (19:17 -0500)]
hwpmc: Add IDs for Intel Comet/Ice/Tiger/Rocketlake CPUs.

MFC after: 1 month

(cherry picked from commit 913c07a04998b8cd11dc428f5d00fae7dd392244)

2 years agolibpmc: Update some x86 event definitions.
Alexander Motin [Thu, 25 Nov 2021 16:19:26 +0000 (11:19 -0500)]
libpmc: Update some x86 event definitions.

MFC after: 1 month

(cherry picked from commit 52d973f52c07b94909a6487be373c269988dc151)

2 years agogfx_fb: Fix a typo in a source code comment
Gordon Bergling [Wed, 22 Dec 2021 09:00:42 +0000 (10:00 +0100)]
gfx_fb: Fix a typo in a source code comment

- s/decriptor/descriptor/

(cherry picked from commit b5e0a70193a7a02ba611317cd1688e29002685a4)

2 years agosound(4): Fix a typo in a source code comment
Gordon Bergling [Wed, 22 Dec 2021 09:18:35 +0000 (10:18 +0100)]
sound(4): Fix a typo in a source code comment

- s/aggresively/aggressively/

(cherry picked from commit d34632a235dc4cb1b4f89e5dd570a6a53f0117ce)

2 years agommc_sim: fix setting of the mutex name
Andriy Gapon [Wed, 15 Dec 2021 11:37:59 +0000 (13:37 +0200)]
mmc_sim: fix setting of the mutex name

To quote the manual:
 The pointer passed in as name and type is saved rather than the data
 it points to.  The data pointed to must remain stable until the mutex
 is destroyed.

It seems that the type is actually copied, but the name is stored as
a pointer indeed.
mmc_cam_sim_alloc used a name stored on stack.
So, a corrupt mutex name would be reported.
For example:
  lock order reversal: (sleepable after non-sleepable)
  1st 0xd7285b20 <8A><C0><C0>P@<C1><D0>P@<C1>^D^A (aw_mmc_sim, sleep mutex) @ sys/cam/cam_xpt.c:2804

This change moves the name to struct mmc_sim.
Also, that name is used as the sim name as well.
Unused mtx_name variable is removed too.
The name buffer is reduced to 16 characters.

(cherry picked from commit 18679ab1c06575517df9df2509564dbf038d4720)
(cherry picked from commit 8eca341d9bb678f08065edd8f24c2ab32dcf8e56)

2 years agonfscl: Fix must_commit/writeverf handling for Direct I/O
Rick Macklem [Sat, 11 Dec 2021 23:00:30 +0000 (15:00 -0800)]
nfscl: Fix must_commit/writeverf handling for Direct I/O

Without this patch, the KASSERT(must_commit == 0,..) can be
triggered by the writeverf in the Direct I/O write reply changing.
This is not a situation that should cause a panic(). Correct
handling is to ignore the change in "writeverf" for Direct
I/O, since it is done with NFSWRITE_FILESYNC.

This patch modifies the semantics of the "must_commit"
argument slightly, allowing an initial value of 2 to indicate
that a change in "writeverf" should be ignored.
It also fixes the KASSERT()s.

This bug would affect few, since Direct I/O is not enabled
by default and "writeverf" rarely changes. Normally "writeverf"
only changes when a NFS server reboots, however I found the
bug when testing against a Linux 5.15.1 kernel nfsd, which
replied to a NFSWRITE_FILESYNC write with a "writeverf" of all
0x0 bytes.

(cherry picked from commit ead50c94cb604594987e6512289268891a427725)

2 years agoocs_fc: Populate subvendor and subdevice ids.
Ram Kishore Vegesna [Mon, 20 Dec 2021 12:25:13 +0000 (17:55 +0530)]
ocs_fc: Populate subvendor and subdevice ids.
Enable serialnumber reporting.

Reviewed by: mav
MFC after: 3 days

(cherry picked from commit cba757ef2a7ec2bb985fbcd67e8d616328b7209a)

ocs_fs(4): Fix some common typos in source code comments

- s/transfered/transferred/
- s/associted/associated/

MFC after: 3 days

(cherry picked from commit 16b71d98d96a3a9a2ac666440aa80f12d478959d)

2 years agolibefivar(3): efi_set_variables_supported.3 should be efi_variables_supported.3
Li-Wen Hsu [Tue, 21 Dec 2021 12:42:39 +0000 (20:42 +0800)]
libefivar(3): efi_set_variables_supported.3 should be efi_variables_supported.3

MFC after: 3 days

(cherry picked from commit 71779dddffe5e860118f42739ff8d51d181272ce)

2 years agosmist: Remove unneeded Giant from bus_dma_tag_create().
Alexander Motin [Fri, 10 Dec 2021 01:54:22 +0000 (20:54 -0500)]
smist: Remove unneeded Giant from bus_dma_tag_create().

bus_dmamap_load() call uses BUS_DMA_NOWAIT.

MFC after: 2 weeks

(cherry picked from commit a69f8104665c7356b08d81728d406c595973672c)