]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
5 years agoMerge ^/head r338731 through r338987.
dim [Thu, 27 Sep 2018 20:00:07 +0000 (20:00 +0000)]
Merge ^/head r338731 through r338987.

5 years agoClear stack allocated data structure to prevent kernel memory leak.
gordon [Thu, 27 Sep 2018 18:39:54 +0000 (18:39 +0000)]
Clear stack allocated data structure to prevent kernel memory leak.

Reported by: Thomas Barabosch, Fraunhofer FKIE
Reviewed by: wes@
Approved by: re (implicit)
Approved by: so
Security: FreeBSD-EN-18:12.mem
Security: CVE-2018-17155

5 years agoAdd description, parameters, options, sysctl and examples of using AQMs to ipfw man...
ygy [Thu, 27 Sep 2018 18:14:01 +0000 (18:14 +0000)]
Add description, parameters, options, sysctl and examples of using AQMs to ipfw man page. CoDel, PIE, FQ-CoDel and FQ-PIE AQM for Dummynet exist in FreeBSD 11 and 10.3.

Submitted by: ralsaadi@swin.edu.au
Reviewed by: AllanJude
Approved by: re (gjb)
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D12507

5 years agoDon't clear DR6 for debug exceptions from userland.
jhb [Thu, 27 Sep 2018 17:33:59 +0000 (17:33 +0000)]
Don't clear DR6 for debug exceptions from userland.

This reverts part of r333368.  The attempt to clear DR6 was occuring
too soon as trapsignal() does not pause to let the debugger notice the
SIGTRAP and query DR6.  The signal exchange does not occur until much
later during ast().  As a result, GDB was no longer recognizing
hardware breakpoints and watchpoints on x86.

In addition, any userland programs that want to inspect DR6 in a
SIGTRAP handler don't have a way to do this if we clear DR6 in the
exception handler.

Instead of relying on the kernel to clear DR6, debuggers will have to
explicitly clear it after a trace trap (which they needed to do on
older kernels anyway).

Reviewed by: kib
Approved by: re (delphij)
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D17319

5 years agoamd64: reimplement libc memcmp and bcmp with kernel memcmp
mjg [Thu, 27 Sep 2018 17:08:29 +0000 (17:08 +0000)]
amd64: reimplement libc memcmp and bcmp with kernel memcmp

Both are significantly slower than hand-coded loops. See r338963 for
kernel commit.

bcmp differs from memcmp by always returning 1 when a difference is
found, as opposed to going for a value bigger or lower than 0
depending on what it is. This means it can do less work. For now the
code is duplicated and modified. This will get deduplicated after
another round of optimization when memcmp will get a longer-term form.

Both tested with the glibc suite. While the suite does not have a test
for bcmp, I created a wrapper routine which verified that values match
(0 vs 0, 1 vs non-zero).

Reviewed by: kib
Approved by: re (gjb)
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17336

5 years agoamd64: macroify and mostly depessimize copyinstr
mjg [Thu, 27 Sep 2018 15:53:36 +0000 (15:53 +0000)]
amd64: macroify and mostly depessimize copyinstr

See r338968 for details.

Reviewed by: kib
Approved by: re (gjb)
Differential Revision: https://reviews.freebsd.org/D17288

5 years agoIn in6_pcbpurgeif0() called, e.g., from if_clone_destroy(),
bz [Thu, 27 Sep 2018 15:32:37 +0000 (15:32 +0000)]
In in6_pcbpurgeif0() called, e.g., from if_clone_destroy(),
once we have a lock, make sure the inp is not marked freed.
This can happen since the list traversal and locking was
converted to epoch(9).  If the inp is marked "freed", skip it.

This prevents a NULL pointer deref panic later on.

Reported by: slavash (Mellanox)
Tested by: slavash (Mellanox)
Reviewed by: markj (no formal review but caught my unlock mistake)
Approved by: re (kib)

5 years agoamd64: mostly depessimize copystr
mjg [Thu, 27 Sep 2018 15:27:53 +0000 (15:27 +0000)]
amd64: mostly depessimize copystr

- remove a forward branch in the common case
- replace xchg + lodsb/stosb loop with simple movs

A simple test on Intel(R) Core(TM) i7-4600U CPU @ 2.10GH copying
/foo/bar/baz in a loop goes from 295715863 ops/s to 465807408.

Further changes are pending.

Reviewed by: kib
Approved by: re (gjb)
Differential Revision: https://reviews.freebsd.org/D17281

5 years agoamd64: clean up copyin/copyout
mjg [Thu, 27 Sep 2018 15:24:16 +0000 (15:24 +0000)]
amd64: clean up copyin/copyout

- move the PSL.AC comment to the fault handler
- stop testing for zero-sized ops. after several minutes of package
building there were no copyin calls with zero bytes and very few
copyout. the semantic of returning 0 in this case is preserved
- shorten exit paths by clearing %eax earlier
- replace xchg with 3 movs. this is what compilers do. a naive
benchmark on EPYC suggests about 1% increase in thoughput thanks to
this change.
- remove the useless movb %cl,%al from copyout. it looks like a
leftover from many years ago

Reviewed by: kib
Approved by: re (gjb)
Differential Revision: https://reviews.freebsd.org/D17286

5 years agolib(4): Fix mdoc issues.
0mp [Thu, 27 Sep 2018 14:52:42 +0000 (14:52 +0000)]
lib(4): Fix mdoc issues.

- Fix "mandoc -Tlint" warnings.
- Use the "Er" macro for errors.
- Add an extra newline for readability.
- Reference m_pullup(9) and m_defrag(9).
- Use the "Fx" macro when talking about FreeBSD versions.

Reviewed by: bcr
Approved by: re (gjb), krion (mentor)
Differential Revision: https://reviews.freebsd.org/D17270

5 years agoRemove -m (update) from ldconfig -32 & -soft invocation on startup.
kib [Thu, 27 Sep 2018 14:31:41 +0000 (14:31 +0000)]
Remove -m (update) from ldconfig -32 & -soft invocation on startup.

Since r154114 which introduced ldconfig_local32_dirs, ldconfig -32 was
called with -m. This means that ld-elf32.so.hints paths set is not
cleared for compat32 on boot, unlike ld,so,hints.  Same -m was used in
r294295 for ld-elf-soft.so.hints on arm.  The patch fixes the
asymmetry.

Noted by: Andreas Longwitz <longwitz@incore.de>
Reviewed by: brooks, emaste, imp
Discussed with: bdrewery
Sponsored by: The FreeBSD Foundation
Approved by: re (gjb)
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D17331

5 years agoamd64: implement memcmp in assembly
mjg [Thu, 27 Sep 2018 14:05:44 +0000 (14:05 +0000)]
amd64: implement memcmp in assembly

Both the in-kernel C variant and libc asm variant have very poor performance.
The former compiles to a single byte comparison loop, which breaks down even
for small sizes. The latter uses rep cmpsq/b which turn out to have very poor
throughput and are slower than a hand-coded 32-byte comparison loop.

Depending on size this is about 3-4 times faster than the current routines.

Reviewed by: kib
Approved by: re (gjb)
Differential Revision: https://reviews.freebsd.org/D17328

5 years agoExport ID_AA64PFR0_EL1 to userland
andrew [Thu, 27 Sep 2018 13:54:09 +0000 (13:54 +0000)]
Export ID_AA64PFR0_EL1 to userland

Create a user view of the ID_AA64PFR0_EL1 register with values common
across all CPUs.

Approved by: re (kib)
Sponsored by: ABT Systems Ltd
Differential Revision: https://reviews.freebsd.org/D17301

5 years agoMove the undefined instruction handler to identcpu.c so we have access
andrew [Thu, 27 Sep 2018 13:50:57 +0000 (13:50 +0000)]
Move the undefined instruction handler to identcpu.c so we have access
to the registers from boot.

Approved by: re (kib)
Sponsored by: ABT Systems Ltd
Differential Revision: https://reviews.freebsd.org/D17301

5 years agoCross-reference style.Makefile(5) from make(1) and make.conf(5).
0mp [Thu, 27 Sep 2018 12:20:32 +0000 (12:20 +0000)]
Cross-reference style.Makefile(5) from make(1) and make.conf(5).

Reviewed by: krion, mat, sjg
Approved by: re (gjb), krion (mentor), mat (mentor)
Sponsored by: Bally Wulff Games & Entertainment GmbH
Differential Revision: https://reviews.freebsd.org/D17170

5 years agonewvers.sh: Unbreak building in Git repositories.
0mp [Thu, 27 Sep 2018 12:15:31 +0000 (12:15 +0000)]
newvers.sh: Unbreak building in Git repositories.

Building the kernel in Git repositories when git-svn is not available and
the "help.autocorrect" Git parameter is enabled results in Git trying to
replace the "svn" command (it does not know) with "serve". As a result the
output of the "git server" command is appended to the value of the
environmental variable VERINFO, which causes the auto generated vers.c
file to contain invalid C syntax (missing newline escapes):

    #define "@(#)FreeBSD 12.0-ALPHA7  r000eversion 2
    0015agent=git/2.19.0
    000cls-refs
    0012fetch=shallow
    0012server-option
    0000=5e2272613fa(splash-vt)"
    #define VERSTR "FreeBSD 12.0-ALPHA7  r000eversion 2
    0015agent=git/2.19.0
    000cls-refs
    0012fetch=shallow
    0012server-option
    0000=5e2272613fa(splash-vt)\n"

Using `-c help.autocorrect=0` seems to be a good solution as it does not
modify user's environment. I am not sure, however, if we should use
programs (or Git commands), which we are not sure exist (we never check if
git-svn is available on the host), as there may be more unexpected
behaviors like this one.

Reviewed by: eadler, emaste, krion
Approved by: re (gjb), krion (mentor)
Sponsored by: Bally Wulff Games & Entertainment GmbH
Differential Revision: https://reviews.freebsd.org/D17271

5 years agomsdosfs(5): Explain how to determine version of the FAT file system.
0mp [Thu, 27 Sep 2018 12:08:53 +0000 (12:08 +0000)]
msdosfs(5): Explain how to determine version of the FAT file system.

While here, remove deprecated Tn macros.

Reviewed by: bcr
Approved by: re (gjb), krion (mentor)
Sponsored by: Bally Wulff Games & Entertainment GmbH
Differential Revision: https://reviews.freebsd.org/D17237

5 years agoHandle a guest executing a vm instruction by trapping and raising an
andrew [Thu, 27 Sep 2018 11:16:19 +0000 (11:16 +0000)]
Handle a guest executing a vm instruction by trapping and raising an
undefined instruction exception. Previously we would exit the guest,
however an unprivileged user could execute these.

Found with: syzkaller
Reviewed by: araujo, tychon (previous version)
Approved by: re (kib)
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D17192

5 years agoProvide refobj context when doing libmap substitution inside
kib [Wed, 26 Sep 2018 21:28:14 +0000 (21:28 +0000)]
Provide refobj context when doing libmap substitution inside
search_library_path().

This corrects the scope of libmap matches.

Reported and tested by: Andreas Longwitz <longwitz@incore.de>
Sponsored by: The FreeBSD Foundation
Approved by: re (gjb)
MFC after: 1 week

5 years agoWhen doing lm_add(), check for duplicates.
kib [Wed, 26 Sep 2018 21:27:08 +0000 (21:27 +0000)]
When doing lm_add(), check for duplicates.

This is useful when lm_find() moves the match to the global mapping,
since lm_find() could be called with a same path more than once.

Reported and tested by: Andreas Longwitz <longwitz@incore.de>
Sponsored by: The FreeBSD Foundation
Approved by: re (gjb)
MFC after: 1 week

5 years agocxgbe(4): Enable support for per-connection rate limiting in the default
np [Wed, 26 Sep 2018 21:16:07 +0000 (21:16 +0000)]
cxgbe(4): Enable support for per-connection rate limiting in the default
firmware configuration files.

Approved by: re@ (gjb@)
Sponsored by: Chelsio Communications

5 years agoAdd per-session locking to cryptosoft (swcr).
sef [Wed, 26 Sep 2018 20:23:12 +0000 (20:23 +0000)]
Add per-session locking to cryptosoft (swcr).

As part of ZFS Crypto, I started getting a series of panics when I did not
have AESNI loaded.  Adding locking fixed it, and I concluded that the
Reinit function altered the AES key schedule.  This locking is not as
fine-grained as it could be (AESNI uses per-cpu locking), but
it's minimally invasive.

Sponsored by: iXsystems Inc
Reviewed by: cem, mav
Approved by: re (gjb), mav (mentor)
Differential Revision: https://reviews.freebsd.org/D17307

5 years agoRelax syntax requirements of source string
imp [Wed, 26 Sep 2018 19:41:06 +0000 (19:41 +0000)]
Relax syntax requirements of source string

The original spec for the strings describing the PNP info didn't allow
spaces. Several times now people have broken the install by including
them. Relax the syntax to allow them after the ; which is where
people's muscle memory tends to put them.

Approved by: re@ (gjb)

5 years agoRemove bogus spaces.
imp [Wed, 26 Sep 2018 19:41:00 +0000 (19:41 +0000)]
Remove bogus spaces.

Spaces aren't allowed in these strings.

Approved by: re@ (glen)

5 years agoHandle overflow of uid or gid in arguments for chown
bdrewery [Wed, 26 Sep 2018 18:40:57 +0000 (18:40 +0000)]
Handle overflow of uid or gid in arguments for chown

chown incorrectly allows a uid or gid greater than UID_MAX/GID_MAX respectively.
Using such an argument rolls over to accounts such as root, operator, etc.

Approved by: re (gjb)
Relnotes: yes
Reviewed by: cem, kib
Submitted by: Don Morris <dgmorris@earthlink.net>
Sponsored by: Dell EMC
Differential Revision: https://reviews.freebsd.org/D15119

5 years agoAdd PNP info to PCI attachments of cbb, cxgb, ida, iwn, ixl, ixlv,
imp [Wed, 26 Sep 2018 17:12:30 +0000 (17:12 +0000)]
Add PNP info to PCI attachments of cbb, cxgb, ida, iwn, ixl, ixlv,
mfi, mps, mpr, mvs, my, oce, pcn, ral, rl. This only labels existing
pci device tables, and has no probe / attach code changes.

Reviewed by: imp, chuck
Submitted by: Lakhan Shiva Kamireddy <lakhanshiva@gmail.com>
Sponsored by: Google, Inc. (GSoC 2018)
Approved by: re (glen)

5 years agoReapply, with minor tweaks, r338025, from the original commit:
imp [Wed, 26 Sep 2018 17:12:14 +0000 (17:12 +0000)]
Reapply, with minor tweaks, r338025, from the original commit:

Remove unused and easy to misuse PNP macro parameter

Inspired by r338025, just remove the element size parameter to the
MODULE_PNP_INFO macro entirely.  The 'table' parameter is now required to
have correct pointer (or array) type.  Since all invocations of the macro
already had this property and the emitted PNP data continues to include the
element size, there is no functional change.

Mostly done with the coccinelle 'spatch' tool:

  $ cat modpnpsize0.cocci
    @normaltables@
    identifier b,c;
    expression a,d,e;
    declarer MODULE_PNP_INFO;
    @@
     MODULE_PNP_INFO(a,b,c,d,
    -sizeof(d[0]),
     e);

    @singletons@
    identifier b,c,d;
    expression a;
    declarer MODULE_PNP_INFO;
    @@
     MODULE_PNP_INFO(a,b,c,&d,
    -sizeof(d),
     1);

  $ rg -l MODULE_PNP_INFO -- sys | \
    xargs spatch --in-place --sp-file modpnpsize0.cocci

(Note that coccinelle invokes diff(1) via a PATH search and expects diff to
tolerate the -B flag, which BSD diff does not.  So I had to link gdiff into
PATH as diff to use spatch.)

Tinderbox'd (-DMAKE_JUST_KERNELS).
Approved by: re (glen)

5 years agoAdd "src-ip" or "dst-ip" keyword to the output, when we are printing the
ae [Wed, 26 Sep 2018 15:37:48 +0000 (15:37 +0000)]
Add "src-ip" or "dst-ip" keyword to the output, when we are printing the
rest of rule options.

Reported by: lev
Approved by: re (gjb)
MFC after: 1 week

5 years agoadd REPRODUCIBLE_BUILD note to UPDATING
emaste [Wed, 26 Sep 2018 15:07:06 +0000 (15:07 +0000)]
add REPRODUCIBLE_BUILD note to UPDATING

Reported by: bz
Approved by: re (gjb)

5 years agoFix witness warning in xform_init().
ae [Wed, 26 Sep 2018 14:47:51 +0000 (14:47 +0000)]
Fix witness warning in xform_init().

Do not call crypto_newsession() while holding xforms_lock mutex.
Release mutex before invoking crypto_newsession(), and use
ipsec_kmod_enter()/ipsec_kmod_exit() functions to protect from doing
access to unloaded kernel module memory.

Move xform-releated functions into subr_ipsec.c to be able use
ipsec_kmod_* functions. Also unconditionally build ipsec_kmod_*
functions, since now they are always used by IPSec code.

Add xf_cntr field to struct xformsw, it is used by ipsec_kmod_*
functions. Also constify xf_name field, since it is not expected to be
modified.

Approved by: re (kib)
Differential Revision: https://reviews.freebsd.org/D17302

5 years agoClarify UPDATING entry about lld
emaste [Wed, 26 Sep 2018 14:32:36 +0000 (14:32 +0000)]
Clarify UPDATING entry about lld

The workaround described in the 20180530 entry is no longer required.
Amend that entry and add a new 20180530 entry noting lld is the
default amd64 linker.

Reviewed by: imp
Approved by: re (kib)

5 years agoAdd PCIV_INVALID definition
slavash [Wed, 26 Sep 2018 13:16:55 +0000 (13:16 +0000)]
Add PCIV_INVALID definition

From PCI Spec rev 2.2, 6.2.1. Device Identification:
Vendor ID This field identifies the manufacturer of the device. Valid
vendor identifiers are allocated by the PCI SIG to ensure uniqueness.
0FFFFh is an invalid value for Vendor ID.

MFC after:      3 days
Approved by:    re (Glen), hselasky (mentor), kib (mentor)
Sponsored by:   Mellanox Technologies

5 years agoWhitespace changes and fixing a typo. No functional change.
tuexen [Wed, 26 Sep 2018 10:24:50 +0000 (10:24 +0000)]
Whitespace changes and fixing a typo. No functional change.

Approved by: re (kib@)
MFC after: 1 week

5 years agocxgbe(4): Treat base/end of firmware parameters as signed integers when
np [Wed, 26 Sep 2018 02:27:37 +0000 (02:27 +0000)]
cxgbe(4): Treat base/end of firmware parameters as signed integers when
figuring out whether the range is valid or not.

Approved by: re@ (rgrimes@)
MFC after: 1 week
Sponsored by: Chelsio Communications

5 years agoFix some uses of dmaplimit.
kib [Tue, 25 Sep 2018 20:07:58 +0000 (20:07 +0000)]
Fix some uses of dmaplimit.

dmaplimit is the first byte after the end of DMAP.

Reported by: "Johnson, Archna" <Archna.Johnson@netapp.com>
Reviewed by: alc, markj
Approved by: re (gjb)
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D17318

5 years agoBring the 32-bit powerpc (PowerMac) back to live. The commit 338486 reworked
andreast [Tue, 25 Sep 2018 19:29:35 +0000 (19:29 +0000)]
Bring the 32-bit powerpc (PowerMac) back to live. The commit 338486 reworked
some TLS bits. This broke operation on the PowerMac. Namely one could not login.
At login the screen/shell was giving back lots of backslashes and the login
shell dumped core.

The fix to this issue is to revert the powerpc commit from 338486 and to
increase the TLS_TCB_SIZE to 16.
Reverting only did not help, login was possible but userland applications
aborted with strange messages.

I tested this patch with world/kernel builds and with port upgrades.
Additionally a full gcc8 bootstrap was successfully completed.

Reviewed by: jhibbits@
Approved by: re (Glen)

5 years agoDo not remove ld man page if lld is enabled and binutils is not
emaste [Tue, 25 Sep 2018 18:54:18 +0000 (18:54 +0000)]
Do not remove ld man page if lld is enabled and binutils is not

Reported by: Mark Millard
Approved by: re (gjb)
Sponsored by: The FreeBSD Foundation

5 years agoFix an issue in r338862.
kib [Tue, 25 Sep 2018 18:24:25 +0000 (18:24 +0000)]
Fix an issue in r338862.

For pmap_invalidate_all_pcid(), only reset pm_gen for non-kernel
pmaps, as it was done before the conversion to ifuncs.  The reset is
useless but innocent for kernel_pmap. Coverity reported that cpuid is
used uninitialized in this case.

Reported by: cem
Reviewed by: alc, cem, markj
CID:  1395807
Sponsored by: The FreeBSD Foundation
Approved by: re (gjb)
Differential revision: https://reviews.freebsd.org/D17314

5 years agozfs: depessimize zfs_root with rmlocks
mjg [Tue, 25 Sep 2018 17:58:06 +0000 (17:58 +0000)]
zfs: depessimize zfs_root with rmlocks

Currently vfs calls the root method on each absolute lookup and when
crossing mount points.

zfs_root ends up looking up the inode internally as if it was not
instantianted which results in significant lock contention on systems
like EPYC.

Store the vnode in the mount point and protect the access with rmlocks.
This is a temporary hack for 12.0.

Sample result:

before:
make -s -j 128 buildkernel 2778.09s user 3319.45s system 8370% cpu 1:12.85 total

after:
make -s -j 128 buildkernel 3199.57s user 1772.78s system 8232% cpu 1:00.40 total

Tested by: pho (zfs mount/unmount tests)
Reviewed by: kib, mav, sef (different parts)
Approved by: re (gjb)
Differential Revision: https://reviews.freebsd.org/D17233

5 years agoDon't override LDFLAGS set in bsd.cpu.mk.
brooks [Tue, 25 Sep 2018 15:25:42 +0000 (15:25 +0000)]
Don't override LDFLAGS set in bsd.cpu.mk.

This is a direct commit to a generated file.  Simon plans to fix this
upstream before the next import.

PR: 231557
Approved by: re (gjb)
Obtained from: CheriBSD
Sponsored by: DARPA, AFRL

5 years agocxgbe(4): Link related changes.
np [Tue, 25 Sep 2018 05:52:42 +0000 (05:52 +0000)]
cxgbe(4): Link related changes.

- Switch to using 32b port/link capabilities in the driver.  The 32b
  format is used internally by firmwares > 1.16.45.0 and the driver will
  now interact with the firmware in its native format, whether it's 16b
  or 32b.  Note that the 16b format doesn't have room for 50G, 200G, or
  400G speeds.

- Add a bit in the pause_settings knobs to allow negotiated PAUSE
  settings to override manual settings.

- Ensure that manual link settings persist across an administrative
  down/up as well as transceiver unplug/replug.

- Remove unused is_*G_port() functions.

Approved by: re@ (gjb@)
MFC after: 1 month
Sponsored by: Chelsio Communications

5 years agopowerpc: Blacklist the top 64kB range of the lower 4GB PA space
jhibbits [Tue, 25 Sep 2018 02:34:28 +0000 (02:34 +0000)]
powerpc: Blacklist the top 64kB range of the lower 4GB PA space

The PHB4 host bridge used by the POWER9 uses a 64kB range in 32-bit
space at the address 0xffff0000-0xffffffff.  Reserve this range so that
DMA memory cannot be allocated within this range.  This fixes seemingly
random crashes on a POWER9 system.  Ideally this range will have been
reserved by the firmware, but as of now this is not the case.

Submitted by: git_bdragon.rtk0.net
Reviewed by: nwhitehorn
Approved by: re(kib)
Differential Revision: https://reviews.freebsd.org/D17183

5 years agoRecognize the Amazon PCI serial device found in i3.metal EC2 instances
cperciva [Mon, 24 Sep 2018 22:15:04 +0000 (22:15 +0000)]
Recognize the Amazon PCI serial device found in i3.metal EC2 instances
as an NS8250 UART.

Reviewed by: sbruno, imp
Approved by: re (delphij)
Sponsored by: https://www.patreon.com/cperciva
Differential Revision: https://reviews.freebsd.org/D17250

5 years agosysctl(8): Add a standard exit status section.
0mp [Mon, 24 Sep 2018 20:46:45 +0000 (20:46 +0000)]
sysctl(8): Add a standard exit status section.

Reviewed by: bcr
Approved by: re (gjb), krion (mentor)
Differential Revision: https://reviews.freebsd.org/D17147

5 years agoAdd more NUMA-specific low memory predicates.
markj [Mon, 24 Sep 2018 19:24:17 +0000 (19:24 +0000)]
Add more NUMA-specific low memory predicates.

Use these predicates instead of inline references to vm_min_domains.
Also add a global all_domains set, akin to all_cpus.

Reviewed by: alc, jeff, kib
Approved by: re (gjb)
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17278

5 years agorestore pmccontrol -L behavior on x86
mmacy [Mon, 24 Sep 2018 19:06:09 +0000 (19:06 +0000)]
restore pmccontrol -L behavior on x86

When I updated counter definition handling for x86 I broke
'pmccontrol -L' listing counter names. This just changes
pmccontrol to call the library function on x86.

PR: 230984
Approved by: re (kib@)

5 years agoRestore the API of the kf_sa_local and kf_sa_peer members.
jhb [Mon, 24 Sep 2018 18:20:38 +0000 (18:20 +0000)]
Restore the API of the kf_sa_local and kf_sa_peer members.

In 11.x and earlier these were accessible as direct members of 'struct
kinfo_file'.  Existing code already knows about the new location of
these members as well, so wrapper macros did not work for these
fields.  Instead, define an anonymous struct containing the fields
from 'struct kinfo_file' in FreeBSD 11 that were not part of the
'kf_un' union.  This anonymous struct is then placed in an anonymous
union along with the new 'kf_un' union.  This preserves the API of
both structure layouts without requiring any wrapper macros.

PR: 231525
Reviewed by: kib
Approved by: re (gjb)
Differential Revision: https://reviews.freebsd.org/D17262

5 years agoImplement pmap_sync_icache().
jhb [Mon, 24 Sep 2018 17:41:29 +0000 (17:41 +0000)]
Implement pmap_sync_icache().

This invokes "fence" on the hart performing the write followed by an IPI
to execute "fence.i" on all harts.

This is required to support userland debuggers setting breakpoints in
user processes.

Reviewed by: br (earlier version), markj
Approved by: re (gjb)
Sponsored by: DARPA
Differential Revision: https://reviews.freebsd.org/D17139

5 years agoFix use-after-free in RAID0 error reporting of GEOM_RAID.
mav [Mon, 24 Sep 2018 16:58:55 +0000 (16:58 +0000)]
Fix use-after-free in RAID0 error reporting of GEOM_RAID.

PR: 231510
Submitted by: yangx92@hotmail.com
Approved by: re (gjb)
MFC after: 1 week

5 years agoPassing UMA_ZONE_NOFREE to uma_zcreate() for swpctrie_zone and swblk_zone is
alc [Mon, 24 Sep 2018 16:49:02 +0000 (16:49 +0000)]
Passing UMA_ZONE_NOFREE to uma_zcreate() for swpctrie_zone and swblk_zone is
redundant, because uma_zone_reserve_kva() is performed on both zones and it
sets this same flag on the zone.  (Moreover, the implementation of the swap
pager does not itself require these zones to be UMA_ZONE_NOFREE.)

Reviewed by: kib, markj
Approved by: re (gjb)
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D17296

5 years agoEnsure that "domain" is initialized when vm_ndomains == 1.
markj [Mon, 24 Sep 2018 15:32:46 +0000 (15:32 +0000)]
Ensure that "domain" is initialized when vm_ndomains == 1.

Reported by: alc
Approved by: re (gjb)

5 years agoMove libc linker ifunc test to build target only
emaste [Mon, 24 Sep 2018 13:42:46 +0000 (13:42 +0000)]
Move libc linker ifunc test to build target only

Targets like 'cleandir' must not depend on toolchain capabilities.

Reported by: delphij, Shawn Webb
Approved by: re (kib)
Sponsored by: The FreeBSD Foundation

5 years agoEliminate false sharing in malloc due to statistic collection
mjg [Sun, 23 Sep 2018 19:00:06 +0000 (19:00 +0000)]
Eliminate false sharing in malloc due to statistic collection

Currently stats are collected in a MAXCPU-sized array which is not
aligned and suffers enormous false-sharing. Fix the problem by
utilizing per-cpu allocation.

The counter(9) API is not used here as it is too incomplete and does
not provide a win over per-cpu zone sized for malloc stats struct. In
particular stats are being reported for each cpu separately by just
copying what is supposed to be an array element for given cpu.

This eliminates significant false-sharing during malloc-heavy tests
e.g. on Skylake. See the review for details.

Reviewed by: markj
Approved by: re (kib)
Differential Revision: https://reviews.freebsd.org/D17289

5 years agoRemove the unused parameter 'locked' from the function
tuexen [Sun, 23 Sep 2018 16:37:32 +0000 (16:37 +0000)]
Remove the unused parameter 'locked' from the function
syncache_respond(). There is no functional change. The
parameter became unused in r313330, but wasn't removed.

Approved by: re (kib@)
MFC after: 1 month
Sponsored by: Netflix, Inc.

5 years agoSet the default loader for powerpc(32- and 64-bit) back to to forth.
andreast [Sat, 22 Sep 2018 20:58:43 +0000 (20:58 +0000)]
Set the default loader for powerpc(32- and 64-bit) back to to forth.
There are some issues with the lua-loader. To be on the safe side, use a well
known and working loader.

Approved by: re (glen)

5 years agoCorrect panic messages.
kib [Sat, 22 Sep 2018 17:05:49 +0000 (17:05 +0000)]
Correct panic messages.

Reviewed by: mckusick
Sponsored by: The FreeBSD Foundation
Approved by: re (rgrimes)
MFC after: 1 week

5 years agoFurther reorganize pmap_invalidate TLB code.
kib [Sat, 22 Sep 2018 17:04:39 +0000 (17:04 +0000)]
Further reorganize pmap_invalidate TLB code.

Split calculation of mask for shootdown IPI and local
invalidation. Reorder IPI before local.

Suggested by: alc
Reviewed by: alc, markj
Tested by: pho
Sponsored by: The FreeBSD Foundation
Approved by: re (rgrimes)
Differential revision: https://reviews.freebsd.org/D17277

5 years agoUpdate ifr_name before invoking IPSECSREQID ioctl, this fixes the case,
ae [Sat, 22 Sep 2018 16:30:48 +0000 (16:30 +0000)]
Update ifr_name before invoking IPSECSREQID ioctl, this fixes the case,
when `ifconfig ipsec create reqid N` command invoked without interface
unit number. The "name" global variable is updated after interface
cloning in the ifclonecreate() and contains actual interface name.

Reported by: lev
Approved by: re (kib)
MFC after: 1 week

5 years agoWe don't need shell protection for when we're expanding matches.
imp [Sat, 22 Sep 2018 15:32:53 +0000 (15:32 +0000)]
We don't need shell protection for when we're expanding matches.
Don't add it. This should fix when we do regepx matches against
variables we've set and fix wifi bring up.

PR: 231441
Approved by: re@ (kib)
Differential Revision: https://reviews.freebsd.org/D17267

5 years agoMove hosts.allow to lib/libwrap/
brd [Sat, 22 Sep 2018 13:17:30 +0000 (13:17 +0000)]
Move hosts.allow to lib/libwrap/

This leverages CONFS to handle the install.

Approved by: re (blanket, pkgbase), bapt (mentor)
Differential Revision: https://reviews.freebsd.org/D17240

5 years agoImprove loader passwords:
trasz [Sat, 22 Sep 2018 13:14:44 +0000 (13:14 +0000)]
Improve loader passwords:

1. Be clear about which password is being requested
2. Remove extraneous whitespace between the prompt and the cursor
3. Move the twiddle to where the prompt is, instead of two characters to the right
4. Fix erasing the 'incorrect password' message when retrying; previously it was erased partially
5. Remove the unneeded exclamation mark

Reviewed by: kevans
Approved by: re (gjb)
MFC after: 2 weeks
Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D17236

5 years agovfs: __predict common case in VFS_EPILOGUE/PROLOGUE
mjg [Sat, 22 Sep 2018 11:39:30 +0000 (11:39 +0000)]
vfs: __predict common case in VFS_EPILOGUE/PROLOGUE

NFS is the only in-tree filesystem using the feature, but all ops test
for it.

Currently the resulting sigdefer calls have to be jumped over in the
common case.

This is a bandaid, longer term fix will move this feature away.

Approved by: re (kib)

5 years agocxgbe(4): Reuse existing "switching" L2T entries when possible.
np [Sat, 22 Sep 2018 01:24:30 +0000 (01:24 +0000)]
cxgbe(4): Reuse existing "switching" L2T entries when possible.

Approved by: re@ (rgrimes@)
Sponsored by: Chelsio Communications

5 years agocxgbetool(8): The VLAN tag provided in the action for a filter must be prefixed
np [Fri, 21 Sep 2018 23:48:40 +0000 (23:48 +0000)]
cxgbetool(8): The VLAN tag provided in the action for a filter must be prefixed
with either '=' or '+'.  Fix the description of the parameter in the man page
while here.

Approved by: re@ (kib@)
Sponsored by: Chelsio Communications

5 years agoMFV r338866: 9700 ZFS resilvered mirror does not balance reads
mav [Fri, 21 Sep 2018 21:56:00 +0000 (21:56 +0000)]
MFV r338866: 9700 ZFS resilvered mirror does not balance reads

illumos/illumos-gate@82f63c3c2bf5e4378706e8dcfccf717d67371be9

Reviewed by: Toomas Soome <tsoome@me.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Approved by: Matthew Ahrens <mahrens@delphix.com>
Author:     Jerry Jelinek <jerry.jelinek@joyent.com>

Approved by: re (delphij)

5 years agoUse the GNU as-compatible .endm instead of .endmacro.
markj [Fri, 21 Sep 2018 20:20:03 +0000 (20:20 +0000)]
Use the GNU as-compatible .endm instead of .endmacro.

Approved by: re (gjb)

5 years agoConvert x86 TLB top-level invalidation functions to ifuncs.
kib [Fri, 21 Sep 2018 17:53:06 +0000 (17:53 +0000)]
Convert x86 TLB top-level invalidation functions to ifuncs.

Note that shootdown IPI handlers are already per-mode.

Suggested by: alc
Reviewed by: alc, markj
Tested by: pho
Sponsored by: The FreeBSD Foundation
Approved by: re (gjb)
Differential revision: https://reviews.freebsd.org/D17184

5 years agolibc: require ifunc-capable linker for amd64/i386
emaste [Fri, 21 Sep 2018 17:49:37 +0000 (17:49 +0000)]
libc: require ifunc-capable linker for amd64/i386

We expect to introduce optimized libc routines in the near future,
which requires use of a linker that supports ifuncs.

Approved by: re (gjb, kib)
Sponsored by:   The FreeBSD Foundation

5 years agoDisable sbrk() use in GNU tools.
brooks [Fri, 21 Sep 2018 17:44:05 +0000 (17:44 +0000)]
Disable sbrk() use in GNU tools.

We're studing the possibility of deprecating sbrk().  To make it easier
we're removing unnecessicary uses in the base system.  None of these
tools require sbrk(), but they agressively prefer it for no good reason.

Reviewed by:    andrew
Approved by: re (kib)
Sponsored by: DARPA, AFRL
Differential Revision:  https://reviews.freebsd.org/D16141

5 years agoamd64: even up copyin/copyout with memcpy + other cleanup
mjg [Fri, 21 Sep 2018 15:00:46 +0000 (15:00 +0000)]
amd64: even up copyin/copyout with memcpy + other cleanup

- _fault handlers for both primitives are identical, provide just one
- change the copying scheme to match memcpy (in particular jump
avoidance for the most common case of multiply of 8)
- stop re-reading pcb address on exit, just store it locally (in r9)

Reviewed by: kib
Approved by: re (gjb)
Differential Revision: https://reviews.freebsd.org/D17265

5 years agoFix possible NULL pointer dereference in ffec_alloc_mbufcl().
ae [Fri, 21 Sep 2018 13:44:05 +0000 (13:44 +0000)]
Fix possible NULL pointer dereference in ffec_alloc_mbufcl().

PR: 231514
Approved by: re (kib)
MFC after: 1 week

5 years agoInclude kernel ident in uname
emaste [Fri, 21 Sep 2018 13:43:06 +0000 (13:43 +0000)]
Include kernel ident in uname

In non-reproducible mode we have the kernel ident as a side effect of
including the build directory.  Explicitly add it to the ident string in
reproducible mode.

Reported by: mjg
Approved by: re (gjb)
Sponsored by: The FreeBSD Foundation

5 years agoselect: stop doing zero-sized memsets
mjg [Fri, 21 Sep 2018 13:20:41 +0000 (13:20 +0000)]
select: stop doing zero-sized memsets

Approved by: re (kib)

5 years agoremove double space between branch and version in kernel ident
emaste [Fri, 21 Sep 2018 13:02:25 +0000 (13:02 +0000)]
remove double space between branch and version in kernel ident

Reported by: dim
Approved by: re (kib)
Sponsored by: The FreeBSD Foundation

5 years agoamd64: check for small size in memmove, memcpy and memset
mjg [Fri, 21 Sep 2018 12:27:36 +0000 (12:27 +0000)]
amd64: check for small size in memmove, memcpy and memset

If the size is 15 bytes or less avoid spinning up rep just to copy the 8
bytes. In my tests on EPYC and old Intel microarchs without ERMS (like
Westmere) it provided a nice win over the current version (e.g. for EPYC
memset with 15 bytes of size goes from 59712651 ops/s to 70600095) all
while almost not pessimizing the other cases.

Data collected during package building shows that < 16 sizes are pretty
common.

Verified with the glibc test suite.

Approved by: re (kib)

5 years agoAdd an installer option to disable destructive dtrace.
des [Fri, 21 Sep 2018 09:27:32 +0000 (09:27 +0000)]
Add an installer option to disable destructive dtrace.

Submitted by: Jörg Pernfuß <code.jpe@gmail.com>
Approved by: re (kib)
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D12474

5 years agoMention setting $lines to 0 in ddb can disable paging
lwhsu [Fri, 21 Sep 2018 07:36:02 +0000 (07:36 +0000)]
Mention setting $lines to 0 in ddb can disable paging

Reviewed by: bcr (earlier version), markj
Approved by: re (kib), markj (mentor)
MFC after: 3 days
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17068

5 years agofix vlan locking to permit sx acquisition in ioctl calls
mmacy [Fri, 21 Sep 2018 01:37:08 +0000 (01:37 +0000)]
fix vlan locking to permit sx acquisition in ioctl calls

- update vlan(9) to handle changes earlier this year in multicast locking

Tested by: np@, darkfiberu at gmail.com

PR: 230510
Reviewed by: mjoras@, shurd@, sbruno@
Approved by: re (gjb@)
Sponsored by: Limelight Networks
Differential Revision: https://reviews.freebsd.org/D16808

5 years agoUpdate head from ALPHA6 to ALPHA7 as part of the 12.0-RELEASE
gjb [Thu, 20 Sep 2018 23:59:42 +0000 (23:59 +0000)]
Update head from ALPHA6 to ALPHA7 as part of the 12.0-RELEASE
cycle.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation

5 years agoamd64: macroify copyin/copyout and provide erms variants, follow up
mjg [Thu, 20 Sep 2018 20:32:08 +0000 (20:32 +0000)]
amd64: macroify copyin/copyout and provide erms variants, follow up

Fix a fat-fingered typo with a "funny" side-effect: when doing copyin on a
cpu without ERMS and with size being a multiply of 8 a page fault would be
triggered resulting in EFAULT.

Pointy hat: mjg
Approved by: re (implicit)

5 years agoAdd IFCAP_TSO6 for igb
shurd [Thu, 20 Sep 2018 20:06:44 +0000 (20:06 +0000)]
Add IFCAP_TSO6 for igb

It seems igb supports TSO6, but the capability got lost in
the iflib update. Restore this capability.

PR: 231476
Reported by: lev
Reviewed by: erj
Approved by: re (gjb)
Sponsored by: Limelight Networks
Differential Revision: https://reviews.freebsd.org/D17242

5 years agoAdd new field max_hdrsize to struct encap_config.
ae [Thu, 20 Sep 2018 19:45:27 +0000 (19:45 +0000)]
Add new field max_hdrsize to struct encap_config.

It is currently unused and reserved for future use to keep KBI/KPI.
Also add several spare pointers to be able extend structure if it
will be needed.

Approved by: re (gjb)

5 years agoFix capabilities handling for iflib drivers
shurd [Thu, 20 Sep 2018 19:35:35 +0000 (19:35 +0000)]
Fix capabilities handling for iflib drivers

Various capabilities were not being handled correctly in the
SIOCSIFCAP handler. Specifically:

IFCAP_RXCSUM and IFCAP_RXCSUM_IPV6 could be set even if not supported

It was impossible to disable IFCAP_RXCSUM and/or IFCAP_RXCSUM_IPV6 via
ifconfig since it does ioctl() per command-line flag rather than combine
them into a single call.

IFCAP_VLAN_HWCSUM could not be modified via the ioctl()

Setting any combination of the three IFCAP_WOL flags would set only
IFCAP_WOL_MCAST | IFCAP_WOL_MAGIC. For example, setting only
IFCAP_WOL_UCAST would result in both IFCAP_WOL_MCAST and IFCAP_WOL_MAGIC
being enabled, but IFCAP_WOL_UCAST would not be enabled.

Because if_vlancap() was called before if_togglecapenable(), vlan flags
were sometimes not applied correctly.

Interfaces were being unnecessarily stopped and restarted for WoL

PR: 231151
Submitted by: Kaho Toshikazu <kaho@elam.kais.kyoto-u.ac.jp>
Reported by: Shirkdog <mshirk@daemon-security.com>
Reviewed by: galladin
Approved by: re (gjb)
Sponsored by: Limelight Networks
Differential Revision: https://reviews.freebsd.org/D17158

5 years agoamd64: macroify copyin/copyout and provide erms variants
mjg [Thu, 20 Sep 2018 18:30:17 +0000 (18:30 +0000)]
amd64: macroify copyin/copyout and provide erms variants

Reviewed by: kib
Approved by: re (gjb)
Differential Revision: https://reviews.freebsd.org/D17257

5 years agoEnsure that imports into per-domain kmem arenas are KVA_QUANTUM-aligned.
markj [Thu, 20 Sep 2018 18:29:55 +0000 (18:29 +0000)]
Ensure that imports into per-domain kmem arenas are KVA_QUANTUM-aligned.

The old code appears to assume that vmem_alloc() would import
size-aligned KVA chunks from the parent kernel_arena, but vmem doesn't
provide this guarantee.

Also remove the unused global RWX arena and add comments explaining why
we have per-domain arenas.

Reported by: alc
Reviewed by: alc, kib (previous version)
Approved by: re (gjb)
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17249

5 years agovfs: remove lookup_shared tunable
mjg [Thu, 20 Sep 2018 18:25:26 +0000 (18:25 +0000)]
vfs: remove lookup_shared tunable

Reviewed by: kib, jhb
Approved by: re (gjb)
Differential Revision: https://reviews.freebsd.org/D17253

5 years agoAdd iflib.4 manpage
shurd [Thu, 20 Sep 2018 18:24:32 +0000 (18:24 +0000)]
Add iflib.4 manpage

The new manpage documents the tunables and statistic sysctls exposed by
iflib.

Reviewed by: bcr
Approved by: re (gjb)
Sponsored by: Limelight Networks
Differential Revision: https://reviews.freebsd.org/D16920

5 years agoFix variable name typo in the bsdinstall ttys hardening code.
markj [Thu, 20 Sep 2018 16:37:50 +0000 (16:37 +0000)]
Fix variable name typo in the bsdinstall ttys hardening code.

Submitted by: Jörg Pernfuß <code.jpe@gmail.com>
Reviewed by: allanjude, dab, emaste
Approved by: re (gjb)
Differential Revision: https://reviews.freebsd.org/D12476

5 years agoIn icmp6_rip6_input(), once we have a lock, make sure the inp is
bz [Thu, 20 Sep 2018 15:45:53 +0000 (15:45 +0000)]
In icmp6_rip6_input(), once we have a lock, make sure the inp is
not freed.  This can happen since the list traversal and locking
was converted to epoch(9).  If the inp is marked "freed", skip it.

This prevents a NULL pointer deref panic in ip6_savecontrol_v4()
trying to access the socket hanging off the inp, which was gone
by the time we got there.

Reported by: andrew
Tested by: andrew
Approved by: re (gjb)

5 years agoChange the domain selection policy in kmem_back().
markj [Thu, 20 Sep 2018 15:45:12 +0000 (15:45 +0000)]
Change the domain selection policy in kmem_back().

Ensure that pages backing the same virtual large page come from the
same physical domain, as kmem_malloc_domain() does.

PR: 231038
Reviewed by: alc, kib
Approved by: re (gjb)
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17248

5 years agofd: prevent inlining of _fdrop thorough kern_descrip.c
mjg [Thu, 20 Sep 2018 13:32:40 +0000 (13:32 +0000)]
fd: prevent inlining of _fdrop thorough kern_descrip.c

fdrop is used in several places in the file and almost never has to call
_fdrop. Thus inlining it is a pure waste of space.

Approved by: re (kib)

5 years agoamd64: move fusufault after all users
mjg [Thu, 20 Sep 2018 13:29:43 +0000 (13:29 +0000)]
amd64: move fusufault after all users

A lot of function have the following check:
        cmpq    %rax,%rdi                       /* verify address is valid */
        ja      fusufault

The label is present earlier in kernel .text, which means this is a jump
backwards. Absent any information in branch predictor, the cpu predicts it
as taken. Since it is almost never taken in practice, this results in a
completely avoidable misprediction.

Move it past all consumers, so that it is predicted as not taken.

Approved by: re (kib)

5 years agoMFV r338797:
mm [Thu, 20 Sep 2018 11:44:36 +0000 (11:44 +0000)]
MFV r338797:
Sync libarchive with vendor.

Relevant vendor changes:
  PR #1019: Add allocation check for the zip_entry struct
  Oss-Fuzz #10192: Handle whitespace-only ACL fields correctly

Approved by: re (kib)
MFC after: 1 week

5 years agoImport mandoc 1.14.4
bapt [Thu, 20 Sep 2018 10:58:52 +0000 (10:58 +0000)]
Import mandoc 1.14.4

Approved by: re (kib)
MFC after: 1 week

5 years agoMove the openssl.cnf install to secure/usr.bin/openssl/
brd [Thu, 20 Sep 2018 09:34:55 +0000 (09:34 +0000)]
Move the openssl.cnf install to secure/usr.bin/openssl/

This leverages CONFS to do the install

Approved by: re (pkgbase, blanket), bapt (mentor)
Differential Revision: https://reviews.freebsd.org/D17245

5 years agoMove nsmb.conf to lib/libsmb/
brd [Thu, 20 Sep 2018 09:31:27 +0000 (09:31 +0000)]
Move nsmb.conf to lib/libsmb/

This leverages CONFS to do the install

Approved by: re (pkgbase, blanket), bapt (mentor)
Differential Revision: https://reviews.freebsd.org/D17243

5 years agoMove opieaccess to lib/libopie/
brd [Thu, 20 Sep 2018 09:26:10 +0000 (09:26 +0000)]
Move opieaccess to lib/libopie/

This leverages CONFS to do the install

Approved by: re (blanket, pkgbase), bapt (mentor)
Differential Revision: https://reviews.freebsd.org/D17241

5 years agoMove hosts.lpd and printcap to usr.sbin/lpr/lpd/
brd [Thu, 20 Sep 2018 09:21:05 +0000 (09:21 +0000)]
Move hosts.lpd and printcap to usr.sbin/lpr/lpd/

This leverages CONFS to handle the install

Approved by: re (blanket, pkgbase), bapt (mentor)
Differential Revision: https://reviews.freebsd.org/D17238

5 years agoimport mandoc 1.14.1
bapt [Thu, 20 Sep 2018 07:33:14 +0000 (07:33 +0000)]
import mandoc 1.14.1

5 years agoVarious fixes for floating point on RISC-V.
jhb [Wed, 19 Sep 2018 23:45:18 +0000 (23:45 +0000)]
Various fixes for floating point on RISC-V.

- Explicitly load an empty initial state into FP registers when taking
  the fault on the first FP instruction in a thread.  Setting
  SSTATE.FS to INITIAL is just a marker to let context switch restore
  code know that it can load FP registers with zeroes instead of
  memory loads.  It does not imply that the hardware will reset all
  registers to zero on first access.  In addition, set the state to
  CLEAN instead of INITIAL after the first FP instruction.
  cpu_switch() doesn't do anything for INITIAL and only restores from
  the pcb if the state is CLEAN.  We could perhaps change cpu_switch
  to call fpe_state_clear if the state was INITIAL and leave SSTATE.FS
  set to INITIAL instead of CLEAN after the first FP instruction.
  However, adding this complexity to cpu_switch() doesn't seem worth
  the supposed gain.
- Only save the current FPU registers in fill_fpregs() if the request
  is made to save the current thread's registers.  Previously if a
  debugger requested FP registers via ptrace() it was getting a copy
  of the debugger's FP registers rather than the debugee's.
- Zero the entire FP register set structure returned for ptrace() if a
  thread hasn't used FP registers rather than leaking garbage in the
  fp_fcsr field.
- If a debugger writes FP registers via ptrace(), always mark the pcb
  as having valid FP registers and set SSTATUS.FS_MASK to CLEAN so
  that the registers will be restored when the debugged thread
  resumes.
- Be more explicit about clearing the SSTATUS.FS field before setting
  it to CLEAN on the first FP instruction trap.

Submitted by: br, markj
Approved by: re (rgrimes)
Sponsored by: DARPA
Differential Revision: https://reviews.freebsd.org/D17141