dragonfly.git
4 years agokernel - Implement support for SMAP and SMEP security (3)
Matthew Dillon [Fri, 17 May 2019 01:44:28 +0000 (18:44 -0700)]
kernel - Implement support for SMAP and SMEP security (3)

* Issue clac after the push on all traps, interrupts, and
  exceptions.

* Improve code documentation.

4 years agokernel - Clean up direction flag on syscall entry
Matthew Dillon [Fri, 17 May 2019 01:43:20 +0000 (18:43 -0700)]
kernel - Clean up direction flag on syscall entry

* Make sure the direction flag is clear on syscall entry.  Don't
  trust userland.

4 years agokernel - Implement support for SMAP and SMEP security (2)
Matthew Dillon [Fri, 17 May 2019 00:37:48 +0000 (17:37 -0700)]
kernel - Implement support for SMAP and SMEP security (2)

* Oops.  Do the CR4 initialization in the correct place, so it is
  applied to all CPUs.

4 years agokernel - Implement support for SMAP and SMEP security
Matthew Dillon [Fri, 17 May 2019 00:14:58 +0000 (17:14 -0700)]
kernel - Implement support for SMAP and SMEP security

* Implement support for SMAP security.  This prevents accidental
  accesses to user address space from the kernel.  When available,
  we wrap intentional user-space accesses from the kernel with
  the 'stac' and 'clac' instructions.

  We use a NOP replacement policy to implement the feature.  The wrapper
  is initially a 'nop %eax' (3-byte NOP), and is replaced by 'stac' and
  'clac' via a .section iteration when the feature is supported.

* Implement support for SMEP security.  This prevents accidental
  execution of user code from the kernel and simply requires
  turning the bit on in CR4.

* Reports support in dmesg via the 'CPU Special Features Installed:'
  line.

4 years agokernel - Implement retpoline for kernel
Matthew Dillon [Thu, 16 May 2019 18:11:35 +0000 (11:11 -0700)]
kernel - Implement retpoline for kernel

* Now that we have gcc-8 operational, we can turn on retpoline (software
  spectre protection against the return stack buffer).  Turn it on via
  -mindirect-branch=thunk-inline

* No discernable performance loss with a generic buildkernel test:

Xeon e5-2620v4 x 2
                        time make -j 32 nativekernel (all tmpfs)
BEFORE 1717.427u 323.662s 2:28.49 1374.5%      9582+721k 200842+0io 4870pf+0w
BEFORE 1720.130u 338.635s 2:30.21 1370.5%      9555+720k 199720+0io 4804pf+0w
BEFORE 1722.395u 341.508s 2:30.71 1369.4%      9559+720k 199720+0io 4804pf+0w

AFTER  1720.271u 329.492s 2:28.27 1382.4%      9578+721k 200842+0io 4870pf+0w
AFTER  1736.268u 344.874s 2:30.90 1379.1%      9555+720k 199720+0io 4804pf+0w
AFTER  1726.056u 348.324s 2:31.14 1372.4%      9543+719k 199720+0io 4804pf+0w

4 years agoDon't include "internal" headers outside of regular headers.
Sascha Wildner [Wed, 15 May 2019 20:34:17 +0000 (22:34 +0200)]
Don't include "internal" headers outside of regular headers.

Include files like <sys/_timespec.h> and so on contain small parts
such as struct timespec that are supposed to be provided by multiple
regular headers. They should only be included by other headers, not
by *.c files.

None of these was actually needed except for the libtelnet one
(replaced with <stddef.h>).

4 years agoUpdate the pciconf(8) database.
Sascha Wildner [Wed, 15 May 2019 18:27:38 +0000 (20:27 +0200)]
Update the pciconf(8) database.

May 14, 2019 snapshot from https://pci-ids.ucw.cz

4 years agokernel - Add MDS mitigation support for Intel side-channel attack
Matthew Dillon [Wed, 15 May 2019 00:33:39 +0000 (17:33 -0700)]
kernel - Add MDS mitigation support for Intel side-channel attack

* Add MDS (Microarchitectural Data Sampling) attack mitigation to
  the kernel.  This is an attack against Intel CPUs made from 2011
  to date.  The attack is not currently known to work against AMD CPUs.

  With an intel microcode update the mitigation can be enabled with

  sysctl machdep.mds_mitigation=MD_CLEAR

* Without the intel microcode update, only disabling hyper-threading
  gives you any protection.  Older architectures might not get
  support.  If sysctl machdep.mds_support does not show support,
  then the currently loaded microcode does not have support for the
  feature.

* DragonFlyBSD only supports the MD_CLEAR mode, and it will only
  be available with a microcode update from Intel.

  Updating the microcode alone does not protect against the attack.
  The microcode must be updated AND the mode must be turned on in
  DragonFlyBSD to protect against the attack.

  This mitigation burns around 250nS of additional latency on kernel->user
  transitions (system calls and interrupts primarily).  The additional
  latency will not be present if the microcode has support but it is disabled
  in the kernel, so you should be able to safely update your microcode
  even if you do not intend to use the mitigation.

* It is unclear whether the microcode + mitigation completely protects
  the machine.  The attack is supposedly a sibling hyper-thread
  attack and it may be that the only way to completely protect your
  machine is to disable hyper-threading entirely.  Or buy AMD.

Templated-from: NetBSD

4 years agokernel - VM rework part 8 - Precursor work for terminal pv_entry removal
Matthew Dillon [Tue, 14 May 2019 03:35:51 +0000 (20:35 -0700)]
kernel - VM rework part 8 - Precursor work for terminal pv_entry removal

* Adjust structures so the pmap code can iterate backing_ba's with
  just the vm_object spinlock.

  Add a ba.pmap back-pointer.

  Move entry->start and entry->end into the ba (ba.start, ba.end).
  This is replicative of the base entry->ba.start and entry->ba.end,
  but local modifications are locked by individual objects to allow
  pmap ops to just look at backing ba's iterated via the object.

  Remove the entry->map back-pointer.

  Remove the ba.entry_base back-pointer.

* ba.offset is now an absolute offset and not additive.  Adjust all code
  that calculates and uses ba.offset (fortunately it is all concentrated
  in vm_map.c and vm_fault.c).

* Refactor ba.start/offset/end modificatons to be atomic with
  the necessary spin-locks to allow the pmap code to safely iterate
  the vm_map_backing list for a vm_object.

* Test VM system with full synth run.

4 years agokernel/evdev: Synchronize event codes with Linux 4.16
Peeter Must [Mon, 13 May 2019 09:31:47 +0000 (12:31 +0300)]
kernel/evdev: Synchronize event codes with Linux 4.16

Taken-from: FreeBSD, Linux

4 years agortld-elf - Notify thread state to optimize relocations (2)
Matthew Dillon [Sun, 12 May 2019 16:26:54 +0000 (09:26 -0700)]
rtld-elf - Notify thread state to optimize relocations (2)

* Remove write() prototype in dlfcn.c that was only used for
  debugging.

Reminded-by: swildner
4 years agopathconf.2/sysconf.3: Add some related references to SEE ALSO.
Sascha Wildner [Sun, 12 May 2019 16:19:52 +0000 (18:19 +0200)]
pathconf.2/sysconf.3: Add some related references to SEE ALSO.

4 years agortld-elf - Notify thread state to optimize relocations
Matthew Dillon [Sun, 12 May 2019 04:01:55 +0000 (21:01 -0700)]
rtld-elf - Notify thread state to optimize relocations

* Add shims to allow libthread_xu to notify rtld when threading
  is being used.

* Requires weak symbols in libc which are overriden by rtld-elf.

* Implement the feature in rtld-elf and use it to avoid making calls
  to lwp_gettid().  When threaded, use tls_get_tcb() (which does not
  require a system call) instead of lwp_gettid().  When not threaded,
  just use a constant.

  NOTE: We cannot use tls_get_tcb() unconditionally because the tcb
is not setup during early relocations.  So do this whack-a-mole
to make it work.

* This leaves just the sigprocmask wrappers around rtld-elf (which
  are needed to prevent stacked relocations from signal handlers).

Poked-by: mjg
4 years agokernel - VM rework part 7 - Initial vm_map_backing index
Matthew Dillon [Sat, 11 May 2019 05:39:53 +0000 (22:39 -0700)]
kernel - VM rework part 7 - Initial vm_map_backing index

* Implement a TAILQ and hang vm_map_backing structures off
  of the related object.  This feature is still in progress
  and will eventually be used to allow pmaps to manipulate
  vm_page's without pv_entry's.

  At the same time, remove all sharing of vm_map_backing.
  For example, clips no longer share the vm_map_backing.  We
  can't share the structures if they are being used to
  itemize areas for pmap management.

  TODO - reoptimize this at some point.

  TODO - not yet quite deterministic enough for pmap
 searches (due to clips).

* Refactor vm_object_reference_quick() to again allow
  operation on any vm_object whos ref_count is already
  at least 1, or which belongs to a vnode.  The ref_count
  is no longer being used for complex vm_object collapse,
  shadowing, or migration code.

  This allows us to avoid a number of unnecessary token
  grabs on objects during clips, shadowing, and forks.

* Cleanup a few fields in vm_object.  Name TAILQ_ENTRY()
  elements blahblah_entry instead of blahblah_list.

* Fix an issue with a.out binaries (that are still supported but
  nobody uses) where the object refs on the binaries were not
  being properly accounted for.

4 years agokernel - VM rework part 6 - Stabilize
Matthew Dillon [Sat, 11 May 2019 01:41:08 +0000 (18:41 -0700)]
kernel - VM rework part 6 - Stabilize

* Fix a case and situations where VPAGETABLE won't work.

4 years agokernel - VM rework part 5 - Cleanup
Matthew Dillon [Fri, 10 May 2019 18:37:00 +0000 (11:37 -0700)]
kernel - VM rework part 5 - Cleanup

* Cleanup vm_map_entry_shadow()

* Remove (unused) vmspace_president_count()
  Remove (barely used) struct lwkt_token typedef.

* Cleanup the vm_map_aux, vm_map_entry, vm_map, and vm_object
  structures

* Adjfustments to in-code documentation

4 years agoClean up some Makefiles.
Sascha Wildner [Sat, 11 May 2019 22:08:34 +0000 (00:08 +0200)]
Clean up some Makefiles.

* WARNS?=6 is usually not needed because upper-level Makefile.inc's
  already have it (such as usr.bin/Makefile.inc).

* Remove an unneded SRCS in ndis_events(8).

4 years agolibutil: Raise WARNS to 6.
Sascha Wildner [Sat, 11 May 2019 21:56:20 +0000 (23:56 +0200)]
libutil: Raise WARNS to 6.

4 years agokcollect - Adjust Mops right hand on graph
Matthew Dillon [Sat, 11 May 2019 18:39:22 +0000 (11:39 -0700)]
kcollect - Adjust Mops right hand on graph

* Adjust the Mops cap based on ncpus.

4 years agokernel - Restore kern.cam.da.X.trim_enabled sysctl
Matthew Dillon [Sat, 11 May 2019 16:06:43 +0000 (09:06 -0700)]
kernel - Restore kern.cam.da.X.trim_enabled sysctl

* This sysctl was not always being properly installed due to an
  ordering and timing issue.

* The code was not setting the trim flag in the correct structure.

4 years agokernel - VM rework (fix introduced bug)
Matthew Dillon [Sat, 11 May 2019 16:04:25 +0000 (09:04 -0700)]
kernel - VM rework (fix introduced bug)

* Fix a null-pointer dereferencing bug in vm_object_madvise() introduced
  in recent commits.

4 years agokernel - VM rework part 4 - Implement vm_fault_collapse()
Matthew Dillon [Fri, 10 May 2019 01:37:10 +0000 (18:37 -0700)]
kernel - VM rework part 4 - Implement vm_fault_collapse()

* Add the function vm_fault_collapse().  This function simulates
  faults to copy all pages from backing objects into the front
  object, allowing the backing objects to be disconnected
  from the map entry.

  This function is called under certain conditions from the
  vmspace_fork*() code prior to a fork to potentially collapse
  the entry's backing objects into the front object.  The
  caller then disconnects the backing objects, truncating the
  list to a single object (the front object).

  This optimization is necessary to prevent the backing_ba list
  from growing in an unbounded fashion.  In addition, being able
  to disconnect the graph allows redundant backing store to
  be freed more quickly, reducing memory use.

* Add sysctl vm.map_backing_shadow_test (default enabled).
  The vmspace_fork*() code now does a quick all-shadowed test on
  the first backing object and calls vm_fault_collapse()
  if it comes back true, regardless of the chain length.

* Add sysctl vm.map_backing_limit (default 5).
  The vmspace_fork*() code calls vm_fault_collapse() when the
  ba.backing_ba list exceeds the specified number of entries.

* Performance is a tad faster than the original collapse
  code.

4 years agokernel - VM rework part 3 - Cleanup pass
Matthew Dillon [Thu, 9 May 2019 06:31:25 +0000 (23:31 -0700)]
kernel - VM rework part 3 - Cleanup pass

* Cleanup various structures and code

4 years agokernel - VM rework part 2 - Replace backing_object with backing_ba
Matthew Dillon [Thu, 9 May 2019 02:39:44 +0000 (19:39 -0700)]
kernel - VM rework part 2 - Replace backing_object with backing_ba

* Remove the vm_object based backing_object chains and all related
  chaining code.

  This removes an enormous number of locks from the VM system and
  also removes object-to-object dependencies which requires careful
  traversal code.  A great deal of complex code has been removed
  and replaced with far simpler code.

  Ultimately the intention will be to support removal of pv_entry
  tracking from vm_pages to gain lockless shared faults, but that
  is far in the future.  It will require hanging vm_map_backing
  structures off of a list based in the object.

* Implement the vm_map_backing structure which is embedded in the
  vm_map_entry and then links to additional dynamically allocated
  vm_map_backing structures via entry->ba.backing_ba.  This structure
  contains the object and offset and essentially takes over the
  functionality that object->backing_object used to have.

  backing objects are now handled via vm_map_backing.  In this
  commit, fork operations create a fan-in tree to shared subsets
  of backings via vm_map_backing.  In this particular commit,
  these subsets are not collapsed in any way.

* Remove all the vm_map_split and collapse code.  Every last line
  is gone.  It will be reimplemented using vm_map_backing in a
  later commit.

  This means that as-of this commit both recursive forks and
  parent-to-multiple-children forks cause an accumulation of
  inefficient lists of backing objects to occur in the parent
  and children.  This will begin to get addressed in part 3.

* The code no longer releases the vm_map lock (typically shared)
  across (get_pages) I/O.  There are no longer any chaining locks to
  get in the way (hopefully).  This means that the code does not
  have to re-check as carefully as it did before.  However, some
  complexity will have to be added back in once we begin to address
  the accumulation of vm_map_backing structures.

* Paging performance improved by 30-40%

4 years agokernel - VM rework part 1 - Remove shadow_list
Matthew Dillon [Tue, 7 May 2019 06:14:02 +0000 (23:14 -0700)]
kernel - VM rework part 1 - Remove shadow_list

* Remove shadow_head, shadow_list, shadow_count.

* This leaves the kernel operational but without collapse optimizations
  on 'other' processes when a prorgam exits.

4 years agoSync ACPICA with Intel's version 20190509.
Sascha Wildner [Fri, 10 May 2019 09:46:14 +0000 (11:46 +0200)]
Sync ACPICA with Intel's version 20190509.

* Revert some changes that were causing issues in the kernel subsystem
  and in iasl(8).

* Additional improvements in iasl(8).

For detailed list, please see sys/contrib/dev/acpica/changes.txt.

4 years agokernel - __read_mostly pass on vm_fault
Matthew Dillon [Fri, 10 May 2019 01:00:25 +0000 (18:00 -0700)]
kernel - __read_mostly pass on vm_fault

* Qualify a number of variables with __read_mostly

4 years agokernel - __read_mostly pass on vfs_subr
Matthew Dillon [Fri, 10 May 2019 00:57:44 +0000 (17:57 -0700)]
kernel - __read_mostly pass on vfs_subr

* Qualify a number of variables with __read_mostly

4 years agokernel - __read_mostly pass on vfs_cache
Matthew Dillon [Fri, 10 May 2019 00:48:44 +0000 (17:48 -0700)]
kernel - __read_mostly pass on vfs_cache

* Qualify a number of variables with __read_mostly

* Move the numdefered global to the pcpu structure and adjust the
  heuristic for it.

4 years agokernel - __read_mostly pass on lwkt_thread
Matthew Dillon [Fri, 10 May 2019 00:47:21 +0000 (17:47 -0700)]
kernel - __read_mostly pass on lwkt_thread

* Qualify a number of globals as __read_mostly

* Conditionalize-out (effectively remove) a number of other
  globals that were being used for debugging.

4 years agokernel - Quick pass add __read_frequently
Matthew Dillon [Thu, 9 May 2019 23:52:12 +0000 (16:52 -0700)]
kernel - Quick pass add __read_frequently

* Do a quick pass to add __read_frequently to certain specific
  globals.

4 years agokernel - Bring in __read_mostly etc
Matthew Dillon [Thu, 9 May 2019 23:45:05 +0000 (16:45 -0700)]
kernel - Bring in __read_mostly etc

* Bring __read_mostly, __read_frequently, and __exclusive_cache_line
  in from FreeBSD.

* Remove linux compat __read_mostly now that we have a real one.

Taken-From: FreeBSD/mjg_

4 years agoRemove any remaining traces of varargs.h.
Sascha Wildner [Wed, 8 May 2019 19:48:05 +0000 (21:48 +0200)]
Remove any remaining traces of varargs.h.

This is a follow-up of b3a17fb68c15a4c57da6867f1b2119587b7a68a8.

4 years agokernel: Stop including userland-only includes in kernel code (1/x).
Sascha Wildner [Wed, 8 May 2019 08:19:59 +0000 (10:19 +0200)]
kernel: Stop including userland-only includes in kernel code (1/x).

Specifically <stdbool.h>, <arpa/inet.h>, <dlfcn.h>, <limits.h>, and
<unistd.h>.

Only in hammer2's zlib it needed to be exchanged with a more suitable
header. The rest could be removed.

4 years agoAdd fuse kernel part to LINT64.
Sascha Wildner [Wed, 8 May 2019 08:13:49 +0000 (10:13 +0200)]
Add fuse kernel part to LINT64.

4 years agodup3.3: Adjust HISTORY section.
Sascha Wildner [Tue, 7 May 2019 06:51:30 +0000 (08:51 +0200)]
dup3.3: Adjust HISTORY section.

4 years agolibc: Add dup3() from FreeBSD.
Sascha Wildner [Mon, 6 May 2019 16:53:26 +0000 (18:53 +0200)]
libc: Add dup3() from FreeBSD.

As proposed in http://austingroupbugs.net/view.php?id=411

It seems to help with various ports.

Pointed-out-by: zrj
4 years ago<unistd.h>: Move eaccess() prototype to a better place.
Sascha Wildner [Mon, 6 May 2019 15:24:26 +0000 (17:24 +0200)]
<unistd.h>: Move eaccess() prototype to a better place.

4 years agolibc/net: Document more functions.
Sascha Wildner [Mon, 6 May 2019 07:45:03 +0000 (09:45 +0200)]
libc/net: Document more functions.

gethostbyaddr_r()
gethostbyname_r()
gethostbyname2_r()
gethostent_r()
getnetbyaddr_r()
getnetbyname_r()
getnetent_r()

4 years agolibc/net: Adjust h_errorp arg name to herrno_p like everywhere else.
Sascha Wildner [Mon, 6 May 2019 07:01:57 +0000 (09:01 +0200)]
libc/net: Adjust h_errorp arg name to herrno_p like everywhere else.

4 years ago<netdb.h>: Add whitespace in a prototype.
Sascha Wildner [Mon, 6 May 2019 05:54:15 +0000 (07:54 +0200)]
<netdb.h>: Add whitespace in a prototype.

4 years agogetservent.3: Fix function name.
Sascha Wildner [Mon, 6 May 2019 05:40:47 +0000 (07:40 +0200)]
getservent.3: Fix function name.

4 years agolibc: Change a few DIAGNOSTICS sections into RETURN VALUES and/or ERRORS.
Sascha Wildner [Sun, 5 May 2019 00:10:38 +0000 (02:10 +0200)]
libc: Change a few DIAGNOSTICS sections into RETURN VALUES and/or ERRORS.

DIAGNOSTICS is for stderr type messages only.

4 years agolibc: Add forgotten MLINK.
Sascha Wildner [Sat, 4 May 2019 23:37:05 +0000 (01:37 +0200)]
libc: Add forgotten MLINK.

4 years agolibc: Document yp_maplist().
Sascha Wildner [Sat, 4 May 2019 23:33:57 +0000 (01:33 +0200)]
libc: Document yp_maplist().

While here, correct a wrong type.

Taken-from: OpenBSD

4 years ago<sys/fcntl.h>: Restrict POSIX_FADV_* visibility to userland.
Sascha Wildner [Sat, 4 May 2019 21:28:38 +0000 (23:28 +0200)]
<sys/fcntl.h>: Restrict POSIX_FADV_* visibility to userland.

While here, add a clarifying comment that the information isn't used.

Pointed-out-by: zrj
4 years agolibc/locale: Document mbrtoc{16,32}_l() and c{16,32}rtomb_l().
Sascha Wildner [Sat, 4 May 2019 21:24:53 +0000 (23:24 +0200)]
libc/locale: Document mbrtoc{16,32}_l() and c{16,32}rtomb_l().

4 years agodrm/radeon - Attempt to fix data structure corruption on exit
Matthew Dillon [Sat, 4 May 2019 21:18:34 +0000 (14:18 -0700)]
drm/radeon - Attempt to fix data structure corruption on exit

* Attempt to fix data structure corruption in the radeon driver
  when X exits.  This was causing X to lockup due to an attempt
  to double-remove vm->va from its interval tree.

* Validation operations based on field state.  In particular,
  do not try to issue the interval tree removal unless
  it.start or it.last are non-zero.

  Also, in radeon_vm_fini() do not issue the interval tree removal
  unless the bo can be successfully reserved.  Otherwise the
  structure might be placed in a bad state while it is still in use.

4 years agodrm - Move startup delay to VERSION ioctl
Matthew Dillon [Sat, 4 May 2019 21:15:30 +0000 (14:15 -0700)]
drm - Move startup delay to VERSION ioctl

* We had a startup delay in the i915 attach path, which is
  synchronous with the kldload that X does.  Unfortunately, this
  doesn't appear to work well, probably because it just stalls
  everything and leaves the race intact after the sleep returns.
  Also, the kld lock is held across the sleep.

* Move the startup delay to the first call of the DRM_IOCTL_VERSION
  ioctl.  This is outside the kld path allows drm to free-run while
  simply imposing a short delay on the X startup to give the drm
  system time to stabilize.

* Should fix several intel i915 startup issues that can leave the
  screen corrupt, and perhaps other startup issues.

4 years agolibc: Add posix_fadvise(), for now empty except for some error checking.
Sascha Wildner [Sat, 4 May 2019 20:20:02 +0000 (22:20 +0200)]
libc: Add posix_fadvise(), for now empty except for some error checking.

This should help some dports.

From POSIX' point of view this is sufficient because it is not
required that the implementation does anything with the passed
information.

The manual page was taken from FreeBSD.

4 years agolibc: Document getservent_r(), getservbyport_r(), and getservbyname_r().
Sascha Wildner [Sat, 4 May 2019 17:44:03 +0000 (19:44 +0200)]
libc: Document getservent_r(), getservbyport_r(), and getservbyname_r().

Partially-taken-from: OpenBSD

4 years agolibc: Document getprotoent_r(), getprotobynumber_r(), and getprotobyname_r().
Sascha Wildner [Sat, 4 May 2019 10:20:06 +0000 (12:20 +0200)]
libc: Document getprotoent_r(), getprotobynumber_r(), and getprotobyname_r().

Partially-taken-from: OpenBSD

4 years agolibc: Document offtime(), timelocal(), and timeoff().
Sascha Wildner [Sat, 4 May 2019 09:50:10 +0000 (11:50 +0200)]
libc: Document offtime(), timelocal(), and timeoff().

Taken-from: NetBSD

4 years agobuild - Make sure /usr/local/bin is NOT in the $PATH for kernel
Matthew Dillon [Sat, 4 May 2019 04:46:16 +0000 (21:46 -0700)]
build - Make sure /usr/local/bin is NOT in the $PATH for kernel

* Make sure /usr/local/bin is NOT in the $PATH when building the
  kernel.  If it is, a dports-installed binutils can cause an
  incompatible linker (e.g. one that doesn't recognize LDVER, for
  example) to be used, blowing up incremental builds between
  buildkernel, nativekernel, and manual builds from the object
  directory ( /usr/obj/usr/src/sys/<KERNEL_CONFIG> ).

4 years agodrm/ttm: Fix a deadlock involving fictitious VM pages
Matthew Dillon [Fri, 3 May 2019 20:36:22 +0000 (22:36 +0200)]
drm/ttm: Fix a deadlock involving fictitious VM pages

This prevents processes getting hung in "ttm_unm" state.

4 years agodrm: Sync ttm and radeon drivers with Linux 3.18
François Tigeot [Fri, 3 May 2019 19:56:27 +0000 (21:56 +0200)]
drm: Sync ttm and radeon drivers with Linux 3.18

4 years agodrm: Import dma-buf reservation code from Linux 4.7.10
François Tigeot [Fri, 3 May 2019 19:53:58 +0000 (21:53 +0200)]
drm: Import dma-buf reservation code from Linux 4.7.10

4 years agodrm: More linux/seqlock.h functions
François Tigeot [Fri, 3 May 2019 19:45:23 +0000 (21:45 +0200)]
drm: More linux/seqlock.h functions

4 years agokernel - Permanently fix FP bug - completely remove lazy heuristic
Matthew Dillon [Fri, 3 May 2019 20:24:13 +0000 (13:24 -0700)]
kernel - Permanently fix FP bug - completely remove lazy heuristic

* Remove the FP lazy heuristic.  When the FP unit is being used by a
  thread, it will now *always* be actively saved and restored on
  context switch.

  This means that if a process uses the FP unit at all, its context
  switches (to another thread) will active save/restore the state forever
  more.

* This fixes a known hardware bug on Intel CPUs that we thought was fixed
  before (by not saving The FP context from thread A from the DNA interrupt
  on thread B)...  but it turns out it wasn't.

  We could tickle the bug on Intel CPUs by forcing synth to regenerate
  its flavor index over and over again.  This regeneration fork/exec's
  about 60,000 make's, sequencing concurrently on all cores, and usually
  hits the bug in less than 5 minutes.

* We no longer support lazy FP restores, period.  This is like the fourth
  time I've tried to deal with this, so now its time to give up and not
  use lazy restoration at all, ever again.

4 years agokernel - Backout procfs map change
Matthew Dillon [Fri, 3 May 2019 20:04:39 +0000 (13:04 -0700)]
kernel - Backout procfs map change

* Backout the addition of MAP_STACK 'STK' flagging in the map
  output.  It blows up gcore's /proc/pid/map scan (not procfs's
  fault)... but lets not rock the boat for now.  The flag isn't
  important.

4 years agokernel - Implement debug function w/kern.logsigexit > 1
Matthew Dillon [Fri, 3 May 2019 17:15:13 +0000 (10:15 -0700)]
kernel - Implement debug function w/kern.logsigexit > 1

* kern.logsigexit defaults to 1, which logs signal exits that might
  core dump.

* This change allows setting this sysctl to 2 for debugging purposes.
  The kernel will log the error and then stall uninterruptibly until
  you set the sysctl back to 1 (to resume logging normally).

  This is more kernel debugging only.

4 years agolibrecrypto: Rename unused header.
zrj [Fri, 3 May 2019 10:59:15 +0000 (13:59 +0300)]
librecrypto: Rename unused header.

It is not used during the buildworld.

4 years agodrm/linux: Add an interval_tree implementation
Matthew Dillon [Fri, 3 May 2019 08:58:10 +0000 (10:58 +0200)]
drm/linux: Add an interval_tree implementation

Contrary to the official Linux one, it does not use RB trees.

4 years agodrm: Do not directly define __OS_HAS_AGP
François Tigeot [Fri, 3 May 2019 08:46:33 +0000 (10:46 +0200)]
drm: Do not directly define __OS_HAS_AGP

Use CONFIG_AGP instead

4 years agodrm: Do not use PHOLD/PRELE() in flush_taskqueue()
François Tigeot [Fri, 3 May 2019 08:28:26 +0000 (10:28 +0200)]
drm: Do not use PHOLD/PRELE() in flush_taskqueue()

4 years agodrm/linux: Expand mm_types.h and mmu_notifier.h coverage
François Tigeot [Fri, 3 May 2019 07:37:41 +0000 (09:37 +0200)]
drm/linux: Expand mm_types.h and mmu_notifier.h coverage

4 years agoindent.1: Add some missing whitespace.
Sascha Wildner [Fri, 3 May 2019 07:29:12 +0000 (09:29 +0200)]
indent.1: Add some missing whitespace.

4 years agoworld - update manual page for mmap()
Matthew Dillon [Fri, 3 May 2019 06:21:52 +0000 (23:21 -0700)]
world - update manual page for mmap()

* Update the manual page for mmap().

4 years agokernel - Fix serious bug in MAP_STACK, deprecate auto-grow semantics
Matthew Dillon [Fri, 3 May 2019 06:03:32 +0000 (23:03 -0700)]
kernel - Fix serious bug in MAP_STACK, deprecate auto-grow semantics

* When MAP_STACK is used without MAP_TRYFIXED, the address the kernel
  determines for the stack was *NOT* being returned to userland.  Instead,
  userland always got only the hint address.

* This fixes ruby MAP_STACK use cases and possibly more.

* Deprecate MAP_STACK auto-grow semantics.  All user mmap() calls with
  MAP_STACK are now converted to normal MAP_ANON mmaps.  The kernel will
  continue to create an auto-grow stack segment for the primary user stack
  in exec(), allowing older pthread libraries to continue working, but this
  feature is deprecated and will be removed in a future release.

4 years agopthreads and kernel - change MAP_STACK operation
Matthew Dillon [Fri, 3 May 2019 02:48:53 +0000 (19:48 -0700)]
pthreads and kernel - change MAP_STACK operation

* Only allow new mmap()'s to intrude on ungrown MAP_STACK areas when
  MAP_TRYFIXED is specified.  This was not working as intended before.
  Adjust the manual page to be more clear.

* Make kern.maxssiz (the maximum user stack size) visible via sysctl.

* Add kern.maxthrssiz, indicating the approximate space for placement
  of pthread stacks.  This defaults to 128GB.

* The old libthread_xu stack code did use TRYFIXED and will work
  with the kernel changes, but change how it works to not assume
  that the user stack should suddenly be limited to the pthread stack
  size (~2MB).

  Just use a normal mmap() now without TRYFIXED and a hint based on
  kern.maxthrssiz (defaults to 512GB), calculating a starting address
  hint that is (_usrstack - maxssiz - maxthrssiz).

* Adjust procfs to report MAP_STACK segments as 'STK'.

4 years agopthread_set_name_np.3: Add some articles.
Sascha Wildner [Thu, 2 May 2019 08:28:42 +0000 (10:28 +0200)]
pthread_set_name_np.3: Add some articles.

4 years agokernel - Add kern.ipc.soaccept_reuse and set default to 1
Matthew Dillon [Wed, 1 May 2019 18:31:50 +0000 (11:31 -0700)]
kernel - Add kern.ipc.soaccept_reuse and set default to 1

* This feature, enabled by default, allows a service listening on
  a socket to be killed and restarted without causing
  "bind: Address already in use" errors due to accepted connections still
  being present.

* The accepted connections may still be present either because they
  are still in active use (though typically this is not the case when
  a service is killed... its children also get killed).  But also, more
  importantly, if the sockets are still present due to lingering on a
  TCP timeout.

  In both of these situations we allow bind() to ignore matches against
  accepted connections.  This allows a service to be restared without
  having to set SO_REUSEADDR (for example named/bind generally does not
  set SO_REUSEADDR and restarting can be a pain).

4 years agoPRIV: Handle histedit.h in unpriv_base.sh
zrj [Wed, 1 May 2019 07:50:24 +0000 (10:50 +0300)]
PRIV: Handle histedit.h in unpriv_base.sh

4 years agoComplete upgrade of libedit from 2017-03-29 to 2019-03-24
zrj [Tue, 30 Apr 2019 20:00:20 +0000 (23:00 +0300)]
Complete upgrade of libedit from 2017-03-29 to 2019-03-24

4 years agoMerge remote-tracking branch 'origin/vendor/LIBEDIT'
zrj [Tue, 30 Apr 2019 20:44:55 +0000 (23:44 +0300)]
Merge remote-tracking branch 'origin/vendor/LIBEDIT'

 Conflicts:
contrib/libedit/src/chartype.h

4 years agobsd.lib.mk: Fix tyoo.
zrj [Tue, 30 Apr 2019 19:27:46 +0000 (22:27 +0300)]
bsd.lib.mk: Fix tyoo.

Reported-by: swildner
4 years agoUpdate libedit from version 2017-03-29 to 2019-03-24 on vendor branch
zrj [Tue, 30 Apr 2019 19:04:07 +0000 (22:04 +0300)]
Update libedit from version 2017-03-29 to 2019-03-24 on vendor branch

4 years agoComplete upgrade of libedit from 2015-03-25 to 2017-03-29
zrj [Tue, 30 Apr 2019 17:43:58 +0000 (20:43 +0300)]
Complete upgrade of libedit from 2015-03-25 to 2017-03-29

Disable use of Symbol.map, bump shlib ver and move to shpub.
Add compatibility on api change for lvm(8).

4 years agoMerge remote-tracking branch 'origin/vendor/LIBEDIT'
zrj [Tue, 30 Apr 2019 17:59:56 +0000 (20:59 +0300)]
Merge remote-tracking branch 'origin/vendor/LIBEDIT'

 Conflicts:
contrib/libedit/src/chartype.h
contrib/libedit/src/eln.c
contrib/libedit/src/filecomplete.c
contrib/libedit/src/sys.h

4 years agosh(1): Exclude <histedit.h> better for BOOTSTRAPPING.
zrj [Fri, 26 Apr 2019 16:32:29 +0000 (19:32 +0300)]
sh(1): Exclude <histedit.h> better for BOOTSTRAPPING.

4 years agolibedit: Start tracking minimal symbol map.
zrj [Fri, 26 Jan 2018 10:23:50 +0000 (12:23 +0200)]
libedit: Start tracking minimal symbol map.

Previous variant included non header public symbols. Map is changing
too significantly, symbol versioning is not supported by upstream.
For now include all currently used symbols + ones in contrib/lvm2.

When certain symbols are used by base utilities updates, they should be
added to minimal map too. All symbols are still available in static lib.

4 years agolibedit: Privatize the last public header.
zrj [Tue, 30 Apr 2019 07:28:00 +0000 (10:28 +0300)]
libedit: Privatize the last public header.

Adjust all cases to include correct histedit.h header.

4 years agoLIBPRIV: Remove leftover deps from wpa_cli(8).
zrj [Fri, 26 Apr 2019 16:45:52 +0000 (19:45 +0300)]
LIBPRIV: Remove leftover deps from wpa_cli(8).

Currently we use edit.c implemenatation. There is edit_simple.c variant.
Third variant - edit_readline.c is not compatible with libedit
(no support for rl_replace_line() for libreadline compatibility).

4 years ago<net/pf/pfvar.h>: Fix buildworld. Move malloc declaration into _KERNEL.
Sascha Wildner [Tue, 30 Apr 2019 07:56:41 +0000 (09:56 +0200)]
<net/pf/pfvar.h>: Fix buildworld. Move malloc declaration into _KERNEL.

This header isn't only used by the kernel.

Reported-by: zrj
4 years agodrm: Bring in the Linux fence implementation from NetBSD
François Tigeot [Mon, 29 Apr 2019 21:10:54 +0000 (23:10 +0200)]
drm: Bring in the Linux fence implementation from NetBSD

4 years agopf - Improve SMP counter performance, static array MAXCPU -> kmalloc
Matthew Dillon [Mon, 29 Apr 2019 19:48:58 +0000 (12:48 -0700)]
pf - Improve SMP counter performance, static array MAXCPU -> kmalloc

* Change the global counters to pcpu counters.  Counters are now
  incremented in a cache-friendly state and will be aggregated
  in the status ioctl.

* Change all static declarations of MAXCPU arrays into kmalloc()d
  arrays to reduce kernel bss size.

4 years ago<execinfo.h>: Include <sys/cdefs.h> explicitly for __{BEGIN,END}_DECLS.
Sascha Wildner [Mon, 29 Apr 2019 10:44:01 +0000 (12:44 +0200)]
<execinfo.h>: Include <sys/cdefs.h> explicitly for __{BEGIN,END}_DECLS.

Normally this should come in via our <stddef.h>, but ports compilers
might include the compiler's own <stddef.h> that doesn't seem to
include it.

Reported-by: profmax
4 years agokernel/ums: Use evdev's private lock for ums
Peeter Must [Mon, 29 Apr 2019 10:19:54 +0000 (13:19 +0300)]
kernel/ums: Use evdev's private lock for ums

* evdev can use either an internal or an external lock (the
  parent driver's lock) to protect its private data in
  evdev_dev. For ums evdev uses the ums (external) lock.
  However, sometimes this leads to a panic when the usb
  mouse is detached. This is because the ums may have cleaned
  up its structures, including the lock, while the evdev is
  still busy freeing its resources. If this happens, evdev
  will panic since it cannot use the lock.

* The remedy is to make evdev use its private lock instead of
  ums's lock. This is similar to how evdev and ukbd operate.

* A similar situation may occur for other drivers that we will
  need to link to evdev.

* This change will make our ums/evdev deviate from FreeBSD.

4 years agodebug - update kmapinfo
Matthew Dillon [Sun, 28 Apr 2019 21:19:08 +0000 (14:19 -0700)]
debug - update kmapinfo

* Update kmapinfo for recent vm_map changes.

4 years agokernel - Limit console message rate for swap-full warnings
Matthew Dillon [Sun, 28 Apr 2019 04:45:35 +0000 (21:45 -0700)]
kernel - Limit console message rate for swap-full warnings

* Limit the message rate on the console for swap-full warnings
  to 1hz.  This prevents console spam due to a swap-full condition
  from making the system unusable.

4 years agoahci - Reduce livelock warnings with ahci
Matthew Dillon [Sun, 28 Apr 2019 03:45:31 +0000 (20:45 -0700)]
ahci - Reduce livelock warnings with ahci

* Mark the ahci (sata) interrupt as HIFREQ to avoid triggering
  livelock warnings.

* Very high interrupt rates are possible with modern SSDs.  We
  don't use the AHCI chipset's interrupt rate moderation features
  because they are a bit problematic (often implemented via an
  unconditional delay even for single commands, for example).

  By flagging the interrupt as HIFREQ, the livelock code will
  trigger at kern.livelock_limit_hi instead of kern.livelock_limit.

4 years agopf - Fix SMP race in max-src-nodes, max-src-conn tracking
Matthew Dillon [Sun, 28 Apr 2019 03:02:39 +0000 (20:02 -0700)]
pf - Fix SMP race in max-src-nodes, max-src-conn tracking

* Fix a SMP race in max-src-nodes tracking where an atomic op was
  not being used.

* Fix a possible SMP race in max-src-conn tracking where atomic ops
  were not being used.

Reported-by: zach
4 years agoworld - Fix deprecated crypto calls
Matthew Dillon [Sat, 27 Apr 2019 05:29:20 +0000 (22:29 -0700)]
world - Fix deprecated crypto calls

* Fix deprecated crypto calls

Suggested-by: zrj
4 years agoworld - Conditionalize MAKEWHATIS path
Matthew Dillon [Sat, 27 Apr 2019 05:27:07 +0000 (22:27 -0700)]
world - Conditionalize MAKEWHATIS path

* Old systems installing a new world have MAKEWHATIS in the old
  location.

* Adjust /usr/src/share/man/Makefile to find the binary in either
  the old or new location.

4 years agodrm: Remove a debugging message
François Tigeot [Fri, 26 Apr 2019 19:56:59 +0000 (21:56 +0200)]
drm: Remove a debugging message

4 years agodrm/linux: Improve RCU support
François Tigeot [Fri, 26 Apr 2019 18:01:09 +0000 (20:01 +0200)]
drm/linux: Improve RCU support

Add more RCU directives, make sure existing ones are more correct.

4 years agoRemove two more files by 'make upgrade'.
Sascha Wildner [Fri, 26 Apr 2019 12:03:09 +0000 (14:03 +0200)]
Remove two more files by 'make upgrade'.

4 years agolibssh: Do not create obj dir for Makefile.etc.
zrj [Fri, 26 Apr 2019 11:07:58 +0000 (14:07 +0300)]
libssh: Do not create obj dir for Makefile.etc.

We only install raw moduli file here directly from contrib (TRUST).
Adjust etc/Makefile too.

Note: backup copy is also installed into /usr/share/examples/etc/ssh/
together with current base default sshd_config and ssh_config.
The ssh configs in /etc/ssh/ are left for system administrator to handle
and update when default options are removed or added.

4 years agonrelease: Reduce the size of /usr/local on the IMG/ISO considerably.
Sascha Wildner [Fri, 26 Apr 2019 08:57:33 +0000 (10:57 +0200)]
nrelease: Reduce the size of /usr/local on the IMG/ISO considerably.

* Exchange git with git-lite which should have everything we need for
  our purposes. This gets rid of perl and various p5-* packages.

* Build the bind-tools without option PYTHON. This gets rid of python
  and various py27-* packages.

* While here, use <category>_<port>_{,UN}SET to handle options, instead
  of rolling our own mechanism.

All in all, this commit cuts the number of installed packages from 40
to 22 and reduces /usr/local's size from 300M to 145M.

Thanks to zrj for help and advice.

4 years agobsd.libnames.mk: Adjust for recent libobjc removal.
Sascha Wildner [Thu, 25 Apr 2019 20:24:41 +0000 (22:24 +0200)]
bsd.libnames.mk: Adjust for recent libobjc removal.