]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
23 months agorescure.8: Do not recommend release artifact disc2
Mateusz Piotrowski [Thu, 30 Jun 2022 11:28:00 +0000 (13:28 +0200)]
rescure.8: Do not recommend release artifact disc2

The FreeBSD project does not publish disc2 image anymore.

MFC after: 2 weeks

(cherry picked from commit 7963c02c9bc222e8ac8c1a3acb87451bd74b9733)

23 months agosysctl.conf.5: Document rc.d/sysctl and rc.d/sysctl_lastload
Mateusz Piotrowski [Thu, 30 Jun 2022 13:27:21 +0000 (15:27 +0200)]
sysctl.conf.5: Document rc.d/sysctl and rc.d/sysctl_lastload

Also, update the BUGS section. The example describes an issue, which is
not true anymore thanks to sysctl_lastload. Point readers to rcorder(8)
instead.

MFC after: 2 weeks

(cherry picked from commit 383ccaa4050e3cbbd8ce8163c8aebd07c3d94ab1)

23 months agorc.conf.5: Improve documentation of <name>_oomprotect
Mateusz Piotrowski [Thu, 7 Jul 2022 18:01:57 +0000 (20:01 +0200)]
rc.conf.5: Improve documentation of <name>_oomprotect

Apart from improving readability, this commit mentions that
<name>_oomprotect is ignored in a jail environment. Also, replace
${name}_cmd with the correct ${argument}_cmd and point the reader to
rc.subr(8).

MFC after: 1 week

(cherry picked from commit df1817a81e891c4850157e7f21f94b113d663bec)

23 months agorc.conf(5): Add _limits, _login_class, and _oomprotect
Daniel Ebdrup Jensen [Tue, 18 May 2021 12:46:41 +0000 (14:46 +0200)]
rc.conf(5): Add _limits, _login_class, and _oomprotect

Add a few very useful variables that might easily be overlooked, since
they're only documented in rc.subr(8) which might not be the first place
that people look.

At least _oomprotect has existed since 11.0-RELEASE, and doesn't appear
to be very well-known. While the others aren't as new, in my estimation,
a lot more people would use them if they knew about them.

While here, also add a reference to rc.subr(8) and login.conf(5), and
sort the variables alphabetically.

Reported by:  Daniel Dettlaff <dmilith at gmail.com>
Reviewed by: ceri, gbe, 0mp, ygy, a.wolk, pauamma

(cherry picked from commit bd6dce978c1a4d4472c98ff5685de3c2f2bd0203)

23 months agorc.conf.5: -Tlint fixes.
Ceri Davies [Thu, 1 Jul 2021 21:51:37 +0000 (22:51 +0100)]
rc.conf.5: -Tlint fixes.

(cherry picked from commit 2ce58512957ec373abfb71712687d7e7b6abea82)

23 months agorc.subr: Make sure oomprotect protects existing children
Mike Walker [Thu, 7 Jul 2022 20:28:37 +0000 (22:28 +0200)]
rc.subr: Make sure oomprotect protects existing children

The rc(8) framework support protecting services from OOM killer.
The current implementation applies the protection after the service has
already started. This works fine if only the main process is to be
protected (*_oomprotect=yes). However, the current implementation fails
to protect existing children when children are also to be protected
(*_oomprotect=all). This patch fixes that.

Note: it is not easy to apply the protectoin earlier because we want to
support both the services which use the "command" variable and those
that use the "start_cmd" variable.

PR: 256148
Approved by: adrian, osogbo
Tested by: Jamie Landeg-Jones <jamie@catflap.org>
Fixes: 3bead71e959d - Add a global option where we can protect
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D35747

(cherry picked from commit 68e035c0172b441db772de41ad0f8977679bfedc)

23 months agoprotect.1: Document that protect(1) does not work in jails
Mateusz Piotrowski [Mon, 11 Jul 2022 22:43:27 +0000 (00:43 +0200)]
protect.1: Document that protect(1) does not work in jails

The reason is that in order to protect a process procctl(2) needs
the PRIV_VM_MADV_PROTECT privilege, which is currently denied in jails
(see kern_jail.c).

MFC after: 1 week

(cherry picked from commit 6452fb1e87ed9d00b52fa1e63e7c3a7516c9586c)

23 months agoprotect.1: Improve synopsis
Mateusz Piotrowski [Thu, 7 Jul 2022 13:12:50 +0000 (15:12 +0200)]
protect.1: Improve synopsis

While here, make the list's -width argument a bit shorter for
readability.

MFC after: 3 days

(cherry picked from commit cb56f86025b88bc4174aa668b3966886b8420955)

23 months agoprotect(1): Correct typo and add newline
Daniel Ebdrup Jensen [Tue, 12 Apr 2022 10:38:50 +0000 (12:38 +0200)]
protect(1): Correct typo and add newline

Fix a typo, and move a sentence onto a new line in accordance with
mdoc(7) syntax.

While here, also remember to bump .Dd accordingly, as it was missed in
the prior commit.

Reported by: maxim@

(cherry picked from commit bd1eafcdd02a6f559844aafe0dd0df34a356259d)

23 months agoprotect.1: document existence of _oomprotect
Adam Wolk [Mon, 11 Apr 2022 22:23:43 +0000 (00:23 +0200)]
protect.1: document existence of _oomprotect

Improve discoverability of the functionality by mentioning in the
userland tool manual. Add a SEE ALSO entry to rc.conf(5) where more
details are provided.

Sponsored by:   Fudo Security (a.wolk)
Differential Revision: https://reviews.freebsd.org/D30334

(cherry picked from commit c8b6be0f7d1b92d11b279761685f61f6702700a1)

23 months agojail.8: Fix formatting of synopsis and some code examples
Mateusz Piotrowski [Mon, 18 Jul 2022 11:38:00 +0000 (13:38 +0200)]
jail.8: Fix formatting of synopsis and some code examples

MFC after: 3 days

(cherry picked from commit 203be0938dc5e1bd46b028f72077f8531e98a6cd)

23 months agoifconfig.8: Prefer consistent terminologies
Zhenlei Huang [Wed, 29 Jun 2022 06:55:36 +0000 (08:55 +0200)]
ifconfig.8: Prefer consistent terminologies

Reviewed by: pauamma_gundo.com, email_luiz.eng.br
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D35384

(cherry picked from commit ccc48995c2cffd70256237e6f2d478c4c878db76)

23 months agoRewrite function definitions in the UFS/FFS code base with identifier lists.
Kirk McKusick [Wed, 13 Jul 2022 21:06:43 +0000 (14:06 -0700)]
Rewrite function definitions in the UFS/FFS code base with identifier lists.

No functional change to the code.

(cherry picked from commit 064e6b4303d8aec9cfd27653d4dd2abea829a6c7)

Fixes to build from 064e6b4:

(cherry picked from commit c792466f878a082a63683d3a8a1f7b468081d835)

(cherry picked from commit 2e66649e4f34188d92bd32b5ba7fde8d1e86ef40)

23 months agoFix clang 15 warning in cxgbe
Dimitry Andric [Sat, 16 Jul 2022 19:19:51 +0000 (21:19 +0200)]
Fix clang 15 warning in cxgbe

Clang 15 warns:

    sys/dev/cxgbe/cudbg/cudbg_lib.c:2949:6: error: variable 'i' set but not used [-Werror,-Wunused-but-set-variable]
            int i = 0;
                ^

Apparently 'i' was meant as the current retry counter, but '1' was used
in the while loop comparison instead, making the loop potentially
infinite, if 'busy' never gets reset.

MFC after: 3 days
Reviewed by: np
Differential Revision: https://reviews.freebsd.org/D35834

(cherry picked from commit fb0493d55998eeb9f062b15b40924ff722f3eba5)

23 months agoUnlock inp when handling TCP_MD5SIG socket options
Claudio Jeker [Thu, 23 Jun 2022 14:50:47 +0000 (15:50 +0100)]
Unlock inp when handling TCP_MD5SIG socket options

Unlock the inp when hanlding TCP_MD5SIG socket options. tcp_ipsec_pcbctl
handles locking the inp when the option is being modified.

This was found by Claudio Jeker while working on the OpenBGPd port.

On 14 we get a panic when trying to call getsockopt, on 13.1 the process
locks up using 100% CPU.

Reviewed by: rscheff (transport), tuexen
MFC after: 3 days
Sponsored by: Klara Inc.
Differential Revision: https://reviews.freebsd.org/D35532

(cherry picked from commit 97453e5e7258158042795740f2736cfca972269d)

23 months agoaio: Improve UMA usage
Mark Johnston [Mon, 20 Jun 2022 16:17:11 +0000 (12:17 -0400)]
aio: Improve UMA usage

- Remove the AIO proc zone.  This zone gets one allocation per AIO
  daemon process, which isn't enough to warrant a dedicated zone.  Plus,
  unlike other AIO structures, aiops are small (32 bytes with LP64), so
  UMA doesn't provide better space efficiency than malloc(9).  Change
  one of the malloc types in vfs_aio.c to make it more general.

- Don't set the NOFREE flag on the other AIO zones.  This flag means
  that memory allocated to the AIO subsystem is never freed back to the
  VM, so it's always preferable to avoid using it when possible.  NOFREE
  was set without explanation when AIO was converted to use UMA 20 years
  ago, but it does not appear to be required; all of the structures
  allocated from UMA (per-process kaioinfo, kaiocb, and aioliojob) keep
  track of references and get freed only when none exist.  Plus, these
  structures will contain dangling pointer after they're freed (e.g.,
  the "cred", "fd_file" and "uiop" fields of struct kaiocb), so
  use-after-frees are dangerous even when the structures themselves are
  type-stable.

Reviewed by: asomers
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 9553bc89dbc38a861a750ddc605cec0381788c5d)

23 months agotime: Make realitexpire() local to kern_time.c
Mark Johnston [Wed, 13 Jul 2022 13:57:28 +0000 (09:57 -0400)]
time: Make realitexpire() local to kern_time.c

Sponsored by: The FreeBSD Foundation

(cherry picked from commit ef221ff645322f0ec147c706652744869774e128)

23 months agoAdjust agp_find_device() definition in agp.c to avoid clang 15 warning
Dimitry Andric [Sat, 16 Jul 2022 14:46:21 +0000 (16:46 +0200)]
Adjust agp_find_device() definition in agp.c to avoid clang 15 warning

With clang 15, the following -Werror warning is produced:

    sys/dev/agp/agp.c:910:16: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    agp_find_device()
                   ^
                    void

This is because agp_find_device() is declared with a (void) argument
list, and defined with an empty argument list. Make the definition match
the declaration.

MFC after: 3 days

(cherry picked from commit c0817e2aba26ceb683e9c649c22d7fcd9a921231)

23 months agoRemove unused but set variable in cxgb_sge
Dimitry Andric [Sat, 16 Jul 2022 18:16:36 +0000 (20:16 +0200)]
Remove unused but set variable in cxgb_sge

Clang 15 warns:

    sys/dev/cxgb/cxgb_sge.c:1290:21: error: variable 'txsd' set but not used [-Werror,-Wunused-but-set-variable]
            struct tx_sw_desc *txsd = &txq->sdesc[txqs->pidx];
                               ^

It appears 'txsd' is a leftover from a previous refactoring (see
3f345a5d09b6), but is no longer used for anything, and can be removed
without any functional change.

MFC after: 3 days
Reviewed by: np
Differential Revision: https://reviews.freebsd.org/D35833

(cherry picked from commit cab040039d6fe1b2a6de8f2ba2cc882c313d3c75)

23 months agoWPA_DISTDIR does not need to end in a slash
Dimitry Andric [Sat, 16 Jul 2022 15:45:26 +0000 (17:45 +0200)]
WPA_DISTDIR does not need to end in a slash

Since all uses of the macro also append a slash, this leads to double
slashes.

MFC after: 3 days

(cherry picked from commit 9917049b60f7cf7345a09d2bc22d51764a477984)

23 months agoAdjust parse() definition in boot2 to avoid clang 15 warning
Dimitry Andric [Fri, 15 Jul 2022 19:15:11 +0000 (21:15 +0200)]
Adjust parse() definition in boot2 to avoid clang 15 warning

With clang 15, the following -Werror warning is produced:

    stand/i386/boot2/boot2.c:358:6: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]

This is because parse() is declared with a (void) argument list, and
defined with an empty argument list. Make the definition match the
declaration.

MFC after: 3 days

(cherry picked from commit e60f6384f9dbe3abe83e59acf0997c591752ff81)

23 months agoMerge fix for zfs readmmap test from CheriBSD
Dimitry Andric [Fri, 15 Jul 2022 19:10:09 +0000 (21:10 +0200)]
Merge fix for zfs readmmap test from CheriBSD

Merge commit 1737d8397a0 by Brooks Davis:

  time() is declared in time.h

This fixes a -Werror warning from clang 15:

  tests/sys/cddl/zfs/bin/readmmap.c:97:9: error: call to undeclared function 'time'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]

Obtained from: https://github.com/CTSRD-CHERI/cheribsd/commit/1737d8397a0
MFC after: 3 days

(cherry picked from commit 47be48457393ba6747cc3144272b1f4d8b9077fb)

23 months agoqat(4): Fix a typo in a source code comment
Gordon Bergling [Sat, 16 Jul 2022 11:47:14 +0000 (13:47 +0200)]
qat(4): Fix a typo in a source code comment

- s/bufer/buffer/

Obtained from: NetBSD

(cherry picked from commit e4a203234add5c57e5081521a4f4018bae7e398d)

23 months agopfctl(8): Fix a typo in a source code comment
Gordon Bergling [Sat, 16 Jul 2022 11:48:30 +0000 (13:48 +0200)]
pfctl(8): Fix a typo in a source code comment

- s/bufer/buffer/

(cherry picked from commit c9856c4ffbda670f3fdc03d4c046a70e3e225f68)

23 months agoqat(4): Fix a typo in a source code comment
Gordon Bergling [Sat, 16 Jul 2022 12:26:24 +0000 (14:26 +0200)]
qat(4): Fix a typo in a source code comment

- s/mirco/micro/

Obtained from: NetBSD

(cherry picked from commit db1c3dbe82953edda57f85f2e6d65ded272e5b0d)

23 months agocrunchide(1): Fix a typo in a comment
Gordon Bergling [Sat, 16 Jul 2022 11:32:47 +0000 (13:32 +0200)]
crunchide(1): Fix a typo in a comment

- s/maek/make/

Obtained from: NetBSD

(cherry picked from commit d34de8d378b36c48b3ae46a0abf8d8eb041877ad)

23 months agolinux(4): Fix a typo in a source code comment
Gordon Bergling [Sat, 16 Jul 2022 11:39:17 +0000 (13:39 +0200)]
linux(4): Fix a typo in a source code comment

- s/alredy/already/

(cherry picked from commit d3d3b76c1b614b54d255e4248c45f43b20d519b8)

23 months agocxgbe(4): Fix a typo in a source code comment
Gordon Bergling [Sat, 16 Jul 2022 11:38:57 +0000 (13:38 +0200)]
cxgbe(4): Fix a typo in a source code comment

- s/alredy/already/

(cherry picked from commit 63303133a7f9cd616eeea410a45fd0ae4eef70e6)

23 months agox86: Check for APIC presence only if DEV_ATPIC is defined
Mark Johnston [Tue, 28 Dec 2021 22:42:12 +0000 (17:42 -0500)]
x86: Check for APIC presence only if DEV_ATPIC is defined

We only attempt to gracefully handle absence of an APIC if "device
atpic" is defined in the kernel configuration.

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

(cherry picked from commit deca0138dc659747c9edd4648690cdfdb01f58e8)

23 months agotimecounter: Load the currently selected tc once in tc_windup()
Mark Johnston [Fri, 29 Oct 2021 18:29:22 +0000 (14:29 -0400)]
timecounter: Load the currently selected tc once in tc_windup()

Reported by: Sebastian Huber <sebastian.huber@embedded-brains.de>
Reviewed by: kib
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 26f76aea2d276aacb69a1f9d78558d6107155aed)

23 months agoktls: Zero out TLS_GET_RECORD control messages
Mark Johnston [Thu, 20 Jan 2022 20:42:46 +0000 (15:42 -0500)]
ktls: Zero out TLS_GET_RECORD control messages

Otherwise we end up copying one uninitialized byte into the socket
buffer.

Reported by: KMSAN
Reviewed by: jhb
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 6be8944d96d2cb5938b69c63b483efa616eafb56)

23 months agogeli: Add a chicken switch for unmapped I/O
Mark Johnston [Mon, 18 Apr 2022 21:16:10 +0000 (17:16 -0400)]
geli: Add a chicken switch for unmapped I/O

We have a report of a panic in GELI that appears to go away when
unmapped I/O is disabled.  Add a tunable to make such investigations
easier in the future.  No functional change intended.

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

(cherry picked from commit 081b4452a758dd81dcdc68ffb6f7bad901d53e3d)

23 months agorc: Fix quoting in the zpoolreguid script
Mark Johnston [Tue, 31 May 2022 14:51:28 +0000 (10:51 -0400)]
rc: Fix quoting in the zpoolreguid script

Reported by: 0mp
Fixes: 227caacc918a ("rc: Add a zpoolreguid rc.d script")
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 89e58b955cf5d2187af5f2460d11b64f4d229c8a)

23 months agorc: Add a zpoolreguid rc.d script
Mark Johnston [Mon, 30 May 2022 14:43:44 +0000 (10:43 -0400)]
rc: Add a zpoolreguid rc.d script

If one boots up multiple copies of a template VM image containing a
zpool, the pool GUIDs will be identical, making it impossible to, e.g.,
share datasets between them.

This diff introduces a simple workaround for the problem: one can use
the script to, upon first boot, assign a new GUID to one or more zpools.
This will be useful when building ZFS-based VM images from release(7).

Reviewed by: mav, allanjude, asomers
Reviewed by: Pau Amma (docs)
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 227caacc918a8c9b32608cff42116e7d890b9ddc)

23 months agovm_object: Assert that overcommit charge is released in the object dtor
Mark Johnston [Tue, 12 Jul 2022 12:53:05 +0000 (08:53 -0400)]
vm_object: Assert that overcommit charge is released in the object dtor

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

(cherry picked from commit e1979b45b63725972d394562f95d89f8cc9a0bb4)

23 months agovm_map: Simplify a call to vm_object_allocate_anon()
Mark Johnston [Tue, 12 Jul 2022 12:53:17 +0000 (08:53 -0400)]
vm_map: Simplify a call to vm_object_allocate_anon()

vm_object_allocate_anon() automatically sets "charge" to 0 if no cred
reference is provided, so the caller doesn't need any conditional logic.

No functional change intended.

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

(cherry picked from commit 70b2996120a7f96527ce5c676f938886e8aa292d)

23 months agoRevert "bsdinstall: add knob to set ASLR sysctls"
Marcin Wojtas [Fri, 12 Nov 2021 19:32:57 +0000 (20:32 +0100)]
Revert "bsdinstall: add knob to set ASLR sysctls"

This reverts commit 020f4112559ebf7e94665c9a69f89d21929ce82a.

Because now ASLR is enabled by default for 64-bit architectures
and the purpose of the installation menu is to allow choosing
additional 'mitigation'/'hardening' options that are originally
disabled, remove the ASLR knob from bsdinstall.

Discussed with: emaste
Obtained from: Semihalf
Sponsored by: Stormshield

(cherry picked from commit bf410c6eda515364db5f6ed74b765efdec0595ae)

23 months agoEnable ASLR by default for 64-bit executables
Marcin Wojtas [Sun, 24 Oct 2021 14:53:06 +0000 (16:53 +0200)]
Enable ASLR by default for 64-bit executables

Address Space Layout Randomization (ASLR) is an exploit mitigation
technique implemented in the majority of modern operating systems.
It involves randomly positioning the base address of an executable
and the position of libraries, heap, and stack, in a process's address
space. Although over the years ASLR proved to not guarantee full OS
security on its own, this mechanism can make exploitation more difficult.

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

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

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

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

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

Co-developed by: Dawid Gorecki <dgr@semihalf.com>
Reviewed by: emaste, kib
Obtained from: Semihalf
Sponsored by: Stormshield
MFC after: 1 month
Differential revision: https://reviews.freebsd.org/D27666

(cherry picked from commit b014e0f15bc73d80ef49b64fd1f8c29f469467cb)

23 months agostand/uboot: setup archsw before probing devices
Albert Jakiela [Tue, 28 Jun 2022 15:28:35 +0000 (17:28 +0200)]
stand/uboot: setup archsw before probing devices

In some cases ubldr would try to mount a disk device before
the archsw struct was filled with functions pointers.
This would result in a NULL pointer derefrence of the arch_getdev field.
Fix that filling the archsw functions earlier.
Note that this matches the EFI behavoiur.

Reviewed by: imp, mw
Sponsored by: Stormshield
Obtained from: Semihalf
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D35670

(cherry picked from commit 1323f0aa9cb0392d2946226bd76f14463e875a60)

23 months agolockstat: Fix construction of comparision predicates
Kornel Dulęba [Mon, 4 Jul 2022 06:48:52 +0000 (08:48 +0200)]
lockstat: Fix construction of comparision predicates

Passing "0x%p" to sprintf results in double "0x" being printed.
This causes a dtrace script compilation failure when "-d" flag
is specified.
Fix that by removing the extraneous "0x".

Reviewed by: markj
Approved by: mw(mentor)
Obtained from: Semihalf
Sponsored by: Alstom
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D35690

(cherry picked from commit 9dbacce2d48abf04b4d65d2994586e1ff44b08fb)

23 months agoe6000sw: Fix direct register write logic
Kornel Dulęba [Mon, 4 Jul 2022 06:53:41 +0000 (08:53 +0200)]
e6000sw: Fix direct register write logic

When accessing a register directly from etherswitchcfg one must specify
a register group(e.g. registers of portN) and the register offset within
the group. The latter is passed as the 5 least significant bits.
Extract the former by dividing the register address by 32, not by 5.

Approved by: mw(mentor)
Obtained from: Semihalf
Sponsored by: Stormshield
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D35672

(cherry picked from commit 66548259075788d2084e9da1c5df7b88f44c4b4d)

23 months agoigc: Change default duplex setting
Kornel Dulęba [Thu, 30 Jun 2022 11:57:58 +0000 (13:57 +0200)]
igc: Change default duplex setting

During media selection through ifconfig one might not specify
the duplex setting through the mediaopt flag.
In that case the igc driver would default to full-duplex.
The problem with this approach is that e1000(em/igb) driver
defaults to half-duplex.
Because of that if one connects both NICs and sets media to
e.g. 100baseTX on both of them no link will be found.
Fix that by matching igc behaviour with what e1000 does.

Reviewed by: grehan
Approved by: mw(mentor)
Obtained from: Semihalf
Sponsored by: Stormshield
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D35673

(cherry picked from commit 3b8d04f845b416d29a258658b8a48d1afb4a2e81)

23 months agoDecode the arm64 SVE ID register
Andrew Turner [Tue, 28 Jun 2022 11:44:49 +0000 (11:44 +0000)]
Decode the arm64 SVE ID register

The field values are only valid when the ID_AA64PFR0_EL1.SVE or
ID_AA64PFR1_EL1.SME vields are non-zero. When this is not the case
the register is reserved as zero so is safe to read, but the SVEver
field will be incorrect so only print the decoded register when
the SVE or SME fields indicate it is valid.

Sponsored by: The FreeBSD Foundation

(cherry picked from commit cb91f112a3dc6cb68fe618623f59cee576ce4d14)

23 months agoAllow use of the arm64 unnamed register form
Andrew Turner [Wed, 29 Jun 2022 16:34:41 +0000 (17:34 +0100)]
Allow use of the arm64 unnamed register form

On arm64 all registers have a name that encodes op0, op1, CRn, CRm, and
op2 that are used to encode the register in the instruction. As some
registers we need to access may not be supportedby older compilers, or
are only supported when specific extensions are enabled support this
alternative form.

Sponsored by: The FreeBSD Foundation

(cherry picked from commit 66ba742d2e6c950611fa3d557512133b0216daa7)

23 months agoSplit out vfp_new_thread
Andrew Turner [Fri, 24 Jun 2022 11:53:15 +0000 (11:53 +0000)]
Split out vfp_new_thread

To keep the vfp thread creation code in one place move into vfp.c. This
will also help with adding SVE support as it depends on VFP.

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

(cherry picked from commit baf8f20a4af43283a1fbee49b0c2ad906074f20f)

23 months agoAdd the SVE reigster definitions
Andrew Turner [Fri, 24 Jun 2022 11:51:26 +0000 (11:51 +0000)]
Add the SVE reigster definitions

Sponsored by: The FreeBSD Foundation

(cherry picked from commit 2f317e7312971812bde8b8b0d9da21a2c1d378a3)

23 months agoTrap SVE instructions until we have SVE support
Andrew Turner [Fri, 24 Jun 2022 11:50:28 +0000 (11:50 +0000)]
Trap SVE instructions until we have SVE support

When running on hardware that supports SVE send the correct signal when
an SVE instruction is run.

Sponsored by: The FreeBSD Foundation

(cherry picked from commit ffa5bf8b600a77838be8fbf383382a2e7bafedc6)

23 months agoAdd the arm64 FPAC exception value
Andrew Turner [Mon, 4 Jul 2022 08:30:49 +0000 (09:30 +0100)]
Add the arm64 FPAC exception value

This is currently unused, but is useful to reduce conflicts when MFCing
patches from main.

Extracted from 85b7c566f15 ("Add arm64 pointer authentication support").

Sponsored by: The FreeBSD Foundation

23 months agoRemove PAGE_SIZE from the kcov tests
Andrew Turner [Wed, 20 Apr 2022 17:33:00 +0000 (17:33 +0000)]
Remove PAGE_SIZE from the kcov tests

To allow for a dynamic page size on arm64 remove the static valud from
the kcov tests

Sponsored by: The FreeBSD Foundation

(cherry picked from commit 2ff6e4ee9762526ed1e924da838a760423271978)

23 months agoRemove PAGE_SIZE from hastd
Andrew Turner [Tue, 3 May 2022 13:59:33 +0000 (14:59 +0100)]
Remove PAGE_SIZE from hastd

It may not be known at compile time so we should detect it at run time.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D35118

(cherry picked from commit ea578b34cb35505e7253c4d8f279fed1d38380ee)

23 months agoClean up in the pci host generic driver
Andrew Turner [Mon, 23 May 2022 09:41:36 +0000 (10:41 +0100)]
Clean up in the pci host generic driver

Add clean up on failure and a detach function to the pci host generic
driver.

Reviewed by: jhb (earlier version)
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D35291

(cherry picked from commit d843dd0e1addd2aa69a78be99e251147aafcfd80)

23 months agoAdd arm64 CnP support
Andrew Turner [Wed, 25 May 2022 09:55:40 +0000 (10:55 +0100)]
Add arm64 CnP support

Set the Common not Private bit in the ttbr registers when supported on
arm64. This tells the hardware it can share the translation table
entries on multiple CPUs.

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

(cherry picked from commit 9e0716f4610158936c0b9cec1a9930c4ebe924fb)

23 months agoDecode all Arm GIC feature ID bits
Andrew Turner [Tue, 24 May 2022 10:03:13 +0000 (11:03 +0100)]
Decode all Arm GIC feature ID bits

The AWS Graviton3 CPU features a GIC 4.1 CPU Interface. Teach the CPU
identift code to decode it.

Sponsored by: The FreeBSD Foundation

(cherry picked from commit 477204e70b658c518064a02203a2050d5a0841be)

23 months agoAdd more Arm CPU IDs
Andrew Turner [Tue, 24 May 2022 10:01:15 +0000 (11:01 +0100)]
Add more Arm CPU IDs

Add more CPU main ID register values for Arm Cortex and Neoverse CPUs

Sponsored by: The FreeBSD Foundation

(cherry picked from commit 969da7c749ebf05a2a9b10e32b5d6d7c3f270dbb)

23 months agoAdd SPLIT_KERNEL_DEBUG knob
Ed Maste [Tue, 7 Jun 2022 14:20:39 +0000 (10:20 -0400)]
Add SPLIT_KERNEL_DEBUG knob

Prior to 9b6edf364eb0 WITHOUT_KERNEL_SYMBOLS split kernel debug data
into standalone debug files at build time, but did not install those
files.  As of 9b6edf364eb0 it stopped splitting the debug data, leaving
it in the kernel and modules (the default kernel configs include
DEBUG=-g).

Revert 9b6edf364eb0 and introduce a new build-time SPLIT_KERNEL_DEBUG
knob, as some people rely on the pre-9b6edf364eb0 WITHOUT_KERNEL_SYMBOLS
behaviour and that was imp's original intent.

PR: 264433
Reviewed by: eugen, imp
MFC after: 3 weeks
Relnotes: yes
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D35437

(cherry picked from commit 92fc5822a8301d0c20d292e97d1661b25f5035bc)
(cherry picked from commit e3709cfe6a2a1f7d345db2870be175c9cf2a8979)
(cherry picked from commit a7bd57de86372d834cf9312fcc4c39070653e009)

23 months agoeventtimer: Pass a pcpu state pointer to getnext(cpu)event()
Mark Johnston [Mon, 11 Jul 2022 19:38:43 +0000 (15:38 -0400)]
eventtimer: Pass a pcpu state pointer to getnext(cpu)event()

Callers have already loaded the pointer, so these functions don't need
to fetch it again.

No functional change intended.

Sponsored by: The FreeBSD Foundation

(cherry picked from commit ebb3cb61958da8bcc3c28ec3b20dc3a6b8168952)

23 months agosched_ule: Fix a typo in a comment
Mark Johnston [Mon, 11 Jul 2022 19:33:20 +0000 (15:33 -0400)]
sched_ule: Fix a typo in a comment

PR: 226107

(cherry picked from commit ba71333f6049ee76b0023b3b9e8444d5ccb1a7ff)

23 months agosched_ule: Eliminate a superfluous local variable in tdq_move()
Mark Johnston [Mon, 4 Jul 2022 23:05:59 +0000 (19:05 -0400)]
sched_ule: Eliminate a superfluous local variable in tdq_move()

No functional change intended.

Sponsored by: The FreeBSD Foundation

(cherry picked from commit 35dd6d6cb56209b49c055253dac549d8426f1003)

23 months agosched_ule: Purge an obsolete comment
Mark Johnston [Mon, 4 Jul 2022 23:07:51 +0000 (19:07 -0400)]
sched_ule: Purge an obsolete comment

The referenced bitmask was removed in commit 62fa74d95a1.

Sponsored by: The FreeBSD Foundation

(cherry picked from commit ef80894c9d01b13f6507abd6e5a0508dbb64d73b)

23 months agolibvmm: add __BEGIN_DECLS/__END_DECLS for linking with c++ binaries
Vitaliy Gusev [Mon, 11 Jul 2022 19:25:43 +0000 (15:25 -0400)]
libvmm: add __BEGIN_DECLS/__END_DECLS for linking with c++ binaries

Reviewed by: jhb, markj, imp
Sponsored by: vStack

(cherry picked from commit 1228a047aa653e7e9067bdcff4a9a62657df2c15)

23 months agodwc3: add ACPI attachment
Bjoern A. Zeeb [Tue, 5 Jul 2022 01:07:07 +0000 (01:07 +0000)]
dwc3: add ACPI attachment

Split the current FDT-only implementation up into an FDT and an
ACPI part reusing and sharing as much code as possible (thanks mw!).

This makes the Synopsis XHCI root hubs attach correctly on SolidRun's
HoenyComb instead of just the generic XHCI root and this means we
are also doing proper chip setup and applying the quirk needed there [1].

There is one problem with ACPI attachment in that it uses the generic
XHCI PNP ID.  So we need to do extra checks in order to not claim
all xhci, which means we check for a known quirk to be present
in acpi_probe.  Long term this isn't scaling and this was discussed
in SolidRun's Discord Channel in 2021 with the intend that "jnettlet"
will take this to a steering committee.  Since then ACPI has kind-of
become a technology non grata (due to not getting changes into Linux
timely) so it is unclear if this will ever happen.  If there will be
further hardware with dwc3/ACPI we should go and make sure this problem
gets solved.

[1] https://github.com/SolidRun/edk2-platforms/blob/24698f90b79facfbbfc4067b39a4ddf8c7fdfa88/Silicon/NXP/LX2160A/AcpiTables/Dsdt/Usb.asl

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

(cherry picked from commit fbb5cb66f74cd9e7c2b1491dee6f5a3df72aea7a)

23 months agodwc3: improve debugging
Bjoern A. Zeeb [Sat, 2 Jul 2022 21:10:00 +0000 (21:10 +0000)]
dwc3: improve debugging

Rather than hiding behind #if 0, hide the debugging behind DWC3_DEBUG
so it can be turned on with a single define.  Require bootverbose
to print anything so we can still avoid spamming the console if DWC3_DEBUG
is on.
Harmonize the format string in snsp_dwc3_dump_regs() to always print the
full register and also print the XHCI quirks.
Call snsp_dwc3_dump_regs() twice, before and after generic XHCI attachment
and initialisation as this may have an effect on the confirgumation state.

Obtained from: an old debug patch
Reviewed by: mw
Differential Revision: https://reviews.freebsd.org/D35700

(cherry picked from commit 11a7d5e5d906f691558e06d4bb93b892de31b446)

23 months agodwc3: add more quirks and checks
Bjoern A. Zeeb [Sat, 2 Jul 2022 20:56:07 +0000 (20:56 +0000)]
dwc3: add more quirks and checks

Rather than just printing the Global SNPS ID Register store it as well
so we can do a version check later.
In addition, for debugging purposes, read the Global Hardware Parameters
Registers and print them.

Based on the snpsid disable an XHCI feature using a quirk prepared
in 447c418da03454a2a00bc115a69c62055a6d5272.
Add the "snps,dis_u3_susphy_quirk" quirk and handle Suspend USB3.0 SS PHY
after power-on-reset/during core initialization (suggested to be cleared)
based on the DWC3_GHWPARAMS0 register.

Obtained from: an old debugging patch
Reviewed by: mw (earlier version), mmel
Differential Revision: https://reviews.freebsd.org/D35699

(cherry picked from commit 09cdf4878c621be4cd229fa88cdccdcdc8c101f7)
(cherry picked from commit ec32fc2af52530e49d8a522ae29bf20b2e57603b)

23 months agodwc3: uncondinationally enable Host IN Auto Retry
Bjoern A. Zeeb [Sat, 2 Jul 2022 19:14:39 +0000 (19:14 +0000)]
dwc3: uncondinationally enable Host IN Auto Retry

Enable dwc3's auto retry feature. For IN transfers with crc errors
or internal overruns this will make the host reply with a
non-terminating retry ACK.  I believe the hope was to improve
reliability after seeing occasional hiccups.

Obtained from: an old debugging patch
Reviewed by: mw
Differential Revision: https://reviews.freebsd.org/D35698

(cherry picked from commit cec0a5ec6b1074d253a7ba30226d1f99e0c18d4e)

23 months agodwc3: fix snps,dis-del-phy-power-chg-quirk
Bjoern A. Zeeb [Sat, 2 Jul 2022 18:17:13 +0000 (18:17 +0000)]
dwc3: fix snps,dis-del-phy-power-chg-quirk

If snps,dis-del-phy-power-chg-quirk is set, the register bit should be
cleared not ored on (it's the "dis" version).

Reviewed by: mw
Differential Revision: https://reviews.freebsd.org/D35697

(cherry picked from commit 0084212bfdfbcd662f3e823636b40173e828509d)

23 months agoUSB: dwc3: use device_{has,get}_property()
Bjoern A. Zeeb [Mon, 29 Nov 2021 19:26:52 +0000 (19:26 +0000)]
USB: dwc3: use device_{has,get}_property()

Switch the driver to use device based functions which will work not
only with FDT but also ACPI.

While here make dr_mode a local variable as it is only used during
probe and not needed later in the softc.

Reviewed by: mw
Differential Revision: https://reviews.freebsd.org/D33170

(cherry picked from commit b11f52f4db4420f69da537e5ed9b54b7c4fef093)

23 months agopca954x: harmonize pca9547 and pca954x and add pca9540 support
Bjoern A. Zeeb [Sat, 2 Jul 2022 23:33:32 +0000 (23:33 +0000)]
pca954x: harmonize pca9547 and pca954x and add pca9540 support

The two implementations for the pca9548 switch and the pca9547 mux
seemed close enough so we can put them together and with a bit more
abstraction add pca9540 support.

While here apply a bit of consistency in variable and driver naming and
use device_has_property instead of the FDT-only OF_ variant.

This disconnects pca9547 from the build but does not yet delete it.

Reviewed by: mmel (earlier version), avg
Sponsored by: Traverse Technologies (providing Ten64 HW for testing)
Differential Revision: https://reviews.freebsd.org/D35701

(cherry picked from commit 97dbd37753ae1bf9c4f6a23e46e21f0a9f408c82)

23 months agotca6416: add support for tca9539
Bjoern A. Zeeb [Sun, 3 Jul 2022 00:51:13 +0000 (00:51 +0000)]
tca6416: add support for tca9539

Programming-wise tca6416 and tca9539 seem identical so all we have to
do is add the extra ofw_compat_data line.

Reviewed by: mw
Sponsored by: Traverse Technologies (providing Ten64 HW for testing)
Differential Revision: https://reviews.freebsd.org/D35702

(cherry picked from commit c4b98101c5b1dc34d077f078d04d777df3cf9e38)

23 months agoarm64: NXP add LS1088a clockgen support
Bjoern A. Zeeb [Tue, 28 Jun 2022 00:02:17 +0000 (00:02 +0000)]
arm64: NXP add LS1088a clockgen support

Add a driver for NXP LS1088a clockgen support which passes
configuration information to QorIQ clockgen class.
The implementaiton started off as copy of ls1028 support and was
adjusted accordingly.

Reviewed by: dgr_semihalf.com (earlier), mmel
Sponsored by: Traverse Technologies (providing Ten64 HW for testing)
Differential Revision: https://reviews.freebsd.org/D35617

(cherry picked from commit 8154df37a55948aca8358ade68b659d1aa71b755)

23 months agoACPI: change arguments to internal acpi_find_dsd()
Bjoern A. Zeeb [Thu, 23 Jun 2022 00:17:14 +0000 (00:17 +0000)]
ACPI: change arguments to internal acpi_find_dsd()

acpi_find_dsd() is not a bus function and we only need the acpi_device (ad).
The only caller has already looked up the ad (from ivars) for us.
Directly pass the ad to acpi_find_dsd() instead of bus, dev and remove
the extra call to device_get_ivars(); the changed argument also means we
now call AcpiEvaluateObject directly on the handle.

This optimisation was done a while ago while debugging a driver which
ended up with a bad bus, dev combination making the old version fail.

Reviewed by: mw
Differential Revision: https://reviews.freebsd.org/D35558

(cherry picked from commit 945eaca155fc0d48da8d11fc41b8b00f17254d90)

23 months agofile: upgrade to 5.42.
Xin LI [Mon, 4 Jul 2022 00:07:28 +0000 (17:07 -0700)]
file: upgrade to 5.42.

(cherry picked from commit a4d6d3b8910f3805eebcd8703e11e066aad2e2a1)

23 months agolibmagic: Remove support for older FreeBSD where xlocale was not available.
Xin LI [Mon, 3 Jan 2022 02:05:08 +0000 (18:05 -0800)]
libmagic: Remove support for older FreeBSD where xlocale was not available.

The MINIMUM_SUPPORTED_OSREL is 1002501 (FreeBSD 10.3), and xlocale is
supported there.

While I'm there, explicitly use config.h generated with --disable-bzlib
--disable-xzlib instead of deleting them manually.

(cherry picked from commit 90266521018938b7b9f0003ba9a383b6920859e9)

file: Turns out we need xlocal.h protection

It turns out that we still need xlocal.h protection for when we're
cross building on Linux. Linux doesn't have this file, but os/x
does. Before, we'd assume we didn't have it, like old FreeBSD, when
cross compiling. After the latest update, all that code was removed so
cross compiling needs to be handled separaetly. Do so by defining
HAVE_XLOCALE_H only when we're not building on linux. This allows us
to build the mkmagic build tool needed to build file(1).

Sponsored by: Netflix
Reviewed by: jrtc27
Differential Revision: https://reviews.freebsd.org/D33741

(cherry picked from commit f3d7ace4b235422e5ccff0315f2965ac935241d8)

23 months agomount_nfs.8: Update BUGS section for NFSv4.1/4.2
Rick Macklem [Sun, 3 Jul 2022 20:37:23 +0000 (13:37 -0700)]
mount_nfs.8: Update BUGS section for NFSv4.1/4.2

If the "intr" and/or "soft" mount options are used for
NFSv4 mounts, the protocol can be broken when the
operation returns without waiting for the RPC reply.
The likelyhood of failure increases for NFSv4.1/4.2
mounts, since the session slot will be broken when
an RPC reply is not processed.

This is mentioned in the BUGS section of "man mount_nfs",
but there was no specific mention of the session slot
problem.  This patch adds a sentence for this case.

PR: 260011

(cherry picked from commit aba7a81ab71ebef1bb20404634bc3c58ba615310)

23 months agoBootstrap crunchgen after removing -dc from linker invocation
Dimitry Andric [Thu, 14 Jul 2022 21:13:41 +0000 (23:13 +0200)]
Bootstrap crunchgen after removing -dc from linker invocation

In ec81497cc726 crunchgen was updated to remove -dc from the linker
invocations in its generated makefile output, as this flag is no longer
necessary, and is going to be an error with lld 15.

Update the BOOTSTRAPPING conditions for copying the crunchgen binary
from the host, or actually bootstrapping it when necessary. Since
ec81497cc726 did not bump __FreeBSD_version, I have chosen the nearest
values.

Fixes: ec81497cc726
MFC after: 3 days

(cherry picked from commit 93f5ab129a3d46f4f434a13306fc99f476456c00)

23 months agoRevert "build(7): fix references to svn(1) and svnlite(1)"
Ed Maste [Sun, 17 Jul 2022 17:57:24 +0000 (13:57 -0400)]
Revert "build(7): fix references to svn(1) and svnlite(1)"

This reverts commit 830d566254d3f4e5204f849cb2d2c70d9afffb8f.
The content change was already cherry-picked, and 830d566254d3 served
only to introduce a typo.

Reported by: mhorne

23 months agocrypto: Validate return values from CRYPTODEV_PROCESS()
Mark Johnston [Fri, 1 Jul 2022 15:09:39 +0000 (11:09 -0400)]
crypto: Validate return values from CRYPTODEV_PROCESS()

Errors are always handled by the completion callback, so we should check
that they're not also passed back to the caller.

No functional change intended.

Reviewed by: kp, mav, jhb
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 99df914899f56efe63afd9e0fef79148fa6ca162)

23 months agoloader: Relax the check in is_kernphys_relocatable()
Mark Johnston [Wed, 15 Jun 2022 14:47:13 +0000 (10:47 -0400)]
loader: Relax the check in is_kernphys_relocatable()

The check fails in kernels compiled with KASAN because AddressSanitizer
inserts redzones around global variables, so the size of the "kernphys"
symbol is 32 rather than 8.  Thus we fall back to copying even though
it's not necessary.

Simply remove the size check.  I didn't want to extend the symbol size
check since there's no guarantee that AddressSanitizer will always emit
32 bytes for "kernphys".

Reviewed by: kib
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 9a964ad56182740ea09b87f7e6db4197c6756e48)

23 months agomsun: Rewrite function definitions with identifier lists
Yi Kong [Tue, 12 Jul 2022 05:17:47 +0000 (13:17 +0800)]
msun: Rewrite function definitions with identifier lists

This syntax is removed in C2x proposal N2432.

Reviewed by: pfg
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D35771

(cherry picked from commit 7e06f4708cbe8a8ace21d6629cb4b9c8c9340152)

23 months agomount_nfs: Warn that intr, soft are not safe for NFSv4
Rick Macklem [Fri, 1 Jul 2022 21:43:17 +0000 (14:43 -0700)]
mount_nfs: Warn that intr, soft are not safe for NFSv4

If the "intr" and/or "soft" mount options are used for
NFSv4 mounts, the protocol can be broken when the
operation returns without waiting for the RPC reply.
The likelyhood of failure increases for NFSv4.1/4.2
mounts, since the session slot will be broken when
an RPC reply is not processed.

This is mentioned in the BUGS section of "man mount_nfs",
but more needs to be done.  This patch adds code that
generates a warning message when the mount is done.

PR: 260011
(cherry picked from commit c0d14b0220ae22d25462cef191f20e9f04c5e87e)

23 months agoipfilter: Support only jails in VNET
Cy Schubert [Thu, 17 Mar 2022 18:05:05 +0000 (11:05 -0700)]
ipfilter: Support only jails in VNET

Jails without VNET have complete access to the ipfilter rules, NAT,
pools and logs. This is insecure. Only allow jails to manipulate
ipfilter rules, NAT tables and ippools if the jail has its own VNET.
Otherwise a jail can affect the global system.

This patch brings ipfilter in line with ipfw's support of VNET jails and
non-support of non-VNET jails.

(cherry picked from commit c47db49ba4aa7e74afe22591a62fbda95317932d)

23 months agopipe: Use a distinct wait channel for I/O serialization
Mark Johnston [Tue, 14 Jun 2022 14:52:03 +0000 (10:52 -0400)]
pipe: Use a distinct wait channel for I/O serialization

Suppose a thread tries to read from an empty pipe.  pipe_read() does the
following:

1. pipelock(), possibly sleeping
2. check for buffered data
3. pipeunlock()
4. set PIPE_WANTR and sleep
5. goto 1

pipelock() is an open-coded mutex; if a thread blocks in pipelock(), it
sleeps until the lock holder calls pipeunlock().

Both sleeps use the same wait channel.  So if there are multiple threads
in pipe_read(), a thread T1 in step 3 can wake up a thread T2 sleeping
in step 4.  Then T1 goes to sleep in step 4, and T2 acquires and
releases the pipelock, waking up T1 again.  This can go on indefinitely,
livelocking the process (and potentially starving a would-be writer).

Fix the problem by using a separate wait channel for pipelock().

Reported by: Paul Floyd <paulf2718@gmail.com>
Reviewed by: mjg, kib
PR: 264441
Sponsored by: The FreeBSD Foundation

(cherry picked from commit e8955bd643ee852d70a0b065f2a0d1bb3fa99df2)

23 months agopf: Make sure that pfi_update_status() always zeros counters
Mark Johnston [Thu, 30 Jun 2022 14:19:23 +0000 (10:19 -0400)]
pf: Make sure that pfi_update_status() always zeros counters

pfi_update_status() can return early if the status interface doesn't
exist.  But in this case pf_getstatus() was copying uninitialized stack
memory into the output nvlist.

Reported by: Jenkins (KMSAN job)
Reviewed by: kp
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 333670372ffe2f1c562e1088a7779eb709006ba2)

23 months agopf: Ensure that pfiio_name is always nul terminated
Mark Johnston [Thu, 30 Jun 2022 14:18:50 +0000 (10:18 -0400)]
pf: Ensure that pfiio_name is always nul terminated

Reported by: syzkaller
Reviewed by: kp
Sponsored by: The FreeBSD Foundation

(cherry picked from commit bc83b3592241a6bcb18e1537fcd27a8eb342a701)

23 months agoipfw: add support radix tables and table lookup for MAC addresses
Arseny Smalyuk [Sat, 4 Jun 2022 16:12:29 +0000 (19:12 +0300)]
ipfw: add support radix tables and table lookup for MAC addresses

By analogy with IP address matching, add a way to use ipfw radix
tables for MAC matching. This is implemented using new ipfw table
with mac:radix type. Also there are src-mac and dst-mac lookup
commands added.

Usage example:
  ipfw table 1 create type mac
  ipfw table 1 add 11:22:33:44:55:66/48
  ipfw add skipto tablearg src-mac 'table(1)'
  ipfw add deny src-mac 'table(1, 100)'
  ipfw add deny lookup dst-mac 1

Note: sysctl net.link.ether.ipfw=1 should be set to enable ipfw
filtering on L2.

Reviewed by: melifaro
Obtained from: Yandex LLC
Relnotes: yes
Sponsored by: Yandex LLC
Differential Revision: https://reviews.freebsd.org/D35103

(cherry picked from commit 81cac3906eb9c14f81e03b7bcb6893b8d30e5432)

23 months agoBump __FreeBSD_version for new <crypto/*.h> headers.
John Baldwin [Tue, 18 Jan 2022 22:49:24 +0000 (14:49 -0800)]
Bump __FreeBSD_version for new <crypto/*.h> headers.

This bump covers the addition of both <crypto/chacha20_poly1305.h> and
<crypto/curve25519.h>.

Sponsored by: The FreeBSD Foundation

(cherry picked from commit dd2f7a4b45eb1285e710cfce60cb77f7c11f8075)
(cherry picked from commit 2c4b65cc3d227f31864e183c15f6c42e2c596cd9)

23 months agocrypto: Add an API supporting curve25519.
John Baldwin [Mon, 24 Jan 2022 23:27:39 +0000 (15:27 -0800)]
crypto: Add an API supporting curve25519.

This adds a wrapper around libsodium's curve25519 support matching
Linux's curve25519 API.  The intended use case for this is WireGuard.

Note that this is not integrated with OCF as it is not related to
symmetric operations on data.

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

(cherry picked from commit 0c6274a819ffdf6d5a3713b2c0f7014840f01703)

23 months agocrypto: Add a simple API for [X]ChaCha20-Poly1035 on flat buffers.
John Baldwin [Tue, 18 Jan 2022 22:47:13 +0000 (14:47 -0800)]
crypto: Add a simple API for [X]ChaCha20-Poly1035 on flat buffers.

This is a synchronous software API which wraps the existing software
implementation in libsodium.  This is different from the code in main
in that this uses libsodium directly.  The version in main uses the
software backend shared with OCF, but main required changes that break
the ABI of struct enc_xform that cannot be merged to stable/13.

Sponsored by: The FreeBSD Foundation

(cherry picked from commit e71680049bb8ff395aeaa144377dd9e49331f45e)

23 months agocrypto.ko: Add hchacha20 from libsodium.
John Baldwin [Tue, 11 Jan 2022 22:15:51 +0000 (14:15 -0800)]
crypto.ko: Add hchacha20 from libsodium.

This was added to 'device crypto' in the kernel in
bbb7a2c7c329494e0148026f8568c0da4d8db085 but was missing from the
module.

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

(cherry picked from commit 7df4c50643cfeecdd42b8e55c38709bf84b1b002)

23 months agousr.bin/dtc: Include <limits> for std::numeric_limits<>.
John Baldwin [Thu, 9 Jun 2022 17:20:03 +0000 (10:20 -0700)]
usr.bin/dtc: Include <limits> for std::numeric_limits<>.

This is needed when building natively as a cross-tool on hosts such as
Linux using more recent versions of libstdc++.

Co-authored-by: Alexander Richardson <arichardson@FreeBSD.org>
Obtained from: CheriBSD

(cherry picked from commit 1c44d2bf86834a7214e0cc7bde7c956b5b02fd21)

23 months ago.github: Add a build on Ubuntu 22.04 using llvm 14.
John Baldwin [Thu, 9 Jun 2022 17:20:03 +0000 (10:20 -0700)]
.github: Add a build on Ubuntu 22.04 using llvm 14.

Reviewed by: uqs
Pull Request: https://github.com/freebsd/freebsd-src/pull/599

(cherry picked from commit 74536fca79facf0e4fdbaf833b94d82e92bb9f77)

23 months ago.github: Cross-build aarch64 as well as amd64 kernels.
John Baldwin [Thu, 9 Jun 2022 17:20:03 +0000 (10:20 -0700)]
.github: Cross-build aarch64 as well as amd64 kernels.

This required adding an explicit os list to the matrix.

Reviewed by: uqs
Pull Request: https://github.com/freebsd/freebsd-src/pull/599

(cherry picked from commit 3491ed652e0af484b8357ba67e45af17a0e54173)

23 months ago.github: Update compilers used for cross-build testing.
John Baldwin [Thu, 9 Jun 2022 17:20:02 +0000 (10:20 -0700)]
.github: Update compilers used for cross-build testing.

- Drop clang 9 build, and switch the remaining ubuntu build to
  the more modern clang 12.

- Update the label for the macos-latest builds which are now using
  clang 13 rather than clang 12.

Reviewed by: uqs
Pull Request: https://github.com/freebsd/freebsd-src/pull/599

(cherry picked from commit 49335eda0f5d80e9c86754b5ed95a285b49ef166)

23 months agoMake it clear we're running clang-12 for the GH actions
Ulrich Spörlein [Mon, 19 Jul 2021 08:25:58 +0000 (10:25 +0200)]
Make it clear we're running clang-12 for the GH actions

This chases a homebrew change in the default clang version.

Reviewed by: arichardson
Differential Revision: https://reviews.freebsd.org/D31231

(cherry picked from commit 2f677dcedf3b70bf97a51c2b0fd9927b67c666ff)

23 months agorelease: increase IMAGE_SIZE for arm, arm64, riscv
Glen Barber [Wed, 13 Jul 2022 18:36:22 +0000 (14:36 -0400)]
release: increase IMAGE_SIZE for arm, arm64, riscv

Related to:  PR 264032
Sponsored by: Rubicon Communications, LLC ("Netgate")

(cherry picked from commit 1dfcff294e44d4b45813288ef4095c36abb22f0e)

23 months agoetcupdate: Preserve permissions when installing a resolved file.
John Baldwin [Wed, 25 May 2022 21:20:40 +0000 (14:20 -0700)]
etcupdate: Preserve permissions when installing a resolved file.

Similar to the change in 1a04446f088c79cc2cf85fd86e60ebcc228d3075, use
cat to overwrite the contents of the existing file rather than cp so
that metadata of the existing file such as permissions and ownership
is preserved.

PR: 255514
Reported by: uqs

(cherry picked from commit f8287caae48246e34d6a7af5446df3c36127b7f0)

23 months agoetcupdate: Don't rotate trees for a dry run.
John Baldwin [Wed, 25 May 2022 21:02:51 +0000 (14:02 -0700)]
etcupdate: Don't rotate trees for a dry run.

When performing a dry run, remove the temporary tree created rather
than rotating the trees.  Rotating the trees meant that etcupdate
thought the latest changes were already merged and would not merge
them on the next real run.

PR: 260281
Reported by: Tomoaki AOKI <junchoon@dec.sakura.ne.jp>
Fixes: 0611aec3cf3a etcupdate: Always extract to a temporary tree.

(cherry picked from commit 431944fb5ffff5ad56e720b75b7beecdc4878e0e)

23 months agocrypto: Fix assertions for digest-only sessions with separate output.
John Baldwin [Thu, 30 Jun 2022 17:10:00 +0000 (10:10 -0700)]
crypto: Fix assertions for digest-only sessions with separate output.

Digest-only sessions do not generate modified payload as an output, so
don't bother asserting anything about the payload with respect to the
output buffer other than the payload output start being zero.

In addition, a verify request on a digest-only session doesn't
generate any output at all so should never have a separate output
buffer.

PR: 252316
Reviewed by: markj
Co-authored-by: Jeremy Faulkner <gldisater@gmail.com>
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D35578

(cherry picked from commit c71f2370c5d480cf70f12ee276e044681c57aefc)

23 months agogcore: Use PT_GETREGSET for NT_THRMISC and NT_PTLWPINFO.
John Baldwin [Thu, 30 Jun 2022 17:04:19 +0000 (10:04 -0700)]
gcore: Use PT_GETREGSET for NT_THRMISC and NT_PTLWPINFO.

This avoids the need for dealing with converting lwpinfo for alternate
ABIs in gcore itself.

Reviewed by: markj
MFC after: 2 weeks
Sponsored by: DARPA
Differential Revision: https://reviews.freebsd.org/D35667

(cherry picked from commit d95657a1a758e8d993a0eb92259f8c860a309207)

23 months agoAdd register sets for NT_THRMISC and NT_PTLWPINFO.
John Baldwin [Thu, 30 Jun 2022 17:04:02 +0000 (10:04 -0700)]
Add register sets for NT_THRMISC and NT_PTLWPINFO.

For the kernel this is mostly a non-functional change.  However, this
will be useful for simplifying gcore(1).

Reviewed by: markj
MFC after: 2 weeks
Sponsored by: DARPA
Differential Revision: https://reviews.freebsd.org/D35666

(cherry picked from commit 0288d4277faf77c37d23efce73883eb3ef1a353c)

23 months agogcore: Remove unused typedefs.
John Baldwin [Thu, 30 Jun 2022 17:03:32 +0000 (10:03 -0700)]
gcore: Remove unused typedefs.

These are no longer needed after commit 4965ac059da1 which used
PT_GETREGSET to fetch NT_PRSTATUS and NT_FPREGSET.

Reviewed by: markj, emaste
MFC after: 2 weeks
Sponsored by: DARPA
Differential Revision: https://reviews.freebsd.org/D35665

(cherry picked from commit d2a3c30a511d4802412a102e9fa44f810605a872)