Commit graph

1283 commits

Author SHA1 Message Date
Doug Moore
b1290f4746 vm_reserv: use enhanced bitstring for popmaps
vm_reserv.c uses its own bitstring implemenation for popmaps. Using
the bitstring_t type from a standard header eliminates the code
duplication, allows some bit-at-a-time operations to be replaced with
more efficient bitstring range operations, and, in
vm_reserv_test_contig, allows bit_ffc_area_at to more efficiently
search for a big-enough set of consecutive zero-bits.

Make bitstring changes improve the vm_reserv code.  Define a bit_ntest
method to test whether a range of bits is all set, or all clear.
Define bit_ff_at and bit_ff_area_at to implement the ffs and ffc
versions with a parameter to choose between set- and clear- bits.
Improve the area_at implementation.  Modify the bit_nset and
bit_nclear implementations to allow code optimization in the cases
when start or end are multiples of _BITSTR_BITS.

Add a few new cases to bitstring_test.

Discussed with:	alc
Reviewed by:	markj
Tested by:	pho (earlier version)
Differential Revision:	https://reviews.freebsd.org/D33312

(cherry picked from commit 84e2ae64c5)
2022-07-11 00:54:06 -05:00
Alan Somers
1f44d1861a fusefs: handle evil servers that return illegal inode numbers
* If during FUSE_CREATE, FUSE_MKDIR, etc the server returns the same
  inode number for the new file as for its parent directory, reject it.
  Previously this would triggers a recurse-on-non-recursive lock panic.

* If during FUSE_LINK the server returns a different inode number for
  the new name as for the old one, reject it.  Obviously, that can't be
  a hard link.

* If during FUSE_LOOKUP the server returns the same inode number for the
  new file as for its parent directory, reject it.  Nothing good can
  come of this.

PR:		263662
Reported by:	Robert Morris <rtm@lcs.mit.edu>
Reviewed by:	pfg
Differential Revision: https://reviews.freebsd.org/D35128

(cherry picked from commit 0bef4927ea)
2022-06-18 08:16:20 -06:00
Alan Somers
14cd9da9db fusefs: make the mknod.cc tests a bit more general.
Reviewed by:    pfg

(cherry picked from commit 8b582b1640)
2022-06-18 08:16:06 -06:00
Thomas Pasqualini
f40bb3b602 pf tests: pfsync and route_to test case
Test pfsync in a more realistic scenario with carp and route_to rules.

Build this topology and initiate a single ping session from client to
server:
		   ┌──────┐
		   │client│
		   └───┬──┘
		       │
		   ┌───┴───┐
		   │bridge0│
		   └┬─────┬┘
		    │     │
   ┌────────────────┴─┐ ┌─┴────────────────┐
   │gw_route_to_master├─┤gw_route_to_backup│
   └────────────────┬─┘ └─┬────────────────┘
		    │     │
		   ┌┴─────┴┐
		   │bridge1│
		   └┬─────┬┘
		    │     │
   ┌────────────────┴─┐ ┌─┴────────────────┐
   │gw_reply_to_master├─┤gw_reply_to_backup│
   └────────────────┬─┘ └─┬────────────────┘
		    │     │
		   ┌┴─────┴┐
		   │bridge2│
		   └───┬───┘
		       │
		   ┌───┴──┐
		   │server│
		   └──────┘

gw* jails forward traffic through pf route-to rules, not fib lookups.
If backup_promotion arg is given (as in the pfsync_pbr test case), a
carp failover event occurs during the ping session on both gateways.

Verify that ping messages still go where we expect them to go.

MFC after:	2 weeks
Sponsored by:	Orange Business Services

(cherry picked from commit 536e1da18b)
2022-06-18 09:30:11 +02:00
Dmitry Chagin
b7af02ed79 Prevent running sigwait tests in parallel
test_sig_discard_ign_* could not run at the same time.

Approved by:    dchagin
Sponsored by:   Netflix
Differential Revision:  https://reviews.freebsd.org/D35236

(cherry picked from commit c678572e76)
2022-06-17 22:35:24 +03:00
Dmitry Chagin
8f12d3536c fusefs tests: Remove an unused variable.
Reviewed by:		asomers
Differential revision:	https://reviews.freebsd.org/D35185
MFC after:		2 weeks

(cherry picked from commit d966efcc08)
2022-06-17 22:35:16 +03:00
Dmitry Chagin
7acb65fb3e tests: Get rid of invalid since 3e11d3f6 testcase
MFC after:		2 weeks

(cherry picked from commit e4a257058c)
2022-06-17 22:35:16 +03:00
Dmitry Chagin
66a762e5f6 Add tests for affinity syscalls.
MFC after:		2 weeks

(cherry picked from commit c8b5c478f6)
2022-06-17 22:35:15 +03:00
Dmitry Chagin
99a4f33f27 Fix build after 128b9bf9
MFC after:	2 weeks

(cherry picked from commit 0ced2aef06)
2022-06-17 22:33:56 +03:00
Dmitry Chagin
bbc82e5536 Add tests for sigwait family syscalls.
MFC after:              2 weeks

(cherry picked from commit 128b9bf96c)
2022-06-17 22:33:56 +03:00
Thomas Munro
5fac6f1687 poll(2): Add POLLRDHUP.
Teach poll(2) to support Linux-style POLLRDHUP events for sockets, if
requested.  Triggered when the remote peer shuts down writing or closes
its end.

Reviewed by:	kib
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D29757

(cherry picked from commit 3aaaa2efde)
2022-06-17 22:22:13 +03:00
Mark Johnston
294386e0f7 kqueue tests: Simplify the test runner
Just invoke the test program directly instead of trying to convert its
output to TAP format.  The test suite is all or nothing; there's no way
to enumerate individual test cases, so there's no advantage in trying to
massage its output, and doing so throws away information that's useful
when diagnosing test failures.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 68fe988a40)
2022-06-07 20:42:28 -04:00
Mark Johnston
f2ce33a640 kqueue tests: Add new EVFILT_TIMER regression tests from upstream
One of the tests exposes the regression reported in PR 264131.

One test is disabled because FreeBSD does not support setting EV_ONESHOT
on an already-added periodic timer.  Though, in this case the flag is
simply ignored, which isn't ideal.

One test is slightly modified to set EV_ADD when reconfiguring a
disabled timer per some commentary in PR 258412.

Ideally we would re-import the test suite from libkqueue but there is a
fair bit of divergence so this will require some effort.  This just gets
us one small step closer while increasing test coverage.

PR:		258412
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit d6d4f9b45e)
2022-06-07 20:42:25 -04:00
Mark Johnston
c87ff7f5c6 kqueue tests: Add file and line info to some test failure output
This brings us slightly closer to upstream and is useful when debugging
test failures.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit c728c56c87)
2022-06-07 20:42:18 -04:00
Mark Johnston
42ccdf4493 kqueue tests: Re-enable kqueue proc tests
- Some EVFILT_PROC bugs were fixed around the time that the tests were
  disabled.
- I can't reproduce any failures locally.
- Jenkins logs referenced from the PR are gone, so let's re-enable the
  tests and see whether a problem persists.

PR:		233586
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit bc7512cc58)
2022-06-07 20:42:15 -04:00
Kristof Provost
4dfd3ffc44 if: avoid interface destroy race
When we destroy an interface while the jail containing it is being
destroyed we risk seeing a race between if_vmove() and the destruction
code, which results in us trying to move a destroyed interface.

Protect against this by using the ifnet_detach_sxlock to also covert
if_vmove() (and not just detach).

PR:		262829
MFC after:	3 weeks
Differential Revision:	https://reviews.freebsd.org/D34704

(cherry picked from commit 868bf82153)
2022-05-27 18:25:10 +02:00
Mark Johnston
a3113db102 bitstring_test: Add regression tests for bit_ff(c|s)_area_at()
Validate the cases where a match can be found immediately and where no
match can be found.  This extends the existing test cases and is enough
to catch the bug fixed in commit 6e7a585348 ("bitstring: fix ff_area()
when start!=0").

Reviewed by:	dougm
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 670be460e4)
2022-05-27 09:14:47 -04:00
Alan Somers
8f8e64da6b Fix overflow errors in sbttous and sbttoms
Both of these functions would overflow for very large inputs.  Add tests
for them.  Also, add tests for the inverse functions, *stosbt, whose
overflow errors were fixed by 4c30b9ecd4.

PR:		263073
Sponsored by:	Axcient
Reviewed by:	imp
Differential Revision: https://reviews.freebsd.org/D34809

(cherry picked from commit 10f44229dc)
2022-05-23 13:11:27 -06:00
Alan Somers
8272680eec fusefs: annotate more file descriptor leaks in the tests
The fusefs tests intentionally leak file descriptors.  Annotate all of
the leakages in order to hopefully pacify Coverity.

Reported by:	Coverity (20 different CIDs)
Sponsored by:	Axcient

(cherry picked from commit 4ac4b12699)
2022-05-23 13:11:19 -06:00
Alan Somers
2737e6bca7 fusefs: use the fsname mount option if set
The daemon can specify fsname=XXX in its mount options.  If so, the file
system should report f_mntfromname as XXX during statfs.  This will show
up in the output of commands like mount and df.

Submitted by:	Ali Abdallah <ali.abdallah@suse.com>
Differential Revision:	https://reviews.freebsd.org/D35090

(cherry picked from commit 2f6362484c)
2022-05-23 13:11:11 -06:00
Alan Somers
2c999421c4 fusefs: add a test for the subtype= option
At mount time server can set, for example, "subtype=xfs", so that
mount(8) will later show the mountpoint's file system as "fusefs.xfs".
fusefs has had this feature ever since the original GSoC commit in 2012,
but there's never been a test for it.

(cherry picked from commit 616eaa66aa)
2022-05-23 13:11:08 -06:00
Andrew Turner
658631a37d Add PT_GETREGSET
This adds the PT_GETREGSET and PT_SETREGSET ptrace types. These can be
used to access all the registers from a specified core dump note type.
The NT_PRSTATUS and NT_FPREGSET notes are initially supported. Other
machine-dependant types are expected to be added in the future.

The ptrace addr points to a struct iovec pointing at memory to hold the
registers along with its length. On success the length in the iovec is
updated to tell userspace the actual length the kernel wrote or, if the
base address is NULL, the length the kernel would have written.

Because the data field is an int the arguments are backwards when
compared to the Linux PTRACE_GETREGSET call.

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

(cherry picked from commit 548a2ec49b)
2022-05-12 15:12:59 -07:00
Alan Somers
c7b4932df6 fusefs: fix FUSE_CREATE with file handles and fuse protocol < 7.9
Prior to fuse protocol version 7.9, the fuse_entry_out structure had a
smaller size.  But fuse_vnop_create did not take that into account when
working with servers that use older protocols.  The bug does not matter
for servers which don't use file handles or open flags (the only fields
affected).

PR:		263625
Submitted by:	Ali Abdallah <ali.abdallah@suse.com>

(cherry picked from commit 45825a12f9)
2022-05-12 14:43:22 -06:00
Alan Somers
04f7286f44 fusefs: correctly handle servers that report too much data written
During a FUSE_WRITE, the kernel requests the server to write a certain
amount of data, and the server responds with the amount that it actually
did write.  It is obviously an error for the server to write more than
it was provided, and we always treated it as such, but there were two
problems:

* If the server responded with a huge amount, greater than INT_MAX, it
  would trigger an integer overflow which would cause a panic.

* When extending the file, we wrongly set the file's size before
  validing the amount written.

PR:		263263
Reported by:	Robert Morris <rtm@lcs.mit.edu>
Sponsored by:	Axcient
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D34955

(cherry picked from commit 3a1b3c6a1e)
2022-05-12 14:39:47 -06:00
Alan Somers
ef0e12d565 fusefs: validate servers' error values
Formerly fusefs would pass up the stack any error value returned by the
fuse server.  However, some values aren't valid for userland, but have
special meanings within the kernel.  One of these, EJUSTRETURN, could
cause a kernel page fault if the server returned it in response to
FUSE_LOOKUP.  Fix by validating all errors returned by the server.

Also, fix a data lifetime bug in the FUSE_DESTROY test.

PR:		263220
Reported by:	Robert Morris <rtm@lcs.mit.edu>
Sponsored by:	Axcient
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D34931

(cherry picked from commit 155ac516c6)
2022-05-12 14:37:24 -06:00
John Baldwin
66b4bdd5ad module_test: Fix some assignments to errno intended to be tests.
Reported by:	vangyzen
Reviewed by:	vangyzen, markj
Sponsored by:	University of Cambridge, Google, Inc.
Differential Revision:	https://reviews.freebsd.org/D34528

(cherry picked from commit 18207579a2)
2022-05-11 10:30:09 -07:00
John Baldwin
ec687150e5 Add simple kyua tests for the mod* system calls.
Reviewed by:	markj
Obtained from:	CheriBSD
Sponsored by:	University of Cambridge, Google, Inc.
Differential Revision:	https://reviews.freebsd.org/D34417

(cherry picked from commit 5a1de9c25d)
2022-05-11 10:29:45 -07:00
John Baldwin
5bd5219d15 Cast pointer to uintptr_t to avoid alignment warnings.
Both struct ip and struct udphdr both have an aligment of 2, but the
cast from struct ip to a uint32_t pointer confused GCC 9 into raising
the required alignment to 4 and then raising a
-Waddress-of-packed-member error when casting to struct udphdr.

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

(cherry picked from commit dba02df30d)
2022-05-10 17:11:27 -07:00
Alex Richardson
b0188ea200 Add a test for https://reviews.freebsd.org/D31858 (PR 258310)
This test (based on https://github.com/jiixyj/epoll-shim/pull/32#issuecomment-891276654)
fails reproducibly on QEMU with KVM and `-smp 2` prior to D31858 (committed
as 98168a6e6c) and passes with the patch applied.

Reviewed By:	kib, imp
Differential Revision: https://reviews.freebsd.org/D31862

(cherry picked from commit d7d962ead0)
2022-05-07 12:56:58 +01:00
Andrew Turner
9bd46f48da Disable subr_physmem_test on mips
It doesn't build.

Direct commit as mips doesn't exist in 14.

Sponsored by:	The FreeBSD Foundation
2022-05-03 16:51:57 +01:00
Andrew Turner
3ed2c7a4be Have path_test ask the kernel for the page size
It may be dynamic so we can't rely on PAGE_SIZE being present or
correct.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 8d40ee599d)
2022-05-03 15:04:04 +01:00
Andrew Turner
d017d1faa1 Have the coredump_phnum test ask for the page size
The page size may be dynamically selected on boot. Have the
coredump_phnum test helper ask the kernel for the correct value.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit df696a2fb6)
2022-05-03 15:04:04 +01:00
Andrew Turner
fc5ab0227b Handle non-page aligned/sized memory in physmem
In some configurations the firmware may pass memory regions that are
not page sized or aligned, e.g. when using 16k pages on arm64. If this
is the case we will calculate many small regions because the alignment
is applied before being inserted. As we round the start up and end down
this will leave a 1 page hole between what should have been a single
region.

Fix by keeping the original alignment until we are just about to insert
the region into the avail array.

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

(cherry picked from commit d8bff5b67c)
2022-05-03 15:04:04 +01:00
Andrew Turner
0edb26c3ba Port subr_physmem to userspace and add tests
These give us some confidience we haven't broken anything in early
boot code that may be running before the console.

Reviewed by:	emaste
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D34691

(cherry picked from commit 8c99dfed54)

Disable the physmem test for now

It fails to build on at least i386

(cherry picked from commit d8819d88af)

Enable subr_physmem_test on supported architectures

Only build where it's supported.

While here add support for amd64 to help with testing.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 41e6d2091c)
2022-05-03 15:04:04 +01:00
John Baldwin
1462dc95f7 ktls: Support for TLS 1.3 receive offload.
Note that support for TLS 1.3 receive offload in OpenSSL is still an
open pull request in active development.  However, potential changes
to that pull request should not affect the kernel interface.

Reviewed by:	hselasky
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D33007

(cherry picked from commit 05a1d0f5d7)
2022-04-29 14:07:27 -07:00
Alan Somers
507b75ced9 fusefs: fix two bugs regarding VOP_RECLAIM of the root inode
* We never send FUSE_LOOKUP for the root inode, since its inode number
  is hard-coded to 1.  Therefore, we should not send FUSE_FORGET for it,
  lest the server see its lookup count fall below 0.

* During VOP_RECLAIM, if we are reclaiming the root inode, we must clear
  the file system's vroot pointer.  Otherwise it will be left pointing
  at a reclaimed vnode, which will cause future VOP_LOOKUP operations to
  fail.  Previously we only cleared that pointer during VFS_UMOUNT.  I
  don't know of any real-world way to trigger this bug.

Reviewed by:	pfg
Differential Revision: https://reviews.freebsd.org/D34753

(cherry picked from commit 3227325366)
2022-04-29 11:16:00 -06:00
Mark Johnston
00193c79b4 path_test: Verify that operations on unlinked files work
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit b13ac67842)
2022-04-25 08:59:18 -04:00
Mark Johnston
3861fe8ba8 path_test: Correct the kevent test
Perhaps surprisingly, and contrary to the expectations of
path_test:path_event, NOTE_LINK events are not raised when a file is
unlinked.  Prior to commit bf13db086b, the test happened to work
because unlinking the file would cause the vnode to be recycled, and
EVFILT_VNODE knotes deliver an event with EV_EOF set when the vnode is
doomed.  Since the test did not verify the note type, the test
succeeded.  After commit bf13db086b, the vnode is not recycled after
being unlinked and so the test hangs.

Fix the test by waiting for NOTE_DELETE instead, and check that we got
the note that we expected.

Reported by:	Jenkins
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 333f668468)
2022-04-20 10:15:06 -04:00
Kristof Provost
c956e8491f netinet tests: only log critical errors from scapy
See also a26e895f3d.

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

(cherry picked from commit d234b011a8)
2022-03-24 10:45:00 +01:00
Kristof Provost
10d71d02cf pf tests: Test retrieving nested nat-anchors
MFC after:	1 week
Sponsored by:	Rubicon Communications, LLC ("Netgate")

(cherry picked from commit 3c3a19d1f4)
2022-03-24 10:44:54 +01:00
Kristof Provost
146681af72 pf tests: Test setting and retrieving nested anchors
MFC after:	1 week
Sponsored by:	Rubicon Communications, LLC ("Netgate")

(cherry picked from commit d58d2e403d)
2022-03-24 10:44:40 +01:00
Alan Somers
79ec7ebf88 fusefs: fix a cached attributes bug during directory rename
When renaming a directory into a different parent directory, invalidate
the cached attributes of the new parent.  Otherwise, stat will show the
wrong st_nlink value.

Reviewed by:	ngie
Differential Revision: https://reviews.freebsd.org/D34336

(cherry picked from commit e8553be9bc)
2022-03-09 09:59:49 -07:00
Ed Maste
71f452d58c zfs: Update test format strings to match variable typtes
And drop stray 'd' from the end of some printed numbers.  I assume this
was the result of someone thinking u is a printf length modifier for d,
not a format specifier itself.

Reviewed by:	kevans, rew
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D34387

(cherry picked from commit f27fb06cad)
2022-03-07 19:33:21 -05:00
Mark Johnston
45014f965e tests: Fix the test plan for closefrom_test
Fixes:	f3f3e3c44d ("fd: add close_range(..., CLOSE_RANGE_CLOEXEC)")
Reported by:	Jenkins

(cherry picked from commit 3a01dcc99f)
2022-03-07 12:15:47 +00:00
Mateusz Guzik
8891979494 fd: add close_range(..., CLOSE_RANGE_CLOEXEC)
For compatibility with Linux.

MFC after:	3 days
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D34424

(cherry picked from commit f3f3e3c44d)
2022-03-07 12:15:47 +00:00
Arka Sharma
6a73d96ac4 mmap map_at_zero test: handle W^X
Use kern.elfXX.allow_wx to decide whether to map W+X or W-only memory.

Future work could expand this test to add an "allow_wx" axis to the
test matrix, but I would argue that a separate test should be written,
since that's orthogonal to map_at_zero.

MFC after:	1 week
Sponsored by:	Dell EMC Isilon

(cherry picked from commit 766c2466ff)
2022-03-03 08:20:07 -06:00
Alan Somers
837e2f537c [skip ci] fusefs: delete a stray comment from 91972cfcdd
(cherry picked from commit 0b6a34acda)
2022-03-02 16:37:25 -07:00
Eric van Gyzen
656de74c63 aio_md_test: label the md
Add a label to md devices created by this test.  The next time this
test leaks md devices, finding the culprit will be much easier.

Thanks to:	sobomax, for adding labels in r322969
MFC after:	1 week
Sponsored by:	Dell EMC Isilon

(cherry picked from commit 9666cda976)
2022-03-02 15:56:30 -06:00
Eric van Gyzen
ac20fa249f aio_md_test: NUL-terminate result of readlink
readlink does not NUL-terminate the output buffer.  This led to spurious
failures to destroy the md device because the unit number was garbage.
NUL-terminate the output buffer.

Reported by:	ASLR
MFC after:	1 week
Sponsored by:	Dell EMC Isilon

(cherry picked from commit ea0e1b19f2)
2022-03-02 15:56:30 -06:00
Eric van Gyzen
77f0c44e49 aio_md_test: fix cleanup
ATF cleanup functions cannot use functions such as ATF_REQUIRE
and atf_tc_fail.  These functions assert that a test case is
currently running, which is not true during cleanup, so the
process aborts.  Change the cleanup function to simply print
to stderr and return.

MFC after:	1 week
Sponsored by:	Dell EMC Isilon

(cherry picked from commit c6f92e64b6)
2022-03-02 15:56:30 -06:00