]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
3 years agoImprove URL parsing. In particular, convert scheme and host to lowercase.
Dag-Erling Smørgrav [Tue, 27 Nov 2018 10:45:14 +0000 (10:45 +0000)]
Improve URL parsing.  In particular, convert scheme and host to lowercase.

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

(cherry picked from commit 8d9de5b10a24bd2d79ed99f139c0ac28c09b15ca)

3 years agoSupport proxying FTP over HTTPS, not just HTTP.
Dag-Erling Smørgrav [Tue, 27 Nov 2018 10:06:41 +0000 (10:06 +0000)]
Support proxying FTP over HTTPS, not just HTTP.

There is probably a PR for this, but I can't find this, or remember who
submitted it.  The patch got lost in the noise of another that wasn't
ready to commit.

MFC after: 3 days
Approved by: kp
Sponsored by: Rubicon Communications, LLC ("Netgate")

(cherry picked from commit b68815f0886031fcccb426b85484b18a282d1b8c)

3 years agopf tests: Test cases for the 'kill state(s)' feature
Kristof Provost [Fri, 16 Apr 2021 15:33:17 +0000 (17:33 +0200)]
pf tests: Test cases for the 'kill state(s)' feature

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

(cherry picked from commit 065b5c7fb26eb4239e9bd513dde5a55ef78e45c4)

3 years agopf: Refactor state killing
Kristof Provost [Fri, 16 Apr 2021 14:34:21 +0000 (16:34 +0200)]
pf: Refactor state killing

Extract the state killing code from pfioctl() and rephrase the filtering
conditions for readability.

No functional change intended.

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

(cherry picked from commit 586aab9e0aa6c811758c19fb03831fc1e7305252)

3 years agoipfw: do not use sleepable malloc in callout context.
Andrey V. Elsukov [Fri, 16 Apr 2021 07:22:44 +0000 (10:22 +0300)]
ipfw: do not use sleepable malloc in callout context.

Use M_NOWAIT flag when hash growing is called from callout.

PR:             255041
Reviewed by: kevans
Differential Revision: https://reviews.freebsd.org/D29772

(cherry picked from commit 9bacbf1ae243de43d642c3ac0b7318ae0e5c5235)

3 years agolibkiconv: address memory leak in not-found cases
Ed Maste [Wed, 21 Apr 2021 17:45:27 +0000 (13:45 -0400)]
libkiconv: address memory leak in not-found cases

Found in "Understanding and Detecting Disordered Error Handling with
Precise Function Pairing" by Qiushi Wu et al.

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

(cherry picked from commit 3cfd08c1c74058451a02bac35307bf7fa509c617)

3 years agoaesni: Avoid modifying session keys in hmac_update()
Mark Johnston [Tue, 27 Apr 2021 00:04:25 +0000 (20:04 -0400)]
aesni: Avoid modifying session keys in hmac_update()

Otherwise aesni_process() is not thread-safe for AES+SHA-HMAC
transforms, since hmac_update() updates the caller-supplied key directly
to create the derived key.  Use a buffer on the stack to store a copy of
the key used for computing inner and outer digests.

This is a direct commit to stable/12 as the bug is not present in later
branches.

Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D30001

3 years agowlanstats: fix build
Sofian Brabez [Tue, 20 Apr 2021 18:31:48 +0000 (18:31 +0000)]
wlanstats: fix build

Add -Wno-cast-align to the CFLAGS to fix the build of wlanstats

Approved by: adrian
MFC after: 1 week

(cherry picked from commit b8be8094958a01255f5430bd6a36ff936bdd53c3)

3 years agoiwnstats: fix build with clang and allow install under /usr/local/sbin
Sofian Brabez [Tue, 20 Apr 2021 17:58:46 +0000 (17:58 +0000)]
iwnstats: fix build with clang and allow install under /usr/local/sbin

iwnstats was not compiling because of some issues raised by the clang
compiler due to -Werror. As a tool it is not connected to world build.

Add missing field "barker_mrc" initialization in struct
iwn_sensitivity_limits for -Wmissing-field-initializers, remove unused
pointer *is on iwn_stats_*_print functions and unused variables for
-Wunused-parameter and -Wunused-variable.

The value for field "barker_mrc" of struct iwn2030_sensitivity_limits
was obtained from linux 3.2 wireless/iwlwifi driver code (iwl-2000.c:115
.barker_corr_th_min_mrc = 390).

Also set BINDIR in Makefile to make it possible to install under
/usr/local/sbin/iwnstats as it require super user.

Reviewed by: adrian
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D29800

(cherry picked from commit 561d34d70596b455c6a513431f8ad007076f90c5)

3 years agoFix race in case of device destruction.
Alexander Motin [Tue, 13 Apr 2021 15:19:10 +0000 (11:19 -0400)]
Fix race in case of device destruction.

During device destruction it is possible that open() succeed, but
fdevname() return NULL, that can't be assigned to string variable.
Fix that by adding explicit NULL check.

Also while there switch from fdevname() to fdevname_r().

Sponsored by: iXsystems, Inc.
MFC after: 2 weeks

(cherry picked from commit e49d3eb40324eaffaa13b93f2c4173dfa04dfa34)

3 years agoFix zgrep --version
Mateusz Piotrowski [Tue, 13 Apr 2021 10:12:53 +0000 (12:12 +0200)]
Fix zgrep --version

"zgrep --version" is expected to print the version information in the
same way as "zgrep -V". However, the case handling the --version flag
is never reached, so "zgrep --version" prints:
    zgrep: missing pattern
instead of:
    grep (BSD grep, GNU compatible) 2.6.0-FreeBSD

Reviewed by: yuripv
Approved by: yuripv (src)
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D29813

(cherry picked from commit 16e0391f8e2124eb85af984204548cf841648db5)

3 years agoixgbe: Clarify index name in ixgbe_mc_filter_apply
Kevin Bowling [Sat, 17 Apr 2021 01:17:43 +0000 (18:17 -0700)]
ixgbe: Clarify index name in ixgbe_mc_filter_apply

"It looks like it would be less confusing to rename 'count' to
something like 'idx', since that's what it's used for in this
function."

Reviewed by: erj
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D29798

(cherry picked from commit 21afed4b1d18578aa8c9fa31e9e677971f8b4300)

3 years agonfsd: fix replies from session cache for multiple retries
Rick Macklem [Sat, 10 Apr 2021 22:50:25 +0000 (15:50 -0700)]
nfsd: fix replies from session cache for multiple retries

Recent testing of network partitioning a FreeBSD NFSv4.1
server from a Linux NFSv4.1 client identified problems
with both the FreeBSD server and Linux client.

Commit 05a39c2c1c18 fixed replying with the cached reply in
in the session slot if same session slot sequence#.
However, the code uses the reply and, as such,
will fail for a subsequent retry of the RPC.
A subsequent retry would be an extremely rare event,
but this patch fixes this, so long as m_copym(..M_NOWAIT)
does not fail, which should also be a rare event.

This fix affects the exceedingly rare case where a NFSv4
client retries a non-idempotent RPC, such as a lock
operation, multiple times.  Note that retries only occur
after the client has needed to create a new TCP connection,
with a new TCP connection for each retry.

PR: 254816

(cherry picked from commit 22cefe3d8378f58adcdbb2c7589b9f30c2a38315)

3 years agompt(4): Remove incorrect S/G segments limits.
Alexander Motin [Sat, 17 Apr 2021 14:41:35 +0000 (10:41 -0400)]
mpt(4): Remove incorrect S/G segments limits.

First, two of those four checks are unreachable.
Second, I don't believe there should be ">=" instead of ">".
Third, bus_dma(9) already returns the same EFBIG if ">".

This fixes false I/O errors in worst S/G cases with maxphys >= 2MB.

MFC after: 1 week

(cherry picked from commit 0f29396e493bd87ffa6a63fcb602b12e79d21a1e)

3 years agoFix leak in libc NFSv4 ACL flags parsing
Andrew Walker [Tue, 20 Apr 2021 19:34:44 +0000 (15:34 -0400)]
Fix leak in libc NFSv4 ACL flags parsing

Free memory allocated by strdup() in parse_flags_verbose().

Submitted by: Andrew Walker <walker.aj325_gmail.com>
Reported by: valgrind
Reviewed by: allanjude, freqlabs, rpokala
Sponsored by: iXsystems, Inc.
Differential Revision: https://reviews.freebsd.org/D29871

(cherry picked from commit dd559118ab3f065ae230b324c3fe4bb1c9b7ca56)

3 years agopms(4): Limit maximum I/O size to 256KB instead of 1MB.
Alexander Motin [Fri, 16 Apr 2021 19:39:01 +0000 (15:39 -0400)]
pms(4): Limit maximum I/O size to 256KB instead of 1MB.

There is a weird limit of AGTIAPI_MAX_DMA_SEGS (128) S/G segments per
I/O since the initial driver import.  I don't know why it was added,
can only guess some hardware limitation, but in worst case it means
maximum I/O size of 508KB.  Respect it to be safe, rounding to 256KB.

MFC after: 1 week
Sponsored by: iXsystems, Inc.

(cherry picked from commit 3e347834200b5d91a33384e696793e4ac20a44d4)

3 years agopms(4): Do not return CAM_REQ_CMP on errors.
Alexander Motin [Fri, 16 Apr 2021 19:16:09 +0000 (15:16 -0400)]
pms(4): Do not return CAM_REQ_CMP on errors.

It is a direct request for data corruptions, one report of which we
have received.  I am very surprised that only one.

MFC after: 1 week
Sponsored by: iXsystems, Inc.

(cherry picked from commit 8434a65ce49bd6bc6779f0e57b0ce0f4bc46f48e)

3 years agoRevert "stats.7: Add dwatch(1) to the list"
Fernando Apesteguía [Thu, 22 Apr 2021 17:55:01 +0000 (19:55 +0200)]
Revert "stats.7: Add dwatch(1) to the list"

As gbe@ notes, the stats(7) framework is not present in stable/12

This reverts commit 76b02b5cea1dc548d30b2ec5e95ce5a27deb16e3.

3 years agostats.7: Add dwatch(1) to the list
Fernando Apesteguía [Thu, 22 Apr 2021 13:54:45 +0000 (15:54 +0200)]
stats.7: Add dwatch(1) to the list

PR: 255303
Approved by: 0mp (mentor)
Differential Revision: https://reviews.freebsd.org/D29924

(cherry picked from commit 2e5929a75634504d388cc04d24e6a558840e18cb)

3 years agonfsd: fix replies from session cache for retried RPCs
Rick Macklem [Thu, 8 Apr 2021 21:04:22 +0000 (14:04 -0700)]
nfsd: fix replies from session cache for retried RPCs

Recent testing of network partitioning a FreeBSD NFSv4.1
server from a Linux NFSv4.1 client identified problems
with both the FreeBSD server and Linux client.

The FreeBSD server failec to reply using the cached
reply in the session slot when an RPC was retried on
the session slot, as indicated by same slot sequence#.

This patch fixes this.  It should also fix a similar
failure for NFSv4.0 mounts, when the sequence# in
the open/lock_owner requires a reply be done from
an entry locked into the DRC.

This fix affects the fairly rare case where a NFSv4
client retries a non-idempotent RPC, such as a lock
operation.  Note that retries only occur after the
client has needed to create a new TCP connection.

(cherry picked from commit 05a39c2c1c18cd0c4382a4f58e0952d3f77e7dfa)

3 years agoImprove size readability.
Michael Reifenberger [Mon, 15 Feb 2021 19:23:32 +0000 (20:23 +0100)]
Improve size readability.
Preserve more space for swap devise names.
Prevent line overflow with long devise name.
Don't draw a bar when swap is not used at all.
Simplify and optimize code.
Change the label to end at end of 100%.
PR: 251655
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D27496

(cherry picked from commit 8d06c3e7a40831ac139d83b85b282206229b426f)

3 years agosafexcel: Fix the SHA-HMAC digest computation when AAD is present
Mark Johnston [Wed, 21 Apr 2021 18:50:48 +0000 (14:50 -0400)]
safexcel: Fix the SHA-HMAC digest computation when AAD is present

The driver would fail to include the AAD in the input stream, resulting
in incorrect digests for requests combining SHA-HMAC with AES-CBC or
-CTR.  Ensure that the AAD is included in the processor's input stream,
and fix the corresponding instruction sequence to include the AAD as
input to the digest computation.

This is a direct commit to stable/12 since the bug was introduced while
merging there and is not present in later branches.

3 years agospigen.4: Fix typos
Mateusz Piotrowski [Sun, 18 Apr 2021 07:45:18 +0000 (09:45 +0200)]
spigen.4: Fix typos

MFC after: 3 days

(cherry picked from commit 40277af7f23405c276edf02c3ddc8e770a06e3f6)

3 years agoExplain the newfs naming convention
Mateusz Piotrowski [Wed, 20 Jan 2021 10:40:20 +0000 (11:40 +0100)]
Explain the newfs naming convention

It might be unclear why newfs and newfs_msdos should cross-reference
each other. Add a note explaining it.

This is a follow-up to 74bd20769706041108a573601cf0b61c755bdc56.

Reported by: kib
Reviewed by:    imp, kib, rpokala
MFC after: 3 days

(cherry picked from commit 5b9b65e92fb40703038cbcf61feb4616c42e0b6e)

3 years agopf tests: Test multi-wan rdr
Kristof Provost [Tue, 6 Apr 2021 11:25:49 +0000 (13:25 +0200)]
pf tests: Test multi-wan rdr

This replicates an issue observed on pfSense: https://redmine.pfsense.org/issues/11436

In essence, reply-to is needed to ensure that connections always leave
the WAN interface they came in on, but this confused the state tracking.

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

(cherry picked from commit f37667e2359245ad123fd775c072fd82c81bc476)

3 years agopf: Do not short-circuit processing for REPLY_TO
Kristof Provost [Wed, 7 Apr 2021 13:46:44 +0000 (15:46 +0200)]
pf: Do not short-circuit processing for REPLY_TO

When we find a state for packets that was created by a reply-to rule we
still need to process the packet. The state may require us to modify the
packet (e.g. in rdr or nat cases), which we won't do with the shortcut.

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

(cherry picked from commit 6d786845cf63c8bf57174e3e43b0b5c5eca75be3)

3 years agopf: Add static DTrace probe points
Kristof Provost [Fri, 2 Apr 2021 13:53:34 +0000 (15:53 +0200)]
pf: Add static DTrace probe points

These two have proven to be useful during debugging. We may as well keep
them permanently.
Others will be added as their utility becomes clear.

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

(cherry picked from commit f4c02909167b6f791df470afddfe31cabf009c4d)

3 years agopf: change pf_route so pf only runs when packets enter and leave the stack.
Kristof Provost [Fri, 2 Apr 2021 10:23:42 +0000 (12:23 +0200)]
pf: change pf_route so pf only runs when packets enter and leave the stack.

before this change pf_route operated on the semantic that pf runs
when packets go over an interface, so when pf_route changed which
interface the packet was on it would run pf_test again. this change
changes (restores) the semantic that pf is only supposed to run
when packets go in or out of the network stack, even if route-to
is responsibly for short circuiting past the network stack.

just to be clear, for normal packets (ie, those not touched by
route-to/reply-to/dup-to), there isn't a difference between running
pf when packets enter or leave the stack, or having pf run when a
packet goes over an interface.

the main reason for this change is that running the same packet
through pf multiple times creates confusion for the state table.
by default, pf states are floating, meaning that packets are matched
to states regardless of which interface they're going over. if a
packet leaving on em0 is rerouted out em1, both traversals will end
up using the same state, which at best will make the accounting
look weird, or at worst fail some checks in the state and get
dropped.

another reason for this commit is is to make handling of the changes
that route-to makes consistent with other changes that are made to
packet. eg, when nat is applied to a packet, we don't run pf_test
again with the new addresses.

the main caveat with this diff is you can't have one rule that
pushes a packet out a different interface, and then have a rule on
that second interface that NATs the packet. i'm not convinced this
ever worked reliably or was used much anyway, so we don't think
it's a big concern.

discussed with many, with special thanks to bluhm@, sashan@ and
sthen@ for weathering most of that pain.
ok claudio@ sashan@ jmatthew@

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

(cherry picked from commit 829a69db855b48ff7e8242b95e193a0783c489d9)

3 years agonfsd: make the server repeat CB_RECALL every couple of seconds
Rick Macklem [Mon, 5 Apr 2021 01:15:54 +0000 (18:15 -0700)]
nfsd: make the server repeat CB_RECALL every couple of seconds

Commit 01ae8969a9ee stopped the NFSv4.1/4.2 server from implicitly
binding the back channel to a new TCP connection so that it
conforms to RFC5661, for NFSv4.1/4.2. An effect of this
for the Linux NFS client is that it will do a
BindConnectionToSession when it sees NFSV4SEQ_CBPATHDOWN
set in a sequence reply. This will fix the back channel, but the
first attempt at a callback like CB_RECALL will already have
failed. Without this patch, a CB_RECALL will not be retried
and that can result in a 5 minute delay until the delegation
times out.

This patch modifies the code so that it will retry the
CB_RECALL every couple of seconds, often avoiding the
5 minute delay.

This is not critical for correct behaviour, but avoids
the 5 minute delay for the case where the Linux client
re-binds the back channel via BindConnectionToSession.

(cherry picked from commit 7a606f280a3e174dcdd12736b7b976903809eb9c)

3 years agoEnsure that the mount command shows "with quotas" when quotas are enabled.
Kirk McKusick [Wed, 14 Apr 2021 22:22:12 +0000 (15:22 -0700)]
Ensure that the mount command shows "with quotas" when quotas are enabled.

(cherry picked from commit 14d0cd7225e250015eb6d9c79a7eb4e944211b23)

3 years agoWhen we are about to send down to the driver layer
Randall Stewart [Wed, 27 Jan 2021 18:32:52 +0000 (13:32 -0500)]
When we are about to send down to the driver layer
we need to make sure that the m_nextpkt field is NULL
else the lower layers may do unwanted things.

Reviewed By:  gallatin, melifaro
Differential Revision: https://reviews.freebsd.org/D28377
PR: 253587

(cherry picked from commit 24a8f6d369962f189ad808f538029179b1e7dc2f)

3 years agonfsd: fix BindConnectionToSession so that it clears "cb path down"
Rick Macklem [Sun, 4 Apr 2021 22:05:39 +0000 (15:05 -0700)]
nfsd: fix BindConnectionToSession so that it clears "cb path down"

Commit 01ae8969a9ee stopped the NFSv4.1/4.2 server from implicitly
binding the back channel to a new TCP connection so that it
conforms to RFC5661, for NFSv4.1/4.2. An effect of this
for the Linux NFS client is that it will do a
BindConnectionToSession when it sees NFSV4SEQ_CBPATHDOWN
set in a sequence reply. It will do this for every RPC
reply until it no longer sees the flag.
Without that patch, this will happen until the client does
an Open, which will clear LCL_CBDOWN.

This patch clears LCL_CBDOWN right away, so that
NFSV4SEQ_CBPATHDOWN will no longer be sent to the client
in Sequence replies and the Linux client will not repeat
the BindConnectionToSession RPCs.

This is not critical for correct behaviour, but reduces
RPC overheads for cases where the Open will not be done
for a while.

(cherry picked from commit 6f2addd838810ce33c7e9ad9543827d45e0b491c)

3 years agosystat.1: Remove Tn macros
Mateusz Piotrowski [Sat, 6 Feb 2021 13:14:20 +0000 (14:14 +0100)]
systat.1: Remove Tn macros

They are no longer supported by mdoc(7).

MFC after: 1 week

(cherry picked from commit fcbaf46b763a91bb41fe68afdcf59a7d210bc2f7)

3 years agosystat.1: Fix synopsis
Mateusz Piotrowski [Wed, 10 Feb 2021 17:02:14 +0000 (18:02 +0100)]
systat.1: Fix synopsis

systat does not have a "-display" flag. Use Ar to indicate that
"display" is meant to be substituted with an actual display command.

(cherry picked from commit e6f59be239aa17f80b44ded4779e29f5d5352b28)

3 years agotcp: Use sbuf_drain unconditionally
Richard Scheffenegger [Fri, 2 Apr 2021 18:26:48 +0000 (20:26 +0200)]
tcp: Use sbuf_drain unconditionally

After making sbuf_drain safe for external use,
there is no need to protect the call.

MFC after: 2 weeks
Reviewed By: tuexen, #transport
Sponsored by: NetApp, Inc.
Differential Revision: https://reviews.freebsd.org/D29545

(cherry picked from commit 38ea2bd0698e434ec531b97fa94b24db24e16629)
(cherry picked from commit a04906f0273fa6d80eb3ebf22b9b84e53e6b21e0)

3 years agotcp: Shouldn't drain empty sbuf
Richard Scheffenegger [Thu, 1 Apr 2021 15:18:04 +0000 (17:18 +0200)]
tcp: Shouldn't drain empty sbuf

MFC after: 2 weeks
Reviewed By: tuexen, #transport
Sponsored by: NetApp, Inc.
Differential Revision: https://reviews.freebsd.org/D29524

(cherry picked from commit 9aef4e7c2bd4371e526e4e3feb26064d361ad8ce)

3 years agotcp: For hostcache performance, use atomics instead of counters
Richard Scheffenegger [Thu, 1 Apr 2021 08:00:32 +0000 (10:00 +0200)]
tcp: For hostcache performance, use atomics instead of counters

As accessing the tcp hostcache happens frequently on some
classes of servers, it was recommended to use atomic_add/subtract
rather than (per-CPU distributed) counters, which have to be
summed up at high cost to cache efficiency.

PR: 254333
MFC after: 2 weeks
Sponsored by: NetApp, Inc.
Reviewed By: #transport, tuexen, jtl
Differential Revision: https://reviews.freebsd.org/D29522

(cherry picked from commit 529a2a0f2765f6c57c50a5af6be242c03bf714e3)

3 years agotcp: Make hostcache.cache_count MPSAFE by using a counter_u64_t
Richard Scheffenegger [Wed, 31 Mar 2021 17:30:20 +0000 (19:30 +0200)]
tcp: Make hostcache.cache_count MPSAFE  by using a counter_u64_t

Addressing the underlying root cause for cache_count to
show unexpectedly high  values, by protecting all arithmetic on
that global variable by using counter(9).

PR: 254333
Reviewed By: tuexen, #transport
MFC after: 2 weeks
Sponsored by: NetApp, Inc.
Differential Revision: https://reviews.freebsd.org/D29510

(cherry picked from commit 95e56d31e348594973affd0ea81d8f8383bc3031)

3 years agotcp: drain tcp_hostcache_list in between per-bucket locks
Richard Scheffenegger [Wed, 31 Mar 2021 17:24:01 +0000 (19:24 +0200)]
tcp: drain tcp_hostcache_list in between per-bucket locks

Explicitly drain the sbuf after completing each hash bucket
to minimize the work performed while holding the hash
bucket lock.

PR: 254333
MFC after: 2 weeks
Reviewed By: tuexen, jhb, #transport
Sponsored by:  NetApp, Inc.
Differential Revision: https://reviews.freebsd.org/D29483

(cherry picked from commit 869880463cc2ce64e2e6599eaec880a981f3ced6)

3 years agotcp: reduce memory footprint when listing tcp hostcache
Richard Scheffenegger [Sun, 28 Mar 2021 21:12:03 +0000 (23:12 +0200)]
tcp: reduce memory footprint when listing tcp hostcache

In tcp_hostcache_list, the sbuf used would need a large (~2MB)
blocking allocation of memory (M_WAITOK), when listing a
full hostcache. This may stall the requestor for an indeterminate
time.

A further optimization is to return the expected userspace
buffersize right away, rather than preparing the output of
each current entry of the hostcase, provided by: @tuexen.

This makes use of the ready-made functions of sbuf to work
with sysctl, and repeatedly drain the much smaller buffer.

PR: 254333
MFC after: 2 weeks
Reviewed By: #transport, tuexen
Sponsored by: NetApp, Inc.
Differential Revision: https://reviews.freebsd.org/D29471

(cherry picked from commit cb0dd7e122b8936ad61a141e65ef8ef874bfebe5)

3 years agoMake sbuf_drain safe for external use
Richard Scheffenegger [Fri, 2 Apr 2021 18:11:45 +0000 (20:11 +0200)]
Make sbuf_drain safe for external use

While sbuf_drain was an internal function, two
KASSERTS checked the sanity of it being called.
However, an external caller may be ignorant if
there is any data to drain, or if an error has
already accumulated. Be nice and return immediately
with the accumulated error.

MFC after: 2 weeks
Reviewed By: tuexen, #transport
Sponsored by: NetApp, Inc.
Differential Revision: https://reviews.freebsd.org/D29544

(cherry picked from commit cad4fd0365a5e3235e715e072e6ee9dffaa7a3ab)

3 years agoExport sbuf_drain to orchestrate lock and drain action
Richard Scheffenegger [Wed, 31 Mar 2021 16:25:53 +0000 (18:25 +0200)]
Export sbuf_drain to orchestrate lock and drain action

While exporting large amounts of data to a sysctl
request, datastructures may need to be locked.

Exporting the sbuf_drain function allows the
coordination between drain events and held
locks, to avoid stalls.

PR: 254333
Reviewed By: jhb
MFC after: 2 weeks
Sponsored by: NetApp, Inc.
Differential Revision: https://reviews.freebsd.org/D29481

(cherry picked from commit c804c8f2c58ba42d476de07fbceff9ac4dd95f0e)

3 years agoconfig(8): Mention the authors of a paper in the SEE ALSO section
Gordon Bergling [Fri, 9 Apr 2021 09:20:49 +0000 (11:20 +0200)]
config(8): Mention the authors of a paper in the SEE ALSO section

Obtained from: OpenBSD

(cherry picked from commit 2b59392cb0da804e825c63469beb1934ec4267db)

3 years agolpd(8): Mention the author of a paper in the SEE ALSO section
Gordon Bergling [Fri, 9 Apr 2021 09:29:18 +0000 (11:29 +0200)]
lpd(8): Mention the author of a paper in the SEE ALSO section

Obtained from: OpenBSD

(cherry picked from commit c07aa0a5878f55ef22b8d0ba5f66a728b1407427)

3 years agormlock(9): add an RM_DUPOK flag
Mitchell Horne [Thu, 8 Apr 2021 17:41:19 +0000 (14:41 -0300)]
rmlock(9): add an RM_DUPOK flag

Allows for duplicate locks to be acquired without witness complaining.
Similar flags exists already for rwlock(9) and sx(9).

Reviewed by: markj
Sponsored by: NetApp, Inc.
Sponsored by: Klara, Inc.

(cherry picked from commit 2816bd8442bc323d50434d0e64cb4b7c10a195e8)

3 years agoPartially revert r248770.
Dmitry Chagin [Fri, 2 Apr 2021 08:43:17 +0000 (11:43 +0300)]
Partially revert r248770.

Under geom(4) nvme_ns_bio_process() is on the path where sleep
is prohibited as g_io_shedule_down() calls THREAD_NO_SLEEPNG()
before geom->start().

Reviewed By: imp
Differential Revision: https://reviews.freebsd.org/D29539

(cherry picked from commit a78109d5db87b08785a822770e2e4fdb15f921b6)

3 years agoRemoved the reference to the deprecated splx API from ifnet(9).
Dmitry Chagin [Fri, 9 Apr 2021 14:22:12 +0000 (17:22 +0300)]
Removed the reference to the deprecated splx API from ifnet(9).

Reviewed by: emaste, markj
PR: 254880
Differential Revision: https://reviews.freebsd.org/D29666

(cherry picked from commit f2400e6e832d42ca72b0d04ecd070598f4a81eb7)

3 years agosys/ck.h: Add an include guard
Kevin Bowling [Sun, 21 Mar 2021 18:50:30 +0000 (11:50 -0700)]
sys/ck.h: Add an include guard

Approved by: cognet
MFC after: 1 week
Sponsored by: BBOX.io
Differential Revision: https://reviews.freebsd.org/D29357

(cherry picked from commit 2595d78f3df2ca389aae259a291f93eb06ecad43)

3 years agonfsd: silence rpcb_unset noise for NFSv4 only servers
Rick Macklem [Thu, 1 Apr 2021 22:09:03 +0000 (15:09 -0700)]
nfsd: silence rpcb_unset noise for NFSv4 only servers

An NFSv4 only configuration does not register with
rpcbind(). Without this patch a failure to rpcb_unset()
is reported when the daemon is terminated for this case.

This is harmless noise, but this patch avoids calling
rpcb_unset() for the NFSv4 only case, avoiding the noise.

When called with "-d", it still does the rpcb_unset(),
assuming that the configuration might have been
changed to NFSv4 only and unregistering with
rpcbind() might still be needed.

(cherry picked from commit b43fe9eb4b3365156016ae3477747a46fc094bb8)

3 years agosetclassenvironment: trim leading spaces in variable names
Yuri Pankov [Sun, 11 Apr 2021 22:02:12 +0000 (01:02 +0300)]
setclassenvironment: trim leading spaces in variable names

Trim leading spaces in variable names when the list is e.g.
pretty-formatted in /etc/login.conf or ~/.login_conf.

PR: 247947
Reviewed by: allanjude
Differential Revision: https://reviews.freebsd.org/D25649

(cherry picked from commit eeaf9d562fe137e0c52b8c346742dccfc8bde015)

3 years agoAvoid raising unexpected floating point exceptions in libm
Dimitry Andric [Fri, 9 Apr 2021 23:07:54 +0000 (01:07 +0200)]
Avoid raising unexpected floating point exceptions in libm

When using clang with x86_64 CPUs that support AVX, some floating point
transformations may raise exceptions that would not have been raised by
the original code. To avoid this, use the -fp-exception-behavior=maytrap
flag, introduced in clang 10.0.0.

In particular, this fixes a number of test failures with ctanhf(3) and
ctanf(3), when libm is compiled with -mavx. An unexpected FE_INVALID
exception is then raised, because clang emits vdivps instructions to
perform certain divides. (The vdivps instruction operates on multiple
single-precision float operands simultaneously, but the exceptions may
be influenced by unused parts of the XMM registers. In this particular
case, it was calculating 0 / 0, which results in FE_INVALID.)

If -fp-exception-behavior=maytrap is specified however, clang uses
vdivss instructions instead, which work on one operand, and should not
raise unexpected exceptions.

Reported by: olivier
Reviewed by: arichardson
PR: 254911
Differential Revision: https://reviews.freebsd.org/D29686

(cherry picked from commit 3b00222f156dca5700c839d73e36daf479fa640c)

Only use -fp-exception-behavior=maytrap on x86, for now

After 3b00222f156d, it turns out that clang only supports strict
floating point semantics for SystemZ and x86 at the moment, while for
other architectures it is still experimental.

Therefore, only use -fp-exception-behavior=maytrap on x86 for now,
otherwise this option results in "error: overriding currently
unsupported use of floating point exceptions on this target
[-Werror,-Wunsupported-floating-point-opt]" on other architectures.

Fixes: 3b00222f156d
PR: 254911

(cherry picked from commit bae9fd0b33462e9506c3ac3400089c6dbc4aee8f)

3 years agoAvoid -pedantic warnings about using _Generic in __fp_type_select
Dimitry Andric [Thu, 8 Apr 2021 11:13:15 +0000 (13:13 +0200)]
Avoid -pedantic warnings about using _Generic in __fp_type_select

When compiling parts of math.h with clang using a C standard before C11,
and using -pedantic, it will result in warnings similar to:

bug254714.c:5:11: warning: '_Generic' is a C11 extension [-Wc11-extensions]
  return !isfinite(1.0);
          ^
/usr/include/math.h:111:21: note: expanded from macro 'isfinite'
                    ^
/usr/include/math.h:82:39: note: expanded from macro '__fp_type_select'
                                      ^

This is because the block that enables use of _Generic is conditional
not only on C11, but also on whether the compiler advertises support for
C generic selections via __has_extension(c_generic_selections).

To work around the warning without having to pessimize the code, use the
__extension__ keyword, which is supported by both clang and gcc. While
here, remove the check for __clang__, as _Generic has been supported for
a long time by gcc too now.

Reported by: yuri
PR: 254714

3 years agom4(1): Add a SEE ALSO section and reference an AT&T manual
Gordon Bergling [Thu, 8 Apr 2021 19:16:54 +0000 (21:16 +0200)]
m4(1): Add a SEE ALSO section and reference an AT&T manual

Obtained from: OpenBSD

(cherry picked from commit 97fa288a663dfae192c471ec5cbfdf0d2f45367e)

3 years agolibnv: Allow use in non-sleepable contexts
Kristof Provost [Thu, 25 Mar 2021 12:59:14 +0000 (13:59 +0100)]
libnv: Allow use in non-sleepable contexts

44c125c4cebc2fd87c6260b90eddae11201f5232 switched the nvlist allocations
to be M_WAITOK, but this precludes the use in non-sleepable contexts.
(E.g. with a nonsleepable lock held).

All callers for these allocation functions already cope with memory
alloation failures, so there's no reason to allow sleeping during
allocations.

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

(cherry picked from commit ab8d25880ebc9ddca1ae6af938680036349edf3f)

3 years agopf tests: make synproxy and nat work correctly even if inetd is running
Kurosawa Takahiro [Wed, 7 Apr 2021 06:17:51 +0000 (08:17 +0200)]
pf tests: make synproxy and nat work correctly even if inetd is running

tests/sys/netfil/pf/synproxy fails if inetd has been running
outside of the jail because pidfile_open() fails with EEXIST.
tests/sys/netfil/pf/nat has the same problem but the test succeeds
because whether inetd is running is not so important.

Fix the problem by changing the pidfile path from the default
location.

Reviewed by: kp
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D29622

(cherry picked from commit 5a5623397c73e46b206289d32d1d6b9de420da9c)

3 years agoAdd IDs for ASMedia ASM116x PCIe 3.0 AHCI controllers.
Alexander Motin [Wed, 7 Apr 2021 19:03:36 +0000 (15:03 -0400)]
Add IDs for ASMedia ASM116x PCIe 3.0 AHCI controllers.

MFC after: 1 week

(cherry picked from commit 5a8d32b53b919d82d6a3aa9f155bd2a00fb51dc2)

3 years agopms: handle maximum size IO with any alignment
Ryan Libby [Wed, 20 Jan 2021 21:59:49 +0000 (13:59 -0800)]
pms: handle maximum size IO with any alignment

Define the maximum numbers of segments to allow for non-page alignment
at the beginning and end of a maxphys size transfer.  Also set
ccb_pathinq.maxio consistent with maxphys.

Reviewed by: imp
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D28043

(cherry picked from commit e54a1d5751805714bf6ea5e2e99887388110f9f0)

3 years agoreadelf: return error in case of invalid file
Ed Maste [Mon, 5 Apr 2021 01:01:28 +0000 (21:01 -0400)]
readelf: return error in case of invalid file

GNU readelf exits with an error for a number of invalid file cases.
Previously ELF Tool Chain readelf always exited with 0.  Now we exit 1
upon detecting an error with one or more input files, but in any case
all of them are processed.

This should catch common failure cases.  We still do not report an error
for some types of malformed ELF files, but this is consistent with GNU
readelf.

PR: 252727
Reviewed by: jkoshy, markj
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D29377

(cherry picked from commit ea444392bb5b351c930f28a02a4e68f51b25ba69)

3 years agofreebsd-update: improve mandoc db generation
Ed Maste [Sun, 4 Apr 2021 00:57:26 +0000 (20:57 -0400)]
freebsd-update: improve mandoc db generation

freebsd-update compares the dates on man pages with mandoc.db, and if
any newer pages are found it regenerates mandoc.db.

Previously, if mandoc.db did not already exist the check failed and
freebsd-update then failed to create one.  Now, check that mandoc.db
exists before performing the check for newer pages.

Reported by: bdrewery (in D10482)
Reviewed by: gordon
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D29575

(cherry picked from commit 741223a65cd1752360c44341b762295f633e21cf)

3 years agosysctl.conf(5): Mention sysctl.conf.local in the sysctl.conf(5) manual page
Gordon Bergling [Fri, 9 Apr 2021 15:28:18 +0000 (17:28 +0200)]
sysctl.conf(5): Mention sysctl.conf.local in the sysctl.conf(5) manual page

The possibility of using a sysctl.conf.local on a machine that has a shared
sysctl.conf(5) isn't documented. So mention the sysctl.conf.local in the
manual page.

PR: 254901
Submitted by: Jose Luis Duran <jlduran at gmail dot com>
Reported by: Jose Luis Duran <jlduran at gmail dot com>
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D29673

(cherry picked from commit 46c99528078ad478f50910110a933abef0b89cde)

3 years agonfsd: do not implicitly bind the back channel for NFSv4.1/4.2 mounts
Rick Macklem [Tue, 30 Mar 2021 21:31:05 +0000 (14:31 -0700)]
nfsd: do not implicitly bind the back channel for NFSv4.1/4.2 mounts

The NFSv4.1 (and 4.2 on 13) server incorrectly binds
a new TCP connection to the back channel when first
used by an RPC with a Sequence op in it (almost all of them).
RFC5661 specifies that only the fore channel should be bound.

This was done because early clients (including FreeBSD)
did not do the required BindConnectionToSession RPC.

Unfortunately, this breaks the Linux client when the
"nconnects" mount option is used, since the server
may do a callback on the incorrect TCP connection.

This patch converts the server behaviour to that
required by the RFC.  It also makes the server test/indicate
failure of the back channel more aggressively.

Until this patch is applied to the server, the
"nconnects" mount option is not recommended for a Linux
NFSv4.1/4.2 client mount to the FreeBSD server.

PR: 254560
(cherry picked from commit 01ae8969a9eed652fbd894faa5b31b1593079ed8)

3 years agonfsv4 client: fix forced dismount when sleeping in the renew thread
Rick Macklem [Tue, 23 Mar 2021 20:04:37 +0000 (13:04 -0700)]
nfsv4 client: fix forced dismount when sleeping in the renew thread

During a recent NFSv4 testing event a test server caused a hang
where "umount -N" failed.  The renew thread was sleeping on "nfsv4lck"
and the "umount" was sleeping, waiting for the renew thread to
terminate.

This is the second of two patches that is hoped to fix the renew thread
so that it will terminate when "umount -N" is done on the mount.

This patch adds a 5second timeout on the msleep()s and checks for
the forced dismount flag so that the renew thread will
wake up and see the forced dismount flag.  Normally a wakeup()
will occur in less than 5seconds, but if a premature return from
msleep() does occur, it will simply loop around and msleep() again.
The patch also adds the "mp" argument to nfsv4_lock() so that it
will return when the forced dismount flag is set.

While here, replace the nfsmsleep() wrapper that was used for portability
with the actual msleep() call.

(cherry picked from commit 82ee386c2afb42388804c1189751b83048953433)

3 years agoig4: Add PCI IDs for Intel Gemini Lake I2C controller.
Vladimir Kondratyev [Tue, 23 Feb 2021 22:20:36 +0000 (01:20 +0300)]
ig4: Add PCI IDs for Intel Gemini Lake I2C controller.

Submitted by: Dmitry Luhtionov
MFC after: 2 weeks

3 years ago[tcp] Fix ECN on finalizing sessions.
Richard Scheffenegger [Thu, 8 Apr 2021 12:50:34 +0000 (14:50 +0200)]
[tcp] Fix ECN on finalizing sessions.

A subtle oversight would subtly change new data packets
sent after a shutdown() or close() call, while the send
buffer is still draining.

MFC after: 3 days
Reviewed By: #transport, tuexen
Sponsored by: NetApp, Inc.
Differential Revision: https://reviews.freebsd.org/D29616

(cherry picked from commit 9f2eeb02623d6a847a90da68a5892c25b14ce2d4)

3 years agoAdd sysctl debug.uma_reclaim
Konstantin Belousov [Sun, 4 Apr 2021 16:28:14 +0000 (19:28 +0300)]
Add sysctl debug.uma_reclaim

(cherry picked from commit 89619b747bcff379dca98e975a98865a45366417)

3 years agostruct mount uppers: correct locking annotations
Konstantin Belousov [Thu, 8 Apr 2021 22:03:06 +0000 (01:03 +0300)]
struct mount uppers: correct locking annotations

(cherry picked from commit 5af1131de7fc18c795ed28e69d9393f78875d3e5)

3 years ago[bc] Update to version 4.0.0
Stefan Eßer [Tue, 6 Apr 2021 08:44:52 +0000 (10:44 +0200)]
[bc] Update to version 4.0.0

This version fixes an issue (missing pop of top-of-stack value in the
"P" command of the dc program).

This issue did not affect the bc program, since it does not use dc as
an back-end to actually perform the calculations as was the case with
the traditional bc and dc programs.

The major number has been bumped due to Windows support that has been
added to this version. It does not correspond to a major change that
might affect FreeBSD.

(cherry picked from commit b55a927bc884d7780d65a508572023b0dc2dede9)

3 years agonet: fixing a memory leak in if_deregister_com_alloc()
Tai-hwa Liang [Sat, 6 Mar 2021 14:36:35 +0000 (14:36 +0000)]
net: fixing a memory leak in if_deregister_com_alloc()

Drain the callbacks upon if_deregister_com_alloc() such that the
if_com_free[type] won't be nullified before if_destroy().

Taking fwip(4) as an example, before this fix, kldunload if_fwip will
go through the following:

  1. fwip_detach()
  2. if_free() -> schedule if_destroy() through NET_EPOCH_CALL
  3. fwip_detach() returns
  4. firewire_modevent(MOD_UNLOAD) -> if_deregister_com_alloc()
  5. kernel complains about:
Warning: memory type fw_com leaked memory on destroy (1 allocations, 64 bytes leaked).
  6. EPOCH runs if_destroy() -> if_free_internal()

By this time, if_com_free[if_alloctype] is NULL since it's already
nullified by if_deregister_com_alloc(); hence, firewire_free() won't
have a chance to release the allocated fw_com.

Reviewed by: hselasky, glebius
MFC after: 2 weeks

(cherry picked from commit 092f3f081265c68cd8de0234ba8e46560ccc061e)

3 years agoffsinfo: Update example to avoid to-be-deprecated vinum
Ed Maste [Mon, 29 Mar 2021 00:04:29 +0000 (20:04 -0400)]
ffsinfo: Update example to avoid to-be-deprecated vinum

Reviewed by: mckusick
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D29478

(cherry picked from commit a64096aa63ea1303ae8d20d4147b3b097071072f)

3 years agovfs: honor error code returned by mac_vnode_check_rename_from
Mateusz Guzik [Wed, 29 Jul 2020 17:04:33 +0000 (17:04 +0000)]
vfs: honor error code returned by mac_vnode_check_rename_from

(cherry picked from commit fd8c6a48abe0ad2ba64b611fe044830f89b30138)

3 years agonullfs: protect against user creating inconsistent state
Konstantin Belousov [Thu, 1 Apr 2021 17:42:14 +0000 (20:42 +0300)]
nullfs: protect against user creating inconsistent state

PR: 253593

(cherry picked from commit 76b1b5ce6d81f66b09be8a20aecd064b65fd6b50)

3 years agoStyle
Konstantin Belousov [Sun, 4 Apr 2021 16:27:42 +0000 (19:27 +0300)]
Style

(cherry picked from commit 51a7be5f6036ebd47c8b3f704d52e7ec3f837114)

3 years agombuf: add a way to mark flowid as calculated from the internal headers
Konstantin Belousov [Fri, 12 Feb 2021 13:38:07 +0000 (15:38 +0200)]
mbuf: add a way to mark flowid as calculated from the internal headers

(cherry picked from commit e243367b644562c9410b39f8d78dafdb7e785d85)

3 years agoMFC jail: fix jail(8) synposis and usage message to match reality.
Jamie Gritton [Sun, 4 Apr 2021 17:49:38 +0000 (10:49 -0700)]
MFC jail: fix jail(8) synposis and usage message to match reality.

Reported by: yuri
PR: 254741

(cherry picked from commit 8c1d956ffa0355ece3b63ea8587938176f87f072)

3 years agoFix the build after 5061d5a0cfaf68a6891db82f6bd26ad3e72e87b1
Alan Somers [Thu, 8 Apr 2021 23:11:00 +0000 (23:11 +0000)]
Fix the build after 5061d5a0cfaf68a6891db82f6bd26ad3e72e87b1

A merge conflict in the MFC broke the build.  Direct commit to stable/12
because main and stable/13 are unaffected.

3 years agompsutil.8: fix typos in the man page
Alan Somers [Thu, 25 Mar 2021 14:43:40 +0000 (08:43 -0600)]
mpsutil.8: fix typos in the man page

Sponsored by: Axcient

(cherry picked from commit f073ab8712a032faecf1fb94c4491fd555461ad8)

3 years agofusefs: fix two bugs regarding fcntl file locks
Alan Somers [Thu, 18 Mar 2021 20:27:27 +0000 (14:27 -0600)]
fusefs: fix two bugs regarding fcntl file locks

1) F_SETLKW (blocking) operations would be sent to the FUSE server as
   F_SETLK (non-blocking).

2) Release operations, F_SETLK with lk_type = F_UNLCK, would simply
   return EINVAL.

PR: 253500
Reported by: John Millikin <jmillikin@gmail.com>

(cherry picked from commit 929acdb19acb67cc0e6ee5439df98e28a84d4772)

fusefs: fix a dead store in fuse_vnop_advlock

kevans actually caught this in the original review and I fixed it, but
then I committed an older copy of the branch.  Whoops.

Reported by: kevans
Differential Revision: https://reviews.freebsd.org/D29031

(cherry picked from commit 9c5aac8f2e84ca4bbdf82514302c08c0453ec59b)

3 years agoModernize geom_stats_snapshot_get
Alan Somers [Wed, 3 Mar 2021 20:06:38 +0000 (13:06 -0700)]
Modernize geom_stats_snapshot_get

* A logically useless memset() is used to fault in some memory pages.
  Change it to explicit_bzero so the compiler won't eliminate it.

* Eliminate the second memset.  It made sense in the days of the Big
  Kernel Lock, but not in the days of fine-grained SMP and especially
  not in the days of VDSO.

Sponsored by: Axcient
Reviewed by: phk
Differential Revision: https://reviews.freebsd.org/D29047

(cherry picked from commit f05b724ecb310fb91da1947ae6c68647f58f5f12)

3 years ago[skip ci] fix a typo in a comment in mdconfig.c
Alan Somers [Sat, 27 Feb 2021 16:04:10 +0000 (09:04 -0700)]
[skip ci] fix a typo in a comment in mdconfig.c

Sponsored by: Axcient
Reviewed by:    mav, imp
Differential Revision:  https://reviews.freebsd.org/D28968

(cherry picked from commit d977417d74a704930b5952cbd653638ccd25eaa7)

3 years agoSpeed up geom_stats_resync in the presence of many devices
Alan Somers [Sat, 27 Feb 2021 15:59:40 +0000 (08:59 -0700)]
Speed up geom_stats_resync in the presence of many devices

The old code had a O(n) loop, where n is the size of /dev/devstat.
Multiply that by another O(n) loop in devstat_mmap for a total of
O(n^2).

This change adds DIOCGMEDIASIZE support to /dev/devstat so userland can
quickly determine the right amount of memory to map, eliminating the
O(n) loop in userland.

This change decreases the time to run "gstat -bI0.001" with 16,384 md
devices from 29.7s to 4.2s.

Also, fix a memory leak first reported as PR 203097.

Sponsored by: Axcient
Reviewed by: mav, imp
Differential Revision: https://reviews.freebsd.org/D28968

(cherry picked from commit ab63da3564e8ab0907f9d8eb565774848ffdadeb)

3 years agofortune: add a tip about gstat
Alan Somers [Fri, 26 Feb 2021 15:06:07 +0000 (08:06 -0700)]
fortune: add a tip about gstat

(cherry picked from commit 60a632f047cdb6e5314711f593a4d3b1f1d8dde9)

3 years agofusefs: set d_off during VOP_READDIR
Alan Somers [Fri, 12 Feb 2021 01:01:10 +0000 (18:01 -0700)]
fusefs: set d_off during VOP_READDIR

This allows d_off to be used with lseek to position the file so that
getdirentries(2) will return the next entry.  It is not used by
readdir(3).

PR: 253411
Reported by: John Millikin <jmillikin@gmail.com>
Reviewed by: cem
Differential Revision: https://reviews.freebsd.org/D28605

(cherry picked from commit 71befc35061b3c9d8cc07e34c5dce622c848fcdb)

3 years agomount_nullfs: rename a local variable
Alan Somers [Fri, 12 Feb 2021 18:30:52 +0000 (11:30 -0700)]
mount_nullfs: rename a local variable

The "source" variable was introduced in r26072, probably as the
traditional counterpart to "target".  But the "source"/"target" names
suggest the opposite of their actual meaning.  With ln, for example, the
source is the real file and the target is the newly created link.  In
mount_nullfs the meaning is the opposite: the target is the existing
file system and the source is the newly created mountpoint.  Better to
use "target"/"mountpoint" terminology, which matches the man page.

Sponsored by: Axcient

(cherry picked from commit f540cb27a23719d88b7e5143be6e62f75dd25f08)

3 years agonetmap: pkt-gen: allow -Z and -z to be used together
Vincenzo Maffione [Tue, 30 Mar 2021 06:13:07 +0000 (06:13 +0000)]
netmap: pkt-gen: allow -Z and -z to be used together

These options are used for generating random source/destination
IP/ports within transmitted packets.

MFC after: 1 week

3 years agonetmap: bridge: fix transmission in busy-wait mode
Vincenzo Maffione [Tue, 30 Mar 2021 06:24:56 +0000 (06:24 +0000)]
netmap: bridge: fix transmission in busy-wait mode

In busy-wait mode (BUSYWAIT defined), NIOCTXSYNC should be
performed after packets have been moved to the TX ring
(rather than before).
Before the change, moved packets may stall for an indefinite
time in the TX ring.

MFC after: 1 week

(cherry picked from commit 51cc31088bf4d23a6ad0bfe8851adaa049d750fc)

3 years agodummynet: Move timekeeping information into dn_cfg
Kristof Provost [Tue, 9 Mar 2021 15:44:26 +0000 (16:44 +0100)]
dummynet: Move timekeeping information into dn_cfg

Just like with the packet counters move the timekeeping information into
dn_cfg. This reduces the global name space use for dummynet and will
make subsequent work to add vnet support and re-use in pf easier.

Reviewed by: donner
MFC after: 2 weeks
Sponsored by: Rubicon Communications, LLC ("Netgate")
Different Revision: https://reviews.freebsd.org/D29246

(cherry picked from commit 320bed3c007be1c2ff1f4b0d00d64d541d807fed)

3 years agodummynet: Move packet counters into dn_cfg
Kristof Provost [Tue, 9 Mar 2021 15:27:31 +0000 (16:27 +0100)]
dummynet: Move packet counters into dn_cfg

Move the packets counters into the dn_cfg struct. This reduces the
global name space use for dummynet and will make future work for things
like vnet support and re-use in pf easier.

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

(cherry picked from commit cd5671efc0190ba0f9eb41bba42e703277af20c3)

3 years agoMove time math out of disabled interrupts sections.
Alexander Motin [Wed, 10 Mar 2021 18:39:15 +0000 (13:39 -0500)]
Move time math out of disabled interrupts sections.

We don't need the result before next sleep time, so no reason to
additionally increase interrupt latency.

While there, remove extra PM ticks to microseconds conversion, making
C2/C3 sleep times look 4 times smaller than really.  The conversion
is already done by AcpiGetTimerDuration().  Now I see reported sleep
times up to 0.5s, just as expected for planned 2 wakeups per second.

MFC after: 1 month

(cherry picked from commit 2cee045b4d62568d065b838a6cf129fed2424709)

3 years agoDo not read timer extra time when MWAIT is used.
Alexander Motin [Mon, 8 Mar 2021 23:43:47 +0000 (18:43 -0500)]
Do not read timer extra time when MWAIT is used.

When we enter C2+ state via memory read, it may take chipset some
time to stop CPU.  Extra register read covers that time.  But MWAIT
makes CPU stop immediately, so we don't need to waste time after
wakeup with interrupts still disabled, increasing latency.

On my system it reduces ping localhost latency, waking up all CPUs
once a second, from 277us to 242us.

MFC after: 1 month

(cherry picked from commit 075e4807df3e6b0d9196d56e4dbc33765d57e1f8)

3 years agoChange mwait_bm_avoidance use to match Linux.
Alexander Motin [Mon, 8 Mar 2021 22:57:46 +0000 (17:57 -0500)]
Change mwait_bm_avoidance use to match Linux.

Even though the information is very limited, it seems the intent of
this flag is to control ACPI_BITREG_BUS_MASTER_STATUS use for C3,
not force ACPI_BITREG_ARB_DISABLE manipulations for C2, where it was
never needed, and which register not really doing anything for years.
It wasted lots of CPU time on congested global ACPI hardware lock
when many CPU cores were trying to enter/exit deep C-states same time.

On idle 80-core system it pushed ping localhost latency up to 20ms,
since badport_bandlim() via counter_ratecheck() wakes up all CPUs
same time once a second just to synchronously reset the counters.
Now enabling C-states increases the latency from 0.1 to just 0.25ms.

Discussed with: kib
MFC after: 1 month

(cherry picked from commit 455219675dbd61010e180cacdfed51e7e34111e1)

3 years agomount: Disallow mounting over a jail root
Mark Johnston [Tue, 6 Apr 2021 18:57:57 +0000 (14:57 -0400)]
mount: Disallow mounting over a jail root

Discussed with: jamie
Approved by: so
Security: CVE-2020-25584
Security: FreeBSD-SA-21:10.jail_mount

3 years agovm_fault: Shoot down multiply mapped COW source page mappings
Mark Johnston [Tue, 6 Apr 2021 18:56:37 +0000 (14:56 -0400)]
vm_fault: Shoot down multiply mapped COW source page mappings

Reviewed by: kib, rlibby
Discussed with: alc
Approved by: so
Security: CVE-2021-29626
Security: FreeBSD-SA-21:08.vm

3 years agoLock busdma operations and serialize detach against open/close
Marcel Moolenaar [Thu, 4 Jul 2019 02:51:34 +0000 (02:51 +0000)]
Lock busdma operations and serialize detach against open/close

Use sx to allow M_WAITOK allocations (suggested by markj).

admbugs: 782
Reviewed by: markj

(cherry picked from commit 9f011bca829751ed3552ac94fe7c865d75fabfc4)

3 years agoReduce chance of RCU deadlock in the LinuxKPI by implementing the section
Hans Petter Selasky [Sun, 28 Mar 2021 07:36:48 +0000 (09:36 +0200)]
Reduce chance of RCU deadlock in the LinuxKPI by implementing the section
feature of the concurrency kit, CK.

Differential Revision: https://reviews.freebsd.org/D29467
Reviewed by: kib@ and markj@
Sponsored by: Mellanox Technologies // NVIDIA Networking

(cherry picked from commit 177772088060ab0f41bcdbdd81c4712e7f1c7621)

3 years agoipdivert: check that PCB is still valid after taking INPCB_RLOCK.
Andrey V. Elsukov [Tue, 30 Mar 2021 09:31:09 +0000 (12:31 +0300)]
ipdivert: check that PCB is still valid after taking INPCB_RLOCK.

We are inspecting PCBs of divert sockets under NET_EPOCH section,
but PCB could be already detached and we should check INP_FREED flag
when we took INP_RLOCK.

PR: 254478
Differential Revision: https://reviews.freebsd.org/D29420

(cherry picked from commit c80a4b76ceacc5aab322e7ac1407eea8c90cb3b1)

3 years agonetmap: iflib: add nm_config callback
Vincenzo Maffione [Mon, 29 Mar 2021 09:26:12 +0000 (11:26 +0200)]
netmap: iflib: add nm_config callback

This per-driver callback is invoked by netmap when it wants
to align the number of TX/RX netmap rings and/or the number of
TX/RX netmap slots to the actual state configured in the hardware.
The alignment happens when netmap mode is switched on (with no
active netmap file descriptors for that netmap port), or when
collecting netmap port information.

MFC after: 1 week

(cherry picked from commit 21d0c01226eb979556d6d792ec58eb54012fbc24)

3 years agonfsv4 client: fix forced dismount when sleeping on nfsv4lck
Rick Macklem [Fri, 19 Mar 2021 21:09:33 +0000 (14:09 -0700)]
nfsv4 client: fix forced dismount when sleeping on nfsv4lck

During a recent NFSv4 testing event a test server caused a hang
where "umount -N" failed.  The renew thread was sleeping on "nfsv4lck"
and the "umount" was sleeping, waiting for the renew thread to
terminate.

This is the first of two patches that is hoped to fix the renew thread
so that it will terminate when "umount -N" is done on the mount.

nfsv4_lock() checks for forced dismount, but only after it wakes up
from msleep().  Without this patch, a wakeup() call was required.
This patch adds a 1second timeout on the msleep(), so that it will
wake up and see the forced dismount flag.  Normally a wakeup()
will occur in less than 1second, but if a premature return from
msleep() does occur, it will simply loop around and msleep() again.

While here, replace the nfsmsleep() wrapper that was used for portability
with the actual msleep() call and make the same change for nfsv4_getref().

(cherry picked from commit 5f742d3879deb1f46f2d151d5ef84f49e8d6afe6)

3 years agonfsv4 pnfs client: fix updating of the layout stateid.seqid
Rick Macklem [Thu, 18 Mar 2021 19:20:25 +0000 (12:20 -0700)]
nfsv4 pnfs client: fix updating of the layout stateid.seqid

During a recent NFSv4 testing event a test server was replying
NFSERR_OLDSTATEID for layout stateids presented to the server
for LayoutReturn operations.  Upon rereading RFC5661, it was
apparent that the FreeBSD NFSv4.1/4.2 pNFS client did not
maintain the seqid field of the layout stateid correctly.

This patch is believed to correct the problem.  Tested against
a FreeBSD pNFS server with diagnostics added to check the stateid's
seqid did not indicate problems.  Unfortunately, testing aginst
this server will not happen in the near future, so the fix may
not be correct yet.

(cherry picked from commit fd232a21bb35e8ba8b62c2314b16b2f1d7c00afc)

3 years agoinit: use explicit_bzero() for clearing passwords
Kyle Evans [Wed, 3 Mar 2021 03:38:37 +0000 (21:38 -0600)]
init: use explicit_bzero() for clearing passwords

This is a nop in practice, because it cannot be proven that this
particular bzero() is not significant.  Make it explicit anyways, rather
than relying on an implementation detail of how the password is
collected.

Discussed with: Andrew Gierth <andrew tao146 riddles org uk>

(cherry picked from commit 852f70b24043885f0e438e8fecedd482a9a96d5e)

3 years agoMFC 874b1a35486b570513680c3d456b062ba097e1d9:
Cy Schubert [Tue, 23 Mar 2021 03:11:58 +0000 (20:11 -0700)]
MFC 874b1a35486b570513680c3d456b062ba097e1d9:

ipfilter: simplify ipf_proxy_check() return codes

ipf_proxy_check() returns -1 for an error and 0 or 1 for success.
ipf_proxy_check()'s callers check for error and if the return code
is 0, they change it to 1 prior to returning to their callers. Simply
by returning -1 or 1 we reduce complexity and cycles burned changing
0 to 1.

(cherry picked from commit 874b1a35486b570513680c3d456b062ba097e1d9)