]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
4 years agoloader: provide u> and xemit words if needed
Toomas Soome [Tue, 17 Sep 2019 18:05:33 +0000 (18:05 +0000)]
loader: provide u> and xemit words if needed

We have external interpreter (userboot.so) which may be lagging behind
with updates and may be missing u> xemit words.

4 years agoThe VFS-level clustering code collects together sequential blocks
Kirk McKusick [Tue, 17 Sep 2019 17:44:50 +0000 (17:44 +0000)]
The VFS-level clustering code collects together sequential blocks
by issuing delayed-writes (bdwrite()) until a non-sequential block
is written or the maximum cluster size is reached. At that point
it collects the delayed buffers together (using bread()) to write
them in a single operation. The assumption was that since we just
looked at them they will still be in memory so there is no need to
check for a read error from bread(). Very occationally (apparently
every 10-hours or so when being pounded by Peter Holm's tests)
this assumption is wrong.

The fix is to check for errors from bread() and fail the cluster
write thus falling back to the default individual flushing of any
still dirty buffers.

Reported by: Peter Holm and Chuck Silvers
Reviewed by: kib
MFC after:   3 days

4 years agoloader: revert r352421
Toomas Soome [Tue, 17 Sep 2019 16:16:46 +0000 (16:16 +0000)]
loader: revert r352421

As insisted by kib, malloc(0) is quite legal.

4 years agovfs: apply r352437 to the fast path as well
Mateusz Guzik [Tue, 17 Sep 2019 15:53:40 +0000 (15:53 +0000)]
vfs: apply r352437 to the fast path as well

This one is very hard to run into. If the filesystem is being unmounted or
the mount point is freed the vfs_op_thread_enter will fail. For it to
succeed the mount point itself would have to be reallocated in the time
window between the initial read and the attempt to enter.

Sponsored by: The FreeBSD Foundation

4 years agofixup up fallout from r352447 in libbe
Andriy Gapon [Tue, 17 Sep 2019 14:15:48 +0000 (14:15 +0000)]
fixup up fallout from r352447 in libbe

I totally forgot that we now have another in-tree consumer of libzfs.

MFC after: 3 days
X-MFC with: r352447

4 years agoTemporarily skip flakey test case lib.libc.sys.stat_test.stat_socket
Li-Wen Hsu [Tue, 17 Sep 2019 14:08:09 +0000 (14:08 +0000)]
Temporarily skip flakey test case lib.libc.sys.stat_test.stat_socket

PR: 240621
Sponsored by: The FreeBSD Foundation

4 years agoMFZoL: Add -vnP support to 'zfs send' for bookmarks
Andriy Gapon [Tue, 17 Sep 2019 13:58:15 +0000 (13:58 +0000)]
MFZoL: Add -vnP support to 'zfs send' for bookmarks

zfsonlinux/zfs@835db58592d7d947e5818eb7281882e2a46073e0

We have long supported estimating a size of an incremental stream from a
snapshot.  We should do the same for bookmarks as well.

Obtained from: ZoL
Author: loli10K <ezomori.nozomu@gmail.com>
MFC after: 3 days

4 years agoloader.efi: efipart needs to use ioalign
Toomas Soome [Tue, 17 Sep 2019 13:50:25 +0000 (13:50 +0000)]
loader.efi: efipart needs to use ioalign

UEFI specification 2.7A, EFI_BLOCK_IO_PROTOCOL, page 566.

The ioalign property does define the alignment of data buffer.

If the alignment is required and our buffer is not aligned, or if
the data buffer is not multiple of Blocksize, we need to use bounce buffer
to perform the block IO. This is much like with BIOS version, except
there the INT13 needs buffer to be located in low memory.

Additionally, we need to handle disk writes properly.

4 years agoloader: add memalign() to libsa
Toomas Soome [Tue, 17 Sep 2019 13:15:27 +0000 (13:15 +0000)]
loader: add memalign() to libsa

Implement memalign(size_t alignment, size_t size) to allocate aligned memory.

4 years agoloader: stand.h should define reallocf as Reallocf
Toomas Soome [Tue, 17 Sep 2019 13:07:02 +0000 (13:07 +0000)]
loader: stand.h should define reallocf as Reallocf

Use the same approach as other zalloc functions.

4 years agoloader: cstyle cleanup libsa zalloc sources
Toomas Soome [Tue, 17 Sep 2019 11:35:53 +0000 (11:35 +0000)]
loader: cstyle cleanup libsa zalloc sources

Clean up libstand zalloc* sources. Note that it is not 100% whitespace cleanup.
I also reduced block in znalloc and zfree as those were obvious simplifications
and did help to save one level of indent.

4 years agoloader: factor out guard location setup from Realloc
Toomas Soome [Tue, 17 Sep 2019 09:47:35 +0000 (09:47 +0000)]
loader: factor out guard location setup from Realloc

To simplify and make it easier to read, use ga_Bytes field from guard
structure.

4 years agoOnly allow a SCTP-AUTH shared key to be updated by the application
Michael Tuexen [Tue, 17 Sep 2019 09:46:42 +0000 (09:46 +0000)]
Only allow a SCTP-AUTH shared key to be updated by the application
if it is not deactivated and not used.
This avoids a use-after-free problem.

Reported by: da_cheng_shao@yeah.net
MFC after: 3 days

4 years agovfs: fix braino resulting in NULL pointer deref in r352424
Mateusz Guzik [Tue, 17 Sep 2019 08:09:39 +0000 (08:09 +0000)]
vfs: fix braino resulting in NULL pointer deref in r352424

The breakage was added after all the testing and the testing which followed
was not sufficient to find it.

Reported by: pho
Sponsored by: The FreeBSD Foundation

4 years agomips: move support for temporary mappings above KSEG0 to per-CPU data
Jason A. Harmening [Tue, 17 Sep 2019 03:39:31 +0000 (03:39 +0000)]
mips: move support for temporary mappings above KSEG0 to per-CPU data

This is derived from similar work done in r310481 for i386 and r312610 for
armv6/armv7. Additionally, use a critical section to keep the thread
pinned for per-CPU operations instead of completely disabling local interrupts.

No objections from: adrian, jmallett, imp
Differential Revision:  https://reviews.freebsd.org/D18593

4 years agoRemove dead code from vm_map_unlink_entry made dead by r351476, and also
Doug Moore [Tue, 17 Sep 2019 02:53:59 +0000 (02:53 +0000)]
Remove dead code from vm_map_unlink_entry made dead by r351476, and also
a no-longer-used enumerant.

Reviewed by: alc
Approved by: markj (mentor, implicit)
Tested by: pho (as part of a larger change)
Differential Revision: https://reviews.freebsd.org/D21668

4 years agoAmend r352422, add missing 'n'
Dmitri Goutnik [Tue, 17 Sep 2019 00:22:20 +0000 (00:22 +0000)]
Amend r352422, add missing 'n'

Reported by: yuripv
Approved by: araujo (mentor)
Differential Revision: https://reviews.freebsd.org/D21679

4 years agofix the article to be correct...
John-Mark Gurney [Mon, 16 Sep 2019 22:48:40 +0000 (22:48 +0000)]
fix the article to be correct...

4 years agoRISC-V: Support EARLY_AP_STARTUP
Mitchell Horne [Mon, 16 Sep 2019 22:17:16 +0000 (22:17 +0000)]
RISC-V: Support EARLY_AP_STARTUP

The EARLY_AP_STARTUP option initializes non-boot processors
much sooner during startup. This adds support for this option
on RISC-V and enables it by default for GENERIC.

Reviewed by: jhb, markj
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D21661

4 years agovfs: convert struct mount counters to per-cpu
Mateusz Guzik [Mon, 16 Sep 2019 21:37:47 +0000 (21:37 +0000)]
vfs: convert struct mount counters to per-cpu

There are 3 counters modified all the time in this structure - one for
keeping the structure alive, one for preventing unmount and one for
tracking active writers. Exact values of these counters are very rarely
needed, which makes them a prime candidate for conversion to a per-cpu
scheme, resulting in much better performance.

Sample benchmark performing fstatfs (modifying 2 out of 3 counters) on
a 104-way 2 socket Skylake system:
before:   852393 ops/s
after:  76682077 ops/s

Reviewed by: kib, jeff
Tested by: pho
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D21637

4 years agovfs: manage mnt_writeopcount with atomics
Mateusz Guzik [Mon, 16 Sep 2019 21:33:16 +0000 (21:33 +0000)]
vfs: manage mnt_writeopcount with atomics

See r352424.

Reviewed by: kib, jeff
Tested by: pho
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D21575

4 years agovfs: manage mnt_lockref with atomics
Mateusz Guzik [Mon, 16 Sep 2019 21:32:21 +0000 (21:32 +0000)]
vfs: manage mnt_lockref with atomics

See r352424.

Reviewed by: kib, jeff
Tested by: pho
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D21574

4 years agovfs: manage mnt_ref with atomics
Mateusz Guzik [Mon, 16 Sep 2019 21:31:02 +0000 (21:31 +0000)]
vfs: manage mnt_ref with atomics

New primitive is introduced to denote sections can operate locklessly
on aspects of struct mount, but which can also be disabled if necessary.
This provides an opportunity to start scaling common case modifications
while providing stable state of the struct when facing unmount, write
suspendion or other events.

mnt_ref is the first counter to start being managed in this manner with
the intent to make it per-cpu.

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

4 years agoAdd myself (dmgk) to calendar.freebsd
Dmitri Goutnik [Mon, 16 Sep 2019 20:43:20 +0000 (20:43 +0000)]
Add myself (dmgk) to calendar.freebsd

Approved by: tz (mentor)
Differential Revision: https://reviews.freebsd.org/D21675

4 years agoAdd myself (dmgk) as a ports committer
Dmitri Goutnik [Mon, 16 Sep 2019 20:41:37 +0000 (20:41 +0000)]
Add myself (dmgk) as a ports committer

Approved by: tz (mentor)
Differential Revision: https://reviews.freebsd.org/D21672

4 years agoloader: Malloc(0) should return NULL.
Toomas Soome [Mon, 16 Sep 2019 20:28:08 +0000 (20:28 +0000)]
loader: Malloc(0) should return NULL.

We really should not allocate anything with size 0.

4 years agoloader_4th: scan_buffer can leave empty string on stack
Toomas Soome [Mon, 16 Sep 2019 20:26:53 +0000 (20:26 +0000)]
loader_4th: scan_buffer can leave empty string on stack

When the file processing is done, we will have string with lenght 0 in stack and we will attempt to
allocate 0 bytes.

4 years agoFix an off-by-one error from r351961
Alan Somers [Mon, 16 Sep 2019 16:41:01 +0000 (16:41 +0000)]
Fix an off-by-one error from r351961

That revision addressed a Coverity CID that could lead to a buffer overflow,
but it had an off-by-one error in the buffer size check.

Reported by: Coverity
Coverity CID: 1405530
MFC after: 3 days
MFC-With: 351961
Sponsored by: The FreeBSD Foundation

4 years agofusefs: initialize C++ classes the Coverity way
Alan Somers [Mon, 16 Sep 2019 15:56:21 +0000 (15:56 +0000)]
fusefs: initialize C++ classes the Coverity way

Coverity complained that I wasn't initializing some class members until the
SetUp method.  Do it in the constructor instead.

Reported by: Coverity
Coverity CIDs: 14043521404378
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation

4 years agofusefs: fix some minor Coverity CIDs in the tests
Alan Somers [Mon, 16 Sep 2019 15:44:59 +0000 (15:44 +0000)]
fusefs: fix some minor Coverity CIDs in the tests

Where open(2) is expected to fail, the tests should assert or expect that
its return value is -1.  These tests all accepted too much but happened to
pass anyway.

Reported by: Coverity
Coverity CID: 1404512140437814045041404483
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation

4 years agoAssert that the refcount value is not VPRC_BLOCKED in vm_page_drop().
Mark Johnston [Mon, 16 Sep 2019 15:16:48 +0000 (15:16 +0000)]
Assert that the refcount value is not VPRC_BLOCKED in vm_page_drop().

VPRC_BLOCKED is a refcount flag used to indicate that a thread is
tearing down mappings of a page.  When set, it causes attempts to wire a
page via a pmap lookup to fail.  It should never represent the last
reference to a page, so assert this.

Suggested by: kib
Reviewed by: alc, kib
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D21639

4 years agoFix a race in vm_page_dequeue_deferred_free() after r352110.
Mark Johnston [Mon, 16 Sep 2019 15:12:49 +0000 (15:12 +0000)]
Fix a race in vm_page_dequeue_deferred_free() after r352110.

This function loaded the page's queue index before setting PGA_DEQUEUE.
In this window the page daemon may have deactivated the page, updating
its queue index.  Make the operation atomic using vm_page_pqstate_cmpset();
the page daemon will not modify the page once it observes that PGA_DEQUEUE
is set.

Reported and tested by: pho
Reviewed by: alc, kib
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D21639

4 years agoFix a page leak in vm_page_reclaim_run().
Mark Johnston [Mon, 16 Sep 2019 15:09:31 +0000 (15:09 +0000)]
Fix a page leak in vm_page_reclaim_run().

After r352110 the attempt to remove mappings of the page being replaced
may fail if the page is wired.  In this case we must free the replacement
page.

Reviewed by: alc, kib
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D21639

4 years agoFix a couple of nits in r352110.
Mark Johnston [Mon, 16 Sep 2019 15:06:19 +0000 (15:06 +0000)]
Fix a couple of nits in r352110.

- Remove a dead variable from the amd64 pmap_extract_and_hold().
- Fix grammar in the vm_page_wire man page.

Reported by: alc
Reviewed by: alc, kib
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D21639

4 years agoRevert r352406, which contained changes I didn't intend to commit.
Mark Johnston [Mon, 16 Sep 2019 15:04:45 +0000 (15:04 +0000)]
Revert r352406, which contained changes I didn't intend to commit.

4 years agoFix a couple of nits in r352110.
Mark Johnston [Mon, 16 Sep 2019 15:03:12 +0000 (15:03 +0000)]
Fix a couple of nits in r352110.

- Remove a dead variable from the amd64 pmap_extract_and_hold().
- Fix grammar in the vm_page_wire man page.

Reported by: alc
Reviewed by: alc, kib
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D21639

4 years agofusefs: fix some minor issues with fuse_vnode_setparent
Alan Somers [Mon, 16 Sep 2019 14:51:49 +0000 (14:51 +0000)]
fusefs: fix some minor issues with fuse_vnode_setparent

* When unparenting a vnode, actually clear the flag. AFAIK this is basically
  a no-op because we only unparent a vnode when reclaiming it or when
  unlinking.

* There's no need to call fuse_vnode_setparent during reclaim, because we're
  about to free the vnode data anyway.

Reviewed by: emaste
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D21630

4 years agonfscl_loadattrcache: fix rest of the cases to not call
Konstantin Belousov [Mon, 16 Sep 2019 13:26:27 +0000 (13:26 +0000)]
nfscl_loadattrcache: fix rest of the cases to not call
vnode_pager_setsize() under the node mutex.

r248567 moved some calls of vnode_pager_setsize() after the node lock
is unlocked, do the rest now.

Reported and tested by: peterj
Sponsored by: The FreeBSD Foundation
MFC after: 1 week

4 years agosbuf(9): fix sbuf_drain_func typedef markup
Yuri Pankov [Mon, 16 Sep 2019 13:10:03 +0000 (13:10 +0000)]
sbuf(9): fix sbuf_drain_func typedef markup

Reviewed by: 0mp (previous version)
Differential Revision: https://reviews.freebsd.org/D21569

4 years agopkgbase: Move cap_mkdb from runtime to utilities POST-INSTALL
Emmanuel Vadot [Mon, 16 Sep 2019 12:51:30 +0000 (12:51 +0000)]
pkgbase: Move cap_mkdb from runtime to utilities POST-INSTALL

Since login and login.conf moved to the utilities packages move also
the post-install related commands.

Reported by: mj-mailinglist@gmx.de
Reviewed by: bapt

4 years agoFix 20190507 UPDATING entry
Kyle Evans [Mon, 16 Sep 2019 12:44:44 +0000 (12:44 +0000)]
Fix 20190507 UPDATING entry

The rc mechanism for loading kernel modules is actually called 'kld_list',
not 'kld_load'

Reported by: yuripv

4 years agoDon't write to memory outside of the allocated array for SACK blocks.
Michael Tuexen [Mon, 16 Sep 2019 08:18:05 +0000 (08:18 +0000)]
Don't write to memory outside of the allocated array for SACK blocks.

Obtained from: rrs@
MFC after: 3 days
Sponsored by: Netflix, Inc.

4 years agoDo not use our custom completion function, it is not needed anymore
Baptiste Daroussin [Mon, 16 Sep 2019 07:31:59 +0000 (07:31 +0000)]
Do not use our custom completion function, it is not needed anymore

4 years agoIncrease the size of the send and receive buffers for YP client rpc
Konstantin Belousov [Mon, 16 Sep 2019 06:42:01 +0000 (06:42 +0000)]
Increase the size of the send and receive buffers for YP client rpc
calls to max allowed UDP datagram size.

Since max allowed size both for keys and values where increased, the
old sizes of around 1K cause ypmatch(3) failures, while plain maps
fetches work.

The buffers were reduced in r34146 from default UDP rpcclient values
to 1024/2304 due to the key and value size being 1K.

Reviewed by: slavash
Sponsored by: Mellanox Technologies
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D21586

4 years agoDocument logic for __DEFAULT_DEPENDENT_OPTIONS
Simon J. Gerraty [Mon, 16 Sep 2019 00:32:23 +0000 (00:32 +0000)]
Document logic for __DEFAULT_DEPENDENT_OPTIONS

Reviewed by: stevek
Differential Revision: https://reviews.freebsd.org/D21640

4 years agoRelax TX draining in ns8250_bus_transmit().
Alexander Motin [Sun, 15 Sep 2019 23:56:39 +0000 (23:56 +0000)]
Relax TX draining in ns8250_bus_transmit().

Since TX interrupt is generated when THRE is set, wait for TEMT set means
wait for full character transmission time.  At low speeds that may take
awhile, burning CPU time while holding sc_hwmtx lock, also congested.

This is partial revert of r317659.

PR: 240121
MFC after: 2 weeks

4 years agoAvoid mixing cluster numbers and sector numbers. Makes code more readable.
Xin LI [Sun, 15 Sep 2019 19:41:54 +0000 (19:41 +0000)]
Avoid mixing cluster numbers and sector numbers. Makes code more readable.

Obtained from: NetBSD
MFC after: 2 weeks

4 years agoApply a runtime patch to the FDT data for imx6 to fix iomuxc problems.
Ian Lepore [Sun, 15 Sep 2019 19:38:15 +0000 (19:38 +0000)]
Apply a runtime patch to the FDT data for imx6 to fix iomuxc problems.

The latest imported FDT data defines a node for an iomuxc-gpr device,
which we don't support (or need, right now) in addition to the usual
iomuxc device.  Unfortunately, the dts improperly assigns overlapping
ranges of mmio space to both devices.  The -gpr device is also a syscon
and simple_mfd device.

At runtime the simple_mfd driver attaches for the iomuxc-gpr node, then
when the real iomuxc driver comes along later, it fails to attach because
it tries to allocate its register space, and it's already partially in
use by the bogus instance of simple_mfd.

This change works around the problem by simply disabling the node for
the iomuxc-gpr device, since we don't need it for anything.

4 years agoWhen the IP layer calls back into the SCTP layer to perform the SCTP
Michael Tuexen [Sun, 15 Sep 2019 18:29:45 +0000 (18:29 +0000)]
When the IP layer calls back into the SCTP layer to perform the SCTP
checksum computation, do not assume that the IP header chain and the
SCTP common header are in contiguous memory although the SCTP lays
out the mbuf chains that way. If there are IP-level options inserted
by the IP layer, the constraint is not fulfilled anymore.

This issues was found by running syzkaller. Thanks to markj@ who is
running an instance which also provides kernel dumps. This allowed me
to find this issue.

MFC after: 3 days

4 years agorangelock: add rangelock_cookie_assert
Kyle Evans [Sun, 15 Sep 2019 02:59:53 +0000 (02:59 +0000)]
rangelock: add rangelock_cookie_assert

A future change to posixshm to add file sealing (in DIFF_21391[0] and child)
will move locking out of shm_dotruncate as kern_shm_open() will require the
lock to be held across the dotruncate until the seal is actually applied.
For this, the cookie is passed into shm_dotruncate_locked which asserts
RCA_WLOCKED.

[0] Name changed to protect the innocent, hopefully, from getting autoclosed
due to this reference...

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

4 years agoMake the ti_sysc device quiet. It's an internal utility pseudo-device
Ian Lepore [Sun, 15 Sep 2019 01:02:01 +0000 (01:02 +0000)]
Make the ti_sysc device quiet.  It's an internal utility pseudo-device
that makes the upstream FDT data work right, so we don't need to see a
couple dozen instances of it spam the dmesg at boot time unless it's a
verbose boot.

4 years agoFix arm and aarch64 builds of libedit after r352275
Dimitry Andric [Sat, 14 Sep 2019 21:49:42 +0000 (21:49 +0000)]
Fix arm and aarch64 builds of libedit after r352275

On arm and arm64, where chars are unsigned by default, buildworld dies
with:

--- terminal.o ---
/usr/src/contrib/libedit/terminal.c:569:41: error: comparison of
integers of different signs: 'wint_t' (aka 'int') and 'wchar_t' (aka
'unsigned int') [-Werror,-Wsign-compare]
                                     el->el_cursor.v][where & 0370] !=
                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
/usr/src/contrib/libedit/terminal.c:659:28: error: comparison of
integers of different signs: 'wint_t' (aka 'int') and 'wchar_t' (aka
'unsigned int') [-Werror,-Wsign-compare]
                                     [el->el_cursor.h] == MB_FILL_CHAR)
                                     ~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~

Fix this by making MB_FILL_CHAR a wint_t, so no casting is needed.

Note that in https://reviews.freebsd.org/D21584 this was also proposed
by Yuichiro Naito <naito.yuichiro_gmail.com>.

Reviewed by: bapt
Subscribers: naito.yuichiro_gmail.com, ml_vishwin.info
MFC after: 3 weeks
X-MFC-With: r352275
Differential Revision: https://reviews.freebsd.org/D21657

4 years agoFix aux_info corruption in rtld direct execution mode.
Brandon Bergren [Sat, 14 Sep 2019 21:18:10 +0000 (21:18 +0000)]
Fix aux_info corruption in rtld direct execution mode.

After the aux vector is moved, it is necessary to re-digest aux_info so the
pointers are updated to the new locations.

This was causing thread creation to fail on powerpc64 when using direct
execution due to a nonsense value being read for aux_info[AT_STACKPROT].

Approved by: jhibbits (mentor)
Differential Revision: https://reviews.freebsd.org/D21656

4 years agoCreate a mechanism for encoding a system errno into the IIC_Exxxxx space.
Ian Lepore [Sat, 14 Sep 2019 19:33:36 +0000 (19:33 +0000)]
Create a mechanism for encoding a system errno into the IIC_Exxxxx space.

Errors are communicated between the i2c controller layer and upper layers
(iicbus and slave device drivers) using a set of IIC_Exxxxxx constants which
effectively define a private number space separate from (and having values
that conflict with) the system errno number space. Sometimes it is necessary
to report a plain old system error (especially EINTR) from the controller or
bus layer and have that value make it back across the syscall interface
intact.

I initially considered replicating a few "crucial" errno values with similar
names and new numbers, e.g., IIC_EINTR, IIC_ERESTART, etc. It seemed like
that had the potential to grow over time until many of the errno names were
duplicated into the IIC_Exxxxx space.

So instead, this defines a mechanism to "encode" an errno into the IIC_Exxxx
space by setting the high bit and putting the errno into the lower-order
bits; a new errno2iic() function does this. The existing iic2errno()
recognizes the encoded values and extracts the original errno out of the
encoded value. An interesting wrinkle occurs with the pseudo-error values
such as ERESTART -- they aleady have the high bit set, and turning it off
would be the wrong thing to do. Instead, iic2errno() recognizes that lots of
high bits are on (i.e., it's a negative number near to zero) and just
returns that value as-is.

Thus, existing drivers continue to work without needing any changes, and
there is now a way to return errno values from the lower layers. The first
use of that is in iicbus_poll() which does mtx_sleep() with the PCATCH flag,
and needs to return the errno from that up the call chain.

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

4 years agoIntroduce arb(3), the Array-based Red-Black Tree macros: similar
Edward Tomasz Napierala [Sat, 14 Sep 2019 19:23:46 +0000 (19:23 +0000)]
Introduce arb(3), the Array-based Red-Black Tree macros: similar
to the traditional tree(3) RB trees, but using an array (preallocated,
linear chunk of memory) to store the tree.

This avoids allocation overhead, improves memory locality,
and makes it trivially easy to share/transfer/copy the entire tree
without the need for marshalling.  The downside is that the size
is fixed at initialization time; there is no mechanism to resize
it.

This is one of the dependencies for the new stats(3) framework
(https://reviews.freebsd.org/D20477).

Reviewed by: bcr (man pages), markj
Discussed with: cem
MFC after: 2 weeks
Sponsored by: Klara Inc, Netflix
Obtained from: Netflix
Differential Revision: https://reviews.freebsd.org/D20324

4 years agoMake pseudofs(9) create directory entries in order, instead
Edward Tomasz Napierala [Sat, 14 Sep 2019 19:16:07 +0000 (19:16 +0000)]
Make pseudofs(9) create directory entries in order, instead
of the reverse.

This fixes Linux sysctl(8) binary - it assumes the first two
directory entries are always "." and "..". There might be other
Linux apps affected by this.

NB it might be a good idea to rewrite it using queue(3).

Reviewed by: kib
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D21550

4 years agoInclude <lock.h>, required to use spinlocks in this code.
Ian Lepore [Sat, 14 Sep 2019 18:20:14 +0000 (18:20 +0000)]
Include <lock.h>, required to use spinlocks in this code.

4 years agoamend r:352320 Fix date for sg@
Stephen Gregoratto [Sat, 14 Sep 2019 14:26:30 +0000 (14:26 +0000)]
amend r:352320 Fix date for sg@

Approved by:    bcr (mentor)

4 years agoSet bcr@ mentor for sg@
Stephen Gregoratto [Sat, 14 Sep 2019 12:40:46 +0000 (12:40 +0000)]
Set bcr@ mentor for sg@

Approved by:    bcr (mentor)

4 years agoImprove the description of big5(5)
Li-Wen Hsu [Sat, 14 Sep 2019 08:15:16 +0000 (08:15 +0000)]
Improve the description of big5(5)

- Fix the statement that big5 is a de facto standard of Traditional Chinese
  text [1]
- Add a BUGS section describes the problem of big5 and suggests use utf8

PR: 189095
Submitted by: Brennan Vincent <brennan@umanwizard.com> [1]
Reviewed by: Ting-Wei Lan <lantw44@gmail.com>
MFC after: 3 days
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D21622

4 years agolualoader: Add reload-conf loader command
Kyle Evans [Sat, 14 Sep 2019 03:38:18 +0000 (03:38 +0000)]
lualoader: Add reload-conf loader command

This command will trigger a reload of the configuration from disk. This is
useful if you've changed currdev from recovery media to local disk as much
as I have over the past ~2 hours and are tired of the extra keystrokes.

This is really just a glorified shortcut, but reload-conf is likely easier
to remember for other people and does save some keystrokes when reloading
the configuration. It is also resilient to the underlying config method
changing interface, but this is unlikely to happen.

MFC after: 1 week

4 years agopowerpc64/powernv: Add opal NVRAM driver for PowerNV systems
Justin Hibbits [Sat, 14 Sep 2019 03:30:34 +0000 (03:30 +0000)]
powerpc64/powernv: Add opal NVRAM driver for PowerNV systems

Add a very basic NVRAM driver for OPAL which can be used by the IBM
powerpc-utils nvram utility, not to be confused with the base nvram utility,
which only operates on powermac_nvram.

The IBM utility handles all partitions itself, treating the nvram device as
a plain store.

An alternative would be to manage partitions in the kernel, and augment the
base nvram utility to deal with different backing stores, but that
complicates the driver significantly.  Instead, present the same interface
IBM's utlity expects, and we get the usage for free.

Tested by: bdragon

4 years agoAdd a "count_until_fail" option to gnop, which says to start failing
Chuck Silvers [Fri, 13 Sep 2019 23:03:56 +0000 (23:03 +0000)]
Add a "count_until_fail" option to gnop, which says to start failing
I/O requests after the given number have been allowed though.

Approved by:    imp (mentor)
Reviewed by:    rpokala kib 0mp mckusick
Sponsored by:   Netflix
Differential Revision:  https://reviews.freebsd.org/D21593

4 years agoDrivers may pass runt packets to filter. This is okay.
Gleb Smirnoff [Fri, 13 Sep 2019 22:36:04 +0000 (22:36 +0000)]
Drivers may pass runt packets to filter. This is okay.

Reviewed by: gallatin

4 years agoInclude <stdint.h> in unwind-arm.h, since it uses uint32_t and uint64_t
Dimitry Andric [Fri, 13 Sep 2019 21:00:19 +0000 (21:00 +0000)]
Include <stdint.h> in unwind-arm.h, since it uses uint32_t and uint64_t
in various declarations.

Otherwise, depending on how unwind-arm.h is included from other source
files, the compiler may complain that uint32_t and uint64_t are unknown
types.

MFC after: 3 days

4 years agoAdd RELNOTES comment for r352304 discussing removing default mlock()
Cy Schubert [Fri, 13 Sep 2019 20:21:59 +0000 (20:21 +0000)]
Add RELNOTES comment for r352304 discussing removing default mlock()
for ntpd.

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

4 years agoNo longer mlock() ntpd pages by default in memory thus allowing its
Cy Schubert [Fri, 13 Sep 2019 20:20:05 +0000 (20:20 +0000)]
No longer mlock() ntpd pages by default in memory thus allowing its
pages to page as necessary.

To restore historic BSD behaviour add the following to ntp.conf:
rlimit memlock 32

Discussed on: freebsd-current@ between Sept 6-9, 2019
Reported by: Users using ASLR with stack gap != 0
Reviewed by: ian, kib, rgrimes (all previous versions)
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D21581

4 years agoriscv trap_pfault: remove unneeded hold of the process around vm_fault() call.
Konstantin Belousov [Fri, 13 Sep 2019 20:17:14 +0000 (20:17 +0000)]
riscv trap_pfault: remove unneeded hold of the process around vm_fault() call.

This is re-appearance of the nop code removed from other arches in r287625.

Reviewed by: alc (as part of the larger patch), markj
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
DIfferential revision: https://reviews.freebsd.org/D21645

4 years agoAdd support for Intel Stratix 10 platform.
Ruslan Bukin [Fri, 13 Sep 2019 16:50:57 +0000 (16:50 +0000)]
Add support for Intel Stratix 10 platform.

Intel Stratix 10 SoC includes a quad-core arm64 cluster and FPGA fabric.

This adds support for reconfiguring FPGA.

Accessing FPGA core of this SoC require the level of privilege EL3,
while kernel runs in EL1 (lower) level of privilege.

This provides an Intel service layer interface that uses SMCCC to pass
queries to the secure-monitor (EL3).

Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D21454

4 years agoAdd generic arm/arm64 secure-monitor SMCCC interface and switch
Ruslan Bukin [Fri, 13 Sep 2019 15:56:33 +0000 (15:56 +0000)]
Add generic arm/arm64 secure-monitor SMCCC interface and switch
PSCI code to use it.

This interface will also be used by Intel Stratix 10 platform.

This was not tested on arm due to lack of PSCI-enabled arm hardware
lying around.

Reviewed by: andrew
Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D21439

4 years agovfs: release usecount using fetchadd
Mateusz Guzik [Fri, 13 Sep 2019 15:49:04 +0000 (15:49 +0000)]
vfs: release usecount using fetchadd

1. If we release the last usecount we take ownership of the hold count, which
means the vnode will remain allocated until we vdrop it.
2. If someone else vrefs they will find no usecount and will proceed to add
their own hold count.
3. No code has a problem with v_usecount transitioning to 0 without the
interlock

These facts combined mean we can fetchadd instead of having a cmpset loop.

Reviewed by: kib (previous version)
Tested by: pho
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D21528

4 years agoRemove remnant from the pre LIBADD era
Baptiste Daroussin [Fri, 13 Sep 2019 14:51:00 +0000 (14:51 +0000)]
Remove remnant from the pre LIBADD era

4 years agoUpdate libedit to a snapshot from 2019-09-10
Baptiste Daroussin [Fri, 13 Sep 2019 06:50:02 +0000 (06:50 +0000)]
Update libedit to a snapshot from 2019-09-10

This version bring many fixes regarding unicode support
It also adds proper support for filename completion (we do not need our custom
patches anymore)
Improves the libreadline compatibility

Note that the same work was done by Yuichiro Naito in
https://reviews.freebsd.org/D21196 the main difference is in this case we have
reimported libedit in contrib to fix a long standing mess in the previous merges
which prevented a proper update workflow. (discussed long ago with pfg@)

The only difference with upstream libedit is we have added a compatibility shim
for the _elf_fn_sh_complete function which we previously added to support quoting
in filename completion and is not needed anymore.
This was added to continue supported old /bin/sh binaries and not break backward
compatibility (as discussed with jilles@)

Reviewed by: Yuichiro Naito <naito.yuichiro_gmail.com>
MFC after: 3 weeks
Differential Revision: https://reviews.freebsd.org/D21584

4 years agoInsert proper copyright/license headers
Baptiste Daroussin [Fri, 13 Sep 2019 06:36:24 +0000 (06:36 +0000)]
Insert proper copyright/license headers

Those scripts are without copyright and license assignement since their creation
After grabbing information from The various authors and contributors assign
proper license header and copyrights.

This has been reported by yuripv in his work on integrating those in Illumos!

Reported by: yuripv
Discussed with: marino, edwin
MFC after: 3 days

4 years agomtree -O: Fix not descending on hash collisions
Bryan Drewery [Thu, 12 Sep 2019 20:46:46 +0000 (20:46 +0000)]
mtree -O: Fix not descending on hash collisions

MFC after: 2 weeks
Obtained from: NetBSD (nakayama)

4 years ago[jail] removal by jid doesn't trigger pre/post stop scripts
Michael Zhilin [Thu, 12 Sep 2019 18:53:29 +0000 (18:53 +0000)]
[jail] removal by jid doesn't trigger pre/post stop scripts

This commit fixes bug: command "jail -r" didn't trigger pre/post stop
commands (and others) defined in config file if jid is specified insted of
name. Also it adds basic tests for usr.sbin/jail to avoid regression.

Reviewed by: jamie, kevans, ray
MFC after:      5 days
Differential Revision: https://reviews.freebsd.org/D21328

4 years agomtree -c: Fix username logic when getlogin(3) fails.
Bryan Drewery [Thu, 12 Sep 2019 18:51:59 +0000 (18:51 +0000)]
mtree -c: Fix username logic when getlogin(3) fails.

Obtained from: NetBSD (Credit to Sascha Wildner with DragonFlyBSD)
MFC after: 2 weeks

4 years agomtree: Fix -f -f not considering type changes.
Bryan Drewery [Thu, 12 Sep 2019 18:44:48 +0000 (18:44 +0000)]
mtree: Fix -f -f not considering type changes.

This only lists the changed type and not other attributes so that it
matches the behavior of -C as done in r66747 for fmtree. The NetBSD
-ff implementation was copied from fmtree.

Reviewed by: imp
MFC after: 2 weeks
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D21623

4 years ago[Bug 240473] add support of Ralink RT5390R Wireless Card
Michael Zhilin [Thu, 12 Sep 2019 18:37:26 +0000 (18:37 +0000)]
[Bug 240473] add support of Ralink RT5390R Wireless Card

This commit adds PCI ID of Ralink RT5390R into ids table of driver ral.
Tests show stability of card during day. Network speed is reasonable (
around several megabytes per second).

PR: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=240473
Reported by: zetrotrack000@gmail.com
Reviewed by: ray
Approved by: ray
MFC after: 5 days
Differential Revision:  https://reviews.freebsd.org/D21604

4 years agoarm64: connect Linuxulator to the build
Ed Maste [Thu, 12 Sep 2019 18:14:44 +0000 (18:14 +0000)]
arm64: connect Linuxulator to the build

More work needs to be done, but it is capable of running basic
statically or dynamically linked Linux/arm64 binaries.

Relnotes: Yes
Sponsored by: The FreeBSD Foundation

4 years agoRemove Tagged Command Queuing feature reporting.
Alexander Motin [Thu, 12 Sep 2019 17:42:37 +0000 (17:42 +0000)]
Remove Tagged Command Queuing feature reporting.

I never saw those devices myself, FreeBSD never supported them, and it is
officially obsolete since ACS-2 specification.

MFC after: 3 days

4 years agoReport Trusted Computing feature set support.
Alexander Motin [Thu, 12 Sep 2019 17:20:51 +0000 (17:20 +0000)]
Report Trusted Computing feature set support.

It practically means the device is SED.

MFC after: 3 days

4 years agoRemove a redundant NULL pointer check in cpuset_modify_domain().
Mark Johnston [Thu, 12 Sep 2019 16:47:38 +0000 (16:47 +0000)]
Remove a redundant NULL pointer check in cpuset_modify_domain().

cpuset_getroot() is guaranteed to return a non-NULL pointer.

Reported by: Mark Millard <marklmi@yahoo.com>
MFC after: 1 week
Sponsored by: The FreeBSD Foundation

4 years ago[PPC64] Add ifunc support in libcsu
Leandro Lupori [Thu, 12 Sep 2019 16:45:07 +0000 (16:45 +0000)]
[PPC64] Add ifunc support in libcsu

When ifuncs are used in statically linked binaries, the C runtime
must perform the needed dynamic relocations, to make calls to ifuncs
work correctly.

Reviewed by: jhibbits
Differential Revision: https://reviews.freebsd.org/D21070

4 years agoUse REFCOUNT_COUNT() to obtain refcount where appropriate.
Hans Petter Selasky [Thu, 12 Sep 2019 16:26:59 +0000 (16:26 +0000)]
Use REFCOUNT_COUNT() to obtain refcount where appropriate.
Refcount waiting will set some flag bits in the refcount value.
Make sure these bits get cleared by using the REFCOUNT_COUNT()
macro to obtain the actual refcount.

Differential Revision: https://reviews.freebsd.org/D21620
Reviewed by: kib@, markj@
MFC after: 1 week
Sponsored by: Mellanox Technologies

4 years agoUse %u instead of %d to print unsigned integer.
Hans Petter Selasky [Thu, 12 Sep 2019 16:20:03 +0000 (16:20 +0000)]
Use %u instead of %d to print unsigned integer.
While at it remove an empty line.

MFC after: 1 week
Sponsored by: Mellanox Technologies

4 years agoFix for undefined behaviour.
Hans Petter Selasky [Thu, 12 Sep 2019 15:57:49 +0000 (15:57 +0000)]
Fix for undefined behaviour.
Left shift of 1 by 31 places cannot be represented in type 'int'.

MFC after: 1 week
Sponsored by: Mellanox Technologies

4 years agoGet the readline header from the installed header instead of the from the source
Baptiste Daroussin [Thu, 12 Sep 2019 15:50:14 +0000 (15:50 +0000)]
Get the readline header from the installed header instead of the from the source
location.

4 years agoGet the readline header from the installed header instead of the from the source
Baptiste Daroussin [Thu, 12 Sep 2019 15:46:58 +0000 (15:46 +0000)]
Get the readline header from the installed header instead of the from the source
location.

With newer import of libedit, the path to be able to access readline/readline.h
will also include header which name will conflict with some expected by ntp in
another path and end up breaking the build.

4 years agoRemove useless extra definition of libedit flags
Baptiste Daroussin [Thu, 12 Sep 2019 15:44:53 +0000 (15:44 +0000)]
Remove useless extra definition of libedit flags

Note that all the line editor part is done in the libntp

4 years agoSIOCSIFNAME: Do nothing if we're not actually changing
Kyle Evans [Thu, 12 Sep 2019 15:36:48 +0000 (15:36 +0000)]
SIOCSIFNAME: Do nothing if we're not actually changing

Instead of throwing EEXIST, just succeed if the name isn't actually
changing. We don't need to trigger departure or any of that because there's
no change from consumers' perspective.

PR: 240539
Reviewed by: brooks
MFC after: 5 days
Differential Revision: https://reviews.freebsd.org/D21618

4 years agoFollow up r352244: kenv: tighten up assertions
Kyle Evans [Thu, 12 Sep 2019 14:34:46 +0000 (14:34 +0000)]
Follow up r352244: kenv: tighten up assertions

As I like to forget: static kenv var formatting is actually such that an
empty environment would be double null bytes. We should make sure that a
non-zero buffer has at least enough for this, though most of the current
usage is with a 4k buffer.

4 years agokenv: assert that an empty static buffer passed in is "empty"
Kyle Evans [Thu, 12 Sep 2019 13:51:43 +0000 (13:51 +0000)]
kenv: assert that an empty static buffer passed in is "empty"

Garbage in the passed-in buffer can cause problems if any attempts to read
the kenv are inadvertently made between init_static_kenv and the first
kern_setenv -- assuming there is one.

This is cheap and easy, so do it. This also helps rule out some class of
bugs as one tries to debug; tunables fetch from the static environment up
until SI_SUB_KMEM + 1, and many of these buffers are global ~4k buffers that
rely on BSS clearing while others just grab a page of free memory and use it
(e.g. xen).

4 years agoig4(4): Fix SDA HOLD time set too low on Skylake controllers
Vladimir Kondratyev [Thu, 12 Sep 2019 12:33:09 +0000 (12:33 +0000)]
ig4(4): Fix SDA HOLD time set too low on Skylake controllers

Execution of "Soft reset" command (IG4_REG_RESETS_SKL) at controller init
stage sets SDA_HOLD register value to 0x0001 which is often too low for
normal operation.

Set SDA_HOLD back to 28 after reset to restore controller functionality.

PR: 240339
Reported by: imp, GregV, et al.
MFC after: 3 days

4 years agoRemove usesless readline compat includes which will reinclude readline.h
Baptiste Daroussin [Thu, 12 Sep 2019 08:54:48 +0000 (08:54 +0000)]
Remove usesless readline compat includes which will reinclude readline.h
itself.

This simplifies the upcoming update to newer libedit.

4 years agoImport tzdata 2019c
Philip Paeps [Thu, 12 Sep 2019 00:19:16 +0000 (00:19 +0000)]
Import tzdata 2019c

Changes: https://github.com/eggert/tz/blob/2019c/NEWS

MFC after: 3 days

4 years agobuf: Add B_INVALONERR flag to discard data
Conrad Meyer [Wed, 11 Sep 2019 21:24:14 +0000 (21:24 +0000)]
buf: Add B_INVALONERR flag to discard data

Setting the B_INVALONERR flag before a synchronous write causes the buf
cache to forcibly invalidate contents if the write fails (BIO_ERROR).

This is intended to be used to allow layers above the buffer cache to make
more informed decisions about when discarding dirty buffers without
successful write is acceptable.

As a proof of concept, use in msdosfs to handle failures to mark the on-disk
'dirty' bit during rw mount or ro->rw update.

Extending this to other filesystems is left as future work.

PR: 210316
Reviewed by: kib (with objections)
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D21539

4 years agogetsockopt.2: clarify that SO_TIMESTAMP is not 100% reliable
Alan Somers [Wed, 11 Sep 2019 19:48:32 +0000 (19:48 +0000)]
getsockopt.2: clarify that SO_TIMESTAMP is not 100% reliable

When SO_TIMESTAMP is set, the kernel will attempt to attach a timestamp as
ancillary data to each IP datagram that is received on the socket. However,
it may fail, for example due to insufficient memory. In that case the
packet will still be received but not timestamp will be attached.

Reviewed by: kib
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D21607

4 years agofusefs: Fix iosize for FUSE_WRITE in 7.8 compat mode
Alan Somers [Wed, 11 Sep 2019 19:29:40 +0000 (19:29 +0000)]
fusefs: Fix iosize for FUSE_WRITE in 7.8 compat mode

When communicating with a FUSE server that implements version 7.8 (or older)
of the FUSE protocol, the FUSE_WRITE request structure is 16 bytes shorter
than normal. The protocol version check wasn't applied universally, leading
to an extra 16 bytes being sent to such servers. The extra bytes were
allocated and bzero()d, so there was no information disclosure.

Reviewed by: emaste
MFC after: 3 days
MFC-With: r350665
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D21557

4 years agoping: Verify whether a datagram timestamp was actually received.
Alan Somers [Wed, 11 Sep 2019 18:54:45 +0000 (18:54 +0000)]
ping: Verify whether a datagram timestamp was actually received.

ping(8) uses SO_TIMESTAMP, which attaches a timestamp to each IP datagram at
the time it's received by the kernel.  Except that occasionally it doesn't.
Add a check to see whether such a timestamp was actually set before trying
to read it.  This fixes segfaults that can happen when the kernel doesn't
attach a timestamp.

The bug has always existed, but prior to r351461 it manifested as an
implausible round-trip-time, not a segfault.

Reported by: pho
MFC after: 3 days
MFC-With: 351461