]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
2 years agoawk: revert upstream's attempt to disallow hex strings
Warner Losh [Thu, 15 Jul 2021 22:46:06 +0000 (16:46 -0600)]
awk: revert upstream's attempt to disallow hex strings

Upstream one-true-awk decided to disallow hex strings as numbers. This
is in line with awk's behavior prior to C99, and allowed by the POSIX
standard. The standard, however, allows them to be treated as numbers
because that's what the standard said in the 2001 through 2004 editions.
Since 2001, the nawk in FreeBSD has treated them as numbers, so restore
that behavior, allowed by the standard.

A number of scripts in the FreeBSD tree depend on this interpretation,
including scripts to build the kernel which had mysteriously started
failing for some people and not others. By re-allowing 0x hex numbers,
this fixes those scripts and restores POLA.

Upstream issue: https://github.com/onetrueawk/awk/issues/126
Sponsored by: Netflix
Reviewed by: kevans
MFC After: asap due to regression alrady merged to stable
Differential Revision: https://reviews.freebsd.org/D31199

(cherry picked from commit d4d252c49976de33d0a2926df733744d0b8d95fa)

2 years agopf: add pf_find_state_all_exists
Mateusz Guzik [Thu, 8 Jul 2021 13:11:57 +0000 (15:11 +0200)]
pf: add pf_find_state_all_exists

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

(cherry picked from commit 19d6e29b872232c47190344f3dfded2f73edd8ae)

2 years agopf: padalign global locks found in pf.c
Mateusz Guzik [Mon, 5 Jul 2021 09:26:29 +0000 (11:26 +0200)]
pf: padalign global locks found in pf.c

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

(cherry picked from commit f649cff58721f493f218a4d1fb88a12255945472)

2 years agopf: allow table stats clearing and reading with ruleset rlock
Mateusz Guzik [Fri, 2 Jul 2021 12:55:57 +0000 (14:55 +0200)]
pf: allow table stats clearing and reading with ruleset rlock

Instead serialize against these operations with a dedicated lock.

Prior to the change, When pushing 17 mln pps of traffic, calling
DIOCRGETTSTATS in a loop would restrict throughput to about 7 mln.  With
the change there is no slowdown.

Reviewed by: kp (previous version)
Sponsored by: Rubicon Communications, LLC ("Netgate")

(cherry picked from commit dc1ab04e4c9ede3606985e0cce1200e3060ac166)

2 years agopf: depessimize table handling
Mateusz Guzik [Fri, 2 Jul 2021 11:19:56 +0000 (13:19 +0200)]
pf: depessimize table handling

Creating tables and zeroing their counters induces excessive IPIs (14
per table), which in turns kills single- and multi-threaded performance.

Work around the problem by extending per-CPU counters with a general
counter populated on "zeroing" requests -- it stores the currently found
sum. Then requests to report the current value are the sum of per-CPU
counters subtracted by the saved value.

Sample timings when loading a config with 100k tables on a 104-way box:

stock:

pfctl -f tables100000.conf  0.39s user 69.37s system 99% cpu 1:09.76 total
pfctl -f tables100000.conf  0.40s user 68.14s system 99% cpu 1:08.54 total

patched:

pfctl -f tables100000.conf  0.35s user 6.41s system 99% cpu 6.771 total
pfctl -f tables100000.conf  0.48s user 6.47s system 99% cpu 6.949 total

Reviewed by: kp (previous version)
Sponsored by: Rubicon Communications, LLC ("Netgate")

(cherry picked from commit f92c21a28cd856834249a008771b2f002e477a39)

2 years agolibalias: fix divide by zero causing panic
Stefan Eßer [Sat, 10 Jul 2021 11:00:56 +0000 (13:00 +0200)]
libalias: fix divide by zero causing panic

The packet_limit can fall to 0, leading to a divide by zero abort in
the "packets % packet_limit".

An possible solution would be to apply a lower limit of 1 after the
calculation of packet_limit, but since any number modulo 1 gives 0,
the more efficient solution is to skip the modulo operation for
packet_limit <= 1.

Reported by: Karl Denninger <karl@denninger.net>

(cherry picked from commit 58080fbca09fda6d5f011d37059edbca8ceb4c58)

2 years agopf: rename pf_state to pf_kstate
Kristof Provost [Tue, 6 Jul 2021 09:42:20 +0000 (11:42 +0200)]
pf: rename pf_state to pf_kstate

Indicate that this is a kernel-only structure, and make it easier to
distinguish from others used to communicate with userspace.

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

(cherry picked from commit 211cddf9e3a1bc0d4b1b94bea7d16a47b5a17f49)

2 years agotcp: tolerate missing timestamps
Michael Tuexen [Fri, 11 Jun 2021 18:14:34 +0000 (20:14 +0200)]
tcp: tolerate missing timestamps

Some TCP stacks negotiate TS support, but do not send TS at all
or not for keep-alive segments. Since this includes modern widely
deployed stacks, tolerate the violation of RFC 7323 per default.

Reviewed by: rgrimes, rrs, rscheff
Differential Revision: https://reviews.freebsd.org/D30740
Sponsored by: Netflix, Inc.

(cherry picked from commit 870af3f4dc57a6bbfc03f6a49ca0d5b7ff1b975a)

2 years agozfsd: Check for error from zpool_vdev_online
Ryan Moeller [Tue, 6 Jul 2021 16:00:18 +0000 (16:00 +0000)]
zfsd: Check for error from zpool_vdev_online

Onlining a vdev can fail. Log the error if it does.

Reviewed by: mav, asomers
MFC after: 1 week
Sponsored by: iXsystems, Inc.
Differential Revision: https://reviews.freebsd.org/D30882

(cherry picked from commit 53b438b2425c374f6147ac80b3330a9ec08432bb)

2 years agonvme(4): Report NPWA before NPWG as stripesize.
Alexander Motin [Tue, 6 Jul 2021 02:19:48 +0000 (22:19 -0400)]
nvme(4): Report NPWA before NPWG as stripesize.

New Samsung 980 SSDs report Namespace Preferred Write Alignment of
8 (4KB) and Namespace Preferred Write Granularity of 32 (16KB).
My quick tests show that 16KB is a minimal sequential write size
when the SSD reaches peak IOPS, so writing much less is very slow.
But writing slightly less or slightly more does not change much,
so it seems not so much a size granularity as minimum I/O size.

Thinking about different stripesize consumers:
 - Partition alignment should be based on NPWA by definition.
 - ZFS ashift in part of forcing alignment of all I/Os should also
be based on NPWA.  In part of forcing size granularity, if really
needed, it may be set to NPWG, but too big value can make ZFS too
space-inefficient, and the 16KB is actually the biggest supported
value there now.
 - ZFS recordsize/volblocksize could potentially be tuned up toward
NPWG to work as I/O size granularity, but enabled compression makes
it too fuzzy.  And those are normally user-configurable things.
 - ZFS I/O aggregation code could definitely use Optimal Write Size
value and may be NPWG, but we don't have fields in GEOM now to report
the minimal and optimal I/O sizes, and even maximal is not reported
outside GEOM DISK to be used by ZFS.

MFC after: 1 week

(cherry picked from commit e3bcd07d834def94dcf570ac7350ca2c454ebf10)

2 years agoclang: stop linking _p libs for -pg as of FreeBSD 14
Ed Maste [Sat, 26 Jun 2021 23:58:16 +0000 (19:58 -0400)]
clang: stop linking _p libs for -pg as of FreeBSD 14

In FreeBSD 14 we will stop providing _p libraries (compiled with -pg).

[Note this is controlled by the target version.  There is no change for
FreeBSD <= 13.]

Reviewed by: dim (upstream)
Obtained from: LLVM 699d47472c3f
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D30861

(cherry picked from commit b762974cf4b9ea77f1decf4a6d829372f0a97f75)

2 years agoibstat: Include prototype for sysctlbyname().
Hans Petter Selasky [Thu, 27 May 2021 07:39:49 +0000 (09:39 +0200)]
ibstat: Include prototype for sysctlbyname().

Fixes the following compile warning:
      implicit declaration of function 'sysctlbyname' is invalid in C99
      [-Wimplicit-function-declaration]

Found by: J87
Differential Revision: https://reviews.freebsd.org/D30484
Sponsored by: Mellanox Technologies // NVIDIA Networking

(cherry picked from commit 16fa3dcba027d13dcda9ee78e6057e3e5a79f80c)

2 years agoImprove handling of USB device re-open in the LibUSB v1.x API.
Hans Petter Selasky [Fri, 11 Jun 2021 15:06:10 +0000 (17:06 +0200)]
Improve handling of USB device re-open in the LibUSB v1.x API.

Make sure the "device_is_gone" flag is cleared after every successful open,
so that the "device_is_gone" flag doesn't persist forever.

Found by: sergii.dmytruk@3mdeb.com
PR: 256296
Sponsored by: Mellanox Technologies // NVIDIA Networking

(cherry picked from commit 6847ea50196f1a685be408a24f01cb8d407da19c)

2 years agoThis should have been committed in r348511 with the awk update.
Warner Losh [Sun, 2 Jun 2019 16:44:50 +0000 (16:44 +0000)]
This should have been committed in r348511 with the awk update.

It was in my tree, the build worked, but I committed from contrib/one-true-awk
rather than the top level, so was omitted.

(cherry picked from commit e9b659753c07b539df17441012b0bfa5ebdbe0ea)

2 years agoone-true-awk: import 20210221 (1e4bc42c53a1) which fixes a number of bugs
Warner Losh [Wed, 7 Jul 2021 23:30:35 +0000 (17:30 -0600)]
one-true-awk: import 20210221 (1e4bc42c53a1) which fixes a number of bugs

Import the latest bsd-features branch of the one-true-awk upstream:

o Move to bison for $YACC
o Set close-on-exec flag for file and pipe redirects that aren't std*
o lots of little fixes to modernize ocde base
o free sval member before setting it
o fix a bug where a{0,3} could match aaaa
o pull in systime and strftime from NetBSD awk
o pull in fixes from {Net,Free,Open}BSD (normalized our code with them)
o add BSD extensions and, or, xor, compl, lsheift, rshift (mostly a nop)

Also revert a few of the trivial FreeBSD changes that were done slightly
differently in the upstreaming process. Also, our PR database may have
been mined by upstream for these fixes, and Mikolaj Golub may deserve
credit for some of the fixes in this update.

Suggested by: Mikolaj Golub <to.my.trociny@gmail.com>
PR: 143363,143365,143368,143369,143373,143375,214782
Sponsored by: Netflix

(cherry picked from commit f39dd6a9784467f0db5886012b3f4b13899be6b8)

2 years agoFix another UBSan error in awk
Alex Richardson [Mon, 21 Sep 2020 19:03:12 +0000 (19:03 +0000)]
Fix another UBSan error in awk

This applies my upstreamed fix: https://github.com/onetrueawk/awk/commit/ad9bd2f40a89ec9533b92254b86a756cf4f40fd4
Found By: UBSan

(cherry picked from commit 1116946093d537569a29692a6a86de59cd49384e)

2 years agoawk: Fix subobject out-of-bounds access
Alex Richardson [Mon, 21 Sep 2020 19:03:07 +0000 (19:03 +0000)]
awk: Fix subobject out-of-bounds access

When matching a regex with ^, it would attempt to access
gototab[NSTATES][NCHARS+2], and therefore access the state for the \002
character instead. This change is required to run awk under CHERI (with
sub-object bounds) and when running with UBSan instrumentation.

This was committed upstream as https://github.com/onetrueawk/awk/commit/cbf924342b63a095a4c6842280c3085b1b63ae45

Found by: CHERI (with subobject bounds enabled)
Obtained from: CheriBSD
Reviewed By: imp
Differential Revision: https://reviews.freebsd.org/D26509

(cherry picked from commit ae692c42cb46a5e72772070070840b15dd5d6bd8)

2 years agoAnother partial revert of r301289.
Warner Losh [Mon, 3 Jun 2019 05:25:22 +0000 (05:25 +0000)]
Another partial revert of r301289.

In this case, a change was made in one-true-awk from *FS to
getsval(fsloc) in a line just after one of the lines that had the 0 ->
NULL change. It works both ways as far as I can tell.  It looks like a
bug fix, but I've not tried to track down which ancient version of
one-true-awk it was in (github starts too late for tracking this
down). Before and after the changes the regression suite is passes
100% relative to the un-modified one-true-awk.

(cherry picked from commit d9e8cf281b12ca943d150b29ae5a847b0df888f3)

2 years agoFix mismerge that crept into r301289.
Warner Losh [Mon, 3 Jun 2019 05:25:16 +0000 (05:25 +0000)]
Fix mismerge that crept into r301289.

The conversion of 0 -> NULL required a rebase at some point, as noted
in r301289 when pfg commited it. In that rebase, three lines remained
that had been removed in a prior version of awk, and one of them had a
0 -> NULL change causing a conflict. The conflict should have been
resolved by removing the three lines, but wasn't. This introduces a
regression into f.split3 test which prior to this commit we were
failing, but a pure onetrueawk wasn't. Remove the offending 3 lines.

(cherry picked from commit 31d232c2a3c18fb05e5b2f1ec42872708cbfd27e)

2 years agoRevert r348518
Warner Losh [Sun, 2 Jun 2019 20:52:21 +0000 (20:52 +0000)]
Revert r348518

It should not have happened. The change is actually in upstream and I misread the diffs.

(cherry picked from commit adb46ac4c0a64c2cd1fbf46022f4aafb4e605cd3)

2 years agoReapply r301691:
Warner Losh [Sun, 2 Jun 2019 20:47:15 +0000 (20:47 +0000)]
Reapply r301691:

Revert r301689 - one-true-awk: Avoid a NULL dereference.

I got this wrong and the coverity report doesn't match the NetBSD change,
which was thought for a different version.

The change wouldn't hurt but let's wait until upstream figures this out.

(cherry picked from commit 2675e1b91dcfa744a414a42f5522f4fed958476c)

2 years agoReapply r315426 by pfg:
Warner Losh [Sun, 2 Jun 2019 16:30:53 +0000 (16:30 +0000)]
Reapply r315426 by pfg:

|    MFV r315425: one-true-awk: have calloc(3) do the multiplication.

(cherry picked from commit 06d1e65393f95e0fd2d068fe118487f754e4248b)

2 years agoReapply r301289 by pfg:
Warner Losh [Sun, 2 Jun 2019 16:28:20 +0000 (16:28 +0000)]
Reapply r301289 by pfg:

|    MFV r300961: one-true-awk: replace 0 with NULL for pointers
|    Also remove a redundant semicolon.
|    Also had to rebase on upstream pull.

(cherry picked from commit 10ce5b990fc0c874071c21e47d02194337732f27)

2 years agoMerge from upstream at 4189ef5d from https://github.com/onetrueawk/awk.git
Warner Losh [Sun, 2 Jun 2019 16:25:07 +0000 (16:25 +0000)]
Merge from upstream at 4189ef5d from https://github.com/onetrueawk/awk.git

Note: this backs out a number of changes we've made to awk because
they aren't upstream, but are on the vendor branch. Those will be
reapplied. svn makes it needlessly difficult to know which ones, but
at least r315426, r301289, and maybe r301691, though there may be
others too. None of these are critical, so bisecting through this
point is safe for all but awk regression tests :).

(cherry picked from commit b5253557294400621041b8ce1dfbf11e124c1575)

2 years agoUpdate awk(1) manual to state an exception to egrep(1)-like RE syntax
Devin Teske [Fri, 2 Nov 2018 23:03:40 +0000 (23:03 +0000)]
Update awk(1) manual to state an exception to egrep(1)-like RE syntax

Reviewed by: imp, jmg
MFC after: 3 days
Sponsored by: Smule, Inc.
Differential Revision: https://reviews.freebsd.org/D17739

(cherry picked from commit e0ff4751f0a9757f0bfc776b5da5421f6294daf8)

2 years agobhyve: Fix NVMe iovec construction for large IOs
Chuck Tuffli [Sun, 27 Jun 2021 22:14:52 +0000 (15:14 -0700)]
bhyve: Fix NVMe iovec construction for large IOs

The UEFI driver included with Rocky Linux 8.4 uncovered an existing bug
in the NVMe emulation's construction of iovec's.

By default, NVMe data transfer operations use a scatter-gather list in
which all entries point to a fixed size memory region. For example, if
the Memory Page Size is 4KiB, a 2MiB IO requires 512 entries. Lists
themselves are also fixed size (default is 512 entries).

Because the list size is fixed, the last entry is special. If the IO
requires more than 512 entries, the last entry in the list contains the
address of the next list of entries. But if the IO requires exactly 512
entries, the last entry points to data.

The NVMe emulation missed this logic and unconditionally treated the
last entry as a pointer to the next list. Fix is to check if the
remaining data is greater than the page size before using the last entry
as a pointer to the next list.

PR: 256422
Reported by: dave@syix.com
Tested by: jason@tubnor.net
Relnotes: yes

(cherry picked from commit 91064841d72b285a146a3f1c32cb447251e062ea)

2 years agolibpfctl: memory leak fix
Kristof Provost [Wed, 30 Jun 2021 11:02:35 +0000 (13:02 +0200)]
libpfctl: memory leak fix

We must remember to free the nvlist we create from the kernel's response
to DIOCGETSTATESNV, on every iteration.

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

(cherry picked from commit 0e9f1892ec739d7fbd854af699507167a0a5dde2)

2 years agopf: getstates: avoid taking the hashrow lock if the row is empty
Kristof Provost [Tue, 29 Jun 2021 09:34:49 +0000 (11:34 +0200)]
pf: getstates: avoid taking the hashrow lock if the row is empty

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

(cherry picked from commit a19ff8ce9b58548a5f965db2c46eb03c38b15edb)

2 years agopf: Reduce the data returned in DIOCGETSTATESNV
Kristof Provost [Tue, 29 Jun 2021 08:26:40 +0000 (10:26 +0200)]
pf: Reduce the data returned in DIOCGETSTATESNV

This call is particularly slow due to the large amount of data it
returns. Remove all fields pfctl does not use. There is no functional
impact to pfctl, but it somewhat speeds up the call.

It might affect other (i.e. non-FreeBSD) code that uses the new
interface, but this call is very new, so there's unlikely to be any. No
releases contained the previous version, so we choose to live with the
ABI modification.

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

(cherry picked from commit 34285eefddc99c994c3e5374ba7836cc7cfc8e2e)

2 years agopf tests: Stress state retrieval
Kristof Provost [Mon, 28 Jun 2021 10:48:20 +0000 (12:48 +0200)]
pf tests: Stress state retrieval

Create and retrieve 20.000 states. There have been issues with nvlists
causing very slow state retrieval. We don't impose a specific limit on
the time required to retrieve the states, but do log it. In excessive
cases the Kyua timeout will fail this test.

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

(cherry picked from commit d8d43b2de1fa679179f7089cb3c31e6780ec82af)

2 years agopf tests: ftp-proxy test
Kristof Provost [Thu, 1 Jul 2021 15:15:36 +0000 (17:15 +0200)]
pf tests: ftp-proxy test

Basic test case for ftp-proxy

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

(cherry picked from commit dd82fd3543022017b84007ac1a0d45fc683f9850)

2 years agoftp-proxy: Revert incorrect migration to libpfctl
Kristof Provost [Thu, 1 Jul 2021 15:16:10 +0000 (17:16 +0200)]
ftp-proxy: Revert incorrect migration to libpfctl

libpfctl supports creating rules, but not (yet) adding addresses to a
pool. Adding addresses certainly does not work through adding a rule.

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

(cherry picked from commit 8923ea6c867fd75b08b76883ec122c429a4018f9)

2 years agodummynet: fix sysctls
Kristof Provost [Thu, 1 Jul 2021 07:42:34 +0000 (09:42 +0200)]
dummynet: fix sysctls

The sysctl nodes which use V_dn_cfg must be marked as CTLFLAG_VNET so
that we use the correct per-vnet offset

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

(cherry picked from commit 8f76eebce424de064f65fec5cdd105446a2de3bd)

2 years agoMount and unmount devfs around calls to add packages.
Warner Losh [Fri, 21 Jun 2019 03:49:36 +0000 (03:49 +0000)]
Mount and unmount devfs around calls to add packages.

pkg now uses /dev/null for some of its operations. NanoBSD's packaging
stuff didn't mount that for the chroot it ran in, so any config that
added packages would see the error:
pkg: Cannot open /dev/null:No such file or directory
when trying to actually add those packages. It's easy enough for
nanobsd to mount /dev and it won't hurt anything that was already
working and may help things that weren't (like this). I moved the
mount/unmount pair to be in the right push/pop order from the
submitted patch.

PR: 238727
Submitted by: mike tancsa
Tested by: Karl Denninger

(cherry picked from commit 804b78634d543667a37ac459e692fe42c9dd30e8)

2 years agomergemaster: handle symbolic links during update.
Warner Losh [Wed, 18 Nov 2020 19:22:24 +0000 (19:22 +0000)]
mergemaster: handle symbolic links during update.

/etc/os-release is now a symbolic link to a generated file. Make
mergemaster cope with symbolic links generically. I'm no longer
a big mergemaster user, so this has only been lightly tested
by me, though Kimura-san has ran it through its paces.

Submitted by: Yasushiro KIMURA-san
PR: 242212
MFC After: 2 weeks

(cherry picked from commit 30a56f9ef72705f2f3646ce4330cbc20675a465e)

2 years agoarm: Make sure we can handle a thumb entry point.
Olivier Houchard [Wed, 30 Jun 2021 20:56:50 +0000 (22:56 +0200)]
arm: Make sure we can handle a thumb entry point.

Similarly to what's been done on arm64 with commit
712c060c94fd447c91b0e6218c12a431206b487a, when executing a binary, if the
entry point is a thumb symbol, then make sure we set the PSL_T flag, otherwise
the CPU will interpret it in ARM mode, and that will likely leads to an
undefined instruction.

PR: 256899
MFC after:  1 week

(cherry picked from commit 8c3bd133dd52824e427e350c65eae1fd9eb5a3cd)
Signed-off-by: Olivier Houchard <cognet@FreeBSD.org>
2 years agoAdd deprecation notice for WITH_PROFILE option
Ed Maste [Sun, 27 Jun 2021 17:21:26 +0000 (13:21 -0400)]
Add deprecation notice for WITH_PROFILE option

As discussed on freebsd-current [1] and freebsd-arch [2] and review
D30833, FreeBSD 14 will ship without the _p.a libraries built with -pg.
Both upstream and base system (in commit b762974cf4b9) Clang have been
modified to remove the special case for linking against these libraries.

Clang's -pg support and mcount() remain, so building with -pg can still
be used on code that the user builds; we just do not provide prebuilt
libraries compiled with -pg.  A similar change is still needed for GCC.

[1]  https://lists.freebsd.org/pipermail/freebsd-current/2020-January/075105.html
[2] https://lists.freebsd.org/archives/freebsd-arch/2021-June/000016.html

MFC after: 1 week
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 175841285e289edebb6603da39f02549521ce950)

Clarify notice for profiled libraries in FreeBSD 14

Reported by: kevans
Fixes: 175841285e28 ("Add deprecation notice for...")
Sponsored by: The FreeBSD Foundation

(cherry picked from commit f94360971e649fa684ef3b7e72839b59c7242bdb)

2 years agolibnv: optimize nvlist size calculation
Mariusz Zaborski [Fri, 11 Jun 2021 15:35:36 +0000 (17:35 +0200)]
libnv: optimize nvlist size calculation

If we had a multiple nvlist, during nvlist_pack, we calculated the size
of every nvlist separately. For example, if we had a nvlist with three
nodes each containing another (A contains B, and B contains C), we first
calculated the size of nvlist A (which contains B, C), then we calculate
the size of B (which contains C, notice that we already did the
calculation of B, when we calculate A), and finally C. This means that
this calculation was O(N!). This was done because each time we pack
nvlist, we have to put its size in the header
(the separate header for A, B, and C).

To not break the ABI and to reduce the complexity of nvlist_size,
instead of calculating the nvlist size when requested,
we track the size of each nvlist.

Reported by: pjd, kp
Tested by: kp

(cherry picked from commit 89d5cbb82294c8624e66f920d50353057ccab14b)

2 years agolibnv: fix revert
Mariusz Zaborski [Sun, 17 Feb 2019 18:32:19 +0000 (18:32 +0000)]
libnv: fix revert

Reported by: jenkins

(cherry picked from commit 3bea7b5b05f200df4cabee12e405b8feade16f0e)

2 years agolibnv: fix double free
Mariusz Zaborski [Sun, 17 Feb 2019 18:26:27 +0000 (18:26 +0000)]
libnv: fix double free

In r343986 we introduced a double free. The structure was already
freed fixed in the r302966. This problem was introduced
because the GitHub version was out of sync with the FreeBSD one.

Submitted by: Mindaugas Rasiukevicius <rmind@netbsd.org>
MFC with: r343986

(cherry picked from commit d97753b5c8f1d32fbcdcbb0d129b49f808245865)

2 years agolibnv: fix memory leaks
Mariusz Zaborski [Sun, 10 Feb 2019 23:30:54 +0000 (23:30 +0000)]
libnv: fix memory leaks

Free the data array for NV_TYPE_DESCRIPTOR_ARRAY case.

MFC after: 2 weeks

(cherry picked from commit 0020c845a086766b3315372f006363f8ad76ac54)

2 years agolibnv: fix memory leaks
Mariusz Zaborski [Sun, 10 Feb 2019 23:28:55 +0000 (23:28 +0000)]
libnv: fix memory leaks

nvpair_create_stringv: free the temporary string; this fix affects
nvlist_add_stringf() and nvlist_add_stringv().

nvpair_remove_nvlist_array (NV_TYPE_NVLIST_ARRAY case): free the chain
of nvpairs (as resetting it prevents nvlist_destroy() from freeing it).
Note: freeing the chain in nvlist_destroy() is not sufficient, because
it would still leak through nvlist_take_nvlist_array().  This affects
all nvlist_*_nvlist_array() use

Submitted by: Mindaugas Rasiukevicius <rmind@netbsd.org>
Reported by: clang/gcc ASAN
MFC after: 2 weeks

(cherry picked from commit b5d787d93b3d83f28e87e1f8cc740cb160f8f0ac)

2 years agosbin/md5: add md5sum to synopsis in the man-page
Stefan Eßer [Sat, 19 Jun 2021 11:27:16 +0000 (13:27 +0200)]
sbin/md5: add md5sum to synopsis in the man-page

When invoked with "sum" following the hash name, the -c option takes a
file argument, not a string argument.

(cherry picked from commit 84f35b6f86efd004a8f25ef6eecea0f5d02733c4)

sbin/md5: improve compatibility with coreutils -c option

The -c option expects a digest file in either BSD or coreutils format.

The output for matched and mismatched files is identical to that
of the coreutils version.

The review of these changes included test cases that have already
been committed for the functionality that existed before.
Another test script is added to cover the coreutils compatible
extension implemented by this patch.

This commit contains a tests/Makefile that has been cleaned up
compared to the review version, using an implicit rule to apply the
TESTBASE path at build time (and the scripts have been renamed to
have an extension of .SH instead of .sh to trigger this rule).

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

(cherry picked from commit b33d1898c1b0e6d76b52eb48078260588802dc95)

md5: Improve compatibility with coreutils and format fix

The previous changes that added support for the coreutils -c option
modified the output generated by passing -r to match that of the
coreutils versions. The difference is that coreutils separates the
hash from the file name by two blanks "  " (or a blank followed by
an asterisk " *" with the -b option denoting).

While most scripts or users will not notice the difference, it might
be considered a violation of POLA and this commit reverts the change
for the non-sum programs. These will print a single blank " " as the
separator, as they die before the previous commit.

In order to still generate output that is identical to that of the
coreutils programs, this commit generates the "  " or " *" separator
used by them for the -sum versions, depending on the presence of the
-b option.

(cherry picked from commit b33d1898c1b0e6d76b52eb48078260588802dc95)

md5: Fix cross-build after c2870e576bd2

On macOS and Linux the current set of headers do not end up pulling in
sys/param.h, causing MAXPATHLEN to not be defined and the build to fail.

(cherry picked from commit cab31e0e216c7defefd4aba14693ba2252ea7308)

2 years agomd5: portability fix -- include stdbool.h explicitly
Warner Losh [Thu, 20 May 2021 17:26:46 +0000 (11:26 -0600)]
md5: portability fix -- include stdbool.h explicitly

stdbool.h needs to be included to use type bool variables. Due to
namespace pollution, this gets brought in on FreeBSD, but not on
other systems. Include it explicilty.

Noticed by: arichards@
Sponsored by: Netflix

2 years agomd5: Create md5sum, etc compatible programs
Warner Losh [Wed, 19 May 2021 17:26:20 +0000 (11:26 -0600)]
md5: Create md5sum, etc compatible programs

On Linux, there's a similar set of programs to ours, but that end in the
letters 'sum'. These act basically like FreeBSD versions run with the -r
option. Add code so that when the program ends in 'sum' you get the
linux -r behavior. This is enough to make most things that use sha*sum
work correctly (the -c / --check options, as well as the long args are
not implemented). When running with the -sum programs, ignore -t instead
of running internal speed tests and make -c an error.

Reviewed by: sef, and kp and allanjude (earlier version)
Relnotes: yes
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D30309

2 years agosbin/md5: Create /usr/tests/sbin/md5 directory for placing tests
Li-Wen Hsu [Fri, 25 Jun 2021 10:29:46 +0000 (18:29 +0800)]
sbin/md5: Create /usr/tests/sbin/md5 directory for placing tests

Author: Li-Wen Hsu <lwhsu@FreeBSD.org>
Sponsored by: The FreeBSD Foundation

(cherry picked from commit cb194afef50dc4e1473413a69462aaf03cfe0ce4)

sbin/md5: add tests

While the correctness of the supported hash algorithms can be tested
with the built-in self-test feature, these test cases are meant to
detect changes in the output format.

A follow-up commit will improve the compatibility with the coreutils
versions of the hash programs, and these tests should detect any
unintended side-effects of such a change on existing functionality.

(cherry picked from commit 884fc5527a3ffd9830b941cbec328de1623044cc)

sbin/md5: fix test case to not write outside temp directory

The bsd-p-test did create files 1.out .. 8.out in the test directory.
This has been fixed and the temporary output files are now written
to the temporary directory.

(cherry picked from commit 95d3044bbdadfca6120a3e7c61c9ebb9a476f369)

2 years agolibalias: Switch to SPLAY trees
Lutz Donnerhacke [Thu, 27 May 2021 21:42:54 +0000 (23:42 +0200)]
libalias: Switch to SPLAY trees

Current data structure is using a hash of unordered lists.  Those
unordered lists are quite efficient, because the least recently
inserted entries are most likely to be used again.  In order to avoid
long search times in other cases, the lists are hashed into many
buckets.  Unfortunatly a search for a miss needs an exhaustive
inspection and a careful definition of the hash.

Splay trees offer a similar feature - almost O(1) for access of the
least recently used entries), and amortized O(ln(n) - for almost all
other cases.  Get rid of the hash.

Now the data structure should able to quickly react to external
packets without eating CPU cycles for breakfast, preventing a DoS.

PR: 192888
Discussed with: Dimitry Luhtionov
Differential Revision: https://reviews.freebsd.org/D30516
Differential Revision: https://reviews.freebsd.org/D30536
Differential Revision: https://reviews.freebsd.org/D30844

(cherry picked from commit 935fc93af157dee352eb4b6c83f8a2a9e7fd9a4e)
(cherry picked from commit d261e57deacb0d00d9e827447f235df83dda3e3a)
(cherry picked from commit f70c98a2f5d993dc518efd606aa341eda99400ef)
(cherry picked from commit 25392fac9488bcae5c451500df2e2945430484a6)
(cherry picked from commit 2f4d91f9cb22fc65eb65407e8118b433a5d71976)
(cherry picked from commit 4060e77f49d1b9fd2254f3f4da94fd64fce83f72)

2 years agolibalias: Restructure
Lutz Donnerhacke [Tue, 25 May 2021 13:03:34 +0000 (15:03 +0200)]
libalias: Restructure

Clean up the database handling in order to switch to more efficient
data structures.  The development of this patch was artificially split
in to many small steps to ease reviewing.

- Common search terms
- Separate fully qualified search
- Separate table for partial links
- Cleanup _FindLinkIn
- Factor out the outgoing search function
- Factor out a common idiom to return found links
- Reorder incoming links by grouping of common search terms
- Remove LSNAT from outgoing search
- Group internal structure semantically
- Separate table for PPTP
- Use AliasRange instead of PORT_BASE
- Remove temporary state deleteAllLinks from global struct
- Avoid uninitialized expiration

Discussed with: Dimitry Luhtionov
Differential Revision: https://reviews.freebsd.org/D30568
Differential Revision: https://reviews.freebsd.org/D30569
Differential Revision: https://reviews.freebsd.org/D30570
Differential Revision: https://reviews.freebsd.org/D30571
Differential Revision: https://reviews.freebsd.org/D30572
Differential Revision: https://reviews.freebsd.org/D30573
Differential Revision: https://reviews.freebsd.org/D30574
Differential Revision: https://reviews.freebsd.org/D30575
Differential Revision: https://reviews.freebsd.org/D30580
Differential Revision: https://reviews.freebsd.org/D30581
Differential Revision: https://reviews.freebsd.org/D30604
Differential Revision: https://reviews.freebsd.org/D30582

(cherry picked from commit d41044ddfdbc2a026570cae11d5fc2e18f5e4b92)
(cherry picked from commit 32f9c2ceb3ec8266e48ec0f6d1556fd98ef12db6)
(cherry picked from commit cac129e6030095c33e95c5ce1cdcb9c5c21efce9)
(cherry picked from commit 19dcc4f2250b3850991366e3058ca8a64b2f135d)
(cherry picked from commit d5419034381d0e8e8c99f0f678118b197144bfff)
(cherry picked from commit d4ab07d2aeb13b1aae9ad5d73e5fe77131f2350c)
(cherry picked from commit 492d3b7109b45ff30fd199b7eeed797447746e42)
(cherry picked from commit 7b44ff4c52ce9e7a89e772566a249e5481fe0ac4)
(cherry picked from commit 1178dda53d10b096e0b99e356d15b7c24390e099)
(cherry picked from commit 9efcad61d8309ecad3c15392b277fd329a1e45e4)
(cherry picked from commit fe83900f9fa931e3d0942ec9c0709896b887c3d7)
(cherry picked from commit d989935b5bcd880353f0de89eda958c45e7e3342)
(cherry picked from commit b50a4dce185481bebf8096c27588ae04a4a2fd7c)
(cherry picked from commit f28455344483310cfd1aa5c0bdd4d014810c0e32)

2 years agolibalias: Promote per instance global variable timeStamp
Lutz Donnerhacke [Tue, 25 May 2021 07:07:21 +0000 (09:07 +0200)]
libalias: Promote per instance global variable timeStamp

Summary:
- Use LibAliasTime as a real global variable for central timekeeping.
- Reduce number of syscalls in user space considerably.
- Dynamically adjust the packet counters to match the second resolution.
- Only check the first few packets after a time increase for expiry.

Discussed with: hselasky
Differential Revision: https://reviews.freebsd.org/D30566

(cherry picked from commit ef828d39be8e4b6d922db080ed41611702dec56d)

2 years agolibalias: Stats are unsigned
Lutz Donnerhacke [Mon, 31 May 2021 22:08:24 +0000 (00:08 +0200)]
libalias: Stats are unsigned

Stats counters are used as unsigned valued (i.e. printf("%u")) but are
defined as signed int.  This causes trouble later, so fix it early.

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

(cherry picked from commit 3fd20a79e7b55d135bbc5fa197980fe0e9ee0f14)

2 years agolibalias: tidy up housekeeping
Lutz Donnerhacke [Sat, 15 May 2021 15:35:36 +0000 (17:35 +0200)]
libalias: tidy up housekeeping

Replace current expensive, but sparsly called housekeeping
by a single, repetive action.

This is part of a larger restructure of libalias in order to switch to
more efficient data structures.  The whole restructure process is
split into 15 reviews to ease reviewing.  All those steps will be
squashed into a single commit for MFC in order to hide the
intermediate states from production systems.

Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D30277

(cherry picked from commit 294799c6b081faece556a5010a4f51552e131c2f)

2 years agorefcount: add refcount_releasen
Mateusz Guzik [Mon, 5 Jul 2021 12:45:32 +0000 (12:45 +0000)]
refcount: add refcount_releasen

This is a direct commit as the routine in main was added as a side
effect of functionality which later got reverted.

2 years agopf: make DIOCGETSTATESNV iterations killable
Mateusz Guzik [Fri, 2 Jul 2021 07:28:48 +0000 (09:28 +0200)]
pf: make DIOCGETSTATESNV iterations killable

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

(cherry picked from commit 48d5b86364fa8e86318805d0078ccf9066e94ae8)

2 years agopfctl: cache getprotobynumber results
Mateusz Guzik [Thu, 1 Jul 2021 19:25:43 +0000 (21:25 +0200)]
pfctl: cache getprotobynumber results

As for example pfctl -ss keeps calling it, it saves a lot of overhead
from elided parsing of /etc/nsswitch.conf and /etc/protocols.

Sample result when running a pre-nvlist binary with nfs root and dumping
7 mln states:
before: 24.817u 62.993s 1:28.52 99.1%
after: 8.064u 1.117s 0:18.87 48.5%

Idea by Jim Thompson

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

(cherry picked from commit 858937bea4599d254a97ee6321683f8629604e15)

2 years agopf: revert: Use counter(9) for pf_state byte/packet tracking
Mateusz Guzik [Mon, 28 Jun 2021 18:50:56 +0000 (20:50 +0200)]
pf: revert: Use counter(9) for pf_state byte/packet tracking

stats are not shared and consequently per-CPU counters only waste
memory.

No slowdown was measured when passing over 20M pps.

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

(cherry picked from commit 55cc305dfcad0ad7c4f528fa47f7473927e8223a)

2 years agopf: make sure the dtrace probe has safe access to state
Mateusz Guzik [Mon, 28 Jun 2021 19:32:20 +0000 (21:32 +0200)]
pf: make sure the dtrace probe has safe access to state

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

(cherry picked from commit d26ef5c7ac830812f07a02787f25fed5d6f8609e)

2 years agopf: deduplicate V_pf_state_z handling with pfsync
Mateusz Guzik [Mon, 28 Jun 2021 18:18:26 +0000 (20:18 +0200)]
pf: deduplicate V_pf_state_z handling with pfsync

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

(cherry picked from commit 803dfe3da0e30520227a791ba5c2b93da16e1cf5)

2 years agopf: fix error-case leaks in pf_create_state
Mateusz Guzik [Mon, 28 Jun 2021 18:29:58 +0000 (20:29 +0200)]
pf: fix error-case leaks in pf_create_state

The hand-rolled clean up failed to free counters.

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

(cherry picked from commit 7f025db57c7879bfa43ac74ecd95903439fdd1d0)

2 years agopf: assert that sizeof(struct pf_state) <= 312
Mateusz Guzik [Mon, 28 Jun 2021 12:49:40 +0000 (14:49 +0200)]
pf: assert that sizeof(struct pf_state) <= 312

To prevent accidentally going over a threshold which makes UMA fit only
12 objects per page instead of 13.

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

(cherry picked from commit e6dd0e2e8d4f59275fb576a9ccb9d356d36457bb)

2 years agopf: factor out state allocation into pf_alloc_state
Mateusz Guzik [Mon, 28 Jun 2021 12:22:31 +0000 (14:22 +0200)]
pf: factor out state allocation into pf_alloc_state

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

(cherry picked from commit ccb17a21041e9206b80fa9f64b6ec20233df6403)

2 years agopf: add pf_release_staten and use it in pf_unlink_state
Mateusz Guzik [Mon, 28 Jun 2021 12:18:43 +0000 (14:18 +0200)]
pf: add pf_release_staten and use it in pf_unlink_state

Saves one atomic op.

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

(cherry picked from commit d09388d013300fc4aa1ee1a6bc24260cd400aff3)

2 years agopf: Add endline to all DPFPRINTF()
Kristof Provost [Sun, 24 Nov 2019 13:53:36 +0000 (13:53 +0000)]
pf: Add endline to all DPFPRINTF()

DPFPRINTF() doesn't automatically add an endline, so be consistent and
always add it.

(cherry picked from commit 492f3a312a2617899809285cdb6a32baf6836b13)

2 years agotests/libalias: Bugfix in used variables
Lutz Donnerhacke [Fri, 2 Jul 2021 21:58:16 +0000 (23:58 +0200)]
tests/libalias: Bugfix in used variables

Fix two copy and waste errors (referencing the wrong variable).

(cherry picked from commit b3dc6f137b8d626c4415a5fa9c9874ac4ca78658)

2 years agofusefs: delete dead code
Alan Somers [Tue, 15 Jun 2021 19:34:01 +0000 (13:34 -0600)]
fusefs: delete dead code

Delete two fields in the per-mountpoint struct that have never been
used.

Sponsored by: Axcient

(cherry picked from commit d63e6bc256016c7f5223ff5541671e5a96c4c6c4)

2 years agoid: sanitize arguments better
Alan Somers [Fri, 11 Jun 2021 16:38:07 +0000 (10:38 -0600)]
id: sanitize arguments better

The -[AMc] flags ignore the user argument.  Better if id rejects
invocations that include a user argument along with any of those flags.

PR: 256554
Reviewed by: trasz
Sponsored by: Axcient
Differential Revision: https://reviews.freebsd.org/D30734

(cherry picked from commit 4a06e9377398b34922f8a67d7cb3ea980b95bde8)

2 years agobhyvectl: print a better error message when vm_open() fails
Marko [Sun, 7 Mar 2021 06:19:30 +0000 (21:19 -0900)]
bhyvectl: print a better error message when vm_open() fails

libvmm: explicitly save and restore errno in vm_open()

Use errno to print a more descriptive error message when vm_open() fails

PR:             250671
Reviewed by: grehan
Differential Revision: https://reviews.freebsd.org/D29109

(cherry picked from commit 6bb140e3ca895a148f32c93d50f93619bf735f73)
(cherry picked from commit a7f81b488df2d4a5dcd785b4112e04ffb6ca0442)

2 years agolinux(4): Prevent integer overflow in futex_requeue.
Dmitry Chagin [Thu, 10 Jun 2021 11:23:11 +0000 (14:23 +0300)]
linux(4): Prevent integer overflow in futex_requeue.

To prevent a signed integer overflow in futex_requeue add a sanity check
to catch negative values of nrwake or nrrequeue.

(cherry picked from commit 25b09d6f398ea8a260ee8e2e8209fd76c61e13ee)

2 years agoFix a use-after-free in an error case.
Takanori Watanabe [Wed, 26 May 2021 09:23:33 +0000 (18:23 +0900)]
Fix a use-after-free in an error case.

PR: 255872
Submitted by:  lylgood
Differential Revision:  https://reviews.freebsd.org/D30454

(cherry picked from commit 14803ec8d193d8d46f4137a7dba61b277c6a2fed)

2 years agoUPDATING: Add an entry for commit 6ae32cc8182f
Rick Macklem [Sat, 26 Jun 2021 23:53:13 +0000 (16:53 -0700)]
UPDATING: Add an entry for commit 6ae32cc8182f

This is a direct commit.

2 years agoparam.h: Bump __FreeBSD_version for commit 6ae32cc8182f
Rick Macklem [Sat, 26 Jun 2021 23:47:59 +0000 (16:47 -0700)]
param.h: Bump __FreeBSD_version for commit 6ae32cc8182f

Commit 6ae32cc8182f changed the internal KAPI between the krpc and
nfsd modules.  As such, both need to be rebuilt from sources.
Bump __FreeBSD_version to 1202508.

This is a direct commit.

2 years agokrpc: Acquire ref count of CLIENT for backchannel use
Rick Macklem [Fri, 11 Jun 2021 23:57:14 +0000 (16:57 -0700)]
krpc: Acquire ref count of CLIENT for backchannel use

Michael Dexter <editor@callfortesting.org> reported
a crash in FreeNAS, where the first argument to
clnt_bck_svccall() was no longer valid.
This argument is a pointer to the callback CLIENT
structure, which is free'd when the associated
NFSv4 ClientID is free'd.

This appears to have occurred because a callback
reply was still in the socket receive queue when
the CLIENT structure was free'd.

This patch acquires a reference count on the CLIENT
that is not CLNT_RELEASE()'d until the socket structure
is destroyed. This should guarantee that the CLIENT
structure is still valid when clnt_bck_svccall() is called.
It also adds a check for closed or closing to
clnt_bck_svccall() so that it will not process the callback
RPC reply message after the ClientID is free'd.

(cherry picked from commit e1a907a25cfa422c0d1acaf9f91352ada04f4bca)

2 years agonfscl: Fix generation of va_fsid for a tree of NFSv4 server file systems
Rick Macklem [Mon, 7 Jun 2021 20:48:25 +0000 (13:48 -0700)]
nfscl: Fix generation of va_fsid for a tree of NFSv4 server file systems

Pre-r318997 the code looked like:
if (vp->v_mount->mnt_stat.f_fsid.val[0] != (uint32_t)np->n_vattr.na_filesid[0])
         vap->va_fsid = (uint32_t)np->n_vattr.na_filesid[0];
Doing this assignment got lost by r318997 and, as such, NFSv4 mounts
of servers with trees of file systems on the server is broken, due to duplicate
fileno values for the same st_dev/va_fsid.

Although I could have re-introduced the assignment, since the value of
na_filesid[0] is not guaranteed to be unique across the server file systems,
I felt it was better to always do the hash for na_filesid[0,1].
Since dev_t (st_dev/va_fsid) is now 64bits, I switched to a 64bit hash.

There is a slight chance of a hash conflict where 2 different na_filesid
values map to same va_fsid, which will be documented in the BUGS
section of the man page for mount_nfs(8).  Using a table to keep track
of mappings to catch conflicts would not easily scale to 10,000+ server file
systems and, when the conflict occurs, it only results in fts(3) reporting
a "directory cycle" under certain circumstances.

(cherry picked from commit 03c81af24920e14bd977f34edcd3eb7fb122db19)

2 years agoamd64: typo fix: memcmpy -> memcmp in a comment
Mateusz Guzik [Sat, 26 Jun 2021 03:57:47 +0000 (05:57 +0200)]
amd64: typo fix: memcmpy -> memcmp in a comment

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

(cherry picked from commit 9a8e4527f07dbb356bb1942efc09888f957df056)

2 years agoamd64: stop re-reading curpc in suword
Mateusz Guzik [Sun, 12 May 2019 06:34:58 +0000 (06:34 +0000)]
amd64: stop re-reading curpc in suword

Plugs re-reads missed in r341719

Sponsored by: The FreeBSD Foundation

(cherry picked from commit 8eae2be460aebfcba63cf5cdc11fa6fd0962470e)

2 years agoamd64: fixup MEMMOVE comment (10 -> r10)
Mateusz Guzik [Sun, 12 May 2019 06:42:17 +0000 (06:42 +0000)]
amd64: fixup MEMMOVE comment (10 -> r10)

Sponsored by: The FreeBSD Foundation

(cherry picked from commit 45372f1a6f7a43d235b083e51c9265574201ad26)

2 years agoamd64: move memcmp checks upfront
Mateusz Guzik [Sun, 31 Jan 2021 15:46:18 +0000 (16:46 +0100)]
amd64: move memcmp checks upfront

This is a tradeoff which saves jumps for smaller sizes while making
the 8-16 range slower (roughly in line with the other cases).

Tested with glibc test suite.

For example size 3 (most common with vfs namecache) (ops/s):
before: 407086026
after: 461391995

The regressed range of 8-16 (with 8 as example):
before: 540850489
after: 461671032

(cherry picked from commit f1be262ec11c1c35e6485f432415b5b52adb505d)

2 years agoamd64: tidy up pagezero*/pagecopy (movq -> movl)
Mateusz Guzik [Sun, 12 May 2019 07:11:44 +0000 (07:11 +0000)]
amd64: tidy up pagezero*/pagecopy (movq -> movl)

Sponsored by: The FreeBSD Foundation

(cherry picked from commit b72515e129f6320eb43e0ee853fcbb099b300e57)

2 years agoamd64: add missing ALIGN_TEXT to loops in memset and memmove
Mateusz Guzik [Fri, 29 Jan 2021 15:09:14 +0000 (16:09 +0100)]
amd64: add missing ALIGN_TEXT to loops in memset and memmove

(cherry picked from commit 164c3b81848bc81dc200b12370999474225447a3)

2 years agolinker_set: fix globl/weak symbol redefinitions to work on clang 12
Greg V [Tue, 20 Apr 2021 00:47:15 +0000 (01:47 +0100)]
linker_set: fix globl/weak symbol redefinitions to work on clang 12

In clang 12.0.0.rc2, going from weak to global is now a hard error:

```
/usr/src/stand/libsa/amd64/_setjmp.S:67:25: error: _longjmp changed binding to STB_GLOBAL
.text; .p2align 4,0x90; .globl _longjmp; .type _longjmp,@function; _longjmp:; .cfi_startproc
```

And the other way is a warning, but we have -Werror:

```
error: __start_set_Xcommand_set changed binding to STB_WEAK [-Werror,-Winline-asm]
error: __stop_set_Xcommand_set changed binding to STB_WEAK [-Werror,-Winline-asm]
```

ref: https://reviews.llvm.org/D90108

Reviewed By: arichardson
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D29159

(cherry picked from commit 32231805fbe2b9438c2de50c229b43c016207a08)

2 years agosys/dev/md: Drop unncessary __GLOBL(mfs_root)
Alex Richardson [Tue, 30 Mar 2021 13:53:41 +0000 (14:53 +0100)]
sys/dev/md: Drop unncessary __GLOBL(mfs_root)

LLVM12 complains if you change the symbol binding:
error: mfs_root_end changed binding to STB_WEAK [-Werror,-Winline-asm]
error: mfs_root changed binding to STB_WEAK [-Werror,-Winline-asm]

(cherry picked from commit 69e18c9b7b12e7fd97a740d8748d8718021a1e34)

2 years agopf: store L4 headers in pf_pdesc
Kristof Provost [Fri, 4 Jun 2021 08:52:07 +0000 (10:52 +0200)]
pf: store L4 headers in pf_pdesc

Rather than pointers to the headers store full copies. This brings us
slightly closer to what OpenBSD does, and also makes more sense than
storing pointers to stack variable copies of the headers.

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

(cherry picked from commit d38630f6192a40934912fbffc52c9650776c2b53)

2 years agopf: Mark struct pf_pdesc as kernel only
Kristof Provost [Wed, 3 Mar 2021 09:28:14 +0000 (10:28 +0100)]
pf: Mark struct pf_pdesc as kernel only

This structure is only used by the kernel module internally. It's not
shared with user space, so hide it behind #ifdef _KERNEL.

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

(cherry picked from commit 29698ed904737ebfd139a21e39e5421cf81badd8)

2 years agoWork around bogus old gcc "initializer element is not constant" error
Dimitry Andric [Fri, 25 Jun 2021 18:42:38 +0000 (20:42 +0200)]
Work around bogus old gcc "initializer element is not constant" error

After df3b437c1e073eb83e9a93af1c417f3ee8d0de3b, older gcc's such as
4.2.1 (still used on earlier branches for e.g. mips and powerpc) and
6.3.0 (still used for some cross-builds) started throwing bogus errors
like:

In file included from /workspace/src/lib/msun/src/s_llround.c:11:0:
/workspace/src/lib/msun/src/s_lround.c:54:31: error: initializer element is not constant
 static const type dtype_min = type_min - 0.5;
                               ^~~~~~~~
/workspace/src/lib/msun/src/s_lround.c:55:31: error: initializer element is not constant
 static const type dtype_max = type_max + 0.5;
                               ^~~~~~~~

Since 'type_min' and 'type_max' are constants declared just above these
lines this error is nonsensical, but older gcc's are not smart enough.

Work around the error by reusing the (type)DTYPE_MIN and (type)DTYPE_MAX
macros, so I can MFC this right away, unbreaking a few stable builds.

(cherry picked from commit 0bcd49c13ada1461bcea85e0466811ddcb290b5e)

2 years agoFix failures in libm's lround_test after clang 12 import
Dimitry Andric [Tue, 22 Jun 2021 16:38:27 +0000 (18:38 +0200)]
Fix failures in libm's lround_test after clang 12 import

It turned out that the (type)DTYPE_MAX conversions at the top of
s_lround.c are now emitted as cvtsi2sd instructions, at least on SSE
capable CPUs. This caused the FE_INEXACT flag to always be set, at least
for the double and float variants. Under clang 11, the whole INRANGE()
comparisons were still optimized away, but this has "improved" in clang
12, due to stricter adherence to the -ffp-exception-behavior=maytrap
compiler flag.

To avoid run-time integer to float conversions, use static constants
instead, so they are computed at compile time, and the INRANGE()
statements are optimized away again, if applicable.

While here, use an integer instead of a floating type to store the test
results in lround_test.c, as this is more appropriate, and we can also
drop the volatile hack.

Reported by: arichardson

(cherry picked from commit df3b437c1e073eb83e9a93af1c417f3ee8d0de3b)

2 years agoDisable llvm generating 128-bit multiply libcalls on 32-bit ARM
Dimitry Andric [Tue, 22 Jun 2021 20:26:13 +0000 (22:26 +0200)]
Disable llvm generating 128-bit multiply libcalls on 32-bit ARM

Merge commit 789708617d20 from llvm git (Koutheir Attouchi):

  Do not generate calls to the 128-bit function __multi3() on 32-bit ARM

  Re-applying this patch after bots failures. Should be fine now.

  The function __multi3() is undefined on 32-bit ARM, so a call to it should
  never be emitted. Instead, plain instructions need to be generated to
  perform 128-bit multiplications.

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

Reported by: mmel

(cherry picked from commit 014a40f8f643a5dad6a6ba5c4bf6ea5d4f445fe6)

2 years agoFix clang assertion while building recent www/chromium
Dimitry Andric [Mon, 21 Jun 2021 18:46:34 +0000 (20:46 +0200)]
Fix clang assertion while building recent www/chromium

Merge commit c8227f06b335 from llvm git (by Arthur Eubanks):

  [clang] Don't assert in EmitAggregateCopy on trivial_abi types

  Fixes PR42961.

  Reviewed By: rnk

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

PR: 256721, 255570
Reported by: jbeich

(cherry picked from commit e7e517981a6591c79fb49cd8810361b0f3ad5983)

2 years agojail: Don't allow substitution of valueless jail parameters.
Jamie Gritton [Fri, 18 Jun 2021 16:44:37 +0000 (09:44 -0700)]
jail: Don't allow substitution of valueless jail parameters.
PR: 256544
Reported by: cryptogranny at gmail.com

(cherry picked from commit 5bf6dca2c6dbf63d382e97905e205ded3e8525d2)

2 years agotests/netgraph: Fix build error due to missing directory
Lutz Donnerhacke [Thu, 24 Jun 2021 11:54:54 +0000 (13:54 +0200)]
tests/netgraph: Fix build error due to missing directory

While MFCing the tests into stable/11 the test directory needs to be
added, because earlier netgraph tests were not MFCed to this train.

PR: 256773
Reported by: Arrigo Marchiori
Submitted by: Arrigo Marchiori
Tested by: Arrigo Marchiori

This is a direct commit into the stable/12 branch.

2 years agobsnmp: Fix incorrect use of libpfctl
Kristof Provost [Tue, 15 Jun 2021 08:50:32 +0000 (10:50 +0200)]
bsnmp: Fix incorrect use of libpfctl

When we introduced libpfctl in bnsmpd this was done incorrectly, and a
GETRULE call was replaced by pfctl_add_rule().
Change it to pfctl_get_rule().

Reviewed by: donner
MFC after: 3 days
Sponsored by: Rubicon Communications, LLC ("Netgate")

(cherry picked from commit 67cef6d411cef0c3dfcf768ff890b4f97cf513b6)

2 years agokern.mk: fix -Wno-error style to fix build with Clang 12
Greg V [Wed, 10 Mar 2021 22:17:09 +0000 (17:17 -0500)]
kern.mk: fix -Wno-error style to fix build with Clang 12

Clang 12 no longer supports -Wno-error-..., only the -Wno-error=...
style (which is already used everywhere else in the tree).

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

(cherry picked from commit 15565e0a2177f53b086609fecd48991c52dad5eb)

2 years agoRemove a use of a negative array index from fxp(4).
Mark Johnston [Wed, 19 Dec 2018 04:54:32 +0000 (04:54 +0000)]
Remove a use of a negative array index from fxp(4).

This fixes a warning seen when compiling amd64 GENERIC with clang 7.
Also remove the workaround added in r337324.  clang 7 and gcc 4.2
generate the same code with or without the code change.

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

(cherry picked from commit 0e4a3d93eefdc9730f572e8277b100eff6cf3491)

2 years agoExport various 128 bit long double functions from libgcc_s.so.1
Dimitry Andric [Mon, 14 Jun 2021 19:17:05 +0000 (21:17 +0200)]
Export various 128 bit long double functions from libgcc_s.so.1

These were already compiled for some time on aarch64 and riscv, by
including lib/libcompiler_rt/Makefile.inc, but never exported in the
shared library. Since gcc exports these under version GCC_4.6.0, we do
the same.

This review should replace D11482 for now. For e.g. amd64 more work is
still to be done, as compiler-rt does not seem to support 128 bit long
double math for that architecture.

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

(cherry picked from commit 790a6be5a1699291c6da87871426d0c56dedcc89)

2 years agocpucontrol: fix extended signature matching code to avoid fallthough
Dan Nelson [Mon, 14 Jun 2021 19:28:16 +0000 (15:28 -0400)]
cpucontrol: fix extended signature matching code to avoid fallthough

PR: 256502

(cherry picked from commit 87799c5f85dc0aed7e53ca841504e3b2ffc88498)

2 years agostand: Fix __elfN(loadimage) return value
Mark Johnston [Sun, 6 Jun 2021 20:40:25 +0000 (16:40 -0400)]
stand: Fix __elfN(loadimage) return value

Caller functions expect __elfN(loadimage) to return a value of zero on
failure and the file size on success.

PR: 256390
Reviewed by: markj

(cherry picked from commit 1ea87e2a70c31454a8696ab2979d13d21c5575d2)

2 years agobsdconfig: add a new mirror in Bulgaria
Philip Paeps [Thu, 17 Jun 2021 13:07:37 +0000 (21:07 +0800)]
bsdconfig: add a new mirror in Bulgaria

Provided by Telepoint Mirror Service.

Reported by: Valentin Nikolov <mirror@telepoint.bg>

(cherry picked from commit 1c9605fe1e190197b3846e01dce1e491bef0ec34)

2 years agobsdinstall: add a new mirror in Bulgaria
Philip Paeps [Thu, 17 Jun 2021 13:07:37 +0000 (21:07 +0800)]
bsdinstall: add a new mirror in Bulgaria

Provided by Telepoint Mirror Service.

Reported by: Valentin Nikolov <mirror@telepoint.bg>

(cherry picked from commit 7daa45becfd32cb38933bfdc87e8a10fc982d188)

2 years agoipfw.8: synopsis misses nat show form
Lutz Donnerhacke [Mon, 10 May 2021 16:30:42 +0000 (18:30 +0200)]
ipfw.8: synopsis misses nat show form

Document the existing behavior, which is currently only available by
reading third party documentation or the source code itself.

PR: 254617
Submitted by: Oliver Kiddle
Differential Revision: https://reviews.freebsd.org/D30189

(cherry picked from commit c8250c5ada85fec8936e8eb8695d7cb80a3ce8ab)

2 years agopf: don't hold a lock during copyout()
Kristof Provost [Mon, 14 Jun 2021 12:04:02 +0000 (14:04 +0200)]
pf: don't hold a lock during copyout()

copyout() can trigger page faults, so it may potentially sleep.

Reported by: avg
MFC after: 3 days
Sponsored by: Rubicon Communications, LLC ("Netgate")

(cherry picked from commit 8b5f4e692b1d1585ecfc6690552650114e3e704e)

2 years agodummynet: free(NULL, M_DUMMYNET); is safe
Kristof Provost [Fri, 21 May 2021 14:55:07 +0000 (16:55 +0200)]
dummynet: free(NULL, M_DUMMYNET); is safe

There's no need to check pointers for NULL before free()ing them.

No functional change.

MFC after: 2 weeks
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D30382

(cherry picked from commit 1b2dbe37fa32d7255faf7d1feec7bb31414a8102)

2 years agodummynet: Fix schedlist and aqmlist locking
Kristof Provost [Fri, 21 May 2021 12:26:49 +0000 (14:26 +0200)]
dummynet: Fix schedlist and aqmlist locking

These are global (i.e. shared across vnets) structures, so we need
global lock to protect them.  However, we look up entries in these lists
(find_aqm_type(), find_sched_type()) and return them. We must ensure
that the returned structures cannot go away while we are using them.

Resolve this by using NET_EPOCH(). The structures can be safely accessed
under it, and we postpone their cleanup until we're sure they're no
longer used.

MFC after: 2 weeks
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D30381

(cherry picked from commit 51d73df18e4d120f6f062062c18efae3ed5193a6)