Replace various macros with nitems() from <sys/param.h>.

ok pedro@
Revert a part of r1.98 if_run.c which caused a regression on older gen
run(4) devices.

ok stsp@

imported to Bitrig by patrick@, ok'd by pedro@
Add the -d flag (limit display depth) for compatibility with FreeBSD,
DragonFly, NetBSD and GNU coreutils, even though it's not POSIX.
Actually, this simplifies the code rather than complicating it.

Because -a and -d need not be mutually exclusive (as observed by
millert@) and -s is identical to -d 0, -a and -s are no longer
mutually exclusive, but -as and -sa are now the same as -s.
That is explicitly allowed by POSIX.

Based on a patch from William Orr <will at worrbase dot com>,
but extensively massaged and HISTORY added by me.

feedback and ok millert@

imported to Bitrig by patrick@, ok'd by pedro@
Don't assume that ep_taddr and ep_daddr are page-aligned.  It is possible to
construct ELF executables for which ep_daddr ends up not being properly
aligned.  Sanitize the addresses before setting up the address space for the
new executable.  Should fix the panic discovered by Alejandro Hernandez.

ok miod@

imported to Bitrig by patrick@, ok'd by pedro@
Disable SSLv3 in response to POODLE attack.

ok pedro@
arm: drain the write buffer on every pte sync

Currently we keep the pagetables uncached.  This means that we
don't need to take care of flushing the L1- and L2-Caches when
we change something there.  But what we forgot is that the write
buffer has to be emptied manually if we want to make sure the
changes get to the memory as soon as possible.

What happens at the moment is that when we change something in
the pagetables, we do not make sure it hits memory ASAP.

Therefore, drain the writebuf every time we call PTE_SYNC.

This fixes the issues seen when trying to boot Allwinner A20
based systems.

ok drahn@
remove trailing whitespace
Simple cleanups for amd64 pmap

- use __func__ in panics/printfs (fixes some out of sync function names)
- tell the compiler that code paths where we print diagnostics are unlikely
- use pmap_valid_entry() in some places
- remove KERNSPACE, which is not used anywhere

OK guenther@ mlarkin@ kettenis@
Move some hibernate #defines to pte.h and eliminate some duplicate defines
from hibernate code that were already defined in pte.h (with different
names). No functional change.

ok sf@, deraadt@
Make amd64 pmap more efficient on multi-processor

With the current implementation, when accessing an inactive pmap, its
ptes are mapped in the APTE range. This has the problem that the APTE
range is mapped on all CPUs and changes to the APTE must therefore be
followed by a remote TLB flush on all CPUs. This is very inefficient
because the costs increase quadratically with the number of CPUs.

Therefore, the code is changed to remove the APTE mechanism completely
and instead switch the pmap locally. A remote TLB flush is then only
done if the pmap is in use on the remote CPU. In the common case, this
will replace one TLB flush on all CPUs with two local TLB flushes.

An additional optimization is done in cases where only a single PTE of
an inactive pmap is accessed: The requested PTE is found by walking the
page tables manually via the direct mapping. This makes some more TLB
flushes unnecessary.

Furthermore, some code is reordered so that the TLB-shootdown-IPIs are
sent first, then more local processing takes place, and only afterwards
the CPU waits for the remote TLB-shootdowns to finish.

This diff is based on a patch for i386 by Artur Grabowski <art blahonga org>
from 2008. Some additional bits were taken from a different patch by
Artur from 2005.

Tested by many. OK mlarkin@

Adaptation to Bitrig + locking bits by pedro@

No objections.
in usage() and SYNOPSIS, sort options as suggested by jmc@
rearrange -d, again, after giving ingo some dodgy advice;
ok ingo
fix a regression that i caused in rev. 1.26: *do* report the size of
files listed on the command line, no matter what options are given;
issue reported by edd@; ok millert@ edd@
Don't bother messing with minphys, we always need to support
transfers of size MAXBSIZE. If the number of DMA segments
supported by the device is too low, don't use it.

Discussion at http://marc.info/?l=openbsd-tech&m=140978303923966&w=2

imported to Bitrig by patrick@, ok'd by pedro@
Add missing memory barriers to virtio.

imported to Bitrig and adapted to C11 atomics by patrick@, ok'd by pedro@
publish_avail_idx does not read the used ring, no need to call
bus_dmamap_sync for it.

imported to Bitrig by patrick@, ok'd by pedro@
Make tmpfs_snapshot.h usable in userland.

ok pedro@
Let upgrade.sh fetch the ftplist again.

ok jcv@
Define OFF_MAX, to be used only in the kernel.

Many variables in the kernel are of type off_t. There isn't, however, a
definition holding the highest value that this type can represent.
Address this issue by defining OFF_MAX; inspired by FreeBSD.

OK natano@ patrick@.
Don't silently truncate uint64_t to off_t.

Prevent a silent truncation of uint64_t to off_t when calling vn_rdwr()
by explicitly checking against OFF_MAX. Add an earlier check to catch
this condition in the load case; when generating a snap, there is no
immediate way of knowing how large it will be, so we need to check every
time before calling vn_rdwr().

Problem noticed by Gerhard Roth <groth@genua.de>.

OK natano@ patrick@.