]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
3 years agolink_elf_obj: Handle init_array sections in KLDs
Mark Johnston [Thu, 4 Mar 2021 15:02:47 +0000 (10:02 -0500)]
link_elf_obj: Handle init_array sections in KLDs

Reuse existing handling for .ctors, print a warning if multiple
constructor sections are present.   Destructors are not handled as of
yet.

This is required for KASAN.

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

(cherry picked from commit 5e6989ba4f26acafc77baa6055c0a9e7fe683514)

3 years agogmirror: Pre-allocate the timeout event structure
Mark Johnston [Thu, 11 Mar 2021 20:43:04 +0000 (15:43 -0500)]
gmirror: Pre-allocate the timeout event structure

We can't call malloc(M_WAITOK) in a callout handler.

Reviewed by: imp
Reported by: pho
Tested by: pho
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D29223

(cherry picked from commit 2f1cfb7f63ca744e7a143896347bdc8606c291d6)

3 years agosbin/ifconfig: Use a global libifconfig handle
Ryan Moeller [Sun, 28 Feb 2021 10:30:09 +0000 (10:30 +0000)]
sbin/ifconfig: Use a global libifconfig handle

This should eventually replace the socket passed to the various
handlers. In the meantime, making it global avoids repeatedly opening
and closing handles.

Reported by: kp
Reviewed by: kp (earlier version)
Differential Revision: https://reviews.freebsd.org/D28990

(cherry picked from commit 8b22242550c98d0a59b6589f2be0beb1dc2eac13)

3 years agotests/sys/netgraph/ng_macfilter_test: Fix invalid TAP output
Alex Richardson [Fri, 12 Mar 2021 17:35:24 +0000 (17:35 +0000)]
tests/sys/netgraph/ng_macfilter_test: Fix invalid TAP output

This should allow the test to pass in Jenkins. Testing it locally now
reports "passed" instead of "invalid TAP data".

While touching this file also fix some shellcheck warnings that were
pointed out by my IDE.

Reviewed By: lwhsu, afedorov
Differential Revision: https://reviews.freebsd.org/D29054

(cherry picked from commit 65f4ff4e68afc3867781dfc8cd4faf2a8be1c74f)

3 years agocapsicum-test: Update for O_BENEATH removal
Alex Richardson [Fri, 12 Mar 2021 17:12:10 +0000 (17:12 +0000)]
capsicum-test: Update for O_BENEATH removal

Update the tests to check O_RESOLVE_BENEATH instead.
If this looks reasonable, I'll try to upstream this change.
This keeps a compat fallback for O_BENEATH since the Linux port still
has/had O_BENEATH with "no .., no absolute paths" semantics.

Test Plan: `/usr/tests/sys/capsicum/capsicum-test -u 977` passes and
runs the O_RESOLVE_BENEATH tests.
Reviewed By: markj
Differential Revision: https://reviews.freebsd.org/D29016

(cherry picked from commit 8cf5812af4b7f4933983822ff8e1e9185818fbef)

3 years agotests/sys/cddl: correctly quote atf_set "require.progs"
Alex Richardson [Mon, 8 Mar 2021 09:38:24 +0000 (09:38 +0000)]
tests/sys/cddl: correctly quote atf_set "require.progs"

The argument has to be a single whitespace-separate value. While touching
all these lines also add ksh93, since `atf_set "require.progs"` overrides
the default value specified in the Kyuafile. This then results in tests
being executed despite ksh93 not being installed.

Reviewed By: asomers
Differential Revision: https://reviews.freebsd.org/D29066

(cherry picked from commit 0b86424c31ece31190c94d55feb5d190be4de5df)

3 years agoRemove unnecessary semicolon from CRITICAL_ASSERT()
Alex Richardson [Thu, 4 Mar 2021 15:06:32 +0000 (15:06 +0000)]
Remove unnecessary semicolon from CRITICAL_ASSERT()

This fixes off-by-default "empty statement" compiler warnings.

(cherry picked from commit b2c8cbf992cb0b51118beae9c304580705ae00c9)

3 years agoFix capsicum-test build with GCC
Alex Richardson [Wed, 3 Mar 2021 13:53:30 +0000 (13:53 +0000)]
Fix capsicum-test build with GCC

Apparently GCC defines NULL to 0 in C++11 mode (instead of nullptr), so
this causes the following error:
```
In file included from capsicum-test.h:15,
                 from capsicum-test.cc:1:
gtest-1.10.0/include/gtest/gtest.h: In instantiation of 'testing::AssertionResult testing::internal::CmpHelperNE(const char*, const char*, const T1&, const T2&) [with T1 = long int; T2 = procstat*]':
capsicum-test.cc:75:3:   required from here
gtest-1.10.0/include/gtest/gtest.h:1621:28: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
 1609 |   if (val1 op val2) {\
      |       ~~~~~~~~~~~~
......
 1621 | GTEST_IMPL_CMP_HELPER_(NE, !=);
gtest-1.10.0/include/gtest/gtest.h:1609:12: note: in definition of macro 'GTEST_IMPL_CMP_HELPER_'
 1609 |   if (val1 op val2) {\
      |            ^~
```

Fix this by using nullptr directly.

Submitted upstream as https://github.com/google/capsicum-test/pull/56

Reported by: Jenkins CI

(cherry picked from commit 47ceb65f3c213904642f4859a53a3139e9cb287d)

3 years agoSimplify the capsicum-test wrapper script
Alex Richardson [Tue, 2 Mar 2021 18:27:34 +0000 (18:27 +0000)]
Simplify the capsicum-test wrapper script

Instead of running tests one-by-one with the shell wrapper we now run
the full gtest testsuite twice (once as root, once as non root). This
significantly speeds up running tests despite running them twice.
This change also passes the missing -u flag to capsicum-test that caused
test failures (https://bugs.freebsd.org/250178)

Previously, running the testsuite with the wrapper script took ~3s per
test on aarch64 QEMU, i.e. a total of almost 5 minutes.
Now it takes 6 seconds to run all tests twice.

Before:
root@freebsd-aarch64:/usr/tests/sys/capsicum # /usr/bin/time kyua test functional
94/96 passed (2 failed)
      309.97 real        58.46 user       244.31 sys

After:
root@freebsd-aarch64:/usr/tests/sys/capsicum # /usr/bin/time kyua test functional
functional:test_root  ->  passed  [2.659s]
functional:test_unprivileged  ->  passed  [2.391s]
2/2 passed (0 failed)
        5.48 real         1.06 user         2.52 sys

This overhead is caused by kyua + atf-sh spawning lots of additional
processes and can be avoided by just running the googletest test binary.
syscall                     seconds   calls  errors
fork                   39.810229456    1275       0
sigprocmask            13.546928736     572       0

i.e. 1275 processes spawned to run a single test.

Test Plan: All tests pass with D28907.
PR: 250178
Reviewed By: lwhsu
Differential Revision: https://reviews.freebsd.org/D29014

(cherry picked from commit 53a535c1d80a2e5ea33a4e8807647e600402b1d8)

3 years agoUpdate capsicum-test to git commit f4d97414d48b8f8356b971ab9f45dc5c70d53c40
Alex Richardson [Tue, 2 Mar 2021 16:28:26 +0000 (16:28 +0000)]
Update capsicum-test to git commit f4d97414d48b8f8356b971ab9f45dc5c70d53c40

This includes various fixes that I submitted recently such as updating the
pdkill() tests for the actual implemented behaviour
(https://github.com/google/capsicum-test/pull/53) and lots of changes to
avoid calling sleep() and replacing it with reliable synchronization
(pull requests 49,51,52,53,54). This should make the testsuite more reliable
when running on Jenkins. Additionally, process status is now retrieved using
libprocstat instead of running `ps` and parsing the output
(https://github.com/google/capsicum-test/pull/50). This fixes one previously
failing test and speeds up execution.

Overall, this update reduces the total runtime from ~60s to about 4-5 seconds.

(cherry picked from commit 955a3f9ad586f38395e66127f9f2f4afbf3d5a94)

3 years agoUpdate capsicum-test to git commit 7707222b46abe52d18fd4fbb76115ffdb3e6f74b
Alex Richardson [Tue, 16 Feb 2021 14:35:12 +0000 (14:35 +0000)]
Update capsicum-test to git commit 7707222b46abe52d18fd4fbb76115ffdb3e6f74b

This includes changes to use GTEST_SKIP() instead of the local hand-rolled
mechanism as well as a few minor cleanups.

(cherry picked from commit 2d936e6c99ad1c4fb01f6c99a96dcc924ee44b9d)

3 years agotests/sys/netgraph: Tell kyua that perl is required
Alex Richardson [Tue, 23 Feb 2021 17:02:31 +0000 (17:02 +0000)]
tests/sys/netgraph: Tell kyua that perl is required

Otherwise these tests fail with incomprehensible error messages.

Reviewed By: kp
Differential Revision: https://reviews.freebsd.org/D28894

(cherry picked from commit 3775ddcf5a12c8e23970e94b7b165bf23c92aeba)

3 years agotests/sys/netpfil/pf: Add missing python3 requirements
Alex Richardson [Tue, 23 Feb 2021 19:04:01 +0000 (19:04 +0000)]
tests/sys/netpfil/pf: Add missing python3 requirements

This also fixes a typo in the dup test that caused the head function to
not be called. On my test system without python3 the tests are now
skipped instead of failing.

Reviewed By: kp
Differential Revision: https://reviews.freebsd.org/D28903

(cherry picked from commit 98202829d1b3727a8706f45d052fc9e9507b562b)

3 years agoSilence a macro-redefined warning when crossbuilding
Alex Richardson [Mon, 1 Mar 2021 14:11:20 +0000 (14:11 +0000)]
Silence a macro-redefined warning when crossbuilding

This is already defined by the ncurses headers, so just undef it before
defining it again.

(cherry picked from commit 10f2a0c2e8766e9878ad4181f555d8dda84da34e)

3 years agotests/sys/audit: add missing comma delimiter between fields
Alex Richardson [Tue, 2 Mar 2021 18:34:42 +0000 (18:34 +0000)]
tests/sys/audit: add missing comma delimiter between fields

This makes the `kyua report --verbose` output a lot easier to parse when
looking at failed tests. It also fixes the closefrom() test since I
tested my changes with this commit but forgot to push it together with
fa32350347b4e351a144b5423f0fb2ca9d67f4ca.

Fixes: fa32350347b4 ("close_range: add audit support")
(cherry picked from commit c97304110a02f9c41b515e7b94d53229ab8f61af)

3 years agoclose_range: add audit support
Alex Richardson [Tue, 23 Feb 2021 17:47:07 +0000 (17:47 +0000)]
close_range: add audit support

This fixes the closefrom test in sys/audit.

Includes cherry-picks of the following commits from openbsm:

https://github.com/openbsm/openbsm/commit/4dfc628aafe589d68848f7033f3d3488c4d979e0
https://github.com/openbsm/openbsm/commit/99ff6fe32aebc5a4b8d40d60062b8574697df557
https://github.com/openbsm/openbsm/commit/da48a0399e95448693d3fa2be48454ca564c1be8

Reviewed By: kevans
Differential Revision: https://reviews.freebsd.org/D28388

(cherry picked from commit fa32350347b4e351a144b5423f0fb2ca9d67f4ca)

3 years agotests/sys/audit: Avoid race caused by starting auditd(8) for testing
Alex Richardson [Thu, 18 Feb 2021 10:14:27 +0000 (10:14 +0000)]
tests/sys/audit: Avoid race caused by starting auditd(8) for testing

In the CheriBSD CI we reproducibly see the first test in sys/audit
(administrative:acct_failure) fail due to a missing startup message.
It appears this is caused by a race condition when starting auditd:
`service auditd onestart` returns as soon as the initial auditd() parent
exits (after the daemon(3) call).
We can avoid this problem by setting up the auditd infrastructure
in-process: libauditd contains audit_quick_{start,stop}() functions that
look like they are ideally suited to this task.
This patch also avoids forking lots of shell processes for each of the 418
tests by using `auditon(A_SENDTRIGGER, &trigger, sizeof(trigger))` to check
for a running auditd(8) instead of using `service auditd onestatus`.

With these two changes (and D28388 to fix the XFAIL'd test) I can now
boot and run `cd /usr/tests/sys/audit && kyua test` without any failures
in a single-core QEMU instance. Before there would always be at least one
failed test.

Besides making the tests more reliable in CI, a nice side-effect of this
change is that it also significantly speeds up running them by avoiding
lots of fork()/execve() caused by shell scripts:
Running kyua test on an AArch64 QEMU took 315s before and now takes 68s,
so it's roughly 3.5 times faster. This effect is even larger when running
on a CHERI-RISC-V QEMU since emulating CHERI instructions on an x86 host
is noticeably slower than emulating AArch64.

Test Plan: aarch64+amd64 QEMU no longer fail.

Reviewed By: asomers
Differential Revision: https://reviews.freebsd.org/D28451

(cherry picked from commit df093aa9463b2121d8307fb91c4ba7cf17f4ea64)

3 years agofix panic when rescue retransmission and FIN overlap
Richard Scheffenegger [Wed, 17 Mar 2021 15:44:29 +0000 (16:44 +0100)]
fix panic when rescue retransmission and FIN overlap

PR:           254244
PR:           254309
Reviewed By:  #transport, hselasky, tuexen
Approved by:  re (cperciva)
MFC after:    immediately
Sponsored By: NetApp, Inc.
Differential Revision: https://reviews.freebsd.org/D29315

(cherry picked from commit e9f029831fa5747ae1b405f5716c52cb4ebf1e04)

3 years agoFix GCC build of ptrace_test after 96a9e50e63bfc
Alex Richardson [Wed, 3 Mar 2021 11:21:04 +0000 (11:21 +0000)]
Fix GCC build of ptrace_test after 96a9e50e63bfc

It seems like GCC's -Wsign-compare is stricter and also warns for
constants. Appease GCC by adding the required casts.

Fixes: 96a9e50e63bfc ("ptrace_test: Add more debug output on test failures")
Reported by: Jenkins CI

(cherry picked from commit 1fcbddec14dd693acf6a4be579f8d9e10b6a06a4)

3 years agoFix ptrace_test:ptrace__syscall_args after ATF upgrade
Alex Richardson [Tue, 23 Feb 2021 12:51:35 +0000 (12:51 +0000)]
Fix ptrace_test:ptrace__syscall_args after ATF upgrade

ATF now opens the results file (without CLOEXEC), so the child actually
has a valid file descriptor 3. To fix this simply use a large number that
will definitely not be a valid file descriptor.

Reviewed by: jhb, cem, lwhsu
Differential Revision: https://reviews.freebsd.org/D28889

(cherry picked from commit 17cc20092cd7a45adb6d772e0f449617007a82d9)

3 years agoRemove atf_tc_skip calls from ptrace_test
Alex Richardson [Mon, 1 Mar 2021 18:51:02 +0000 (18:51 +0000)]
Remove atf_tc_skip calls from ptrace_test

I've run these tests many times in a loop on multiple architectures and
it works reliably for me, maybe it's time to retire these skips?
This also adds an additional waitpid to one of the tests to avoid
a potential race condition (suggested by markj@).

PR: 239397, 244056, 239425, 240510, 220841, 243605
Reviewed By: markj
Differential Revision: https://reviews.freebsd.org/D28888

(cherry picked from commit 1032131464f1196ad674b30c14a9e611789a1061)

3 years agoptrace_test: Add more debug output on test failures
Alex Richardson [Mon, 1 Mar 2021 18:49:31 +0000 (18:49 +0000)]
ptrace_test: Add more debug output on test failures

Mostly automatic, using
`CHILD_REQUIRE\(([^|&\n]*) ==` -> `CHILD_REQUIRE_EQ_INT($1,`
`ATF_REQUIRE\(([^|&\n]*) ==` -> `REQUIRE_EQ_INT($1,` followed by
git-clang-format -f and then manually checking ones that contain ||/&&.

Test Plan:
Still getting the same failure but now it prints
`psr.sr_error (0) == EBADF (9) not met` instead of just failing
without printing the values.

PR: 243605
Reviewed By: jhb
Differential Revision: https://reviews.freebsd.org/D28887

(cherry picked from commit 96a9e50e63bfcbca7309c012c2c7a477c8826824)

3 years agoatf: Fix ATF_BUILD_* values when not using the bootstrap compiler
Alex Richardson [Wed, 3 Feb 2021 09:32:16 +0000 (09:32 +0000)]
atf: Fix ATF_BUILD_* values when not using the bootstrap compiler

Currently, we encode the full path and compile flags for the build
compiler in libatf. However, these values are not correct when
cross-compiling: For example, when I build on macOS, CC is set to the
host path /usr/local/Cellar/llvm/11.0.0_1/bin/clang-11. This path will
not exist on the target system.
Simplify this logic and use cc/cpp/c++ since those binaries will exist
on the target system unless the compiler was explicitly disabled.
I'm not convinced ATF needs to encode these values, but this is a
minimal fix for these tests when using a non-bootstrapped compiler.

Reviewed By: ngie, brooks
Differential Revision: https://reviews.freebsd.org/D28414

(cherry picked from commit 9b131f1e51a00c8bbbda32672fb5db88010400f6)

3 years agolibc: Fix t_spawn_fileactions test after ATF update
Alex Richardson [Thu, 18 Feb 2021 10:07:51 +0000 (10:07 +0000)]
libc: Fix t_spawn_fileactions test after ATF update

Since https://github.com/freebsd/atf/commit/4581cefc1e3811dd3c926b5dd4b15fd63d2e19da
ATF opens the results file on startup. This fixes problems like
capsicumized tests not being able to open the file on exit.

However, this test closes all file descriptors above 3 to get a
deterministic fd table allocation for the child. Instead of using closefrom
(which will close the ATF output file FD) I've changed this test use
the lowest available fd and pass that to the helper program as a string.

We could also try to re-open the results file in ATF if we get a EBADF
error, but that will fail when running under Capsicum.

Reviewed By: cem
Differential Revision: https://reviews.freebsd.org/D28684

(cherry picked from commit 2aa3ef285a23d802f0bd6c7281612e16834e9b68)

3 years agoFix two failing tests after ATF update
Alex Richardson [Mon, 15 Feb 2021 22:11:30 +0000 (22:11 +0000)]
Fix two failing tests after ATF update

Since https://github.com/freebsd/atf/commit/4581cefc1e3811dd3c926b5dd4b15fd63d2e19da
ATF opens the results file on startup. This fixes problems like
capsicumized tests not being able to open the file on exit.

However, this test closes all file descriptors just to check that
socketpair returns fd 3+4 and thereby also closes the ATF results file.
This then results in an EBADF when writing the result so the test is
reported as broken.

While system calls that create new file descriptors (must?) use the lowest
available file descriptor number, it does not seem useful to test this
property here. Drop the check for FD==3/4 to unbreak the testsuite.

We could also try to re-open the results file in ATF if we get a EBADF
error, but that will fail when running under Capsicum.

Reviewed By: cem
Differential Revision: https://reviews.freebsd.org/D28683

(cherry picked from commit 10fc4c3218381fef7189a5b8d46a757cd1989dff)

3 years agotests/sys/vfs/lookup_cap_dotdot: No longer aborts after ATF update
Alex Richardson [Thu, 4 Feb 2021 17:48:29 +0000 (17:48 +0000)]
tests/sys/vfs/lookup_cap_dotdot: No longer aborts after ATF update

It appears this test no longer fails after c203bd70b5957f85616424b6fa374479372d06e3.

PR: 215690
(cherry picked from commit 1eec5861d52e074bc20d08aef051af59cc70040e)

3 years agoImport atf 0.22 snapshot ca73d08c3fc1ecffc1f1c97458c31ab82c12bb01
Alex Richardson [Thu, 4 Feb 2021 14:48:10 +0000 (14:48 +0000)]
Import atf 0.22 snapshot ca73d08c3fc1ecffc1f1c97458c31ab82c12bb01

This includes improvements to the atf-sh helper functions that
significantly reduce the number of spawned processes for each test
and therefore speeds up running the testsuite noticeably.

(cherry picked from commit c203bd70b5957f85616424b6fa374479372d06e3)

3 years agoFix bootstrap tools build on macOS after 02af91c52e71e8a0f47251e637c9687f35d45dd9
Alex Richardson [Wed, 17 Feb 2021 16:03:11 +0000 (16:03 +0000)]
Fix bootstrap tools build on macOS after 02af91c52e71e8a0f47251e637c9687f35d45dd9

After changing the namespace.h header we need to provide _err on macOS, too.
Previously we used the system libc err*/warn*, but that does not provide
_err/_warn (which is used by other bootstrapped files from libc).
To fix this problem bootstrap err.c on macOS as well.

Fixes: 02af91c52 (Fix crossbuild bootstrap tools build with Clang 12)
(cherry picked from commit 962a3814d4c838d21a67a4b704c64be843cb2b51)

3 years agoFix crossbuild bootstrap tools build with Clang 12
Alex Richardson [Wed, 10 Feb 2021 11:05:02 +0000 (11:05 +0000)]
Fix crossbuild bootstrap tools build with Clang 12

Clang 12 no longer allows re-defining a weak symbol as non-weak. This
happed here because we compile err.c with _err defined to err. To fix
this, use the same approach as the libc namespace.h

(cherry picked from commit 02af91c52e71e8a0f47251e637c9687f35d45dd9)

3 years agobin/pkill: Fix {pgrep,pkill}-j_test.sh
Alex Richardson [Sat, 13 Feb 2021 13:53:50 +0000 (13:53 +0000)]
bin/pkill: Fix {pgrep,pkill}-j_test.sh

The POSIX sh case statement does not allow for pattern matching using the
regex + qualifier so this case statement never matches. Instead just check
for a string starting with a digit followed by any character.

While touching these files also fix various shellcheck warnings.

`kyua -v parallelism=4 test` failed before, succeeds now.

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

(cherry picked from commit 5ff2e55e0071dabbf18cdbe13a1230822d1270d4)

3 years agolib/libc/tests/rpc: Correctly set timeout
Alex Richardson [Sat, 13 Feb 2021 13:52:59 +0000 (13:52 +0000)]
lib/libc/tests/rpc: Correctly set timeout

The rpc_control() API does not accept the CLCR_SET_RPCB_TIMEOUT command,
it only accepts RPC_SVC_CONNMAXREC_GET/RPC_SVC_CONNMAXREC_SET, so it was
not doing anything.
Instead of incorrectly calling this API, use clnt_create_timed() instead.

I noticed this because the test was timing out after 120s in the CheriBSD CI.

Reviewed By: ngie
Differential Revision: https://reviews.freebsd.org/D28478

(cherry picked from commit 90b5fc95832da64a5f56295e687379732c33718f)

3 years agousr.bin/jail: Fix tests when using kyua -v parallelism=N
Alex Richardson [Thu, 4 Feb 2021 17:56:54 +0000 (17:56 +0000)]
usr.bin/jail: Fix tests when using kyua -v parallelism=N

These tests create jails with the same name, so they cannot be run in
parallel.

Reviewed By: lwhsu
Differential Revision: https://reviews.freebsd.org/D28482

(cherry picked from commit 72692dfdfe7b4ffd894afd67959651ca1b01a105)

3 years agosbin/pfctl: fix tests after recent output changes
Alex Richardson [Thu, 4 Feb 2021 17:56:26 +0000 (17:56 +0000)]
sbin/pfctl: fix tests after recent output changes

The output now contains http-alt instead of 8080 and personal-agent
instead of 5555.
This was probably caused by 228e2087a32847fa51168f3f0c58f931cb2cb0f8.

Reviewed By: kp
Differential Revision: https://reviews.freebsd.org/D28481

(cherry picked from commit 58de61b9967b36f5fbd34e8b51ece7b4b772f104)

3 years agotools/build/make.py: -DNO_CLEAN -> -DWITHOUT_CLEAN
Alex Richardson [Wed, 3 Feb 2021 15:56:03 +0000 (15:56 +0000)]
tools/build/make.py: -DNO_CLEAN -> -DWITHOUT_CLEAN

(cherry picked from commit 43e083be8103685e65582e002d33e861f7d5c794)

3 years agousr.sbin/praudit: Fix tests after 5619d49e07
Alex Richardson [Wed, 3 Feb 2021 15:26:19 +0000 (15:26 +0000)]
usr.sbin/praudit: Fix tests after 5619d49e07

Commit 5619d49e07 made the getgrgid() call inside bsm work as
intended so we now print "wheel" instead of a numeric 0 in the rgid field.

Reviewed By: markj
Differential Revision: https://reviews.freebsd.org/D28462

(cherry picked from commit 7791ecf04b48a0c365b003447f479ec890115dfc)

3 years agotests/sys/audit: Skip extattr tests if extattrs are not supported
Alex Richardson [Tue, 2 Feb 2021 09:55:18 +0000 (09:55 +0000)]
tests/sys/audit: Skip extattr tests if extattrs are not supported

In the CheriBSD CI, we run the testsuite with /tmp as tmpfs. This causes
the extattr audit tests to fail since tmpfs does not (yet) support
extattrs. Skip those tests if the target path is on a file system that
does not support extended file attributes.

While touching these two files also convert the ATF_REQUIRE_EQ(-1, ...)
checks to use ATF_REQURIE_ERRNO().

Reviewed By: asomers
Differential Revision: https://reviews.freebsd.org/D28392

(cherry picked from commit 40407d3998d1a12cbe929721f4dbe72b4be478a6)

3 years agoUpdate comment missed in 83ff5d5d98cbcf9b66dccd70022358aec8918a14
Alex Richardson [Fri, 29 Jan 2021 09:19:27 +0000 (09:19 +0000)]
Update comment missed in 83ff5d5d98cbcf9b66dccd70022358aec8918a14

Reported by: jrtc27

(cherry picked from commit d4a6843bb1207d71234099ded81cee75d3ae8864)

3 years agotests/sys/audit: fix timeout calculation
Alex Richardson [Thu, 28 Jan 2021 17:23:27 +0000 (17:23 +0000)]
tests/sys/audit: fix timeout calculation

This changes the behaviour to a 30s total timeout (needed when running
on slow emulated uniprocessor systems) and timing out after 10s without
any input. This also uses timespecsub() instead of ignoring the
nanoseconds field.

After this change the tests runs more reliably on QEMU and time out less
frequently.

Reviewed By: asomers
Differential Revision: https://reviews.freebsd.org/D28391

(cherry picked from commit 869cc06480b75b4caea0d049e0cf7f82bb5aeed1)

3 years agoUn-XFAIL two tests with Clang > 10
Alex Richardson [Thu, 28 Jan 2021 17:17:49 +0000 (17:17 +0000)]
Un-XFAIL two tests with Clang > 10

SVN r343917 fixed this for in-tree clang, but when building with a newer
out-of-tree clang the test was still marked as XFAIL.

Reviewed By: dim
Differential Revision: https://reviews.freebsd.org/D28390

(cherry picked from commit 83ff5d5d98cbcf9b66dccd70022358aec8918a14)

3 years agoDon't include libarchive fuzz tests by default
Alex Richardson [Mon, 25 Jan 2021 14:03:17 +0000 (14:03 +0000)]
Don't include libarchive fuzz tests by default

These tests are basic fuzz tests that permute input to trigger crashes
rather than regression or unit tests. Additionally, some of them take a
rather long time to run and should probably be run on a dedicated fuzzing
job instead. Moreover, these simple tests use rand() instead of a real
fuzzing tool that generates interesting inputs (e.g. LLVM libFuzzer) so are
unlikely to find anything interesting when run in CI.

This allows removing one BROKEN_TESTS case due to timeouts and speeds up
running tests on emulated platforms such as QEMU.

Reviewed By: lwhsu, mm
Differential Revision: https://reviews.freebsd.org/D27153

(cherry picked from commit 3454fa118c41a588e2dad20614325297c989c60b)

3 years agorc.d/auditd: set pidfile
Alex Richardson [Thu, 28 Jan 2021 17:17:07 +0000 (17:17 +0000)]
rc.d/auditd: set pidfile

auditd creates a pidfile so we should use it for status checks.
This also seems to speed up the frequent onestatus checks used in
tests/sys/audit.

Reviewed By: asomers
Differential Revision: https://reviews.freebsd.org/D28389

(cherry picked from commit bcc5b2445674e4691853d7533e4873a6712f67ee)

3 years agokerberos5: Silence compiler warnings
Alex Richardson [Wed, 27 Jan 2021 10:41:57 +0000 (10:41 +0000)]
kerberos5: Silence compiler warnings

Building the kerberos5 subdirectory currently produces lots of warnings.
Since there are many instances of these warnings and it's contrib code,
this change silences the warnings instead of fixing them.

Reviewed By: jhb, cy, bjk
Differential Revision: https://reviews.freebsd.org/D28025

(cherry picked from commit 4f009328a2477f5f1c682629fc5708498b7c689f)

3 years agokern.mk: Fix wrong variable being used for linker path after 172a624f0
Alex Richardson [Mon, 8 Mar 2021 09:37:39 +0000 (09:37 +0000)]
kern.mk: Fix wrong variable being used for linker path after 172a624f0

When I synchronized kern.mk with bsd.sys.mk, I accidentally changed
CCLDFLAGS to LDFLAGS which is not used by the kernel builds. This commit
should unbreak the GitHub actions cross-build CI. I didn't notice it
locally because cheribuild already passes -fuse-ld in the linker flags as
it predates this being done in the makefiles.

Reported By: Jose Luis Duran
Fixes: 172a624f0 ("Silence annoying and incorrect non-default linker warning with GCC")

(cherry picked from commit 01fe4cac28d0b5ab2b8f4ef081fd3c81dcbb4df3)

3 years agoSilence annoying and incorrect non-default linker warning with GCC
Alex Richardson [Thu, 4 Mar 2021 18:27:37 +0000 (18:27 +0000)]
Silence annoying and incorrect non-default linker warning with GCC

The CROSS_TOOLCHAIN GCC .mk files include -B${CROSS_BINUTILS_PREFIX}, so
GCC will select the right linker and we don't need to warn.
While here also apply 17b8b8fb5fc4acc832dabfe7ef11e3e1d399ad0f to kern.mk.

Test Plan: no more warning printed with CROSS_TOOLCHAIN=mips-gcc6
Reviewed By: jhb
Differential Revision: https://reviews.freebsd.org/D29015

(cherry picked from commit 172a624f0c9fbc47d74fd5178d46f771f82dc6a0)

3 years agoreadelf: Fix printing NT_FREEBSD_ARCH_TAG
Alex Richardson [Wed, 3 Feb 2021 15:24:28 +0000 (15:24 +0000)]
readelf: Fix printing NT_FREEBSD_ARCH_TAG

Looking at lib/csu/arm/crt1_s.S, this should be a string and therefore the
restriction to 4 characters seems wrong.
Found whle updating https://reviews.llvm.org/D74393.

Reviewed By: emaste
Differential Revision: https://reviews.freebsd.org/D28470

(cherry picked from commit 2a39919364b5368e026f656ff41861a3fdd56110)

3 years agosys/arm64/arm64/vfp.c: Fix -Wunused and -Wpointer-sign warnings
Alex Richardson [Thu, 4 Mar 2021 14:55:29 +0000 (14:55 +0000)]
sys/arm64/arm64/vfp.c: Fix -Wunused and -Wpointer-sign warnings

These are off by default but were flagged by my IDE while adding some
debugging printfs for D29060.

(cherry picked from commit 0072e5e0f3a0bb3aa06708ba64497ef75021d431)

3 years agotmpfs: implement pathconf(_PC_SYMLINK_MAX)
Alex Richardson [Wed, 17 Mar 2021 09:49:49 +0000 (09:49 +0000)]
tmpfs: implement pathconf(_PC_SYMLINK_MAX)

This fixes one of the sys/audit tests when running them on tmpfs.

Reviewed By: delphij, kib
Differential Revision: https://reviews.freebsd.org/D28387

(cherry picked from commit 1d15bceae63c438e3ff7dc7a0ca8a2c538e357b9)

3 years agoCreate symlinks to host tools on non-FreeBSD hosts
Alex Richardson [Wed, 17 Mar 2021 09:48:28 +0000 (09:48 +0000)]
Create symlinks to host tools on non-FreeBSD hosts

This is unnecessary when cross-building from Linux/macOS.
Additionally, cp -p appears to be broken on macOS Big Sur
(https://openradar.appspot.com/8957219).

For some unknown reason this commit appears to fix
freezes when building on macOS Big Sur.
This also fixes building in docker with volume mounts
with ACLs, since setting the ACL with cp -p fails otherwise.

Obtained From: CheriBSD
Tested By: gnn (macOS Big Sur), Nathaniel Wesley Filardo (docker)
Reviewed By: jrtc27, imp
Differential Revision: https://reviews.freebsd.org/D28267

(cherry picked from commit a8b20f4fabbca9bef377009429848d4f9cea18ae)

3 years agolibc/qsort: Don't allow interposing recursive calls
Alex Richardson [Thu, 18 Feb 2021 10:12:29 +0000 (10:12 +0000)]
libc/qsort: Don't allow interposing recursive calls

This causes problems when using ASAN with a runtime older than 12.0 since
the intercept does not expect qsort() to call itself using an interposable
function call. This results in infinite recursion and stack exhaustion
when a binary compiled with -fsanitize=address calls qsort.
See also https://bugs.llvm.org/show_bug.cgi?id=46832 and
https://reviews.llvm.org/D84509 (ASAN runtime patch).

To prevent this problem, this patch uses a static helper function
for the actual qsort() implementation. This prevents interposition and
allows for direct calls. As a nice side-effect, we can also move the
qsort_s checks to the top-level function and out of the recursive calls.

Reviewed By: kib
Differential Revision: https://reviews.freebsd.org/D28133

(cherry picked from commit cbcfe28f9d5f975f97b7fb4a0d72bc9780eb0c46)

3 years agoAArch64: Don't set flush-subnormals-to-zero flag on startup
Alex Richardson [Mon, 1 Mar 2021 14:27:30 +0000 (14:27 +0000)]
AArch64: Don't set flush-subnormals-to-zero flag on startup

This flag has been set on startup since 65618fdda0f272a823e6701966421bdca0efa301.
However, This causes some of the math-related tests to fail as they report
zero instead of a tiny number. This fixes at least
/usr/tests/lib/msun/ldexp_test and possibly others.
Additionally, setting this flag prevents printf() from printing subnormal
numbers in decimal form.
See also https://www.openwall.com/lists/musl/2021/02/26/1

PR: 253847
Reviewed By: mmel
Differential Revision: https://reviews.freebsd.org/D28938

(cherry picked from commit 0e4ff0acbe80c547988bede738af2e227c7eb47c)

3 years agoArch64: Clear VFP state on execve()
Alex Richardson [Tue, 9 Mar 2021 19:11:40 +0000 (19:11 +0000)]
Arch64: Clear VFP state on execve()

I noticed that many of the math-related tests were failing on AArch64.
After a lot of debugging, I noticed that the floating point exception flags
were not being reset when starting a new process. This change resets the
VFP inside exec_setregs() to ensure no VFP register state is leaked from
parent processes to children.

This commit also moves the clearing of fpcr that was added in 65618fdda0f27
from fork() to execve() since that makes more sense: fork() can retain
current register values, but execve() should result in a well-defined
clean state.

Reviewed By: andrew
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D29060

(cherry picked from commit 953a7d7c61f3b2f5351dfe668510ec782ae282e8)

3 years agoFix fget_only_user() to return ENOTCAPABLE on a failed capsicum check
Alex Richardson [Mon, 15 Feb 2021 22:09:33 +0000 (22:09 +0000)]
Fix fget_only_user() to return ENOTCAPABLE on a failed capsicum check

After eaad8d1303da500ed691bd774742a4555a05e729 four additional
capsicum-test tests started failing. It turns out this is because
fget_only_user() was returning EBADF on a failed capsicum check instead
of forwarding the return value of cap_check_inline() like
fget_unlocked_seq().

capsicum-test failures before this:
```
[  FAILED  ] 7 tests, listed below:
[  FAILED  ] Capability.OperationsForked
[  FAILED  ] Capability.NoBypassDAC
[  FAILED  ] Pdfork.OtherUserForked
[  FAILED  ] PipePdfork.WildcardWait
[  FAILED  ] OpenatTest.WithFlag
[  FAILED  ] ForkedOpenatTest_WithFlagInCapabilityMode._
[  FAILED  ] Select.LotsOFileDescriptorsForked
```
After:
```
[  FAILED  ] 3 tests, listed below:
[  FAILED  ] Capability.NoBypassDAC
[  FAILED  ] Pdfork.OtherUserForked
[  FAILED  ] PipePdfork.WildcardWait
```

Reviewed By: mjg
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D28691

(cherry picked from commit 0482d7c9e944433abc98fc27a265ae762abce9a0)

3 years agomsun: ctanh/ctanhf: Import fix from musl libc
Alex Richardson [Mon, 15 Feb 2021 22:06:41 +0000 (22:06 +0000)]
msun: ctanh/ctanhf: Import fix from musl libc

This applies musl commit b02eed9c4841913d690a2d0029737d72615384fe by
Szabolcs Nagy and updates the tests accordingly. This also allows
removing an XFAIL from the test.

musl commit message:

complex: fix ctanh(+-0+i*nan) and ctanh(+-0+-i*inf)

These cases were incorrect in C11 as described by
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1886.htm

PR: 217528

Reviewed By: dim
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D28578

(cherry picked from commit a7b42c4b7f7ad7bd1b22ab57ed9185bdcea6f0a2)

3 years agovm: Round up npages and alignment for contig reclamation
Mark Johnston [Tue, 2 Mar 2021 15:19:53 +0000 (10:19 -0500)]
vm: Round up npages and alignment for contig reclamation

When searching for runs to reclaim, we need to ensure that the entire
run will be added to the buddy allocator as a single unit.  Otherwise,
it will not be visible to vm_phys_alloc_contig() as it is currently
implemented.  This is a problem for allocation requests that are not a
power of 2 in size, as with 9KB jumbo mbuf clusters.

Reported by: alc
Reviewed by: alc
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D28924

(cherry picked from commit 0401989282d1bb9972ae2bf4862c2c6c92ae5f27)

3 years agonfsclient: Fix ReadDS/WriteDS/CommitDS nfsstats RPC counts for a NFSv3 DS
Rick Macklem [Tue, 2 Mar 2021 22:18:23 +0000 (14:18 -0800)]
nfsclient: Fix ReadDS/WriteDS/CommitDS nfsstats RPC counts for a NFSv3 DS

During a recent virtual NFSv4 testing event, a bug in the FreeBSD client
was detected when doing I/O DS operations on a Flexible File Layout pNFS
server.  For an NFSv3 DS, the Read/Write/Commit nfsstats were incremented
instead of the ReadDS/WriteDS/CommitDS counts.
This patch fixes this.

Only the RPC counts reported by nfsstat(1) were affected by this bug,
the I/O operations were performed correctly.

(cherry picked from commit c04199affeacbd9e9dda3aaf5ca0b1b180031e78)

3 years agonfsclient: Fix the stripe unit size for a File Layout pNFS layout
Rick Macklem [Mon, 1 Mar 2021 20:49:32 +0000 (12:49 -0800)]
nfsclient: Fix the stripe unit size for a File Layout pNFS layout

During a recent virtual NFSv4 testing event, a bug in the FreeBSD client
was detected when doing a File Layout pNFS DS I/O operation.
The size of the I/O operation was smaller than expected.
The I/O size is specified as a stripe unit size in bits 6->31 of nflh_util
in the layout.  I had misinterpreted RFC5661 and had shifted the value
right by 6 bits. The correct interpretation is to use the value as
presented (it is always an exact multiple of 64), clearing bits 0->5.
This patch fixes this.

Without the patch, I/O through the DSs work, but the I/O size is 1/64th
of what is optimal.

(cherry picked from commit 94f2e42f5e0b78a7a4684d4a4eb62ea470a57eb1)

3 years agonfsclient: add nfs node locking around uses of n_direofoffset
Rick Macklem [Sun, 28 Feb 2021 22:53:54 +0000 (14:53 -0800)]
nfsclient: add nfs node locking around uses of n_direofoffset

During code inspection I noticed that the n_direofoffset field
of the NFS node was being manipulated without any lock being
held to make it SMP safe.
This patch adds locking of the NFS node's mutex around
handling of n_direofoffset to make it SMP safe.

I have not seen any failure that could be attributed to n_direofoffset
being manipulated concurrently by multiple processors, but I think this
is possible, since directories are read with shared vnode
locking, plus locks only on individual buffer cache blocks.
However, there have been as yet unexplained issues w.r.t reading
large directories over NFS that could have conceivably been caused
by concurrent manipulation of n_direofoffset.

(cherry picked from commit 15bed8c46b32dec19e922cb89e12c8970867a303)

3 years agonfsclient: add checks for a server returning the current directory
Rick Macklem [Sun, 28 Feb 2021 22:15:32 +0000 (14:15 -0800)]
nfsclient: add checks for a server returning the current directory

Commit 3fe2c68ba20f dealt with a panic in cache_enter_time() where
the vnode referred to the directory argument.
It would also be possible to get these panics if a broken
NFS server were to return the directory as an new object being
created within the directory or in a Lookup reply.

This patch adds checks to avoid the panics and logs
messages to indicate that the server is broken for the
file object creation cases.

(cherry picked from commit 3e04ab36ba5ce5cbbf6d22f17a01a391a04e465f)

3 years agodumpon.8: Ask DDB to call doadump() rather than calling it directly
Mark Johnston [Mon, 8 Mar 2021 17:39:05 +0000 (12:39 -0500)]
dumpon.8: Ask DDB to call doadump() rather than calling it directly

Sponsored by: The FreeBSD Foundation

(cherry picked from commit af06ff55535d9b2de253103e974558104e0a3d97)

3 years agoRename _cscan_atomic.h and _cscan_bus.h to atomic_san.h and bus_san.h
Mark Johnston [Mon, 8 Mar 2021 17:39:06 +0000 (12:39 -0500)]
Rename _cscan_atomic.h and _cscan_bus.h to atomic_san.h and bus_san.h

Other kernel sanitizers (KMSAN, KASAN) require interceptors as well, so
put these in a more generic place as a step towards importing the other
sanitizers.

No functional change intended.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D29103

(cherry picked from commit 435c7cfb2418fdac48fa53e29e38ef03646b817d)

3 years agoath_hal: Stop printing messages during boot
Mark Johnston [Mon, 8 Mar 2021 17:39:06 +0000 (12:39 -0500)]
ath_hal: Stop printing messages during boot

ath_hal is compiled into the kernel by default and so always prints a
message to dmesg even when the system has no ath hardware.

Sponsored by: The FreeBSD Foundation

(cherry picked from commit 0e72eb460228e4b9cb790beb7113d0a5c88db503)

3 years agoposix timers: Improve the overrun calculation
Mark Johnston [Mon, 8 Mar 2021 17:39:06 +0000 (12:39 -0500)]
posix timers: Improve the overrun calculation

timer_settime(2) may be used to configure a timeout in the past.  If
the timer is also periodic, we also try to compute the number of timer
overruns that occurred between the initial timeout and the time at which
the timer fired.  This is done in a loop which iterates once per period
between the initial timeout and now.  If the period is small and the
initial timeout was a long time ago, this loop can take forever to run,
so the system is effectively DOSed.

Replace the loop with a more direct calculation of
(now - initial timeout) / period to compute the number of overruns.

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

(cherry picked from commit 7995dae9d3f58abf38ef0001cee24131f3c9054b)

3 years agoposix timers: Sprinkle some style fixes
Mark Johnston [Mon, 8 Mar 2021 17:39:06 +0000 (12:39 -0500)]
posix timers: Sprinkle some style fixes

Sponsored by: The FreeBSD Foundation

(cherry picked from commit 60d12ef952a39581e967a1a608522fdbdedefa01)

3 years agoposix timers: Declare unexported functions as static
Mark Johnston [Mon, 8 Mar 2021 17:39:06 +0000 (12:39 -0500)]
posix timers: Declare unexported functions as static

Sponsored by: The FreeBSD Foundation

(cherry picked from commit 8ff2b41c05a8f98e30250b929e9722f714f1f319)

3 years agowg: Style
Mark Johnston [Mon, 8 Mar 2021 17:39:05 +0000 (12:39 -0500)]
wg: Style

Sponsored by: The FreeBSD Foundation

(cherry picked from commit d8cebef50e7b5fac1e28bcb1f931962210f9b5f6)

3 years agons8250: don't drop IER_TXRDY on bus_grab/ungrab
Mitchell Horne [Wed, 10 Mar 2021 14:57:12 +0000 (10:57 -0400)]
ns8250: don't drop IER_TXRDY on bus_grab/ungrab

It has been observed that some systems are often unable to resume from
ddb after entering with debug.kdb.enter=1. Checking the status further
shows the terminal is blocked waiting in tty_drain(), but it never makes
progress in clearing the output queue, because sc->sc_txbusy is high.

I noticed that when entering polling mode for the debugger, IER_TXRDY is
set in the failure case. Since this bit is never tracked by the softc,
it will not be restored by ns8250_bus_ungrab(). This creates a race in
which a TX interrupt can be lost, creating the hang described above.
Ensuring that this bit is restored is enough to prevent this, and resume
from ddb as expected.

The solution is to track this bit in the sc->ier field, for the same
lifetime that TX interrupts are enabled.

PR: 223917, 240122
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 7e7f7beee732810d3afcc83828341ac3e139b5bd)

3 years agodevelopment(7): update to reflect Git transition
Edward Tomasz Napierala [Thu, 11 Mar 2021 20:03:30 +0000 (20:03 +0000)]
development(7): update to reflect Git transition

Reviewed By: debdrup, imp (earlier version)
Sponsored By: EPSRC
Differential Revision: https://reviews.freebsd.org/D28939

(cherry picked from commit d28cbb7944e5b1015d94a04cadc97d473838611e)

3 years agolinux(4): make getcwd(2) return ERANGE instead of ENOMEM
Edward Tomasz Napierala [Fri, 12 Mar 2021 15:31:37 +0000 (15:31 +0000)]
linux(4): make getcwd(2) return ERANGE instead of ENOMEM

For native FreeBSD binaries, the return value from __getcwd(2)
doesn't really matter, as the libc wrapper takes over and returns
the proper errno.

PR: kern/254120
Reported By: Alex S <iwtcex@gmail.com>
Reviewed By: kib
Sponsored By: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D29217

(cherry picked from commit 0dfbdd9fc269f0438ffcc31632d35234a90584ad)

3 years agoMake kern.timecounter.hardware tunable
Konstantin Belousov [Sun, 7 Mar 2021 23:50:12 +0000 (01:50 +0200)]
Make kern.timecounter.hardware tunable

(cherry picked from commit 56b9bee63a42dbac712acf540f23a4c3dbd099a9)

3 years agoMove ic_check_send_space clear to the actual check.
Alexander Motin [Wed, 3 Mar 2021 20:21:26 +0000 (15:21 -0500)]
Move ic_check_send_space clear to the actual check.

It closes tiny race when the flag could be set between being cleared
and the space is checked, that would create us some more work.  The
flag setting is protected by both locks, so we can clear it in either
place, but in between both locks are dropped.

MFC after: 1 week

(cherry picked from commit afc3e54eeee635a525c88e4678cc38e3219302c3)

3 years agoRestore condition removed in df3747c6607b.
Alexander Motin [Wed, 3 Mar 2021 16:58:04 +0000 (11:58 -0500)]
Restore condition removed in df3747c6607b.

I think it allowed to avoid some TX thread wakeups while the socket
buffer is full.  But add there another options if ic_check_send_space
is set, which means socket just reported that new space appeared, so
it may have sense to pull more data from ic_to_send for better TX
coalescing.

MFC after: 1 week

(cherry picked from commit aff9b9ee894e3e6b6d8c7e4182d6b973804df853)

3 years agoReplace STAILQ_SWAP() with simpler STAILQ_CONCAT().
Alexander Motin [Tue, 2 Mar 2021 23:39:44 +0000 (18:39 -0500)]
Replace STAILQ_SWAP() with simpler STAILQ_CONCAT().

Also remove stray STAILQ_REMOVE_AFTER(), not causing problems only
because STAILQ_SWAP() fixed corrupted stqh_last.

MFC after: 1 week

(cherry picked from commit df3747c6607be12d48db825653e6adfc3041e97f)

3 years agoFix initiator panic after 6895f89fe54e.
Alexander Motin [Tue, 2 Mar 2021 21:07:22 +0000 (16:07 -0500)]
Fix initiator panic after 6895f89fe54e.

There are sessions without socket that are not disconnecting yet.

MFC after: 3 weeks

(cherry picked from commit 06e9c710998b83a3be21f7f264187fff5d590bc3)

3 years agoOptimize TX coalescing by keeping pointer to last mbuf.
Alexander Motin [Tue, 2 Mar 2021 04:31:34 +0000 (23:31 -0500)]
Optimize TX coalescing by keeping pointer to last mbuf.

Before m_cat() each time traversed through all the coalesced chain.

MFC after: 1 week

(cherry picked from commit b85a67f54a40053e75658a17c620b89bafaba67f)

3 years agoOptimize out few extra memory accesses.
Alexander Motin [Mon, 1 Mar 2021 23:35:45 +0000 (18:35 -0500)]
Optimize out few extra memory accesses.

MFC after: 1 week

(cherry picked from commit a59e2982fe3e6339629cc77fe9d349d60e03a05e)

3 years agoMicro-optimize OOA queue processing.
Alexander Motin [Sat, 27 Feb 2021 15:14:05 +0000 (10:14 -0500)]
Micro-optimize OOA queue processing.

- Move ctl_get_cmd_entry() calls from every OOA traversal to when
  the requests first inserted, storing seridx in struct ctl_scsiio.
- Move some checks out of the loop in ctl_check_ooa().
- Replace checks for errors that can not happen with asserts.
- Transpose ctl_serialize_table, so that any OOA traversal accessed
  only one row (cache line).  Compact it from enum to uint8_t.
- Optimize static branch predictions in hottest places.

Due to O(n) nature on deep LUN queues this can be the hottest code
path in CTL, and additional 20% of IOPS I see in some 4KB I/O tests
are good to have in reserve.  About 50% of CPU time here according
to the profiles is now spent in two memory accesses per traversed
request in OOA.

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

(cherry picked from commit 9d9fd8b79f0ebe59f791c8225fa01ab59858b7b5)

3 years agoCoalesce socket reads in software iSCSI.
Alexander Motin [Mon, 22 Feb 2021 17:23:35 +0000 (12:23 -0500)]
Coalesce socket reads in software iSCSI.

Instead of 2-4 socket reads per PDU this can do as low as one read
per megabyte, dramatically reducing TCP overhead and lock contention.

With this on iSCSI target I can write more than 4GB/s through a
single connection.

MFC after: 1 month

(cherry picked from commit 6895f89fe54e0858aea70d2bd2a9651f45d7998e)

3 years agoFix build after 2c7dc6bae9fd.
Alexander Motin [Sun, 21 Feb 2021 22:21:14 +0000 (17:21 -0500)]
Fix build after 2c7dc6bae9fd.

MFC after: 1 month

(cherry picked from commit c02a28754bc229c05e8baf9b6632cbd59bc73e48)

3 years agoRefactor CTL datamove KPI.
Alexander Motin [Sun, 21 Feb 2021 21:45:14 +0000 (16:45 -0500)]
Refactor CTL datamove KPI.

 - Make frontends call unified CTL core method ctl_datamove_done()
to report move completion.  It allows to reduce code duplication
in differerent backends by accounting DMA time in common code.
 - Add to ctl_datamove_done() and be_move_done() callback samethr
argument, reporting whether the callback is called in the same
context as ctl_datamove().  It allows for some cases like iSCSI
write with immediate data or camsim frontend write save one context
switch, since we know that the context is sleepable.
 - Remove data_move_done() methods from struct ctl_backend_driver,
unused since forever.

MFC after:  1 month

(cherry picked from commit 2c7dc6bae9fd5c2fa0a65768df8e4e99c2f159f1)

3 years agoMicrooptimize CTL I/O queues.
Alexander Motin [Fri, 19 Feb 2021 20:42:57 +0000 (15:42 -0500)]
Microoptimize CTL I/O queues.

Switch OOA queue from TAILQ to LIST and change its direction, so that
we traverse it forward, not backward.  There is only one place where
we really need other direction, and it is not critical.

Use STAILQ_REMOVE_HEAD() instead of STAILQ_REMOVE() in backends.

Replace few impossible conditions with assertions.

MFC after: 1 month

(cherry picked from commit 05d882b780f5be2da6f3d3bfef9160aacc4888d6)

3 years agoSave context switch per I/O for iSCSI and IOCTL frontends.
Alexander Motin [Fri, 19 Feb 2021 03:07:32 +0000 (22:07 -0500)]
Save context switch per I/O for iSCSI and IOCTL frontends.

Introduce new CTL core KPI ctl_run(), preprocessing I/Os in the caller
context instead of scheduling another thread just for that.  This call
may sleep, that is not acceptable for some frontends like the original
CAM/FC one, but iSCSI already has separate sleepable per-connection RX
threads, and another thread scheduling is mostly just a waste of time.
IOCTL frontend actually waits for the I/O completion in the caller
thread, so the use of another thread for this has even less sense.

With this change I can measure ~5% IOPS improvement on 4KB iSCSI I/Os
to ZFS.

MFC after: 1 month

(cherry picked from commit 812c9f48a2b7bccc31b2a6077b299822357832e4)

3 years agoMove XPT_IMMEDIATE_NOTIFY handling out of periph lock.
Alexander Motin [Thu, 18 Feb 2021 21:22:01 +0000 (16:22 -0500)]
Move XPT_IMMEDIATE_NOTIFY handling out of periph lock.

It is a rare, but still better to not have lock dependencies.

MFC after: 1 month

(cherry picked from commit c67a2909a629db138227993e1093e66bb6c00af5)

3 years agonewsyslog(8): Implement a new 'E' flag to not rotate empty log files
Juraj Lutter [Sun, 28 Feb 2021 22:07:14 +0000 (23:07 +0100)]
newsyslog(8): Implement a new 'E' flag to not rotate empty log files

Based on an idea from dvl's coworker, László DANIELISZ, implement
a new flag, 'E', that prevents newsyslog(8) from rotating the empty
log files. This 'E' flag ist mostly usable in conjunction with 'B'
flag that instructs newsyslog(8) to not insert an informational
message into the log file after rotation, keeping it still empty.

Reviewed by: markj, ian, manpages (rpokala)
Approved by: markj, ian, manpages (rpokala)
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D28940

(cherry picked from commit c7d27b225df8d7fb36a31a21737d4309593c4604)

3 years agoDo not complain about incorrect cylinder group check-hashes when
Kirk McKusick [Fri, 12 Mar 2021 06:44:33 +0000 (22:44 -0800)]
Do not complain about incorrect cylinder group check-hashes when
asked to add them to a filesystem.

Sponsored by: Netflix

(cherry picked from commit 6385cabd5be627c4f395e3abf215882aaeb36320)

3 years agolib/flua/libjail: Allow empty params table
Ryan Moeller [Thu, 25 Feb 2021 05:16:52 +0000 (05:16 +0000)]
lib/flua/libjail: Allow empty params table

The name or jid always gets added to the params, and that's enough to
avoid allocating a 0 length params array.

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

(cherry picked from commit e175b519a6fb83889fb3ca679b73d11ea5bea7ad)

3 years agosbin/ifconfig: Get lagg status with libifconfig
Ryan Moeller [Sat, 27 Feb 2021 03:05:31 +0000 (03:05 +0000)]
sbin/ifconfig: Get lagg status with libifconfig

Also trimmed an unused block of code that never prints out LAGG_PROTOS.
Reviewed by: kp (earlier version)
Differential Revision: https://reviews.freebsd.org/D28961

(cherry picked from commit a0ebb915045ed0056decec5f001471af4e999f61)

3 years agolibifconfig: Add a function to get down reason
Ryan Moeller [Sun, 28 Feb 2021 09:34:30 +0000 (09:34 +0000)]
libifconfig: Add a function to get down reason

For use in ifconfig.

Reviewed by: kp
Differential Revision: https://reviews.freebsd.org/D28991

(cherry picked from commit b12a960e4274926171dc7a4f9887a0d0a5195b44)

3 years agosbin/ifconfig: Get bridge status with libifconfig
Ryan Moeller [Fri, 26 Feb 2021 23:04:38 +0000 (23:04 +0000)]
sbin/ifconfig: Get bridge status with libifconfig

Reviewed by: kp
Differential Revision: https://reviews.freebsd.org/D28954

(cherry picked from commit 6f497e47e925f6886f444a8e31e2e939fca264f2)

3 years agosbin/ifconfig: Get groups with libifconfig
Ryan Moeller [Sat, 27 Feb 2021 08:17:04 +0000 (08:17 +0000)]
sbin/ifconfig: Get groups with libifconfig

Reviewed by: kp
Differential Revision: https://reviews.freebsd.org/D28965

(cherry picked from commit 64bacab177f7c743af3268a3e1ffcddaf77a68d0)

3 years agosbin/ifconfig: Get carp status with libifconfig
Ryan Moeller [Fri, 26 Feb 2021 23:40:58 +0000 (23:40 +0000)]
sbin/ifconfig: Get carp status with libifconfig

A trivial change now that ifconfig is already using libifconfig.
Reviewed by: kp (earlier version)
Differential Revision: https://reviews.freebsd.org/D28955

(cherry picked from commit da393346ac47b22b5f8af4040a59971faadd2c5c)

3 years agosbin/ifconfig: Minor housekeeping
Ryan Moeller [Sun, 28 Feb 2021 02:08:43 +0000 (02:08 +0000)]
sbin/ifconfig: Minor housekeeping

Coalesce adjacent lint ifdefs.
Fix spelling of nitems.

Reviewed by: kp
Differential Revision: https://reviews.freebsd.org/D29022

(cherry picked from commit 88832d59dec10e97dd64b44391606776b20e782b)

3 years agolibifconfig: Fix typo in symbol map
Ryan Moeller [Wed, 3 Mar 2021 01:55:18 +0000 (01:55 +0000)]
libifconfig: Fix typo in symbol map

(cherry picked from commit 80545a16df95263781b3422695527b6238f4bd2c)

3 years agosbin/ifconfig: Drop local name var in sfp_status
Ryan Moeller [Sun, 28 Feb 2021 02:15:11 +0000 (02:15 +0000)]
sbin/ifconfig: Drop local name var in sfp_status

There is already a globally defined name variable.

(cherry picked from commit 9995455218ff19df9cf0dcaf0198269dc76eeb2d)

3 years agolibifconfig: Set error in ifconfig_get_groups
Ryan Moeller [Sat, 27 Feb 2021 08:07:21 +0000 (08:07 +0000)]
libifconfig: Set error in ifconfig_get_groups

This should return -1 with OTHER/ENOMEM set in the handle when malloc
fails, like everywhere else in libifconfig.

Reviewed by: kp
Differential Revision: https://reviews.freebsd.org/D28964

(cherry picked from commit 1d9ba697f99a88b321a7d8b96fa142ea774cd3be)

3 years agovm_reserv: Fix list locking in vm_reserv_reclaim_contig()
Mark Johnston [Thu, 11 Mar 2021 15:34:28 +0000 (10:34 -0500)]
vm_reserv: Fix list locking in vm_reserv_reclaim_contig()

The per-domain partpop queue is locked by the combination of the
per-domain lock and individual reservation mutexes.
vm_reserv_reclaim_contig() scans the queue looking for partially
populated reservations that can be reclaimed in order to satisfy the
caller's allocation.

During the scan, we drop the per-domain lock.  At this point, the rvn
pointer may be invalidated.  Take care to load rvn after re-acquiring
the per-domain lock.

While here, simplify the condition used to check whether a reservation
was dequeued while the per-domain lock was dropped.

Reviewed by: alc, kib
Reported by: gallatin
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D29203

(cherry picked from commit 968079f253c11433d47bece4b41b46fcbf985903)

3 years agoFlush remaining routes from the routing table during VNET shutdown.
Alexander V. Chernikov [Mon, 8 Mar 2021 21:35:41 +0000 (21:35 +0000)]
Flush remaining routes from the routing table during VNET shutdown.

Summary:
This fixes rtentry leak for the cloned interfaces created inside the
 VNET.

Loopback teardown order is `SI_SUB_INIT_IF`, which happens after `SI_SUB_PROTO_DOMAIN` (route table teardown).
Thus, any route table operations are too late to schedule.
As the intent of the vnet teardown procedures to minimise the amount of effort by doing global cleanups instead of per-interface ones, address this by adding a relatively light-weight routing table cleanup function, `rib_flush_routes()`.
It removes all remaining routes from the routing table and schedules the deletion, which will happen later, when `rtables_destroy()` waits for the current epoch to finish.

Test Plan:
```
set_skip:set_skip_group_lo  ->  passed  [0.053s]
tail -n 200 /var/log/messages | grep rtentry
```

PR: 253998
Reported by: rashey at superbox.pl
Reviewed By: kp
Differential Revision: https://reviews.freebsd.org/D29116

(cherry picked from commit b1d63265ac399112b3bca36c3d75df1a3c2c8102)

3 years agoFix various NOINET* builds broken by 145bf6c0af48.
Alexander V. Chernikov [Fri, 12 Feb 2021 20:36:20 +0000 (20:36 +0000)]
Fix various NOINET* builds broken by 145bf6c0af48.

Reported by: mjg, bdragon

(cherry picked from commit 8ca99aecf749dd088310f81f3c5364a462f1e332)

3 years agoFix blackhole/reject routes.
Alexander V. Chernikov [Mon, 8 Feb 2021 23:29:05 +0000 (23:29 +0000)]
Fix blackhole/reject routes.

Traditionally *BSD routing stack required to supply some
 interface data for blackhole/reject routes. This lead to
 varieties of hacks in routing daemons when inserting such routes.
With the recent routeing stack changes, gateway sockaddr without
 RTF_GATEWAY started to be treated differently, purely as link
 identifier.

This change broke net/bird, which installs blackhole routes with
 127.0.0.1 gateway without RTF_GATEWAY flags.

Fix this by automatically constructing necessary gateway data at
 rtsock level if RTF_REJECT/RTF_BLACKHOLE is set.

Reported by: Marek Zarychta <zarychtam at plan-b.pwste.edu.pl>
Reviewed by: donner

(cherry picked from commit 145bf6c0af48b89f13465e145f4516de37c31d85)

3 years agoPartially revert libcxxrt changes to avoid _Unwind_Exception change
Dimitry Andric [Sat, 13 Mar 2021 13:54:05 +0000 (14:54 +0100)]
Partially revert libcxxrt changes to avoid _Unwind_Exception change

(Note I am also applying this to main and stable/13, to restore the old
libcxxrt ABI and to avoid having to maintain a compat library.)

After the recent cherry-picking of libcxxrt commits 0ee0dbfb0d26 and
d2b3fadf2db5, users reported that editors/libreoffice packages from the
official package builders did not start anymore. It turns out that the
combination of these commits subtly changes the ABI, requiring all
applications that depend on internal details of struct _Unwind_Exception
(available via unwind-arm.h and unwind-itanium.h) to be recompiled.

However, the FreeBSD package builders always use -RELEASE jails, so
these still use the old declaration of struct _Unwind_Exception, which
is not entirely compatible. In particular, LibreOffice uses this struct
in its internal "uno bridge" component, where it attempts to setup its
own exception handling mechanism.

To fix this incompatibility, go back to the old declarations of struct
_Unwind_Exception, and restore the __LP64__ specific workaround we had
in place before (which was to cope with yet another, older ABI bug).

Effectively, this reverts upstream libcxxrt commits 88bdf6b290da
("Specify double-word alignment for ARM unwind") and b96169641f79
("Updated Itanium unwind"), and reapplies our commit 3c4fd2463bb2
("libcxxrt: add padding in __cxa_allocate_* to fix alignment").

PR: 253840

3 years agoRestore AT_RESOLVE_BENEATH support for funlinkat(2)/unlinkat(2).
Konstantin Belousov [Fri, 5 Mar 2021 02:07:57 +0000 (04:07 +0200)]
Restore AT_RESOLVE_BENEATH support for funlinkat(2)/unlinkat(2).

(cherry picked from commit ead7697f04c036853535a4281cec9aa09ef21270)