]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
2 years ago[skip ci] correct a few SPDX license tags
Alan Somers [Wed, 7 Jul 2021 19:52:20 +0000 (13:52 -0600)]
[skip ci] correct a few SPDX license tags

These were all incorrectly labeled as 2-clause BSD licenses by a
semi-automated process, when in fact they are 3-clause.

Discussed with: pfg, imp
Sponsored by: Axcient

(cherry picked from commit 3874c0abb0afaea6adc24ac96dc9dc5043f2b69e)

2 years agofusefs: correctly set lock owner during FUSE_SETLK
Alan Somers [Thu, 20 May 2021 01:10:15 +0000 (19:10 -0600)]
fusefs: correctly set lock owner during FUSE_SETLK

During FUSE_SETLK, the owner field should uniquely identify the calling
process.  The fusefs module now sets it to the process's pid.
Previously, it expected the calling process to set it directly, which
was wrong.

libfuse also apparently expects the owner field to be set during
FUSE_GETLK, though I'm not sure why.

PR: 256005
Reported by: Agata <chogata@moosefs.pro>
Reviewed by: pfg
Differential Revision: https://reviews.freebsd.org/D30622

(cherry picked from commit 18b19f8c6e04935a63a951afe0e540674bc94455)

2 years agofusefs: ensure that FUSE ops' headers' unique values are actually unique
Alan Somers [Fri, 18 Jun 2021 00:04:59 +0000 (18:04 -0600)]
fusefs: ensure that FUSE ops' headers' unique values are actually unique

Every FUSE operation has a unique value in its header.  As the name
implies, these values are supposed to be unique among all outstanding
operations.  And since FUSE_INTERRUPT is asynchronous and racy, it is
desirable that the unique values be unique among all operations that are
"close in time".

Ensure that they are actually unique by incrementing them whenever we
reuse a fuse_dispatcher object, for example during fsync, write, and
listextattr.

PR: 244686
Reviewed by: pfg
Differential Revision: https://reviews.freebsd.org/D30810

(cherry picked from commit 5403f2c163f7e3d1adb9431d216f88d57cf9d74b)

2 years agofusefs: delete some dead code
Alan Somers [Thu, 24 Dec 2020 19:21:00 +0000 (19:21 +0000)]
fusefs: delete some dead code

The original fusefs GSoC project seems to have envisioned exchanging two
types of messages with FUSE servers.  Perhaps vectored and non-vectored?
But in practice only one type has ever been used.  Delete the other type.

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

(cherry picked from commit 4f4111d2c5ab64591b9e15dab4257d8187458fd1)

2 years agofusefs: also debug INIT operations in the test suite
Alan Somers [Thu, 17 Jun 2021 22:06:43 +0000 (16:06 -0600)]
fusefs: also debug INIT operations in the test suite

Reviewed by: pfg

(cherry picked from commit 77b040c993ba9d4844e36f1f5b057066a5b4015a)

2 years agofusefs: delete dead code
Alan Somers [Fri, 18 Jun 2021 00:14:57 +0000 (18:14 -0600)]
fusefs: delete dead code

It was always dead, accidentally included in SVN r345876.

Reviewed by: pfg

(cherry picked from commit b97c7abc1a1cee72ef62109add860c1e8e618efd)

2 years agoSimplify fuse_device_filt_write
gAlfonso-bit [Wed, 16 Jun 2021 19:45:04 +0000 (15:45 -0400)]
Simplify fuse_device_filt_write

It always returns 1, so why bother having a variable.

Pull Request: https://github.com/freebsd/freebsd-src/pull/478

(cherry picked from commit 9b876fbd504e5c718d8d0275b32d806ab14558c8)

2 years agofusefs: support EVFILT_WRITE on /dev/fuse
Alan Somers [Tue, 15 Jun 2021 23:17:28 +0000 (17:17 -0600)]
fusefs: support EVFILT_WRITE on /dev/fuse

/dev/fuse is always ready for writing, so it's kind of dumb to poll it.
But some applications do it anyway.  Better to return ready than EINVAL.

Reviewed by: emaste, pfg
Differential Revision: https://reviews.freebsd.org/D30784

(cherry picked from commit 7b8622fa220b9c08041102f638f848c48e022644)

2 years agofusefs: improve warnings about buggy FUSE servers
Alan Somers [Tue, 15 Jun 2021 20:24:05 +0000 (14:24 -0600)]
fusefs: improve warnings about buggy FUSE servers

The fusefs driver will print warning messages about FUSE servers that
commit protocol violations.  Previously it would print those warnings on
every violation, but that could spam the console.  Now it will print
each warning no more than once per lifetime of the mount.  There is also
now a dtrace probe for each violation.

Sponsored by: Axcient
Reviewed by: emaste, pfg
Differential Revision: https://reviews.freebsd.org/D30780

(cherry picked from commit 0b9a5c6fa1733e600dcdb3b9df3b3d0ad5996920)

2 years agopf: clean up syncookie callout on vnet shutdown
Kristof Provost [Tue, 20 Jul 2021 19:03:08 +0000 (21:03 +0200)]
pf: clean up syncookie callout on vnet shutdown

Ensure that we cancel any outstanding callouts for syncookies when we
terminate the vnet.

MFC after: 1 week
Sponsored by: Modirum MDPay

(cherry picked from commit 32271c4d383effeac7878201ef5cbdfaeedc3755)

2 years agopf: remove stray debug line
Kristof Provost [Tue, 20 Jul 2021 19:02:33 +0000 (21:02 +0200)]
pf: remove stray debug line

MFC after: 1 week
Sponsored by: Modirum MDPay

(cherry picked from commit 84db87b8dafd9e9970fd36ac48c11ffdc89d31d0)

2 years agopf: fix LINT build
Kristof Provost [Tue, 20 Jul 2021 14:48:35 +0000 (16:48 +0200)]
pf: fix LINT build

We failed to list the new pf_syncookies.c file in sys/conf/files. This
worked for the usual configurations, where pf is a module, but not for
LINT builds.

Reported by: lwhsu
MFC after: 1 week
Sponsored by: Modirum MDPay

(cherry picked from commit b972a7fa9e1e01367435a5699b71cc7b5e494fee)

2 years agopf tests: ensure syncookie does not create state
Kristof Provost [Wed, 30 Jun 2021 13:27:46 +0000 (15:27 +0200)]
pf tests: ensure syncookie does not create state

Test that with syncookies enabled pf does not create state for
connections before the remote peer has replied to the SYN|ACK message.

MFC after: 1 week
Sponsored by: Modirum MDPay
Differential Revision: https://reviews.freebsd.org/D31142

(cherry picked from commit 27ab791a55191c0b6503391d411303b042b41047)

2 years agopf tests: Forwarding syncookie test
Kristof Provost [Wed, 2 Jun 2021 16:16:03 +0000 (18:16 +0200)]
pf tests: Forwarding syncookie test

Test syncookies on a forwarding host. That is, in a setup where the
machine (or vnet) running pf is not the same as the machine (or vnet)
running the server it's protecting.

MFC after: 1 week
Sponsored by: Modirum MDPay
Differential Revision: https://reviews.freebsd.org/D31141

(cherry picked from commit 3be9301a7e4fbd630cbde1bd3e1b59ac726e21af)

2 years agopfctl: syncookie configuration
Kristof Provost [Wed, 26 May 2021 11:41:34 +0000 (13:41 +0200)]
pfctl: syncookie configuration

pfctl and libpfctl code required to enable/disable the syncookie
feature.

MFC after: 1 week
Sponsored by: Modirum MDPay
Differential Revision: https://reviews.freebsd.org/D31140

(cherry picked from commit c69121c473d75abab55f9ade8e8138ac09c0942c)

2 years agopf: syncookie ioctl interface
Kristof Provost [Wed, 26 May 2021 08:18:19 +0000 (10:18 +0200)]
pf: syncookie ioctl interface

Kernel side implementation to allow switching between on and off modes,
and allow this configuration to be retrieved.

MFC after: 1 week
Sponsored by: Modirum MDPay
Differential Revision: https://reviews.freebsd.org/D31139

(cherry picked from commit 231e83d3422ff58fe94de8375a9532a1726056ed)

2 years agopf: syncookie support
Kristof Provost [Thu, 20 May 2021 09:54:41 +0000 (11:54 +0200)]
pf: syncookie support

Import OpenBSD's syncookie support for pf. This feature help pf resist
TCP SYN floods by only creating states once the remote host completes
the TCP handshake rather than when the initial SYN packet is received.

This is accomplished by using the initial sequence numbers to encode a
cookie (hence the name) in the SYN+ACK response and verifying this on
receipt of the client ACK.

Reviewed by: kbowling
Obtained from: OpenBSD
MFC after: 1 week
Sponsored by: Modirum MDPay
Differential Revision: https://reviews.freebsd.org/D31138

(cherry picked from commit 8e1864ed07121b479b95d7e3a5931a9e0ffd4713)

2 years agopf: factor out pf_synproxy()
Kristof Provost [Thu, 10 Jun 2021 13:49:09 +0000 (15:49 +0200)]
pf: factor out pf_synproxy()

MFC after: 1 week
Sponsored by: Modirum MDPay
Differential Revision: https://reviews.freebsd.org/D31137

(cherry picked from commit ee9c3d38039eb29966e1f0b8f617bc564c078289)

2 years agoRevert "loader: support.4th resets the read buffer incorrectly"
Warner Losh [Mon, 26 Jul 2021 22:40:41 +0000 (16:40 -0600)]
Revert "loader: support.4th resets the read buffer incorrectly"

This reverts commit 9c1c02093b90ae49745a174eb26ea85dd1990eec. It seems
to have broken all old nextboot.conf files causing hangs on boot.

PR: 239315
Sponsored by: Netflix

(cherry picked from commit 4783fb730fa1cfdbe5c905bb23ac74f681e2df6b)

2 years agopf: embed a pointer to the lock in struct pf_kstate
Mateusz Guzik [Mon, 19 Jul 2021 12:40:25 +0000 (14:40 +0200)]
pf: embed a pointer to the lock in struct pf_kstate

This shaves calculation which in particular helps on arm.

Note using the & hack instead would still be more work.

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

(cherry picked from commit 907257d6967dd23506e69042c55bb1edc983c0ba)

2 years agopf: shrink struct pf_kstate
Mateusz Guzik [Mon, 19 Jul 2021 12:35:31 +0000 (14:35 +0200)]
pf: shrink struct pf_kstate

Makes room for a pointer.

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

(cherry picked from commit 9009d36afd1e0107e1e5b6988f49436087b3d474)

2 years agopf: add a comment to pf_kstate concerning compat with pf_state_cmp
Mateusz Guzik [Mon, 19 Jul 2021 12:17:33 +0000 (14:17 +0200)]
pf: add a comment to pf_kstate concerning compat with pf_state_cmp

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

(cherry picked from commit f9aa757d8d1e1bfc7951f462e92f00639256cad6)

2 years agopf: add a branch prediction to expire state check in pf_find_state
Mateusz Guzik [Mon, 19 Jul 2021 12:50:08 +0000 (14:50 +0200)]
pf: add a branch prediction to expire state check in pf_find_state

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

(cherry picked from commit 144ec0713daa532342a298fd888a1656ae24a62d)

2 years agoarm: dedup counter(9) address calculation
Mateusz Guzik [Mon, 19 Jul 2021 10:46:01 +0000 (10:46 +0000)]
arm: dedup counter(9) address calculation

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

(cherry picked from commit 78e3a168616dbe3a2c96efe568c960a1344f42e9)

2 years agoAdd __diagused
Mateusz Guzik [Thu, 15 Jul 2021 14:01:02 +0000 (14:01 +0000)]
Add __diagused

This can be used for variables which are only used with either
INVARIANTS or WITNESS. Without any annotation they run into dead store
warnings from cc --analyze and always annotating with __unused may hide
bad vars when it should not.

Reviewed by: kib, markj
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D31185

(cherry picked from commit b9296725cf99696b48926270a553044522d6e344)

2 years agopf: Remove unused arguments from pf_send_tcp()
Kristof Provost [Wed, 19 May 2021 18:33:28 +0000 (20:33 +0200)]
pf: Remove unused arguments from pf_send_tcp()

struct mbuf *replyto is not actually used (and only rarely provided).
The same applies to struct ifnet *ifp.

No functional change.

Reviewed by: mjg
MFC after: 1 week
Sponsored by:   Modirum MDPay
Differential Revision: https://reviews.freebsd.org/D31136

(cherry picked from commit 295f2d939d960e2bdf5c1499da3eb41618be05e6)

2 years agonfssvc: Zero the buffer copied out when NFSSVC_DUMPMNTOPTS is set
Mark Johnston [Fri, 16 Jul 2021 02:39:27 +0000 (22:39 -0400)]
nfssvc: Zero the buffer copied out when NFSSVC_DUMPMNTOPTS is set

Reported by: KMSAN
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 7a9bc8a82ec20f9208643f1615ea4ca1d0e5d933)

2 years agodevd: remove pccard entries
Warner Losh [Thu, 15 Jul 2021 22:17:33 +0000 (16:17 -0600)]
devd: remove pccard entries

The pccard entries are now obsolete, remove them.

Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D31184

(cherry picked from commit a53541355645080cb6d94466f5363db0941da4fa)

2 years agonvme: Enable interrupts after qpair fully constructed
Warner Losh [Thu, 15 Jul 2021 22:17:23 +0000 (16:17 -0600)]
nvme: Enable interrupts after qpair fully constructed

To guard against the ill effects of a spurious interrupt during
construction (or one that was bogusly pending), enable interrupts after
the qpair is completely constructed. Otherwise, we can die with null
pointer dereferences in nvme_qpair_process_completions. This has been
observed in at least one pre-release NVMe drive where the MSIX interrupt
fired while the queue was being created, before we'd started the NVMe
controller card.

The alternative of only turning on the interrupts after the rest was
tried, but was insufficient to work around this bug and made the code
more complicated w/o benefit.

Reviewed by: mav, chuck
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D31182

(cherry picked from commit fc9a0840231770bc7e7dcfe4616babdc6d4389a6)

2 years agoboot: fix OBJS to not include BTX's crt0.o
Warner Losh [Thu, 6 May 2021 19:05:09 +0000 (13:05 -0600)]
boot: fix OBJS to not include BTX's crt0.o

According to comments in the Makefile, to make pxeboot work we need to
have crt0.o first. This is needed because the simplified loader in
pxeboot assumes that the startup code is at offset 0 in this binary. In
normal booting, the start address can be obtained from headers of the
binary, but since pxeboot encodes this as a pure binary, it has no way
of knowing where that is and assumes 0. Added comments to that effect
in the Makefile.

We've done this by adding it to OBJS before all the other .o's are
added. However, there's a problem. This also adds it to the CLEANFILES
variable, which causes it to be removed from multiple places. The
dependencies may also cause it to be re-built at a time that's after
boot2 is built. This causes installs to fail because at install time
boot2 is considered to be out of date and the programs to rebuild it are
no longer in the path.

Cope with this problem by just adding it to LDFLAGS instead.

Glanced at by: kevans ("I thought that went in ages ago")
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D28876

(cherry picked from commit e713d3a013882893fceb84dd14569052271497a9)

2 years agonanobsd: Bump rescue size to 8GB
Warner Losh [Thu, 15 Jul 2021 22:11:15 +0000 (16:11 -0600)]
nanobsd: Bump rescue size to 8GB

Bump the rescue size from 1.2GB to just shy of 8GB as things have grown
somewhat. Also make it possible to build rescue somewhere other than
/usr/src.

Sponsored by: Netflix

(cherry picked from commit 998abf5a1274609f9b74b3301dc0dabe659bd36b)

2 years agonanobsd: default to -j $hw.ncpu
Warner Losh [Thu, 15 Jul 2021 22:07:51 +0000 (16:07 -0600)]
nanobsd: default to -j $hw.ncpu

For paralllel builds, default to using all the CPUs on the system. The
old default of -j 3 was too few.

Sponsored by: Netflix

(cherry picked from commit 7e3a794be3752d21fe760cfb2a38665532c4b6b4)

2 years agonanobsd: Use gpart and create code image before full disk image
Arrigo Marchiori [Thu, 15 Jul 2021 22:06:51 +0000 (16:06 -0600)]
nanobsd: Use gpart and create code image before full disk image

The attached patch brings two main changes to the nanobsd script:
 1- gpart is used instead of fdisk;
 2- the code image is created first, and then used to ``assemble'' the
    full disk image.

The patch was first proposed on the freebsd-embedded list:
http://lists.freebsd.org/pipermail/freebsd-embedded/2012-June/001580.html
and is currently under discussion:
http://lists.freebsd.org/pipermail/freebsd-embedded/2014-January/002216.html

Another effect is that the -f option ("suppress code slice extraction")
now imples the -i option ("suppress disk image build").

imp@ applied Patch by hand to new legacy.sh, plus tweaked for NANO_LOG vs
NANO_OBJ confusion in original.

PR: 186030
Reviewed by: imp@
Differential Revision: https://reviews.freebsd.org/D31102

(cherry picked from commit 587c054bea0f652fdbd86baf5807f21c904ac2ad)

2 years agoloader: make sure CPUTYPE is ignored when building
Warner Losh [Thu, 15 Jul 2021 03:06:08 +0000 (21:06 -0600)]
loader: make sure CPUTYPE is ignored when building

CPUTYPE?=native causes -march=native to be added to the command
line. When the host machine is haswell, this causes some versions of
clang to generate code that can't execute in the efi boot loader
environment. Set _CPUCFLAGS= to undo what's done bsd.cpu.mk. bsd.cpu.mk
is included too early to control with NO_CPU_CFLAGS here. The only other
option is to put that in all the Makefiles, and this is less tedious and
error prone.

PR: 194641
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D31187
MFC After: 1 week

(cherry picked from commit 7a0c0ff7ee25ff1efa3dbedcb20d2c80178639cc)

2 years agoRemove incorrect __restricted labels from strcspn
Alfonso Gregory [Wed, 14 Jul 2021 21:48:35 +0000 (15:48 -0600)]
Remove incorrect __restricted labels from strcspn

strcspn should never have had the __restrict keywords. While both of
these strings are const, it may have unindended side effects. While this
is the kernel, the POSIX definition also omits restrict.

Reviewed by: imp@
Pull Request: https://github.com/freebsd/freebsd-src/pull/497

(cherry picked from commit 56d33e86b74b197a36f42255824b56715c96a596)

2 years agoFix pmbr issues > 2TB
Emrion [Tue, 13 Jul 2021 20:37:59 +0000 (14:37 -0600)]
Fix pmbr issues > 2TB

These issues have low impact because they require precise circumstances
to trigger one of them. The disk must be > 2 TiB in size and either:
- The primary GPT header is dammaged.
- The freebsd-boot partiton is located farther than the first 2 TiB of
  the disc and one of its sectors takes place at a lba value that makes
  the higher 32 bits of this very value change.
Errors and corrections folow:
- decl and incl don't affect CF, so replace with subl/addl $1
- repe uses %cx, so move size to it with movw
- moving a 64-bit value with %cx of 2 (should be 4) so addresses
  > 2TB will work.

PR: 233180
Reviewed by: imp@ (applied patch using description in bug)
Differential Revision: https://reviews.freebsd.org/D31100

(cherry picked from commit 0ca9f1d4a3b772036309fb1c14262ec77c674c5d)

2 years agocam_iosched: use tunable flag and make a bool really a bool
Warner Losh [Tue, 13 Jul 2021 06:00:33 +0000 (00:00 -0600)]
cam_iosched: use tunable flag and make a bool really a bool

kern.cam.do_dynamic_iosched is really a bool, so change its type to
bool. While I'm here, also use the CTLFLAG_TUN flag instead of a
separate tunable line for it and kern.cam.iosched_alpha_bits.

MFC After: 1 week
Sponsored by: Netflix

(cherry picked from commit a065ccb2804fae834a7c66e29b726ea3dbbceace)

2 years agoFix potential NULL pointer dereference of device physical path
Young Xiao [Tue, 21 May 2019 07:36:29 +0000 (15:36 +0800)]
Fix potential NULL pointer dereference of device physical path

In ata_dev_advinfo() and nvme_dev_advinfo(), if the physical path is
being stored and there is a malloc failure (malloc(9) is called with
M_NOWAIT), we could wind up in a situation where the device's
physpath_len is set to the length the user provided, but the physpath
itself is NULL.

If another context then comes in to fetch the physical path value, we
would wind up trying to memcpy a NULL pointer into the caller's buffer.

So, set the physpath_len to 0 when we free the physpath on entry into
the store case for the physical path.  Reset the length to a non-zero
value only after we've successfully malloced a buffer to hold it.

This code mirrors scsi_xpt.c does already as well.

Signed-off-by: Young Xiao <92siuyang@gmail.com>
Reviewed by: imp
PR: 238014

(cherry picked from commit 431ddd94360a9e86c91294eaa2c7b859911984b7)

2 years agoloader: support.4th resets the read buffer incorrectly
John Hood [Sun, 11 Jul 2021 14:44:12 +0000 (08:44 -0600)]
loader: support.4th resets the read buffer incorrectly

Large nextboot.conf files (over 80 bytes) are not read correctly by the
Forth loader, causing file parsing to abort, and nextboot configuration
fails to apply.

Simple repro:

nextboot -e foo=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
shutdown -r now

That will cause the bug to cause a parse failure but shouldn't otherwise
affect the boot.  Depending on your loader configuration, you may also
have to set beastie_disable and/or reduce the number of modules loaded
to see the error on a small console screen.  12.0 or CURRENT users will
also have to explicitly use the Forth loader instead of the Lua loader.
The error will look something like:

Warning: syntax error on file /boot/loader.conf.local
foo="xxxxxxxxxxxxxxnextboot_enable="YES"
                                    ^
/boot/support.4th has crude file I/O buffering, which uses a buffer
'read_buffer', defined to be 80 bytes by the 'read_buffer_size'
constant.  The loader first tastes nextboot.conf, reading and parsing
the first line in it for nextboot_enable="YES".  If this is true, then
it reopens the file and parses it like other loader .conf files.

Unfortunately, the file I/O buffering code does not fully reset the
buffer state in the reset_line_reading word.  If the last file was read
to the end, that doesn't matter; the file buffer is treated as empty
anyway.  But in the nextboot.conf case, the loader will not read to the
end of file if it is over 80 bytes, and the file buffer may be reused
when reading the next file.  When the file is reread, the corrupt text
may cause file parsing to abort on bad syntax (if the corrupt line has
<>2 quotes in it), the wrong variable to be set, no variable to be set
at all, or (if the splice happens to land at a line ending) something
approximating normal operation.

The bug is very old, dating back to at least 2000 if not before, and is
still present in 12.0 and CURRENT r345863 (though it is now hidden by
the Lua loader by default).

Suggested one-line attached.  This does change the behavior of the
reset_line_reading word, which is exported in the line-reading
dictionary (though the export is not documented in loader man pages).
But repo history shows it was probably exported for the PNP support
code, which was never included in the loader build, and was removed 5
months ago.

One thing that puzzles me: how has this bug gone unnoticed/unfixed for
nearly 2 decades?  I find it hard to believe that nobody's tried to do
something interesting with nextboot, like load a kernel and filesystem,
which is what I'm doing.

PR: 239315
Reviewed by: imp

(cherry picked from commit 9c1c02093b90ae49745a174eb26ea85dd1990eec)

2 years agomips: Implement basic pmap_kenter_device, pmap_kremove_device
Conrad Meyer [Thu, 16 May 2019 19:10:48 +0000 (19:10 +0000)]
mips: Implement basic pmap_kenter_device, pmap_kremove_device

Unbreak mips.BERI_DE4_SDROOT build, which uses device xdma. Device xdma
depends on the pmap_kenter_device APIs.

Reported by: tinderbox (local)
Sponsored by: Dell EMC Isilon

(cherry picked from commit fa3ac573a2f712393cebd195bf7331cff3d1b8fe)

2 years agoAdd 'gpio' since mmc now requires gpio_if.h.
John Baldwin [Thu, 16 Apr 2020 20:45:54 +0000 (20:45 +0000)]
Add 'gpio' since mmc now requires gpio_if.h.

(cherry picked from commit fdbb2410cb08214939b0b1570cc375f231abf63e)

2 years agoarm: add device syscon to TEGRA124
Mateusz Guzik [Wed, 21 Jul 2021 12:08:32 +0000 (12:08 +0000)]
arm: add device syscon to TEGRA124

Unbreaks the build.

This is a direct commit.

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

2 years agoarm: hide pc_mpidr behind #if __ARM_ARCH >= 6
Mateusz Guzik [Wed, 21 Jul 2021 12:06:34 +0000 (12:06 +0000)]
arm: hide pc_mpidr behind #if __ARM_ARCH >= 6

This is a direct commit.

Unbreaks the build of:
DB-78XXX
DB-88F5XXX
DB-88F6XXX
RT1310
LINT-V5
TS7800

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

2 years agoarm: add atomic_store_rel_64
Mateusz Guzik [Wed, 21 Jul 2021 12:05:38 +0000 (12:05 +0000)]
arm: add atomic_store_rel_64

This unbreaks building linux compat in tinderbox.

This is a direct commit.

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

2 years agoPartially revert previous commit.
Alexander Motin [Wed, 14 Jul 2021 19:46:22 +0000 (15:46 -0400)]
Partially revert previous commit.

ns identify does not allow nsid of 0xffffffff.  Only general identify
allows it.

MFC after: 1 week

(cherry picked from commit d1a0eab9fbc426ed8cbbddcd90720180c44ce36b)

2 years agoFor ns identify/delete allow nsid of 0xffffffff.
Alexander Motin [Wed, 14 Jul 2021 18:56:34 +0000 (14:56 -0400)]
For ns identify/delete allow nsid of 0xffffffff.

The first should report common parameters, the second should delete
all namespaces.

MFC after: 1 week

(cherry picked from commit dbf1dce8d6d2d0eedac5402c1f137a80805179ca)

2 years agoFilter out LBA formats with LBA Data Size of 0.
Alexander Motin [Wed, 14 Jul 2021 18:01:22 +0000 (14:01 -0400)]
Filter out LBA formats with LBA Data Size of 0.

According to the spec: "If the value reported is 0h, then LBA format
is not supported / used or is not currently available".

MFC after: 1 week

(cherry picked from commit d379886a4170fa3d95a5354612a5e2c15b104841)

2 years agoFix local-unbound setup for some IPv6 deployments.
Dag-Erling Smørgrav [Wed, 10 Mar 2021 14:01:38 +0000 (14:01 +0000)]
Fix local-unbound setup for some IPv6 deployments.

PR: 250984
MFC after: 1 week

2 years agotcpdump: decode packets on pfsync interfaces
Luiz Otavio O Souza [Mon, 12 Jul 2021 17:15:15 +0000 (19:15 +0200)]
tcpdump: decode packets on pfsync interfaces

Reviewed by: kp, scottl
Obtained from: pfsense
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D31153

(cherry picked from commit 3f240bdf3652ea823af34b0f399e2c8be5a6320a)

2 years agoarm: replace byte-by-byte memcmp with an already existing asm variant
Mateusz Guzik [Mon, 19 Jul 2021 09:58:15 +0000 (09:58 +0000)]
arm: replace byte-by-byte memcmp with an already existing asm variant

So happens bcmp as found in support.S is in fact renamed memcmp, add
memcmp back as a symbol.

This is a direct commit to keep the old symbol around, see
9ef5b65085ed2acd ("arm: bcmp -> memcmp") in main for reference.

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

2 years agortwn: make sure to not write in upper bits of txdseq
Andriy Gapon [Mon, 21 Jun 2021 08:05:04 +0000 (11:05 +0300)]
rtwn: make sure to not write in upper bits of txdseq

ni_txseqs is kept as 16-bit counter, but we need to trim the upper four
bits as they may have special meanings for the firmware / hardware.
For instance, bit 15 enables hardware / firmware generation of sequence
numbers that overrides sequence numbers programmed by the driver.

Reviewed by: adrian

(cherry picked from commit 7544c1d20d8b7127ed3511edeb94e01d328daebb)

2 years agopmc(3): mandoc clean ups
Gordon Bergling [Mon, 12 Jul 2021 04:28:03 +0000 (06:28 +0200)]
pmc(3): mandoc clean ups

- new sentence, new line
- tab in filled text
- unusual Xr order
- skipping paragraph macro: Pp before Ss

Reviewed by: bcr
Differential Revision: https://reviews.freebsd.org/D31143

(cherry picked from commit 0b1293252543802b809b5f13f554e5d6391d3445)

2 years agoprocctl(PROC_ASLR_STATUS): fix vmspace leak
Konstantin Belousov [Wed, 14 Jul 2021 23:40:04 +0000 (02:40 +0300)]
procctl(PROC_ASLR_STATUS): fix vmspace leak

(cherry picked from commit 0bdb2cbf9d7c4366a0668b4563c8630538a50086)

2 years agodevmatch: don't announce autoloading so much
Warner Losh [Thu, 8 Jul 2021 19:53:18 +0000 (13:53 -0600)]
devmatch: don't announce autoloading so much

devmatch rc script would announce it was loading a module multiple
times. It used kldload -n so it really wasn't loading it that many
times, but the message is confusing. Use kldstat to see if we need to
load the module before saying we do. This fixes the vast majority of the
problems. It may be possible to race devmatch with a user invocation and
devd, though quite hard. In that case we'll announce things twice, but
still only load it once. No attempt is made to fix this.

PR: 232782
MFC After: 2 weeks
Sponsored by: Netflix

2 years agodevmatch: Be tolerant of .ko being present.
Warner Losh [Thu, 8 Jul 2021 19:44:21 +0000 (13:44 -0600)]
devmatch: Be tolerant of .ko being present.

We document that we did not need .ko on the module names in
devmatch_blocklist, but we really needed them. Keep the documentation
the same, but strip the .ko when we need to use the names so you can
specify either.

PR: 256240
MFC After: 2 weeks
Sponsored by: Netflix

2 years agodevmatch: defer until after kld
Helge Oldach [Wed, 7 Jul 2021 20:43:35 +0000 (14:43 -0600)]
devmatch: defer until after kld

devmatch loads a number of things automatically. Allow the list of
things to load to happen first in case those drivers affect what would
be loaded. Normally, this will produce the same results, but there's
some special cases that may not when drivers are loaded that report
other drivers missing, like virtio_pci.

PR: 253287
Reviewed by: imp
MFC After: 2 weeks

2 years agodevmatch: improve naming of devmatch config variable
Ceri Davies [Fri, 18 Jun 2021 12:17:30 +0000 (13:17 +0100)]
devmatch: improve naming of devmatch config variable

Accept the old rc.conf variable if the new one is not present for
compatability.

Approved by: imp
Differential Revision: https://reviews.freebsd.org/D30806

2 years agoconfig_intrhook: provide config_intrhook_drain
Warner Losh [Thu, 11 Mar 2021 15:42:09 +0000 (08:42 -0700)]
config_intrhook: provide config_intrhook_drain

config_intrhook_drain will remove the hook from the list as
config_intrhook_disestablish does if the hook hasn't been called.  If it has,
config_intrhook_drain will wait for the hook to be disestablished in the normal
course (or expedited, it's up to the driver to decide how and when
to call config_intrhook_disestablish).

This is intended for removable devices that use config_intrhook and might be
attached early in boot, but that may be removed before the kernel can call the
config_intrhook or before it ends. To prevent all races, the detach routine will
need to call config_intrhook_train.

Sponsored by: Netflix, Inc
Reviewed by: jhb, mav, gde (in D29006 for man page)
Differential Revision: https://reviews.freebsd.org/D29005

(cherry picked from commit e52368365db3c0a696b37bfc09d08b7093b41b57)

2 years agosbuf(9): Add NOWAIT dynamic buffer extension mode
Conrad Meyer [Wed, 7 Aug 2019 19:23:07 +0000 (19:23 +0000)]
sbuf(9): Add NOWAIT dynamic buffer extension mode

The goal is to avoid some kinds of low-memory deadlock when formatting
heap-allocated buffers.

Reviewed by: vangyzen
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D21015

(cherry picked from commit 71db411eb627601a5f9a3464f88d75741927ce60)

2 years agopf: bound DIOCGETSTATESV2 memory use
Kristof Provost [Thu, 8 Jul 2021 13:01:19 +0000 (15:01 +0200)]
pf: bound DIOCGETSTATESV2 memory use

Rather than allocating however much memory userspace asks for we only
allocate enough for a handful of states, and copy to userspace for each
completed row.
We start out with enough space for 16 states (per row), but grow that as
required. In most configurations we expect at most a handful of states
per row (more than that would have other negative effects on packet
processing performance).

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

(cherry picked from commit 3fc12ae042040192aa43984106a75663aaa9e0f5)

2 years agolibpfctl: migrate to DIOCGETSTATESV2
Kristof Provost [Tue, 6 Jul 2021 11:05:19 +0000 (13:05 +0200)]
libpfctl: migrate to DIOCGETSTATESV2

Stop using the *NV version to retrieve states, as its performance is
unacceptably bad.

For 1,000,000 states the nvlist version needed ~100 seconds to retrieve
the states, the new version needs ~3 seconds.

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

(cherry picked from commit be70c7a50d324dd56f3a0d37d8372e7855dd580b)

2 years agopf: add DIOCGETSTATESV2
Kristof Provost [Tue, 6 Jul 2021 10:12:12 +0000 (12:12 +0200)]
pf: add DIOCGETSTATESV2

Add a new version of the DIOCGETSTATES call, which extends the struct to
include the original interface information.

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

(cherry picked from commit c6bf20a2a46dc36bf881ac594454f71379828a9a)

2 years agodummynet: reduce console spam
Luiz Otavio O Souza [Thu, 11 Feb 2016 13:35:01 +0000 (07:35 -0600)]
dummynet: reduce console spam

Only print this warning when boot verbose is enabled.
This can get pretty annoying (and useless) in some systems.

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

(cherry picked from commit c5dd8bac0b96e11da02181bd1dbee677e270842d)

2 years agopf: pf_killstates() never fails, so remove the return value
Kristof Provost [Thu, 8 Jul 2021 08:54:16 +0000 (10:54 +0200)]
pf: pf_killstates() never fails, so remove the return value

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

(cherry picked from commit 34641052826c718566b994b75cd2bddb53a21583)

2 years agopf: Handle errors returned by pf_killstates()
Kristof Provost [Mon, 5 Jul 2021 12:21:03 +0000 (14:21 +0200)]
pf: Handle errors returned by pf_killstates()

Happily this wasn't a real bug, because pf_killstates() never fails, but
we should check the return value anyway, in case it does ever start
returning errors.

Reported by: clang --analyze
MFC after: 1 week
Sponsored by: Rubicon Communications, LLC ("Netgate")

(cherry picked from commit fa96701c8abbc29aad7f8f8d6b823bd7f89c6c15)

2 years agopf: Remove unneeded NULL check
Kristof Provost [Mon, 5 Jul 2021 12:02:06 +0000 (14:02 +0200)]
pf: Remove unneeded NULL check

pidx is never NULL, and is used unconditionally later on in the
function.
Add an assertion, as documentation for the requirement to provide an idx
pointer.

Reported by: clang --analyze
MFC after: 1 week
Sponsored by: Rubicon Communications, LLC ("Netgate")

(cherry picked from commit 8cceacc0f1ee6a77c5f0566b8e6b0f054160fb20)

2 years agorc.d: connect sysctl_lastload
Eugene Grosbein [Thu, 20 May 2021 04:51:31 +0000 (11:51 +0700)]
rc.d: connect sysctl_lastload

Add recently added sysctl_lastload.

(cherry picked from commit 20eb969793921dce9e524d19fc02b84cabd98f74)

2 years agoipfw: reload sysctl.conf variables if needed
Eugene Grosbein [Mon, 17 May 2021 21:03:15 +0000 (04:03 +0700)]
ipfw: reload sysctl.conf variables if needed

Currently ipfw has multiple components that are not parts
of GENERIC kernel like dummynet etc. They can bring in important
sysctls if enabled with rc.conf(5) and loaded with ipfw startup script
by means of "required_modules" after initial consult
with /etc/sysctl.conf at boot time. Here is an example of one
increasing limit for dummynet hold queues that defaults to 100:

net.inet.ip.dummynet.pipe_slot_limit=1000

This makes it possible to use ipfw/dummynet rules such as:

ipfw pipe 1 config bw 50Mbit/s queue 1000

Such rule is rejected unless above sysctl is applied.
Another example is a group of net.inet.ip.alias.* sysctls
created after libalias.ko loaded as dependency of ipfw_nat.

This is not a problem if corresponding code compiled in custom kernel
so sysctls exist when sysctl.conf is read early or kernel modules
loaded with a loader. This change makes it work also for GENERIC
and modules loaded by means of rc.conf(5) settings.

(cherry picked from commit f5b5de1a3210234f3a6864c88a2d3e11ac2dbf04)

2 years agorc.d: unbreak sysctl lastload
Eugene Grosbein [Wed, 19 May 2021 13:02:31 +0000 (20:02 +0700)]
rc.d: unbreak sysctl lastload

/etc/rc.d/securelevel is supposed to run /etc/rc.d/sysctl lastload
late at boot time to apply /etc/sysctl.conf settings that fail
to apply early. However, this does not work in default configuration
because of kern_securelevel_enable="NO" by default.

Add new script /etc/rc.d/sysctl_lastload that starts unconditionally.

Reported by: Marek Zarychta
MFC after: 1 month

(cherry picked from commit f4b38c360e63a6e66245efedbd6c070f9c0aee55)

2 years agoUPDATING: Not unusual side effect of the awk bug fixed in 40a925385fa6b
Warner Losh [Fri, 16 Jul 2021 04:05:31 +0000 (22:05 -0600)]
UPDATING: Not unusual side effect of the awk bug fixed in 40a925385fa6b

You might not be able to build the kernel if you have an awk between Jul
10th and today. In stable/12, more (all) platforms than -current or
stable/13 have the first offset of the thread structure in the 0xfxx
range, which triggers this problem. If you've updated awk, you'll likely
need to follow the instructions here to install a fixed version before
you'll be able to build a kernel.

Sponsored by: Netflix

2 years agoSkip netgraph tests when WITHOUT_NETGRAPH is set
Ed Maste [Tue, 6 Jul 2021 13:44:15 +0000 (09:44 -0400)]
Skip netgraph tests when WITHOUT_NETGRAPH is set

PR: 256986
Reported by: John Marshall
MFC after: 1 week
Sponsored by: The FreeBSD Foundation

(cherry picked from commit c9144ec14d2a5a53cfe91ada1b3b9c06b78dc999)

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)