]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
3 years agoStop ignoring ERELOOKUP from VOP_INACTIVE()
Konstantin Belousov [Sat, 30 Jan 2021 19:17:29 +0000 (21:17 +0200)]
Stop ignoring ERELOOKUP from VOP_INACTIVE()

When possible, relock the vnode and retry inactivation.  Only vunref() is
required not to drop the vnode lock, so handle it specially by not retrying.

This is a part of the efforts to ensure that unlinked not referenced vnode
does not prevent inode from reusing.

Reviewed by: chs, mckusick
Tested by: pho
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation

3 years agoufs vnops: brace softdep_prelink() with DOINGSUJ instead of DOINGSOFTDEP
Konstantin Belousov [Sat, 23 Jan 2021 23:12:39 +0000 (01:12 +0200)]
ufs vnops: brace softdep_prelink() with DOINGSUJ instead of DOINGSOFTDEP

because softdep_prelink() is reverted to NOP for non-J case.  There is no
need to do anything before ufs_direnter() in SU/non-J case, everything
required to sync the directory is done in VOP_VPUT_PAIR().

Suggested by: mckusick
Reviewed by: chs, mckusick
Tested by: pho
MFC after: 2 week
Sponsored by: The FreeBSD Foundation

3 years agoffs softdep: remove will_direnter argument of softdep_prelink()
Konstantin Belousov [Sat, 23 Jan 2021 22:40:19 +0000 (00:40 +0200)]
ffs softdep: remove will_direnter argument of softdep_prelink()

Originally this was done in 8a1509e442bc9a075 to forcibly cover cases
where a hole in the directory could be created by extending into
indirect block, since dependency of writing out indirect block is not
tracked.  This results in excessive amount of fsyncing the directories,
where all creation of new entry forced fsync before it.  This is not needed,
it is enough to fsync when IN_NEEDSYNC is set, and VOP_VPUT_PAIR() provides
the required hook to only perform required syncing.

The series of changes culminating in this commit puts the performance of
metadata-intensive loads back to that before 8a1509e442bc9a075.

Analyzed by: mckusick
Reviewed by: chs, mckusick
Tested by: pho
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation

3 years agoufs_direnter: directory truncation does not need special case for rename
Konstantin Belousov [Fri, 29 Jan 2021 12:31:52 +0000 (14:31 +0200)]
ufs_direnter: directory truncation does not need special case for rename

In ufs_rename case, tdvp is locked from the place where ufs_direnter()
is done till VOP_VPUT_PAIR(), which means that we no longer need to specially
handle rename in ufs_direnter().  Truncation, if possible, is done in the
same way in ffs_vput_pair() both for rename and other VOPs calling
ufs_direnter().  Remove isrename argument and set IN_ENDOFF if
ufs_direnter() succeeded and directory needs truncation.

In ffs_vput_pair(), stop verifying the condition that directory needs
truncation when IN_ENDOFF is set, instead assert that the condition is
true.

Suggested by: mckusick
Reviewed by: chs, mckusick
Tested by: pho
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation

3 years agoufs_rename: use VOP_VPUT_PAIR and rely on directory sync/truncation there
Konstantin Belousov [Thu, 28 Jan 2021 13:34:56 +0000 (15:34 +0200)]
ufs_rename: use VOP_VPUT_PAIR and rely on directory sync/truncation there

Suggested by: mckusick
Reviewed by: chs, mckusick
Tested by: pho
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation

3 years agoufs_direnter: move directory truncation to ffs_vput_pair().
Konstantin Belousov [Wed, 27 Jan 2021 20:34:14 +0000 (22:34 +0200)]
ufs_direnter: move directory truncation to ffs_vput_pair().

VOP_VPUT_PAIR() provides the hook to do the truncation right before
unlock, which is required since truncation might need to fsync(), which
itself might unlock the directory vnode.

Set new flag IN_ENDOFF which indicates that i_endoff is valid and should
be checked against inode size. Excessive size is chomped, but this
operation is advisory and failure to truncate should not result in the
failure of the main VOP.

Reviewed by: chs, mckusick
Tested by: pho
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation

3 years agoffs_vput_pair(): try harder to recover from the vnode reclaim
Konstantin Belousov [Wed, 27 Jan 2021 18:10:51 +0000 (20:10 +0200)]
ffs_vput_pair(): try harder to recover from the vnode reclaim

In particular, if unlock_vp is false, save vp's inode number and
generation. If ffs_inotovp() can re-create the vnode with the same
number and generation after we finished with handling dvp, then we most
likely raced with unmount, and were able to restore atomicity of open.
We use FFSV_REPLACE_DOOMED there, to drop the old vnode.

This additional recovery is not strictly required, but it improves the
quality of the implementation.

Suggested by: mckusick
Reviewed by: chs, mckusick
Tested by: pho
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation

3 years agoFFS: implement special VOP_VPUT_PAIR().
Konstantin Belousov [Wed, 27 Jan 2021 18:09:53 +0000 (20:09 +0200)]
FFS: implement special VOP_VPUT_PAIR().

It cleans IN_NEEDSYNC flag on dvp before returning, by applying
ffs_syncvnode() until success or an error different from ERELOOKUP.
IN_NEEDSYNC cleanup is required to avoid creating holes in the directories
when extended into indirect block.

Reviewed by: chs, mckusick
Tested by: pho
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation

3 years agonfsserver: use VOP_VPUT_PAIR().
Konstantin Belousov [Sun, 24 Jan 2021 13:02:27 +0000 (15:02 +0200)]
nfsserver: use VOP_VPUT_PAIR().

Apply VOP_VPUT_PAIR() to the end of vnode operations after the
VOP_MKNOD(), VOP_MKDIR(), VOP_LINK(), VOP_SYMLINK(), VOP_CREATE().

Reviewed by: chs, mckusick
Tested by: pho
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation

3 years agoffs_snapshot: use VOP_VPUT_PAIR after VOP_CREATE.
Konstantin Belousov [Sun, 24 Jan 2021 13:56:05 +0000 (15:56 +0200)]
ffs_snapshot: use VOP_VPUT_PAIR after VOP_CREATE.

If the snapshot embrio was reclaimed under us, return error outright.

Reviewed by: chs, mckusick
Tested by: pho
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation

3 years agoUse VOP_VPUT_PAIR() for eligible VFS syscalls.
Konstantin Belousov [Thu, 28 Jan 2021 22:31:30 +0000 (00:31 +0200)]
Use VOP_VPUT_PAIR() for eligible VFS syscalls.

The current list is limited to the cases where UFS needs to handle
vput(dvp) specially. Which means VOP_CREATE(), VOP_MKDIR(), VOP_MKNOD(),
VOP_LINK(), and VOP_SYMLINK().

Reviewed by: chs, mkcusick
Tested by: pho
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation

3 years agonullfs: provide special bypass for VOP_VPUT_PAIR
Konstantin Belousov [Sun, 24 Jan 2021 13:22:48 +0000 (15:22 +0200)]
nullfs: provide special bypass for VOP_VPUT_PAIR

Generic bypass cannot understand the rules of liveness for the VOP.

Reviewed by: chs, mckusick
Tested by: pho
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation

3 years agoAdd VOP_VPUT_PAIR() with trivial default implementation.
Konstantin Belousov [Thu, 28 Jan 2021 22:30:53 +0000 (00:30 +0200)]
Add VOP_VPUT_PAIR() with trivial default implementation.

The VOP is intended to be used in situations where VFS has two
referenced locked vnodes, typically a directory vnode dvp and a vnode
vp that is linked from the directory, and at least dvp is vput(9)ed.
The child vnode can be also vput-ed, but optionally left referenced and
locked.

There, at least UFS may need to do some actions with dvp which cannot be
done while vp is also locked, so its lock might be dropped temporary.
For instance, in some cases UFS needs to sync dvp to avoid filesystem
state that is currently not handled by either kernel nor fsck. Having
such VOP provides the neccessary context for filesystem which can do
correct locking and handle potential reclamation of vp after relock.

Trivial implementation does vput(dvp) and optionally vput(vp).

Reviewed by: chs, mckusick
Tested by: pho
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation

3 years agovn_open(): If the vnode is reclaimed during open(2), do not return error.
Konstantin Belousov [Wed, 3 Feb 2021 11:02:18 +0000 (13:02 +0200)]
vn_open(): If the vnode is reclaimed during open(2), do not return error.

Most future operations on the returned file descriptor will fail
anyway, and application should be ready to handle that failures.  Not
forcing it to understand the transient failure mode on open, which is
implementation-specific, should make us less special without loss of
reporting of errors.

Suggested by: chs
Reviewed by: chs, mckusick
Tested by: pho
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation

3 years agoufs_direnter/SU: unconditionally UFS_UPDATE inode when extending directory
Konstantin Belousov [Sat, 23 Jan 2021 21:52:10 +0000 (23:52 +0200)]
ufs_direnter/SU: unconditionally UFS_UPDATE inode when extending directory

for all kinds of async/SU mount variants.

Submitted by: mckusick
Reviewed by: chs
Tested by: pho
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation

3 years agoffs_syncvnode: only clear IN_NEEDSYNC after successfull sync
Konstantin Belousov [Sat, 23 Jan 2021 21:50:55 +0000 (23:50 +0200)]
ffs_syncvnode: only clear IN_NEEDSYNC after successfull sync

If it is cleaned before the sync, other threads might see the inode without
the flag set, because syncing could unlock it.

Reviewed by: chs, mckusick
Tested by: pho
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation

3 years agoMerge ufs_fhtovp() into ffs_inotovp().
Konstantin Belousov [Thu, 28 Jan 2021 12:20:48 +0000 (14:20 +0200)]
Merge ufs_fhtovp() into ffs_inotovp().

The function alone was not used for anything but ffs_fstovp() for long time.

Suggested by: mckusick
Reviewed by: chs, mckusick
Tested by: pho
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation

3 years agoffs_inotovp(): interface to convert (ino, gen) into alive vnode
Konstantin Belousov [Tue, 26 Jan 2021 11:52:59 +0000 (13:52 +0200)]
ffs_inotovp(): interface to convert (ino, gen) into alive vnode

It generalizes the VFS_FHTOVP() interface, making it possible to fetch
the inode without faking filehandle.  Also it adds the ffs flags argument
which allows to control ffs_vgetf() call.

Requested by: mckusick
Reviewed by: chs, mckusick
Tested by: pho
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation

3 years agoffs: Add FFSV_REPLACE_DOOMED flag to ffs_vgetf()
Konstantin Belousov [Tue, 26 Jan 2021 11:35:21 +0000 (13:35 +0200)]
ffs: Add FFSV_REPLACE_DOOMED flag to ffs_vgetf()

It specifies that caller requests a fresh non-doomed vnode.  If doomed
vnode is found in the hash, it should behave similarly to FFSV_REPLACE.
Or, to put it differently, the flag is same as FFSV_REPLACE, but only
when the found hashed vnode is doomed.

Reviewed by: chs, mkcusick
Tested by: pho
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation

3 years agoffs: call ufsdirhash_dirtrunc() right after setting directory size
Konstantin Belousov [Thu, 28 Jan 2021 18:33:58 +0000 (20:33 +0200)]
ffs: call ufsdirhash_dirtrunc() right after setting directory size

Later processing of ffs_truncate() might temporary unlock the directory
vnode, causing unsychronized dirhash and inode sizes if update is
postponed to UFS_TRUNCATE() callers.

Reviewed by: chs, mkcusick
Tested by: pho
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation

3 years agobuf SU hooks: track buf_start() calls with B_IOSTARTED flag
Konstantin Belousov [Sat, 30 Jan 2021 02:10:34 +0000 (04:10 +0200)]
buf SU hooks: track buf_start() calls with B_IOSTARTED flag

and only call buf_complete() if previously started.  Some error paths,
like CoW failire, might skip buf_start() and do bufdone(), which itself
call buf_complete().

Various SU handle_written_XXX() functions check that io was started
and incomplete parts of the buffer data reverted before restoring them.
This is a useful invariant that B_IO_STARTED on buffer layer allows to
keep instead of changing check and panic into check and return.

Reported by: pho
Reviewed by: chs, mckusick
Tested by: pho
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundations

3 years agoffs_vnops.c: Move opt_*.h includes to the top.
Konstantin Belousov [Thu, 28 Jan 2021 18:30:35 +0000 (20:30 +0200)]
ffs_vnops.c: Move opt_*.h includes to the top.

as it is done in other places.  Header files might need options defined
for correct operation.

Reviewed by: chs, mckusick
Tested by: pho
Sponsored by: The FreeBSD Foundation
MFC after: 1 week

3 years agopkg(7): address minor nits (mostly clang-analyze complaints)
Kyle Evans [Fri, 12 Feb 2021 00:58:27 +0000 (18:58 -0600)]
pkg(7): address minor nits (mostly clang-analyze complaints)

- One (1) spurious whitespace.
- One (1) occurrence of "random(3) bad, arc4random(3)" good.
- Three (3) writes that will never be seen.

The latter two points are complaints from clang-analyze. Switching to
arc4random(3) is decidedly a good idea because we weren't doing any kind
of PRNG seeding anyways. The discarded assignments are arguably good
for future-proofing, but it's better to improve the S/N ratio from
clang-analyze.

Reviewed by: bapt, manu
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D28525

3 years agopkg(7): add an -r reponame option for bootstrap and add
Kyle Evans [Fri, 12 Feb 2021 00:58:26 +0000 (18:58 -0600)]
pkg(7): add an -r reponame option for bootstrap and add

This is limited to bootstrap/add because some real pkg(8) commands
have -r flags with an incompatible meaning/usage, e.g., pkg-audit.
pkg(7) will still commence the search as it has, but it will ignore any
repo objects without the given name so that overrides and whatnot still
work as expected.

The use of it for add is noted in the manpage; notably, that the
signature config for that repository will be used over global config if
it's specified. i.e., pkg(7) should assume that the given pkg did come
from that repository and treat it appropriately.

Reviewed by: bapt, manu
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D28524

3 years agoyacc: Regen test cases for the previous commit
Jung-uk Kim [Thu, 11 Feb 2021 23:41:28 +0000 (18:41 -0500)]
yacc: Regen test cases for the previous commit

3 years agoyacc: Use NULL instead of 0 for pointers
Jung-uk Kim [Thu, 11 Feb 2021 23:40:00 +0000 (18:40 -0500)]
yacc: Use NULL instead of 0 for pointers

Note araujo tried to fix it in r298241 but he only touched generated
files for bootstrap.  This commit properly fixes the problem.

3 years agolex: Use NULL instead of 0 for pointers
Jung-uk Kim [Thu, 11 Feb 2021 23:31:53 +0000 (18:31 -0500)]
lex: Use NULL instead of 0 for pointers

Note araujo tried to fix it in r298241 but he only touched generated
files for bootstrap.  This commit properly fixes the problem.

3 years agoefibootmgr: Check for efi supported after parsing args
Warner Losh [Thu, 11 Feb 2021 23:06:30 +0000 (16:06 -0700)]
efibootmgr: Check for efi supported after parsing args

Move the check for efi variables being supported to after parsing the args. This
allows '-h' to produce both as a normal user as well as on all systems.

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
MFC after: 1 week

3 years agocam: Properly find the sim in the assertion in xpt_pollwait().
John Baldwin [Mon, 8 Feb 2021 23:02:14 +0000 (15:02 -0800)]
cam: Properly find the sim in the assertion in xpt_pollwait().

I had missed merging this fixup into
447b3557a9cc5f00a301be8404339f21a9a0faa8 before pushing it.

Pointy hat to: jhb
MFC after: 2 weeks

3 years agoiscsi: Mark iSCSI CAM sims as non-pollable.
John Baldwin [Thu, 11 Feb 2021 21:51:20 +0000 (13:51 -0800)]
iscsi: Mark iSCSI CAM sims as non-pollable.

Previously, iscsi_poll() just panicked.  This meant if you got a panic
on a box when using the iSCSI initiator, the attempt to shutdown would
trigger a nested panic and never write out a core.  Now, CCB's sent to
iSCSI devices (such as the sychronize-cache request in dashutdown())
just fail with a timeout during a panic shutdown.

Reviewed by: scottl, mav
MFC after: 2 weeks
Sponsored by: Chelsio
Differential Revision: https://reviews.freebsd.org/D28455

3 years agocam: Don't permit crashdumps on non-pollable devices.
John Baldwin [Thu, 11 Feb 2021 21:51:01 +0000 (13:51 -0800)]
cam: Don't permit crashdumps on non-pollable devices.

If a disk's SIM doesn't support polling, then it can't be used to
store crashdumps.  Leave d_dump NULL in that case so that dumpon(8)
fails gracefully rather than having dumps fail at crash time.

Reviewed by: scottl, mav, imp
MFC after: 2 weeks
Sponsored by: Chelsio
Differential Revision: https://reviews.freebsd.org/D28454

3 years agocam: Permit non-pollable sims.
John Baldwin [Thu, 11 Feb 2021 21:49:43 +0000 (13:49 -0800)]
cam: Permit non-pollable sims.

Some CAM sim drivers do not support polling (notably iscsi(4)).
Rather than using a no-op poll routine that always times out requests,
permit a SIM to set a NULL poll callback.  cam_periph_runccb() will
fail polled requests non-pollable sims immediately as if they had
timed out.

Reviewed by: scottl, mav (earlier version)
Reviewed by: imp
MFC after: 2 weeks
Sponsored by: Chelsio
Differential Revision: https://reviews.freebsd.org/D28453

3 years agoWiden ifnet_detach_sxlock coverage
Kristof Provost [Mon, 8 Feb 2021 09:04:27 +0000 (10:04 +0100)]
Widen ifnet_detach_sxlock coverage

Widen the ifnet_detach_sxlock to cover the entire vnet sysuninit code.
This ensures that we can't end up having the vnet_sysuninit free the UDP
pcb while the detach code is running and trying to purge the UDP pcb.

MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D28530

3 years agorelease.sh: fix OSVERSION and UNAME_r overrides
Glen Barber [Thu, 11 Feb 2021 15:46:38 +0000 (10:46 -0500)]
release.sh: fix OSVERSION and UNAME_r overrides

Add PBUILD_FLAGS and UNAME_r overrides to extra_chroot_setup()
to fix building ports for 14-CURRENT builds on 13.x.

MFC after: 3 days
MFC with: c511a5ab53ba335dc85f7ac93843872eb5763602
Sponsored by: Rubicon Communications, LLC ("Netgate")

3 years agomlx4, mthca: Silence warnings about no-op alignment operations
Mark Johnston [Thu, 11 Feb 2021 15:16:59 +0000 (10:16 -0500)]
mlx4, mthca: Silence warnings about no-op alignment operations

Since commit 8fa6abb6f4f64f ("Expose clang's alignment builtins and use
them for roundup2/rounddown2"), clang emits warnings for several
alignment operations in these drivers because the operation is a no-op.
The compiler is arguably being too strict here, but in the meantime
let's silence the warnings by conditionally compiling the alignment
operations.

Reviewed by: arichardson, hselasky
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D28576

3 years agoVOP_ADVLOCK(9): fix a typo
Guangyuan Yang [Thu, 11 Feb 2021 00:25:58 +0000 (00:25 +0000)]
VOP_ADVLOCK(9): fix a typo

Submitted by: Ka Ho Ng <khng300@gmail.com>
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D28575

3 years agoFix lib/msun/test builds on platforms without 80-bit long doubles
Dimitry Andric [Thu, 11 Feb 2021 11:01:10 +0000 (12:01 +0100)]
Fix lib/msun/test builds on platforms without 80-bit long doubles

After d3338f3355a612cf385632291f46c5777bba8d18, the lib/msun test case
'hypotl_near_underflow' would fail to compile on platforms where long
doubles weren't 80 bit, like on x86. Disable this particular test on
such platforms for now.

PR: 253313
MFC after: 1 week
X-MFC-With:     d3338f3355a612cf385632291f46c5777bba8d18

3 years ago[udp] fix possible mbuf and lock leak in udp_input().
Andrey V. Elsukov [Thu, 11 Feb 2021 08:55:39 +0000 (11:55 +0300)]
[udp] fix possible mbuf and lock leak in udp_input().

In error case we can leave `inp' locked, also we need to free
mbuf chain `m' in the same case. Release the lock and use `badunlocked'
label to exit with freed mbuf. Also modify UDP error statistic to
match the IPv6 code.

Remove redundant INP_RUNLOCK() from the `if (last == NULL)' block,
there are no ways to reach this point with locked `inp'.

Obtained from: Yandex LLC
MFC after: 3 days
Sponsored by: Yandex LLC

3 years ago[udp6] fix possible panic due to lack of locking.
Andrey V. Elsukov [Thu, 11 Feb 2021 08:38:41 +0000 (11:38 +0300)]
[udp6] fix possible panic due to lack of locking.

The lookup for a IPv6 multicast addresses corresponding to
the destination address in the datagram is protected by the
NET_EPOCH section. Access to each PCB is protected by INP_RLOCK
during comparing. But access to socket's so_options field is
not protected. And in some cases it is possible, that PCB
pointer is still valid, but inp_socket is not. The patch wides
lock holding to protect access to inp_socket. It copies locking
strategy from IPv4 UDP handling.

PR: 232192
Obtained from: Yandex LLC
MFC after: 3 days
Sponsored by: Yandex LLC
Differential Revision: https://reviews.freebsd.org/D28232

3 years agoMerge bmake-20210206
Simon J. Gerraty [Thu, 11 Feb 2021 06:01:59 +0000 (22:01 -0800)]
Merge bmake-20210206

Changes of interest

  o unit-tests: use private TMPDIR to avoid errors from other users
  o avoid strdup in mkTempFile
  o always use vfork
  o job.c: do not create empty shell files in jobs mode
    reduce unnecessary calls to waitpid
  o cond.c: fix debug output for comparison operators in conditionals

3 years agokldload(8): Improve phrasing
Daniel Ebdrup Jensen [Thu, 11 Feb 2021 05:01:49 +0000 (06:01 +0100)]
kldload(8): Improve phrasing

Mountroot isn't documented in the extant manual pages - so this
phrasing, while less absolute and concise, still conveys which
modules are recommended to be handled via loader.conf(5), and it also
does a better job of elucidating that the modules can include filesystem
drivers.

Submitted by: kevans (earlier version)
Reported by: imp, kevans, eugen
Reviewed by: kevans
Differential Revision: https://reviews.freebsd.org/D28542

3 years agousleep(3): replace 'process' with 'calling thread'
Konstantin Belousov [Thu, 11 Feb 2021 03:49:25 +0000 (05:49 +0200)]
usleep(3): replace 'process' with 'calling thread'

PR: 253395
Reported by: zegang.luo@qq.com
MFC after: 3 days
Sponsored by: The FreeBSD Foundation

3 years agorelease: fix overriding UNAME_r
Glen Barber [Thu, 11 Feb 2021 02:23:58 +0000 (21:23 -0500)]
release: fix overriding UNAME_r

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

3 years agoImport bmake-20210206
Simon J. Gerraty [Thu, 11 Feb 2021 01:51:11 +0000 (17:51 -0800)]
Import bmake-20210206

Changes of interest

  o unit-tests: use private TMPDIR to avoid errors from other users
  o avoid strdup in mkTempFile
  o always use vfork
  o job.c: do not create empty shell files in jobs mode
    reduce unnecessary calls to waitpid
  o cond.c: fix debug output for comparison operators in conditionals

3 years agoFix incorrect hypotl(3) result with subnormal numbers
Dimitry Andric [Wed, 10 Feb 2021 22:28:43 +0000 (23:28 +0100)]
Fix incorrect hypotl(3) result with subnormal numbers

This adjusts the factor used to scale the subnormal numbers, so it
becomes the right value after adjusting its exponent. Thanks to Steve
Kargl for finding the most elegant fix.

Also enable the hypot tests, and add a test case for this bug.

PR: 253313
MFC after: 1 week

3 years agoarm64: if_dwc is also needed by intel stratix10 platform
Emmanuel Vadot [Thu, 4 Feb 2021 16:07:17 +0000 (17:07 +0100)]
arm64: if_dwc is also needed by intel stratix10 platform

MFC after: 3 days

3 years agoarm64: Add a SOC_BRCM_NS2 option
Emmanuel Vadot [Thu, 4 Feb 2021 14:40:54 +0000 (15:40 +0100)]
arm64: Add a SOC_BRCM_NS2 option

Only compile files needed for this platform if the option is enabled in the
kernel config file.
Add the option to GENERIC.

MFC after: 3 days

3 years agoarm64: Make thunderx vnic file depend on soc_cavm_thunderx
Emmanuel Vadot [Thu, 4 Feb 2021 14:31:23 +0000 (15:31 +0100)]
arm64: Make thunderx vnic file depend on soc_cavm_thunderx

MFC after: 3 days

3 years agoarm64: Order sys/conf/files.arm64
Emmanuel Vadot [Thu, 4 Feb 2021 13:54:22 +0000 (14:54 +0100)]
arm64: Order sys/conf/files.arm64

This is now easier to read and see what's compiled-in

No functional changes intended.

MFC after: 3 days

3 years agonetgraph/ng_bridge: Add counters for the first link, too
Lutz Donnerhacke [Wed, 10 Feb 2021 10:47:38 +0000 (11:47 +0100)]
netgraph/ng_bridge: Add counters for the first link, too

For broadcast, multicast and unknown unicast, the replication loop
sends a copy of the packet to each link, beside the first one. This
special path is handled later, but the counters are not updated.
Factor out the common send and count actions as a function.

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

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

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

MFC after: 1 week

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

They are no longer supported by mdoc(7).

MFC after: 1 week

3 years agolocaledef: Fix bootstrapping on Ubuntu 16.04
Jessica Clarke [Wed, 10 Feb 2021 16:41:35 +0000 (16:41 +0000)]
localedef: Fix bootstrapping on Ubuntu 16.04

Glibc's stdlib.h defines various prototypes for GNU extensions that take
a locale_t. Newer versions use locale_t directly and include an internal
bits/types/locale_t.h in order to get its definition, but older versions
include xlocale.h for that, for which our bootstrap version is empty.
Moreover it expects to use the glibc-specific __locale_t type. Thus,
provide dummy definitions of both types in order to ensure the
prototypes don't give any errors, and guard against the header being
inadvertently included between the bootstrapping namespace.h and
un-namespace.h, where locale_t is #define'd.

This header is not used when bootstrapping on FreeBSD and exists solely
to stub out glibc's, so this should have no impact on FreeBSD hosts.

Reviewed by: arichardson, emaste (comment only)
Differential Revision: https://reviews.freebsd.org/D28317

3 years agovm: Honour the "noreuse" flag to vm_page_unwire_managed()
Mark Johnston [Wed, 10 Feb 2021 16:10:27 +0000 (11:10 -0500)]
vm: Honour the "noreuse" flag to vm_page_unwire_managed()

This flag indicates that the page should be enqueued near the head of
the inactive queue, skipping the LRU queue.  It is used when unwiring
pages from the buffer cache following direct I/O or after I/O when
POSIX_FADV_NOREUSE or _DONTNEED advice was specified, or when
sendfile(SF_NOCACHE) completes.  For the direct I/O and sendfile cases
we only enqueue the page if we decide not to free it, typically because
it's mapped.

Pass "noreuse" through to vm_page_release_toq() so that we actually
honour the desired LRU policy for these scenarios.

Reported by: bdrewery
Reviewed by: alc, kib
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D28555

3 years agoAlways build the sanitizer runtimes when compiling with clang
Alex Richardson [Wed, 10 Feb 2021 15:25:14 +0000 (15:25 +0000)]
Always build the sanitizer runtimes when compiling with clang

This allows instrumenting e.g. test binaries even when compiling with an
external clang (e.g. CROSS_TOOLCHAIN=llvm11). I have some upcoming patches
that allow building the entire base system with ASan/UBSan/etc.
instrumentation and this is required in preparation for this.

Reviewed By: dim, emaste
Differential Revision: https://reviews.freebsd.org/D28532

3 years agousr.sbin/makefs: fix use-after-free in read_mtree_keywords()
Alex Richardson [Wed, 10 Feb 2021 15:23:23 +0000 (15:23 +0000)]
usr.sbin/makefs: fix use-after-free in read_mtree_keywords()

The st variable is used as a shortcut for &node->inode->st, but in one
branch just before the exit we update node->inode without changing st.

Reported by: AddressSanitizer
Reviewed By: emaste
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D28570

3 years agoMFV d60fa10fd872db7e3d8cb1e161cfdae026c43b14:
Cy Schubert [Wed, 10 Feb 2021 04:25:05 +0000 (20:25 -0800)]
MFV d60fa10fd872db7e3d8cb1e161cfdae026c43b14:

Update unbound 1.13.0 --> 1.13.1.

Includes numerous bugfixes documented at:
https://www.nlnetlabs.nl/projects/unbound/download/#unbound-1-13-1

MFC after: 1 month

3 years agoFix non-IPv6 build post 57785538c6e0d7e8ca0f161ab95bae10fd304047.
Cy Schubert [Wed, 10 Feb 2021 01:13:01 +0000 (17:13 -0800)]
Fix non-IPv6 build post 57785538c6e0d7e8ca0f161ab95bae10fd304047.

57785538c6e0d7e8ca0f161ab95bae10fd304047 change the test for FreeBSD
from __FreeBSD_version to __FreeBSD__. However this test was performed
before sys/param.h was included, therefore __FreeBSD_version was never
defined. As the test was never true opt_random_ip_id.h was never included.

Submitted by: bdragon
Reported by: bdragon
MFC after: 1 week
X-MFC with: 57785538c6e0d7e8ca0f161ab95bae10fd304047

3 years agolibsysdecode: fix decoding of TCP_NOPUSH and TCP_MD5SIG
Michael Tuexen [Tue, 9 Feb 2021 22:35:55 +0000 (23:35 +0100)]
libsysdecode: fix decoding of TCP_NOPUSH and TCP_MD5SIG

TCP_FASTOPEN_MIN_COOKIE_LEN was incorrectly registered as a name of
a IPPROTO_TCP level socket option, which overwrote TCP_NOPUSH.
TCP_FASTOPEN_PSK_LEN was incorrectly registered as a name of an
IPPROTO_TCP level socket option, which overwrote TCP_MD5SIG.

MFC after: 3 days
Sponsored by: Netflix, Inc.

3 years agoAdd test case for 93fc67896550 (incorrect powf(3) result)
Dimitry Andric [Tue, 9 Feb 2021 22:37:08 +0000 (23:37 +0100)]
Add test case for 93fc67896550 (incorrect powf(3) result)

This adds the test case to contrib/netbsd-tests/lib/libm/t_pow.c, as it
is currently the only place testing pow(3) and friends.

MFC after: 1 week

3 years agobsd.compiler.mk: Detect distribution-provided GCC when executed as cc
Jessica Clarke [Tue, 9 Feb 2021 21:40:24 +0000 (21:40 +0000)]
bsd.compiler.mk: Detect distribution-provided GCC when executed as cc

Clang always prints "clang $VERSION" regardless of the name used to
execute it, whereas GCC prints "$progname $VERSION", meaning if CC is
set to cc and cc is GCC it will print "cc $VERSION". We are able to
detect some of those cases since it then prints "($PKGVERSION)", where
the default is "GCC", but many distributions override that to print
their name and the package version number (e.g. "Debian 10.2.1-6"), so
nothing tells us it's GCC other than the fact that it's not Clang (and
that there's an FSF copyright disclaimer).

However, GCC's -v option will always print "gcc version $VERSION", so
fall back on using that to detect GCC. Whilst Clang also supports this
option, we should never get here, so Clang handling is not added.

Reviewed by: brooks, emaste, arichardson
Differential Revision: https://reviews.freebsd.org/D28315

3 years agoFix lib/msun's ctrig_test/test_inf_inputs test case with clang >= 10
Dimitry Andric [Tue, 9 Feb 2021 21:06:51 +0000 (22:06 +0100)]
Fix lib/msun's ctrig_test/test_inf_inputs test case with clang >= 10

This sprinkles a few strategic volatiles in an attempt to defeat clang's
optimization interfering with the expected floating-point exception
flags.

Reported by: lwhsu
PR: 244732
MFC after: 3 days

3 years agoVendor import of Unbound 1.13.1.
Cy Schubert [Tue, 9 Feb 2021 20:59:02 +0000 (12:59 -0800)]
Vendor import of Unbound 1.13.1.

Includes numerous bugfixes documented at:
https://www.nlnetlabs.nl/projects/unbound/download/#unbound-1-13-1

3 years agonetgraph/ng_bridge: Document staleness in multithreaded operation
Lutz Donnerhacke [Tue, 9 Feb 2021 11:32:46 +0000 (12:32 +0100)]
netgraph/ng_bridge: Document staleness in multithreaded operation

In the data path of ng_bridge(4), the only value of the host struct,
which needs to be modified, is the staleness, which is reset every
time a frame is received.  It's save to leave the code as it is.

This patch is part of a series to make ng_bridge(4) multithreaded.

Reviewed by: kp
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D28546

3 years agonetgraph/ng_bridge: Merge internal structures
Lutz Donnerhacke [Mon, 8 Feb 2021 21:36:46 +0000 (22:36 +0100)]
netgraph/ng_bridge: Merge internal structures

In a earlier version of ng_bridge(4) the exernal visible host entry
structure was a strict subset of the internal one.  So internal view
was a direct annotation of the external structure.  This strict
inheritance was lost many versions ago.  There is no need to
encapsulate a part of the internal represntation as a separate
structure.

This patch is a preparation to make the internal structure read only
in the data path in order to make ng_bridge(4) multithreaded.

Reviewed by: kp
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D28545

3 years agoSet file mode during zfs_write
Antonio Russo [Mon, 8 Feb 2021 17:15:05 +0000 (10:15 -0700)]
Set file mode during zfs_write

Apply https://github.com/openzfs/zfs/pull/11576

Direct commit from upstream openzfs. Full commit message below:

Set file mode during zfs_write

3d40b65 refactored zfs_vnops.c, which shared much code verbatim between
Linux and BSD.  After a successful write, the suid/sgid bits are reset,
and the mode to be written is stored in newmode.  On Linux, this was
propagated to both the in-memory inode and znode, which is then updated
with sa_update.

3d40b65 accidentally removed the initialization of newmode, which
happened to occur on the same line as the inode update (which has been
moved out of the function).

The uninitialized newmode can be saved to disk, leading to a crash on
stat() of that file, in addition to a merely incorrect file mode.

Reviewed-by: Ryan Moeller <ryan@ixsystems.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Antonio Russo <aerusso@aerusso.net>
Closes #11474
Closes #11576

Obtained from: openzfs/zfs@f8ce8aed0
MFC after: 0 days
Sponsored by: iXsystems, Inc.

3 years agousr.bin/grep: Fix Address OOB read error
Alex Richardson [Tue, 19 Jan 2021 11:35:07 +0000 (11:35 +0000)]
usr.bin/grep: Fix Address OOB read error

I found this when compiling all the bootstrap tools with -fsanitize=addres:

==65590==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x62d000008400 at pc 0x000000473053 bp 0x7ffc1c7dd910 sp 0x7ffc1c7dd0b8
READ of size 32769 at 0x62d000008400 thread T0
    #0 0x473052 in regexec (/local/scratch/alr48/cheri/build/freebsd-amd64-build/local/scratch/alr48/cheri/freebsd/amd64.amd64/tmp/legacy/bin/grep+0x473052)
    #1 0x4c9cf3 in procline /local/scratch/alr48/cheri/freebsd/usr.bin/grep/util.c:539:8
    #2 0x4c8687 in procfile /local/scratch/alr48/cheri/freebsd/usr.bin/grep/util.c:379:18
    #3 0x4c6596 in main /local/scratch/alr48/cheri/freebsd/usr.bin/grep/grep.c:714:8

0x62d000008400 is located 0 bytes to the right of 32768-byte region [0x62d000000400,0x62d000008400)
allocated by thread T0 here:
    #0 0x493d5d in malloc (/local/scratch/alr48/cheri/build/freebsd-amd64-build/local/scratch/alr48/cheri/freebsd/amd64.amd64/tmp/legacy/bin/grep+0x493d5d)
    #1 0x4cad75 in grep_malloc /local/scratch/alr48/cheri/freebsd/usr.bin/grep/util.c:656:13
    #2 0x4c8129 in procfile /local/scratch/alr48/cheri/freebsd/usr.bin/grep/util.c
    #3 0x4c6596 in main /local/scratch/alr48/cheri/freebsd/usr.bin/grep/grep.c:714:8

SUMMARY: AddressSanitizer: heap-buffer-overflow (/local/scratch/alr48/cheri/build/freebsd-amd64-build/local/scratch/alr48/cheri/freebsd/amd64.amd64/tmp/legacy/bin/grep+0x473052) in regexec

Reviewed By: kevans
MFC after: 1 week

3 years agocache: assorted comment fixups
Mateusz Guzik [Tue, 9 Feb 2021 16:06:27 +0000 (17:06 +0100)]
cache: assorted comment fixups

3 years agoRevert "amd64: implement strlen in assembly"
Mateusz Guzik [Tue, 9 Feb 2021 15:18:58 +0000 (16:18 +0100)]
Revert "amd64: implement strlen in assembly"

This reverts commit af366d353b84bdc4e730f0fc563853abc338271c.

Trips over '\xa4' byte and terminates early, as found in
lib/libc/gen/setdomainname_test:setdomainname_basic testcase

However, keep moving libkern/strlen.c out of conf/files.

Reported by: lwhsu

3 years agoarm32: Align arguments of sync_icache() syscall to cacheline size.
Michal Meloun [Tue, 9 Feb 2021 10:36:36 +0000 (11:36 +0100)]
arm32: Align arguments of sync_icache() syscall to cacheline size.

Otherwise, we may miss synchronization of the last cacheline.
MFC after: 3 days

3 years agoloader: do not autoselect smaller font than 8x16 with high res display
Toomas Soome [Mon, 8 Feb 2021 22:34:47 +0000 (00:34 +0200)]
loader: do not autoselect smaller font than 8x16 with high res display

The VT screen buffer size is calculated based on our default
built in (8x16) font.

With high-resolution display, we want to use at least 8x16 font,
or we will have large unused areas on screen.

MFC after: 1 week

3 years agoloader: remove BORDER_PIXELS
Toomas Soome [Mon, 8 Feb 2021 18:49:09 +0000 (20:49 +0200)]
loader: remove BORDER_PIXELS

BORDER_PIXELS is left over from picking up the source from illumos
port. Since FreeBSD VT does not use border in terminal size
calculation, there is no reason why should loader use it.

MFC after: 1 week

3 years agokern: sonewconn: set so_options before pru_attach()
Kyle Evans [Wed, 20 Jan 2021 17:53:05 +0000 (11:53 -0600)]
kern: sonewconn: set so_options before pru_attach()

Protocol attachment has historically been able to observe and modify
so->so_options as needed, and it still can for newly created sockets.
779f106aa169 moved this to after pru_attach() when we re-acquire the
lock on the listening socket.

Restore the historical behavior so that pru_attach implementations can
consistently use it. Note that some pru_attach() do currently rely on
this, though that may change in the future. D28265 contains a change to
remove the use in TCP and IB/SDP bits, as resetting the requested linger
time on incoming connections seems questionable at best.

This does move the assignment out from under the head's listen lock, but
glebius notes that head won't be going away and applications cannot
assume any specific ordering with a race between a connection coming in
and the application changing socket options anyways.

Discussed-with: glebius
MFC-after: 1 week

3 years agodevfs: fix use count leak when using TIOCSCTTY
Mateusz Guzik [Mon, 8 Feb 2021 22:10:57 +0000 (23:10 +0100)]
devfs: fix use count leak when using TIOCSCTTY

by matching devfs_ctty_ref

Fixes: 3b44443626603f65 ("devfs: rework si_usecount to track opens")
3 years agoSimplify the FreeBSD check using __FreeBSD__ compiler macro.
Cy Schubert [Sun, 7 Feb 2021 03:22:52 +0000 (19:22 -0800)]
Simplify the FreeBSD check using __FreeBSD__ compiler macro.

Rather than rely on __FreeBSD_version, defined in sys/param.h, use
__FreeBSD__ defined by the compiler.

Reported by: emaste
MFC after: 1 week

3 years agoSimply FreeBSD check using __FreeBSD__ and remove OpenBSD
Cy Schubert [Sun, 7 Feb 2021 03:15:27 +0000 (19:15 -0800)]
Simply FreeBSD check using __FreeBSD__ and remove OpenBSD

MFC after: 1 week

3 years agoZFS: fix assertions with INVARIANTS
Alan Somers [Wed, 20 Jan 2021 15:55:36 +0000 (08:55 -0700)]
ZFS: fix assertions with INVARIANTS

AFAICT, this was an oversight from
9e5787d2284e187abb5b654d924394a65772e004 (svn r364746).  That revision
inadvertently disabled assertions unconditionally.

Reviewed by: freqlabs
MFC after: 3 days
Sponsored by: Axcient
Differential Revision: https://reviews.freebsd.org/D28256

3 years agoRevert "SO_RERROR indicates that receive buffer overflows should be handled as errors."
Alexander V. Chernikov [Mon, 8 Feb 2021 22:30:39 +0000 (22:30 +0000)]
Revert "SO_RERROR indicates that receive buffer overflows should be handled as errors."
Wrong version of the change was pushed inadvertenly.

This reverts commit 4a01b854ca5c2e5124958363b3326708b913af71.

3 years agohid: bump HID_ITEM_MAXUSAGES to 8
Warner Losh [Mon, 8 Feb 2021 19:29:20 +0000 (12:29 -0700)]
hid: bump HID_ITEM_MAXUSAGES to 8

My YOGA requires a minimum of 7 to parse w/o an error. Since the memory savings
are trivial and the yoga a popular system, bump the default up to 8. There's no
API/ABI issues in doing this. This hid_item struct isn't exported to userland
and the one libusbhid has is different and only shares a name...

MFC After: 3 days
Reviewed by: wulf@
Differential Revision: https://reviews.freebsd.org/D28543

3 years agoDon't check compat.linux.emul_path before loading linux(4)
Edward Tomasz Napierala [Mon, 8 Feb 2021 21:52:31 +0000 (21:52 +0000)]
Don't check compat.linux.emul_path before loading linux(4)

Fix e40787f900f to make libexec/rc/rc.d/linux retrieve the sysctl
after loading the kernel module which provides it, not before.

Reported By: jkim
Sponsored By: The FreeBSD Foundation

3 years agoacpi: limit the AMDI0020/AMDI0010 workaround to an option
Warner Losh [Mon, 8 Feb 2021 21:43:25 +0000 (14:43 -0700)]
acpi: limit the AMDI0020/AMDI0010 workaround to an option

It appears that production versions of EPYC firmware get the _STA method right
for these nodes. In fact, this workaround breaks on production hardware by
including too many uart nodes. This work around was for pre-release hardware
that wound up not having a large deployment. Move this work around to a kernel
option since the machines that needed it have been powered off and are difficult
to resurrect. Should there be a more significant deployment than is understood,
we can restrict it based on smbios strings.

Discussed with: mmacy@, seanc@, jhb@
MFC After: 3 days

3 years agoTurn off forgotten multipath debug messages
Alexander V. Chernikov [Mon, 8 Feb 2021 20:11:38 +0000 (20:11 +0000)]
Turn off forgotten multipath debug messages

Reported by: mike tancsa<mike at sentex.net>
MFC after: 3 days

3 years agoSO_RERROR indicates that receive buffer overflows should be handled as errors.
Alexander V. Chernikov [Sun, 7 Feb 2021 17:21:18 +0000 (17:21 +0000)]
SO_RERROR indicates that receive buffer overflows should be handled as errors.
Historically receive buffer overflows have been ignored and programs
could not tell if they missed messages or messages had been truncated
because of overflows. Since programs historically do not expect to get
receive overflow errors, this behavior is not the default.

This is really really important for programs that use route(4) to keep in sync
with the system. If we loose a message then we need to reload the full system
state, otherwise the behaviour from that point is undefined and can lead
to chasing bogus bug reports.

3 years agowsp: Add sysctl tunable for Z-Axis inversion
Vladimir Kondratyev [Mon, 8 Feb 2021 21:26:42 +0000 (00:26 +0300)]
wsp: Add sysctl tunable for Z-Axis inversion

This adds a new sysctl to Wellspring Touchpad driver for controlling
Z-Axis (2-finger vertical scroll) direction "hw.usb.wsp.z_invert".

Submitted by: James Wright <james.wright_AT_digital-chaos_DOT_com>
Reviewed by: wulf
PR: 253321
Differential revision: https://reviews.freebsd.org/D28521

3 years agonvme: Make nvme_ctrlr_hw_reset static
Warner Losh [Mon, 8 Feb 2021 20:28:18 +0000 (13:28 -0700)]
nvme: Make nvme_ctrlr_hw_reset static

nvme_ctrlr_hw_reset is no longer used outside of nvme_ctrlr.c, so
make it static. If we need to change this in the future we can.

3 years agoktls(4): Mention WITH_OPENSSL_KTLS in the ktls(4) manual page
Gordon Bergling [Mon, 8 Feb 2021 20:21:26 +0000 (21:21 +0100)]
ktls(4): Mention WITH_OPENSSL_KTLS in the ktls(4) manual page

Since we ship a ktls(4) enabled OpenSSL version, mention
the src.conf(5) option WITH_OPENSSL_KTLS in the manual page.

Reviewed by: jhb
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D28435

3 years agonvme: use NVME_GONE rather than hard-coded 0xffffffff
Warner Losh [Mon, 8 Feb 2021 20:08:48 +0000 (13:08 -0700)]
nvme: use NVME_GONE rather than hard-coded 0xffffffff

Make it clearer that the value 0xfffffff is being used to detect the device is
gone. We use it other places in the driver for other meanings.

3 years agoFix incorrect powf(3) result with x near 1 and |y| much larger than 1
Steve Kargl [Mon, 8 Feb 2021 19:45:30 +0000 (20:45 +0100)]
Fix incorrect powf(3) result with x near 1 and |y| much larger than 1

This adjusts the check to trigger overflow/underflow to a slightly lower
value.

Before: powf(9.999995e-01, -1.342177e+08) -> inf
After:  powf(9.999995e-01, -1.342177e+08) -> 1.858724e+31

MFC after: 1 week

3 years agomca: Handle inconsistent CMCI capability reporting
Mark Johnston [Mon, 8 Feb 2021 19:42:54 +0000 (14:42 -0500)]
mca: Handle inconsistent CMCI capability reporting

A BIOS bug may apparently cause the BSP to report that it does not
implement CMCI, with some APs reporting that they do.  In this scenario,
avoid a NULL pointer dereference that occurs in cmci_monitor() because
cmc_state was not allocated by the BSP.

PR: 253272
Reported by: asomers, mmacy
Reviewed by: kib (previous version)
MFC after: 1 week

3 years agoamd64: fix up a braino in strlen comment
Mateusz Guzik [Mon, 8 Feb 2021 19:24:26 +0000 (19:24 +0000)]
amd64: fix up a braino in strlen comment

3 years agoprepare-commit-msg: Remove blank character
Daniel Ebdrup Jensen [Mon, 8 Feb 2021 19:15:34 +0000 (20:15 +0100)]
prepare-commit-msg: Remove blank character

Approved by: emaste@ (maintainer)

3 years agoamd64: implement strlen in assembly
Mateusz Guzik [Mon, 8 Feb 2021 17:01:48 +0000 (18:01 +0100)]
amd64: implement strlen in assembly

The C variant in libkern performs excessive branching to find the
non-zero byte instead of using the bsfq instruction. The same code
patched to use it is still slower than the routine implemented here
as the compiler keeps neglecting to perform certain optimizations
(like using leaq).

On top of that the routine can is a starting point for copyinstr
which operates on words instead of bytes.

Tested with glibc test suite.

Sample results (calls/s):

Haswell:
$(perl -e "print 'A' x 3"):
stock: 211198039
patched:338626619
asm: 465609618

$(perl -e "print 'A' x 100"):
stock:  83151997
patched: 98285919
asm: 120719888

AMD EPYC 7R32:
$(perl -e "print 'A' x 3"):
stock: 282523617
asm: 491498172

$(perl -e "print 'A' x 100"):
stock: 114857172
asm: 112082057

3 years agoRestore the augmented strlen commentary
Mateusz Guzik [Sun, 7 Feb 2021 19:53:34 +0000 (19:53 +0000)]
Restore the augmented strlen commentary

... lost in revert

3 years agolibkern: use compiler builtins for strcpy, strcmp and strlen
Mateusz Guzik [Sun, 7 Feb 2021 19:50:25 +0000 (19:50 +0000)]
libkern: use compiler builtins for strcpy, strcmp and strlen

3 years agogrep: fix -A handling in conjunction with -m match limitation
Kyle Evans [Mon, 8 Feb 2021 18:31:17 +0000 (12:31 -0600)]
grep: fix -A handling in conjunction with -m match limitation

The basic issue here is that grep, when given -m 1, would stop all
line processing once it hit the match count and exit immediately.  The
problem with exiting immediately is that -A processing only happens when
subsequent lines are processed and do not match.

The fix here is relatively easy; when bsdgrep matches a line, it resets
the 'tail' of the matching context to the value supplied to -A and
dumps anything that's been queued up for -B. After the current line has
been printed and tail is reset, we check our mcount and do what's
needed. Therefore, at the time that we decide we're doing nothing, we
know that 'tail' of the context is correct and we can simply continue
on if there's still more to pick up.

With this change, we still bail out immediately if there's been no -A
flag. If -A was supplied, we signal that we should continue on. However,
subsequent lines will not even bothere to try and process the line.  We
have reached the match count, so even if the next line would match then
we must process it if it hadn't. Thus, the loop in procfile() can
short-circuit and just process the line as a non-match until
procmatches() indicates that it's safe to stop.

A test has been added to reflect both that we should be picking up the
next line and that the next line should be considered a non-match even
if it should have been.

PR: 253350
MFC-after: 3 days

3 years agovt: terminal size can grow too big with small font
Toomas Soome [Thu, 21 Jan 2021 22:18:56 +0000 (00:18 +0200)]
vt: terminal size can grow too big with small font

vt is using static buffers for on screen data, the buffer size is
calculated based on maximum supported screen size and 8x16 font.

When using hi-res graphics and very smaller than 8x16 font, we
need to be careful not to overflow static buffers in vt.

Testing: I did test by building smaller buffers than vt currently is using,
royger was testing on actual 4k capable hardware.

MFC after: 1 week
Tested by: royger

3 years agobinmiscctl: Avoid segfault with "binmiscctl add" and no extra params
Mark Johnston [Mon, 8 Feb 2021 14:20:38 +0000 (09:20 -0500)]
binmiscctl: Avoid segfault with "binmiscctl add" and no extra params

MFC after: 1 week

3 years agoktls: Avoid wakeups and locking for synchronous callbacks
Mark Johnston [Mon, 8 Feb 2021 14:19:27 +0000 (09:19 -0500)]
ktls: Avoid wakeups and locking for synchronous callbacks

When performing encryption in software, the KTLS crypto callback always
locks the session to deliver a wakeup.  But, if we're handling the
operation synchronously this is wasted effort and can result in
sleepqueue lock contention on large systems.

Use CRYPTO_SESS_SYNC() to determine whether the operation will be
completed asynchronously or not, and select a callback appropriately.
Avoid locking the session to check for completion if the session handles
requests synchronously.

Reviewed by: jhb
Sponsored by: Ampere Computing
Submitted by: Klara, Inc.
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D28195

3 years agoopencrypto: Introduce crypto_dispatch_async()
Mark Johnston [Mon, 8 Feb 2021 14:19:19 +0000 (09:19 -0500)]
opencrypto: Introduce crypto_dispatch_async()

Currently, OpenCrypto consumers can request asynchronous dispatch by
setting a flag in the cryptop.  (Currently only IPSec may do this.)   I
think this is a bit confusing: we (conditionally) set cryptop flags to
request async dispatch, and then crypto_dispatch() immediately examines
those flags to see if the consumer wants async dispatch. The flag names
are also confusing since they don't specify what "async" applies to:
dispatch or completion.

Add a new KPI, crypto_dispatch_async(), rather than encoding the
requested dispatch type in each cryptop. crypto_dispatch_async() falls
back to crypto_dispatch() if the session's driver provides asynchronous
dispatch. Get rid of CRYPTOP_ASYNC() and CRYPTOP_ASYNC_KEEPORDER().

Similarly, add crypto_dispatch_batch() to request processing of a tailq
of cryptops, rather than encoding the scheduling policy using cryptop
flags.  Convert GELI, the only user of this interface (disabled by
default) to use the new interface.

Add CRYPTO_SESS_SYNC(), which can be used by consumers to determine
whether crypto requests will be dispatched synchronously. This is just
a helper macro. Use it instead of looking at cap flags directly.

Fix style in crypto_done(). Also get rid of CRYPTO_RETW_EMPTY() and
just check the relevant queues directly. This could result in some
unnecessary wakeups but I think it's very uncommon to be using more than
one queue per worker in a given workload, so checking all three queues
is a waste of cycles.

Reviewed by: jhb
Sponsored by: Ampere Computing
Submitted by: Klara, Inc.
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D28194