]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
4 years agoLinuxKPI: Fix build on powerpc/sparc.
johalun [Thu, 16 May 2019 19:32:11 +0000 (19:32 +0000)]
LinuxKPI: Fix build on powerpc/sparc.

Use cmpset instead of testandset in tasklet lock code.

Reviewed by: hps
Approved by: imp (mentor), hps
Obtained from: hps
MFC after: 1 week

4 years agomips: Implement basic pmap_kenter_device, pmap_kremove_device
cem [Thu, 16 May 2019 19:10:48 +0000 (19:10 +0000)]
mips: Implement basic pmap_kenter_device, pmap_kremove_device

Unbreak mips.BERI_DE4_SDROOT build, which uses device xdma. Device xdma
depends on the pmap_kenter_device APIs.

Reported by: tinderbox (local)
Sponsored by: Dell EMC Isilon

4 years agoFix hostname to be returned in an ICMPv6 NI Reply message defined
hrs [Thu, 16 May 2019 19:09:41 +0000 (19:09 +0000)]
Fix hostname to be returned in an ICMPv6 NI Reply message defined
in RFC 4620, ICMPv6 Node Information Queries.  A vnet jail with an
IPv6 address sent a hostname of the host environment, not the
jail, even if another hostname was set to the jail.

This change can be tested by the following commands:

 # ifconfig epair0 create
 # jail -c -n j1 vnet host.hostname=vnetjail path=/ persist
 # ifconfig epair0b vnet j1
 # ifconfig epair0a inet6 -ifdisabled auto_linklocal up
 # jexec j1 ifconfig epair0b inet6 -ifdisabled auto_linklocal up
 # ping6 -w ff02::1%epair0a

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

4 years agoAnnounce OpenBSD 6.5.
roberto [Thu, 16 May 2019 18:54:20 +0000 (18:54 +0000)]
Announce OpenBSD 6.5.

4 years agoLinuxKPI: Updates to tasklets for Linux 5.0.
johalun [Thu, 16 May 2019 18:03:08 +0000 (18:03 +0000)]
LinuxKPI: Updates to tasklets for Linux 5.0.

DRM drivers expect tasklets to have a counter for enable/disable calls.
Also, add a few more tasklet locking functions.

This patch is part of D19565

Reviewed by: hps
Approved by: imp (mentor), hps
MFC after: 1 week

4 years agoLinuxKPI: Add group_leader member to struct task_struct.
johalun [Thu, 16 May 2019 17:53:36 +0000 (17:53 +0000)]
LinuxKPI: Add group_leader member to struct task_struct.

Assign self as group leader at creation to act as the only member of a
new process group.
This patch is part of D19565

Reviewed by: hps
Approved by: imp (mentor), hps
MFC after: 1 week

4 years agoLinuxKPI: Update access_ok macro for v5.0.
johalun [Thu, 16 May 2019 17:44:17 +0000 (17:44 +0000)]
LinuxKPI: Update access_ok macro for v5.0.

Check LINUXKPI_VERSION macro for backwards compatibility.
It's recommended to update any drivers that depend on the older KPI
so we can deprecate < 5.0 code as we update to newer Linux version.
This patch is part of D19565

Reviewed by: hps
Approved by: imp (mentor), hps
MFC after: 1 week

4 years agoAllow loading the same DMA address multiple times without any prior
tychon [Thu, 16 May 2019 17:41:16 +0000 (17:41 +0000)]
Allow loading the same DMA address multiple times without any prior
unload for the LinuxKPI.

Reviewed by: kib, zeising
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D20181

4 years agoxdma(4): Fix invalid pointer use (breaks arm.SOCFPGA build)
cem [Thu, 16 May 2019 17:34:36 +0000 (17:34 +0000)]
xdma(4): Fix invalid pointer use (breaks arm.SOCFPGA build)

In xdma_handle_mem_node(), vmem_size_t and vmem_addr_t pointers were passed to
an FDT API that emits u_long values to the output parameter pointer.  This
broke on systems with both xdma and 32-bit vmem size/addr types (SOCFPGA).

Reported by: tinderbox
Sponsored by: Dell EMC Isilon

4 years agoarm64: Add the rename interpreter path for compat32 ld-elf
jhibbits [Thu, 16 May 2019 17:04:29 +0000 (17:04 +0000)]
arm64: Add the rename interpreter path for compat32 ld-elf

Let arm64 and arm32 dynamic binaries coexist.  Match all other compat32
archs.

Reviewed by: manu
Sponsored by: Juniper Networks, Inc

4 years agoFCP-101: ae(4) is sufficently popular to be moved to the keep list.
brooks [Thu, 16 May 2019 15:22:17 +0000 (15:22 +0000)]
FCP-101: ae(4) is sufficently popular to be moved to the keep list.

4 years agoamd64 pmap: sysctl vm.pmap.pcid_save_cnt should be read-only.
kib [Thu, 16 May 2019 14:33:32 +0000 (14:33 +0000)]
amd64 pmap: sysctl vm.pmap.pcid_save_cnt should be read-only.

Sponsored by: The FreeBSD Foundation
MFC after: 1 week

4 years agoamd64 pmap: Add tunable vm.pmap.di_locked to set DI mode.
kib [Thu, 16 May 2019 14:29:09 +0000 (14:29 +0000)]
amd64 pmap: Add tunable vm.pmap.di_locked to set DI mode.

This is done mostly for debugging in field.  Also added the sysctl of
the same name to report used mode.

Sponsored by: The FreeBSD Foundation
MFC after: 1 month

4 years agoamd64 pmap: Rename DI functions.
kib [Thu, 16 May 2019 13:40:54 +0000 (13:40 +0000)]
amd64 pmap: Rename DI functions.

pmap_delayed_invl_started -> pmap_delayed_invl_start
pmap_delayed_invl_finished -> pmap_delayed_invl_finish

Requested by: markj
Sponsored by: The FreeBSD Foundation
MFC after: 1 month

4 years agoamd64 pmap: rework delayed invalidation, removing global mutex.
kib [Thu, 16 May 2019 13:28:48 +0000 (13:28 +0000)]
amd64 pmap: rework delayed invalidation, removing global mutex.

For machines having cmpxcgh16b instruction, i.e. everything but very
early Athlons, provide lockless implementation of delayed
invalidation.

The implementation maintains lock-less single-linked list with the
trick from the T.L. Harris article about volatile mark of the elements
being removed. Double-CAS is used to atomically update both link and
generation.  New thread starting DI appends itself to the end of the
queue, setting the generation to the generation of the last element
+1.  On DI finish, thread donates its generation to the previous
element.  The generation of the fake head of the list is the last
passed DI generation.  Basically, the implementation is a queued
spinlock but without spinlock.

Many thanks both to Peter Holm and Mark Johnson for keeping with me
while I produced intermediate versions of the patch.

Reviewed by: markj
Tested by: pho
Sponsored by: The FreeBSD Foundation
MFC after: 1 month
MFC note: td_md.md_invl_gen should go to the end of struct thread
Differential revision: https://reviews.freebsd.org/D19630

4 years agosubr_turnstile: Extract some common code to a helper.
kib [Thu, 16 May 2019 13:17:57 +0000 (13:17 +0000)]
subr_turnstile: Extract some common  code to a helper.

Code walks the list of contested turnstiles to calculate the priority
to unlend.

Reviewed by: markj
Tested by: pho
Sponsored by: The FreeBSD Foundation
MFC after: 1 week

4 years agortld_malloc.c: cleanup morepages().
kib [Thu, 16 May 2019 13:13:33 +0000 (13:13 +0000)]
rtld_malloc.c: cleanup morepages().

Use roundup2() and rounddown2() instead of inlining them.
Get rid of the fd local variable, use literal -1 for the mmap argument.
Use MAP_FAILED as mmap(2) failure indicator.
After that, apply some style.

Sponsored by: The FreeBSD Foundation
MFC after: 1 week

4 years agoRemove more dead definitions from rtld_malloc.c after r347019.
kib [Thu, 16 May 2019 13:07:26 +0000 (13:07 +0000)]
Remove more dead definitions from rtld_malloc.c after r347019.

Sponsored by: The FreeBSD Foundation
MFC after: 1 week

4 years agoRevert r347582 for now.
markj [Thu, 16 May 2019 13:04:26 +0000 (13:04 +0000)]
Revert r347582 for now.

The inp lock still needs to be dropped when calling into the driver ioctl
handler, as some drivers expect to be able to sleep.

Reported by: kib

4 years agoimgact_elf.c: Add comment explaining the malloc/VOP_UNLOCK() dance
kib [Thu, 16 May 2019 13:03:54 +0000 (13:03 +0000)]
imgact_elf.c: Add comment explaining the malloc/VOP_UNLOCK() dance
from r347148.

Requested by: alc
Sponsored by: The FreeBSD Foundation
MFC after: 3 days

4 years agoarm64: bzero buffer for ucontext in freebsd32_swapcontext().
kib [Thu, 16 May 2019 13:00:35 +0000 (13:00 +0000)]
arm64: bzero buffer for ucontext in freebsd32_swapcontext().

This change is the same as r340994 for amd64.

PR: 237922
Submitted by: Young <yangx92@hotmail.com>
MFC after: 3 days

4 years agoThe "apropos ''" command no longer works; change development(7)
trasz [Thu, 16 May 2019 09:49:19 +0000 (09:49 +0000)]
The "apropos ''" command no longer works; change development(7)
to suggest "apropos ." instead.

MFC after: 2 weeks
Sponsored by: DARPA, AFRL

4 years agodb show thread: avoid overflow in tick conversion
rlibby [Thu, 16 May 2019 05:29:54 +0000 (05:29 +0000)]
db show thread: avoid overflow in tick conversion

The previous calculations for displaying the time since last switch
easily overflowed, after less than 36 min for hz=1000.  Now overflow
takes 2000 times longer (as long as ticks takes to wrap).

Reviewed by: cem, markj
Sponsored by: Dell EMC Isilon
Differential revision: https://reviews.freebsd.org/D20273

4 years agoiommu static analysis cleanup
rlibby [Thu, 16 May 2019 04:24:08 +0000 (04:24 +0000)]
iommu static analysis cleanup

A static analyzer complained about a couple instances of checking a
variable against NULL after already having dereferenced it.
 - dmar_gas_alloc_region: remove the tautological NULL checks
 - dmar_release_resources / dmar_fini_fault_log: don't deref unit->regs
   unless initialized.

And while here, fix an inverted initialization check in dmar_fini_qi.

Reviewed by: kib
Sponsored by: Dell EMC Isilon
Differential revision: https://reviews.freebsd.org/D20263

4 years agoThe driver list prints "(null)" for the NDIS driver when -h (help) or
cy [Thu, 16 May 2019 02:41:25 +0000 (02:41 +0000)]
The driver list prints "(null)" for the NDIS driver when -h (help) or
an unknown switch is passed outputting the command usage. This is
because the NDIS driver is uninitialized when usage help is printed.
To resolve this we initialize the driver prior to the possibility of
printing the usage help message.

Obtained from: The wpa_supplicant port
MFC after: 1 week

4 years agoipsec tests: Skip if ipsec.ko is not loaded
kp [Thu, 16 May 2019 02:18:57 +0000 (02:18 +0000)]
ipsec tests: Skip if ipsec.ko is not loaded

As of r347410 IPSec is no longer built into GENERIC. The ipsec.ko module must
be loaded before we can execute the IPSec tests.

Check this, and skip the tests if IPSec is not available.

4 years agolibbe(3): Descend into children of datasets w/ mountpoint=none
kevans [Thu, 16 May 2019 02:11:33 +0000 (02:11 +0000)]
libbe(3): Descend into children of datasets w/ mountpoint=none

These datasets will generally be canmount=noauto,mountpoint=none (e.g.
zroot/var) but have children that may need to be mounted. Instead of
skipping that segment for no good reason, descend.

Submitted by: Wes Maag
Reported by: Wes Maag
MFC after: 3 days

4 years agox86: Correctly identify bhyve hypervisor
cem [Thu, 16 May 2019 01:32:54 +0000 (01:32 +0000)]
x86: Correctly identify bhyve hypervisor

Spotted after a similar report by Olivier Cochard-LabbĂ©.

Sponsored by: Dell EMC Isilon

4 years agoMove master.passwd and group to lib/libc/gen/
brd [Thu, 16 May 2019 01:09:13 +0000 (01:09 +0000)]
Move master.passwd and group to lib/libc/gen/

libc was picked as the destination location for these because of the syscalls
that use these files as the lowest level place they are referenced.

Approved by: will (mentor), rgrimes, manu
Differential Revision: https://reviews.freebsd.org/D16728

4 years agox86: spell vpxor %zmm0 as vpxord
rlibby [Wed, 15 May 2019 18:13:43 +0000 (18:13 +0000)]
x86: spell vpxor %zmm0 as vpxord

Fix gcc/gas amd64 & i386 build after r347566.

Reviewed by: kib
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D20264

4 years agoLinuxKPI: Add helper macros IS_ALIGNED and DIV_ROUND_DOWN_ULL.
johalun [Wed, 15 May 2019 17:57:06 +0000 (17:57 +0000)]
LinuxKPI: Add helper macros IS_ALIGNED and DIV_ROUND_DOWN_ULL.

This patch is part of D19565

Reviewed by: hps
Approved by: imp (mentor), hps
MFC after: 1 week

4 years agoProperly announce MD_CLEAR.
kib [Wed, 15 May 2019 17:55:41 +0000 (17:55 +0000)]
Properly announce MD_CLEAR.

Submitted by: Petr Lampa <lampa@fit.vutbr.cz>
MFC after: 3 days

4 years agoLinuxKPI: Move {lower|upper}_32_bits macros from port to base.
johalun [Wed, 15 May 2019 17:48:11 +0000 (17:48 +0000)]
LinuxKPI: Move {lower|upper}_32_bits macros from port to base.

This patch is part of D19565

Reviewed by: hps
Approved by: imp (mentor), hps
MFC after: 1 week

4 years agoLinuxKPI: Include asm/atomic-long.h from atomic.h.
johalun [Wed, 15 May 2019 17:44:25 +0000 (17:44 +0000)]
LinuxKPI: Include asm/atomic-long.h from atomic.h.

This patch is part of D19565

Reviewed by: hps
Approved by: imp (mentor), hps
MFC after: 1 week

4 years agoLinuxKPI: Add get_random_u32 function.
johalun [Wed, 15 May 2019 17:32:00 +0000 (17:32 +0000)]
LinuxKPI: Add get_random_u32 function.

This patch is part of D19565

Reviewed by: hps
Approved by: imp (mentor), hps
MFC after: 1 week

4 years agoLinuxKPI: Update user_access_begin for Linux v5.0.
johalun [Wed, 15 May 2019 17:04:12 +0000 (17:04 +0000)]
LinuxKPI: Update user_access_begin for Linux v5.0.

Check the new LINUXKPI_VERSION macro for backwards compatibility.
This patch is part of D19565

Reviewed by: hps
Approved by: imp (mentor), hps
MFC after: 1 week

4 years agoLinuxKPI: Expand ktime functionality.
johalun [Wed, 15 May 2019 16:59:04 +0000 (16:59 +0000)]
LinuxKPI: Expand ktime functionality.

Also, make ktime_get_raw call getnanouptime instead of getnanotime
to match (the correct) ktime_get_raw_ns.
This patch is part of D19565

Reviewed by: hps
Approved by: imp (mentor), hps
MFC after: 1 week

4 years ago[ar71xx_gpio] Add AR9341/AR9342 to the list of chips for programming function/output...
adrian [Wed, 15 May 2019 16:51:08 +0000 (16:51 +0000)]
[ar71xx_gpio] Add AR9341/AR9342 to the list of chips for programming function/output enable.

This is reqired to use the gpiofunc behaviour for configuring GPIO
pins at boot time.

Submitted by: <yamori813@yahoo.co.jp>
Differential Revision: https://reviews.freebsd.org/D20170

4 years agoAdd small EXAMPLE section to bsearch.3.
bcr [Wed, 15 May 2019 15:54:27 +0000 (15:54 +0000)]
Add small EXAMPLE section to bsearch.3.

Submitted by: fernape (via Phabricator)
Reviewed by: bcr, jilles, dab
Approved by: bcr (man pages), jilles (src)
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D19902

4 years agoAdd more obsolete files.
antoine [Wed, 15 May 2019 15:11:49 +0000 (15:11 +0000)]
Add more obsolete files.

4 years agoReplace the leap-seconds file in r347488 from USNO with a
delphij [Wed, 15 May 2019 03:39:27 +0000 (03:39 +0000)]
Replace the leap-seconds file in r347488 from USNO with a
leap-seconds file from NIST at ftp://ftp.nist.gov/pub/time.

Future updates should use the NIST version of file, available
at ftp://ftp.nist.gov/pub/time/leap-seconds.list .

Requested by:   ian@
Obtained from:  ftp://ftp.nist.gov/pub/time/leap-seconds.3676924800
MFC after:      3 days

4 years agoLinuxKPI: Add prepare to pm_ops and bump FreeBSD version.
johalun [Tue, 14 May 2019 23:50:46 +0000 (23:50 +0000)]
LinuxKPI: Add prepare to pm_ops and bump FreeBSD version.

This patch is part of D19565

Reviewed by: hps
Approved by: imp (mentor), hps
MFC after: 1 week

4 years agoLinuxKPI: Add vm_fault_t type.
johalun [Tue, 14 May 2019 23:32:02 +0000 (23:32 +0000)]
LinuxKPI: Add vm_fault_t type.

This patch is part of D19565

Reviewed by: hps
Approved by: imp (mentor), hps
MFC after: 1 week

4 years agoLinuxKPI: Add context member to ww_mutex and bump FreeBSD version.
johalun [Tue, 14 May 2019 23:21:20 +0000 (23:21 +0000)]
LinuxKPI: Add context member to ww_mutex and bump FreeBSD version.

This patch is part of https://reviews.freebsd.org/D19565.

Reviewed by: hps
Approved by: imp (mentor), hps

4 years agoLinuxKPI: Let del_timer return a value to match Linux.
johalun [Tue, 14 May 2019 23:12:14 +0000 (23:12 +0000)]
LinuxKPI: Let del_timer return a value to match Linux.

This patch is part of https://reviews.freebsd.org/D19565.

Reviewed by: hps
Approved by: imp (mentor), hps
MFC after: 1 week

4 years agoReplace global list for grouplist with list(s) for each exportlist element.
rmacklem [Tue, 14 May 2019 22:00:47 +0000 (22:00 +0000)]
Replace global list for grouplist with list(s) for each exportlist element.

In mountd.c, the grouplist structures are linked into a single global
linked list headed by "grphead". The only use of this linked list is
to free all list elements when the exportlist elements are also all being
free'd at the time the exports are being reloaded.
This patch replaces this one global linked list head with a list head in
each exportlist structure, where the grouplist elements for that exported
file system are linked.
The only change is that now the grouplist elements are free'd with the
associated exportlist element as they are free'd instead of all grouplist
elements being free'd after the exportlist elements are free'd. This
change should have no effect in practice.
This is being done, since a future patch that will add a "-I" option for
incrementally updating the exports in the kernel needs to know which
grouplist elements are associated with each exported file system and
having them linked into a list headed by the exportlist element does that.

MFC after: 1 month

4 years agoClose some races in multicast socket option handling.
markj [Tue, 14 May 2019 21:30:55 +0000 (21:30 +0000)]
Close some races in multicast socket option handling.

r333175 converted the global multicast lock to a sleepable sx lock,
so the lock order with respect to the (non-sleepable) inp lock changed.
To handle this, r333175 and r333505 added code to drop the inp lock,
but this opened races that could leave multicast group description
structures in an inconsistent state.  This change fixes the problem by
simply acquiring the global lock sooner.  Along the way, this fixes
some LORs and bogus error handling introduced in r333175, and commits
some related cleanup.

Reported by: syzbot+ba7c4943547e0604faca@syzkaller.appspotmail.com
Reported by: syzbot+1b803796ab94d11a46f9@syzkaller.appspotmail.com
Reviewed by: ae
MFC after: 3 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D20070

4 years agoFix handling of r10 in Linux ptrace(2). This fixes decoding
trasz [Tue, 14 May 2019 20:59:44 +0000 (20:59 +0000)]
Fix handling of r10 in Linux ptrace(2).  This fixes decoding
of the 'flags' argument to mmap(2) with Linux strace(1).

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

4 years agotuntap: Defer clearing if_softc until after if_detach
kevans [Tue, 14 May 2019 20:32:29 +0000 (20:32 +0000)]
tuntap: Defer clearing if_softc until after if_detach

r346670 added an sx to close a race between the ifioctl handler and
interface destruction. Unfortunately, it clears if_softc immediately after
the interface is closed, but before if_detach has been invoked.

Any time before detachment, an interface that's part of a bridge may still
receive traffic that's pushed through tunstart/tunstart_l2 and promptly
lead to a panic because if_softc is now NULL.

Fix it by deferring the clearing of if_softc until after the interface has
detached and thus been removed from the bridge. if_softc still gets cleared
in case another thread has already entered the ioctl handler before it's
replaced with ifdead_ioctl.

Reported by: markj
MFC after: 3 days

4 years agoSpecify -z notext when building with -z ifunc-noplt.
markj [Tue, 14 May 2019 18:26:39 +0000 (18:26 +0000)]
Specify -z notext when building with -z ifunc-noplt.

The upstream implementation of -z ifunc-noplt disallows its combination
with -z text.  The option does not have much significance for kernel
builds, though.

Reviewed by: kib (previous version)
Discussed with: emaste
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D20260

4 years agoRemove redundant -Wl uses from the kernel's LDFLAGS.
markj [Tue, 14 May 2019 18:10:32 +0000 (18:10 +0000)]
Remove redundant -Wl uses from the kernel's LDFLAGS.

No functional change intended.

MFC after: 3 days
Sponsored by: The FreeBSD Foundation

4 years agoMitigations for Microarchitectural Data Sampling.
kib [Tue, 14 May 2019 17:02:20 +0000 (17:02 +0000)]
Mitigations for Microarchitectural Data Sampling.

Microarchitectural buffers on some Intel processors utilizing
speculative execution may allow a local process to obtain a memory
disclosure.  An attacker may be able to read secret data from the
kernel or from a process when executing untrusted code (for example,
in a web browser).

Reference: https://www.intel.com/content/www/us/en/security-center/advisory/intel-sa-00233.html
Security: CVE-2018-12126, CVE-2018-12127, CVE-2018-12130, CVE-2019-11091
Security: FreeBSD-SA-19:07.mds
Reviewed by: jhb
Tested by: emaste, lwhsu
Approved by: so (gtetlow)

4 years agoFix some spelling errors in ng_eiface(4).
ygy [Tue, 14 May 2019 15:41:34 +0000 (15:41 +0000)]
Fix some spelling errors in ng_eiface(4).

MFC after: 3 days
PR: 237764
Submitted by: Tom Marcoen <tom.marcoen@gmail.com>

4 years agoFix formatting.
markj [Tue, 14 May 2019 15:19:48 +0000 (15:19 +0000)]
Fix formatting.

MFC after: 3 days

4 years agoRemove bpf interface lock, it is no longer exist.
ae [Tue, 14 May 2019 10:21:28 +0000 (10:21 +0000)]
Remove bpf interface lock, it is no longer exist.

4 years agoRevert r346292 (permit_nonrandom_stackcookies)
cem [Mon, 13 May 2019 23:37:44 +0000 (23:37 +0000)]
Revert r346292 (permit_nonrandom_stackcookies)

We have a better, more comprehensive knob for this now:
kern.random.initial_seeding.bypass_before_seeding=1.

Requested by: delphij
Sponsored by: Dell EMC Isilon

4 years agoloader: fix memory handling errors in module.c
tsoome [Mon, 13 May 2019 22:17:11 +0000 (22:17 +0000)]
loader: fix memory handling errors in module.c

file_loadraw():
check for file_alloc() and strdup() results.
we leak 'name'.

mod_load() does leak 'filename'.

mod_loadkld() does not need to check fp, file_discard() does check.

4 years agoAvoid possible recursion on BPF_LOCK() in bpfwrite().
ae [Mon, 13 May 2019 20:17:55 +0000 (20:17 +0000)]
Avoid possible recursion on BPF_LOCK() in bpfwrite().

Release BPF_LOCK() before invoking if_output() and if_input().
Also enter epoch section before releasing lock, this should prevent
access to ifnet that may be freed on interface detach.

Reported by: markj

4 years agoFortuna: Fix false negatives in is_random_seeded()
cem [Mon, 13 May 2019 19:35:35 +0000 (19:35 +0000)]
Fortuna: Fix false negatives in is_random_seeded()

(1) We may have had sufficient entropy to consider Fortuna seeded, but the
random_fortuna_seeded() function would produce a false negative if
fs_counter was still zero.  This condition could arise after
random_harvestq_prime() processed the /boot/entropy file and before any
read-type operation invoked "pre_read()."  Fortuna's fs_counter variable is
only incremented (if certain conditions are met) by reseeding, which is
invoked by random_fortuna_pre_read().

is_random_seeded(9) was introduced in r346282, but the function was unused
prior to r346358, which introduced this regression.  The regression broke
initial seeding of arc4random(9) and broke periodic reseeding[A], until something
other than arc4random(9) invoked read_random(9) or read_random_uio(9) directly.
(Such as userspace getrandom(2) or read(2) of /dev/random.  By default,
/etc/rc.d/random does this during multiuser start-up.)

(2) The conditions under which Fortuna will reseed (including initial seeding)
are: (a) sufficient "entropy" (by sheer byte count; default 64) is collected
in the zeroth pool (of 32 pools), and (b) it has been at least 100ms since
the last reseed (to prevent trivial DoS; part of FS&K design).  Prior to
this revision, initial seeding might have been prevented if the reseed
function was invoked during the first 100ms of boot.

This revision addresses both of these issues.  If random_fortuna_seeded()
observes a zero fs_counter, it invokes random_fortuna_pre_read() and checks
again.  This addresses the problem where entropy actually was sufficient,
but nothing had attempted a read -> pre_read yet.

The second change is to disable the 100ms reseed guard when Fortuna has
never been seeded yet (fs_lasttime == 0).  The guard is intended to prevent
gratuitous subsequent reseeds, not initial seeding!

Machines running CURRENT between r346358 and this revision are encouraged to
refresh when possible.  Keys generated by userspace with /dev/random or
getrandom(9) during this timeframe are safe, but any long-term session keys
generated by kernel arc4random consumers are potentially suspect.

[A]: Broken in the sense that is_random_seeded(9) false negatives would cause
arc4random(9) to (re-)seed with weak entropy (SHA256(cyclecount ||
FreeBSD_version)).

PR: 237869
Reported by: delphij, dim
Reviewed by: delphij
Approved by: secteam(delphij)
X-MFC-With: r346282, r346358 (if ever)
Security: yes
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D20239

4 years agoAdd an UPDATING entry and bump __FreeBSD_version for r347532.
markj [Mon, 13 May 2019 18:48:08 +0000 (18:48 +0000)]
Add an UPDATING entry and bump __FreeBSD_version for r347532.

Reported by: rgrimes, Oliver Pinter <oliver.pinter@hardenedbsd.org>

4 years agoRestore the pre-r347532 behaviour of ignoring wiring failures in mmap().
markj [Mon, 13 May 2019 18:40:01 +0000 (18:40 +0000)]
Restore the pre-r347532 behaviour of ignoring wiring failures in mmap().

The error handling added in r347532 is not right when mapping vnodes
and will be fixed separately.

Reported by: syzbot+1d2cc393bd6c88a548be@syzkaller.appspotmail.com
MFC with: r347532

4 years agoAdd warning to the Linuxulator makefiles that building it outside of a
dchagin [Mon, 13 May 2019 18:28:40 +0000 (18:28 +0000)]
Add warning to the Linuxulator makefiles that building it outside of a
kernel does not make sence.

PR: 222861
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D20179

4 years agoLinuxulator depends on a fundamental kernel settings such as SMP. Many
dchagin [Mon, 13 May 2019 18:24:29 +0000 (18:24 +0000)]
Linuxulator depends on a fundamental kernel settings such as SMP. Many
of them listed in opt_global.h which is not generated while building
modules outside of a kernel and such modules never match real cofigured
kernel.

So, we should prevent our users from building obviously defective modules.

Therefore, remove the root cause of the building of modules outside of a
kernel - the possibility of building modules with DEBUG or KTR flags.
And remove all of DEBUG printfs as it is incomplete and in threaded
programms not informative, also a half of system call does not have DEBUG
printf. For debuging Linux programms we have dtrace, ktr and ktrace ability.

PR: 222861
Reviewed by: trasz
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D20178

4 years agoLinuxulator getpeername() returns EINVAL in case then namelen less then 0.
dchagin [Mon, 13 May 2019 18:14:20 +0000 (18:14 +0000)]
Linuxulator getpeername() returns EINVAL in case then namelen less then 0.

MFC after: 2 weeks

4 years agoExtend the libcap_sysctl tests.
markj [Mon, 13 May 2019 17:53:03 +0000 (17:53 +0000)]
Extend the libcap_sysctl tests.

- Add some coverage for cap_sysctl(3).
- Add a test for the case where the caller wishes to find the sysctl
  output length without specifying an output buffer.

Reviewed by: oshogbo
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17856

4 years agoConvert the libcap_sysctl test cases to ATF.
markj [Mon, 13 May 2019 17:51:03 +0000 (17:51 +0000)]
Convert the libcap_sysctl test cases to ATF.

Reviewed by: oshogbo
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17855

4 years agoAdd cap_sysctl(3) and cap_sysctlnametomib(3).
markj [Mon, 13 May 2019 17:49:54 +0000 (17:49 +0000)]
Add cap_sysctl(3) and cap_sysctlnametomib(3).

These complement cap_sysctlbyname(3) to provide a drop-in
replacement for the corresponding libc functions.

Also revise the libcap_sysctl limit interface to provide access
to sysctls by MIB, and to avoid direct manipulation of nvlists
by the caller.

Reviewed by: oshogbo
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17854

4 years agoOur bsd_to_linux_sockaddr() and linux_to_bsd_sockaddr() functions
dchagin [Mon, 13 May 2019 17:48:16 +0000 (17:48 +0000)]
Our bsd_to_linux_sockaddr() and linux_to_bsd_sockaddr() functions
alter the userspace sockaddr to convert the format between linux and BSD versions.
That's the minimum 3 of copyin/copyout operations for one syscall.

Also some syscall uses linux_sa_put() and linux_getsockaddr() when load
sockaddr to userspace or from userspace accordingly.

To avoid this chaos, especially converting sockaddr in the userspace,
rewrite these 4 functions to convert sockaddr only in kernel and leave
only 2 of this functions.

Also in order to reduce duplication between MD parts of the Linuxulator put
struct sockaddr conversion functions that are MI out into linux_common module.

PR: 232920
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D20157

4 years agoProvide separate accounting for user-wired pages.
markj [Mon, 13 May 2019 16:38:48 +0000 (16:38 +0000)]
Provide separate accounting for user-wired pages.

Historically we have not distinguished between kernel wirings and user
wirings for accounting purposes.  User wirings (via mlock(2)) were
subject to a global limit on the number of wired pages, so if large
swaths of physical memory were wired by the kernel, as happens with
the ZFS ARC among other things, the limit could be exceeded, causing
user wirings to fail.

The change adds a new counter, v_user_wire_count, which counts the
number of virtual pages wired by user processes via mlock(2) and
mlockall(2).  Only user-wired pages are subject to the system-wide
limit which helps provide some safety against deadlocks.  In
particular, while sources of kernel wirings typically support some
backpressure mechanism, there is no way to reclaim user-wired pages
shorting of killing the wiring process.  The limit is exported as
vm.max_user_wired, renamed from vm.max_wired, and changed from u_int
to u_long.

The choice to count virtual user-wired pages rather than physical
pages was done for simplicity.  There are mechanisms that can cause
user-wired mappings to be destroyed while maintaining a wiring of
the backing physical page; these make it difficult to accurately
track user wirings at the physical page layer.

The change also closes some holes which allowed user wirings to succeed
even when they would cause the system limit to be exceeded.  For
instance, mmap() may now fail with ENOMEM in a process that has called
mlockall(MCL_FUTURE) if the new mapping would cause the user wiring
limit to be exceeded.

Note that bhyve -S is subject to the user wiring limit, which defaults
to 1/3 of physical RAM.  Users that wish to exceed the limit must tune
vm.max_user_wired.

Reviewed by: kib, ngie (mlock() test changes)
Tested by: pho (earlier version)
MFC after: 45 days
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D19908

4 years agoDo not leak memory used for binary filter.
ae [Mon, 13 May 2019 14:07:02 +0000 (14:07 +0000)]
Do not leak memory used for binary filter.

4 years agoRework locking in BPF code to remove rwlock from fast path.
ae [Mon, 13 May 2019 13:45:28 +0000 (13:45 +0000)]
Rework locking in BPF code to remove rwlock from fast path.

On high packets rate the contention on rwlock in bpf_*tap*() functions
can lead to packets dropping. To avoid this, migrate this code to use
epoch(9) KPI and ConcurrencyKit's lists.

* all lists changed to use CK_LIST;
* reference counting added to bpf_if and bpf_d;
* now bpf_if references ifnet and releases this reference on destroy;
* each bpf_d descriptor references bpf_if when it is attached;
* new struct bpf_program_buffer introduced to keep BPF filter programs;
* bpf_program_buffer, bpf_d and bpf_if structures are freed by
  epoch_call();
* bpf_freelist and ifnet_departure event are no longer needed, thus
  both are removed;

Reviewed by: melifaro
Sponsored by: Yandex LLC
Differential Revision: https://reviews.freebsd.org/D20224

4 years agoRevert r347356 and r347371
manu [Mon, 13 May 2019 12:38:33 +0000 (12:38 +0000)]
Revert r347356 and r347371

passwd related files need to be tagged as config file so pkg update
will attempt merging them when we install a new package.
We should use CONFS for that.
Revert for now until I come up with a better version of this patch as
it breaks pkgbase for users.

4 years agoRevert r347402. After r347429 symlink is no longer needed.
ae [Mon, 13 May 2019 08:34:13 +0000 (08:34 +0000)]
Revert r347402. After r347429 symlink is no longer needed.

4 years agoCatch up with r347241.
markj [Mon, 13 May 2019 01:18:17 +0000 (01:18 +0000)]
Catch up with r347241.

MFC with: r347241

4 years agoAdd support for HiFive Unleashed -- the board with a multi-core RISC-V SoC
br [Sun, 12 May 2019 16:17:05 +0000 (16:17 +0000)]
Add support for HiFive Unleashed -- the board with a multi-core RISC-V SoC
from SiFive, Inc.

The first core on this SoC (hart 0) is a 64-bit microcontroller.

o Pick a hart to run boot process using hart lottery.
  This allows to exclude hart 0 from running the boot process.
  (BBL releases hart 0 after the main harts, so it never wins the lottery).
o Renumber CPUs early on boot.
  Exclude non-MMU cores. Store the original hart ID in struct pcpu. This
  allows to find out the correct destination for IPIs and remote sfence
  calls.

Thanks to SiFive, Inc for the board provided.

Reviewed by: markj
Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D20225

4 years agoarm: allwinner: aw_clk_nm: Don't reparent the clock if we didn't ask
manu [Sun, 12 May 2019 15:27:01 +0000 (15:27 +0000)]
arm: allwinner: aw_clk_nm: Don't reparent the clock if we didn't ask

When looking for the best frequency don't change the clock parent if the
clock wasn't configured to do that.

4 years agocache: fix a brainfart in r347505
mjg [Sun, 12 May 2019 07:56:01 +0000 (07:56 +0000)]
cache: fix a brainfart in r347505

If bumping over the counter goes over the limit we have to decrement it back.

Previous code would only bump the counter after adding the entry (thus allowing
the cache to go over the limit).

Sponsored by: The FreeBSD Foundation

4 years agoseqc: fix sed-introduced typos (seqcuence -> sequence)
mjg [Sun, 12 May 2019 07:13:25 +0000 (07:13 +0000)]
seqc: fix sed-introduced typos (seqcuence -> sequence)

Sponsored by: The FreeBSD Foundation

4 years agoamd64: tidy up pagezero*/pagecopy (movq -> movl)
mjg [Sun, 12 May 2019 07:11:44 +0000 (07:11 +0000)]
amd64: tidy up pagezero*/pagecopy (movq -> movl)

Sponsored by: The FreeBSD Foundation

4 years agocache: bump numcache on entry, while here fix lnumcache type
mjg [Sun, 12 May 2019 06:59:22 +0000 (06:59 +0000)]
cache: bump numcache on entry, while here fix lnumcache type

Sponsored by: The FreeBSD Foundation

4 years agoamd64: fixup MEMMOVE comment (10 -> r10)
mjg [Sun, 12 May 2019 06:42:17 +0000 (06:42 +0000)]
amd64: fixup MEMMOVE comment (10 -> r10)

Sponsored by: The FreeBSD Foundation

4 years agocache: push sdt probes in cache_zap_locked to code doing the work
mjg [Sun, 12 May 2019 06:39:30 +0000 (06:39 +0000)]
cache: push sdt probes in cache_zap_locked to code doing the work

Avoids branching to check which probe to evaluate. Very same check was
being done later to do the actual work.

Sponsored by: The FreeBSD Foundation

4 years agox86: store pending bitmapped IPIs in per-cpu areas
mjg [Sun, 12 May 2019 06:36:54 +0000 (06:36 +0000)]
x86: store pending bitmapped IPIs in per-cpu areas

This gets rid of the global cpu_ipi_pending array.

While replace cmpset with fcmpset in the delivery code and opportunistically
check if given IPI is already pending.

Sponsored by: The FreeBSD Foundation

4 years agoamd64: stop re-reading curpc in suword
mjg [Sun, 12 May 2019 06:34:58 +0000 (06:34 +0000)]
amd64: stop re-reading curpc in suword

Plugs re-reads missed in r341719

Sponsored by: The FreeBSD Foundation

4 years agorandom(4): depessimize arc4random
mjg [Sun, 12 May 2019 06:32:46 +0000 (06:32 +0000)]
random(4): depessimize arc4random

- __predict_false reseeding on entry as it is almost never true.
- don't blindly atomic_cmpset as on x86 it ends up dirtying the cacheline.
it almost ever succeeds per above
- fetch the timestamp prior to getting the cpu number

Reviewed by: cem
Approved by: secteam (delphij)
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D20242

4 years agoFactor code into two new functions in preparation for a future commit.
rmacklem [Sat, 11 May 2019 22:41:58 +0000 (22:41 +0000)]
Factor code into two new functions in preparation for a future commit.

Factor code into two functions.
read_exportfile() a functon  which reads the exports file(s) and calls
get_exportlist_one() to process each of them.
delete_export() a function which deletes the exports in the kernel for a file
system.
The contents of these functions is just the same code as was used to do the
operations, moved into separate functions. As such, there is no semantic change.
This is being done in preparation for a future commit that will add an
option to do incremental changes of kernel exports upon receiving SIGHUP.

MFC after: 1 month

4 years agoCorrect a handful of typos.
schweikh [Sat, 11 May 2019 19:31:54 +0000 (19:31 +0000)]
Correct a handful of typos.

4 years agoSupport the use of the ipsec kld.
cy [Sat, 11 May 2019 17:59:13 +0000 (17:59 +0000)]
Support the use of the ipsec kld.

X-MFC with: r347410

4 years agoA new parameter to blist_alloc specifies an upper bound on the size of
dougm [Sat, 11 May 2019 16:15:13 +0000 (16:15 +0000)]
A new parameter to blist_alloc specifies an upper bound on the size of
the allocation request, so that the blocks allocated are from the next
set of free blocks big enough to satisfy the minimum requirements of
the request, and the number of blocks allocated are as many as
possible, up to the specified maximum. The implementation of
swp_pager_getswapspace uses this parameter to ask for a number of
blocks between the new halved request size and the previous failed
request size. Thus a request for 32 blocks may fail, but instead of
getting only 16 blocks instead, the caller asks for 16 to 31 next, and
might get 19 or 27, which is closer to what they originally wanted.

I expect this to lead to bigger block allocations and less block
fragmentation, at least in some cases.

Approved by: kib (mentor)
Differential Revision: https://reviews.freebsd.org/D20001

4 years agorevert r346588 for now
jhibbits [Sat, 11 May 2019 15:17:42 +0000 (15:17 +0000)]
revert r346588 for now

The rewrite of strcmp in assembly uses an instruction added in PowerISA
2.05, making it SIGILL on CPUs older than the POWER6, such as the PPC970 in
the PowerMac G5.  Revert this until we get clang+lld, or retire the in-tree
binutils in favor of newer binutils with IFUNC support, whichever comes
first.

4 years agotwsi: Calculate the clock param based on the bus frequency
manu [Sat, 11 May 2019 15:03:51 +0000 (15:03 +0000)]
twsi: Calculate the clock param based on the bus frequency

Instead of precalculating the different speed, respect the bus frequency
and calculate the clock register parameter based on it.
If the platform didn't register the core clk, fallback on the precomputed
values (This is likely do be the case on Marvell boards).

4 years agoallwinner: clk: sun8i_r: Correct resets
manu [Sat, 11 May 2019 15:02:55 +0000 (15:02 +0000)]
allwinner: clk: sun8i_r: Correct resets

The i2c reset wasn't defined and some bits where wrong, correct them.

4 years agoallwinner: clk: prediv_mux: Init the current parent
manu [Sat, 11 May 2019 15:02:20 +0000 (15:02 +0000)]
allwinner: clk: prediv_mux: Init the current parent

Do not init the first parent but read the clock register to find
it's current parent and init this one.

4 years agoUpdate leap-seconds to leap-seconds.3757622400.
delphij [Sat, 11 May 2019 14:22:21 +0000 (14:22 +0000)]
Update leap-seconds to leap-seconds.3757622400.

As per https://datacenter.iers.org/data/latestVersion/16_BULLETIN_C16.txt:

     INTERNATIONAL EARTH ROTATION AND REFERENCE SYSTEMS SERVICE (IERS)

SERVICE INTERNATIONAL DE LA ROTATION TERRESTRE ET DES SYSTEMES DE REFERENCE

SERVICE DE LA ROTATION TERRESTRE DE L'IERS
OBSERVATOIRE DE PARIS
61, Av. de l'Observatoire 75014 PARIS (France)
Tel.      : +33 1 40 51 23 35
e-mail    : services.iers@obspm.fr
http://hpiers.obspm.fr/eop-pc

                                              Paris, 07 January 2019

                                              Bulletin C 57

                                              To authorities responsible
                                              for the measurement and
                                              distribution of time

                          INFORMATION ON UTC - TAI

 NO leap second will be introduced at the end of June 2019.
 The difference between Coordinated Universal Time UTC and the
 International Atomic Time TAI is :

     from 2017 January 1, 0h UTC, until further notice : UTC-TAI = -37 s

 Leap seconds can be introduced in UTC at the end of the months of December
 or June,  depending on the evolution of UT1-TAI. Bulletin C is mailed every
 six months, either to announce a time step in UTC, or to confirm that there
 will be no time step at the next possible date.

                                            Christian BIZOUARD
                                            Director
                                            Earth Orientation Center of IERS
    Observatoire de Paris, France

Requested by: rgrimes
Obtained from: ftp://tycho.usno.navy.mil/pub/ntp/leap-seconds.3757622400
MFC after: 3 days

4 years agoCallers of swp_pager_getswapspace get either as many blocks as they
dougm [Sat, 11 May 2019 10:16:43 +0000 (10:16 +0000)]
Callers of swp_pager_getswapspace get either as many blocks as they
requested, or none, and in the latter case it is up to them to pick a
smaller request to make - which they always do by halving the failed
request. This change to swp_pager_getswapspace leaves the task of
downsizing the request to the function and not its caller. It still
does so by halving the original request.

Approved by: kib (mentor)
Differential Revision: https://reviews.freebsd.org/D20228

4 years agoWhen bitpos can't be implemented with an inline ffs* instruction,
dougm [Sat, 11 May 2019 09:09:10 +0000 (09:09 +0000)]
When bitpos can't be implemented with an inline ffs* instruction,
change the binary search so that it does not depend on a single bit
only being set in the bitmask. Use bitpos more generally, and avoid
some clearing of bits to accommodate its current behavior.

Approved by: kib (mentor)
Differential Revision: https://reviews.freebsd.org/D20237

4 years agotuntap: Improve style
kevans [Sat, 11 May 2019 04:18:06 +0000 (04:18 +0000)]
tuntap: Improve style

No functional change.

tun_flags of the tuntap_driver was renamed to ident_flags to reflect the
fact that it's a subset of the tun_flags that identifies a tuntap device.
This maps more easily (visually) to the TUN_DRIVER_IDENT_MASK that masks off
the bits of tun_flags that are applicable to tuntap driver ident. This is a
purely cosmetic change.

5 years agoRevert r347469.
dougm [Sat, 11 May 2019 02:13:52 +0000 (02:13 +0000)]
Revert r347469.

Approved by: kib (mentor)

5 years agoFactor out some exportlist list operations into separate functions.
rmacklem [Fri, 10 May 2019 23:52:17 +0000 (23:52 +0000)]
Factor out some exportlist list operations into separate functions.

This patch moves the code that removes and frees all exportlist elements
out into a separate function called free_exports().
It does the same for the insertion of a new exportlist entry into a list.
It also adds a second argument to ex_search() for the list to use.
None of these changes have any semantic effect. They are being done to
prepare the code for future patches that convert the single linked list
for the exportlist to a hash table of lists and a patch that will do
incremental changes of exports in the kernel.
And it fixes the argument for SLIST_HEAD_INITIALIZER() to be a pointer,
which doesn't really matter, since SLIST_HEAD_INITIALIZER() doesn't use
the argument.

MFC after: 1 month

5 years agonetdump: Ref the interface we're attached to
cem [Fri, 10 May 2019 23:12:59 +0000 (23:12 +0000)]
netdump: Ref the interface we're attached to

Serialize netdump configuration / deconfiguration, and discard our
configuration when the affiliated interface goes away by monitoring
ifnet_departure_event.

Reviewed by: markj, with input from vangyzen@ (earlier version)
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D20206