FreeBSD/src 355799head/sys/dev/kbd kbd.c

kbd: patch linker set methods, too

This is needed after r355796. Some double-registration of kbd drivers needs
to be sorted out, then this sysinit will simply add these drivers into the
normal list and kill off any other bits in the driver that are aware of the
linker set, for simplicity.

FreeBSD/src 355798head/sys/dev/kbd kbdreg.h kbd.c, head/sys/sys param.h

kbd: remove kbdsw, store pointer to driver in each keyboard_t

The previous implementation relied on a kbdsw array that mirrored the global
keyboards array. This is fine, but also requires extra locking consideration
when accessing to ensure that it's not being resized as new keyboards are
added.

The extra pointer costs little in a struct that there are relatively few of
on any given system, and simplifies locking requirements ever-so-slightly as
we only need to consider the locking requirements of whichever method is
being invoked.

__FreeBSD_version is bumped as any kbd modules will need rebuilt following
this change.

FreeBSD/src 355797head/sys/arm/samsung/exynos chrome_kb.c

chrome_kb: remove default get_fkeystr/diag implementations

This file was missed in r355796, but no harm would have come from this.

FreeBSD/src 355796head/sys/dev/adb adb_kbd.c, head/sys/dev/atkbdc atkbd.c

kbd: provide default implementations of get_fkeystr/diag

Most keyboard drivers are using the genkbd implementations as it is;
formally use them for any that aren't set and make
genkbd_get_fkeystr/genkbd_diag private.

FreeBSD/src 355795stable/11/sys/contrib/ipfilter/netinet ip_fil_freebsd.c fil.c, stable/12/sys/contrib/ipfilter/netinet ip_fil_freebsd.c fil.c

MFC r355670:

Rather than pass the address of the packet information control block to
ipf_pcksum6(), directly pass the adddress of the mbuf to it. This reduces
one pointer dereference. ipf_pcksum6() doesn't use the packet information
control block except to obtain the mbuf address.

FreeBSD/src 355794head/sys/dev/adb adb_kbd.c, head/sys/dev/atkbdc atkbd.c

keyboard switch definitions: standardize on c99 initializers

A future change will provide default implementations for some of these where
it makes sense and most of them are already using the genkbd
implementation (e.g. get_fkeystr, diag).

FreeBSD/src 355793head/sys/arm/versatile pl050.c, head/sys/dev/gpio gpiokeys.c

kbd drivers: use kbdd_* indirection for diag invocation

These invocations were directly calling enkbd_diag(), rather than
indirection back through kbdd_diag/kbdsw. While they're functionally
equivent, invoking kbdd_diag where feasible (i.e. not in a diag
implementation) makes it easier to visually identify locking needs in these
other drivers.

FreeBSD/src 355792head/sys/sys sched.h

Remove a declaration of sched_clock() redundant after r355779.

FreeBSD/src 355791head/sys/tools vnode_if.awk

vfs: allow tail call optimisation in vops in the common case

Most frequently used vops boil down to checking SDT probes, doing the call and
checking again. There is no vop_post/pre in their case but the check after the
call prevents tail call optimisation from taking place. Instead, check once
upfront. Kernels with debug or vops with non-empty vop_post still don't short
circuit.

Reviewed by:    kib
Tested by:      pho
Differential Revision:  https://reviews.freebsd.org/D22739

FreeBSD/src 355790head/sys/fs/nfsclient nfs_clvnops.c, head/sys/kern vfs_lookup.c vfs_subr.c

vfs: flatten vop vectors

This eliminates the following loop from all VOP calls:

while(vop != NULL && \
    vop->vop_spare2 == NULL && vop->vop_bypass == NULL)
        vop = vop->vop_default;

Reviewed by:    jeff
Tesetd by:      pho
Differential Revision:  https://reviews.freebsd.org/D22738

FreeBSD/src 355789head/sys/kern kern_mutex.c

mtx: eliminate recursion support from thread lock

Now that it is not used after schedlock changes got merged.

Note the unlock routine temporarily still checks for it on account of just using
regular spin unlock.

This is a prelude towards a general clean up.

FreeBSD/src 355788head/sbin/camcontrol camcontrol.c

Properly detect ATA sanitize errors.

It seems I read specifications not careful enough.  There are devices not
setting successful completion bit, causing previous code report false error.

MFC after:      1 week

FreeBSD/src 355787head/sys/arm64/arm64 pmap.c

Apply a small optimization to pmap_remove_l3_range().  Specifically, hoist a
PHYS_TO_VM_PAGE() operation that always returns the same vm_page_t out of
the loop.  (Since arm64 is configured as VM_PHYSSEG_SPARSE, the
implementation of PHYS_TO_VM_PAGE() is more costly than that of
VM_PHYSSEG_DENSE platforms, like amd64.)

MFC after:      1 week

FreeBSD/src 355786head/stand/libsa/zfs zfsimpl.c, head/sys/cddl/boot/zfs zfsimpl.h zfssubr.c

loader: rewrite zfs vdev initialization

In some cases the pool discovery will get stuck in infinite loop while setting
up the vdev children.

To fix, we split the vdev setup into two parts, first we create vdevs based on
configuration we do get from pool label, then, we process pool config from MOS
and update the pool config if needed.

Testing done: confirm previously hung loader is not hung any more.

MFC after:      1 week

FreeBSD/src 355785stable 12 11, stable/11/sys/contrib/ipfilter/netinet fil.c

MFC r355669:

in6_cksum() returns zero when checksums are good.

FreeBSD/src 355784head/sys/kern sched_ule.c sched_4bsd.c

schedlock 4/4

Don't hold the scheduler lock while doing context switches.  Instead we
unlock after selecting the new thread and switch within a spinlock
section leaving interrupts and preemption disabled to prevent local
concurrency.  This means that mi_switch() is entered with the thread
locked but returns without.  This dramatically simplifies scheduler
locking because we will not hold the schedlock while spinning on
blocked lock in switch.

This change has not been made to 4BSD but in principle it would be
more straightforward.

Discussed with: markj
Reviewed by:    kib
Tested by:      pho
Differential Revision: https://reviews.freebsd.org/D22778

FreeBSD/src 355783head/sys/powerpc/powernv platform_powernv.c opal.h

powerpc/powernv: Set the PTCR for the Nest MMU

The Nest MMU manages address translation for accelerators on the POWER9.  To
do so, it needs a page table, so export the system page table to the Nest
MMU.  This will quietly fail on pre-POWER9 systems that do not have a NMMU.

The NMMU is currently unused, so this change is currently effectively a NOP,
but the NMMU and VAS will eventually be used.

FreeBSD/src 355782head/sys/kern subr_turnstile.c

schedlock 3/4

Eliminate lock recursion from turnstiles.  This was simply used to avoid
tracking the top-level turnstile lock.  explicitly check for it before
picking up and dropping locks.

Reviewed by:    kib
Tested by:      pho
Differential Revision:  https://reviews.freebsd.org/D22746

FreeBSD/src 355781head/sys/kern subr_sleepqueue.c, head/sys/sys proc.h

schedlock 2/4

Do all sleepqueue post-processing in sleepq_remove_thread() so that we
do not require the thread lock after a context switch.

Reviewed by:    jhb, kib
Differential Revision:  https://reviews.freebsd.org/D22745

FreeBSD/src 355780head/sys/arm/arm unwind.c elf_machdep.c, head/sys/arm/include stack.h

Rewrite arm kernel stack unwind code to work when unwinding through modules.

The arm kernel stack unwinder has apparently never been able to unwind when
the path of execution leads through a kernel module. There was code that
tried to handle modules by looking for the unwind data in them, but it did
so by trying to find symbols which have never existed in arm kernel
modules. That caused the unwind code to panic, and because part of panic
handling calls into the unwind code, that just created a recursion loop.

Locating the unwind data in a loaded module requires accessing the Elf
section headers to find the SHT_ARM_EXIDX section. For preloaded modules
those headers are present in a metadata blob. For dynamically loaded
modules, the headers are present only while the loading is in progress; the
memory is freed once the module is ready to use. For that reason, there is
new code in kern/link_elf.c, wrapped in #ifdef __arm__, to extract the
unwind info while the headers are loaded. The values are saved into new
fields in the linker_file structure which are also conditional on __arm__.

In arm/unwind.c there is new code to locally cache the per-module info
needed to find the unwind tables. The local cache is crafted for lockless
read access, because the unwind code often needs to run in context where
sleeping is not allowed.  A large comment block describes the local cache
list, so I won't repeat it all here.

FreeBSD/src 355779head/sys/kern subr_sleepqueue.c sched_ule.c

schedlock 1/4

Eliminate recursion from most thread_lock consumers.  Return from
sched_add() without the thread_lock held.  This eliminates unnecessary
atomics and lock word loads as well as reducing the hold time for
scheduler locks.  This will eventually allow for lockless remote adds.

Discussed with: kib
Reviewed by:    jhb
Tested by:      pho
Differential Revision:  https://reviews.freebsd.org/D22626

FreeBSD/src 355778head/sys/powerpc/mpc85xx fsl_sata.c

powerpc/mpc85xx: Clean up Freescale SATA driver a little

* Remove unused ATA_IN/OUT macros, they just clutter up the file.
* Fix some RID management bits for the channel memory resource.

FreeBSD/src 355777head/usr.bin/uniq uniq.c uniq.1

Support --all-repeats in uniq(1) for compatibility with gnu coreutils.

This adds a new -D/--all-repeats option to uniq(1), which outputs each copy
of any repeated lines (as opposed to a single copy of a repeated line). You
can specify a separator option to output a blank line before or after each
group of repeated lines. This adds compatibility with the GNU coreutils
version of uniq(1).

This change also re-groups the -c, -d, -D, -u options in the usage display
and man page to indicate that they are mutally exclusive of each other. This
matches the posix/opengroup definition of uniq(1) command line args. Note
that this change does NOT actually enforce the mutual exclusion in the code,
for now, it simply documents that the arguments should be considered
exclusive with each other.

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

FreeBSD/src 355776head/include stdlib.h, head/sys/compat/linuxkpi/common/include/linux compiler.h

Revert r355760, r355759

And remove the inline/deprecated attribute use entirely in stdlib.h, from
r355747.  The intent was to provide a buildable API transitionary period, but
clearly that was counter-productive.

Reported by:    delphij, imp, others

FreeBSD/src 355775head/sys/dev/kbd kbdreg.h

kbd: convert kbdd_* macros to inline functions

This reduces the noise when interested parties wish to de-Giant kbd; these
accesses to kbdsw will need to be properly locked.
DeltaFile
+140-47head/sys/dev/kbd/kbdreg.h
+140-471 files

FreeBSD/src 355774head/sys/dev/nvme nvme_qpair.c

Properly synchronize completion DMA buffers.
Within command completion processing the callback function may access
DMAed data buffer. Synchronize it before use, not after.
This allows to use NVMe disk on non-DMA coherent arm64 system.

MFC after:      3 weeks

FreeBSD/src 355773head/stand/libsa/zfs zfsimpl.c

loader: zfsimpl.c cstyle cleanup

No functional changes intended.

MFC after:      1 week
DeltaFile
+139-117head/stand/libsa/zfs/zfsimpl.c
+139-1171 files

FreeBSD/src 355772stable 12, stable/12/libexec/getty subr.c main.c

MFC r355222, r355260:

r355222: Use strlcat().
r355260: Simplify code with strlcpy/strlcat.

FreeBSD/src 355771head/sys/kern uipc_shm.c

Fix a mistake in r355765.  We need to activate the page if it is not yet
on a pagequeue.

Reported by:    pho

FreeBSD/src 355770user/pho/stress2/misc tmpfs19.sh

Added one more tmpfs(5) test scenario.

FreeBSD/src 355769head/sys/dev/kbd kbdreg.h

kbd: drop _KERNEL #ifdef in kbdreg.h

This #ifdef is misleading as there are actually no user-serviceable parts
inside and, as far as I can tell, there is no pollution leading from
userland to this header. Furthermore, it becomes a slight nuisance when
attempting to move things around in this header.

FreeBSD/src 355768stable 11, stable/11 ObsoleteFiles.inc

MFC r355638:    ObsoleteFiles.inc: chase libpcap update in r334277

libpcap 1.9.0 (pre-release) update removed the export-defs.h header.

PR:            242559
Submitted by:   John Hein

FreeBSD/src 355767stable 12, stable/12 ObsoleteFiles.inc

MFC r355638: ObsoleteFiles.inc: chase libpcap update in r334277

libpcap 1.9.0 (pre-release) update removed the export-defs.h header.

PR:            242559
Submitted by:   John Hein

FreeBSD/src 355766head/sys/vm vm_fault.c vm_object.c

Previously we did not support invalid pages in default objects.  This means
that if fault fails to progress and needs to restart the loop it must free
the page it is working on and allocate again on restart.  Resolve the few
places that need to be modified to support this condition and simply
deactivate the page.  Presently, we only permit this when fault restarts
for busy contention.  This has an added benefit of removing some object
trylocking in this case.

While here consolidate some page cleanup logic into fault_page_free() and
fault_page_release() to reduce redundant code and automate some teardown.

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

FreeBSD/src 355765head/sys/dev/md md.c, head/sys/kern uipc_shm.c

Add a deferred free mechanism for freeing swap space that does not require
an exclusive object lock.

Previously swap space was freed on a best effort basis when a page that
had valid swap was dirtied, thus invalidating the swap copy.  This may be
done inconsistently and requires the object lock which is not always
convenient.

Instead, track when swap space is present.  The first dirty is responsible
for deleting space or setting PGA_SWAP_FREE which will trigger background
scans to free the swap space.

Simplify the locking in vm_fault_dirty() now that we can reliably identify
the first dirty.

Discussed with: alc, kib, markj
Differential Revision:  https://reviews.freebsd.org/D22654

FreeBSD/src 355764head/sys/vm vm_map.c

Slightly optimize locking in vm_map_copy_swap_entry().  Anonymous objects
require the object lock to synchronize collapse.  Other swap objects such
as tmpfs do not.

Reported by:    mjg
Reviewed by:    kib, markj
Differential Revision:  https://reviews.freebsd.org/D22747
DeltaFile
+12-9head/sys/vm/vm_map.c
+12-91 files

FreeBSD/src 355763head/sys/kern kern_exec.c, head/sys/vm vm_page.c

Handle pagein clustering in vm_page_grab_valid() so that it can be used by
exec_map_first_page().  This will also enable pagein clustering for other
interested consumers (tmpfs, md, etc).

Discussed with: alc
Approved by:    kib
Differential Revision:  https://reviews.freebsd.org/D22731

FreeBSD/src 355762head/sys/sys cdefs.h

cdefs: use more accurate GCC version for the deprecated attribute.

The message argument in the "deprecated" attribute was introduced in GCC 4.5 *.
Use the accurate version number for consistency, as done already with other
attributes.

* https://gcc.gnu.org/onlinedocs/gcc-4.5.0/gcc/Function-Attributes.html

FreeBSD/src 355761head/include unistd.h

<unistd.h>: remove redundant __BSD_VISIBLE

This bit is already inside of a larger __BSD_VISIBLE block.

Reported by:    vangyzen

FreeBSD/src 355760head/sys/compat/linuxkpi/common/include/linux compiler.h

linuxkpi: Drop incompatible __deprecated definition

Probably all of these linuxkpi stubs should be '#ifndef' guarded, but maybe
that would prevent people from noticing when they are defined.

Introduced in r355759.  For some reason I only ran a buildworld and not a
kernel.  Mea culpa.

Reported by:    Mark Millard
X-MFC-with:     r355759

FreeBSD/src 355759head/include stdlib.h, head/sys/sys cdefs.h

cdefs: Add __deprecated(message) function attribute macro

The legacy version of GCC4 currently in base does not support the
parameterized form of this function attribute, as recent introduced in
stdlib.h (r355747).

As we have done for other function attributes with similar compatibility
problems, add a version-compatibile definition in sys/cdefs.h.  Note that
Clang defines itself to be GCC 4, so one must check for __clang__ in
addition to __GNUC__ version.  On legacy GCC 4, the macro expands to just
the __deprecated__ attribute; on modern GCC or Clang, the macro expands to
the parameterized variant with the message.

Ignoring legacy or unsupported compilers, the macro is also beneficial in
that it is a bit more ergonomic than the full
__attribute__((__deprecated__())) boilerplate.

Reported by:    CI (but not tinderbox); imp and others
Reviewed by:    imp
Differential Revision:  https://reviews.freebsd.org/D22817

FreeBSD/src 355758head/sbin/mount_nfs mount_nfs.8

Update the mount_nfs.8 man page to include NFSv4.2.

r355677 added NFSv4.2 support to the NFS client. This patch updates the
mount_nfs.8 man page to reflect that.
It also clarifies that the "nolockd" option does not apply to NFSv4 mounts.

This is a content change.

FreeBSD/src 355757head/sys/kern subr_blist.c

Simplify the processing a leaf mask to find big-enough ranges of set
bits, by storing and modifying the complement of the original leaf
mask, and by avoiding some unnecessary intermediate variables in
computing the shift amounts. The logic is similar to what has recently
been committed to sys/sys/bitstring.h.

Compute better hint updates for the case when the cursor starts in
mid-leaf, and eliminates some otherwise viable solutions. Assume the
worst case, that all the eliminated offsets could have been solutions,
and you can still compute a better hint than we use now.

Eliminate some unnecessary conditional control flow.

Approved by: alc
Tested by: pho
Differential Revision: https://reviews.freebsd.org/D22666

FreeBSD/src 355756stable 12, stable/12/usr.bin/gcore elfcore.c

MFC r355506:
gcore: Avoid using vm_map_entry_t.

FreeBSD/src 355755head/sys/arm64/rockchip rk_pcie.c rk_pcie_phy.c, head/sys/conf files.arm64

Add driver for Rockchip PCIe root complex found in RK3399 SOC.
Unfortunately, there are some limitations:
- memory aperture of his controller is only 16MiB, so it is nearly
  unusable for graphic cards
- every attempt to generate type 1 config cycle always causes trap.
  These config cycles are disabled now and we don't support cards
  with PCIe switch.
- in some cases, attempt to do config cycle to (probably) not-yet ready
  card also causes trap. This cannot be detected at runtime, but it seems
  like very rare issue.

MFC after:      3 weeks
Differential Revision:  https://reviews.freebsd.org/D22724

FreeBSD/src 355754head/sys/amd64/linux linux_dummy.c, head/sys/amd64/linux32 linux32_dummy.c

Add sync_file_range(2) implementation to linux(4); it's a thin wrapper
over the usual fsync(2).

This silences some warnings when running "apt-get upgrade".

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

FreeBSD/src 355753head/sys/amd64/linux linux_systrace_args.c, head/sys/amd64/linux32 linux32_systrace_args.c

Regen after r355752.

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

FreeBSD/src 355752head/sys/amd64/linux syscalls.master, head/sys/amd64/linux32 syscalls.master

Fix definitions for linuxulator's sync_file_range(2).

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

FreeBSD/src 355751head/usr.sbin/sesutil sesutil.c sesutil.8

Add 'sesutil show' subcommand to show enclosure and its contents
in a user-friendly way.

Reviewed by:    allanjude, bcr (manpages)
MFC after:      2 weeks
Relnotes:       yes
Sponsored by:   Klara Inc.
Differential Revision:  https://reviews.freebsd.org/D22567

FreeBSD/src 355750head/contrib/netcat netcat.c nc.1, head/usr.bin/nc Makefile

Add -M option to nc(1), which makes it print the TCP connection
statistics obtained with stats(3) in JSON format to standard error.

Reviewed by:    allanjude, thj, cem (earlier version)
Tested by:      thj
MFC after:      2 weeks
Relnotes:       yes
Sponsored by:   Klara Inc.
Differential Revision:  https://reviews.freebsd.org/D21324