]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
5 years agoMFC r345087: Use consistent struct stat arg name in stat man page
emaste [Wed, 20 Mar 2019 03:50:45 +0000 (03:50 +0000)]
MFC r345087: Use consistent struct stat arg name in stat man page

stat, lstat, and fstat use `*sb` as the stat struct pointer arg name,
while fstatat previously used `*buf`.

5 years agoif_tun: Fix MFC r344794:
kp [Wed, 20 Mar 2019 01:55:24 +0000 (01:55 +0000)]
if_tun: Fix MFC r344794:

VNET_DEFINE_STATIC does not exist on stable/11, so we should use 'static
VNET_DEFINE' instead.

5 years agoPartially MFC r345079 + direct commit to stable/11.
cy [Tue, 19 Mar 2019 19:57:37 +0000 (19:57 +0000)]
Partially MFC r345079 + direct commit to stable/11.

The MFC updates tools/build/mk/OptionalObsoleteFiles.inc.

The direct commit updates etc/rc.d/Makefile becasue this file was moved
in HEAD to libexec/rc/rc.d/Makefile, making svn merge impossible.

The original log message follows:

Fix still installing ipfilter rc.d files even when WITHOUT_IPFILTER
is specified.

When WITHOUT_IPFILTER is specified, delete-old-files fails to delete
the optional rc.d files from above. Fix this.

WITHOUT_IPFILTER fails to delete the ipfilter.5 optional file during
delete-old-files. Fix this.

Reported by: Dmitry Luhtionov <dmitryluhtionov@gmail.com>

5 years agoMFC r344794:
kp [Tue, 19 Mar 2019 00:27:48 +0000 (00:27 +0000)]
MFC r344794:

tun: VIMAGE fix for if_tun cloner

The if_tun cloner is not virtualised, but if_clone_attach() does use a
virtualised list of cloners.
The result is that we can't find the if_tun cloner when we try to remove
a renamed tun interface. Virtualise the cloner, and move the final
cleanup into a sysuninit so that we're sure this happens after all of
the vnet_sysuninits

Note that we need unit numbers to be system-unique (rather than unique
per vnet, as is done by if_clone_simple()). The unit number is used to
create the corresponding /dev/tunX device node, and this node must match
with the interface.
Switch to if_clone_advanced() so that we have control over the unit
numbers.

Reproduction scenario:
jail -c -n foo persist vnet
jexec test ifconfig tun create
jexec test ifconfig tun0 name wg0
jexec test ifconfig wg0 destroy

PR: 235704
Reviewed by: bz, hrs, hselasky
Differential Revision: https://reviews.freebsd.org/D19248

5 years agoMFC r345189:
kib [Mon, 18 Mar 2019 10:28:40 +0000 (10:28 +0000)]
MFC r345189:
Add symbolic name for TSC_AUX MSR address.

5 years agoMFC r345004 (with modification):
ae [Mon, 18 Mar 2019 09:31:23 +0000 (09:31 +0000)]
MFC r345004 (with modification):
  Add IP_FW_NAT64 to codes that ipfw_chk() can return.

  It will be used by upcoming NAT64 changes. We use separate code
  to avoid propogating EACCES error code to user level applications
  when NAT64 consumes a packet.

  Obtained from: Yandex LLC
  Sponsored by: Yandex LLC

5 years agoMFC r345003:
ae [Mon, 18 Mar 2019 09:23:15 +0000 (09:23 +0000)]
MFC r345003:
  Add NULL pointer check to nat64_output().

  It is possible that a processed packet was originated by local host,
  in this case m->m_pkthdr.rcvif is NULL. Check and set it to V_loif to
  avoid NULL pointer dereference in IP input code, since it is expected
  that packet has valid receiving interface when netisr processes it.

  Obtained from:        Yandex LLC
  Sponsored by: Yandex LLC

5 years agoMFC r344745:
avos [Mon, 18 Mar 2019 02:58:34 +0000 (02:58 +0000)]
MFC r344745:
urtwn(4): fix Tx instability with RTL8192CU chipsets

PR: 233949

5 years agoMFC r345075:
kib [Fri, 15 Mar 2019 18:53:36 +0000 (18:53 +0000)]
MFC r345075:
Add register number, CPUID bits, and print identification for TSX
force abort errata.

5 years agoMFC r345074:
kib [Fri, 15 Mar 2019 18:50:00 +0000 (18:50 +0000)]
MFC r345074:
Remove useless version check.

5 years agoMFC r342214:
markj [Fri, 15 Mar 2019 15:16:31 +0000 (15:16 +0000)]
MFC r342214:
Remove a use of a negative array index from fxp(4).

5 years agoMFC r344921:
kp [Fri, 15 Mar 2019 11:01:52 +0000 (11:01 +0000)]
MFC r344921:

pf: Fix DIOCGETSRCNODES

r343295 broke DIOCGETSRCNODES by failing to reset 'nr' after counting the
number of source tracking nodes.
This meant that we never copied the information to userspace, leading to '? ->
?' output from pfctl.

PR: 236368

5 years agoMFC r344748:
avos [Fri, 15 Mar 2019 08:18:02 +0000 (08:18 +0000)]
MFC r344748:
Allow to build ifconfig(8) without wireless support

The change removes SIOC[GS]IEEE80211 handling from ifconfig(8)
if WITHOUT_WIRELESS_SUPPORT=yes is set in src.conf(5).

Reviewed by: bz
Differential Revision: https://reviews.freebsd.org/D19289

5 years agoMFC r344873:
ae [Thu, 14 Mar 2019 08:27:01 +0000 (08:27 +0000)]
MFC r344873:
  Fix typo.

5 years agoMFC r344903: Improve entropy for ZFS taskqueue selection.
mav [Thu, 14 Mar 2019 00:58:57 +0000 (00:58 +0000)]
MFC r344903: Improve entropy for ZFS taskqueue selection.

I just found that at least on Skylake CPUs cpu_ticks() never returns odd
values, only even, and possibly has even bigger step (176/2?), that makes
its lower bits very bad entropy source, leaving half of taskqueues unused.
Switch to sbinuptime(), closer to upstreams, mitigates the problem by the
rate conversion working as kind of hash function.  In case that is somehow
not enough (timer rate is too low or too divisible) mix in curcpu.

5 years agoMFC r344866: Add respective tunables to few ZFS sysctls.
mav [Thu, 14 Mar 2019 00:57:54 +0000 (00:57 +0000)]
MFC r344866: Add respective tunables to few ZFS sysctls.

5 years agoMFC r344844: Flush stdout after each iteration.
mav [Wed, 13 Mar 2019 20:29:10 +0000 (20:29 +0000)]
MFC r344844: Flush stdout after each iteration.

Without this, if output is redirected from the console, it is buffered for
too long, making tool quite unusable.

5 years agoMFC r344636: Refactor command ordering/blocking mechanism in CTL.
mav [Wed, 13 Mar 2019 20:28:07 +0000 (20:28 +0000)]
MFC r344636: Refactor command ordering/blocking mechanism in CTL.

Replace long per-LUN queue of blocked commands, scanned on each command
completion and sometimes even twice, causing up to O(n^^2) processing cost,
by much shorter per-command blocked queues, scanned only when respective
command completes, and check only commands before the previous blocker,
reducing cost to O(n).

While there, unblock aborted commands to make them "complete" ASAP to be
removed from the OOA queue and so not waste time ordering other commands
against them.  Aborted commands that were not sent to execution yet should
have no visible side effects, so this is safe and easy optimization now,
comparing to commands already in processing, which are a still pain.

Together those two optimizations should fix quite pathological case, when
due to backend slowness CTL accumulated many thousands of blocked requests,
partially aborted by initiator and so supposedly not even existing, but
still wasting CTL CPU time.

5 years agoMFC r344586: Scrap some debug printf's, unused for years.
mav [Wed, 13 Mar 2019 20:26:46 +0000 (20:26 +0000)]
MFC r344586: Scrap some debug printf's, unused for years.

5 years agoMFC r344818: freebsd-update.8: update example to contemporary versions
emaste [Tue, 12 Mar 2019 17:04:48 +0000 (17:04 +0000)]
MFC r344818: freebsd-update.8: update example to contemporary versions

PR: 235761
Reported by: linimon

5 years agoMFC r339299: Pull in a follow-on commit to resolve a deadlock in ZFS
mav [Tue, 12 Mar 2019 16:46:34 +0000 (16:46 +0000)]
MFC r339299: Pull in a follow-on commit to resolve a deadlock in ZFS
sequential resilver (r334844)

MFV/ZoL: Fix deadlock in IO pipeline

commit a76f3d0437e5e974f0f748f8735af3539443b388
Author: Brian Behlendorf <behlendorf1@llnl.gov>
Date:   Fri Mar 16 16:46:06 2018 -0700

    Fix deadlock in IO pipeline

    In vdev_queue_aggregate() the zio_execute() bypass should not be
    called under the vdev queue lock.  This can result in a deadlock
    as shown in the stack traces below.

    Drop the vdev queue lock then walk the parents of the aggregate IO
    to determine the list of component IOs to be bypassed.  This can
    be done safely without holding the io_lock since the new aggregate
    IO has not yet been returned and its parents cannot change.

    ---  THREAD 1 ---
    arc_read()
      zio_nowait()
        zio_vdev_io_start()
          vdev_queue_io() <--- mutex_enter(vq->vq_lock)
            vdev_queue_io_to_issue()
              vdev_queue_aggregate()
                zio_execute()
            vdev_queue_io_to_issue()
              vdev_queue_aggregate()
                zio_execute()
                  zio_vdev_io_assess()
                    zio_wait_for_children() <- mutex_enter(zio->io_lock)

    --- THREAD 2 --- (inverse order)
    arc_read()
      zio_change_priority() <- mutex_enter(zio->zio_lock)
        vdev_queue_change_io_priority() <- mutex_enter(vq->vq_lock)

Reviewed-by: Tom Caputi <tcaputi@datto.com>
Reviewed-by: Don Brady <don.brady@delphix.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
5 years agoMFC 318429,318967,319721,319723,323600,323724,328353-328361,330042,343056:
jhb [Mon, 11 Mar 2019 23:16:10 +0000 (23:16 +0000)]
MFC 318429,318967,319721,319723,323600,323724,328353-328361,330042,343056:
Add a driver for the Chelsio T6 crypto accelerator engine.

Note that with the set of commits in this batch, no additional tunables
are needed to use the driver once it is loaded.

318429:
Add a driver for the Chelsio T6 crypto accelerator engine.

The ccr(4) driver supports use of the crypto accelerator engine on
Chelsio T6 NICs in "lookaside" mode via the opencrypto framework.

Currently, the driver supports AES-CBC, AES-CTR, AES-GCM, and AES-XTS
cipher algorithms as well as the SHA1-HMAC, SHA2-256-HMAC, SHA2-384-HMAC,
and SHA2-512-HMAC authentication algorithms.  The driver also supports
chaining one of AES-CBC, AES-CTR, or AES-XTS with an authentication
algorithm for encrypt-then-authenticate operations.

Note that this driver is still under active development and testing and
may not yet be ready for production use.  It does pass the tests in
tests/sys/opencrypto with the exception that the AES-GCM implementation
in the driver does not yet support requests with a zero byte payload.

To use this driver currently, the "uwire" configuration must be used
along with explicitly enabling support for lookaside crypto capabilities
in the cxgbe(4) driver.  These can be done by setting the following
tunables before loading the cxgbe(4) driver:

    hw.cxgbe.config_file=uwire
    hw.cxgbe.cryptocaps_allowed=-1

318967:
Fail large requests with EFBIG.

The adapter firmware in general does not accept PDUs larger than 64k - 1
bytes in size.  Sending crypto requests larger than this size result in
hangs or incorrect output, so reject them with EFBIG.  For requests
chaining an AES cipher with an HMAC, the firmware appears to require
slightly smaller requests (around 512 bytes).

319721:
Add explicit handling for requests with an empty payload.

- For HMAC requests, construct a special input buffer to request an empty
  hash result.
- For plain cipher requests and requests that chain an AES cipher with an
  HMAC, fail with EINVAL if there is no cipher payload.  If needed in
  the future, chained requests that only contain AAD could be serviced as
  HMAC-only requests.
- For GCM requests, the hardware does not support generating the tag for
  an AAD-only request.  Instead, complete these requests synchronously
  in software on the assumption that such requests are rare.

319723:
Fix the software fallback for GCM to validate the existing tag for decrypts.

323600:
Fix some incorrect sysctl pointers for some error stats.

The bad_session, sglist_error, and process_error sysctl nodes were
returning the value of the pad_error node instead of the appropriate
error counters.

323724:
Enable support for lookaside crypto operations by default.

This permits ccr(4) to be used with the default firmware configuration
file.

328353:
Always store the IV in the immediate portion of a work request.

Combined authentication-encryption and GCM requests already stored the
IV in the immediate explicitly.  This extends this behavior to block
cipher requests to work around a firmware bug.  While here, simplify
the AEAD and GCM handlers to not include always-true conditions.

328354:
Always set the IV location to IV_NOP.

The firmware ignores this field in the FW_CRYPTO_LOOKASIDE_WR work
request.

328355:
Reject requests with AAD and IV larger than 511 bytes.

The T6 crypto engine's control messages only support a total AAD
length (including the prefixed IV) of 511 bytes.  Reject requests with
large AAD rather than returning incorrect results.

328356:
Don't discard AAD and IV output data for AEAD requests.

The T6 can hang when processing certain AEAD requests if the request
sets a flag asking the crypto engine to discard the input IV and AAD
rather than copying them into the output buffer.  The existing driver
always discards the IV and AAD as we do not need it.  As a workaround,
allocate a single "dummy" buffer when the ccr driver attaches and
change all AEAD requests to write the IV and AAD to this scratch
buffer.  The contents of the scratch buffer are never used (similar to
"bogus_page"), and it is ok for multiple in-flight requests to share
this dummy buffer.

328357:
Fail crypto requests when the resulting work request is too large.

Most crypto requests will not trigger this condition, but a request
with a highly-fragmented data buffer (and a resulting "large" S/G
list) could trigger it.

328358:
Clamp DSGL entries to a length of 2KB.

This works around an issue in the T6 that can result in DMA engine
stalls if an error occurs while processing a DSGL entry with a length
larger than 2KB.

328359:
Expand the software fallback for GCM to cover more cases.

- Extend ccr_gcm_soft() to handle requests with a non-empty payload.
  While here, switch to allocating the GMAC context instead of placing
  it on the stack since it is over 1KB in size.
- Allow ccr_gcm() to return a special error value (EMSGSIZE) which
  triggers a fallback to ccr_gcm_soft().  Move the existing empty
  payload check into ccr_gcm() and change a few other cases
  (e.g. large AAD) to fallback to software via EMSGSIZE as well.
- Add a new 'sw_fallback' stat to count the number of requests
  processed via the software fallback.

328360:
Don't read or generate an IV until all error checking is complete.

In particular, this avoids edge cases where a generated IV might be
written into the output buffer even though the request is failed with
an error.

328361:
Store IV in output buffer in GCM software fallback when requested.

Properly honor the lack of the CRD_F_IV_PRESENT flag in the GCM
software fallback case for encryption requests.

330042:
Don't overflow the ipad[] array when clearing the remainder.

After the auth key is copied into the ipad[] array, any remaining bytes
are cleared to zero (in case the key is shorter than one block size).
The full block size was used as the length of the zero rather than the
size of the remaining ipad[].  In practice this overflow was harmless as
it could only clear bytes in the following opad[] array which is
initialized with a copy of ipad[] in the next statement.

343056:
Reject new sessions if the necessary queues aren't initialized.

ccr reuses the control queue and first rx queue from the first port on
each adapter.  The driver cannot send requests until those queues are
initialized.  Refuse to create sessions for now if the queues aren't
ready.  This is a workaround until cxgbe allocates one or more
dedicated queues for ccr.

Relnotes: yes
Sponsored by: Chelsio Communications

5 years agoMFC 318388: Add sglist_append_sglist().
jhb [Mon, 11 Mar 2019 22:48:51 +0000 (22:48 +0000)]
MFC 318388: Add sglist_append_sglist().

This function permits a range of one scatter/gather list to be appended to
another sglist.  This can be used to construct a scatter/gather list that
reorders or duplicates ranges from one or more existing scatter/gather
lists.

Sponsored by: Chelsio Communications

5 years agoMFC 328453: Move per-operation data out of the csession structure.
jhb [Mon, 11 Mar 2019 22:17:53 +0000 (22:17 +0000)]
MFC 328453: Move per-operation data out of the csession structure.

Create a struct cryptop_data which contains state needed for a single
symmetric crypto operation and move that state out of the session. This
closes a race with the CRYPTO_F_DONE flag that can result in use after
free.

While here, remove the 'cse->error' member.  It was just a copy of
'crp->crp_etype' and cryptodev_op() and cryptodev_aead() checked both
'crp->crp_etype' and 'cse->error'.  Similarly, do not check for an
error from mtx_sleep() since it is not used with PCATCH or a timeout
so cannot fail with an error.

PR: 218597
Sponsored by: Chelsio Communications

5 years agoMFC 328057: Split crp_buf into a union.
jhb [Mon, 11 Mar 2019 21:56:35 +0000 (21:56 +0000)]
MFC 328057: Split crp_buf into a union.

This adds explicit crp_mbuf and crp_uio pointers of the right type to
replace casts of crp_buf.  This does not sweep through changing existing
code, but new code should use the correct fields instead of casts.

Sponsored by: Chelsio Communications

5 years agoMFC 327839: Change the type of 'crp_opaque' from caddr_t to void *.
jhb [Mon, 11 Mar 2019 21:51:15 +0000 (21:51 +0000)]
MFC 327839: Change the type of 'crp_opaque' from caddr_t to void *.

Opaque pointers should be void *.  Note that this does not go through
the tree removing all of the now-unnecessary casts.

Sponsored by: Chelsio Communications

5 years agoMFC 331417,331597: Add the cryptocheck test tool.
jhb [Mon, 11 Mar 2019 21:37:58 +0000 (21:37 +0000)]
MFC 331417,331597: Add the cryptocheck test tool.

331417:
Bring in JHB's cryptocheck tool

It can be used to validate basic algorithm correctness on a variety of inputs,
by comarison to openssl.

While here, add some sanity to the crypto/Makefile.

The tool may not be perfect, but getting it in tree where collaboration can
happen is a nice first step.  The pace of development outside of svn seems
to have slowed down mid-2017.

331597:
Update the license to note my work on cryptocheck was sponsored.

Sponsored by: Chelsio Communications

5 years agoMFC 323891,323892: Support EtA requests via /dev/crypto.
jhb [Mon, 11 Mar 2019 21:35:56 +0000 (21:35 +0000)]
MFC 323891,323892: Support EtA requests via /dev/crypto.

323891:
Add a new COP_F_CIPHER_FIRST flag for struct crypt_op.

This requests that the cipher be performed before rather than after
the HMAC when both are specified for a single operation.

323892:
Support AEAD requests with non-GCM algorithms.

In particular, support chaining an AES cipher with an HMAC for a request
including AAD.  This permits submitting requests from userland to encrypt
objects like IPSec packets using these algorithms.

In the non-GCM case, the authentication crypto descriptor covers both the
AAD and the ciphertext.  The GCM case remains unchanged.  This matches
the requests created internally in IPSec.  For the non-GCM case, the
COP_F_CIPHER_FIRST is also supported since the ordering matters.

Note that while this can be used to simulate IPSec requests from userland,
this ioctl cannot currently be used to perform TLS requests using AES-CBC
and MAC-before-encrypt.

Sponsored by: Chelsio Communications

5 years agoMFC r342952:
ngie [Mon, 11 Mar 2019 18:17:12 +0000 (18:17 +0000)]
MFC r342952:

Add Linux compatibility support for `SC_NPROCESSORS_{CONF,ONLN}` as `_SC_NPROCESSORS_{CONF,ONLN}`

The goal of this change is to make it easier to use getconf to query
the number of available processors.

Sadly it's unclear per POSIX, which form (with a preceding _ or
lacking it) is correct. I will bring this up on the Austin Group list so
this point is clarified for implementors that might rely on this getconf
variable in future POSIX spec versions.

This is something I noticed when trying to import GoogleTest to FreeBSD
as one of the CI scripts uses this variable on Linux.

Approved by: emaste (mentor)
Differential Revision: https://reviews.freebsd.org/D19527

5 years agoMFC r344743: Reduce CTL threads priority to about PUSER.
mav [Mon, 11 Mar 2019 13:56:51 +0000 (13:56 +0000)]
MFC r344743: Reduce CTL threads priority to about PUSER.

Since in most configurations CTL serves as network service, we found
that this change improves local system interactivity under heavy load.
Priority of main threads is set slightly higher then worker taskqueues
to make them quickly sort incoming requests not creating bottlenecks,
while plenty of worker taskqueues should be less sensitive to latency.

5 years agoMFC r344489: Free some space in struct ctl_io_hdr for better use.
mav [Mon, 11 Mar 2019 01:44:37 +0000 (01:44 +0000)]
MFC r344489: Free some space in struct ctl_io_hdr for better use.

 - Collapse original_sc and serializing_sc fields into one, since they
are never used simultanously, we have only one local I/O and one remote.

 - Move remote_sglist and local_sglist fields into CTL_PRIV_BACKEND,
since they are used only on Originating SC in XFER mode, where requests
don't ever reach backends, so we can reuse backend's private storage.

5 years agoMFC r336255: Only define g_eli_key_cmp in the kernel
kevans [Mon, 11 Mar 2019 01:12:23 +0000 (01:12 +0000)]
MFC r336255: Only define g_eli_key_cmp in the kernel

5 years agoFix build breakage caused by r344984
wulf [Sun, 10 Mar 2019 21:43:13 +0000 (21:43 +0000)]
Fix build breakage caused by r344984

This is a direct commit to stable/11

5 years agoMFC r344494,r344495:
wulf [Sun, 10 Mar 2019 20:58:24 +0000 (20:58 +0000)]
MFC r344494,r344495:

evdev: export event device properties through sysctl interface

A big security advantage of Wayland is not allowing applications to read
input devices all the time. Having /dev/input/* accessible to the user
account subverts this advantage.

libudev-devd was opening the evdev devices to detect their types (mouse,
keyboard, touchpad, etc). This don't work if /dev/input/* is inaccessible.
With the kernel exposing this information as sysctls (kern.evdev.input.*),
we can work w/o /dev/input/* access, preserving the Wayland security model.

Submitted by: Greg V <greg@unrelenting.technology>
Reviewed by: wulf, imp
Differential Revision: https://reviews.freebsd.org/D18694

5 years agoMFC r343362,r343365,r343367,r343368,r343461,r343751,r344310:
ngie [Sun, 10 Mar 2019 16:13:00 +0000 (16:13 +0000)]
MFC r343362,r343365,r343367,r343368,r343461,r343751,r344310:

r343362:

Add [initial] functional tests for sendfile(2) as lib/libc/sys/sendfile

These testcases exercise a number of functional requirements for sendfile(2).

The testcases use IPv4 and IPv6 domain sockets with TCP, and were confirmed
functional on UFS and ZFS. UDP address family sockets cannot be used per the
sendfile(2) contract, thus using UDP sockets is outside the scope of
testing the syscall in positive cases. As seen in
`:s_negative_udp_socket_test`, UDP is used to test the sendfile(2) contract
to ensure that EINVAL is returned by sendfile(2).

The testcases added explicitly avoid testing out `SF_SYNC` due to the
complexity of verifying that support. However, this is a good next logical
item to verify.

The `hdtr_positive*` testcases work to a certain degree (the header
testcases pass), but the trailer testcases do not work (it is an expected
failure). In particular, the value received by the mock server doesn't match
the expected value, and instead looks something like the following (using
python array notation):

`trailer[:]message[1:]`

instead of:

`message[:]trailer[:]`

This makes me think there's a buffer overrun issue or problem with the
offset somewhere in the sendfile(2) system call, but I need to do some
other testing first to verify that the code is indeed sane, and my
assumptions/code isn't buggy.

The `sbytes_negative` testcases that check `sbytes` being set to an
invalid value resulting in `EFAULT` fails today as the other change
(which checks `copyout(9)`) has not been committed [1]. Thus, it
should remain an expected failure (see bug 232210 for more details
on this item).

Next steps for testing sendfile(2):
1. Fix the header/trailer testcases so that they pass.
2. Setup if_tap interface and test with it, instead of using "localhost", per
   @asomers's suggestion.
3. Handle short recv(2)'s in `server_cat(..)`.
4. Add `SF_SYNC` support.
5. Add some more negative tests outside the scope of the functional contract.

PR:  232210

r343365:

Unbreak the gcc build with sendfile_test after r343362

gcc 8.x is more pedantic than clang 7.x with format strings and the tests
passed `void*` variables while supplying `%s` (which is technically
incorrect).

Make the affected `void*` variables use `char*` storage instead to address
this issue, as the compiler will upcast the values to `char*`.

MFC with: r343362

r343367:

Unbreak the build on architectures where size_t isn't synonymous with uintmax_t

I should have used `%zu` instead of `%ju` with `size_t` types.

MFC with: r343362, r343365
Pointyhat to: ngie

r343368:

Fix up r343367

I should have only changed the format qualifier with the `size_t` value,
`length`, not the other [`off_t`] value, `dest_file_size`.

MFC with: r343362, r343365, r343367

r343461:

Fix reporting errors with `gai_strerror(..)`

The return value (`err`) should be checked; not the `errno` value.

PR: 235200
MFC with: r343362, r343365, r343367-r343368

r343751:

Avoid the DNS lookup for "localhost"

ci.FreeBSD.org does not have access to a DNS resolver/network (unlike my test
VM), so in order for the test to pass on the host, it needs to avoid the DNS
lookup by using the numeric host address representation.

PR: 235200
MFC with: r343362, r343365, r343367-r343368, r343461

r344310:

Make `server_cat(..)` handle short receives

In short, the prior code was far too simplistic when it came to calling recv(2)
and failed intermittently (or in the case of Jenkins, deterministically).

Handle short recv(2)s by checking the return code and incrementing the window
into the buffer by the number of received bytes. If the number of received
bytes <= 0, then bail out of the loop, and test the total number of received
bytes vs the expected number of bytes sent for equality, and base whether or
not the test passes/fails on that fact.

Remove the expected failure, now that the hdtr testcases deterministically pass
on my host after this change [1].

PR: 234809 [1], 235200

Approved by: emaste (mentor)
Differential Revision: https://reviews.freebsd.org/D19524

5 years agopf: Small performance tweak
kp [Sun, 10 Mar 2019 00:56:39 +0000 (00:56 +0000)]
pf: Small performance tweak

Because fetching a counter is a rather expansive function we should use
counter_u64_fetch() in pf_state_expires() only when necessary. A "rdr
pass" rule should not cause more effort than separate "rdr" and "pass"
rules. For rules with adaptive timeout values the call of
counter_u64_fetch() should be accepted, but otherwise not.

From the man page:
    The adaptive timeout values can be defined both globally and for
    each rule.  When used on a per-rule basis, the values relate to the
    number of states created by the rule, otherwise to the total number
    of states.

This handling of adaptive timeouts is done in pf_state_expires().  The
calculation needs three values: start, end and states.

1. Normal rules "pass .." without adaptive setting meaning "start = 0"
   runs in the else-section and therefore takes "start" and "end" from
   the global default settings and sets "states" to pf_status.states
   (= total number of states).

2. Special rules like
   "pass .. keep state (adaptive.start 500 adaptive.end 1000)"
   have start != 0, run in the if-section and take "start" and "end"
   from the rule and set "states" to the number of states created by
   their rule using counter_u64_fetch().

Thats all ok, but there is a third case without special handling in the
above code snippet:

3. All "rdr/nat pass .." statements use together the pf_default_rule.
   Therefore we have "start != 0" in this case and we run the
   if-section but we better should run the else-section in this case and
   do not fetch the counter of the pf_default_rule but take the total
   number of states.

Submitted by: Andreas Longwitz <longwitz@incore.de>

5 years agoMFC r343990:
avos [Sat, 9 Mar 2019 12:54:10 +0000 (12:54 +0000)]
MFC r343990:
net80211: hide casts for 'i_seq' field offset calculation inside
ieee80211_getqos() and reuse it in various places.

5 years agoMFC r340073, r341359:
kp [Sat, 9 Mar 2019 10:28:36 +0000 (10:28 +0000)]
MFC r340073, r341359:

pf: Keep a reference to struct ifnets we're using

Ensure that the struct ifnet we use can't go away until we're done with
it.

pf: Fix panic on overlapping interface names

In rare situations[*] it's possible for two different interfaces to have
the same name. This confuses pf, because kifs are indexed by name (which
is assumed to be unique). As a result we can end up trying to
if_rele(NULL), which panics.

Explicitly checking the ifp pointer before if_rele() prevents the panic.
Note pf will likely behave in unexpected ways on the the overlapping
interfaces.

[*] Insert an interface in a vnet jail. Rename it to an interface which
exists on the host. Remove the jail. There are now two interfaces with
the same name in the host.

5 years agoMFC r344838:
cy [Sat, 9 Mar 2019 00:32:00 +0000 (00:32 +0000)]
MFC r344838:

Remove an empty directory emptied by r343702.

5 years agoMFC 344671: Don't assume all children of a nexus are ports.
jhb [Fri, 8 Mar 2019 19:20:46 +0000 (19:20 +0000)]
MFC 344671: Don't assume all children of a nexus are ports.

Specifically, ccr(4) devices are also children of cxgbe nexus devices.
Rather than making assumptions about the child device's softc, walk
the list of ports from the nexus' softc to determine if a child is a
port in t4_child_location_str().  This fixes a panic when detaching a
ccr device.

5 years agoMFC 343048:
jhb [Fri, 8 Mar 2019 18:53:54 +0000 (18:53 +0000)]
MFC 343048:
Update the note about the need for COMPAT_FREEBSD<n> kernel options.

Rather than mentioning the requirement for 4.x binaries but not
explaining why (it was assuming an upgrade from 4.x to 5.0-current),
explain when compat options are needed (for running existing host
binaries) in a more general way while using a more modern example
(COMPAT_FREEBSD11 for 11.x binaries).  While here, explicitly mention
that a GENERIC kernel should always work.

5 years agoMFC r344696:
vmaffione [Fri, 8 Mar 2019 08:27:33 +0000 (08:27 +0000)]
MFC r344696:

netmap: pkt-gen: fix bug in send_packets()

The send_packets() function was using ring->cur as index to scan
the transmit ring. This function may also set ring->cur ahead of
ring->head, in case no more slots are available. However, the function
also uses nm_ring_space() which looks at ring->head to check how many
slots are available. If ring->head and ring->cur are different, this
results in pkt-gen advancing ring->cur beyond ring->tail.

This patch fixes send_packets() (and similar source locations) to
use ring->head as a index, rather than using ring->cur.

5 years agoMFC 342658:
jhb [Fri, 8 Mar 2019 01:04:19 +0000 (01:04 +0000)]
MFC 342658:
Correct variable name in two panic messages: num_msi_irq -> num_msi_irqs.

5 years agoMFC r344661, r344669: Limit 24xx adapters to only MSI interrupts by default.
mav [Fri, 8 Mar 2019 00:56:41 +0000 (00:56 +0000)]
MFC r344661, r344669: Limit 24xx adapters to only MSI interrupts by default.

This was actually the known good configuration we used before.
Single MSI-X configuration doesn't even work there on my tests, just due
to lack of documentation not sure whether by design or I am doing something
wrong.

PR: 233654

5 years agoMFC r344660: Add to isp(4) tunables to limit MSI/MSI-X usage.
mav [Fri, 8 Mar 2019 00:54:54 +0000 (00:54 +0000)]
MFC r344660: Add to isp(4) tunables to limit MSI/MSI-X usage.

There are some problem reports possibly related to the new driver use of
multiple interrupts on older cards.  Hopefully this allow to workaround
them.

5 years agoMFC r344702: There is no `device atacard` but there is `device atapccard`.
mav [Fri, 8 Mar 2019 00:53:33 +0000 (00:53 +0000)]
MFC r344702: There is no `device atacard` but there is `device atapccard`.

5 years agoMFC 340020: Don't enter DDB for fatal traps before panic by default.
jhb [Fri, 8 Mar 2019 00:20:37 +0000 (00:20 +0000)]
MFC 340020: Don't enter DDB for fatal traps before panic by default.

Add a new 'debugger_on_trap' knob separate from 'debugger_on_panic'
and make the calls to kdb_trap() in MD fatal trap handlers prior to
calling panic() conditional on this new knob instead of
'debugger_on_panic'.  Disable the new knob by default.  Developers who
wish to recover from a fatal fault by adjusting saved register state
and retrying the faulting instruction can still do so by enabling the
new knob.  However, for the more common case this makes the user
experience for panics due to a fatal fault match the user experience
for other panics, e.g. 'c' in DDB will generate a crash dump and
reboot the system rather than being stuck in an infinite loop of fatal
fault messages and DDB prompts.

5 years agoMFC r344553:
dab [Thu, 7 Mar 2019 15:31:32 +0000 (15:31 +0000)]
MFC r344553:

asmc: Add support for Mac mini 2,1

PR:             235798
Submitted by:   Trev <fbsdbugs4@sentry.org>
Reported by:    Trev <fbsdbugs4@sentry.org>

5 years agoMFC r339941 (by mckusick):
kib [Thu, 7 Mar 2019 13:53:59 +0000 (13:53 +0000)]
MFC r339941 (by mckusick):
In preparation for adding inode check-hashes, change the fsck_ffs
inodirty() function to have a pointer to the inode being dirtied.
No functional change (as for now the parameter is ununsed).

Also for stable/11 UFS_NDADDR was renamed to NDADDR.

5 years agoMFC r344883:
cy [Thu, 7 Mar 2019 13:45:36 +0000 (13:45 +0000)]
MFC r344883:

(MFV r344878:)

4.2.8p12 --> 4.2.8p13

Security:       CVE-2019-8936
                VuXML: c2576e14-36e2-11e9-9eda-206a8a720317
Obtained from:  nwtime.org

5 years agoMFC r344470:
dab [Thu, 7 Mar 2019 13:10:48 +0000 (13:10 +0000)]
MFC r344470:

Fix several Coverity-detected issues in newsyslog.

- CID 1394815, CID 1305673: Dereference before null check - memory was
  allocated and the allocation checked for NULL with a call to errx()
  if it failed. Code below that was guaranteed that the pointer was
  non-NULL, but there was another check for NULL at the exit of the
  function (after the memory had already been referenced). Eliminate
  the useless NULL check.

- CID 1007452: Resource leak - Storage intended to be allocated and
  returned to the caller was never freed. This was the result of a
  regression in the function signature introduced in r208648 (2010)
  (thanks for that find, @cem!). Fixed by altering the function
  signature and passing the allocated memory to the caller as
  intended. This also fixes PR158794.

- CID 1008620: Logically dead code in newsyslog.c - This was a direct
  result of CID 1007452. Since the memory allocated as described there
  was not returned to the caller, a subsequent check for the memory
  having been allocated was dead code. Returning the memory
  re-animates the code that is the subject of this CID.

- CID 1006131: Unused value - in parsing a configuration file, a
  pointer to the end of the last field was saved, but not used after
  that. Rewrite to use the pointer value. This could have been fixed
  by avoiding the assignment altogether, but this solutions more
  closely follows the pattern used in the preceding code.

PR:             158794
Reported by:    Coverity, Ken-ichi EZURA <k.ezura@gmail.com> (PR158794)

Sponsored by: Dell EMC Isilon

5 years agoMFC of 344731
mckusick [Thu, 7 Mar 2019 00:04:13 +0000 (00:04 +0000)]
MFC of 344731

Roundup tunefs -S logsize to filesystem block size

Sponsored by: Netflix

5 years agoMFC of 344552 and 344732
mckusick [Wed, 6 Mar 2019 23:59:56 +0000 (23:59 +0000)]
MFC of 344552 and 344732

Have fsck_ffs adjust size for files with hole at end

Tighten last lbn calculation

Sponsored by: Netflix

5 years agoMFC 341098: Add read-only sysctls for all tunables in the cxgbe(4) driver.
jhb [Wed, 6 Mar 2019 23:09:27 +0000 (23:09 +0000)]
MFC 341098: Add read-only sysctls for all tunables in the cxgbe(4) driver.

5 years agoMFC 330882: Simplify error handling in t4_tom.ko module loading.
jhb [Wed, 6 Mar 2019 22:13:53 +0000 (22:13 +0000)]
MFC 330882: Simplify error handling in t4_tom.ko module loading.

- Change t4_ddp_mod_load() to return void instead of always returning
  success.  This avoids having to pretend to have proper support for
  unloading when only part of t4_tom_mod_load() has run.
- If t4_register_uld() fails, don't invoke t4_tom_mod_unload() directly.
  The module handling code in the kernel invokes MOD_UNLOAD on a module
  whose MOD_LOAD fails with an error already.

5 years agoMFC r343705:
cy [Wed, 6 Mar 2019 02:51:33 +0000 (02:51 +0000)]
MFC r343705:

new_kmem_alloc(9) is a Solaris/illumos malloc(9). FreeBSD and NetBSD
never get here, however a test for SOLARIS, as redundant as this test is,
serves to document that this is the illumos definition. This should help
those who come after me to follow the code more easily.

5 years agoMFC r343704:
cy [Wed, 6 Mar 2019 02:46:18 +0000 (02:46 +0000)]
MFC r343704:

Kernel module shim sources have no business being in the userland
build directory, especially those for other operating systems.
The kernel module shims for other operating systems are hereby removed.
The kernel module shim for FreeBSD, mlfk_ipl.c, is already in
sys/contrib/ipfilter/netinet. The one here is never used and should
not be in the userland build directory either.

mlfk_rule.c isn't used either however we will keep it in case someone
wishes to use this shim to load rules via a kernel module, handy for
embedded. In that case it should be copied to
sys/contrib/ipfilter/netinet and a Makefile created to employ it.
(Probably a useful documentation project when time permits.)

5 years agoMFC r343703
cy [Wed, 6 Mar 2019 02:43:31 +0000 (02:43 +0000)]
MFC r343703

Remove a reference to HP-UX in a comment.

5 years agoMFC r343702:
cy [Wed, 6 Mar 2019 02:40:01 +0000 (02:40 +0000)]
MFC r343702:

Remove a redundant ip_compat.h, originally merged from upstream.

5 years agoMFC r343701 & r343732:
cy [Wed, 6 Mar 2019 02:37:25 +0000 (02:37 +0000)]
MFC r343701 & r343732:

ipfilter #ifdef cleanup.

Remove #ifdefs for ancient and irrelevant operating systems from
ipfilter.

When ipfilter was written the UNIX and UNIX-like systems in use
were diverse and plentiful. IRIX, Tru64 (OSF/1) don't exist any
more. OpenBSD removed ipfilter shortly after the first time the
ipfilter license terms changed in the early 2000's. ipfilter on AIX,
HP/UX, and Linux never really caught on. Removal of code for operating
systems that ipfilter will never run on again will simplify the code
making it easier to fix bugs, complete partially implemented features,
and extend ipfilter.

Unsupported previous version FreeBSD code and some older NetBSD code
has also been removed.

What remains is supported FreeBSD, NetBSD, and illumos. FreeBSD and
NetBSD have collaborated exchanging patches, while illumos has expressed
willingness to have their ipfilter updated to 5.1.2, provided their
zone-specific updates to their ipfilter are merged (which are of interest
to FreeBSD to allow control of ipfilters in jails from the global zone).

Reviewed by: glebius@
Differential Revision: https://reviews.freebsd.org/D19006

5 years agoMFC r344600:
markj [Tue, 5 Mar 2019 19:41:32 +0000 (19:41 +0000)]
MFC r344600:
Add a missing return statement to g_concat_kernel_dump().

5 years agoMFC r344278:
markj [Tue, 5 Mar 2019 19:39:13 +0000 (19:39 +0000)]
MFC r344278:
Move a racy assertion in filt_pipewrite().

PR: 235640

5 years agoMFC freebsd-update: Clarify unsupported release upgrade error message
emaste [Tue, 5 Mar 2019 19:07:46 +0000 (19:07 +0000)]
MFC freebsd-update: Clarify unsupported release upgrade error message

MFC r343122:

freebsd-update: Clarify unsupported release upgrade error message

Notify users that upgrading from -CURRENT or -STABLE is unsupported by
freebsd-update.

Also ensure --currently-running provides a correctly formatted release
(as done by -r).

Reported by: yuri
Reviewed by: bcran

MFC r343268:

frebsd-update: fix --currently-running after r343122

Reported by: Brandon Schneider

MFC r343271:

freebsd-update: Allow upgrade from pre-release builds

Update r343122 to include -ALPHA, -BETA and -RC releases as
upgrade-able via freebsd-update.

Reported by: delphij, des
Reviewed by: delphij

MFC r343410:

freebsd-update: fix style from r343271 change

PR: 234771
Submitted by: Gerald Aryeetey <aryeeteygerald_rogers.com>
Sponsored by: The FreeBSD Foundation

5 years agofreebsd-update: Use BASEDIR when checking for src componentfreebsd-update: Use BMFC...
emaste [Tue, 5 Mar 2019 18:54:47 +0000 (18:54 +0000)]
freebsd-update: Use BASEDIR when checking for src componentfreebsd-update: Use BMFC r343152: freebsd-update: Use BASEDIR when checking for src component

src could potentially be installed under the based dir
and not under the root or vice versa.

PR: 224048
Submitted by: Gerald Aryeetey <aryeeteygerald_rogers.com>
Reviewed by: delphij
Sponsored by: The FreeBSD Foundation

5 years agoMFC r343270: freebsd-update: Update /etc/passwd after password db changes
emaste [Tue, 5 Mar 2019 18:30:43 +0000 (18:30 +0000)]
MFC r343270: freebsd-update: Update /etc/passwd after password db changes

Add -p to pwd_mkdb in order to ensure password db changes are also
included in /etc/passwd.

PR: 165954, 232921, 229487
Submitted by: Gerald Aryeetey <aryeeteygerald_rogers.com>
Reviewed by: jilles
Sponsored by: The FreeBSD Foundation

5 years agoMFC r343411: freebsd-update: Clarify unsupported upgrade message
emaste [Tue, 5 Mar 2019 18:27:29 +0000 (18:27 +0000)]
MFC r343411: freebsd-update: Clarify unsupported upgrade message

PR: 204115
Submitted by: Gerald Aryeetey <aryeeteygerald_rogers.com>
Reviewed by: delphij
Sponsored by: The FreeBSD Foundation

5 years agoMFC r343412: Fix a typo/wordsmith a description modified in [MFC of r343407]
emaste [Tue, 5 Mar 2019 18:23:55 +0000 (18:23 +0000)]
MFC r343412: Fix a typo/wordsmith a description modified in [MFC of r343407]

5 years agoMFC r343407: freebsd-update: open $PAGER only if necessary
emaste [Tue, 5 Mar 2019 18:20:16 +0000 (18:20 +0000)]
MFC r343407: freebsd-update: open $PAGER only if necessary

PR: 194547, 208497
Submitted by:   Gerald Aryeetey <aryeeteygerald_rogers.com>
Reviewed by: delphij
Sponsored by: The FreeBSD Foundation

5 years agoMFC r343409: freebsd-update: Stop installing empty component sets
emaste [Tue, 5 Mar 2019 18:17:06 +0000 (18:17 +0000)]
MFC r343409: freebsd-update: Stop installing empty component sets

Submitted by: Gerald Aryeetey <aryeeteygerald_rogers.com>
Reported by: rgrimes
Reviewed by: delphij
Sponsored by: The FreeBSD Foundation

5 years agoMFC r343589: freebsd-update: regenerate man page database after update
emaste [Tue, 5 Mar 2019 18:11:36 +0000 (18:11 +0000)]
MFC r343589: freebsd-update: regenerate man page database after update

These are currently not reproducible because they're built by the
makewhatis on the freebsd-update build host, not the one in the tree.
Regenerate after update, and later we can avoid including it in
freebsd-update data.

PR: 214545, 217389
Reviewed by: delphij
Sponsored by: The FreeBSD Foundation

5 years agoMFC r344245:
avos [Mon, 4 Mar 2019 03:38:43 +0000 (03:38 +0000)]
MFC r344245:
snmp_hostres(3): fix a typo in sanity checks in handle_chunk()

PR: 204253
Submitted by: David Binderman <dcb314@hotmail.com>

5 years agoMFC r344244:
avos [Mon, 4 Mar 2019 03:30:39 +0000 (03:30 +0000)]
MFC r344244:
Fix memory / resource leaks in usr.sbin/rpc.ypupdated/update.c

Re-apply r343909 to this file to get the issue fixed.

PR: 204956
Reported by: David Binderman <dcb314@hotmail.com>

5 years agoMFC r344491: An IPv6 address matching should be fixed.
ume [Sun, 3 Mar 2019 03:42:51 +0000 (03:42 +0000)]
MFC r344491: An IPv6 address matching should be fixed.
Specifying an IPv6 address by the -a option was broken
since r309933.

5 years agoUPDATING: Restore the missing period with another direct commit
kevans [Sun, 3 Mar 2019 03:09:43 +0000 (03:09 +0000)]
UPDATING: Restore the missing period with another direct commit

Reported by: rgrimes

5 years agoMFC r344691:
kp [Fri, 1 Mar 2019 18:12:07 +0000 (18:12 +0000)]
MFC r344691:

pf: IPv6 fragments with malformed extension headers could be erroneously passed by pf or cause a panic

We mistakenly used the extoff value from the last packet to patch the
next_header field. If a malicious host sends a chain of fragmented packets
where the first packet and the final packet have different lengths or number of
extension headers we'd patch the next_header at the wrong offset.
This can potentially lead to panics or rule bypasses.

Reported by: Corentin Bayet, Nicolas Collignon, Luca Moro at Synacktiv
Approved by: so
Obtained from: OpenBSD
Security: CVE-2019-5597

5 years agoMFC r344592:
kib [Fri, 1 Mar 2019 11:30:19 +0000 (11:30 +0000)]
MFC r344592:
procctl(2): fix -width parameter to .Bl.

5 years agoMFC r344477:
hselasky [Fri, 1 Mar 2019 08:05:29 +0000 (08:05 +0000)]
MFC r344477:
Add new USB quirk.

PR: 235897
Sponsored by: Mellanox Technologies

5 years agoMFC r343118: new small tool trim(8) to delete contents for blocks
eugen [Fri, 1 Mar 2019 05:04:29 +0000 (05:04 +0000)]
MFC r343118: new small tool trim(8) to delete contents for blocks
on flash based storage devices that use wear-leveling algorithms.

5 years agoMFC r344063,r344088:
mm [Thu, 28 Feb 2019 22:56:15 +0000 (22:56 +0000)]
MFC r344063,r344088:

MFC r344063:
Sync libarchive with vendor.

Relevant vendor changes:
  PR #1085: Fix a null pointer dereference bug in zip writer
  PR #1110: ZIP reader added support for XZ, LZMA, PPMD8 and BZIP2
            decopmpression
  PR #1116: Add support for 64-bit ar format
  PR #1120: Fix a 7zip crash [1] and a ISO9660 infinite loop [2]
  PR #1125: RAR5 reader - fix an invalid read and a memory leak
  PR #1131: POSIX reader - do not fail when tree_current_lstat() fails
            due to ENOENT [3]
  PR #1134: Delete unnecessary null pointer checks before calls of free()
  OSS-Fuzz 10843: Force intermediate to uint64_t to make UBSAN happy.
  OSS-Fuzz 11011: Avoid buffer overflow in rar5 reader

MFC r344088:
  archive_read_disk_posix.c: initialize delayed_errno

PR: 233006 [3]
Security: CVE-2019-1000019 [1], CVE-2019-1000020 [2]

5 years agoMFC r343877,r343880:
bdrewery [Thu, 28 Feb 2019 20:57:41 +0000 (20:57 +0000)]
MFC r343877,r343880:

  r343877:
    ipfw table list: Fix showing header outside of 'all'.
  r343880:
    Fix build of r343877

Relnotes: yes

5 years agoMFC r344510
vmaffione [Thu, 28 Feb 2019 09:42:03 +0000 (09:42 +0000)]
MFC r344510

netmap: remove redundant call to nm_set_native_flags()

This redundant call was introduced by mistake in r343772.

Sponsored by:   Sunny Valley Networks

5 years agoMFC r344444:
dim [Thu, 28 Feb 2019 06:53:18 +0000 (06:53 +0000)]
MFC r344444:

Pull in r353299 from upstream lld trunk (by George Rimar):

  Recommit r353293 "[LLD][ELF] - Set DF_STATIC_TLS flag for i386 target."

  With the following changes:
  1) Compilation fix:
  std::atomic<bool> HasStaticTlsModel = false; ->
  std::atomic<bool> HasStaticTlsModel{false};

  2) Adjusted the comment in code.

  Initial commit message:

  DF_STATIC_TLS flag indicates that the shared object or executable
  contains code using a static thread-local storage scheme.

  Patch checks if IE/LE relocations were used to check if the code uses
  a static model. If so it sets the DF_STATIC_TLS flag.

  Differential revision: https://reviews.llvm.org/D57749

Pull in r353378 from upstream lld trunk (by George Rimar):

  [LLD][ELF] - Set DF_STATIC_TLS flag for X64 target

  This is the same as D57749, but for x64 target.

  "ELF Handling For Thread-Local Storage" p41 says
  (https://www.akkadia.org/drepper/tls.pdf):
  R_X86_64_GOTTPOFF relocation is used for IE TLS models.
  Hence if linker sees this relocation we should add DF_STATIC_TLS flag.

  Differential revision: https://reviews.llvm.org/D57821

This adds support to lld for the DF_STATIC_TLS flag in shared objects,
which signals to the dynamic linker that the shared object requires
static thread local storage.

See also: https://reviews.freebsd.org/D19072

5 years agoMFC r344437: Allow I/OAT of present Xeon E5/E7 to work thorugh PLX NTB.
mav [Thu, 28 Feb 2019 00:30:34 +0000 (00:30 +0000)]
MFC r344437: Allow I/OAT of present Xeon E5/E7 to work thorugh PLX NTB.

Its a hack, we can't know/list all DMA engines, but this covers all
I/OAT of Xeon E5/E7 at least from Sandy Bridge till Skylake I saw.

5 years agoMFC r344441: Fix few issues in ioat(4) driver.
mav [Thu, 28 Feb 2019 00:29:15 +0000 (00:29 +0000)]
MFC r344441: Fix few issues in ioat(4) driver.

 - Do not explicitly count active descriptors.  It allows hardware reset
to happen while device is still referenced, plus simplifies locking.
 - Do not stop/start callout each time the queue becomes empty.  Let it
run to completion and rearm if needed, that is much cheaper then to touch
it every time, plus also simplifies locking.
 - Decouple submit and cleanup locks, making driver reentrant.
 - Avoid memory mapped status register read on every interrupt.
 - Improve locking during device attach/detach.
 - Remove some no longer used variables.

Sponsored by: iXsystems, Inc.

5 years agoMFC r344473:
dab [Wed, 27 Feb 2019 22:29:26 +0000 (22:29 +0000)]
MFC r344473:

CID 1332000: Logically dead code in sys/dev/pms/RefTisa/tisa/sassata/sas/ini/itdio.c

A pointer is first tested for NULL. If non-NULL, another pointer is
set equal to the first. The second pointer is then checked for NULL
and an error path taken if so. This second test and the associated
path is dead code as the pointer value, having just been checked for
NULL, cannot be NULL at this point. Remove the dead code.

Sponsored by: Dell EMC Isilon

5 years agoMFC r344503:
dim [Wed, 27 Feb 2019 22:02:46 +0000 (22:02 +0000)]
MFC r344503:

Pull in r354756 from upstream llvm trunk (by Craig Topper):

  [X86] Fix tls variable lowering issue with large code model

  Summary:
  The problem here is the lowering for tls variable. Below is the DAG
  for the code. SelectionDAG has 11 nodes:

  t0: ch = EntryToken
t8: i64,ch = load<(load 8 from `i8 addrspace(257)* null`,
addrspace 257)> t0, Constant:i64<0>, undef:i64
  t10: i64 = X86ISD::WrapperRIP TargetGlobalTLSAddress:i64<i32*
  @x> 0 [TF=10]
t11: i64,ch = load<(load 8 from got)> t0, t10, undef:i64
      t12: i64 = add t8, t11
    t4: i32,ch = load<(dereferenceable load 4 from @x)> t0, t12,
    undef:i64
  t6: ch = CopyToReg t0, Register:i32 %0, t4

  And when mcmodel is large, below instruction can NOT be folded.

    t10: i64 = X86ISD::WrapperRIP TargetGlobalTLSAddress:i64<i32* @x> 0
    [TF=10]
  t11: i64,ch = load<(load 8 from got)> t0, t10, undef:i64

  So "t11: i64,ch = load<(load 8 from got)> t0, t10, undef:i64" is
  lowered to " Morphed node: t11: i64,ch = MOV64rm<Mem:(load 8 from
  got)> t10, TargetConstant:i8<1>, Register:i64 $noreg,
  TargetConstant:i32<0>, Register:i32 $noreg, t0"

  When llvm start to lower "t10: i64 = X86ISD::WrapperRIP
  TargetGlobalTLSAddress:i64<i32* @x> 0 [TF=10]", it fails.

  The patch is to fold the load and X86ISD::WrapperRIP.

  Fixes PR26906

  Patch by LuoYuanke

  Reviewers: craig.topper, rnk, annita.zhang, wxiao3

  Reviewed By: rnk

  Subscribers: llvm-commits

  Tags: #llvm

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

This should fix "fatal error: error in backend: Cannot select" messages
when compiling <ctype.h> functions using -mcmodel=large.

Reported by: phk
PR: 233143

5 years agoMFC r344218: mdmfs(8): use -o reserve with malloc-backed md(4)
kevans [Wed, 27 Feb 2019 17:00:27 +0000 (17:00 +0000)]
MFC r344218: mdmfs(8): use -o reserve with malloc-backed md(4)

Mentioned in mdconfig(8), malloc-backed md(4) can be unstable unless
required memory is allocated up front with -o reserve. Furthermore, panics
have been observed with md used in fstab on 12.0-RELEASE. Choose the stable
route and pass -o reserve.

5 years agoMFC r336262: Fix machdep_boot.c
kevans [Wed, 27 Feb 2019 13:01:17 +0000 (13:01 +0000)]
MFC r336262: Fix machdep_boot.c

A last minute change made this no longer compile. Pass the right arg
and eliminate now-unused variables from the code.

5 years agoMerge OpenSSL 1.0.2r.
jkim [Tue, 26 Feb 2019 19:36:57 +0000 (19:36 +0000)]
Merge OpenSSL 1.0.2r.

5 years agoMFC r344305, r344365:
markj [Tue, 26 Feb 2019 15:06:44 +0000 (15:06 +0000)]
MFC r344305, r344365:
Impose a limit on the number of GEOM_CTL arguments.

admbug: 854

5 years agoMFC r344307:
markj [Tue, 26 Feb 2019 14:59:41 +0000 (14:59 +0000)]
MFC r344307:
Limit the number of entries allocated for a REPORT_ZONES command.

admbug: 807

5 years agoMerge ENA OOO RX fixes
mw [Tue, 26 Feb 2019 12:26:25 +0000 (12:26 +0000)]
Merge ENA OOO RX fixes

MFC r344150-r344151

Obtained from: Semihalf
Sponsored by: Amazon, Inc.

5 years agoMFC r344315:
cperciva [Tue, 26 Feb 2019 05:37:49 +0000 (05:37 +0000)]
MFC r344315:
  Fix sed script to insert Amazon NTP server into ntp.conf once rather
  than twice.

Reminded by: rgrimes

5 years agoMFC r343920:
tuexen [Mon, 25 Feb 2019 10:51:21 +0000 (10:51 +0000)]
MFC r343920:

Ensure that when using the TCP CDG congestion control and setting the
sysctl variable net.inet.tcp.cc.cdg.smoothing_factor to 0, the smoothing
is disabled. Without this patch, a division by zero orrurs.

Reviewed by: lstewart@, rrs@
Sponsored by: Netflix, Inc.
Differential Revision: https://reviews.freebsd.org/D19071

5 years agoBackport the new TCP reassembly code from head to stable/11.
tuexen [Mon, 25 Feb 2019 10:38:37 +0000 (10:38 +0000)]
Backport the new TCP reassembly code from head to stable/11.

In particular:

* Cherry pick the changes in sys/queue.h from r334804.

* MFC r338102 with manually removing changes to file not existent in
  stable/11 and resolve conflicts in tcp_var.h.
  This change represents a substantial restructure of the way we
  reassembly inbound tcp segments. The old algorithm just blindly
  dropped in segments without coalescing. This meant that every
  segment could take up greater and greater room on the linked list
  of segments. This of course is now subject to a tighter limit (100)
  of segments which in a high BDP situation will cause us to be a
  lot more in-efficent as we drop segments beyond 100 entries that
  we receive. What this restructure does is cause the reassembly
  buffer to coalesce segments putting an emphasis on the two
  common cases (which avoid walking the list of segments) i.e.
  where we add to the back of the queue of segments and where we
  add to the front. We also have the reassembly buffer supporting
  a couple of debug options (black box logging as well as counters
  for code coverage). These are compiled out by default but can
  be added by uncommenting the defines.

* Manually fix tcp_stacks/fastopen.c, since it does not exist anymore
  in head.

* MFC r342280:
  Fix a regression in the TCP handling of received segments.
  When receiving TCP segments the stack protects itself by limiting
  the resources allocated for a TCP connections. This patch adds
  an exception to these limitations for the TCP segement which is the next
  expected in-sequence segment. Without this patch, TCP connections
  may stall and finally fail in some cases of packet loss.

* MFC r343439:
  Don't include two header files when not needed.
  This allows the part of the rewrite of TCP reassembly in this
  files to be MFCed to stable/11 with manual change.

* MFC r344428:
  This patch addresses an issue brought up by bz@ in D18968:
  When TCP_REASS_LOGGING is defined, a NULL pointer dereference would happen,
  if user data was received during the TCP handshake and BB logging is used.
  A KASSERT is also added to detect tcp_reass() calls with illegal parameter
  combinations.

Reviewed by: bz@, jtl, rrs@
Sponsored by: Netflix, Inc.
Differential Revision: https://reviews.freebsd.org/D18960

5 years agoMFC r343579, r344253
vmaffione [Mon, 25 Feb 2019 09:13:33 +0000 (09:13 +0000)]
MFC r343579, r344253

netmap: fix lock order reversal related to kqueue usage

When using poll(), select() or kevent() on netmap file descriptors,
netmap executes the equivalent of NIOCTXSYNC and NIOCRXSYNC commands,
before collecting the events that are ready. In other words, the
poll/kevent callback has side effects. This is done to avoid the
overhead of two system call per iteration (e.g., poll() + ioctl(NIOC*XSYNC)).

When the kqueue subsystem invokes the kqueue(9) f_event callback
(netmap_knrw), it holds the lock of the struct knlist object associated
to the netmap port (the lock is provided at initialization, by calling
knlist_init_mtx).
However, netmap_knrw() may need to wake up another netmap port (or even
the same one), which means that it may need to call knote().
Since knote() needs the lock of the struct knlist object associated to
the to-be-wake-up netmap port, it is possible to have a lock order reversal
problem (AB/BA deadlock).

This change prevents the deadlock by executing the knote() call in a
per-selinfo taskqueue, where it is possible to hold a mutex.
The change also adds a counter (kqueue_users) to keep track of how many
kqueue users are referencing a given struct nm_selinfo.
In this way, nm_os_selwakeup() can schedule the kevent notification
task only when kqueue is actually being used.
This is important to avoid wasting CPU in the common case where
kqueue is not used.

Reviewed by:    aleksandr.fedorov_itglobal.com
Differential Revision:  https://reviews.freebsd.org/D18956

5 years agoMFC r339707: Allow fdisk(8) to deal with sectors larger than 2048
rgrimes [Sun, 24 Feb 2019 01:56:35 +0000 (01:56 +0000)]
MFC r339707: Allow fdisk(8) to deal with sectors larger than 2048
especially for 4Kn drives with PMBR's

Approved by: bde (mentor, implicit)

5 years agoMFC r344386:
dim [Sat, 23 Feb 2019 14:27:09 +0000 (14:27 +0000)]
MFC r344386:

Pull in r354515 from upstream libc++ trunk:

  Fix the build with gcc when `-Wredundant-decls` is passed

  Summary:

  gcc warns that `__throw_runtime_error` is declared both in
  `<__locale>` and `<stdexcept>`, if `-Wredundant-decls` is passed on
  the command line; this is the case with FreeBSD when ${WARNS} == 6.

  Since `<__locale>` gets its first declaration via a transitive
  include of `<stdexcept>`, and the second declaration is after the
  first invocation of `__throw_runtime_error`, delete that second
  declaration.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
  Reviewers: kristina, MaskRay, EricWF, ldionne, ngie

  Reviewed By: EricWF

  Subscribers: krytarowski, brooks, emaste, dim, christof, jdoerfert, libcxx-commits

  Tags: #libc

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

Submitted by: ngie

5 years agoMFC r333131:
shurd [Fri, 22 Feb 2019 18:24:57 +0000 (18:24 +0000)]
MFC r333131:

Fix iflib_encap() EFBIG handling bugs

1) Don't give up if m_collapse() fails.  Rather than giving up, try
m_defrag() immediately.

2) Fix a leak where, if the NIC driver rejected the defrag'ed chain
as having too many segments, we would fail to free the chain.

Reviewed by:  Matthew Macy <mmacy@mattmacy.io> (this version of patch)
Submitted by: Matthew Macy <mmacy@mattmacy.io> (early version of leak fix)

5 years agoMFC r344214:
avos [Fri, 22 Feb 2019 08:10:58 +0000 (08:10 +0000)]
MFC r344214:
Refresh OptionalObsoleteFiles.inc for MK_PMC:

- Add missing pmc.haswellxeon.3 to the list.
- Correct man page section for pmcstudy.8.