dragonfly.git
5 years agoif_tap: Disallow to destroy an opened device
Aaron LI [Thu, 30 Aug 2018 13:13:27 +0000 (21:13 +0800)]
if_tap: Disallow to destroy an opened device

When a tap device (created via 'ifconfig') is opened, disallow to destroy
it (e.g., ifconfig destroy).  Otherwise, a panic occurs when the caller
closes the device, since it has been already destroyed.

Test case:
[A]% ifconfig tap0 create
[B]% # run a program that opens '/dev/tap0' and keep it running
[A]% ifconfig tap0 destroy
[B]% # exit the program which will then close '/dev/tap0'
=> panic!

In addition:
* Add an assertion to tapclose() to assert the device must exist.
* Return EINVAL instead of ENOIX when try to destroy an manually created
  tap device.
* Improve the function description a bit.

5 years agovkernel64 - Fix build
Matthew Dillon [Wed, 29 Aug 2018 17:11:34 +0000 (10:11 -0700)]
vkernel64 - Fix build

* Add missing CPUID_TO_APICID() macro which vm_page.c now needs.

Reminded-by: swildner
5 years agokernel - Fix startup race in usched_dfly
Matthew Dillon [Sun, 26 Aug 2018 18:52:59 +0000 (11:52 -0700)]
kernel - Fix startup race in usched_dfly

* Use a master configuration lock for usched_dfly's thread
  creation, ensuring that no thread tries to check dfly_pcpu[]
  until the whole thing has been initialized.

* Fixes occassional panic in usched_dfly on boot on many-cores
  systems due to a lower-numbered usched thread triggering before
  dfly_pcpu is completely initialized.

5 years agotmpfs - Fix rare deadlock
Matthew Dillon [Sat, 25 Aug 2018 17:10:08 +0000 (10:10 -0700)]
tmpfs - Fix rare deadlock

* Fix a deadlock which can occur between umount and tmpfs, and
  possibly in other very rare situations.

* tmpfs holds the directory node locked when resolving a directory
  entry.  This results in a lock order reversal between the
  directory's tmpfs_node lock and the vnode being locked.

  Fixed by using a NOWAIT/UNLOCK/SLEEPFAIL/RETRY sequence.

5 years agokernel/apple_gmux: Unbreak loading i915.
Peeter Must [Tue, 28 Aug 2018 13:26:05 +0000 (16:26 +0300)]
kernel/apple_gmux: Unbreak loading i915.

* Commit 183e2373896e4ea605435a6bd8f943e8273bf8cd broke loading i915
  on Apple MacBookPro laptops with dual GPUs and the gmux chip. The
  reason is that whereas formely drm_init_pdev() and drm_fill_pdev()
  where mere bookkeeping routines, the above commit relocates
  assignment of irq from drm_drv.c:drm_attach() to drm_fill_pdev().
  Since apple_gmux is loaded before i915, and apple_gmux initializes
  a pdev structure including an irq for the graphics pci device, the
  i915 which is loaded afterwards will get zero for an irq and hence
  fails to attach.

* The temporary fix is to disable apple_gmux initializing a pci_dev
  structure for bookkeeping purposes. This is not needed at the
  moment since the primary purpose of apple_gmux is to switch to iGPU
  so the user is not left with a frozen screen after loading i915. We
  do not support switching between GPUs yet.

* When and if the initialization of graphics pci devices becomes
  independent from the drm subsystem, we can make apple_gmux aware of
  the various GPUs in the system.

5 years agodocs - Update tuning.7
Matthew Dillon [Fri, 24 Aug 2018 18:29:22 +0000 (11:29 -0700)]
docs - Update tuning.7

* Minor update to tuning.7.

5 years agokernel - Fix two missing wakeup()s in kern_lock.c
Matthew Dillon [Fri, 24 Aug 2018 07:19:18 +0000 (00:19 -0700)]
kernel - Fix two missing wakeup()s in kern_lock.c

* Fix two cases where a shared lock request could block forever due
  to missing wakeups for certain specific combinations of request flags.

5 years agoSet autorehash in root's .cshrc.
Sascha Wildner [Thu, 23 Aug 2018 20:06:46 +0000 (22:06 +0200)]
Set autorehash in root's .cshrc.

5 years agokernel - Update AMD topology detection, scheduler NUMA work (TR2) (2)
Matthew Dillon [Thu, 23 Aug 2018 18:43:16 +0000 (11:43 -0700)]
kernel - Update AMD topology detection, scheduler NUMA work (TR2) (2)

* Pass un-mod'd physid to vm_numa_add_topology_mem().  This fixes the
  match logic inside vm_numa_add_topology_mem().

5 years agokernel - Update AMD topology detection, scheduler NUMA work (TR2)
Matthew Dillon [Thu, 23 Aug 2018 01:34:32 +0000 (18:34 -0700)]
kernel - Update AMD topology detection, scheduler NUMA work (TR2)

* Update AMD topology detection to use the correct cpuid.  It
  now properly detects the Threadripper 2990WX as having four nodes
  with 8 cores and 2 threads per core, per node.  It previously detected
  the chip as one node with 32 cores and 2 threads per core.

* Report the basic detected topology without requiring bootverbose.

* Record information about how much memory is attached to each node.
  We previously just assumed that it was symmetric.  This will be
  used by the scheduler.

* Fix instability in the scheduler when running on a large number
  of cores.  Flag 0x08 (on by default) is needed to actively
  schedule overloaded threads onto other cores, but this operation
  was being executed on all cores simultaneously which throws the
  uload/ucount metrics into an unstable state, causing threads to
  bounce around longer the necessary.

  Fix by round-robining the operation based on something similar to
  sched_ticks % cpuid.

  This significantly improves heavy multi-tasking performance on systems
  with many cores.

* Add memory-on-node weighting to the scheduler.  This detects asymetric
  NUMA configurations for situations where not all DIMM slots have been
  populated, and for CPUs which are naturally assymetric such as the
  2990WX which only has memory directly connected to two of its four
  nodes.

  This change will preferentially schedule threads onto nodes with
  greater amounts of attached memory under light loads, and dig into
  the less desirable cpu nodes as the load increases.

5 years agoig4 - Stop I2C controller after checking that it's kind of functional.
Imre Vadász [Sat, 18 Aug 2018 16:42:55 +0000 (18:42 +0200)]
ig4 - Stop I2C controller after checking that it's kind of functional.

5 years agoig4 - We actually need to set the Rx threshold register one smaller.
Imre Vadász [Sat, 18 Aug 2018 16:41:47 +0000 (18:41 +0200)]
ig4 - We actually need to set the Rx threshold register one smaller.

* Setting the IG4_REG_RX_TL register to 1 was actually generating an
  interrupt after 2 bytes were available in the Rx fifo. We need to set the
  register to 0 to get an interrupt for 1 byte already.

5 years agoig4 - Only enable interrupts when we want them. Otherwise keep mask at 0.
Imre Vadász [Sat, 18 Aug 2018 10:58:40 +0000 (12:58 +0200)]
ig4 - Only enable interrupts when we want them. Otherwise keep mask at 0.

* This avoids possible interrupt storms, depending on the state of the I2C
  controller before the driver attached.

* During attaching this clears the interrupt mask.

5 years agoig4 - Use serializer instead of lockmgr lock.
Imre Vadász [Sat, 18 Aug 2018 10:49:40 +0000 (12:49 +0200)]
ig4 - Use serializer instead of lockmgr lock.

* This allows us to use lwkt_serialize_handler_disable when stopping the
  interrupt, which should be safer in case of detaching during an interrupt
  storm.

5 years agohammer2 - Add the vfs.hammer2.cluster_write sysctl back in
Matthew Dillon [Sat, 18 Aug 2018 02:59:06 +0000 (19:59 -0700)]
hammer2 - Add the vfs.hammer2.cluster_write sysctl back in

* Value may be 0 or 1, defaults to 0 (disabled).  Was previously
  enabled.

* By default H2 no longer sets B_CLUSTEROK on dirty buffers being
  written.  Theoretically this shouldn't be a problem because H2
  already uses a large 64KB buffer size.

* Should improve I/O throughput on high-performance SSDs by removing
  kernel overhead and should also work better with vfsync's dirty
  buffer scan which is already sorted.

5 years agokernel - remove BUF_TIMELOCK use in fast flush pass
Matthew Dillon [Sat, 18 Aug 2018 02:57:28 +0000 (19:57 -0700)]
kernel - remove BUF_TIMELOCK use in fast flush pass

* Remove the BUF_TIMELOCK call in the fast flush pass.  This call can
  cause unnecessary flush stalls due to clustered writes getting ahead
  of the vfsync scan.

* Significantly improves filesystem flush performance to SSDs.

5 years agokernel - Refactor the TSC MP synchronization test
Matthew Dillon [Fri, 17 Aug 2018 23:52:45 +0000 (16:52 -0700)]
kernel - Refactor the TSC MP synchronization test

* Refactor the TSC MP synchronization test.  Do not use cpusync.
  Using cpusync results in O(N x N) worth of overhead instead of
  O(N) worth of overhead.

  Instead, have the per-cpu threads run the test simultaneously using
  each other's data.

* We synchronize to the last TSC element that was saved on each cpu.
  This probably needs a bit of work to ensure determinism, but at
  the moment its good in that it synchronizes all cores off of a
  single cache mastership change, instead of having them all compete
  for cache mastership.

* Probably needs some fine tuning, at the moment I allow a slop of
  10uS which is almost certainly too much.  Note, however, that
  SMP interactions can create ~1uS latencies on particular memory
  accesses.

* Solves serious issues with the old test on 64 cpu threads.
  These issues may also have been related to the ipiq fifo size
  being too small.

5 years agokernel - Increase MAXCPUFIFO from 32 to 256
Matthew Dillon [Fri, 17 Aug 2018 23:51:56 +0000 (16:51 -0700)]
kernel - Increase MAXCPUFIFO from 32 to 256

* Increase to 256, ensures that no deadlocks can occur on systems
  with more than 32 cpu threads.

5 years agoRevert "[zoneinfo] Add some missing zoneinfo files"
Sascha Wildner [Fri, 17 Aug 2018 15:51:38 +0000 (17:51 +0200)]
Revert "[zoneinfo] Add some missing zoneinfo files"

This reverts commit e6c3cf619df176c8ebd2391f8f731dfefbc48fcd.

We do not need those files and they were left out intentionally.

Also, adding them broke installworld because we would have needed
new directories in /usr/share/zoneinfo via mtree.

5 years ago[zoneinfo] Add some missing zoneinfo files
Eitan Adler [Thu, 16 Aug 2018 15:13:16 +0000 (15:13 +0000)]
[zoneinfo] Add some missing zoneinfo files

5 years agoUpdate the pciconf(8) database.
Sascha Wildner [Wed, 15 Aug 2018 07:56:46 +0000 (09:56 +0200)]
Update the pciconf(8) database.

August 12, 2018 snapshot from https://pci-ids.ucw.cz

5 years agobsd-family-tree: Small sync with FreeBSD.
Sascha Wildner [Mon, 13 Aug 2018 19:01:18 +0000 (21:01 +0200)]
bsd-family-tree: Small sync with FreeBSD.

5 years agoBuild - for /rescue transition must make upgrade
Matthew Dillon [Mon, 13 Aug 2018 04:03:28 +0000 (21:03 -0700)]
Build - for /rescue transition must make upgrade

* Must make upgrade before make rescue when transitioning to the new
  /rescue topology.

* Must ensure certain header files are not present.  make rescue
  currently improperly uses /usr/include which can have all sorts of
  cruft in it.

* This is a quick hack, will be fixed by a later cleanup of the
  make rescue target to properly split it into buildworld (to build)
  and installworld (to install).

5 years agohammer2 - Shift inode xop functions into hammer2_xop.c
Matthew Dillon [Mon, 30 Jul 2018 00:21:01 +0000 (17:21 -0700)]
hammer2 - Shift inode xop functions into hammer2_xop.c

* Move the inode related xop functions from hammer2_inode.c
  to hammer2_xop.c.  Leave the xop functions in strategy
  and flush where they are.

* Fix desc macro.

5 years agohammer2 - Remote xop implementation part 1
Matthew Dillon [Sun, 29 Jul 2018 02:03:29 +0000 (19:03 -0700)]
hammer2 - Remote xop implementation part 1

* Normalize naming conventions for XOP functions.

* Change the XOP callback API to remove the hammer2_thread argument.
  Pass the clindex and scratch buffer in directly.

* Change the XOP API to pass in a function descriptor instead of a
  function pointer, create prototypes for DMSG send/receive XOPs which
  will be used for XOP components which are DMSG based and not
  local-storage based.

* Adjust comments.

5 years agokernel - Clear bp->b_error prior to initiating write I/O
Matthew Dillon [Sun, 29 Jul 2018 02:01:39 +0000 (19:01 -0700)]
kernel - Clear bp->b_error prior to initiating write I/O

* Clear bp->b_error prior to initiating write I/O so a lingering
  b_error code from a retry that later succeeds is not retained.

5 years agosys/vfs/autofs: Change u_xxx -> unsigned xxx
Tomohiro Kusumi [Sun, 12 Aug 2018 11:26:59 +0000 (04:26 -0700)]
sys/vfs/autofs: Change u_xxx -> unsigned xxx

(ap->a_cmd and refcount apis are of u_xxx)

5 years agokernel/drm: Remove CONFIG_PCI as a kernel option.
Sascha Wildner [Sat, 11 Aug 2018 20:39:07 +0000 (22:39 +0200)]
kernel/drm: Remove CONFIG_PCI as a kernel option.

The code does not link in the absence of it and neither do we expect
systems without PCI support configured, nor does it make sense for
DRM specific stuff in particular, so just set it unconditionally.

If anything, it could be tied to NPCI being >0 (to check if
"device pci" is in the kernel), but for that it would have to
actually build/link without CONFIG_PCI in the first place.

5 years agoSync ACPICA with Intel's version 20180810:
Sascha Wildner [Fri, 10 Aug 2018 20:30:26 +0000 (22:30 +0200)]
Sync ACPICA with Intel's version 20180810:

* Attempt to continue initially loading ACPI tables regardless of
  malformed AML.

* Enhance acpiexec(8)'s -fi option and plug a memory leak in it.

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

5 years agodrm: Sync drm_pci.c with Linux 4.7.10
François Tigeot [Fri, 10 Aug 2018 19:11:19 +0000 (21:11 +0200)]
drm: Sync drm_pci.c with Linux 4.7.10

5 years agodrm: Add CONFIG_PCI
François Tigeot [Fri, 10 Aug 2018 19:07:16 +0000 (21:07 +0200)]
drm: Add CONFIG_PCI

5 years agodrm/linux: Add field devfn to struct pci_dev
François Tigeot [Thu, 9 Aug 2018 21:01:42 +0000 (23:01 +0200)]
drm/linux: Add field devfn to struct pci_dev

5 years agoMove fpclassify.3 from libc to libm where it belongs.
Sascha Wildner [Thu, 9 Aug 2018 12:32:06 +0000 (14:32 +0200)]
Move fpclassify.3 from libc to libm where it belongs.

5 years agoAdd back a signbit.3 manpage that was killed w/o providing a substitute.
Sascha Wildner [Thu, 9 Aug 2018 12:31:25 +0000 (14:31 +0200)]
Add back a signbit.3 manpage that was killed w/o providing a substitute.

5 years agofpgetround.3: Replace references to the former fenv.3 manual page.
Sascha Wildner [Thu, 9 Aug 2018 12:27:02 +0000 (14:27 +0200)]
fpgetround.3: Replace references to the former fenv.3 manual page.

OpenBSD's libm has 4 separate manual pages for these.

5 years agoRemove two references (one commented) to a non-existant manpage.
Sascha Wildner [Thu, 9 Aug 2018 11:41:47 +0000 (13:41 +0200)]
Remove two references (one commented) to a non-existant manpage.

5 years agoRemove some documentation of the i386 specific fpresetsticky().
Sascha Wildner [Thu, 9 Aug 2018 07:26:03 +0000 (09:26 +0200)]
Remove some documentation of the i386 specific fpresetsticky().

5 years agoRevert "pf: Allow disappearing or not yet existing interfaces for ALTQ"
Aaron LI [Thu, 9 Aug 2018 02:40:36 +0000 (10:40 +0800)]
Revert "pf: Allow disappearing or not yet existing interfaces for ALTQ"

This reverts commit 0a887f91f9633448c99b9a5b7c6116a0a22d25d6.

1. It's incorrect to change the ifnet_unlock().  The original protection
   range is used to make sure that the ifp does not get ripped out behind
   our back.

2. We don't suffer from the issue that that commit was intended to fix.

Thanks-to: sephe

5 years agoeventhandler.9: Update events list
Aaron LI [Mon, 25 Jun 2018 09:59:15 +0000 (17:59 +0800)]
eventhandler.9: Update events list

* Remove "dev_clone"

* Add "iflladdr_event", "mountroot", and "usb_dev_configured".
  Descriptions are taken from FreeBSD.

5 years agobpf: Move bpf_track event declaration to <net/bpf.h>
Aaron LI [Mon, 25 Jun 2018 09:31:16 +0000 (17:31 +0800)]
bpf: Move bpf_track event declaration to <net/bpf.h>

Move the declaration of the "bpf_track" event from <sys/eventhandler.h>
to <net/bpf.h>.

Document the "bpf_track" event in eventhandler.9 man page.

Based on FreeBSD.

5 years agoeventhandler: Implement ifnet_link_event
Aaron LI [Mon, 25 Jun 2018 09:04:41 +0000 (17:04 +0800)]
eventhandler: Implement ifnet_link_event

The "ifnet_link_event" is triggered by the change of the link state of
an interface.

Taken-from: FreeBSD

5 years agoeventhandler: Implement ifnet_event
Aaron LI [Mon, 25 Jun 2018 09:00:21 +0000 (17:00 +0800)]
eventhandler: Implement ifnet_event

Implement the "ifnet_event" which is triggered on interface up and down.

Taken-from: FreeBSD

5 years agoif_loop: Use ifc->ifc_name and minor cleanups
Aaron LI [Thu, 21 Jun 2018 05:49:15 +0000 (13:49 +0800)]
if_loop: Use ifc->ifc_name and minor cleanups

* Use "ifc->ifc_name" instead of explicit "lo".

* Minor style updates.

5 years agopf.conf.5: Describe the use of interface group
Aaron LI [Tue, 26 Jun 2018 05:42:42 +0000 (13:42 +0800)]
pf.conf.5: Describe the use of interface group

Add the description on interface group, which is supported by DragonFly
BSD's PF now.

Meanwhile, bring in many small updates/fixes from FreeBSD.

5 years agoMove pf.conf.5 and pf.os.5 to share/man/man5
Aaron LI [Tue, 26 Jun 2018 04:25:07 +0000 (12:25 +0800)]
Move pf.conf.5 and pf.os.5 to share/man/man5

5 years agonet: Tweak some styles and comments
Aaron LI [Thu, 21 Jun 2018 05:56:00 +0000 (13:56 +0800)]
net: Tweak some styles and comments

5 years agopf: Allow disappearing or not yet existing interfaces for ALTQ
Aaron LI [Sat, 16 Jun 2018 15:18:20 +0000 (23:18 +0800)]
pf: Allow disappearing or not yet existing interfaces for ALTQ

Make ALTQ cope with disappearing interfaces (particularly common with
net/mpd4 and netgraph in general).  This also allows to add queues for
an interface that is not yet existing, however, you have to provide
the bandwidth for the interface.

Meanwhile, simplify the ifnet_unlock() calls for ifunit() use.

Taken-from: FreeBSD (r177700)

5 years agopf: Fix and improve interface group support
Aaron LI [Sat, 16 Jun 2018 14:48:38 +0000 (22:48 +0800)]
pf: Fix and improve interface group support

The old PF code has broken partial support of the interface group.
Without this patch, loading the 'pf.ko' module will panic the system.

* Add event handlers of pfi_{attach,detach,change}_group_event()
  to support the interface groups.  Meanwhile, add event handler
  of pfi_ifaddr_event() that is called when an address is set up
  on an interface, and update pfi_{attach,detach}_event() handlers.
  (Based on FreeBSD)

* Remove function pfi_kifaddr_update() as it is merged into
  pfi_ifaddr_event() handler.

* Update pfi_initialize() and pfi_cleanup() functions (Based on
  FreeBSD).

* Split function pfi_kif_find() out of pfi_kif_get().
  (Based on OpenBSD)

* The PF module will be properly initialized on module load, so remove
  extra pfi_initialize() calls.

* Rename malloc type 'PFI_MTYPE' to 'M_PFI',  and merge with malloc type
  'M_PFIADDRPL'.

* Staticize internal functions and variables.

* Some cleanups and style updates.

Thanks to sephe for the guidance.

5 years agopf: Update pfi_kif and pfi_kif_cmp structs
Aaron LI [Thu, 21 Jun 2018 00:59:47 +0000 (08:59 +0800)]
pf: Update pfi_kif and pfi_kif_cmp structs

For struct "pfi_kif", add "pfik_name" entry while remove multiple obsolete
entries and macros.  Rename "pfik_ifname" to "pfik_name" for "pfi_kif_cmp"
struct.

Based on both OpenBSD and FreeBSD.

5 years agoif_pfsync: Depend on "pf" module and some cleanups
Aaron LI [Thu, 21 Jun 2018 01:40:05 +0000 (09:40 +0800)]
if_pfsync: Depend on "pf" module and some cleanups

* Explicitly depend on the "pf" module to make sure it is initialized
  later.

* Remove the unnecessary ksnprintf directive that sets if_xname.

* Order several directives in pfsync_clone_create(), making it more
  consistent with pflog_clone_create().

5 years agoif_pflog: Explicitly depend on "pf" and various cleanups
Aaron LI [Thu, 21 Jun 2018 01:31:44 +0000 (09:31 +0800)]
if_pflog: Explicitly depend on "pf" and various cleanups

* Explicitly depend on the "pf" module to make sure it is initialized
  later than the "pf" main module.

* Fix a missing lwkt token release in pflog_clone_create().

* Remove unnecessary kmalloc() check.

* Use if_initname() to properly set up if_{xname,dname,dunit}.

* Use pflogattach() in module load event handle.

* Staticize functions and variables.

* Remove the unused pflogrtrequest() function.

* Remove the "old_pfloghdr" struct from if_pflog.h.

* Mark some __unused variables.

5 years agoifconfig(8): Add group support
Aaron LI [Sat, 16 Jun 2018 15:01:21 +0000 (23:01 +0800)]
ifconfig(8): Add group support

Obtained from FreeBSD, with some minor changes.

5 years agoif_clone: Add cloned interface to the group of its device name
Aaron LI [Thu, 21 Jun 2018 06:40:31 +0000 (14:40 +0800)]
if_clone: Add cloned interface to the group of its device name

When a new interface is cloned, add it to the group of its device name,
e.g., cloned interfaces tapX will belong to group of "tap" by default.

5 years agonet: Implement interface group support
Aaron LI [Sat, 16 Jun 2018 14:25:31 +0000 (22:25 +0800)]
net: Implement interface group support

The network interface group (aka ifgroup) functionality is currently only
used by the PF (still needs patch to make PF use the ifgroup), allowing
rules to use group names instead of the specific interface names, which
makes firewall rules more generic and simpler.

* The ifgroup data are stored at the following two places:
  - The global list of 'struct ifg_group': each entry is a group which has
    the name and members (a list of pointers to the interfaces).
  - The per-ifnet 'if_groups' list, which records the groups that the
    interface belongs to.

* Introduce the 'ifgroup_lock' locakmgr(9) to protect the global list
  of 'struct ifg_group' and per-ifnet 'if_groups' list.  The R/W locking
  operations are provided by the ifgroup_lockmgr() function.

* Move the copyout() out of the locked loop in if_getgroups() and
  if_getgroupmembers() functions.

* Fix several M_NOWAIT to be M_WAITOK.

* Use M_IFNET instead of M_TEMP for allocated ifgroup memory.

* Add SIOC[ADG]IFGROUP and SIOCGIFGMEMB ioctl's,
  bump __DragonFly_version.

* Add invocations to group_{attach,change,detach}_event handlers.

* Update eventhandler.9 man page.

* Some style updates.

Great thanks to sephe for his patient guidance and review.

Credit to both FreeBSD and OpenBSD for the ifgroup functionality.

NOTE:
When delete the only group from an interface, which leaves an empty
group that will be destroyed, make sure the group_change_event event
is invoked *before* the group destroy (i.e., group_detach_event).
Both FreeBSD and OpenBSD have the ordering problem with group detach
event.  Need to report the problem to them.

5 years agoif_clone: Refactor out if_clone_createif() function
Aaron LI [Mon, 6 Aug 2018 07:36:41 +0000 (15:36 +0800)]
if_clone: Refactor out if_clone_createif() function

The new if_clone_createif() function will create a clone interface
with the given cloner and unit.

5 years agoif_clone: Check cloner name to avoid duplicate in if_clone_attach()
Aaron LI [Sun, 5 Aug 2018 16:34:25 +0000 (00:34 +0800)]
if_clone: Check cloner name to avoid duplicate in if_clone_attach()

Change if_clone_attach() to check the cloner name instead of the pointer
to avoid duplicate, also to return EEXIST instead of panic.

5 years agoif_clone: Refactor out if_clone_{alloc,free}_unit() functions
Aaron LI [Sun, 5 Aug 2018 16:10:54 +0000 (00:10 +0800)]
if_clone: Refactor out if_clone_{alloc,free}_unit() functions

Refactor out if_clone_{alloc,free}_unit() functions from
if_clone_{create,destroy}() functions.

5 years agoif_clone: Remove useless code wrongly added in 84cb91c376f
Aaron LI [Sun, 5 Aug 2018 16:09:53 +0000 (00:09 +0800)]
if_clone: Remove useless code wrongly added in 84cb91c376f

The code was inteded to obtain the created interface and add an
interface group for it, which is a work in progress.

5 years agoFix up more files for the <net/if.h> / <net/if_var.h> split (fixes LINT64).
Sascha Wildner [Tue, 7 Aug 2018 17:55:33 +0000 (19:55 +0200)]
Fix up more files for the <net/if.h> / <net/if_var.h> split (fixes LINT64).

5 years agodevelopment.7: Update repo creation command
Aaron LI [Tue, 7 Aug 2018 02:40:31 +0000 (10:40 +0800)]
development.7: Update repo creation command

Reported-by: resolution (on IRC)
5 years agodrm: Sync drm_read() with Linux 4.7.10
François Tigeot [Sun, 5 Aug 2018 15:07:46 +0000 (17:07 +0200)]
drm: Sync drm_read() with Linux 4.7.10

This should fix various issues related to multithreaded races
and make the drm subsystem more robust.

5 years agoif_clone: Fix if_clone_destroy() with renamed cloned interface
Aaron LI [Sat, 4 Aug 2018 12:30:04 +0000 (20:30 +0800)]
if_clone: Fix if_clone_destroy() with renamed cloned interface

Since the interface can be renamed (SIOCSIFNAME), it's very wrong for
if_clone_destroy() to determine the unit number from interface name,
which has the following two serious problems:

(1) One may only change the unit number in the interface name, then
trying to destroy the interface will panic the system. e.g.,
% ifconfig tap0 create
% ifconfig tap0 name tap99999999
% ifconfig tap99999999 destroy
-> panic: if_clone_destroy: bit is already cleared

(2) The renamed interface cannot be destroyed anymore. e.g.,
% ifconfig tap0 create
% ifconfig tap0 name test
% ifconfig test destroy
-> ifconfig: SIOCIFDESTROY: Invalid argument

Fix the code to use the 'if_dunit' as the correct interface unit number.

Thanks to Jason A. Donenfeld <jason@zx2c4.com> and Brady OBrien
<brady.obrien128@gmail.com> for pointing out the above problem (1).

5 years agoif_clone: Refactor cloner lookup and unit extraction
Aaron LI [Sat, 4 Aug 2018 12:06:21 +0000 (20:06 +0800)]
if_clone: Refactor cloner lookup and unit extraction

Break down the old 'if_clone_lookup()' function into the following 3
functions:

- if_name2unit(): extract the unit number from the interface name.
  Obtained from FreeBSD and has fixes (disallow leading zeros; avoid
  unit overflow).

- if_clone_match(): check whether the cloner matches the interface name.

- new if_clone_lookup(): only lookup the cloner for the interface name.

5 years agoif_clone: Remove unneeded "ifc_namelen" from "struct if_clone"
Aaron LI [Sat, 4 Aug 2018 12:13:39 +0000 (20:13 +0800)]
if_clone: Remove unneeded "ifc_namelen" from "struct if_clone"

The "strlen(ifc_name)" is used instead.

5 years agoif_clone: Move "struct if_clonereq" over from <net/if.h>
Aaron LI [Thu, 21 Jun 2018 00:36:00 +0000 (08:36 +0800)]
if_clone: Move "struct if_clonereq" over from <net/if.h>

The "if_clonereq" struct is __BSD_VISIBLE and is only used by ifconfig(8)
userland tool (via searching "if_clonereq" in the dports grok), so it's
safe to move it to <net/if_clone.h> to be clearer.

5 years agoif_clone: Refactor if_clone_create()
Aaron LI [Fri, 22 Jun 2018 13:47:22 +0000 (21:47 +0800)]
if_clone: Refactor if_clone_create()

In the wildcard case (the caller passes the interface name without
a unit number), if_clone_create() should update the passed name
parameter with the allocated unit number in order to make the caller
know the name of the cloned interface, e.g., ifconfig(8) compares
the passed and returned interface name.  Therefore the caller should
preserve enough space (given by the "len" parameter) to hold the full
interface name.  This shouldn't be a problem since the caller generally
use the "struct if_clonereq" which has enough space for the name.

For the name update code, use simple and clear strlcpy() to replace the
hack with a for loop and obscure snprintf(), and return ENOSPC instead
of panic.

Simplify the ifnet lock a bit.

5 years agoif_clone: Explicitly include <sys/eventhandler.h>
Aaron LI [Tue, 20 Mar 2018 08:11:46 +0000 (16:11 +0800)]
if_clone: Explicitly include <sys/eventhandler.h>

Eventhandler is used there, so include the <sys/eventhandler.h> header
explicitly.

Minor style updates.

5 years agoif_clone: Fix if_clone_event invocation
Aaron LI [Thu, 21 Jun 2018 00:42:16 +0000 (08:42 +0800)]
if_clone: Fix if_clone_event invocation

As the parameter passed to the "if_clone_event" handler indicates, this
event should be triggered when a new interface cloner is *attached*,
rather than when a clone interface is created.  (Based on FreeBSD)

Update the eventhandler.9 man page accordingly.

5 years agoetc/login.conf: Fix COPYRIGHT file path
Aaron LI [Sun, 5 Aug 2018 02:40:46 +0000 (10:40 +0800)]
etc/login.conf: Fix COPYRIGHT file path

5 years agoMakefile.inc1: Print more variables on error
Aaron LI [Fri, 15 Jun 2018 05:01:54 +0000 (13:01 +0800)]
Makefile.inc1: Print more variables on error

Print the .MAKE.MODE, PATH, MAKESYSPATH, MAKEOBJDIRPREFIX, DESTDIR,
SHELL, .SHELL, .MAKE.MAKEFILES, and .PATH variables on error.
(Based on FreeBSD: share/mk/{local,meta}.sys.mk)

5 years agoifconfig(8): Use atexit() to ensure printing interface name
Aaron LI [Fri, 22 Jun 2018 13:23:25 +0000 (21:23 +0800)]
ifconfig(8): Use atexit() to ensure printing interface name

The ifconfig program may not exit at the end of its main() function,
so use atexit(printifnamemaybe) to ensure the interface name (e.g.,
newly cloned but with wildcard name) is printed on exit.
(Taken from FreeBSD)

Use "return (0)" instead of "exit(0)" in the main() function.

Minor whitespace updates.

5 years agoifconfig(8): Sync with FreeBSD a bit and various cleanups
Aaron LI [Sat, 24 Mar 2018 08:56:39 +0000 (16:56 +0800)]
ifconfig(8): Sync with FreeBSD a bit and various cleanups

* Sync ifconfig.c a bit with FreeBSD; replace several warnx() with
  errx(), and improve error messages a bit.

* Remove unnecessary exit() after Perror().

* Sync if_clone.c with FreeBSD.

* Add inclusion guard to ifconfig.h.

* Make iseq() a static function for ifieee80211.c and regdomain.c,
  replacing the duplicate definitions of it; and use iseq()
  consistently to replace strncasecmp() and strcasecmp().

* Move "struct ident" from regdomain.c to regdomain.h, and add and use
  "enum IdentType".

* Various whitespace cleanups.

* Cleanup header file inclusion: remove duplicates, and reorder a bit.

* Fix various signed vs. unsigned comparisons.

* Fix some compilation warnings, and raise WARNS to 3.

5 years agoifconfig(8): Default to AF_LOCAL sockets for non-family-specific operations
Aaron LI [Fri, 23 Mar 2018 01:40:57 +0000 (09:40 +0800)]
ifconfig(8): Default to AF_LOCAL sockets for non-family-specific operations

This allows the query operations to work in non-IPv4 jails, as will be necessary
in a future possible non-INET networking.

Obtained-from: FreeBSD (r18964)

5 years agoifconfig(8): Use strlcpy() instead of strncpy()
Aaron LI [Fri, 23 Mar 2018 01:37:13 +0000 (09:37 +0800)]
ifconfig(8): Use strlcpy() instead of strncpy()

5 years agoifconfig(8): Use nitems() consistently
Aaron LI [Tue, 20 Mar 2018 07:45:43 +0000 (15:45 +0800)]
ifconfig(8): Use nitems() consistently

5 years ago<net/if_var.h>: Clean up unused forward declaration
Aaron LI [Tue, 20 Mar 2018 08:15:42 +0000 (16:15 +0800)]
<net/if_var.h>: Clean up unused forward declaration

Also remove the inclusion of an unnecessary header <sys/systm.h>.

5 years ago<net/if.h>: Do not include <net/if_var.h> for _KERNEL
Aaron LI [Tue, 20 Mar 2018 08:04:41 +0000 (16:04 +0800)]
<net/if.h>: Do not include <net/if_var.h> for _KERNEL

* Clean up an ancient leftover: do not include <net/if_var.h> from <net/if.h>
  for kernel stuffs.

* Adjust various files to include the necessary <net/if_var.h> header.

NOTE:
I have also tested removing the inclusion of <net/if.h> from <net/if_var.h>,
therefore add <net/if.h> inclusion for those files that need it but only
included <net/if_var.h>.  For some files, the header inclusion orderings are
also adjusted.

5 years agopc64 - If appropriate, determine TSC frequency via CPUID.
Imre Vadász [Sat, 4 Aug 2018 15:09:26 +0000 (17:09 +0200)]
pc64 - If appropriate, determine TSC frequency via CPUID.

On Intel systems with Skylake and newer CPUs, and on modern Atom CPUs this
avoids the ca. 200ms TSC calibration process at the beginning of booting.

On most modern Intel CPUs the TSC frequency can be determined via CPUID
information. For the most modern generations this is quite well documented.
If the CPUID information doesn't directly specify the "crystal clock",
we use the frequency values given in Intel's "Software Developer's Manual"
for the different cpu variants.

Since the "crystal clock" seems to exactly match the HPET frequency that we
use in the calibration, this method should be at least as good as our
calibration procedure.

Setting the tunable hw.tsc_ignore_cpuid=1 forces the kernel to calibrate
the TSC if it would otherwise just use the CPUID information.

5 years agoif_tap: Interface type should be IFT_ETHER (2)
Aaron LI [Sat, 4 Aug 2018 14:06:32 +0000 (22:06 +0800)]
if_tap: Interface type should be IFT_ETHER (2)

Ooops, forgot to include the necessary header <net/if_types.h> in the
last commit.

5 years agoif_tap: Interface type should be IFT_ETHER
Aaron LI [Sat, 4 Aug 2018 13:07:04 +0000 (21:07 +0800)]
if_tap: Interface type should be IFT_ETHER

5 years agocorepower - Add support for Platform Energy Counter.
Imre Vadász [Sat, 4 Aug 2018 08:58:17 +0000 (10:58 +0200)]
corepower - Add support for Platform Energy Counter.

5 years agotun.4: Do not mention tunoutput() anymore
Aaron LI [Fri, 3 Aug 2018 12:10:56 +0000 (20:10 +0800)]
tun.4: Do not mention tunoutput() anymore

The tunoutput() function was renamed to be tunifoutput(), and it's an
internal function and doesn't provide useful information here.

5 years agodevfs: Minor style fixes
Aaron LI [Fri, 3 Aug 2018 12:09:19 +0000 (20:09 +0800)]
devfs: Minor style fixes

5 years agofdisk, gpt - Support trim on recent kernels
Matthew Dillon [Wed, 1 Aug 2018 21:38:34 +0000 (14:38 -0700)]
fdisk, gpt - Support trim on recent kernels

* Recent kernels removed the 'trim' sysctls.  Devices now allow trim by
  default.

* Fix the fdisk -E option to no longer try to use the sysctls.

* Add trim support to gpt init (-E).

* Fix swapon -e, change option to -E to match gpt and fdisk
  (-e still supported and does the same thing).

5 years agodrm: Sync drm_bufs.c with Linux 4.7.10
François Tigeot [Wed, 1 Aug 2018 19:27:14 +0000 (21:27 +0200)]
drm: Sync drm_bufs.c with Linux 4.7.10

5 years agohammer2 - Add destroy-inum directive
Matthew Dillon [Wed, 1 Aug 2018 17:14:46 +0000 (10:14 -0700)]
hammer2 - Add destroy-inum directive

* Add support for destroying screwed up inodes (e.g. inodes with CRC
  failures and such).

  hammer2 -s filesystem destroy-inum inode_number

  This will attempt to destroy an inode number without reading it,
  allowing the removal of dead inodes from a corrupted filesystem.

* This is similar to 'hammer2 destroy path', which destroys dead
  directory entries, but acts on the inode instead of on the
  directory entry.

5 years agodrm: simplify authentication management
François Tigeot [Tue, 31 Jul 2018 21:04:04 +0000 (23:04 +0200)]
drm: simplify authentication management

5 years agoif_tap: Remove the unnecessary forward declaration in if_tap.h
Aaron LI [Tue, 31 Jul 2018 11:59:45 +0000 (19:59 +0800)]
if_tap: Remove the unnecessary forward declaration in if_tap.h

5 years agoif_tun: Add TUNGIFNAME ioctl to get the interface name
Aaron LI [Tue, 31 Jul 2018 11:47:37 +0000 (19:47 +0800)]
if_tun: Add TUNGIFNAME ioctl to get the interface name

This ioctl helps to get the name of the network interface associated
with the tun control device via its file descriptor.  One generally
obtains such a file descriptor by opening the tun autocloner (i.e.,
/dev/tun).  While the devname(3) or fdevname(3) functions can be used
to determine the name of the actually created tun device, but there is
no easy way to get the name of the associated network interface, which
is though initially the same as the device name but can be renamed.

Bump __DragonFly_version and update tun.4 man page.

See also the relevant Linux patch that added TUNGETIFF to tun:
https://lists.linuxfoundation.org/pipermail/virtualization/2008-August/011546.html

5 years agoif_tun: Clean up tunioctl()
Aaron LI [Tue, 31 Jul 2018 11:43:48 +0000 (19:43 +0800)]
if_tun: Clean up tunioctl()

Introduce a variable 'caddr_t data' to make code cleaner.  Also improve
the switch flow a bit.

Based on: if_tap.c

5 years agodrm: More Linux 4.7.10 synchronization
François Tigeot [Mon, 30 Jul 2018 20:44:20 +0000 (22:44 +0200)]
drm: More Linux 4.7.10 synchronization

* Add missing event handling code

* Sync or add a few drm_fops.c functions

* Remove unneeded kqueue locking

5 years agohammer2 - Do not assert when shifting around error'd BREFs
Matthew Dillon [Mon, 30 Jul 2018 19:04:49 +0000 (12:04 -0700)]
hammer2 - Do not assert when shifting around error'd BREFs

* When adjusting the radix tree and shifting around BREFs, do not
  assert if the related chain has cached an error (such as a CRC
  error).  The BREF itself can still be moved.

5 years agoinstall(1): Fix building on release and older systems.
Sascha Wildner [Sat, 28 Jul 2018 12:48:16 +0000 (14:48 +0200)]
install(1): Fix building on release and older systems.

While here, add a comment about this to mtree(8)'s Makefile too.

5 years agoinstall(1): Add a -l flag for creating hard or soft links
François Tigeot [Sat, 28 Jul 2018 06:50:52 +0000 (08:50 +0200)]
install(1): Add a -l flag for creating hard or soft links

* This flag was originally introduced in NetBSD in March 1997 and then added
  to FreeBSD in January 2013.

* It will make it easier to update dports(7) from FreeBSD ports.

* The previous DragonFly-specific -l flag was no longer used.

Obtained-from: NetBSD and FreeBSD

5 years agosys/vfs/autofs: Make {test,nlookup}_fs_root() return bool
Tomohiro Kusumi [Thu, 26 Jul 2018 18:18:25 +0000 (11:18 -0700)]
sys/vfs/autofs: Make {test,nlookup}_fs_root() return bool

Change return type of DragonFly specific utility functions for
triggering (very different from FreeBSD, NetBSD and OpenBSD).

5 years agosys/vfs/autofs: Cleanup
Tomohiro Kusumi [Thu, 26 Jul 2018 18:14:09 +0000 (11:14 -0700)]
sys/vfs/autofs: Cleanup

5 years agoMove jail staffs from <net/if.h> and <netinet/in.h> to <sys/jail.h>
Aaron LI [Tue, 20 Mar 2018 07:52:54 +0000 (15:52 +0800)]
Move jail staffs from <net/if.h> and <netinet/in.h> to <sys/jail.h>

* <net/if.h>: Move out prison_if() function prototype to <sys/jail.h>

* <netinet/in.h>: Move out prison_replace_wildcards() and prison_remote_ip()
  function prototypes to <sys/jail.h>

* Include <sys/jail.h> header for those files in need of it

Obtained-from: FreeBSD (r72786)

5 years agokernel: Use nitems() from <sys/param.h> instead of custom define
Aaron LI [Tue, 20 Mar 2018 07:48:55 +0000 (15:48 +0800)]
kernel: Use nitems() from <sys/param.h> instead of custom define

Since <sys/param.h> is already included in these files.

5 years agodisklabel64(8): Remove an obsolete comment
Aaron LI [Tue, 24 Jul 2018 01:22:59 +0000 (09:22 +0800)]
disklabel64(8): Remove an obsolete comment

Also consistently use the locally defined streq() function.

5 years agosys/gpt.h: Add new entry types and CTASSERT
Aaron LI [Tue, 24 Jul 2018 01:20:14 +0000 (09:20 +0800)]
sys/gpt.h: Add new entry types and CTASSERT

Obtained-from: FreeBSD