]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
3 years agovfs: Add get_write_ioflag helper to calculate ioflag
Ka Ho Ng [Thu, 12 Aug 2021 09:35:34 +0000 (17:35 +0800)]
vfs: Add get_write_ioflag helper to calculate ioflag

Converted vn_write to use this helper.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days
Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D31513

3 years agoloader: cstyle cleanup of userboot/devicename.c
Toomas Soome [Wed, 11 Aug 2021 07:07:28 +0000 (10:07 +0300)]
loader: cstyle cleanup of userboot/devicename.c

No functional changes intended.

MFC after: 1 week

3 years agolinux(4): Remove the unnecessary spaces.
Dmitry Chagin [Thu, 12 Aug 2021 08:58:33 +0000 (11:58 +0300)]
linux(4): Remove the unnecessary spaces.

MFC after: 2 weeks

3 years agofork: Remove the unnecessary spaces.
Dmitry Chagin [Thu, 12 Aug 2021 08:58:17 +0000 (11:58 +0300)]
fork: Remove the unnecessary spaces.

MFC after: 2 weeks

3 years agolinux(4): Move ff variable initialization from declaration.
Dmitry Chagin [Thu, 12 Aug 2021 08:57:16 +0000 (11:57 +0300)]
linux(4): Move ff variable initialization from declaration.

Modern style(9) allows variables initialization where they are declared,
but in this case initialization obfuscate the code.

MFC after: 2 weeks

3 years agolinux(4): Verify that higher 32bits of exit_signal in clone3 are unset.
Dmitry Chagin [Thu, 12 Aug 2021 08:56:51 +0000 (11:56 +0300)]
linux(4): Verify that higher 32bits of exit_signal in clone3 are unset.

MFC after: 2 weeks

3 years agolinux(4): Return ENOSYS for unsupported clone3 option bits.
Dmitry Chagin [Thu, 12 Aug 2021 08:56:36 +0000 (11:56 +0300)]
linux(4): Return ENOSYS for unsupported clone3 option bits.

Differential Revision: https://reviews.freebsd.org/D31483
MFC after: 2 weeks

3 years agolinux(4): Add LINUX_RATELIMIT_MSG macro for future use.
Dmitry Chagin [Thu, 12 Aug 2021 08:55:55 +0000 (11:55 +0300)]
linux(4): Add LINUX_RATELIMIT_MSG macro for future use.

Differential Revision: https://reviews.freebsd.org/D31488
MFC after: 2 weeks

3 years agolinux(4): Implement CLONE_CLEAR_SIGHAND option bit.
Dmitry Chagin [Thu, 12 Aug 2021 08:55:35 +0000 (11:55 +0300)]
linux(4): Implement CLONE_CLEAR_SIGHAND option bit.

CLONE_CLEAR_SIGHAND is designed to reset all signal handlers of the child
not set to SIG_IGN to SIG_DFL.

Reviewed by: kib
Differential revision: https://reviews.freebsd.org/D31481
MFC after: 2 weeks

3 years agolinux(4): Add CLONE_PIDFD option bit.
Dmitry Chagin [Thu, 12 Aug 2021 08:55:24 +0000 (11:55 +0300)]
linux(4): Add CLONE_PIDFD option bit.

Differential revision: https://reviews.freebsd.org/D31478
MFC after: 2 weeks

3 years agoEnable arm64 SError exceptions in the kernel
Andrew Turner [Mon, 9 Aug 2021 16:30:44 +0000 (16:30 +0000)]
Enable arm64 SError exceptions in the kernel

These are needed to signal to the kernel when a Reliability,
Availability, and Serviceability (RAS) exception has triggered.

Reviewed by: mhorne
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D31477

3 years agoAdd the Apple arm64 implementer ID
Andrew Turner [Wed, 11 Aug 2021 15:30:44 +0000 (16:30 +0100)]
Add the Apple arm64 implementer ID

Sponsored by: The FreeBSD Foundation

3 years agoSort the arm64 cpu_implementers list by name
Andrew Turner [Wed, 11 Aug 2021 15:29:09 +0000 (16:29 +0100)]
Sort the arm64 cpu_implementers list by name

We perform a linear search, so make it easier to add new entries in the
correct place.

Sponsored by: The FreeBSD Foundation

3 years agolinux(4): Regen for clone3 system call.
Dmitry Chagin [Thu, 12 Aug 2021 08:50:22 +0000 (11:50 +0300)]
linux(4): Regen for clone3 system call.

MFC after: 2 weeks

3 years agolinux(4): Implement clone3 system call.
Dmitry Chagin [Thu, 12 Aug 2021 08:49:36 +0000 (11:49 +0300)]
linux(4): Implement clone3 system call.

clone3 system call is used by glibc-2.34.

Differential revision: https://reviews.freebsd.org/D31475
MFC after: 2 weeks

3 years agolinux(4): Add struct clone_args for future clone3 system call.
Dmitry Chagin [Thu, 12 Aug 2021 08:49:01 +0000 (11:49 +0300)]
linux(4): Add struct clone_args for future clone3 system call.

In preparation for clone3 system call add struct clone_args and use it in
clone implementation.
Move all of clone related bits to the newly created linux_fork.h header.

Differential revision: https://reviews.freebsd.org/D31474
MFC after: 2 weeks

3 years agolinux(4): Regen for clone syscall.
Dmitry Chagin [Thu, 12 Aug 2021 08:47:31 +0000 (11:47 +0300)]
linux(4): Regen for clone syscall.

MFC after: 2 weeks

3 years agolinux(4): Change clone syscall definition to match Linux actual one.
Dmitry Chagin [Thu, 12 Aug 2021 08:46:36 +0000 (11:46 +0300)]
linux(4): Change clone syscall definition to match Linux actual one.

Differential revision: https://reviews.freebsd.org/D31473
MFC after: 2 weeks

3 years agofork: Allow ABI to specify fork return values for child.
Dmitry Chagin [Thu, 12 Aug 2021 08:45:25 +0000 (11:45 +0300)]
fork: Allow ABI to specify fork return values for child.

At least Linux x86 ABI's does not use carry bit and expects that the dx register
is preserved. For this add a new sv_set_fork_retval hook and call it from cpu_fork().

Add a short comment about touching dx in x86_set_fork_retval(), for more details
see phab comments from kib@ and imp@.

Reviewed by: kib
Differential revision: https://reviews.freebsd.org/D31472
MFC after: 2 weeks

3 years agolinux(4): Plug in aarch64 fcntl flags.
Dmitry Chagin [Thu, 12 Aug 2021 08:42:50 +0000 (11:42 +0300)]
linux(4): Plug in aarch64 fcntl flags.

Fixes opendir() libc function.

Differential Revision: https://reviews.freebsd.org/D31357
MFC after: 2 weeks

3 years agolinux(4): Regen for faccessat2 system call.
Dmitry Chagin [Thu, 12 Aug 2021 08:41:35 +0000 (11:41 +0300)]
linux(4): Regen for faccessat2 system call.

MFC after: 2 weeks

3 years agolinux(4): Implement faccessat2 system call.
Dmitry Chagin [Thu, 12 Aug 2021 08:40:42 +0000 (11:40 +0300)]
linux(4): Implement faccessat2 system call.

It's used by bash on arm64 with glibc-2.32.

Reviewed by: trasz
Differential Revision: https://reviews.freebsd.org/D31345
MFC after: 2 weeks

3 years agolinux(4): Fix futex copyrights.
Dmitry Chagin [Thu, 12 Aug 2021 08:36:24 +0000 (11:36 +0300)]
linux(4): Fix futex copyrights.

As no more NetBSD code in futexes exists replace NetBSD copyrights by
standard FreeBSD 2 clause license.
Add Roman Divacky's copyrights as an author of the robust futexes.

Differential revision: https://reviews.freebsd.org/D31347
MFC after: 2 weeks

3 years agovmm: Fix wrong assert in ivhd_dev_add_entry
Ka Ho Ng [Thu, 12 Aug 2021 07:54:40 +0000 (15:54 +0800)]
vmm: Fix wrong assert in ivhd_dev_add_entry

The correct condition is to check the number of ivhd entries fit into
the array.

Reported by: bz
Sponsored by: The FreeBSD Foundation
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D31514

3 years agoloader: fix multiboot loading on UEFI
Roger Pau Monné [Wed, 11 Aug 2021 14:55:10 +0000 (16:55 +0200)]
loader: fix multiboot loading on UEFI

The Xen kernel has no symbol tables, so calling lookup_symbol against
it triggers the following Divide by Zero fault:

Loading Xen kernel...
/boot/xen data=0x2809c8+0x149638 |
!!!! X64 Exception Type - 00(#DE - Divide Error)  CPU Apic ID - 00000000 !!!!

Fix lookup_symbol to prevent the #DE fault from happening if the
symbol table is not loaded and also fix loadfile_raw to mark multiboot
kernels as relocatable, since the only multiboot kernel supported is
Xen and was already unconditionally booted as relocatable.

Fixes: f75caed644a5 ('amd64 UEFI loader: stop copying staging area to 2M physical')
Reviewed by: imp, kib
Differential Revision: https://reviews.freebsd.org/D31507

3 years agoxen: use correct cache attributes for Xen specific memory regions
Roger Pau Monné [Fri, 9 Apr 2021 09:31:44 +0000 (11:31 +0200)]
xen: use correct cache attributes for Xen specific memory regions

bus_activate_resource maps memory regions as uncacheable on x86, which
is more strict than required for regions allocated using xenmem_alloc,
so don't rely on bus_activate_resource and instead map the region
using pmap_mapdev_attr and VM_MEMATTR_XEN as the cache attribute.

Sponsored by: Citrix Systems R&D

3 years agodumpon: fix build on some architectures
Eric van Gyzen [Thu, 12 Aug 2021 02:27:24 +0000 (21:27 -0500)]
dumpon: fix build on some architectures

Fix a -Wsign-compare issue on some architectures.

Fixes: 96f9bd46547d6dfbaf219ab449efacacb0dacccc
Pointy hat to: me
MFC after: 1 week
Sponsored by: Dell EMC Isilon

3 years agoUPDATING: Add an entry for commit 3ad1e1c1ce20
Rick Macklem [Thu, 12 Aug 2021 01:58:00 +0000 (18:58 -0700)]
UPDATING: Add an entry for commit 3ad1e1c1ce20

3 years agonfscl: Add a Lookup+Open RPC for NFSv4.1/4.2
Rick Macklem [Thu, 12 Aug 2021 01:49:26 +0000 (18:49 -0700)]
nfscl: Add a Lookup+Open RPC for NFSv4.1/4.2

This patch adds a Lookup+Open compound RPC to the NFSv4.1/4.2
NFS client, which can be used by nfs_lookup() so that a
subsequent Open RPC is not required.
It uses the cn_flags OPENREAD, OPENWRITE added by commit c18c74a87c15.
This reduced the number of RPCs by about 15% for a kernel
build over NFS.

For now, use of Lookup+Open is only done when the "oneopenown"
mount option is used.  It may be possible for Lookup+Open to
be used for non-oneopenown NFSv4.1/4.2 mounts, but that will
require extensive further testing to determine if it works.

While here, I've added the changes to the nfscommon module
that are needed to implement the Deallocate NFSv4.2 operation.
This avoids needing another cycle of changes to the internal
KAPI between the NFS modules.

This commit has changed the internal KAPI between the NFS
modules and, as such, all need to be rebuilt from sources.
I have not bumped __FreeBSD_version, since it was bumped a
few days ago.

3 years agopowerpc/pseries: Allow radix pmap in pseries for ISA 3.0
Justin Hibbits [Thu, 12 Aug 2021 00:03:27 +0000 (19:03 -0500)]
powerpc/pseries: Allow radix pmap in pseries for ISA 3.0

ISA 3.0 allows for nested radix translations with minimal to no
involvement of the hypervisor.  This should make pseries signficantly
faster on POWER9 pseries instances, as fewer hypercalls are needed to
manage pmap now.

MFC after: 2 weeks
Relnotes: yes

3 years agoar: diff reduction against ELF Tool Chain
Ed Maste [Wed, 4 Aug 2021 13:54:17 +0000 (09:54 -0400)]
ar: diff reduction against ELF Tool Chain

- Drop exit status from bsdar_errc.  ELF Tool Chain always returns
  EXIT_FAILURE in bsdar_errc.

- Remove ar_mode_* wrappers and call ar_read_archive / ar_write_archive
  directly.

Obtained from: ELF Tool Chain
Reviewed by: markj
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D31496

3 years agolibsecureboot: define SOPEN_MAX
Toomas Soome [Tue, 10 Aug 2021 19:46:40 +0000 (22:46 +0300)]
libsecureboot: define SOPEN_MAX

With commit 97cbd5e722389a575e820c4e03f38053308f08ea, the SOPEN_MAX
was removed from stand.h.

We would need better mechanism there.

3 years agoloader: open file list should be dynamic
Toomas Soome [Sat, 31 Jul 2021 08:09:48 +0000 (11:09 +0300)]
loader: open file list should be dynamic

Summary:
Open file list is currently created as statically allocated array (64 items).
Once this array is filled up, loader will not be able to operate with files.
In most cases, this mechanism is good enough, but the problem appears, when
we have many disks with zfs pool(s). In current loader implementation, all
discovered zfs pool configurations are kept in memory and disk devices open -
consuming the open file array. Rewrite the open file mechanism to use
dynamically allocated list.

Reviewed by: imp
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D31364

3 years agonetdump: send key before dump, in case dump fails
Eric van Gyzen [Fri, 6 Aug 2021 15:38:51 +0000 (10:38 -0500)]
netdump: send key before dump, in case dump fails

Previously, if an encrypted netdump failed, such as due to a timeout or
network failure, the key was not saved, so a partial dump was
completely useless.

Send the key first, so the partial dump can be decrypted, because even a
partial dump can be useful.

Reviewed by: bdrewery, markj
MFC after: 1 week
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D31453

3 years agodumpon: fix encrypted dumps after commit 372557d8c3d
Eric van Gyzen [Sat, 7 Aug 2021 08:59:02 +0000 (03:59 -0500)]
dumpon: fix encrypted dumps after commit 372557d8c3d

That commit moved key generation into a child process, including
a memory allocation referenced by a structure.  The child wrote
the structure to the parent over a pipe, but did not write the
referenced allocation.  The parent read the structure from the
child and used its pointer, which was bogus in the parent.

In the child, send both chunks of data to the parent.  In the
parent, make a corresponding allocation and read both chunks.

Fixes: 372557d8c3d37dd0c1d9be56513a436393963848
Reviewed by: bdrewery, markj
MFC after: 1 week
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D31452

3 years agovirtio: Add KMSAN hooks for network and block devices
Mark Johnston [Wed, 11 Aug 2021 20:23:25 +0000 (16:23 -0400)]
virtio: Add KMSAN hooks for network and block devices

This ensures that host-written data is marked as initialized.

Sponsored by: The FreeBSD Foundation

3 years agoether: Add a KMSAN check for transmitted frames
Mark Johnston [Wed, 11 Aug 2021 20:23:12 +0000 (16:23 -0400)]
ether: Add a KMSAN check for transmitted frames

This helps ensure that outbound packet data is initialized per KMSAN.

Sponsored by: The FreeBSD Foundation

3 years agogeom_disk: Add KMSAN checks
Mark Johnston [Wed, 11 Aug 2021 20:22:26 +0000 (16:22 -0400)]
geom_disk: Add KMSAN checks

- In g_disk_start(), verify that the data to be written is initialized
  according to KMSAN shadow state.
- In g_disk_done(), verify that the block driver updated shadow state as
  expected, so as to catch sources of false positives early.

Sponsored by: The FreeBSD Foundation

3 years agokmsan: Export kmsan_mark_mbuf() and kmsan_mark_bio()
Mark Johnston [Wed, 11 Aug 2021 20:22:21 +0000 (16:22 -0400)]
kmsan: Export kmsan_mark_mbuf() and kmsan_mark_bio()

Sponsored by: The FreeBSD Foundation

3 years agoktls: Init reset tag task for cloned sessions
Andrew Gallatin [Wed, 11 Aug 2021 18:06:43 +0000 (14:06 -0400)]
ktls: Init reset tag task for cloned sessions

When cloning a ktls session (which is needed when we need to
switch output NICs for a NIC TLS session), we need to also
init the reset task, like we do when creating a new tls session.

Reviewed by: jhb
Sponsored by: Netflix

3 years agokdb: Handle process enumeration before procinit()
Mitchell Horne [Wed, 11 Aug 2021 17:40:01 +0000 (14:40 -0300)]
kdb: Handle process enumeration before procinit()

Make kdb_thr_first() and kdb_thr_next() return sane values if the
allproc list and pidhashtbl haven't been initialized yet. This can
happen if the debugger is entered very early on, for example with the
'-d' boot flag.

This allows remote gdb to attach at such a time, and fixes some ddb
commands like 'show threads'.

Be explicit about the static initialization of these variables. This
part has no functional change.

Reviewed by: markj, imp (previous version)
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D31495

3 years agoar: remove invalid extra param in bsdar_warnc calls
Ed Maste [Wed, 11 Aug 2021 17:22:23 +0000 (13:22 -0400)]
ar: remove invalid extra param in bsdar_warnc calls

A number of warnings passed an exit status code to bsdar_warnc, but it
does not take exit status (as a warning, it does not exit).

MFC after: 1 week
Sponsored by: The FreeBSD Foundation

3 years agoRELNOTES: Add entries for KASAN and KMSAN
Mark Johnston [Wed, 11 Aug 2021 17:05:50 +0000 (13:05 -0400)]
RELNOTES: Add entries for KASAN and KMSAN

Sponsored by: The FreeBSD Foundation

3 years agoncurses: Apply a tputs() fix from patch 20210403
Mark Johnston [Wed, 11 Aug 2021 16:54:29 +0000 (12:54 -0400)]
ncurses: Apply a tputs() fix from patch 20210403

From the (substantially larger) upstream commit:
+ call delay_output_sp to handle BSD-style padding when tputs_sp is
  called, whether directly or internally, to ensure that the SCREEN
  pointer is passed correctly (reports by Henric Jungheim, Juraj
  Lutter).

This fixes bison segfaults observed when colourized output is enabled.
Thanks to jrtc27@ for identifying the upstream fix.

PR: 256731
MFC after: 3 days

3 years agostand: Add MK_PIE=no to defs.mk
Warner Losh [Wed, 11 Aug 2021 16:59:28 +0000 (10:59 -0600)]
stand: Add MK_PIE=no to defs.mk

There's no need to build both pie and non-pie .o's for stand. There's
some other build thing with MK_BEAR_SSL=yes and/or MK_LOADER_VERIEXEC=yes
that causes the pie build to fail that the 'ar' stage now. Since we don't
need the PIE stuff and the non-PIE stuff, disable PIE for the boot loader.

Reviewed by: emaste
Sponsored by: Netflix

3 years agoRead the arm64 midr register earlier
Andrew Turner [Wed, 11 Aug 2021 15:01:25 +0000 (16:01 +0100)]
Read the arm64 midr register earlier

We use the midr_el1 register to decode which CPU type we are booting
from. Read it on the secondary CPUs before waiting for the boot CPU
to release us as it will need to use it before the release.

Sponsored by: The FreeBSD Foundation

3 years agoUse arm64 sha256 intrinsics in libmd
Andrew Turner [Fri, 23 Jul 2021 09:14:03 +0000 (10:14 +0100)]
Use arm64 sha256 intrinsics in libmd

Summary:
When running on a CPU that supports the arm64 sha256 intrinsics use them
to improve perfromance of sha256 calculations.

With this changethe following improvement has been seen on an Apple M1
with FreeBS running under Parallels, with similar results on a
Neoverse-N1 r3p1.

x sha256.orig
+ sha256.arm64
+--------------------------------------------------------------------+
|++                                                               x x|
|+++                                                              xxx|
||A                                                               |A||
+--------------------------------------------------------------------+
    N           Min           Max        Median           Avg        Stddev
x   5          3.41           3.5          3.46         3.458   0.042661458
+   5          0.47          0.54           0.5         0.504   0.027018512
Difference at 95.0% confidence
        -2.954 +/- 0.0520768
        -85.4251% +/- 0.826831%
        (Student's t, pooled s = 0.0357071)

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

3 years agoOnly use byte register access in legacy virtio pci
Andrew Turner [Thu, 5 Aug 2021 14:36:07 +0000 (14:36 +0000)]
Only use byte register access in legacy virtio pci

Some simulators don't implement arbitrary sized memory access to the
virtio PCI registers. Follow Linux and use single byte accesses to read
and write to these registers.

Reviewed by: bryanv, emaste (previous version)
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D31424

3 years agovfs: Rename ioflg to ioflag in vn_deallocate
Ka Ho Ng [Wed, 11 Aug 2021 09:45:47 +0000 (17:45 +0800)]
vfs: Rename ioflg to ioflag in vn_deallocate

This includes a style fix around ioflag checking as well.

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

3 years agoAdd myself (diizzy) as ports committer
Daniel Engberg [Wed, 11 Aug 2021 07:56:40 +0000 (09:56 +0200)]
Add myself (diizzy) as ports committer

Section 7.1 in Committer's Guide

Reviewed by: tcberner
Approved by: tcberner
Differential Revision: <https://reviews.freebsd.org/D31479>

3 years agoiscontrol(8): Fix a typo in a struct
Gordon Bergling [Wed, 11 Aug 2021 07:55:08 +0000 (09:55 +0200)]
iscontrol(8): Fix a typo in a struct

- s/suport/support/

MFC after: 5 days

3 years agoipfw(8): Fix a typo in an error message
Gordon Bergling [Wed, 11 Aug 2021 07:53:01 +0000 (09:53 +0200)]
ipfw(8): Fix a typo in an error message

- s/suport/support/

MFC after: 5 days

3 years agoMark some sysctls as CTLFLAG_MPSAFE.
Alexander Motin [Wed, 11 Aug 2021 02:17:53 +0000 (22:17 -0400)]
Mark some sysctls as CTLFLAG_MPSAFE.

MFC after: 2 weeks

3 years agock: Correct asm output operand widths in amd64 pointer intrinsics
Mark Johnston [Tue, 10 Aug 2021 21:23:49 +0000 (17:23 -0400)]
ck: Correct asm output operand widths in amd64 pointer intrinsics

This does not appear to change generated code with the default
toolchain.  However, KMSAN makes use of output operand specifications to
instrument inline asm, and with incorrect specifications we get false
positives in code that uses the CK_(S)LIST macros.

This was submitted upstream:
https://github.com/concurrencykit/ck/pull/175

The commit applies the same change locally to make KMSAN usable until
something equivalent is merged upstream.

MFC after: 1 week
Sponsored by: The FreeBSD Foundation

3 years agouma: Add KMSAN hooks
Mark Johnston [Tue, 10 Aug 2021 21:15:03 +0000 (17:15 -0400)]
uma: Add KMSAN hooks

For now, just hook the allocation path: upon allocation, items are
marked as initialized (absent M_ZERO).  Some zones are exempted from
this when it would otherwise raise false positives.

Use kmsan_orig() to update the origin map for UMA and malloc(9)
allocations.  This allows KMSAN to print the return address when an
uninitialized UMA item is implicated in a report.  For example:
  panic: MSan: Uninitialized UMA memory from m_getm2+0x7fe

Sponsored by: The FreeBSD Foundation

3 years agobusdma: Add KMSAN integration
Mark Johnston [Tue, 10 Aug 2021 21:14:15 +0000 (17:14 -0400)]
busdma: Add KMSAN integration

Sanitizer instrumentation of course cannot automatically update shadow
state when devices write to host memory.  KMSAN thus hooks into busdma,
both to update shadow state after a device write, and to verify that the
kernel does not publish uninitalized bytes to devices.

To implement this, when KMSAN is configured, each dmamap embeds a memory
descriptor describing the region currently loaded into the map.
bus_dmamap_sync() uses the operation flags to determine whether to
validate the loaded region or to mark it as initialized in the shadow
map.

Note that in cases where the amount of data written is less than the
buffer size, the entire buffer is marked initialized even when it is
not.  For example, if a NIC writes a 128B packet into a 2KB buffer, the
entire buffer will be marked initialized, but subsequent accesses past
the first 128 bytes are likely caused by bugs.

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

3 years agobusdma: Add an internal BUS_DMA_FORCE_MAP flag to x86 bounce_busdma
Mark Johnston [Tue, 10 Aug 2021 21:11:43 +0000 (17:11 -0400)]
busdma: Add an internal BUS_DMA_FORCE_MAP flag to x86 bounce_busdma

Use this flag to indicate that busdma should allocate a map structure
even no bouncing is required to satisfy the tag's constraints.  This
will be used for KMSAN.

Also fix a memory leak that can occur if the kernel fails to allocate
bounce pages in bounce_bus_dmamap_create().

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

3 years agoAdd a GENERIC-KMSAN kernel configuration for amd64
Mark Johnston [Tue, 10 Aug 2021 19:51:31 +0000 (15:51 -0400)]
Add a GENERIC-KMSAN kernel configuration for amd64

Sponsored by: The FreeBSD Foundation

3 years agokmsan: Add a manual page
Mark Johnston [Tue, 10 Aug 2021 20:55:23 +0000 (16:55 -0400)]
kmsan: Add a manual page

Sponsored by: The FreeBSD Foundation

3 years agoamd64: Add MD bits for KMSAN
Mark Johnston [Tue, 10 Aug 2021 21:14:47 +0000 (17:14 -0400)]
amd64: Add MD bits for KMSAN

Interrupt and exception handlers must call kmsan_intr_enter() prior to
calling any C code.  This is because the KMSAN runtime maintains some
TLS in order to track initialization state of function parameters and
return values across function calls.  Then, to ensure that this state is
kept consistent in the face of asynchronous kernel-mode excpeptions, the
runtime uses a stack of TLS blocks, and kmsan_intr_enter() and
kmsan_intr_leave() push and pop that stack, respectively.

Use these functions in amd64 interrupt and exception handlers.  Note
that handlers for user->kernel transitions need not be annotated.

Also ensure that trap frames pushed by the CPU and by handlers are
marked as initialized before they are used.

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

3 years agoamd64: Populate the KMSAN shadow maps and integrate with the VM
Mark Johnston [Tue, 10 Aug 2021 20:52:36 +0000 (16:52 -0400)]
amd64: Populate the KMSAN shadow maps and integrate with the VM

- During boot, allocate PDP pages for the shadow maps.  The region above
  KERNBASE is currently not shadowed.
- Create a dummy shadow for the vm page array.  For now, this array is
  not protected by the shadow map to help reduce kernel memory usage.
- Grow shadows when growing the kernel map.
- Increase the default kernel stack size when KMSAN is enabled.  As with
  KASAN, sanitizer instrumentation appears to create stack frames large
  enough that the default value is not sufficient.
- Disable UMA's use of the direct map when KMSAN is configured.  KMSAN
  cannot validate the direct map.
- Disable unmapped I/O when KMSAN configured.
- Lower the limit on paging buffers when KMSAN is configured.  Each
  buffer has a static MAXPHYS-sized allocation of KVA, which in turn
  eats 2*MAXPHYS of space in the shadow map.

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

3 years agokern: Ensure that thread-local KMSAN state is available
Mark Johnston [Wed, 11 Aug 2021 00:58:00 +0000 (20:58 -0400)]
kern: Ensure that thread-local KMSAN state is available

Sponsored by: The FreeBSD Foundation

3 years agoAdd the KMSAN runtime
Mark Johnston [Tue, 10 Aug 2021 19:52:36 +0000 (15:52 -0400)]
Add the KMSAN runtime

KMSAN enables the use of LLVM's MemorySanitizer in the kernel.  This
enables precise detection of uses of uninitialized memory.  As with
KASAN, this feature has substantial runtime overhead and is intended to
be used as part of some automated testing regime.

The runtime maintains a pair of shadow maps.  One is used to track the
state of memory in the kernel map at bit-granularity: a bit in the
kernel map is initialized when the corresponding shadow bit is clear,
and is uninitialized otherwise.  The second shadow map stores
information about the origin of uninitialized regions of the kernel map,
simplifying debugging.

KMSAN relies on being able to intercept certain functions which cannot
be instrumented by the compiler.  KMSAN thus implements interceptors
which manually update shadow state and in some cases explicitly check
for uninitialized bytes.  For instance, all calls to copyout() are
subject to such checks.

The runtime exports several functions which can be used to verify the
shadow map for a given buffer.  Helpers provide the same functionality
for a few structures commonly used for I/O, such as CAM CCBs, BIOs and
mbufs.  These are handy when debugging a KMSAN report whose
proximate and root causes are far away from each other.

Obtained from: NetBSD
Sponsored by: The FreeBSD Foundation

3 years agoamd64: Define KVA regions for KMSAN shadow maps
Mark Johnston [Tue, 10 Aug 2021 20:25:39 +0000 (16:25 -0400)]
amd64: Define KVA regions for KMSAN shadow maps

KMSAN requires two shadow maps, each one-to-one with the kernel map.
Allocate regions of the kernels PML4 page for them.  Add functions to
create mappings in the shadow map regions, these will be used by the
KMSAN runtime.

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

3 years agoconf: Add a KMSAN kernel option
Mark Johnston [Tue, 10 Aug 2021 19:51:03 +0000 (15:51 -0400)]
conf: Add a KMSAN kernel option

Sponsored by: The FreeBSD Foundation

3 years agoamd64 pmap: Pre-set PG_M on 2MB KASAN shadow map entries
Mark Johnston [Tue, 10 Aug 2021 20:23:42 +0000 (16:23 -0400)]
amd64 pmap: Pre-set PG_M on 2MB KASAN shadow map entries

Also remove a redundant assertion in pmap_kasan_enter().

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

3 years agobuild.7: Describe the default value for LOCAL_MODULES
Mark Johnston [Tue, 10 Aug 2021 17:34:57 +0000 (13:34 -0400)]
build.7: Describe the default value for LOCAL_MODULES

Suggested by: jhb
MFC after: 1 week

3 years agoMark some sysctls as CTLFLAG_MPSAFE.
Alexander Motin [Wed, 11 Aug 2021 00:44:27 +0000 (20:44 -0400)]
Mark some sysctls as CTLFLAG_MPSAFE.

MFC after: 2 weeks

3 years agogeom(4): Mark all sysctls as CTLFLAG_MPSAFE.
Alexander Motin [Wed, 11 Aug 2021 00:18:46 +0000 (20:18 -0400)]
geom(4): Mark all sysctls as CTLFLAG_MPSAFE.

This code does not use Giant lock for very long time.

MFC after: 2 weeks

3 years agocam(4): Mark all sysctls as CTLFLAG_MPSAFE.
Alexander Motin [Wed, 11 Aug 2021 00:05:40 +0000 (20:05 -0400)]
cam(4): Mark all sysctls as CTLFLAG_MPSAFE.

This code does not use Giant lock for very long time.

MFC after: 2 weeks

3 years agontb_hw_intel(4): Add CTLFLAG_MPSAFE flags.
Alexander Motin [Wed, 11 Aug 2021 00:03:12 +0000 (20:03 -0400)]
ntb_hw_intel(4): Add CTLFLAG_MPSAFE flags.

I should have added those in 50f16247a1.

MFC after: 2 weeks

3 years agortsx: Fix wakeup race similar to sdhci one fixed in 35547df5c786
Warner Losh [Tue, 10 Aug 2021 23:07:50 +0000 (17:07 -0600)]
rtsx: Fix wakeup race similar to sdhci one fixed in 35547df5c786

rtsx copied code from sdhci, and has the same wakeup race bug that was
fixed in 35547df5c786, so apply a similar fix here.

Sponsored by: Netflix

3 years agoAddress the reported mmc serialization issue.
Scott Long [Tue, 10 Aug 2021 22:41:23 +0000 (22:41 +0000)]
Address the reported mmc serialization issue.

Reset the mmc owner before calling the bridge release host callback.

Some people are hitting the "mmc: host bridge didn't serialize us." panic as
the bridge is released before the mmc owner is reset.

Submitted by: luiz
Sponsored by:   Rubicon Communications, LLC ("Netgate")

3 years agoCall wakeup() with the lock held to avoid missed wakeup races.
Scott Long [Tue, 10 Aug 2021 22:36:38 +0000 (22:36 +0000)]
Call wakeup() with the lock held to avoid missed wakeup races.

Submitted by: luiz
Sponsored by: Rubicon Communications, LLC ("Netgate")

3 years agodevmatch: Ignore the pnp fields tagged as ignore ('#')
Warner Losh [Tue, 10 Aug 2021 21:45:50 +0000 (15:45 -0600)]
devmatch: Ignore the pnp fields tagged as ignore ('#')

When matching entries, we should ignore those with a name of '#'. It's
the standard way to skip elements and need to be present to have the
proper offsets to the fields that are observed. No bus has a pnp
attribute of '#' and that is now disallowed for future buses that are
written.

Sponsored by: Netflix
Reviewed by: kbowling
Differential Revision: https://reviews.freebsd.org/D31482

3 years agonfs tls: Update for SSL_OP_ENABLE_KTLS.
John Baldwin [Tue, 10 Aug 2021 21:18:43 +0000 (14:18 -0700)]
nfs tls: Update for SSL_OP_ENABLE_KTLS.

Upstream OpenSSL (and the KTLS backport) have switched to an opt-in
option (SSL_OP_ENABLE_KTLS) in place of opt-out modes
(SSL_MODE_NO_KTLS_TX and SSL_MODE_NO_KTLS_RX) for controlling kernel
TLS.

Reviewed by: rmacklem
Sponsored by: Netflix
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D31445

3 years agoar: provide error exit status upon failure
Ed Maste [Tue, 3 Aug 2021 18:30:06 +0000 (14:30 -0400)]
ar: provide error exit status upon failure

Previously ar and ranlib returned with exit status 0 (success) in the
case of a missing file or other error.  Update to use error handling
similar to that added by ELF Tool Chain after that project forked
FreeBSD's ar.

PR: PR257599 [exp-run]
Reported by: Shawn Webb, gehmehgeh (on HardenedBSD IRC)
Reviewed by: markj
Obtained from: elftoolchain
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D31402

3 years agontb_transport(4): Mark callouts MP-safe.
Alexander Motin [Tue, 10 Aug 2021 20:30:12 +0000 (16:30 -0400)]
ntb_transport(4): Mark callouts MP-safe.

The only thing around NTB using Giant lock is NewBus, and these callouts
have nothing to do with it.

MFC after: 2 weeks

3 years agontb_hw_intel(4): Remove CTLFLAG_NEEDGIANT flags.
Alexander Motin [Tue, 10 Aug 2021 20:24:48 +0000 (16:24 -0400)]
ntb_hw_intel(4): Remove CTLFLAG_NEEDGIANT flags.

Most of the sysctls just read hardware registers.  They don't need
any locking.

MFC after: 2 weeks

3 years agopmc(3): remove Pentium-related man pages and references
Mitchell Horne [Tue, 10 Aug 2021 20:19:58 +0000 (17:19 -0300)]
pmc(3): remove Pentium-related man pages and references

Support for Pentium events was removed completely in e92a1350b50e.

Don't bump .Dd where we are just removing xrefs.

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

3 years agoe1000: rctl/srrctl buffer size init, rfctl fix
Kevin Bowling [Tue, 10 Aug 2021 19:47:22 +0000 (12:47 -0700)]
e1000: rctl/srrctl buffer size init, rfctl fix

Simplify the setup of srrctl.BSIZEPKT on igb class NICs.
Improve the setup of rctl.BSIZE on lem and em class NICs.
Don't try to touch rfctl on lem class NICs.
Manipulate rctl.BSEX correctly on lem and em class NICs.

Approved by: markj
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D31457

3 years agobuild.7: Document LOCAL_MODULES and LOCAL_MODULES_DIR
Mark Johnston [Tue, 10 Aug 2021 15:42:35 +0000 (11:42 -0400)]
build.7: Document LOCAL_MODULES and LOCAL_MODULES_DIR

Reviewed by: 0mp, imp
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D31461

3 years agoshare/man/man7/arch.7: bump date
Piotr Kubaj [Tue, 10 Aug 2021 15:04:51 +0000 (17:04 +0200)]
share/man/man7/arch.7: bump date

3 years agoshare/man/man7/arch.7: powerpc64 support appeared in 9.0-RELEASE
Piotr Kubaj [Tue, 10 Aug 2021 14:33:29 +0000 (16:33 +0200)]
share/man/man7/arch.7: powerpc64 support appeared in 9.0-RELEASE

Differential revision: https://reviews.freebsd.org/D31013
Approved by: eadler, 0mp

3 years ago[skip ci] unix(4): LOCAL_PEERCRED works on SOCK_SEQPACKET, too.
Alan Somers [Tue, 10 Aug 2021 13:29:06 +0000 (07:29 -0600)]
[skip ci] unix(4): LOCAL_PEERCRED works on SOCK_SEQPACKET, too.

MFC after: 2 weeks
Reviewed By: dchagin
Differential Revision: https://reviews.freebsd.org/D31456

3 years agoip(4): Mention IP_IPSEC_POLICY ip-level socket option
Konstantin Belousov [Mon, 9 Aug 2021 11:07:18 +0000 (14:07 +0300)]
ip(4): Mention IP_IPSEC_POLICY ip-level socket option

Text is literally taken from NetBSD ip(4).

Sponsored by: NVIDIA Networking
MFC after: 3 days

3 years agoipsec_set_policy(3): fix sentence
Konstantin Belousov [Mon, 9 Aug 2021 10:37:41 +0000 (13:37 +0300)]
ipsec_set_policy(3): fix sentence

Sponsored by: NVIDIA Networking
MFC after: 3 days

3 years agonetipsec/key.c: Use ANSI C definition for key_random()
Konstantin Belousov [Tue, 3 Aug 2021 01:24:31 +0000 (04:24 +0300)]
netipsec/key.c: Use ANSI C definition for key_random()

Sponsored by: NVIDIA Networking
MFC after: 3 days

3 years agonetipsec/keydb.h: fix typo
Konstantin Belousov [Sat, 31 Jul 2021 01:41:13 +0000 (04:41 +0300)]
netipsec/keydb.h: fix typo

Sponsored by: NVIDIA Networking
MFC after: 3 days

3 years agoe1000: Fix lem/em UDP rx csum offload
Kevin Bowling [Mon, 9 Aug 2021 21:29:31 +0000 (14:29 -0700)]
e1000: Fix lem/em UDP rx csum offload

Rebase on igb code and unify lem/em implementations.

PR: 257642
Reported by: Nick Reilly <nreilly@blackberry.com>
Reviewed by: karels, emaste
Tested by: Nick Reilly <nreilly@blackberry.com>
Approved by: grehan
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D31449

3 years agoriscv: Fix pmap_alloc_l2 when it should allocate a new L1 entry
Jessica Clarke [Mon, 9 Aug 2021 19:28:37 +0000 (20:28 +0100)]
riscv: Fix pmap_alloc_l2 when it should allocate a new L1 entry

The current code checks the RWX bits are 0 but does not check the V bit
is non-zero, meaning not-yet-allocated L1 entries that are still zero
are regarded as being allocated. This is likely due to copying the arm64
code that checks ATTR_DESC_MASK is L1_TABLE, which emcompasses both the
type and the validity in a single field, and erroneously translating
that to a check of just PTE_RWX being 0 to indicate non-leaf, forgetting
about the V bit. This then results in the following panic:

    panic: Fatal page fault at 0xffffffc0005cf292: 0x00000000000050
    cpuid = 1
    time = 1628379581
    KDB: stack backtrace:
    db_trace_self() at db_trace_self
    db_trace_self_wrapper() at db_trace_self_wrapper+0x38
    kdb_backtrace() at kdb_backtrace+0x2c
    vpanic() at vpanic+0x148
    panic() at panic+0x2a
    page_fault_handler() at page_fault_handler+0x1ba
    do_trap_supervisor() at do_trap_supervisor+0x7a
    cpu_exception_handler_supervisor() at
    cpu_exception_handler_supervisor+0x70
    --- exception 13, tval = 0x50
    pmap_enter_l2() at pmap_enter_l2+0xb2
    pmap_enter_object() at pmap_enter_object+0x15e
    vm_map_pmap_enter() at vm_map_pmap_enter+0x228
    vm_map_insert() at vm_map_insert+0x4ec
    vm_map_find() at vm_map_find+0x474
    vm_map_find_min() at vm_map_find_min+0x52
    vm_mmap_object() at vm_mmap_object+0x1ba
    vn_mmap() at vn_mmap+0xf8
    kern_mmap() at kern_mmap+0x4c4
    sys_mmap() at sys_mmap+0x38
    do_trap_user() at do_trap_user+0x208
    cpu_exception_handler_user() at cpu_exception_handler_user+0x72
    --- exception 8, tval = 0x1dd

Instead, we should just check the V bit, as on amd64, and assert that
any valid L1 entries are not leaves, since an L1 leaf would render the
entire range allocated and thus we should not have attempted to map that
VA in the first place.

Reported by: David Gilbert <dgilbert@daveg.ca>
MFC after: 1 week
Reviewed by: markj, mhorne
Differential Revision: https://reviews.freebsd.org/D31460

3 years agoRemove duplicate entry for arm/mv/armada38x/armada38x_rtc.c
Scott Long [Mon, 9 Aug 2021 18:57:50 +0000 (18:57 +0000)]
Remove duplicate entry for arm/mv/armada38x/armada38x_rtc.c

Sponsored by:   Rubicon Communications, LLC ("Netgate")

3 years agovmm: Make iommu ops tables const
Mark Johnston [Mon, 9 Aug 2021 17:28:27 +0000 (13:28 -0400)]
vmm: Make iommu ops tables const

While here, use designated initializers and rename some AMD iommu method
implementations to match the corresponding op names.  No functional
change intended.

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

3 years agoamd64: Fix output operand specs for the stmxcsr and vmread intrinsics
Mark Johnston [Mon, 9 Aug 2021 17:28:08 +0000 (13:28 -0400)]
amd64: Fix output operand specs for the stmxcsr and vmread intrinsics

This does not appear to affect code generation, at least with the
default toolchain.

Noticed because incorrect output specifications lead to false positives
from KMSAN, as the instrumentation uses them to update shadow state for
output operands.

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

3 years agokasan.9: Note the header required for kasan_mark()
Mark Johnston [Fri, 6 Aug 2021 01:52:49 +0000 (21:52 -0400)]
kasan.9: Note the header required for kasan_mark()

Sponsored by: The FreeBSD Foundation

3 years agond6: Mark several callouts as MPSAFE
Mark Johnston [Mon, 9 Aug 2021 17:21:43 +0000 (13:21 -0400)]
nd6: Mark several callouts as MPSAFE

The use of Giant here is vestigal and does not provide any useful
synchronization.  Furthermore, non-MPSAFE callouts can cause the
softclock threads to block waiting for long-running newbus operations to
complete.

Reported by: mav
Reviewed by: bz
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D31470

3 years agoin6: Enter the net epoch in in6_tmpaddrtimer()
Mark Johnston [Mon, 9 Aug 2021 17:14:23 +0000 (13:14 -0400)]
in6: Enter the net epoch in in6_tmpaddrtimer()

We need to do so to safely traverse the ifnet list.

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

3 years agovfs: Avoid a comparison with an uninitialized field in setutimes()
Mark Johnston [Mon, 9 Aug 2021 17:27:20 +0000 (13:27 -0400)]
vfs: Avoid a comparison with an uninitialized field in setutimes()

Some filesystems, e.g., devfs, do not populate va_birthtime in their
GETATTR implementations.  To handle this, make sure that va_birthtime is
initialized to the quasi-standard value of { VNOVAL, 0 } before calling
VOP_GETATTR.

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

3 years agorelease: allow VM_EXTRA_PACKAGES to be specified in the environment
Brad Davis [Mon, 9 Aug 2021 16:31:51 +0000 (10:31 -0600)]
release: allow VM_EXTRA_PACKAGES to be specified in the environment

This is useful for adding extra packages to the build of an AMI.
For example:
env VM_EXTRA_PACKAGES="zsh" make -C release ec2ami

Approved by: gjb
MFC after: 1 week
Sponsored by: Rubicon Communications, LLC ("Netgate")

3 years agorelease: fix copypasta
Brad Davis [Mon, 9 Aug 2021 16:23:18 +0000 (10:23 -0600)]
release: fix copypasta

Approved by: gjb
MFC after: 1 week
X-MFC-With: fd17ea8c1849039c436f7192ca407db70561df03
Sponsored by: Rubicon Communications, LLC ("Netgate")