]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
2 years agolinux: remove locks around callout_drain in timerfd_close()
shu [Wed, 3 Feb 2021 19:10:58 +0000 (19:10 +0000)]
linux: remove locks around callout_drain in timerfd_close()

The lock around callout_drain() is unnecessary and may cause
deadlock when one closes a timer descriptor during timer execution.

Reviewed By: delphij
Submitted By: ankohuu_outlook.com (Shunchao Hu)
Differential Revision: https://reviews.freebsd.org/D28148

(cherry picked from commit 14c40d2c292deff44be5591add7fdad5f9b371aa)

2 years agolinux: Improve debugging by recognizing TIOCGPTPEER
Edward Tomasz Napierala [Thu, 29 Apr 2021 20:26:46 +0000 (21:26 +0100)]
linux: Improve debugging by recognizing TIOCGPTPEER

Sponsored By: EPSRC

(cherry picked from commit 1866c766d2c520faaedbfe98d2e34a95f54053a5)

2 years agolinux: Also translate the signal if the code is CLD_KILLED
Edward Tomasz Napierala [Fri, 29 Oct 2021 13:56:43 +0000 (14:56 +0100)]
linux: Also translate the signal if the code is CLD_KILLED

This fixes ./waitid.gen.test from the strace(1) test suite.

Reviewed By: kib
Sponsored By: EPSRC
Differential Revision: https://reviews.freebsd.org/D32617

(cherry picked from commit c8c93b151678b57d86cd50509c9cbb863bbe9e57)

2 years agolinux: Fix ENOTSOCK handling in sendfile(2)
Edward Tomasz Napierala [Sat, 23 Oct 2021 08:15:37 +0000 (09:15 +0100)]
linux: Fix ENOTSOCK handling in sendfile(2)

The Linux way for sendfile(2) to tell the application
to fallback to another way of copying data is by EINVAL,
not ENOTSOCK.  This fixes package installation scripts
for Mono packages from Focal.

Sponsored By: EPSRC
Differential Revision: https://reviews.freebsd.org/D32604

(cherry picked from commit 2c7f7982825442c851e8bb17555a086a232ef4d9)

2 years agolinux: recognize TCP_INFO and ratelimit the warning
Edward Tomasz Napierala [Sun, 17 Oct 2021 12:19:05 +0000 (13:19 +0100)]
linux: recognize TCP_INFO and ratelimit the warning

This ratelimits the "unsupported getsockopt level 6 optname 11"
warnings that happen all the time when watching Netflix.

Sponsored By: EPSRC
Differential Revision: https://reviews.freebsd.org/D32454

(cherry picked from commit 99f563ed76f49c541e587a2f81bc43c62c86c0e5)

2 years agolinux: Partially implement TCSBRK
Edward Tomasz Napierala [Sun, 17 Oct 2021 10:19:51 +0000 (11:19 +0100)]
linux: Partially implement TCSBRK

This fixes tcflush(3), unbreaking cheribuild.py under arm64 Focal.

Reviewed By: imp
Sponsored By: EPSRC
Differential Revision: https://reviews.freebsd.org/D32291

(cherry picked from commit 7e7859e7c2b900fd1b1af6e90ed31d51b9b5514d)

2 years agolinux: improve FUSE support
Edward Tomasz Napierala [Mon, 7 Jun 2021 09:43:23 +0000 (10:43 +0100)]
linux: improve FUSE support

This fixes a number of AppImages; tested with
scribus-1.5.6.1-linux-x86_64.AppImage.

Reported By: @probonopd
Reviewed By: asomers, emaste
Sponsored By: EPSRC
Differential Revision: https://reviews.freebsd.org/D30606

(cherry picked from commit 128a1db806daac088a79314cee060b8a204e8481)

2 years agolinux: deduplicate DUMMY() entries
Edward Tomasz Napierala [Sat, 29 May 2021 06:32:50 +0000 (06:32 +0000)]
linux: deduplicate DUMMY() entries

No functional changes.

Reviewed By: emaste
Sponsored By: EPSRC
Differential Revision: https://reviews.freebsd.org/D30524

(cherry picked from commit 83043a741d114d7fd4a018e9c70330036ae44f81)

2 years agolinux: make linux64.ko loadable again on aarch64
Edward Tomasz Napierala [Fri, 28 May 2021 13:53:31 +0000 (13:53 +0000)]
linux: make linux64.ko loadable again on aarch64

This should probably get deduplicated; this is a quick fix
just to unbreak things.

Fixes: 6d926e850d2
Sponsored By: EPSRC

(cherry picked from commit 023ee5392c77fbb803ea7552d7a25f7d231e56f8)

2 years agoRegen after 6d926e850d2.
Edward Tomasz Napierala [Fri, 28 May 2021 08:04:17 +0000 (09:04 +0100)]
Regen after 6d926e850d2.

Sponsored By: EPSRC

(cherry picked from commit c0f171736a703c8d01f955190cfe5142381752f5)

2 years agolinux: add new syscall numbers
Edward Tomasz Napierala [Fri, 28 May 2021 08:02:10 +0000 (09:02 +0100)]
linux: add new syscall numbers

Sponsored By: EPSRC
Differential Revision: https://reviews.freebsd.org/D30193

(cherry picked from commit 6d926e850d22c5c563571561c446c3c0dec16143)

2 years agolinux: support AT_EMPTY_PATH flag in fchownat(2)
Edward Tomasz Napierala [Fri, 16 Apr 2021 15:26:43 +0000 (16:26 +0100)]
linux: support AT_EMPTY_PATH flag in fchownat(2)

This fixes rsyslog package installation scripts in Bionic.

Reviewed By: kib
Sponsored By: EPSRC
Differential Revision: https://reviews.freebsd.org/D29108

(cherry picked from commit e47823b8312b7cb61c5c8cb8e1eb981994e3a0b4)

2 years agolinux: make fstatat(2) handle AT_EMPTY_PATH
Edward Tomasz Napierala [Fri, 16 Apr 2021 07:52:59 +0000 (08:52 +0100)]
linux: make fstatat(2) handle AT_EMPTY_PATH

Without it, Qt5 apps from Focal fail to start, being unable to load
their plugins.  It's also necessary for glibc 2.33, as found in recent
Arch snapshots.

PR: 254112
Reviewed By: kib
Sponsored by: The FreeBSD Foundation, EPSRC
Differential Revision: https://reviews.freebsd.org/D28192

(cherry picked from commit 4b45c2bb83a1d7aded0c424d65595cc576760dc7)

2 years agolinux: implement O_PATH
Edward Tomasz Napierala [Thu, 15 Apr 2021 14:24:51 +0000 (15:24 +0100)]
linux: implement O_PATH

Reviewed By: kib
Sponsored By: EPSRC
Differential Revision: https://reviews.freebsd.org/D29773

(cherry picked from commit 1663120ae452fe3783c74ce40522caf0e2327608)

2 years agolinux: extend the LINUX_O_ constants to make room for O_PATH
Edward Tomasz Napierala [Thu, 15 Apr 2021 13:38:58 +0000 (14:38 +0100)]
linux: extend the LINUX_O_ constants to make room for O_PATH

No functional changes.

Sponsored By: EPSRC

(cherry picked from commit 1b11173c00d84d4a25cc8aa3c6c69cc15696b0ec)

2 years agolinux: adjust ordering of Linux auxv and add dummy AT_HWCAP2
Edward Tomasz Napierala [Tue, 13 Apr 2021 11:38:37 +0000 (12:38 +0100)]
linux: adjust ordering of Linux auxv and add dummy AT_HWCAP2

This should be a no-op; the purpose of this is to reduce
a spurious difference between Linuxulator and Linux, to make
debugging core dumps slightly easier.

Note that AT_HWCAP2 we pass to Linux binaries is always 0,
instead of being equal to 'cpu_feature2'.  This matches what
I've observed under Ubuntu Focal VM.

Reviewed By: chuck, dchagin
Sponsored By: EPSRC
Differential Revision: https://reviews.freebsd.org/D29609

(cherry picked from commit ca6e1fa3ce87f56847633530cb94a6fb63405680)

2 years agommc_da: create disk(9) for pre-2.0 SD cards
Andriy Gapon [Thu, 27 Jan 2022 16:49:27 +0000 (18:49 +0200)]
mmc_da: create disk(9) for pre-2.0 SD cards

It does not look like there is anything in mmc_da code that actually
requires protocol 2.0 or later.  dev/mmc code also does not have such a
restriction.

Tested with a very old 2GB mini-SD card.  Prior to this change mmc_da
would claim the card but would not expose it to GEOM.

Without MMCCAM:
 mmc0: <MMC/SD bus> on sdhci_pci0
 mmc0: Probing bus
 mmc0: SD probe: OK (OCR: 0x00ff8000)
 mmc0: Current OCR: 0x00ff8000
 mmc0: CMD8 failed, RESULT: 1
 mmc0: Probing cards
 mmc0: New card detected (CID 1c53565344432020100002982e007600)
 mmc0: New card detected (CSD 005e00325f5a83d02db7ffbf96800000)
 mmc0: Card at relative address 0xb368 added:
 mmc0:  card: SD SDC   1.0 SN 0002982E MFG 06/2007 by 28 SV
 mmc0:  quirks: 0
 mmc0:  bus: 4bit, 50MHz (high speed timing)
 mmc0:  memory: 3998720 blocks, erase sector 256 blocks
 mmc0: setting transfer rate to 50.000MHz (high speed timing)
 GEOM: new disk mmcsd0
 mmcsd0: 2GB <SD SDC   1.0 SN 0002982E MFG 06/2007 by 28 SV> at mmc0 50.0MHz/4bit/65535-block
 mmc0: setting bus width to 4 bits high speed timing

With MMCCAM and this change:
 sdda0 at sdhci_slot0 bus 0 scbus2 target 0 lun 0
 sdda0: Relative addr: 0000b368
 Card features: <Memory>
 sdda0: Serial Number 0002982E
 sdda0: SD SDC   1.0 SN 0002982E MFG 06/2007 by 28 SV
 GEOM: new disk sdda0

(cherry picked from commit 6fd84a627fa066a98777c7ab1e65bdd885407516)

2 years agog_mirror: don't fail reads while losing next-to-last disk
Andriy Gapon [Thu, 27 Jan 2022 10:49:04 +0000 (12:49 +0200)]
g_mirror: don't fail reads while losing next-to-last disk

I observed a situation where some read requests failed when a 2-way geom
mirror lost one disk.  The problem appears to be in the logic that skips
retrying a failed request when a mirror has only one active disk.
Generally, that makes sense.  But during a transition from two disks to
one it is possible that the request failed on the failing disk before it
was inactivated and, so, the remaining active disk is the disk that
should be tried.

This change adds an additional check to ensure that it was the (only)
active disk that was already tried.

(cherry picked from commit 5d5f44623eb3d121d528060d131ee5d6bcd63489)

2 years agosesutil: fix a comment
Alan Somers [Mon, 30 Aug 2021 23:39:38 +0000 (17:39 -0600)]
sesutil: fix a comment

Sponsored by: Axcient

(cherry picked from commit 18acbeb392cb070be34e9c4032e383389f8996e1)

2 years agoses: minor cleanup
Alan Somers [Wed, 25 Aug 2021 21:08:19 +0000 (15:08 -0600)]
ses: minor cleanup

* Prefer variables of small scope rather than large scope
* Remove a magic number
* style(9) for return statements
* Remove the get_enc_status method, which never did anything
* Fix a variable type in the handle_string method
* Proofread some comments

Sponsored by: Spectra Logic, Axcient
Reviewed by: ken, mav
Differential Revision: https://reviews.freebsd.org/D31686

(cherry picked from commit 170a0a8ebbd386b024f7f4c017eb60ea2b9110f2)

2 years agoDocument when zfree(9) was added to FreeBSD.
David E. O'Brien [Thu, 17 Feb 2022 04:03:48 +0000 (20:03 -0800)]
Document when zfree(9) was added to FreeBSD.

(cherry picked from commit 74ca6a22f9c1ff9ea407de7053891fca5a680402)

2 years agoVarious fixes for ggatec and ggated
Alan Somers [Mon, 3 Jan 2022 00:51:44 +0000 (17:51 -0700)]
Various fixes for ggatec and ggated

Dynamically size buffers in ggatec. Instead of static size on the stack.
Add flush support.

Submitted by: Johannes Totz <jo@bruelltuete.com>
Reviewed by: asomers
Differential Revision: https://reviews.freebsd.org/D31722

(cherry picked from commit 6226477a462f5ffbeacafdc9461524c95a7eb154)

geom_gate: ensure readprov is null-terminated

With crafted input to the G_GATE_CMD_CREATE ioctl, geom_gate can be made
to print kernel memory to the system console, potentially revealing
sensitive data from whatever was previously in that memory page.

But but but: this is a case of the sys admin misconfiguring, and you'd
need root privileges to do this.

Submitted By: Johannes Totz <jo@bruelltuete.com>
Reviewed By: asomers
Differential Revision: https://reviews.freebsd.org/D31727

(cherry picked from commit f284bed200b04e48c4ae87a50f4a8a957b0a10ad)

2 years agolibkvm: fix kvm_walk_pages
Bora Özarslan [Thu, 25 Nov 2021 19:09:26 +0000 (14:09 -0500)]
libkvm: fix kvm_walk_pages

Correct bitmap operations in _kvm_bitmap_next.

Reviewed by: jhb
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D19183

(cherry picked from commit 08055452cbf24a3cea48cb4f665bab78d89b7a39)

2 years agocrunchgen: remove -dc from linker invocation
Fangrui Song [Wed, 9 Feb 2022 00:59:53 +0000 (19:59 -0500)]
crunchgen: remove -dc from linker invocation

In GNU ld and ld.lld, -dc is used with -r to allocate space to COMMON
symbols.  It is presumably to work around legacy code which cannot
handle COMMON symbols in relocatable output.  ld.lld may remove -dc or
make it a no-op for the 15.0.0 release.

As of 7420b323a014 crunch/crunchide does not require -dc, as the symbol
hiding technique no longer relied on making symbols local.

In addition -fno-common is now the default in Clang and GCC, so -dc
serves no purpose as the compiler does not generate COMMON symbols
anyway.

See https://maskray.me/blog/2022-02-06-all-about-common-symbols for more
detail on common symbols.

Reviewed by: emaste
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D34215

(cherry picked from commit ec81497cc7260b26c2af615c54aa80f515d6c539)

2 years agovt.4: clarify that a KMS driver switches to graphics mode
Ed Maste [Mon, 14 Feb 2022 19:03:52 +0000 (14:03 -0500)]
vt.4: clarify that a KMS driver switches to graphics mode

PR: 261909
MFC after: 3 days
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 004b0aa86967213d0773ec95b5efd28d8a3c9538)

2 years agobwi: Fix clang 14 warning about possible unaligned access
Dimitry Andric [Mon, 7 Feb 2022 20:59:46 +0000 (21:59 +0100)]
bwi: Fix clang 14 warning about possible unaligned access

On architectures with strict alignment requirements (e.g. arm), clang 14
warns about a packed struct which encloses a non-packed union:

In file included from sys/dev/bwi/bwimac.c:79:
sys/dev/bwi/if_bwivar.h:308:7: error: field iv_val within 'struct bwi_fw_iv' is less aligned than 'union (unnamed union at sys/dev/bwi/if_bwivar.h:305:2)' and is usually due to 'struct bwi_fw_iv' being packed, which can lead to unaligned accesses [-Werror,-Wunaligned-access]
} iv_val;
^

It appears to help if you also add __packed to the inner union (i.e.
iv_val). No change to the layout is intended.

MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D34196

(cherry picked from commit 09d0a0fbe859e3fc7bbff0cf48c389b5e55b9e00)

2 years agoFix the build after commit 5fa005e91560785dad5183db080209447afde3c2
Mark Johnston [Wed, 16 Feb 2022 18:32:18 +0000 (13:32 -0500)]
Fix the build after commit 5fa005e91560785dad5183db080209447afde3c2

Fixes: 5fa005e91560 ("exec: Reimplement stack address randomization")

2 years agosecurity.7: Minor fixes for ASLR sysctl descriptions
Mark Johnston [Mon, 17 Jan 2022 16:44:01 +0000 (11:44 -0500)]
security.7: Minor fixes for ASLR sysctl descriptions

Reviewed by: debdrup, danfe, emaste
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 2188152717376fed1e6016187427666bb06cf33a)

2 years agoUse vmspace->vm_stacktop in place of sv_usrstack in more places.
John Baldwin [Mon, 14 Feb 2022 18:57:30 +0000 (10:57 -0800)]
Use vmspace->vm_stacktop in place of sv_usrstack in more places.

Reviewed by: markj
Obtained from: CheriBSD

(cherry picked from commit becaf6433be4a7c86e8053d42f399176c24d76b6)

2 years agofork: Copy the vm_stacktop field into the new vmspace
Mark Johnston [Tue, 18 Jan 2022 15:42:21 +0000 (10:42 -0500)]
fork: Copy the vm_stacktop field into the new vmspace

Fixes: 1811c1e957ee ("exec: Reimplement stack address randomization")
Reported by: pho
Reported by: syzbot+0446312a51bc13ead834@syzkaller.appspotmail.com
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 46d35d415aa9664b0ddc98a76e453eec20af0016)

2 years agoexec: Reimplement stack address randomization
Mark Johnston [Mon, 17 Jan 2022 16:42:56 +0000 (11:42 -0500)]
exec: Reimplement stack address randomization

The approach taken by the stack gap implementation was to insert a
random gap between the top of the fixed stack mapping and the true top
of the main process stack.  This approach was chosen so as to avoid
randomizing the previously fixed address of certain process metadata
stored at the top of the stack, but had some shortcomings.  In
particular, mlockall(2) calls would wire the gap, bloating the process'
memory usage, and RLIMIT_STACK included the size of the gap so small
(< several MB) limits could not be used.

There is little value in storing each process' ps_strings at a fixed
location, as only very old programs hard-code this address; consumers
were converted decades ago to use a sysctl-based interface for this
purpose.  Thus, this change re-implements stack address randomization by
simply breaking the convention of storing ps_strings at a fixed
location, and randomizing the location of the entire stack mapping.
This implementation is simpler and avoids the problems mentioned above,
while being unlikely to break compatibility anywhere the default ASLR
settings are used.

The kern.elfN.aslr.stack_gap sysctl is renamed to kern.elfN.aslr.stack,
and is re-enabled by default.

PR: 260303
Reviewed by: kib
Discussed with: emaste, mw
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 1811c1e957ee1250b08b3246fc0db37ddf64b736)

2 years agoktls: Disallow transmitting empty frames outside of TLS 1.0/CBC mode
Mark Johnston [Tue, 8 Feb 2022 17:36:41 +0000 (12:36 -0500)]
ktls: Disallow transmitting empty frames outside of TLS 1.0/CBC mode

There was nothing preventing one from sending an empty fragment on an
arbitrary KTLS TX-enabled socket, but ktls_frame() asserts that this
could not happen.  Though the transmit path handles this case for TLS
1.0 with AES-CBC, we should be strict and allow empty fragments only in
modes where it is explicitly allowed.

Modify sosend_generic() to reject writes to a KTLS-enabled socket if the
number of data bytes is zero, so that userspace cannot trigger the
aforementioned assertion.

Add regression tests to exercise this case.

Reported by: syzkaller
Reviewed by: gallatin, jhb
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 5de79eeddb9de079d108d1312148bcbefce45c27)

2 years agofile: Make fget*() and getvnode*() consistent about initializing *fpp
Mark Johnston [Tue, 8 Feb 2022 17:34:20 +0000 (12:34 -0500)]
file: Make fget*() and getvnode*() consistent about initializing *fpp

Most fget*() functions initialize the output parameter to NULL.  Make
the externally visible interface behave consistently, and make
fget_unlocked_seq() private to kern_descrip.c.

This fixes at least one bug in a consumer, _filemon_wrapper_openat(),
which assumes that getvnode() sets the output file pointer to NULL upon
an error.

Reported by: syzbot+01c0459408f896a5933a@syzkaller.appspotmail.com
Reviewed by: kib
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 300cfb96fc2253c3aff8d501d5599fcf811daa34)

2 years agocam_get_device: resolve path links before parsing device name
Andriy Gapon [Sat, 27 Nov 2021 18:49:08 +0000 (20:49 +0200)]
cam_get_device: resolve path links before parsing device name

The CAM subsystem uses bus:taget:lun tuple to address peripherals.  But
for convenience many userland programs such as camcontrol accept devices
names such as da0.  There is a libcam function, cam_open_device, to
support that.  It first calls cam_get_device() to parse the device name
as a driver name and a unit (and handle some special device name
prefixes) and then uses cam_lookup_pass() to find a matching pass
device.

This change extends cam_get_device() to apply realpath(3) to the device
name before parsing it.  This will allow to use tools such as camcontrol
and smartctl with symbolic links that could be friendlier (more
distinguished) names for devices.

Relnotes: maybe

(cherry picked from commit 1abf1e8c6b13f50eed08fef6fb1ade280894f1e4)

2 years agoMerge bmake-20220208
Simon J. Gerraty [Wed, 9 Feb 2022 17:25:03 +0000 (09:25 -0800)]
Merge bmake-20220208

        * unit-tests/Makefile: disable opt-debug-x-trace on Linux if there
        is any chance we have dash as .SHELL

        * meta.c: use a variable to hold command line to be filtered
        to avoid any side effects from content of command line.

Merge commit '535c59a6a9214436f5d6643775d29808e4b3408d'

(cherry picked from commit a6f0e10b24b6011dd5f71c99848ddeef264d9ac9)

2 years agoUpdate to bmake-20220204
Simon J. Gerraty [Sat, 5 Feb 2022 20:29:10 +0000 (12:29 -0800)]
Update to bmake-20220204

(cherry picked from commit 6598559fdf0c6342b6c30229430c739c42dc9941)

2 years agoMerge bmake-20220204
Simon J. Gerraty [Sat, 5 Feb 2022 20:26:16 +0000 (12:26 -0800)]
Merge bmake-20220204

(cherry picked from commit 9f45a3c8c82ffead7044ae836d9257113c630d3b)

2 years agoAfter-import bmake-20211212
Simon J. Gerraty [Sat, 18 Dec 2021 18:14:39 +0000 (10:14 -0800)]
After-import bmake-20211212

(cherry picked from commit 1c04cf7d5415a404722bfa182013efa028280736)

2 years agoMerge bmake-20211212
Simon J. Gerraty [Sat, 18 Dec 2021 18:09:14 +0000 (10:09 -0800)]
Merge bmake-20211212

commit '2935fe8237c83c1dcb113dd5335733263e68e6fd'

(cherry picked from commit 129043849f62f9cfa72f6fae68417d9995860f3f)

2 years agomake: fix MAKE_JOB_ERROR_TOKEN
Simon J. Gerraty [Fri, 10 Sep 2021 20:11:28 +0000 (13:11 -0700)]
make: fix MAKE_JOB_ERROR_TOKEN

The rework of GetBooleanVar to GetBooleanExpr requires
we add "${" and ":U}" around the expression so it can be directly
evaluated.

Reported by: mjg
MFC after: 1 week

#
#                                                         72 columns --|
#
# Uncomment and complete these metadata fields, as appropriate:
#
# PR: <If and which Problem Report is related.>
# Reported by: <If someone else reported the issue.>
# Reviewed by: <If someone else reviewed your modification.>
# Approved by: <If you needed approval for this commit.>
# Obtained from: <If the change is from a third party.>
# MFC after: <N [day[s]|week[s]|month[s]].  Request a reminder email>
# MFH: <Ports tree branch name.  Request approval for merge.>
# Relnotes: <Set to 'yes' for mention in release notes.>
# Security: <Vulnerability reference (one per line) or description.>
# Sponsored by: <If the change was sponsored by an organization.>
# Pull Request: <https://github.com/freebsd/<repo>/pull/###>
# Differential Revision: <https://reviews.freebsd.org/D###>
#
# "Pull Request" and "Differential Revision" require the *full* GitHub or
# Phabricator URL.  The commit author should be set appropriately, using
# `git commit --author` if someone besides the committer sent in the change.
#
#                                                         72 columns --|
#
# Uncomment and complete these metadata fields, as appropriate:
#
# PR: <If and which Problem Report is related.>
# Reported by: <If someone else reported the issue.>
# Reviewed by: <If someone else reviewed your modification.>
# Approved by: <If you needed approval for this commit.>
# Obtained from: <If the change is from a third party.>
# MFC after: <N [day[s]|week[s]|month[s]].  Request a reminder email>
# MFH: <Ports tree branch name.  Request approval for merge.>
# Relnotes: <Set to 'yes' for mention in release notes.>
# Security: <Vulnerability reference (one per line) or description.>
# Sponsored by: <If the change was sponsored by an organization.>
# Pull Request: <https://github.com/freebsd/<repo>/pull/###>
# Differential Revision: <https://reviews.freebsd.org/D###>
#
# "Pull Request" and "Differential Revision" require the *full* GitHub or
# Phabricator URL.  The commit author should be set appropriately, using
# `git commit --author` if someone besides the committer sent in the change.
#
# Uncomment and complete these metadata fields, as appropriate:
#
# PR:
# Reported by: <If someone else reported the issue.>
# Reviewed by: <If someone else reviewed your modification.>
# Approved by: <If you needed approval for this commit.>
# Obtained from: <If the change is from a third party.>
# MFC after: <N [day[s]|week[s]|month[s]].  Request a reminder email>
# MFH: <Ports tree branch name.  Request approval for merge.>
# Relnotes: <Set to 'yes' for mention in release notes.>
# Security: <Vulnerability reference (one per line) or description.>
# Sponsored by: <If the change was sponsored by an organization.>
# Pull Request: <https://github.com/freebsd/<repo>/pull/###>
# Differential Revision: <https://reviews.freebsd.org/D###>
#
# "Pull Request" and "Differential Revision" require the *full* GitHub or
# Phabricator URL.  The commit author should be set appropriately, using
# `git commit --author` if someone besides the committer sent in the change.
#

(cherry picked from commit 3b96abbab03327176b1e4ee02a6742bf9807dd75)

2 years agoUpdate to bmake-20210621
Simon J. Gerraty [Fri, 25 Jun 2021 21:26:16 +0000 (14:26 -0700)]
Update to bmake-20210621

MFC after: 1 week

(cherry picked from commit 68c4481aac28f5a088553b9c31579f6fbc8500fd)

2 years agoMerge commit 'ee914ef902ae018bd4f67192832120f9bf05651f' into new_merge
Simon J. Gerraty [Fri, 25 Jun 2021 21:31:14 +0000 (14:31 -0700)]
Merge commit 'ee914ef902ae018bd4f67192832120f9bf05651f' into new_merge

(cherry picked from commit b0c40a00a67f611868fc0f10bde6b28eb75931be)

2 years agoHave fsck_ffs(8) properly correct superblock check-hash failures.
Kirk McKusick [Wed, 16 Feb 2022 01:09:07 +0000 (17:09 -0800)]
Have fsck_ffs(8) properly correct superblock check-hash failures.

cherry pick cleanups from commit c0bfa109b942659f609b7e2bf3ba042ec0cb3f9d

PR:           245916

2 years agoHave fsck_ffs(8) properly correct superblock check-hash failures.
Kirk McKusick [Fri, 4 Feb 2022 19:46:36 +0000 (11:46 -0800)]
Have fsck_ffs(8) properly correct superblock check-hash failures.

(cherry picked from commit c0bfa109b942659f609b7e2bf3ba042ec0cb3f9d)

PR:           245916

2 years agonfsd: Reply NFSERR_SEQMISORDERED for bogus seqid argument
Rick Macklem [Wed, 9 Feb 2022 23:17:50 +0000 (15:17 -0800)]
nfsd: Reply NFSERR_SEQMISORDERED for bogus seqid argument

The ESXi NFSv4.1 client bogusly sends the wrong value
for the csa_sequence argument for a Create_session operation.
RFC8881 requires this value to be the same as the sequence
reply from the ExchangeID operation most recently done for
the client ID.

Without this patch, the server replies NFSERR_STALECLIENTID,
which is the correct response for an NFSv4.0 SetClientIDConfirm
but is not the correct error for NFSv4.1/4.2, which is
specified as NFSERR_SEQMISORDERED in RFC8881.
This patch fixes this.

This change does not fix the issue reported in the PR, where
the ESXi client loops, attempting ExchangeID/Create_session
repeatedly.

PR: 261291

(cherry picked from commit 17a56f3fabdfacb62f6d8858643cdb1861c8c1b5)

2 years agonfsd: Allow file owners to perform Open(Delegate_cur)
Rick Macklem [Wed, 2 Feb 2022 22:10:16 +0000 (14:10 -0800)]
nfsd: Allow file owners to perform Open(Delegate_cur)

Commit b0b7d978b6a8 changed the NFSv4 server's default
behaviour to check the file's mode or ACL for permission to
open the file, to be Linux and Solaris compatible.
However, it turns out that Linux makes an exception for
the case of Claim_delegate_cur(_fh).

When a NFSv4 client is returning a delegation, it must
acquire Opens against the server to replace the ones
done locally in the client.  The client does this via
an Open operation with Claim_delegate_cur(_fh).  If
this operation fails, due to a change to the file's
mode or ACL after the delegation was issued, the
client does not have any way to retain the open.

As such, the Linux client allows the file's owner
to perform an Open with Claim_delegate_cur(_fh)
no matter what the mode or ACL allows.

This patch makes the FreeBSD server allow this case,
to be Linux compatible.

This patch only affects the case where delegations
are enabled, which is not the default.

(cherry picked from commit e2fe58d61b7ca95cbe87ce841a87c9ae8cecb47b)

2 years agopciconf: Fix PCIS_CRYPTO_ENTERTAIN copy/paste.
Alexander Motin [Wed, 9 Feb 2022 20:56:30 +0000 (15:56 -0500)]
pciconf: Fix PCIS_CRYPTO_ENTERTAIN copy/paste.

Submitted by:   Dmitry Luhtionov <dmitryluhtionov@gmail.com>
MFC after: 1 week

(cherry picked from commit c04506fd4cc82cf0715142b5927de69a425086ba)

2 years agosnd_hda: Add some ATI HDMI codec IDs.
Alexander Motin [Wed, 9 Feb 2022 21:27:15 +0000 (16:27 -0500)]
snd_hda: Add some ATI HDMI codec IDs.

Submitted by: Dmitry Luhtionov <dmitryluhtionov@gmail.com>
MFC after: 1 week

(cherry picked from commit 98d59d2e0d8c61d145796b723021a90daf4439d9)

2 years agovt: fix splash_cpu logos use of vd_drawrect
Stefan Grundmann [Wed, 9 Feb 2022 03:15:53 +0000 (22:15 -0500)]
vt: fix splash_cpu logos use of vd_drawrect

In the (extremely unlikely) case of vd->vd_height ==
vt_logo_sprite_height the vd_drawrect code would write outside of
frame-buffer memory.

MFC after: 1 week
Reviewed by: cem
Differential Revision: https://reviews.freebsd.org/D34220

(cherry picked from commit 06296f77c5bc5ec1710a28b68b9410d192163087)

2 years agoIn GEOM debugging output, show consumer for cloned and duplicated bio's.
Kirk McKusick [Mon, 31 Jan 2022 01:20:10 +0000 (17:20 -0800)]
In GEOM debugging output, show consumer for cloned and duplicated bio's.

(cherry picked from commit 85f7e9a4f0393277b85a247543f71700c5eebb1f)

2 years agoufs: handle LoR between snap lock and vnode lock
Kirk McKusick [Fri, 28 Jan 2022 07:00:51 +0000 (23:00 -0800)]
ufs: handle LoR between snap lock and vnode lock

(cherry picked from commit ddf162d1d15f63e871fa1e44334c9461772b7f7a)

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

2 years agofreebsd-update: improve BE creation feature
Kyle Evans [Sat, 12 Feb 2022 21:36:24 +0000 (15:36 -0600)]
freebsd-update: improve BE creation feature

This addresses one nit and one bug in the BE creation feature of
freebsd-update:

The nit addressed is that it currently only names the BEs after the
userland version, but the kernel version may be higher.  After this
change, we request both and pass them through sort(1) to choose the
highest.  This is especially helpful if a freebsd-update patch touched
one but not the other.

The bug fixed is that roots updated that are not located at '/', e.g.,
by using -b or -j, will no longer create boot environments
automatically.  There's a very low chance these will actually change the
BE in any meaningful way, anyways.  It could make sense in the future
to allow an argument-override to create the BE anyways if someone comes
up with a non-standard setup, e.g., where a jail is an important part of
their boot environment on an appliance or some such setup.

Half of this patch is submitted by delphij@, the other half kevans@.

PR: 261446

(cherry picked from commit e01e8f911b935eabcc35b4d121951e4e21042ee5)

2 years agolibc binuptime(): use the right function to get the most significant bit index
Konstantin Belousov [Tue, 8 Feb 2022 19:13:40 +0000 (21:13 +0200)]
libc binuptime(): use the right function to get the most significant bit index

PR: 261781

(cherry picked from commit a1f9326607dea5ab6979935e3ca2d7402dcc7cc1)

2 years agoFix gzip compressed core dumps on big endian architectures
Justin Hibbits [Thu, 10 Feb 2022 15:21:36 +0000 (09:21 -0600)]
Fix gzip compressed core dumps on big endian architectures

The gzip trailer words (size and CRC) are both little-endian per the spec.

MFC after: 3 days
Sponsored by: Juniper Networks, Inc.

(cherry picked from commit 6db44b0158c37f2206f2c4ea7f29f5b774389e54)

2 years agostrftime.3: Fix a typo and use St for standards
Mateusz Piotrowski [Mon, 7 Feb 2022 14:14:47 +0000 (15:14 +0100)]
strftime.3: Fix a typo and use St for standards

MFC after: 1 week

(cherry picked from commit 407391740865106bc8ba2186d936f94815d0cc12)

2 years agoocs_fc: Fix a possible Null pointer dereference
Ram Kishore Vegesna [Wed, 9 Feb 2022 10:14:12 +0000 (15:44 +0530)]
ocs_fc: Fix a possible Null pointer dereference

Fix a possible Null pointer dereference in ocs_hw_get_profile_list_cb()

PR: 261453
Reported by: lwhsu

MFC after: 3 days

(cherry picked from commit 7bf31432fd03e2a5a815d1cc81de9a7b1ea3d3ca)

2 years agoucred.9: fix typo
Johan Jansson [Fri, 11 Feb 2022 16:46:37 +0000 (18:46 +0200)]
ucred.9: fix typo

PR: 261889

(cherry picked from commit d4b0fa45dc1531fafb1f3f1a1956056597a4722c)

2 years agoFix the spelling of '*/' in the vnic driver
Andrew Turner [Tue, 27 Jul 2021 19:43:08 +0000 (19:43 +0000)]
Fix the spelling of '*/' in the vnic driver

Sponsored by: The FreeBSD Foundation

(cherry picked from commit c007408c245b7aff0f203b021e70f263e57d5173)

2 years agoAPEI: Make sure event data fit into the buffer.
Alexander Motin [Thu, 3 Feb 2022 20:18:31 +0000 (15:18 -0500)]
APEI: Make sure event data fit into the buffer.

There seem to be systems returning some garbage here.  I still don't
know why, but at least I hope this check fix indefinite printf loop.

MFC after: 2 weeks

(cherry picked from commit 3b248a2113829e43c382f5e2b1f85c626c01f024)

2 years agong pppoe(4): Add the required NET_EPOCH section to the hook
Aleksandr Fedorov [Wed, 9 Feb 2022 19:00:50 +0000 (22:00 +0300)]
ng pppoe(4): Add the required NET_EPOCH section to the hook
disconnection function.

Disconnecting hooks are called outside of NET_EPOCH, but
ng_pppoe_disconnect() calls NG_SEND_DATA_ONLY() which should be called
in NET_EPOCH.

PR: 257067
Reported by: niels=freebsd@bakker.net
Reviewed by: vmaffione (mentor), glebius, donner
Approved by: vmaffione (mentor), glebius, donner
Sponsored by: vstack.com
Differential Revision: https://reviews.freebsd.org/D34185

(cherry picked from commit b27e6e91d0ad1f87b296f7583d4f5d938d7a997c)

2 years agonetmap: fix LOR in iflib_netmap_register
Vincenzo Maffione [Fri, 14 Jan 2022 21:09:04 +0000 (21:09 +0000)]
netmap: fix LOR in iflib_netmap_register

In iflib_device_register(), the CTX_LOCK is acquired first and then
IFNET_WLOCK is acquired by ether_ifattach(). However, in netmap_hw_reg()
we do the opposite: IFNET_RLOCK is acquired first, and then CTX_LOCK
is acquired by iflib_netmap_register(). Fix this LOR issue by wrapping
the CTX_LOCK/UNLOCK calls in iflib_device_register with an additional
IFNET_WLOCK. This is safe since the IFNET_WLOCK is recursive.

MFC after: 1 month

(cherry picked from commit e0e12405285b61a724c646b8f8e99e3ec775291e)

2 years agoipsec(4): Fix a few typos in error messages
Gordon Bergling [Sun, 6 Feb 2022 12:43:42 +0000 (13:43 +0100)]
ipsec(4): Fix a few typos in error messages

- s/receieve/receive/

(cherry picked from commit ecc467ebad065299804ca556e86c0c5ebf060700)

2 years agoInstall ipmi man page also on arm64
Ed Maste [Sat, 29 May 2021 20:49:20 +0000 (16:49 -0400)]
Install ipmi man page also on arm64

Fixes: 40d0971bbe5d ("arm64: enable build of the ipmi module")
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 62174eaf460544c7645172cdde2c9204dcfd7321)

2 years agongatm: remove one of doubled semicolons
Ed Maste [Mon, 30 Aug 2021 15:38:51 +0000 (11:38 -0400)]
ngatm: remove one of doubled semicolons

Discussed with: harti

(cherry picked from commit 0637070b5bca4691bf54c5985a74f4d7888050dc)

2 years agomgb: Connect if_mgb module to the build
Ed Maste [Tue, 28 Sep 2021 16:58:40 +0000 (12:58 -0400)]
mgb: Connect if_mgb module to the build

It supports the following Microchip devices:

LAN7430 PCIe Gigabit Ethernet controller with PHY
LAN7431 PCIe Gigabit Ethernet controller with RGMII interface

The driver has a number of caveats and limitations, but is functional.

Relnotes: Yes
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 543df609072fe49079c36d6bee510e1645edde3a)

2 years agovnic: add TODO list
Ed Maste [Tue, 27 Jul 2021 21:51:21 +0000 (17:51 -0400)]
vnic: add TODO list

- non-promisc mode
- multicast filter support

Also drop ARM64TODO comments; this is an issue with this specific
driver, not a general arm64 issue.

PR: 223575
PR: 223573

(cherry picked from commit 941650aae9762293f4c63788ddb17e0114828813)
(cherry picked from commit 29e9b487c1d427409a8bf1f893bc71a57c76f4b0)

2 years agoAnnotate geom_md with MODULE_VERSION
Kyle Evans [Thu, 10 Feb 2022 06:15:29 +0000 (00:15 -0600)]
Annotate geom_md with MODULE_VERSION

This was missed in 74d6c131cbe2 where other geom modules were annotated
with MODULE_VERSION.  Again, the problem is the same: we can't detect
that geom_md is loaded into the kernel without it.

This was noticed in release builds on the cluster; mdconfig attempts to
load geom_md because it can't detect it in the kernel, but the cluster
config includes md(4) and does not build the kmod.  This problem would
have been masked on hosts with the kmod built, as the kmod attempts to
register the g_md module and fails.  With this commit, mdconfig would
not even try to load it again.

(cherry picked from commit b9c92d631cfb06c12b0d2d9ad29a9f3f0b856237)

2 years agostyle.mdoc.5: Document the conventions for -width
Mateusz Piotrowski [Sat, 29 Jan 2022 21:23:49 +0000 (22:23 +0100)]
style.mdoc.5: Document the conventions for -width

Reviewed by: debdrup
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D33394

(cherry picked from commit 79afae3b3f245ffa79726ae097cc843628ae9d92)

2 years agoipheth.4: Simplify output filtering example
Mateusz Piotrowski [Sat, 29 Jan 2022 21:16:50 +0000 (22:16 +0100)]
ipheth.4: Simplify output filtering example

MFC after: 2 weeks

(cherry picked from commit 60401b3883149cfa8ab8158523282715441be66e)

2 years agoipheth.4: Fix examples
Mateusz Piotrowski [Sat, 29 Jan 2022 21:13:42 +0000 (22:13 +0100)]
ipheth.4: Fix examples

It is now necessary to use the -d flag for some of the usbconfig(8)
invocations.

MFC after: 2 weeks

(cherry picked from commit d0b92c068e36bbaf06b6a7dc00cfc7d275878b6c)

2 years agoRemove device lio from i386's LINT-NOIP
Dimitry Andric [Tue, 8 Feb 2022 18:53:52 +0000 (19:53 +0100)]
Remove device lio from i386's LINT-NOIP

This fixes link errors for the LINT-NOIP kernel on i386:

```
ld: error: undefined symbol: tcp_lro_flush_all
>>> referenced by lio_droq.c
>>>               lio_droq.o:(lio_droq_process_packets)

ld: error: undefined symbol: tcp_lro_rx
>>> referenced by lio_core.c
>>>               lio_core.o:(lio_push_packet)

ld: error: undefined symbol: tcp_lro_init
>>> referenced by lio_main.c
>>>               lio_main.o:(lio_attach)

ld: error: undefined symbol: tcp_lro_free
>>> referenced by lio_main.c
>>>               lio_main.o:(lio_attach)
>>> referenced by lio_main.c
>>>               lio_main.o:(lio_destroy_nic_device)
*** [kernel] Error code 1
```

MFC after: 3 days

(cherry picked from commit 14a15342bbc88906c97fbf84553eb5c6de8295ca)

2 years agotty_info: Avoid warning by using logical instead of bitwise operators
Dimitry Andric [Sun, 6 Feb 2022 17:41:20 +0000 (18:41 +0100)]
tty_info: Avoid warning by using logical instead of bitwise operators

Since TD_IS_RUNNING() and TS_ON_RUNQ() are defined as logical
expressions involving '==', clang 14 warns about them being checked with
a bitwise operator instead of a logical one:

```
sys/kern/tty_info.c:124:9: error: use of bitwise '|' with boolean operands [-Werror,-Wbitwise-instead-of-logical]
        runa = TD_IS_RUNNING(td) | TD_ON_RUNQ(td);
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                 ||
sys/sys/proc.h:562:27: note: expanded from macro 'TD_IS_RUNNING'
                                ^
sys/kern/tty_info.c:124:9: note: cast one or both operands to int to silence this warning
sys/sys/proc.h:562:27: note: expanded from macro 'TD_IS_RUNNING'
                                ^
sys/kern/tty_info.c:129:9: error: use of bitwise '|' with boolean operands [-Werror,-Wbitwise-instead-of-logical]
        runb = TD_IS_RUNNING(td2) | TD_ON_RUNQ(td2);
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                  ||
sys/sys/proc.h:562:27: note: expanded from macro 'TD_IS_RUNNING'
                                ^
sys/kern/tty_info.c:129:9: note: cast one or both operands to int to silence this warning
sys/sys/proc.h:562:27: note: expanded from macro 'TD_IS_RUNNING'
                                ^
```

Fix this by using logical operators instead. No functional change
intended.

Reviewed by: cem, emaste, kevans, markj
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D34186

(cherry picked from commit 7d8a4eb943a907a92dd400432c3c3adcbd93dad9)

2 years agoDisable clang 14 warning about bitwise operators in one more place
Dimitry Andric [Thu, 10 Feb 2022 18:48:31 +0000 (19:48 +0100)]
Disable clang 14 warning about bitwise operators in one more place

Follow up 5f2aca839400, where I missed the -Werror warning still being
emitted in libsa.

Fixes: 5f2aca839400
MFC after: 3 days

(cherry picked from commit 74f7afdfd2f5c1beaed7af1bfe89b8b520744500)

2 years agoDisable clang 14 warning about bitwise operators in zstd
Dimitry Andric [Tue, 8 Feb 2022 20:46:03 +0000 (21:46 +0100)]
Disable clang 14 warning about bitwise operators in zstd

Parts of zstd, used in openzfs and other places, trigger a new clang 14
-Werror warning:

```
sys/contrib/zstd/lib/decompress/huf_decompress.c:889:25: error: use of bitwise '&' with boolean operands [-Werror,-Wbitwise-instead-of-logical]
                        (BIT_reloadDStreamFast(&bitD1) == BIT_DStream_unfinished)
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```

While the warning is benign, it should ideally be fixed upstream and
then vendor-imported, but for now silence it selectively.

MFC after: 3 days

(cherry picked from commit 5f2aca83940097d7d23b4137073fb601f8e74232)

2 years agox86 atomic.h: remove obsoleted comment
Konstantin Belousov [Thu, 3 Feb 2022 17:46:22 +0000 (19:46 +0200)]
x86 atomic.h: remove obsoleted comment

(cherry picked from commit 9596b349bb57e50a2baec8497ced9f712f08f147)

2 years agox86 atomics: use lock prefix unconditionally
Konstantin Belousov [Thu, 3 Feb 2022 09:51:36 +0000 (11:51 +0200)]
x86 atomics: use lock prefix unconditionally

(cherry picked from commit 9c0b759bf9b520537616d026f21a0a98d70acd11)

2 years agox86 atomic.h: cleanup comments for preprocessor directives
Konstantin Belousov [Thu, 3 Feb 2022 09:25:03 +0000 (11:25 +0200)]
x86 atomic.h: cleanup comments for preprocessor directives

(cherry picked from commit cbf999e75d61c6efadeed8d32212eefa4dfb3dcb)

2 years agomlx5en: Make sure the NIC IP addresses are written to firmware on link up.
Hans Petter Selasky [Thu, 10 Feb 2022 10:12:21 +0000 (11:12 +0100)]
mlx5en: Make sure the NIC IP addresses are written to firmware on link up.

Fixes e059c120b4223fd5ec3af9def21c0519f439fe57 .

PR: 261746
Sponsored by: NVIDIA Networking

(cherry picked from commit 04f407a3e5e7bf452768201ace260b575f1a7924)

2 years agoUse CPUID leaf 0x40000010 for local APIC freq
Colin Percival [Sun, 9 Jan 2022 00:59:31 +0000 (16:59 -0800)]
Use CPUID leaf 0x40000010 for local APIC freq

Some VM systems announce the frequency of the local APIC via the
CPUID leaf 0x40000010.  Using this allows us to boot slightly
faster by avoiding the need for timer calibration.

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

(cherry picked from commit de1292c6ff8a445fd453effba8cc23c38cea223f)

2 years agoTSC: Use 0x40000010 CPUID leaf for all VM types
Colin Percival [Tue, 4 Jan 2022 07:28:36 +0000 (23:28 -0800)]
TSC: Use 0x40000010 CPUID leaf for all VM types

While this CPUID leaf was originally only used by VMWare, other
hypervisors now also use it to announce the TSC frequency to guests.

This speeds up the boot process by 100 ms in EC2 and other systems,
by allowing the early calibration DELAY to be skipped.

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

(cherry picked from commit 4a432614f68cf35879dbb4ebef089f5b8db95334)

2 years agoDetect CPU type before asking VMWare for TSC freq
Colin Percival [Tue, 4 Jan 2022 07:00:39 +0000 (23:00 -0800)]
Detect CPU type before asking VMWare for TSC freq

This allows us to set tsc_is_invariant and select appropriately
fenced versions of RDTSC based on the CPU type.

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

(cherry picked from commit fd980feb574d0924918b42cd449cedf557dfb9e0)

2 years agox86: Speed up clock calibration
Colin Percival [Mon, 10 Jan 2022 01:22:20 +0000 (17:22 -0800)]
x86: Speed up clock calibration

Prior to this commit, the TSC and local APIC frequencies were calibrated
at boot time by measuring the clocks before and after a one-second sleep.
This was simple and effective, but had the disadvantage of *requiring a
one-second sleep*.

Rather than making two clock measurements (before and after sleeping) we
now perform many measurements; and rather than simply subtracting the
starting count from the ending count, we calculate a best-fit regression
between the target clock and the reference clock (for which the current
best available timecounter is used). While we do this, we keep track
of an estimate of the uncertainty in the regression slope (aka. the ratio
of clock speeds), and stop measuring when we believe the uncertainty is
less than 1 PPM.

In order to avoid the risk of aliasing resulting from the data-gathering
loop synchronizing with (a multiple of) the frequency of the reference
clock, we add some additional spinning depending upon the iteration number.

For numerical stability and simplicity of implementation, we make use of
floating-point arithmetic for the statistical calculations.

On the author's Dell laptop, this reduces the time spent in calibration
from 2000 ms to 29 ms; on an EC2 c5.xlarge instance, it is reduced from
2000 ms to 2.5 ms.

Reviewed by: bde (previous version), kib
Sponsored by: https://www.patreon.com/cperciva
Differential Revision: https://reviews.freebsd.org/D33802

(cherry picked from commit c2705ceaeb09d8579661097fd358ffb5defb5624)

2 years agoGEOM: Set G_CF_DIRECT_SEND/RECEIVE for taste consumers.
Alexander Motin [Sun, 30 Jan 2022 02:59:03 +0000 (21:59 -0500)]
GEOM: Set G_CF_DIRECT_SEND/RECEIVE for taste consumers.

All I/O requests through the taste consumers are synchronous, done
with g_read_data() and without any locks held.  It makes no sense
to delegate the I/O to g_down/g_up threads.

This removes many of context switches during disk retaste.

MFC after: 2 weeks

(cherry picked from commit 10ae42ccbde4fe7c8c9de3d54f3c0d63457a1a68)

2 years agoglabel: Set G_CF_DIRECT_SEND/RECEIVE for taste consumer.
Alexander Motin [Fri, 28 Jan 2022 19:22:41 +0000 (14:22 -0500)]
glabel: Set G_CF_DIRECT_SEND/RECEIVE for taste consumer.

All I/O requests through the taste consumer are synchronous, done
with g_read_data() and without any locks held.  It makes no sense
to delegate the I/O to g_down/g_up threads.

This removes many of context switches during disk retaste.

MFC after: 2 weeks

(cherry picked from commit 29998bf2ac4cc3ac49827336655bdbcb755eeffc)

2 years agoGEOM: Relax direct dispatch for GEOM threads.
Alexander Motin [Fri, 28 Jan 2022 19:12:29 +0000 (14:12 -0500)]
GEOM: Relax direct dispatch for GEOM threads.

The only cases when direct dispatch does not make sense is for I/O
submission from down thread and for completion from up thread.  In
all other cases, if both consumer and producer are OK about it, we
can save on context switches.

MFC after: 2 weeks

(cherry picked from commit ffc1cc95e78ec05a3e1a0aed869e33a44d9f6641)

2 years agograid: Set G_CF_DIRECT_SEND for task consumer.
Alexander Motin [Fri, 28 Jan 2022 16:09:30 +0000 (11:09 -0500)]
graid: Set G_CF_DIRECT_SEND for task consumer.

Unlike normal consumers all taste consumer I/O is synchronous, done
with g_read_data() and without any locks held.  It makes no sense to
delegate I/O submission to g_down thread.

This should remove number of context switches during disk retaste.

MFC after: 2 weeks

(cherry picked from commit 0d8cec7658d50e4190899376330c2c1eb5d8c659)

2 years agoCTL: Fix mode page trucation on HA synchronization.
Alexander Motin [Thu, 3 Feb 2022 15:48:19 +0000 (10:48 -0500)]
CTL: Fix mode page trucation on HA synchronization.

Due to variable size of struct ctl_ha_msg_mode ctl_isc_announce_mode()
sent only first 4 bytes of modified mode page to the other HA side,
that caused its corruption there, noticeable only after failover.

I've found alike bug also in ctl_isc_announce_lun(), but there it was
sending slightly more than needed, that is a smaller problem.

MFC after: 1 week
Sponsored by: iXsystems, Inc.

(cherry picked from commit 1a8d8a3a909f906ed69cca080a6446e7295bcbbb)

2 years agosched: separate out schedinit_ap()
Kyle Evans [Tue, 2 Nov 2021 18:06:47 +0000 (13:06 -0500)]
sched: separate out schedinit_ap()

schedinit_ap() sets up an AP for a later call to sched_throw(NULL).

Currently, ULE sets up some pcpu bits and fixes the idlethread lock with
a call to sched_throw(NULL); this results in a window where curthread is
setup in platforms' init_secondary(), but it has the wrong td_lock.
Typical platform AP startup procedure looks something like:

- Setup curthread
- ... other stuff, including cpu_initclocks_ap()
- Signal smp_started
- sched_throw(NULL) to enter the scheduler

cpu_initclocks_ap() may have callouts to process (e.g., nvme) and
attempt to sched_add() for this AP, but this attempt fails because
of the noted violated assumption leading to locking heartburn in
sched_setpreempt().

Interrupts are still disabled until cpu_throw() so we're not really at
risk of being preempted -- just let the scheduler in on it a little
earlier as part of setting up curthread.

(cherry picked from commit 589aed00e36c22733d3fd9c9016deccf074830b1)

2 years agoFix a memory leak when ip_output_send() returns EAGAIN due to send tag issues
Andrew Gallatin [Thu, 27 Jan 2022 15:28:15 +0000 (10:28 -0500)]
Fix a memory leak when ip_output_send() returns EAGAIN due to send tag issues

When ip_output_send() returns EAGAIN due to issues with send tags (route
change, lagg failover, etc), it must free the mbuf. This is because
ip_output_send() was written as a wrapper/replacement for a direct
call to  if_output(), and the contract with if_output() has
historically been that it owns the mbufs once called. When
ip_output_send() failed to free mbufs, it violated this assumption
and lead to leaked mbufs.

This was noticed when using NIC TLS in combination with hardware
rate-limited connections. When seeing lots of NIC output drops
triggered ratelimit send tag changes, we noticed we were leaking
ktls_sessions, send tags and mbufs. This was due ip_output_send()
leaking mbufs which held references to ktls_sessions, which in
turn held references to send tags.

Many thanks to jbh, rrs, hselasky and markj for their help in
debugging this.

Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D34054
Reviewed by: hselasky, jhb, rrs
MFC after: 2 weeks

(cherry picked from commit 9ba117960e1755a693f9361e4d076630dfe13dba)

2 years agotests: add a basic test for argc == 0
Kyle Evans [Wed, 26 Jan 2022 01:22:03 +0000 (19:22 -0600)]
tests: add a basic test for argc == 0

The kernel should reject such exec()s now, early on. Instead of adding
the needed boilerplate to write a test in C, just add an -n argument for
"(n)ull argv" to the execve helper and exec this other helper that just
exits silently with argv count.

(cherry picked from commit e5b431fc0c20771a2a18cb5169d75cf337d0f1dd)

2 years agoexecve: disallow argc == 0
Kyle Evans [Tue, 25 Jan 2022 22:47:23 +0000 (16:47 -0600)]
execve: disallow argc == 0

The manpage has contained the following verbiage on the matter for just
under 31 years:

"At least one argument must be present in the array"

Previous to this version, it had been prefaced with the weakening phrase
"By convention."

Carry through and document it the rest of the way.  Allowing argc == 0
has been a source of security issues in the past, and it's hard to
imagine a valid use-case for allowing it.  Toss back EINVAL if we ended
up not copying in any args for *execve().

The manpage change can be considered "Obtained from: OpenBSD"

(cherry picked from commit 773fa8cd136a5775241c3e3a70f1997633ebeedf)
(cherry picked from commit c9afc7680f3e1f0510518de9de4264553a31aade)

2 years agobhyve/virtio: use correct device id for virtio-scsi
Robert Wing [Mon, 31 Jan 2022 18:44:47 +0000 (09:44 -0900)]
bhyve/virtio: use correct device id for virtio-scsi

Section 4.1.2.1 of the virtio spec states that the transitional PCI
device id for a scsi device is 0x1004.

Fix suggested by reporter.

PR:             259961
Reported by:    me@nanaya.pro
Reviewed by: imp, jhb
Fixes: f9c005a17f4e ("Add bhyve virtio-scsi storage backend support.")
Differential Revision: https://reviews.freebsd.org/D34103

(cherry picked from commit b4cc5d63b6112746598d21413c9800a43171da52)

2 years agocam: don't lock while handling an AC_UNIT_ATTENTION
Robert Wing [Tue, 4 Jan 2022 01:21:58 +0000 (16:21 -0900)]
cam: don't lock while handling an AC_UNIT_ATTENTION

Don't take the device_mtx lock in daasync() when handling an
AC_UNIT_ATTENTION. Instead, assert the lock is held before modifying the
periph's softc flags.

The device_mtx lock is taken in xptdevicetraverse() before daasync()
is eventually called in xpt_async_bcast().

PR:             240917, 226510, 226578
Reviewed by:    imp
MFC after:      3 weeks
Differential Revision: https://reviews.freebsd.org/D27735

(cherry picked from commit bb8441184bab60cd8a07c2b94bd6c4ae8b56ec25)

2 years agosyncache: accept packet with no SA when TCP_MD5SIG is set
Robert Wing [Sun, 9 Jan 2022 01:07:50 +0000 (16:07 -0900)]
syncache: accept packet with no SA when TCP_MD5SIG is set

When TCP_MD5SIG is set on a socket, all packets are dropped that don't
contain an MD5 signature. Relax this behavior to accept a non-signed
packet when a security association doesn't exist with the peer.

This is useful when a listen socket set with TCP_MD5SIG wants to handle
connections protected with and without MD5 signatures.

Reviewed by: bz (previous version)
Sponsored by:   nepustil.net
Sponsored by:   Klara Inc.
Differential Revision: https://reviews.freebsd.org/D33227

(cherry picked from commit eb18708ec8c7e1de6a05aba41971659549991b10)

2 years agotcpmd5: return ENOENT when security association not found
Robert Wing [Sun, 9 Jan 2022 01:07:10 +0000 (16:07 -0900)]
tcpmd5: return ENOENT when security association not found

Return ENOENT from tcp_ipsec_input() when a security association is not
found. This allows callers of TCP_MD5_INPUT() to differentiate between a
security association not found and receiving a bad signature.

Also return ENOENT from tcp_ipsec_output() for consistency.

Reviewed by: ae
Sponsored by:   nepustil.net
Sponsored by:   Klara Inc.
Differential Revision: https://reviews.freebsd.org/D33226

(cherry picked from commit 91d388119ae229702538b96d79cf76556cf0ecf4)

2 years agocompiler-rt: support ReExec() on FreeBSD
Ed Maste [Wed, 19 Jan 2022 18:08:18 +0000 (13:08 -0500)]
compiler-rt: support ReExec() on FreeBSD

Based on getMainExecutable() in llvm/lib/Support/Unix/Path.inc.
This will need a little more work for an upstream change as it must
support older FreeBSD releases that lack elf_aux_info() / AT_EXEC_PATH.

No objection: dim
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D33934

(cherry picked from commit 96fe7c8ab0f65cf829619abd74ae6c126b21e15f)

2 years agossh: pass 0 to procctl(2) to operate on self
Ed Maste [Thu, 20 Jan 2022 18:41:39 +0000 (13:41 -0500)]
ssh: pass 0 to procctl(2) to operate on self

As of f833ab9dd187 procctl(2) allows idtype P_PID with id = 0 as a
shortcut for the calling process ID.  The shortcut also bypasses the
p_cansee / p_candebug test (since the process is able to act on itself.)

At present if the security.bsd.unprivileged_proc_debug sysctl is 0 then
procctl(P_PID, getpid(), ... for a process to act on itself will fail,
but procctl(P_PID, 0, ... will succeed.  This should likely be addressed
with a kernel change.

In any case the id = 0 shortcut is a tiny optimization for a process to
act on itself and allows the self-procctl to succeed, so use it in ssh.

Reported by: Shawn Webb
Reviewed by: kib
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D33970

(cherry picked from commit 0746301c4995d9e4a82b0e5034b62e310694d1ef)
(cherry picked from commit e38610abcadbfeba5f7a32aa8a6bc8981be64908)

2 years agossh: update to OpenSSH v8.8p1
Ed Maste [Sun, 19 Dec 2021 16:02:02 +0000 (11:02 -0500)]
ssh: update to OpenSSH v8.8p1

OpenSSH v8.8p1 was motivated primarily by a security update and
deprecation of RSA/SHA1 signatures.  It also has a few minor bug fixes.

The security update was already applied to FreeBSD as an independent
change, and the RSA/SHA1 deprecation is excluded from this commit but
will immediately follow.

MFC after: 1 month
Relnotes: Yes
Sponsored by: The FreeBSD Foundation

(cherry picked from commit e9e8876a4d6afc1ad5315faaa191b25121a813d7)
(cherry picked from commit 2ffb13149c8e46cb7d7e891b237255615906dc60)

2 years agoApply fix for ThreadSanitizer false positive data race reports
Dimitry Andric [Mon, 7 Feb 2022 18:39:02 +0000 (19:39 +0100)]
Apply fix for ThreadSanitizer false positive data race reports

Merge commit 28fb22c90fe7 from llvm git (by Dimitry Andric):

  [TSan] Handle FreeBSD specific indirection of libpthread functions

  Similar to 60cc1d3218fc for NetBSD, add aliases and interceptors for the
  following pthread related functions:

  - pthread_cond_init(3)
  - pthread_cond_destroy(3)
  - pthread_cond_signal(3)
  - pthread_cond_broadcast(3)
  - pthread_cond_wait(3)
  - pthread_mutex_init(3)
  - pthread_mutex_destroy(3)
  - pthread_mutex_lock(3)
  - pthread_mutex_trylock(3)
  - pthread_mutex_unlock(3)
  - pthread_rwlock_init(3)
  - pthread_rwlock_destroy(3)
  - pthread_rwlock_rdlock(3)
  - pthread_rwlock_tryrdlock(3)
  - pthread_rwlock_wrlock(3)
  - pthread_rwlock_trywrlock(3)
  - pthread_rwlock_unlock(3)
  - pthread_once(3)
  - pthread_sigmask(3)

  In FreeBSD's libc, a number of internal aliases of the pthread functions
  are invoked, typically with an additional prefixed underscore, e.g.
  _pthread_cond_init() and so on.

  ThreadSanitizer needs to intercept these aliases too, otherwise some
  false positive reports about data races might be produced.

  Reviewed By: dvyukov

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

MFC after: 3 days

(cherry picked from commit 1c21bfb1b1a368f9833b9fb84ed323eeb58c5d4c)

2 years agombuf(9): Assert receive mbufs don't carry a send tag.
Hans Petter Selasky [Wed, 26 Jan 2022 11:13:53 +0000 (12:13 +0100)]
mbuf(9): Assert receive mbufs don't carry a send tag.

Else we would start leaking reference counts.

Discussed with: jhb@
Sponsored by: NVIDIA Networking

(cherry picked from commit 17cbcf33c3b6d0361d71bdb00b8633ec9bb5ae53)