]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
3 years agoRestore Cirrus-CI boot smoke test
Ed Maste [Sun, 2 May 2021 19:28:36 +0000 (15:28 -0400)]
Restore Cirrus-CI boot smoke test

This reverts commit a7d593dd1da27833b5384349700bc3c7bcae6aad.
We now use compute_engine_instance which allows us to specify a custom
disk size.  Also go back to using the default qemu version (rather than
qemu42 or qemu-devel) as any issues were fixed some time ago.

Reviewed by: lwhsu, markj
MFC after: 1 month
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D30082

3 years agolinux: remove redundant SDT tracepoints
Edward Tomasz Napierala [Wed, 5 May 2021 12:58:54 +0000 (13:58 +0100)]
linux: remove redundant SDT tracepoints

Remove all the 'entry' and 'return' probes; they clutter up the source
and are redundant to FBT.

Reviewed By: dchagin
Sponsored By: EPSRC
Differential Revision: https://reviews.freebsd.org/D30040

3 years agoIntroduce DXR as an IPv4 longest prefix matching / FIB module
Marko Zec [Wed, 5 May 2021 11:45:52 +0000 (13:45 +0200)]
Introduce DXR as an IPv4 longest prefix matching / FIB module

DXR maintains compressed lookup structures with a trivial search
procedure.  A two-stage trie is indexed by the more significant bits of
the search key (IPv4 address), while the remaining bits are used for
finding the next hop in a sorted array.  The tradeoff between memory
footprint and search speed depends on the split between the trie and
the remaining binary search.  The default of 20 bits of the key being
used for trie indexing yields good performance (see below) with
footprints of around 2.5 Bytes per prefix with current BGP snapshots.

Rebuilding lookup structures takes some time, which is compensated for by
batching several RIB change requests into a single FIB update, i.e. FIB
synchronization with the RIB may be delayed for a fraction of a second.
RIB to FIB synchronization, next-hop table housekeeping, and lockless
lookup capability is provided by the FIB_ALGO infrastructure.

DXR works well on modern CPUs with several MBytes of caches, especially
in VMs, where is outperforms other currently available IPv4 FIB
algorithms by a large margin.

Synthetic single-thread LPM throughput test method:

kldload test_lookup; kldload dpdk_lpm4; kldload fib_dxr
sysctl net.route.test.run_lps_rnd=N
sysctl net.route.test.run_lps_seq=N

where N is the number of randomly generated keys (IPv4 addresses) which
should be chosen so that each test iteration runs for several seconds.

Each reported score represents the best of three runs, in million
lookups per second (MLPS), for two bechmarks (RND & SEQ) with two FIBs:

host: single interface address, local subnet route + default route
BGP: snapshot from linx.routeviews.org, 887957 prefixes, 496 next hops

Bhyve VM on an Intel(R) Xeon(R) CPU E5-2670 0 @ 2.60 GHz:
inet.algo         host, RND    host, SEQ    BGP, RND    BGP, SEQ
bsearch4             40.6         20.2         N/A         N/A
radix4                7.8          3.8         1.2         0.6
radix4_lockless      18.0          9.0         1.6         0.8
dpdk_lpm4            14.4          5.0        14.6         5.0
dxr                  70.3         34.7        43.0        19.5

Intel(R) Core(TM) i5-5300U CPU @ 2.30 GHz:
inet.algo         host, RND    host, SEQ    BGP, RND    BGP, SEQ
bsearch4             47.0         23.1         N/A         N/A
radix4                8.5          4.2         1.9         1.0
radix4_lockless      19.2          9.5         2.5         1.2
dpdk_lpm4            31.2          9.4        31.6         9.3
dxr                  84.9         41.4        51.7        23.6

Intel(R) Core(TM) i7-4771 CPU @ 3.50 GHz:
inet.algo         host, RND    host, SEQ    BGP, RND    BGP, SEQ
bsearch4             59.5         29.4         N/A         N/A
radix4               10.8          5.5         2.5         1.3
radix4_lockless      24.7         12.0         3.1         1.6
dpdk_lpm4            29.1          9.0        30.2         9.1
dxr                 101.3         49.9        69.8        32.5

AMD Ryzen 7 3700X 8-Core Processor @ 3.60 GHz:
inet.algo         host, RND    host, SEQ    BGP, RND    BGP, SEQ
bsearch4             70.8         35.4         N/A         N/A
radix4               14.4          7.2         2.8         1.4
radix4_lockless      30.2         15.1         3.7         1.8
dpdk_lpm4            29.9          9.0        30.0         8.9
dxr                 163.3         81.5        99.5        44.4

AMD Ryzen 5 5600X 6-Core Processor @ 3.70 GHz:
inet.algo         host, RND    host, SEQ    BGP, RND    BGP, SEQ
bsearch4             93.6         46.7         N/A         N/A
radix4               18.9          9.3         4.3         2.1
radix4_lockless      37.2         18.6         5.3         2.7
dpdk_lpm4            51.8         15.1        51.6        14.9
dxr                 218.2        103.3       114.0        49.0

Reviewed by: melifaro
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D29821

3 years agoRevise FIB lookups per second benchmarking routines.
Marko Zec [Wed, 5 May 2021 10:28:17 +0000 (12:28 +0200)]
Revise FIB lookups per second benchmarking routines.

Add a LPS benchmark variant which introduces artificial dependencies
between successive lookups. While here, instead of writing the results
from the lookups to a huge array, add them to an accumulator, in a more
lightweight attempt at preventing the CPU's OOO machinery from
discarding the lookup results if they would be completely unused.

net.route.test.run_lps_rnd measures LPS throughput with independent
uniformly random keys

net.route.test.run_lps_seq measures LPS throughput with uniformly
random keys with artificial interdependencies
Reviewed by: melifaro
MFC after: 7 days
Differential Revision: https://reviews.freebsd.org/D30096

3 years agoparam.h: Fix typos
Warner Losh [Wed, 5 May 2021 06:50:35 +0000 (00:50 -0600)]
param.h: Fix typos

Submitted by: rpokala@
Sponsored by: Netflix

3 years agoparam.h: Document __FreeBSD_version better
Warner Losh [Thu, 22 Apr 2021 16:44:15 +0000 (10:44 -0600)]
param.h: Document __FreeBSD_version better

Document what __FreeBSD_version means a bit better by documenting the
sorts of events it should be bumped for. Also include a handy shorthand
for what it means. Add a some advice for how frequently to change this
as well.

Added a note about the approved way to parse this from the param.h file,
though that was not in the review. All in-tree users have been updated
to this method prior to this commit. Move and reword the comment that
was on the same line.

Suggestions by: greg@unrelenting, arch@
Reviewed by: rgrimes@ (earlier version).
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D29850

3 years agocxgbe(4): Use ifaddr_event_ext instead of ifaddr_event for CLIP management.
Navdeep Parhar [Sat, 1 May 2021 23:53:50 +0000 (16:53 -0700)]
cxgbe(4): Use ifaddr_event_ext instead of ifaddr_event for CLIP management.

The _ext event notification includes the address being added/removed and
that gives the driver an easy way to ignore non-IPv6 addresses.  Remove
'tom' from the handler's name while here, it was moved out of t4_tom a
long time ago.

MFC after: 1 week
Sponsored by: Chelsio Communications

3 years agoiwmbtfw(8): Add support for Intel 7260/7265 bluetooth adapter firmwares
Philippe Michaud-Boudreault [Tue, 4 May 2021 23:48:21 +0000 (02:48 +0300)]
iwmbtfw(8): Add support for Intel 7260/7265 bluetooth adapter firmwares

To use it comms/iwmbt-firmware port should be updated to 20210315 version.

Submitted by: Philippe Michaud-Boudreault <pitwuu@gmail.com>
Tested by: Helge Oldach <freebsd@oldach.net>
Reviewed by: wulf
PR: 228787
MFC after: 2 weeks

3 years agoCirrus-CI: switch to Clang/LLVM 12
Ed Maste [Tue, 4 May 2021 19:22:25 +0000 (15:22 -0400)]
Cirrus-CI: switch to Clang/LLVM 12

dim@ is preparing to import Clang/LLVM 12 into the base system as the
system compiler / toolchain.  Apply the same change to the Cirrus-CI
config.

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

3 years agonetgraph/ng_bridge: learn MACs via control message
Lutz Donnerhacke [Tue, 4 May 2021 20:14:59 +0000 (22:14 +0200)]
netgraph/ng_bridge: learn MACs via control message

Add a new control message to move ethernet addresses to a given link
in ng_bridge(4). Send this message instead of doing the work directly.
This decouples the read-only activity from the modification under a
more strict writer lock.

Decoupling the work is a prerequisite for multithreaded operation.

Approved by: manpages (bcr), kp (earlier version)
MFC: 3 weeks
Differential Revision: https://reviews.freebsd.org/D28516

3 years agottys: diff reduction
Warner Losh [Tue, 4 May 2021 19:49:27 +0000 (13:49 -0600)]
ttys: diff reduction

Back in the day, we used to have a number of entries that were either
'on' or 'off' directly, rather than conditionally on 'onifexists'
etc. Back then, we tried to line up the 'secure' columns by using the
construct 'on secure' or 'off secure' (one space or two). Now that these
have all moved to a conditional construct, remove the second space on
the ttys that still have it. This reduces diffs between the different
ttys and is no functional change. i386 and amd64 did this a long time
ago, and those are the only ones that affected external users (who used
to sed 's/on /off /' the entires as part of the automation).

MFC After: 3 days
Sponsored by: Netflix

3 years agosctp: drop packet with SHUTDOWN-ACK chunks with wrong vtags
Michael Tuexen [Tue, 4 May 2021 16:42:31 +0000 (18:42 +0200)]
sctp: drop packet with SHUTDOWN-ACK chunks with wrong vtags

MFC after: 3 days

3 years agoptrace: document ENOMEM
Edward Tomasz Napierala [Tue, 4 May 2021 14:22:36 +0000 (15:22 +0100)]
ptrace: document ENOMEM

Reviewed By: emaste, markj
Sponsored By: EPSRC
Differential Revision: https://reviews.freebsd.org/D29960

3 years agolinux(4): fix ptrace(2) to properly handle orig_rax
Edward Tomasz Napierala [Tue, 4 May 2021 13:11:01 +0000 (14:11 +0100)]
linux(4): fix ptrace(2) to properly handle orig_rax

This fixes strace(1) erroneously reporting return values
as "Function not implemented", combined with reporting the binary
ABI as X32.

Very similar code in linux_ptrace_getregs() is left as it is - it's
probably wrong too, but I don't have a way to test it.

Sponsored By: EPSRC
Differential Revision: https://reviews.freebsd.org/D29927

3 years agopath_test: Add a few new test cases
Mark Johnston [Tue, 4 May 2021 12:56:31 +0000 (08:56 -0400)]
path_test: Add a few new test cases

MFC after: 1 week
Sponsored by: The FreeBSD Foundation

3 years agonfsclient: Copy only initialized fields in nfs_getattr()
Mark Johnston [Tue, 4 May 2021 12:53:57 +0000 (08:53 -0400)]
nfsclient: Copy only initialized fields in nfs_getattr()

When loading attributes from the cache, the NFS client is careful to
copy only the fields that it initialized.  After fetching attributes
from the server, however, it would copy the entire vattr structure
initialized from the RPC response, so uninitialized stack bytes would
end up being copied to userspace.  In particular, va_birthtime (v2 and
v3) and va_gen (v3) had this problem.

Use a common subroutine to copy fields provided by the NFS client, and
ensure that we provide a dummy va_gen for the v3 case.

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

3 years agolinux(4): make linkat(2) handle AT_EMPTY_PATH
Edward Tomasz Napierala [Tue, 4 May 2021 12:09:31 +0000 (13:09 +0100)]
linux(4): make linkat(2) handle AT_EMPTY_PATH

Sponsored By: EPSRC
Differential Revision: https://reviews.freebsd.org/D29974

3 years agopci_vendors: update to 2021-05-04
Baptiste Daroussin [Tue, 4 May 2021 12:02:41 +0000 (14:02 +0200)]
pci_vendors: update to 2021-05-04

3 years agostress2: New test scenario added
Peter Holm [Tue, 4 May 2021 10:55:58 +0000 (12:55 +0200)]
stress2: New test scenario added

3 years agonfscl: fix typo in a comment
Rick Macklem [Tue, 4 May 2021 01:29:27 +0000 (18:29 -0700)]
nfscl: fix typo in a comment

MFC after: 2 weeks

3 years agoAdd a few missed libauditd files to ObsoleteFiles.inc
Dimitry Andric [Mon, 3 May 2021 20:47:41 +0000 (22:47 +0200)]
Add a few missed libauditd files to ObsoleteFiles.inc

3 years agoAdd a few missed libalias_cuseeme files to ObsoleteFiles.inc
Dimitry Andric [Mon, 3 May 2021 20:45:08 +0000 (22:45 +0200)]
Add a few missed libalias_cuseeme files to ObsoleteFiles.inc

3 years agoAdd a few missed libprivateevent files to ObsoleteFiles.inc
Dimitry Andric [Mon, 3 May 2021 20:43:39 +0000 (22:43 +0200)]
Add a few missed libprivateevent files to ObsoleteFiles.inc

3 years agoAdd a few missed gnuregex libraries to ObsoleteFiles.inc
Dimitry Andric [Mon, 3 May 2021 20:40:11 +0000 (22:40 +0200)]
Add a few missed gnuregex libraries to ObsoleteFiles.inc

3 years agoAdd a whole bunch of missed obsolete manpages to ObsoleteFiles.inc
Dimitry Andric [Mon, 3 May 2021 20:24:27 +0000 (22:24 +0200)]
Add a whole bunch of missed obsolete manpages to ObsoleteFiles.inc

3 years agoixgbe: Restore AIM support
Sai Rajesh Tallamraju [Mon, 3 May 2021 17:45:00 +0000 (13:45 -0400)]
ixgbe: Restore AIM support

AIM (adaptive interrupt moderation) was part of BSD11 driver. Upon IFLIB
migration, AIM feature got lost. Re-introducing AIM back into IFLIB
based IXGBE driver.

One caveat is that in BSD11 driver, a queue comprises both Rx and Tx
ring. Starting from BSD12, Rx and Tx have their own queues and rings.
Also, IRQ is now only configured for Rx side. So, when AIM is
re-enabled, we should now consider only Rx stats for configuring EITR
register in contrast to BSD11 where Rx and Tx stats were considered to
manipulate EITR register.

Reviewed by: gallatin, markj
Sponsored by: NetApp, Inc.
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D27344

3 years agoAdd missing sockaddr length and family validation to various protocols
Mark Johnston [Mon, 3 May 2021 16:51:04 +0000 (12:51 -0400)]
Add missing sockaddr length and family validation to various protocols

Several protocol methods take a sockaddr as input.  In some cases the
sockaddr lengths were not being validated, or were validated after some
out-of-bounds accesses could occur.  Add requisite checking to various
protocol entry points, and convert some existing checks to assertions
where appropriate.

Reported by: syzkaller+KASAN
Reviewed by: tuexen, melifaro
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D29519

3 years agokern/intr: declare interrupt vectors unsigned
Elliott Mitchell [Mon, 3 May 2021 16:50:17 +0000 (12:50 -0400)]
kern/intr: declare interrupt vectors unsigned

These should never get values large enough for sign to matter, but one
of them becoming negative could cause problems.

MFC after: 1 week
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D29327

3 years agotraceroute6: Properly calculate UDP checksum
Zhenlei Huang [Mon, 3 May 2021 16:46:19 +0000 (12:46 -0400)]
traceroute6: Properly calculate UDP checksum

The revision D25604 capsicumize traceroute6. For UDP the send socket was
changed from SOCK_DGRAM to SOCK_RAW and thus the UDP checksum need be
calculated by application itself other than the kernel.

outpacket is filled with zeros by line 707, thus the first round the UDP
checksum is correct. But subsequent rounds outudp->uh_sum will be left
with garbage.

PR: 255507
Reviewed by: ae, markj, tuexen
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D30042

3 years agodevfs: Avoid comparison with an uninitialized var in devfs_fp_check()
Mark Johnston [Mon, 3 May 2021 16:43:29 +0000 (12:43 -0400)]
devfs: Avoid comparison with an uninitialized var in devfs_fp_check()

devvn_refthread() will initialize *devp only if it succeeds, so check for
success before comparing with fp->f_data.  Other devvn_refthread()
callers are careful to do this.

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

3 years agoVOP_STAT: Provide a default value for va_gen
Mark Johnston [Mon, 3 May 2021 16:43:05 +0000 (12:43 -0400)]
VOP_STAT: Provide a default value for va_gen

Some filesystems, e.g., pseudofs and the NFSv3 client, do not provide
one.

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

3 years agosmp: Initialize arg->cpus sooner in smp_rendezvous_cpus_retry()
Mark Johnston [Mon, 3 May 2021 16:43:00 +0000 (12:43 -0400)]
smp: Initialize arg->cpus sooner in smp_rendezvous_cpus_retry()

Otherwise, if !smp_started is true, then smp_rendezvous_cpus_done() will
harmlessly perform an atomic RMW on an uninitialized variable.

Reported by: KMSAN
MFC after: 1 week
Sponsored by: The FreeBSD Foundation

3 years agobhyve: Set SO_REUSEADDR on the gdb stub socket
Mark Johnston [Mon, 3 May 2021 16:42:54 +0000 (12:42 -0400)]
bhyve: Set SO_REUSEADDR on the gdb stub socket

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

3 years agofilt_timerexpire: do not iterate over the interval
Konstantin Belousov [Wed, 28 Apr 2021 16:28:49 +0000 (19:28 +0300)]
filt_timerexpire: do not iterate over the interval

User-supplied data might make this loop too time-consuming. Divide
directly, and handle both the possibility that we were woken up earlier,
and arithmetic overflows/underflows from the calculation.

Reported and tested by: pho (previous version)
Reviewed by: markj
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D30069

3 years agondis: remove leftover ndis_events binary and manpage
Dimitry Andric [Mon, 3 May 2021 16:37:31 +0000 (18:37 +0200)]
ndis: remove leftover ndis_events binary and manpage

Fixes: bfc99943b04b ("ndis(4): remove as previous announced")

3 years agogcore: add option to dump core using kernel facility
Konstantin Belousov [Sat, 24 Apr 2021 11:20:24 +0000 (14:20 +0300)]
gcore: add option to dump core using kernel facility

-k switch causes gcore to use ptrace(PT_COREDUMP) instead of manually
reading process memory and constructing the core.

Reviewed by: markj
Tested by: pho
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D29955

3 years agogcore: split code to open core file into helper
Konstantin Belousov [Sat, 24 Apr 2021 10:31:58 +0000 (13:31 +0300)]
gcore: split code to open core file into helper

Reviewed by: markj
Tested by: pho
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D29955

3 years agoAdd ptrace(PT_COREDUMP)
Konstantin Belousov [Fri, 23 Apr 2021 13:26:01 +0000 (16:26 +0300)]
Add ptrace(PT_COREDUMP)

It writes the core of live stopped process to the file descriptor
provided as an argument.

Based on the initial version from https://reviews.freebsd.org/D29691,
submitted by MichaÅ‚ Górny <mgorny@gentoo.org>.

Reviewed by: markj
Tested by: pho
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D29955

3 years agoptracestop: mark threads suspended there with the new TDB_SSWITCH flag
Konstantin Belousov [Sat, 24 Apr 2021 12:02:40 +0000 (15:02 +0300)]
ptracestop: mark threads suspended there with the new TDB_SSWITCH flag

This way threads in ptracestop can be discovered by debugger

Reviewed by: markj
Tested by: pho
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D29955

3 years agoptrace: do not allow for parallel ptrace requests
Konstantin Belousov [Sat, 24 Apr 2021 11:57:40 +0000 (14:57 +0300)]
ptrace: do not allow for parallel ptrace requests

Set a new P2_PTRACEREQ flag around the request Wait for the target     .
process P2_PTRACEREQ flag to clear before setting ours                 .

Otherwise, we rely on the moment that the process lock is not dropped
until the stopped target state is important.  This is going to be no
longer true after some future change.

Reviewed by: markj
Tested by: pho
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D29955

3 years agokern_ptrace(): extract code to determine ptrace eligibility into helper
Konstantin Belousov [Sat, 24 Apr 2021 11:52:11 +0000 (14:52 +0300)]
kern_ptrace(): extract code to determine ptrace eligibility into helper

Reviewed by: markj
Tested by: pho
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D29955

3 years agokern_ptrace: change type of proctree_locked to bool
Konstantin Belousov [Fri, 30 Apr 2021 21:14:26 +0000 (00:14 +0300)]
kern_ptrace: change type of proctree_locked to bool

Tested by: pho
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D29955

3 years agoAdd thread_run_flash() helper
Konstantin Belousov [Sat, 24 Apr 2021 11:47:53 +0000 (14:47 +0300)]
Add thread_run_flash() helper

It unsuspends single suspended thread, passed as the argument.
It is up to the caller to arrange the target thread to suspend later,
since the state of the process is not changed from stopped.  In particular,
the unsuspended thread must not leave to userspace, since boundary code
is not prepared to this situation.

Reviewed by: markj
Tested by: pho
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D29955

3 years agoAdd sleepq_remove_nested()
Konstantin Belousov [Sun, 25 Apr 2021 00:01:32 +0000 (03:01 +0300)]
Add sleepq_remove_nested()

The helper removes the thread from a sleep queue, assuming that it would
need to sleep. The sleepq_remove_nested() function is intended for quite
special case, where suspended thread from traced stopped process is
temporary unsuspended to do some work on behalf of the debugger in the
target context, and this work might require sleep.

Reviewed by: markj
Tested by: pho
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D29955

3 years agoELF coredump: define several useful flags for the coredump operations
Konstantin Belousov [Sat, 24 Apr 2021 11:45:01 +0000 (14:45 +0300)]
ELF coredump: define several useful flags for the coredump operations

- SVC_ALL request dumping all map entries, including those marked as
  non-dumpable
- SVC_NOCOMPRESS disallows compressing the dump regardless of the sysctl
  policy
- SVC_PC_COREDUMP is provided for future use by userspace core dump
  request

Reviewed by: markj
Tested by: pho
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D29955

3 years agoimgact_elf: consistently pass flags from coredump down to helper functions
Konstantin Belousov [Sat, 24 Apr 2021 11:42:56 +0000 (14:42 +0300)]
imgact_elf: consistently pass flags from coredump down to helper functions

Reviewed by: markj
Tested by: pho
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D29955

3 years agodaemon: add some basic tests
Alan Somers [Wed, 17 Mar 2021 16:35:00 +0000 (10:35 -0600)]
daemon: add some basic tests

MFC after: 2 weeks
Sponsored by: Axcient
Differential Revision: https://reviews.freebsd.org/D29316

3 years agocam: fix integer overflow during inquiry
Edward Tomasz Napierala [Mon, 3 May 2021 13:46:11 +0000 (14:46 +0100)]
cam: fix integer overflow during inquiry

From my understanding this could happen with iSCSI LUNs with
unusually long names.  The bug would make CAM fail to retrieve
the full inquiry data.  Instead of bumping the size of the local
variable, just use a macro.

Reviewed By: imp, mav
Sponsored by: NetApp, Inc.
Sponsored by: Klara, Inc.
X-NetApp-PR: #50
Differential Revision: https://reviews.freebsd.org/D29991

3 years agoAdd Apollo Lake SIO/LPSS UARTs PCI IDs
Jose Luis Duran [Sun, 2 May 2021 21:20:25 +0000 (21:20 +0000)]
Add Apollo Lake SIO/LPSS UARTs PCI IDs

Add PCI IDs for Intel Apollo Lake Series HSUARTs:

    # pciconf -ll
    drv   selector      class    rev  hdr  vendor device subven subdev
    uart0@pci0:0:24:0:  118000   0b   00   8086   5abc   8086   7270
    uart1@pci0:0:24:1:  118000   0b   00   8086   5abe   8086   7270
    uart2@pci0:0:24:2:  118000   0b   00   8086   5ac0   8086   7270
    uart3@pci0:0:24:3:  118000   0b   00   8086   5aee   8086   7270

NB (Intel Document Number 336256-004US):
1. The E3900 and A3900 Series Processors support four LPSS_UART ports,
   while the N- and J- Series Processors support only LPSS_UART [2:1]
   ports.
2. The LPSS_UART1 port is dedicated for discrete Global Navigation
   Satellite System (GNSS).  This port can be used for generic UART
   functionality if GNSS is not used.
3. The LPSS_UART2 port is dedicated for host OS debug.
4. The LPSS_UART0 and LPSS_UART3 ports are for generic UART functionality.
5. Only UART [1:0] ports support DMA.

PR: 255556
Submitted by: Jose Luis Duran <jlduran@gmail.com>
MFC after: 1 week

3 years agouart_bus_pci.c: Style
Jose Luis Duran [Sun, 2 May 2021 21:20:25 +0000 (21:20 +0000)]
uart_bus_pci.c: Style

Wrap long lines, use tab instead of spaces.

PR: 255556
Submitted by: Jose Luis Duran <jlduran@gmail.com>
MFC after: 1 week

3 years agoifconfig: Minor documentation fix
Jose Luis Duran [Thu, 29 Apr 2021 11:03:48 +0000 (11:03 +0000)]
ifconfig: Minor documentation fix

Fix what appears to have been a small copy/paste typo in ifconfig(8)'s
documentation (man page and header file).

Not that it matters anymore.

Reference: Table I-2 in IEEE Std 802.1Q-2014.

PR: 255557
Submitted by: Jose Luis Duran <jlduran@gmail.com>
MFC after: 1 week

3 years agoAlso enable IPIs on 32-bit arm
Andrew Turner [Sun, 2 May 2021 10:05:03 +0000 (10:05 +0000)]
Also enable IPIs on 32-bit arm

This was missed in 2420f6a

Reported by: tuexen, imp

3 years agoservice/ipfw: Silence warning on restart
Lutz Donnerhacke [Sun, 2 May 2021 20:47:04 +0000 (22:47 +0200)]
service/ipfw: Silence warning on restart

Once the ipfw0 interface has been created, ifconfig(8) create will
throw a warning: ifconfig: create: bad value' when trying to create it
again.

PR: 241013
Submitted by: Jose Luis Duran
Approved by: kp
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D30083

3 years agostress2: Added a regression test
Peter Holm [Mon, 3 May 2021 07:08:43 +0000 (09:08 +0200)]
stress2: Added a regression test

3 years agostress2: Added a syzkaller reproducer
Peter Holm [Mon, 3 May 2021 07:05:32 +0000 (09:05 +0200)]
stress2: Added a syzkaller reproducer

3 years agostress2: Fix a typo.
Peter Holm [Mon, 3 May 2021 06:45:55 +0000 (08:45 +0200)]
stress2: Fix a typo.

3 years agosctp: improve address list scanning
Michael Tuexen [Mon, 3 May 2021 00:50:05 +0000 (02:50 +0200)]
sctp: improve address list scanning

If the alternate address has to be removed, force the stack to
find a new one, if it is still needed.

MFC after: 3 days

3 years agosctp: improve restart handling
Michael Tuexen [Mon, 3 May 2021 00:20:24 +0000 (02:20 +0200)]
sctp: improve restart handling

This fixes in particular a possible use after free bug reported
Anatoly Korniltsev and Taylor Brandstetter for the userland stack.

MFC after: 3 days

3 years agoFix build after 5f2e1835054ee84f2e68ebc890d92716a91775b7.
Alexander Motin [Mon, 3 May 2021 00:07:38 +0000 (20:07 -0400)]
Fix build after 5f2e1835054ee84f2e68ebc890d92716a91775b7.

3 years agoImprove UMA cache reclamation.
Alexander Motin [Sun, 2 May 2021 23:35:28 +0000 (19:35 -0400)]
Improve UMA cache reclamation.

When estimating working set size, measure only allocation batches, not free
batches.  Allocation and free patterns can be very different.  For example,
ZFS on vm_lowmem event can free to UMA few gigabytes of memory in one call,
but it does not mean it will request the same amount back that fast too, in
fact it won't.

Update working set size on every reclamation call, shrinking caches faster
under pressure.  Lack of this caused repeating vm_lowmem events squeezing
more and more memory out of real consumers only to make it stuck in UMA
caches.  I saw ZFS drop ARC size in half before previous algorithm after
periodic WSS update decided to reclaim UMA caches.

Introduce voluntary reclamation of UMA caches not used for a long time. For
each zdom track longterm minimal cache size watermark, freeing some unused
items every UMA_TIMEOUT after first 15 minutes without cache misses. Freed
memory can get better use by other consumers.  For example, ZFS won't grow
its ARC unless it see free memory, since it does not know it is not really
used.  And even if memory is not really needed, periodic free during
inactivity periods should reduce its fragmentation.

Reviewed by: markj, jeff (previous version)
MFC after: 2 weeks
Sponsored by: iXsystems, Inc.
Differential Revision: https://reviews.freebsd.org/D29790

3 years agosctp: improve error handling in INIT/INIT-ACK processing
Michael Tuexen [Sun, 2 May 2021 20:38:27 +0000 (22:38 +0200)]
sctp: improve error handling in INIT/INIT-ACK processing

When processing INIT and INIT-ACK information, also during
COOKIE processing, delete the current association, when it
would end up in an inconsistent state.

MFC after: 3 days

3 years agocopy_file_range(2): improve copying of a large hole to EOF
Rick Macklem [Sun, 2 May 2021 23:04:27 +0000 (16:04 -0700)]
copy_file_range(2): improve copying of a large hole to EOF

PR#255523 reported that a file copy for a file with a large hole
to EOF on ZFS ran slowly over NFSv4.2.
The problem was that vn_generic_copy_file_range() would
loop around reading the hole's data and then see it is all
0s. It was coded this way since UFS always allocates a data
block near the end of the file, such that a hole to EOF never exists.

This patch modifies vn_generic_copy_file_range() to check for a
ENXIO returned from VOP_IOCTL(..FIOSEEKDATA..) and handle that
case as a hole to EOF. asomers@ confirms that it works for his
ZFS test case.

PR: 255523
Tested by: asomers
Reviewed by: asomers
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D30076

3 years agosbin/ipfw: Fix null pointer deference when printing counters
Lutz Donnerhacke [Fri, 30 Apr 2021 14:12:47 +0000 (16:12 +0200)]
sbin/ipfw: Fix null pointer deference when printing counters

ipfw -[tT] prints statistics of the last access. If the rule was never
used, the counter might be not exist.  This happens unconditionally on
inserting a new rule.  Avoid printing statistics in this case.

PR: 255491
Reported by: Haisheng Zhouz
Reviewed by: ae
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D30046

3 years agousr.bin/netstat: use roundup2 when rounding up to power of 2.
Xin LI [Sun, 2 May 2021 16:30:22 +0000 (09:30 -0700)]
usr.bin/netstat: use roundup2 when rounding up to power of 2.

MFC after:  2 weeks

3 years agousr.bin/patch: remove unneeded header.
Xin LI [Sun, 2 May 2021 16:27:32 +0000 (09:27 -0700)]
usr.bin/patch: remove unneeded header.

MFC after: 2 weeks

3 years agoAdd myself (vishwin) as a ports committer
Charlie Li [Sun, 2 May 2021 05:15:14 +0000 (01:15 -0400)]
Add myself (vishwin) as a ports committer

Following section 7.1 in Committer's Guide.

Approved by: arrowd (mentor)
Differential Revision: https://reviews.freebsd.org/D30078

3 years agoEnable IPIs on CPU 0 on arm and arm64
Andrew Turner [Sun, 2 May 2021 07:43:34 +0000 (07:43 +0000)]
Enable IPIs on CPU 0 on arm and arm64

Not all interrupt controllers enable IPIs by default as the Arm
GIC specs make it an implementation defined option. As at least two
hypervisors have also previously masked the IPIs on boot.

As we already enable these IPIs on the non-boot CPUs it is expected
this is a safe operation.

Differential Revision: https://reviews.freebsd.org/D26975

3 years agoImplement bus_map_resource on arm64
Andrew Turner [Sat, 10 Apr 2021 10:25:39 +0000 (10:25 +0000)]
Implement bus_map_resource on arm64

This will allow us to allocate an unmapped memory resource, then
later map it with a specific memory attribute.

This is also needed for virtio with the modern PCI attachment.

Reviewed by: kib (via D29723)
Sponsored by: Innovate UK
Differential Revision: https://reviews.freebsd.org/D29694

3 years agoless: upgrade to v581.2.
Xin LI [Sun, 2 May 2021 06:16:08 +0000 (23:16 -0700)]
less: upgrade to v581.2.

MFC after: 1 week

3 years agoVendor import of less v581.2.
Xin LI [Sun, 2 May 2021 06:13:19 +0000 (23:13 -0700)]
Vendor import of less v581.2.

3 years agopowerpc/xive: Remove POWER9 DD1 IRQ bits
Justin Hibbits [Mon, 26 Apr 2021 18:04:42 +0000 (13:04 -0500)]
powerpc/xive: Remove POWER9 DD1 IRQ bits

The OPAL_XIVE_*_VIA_IFW flags are used only for POWER9 DD1, which we
don't support.

Noticed while perusing Linux and skiboot git logs.

3 years agoFix building sysctl(8) after c78ad20
Andrew Turner [Sat, 1 May 2021 11:10:03 +0000 (11:10 +0000)]
Fix building sysctl(8) after c78ad20

In sysctl we parse an efi header on amd64. Fix this after changing the
virtual memory type from a void * to a uint64_t in c78ad20.

3 years agoSwitch the EFI virtual address to a uint64_t
Andrew Turner [Wed, 14 Apr 2021 08:22:06 +0000 (08:22 +0000)]
Switch the EFI virtual address to a uint64_t

It is defined as a uint64_t in the UEFI spec. As it's not used as a
pointer by the kernel follow this and define it as the same in the
kernel.

Reviewed by: kib, manu, imp
Sponsored by: Innovate UK
Differential Revision: https://reviews.freebsd.org/D29759

3 years agoAdd a way to map arm64 non-posted device memory
Andrew Turner [Thu, 8 Apr 2021 11:54:20 +0000 (11:54 +0000)]
Add a way to map arm64 non-posted device memory

On arm64 we currently use a non-posted write for device memory, however
we should move to use posted writes. This is expected to work on most
hardware, however we will need to support a non-posted option for some
broken hardware.

Reviewed by: imp, manu, bcr (manpage)
Differential Revision: https://reviews.freebsd.org/D29722

3 years agopowerpc64: Optimize radix trap handling a little more
Justin Hibbits [Sat, 1 May 2021 00:58:11 +0000 (19:58 -0500)]
powerpc64: Optimize radix trap handling a little more

Summary:
Since PCPU can live in a GPR for a while longer, let it, rather than
re-getting it in yet another register.  MFSPR is an expensive operation,
12 clock latency on POWER9, so the fewer operations we need, the better.

Since the check is tightly coupled to the fetch, by reducing the number
of fetch+check, we reduce the stalls, and improve the performance
marginally.  Buildworld was measured at a ~5-7% improvement on a single
run.

Reviewed By: nwhitehorn
Differential Revision: https://reviews.freebsd.org/D30003

3 years agogicv3_its: Flush cache after allocating ITT memory
Marcin Wojtas [Thu, 29 Apr 2021 09:39:09 +0000 (11:39 +0200)]
gicv3_its: Flush cache after allocating ITT memory

It has to be zeroed before committing it to device.
We do that by allocating it with M_ZERO, but there was no
memory barrier or cache flush to ensure its sees it zeroed.
This fixes MSIX on LS1028A SoC.

Submitted by: Kornel Duleba <mindal@semihalf.com>
Reviewed by: andrew
Obtained from: Semihalf
Sponsored by: Alstom Group
Differential Revision: https://reviews.freebsd.org/D30033

3 years agoWait longer for a previous IPI to be sent
Eric van Gyzen [Mon, 26 Apr 2021 15:01:17 +0000 (10:01 -0500)]
Wait longer for a previous IPI to be sent

When sending an IPI, if a previous IPI is still pending delivery,
native_lapic_ipi_vectored() waits for the previous IPI to be sent.
We've seen a few inexplicable panics with the current timeout of 50 ms.
Increase the timeout to 1 second and make it tunable.

No hardware specification mentions a timeout in this case; I checked
the Intel SDM, Intel MP spec, and Intel x2APIC spec.  Linux and illumos
wait forever.  In Linux, see __default_send_IPI_shortcut() in
arch/x86/kernel/apic/ipi.c.  In illumos, see apic_send_ipi() in
usr/src/uts/i86pc/io/pcplusmp/apic_common.c.  However, misbehaving hardware
could hang the system if we wait forever.

Reviewed by: mav kib
MFC after: 1 week
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D29942

3 years agoEFI secure boot VECTX related changes
Eric van Gyzen [Fri, 30 Apr 2021 17:53:45 +0000 (12:53 -0500)]
EFI secure boot VECTX related changes

When VECTX is enabled as a kernel option and non-EFI loaders are
built, many reads will fail due to the mis-match of whether
LOADER_VERIEXEC_VECTX or not in readin.h.  Source that includes
bootstrap.h must ensure the kernel option agrees with the compile
time CFLAGS in the various make related files.

Submitted by: bret_ketchum@dell.com (original revision)
Reviewed by: sjg, bdrewery, dab, bret_ketchum@dell.com
MFC after: 1 week
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D29993

3 years agoioccom: define ioctl cmd value that can never be valid
Konstantin Belousov [Thu, 22 Apr 2021 19:40:08 +0000 (22:40 +0300)]
ioccom: define ioctl cmd value that can never be valid

Its use is for cases where some filler is needed for cmd, or we need an
indication that there were no cmd supplied, and so on.

Reviewed by: jhb
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D29935

3 years agoconnectat(2): clarify that the s argument is socket
Konstantin Belousov [Wed, 28 Apr 2021 15:47:31 +0000 (18:47 +0300)]
connectat(2): clarify that the s argument is socket

Sponsored by: The FreeBSD Foundation
MFC after: 3 days

3 years agoO_PATH: disable kqfilter for fifos
Konstantin Belousov [Wed, 28 Apr 2021 15:45:36 +0000 (18:45 +0300)]
O_PATH: disable kqfilter for fifos

Filter on fifos is real filter for the object, and not a filesystem
events filter like EVFILT_VNODE.

Reported by: markj using syzkaller
Reviewed by: markj
Sponsored by: The FreeBSD Foundation
MFC after: 3 days

3 years agoamd64: disable LA57 by default for now
Konstantin Belousov [Wed, 28 Apr 2021 15:50:16 +0000 (18:50 +0300)]
amd64: disable LA57 by default for now

A testing on the real hardware uncovered an issue, and since I do not have
access to the machine, disable until the bug can be fixed.

Reported by: "Pieper, Jeffrey E" <jeffrey.e.pieper@intel.com>
Sponsored by: The FreeBSD Foundation
MFC after: 3 days

3 years agoamd64: invalidate TLB between page table update and access
Konstantin Belousov [Fri, 16 Apr 2021 18:28:08 +0000 (21:28 +0300)]
amd64: invalidate TLB between page table update and access

When setting up trampoline mapping for LA57 switcher, it is possible
that TLB still has some random mapping at that address.

Sponsored by: The FreeBSD Foundation
MFC after: 1 week

3 years agoAdd myself(oh) as src committer and mentor(manu).
Oskar Holmlund [Fri, 30 Apr 2021 12:49:20 +0000 (14:49 +0200)]
Add myself(oh) as src committer and mentor(manu).

Step 7.1.5 in committers guide.

Reviewed by: manu
Approved by: manu (mentor)
Differential Revision: https://reviews.freebsd.org/D29890

3 years agosctp: update the vtag for INIT and INIT-ACK chunks
Michael Tuexen [Fri, 30 Apr 2021 11:31:38 +0000 (13:31 +0200)]
sctp: update the vtag for INIT and INIT-ACK chunks

This is needed in case of responding with an ABORT to an INIT-ACK.

3 years agoiflib: Take iri_pad into account when processing small frames
Marcin Wojtas [Tue, 27 Apr 2021 09:00:15 +0000 (11:00 +0200)]
iflib: Take iri_pad into account when processing small frames

Drivers can specify padding of received frames with iri_pad field.
This can be used to enforce ip alignment by hardware.
Iflib ignored that padding when processing small frames,
which rendered this feature inoperable.
I found it while writing a driver for a NIC that can ip align
received packets. Note that this doesn't change behavior of existing
drivers as they all set iri_pad to 0.

Submitted by: Kornel Duleba <mindal@semihalf.com>
Reviewed by: gallatin
Obtained from: Semihalf
Sponsored by: Alstom Group
Differential Revision: https://reviews.freebsd.org/D30009

3 years agosctp: fix SCTP_PEER_ADDR_PARAMS socket option
Michael Tuexen [Fri, 30 Apr 2021 10:27:47 +0000 (12:27 +0200)]
sctp: fix SCTP_PEER_ADDR_PARAMS socket option

Ignore spp_pathmtu if it is 0, when setting the IPPROTO_SCTP level
socket option SCTP_PEER_ADDR_PARAMS as required by RFC 6458.

MFC after: 1 week

3 years agopf tests: Test scrub fragment reassemble on interfaces with different MTU
Kristof Provost [Tue, 27 Apr 2021 16:46:03 +0000 (18:46 +0200)]
pf tests: Test scrub fragment reassemble on interfaces with different MTU

There's a problem with pf's reassembly code where it produces incorrect
checksums when reassembling across interfaces with different MTUs.
Test this.

PR: 255432
Reviewed by: donner
MFC after: 1 week
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D30013

3 years agopf: Fix IP checksum on reassembly
Kristof Provost [Wed, 28 Apr 2021 10:56:06 +0000 (12:56 +0200)]
pf: Fix IP checksum on reassembly

If we reassemble a packet we modify the IP header (to set the length and
remove the fragment offset information), but we failed to update the
checksum. On certain setups (mostly where we did not re-fragment again
afterwards) this could lead to us sending out packets with incorrect
checksums.

PR: 255432
MFC after: 1 week
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D30026

3 years agosctp: use RTO.Initial of 1 second as specified in RFC 4960bis
Michael Tuexen [Thu, 29 Apr 2021 22:45:56 +0000 (00:45 +0200)]
sctp: use RTO.Initial of 1 second as specified in RFC 4960bis

3 years agosctp: improve consistency in handling chunks with wrong size
Michael Tuexen [Wed, 28 Apr 2021 16:09:11 +0000 (18:09 +0200)]
sctp: improve consistency in handling chunks with wrong size

Just skip the chunk, if no other handling is required by the
specification.

3 years agokasan.9: A couple of fixups
Mark Johnston [Thu, 29 Apr 2021 16:26:03 +0000 (12:26 -0400)]
kasan.9: A couple of fixups

- Mention GENERIC-KASAN.
- Note that the runtime was ported from NetBSD.

Sponsored by: The FreeBSD Foundation

3 years agokasan: Use vm_offset_t for the first parameter to kasan_shadow_map()
Mark Johnston [Thu, 29 Apr 2021 15:39:02 +0000 (11:39 -0400)]
kasan: Use vm_offset_t for the first parameter to kasan_shadow_map()

No functional change intended.

Sponsored by: The FreeBSD Foundation

3 years agoipmi: support getting address from EFI
Yinlong Lu [Thu, 29 Apr 2021 10:04:36 +0000 (05:04 -0500)]
ipmi: support getting address from EFI

The original implementation only supports getting the address from legacy
BIOS (by searching for the SMBIOS_SIG pattern in a fixed address space).

Try to get the SMBIOS table from EFI through efirt (EFI Runtime Services)
firstly.  Continue to search in the legacy BIOS if a NULL address is
returned from EFI.

By this way the ipmi function supports both legacy BIOS and UEFI systems.

Reviewed by: dab, vangyzen
MFC after: 1 week
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D30007

3 years agosrc.libnames.mk: Remove redundant am-utils library definition
Cy Schubert [Thu, 22 Apr 2021 06:17:08 +0000 (23:17 -0700)]
src.libnames.mk: Remove redundant am-utils library definition

r358821 (13f7dbe822d5f447c6137dc0d4ff838fb7050dbe) retired amd(8).
This commit cleans up an artifact left in src.libnames.mk.

Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D29914

3 years agopf: Trivial typo fix
Kristof Provost [Thu, 29 Apr 2021 08:34:00 +0000 (10:34 +0200)]
pf: Trivial typo fix

PV -> PF

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

3 years agoarm: add a release conf for distribution files
Mitchell Horne [Thu, 29 Apr 2021 13:10:08 +0000 (10:10 -0300)]
arm: add a release conf for distribution files

We do not currently generate armv7 distribution sets, because we don't
build any installer images. However, having such sets available can be
useful for quickly installing a base system, particularly in the case
of creating an armv7 poudriere jail on arm64.

Add a configuration file for the generation of these distribution sets.

Reviewed by: manu, imp, gjb
MFC after: 3 weeks
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D29923

3 years agoSynch index of contrib/bc with what is in workdir after cloning.
Michael Gmelin [Thu, 29 Apr 2021 12:29:04 +0000 (14:29 +0200)]
Synch index of contrib/bc with what is in workdir after cloning.

From a workdir perspective this should be a no-op.
See also:
https://lists.freebsd.org/pipermail/freebsd-current/2021-April/079569.html

3 years agopci_vendors: update to 2021.04.26
Baptiste Daroussin [Thu, 29 Apr 2021 04:46:26 +0000 (06:46 +0200)]
pci_vendors: update to 2021.04.26

3 years agopkg(7): replace usage of sbuf(9) with open_memstream(3)
Baptiste Daroussin [Tue, 27 Apr 2021 02:38:55 +0000 (04:38 +0200)]
pkg(7): replace usage of sbuf(9) with open_memstream(3)

open_memstream(3) is a standard way to obtain the same feature we do get
by using sbuf(9) (aka dynamic size buffer), switching to using it makes
pkg(7) more portable, and reduces its number of dependencies.

Reviewed by: manu
Differential Revision: https://reviews.freebsd.org/D30005