]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
6 years agoMFV r331400: 8484 Implement aggregate sum and use for arc counters
mav [Fri, 23 Mar 2018 02:15:05 +0000 (02:15 +0000)]
MFV r331400: 8484 Implement aggregate sum and use for arc counters

In pursuit of improving performance on multi-core systems, we should
implements fanned out counters and use them to improve the performance of
some of the arc statistics. These stats are updated extremely frequently,
and can consume a significant amount of CPU time.

Reviewed by: Pavel Zakharov <pavel.zakharov@delphix.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Approved by: Dan McDonald <danmcd@joyent.com>
Author: Paul Dagnelie <pcd@delphix.com>

6 years agoDebug interrupts aren't instruction traps
jhibbits [Fri, 23 Mar 2018 00:40:08 +0000 (00:40 +0000)]
Debug interrupts aren't instruction traps

The EXC_DEBUG type is akin to the MPC74xx "Instruction Breakpoint" trap.
Don't treat it as a trap instruction.

6 years ago8484 Implement aggregate sum and use for arc counters
mav [Fri, 23 Mar 2018 00:20:42 +0000 (00:20 +0000)]
8484 Implement aggregate sum and use for arc counters

In pursuit of improving performance on multi-core systems, we should
implements fanned out counters and use them to improve the performance of
some of the arc statistics. These stats are updated extremely frequently,
and can consume a significant amount of CPU time.

Reviewed by: Pavel Zakharov <pavel.zakharov@delphix.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Approved by: Dan McDonald <danmcd@joyent.com>
Author: Paul Dagnelie <pcd@delphix.com>

6 years agoRefactor ip6_getpcbopt() for better locking and memory management
sbruno [Thu, 22 Mar 2018 23:34:48 +0000 (23:34 +0000)]
Refactor ip6_getpcbopt() for better locking and memory management

Created GET_PKTOPT_EXT_HDR() and GET_PKTOPT_SOCKADDR() macros to
handle safely fetching options from in6p_outputopts, including
properly dealing with in6p locking and preparing memory for
sooptcopyout().

Changed the function signature of ip6_getpcbopt() to allow the
function to acquire and release locks on in6p as needed.

Submitted by: Jason Eggleston <jason@eggnet.com>
Sponsored by: Limelight Networks
Differential Revision: https://reviews.freebsd.org/D14619

6 years agoSimple locking fixes in ip_ctloutput, ip6_ctloutput, rip_ctloutput.
sbruno [Thu, 22 Mar 2018 22:29:32 +0000 (22:29 +0000)]
Simple locking fixes in ip_ctloutput, ip6_ctloutput, rip_ctloutput.

Submitted by: Jason Eggleston <jason@eggnet.com>
Sponsored by: Limelight Networks
Differential Revision: https://reviews.freebsd.org/D14624

6 years agoAdd missing NULL checks when calling malloc(M_NOWAIT) in
landonf [Thu, 22 Mar 2018 22:13:46 +0000 (22:13 +0000)]
Add missing NULL checks when calling malloc(M_NOWAIT) in
bhnd_nv_strdup/bhnd_nv_strndup.

If malloc(9) failed during initial bhnd(4) attach, while allocating the root
NVRAM path string ("/"), the returned NULL pointer would be passed as the
destination to memcpy().

Reported by: Ilja Van Sprundel <ivansprundel@ioactive.com>

6 years agoHandle locking and memory safety for IPV6_PATHMTU in ip6_ctloutput().
sbruno [Thu, 22 Mar 2018 21:18:34 +0000 (21:18 +0000)]
Handle locking and memory safety for IPV6_PATHMTU in ip6_ctloutput().

Submitted by: Jason Eggleston <jason@eggnet.com>
Reviewed by: ae
Sponsored by: Limelight Networks
Differential Revision: https://reviews.freebsd.org/D14622

6 years agoDo not send signals to init directly from shutdown_nice(9), do it from
kib [Thu, 22 Mar 2018 20:47:25 +0000 (20:47 +0000)]
Do not send signals to init directly from shutdown_nice(9), do it from
the task context.

shutdown_nice() is used from the fast interrupt handlers, mostly for
console drivers, where we cannot lock blockable locks.  Schedule the
task in the fast queue to send the signal from the proper context.

Reviewed by: imp
Discussed with: bde
Sponsored by: The FreeBSD Foundation
MFC after: 1 week

6 years agoFixes for ptrace(PT_GETXSTATE_INFO) related to the padding in struct
kib [Thu, 22 Mar 2018 20:44:27 +0000 (20:44 +0000)]
Fixes for ptrace(PT_GETXSTATE_INFO) related to the padding in struct
ptrace_xstate_info).

struct ptrace_xstate_info has 64bit member but ends up with 32bit
one. As result, on amd64 there is a 32bit padding at the end, but not
on i386.

We must clear the padding before doing the copyout. For compat32 case,
we must copyout the structure which does not have the padding at the
end.  The later fixes 32bit gdb display of the YMM registers when
running on amd64 kernel.

Reported by: Vlad Tsyrklevich
Reviewed by: brooks (previous version)
Sponsored by: The FreeBSD Foundation
admbugs: 765
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D14794

6 years agoImprove write locking in ip6_ctloutput() with macros.
sbruno [Thu, 22 Mar 2018 20:21:05 +0000 (20:21 +0000)]
Improve write locking in ip6_ctloutput() with macros.

Submitted by: Jason Eggleston <jason@eggnet.com>
Sponsored by: Limelight Networks
Differential Revision: https://reviews.freebsd.org/D14620

6 years agoLock reservations with a dedicated lock in each reservation. Protect the
jeff [Thu, 22 Mar 2018 19:21:11 +0000 (19:21 +0000)]
Lock reservations with a dedicated lock in each reservation.  Protect the
vmd_free_count with atomics.

This allows us to allocate and free from reservations without the free lock
except where a superpage is allocated from the physical layer, which is
roughly 1/512 of the operations on amd64.

Use the counter api to eliminate cache conention on counters.

Reviewed by: markj
Tested by: pho
Sponsored by: Netflix, Dell/EMC Isilon
Differential Revision: https://reviews.freebsd.org/D14707

6 years agoStart witness much earlier in boot so that we can shrink the pend list and
jeff [Thu, 22 Mar 2018 19:11:43 +0000 (19:11 +0000)]
Start witness much earlier in boot so that we can shrink the pend list and
make it more immune to further change.

Reviewed by: markj, imp (Part of D14707)
Sponsored by: Netflix, Dell/EMC Isilon

6 years agoUse read_mostly and alignment tags to eliminate or limit false sharing.
jeff [Thu, 22 Mar 2018 19:06:50 +0000 (19:06 +0000)]
Use read_mostly and alignment tags to eliminate or limit false sharing.

Reviewed by: markj (Part of D14707)
Sponsored by: Netflix, Dell/EMC Isilon

6 years agoPull in r327101 from upstream llvm trunk (by Rafael Espindola):
dim [Thu, 22 Mar 2018 18:58:34 +0000 (18:58 +0000)]
Pull in r327101 from upstream llvm trunk (by Rafael Espindola):

  Don't treat .symver as a regular alias definition.

  This patch starts simplifying the handling of .symver.

  For now it just moves the responsibility for creating an alias down to
  the streamer. With that the asm streamer can pass a .symver unchanged,
  which is nice since gas cannot parse "foo@bar = zed".

  In a followup I hope to move the handling down to the writer so that
  we don't need special hacks for avoiding breaking names with @@@ on
  windows.

Pull in r327160 from upstream llvm trunk (by Rafael Espindola):

  Delay creating an alias for @@@.

  With this we only create an alias for @@@ once we know if it should
  use @ or @@. This avoids last minutes renames and hacks to handle MS
  names.

  This only handles the ELF writer. LTO still has issues with @@@
  aliases.

Pull in r327928 from upstream llvm trunk (by Vitaly Buka):

  Object: Move attribute calculation into RecordStreamer. NFC

  Summary: Preparation for D44274

  Reviewers: pcc, espindola

  Subscribers: hiraditya

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

Pull in r327930 from upstream llvm trunk (by Vitaly Buka):

  Object: Fix handling of @@@ in .symver directive

  Summary:
  name@@@nodename is going to be replaced with name@@nodename if symbols is
  defined in the assembled file, or name@nodename if undefined.
  https://sourceware.org/binutils/docs/as/Symver.html

  Fixes PR36623

  Reviewers: pcc, espindola

  Subscribers: mehdi_amini, hiraditya

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

Together, these changes fix handling of @@@ in .symver directives when
doing Link Time Optimization.

Reported by: Shawn Webb <shawn.webb@hardenedbsd.org>
MFC after: 3 months
X-MFC-With: r327952

6 years agoRe-work efidev ordering to fix efirt preloaded by loader on amd64
kevans [Thu, 22 Mar 2018 18:24:00 +0000 (18:24 +0000)]
Re-work efidev ordering to fix efirt preloaded by loader on amd64

On amd64, efi_enter calls fpu_kern_enter(). This may not be called until
fpuinitstate has been invoked, resulting in a kernel panic with
efirt_load="YES" in loader.conf(5).

Move fpuinitstate a little earlier in SI_SUB_DRIVERS so that we can squeeze
efirt between it and efirtc at SI_SUB_DRIVERS, SI_ORDER_ANY. efidev must be
after efirt and doesn't really need to be at SI_SUB_DEVFS, so drop it at
SI_SUB_DRIVER, SI_ORDER_ANY.

The not immediately obvious dependency of fpuinitstate by efirt has been
noted in both places.

Discussed with: kib, andrew
Reported by: Jakob Alvermark <jakob@alvermark.net>
X-MFC-With: r330868

6 years agoRemove google_accounts_manager from VM_RC_LIST in the GCE configuration
gjb [Thu, 22 Mar 2018 17:49:27 +0000 (17:49 +0000)]
Remove google_accounts_manager from VM_RC_LIST in the GCE configuration
file, no longer needed.

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

6 years agoDrop any recursed taking of Giant once and for all at the top of
imp [Thu, 22 Mar 2018 15:34:37 +0000 (15:34 +0000)]
Drop any recursed taking of Giant once and for all at the top of
kern_reboot(). The shutdown path is now safe to run without Giant.

Discussed with: kib@
Sponsored by: Netflix

6 years agoEnter into the EFI environment before dereferencing the runtime services
andrew [Thu, 22 Mar 2018 15:32:57 +0000 (15:32 +0000)]
Enter into the EFI environment before dereferencing the runtime services
pointer. This may be within the EFI address space and not the FreeBSD
kernel address space.

X-MFC-With: r330868
Sponsored by: DARPA, AFRL

6 years agoIncrease the size of the endpoint buffers. They are double buffered so
andrew [Thu, 22 Mar 2018 15:24:26 +0000 (15:24 +0000)]
Increase the size of the endpoint buffers. They are double buffered so
need to be twice the size.

Sponsored by: DARPA, AFRL

6 years agoRevert r331298
imp [Thu, 22 Mar 2018 15:11:53 +0000 (15:11 +0000)]
Revert r331298

Normally, shutdown_nice() just signals init. However, sometimes it
calls kern_reboot directly. For that case, r331298 dropped the Giant
lock before calling it. This turns out to be incorrect for the more
common case where init exists and we just signal it. Restore the old
behavior. The direct call to kern_reboot() doesn't sync buffers to the
disk, so should work with Giant held, so we don't need to drop locks
here for that.

Noticed by: bde@
Sponsored by: Netflix

6 years agotftpd: misc Coverity cleanup in the tests
asomers [Thu, 22 Mar 2018 14:51:05 +0000 (14:51 +0000)]
tftpd: misc Coverity cleanup in the tests

A bunch of unchecked return values from open(2) and read(2)

Reported by: Coverity
CID: 138690013869111386926138692813869321386942
CID: 13869611386979
MFC after: 8 days
X-MFC-With: 330696

6 years agoThe pci_disable_device() function is also expected to clear the PCI
hselasky [Thu, 22 Mar 2018 13:30:35 +0000 (13:30 +0000)]
The pci_disable_device() function is also expected to clear the PCI
busmaster. This fixes LinuxKPI compliancy with Linux.

MFC after: 1 week
Sponsored by: Mellanox Technologies

6 years agoShare Linux errno table with libsysdecode
emaste [Thu, 22 Mar 2018 12:58:49 +0000 (12:58 +0000)]
Share Linux errno table with libsysdecode

Requested by: jhb
Reviewed by: jhb
Sponsored by: Turing Robotic Industries Inc.

6 years agoClear old MSIX IRQ numbers in the LinuxKPI.
hselasky [Thu, 22 Mar 2018 12:26:27 +0000 (12:26 +0000)]
Clear old MSIX IRQ numbers in the LinuxKPI.

When disabling the MSIX IRQ vectors for a PCI device through the
LinuxKPI, make sure any old MSIX IRQ numbers are no longer visible to
the linux_pci_find_irq_dev() function else IRQs can be requested from
the wrong PCI device.

MFC after: 1 week
Sponsored by: Mellanox Technologies

6 years agoPartially revert r328780
kevans [Thu, 22 Mar 2018 11:57:59 +0000 (11:57 +0000)]
Partially revert r328780

efi.4th was added to ObsoleteFiles and disconnected from the build, but not
removed from hte repo. We've since found a mild use for it that makes some
amount of sense, so partially revert r328780 and bring it back to life.

Reported by: many
X-MFC-With: r331326

6 years agoBump netstat.1's .Dd after r331347.
jtl [Thu, 22 Mar 2018 09:43:15 +0000 (09:43 +0000)]
Bump netstat.1's .Dd after r331347.

6 years agoAdd the "TCP Blackbox Recorder" which we discussed at the developer
jtl [Thu, 22 Mar 2018 09:40:08 +0000 (09:40 +0000)]
Add the "TCP Blackbox Recorder" which we discussed at the developer
summits at BSDCan and BSDCam in 2017.

The TCP Blackbox Recorder allows you to capture events on a TCP connection
in a ring buffer. It stores metadata with the event. It optionally stores
the TCP header associated with an event (if the event is associated with a
packet) and also optionally stores information on the sockets.

It supports setting a log ID on a TCP connection and using this to correlate
multiple connections that share a common log ID.

You can log connections in different modes. If you are doing a coordinated
test with a particular connection, you may tell the system to put it in
mode 4 (continuous dump). Or, if you just want to monitor for errors, you
can put it in mode 1 (ring buffer) and dump all the ring buffers associated
with the connection ID when we receive an error signal for that connection
ID. You can set a default mode that will be applied to a particular ratio
of incoming connections. You can also manually set a mode using a socket
option.

This commit includes only basic probes. rrs@ has added quite an abundance
of probes in his TCP development work. He plans to commit those soon.

There are user-space programs which we plan to commit as ports. These read
the data from the log device and output pcapng files, and then let you
analyze the data (and metadata) in the pcapng files.

Reviewed by: gnn (previous version)
Obtained from: Netflix, Inc.
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D11085

6 years agoFix build.
lwhsu [Thu, 22 Mar 2018 08:32:39 +0000 (08:32 +0000)]
Fix build.

Reviewed by: cem
Differential Revision: https://reviews.freebsd.org/D14793

6 years agojedec_dimm: Use correct string length when populating sc->slotid_str
rpokala [Thu, 22 Mar 2018 06:31:05 +0000 (06:31 +0000)]
jedec_dimm: Use correct string length when populating sc->slotid_str

Don't limit the copy to the size of the target string *pointer* (always
4 on 32-bit / 8 on 64-bit). Instead, just use strdup().

Reported by: Coverity
CID: 1386912
Reviewed by: cem, imp
MFC after: 1 week

6 years agoRedo r331328. We need to fix not only type but also format. While
glebius [Thu, 22 Mar 2018 05:26:27 +0000 (05:26 +0000)]
Redo r331328. We need to fix not only type but also format. While
here again notice that we are fixing regression from r331106.

6 years agoFix LINT-NOINET build initializing local to false. This is
glebius [Thu, 22 Mar 2018 05:07:57 +0000 (05:07 +0000)]
Fix LINT-NOINET build initializing local to false. This is
a dead code, since for NOINET build isipv6 is always true,
but this dead code makes it compilable.

Reported by: rpokala

6 years agocxgbe(4): Do not read MFG diags information from custom boards.
np [Thu, 22 Mar 2018 04:42:29 +0000 (04:42 +0000)]
cxgbe(4): Do not read MFG diags information from custom boards.

MFC after: 1 week
Sponsored by: Chelsio Communications

6 years agoforthloader: Don't break BIOS boots...
kevans [Thu, 22 Mar 2018 04:16:14 +0000 (04:16 +0000)]
forthloader: Don't break BIOS boots...

I thought I tested this scenario, but clearly I failed to. =(

BIOS boots won't have efi-autoresizecons, so trying to use it as a forth
word fails during include. Use evaluate on "efi-autoresizecons" as a string
instead to move any potential errors to runtime- safely after we've already
checked that we're booting UEFI.

Pointy hat to: me
Reported by: cy

6 years agocxgbe(4): Tunnel congestion drops on a port should be cleared when the
np [Thu, 22 Mar 2018 02:04:57 +0000 (02:04 +0000)]
cxgbe(4): Tunnel congestion drops on a port should be cleared when the
stats for that port are cleared.

MFC after: 1 week
Sponsored by: Chelsio Communications

6 years agoCorrect signedness bug in drm_modeset_ctl
emaste [Thu, 22 Mar 2018 01:00:55 +0000 (01:00 +0000)]
Correct signedness bug in drm_modeset_ctl

drm_modeset_ctl() takes a signed in from userland, does a boundscheck,
and then uses it to index into a structure and write to it.  The
boundscheck only checks upper bound, and never checks for nagative
values.  If the int coming from userland is negative [after conversion]
it will bypass the boundscheck, perform a negative index into an array
and write to it, causing memory corruption.

Note that this is in the "old" drm driver; this issue does not exist
in drm2.

Reported by: Ilja Van Sprundel <ivansprundel@ioactive.com>
Reviewed by: cem
MFC after: 1 day
Sponsored by: The FreeBSD Foundation

6 years agogetentropy(3): Fallback to kern.arandom sysctl on older kernels
cem [Wed, 21 Mar 2018 23:52:37 +0000 (23:52 +0000)]
getentropy(3): Fallback to kern.arandom sysctl on older kernels

On older kernels, when userspace program disables SIGSYS, catch ENOSYS and
emulate getrandom(2) syscall with the kern.arandom sysctl (via existing
arc4_sysctl wrapper).

Special care is taken to faithfully emulate EFAULT on NULL pointers, because
sysctl(3) as used by kern.arandom ignores NULL oldp.  (This was caught by
getentropy(3) ATF tests.)

Reported by: kib
Reviewed by: kib
Discussed with: delphij
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D14785

6 years agoFix kernel memory disclosure in drm_infobufs
emaste [Wed, 21 Mar 2018 23:51:14 +0000 (23:51 +0000)]
Fix kernel memory disclosure in drm_infobufs

drm_infobufs() has a structure on the stack, fills it out and copies it
to userland.  There are 2 elements in the struct that are not filled out
and left uninitialized.  This will leak uninitialized kernel stack data
to userland.

Submitted by: Domagoj Stolfa <ds815@cam.ac.uk>
Reported by: Ilja Van Sprundel <ivansprundel@ioactive.com>
MFC after: 1 day
Security: Kernel memory disclosure (798)

6 years agoIf a jail parameter isn't found, try loading a related kernel module.
jamie [Wed, 21 Mar 2018 23:50:46 +0000 (23:50 +0000)]
If a jail parameter isn't found, try loading a related kernel module.

6 years agoApply r228478 (CTASSERT => _Static_assert()) to stand bootstrap.h
cem [Wed, 21 Mar 2018 23:46:26 +0000 (23:46 +0000)]
Apply r228478 (CTASSERT => _Static_assert()) to stand bootstrap.h

Reported by: GCC (it doesn't like the unused array)
Sponsored by: Dell EMC Isilon

6 years agoFix kernel memory disclosure in ibcs2_getdents
emaste [Wed, 21 Mar 2018 23:26:42 +0000 (23:26 +0000)]
Fix kernel memory disclosure in ibcs2_getdents

ibcs2_getdents() copies a dirent structure to userland.  The ibcs2
dirent structure contains a 2 byte pad element.  This element is never
initialized, but copied to userland none-the-less.

Note that ibcs2 has not built on HEAD since r302095.

Submitted by: Domagoj Stolfa <ds815@cam.ac.uk>
Reported by: Ilja Van Sprundel <ivansprundel@ioactive.com>
MFC after: 3 days
Security: Kernel memory disclosure (803)

6 years agoFix sysctl types broken in r329612.
glebius [Wed, 21 Mar 2018 23:21:32 +0000 (23:21 +0000)]
Fix sysctl types broken in r329612.

6 years agoAdd ) missing from r330297
emaste [Wed, 21 Mar 2018 23:17:26 +0000 (23:17 +0000)]
Add ) missing from r330297

Sponsored by: The FreeBSD Foundation

6 years agoForth version of EFI autoresizing
kevans [Wed, 21 Mar 2018 22:01:51 +0000 (22:01 +0000)]
Forth version of EFI autoresizing

r331321 delegated autoresizing to an efi-autoresizecons command that
currently is expected to be done in forth/lua prior to drawing anything
useful.

Add the Forth version of the lua addition in r331321, hook efi.4th up to be
installed.

efiboot? was written by dteske@; anything outside of that may be blamed on
me.

6 years agoElide the object lock in the common case in vfs_vmio_unwire().
markj [Wed, 21 Mar 2018 21:15:43 +0000 (21:15 +0000)]
Elide the object lock in the common case in vfs_vmio_unwire().

The object lock was only needed when attempting to free B_DIRECT
buffer pages, and for testing for invalid pages (and freeing them
if so). Handle the latter by instead moving invalid pages near the head
of the inactive queue, where they will be reclaimed quickly.

Reviewed by: alc, kib, jeff
MFC after: 3 weeks
Differential Revision: https://reviews.freebsd.org/D14778

6 years agoEnsure thread library is initialized in pthread_testcancel().
jhb [Wed, 21 Mar 2018 21:13:26 +0000 (21:13 +0000)]
Ensure thread library is initialized in pthread_testcancel().

Call _thr_check_init() before reading curthread in pthread_testcancel().

If a constructor in a library creates a semaphore via sem_init() and
then waits for it via sem_wait(), the program can core dump in
_pthread_testcancel() called from sem_wait().  This is because the
semaphore implementation lives in libc, so the library's constructors
can be run before libthr's constructors.

Reported by: arichardson
Reviewed by: kib
Obtained from: CheriBSD
MFC after: 1 week
Sponsored by: DARPA / AFRL
Differential Revision: https://reviews.freebsd.org/D14786

6 years agoThe net.inet.tcp.nolocaltimewait=1 optimization prevents local TCP connections
glebius [Wed, 21 Mar 2018 20:59:30 +0000 (20:59 +0000)]
The net.inet.tcp.nolocaltimewait=1 optimization prevents local TCP connections
from entering the TIME_WAIT state. However, it omits sending the ACK for the
FIN, which results in RST. This becomes a bigger deal if the sysctl
net.inet.tcp.blackhole is 2. In this case RST isn't send, so the other side of
the connection (also local) keeps retransmitting FINs.

To fix that in tcp_twstart() we will not call tcp_close() immediately. Instead
we will allocate a tcptw on stack and proceed to the end of the function all
the way to tcp_twrespond(), to generate the correct ACK, then we will drop the
last PCB reference.

While here, make a few tiny improvements:
- use bools for boolean variable
- staticize nolocaltimewait
- remove pointless acquisiton of socket lock

Reported by: jtl
Reviewed by: jtl
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D14697

6 years agoUEFI: Ditch console mode setting, choose optimal GOP mode later in boot
kevans [Wed, 21 Mar 2018 20:36:57 +0000 (20:36 +0000)]
UEFI: Ditch console mode setting, choose optimal GOP mode later in boot

boot1 is too early to be deciding a good resolution. Console modes don't map
cleanly/predictably to actual screen resolutions, and GOP does not reflect
the actual screen resolution after a console mode change. Rip it out.

Add an efi-autoresizecons command to loader to choose an optimal screen
resolution based on the current environment. We'll explicitly execute this
later, preferably before we draw anything of value but after we load config
and pick up any tunables we may need to decide where we're going.

This method also allows us to actually pass the correct framebuffer
information on to the kernel.

UGA autoresizing is not implemented because it doesn't have the kind of mode
enumeration that GOP does. If an interested person with relevant hardware
could get in contact, we can take a look at implementing UGA autoresize.

This effectively "fixes" the breakage caused by r327058, but doesn't
actually set the resolution correctly until the interpreter calls
efi-autoresizcons. The lualoader version of this has been included for
reference; the forth equivalent will follow.

Reviewed by: imp (with some hestitation), manu
Differential Revision: https://reviews.freebsd.org/D14788

6 years agolualoader: Use printc when we expect ANSI escape sequences
kevans [Wed, 21 Mar 2018 18:02:56 +0000 (18:02 +0000)]
lualoader: Use printc when we expect ANSI escape sequences

6 years agoDocument the limitations associated with using the audit syscalls
csjp [Wed, 21 Mar 2018 17:22:42 +0000 (17:22 +0000)]
Document the limitations associated with using the audit syscalls
from jailed process.  These might get implemented in jails in the
future, but for now they are not supported.

Discussed on:   freebsd-security@
Reviewed by:    brueffer@
MFC after:      2 weeks

6 years agoImport Blake2 algorithms (blake2b, blake2s) from libb2
cem [Wed, 21 Mar 2018 16:18:14 +0000 (16:18 +0000)]
Import Blake2 algorithms (blake2b, blake2s) from libb2

The upstream repository is on github BLAKE2/libb2.  Files landed in
sys/contrib/libb2 are the unmodified upstream files, except for one
difference:  secure_zero_memory's contents have been replaced with
explicit_bzero() only because the previous implementation broke powerpc
link.  Preferential use of explicit_bzero() is in progress upstream, so
it is anticipated we will be able to drop this diff in the future.

sys/crypto/blake2 contains the source files needed to port libb2 to our
build system, a wrapped (limited) variant of the algorithm to match the API
of our auth_transform softcrypto abstraction, incorporation into the Open
Crypto Framework (OCF) cryptosoft(4) driver, as well as an x86 SSE/AVX
accelerated OCF driver, blake2(4).

Optimized variants of blake2 are compiled for a number of x86 machines
(anything from SSE2 to AVX + XOP).  On those machines, FPU context will need
to be explicitly saved before using blake2(4)-provided algorithms directly.
Use via cryptodev / OCF saves FPU state automatically, and use via the
auth_transform softcrypto abstraction does not use FPU.

The intent of the OCF driver is mostly to enable testing in userspace via
/dev/crypto.  ATF tests are added with published KAT test vectors to
validate correctness.

Reviewed by: jhb, markj
Obtained from: github BLAKE2/libb2
Differential Revision: https://reviews.freebsd.org/D14662

6 years agocryptosoft(4): Zero plain hash contexts, too
cem [Wed, 21 Mar 2018 16:12:07 +0000 (16:12 +0000)]
cryptosoft(4): Zero plain hash contexts, too

An OCF-naive user program could use these primitives to implement HMAC, for
example.  This would make the freed context sensitive data.

Probably other bzeros in this file should be explicit_bzeros as well.
Future work.

Reviewed by: jhb, markj
Differential Revision: https://reviews.freebsd.org/D14662 (minor part of a larger work)

6 years agoUpdate copyright per Matthew Macy
shurd [Wed, 21 Mar 2018 15:57:36 +0000 (15:57 +0000)]
Update copyright per Matthew Macy

"Under my tutelage Nicole did 85% of the work. At the time it seemed
simplest for a number of reasons to put my copyright on it. I now consider
that to have been a mistake."

Submitted by: Matthew Macy <mmacy@mattmacy.io>
Reviewed by: shurd
Approved by: shurd
Differential Revision: https://reviews.freebsd.org/D14766

6 years agoIf the INP lock is uncontested, avoid taking a reference and jumping
jtl [Wed, 21 Mar 2018 15:54:46 +0000 (15:54 +0000)]
If the INP lock is uncontested, avoid taking a reference and jumping
through the lock-switching hoops.

A few of the INP lookup operations that lock INPs after the lookup do
so using this mechanism (to maintain lock ordering):

1. Lock lookup structure.
2. Find INP.
3. Acquire reference on INP.
4. Drop lock on lookup structure.
5. Acquire INP lock.
6. Drop reference on INP.

This change provides a slightly shorter path for cases where the INP
lock is uncontested:

1. Lock lookup structure.
2. Find INP.
3. Try to acquire the INP lock.
4. If successful, drop lock on lookup structure.

Of course, if the INP lock is contested, the functions will need to
revert to the previous way of switching locks safely.

This saves a few atomic operations when the INP lock is uncontested.

Discussed with: gallatin, rrs, rwatson
MFC after: 2 weeks
Sponsored by: Netflix, Inc.
Differential Revision: https://reviews.freebsd.org/D12911

6 years agoUse a table to find the endpoint configuration
andrew [Wed, 21 Mar 2018 15:17:54 +0000 (15:17 +0000)]
Use a table to find the endpoint configuration

On the Allwinner SoCs we need to set a custom endpoint configuration. To
allow for this use a table to store the configuration so the attachment
can override it.

Reviewed by: hselasky
Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D14783

6 years agolualoader: Clear up some possible naming confusion
kevans [Wed, 21 Mar 2018 15:09:47 +0000 (15:09 +0000)]
lualoader: Clear up some possible naming confusion

In the original lualoader project, 'escapef' and 'escapeb' were chosen for
'escape fg' and 'escape bg'. We've carried on this naming convention, and as
our use of attributes grow the likeliness of 'escapeb'/'resetb' being
confused upon glance for 'escape bold'/'reset bold' increases.

Fix this by renaming these four functions to {escape,reset}{fg,bg} rather
than {escape,reset}{f,b} for clarity.

Reported by: dteske

6 years agoMark psycho interrupts as MPSAFE. It's safe to do so now that we don't
imp [Wed, 21 Mar 2018 14:47:17 +0000 (14:47 +0000)]
Mark psycho interrupts as MPSAFE. It's safe to do so now that we don't
need Giant to call shutdown_nice().

6 years agoUnlock giant when calling shutdown_nice()
imp [Wed, 21 Mar 2018 14:47:12 +0000 (14:47 +0000)]
Unlock giant when calling shutdown_nice()

6 years agoThis is MPSAFE on this platform, so don't take Giant out while running
imp [Wed, 21 Mar 2018 14:47:08 +0000 (14:47 +0000)]
This is MPSAFE on this platform, so don't take Giant out while running
the callback.

6 years agoThese interrupts call shutdown_nice() which should be called Giant
imp [Wed, 21 Mar 2018 14:47:03 +0000 (14:47 +0000)]
These interrupts call shutdown_nice() which should be called Giant
unlocked. Rather than dropping it in the interrupt handler, mark these
handlers as MPSAFE.

6 years agobufshutdown is no longer called with Giant held, so there's no need to
imp [Wed, 21 Mar 2018 14:46:59 +0000 (14:46 +0000)]
bufshutdown is no longer called with Giant held, so there's no need to
drop or pickup Giant anymore. Remove that code and adjust comments.

6 years agoRemove Giant from init creation and vfs_mountroot.
imp [Wed, 21 Mar 2018 14:46:54 +0000 (14:46 +0000)]
Remove Giant from init creation and vfs_mountroot.

Sponsored by: Netflix
Discussed with: kib@, mckusick@
Differential Review: https://reviews.freebsd.org/D14712

6 years agoAdd new shared library -- libipt.
br [Wed, 21 Mar 2018 14:37:04 +0000 (14:37 +0000)]
Add new shared library -- libipt.

libipt is the Intel Processor Trace (Intel PT) packets decoder.

- Include libipt to amd64 build.
- Install libipt headers to /usr/include/libipt/

Sponsored by: DARPA, AFRL

6 years agoFollowing ports commit r465175, avoid fetch(1) to obtain
gjb [Wed, 21 Mar 2018 14:36:16 +0000 (14:36 +0000)]
Following ports commit r465175, avoid fetch(1) to obtain
overlays and DTB files for the RPI3.

Submitted by: manu
Sponsored by: The FreeBSD Foundation

6 years agoRevert r331273: "Release the "TUR" reference when clearing the TUR work flag. We...
imp [Wed, 21 Mar 2018 12:55:59 +0000 (12:55 +0000)]
Revert r331273: "Release the "TUR" reference when clearing the TUR work flag. We mostly"

It exposes other issues, so revert to the pervious state of known issues.

6 years agoMove sysinit and sysuninit linker sets in the data (writeable) section.
kib [Wed, 21 Mar 2018 10:26:39 +0000 (10:26 +0000)]
Move sysinit and sysuninit linker sets in the data (writeable) section.

Both sets are sorted in place, and with the introduction of read-only
permissions on the amd64 kernel text, the sorting override depended on
CR0.WP turned off.  Make it correct by moving the sets into writeable
part of the KVA, also fixing boot on machines where hand-off from BIOS
to OS occurs with CR0.WP set.

Based on submission by: Peter Lei <peter.lei@ieee.org>
MFC after: 1 week

6 years ago[bsd-family-tree] Announce NetBSD 7.1.2
eadler [Wed, 21 Mar 2018 09:07:01 +0000 (09:07 +0000)]
[bsd-family-tree] Announce NetBSD 7.1.2

MFC After: 3 days

6 years agoAppease GCC 4.2
cem [Wed, 21 Mar 2018 04:44:19 +0000 (04:44 +0000)]
Appease GCC 4.2

It mistakenly believes the 'static' keyword must come first.  Fix PPC,
Sparc64, and maybe MIPS world.  Fallout from r331279.

Reported by: tinderbox (results come slowly)

6 years agoAdd missed sys/limits.h include
cem [Wed, 21 Mar 2018 03:43:40 +0000 (03:43 +0000)]
Add missed sys/limits.h include

Apparently header pollution on x86 hid its absense.  Sorry, other arch
users.

Fix the missed header introduced in r331279.

Reported by: tinderbox

6 years agocore.lua(8): Update to reflect recently added function clearCachedKernels
kevans [Wed, 21 Mar 2018 03:16:14 +0000 (03:16 +0000)]
core.lua(8): Update to reflect recently added function clearCachedKernels

6 years agolualoader: Add primitive hook module, use it to untangle bogus reference
kevans [Wed, 21 Mar 2018 03:07:16 +0000 (03:07 +0000)]
lualoader: Add primitive hook module, use it to untangle bogus reference

See: comments in the hook module about intended usage, as well as the
introduced use for config.reloaded.

Use the newly introduced hook module to define a "config.reloaded" hook.
This is currently used to register core's clearKernelCache as a reload hook
to avoid a circular dependency and fix this functionality- it didn't
actually work out, and it isn't immediately obvious how it slipped into src.

Other hook types will be introduced into the core lualoader as useful hook
points are identified.

6 years agoRegenerate sysent files after r331279.
cem [Wed, 21 Mar 2018 01:17:01 +0000 (01:17 +0000)]
Regenerate sysent files after r331279.

6 years agoImplement getrandom(2) and getentropy(3)
cem [Wed, 21 Mar 2018 01:15:45 +0000 (01:15 +0000)]
Implement getrandom(2) and getentropy(3)

The general idea here is to provide userspace programs with well-defined
sources of entropy, in a fashion that doesn't require opening a new file
descriptor (ulimits) or accessing paths (/dev/urandom may be restricted
by chroot or capsicum).

getrandom(2) is the more general API, and comes from the Linux world.
Since our urandom and random devices are identical, the GRND_RANDOM flag
is ignored.

getentropy(3) is added as a compatibility shim for the OpenBSD API.

truss(1) support is included.

Tests for both system calls are provided.  Coverage is believed to be at
least as comprehensive as LTP getrandom(2) test coverage.  Additionally,
instructions for running the LTP tests directly against FreeBSD are provided
in the "Test Plan" section of the Differential revision linked below.  (They
pass, of course.)

PR: 194204
Reported by: David CARLIER <david.carlier AT hardenedbsd.org>
Discussed with: cperciva, delphij, jhb, markj
Relnotes: maybe
Differential Revision: https://reviews.freebsd.org/D14500

6 years agoRepresent boolean jail options as an array of structures containing the
jamie [Tue, 20 Mar 2018 23:08:42 +0000 (23:08 +0000)]
Represent boolean jail options as an array of structures containing the
flag and both the regular and "no" names, instead of two different string
arrays whose indices need to match the flag's bit position.  This makes
them similar to the say "jailsys" options are represented.

Loop through either kind of option array with a structure pointer rather
then an integer index.

6 years agoCorrect comment date in r331255
emaste [Tue, 20 Mar 2018 23:08:04 +0000 (23:08 +0000)]
Correct comment date in r331255

Reported by: jhb

6 years agoUse count(9) api for the bpf(4) statistics.
melifaro [Tue, 20 Mar 2018 22:57:06 +0000 (22:57 +0000)]
Use count(9) api for the bpf(4) statistics.

Currently each bfp descriptor uses u64 variables to maintain its counters.
On interfaces with high packet rate this leads to unnecessary contention
and inaccurate reporting.

PR: kern/205320
Reported by: elofu17 at hotmail.com
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D14726

6 years agoExtend the description of ALTQ to call it a system which is a framework in
sevan [Tue, 20 Mar 2018 22:41:26 +0000 (22:41 +0000)]
Extend the description of ALTQ to call it a system which is a framework in
altq(4) to match altq(9). This makes preserving the history section as the
author of ALTQ easier in the history section, rather than calling it a framework
in the description & a system in the history.
Add a history section to altq(4) and extend the history section in altq(9)

Approved by: bcr (mentor)
MFC after: 5 days
Differential Revision:  https://reviews.freebsd.org/D14774

6 years agoRelease the "TUR" reference when clearing the TUR work flag. We mostly
imp [Tue, 20 Mar 2018 22:07:45 +0000 (22:07 +0000)]
Release the "TUR" reference when clearing the TUR work flag. We mostly
do this right, except when there's no BP and we do a TUR by request.
In that case, we clear the flag, but don't release the reference,
leaking the reference on rare occasion.

PR: 226510
Sponsored by: Netflix

6 years agoAt this point iwmesg isn't initialized yet, so print pointer to lock
glebius [Tue, 20 Mar 2018 22:05:21 +0000 (22:05 +0000)]
At this point iwmesg isn't initialized yet, so print pointer to lock
rather than panic before panicing.

6 years agoPush down Giant one layer. In the days of yore, back when Penitums
imp [Tue, 20 Mar 2018 22:01:18 +0000 (22:01 +0000)]
Push down Giant one layer. In the days of yore, back when Penitums
were the new kids on the block and F00F hacks were all the rage, one
needed to take out Giant to do anything moderately complicated with
the VM, mappings and such. So the pccard / cardbus code held Giant for
the entire insertion or removal process.

Today, the VM is MP safe. The lock is only needed for dealing with
newbus things. Move locking and unlocking Giant to be only around
adding and probing devices in pccard and cardbus.

6 years agoFix whitespace issues in r330034. No functional changes.
glebius [Tue, 20 Mar 2018 22:00:58 +0000 (22:00 +0000)]
Fix whitespace issues in r330034. No functional changes.

6 years agoRemove reference to lint. We no longer support it, so exceptions for
imp [Tue, 20 Mar 2018 21:37:33 +0000 (21:37 +0000)]
Remove reference to lint. We no longer support it, so exceptions for
it are no longer relevant.

6 years agoRevert part of r331264: disable interrupts before disabling WP.
markj [Tue, 20 Mar 2018 21:36:35 +0000 (21:36 +0000)]
Revert part of r331264: disable interrupts before disabling WP.

We might otherwise be preempted, leaving WP disabled while another
thread runs on the CPU.

Reported by: kib
X-MFC with: r331264

6 years agoUpdate to include information about using SPDX-License-Identifier
imp [Tue, 20 Mar 2018 21:31:18 +0000 (21:31 +0000)]
Update to include information about using SPDX-License-Identifier
lines.

6 years agoDrop support for lint for cdefs.h.
imp [Tue, 20 Mar 2018 21:18:40 +0000 (21:18 +0000)]
Drop support for lint for cdefs.h.

6 years agoRemove obsolete lint support.
imp [Tue, 20 Mar 2018 21:17:48 +0000 (21:17 +0000)]
Remove obsolete lint support.

6 years agoMake use of the KPI added in r331252.
markj [Tue, 20 Mar 2018 21:16:26 +0000 (21:16 +0000)]
Make use of the KPI added in r331252.

MFC after: 2 weeks

6 years agoRestore close quote lost in r331254
emaste [Tue, 20 Mar 2018 21:04:47 +0000 (21:04 +0000)]
Restore close quote lost in r331254

6 years agoUse <stdarg.h> instead of <machine/stdarg.h> in userland.
jhb [Tue, 20 Mar 2018 21:00:45 +0000 (21:00 +0000)]
Use <stdarg.h> instead of <machine/stdarg.h> in userland.

<machine/stdarg.h> is a kernel-only header.  The standard header for
userland is <stdarg.h>.  Using the standard header in userland avoids
weird build errors when building with external compilers that include
their own stdarg.h header.

Reviewed by: arichardson, brooks, imp
Sponsored by: DARPA / AFRL
Differential Revision: https://reviews.freebsd.org/D14776

6 years agoRemove a lingering inaccuracy from mlock.2.
markj [Tue, 20 Mar 2018 20:45:47 +0000 (20:45 +0000)]
Remove a lingering inaccuracy from mlock.2.

User wirings of the same address range don't stack.

Noted by: Dan Nelson
MFC after: 3 days

6 years agolualoader: Use less atomic options for resetting colors/attributes
kevans [Tue, 20 Mar 2018 20:26:24 +0000 (20:26 +0000)]
lualoader: Use less atomic options for resetting colors/attributes

Noted by dteske:

CSI 1m ... CSI 22m
CSI 2m ... CSI 22m
CSI 4m ... CSI 24m
CSI 5m ... CSI 25m
CSI 7m ... CSI 27m
CSI 8m ... CSI 28m
CSI (30-37)m ... CSI 39m
CSI (40-47)m ... CSI 49m

- Provide resetf/resetb to match escapef/escapeb
- Use CSI 22m to undo a bold

This is a more reasonable approach than what was previously taken.

Reported by: dteske

6 years agoMove the CR0.WP manipulation KPI to x86.
kib [Tue, 20 Mar 2018 20:20:49 +0000 (20:20 +0000)]
Move the CR0.WP manipulation KPI to x86.

This should allow to avoid some #ifdefs in the common x86/ code.

Requested by: markj
Sponsored by: The FreeBSD Foundation
MFC after: 1 week

6 years agolualoader: Reset attributes and color scheme with color.highlight()
kevans [Tue, 20 Mar 2018 20:05:11 +0000 (20:05 +0000)]
lualoader: Reset attributes and color scheme with color.highlight()

Previously, we sent a CSI 0m sequence to reset attributes, which also reset
the color scheme if the terminal defaults didn't match what we're expecting.
Go all-in and reset the color scheme, too, just in case.

Reported by: emaste

6 years agoMake linuxulator fn declaration match definition
emaste [Tue, 20 Mar 2018 19:28:52 +0000 (19:28 +0000)]
Make linuxulator fn declaration match definition

I accidentally swapped 'linux_fixup_elf' to 'linux_elf_fixup' in amd64's
declaration (only),  while bringing this change over from git and
encountering a conflict.

6 years agoRemove stale generated assym.s files after r331254
emaste [Tue, 20 Mar 2018 18:02:21 +0000 (18:02 +0000)]
Remove stale generated assym.s files after r331254

So that -DNO_CLEAN builds work.

This should be reverted after a sufficient transition period (perhaps 3
or 6 months).

Sponsored by: The FreeBSD Foundation

6 years agoRename assym.s to assym.inc
emaste [Tue, 20 Mar 2018 17:58:51 +0000 (17:58 +0000)]
Rename assym.s to assym.inc

assym is only to be included by other .s files, and should never
actually be assembled by itself.

Reviewed by: imp, bdrewery (earlier)
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D14180

6 years agoDisable write protection around patching of XSAVE instruction in the
kib [Tue, 20 Mar 2018 17:47:29 +0000 (17:47 +0000)]
Disable write protection around patching of XSAVE instruction in the
context switch code.

Some BIOSes give control to the OS with CR0.WP already set, making the
kernel text read-only before cpu_startup().

Reported by: Peter Lei <peter.lei@ieee.org>
Reviewed by: jtl
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D14768

6 years agoProvide KPI for handling of rw/ro kernel text.
kib [Tue, 20 Mar 2018 17:43:50 +0000 (17:43 +0000)]
Provide KPI for handling of rw/ro kernel text.

This is a pure syntax patch to create an interface to enable and later
restore write access to the kernel text and other read-only mapped
regions.  It is in line with e.g. vm_fault_disable_pagefaults() by
allowing the nesting.

Discussed with: Peter Lei <peter.lei@ieee.org>
Reviewed by: jtl
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D14768

6 years agoSet the proper vnet in IPsec callback functions.
jhb [Tue, 20 Mar 2018 17:05:23 +0000 (17:05 +0000)]
Set the proper vnet in IPsec callback functions.

When using hardware crypto engines, the callback functions used to handle
an IPsec packet after it has been encrypted or decrypted can be invoked
asynchronously from a worker thread that is not associated with a vnet.
Extend 'struct xform_data' to include a vnet pointer and save the current
vnet in this new member when queueing crypto requests in IPsec.  In the
IPsec callback routines, use the new member to set the current vnet while
processing the modified packet.

This fixes a panic when using hardware offload such as ccr(4) with IPsec
after VIMAGE was enabled in GENERIC.

Reported by: Sony Arpita Das and Harsh Jain @ Chelsio
Reviewed by: bz
MFC after: 1 week
Sponsored by: Chelsio Communications
Differential Revision: https://reviews.freebsd.org/D14763

6 years agoCheck for wrap-around in vm_phys_alloc_seg_contig().
kib [Tue, 20 Mar 2018 16:17:55 +0000 (16:17 +0000)]
Check for wrap-around in vm_phys_alloc_seg_contig().

It is possible to provide insane values for size in contigmalloc(9)
request, which usually not reaches the phys allocator due to failing
KVA allocation.  But with the forthcoming 4/4 i386, where 32bit
architecture has almost 4G KVA, contigmalloc(1G) is not unreasonable
outright and KVA might be available sometimes.

Then, the calculation of pa_end could wrap around, depending on the
physical address, and the checks in vm_phys_alloc_seg_contig() would
pass while the iteration in the loop after the 'done' label goes out
of the vm_page_array bounds.

Fix it by detecting the wrap.

Reported and tested by: pho
Reviewed by: alc, markj
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D14767

6 years agoDrop KTR_CONTENTION.
markj [Tue, 20 Mar 2018 15:51:05 +0000 (15:51 +0000)]
Drop KTR_CONTENTION.

It is incomplete, has not been adopted in the other locking primitives,
and we have other means of measuring lock contention (lock_profiling,
lockstat, KTR_LOCK). Drop it to slightly de-clutter the mutex code and
free up a precious KTR class index.

Reviewed by: jhb, mjg
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D14771