]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
6 years agoMFC r308851 (by imp):
mav [Thu, 1 Feb 2018 16:15:03 +0000 (16:15 +0000)]
MFC r308851 (by imp):
Expand the SMART / Health Information Log Page (Page 02) printout
based on NVM Express 1.2.1 Standard.

6 years agoMFC r308850 (by imp):
mav [Thu, 1 Feb 2018 16:13:28 +0000 (16:13 +0000)]
MFC r308850 (by imp):
Print numbers instead of hex values for smart data. The full 128-bit
number is printed, even though you'd need like a billion IOPs for a 10
billion seconds to overflow the 64-bit counters (~300 years).

6 years agoMFC r308431 (by scottl):
mav [Thu, 1 Feb 2018 15:46:19 +0000 (15:46 +0000)]
MFC r308431 (by scottl):
Convert the Q-Pair and PRP list memory allocations to use BUSDMA.  Add a
bunch of safery belts and error handling in related codepaths.

6 years agoMFC r303466: Kill a few stray debug printfs.
mav [Thu, 1 Feb 2018 15:32:48 +0000 (15:32 +0000)]
MFC r303466: Kill a few stray debug printfs.

6 years agoMFC r303126 (by imp):
mav [Thu, 1 Feb 2018 15:32:14 +0000 (15:32 +0000)]
MFC r303126 (by imp):
Actually import nvme_sim so the CAM attachment for NVME (nda) actually
works.

6 years agoMFC r303040, r303042 (by scottl):
mav [Thu, 1 Feb 2018 15:27:47 +0000 (15:27 +0000)]
MFC r303040, r303042 (by scottl):
Supporting flushing the dump before returning, and simplify/combine the
logic.  Switch to a 5us delay since most NVME devices can easily do 200,000
iops.

6 years agoMFC r303017 (by imp): Implement crashdump support on NVME
mav [Thu, 1 Feb 2018 15:23:49 +0000 (15:23 +0000)]
MFC r303017 (by imp): Implement crashdump support on NVME

6 years agoMFC r328398:
markj [Thu, 1 Feb 2018 14:36:59 +0000 (14:36 +0000)]
MFC r328398:
Remove uneeded parentheses.

6 years agoMFC r328399:
markj [Thu, 1 Feb 2018 14:36:24 +0000 (14:36 +0000)]
MFC r328399:
Use tcpinfoh_t for TCP headers in the tcp:::debug-{drop,input} probes.

6 years agoMFC r328623:
hselasky [Thu, 1 Feb 2018 13:10:58 +0000 (13:10 +0000)]
MFC r328623:
Properly implement the cond_resched() function macro in the LinuxKPI.

Sponsored by: Mellanox Technologies

6 years agoMFC r328329:
hselasky [Thu, 1 Feb 2018 13:04:01 +0000 (13:04 +0000)]
MFC r328329:
Properly implement the "id" callback argument in the "idr_for_each" function
in the LinuxKPI. The old implementation assumed only one IDR layer was present.
Take additional IDR layers into account when computing the "id" value.

Found by: Karthik Palanichamy <karthikp@chelsio.com>
Tested by: Karthik Palanichamy <karthikp@chelsio.com>
Sponsored by: Mellanox Technologies

6 years agoMFC r310014-r327788:
hselasky [Thu, 1 Feb 2018 13:01:44 +0000 (13:01 +0000)]
MFC r310014-r327788:
This is an overwrite merge backport of the LinuxKPI from FreeBSD-head.
Following is a complete list of MFC'ed revisions and also partially
MFC'ed revisions in the end. The MFC'ed revision are listed in
incremental order.

Bump the __FreeBSD_version to force recompilation of any external
kernel modules.

Sponsored by: Mellanox Technologies

MFC r310014:
Remove the only user of sysctl_add_oid().

My plan is to change this function's prototype at some point in the
future to add a new label argument, which can be used to export all of
sysctl as metrics that can be scraped by Prometheus. Switch over this
caller to use the macro wrapper counterpart.

MFC r310031:
linuxkpi: Fix not-found case of linux_pci_find_irq_dev

Linux list_for_each_entry() does not neccessarily end with the iterator
NULL (it may be an offset from NULL if the list member is not the first
element of the member struct).

Reported by:    Coverity
CID:            1366940
Reviewed by:    hselasky@
Sponsored by:   Dell EMC Isilon
Differential Revision:  https://reviews.freebsd.org/D8780

MFC r313806:
Whitespace fix.

Obtained from:          kmacy @
Sponsored by:           Mellanox Technologies

MFC r313807:
Allow passing a constant atomic_t to atomic_read().

Obtained from:          kmacy @
Sponsored by:           Mellanox Technologies

MFC r313808:
Implement more LinuxKPI atomic functions and macros.

Obtained from:          kmacy @
Sponsored by:           Mellanox Technologies

MFC r313810:
Allow container_of() to be used with constant data pointers.

Obtained from:          kmacy @
Sponsored by:           Mellanox Technologies

MFC r313872:
Implement GFP_DMA32 flag in the LinuxKPI.
Define all FreeBSD native GFP bits as GFP_NATIVE_MASK.

Obtained from:          kmacy @
Sponsored by:           Mellanox Technologies

MFC r314040:
Make the LinuxKPI task struct persistent accross system calls.

A set of helper functions have been added to manage the life of the
LinuxKPI task struct. When an external system call or task is invoked,
a check is made to create the task struct by demand. A thread
destructor callback is registered to free the task struct when a
thread exits to avoid memory leaks.

This change lays the ground for emulating the Linux kernel more
closely which is a dependency by the code using the LinuxKPI APIs.

Add new dedicated td_lkpi_task field has been added to struct thread
instead of abusing td_retval[1].

Fix some header file inclusions to make LINT kernel build properly
after this change.

Bump the __FreeBSD_version to force a rebuild of all kernel modules.

Sponsored by:           Mellanox Technologies

MFC r314043:
Add support for LinuxKPI tasklets.

Tasklets are implemented using a taskqueue and a small statemachine on
top. The additional statemachine is required to ensure all LinuxKPI
tasklets get serialized. FreeBSD taskqueues do not guarantee
serialisation of its tasks, except when there is only one worker
thread configured.

Sponsored by:           Mellanox Technologies

MFC r314044:
Streamline the LinuxKPI spinlock wrappers.

1) Add better spinlock debug names when WITNESS_ALL is defined.

2) Make sure that the calling thread gets bound to the current CPU
while a spinlock is locked. Some Linux kernel code depends on that the
CPU ID doesn't change while a spinlock is locked.

3) Add support for using LinuxKPI spinlocks during a panic().

Sponsored by:           Mellanox Technologies

MFC r314050:
Replace dummy implementation of RCU in the LinuxKPI with one based on
the in-kernel concurrency kit's ck_epoch API. Factor RCU hlist_xxx()
functions into own rculist.h header file.

Obtained from:          kmacy @
Sponsored by:           Mellanox Technologies

MFC r314105:
Improve LinuxKPI scatter list support.

The i915kms driver in Linux 4.9 reimplement parts of the scatter list
functions with regards to performance. In other words there is not so
much room for changing structure layouts and functionality if the
i915kms should be built AS-IS. This patch aligns the scatter list
support to what is expected by the i915kms driver. Remove some
comments not needed while at it.

Obtained from:          kmacy @
Sponsored by:           Mellanox Technologies

MFC r314106:
Optimise unmapped LinuxKPI page allocations.

When allocating unmapped pages, take advantage of the direct map on
AMD64 to get the virtual address corresponding to a page. Else all
pages allocated must be mapped because sometimes the virtual address
of a page is requested.

Move all page allocation and deallocation code into an own C-file.

Add support for GFP_DMA32, GFP_KERNEL, GFP_ATOMIC and __GFP_ZERO
allocation flags.

Make a clear separation between mapped and unmapped allocations.

Obtained from:          kmacy @
Sponsored by:           Mellanox Technologies

MFC r314109:
Convert magic values into macros in the LinuxKPI scatterlist
implementation.

Suggested by:           cem @
Sponsored by:           Mellanox Technologies

MFC r314136:
Implement __test_and_clear_bit() and __test_and_set_bit() in the LinuxKPI.

The clang compiler will optimise these functions down to three AMD64
instructions if the bit argument is a constant during compilation.

Sponsored by:           Mellanox Technologies

MFC r314205:
Implement BIT_ULL() macro in the LinuxKPI.

Sponsored by:           Mellanox Technologies

MFC r314207:
Implement srcu_dereference() macro in the LinuxKPI.

Sponsored by:           Mellanox Technologies

MFC r314214:
Prototype device structure to ensure LinuxKPI header file can be
included standalone.

Sponsored by:           Mellanox Technologies

MFC r314215:
Implement more string functions in the LinuxKPI.

Sponsored by:           Mellanox Technologies

MFC r314336:
Define __sum16 type in the LinuxKPI.

Sponsored by:           Mellanox Technologies

MFC r314337:
Implement more bit operation functions in the LinuxKPI.
Some minor whitespace nits while at it.

Obtained from:          kmacy @
Sponsored by:           Mellanox Technologies

MFC r314604:
Update the LinuxKPI RCU and SRCU wrappers for the concurrency kit, CK.

- Optimise the RCU implementation to not allocate and free
ck_epoch_records during runtime. Instead allocate two sets of
ck_epoch_records per CPU for general purpose use. The first set is
only used for reader locks and the second set is only used for
synchronization and barriers and is protected with a regular mutex to
prevent simultaneous issues.

- Move the task structure away from the rcu_head structure and into
the per-CPU structures. This allows the size of the rcu_head structure
to be reduced down to the size of two pointers.

- Fix a bug where the linux_rcu_barrier() function only waited for one
per-CPU epoch record to be completed instead of all.

- Use a critical section or a mutex to protect ck_epoch_begin() and
ck_epoch_end() depending on RCU or SRCU type. All the ck_epoch_xxx()
functions, except ck_epoch_register(), ck_epoch_unregister() and
ck_epoch_recycle() are not re-entrant and needs a critical section or
a mutex to operate in the LinuxKPI, after inspecting the CK
implementation of the above mentioned functions. The simultaneous
issues arise from per-CPU epoch records being shared between multiple
threads depending on the amount of taskswitching and how many threads
are involved with the RCU and SRCU operations.

- Properly free all epoch records by using safe list traversal at
LinuxKPI module unload. It turns out the ck_epoch_recycle() always
have the records on an internal list and use a flag in the epoch
record to track allocated and free entries. This would lead to use
after free during module unload.

- Remove redundant synchronize_rcu() call from the
linux_compat_uninit() function. Let the linux_rcu_runtime_uninit()
function do the final rcu_barrier() instead.

Sponsored by:           Mellanox Technologies

MFC r314675:
Remove duplicate prototype in the LinuxKPI to fix compilation warning.

Reported by:            emaste @
Sponsored by:           Mellanox Technologies

MFC r314771:
Give LinuxKPI Read-Write semaphores better debug names when
WITNESS_ALL is defined. The lock name is based on the filename and
line number where the initialisation happens.

Sponsored by:           Mellanox Technologies

MFC r314772:
Implement DECLARE_RWSEM() macro in the LinuxKPI to initialize a
Read-Write semaphore during module init time.

Sponsored by:           Mellanox Technologies

MFC r314774:
Implement add_timer_on() function in the LinuxKPI.

Obtained from:          kmacy @
Sponsored by:           Mellanox Technologies

MFC r314843:
LinuxKPI workqueue cleanup.

This change makes the workqueue implementation behave more like in
Linux, both functionality wise and structure wise.

All workqueue code has been moved to linux_work.c

Add an atomic based statemachine to the work_struct to ensure proper
operation. Prior to this change struct_work was directly mapped to a
FreeBSD task. When a taskqueue has multiple threads the same task may
end up being executed on more than one worker thread simultaneously.
This might cause problems with code coming from Linux, which expects
serial behaviour, similar to Linux tasklets.

Move all global workqueue function names into the linux_xxx domain to
avoid symbol name clashes in the future.

Implement a few more workqueue related functions and macros.

Create two multithreaded taskqueues for the LinuxKPI during module
load, one for time-consuming callbacks and one for non-time consuming
callbacks.

Sponsored by:           Mellanox Technologies

MFC r314853:
Use grouptaskqueue for tasklets in the LinuxKPI.

This avoids creating own per-CPU threads and also ensures the tasklet
execution happens on the same CPU core invoking the tasklet.

Sponsored by:           Mellanox Technologies

MFC r314859:
Make sure jiffies value is cast to an integer in the LinuxKPI before
doing millisecond conversion. Under FreeBSD jiffies are 32-bit.

Sponsored by:           Mellanox Technologies

MFC r314861:
Implement time_is_after_eq_jiffies() function in the LinuxKPI.

Sponsored by:           Mellanox Technologies

MFC r314904:
Implement eth_zero_addr() in the LinuxKPI.

Sponsored by:           Mellanox Technologies

MFC r314905:
Cleanup the LinuxKPI slab implementation.

Put large functions into linux_slab.c instead of declaring them static
inline.

Add support for more memory allocation wrappers like kmalloc_array()
and __vmalloc().

Make sure either the M_WAITOK or the M_NOWAIT flag is set and mask
away unused memory allocation flags before calling FreeBSD's malloc()
routine.

Move kmalloc_node() definition to slab.h where it belongs.

Implement support for the SLAB_DESTROY_BY_RCU feature when creating a
kmem_cache which basically means kmem_cache memory is freed using
call_rcu().

Sponsored by:           Mellanox Technologies

MFC r314920:
Fix compilation warning for powerpc64 by not using const keyword in
return types:

Type qualifiers ignored on function return type [-Wreturn-type]

Reported by:            andreast @
Sponsored by:           Mellanox Technologies

MFC r314953:
Don't create any threads before SI_SUB_INIT_IF in the LinuxKPI. Else
kthread_add() will assert it is called too soon. This fixes a startup
issue when COMPAT_LINUXKPI is in enabled the kernel configuration
file.

Reported by:            Michael Butler <imb@protected-networks.net>
Sponsored by:           Mellanox Technologies

MFC r314965:
Cleanup the LinuxKPI mutex wrappers.

Add support for using mutexes during KDB and shutdown. This is also
required for doing mode-switching during panic for drm-next.

Add new mutex functions mutex_init_witness() and mutex_destroy()
allowing LinuxKPI mutexes to be tracked by witness.

Declare mutex_is_locked() and mutex_is_owned() like inline functions
to get cleaner warnings. These functions are used inside WARN_ON()
statements which might look a bit odd if these functions get fully
expanded.

Give mutexes better debug names through the mutex_name() macro when
WITNESS_ALL is defined. The mutex_name() macro can prefix parts of the
filename and line number before the mutex name.

Sponsored by:           Mellanox Technologies

MFC r314970:
Implement support for mutexes with deadlock avoidance in the LinuxKPI.

When locking a mutex and deadlock is detected the first mutex lock
call that sees the deadlock will return -EDEADLK .

Sponsored by:           Mellanox Technologies

MFC r314971:
Fix implementation of the DECLARE_WORK() macro in the LinuxKPI to fully
initialize the declared work structure and not only the function callback
pointer.

Sponsored by:           Mellanox Technologies

MFC r315244:
Set "current" pointer for LinuxKPI interrupts and timer callbacks.

Sponsored by:           Mellanox Technologies

MFC r315410:
Define some more LinuxKPI task related macros.

Obtained from:          kmacy @
Sponsored by:           Mellanox Technologies

MFC r315419:
Implement more userspace memory access functions in the LinuxKPI.

Obtained from:          kmacy @
Sponsored by:           Mellanox Technologies

MFC r315420:
The LinuxKPI pagefault disable and enable functions can only be used
pairwise to support the FreeBSD way of pushing and popping the page
fault flags. Ensure this by requiring every occurrence of pagefault
disable function call to have a corresponding pagefault enable call.

Obtained from:          kmacy @
Sponsored by:           Mellanox Technologies

MFC r315422:
Use __LP64__ to detect presence of suword64() to fix linking and
loading of the LinuxKPI on 32-bit platforms.

Reported by:            lwhsu @
Sponsored by:           Mellanox Technologies

MFC r315442:
Add comment describing the use of pagefault_disable() and
pagefault_enable() in the LinuxKPI.

Suggested by:           rpokala@
Sponsored by:           Mellanox Technologies

MFC r315443:
Implement minimalistic memory mapping structure, struct mm_struct, and
some associated helper functions in the LinuxKPI. Let the existing
linux_alloc_current() function allocate and initialize the new
structure and let linux_free_current() drop the refcount on the memory
mapping structure. When the mm_struct's refcount reaches zero, the
structure is freed.

Obtained from:          kmacy @
Sponsored by:           Mellanox Technologies

MFC r315457:
Implement get_pid_task(), pid_task() and some other PID helper
functions in the LinuxKPI. Add a usage atomic to the task_struct
structure to facilitate refcounting the task structure when returned
from get_pid_task(). The get_task_struct() and put_task_struct()
function is used to manage atomic refcounting. After this change the
task_struct should only be freed through put_task_struct().

Obtained from:          kmacy @
Sponsored by:           Mellanox Technologies

MFC r315713:
Add support for more IPv4 and IPv6 related macros in the LinuxKPI.

Sponsored by:           Mellanox Technologies

MFC r315714:
Add full VNET support to the inet_get_local_port_range() function in
the LinuxKPI.

Sponsored by:           Mellanox Technologies

MFC r315719:
Extend cmpxchg() to support 8- and 16-bit values, and add xchg().

These are needed to support updated revisions of the DRM code.

Reviewed by:    hselasky (previous version)

MFC r315856:
Add support for ratelimited printouts in the LinuxKPI.

Sponsored by:           Mellanox Technologies

MFC r315859:
Function macros are preferred in the LinuxKPI.

Sponsored by:           Mellanox Technologies

MFC r315863:
Add proper error checking for the string to number conversion
functions in the LinuxKPI.

Sponsored by:           Mellanox Technologies

MFC r315864:
Use ppsratecheck() for ratelimiting in the LinuxKPI.

Suggested by:           cem @
Sponsored by:           Mellanox Technologies

MFC r316033:
Implement a series of physical page management related functions in
the LinuxKPI for accessing user-space memory in the kernel.

Add functions to hold and wire physical page(s) based on a given range
of user-space virtual addresses.

Add functions to get and put a reference on, wire, hold, mark
accessed, copy and dirty a physical page.

Add new VM related structures and defines as a preparation step for
advancing the memory map capabilities of the LinuxKPI.

Add function to figure out if a virtual address was allocated using
malloc().

Add function to convert a virtual kernel address into its physical
page pointer.

Obtained from:          kmacy @
Sponsored by:           Mellanox Technologies

MFC r316034:
Add more platforms supporting the direct map feature in the LinuxKPI.

Sponsored by:           Mellanox Technologies

MFC r316035:
Implement vmalloc_32() in the LinuxKPI.

Obtained from:          kmacy @
Sponsored by:           Mellanox Technologies

MFC r316521:
Implement down_write_killable() in the LinuxKPI.

Sponsored by:           Mellanox Technologies

MFC r316522:
Unify error handling when si_drv1 is NULL in the LinuxKPI.

Make sure the character device poll callback function does not return
an error code, but a POLLXXX value, in case of failure.

Sponsored by:           Mellanox Technologies

MFC r316561:
Before registering a new mm_struct in the LinuxKPI check if other
tasks in the belonging procedure already have a valid mm_struct and
reference that instead.

The mm_struct in the LinuxKPI should be shared among all tasks
belonging to the same procedure. This has to do with with the mmap_sem
semaphore which should serialize all VM operations inside a given
procedure. Linux based drivers depend on this behaviour.

Sponsored by:           Mellanox Technologies

MFC r316562:
Implement proper support for memory map operations in the LinuxKPI,
like open, close and fault using the character device pager.

Some notes about the implementation:

1) Linux drivers set the vm_ops and vm_private_data fields during a
mmap() call to indicate that the driver wants to use the LinuxKPI VM
operations. Else these operations are not used.

2) The vm_private_data pointer is associated with a VM area structure
and inserted into an internal LinuxKPI list. If the vm_private_data
pointer already exists, the existing VM area structure is used instead
of the allocated one which gets freed.

3) The LinuxKPI's vm_private_data pointer is used as the callback
handle for the FreeBSD VM object. The VM subsystem in FreeBSD has a
similar list to identify equal handles and will only call the
character device pager's close function once.

4) All LinuxKPI VM operations are serialized through the mmap_sem
sempaphore, which is per procedure, which prevents simultaneous access
to the shared VM area structure when receiving page faults.

Obtained from:          kmacy @
Sponsored by:           Mellanox Technologies

MFC r316563:
Fix implementation of task_pid_group_leader() in the LinuxKPI.

In FreeBSD thread IDs and procedure IDs have distinct number
spaces. When asking for the group leader task ID in the LinuxKPI,
return the procedure ID and let this resolve to the first task in the
procedure having a valid LinuxKPI task structure pointer.

Sponsored by:           Mellanox Technologies

MFC r316564:
Implement need_resched() in the LinuxKPI.

Obtained from:          kmacy @
Sponsored by:           Mellanox Technologies

MFC r316565:
Define VM_READ, VM_WRITE and VM_EXEC in the LinuxKPI.

Sponsored by:           Mellanox Technologies

MFC r316568:
Cleanup the bitmap_xxx() functions in the LinuxKPI:

- Move all bitmap related functions from bitops.h to bitmap.h, similar
  to what Linux does.

- Apply some minor code cleanup and simplifications to optimize the
  generated code when using static inline functions.

- Implement the following list of bitmap functions which are needed by
  drm-next and ibcore:
  - bitmap_find_next_zero_area_off()
  - bitmap_find_next_zero_area()
  - bitmap_or()
  - bitmap_and()
  - bitmap_xor()

- Add missing include directives to the qlnxe driver
  (davidcs@ has been notified)

Sponsored by:           Mellanox Technologies

MFC r316606:
The __stringify() macro in the LinuxKPI should expand any macros
before stringifying.

Sponsored by:           Mellanox Technologies

MFC r316609:
Create the LinuxKPI current task structure on the fly if it doesn't
exist when the current macro is used.

Sponsored by:           Mellanox Technologies

MFC r316656:
Fix compilation of LinuxKPI for PowerPC.

Found by:               emaste @
Sponsored by:           Mellanox Technologies

MFC r317135:
Zero number of CPUs should be translated into the default number of
CPUs when allocating a LinuxKPI workqueue. This also ensures that the
created taskqueue always have a non-zero number of worker threads.

Sponsored by:           Mellanox Technologies

MFC r317137:
Fix problem regarding priority inversion when using the concurrency
kit, CK, in the LinuxKPI.

When threads are pinned to a CPU core or when there is only one CPU,
it can happen that a higher priority thread can call the CK
synchronize function while a lower priority thread holds the read
lock. Because the CK's synchronize is a simple wait loop this can lead
to a deadlock situation. To solve this problem use the recently
introduced CK's wait callback function.

When detecting a CK blocking condition figure out the lowest priority
among the blockers and update the calling thread's priority and
yield. If another CPU core is holding the read lock, pin the thread to
the blocked CPU core and update the priority. The calling threads
priority and CPU bindings are restored before return.

If a thread holding a CK read lock is detected to be sleeping, pause()
will be used instead of yield().

Sponsored by:           Mellanox Technologies

MFC r317138:
Use __typeof() instead of typeof() in some RCU related macros in the LinuxKPI.

Sponsored by:           Mellanox Technologies

MFC r317504:
Prefer to use real virtual address over direct map address in the
linux_page_address() function in the LinuxKPI. This solves an issue
where the return value from linux_page_address() is passed to
kmem_free().

Sponsored by:           Mellanox Technologies

MFC r317651:
Add on_each_cpu() and wbinvd_on_all_cpus().

Reviewed by:    hselasky
Differential Revision:  https://reviews.freebsd.org/D10550

MFC r317828:
Fix for use after free in the LinuxKPI.

Background:
The same VM object might be shared by multiple processes and the
mm_struct is usually freed when a process exits.

Grab a reference on the mm_struct while the vmap is in the
linux_vma_head list in case the first process which inserted a VM
object has exited.

Tested by:              kwm @
Sponsored by:           Mellanox Technologies

MFC r317839:
Use pmap_invalidate_cache() to implement wbinvd_on_all_cpus().

Suggested by:   jhb
X-MFC with:     r317651

MFC r318026:
Fix init order in the LinuxKPI for RCU support.

CPU_FOREACH() is not available until SI_SUB_CPU at SI_ORDER_ANY
when the LinuxKPI is loaded as part of the kernel.

Sponsored by:           Mellanox Technologies

MFC r318590:
Add get_cpu() and put_cpu().

MFC r319229:
Add some miscellaneous definitions to support DRM drivers.

Reviewed by:    hselasky
Differential Revision:  https://reviews.freebsd.org/D10985

MFC r319312:
Make sure the thread's priority is restored for all three cases inside
linux_synchronize_rcu_cb() in the LinuxKPI.

Sponsored by:           Mellanox Technologies

MFC r319316:
Fixes for refcounting "struct linux_file" in the LinuxKPI.

- Allow "struct linux_file" to be refcounted when its "_file" member
  is NULL by using its "f_count" field. The reference counts are
  transferred to the file structure when the file descriptor is
  installed.

- Add missing vdrop() calls for error cases during open().

- Set the "_file" member of "struct linux_file" during open. This
allows use of refcounting through get_file() and fput() with LinuxKPI
character devices.

Sponsored by:           Mellanox Technologies

MFC r319317:
Fix a reference count leak in the LinuxKPI due to calling VM open when
it shouldn't be called.

Background:
The Linux VM open operation is called when a new VMA is
created on top of the current VMA. This is done through either mremap
flow or split_vma, usually due to mlock, madvise, munmap and so
on. This is currently not supported by the LinuxKPI.

Sponsored by:           Mellanox Technologies

MFC r319318:
Don't acquire a reference on the VM-space when allocating the LinuxKPI
task structure to avoid deadlock when tearing down the VM object
during a process exit.

Found by:               markj @
Sponsored by:           Mellanox Technologies

MFC r319319:
Remove the VMA handle from its list before calling the LinuxKPI VMA
close operation to prevent other threads from reusing the VM object
handle pointer.

Sponsored by:           Mellanox Technologies

MFC r319320:
Make sure the VMAP's "vm_file" field is referenced in a Linux
compatible way by the linux_dev_mmap_single() function in the
LinuxKPI.

Sponsored by:           Mellanox Technologies

MFC r319321:
Properly set the .d_name field in the cdevsw structure for the
LinuxKPI.

Obtained from:          kmacy @
Sponsored by:           Mellanox Technologies

MFC r319338:
Implement in_atomic() function in the LinuxKPI.

Obtained from:          kmacy @
Sponsored by:           Mellanox Technologies

MFC r319340:
Properly implement idr_preload() and idr_preload_end() in the
LinuxKPI.

Sponsored by:           Mellanox Technologies

MFC r319341:
Implement print_hex_dump(), print_hex_dump_bytes() and
printk_ratelimited() in the LinuxKPI.

While at it fix the inclusion guard of printk.h to be similar to the
rest of the LinuxKPI header files.

Sponsored by:           Mellanox Technologies

MFC r319409:
Add generic kqueue() and kevent() support to the LinuxKPI character
devices. The implementation allows read and write filters to be
created and piggybacks on the poll() file operation to determine when
a filter should trigger. The piggyback mechanism is simply to check
for the EWOULDBLOCK or EAGAIN return code from read(), write() or
ioctl() system calls and then update the kqueue() polling state bits.
The implementation is similar to the one found in the cuse(3) module.
Refer to sys/fs/cuse/*.[ch] for more details.

Sponsored by:           Mellanox Technologies

MFC r319410:
Translate the ERESTARTSYS error code into ERESTART in the LinuxKPI
ioctl(), read() and write() system call handlers. This error code is
internal to the kernel and should not be seen by user-space programs
according to Linux.

Submitted by:           Yanko Yankulov <yanko.yankulov@gmail.com>
Sponsored by:           Mellanox Technologies

MFC r319444:
Make sure the selrecord() function is only called from within system
polling contexts in the LinuxKPI.

After the kqueue() support was added to the LinuxKPI in r319409 the
Linux poll file operation will be used outside the system file polling
callback function, which can cause a NULL-pointer panic inside
selrecord() because curthread->td_sel is set to NULL. This patch moves
the selrecord() call away from poll_wait() and to the system file poll
callback function in the LinuxKPI, which essentially wraps the Linux
one. This is similar to what the cuse(3) module is currently doing.
Refer to sys/fs/cuse/*.[ch] for more details.

Sponsored by:           Mellanox Technologies

MFC r319500:
Add support for setting the non-blocking I/O flag for LinuxKPI
character devices. In Linux the FIONBIO IOCTL is handled by the kernel
and not the drivers. Also need return success for the FIOASYNC ioctl
due to existing logic in kern_fcntl() even though it is not supported
currently.

Sponsored by:           Mellanox Technologies

MFC r319501:
Improve kqueue() support in the LinuxKPI. Some applications using the
kqueue() does not set non-blocking I/O mode for event driven read of
file descriptors. This means the LinuxKPI internal kqueue read and
write event flags must be updated before the next read and/or write
system call. Else the read and/or write system call may block. This
can happen when there is no more data to read following a previous
read event. Then the application also gets blocked from processing
other events. This situation can also be solved by the applications
setting and using non-blocking I/O mode.

Sponsored by:           Mellanox Technologies

MFC r319620:
Fix init order in the LinuxKPI for IDR support after recent changes.

CPU_FOREACH() is not available until SI_SUB_CPU at SI_ORDER_ANY
when the LinuxKPI is loaded as part of the kernel.

Sponsored by:   Mellanox Technologies

MFC r319656:
Add more #ifdef arch checks to the linuxkpi

arm, mips, and powerpc all implement pmap_mapdev_attr() and pmap_unmapdev(),
so add those archs to the checks.  powerpc also includes the atomic_swap_*()
functions, so add that to the supported list as well.  Not tested except by
compiling powerpc.

Reviewed by:    markj

MFC r319675:
Remove ARM and MIPS from linuxkpi ioremap_attr definition

ARM and MIPS fail universe builds.

ARM and MIPS are missing the following:
* VM_MEMATTR_WRITE_THROUGH
* VM_MEMATTR_WRITE_COMBINING

Pointy-hat to:  jhibbits

MFC r319757:
Augment wait queue support in the LinuxKPI.

In particular:
- Don't evaluate event conditions with a sleepqueue lock held, since such
  code may attempt to acquire arbitrary locks.
- Fix the return value for wait_event_interruptible() in the case that the
  wait is interrupted by a signal.
- Implement wait_on_bit_timeout() and wait_on_atomic_t().
- Implement some functions used to test for pending signals.
- Implement a number of wait_event_*() variants and unify the existing
  implementations.
- Unify the mechanism used by wait_event_*() and schedule() to put the
  calling thread to sleep.

This is required to support updated DRM drivers. Thanks to hselasky for
finding and fixing a number of bugs in the original revision.

Reviewed by:    hselasky
Differential Revision:  https://reviews.freebsd.org/D10986

MFC r319758:
Implement pci_disable_device() in the LinuxKPI.

Submitted by:   kmacy

MFC r320063:
Remove prototypes for unimplemented LinuxKPI functions.

MFC r320072:
Avoid including list.h in LinuxKPI headers.

list.h includes a number of FreeBSD headers as a workaround for the
LIST_HEAD name collision. To reduce pollution, avoid including list.h
in commonly used headers when it is not explicitly needed.

Reviewed by:    hselasky
Differential Revision:  https://reviews.freebsd.org/D11249

MFC r320078:
Add kthread parking support to the LinuxKPI.

Submitted by:   kmacy (original version)
Reviewed by:    hselasky
Differential Revision:  https://reviews.freebsd.org/D11264

MFC r320189:
Allow the VM fault handler to be NULL in the LinuxKPI when handling a
memory map request. When the VM fault handler is NULL a return code of
VM_PAGER_BAD is returned from the character device's pager populate
handler. This fixes compatibility with Linux.

Sponsored by:   Mellanox Technologies

MFC r320192:
Add a lockdep macro to the LinuxKPI.

Also fix some nearby style issues.

MFC r320193:
Include kmod.h from the LinuxKPI's module.h.

MFC r320194:
Add missing lock destructor invocations to the LinuxKPI unload handler.

MFC r320196:
Update io-mapping.h in the LinuxKPI.

Add io_mapping_init_wc() and add a third (unused) parameter to
io_mapping_map_wc().

Reviewed by:    hselasky
Differential Revision:  https://reviews.freebsd.org/D11286

MFC r320333:
Add noop_lseek() to the LinuxKPI.

MFC r320334:
Add the thaw_early method to struct dev_pm_ops in the LinuxKPI.

MFC r320335:
Add a couple of macros to lockdep.h in the LinuxKPI.

MFC r320336:
Add ns_to_ktime() to the LinuxKPI.

MFC r320337:
Add u64_to_user_ptr() to the LinuxKPI.

MFC r320364:
Implement parts of the hrtimer API in the LinuxKPI.

Reviewed by:    hselasky
Differential Revision:  https://reviews.freebsd.org/D11359

MFC r320580:
Let io_mapping_init_wc() fall back to an uncacheable mapping.

This allows usage of the function on architectures that don't support
write-combining.

Reported by:    bz, emaste
X-MFC With:     r320196

MFC r320627:
Hold the PCI device list lock when removing an element.

MFC r320633:
Rename the "driver" field to "bsddriver" to avoid a name collision.

MFC r320634:
Add some PCI class definitions.

MFC r320635:
Add a field for the class code to struct pci_driver.

Fill out some previously uninitialized fields as well.

MFC r320636:
Add some auxiliary types for device driver support.

MFC r320656:
Invoke suspend/resume methods from the driver pmops if available.

Obtained from:  kmacy (original version)

MFC r320774:
Fix a bug in synchronize RCU when the calling thread is bound to a CPU.

Set "td_pinned" to zero after "sched_unbind()" to prevent "td_pinned"
from temporarily becoming negative during "sched_bind()". This can
happen if "sched_bind()" uses "sched_pin()" and "sched_unpin()".

Sponsored by:   Mellanox Technologies

MFC r320775:
Complete r320189 which allows a NULL VM fault handler in the LinuxKPI.
Instead of mapping a dummy page upon a page fault, map the page
pointed to by the physical address given by IDX_TO_OFF(vmap->vm_pfn).
To simplify the implementation use OBJT_DEVICE to implement our own
linux_cdev_pager_fault() instead of using the existing
linux_cdev_pager_populate().

Some minor code factoring while at it.

Reviewed by:    markj @
Sponsored by:   Mellanox Technologies

MFC r320810:
Add TASK_COMM_LEN to the LinuxKPI.

MFC r320811:
Add device_is_registered() to the LinuxKPI.

MFC r320812:
Fix the definitions of pgprot_{noncached,writecombine} after r316562.

MFC r320813:
Add some helper definitions to fs.h in the LinuxKPI.

Add a field to struct linux_file to allow the creation of anonymous
shmem objects.

MFC r320852:
Free existing per-thread task structs when unloading linuxkpi.ko.

They are otherwise leaked.

Reported and tested by: ae

MFC r320853:
Add a few functions to ktime.h in the LinuxKPI, and fix nearby style.

Reviewed by:    hselasky
Differential Revision:  https://reviews.freebsd.org/D11534

MFC r320854:
Add some functions to math64.h in the LinuxKPI, and fix nearby style.

Reviewed by:    hselasky
Differential Revision:  https://reviews.freebsd.org/D11535

MFC r320956:
Add some functions to jiffies.h.

Also add some checks for overflow to existing functions.

Reviewed by:    hselasky
Differential Revision:  https://reviews.freebsd.org/D11533

MFC r321773:
Remove cycle_t type from the LinuxKPI similar to Linux upstream.

Sponsored by:   Mellanox Technologies

MFC r321926:
Fix LinuxKPI regression after r321920. The mda_unit and si_drv0 fields are not
wide enough to hold the full 64-bit dev_t. Instead use the "dev" field in
the "linux_cdev" structure to store and lookup this value.

While at it remove superfluous use of parenthesis inside the
MAJOR(), MINOR() and MKDEV() macros in the LinuxKPI.

Sponsored by:   Mellanox Technologies

MFC r322028:
Add subsystem vendor and device ID fields to struct pci_dev.

MFC r322169:
Fix hrtimer_active() in case of cancellation.

While there, switch to FreeBSD internal callout active status.

Reviewed by:    markj, hselasky
Sponsored by:   iXsystems, Inc.
Differential Revision:  https://reviews.freebsd.org/D11900

MFC r322212:
Add macros for defining attribute groups and for WO and RW attributes.

Reviewed by:    hselasky
Differential Revision:  https://reviews.freebsd.org/D11872

MFC r322213:
Add round_jiffies_up(), local_clock() and __setup_timer() to the LinuxKPI.

Reviewed by:    hselasky
Differential Revision:  https://reviews.freebsd.org/D11871

MFC r322272:
Fix few issues of LinuxKPI workqueue.

LinuxKPI workqueue wrappers reported "successful" cancellation for works
already completed in normal way.  This change brings reported status and
real cancellation fact into sync.  This required for drm-next operation.

Reviewed by:    hselasky (earlier version)
Sponsored by:   iXsystems, Inc.
Differential Revision:  https://reviews.freebsd.org/D11904

MFC r322354:
Make sure the linux_wait_event_common() function in the LinuxKPI properly
handles a timeout value of MAX_SCHEDULE_TIMEOUT which basically means there
is no timeout. This is a regression issue after r319757.

While at it change the type of returned variable from "long" to "int" to
match the actual return type.

Sponsored by:   Mellanox Technologies

MFC r322355:
Fixes for wait event in the LinuxKPI. These are regression issues
after r319757.

1) Correct the return value from __wait_event_common() from 1 to 0 in
case the timeout is specified as MAX_SCHEDULE_TIMEOUT. In the other
case __ret is zero and will be substituted in the last part of the
macro with the appropriate value before return.

2) Make sure the "timeout" argument is casted to "int" before
evaluating negativity. Else the signedness of a "long" might be
checked instead of the signedness of an integer.

3) The wait_event() function should not have a return value.

Found by:       KrishnamRaju ErapaRaju <Krishna2@chelsio.com>
Sponsored by:   Mellanox Technologies

MFC r322357:
Use integer type to pass around jiffies and/or ticks values in the
LinuxKPI because in FreeBSD ticks are 32-bit.

Sponsored by:   Mellanox Technologies

MFC r322392:
Add a specialized function for DRM drivers to register themselves.

Such drivers attach to a vgapci bus rather than directly to a pci bus. For
the rest of the LinuxKPI to work correctly in this case, we override the
vgapci bus' ivars with those of the grandparent.

Reviewed by:    hselasky
Differential Revision:  https://reviews.freebsd.org/D11932

MFC r322397:
Make sure the "vm_flags" and "vm_page_prot" fields get set correctly
in the VM area structure in the LinuxKPI when doing mmap() and that
unsupported bits are masked away.

While at it fix some redundant use of parenthesing inside some related
macros.

Found by:       KrishnamRaju ErapaRaju <Krishna2@chelsio.com>
Sponsored by:   Mellanox Technologies

MFC r322567:
Add device resource management fields to struct device.

MFC r322713:
Add a couple of trivial headers to the LinuxKPI.

MFC r322714:
Define prefetch() only if it hasn't already been defined.

MFC r322746:
Fix for deadlock situation in the LinuxKPI's RCU synchronize API.

Deadlock condition:
The return value of TDQ_LOCKPTR(td) is the same for two threads.

1) The first thread signals a wakeup while keeping the rcu_read_lock().
This invokes sched_add() which in turn will try to lock TDQ_LOCK().

2) The second thread is calling synchronize_rcu() calling mi_switch() over
and over again trying to yield(). This prevents the first thread from running
and releasing the RCU reader lock.

Solution:
Release the thread lock while yielding to allow other threads to acquire the
lock pointed to by TDQ_LOCKPTR(td).

Found by:       KrishnamRaju ErapaRaju <Krishna2@chelsio.com>
Sponsored by:   Mellanox Technologies

MFC r322795:
Add some miscellaneous definitions to support the DRM drivers.

MFC r322816:
Set the bus number field when attaching a PCI device.

MFC r323347:
Add more sanity checks to linux_fget() in the LinuxKPI. This prevents
returning pointers to file descriptors which were not created by the
LinuxKPI.

Sponsored by:           Mellanox Technologies

MFC r323349:
Properly implement poll_wait() in the LinuxKPI. This prevents direct
use of the linux_poll_wakeup() function from unsafe contexts, which
can lead to use-after-free issues.

Instead of calling linux_poll_wakeup() directly use the wake_up()
family of functions in the LinuxKPI to do this.

Bump the FreeBSD version to force recompilation of external kernel modules.

Sponsored by:           Mellanox Technologies

MFC r323703:
Add support for shared memory functions to the LinuxKPI.

Obtained from:          kmacy @
Sponsored by:           Mellanox Technologies

MFC r323704:
Only wire pages in the LinuxKPI instead of holding and wiring them.
This prevents the page daemon from regularly scanning the held pages.

Suggested by:           kib @
Sponsored by:           Mellanox Technologies

MFC r323705:
The LinuxKPI atomics do not have acquire nor release semantics unless
specified. Fix code to use READ_ONCE() and WRITE_ONCE() where appropriate.

Suggested by:           kib @
Sponsored by:           Mellanox Technologies

MFC r323910:
Add support for 32-bit compatibility IOCTLs in the LinuxKPI.

Bump the FreeBSD version to force recompilation of external
kernel modules due to structure change.

PR:             222504
Submitted by:   Greg V <greg@unrelenting.technology>
Sponsored by:   Mellanox Technologies

MFC r324278:
Make sure the timer belonging to the delayed work in the LinuxKPI
gets drained before invoking the work function. Else the timer
mutex may still be in use which can lead to use-after-free situations,
because the work function might free the work structure before returning.

Sponsored by:   Mellanox Technologies

MFC r324285:
Add get_random_{int,long} to the LinuxKPI.

Fix some whitespace bugs while here.

Reviewed by:    hselasky
Differential Revision:  https://reviews.freebsd.org/D12588

MFC r324597:
Don't call selrecord() outside the select system call in the LinuxKPI, because
then td->td_sel is NULL and this will result in a segfault inside selrecord().
This happens when only using kqueue() to poll for read and write events.
If select() and kqueue() is mixed there won't be a segfault.

Reported by:    Johannes Lundberg
Sponsored by:   Mellanox Technologies

MFC r324606:
Make the PHOLD in linux_wait_event_common() unconditional.

After some in-progress work is committed, this would otherwise be the only
instance of #if(n)def NO_SWAPPING in the tree. Moreover, the requisite
opt_vm.h include was missing, so the PHOLD/PRELE calls were always being
compiled in anyway.

MFC r325279:
Implement ioread16be() in the LinuxKPI.

Sponsored by:   Mellanox Technologies

MFC r325360:
Remove redundant dev->si_drv1 NULL checks in the LinuxKPI.
This pointer is checked during the linux_dev_open() callback and does
not need to be NULL checked again. It should always be set for
character devices belonging to the "linuxcdevsw" and technically
there is no need to NULL check this pointer at all.

Suggested by:   kib @
Sponsored by:   Mellanox Technologies

MFC r325635:
Remove some not needed comments in the LinuxKPI. Use the Linux source tree
to lookup documentation for the functions implemented in the LinuxKPI
instead.

Sponsored by:   Mellanox Technologies

MFC r325707:
Mask away return codes from del_timer() and del_timer_sync() because
they are not the same like in Linux.

Sponsored by:   Mellanox Technologies

MFC r325708:
Remove release and acquire semantics when accessing the "state" field of the
LinuxKPI task struct. Change type of "state" variable from "int" to
"atomic_t" to simplify code and avoid unneccessary casting.

Sponsored by:   Mellanox Technologies

MFC r325767:
Properly handle the case where the linux_cdev_handle_insert() function
in the LinuxKPI returns NULL. This happens when the VM area's private
data handle already exists and could cause a so-called NULL pointer
dereferencing issue prior to this fix.

Found by:       greg@unrelenting.technology
Sponsored by:   Mellanox Technologies

MFC r327676:
linuxkpi: Implement kcalloc() based on mallocarray()

This means we now get integer overflow protection, which Linux code
might expect as it is also provided by kcalloc() in Linux.

MFC r327788:
linuxkpi: Simplify kmalloc_array.

kmalloc_array seems what we call mallocarray(9).

MFC r312926: (partial, no mergeinfo)
Revert r312923 a better approach will be taken later

MFC r312927: (partial, no mergeinfo)
Revert crap accidentally committed

MFC r316665: (partial, no mergeinfo)
Import CK as of commit 6b141c0bdd21ce8b3e14147af8f87f22b20ecf32
This brings us changes we needed in ck_epoch.

MFC r317053: (partial, no mergeinfo)
Remove unneeded include of vm_phys.h.

MFC r317055: (partial, no mergeinfo)
All these files need sys/vmmeter.h, but now they got it implicitly
included via sys/pcpu.h.

MFC r322168: (partial, no mergeinfo)
o Replace __riscv__ with __riscv
o Replace __riscv64 with (__riscv && __riscv_xlen == 64)

This is required to support new GCC 7.1 compiler.
This is compatible with current GCC 6.1 compiler.

RISC-V is extensible ISA and the idea here is to have built-in define
per each extension, so together with __riscv we will have some subset
of these as well (depending on -march string passed to compiler):

__riscv_compressed
__riscv_atomic
__riscv_mul
__riscv_div
__riscv_muldiv
__riscv_fdiv
__riscv_fsqrt
__riscv_float_abi_soft
__riscv_float_abi_single
__riscv_float_abi_double
__riscv_cmodel_medlow
__riscv_cmodel_medany
__riscv_cmodel_pic
__riscv_xlen

Reviewed by:    ngie
Sponsored by:   DARPA, AFRL
Differential Revision:  https://reviews.freebsd.org/D11901

MFC r322672: (partial, no mergeinfo)
Move some other SI_SUB_INIT_IF initializations to SI_SUB_TASKQ

Drop the EARLY_AP_STARTUP gtaskqueue code, as gtaskqueues are now
initialized before APs are started.

Reviewed by:    hselasky@, jhb@
Sponsored by:   Dell EMC Isilon
Differential Revision:  https://reviews.freebsd.org/D12054

MFC r326984: (partial, no mergeinfo)
Update Matthew Macy contact info

Email address has changed, uses consistent name (Matthew, not Matt)

Reported by:    Matthew Macy <mmacy@mattmacy.io>
Differential Revision:  https://reviews.freebsd.org/D13537

6 years agoMFC r328497:
pfg [Thu, 1 Feb 2018 01:59:37 +0000 (01:59 +0000)]
MFC r328497:
pfctl(8): Fix two wrong conditions.

Caught by gcc80's -Wtautological-compare option.

MFC after: 5 days
Reviewed by: kp
Obtained from: DragonFlyBSD (git e3cdbf6c)

6 years agoMFC r328350:
ae [Wed, 31 Jan 2018 09:24:48 +0000 (09:24 +0000)]
MFC r328350:
  Merge revision 1.35 from NetBSD:
    fix pointer/offset mistakes in handling of IPv4 options

  Reported by: Maxime Villard <maxv at NetBSD.org>

MFC r328352:
  Adopt revision 1.76 and 1.77 from NetBSD:
    Fix a vulnerability in IPsec-IPv6-AH, that allows an attacker to remotely
    crash the kernel with a single packet.

    In this loop we need to increment 'ad' by two, because the length field
    of the option header does not count the size of the option header itself.

    If the length is zero, then 'count' is incremented by zero, and there's
    an infinite loop. Beyond that, this code was written with the assumption
    that since the IPv6 packet already went through the generic IPv6 option
    parser, several fields are guaranteed to be valid; but this assumption
    does not hold because of the missing '+2', and there's as a result a
    triggerable buffer overflow (write zeros after the end of the mbuf,
    potentially to the next mbuf in memory since it's a pool).

    Add the missing '+2', this place will be reinforced in separate commits.

  Reported by: Maxime Villard <maxv at NetBSD.org>

6 years agoMFC r328013:
dab [Tue, 30 Jan 2018 20:49:49 +0000 (20:49 +0000)]
MFC r328013:

Exit fsck_ffs with non-zero status when file system is not repaired.

When the fsck_ffs program cannot fully repair a file system, it will
output the message PLEASE RERUN FSCK. However, it does not exit with a
non-zero status in this case (contradicting the man page claim that it
"exits with 0 on success, and >0 if an error occurs."  The fsck
rc-script (when running "fsck -y") tests the status from fsck (which
passes along the exit status from fsck_ffs) and issues a "stop_boot"
if the status fails. However, this is not effective since fsck_ffs can
return zero even on (some) errors. Effectively, it is left to a later
step in the boot process when the file systems are mounted to detect
the still-unclean file system and stop the boot.

This change modifies fsck_ffs so that when it cannot fully repair the
file system and issues the PLEASE RERUN FSCK message it also exits
with a non-zero status.

While here, the fsck_ffs man page has also been updated to document
the failing exit status codes used by fsck_ffs. Previously, only exit
status 7 was documented. Some of these exit statuses are tested for in
the fsck rc-script, so they are clearly depended upon and deserve
documentation.

PR: 211485
Sponsored by: Dell EMC

6 years agoMFC r328293: stand/fdt: Fallback to `name` + .dtbo if we fail to load `name`
kevans [Tue, 30 Jan 2018 19:31:37 +0000 (19:31 +0000)]
MFC r328293: stand/fdt: Fallback to `name` + .dtbo if we fail to load `name`

[This is a direct commit to stable/11 due to path restructuring in -HEAD;
diffs have been applied to their old locations]

This behavior also matches a Linux-ism by allowing fdt_overlays to specify
names of overlays without an extension, e.g. fdt-overlays="sunxi-h3-h5-emac"

If we fail to load the file given by a name in fdt_overlays, try again with
".dtbo" appended to it. This still allows overlays to lack .dtbo extension
if user prefers it and just adds a fallback cushion.

Future work could move this from a hard-coded ".dtbo" to a loader.conf(5)
configuration option.

6 years agoMFC r328287: Add /boot/overlays to runtime pkg, fix distrib-dirs METALOG
kevans [Tue, 30 Jan 2018 19:20:59 +0000 (19:20 +0000)]
MFC r328287: Add /boot/overlays to runtime pkg, fix distrib-dirs METALOG

/boot/overlays was recently added without belonging to a package. It's only
used by bootloaders at the moment, so add it to the 'runtime' package to get
added with ubldr and friends.

Fix distrib-dirs METALOG generation while we're here. History elsewhere
seems to indicate that bapt@ fixed this to pull in all attributes from
mtrees while generating the METALOG. This fix got clobbered somewhere later,
so restore it.

6 years agoMFC r328032,r328060,r328243: service(8): Support services in jails
kevans [Tue, 30 Jan 2018 19:16:38 +0000 (19:16 +0000)]
MFC r328032,r328060,r328243: service(8): Support services in jails

MFC r328032: service(8): Add support for interfacing with services in jails

Provide a -j option that can take a jail name or id. If -j is specified,
check that the jail exists and proxy the service request through to
service(8) in the jail.

This allows for cleaner workflows when updating services in a jail, turning
the following:

pkg -j dns upgrade
jexec dns service named restart

into:

pkg -j dns upgrade
service -j dns named restart

MFC r328060: service(8): Reset OPTIND properly now that we parse args twice

r328032 introduced a second round of argument parsing to proxy the request
through to a jail as needed, but failed to reset OPTIND before getting to
the second round of parsing to allow other flags to be set.

MFC r328243: usr.sbin/service: Fix -j to not be order dependant

The introduced -j option is highly dependant on the ordering of arguments,
and it exhibited broken behavior in some other circumstances. Fix these
issues, and simplify the feature by removing the unneessary double parsing
of options.

PR: 223325

6 years agoMFC r327451:
eadler [Tue, 30 Jan 2018 04:50:23 +0000 (04:50 +0000)]
MFC r327451:

newsyslog: implement 'p' flag

  Implement the 'p' flag for newsyslog from NetBSD. This flag results in
  the first log file for a given file to not be compressed.

  While here, don't change file attributes during a no-op run

PR: 162798

6 years agoMFC r328305: libcxxrt: Move mangled symbols out of extern "C++" in Version.map
emaste [Tue, 30 Jan 2018 01:13:06 +0000 (01:13 +0000)]
MFC r328305: libcxxrt: Move mangled symbols out of extern "C++" in Version.map

r260553 added a number of mangled C++ symbols to Version.map inside of
an existing `extern "C++"` block.

ld.bfd 2.17.50 treats `extern "C++"` permissively and will match both
mangled and demangled symbols against the strings in the version map
block.  ld.lld interprets `extern "C++"` strictly, and matches only
demangled symbols.

I believe lld's behaviour is correct.  Contemporary versions of ld.bfd
also behave as lld does, so move the mangled symbols out of the
`extern "C++"` block.

PR: 225128, 185663
Sponsored by: The FreeBSD Foundation

6 years agoMFC 327792: Don't store shadow copies of per-process AIO limits.
jhb [Tue, 30 Jan 2018 00:52:22 +0000 (00:52 +0000)]
MFC 327792: Don't store shadow copies of per-process AIO limits.

Previously the AIO subsystem would save a snapshot of the currently
configured per-process limits the first time a process used AIO.  The
process would continue to use the snapshotted limits ignoring any
changes to the global limits during the rest of its lifetime.  This
change removes the snapshotted values and changes the AIO code to
always check the global values which can be toggled at runtime.
This means an administrator can now change the effective limits of
existing processes.  This is more consistent with how other limits
configured via sysctl work in FreeBSD.

Sponsored by: Chelsio Communications

6 years agoMFC 327755: Allow the fast-path for disk AIO requests to fail requests.
jhb [Tue, 30 Jan 2018 00:41:54 +0000 (00:41 +0000)]
MFC 327755: Allow the fast-path for disk AIO requests to fail requests.

- If aio_qphysio() returns a non-zero error code, fail the request rather
  than queueing it to the AIO kproc pool to be retried via the slow path.
  Currently this means that if vm_fault_quick_hold_pages() reports an
  error, EFAULT is returned from the fast-path rather than retrying the
  request in the slow path where it will still fail with EFAULT.
- If aio_qphysio() wishes to use the fast path for a device that doesn't
  support unmapped I/O but there are already the maximum number of
  such requests in flight, fail with EAGAIN as we do for other AIO
  resource limits rather than queueing the request to the AIO kproc pool.
- Move the opcode check for aio_qphysio() out of the caller and into
  aio_qphysio() to simplify some logic and remove two goto's while here.
  It also uses a whitelist (only supported for LIO_READ / LIO_WRITE)
  rather than a blacklist (skipped for LIO_SYNC).

PR: 217261
Sponsored by: Chelsio Communications

6 years agoMFC 327753: Simplify some logic by merging an if test with a subsequent switch.
jhb [Tue, 30 Jan 2018 00:38:24 +0000 (00:38 +0000)]
MFC 327753: Simplify some logic by merging an if test with a subsequent switch.

Specifically, in aio_queue_file() the code was doing this:

   if (opcode == LIO_SYNC) {
       ...
   }

   switch (opcode) {
   ...
   case LIO_SYNC:
       ...
   }

This moves the body of the if statement into the LIO_SYNC case of the
switch statement.

Sponsored by: Chelsio Communications

6 years agoMFC 328035: Sort the list of flags in newsyslog.conf entries.
jhb [Tue, 30 Jan 2018 00:24:03 +0000 (00:24 +0000)]
MFC 328035: Sort the list of flags in newsyslog.conf entries.

Move the 'X' entry into its sorted location in the list
of flags just above 'Z'.

6 years agoMFC 327752: Add a counter to track in-flight AIO requests using unmapped I/O.
jhb [Tue, 30 Jan 2018 00:10:00 +0000 (00:10 +0000)]
MFC 327752: Add a counter to track in-flight AIO requests using unmapped I/O.

Sponsored by: Chelsio Communications

6 years agoMFC 327561:
jhb [Mon, 29 Jan 2018 23:43:04 +0000 (23:43 +0000)]
MFC 327561:
Report offset relative to the backing object for kinfo_vmentry structures.

For the pathname reported in kinfo_vmentry structures (kve_path), the
sysctl handlers walk the object chain to find the bottom-most VM object.
This permits a COW mapping of a file with dirty pages to report the
pathname of the originally mapped file.  Do the same for the object
offset (kve_offset) computing a cumulative offset during the same object
walk so that the reported offset is relative to the reported pathname.

Note that ptrace(PT_VM_ENTRY) already returns a cumulative offset
rather than the raw offset of the VM map entry.

Note also that this does not affect procstat -v output (even structured
output) since that output does not include the kve_offset field.

Sponsored by: DARPA / AFRL

6 years agoMFC: r328419
jkim [Mon, 29 Jan 2018 18:12:59 +0000 (18:12 +0000)]
MFC: r328419

Add declaration of SSL_get_selected_srtp_profile() for OpenSSL.

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

6 years agoMFC r328264:
kib [Mon, 29 Jan 2018 10:19:15 +0000 (10:19 +0000)]
MFC r328264:
Fix compat32 for sysctl net.PF_ROUTE...NET_RT_IFLISTL.

6 years agoMFC revisions r309268, r309260, r309264, r309266, r309267, r309270, r310846,
cognet [Sun, 28 Jan 2018 18:38:17 +0000 (18:38 +0000)]
MFC revisions r309268, r309260, r309264, r309266, r309267, r309270, r310846,
r314435, r314564, r316665, r316691, r316702.
Those import ConcurrencyKit in the FreeBSD kernel.
A few people have showed interest in this being MFC'd, so here we go.

6 years agoMFC r328222:
eadler [Sun, 28 Jan 2018 00:27:51 +0000 (00:27 +0000)]
MFC r328222:

iconv: adding missing break

break is probably intended and correct,
but has no correctness implications due to is94 => is96

6 years agoMFC r328212:
eadler [Sun, 28 Jan 2018 00:26:05 +0000 (00:26 +0000)]
MFC r328212:

limits(1): fix always true condition

6 years agoMFC r328206:
eadler [Sat, 27 Jan 2018 23:40:41 +0000 (23:40 +0000)]
MFC r328206:

limits(1): add missing break

6 years agoMFC r328188,r328189,r328200: Fix wrong output for multibyte corner cases
kevans [Sat, 27 Jan 2018 23:20:01 +0000 (23:20 +0000)]
MFC r328188,r328189,r328200: Fix wrong output for multibyte corner cases

MFC r328188: od(1): Fix wrong output for corner cases in multibyte locales.

Restore the original character to print if we used the look-ahead
buffer, but that didn't help -- we either got an illegal sequence
or still can't complete.

MFC r328189: od(1): Fix mis-patch from r328188

od_test.sh got duplicated erroneously when it was added in r328188. Dedup.

MFC r328200: Silence the gcc warning: 'op' may be used uninitialized in this
function

PR: 224552

6 years agoMFC (conceptually) r328107: Add /boot/overlays
kevans [Sat, 27 Jan 2018 23:13:34 +0000 (23:13 +0000)]
MFC (conceptually) r328107: Add /boot/overlays

This is a direct commit to stable/11, due to path changes in HEAD. Diffs
have been applied on top of stable/11, with exception to the change to
forth/loader.conf. forth/loader.conf has seen additional changes in HEAD
mthat are not being MFC'd to stable/11, so the addition of /boot/overlays to
its module_path is not necessary.

MFC r328107: stand: Add /boot/overlays for separation of overlays from DTB

This matches directory structure used commonly in Linux-land, and it's
cleaner than mixing overlays into the existing module paths. Overlays are
still mixed in by specifying fdt_overlays in loader.conf(5).

6 years agoMFC r320296, r328173: Update dtc(1)
kevans [Sat, 27 Jan 2018 22:50:26 +0000 (22:50 +0000)]
MFC r320296, r328173: Update dtc(1)

MFC r320296 (manu): dtc: Update to upstream 9ce35ff8

 - Add "compatible with gpl dtc X.Y.Z" to version output so U-Boot doesn't complain
 - Fix cross reference node

This fixes some Allwinner DTS (and probably others).

MFC r328173: dtc(1): Update to upstream ea3c233

Highlights of this update:
- /__local_fixups__ is now generated to be GPL dtc and libfdt compliant
- Compiling with -@ will now cause dtc to assign phandles to all labelled
  nodes
- /include/ and /incbin/ now handle absolute paths correctly
- The manpage now has information about overlays, including how to apply
  them and how to generate them
- Syntactic sugar for overlays is now supported, allowing an overlay DTS
  like:

=
/dts-v1/;
/plugin/;

&foo {
    foo,status = "okay";
};
=

to generate a fragment targetting <&foo>.

6 years agopsm: Log syncmask[1], not syncmask[0] twice
dumbbell [Sat, 27 Jan 2018 17:24:27 +0000 (17:24 +0000)]
psm: Log syncmask[1], not syncmask[0] twice

MFC of: r328208

6 years agoMFC r328209:
eadler [Sat, 27 Jan 2018 16:56:54 +0000 (16:56 +0000)]
MFC r328209:

termcap: add xterm-termite

6 years agopsm: Don't try to detect trackpoint packets if the Elantech device has none
dumbbell [Sat, 27 Jan 2018 16:48:29 +0000 (16:48 +0000)]
psm: Don't try to detect trackpoint packets if the Elantech device has none

This fixes a panic when `EVDEV_SUPPORT` is enabled: if a trackpoint
packet was detected but there was no trackpoint, we still tried to emit an
evdev event even though the associated relative evdev device (`evdev_r`)
was not initialized.

PR: 225339
MFC of: r328191

6 years agopsm: Skip sync check when `PSM_CONFIG_NOCHECKSYNC` is set
dumbbell [Sat, 27 Jan 2018 16:36:06 +0000 (16:36 +0000)]
psm: Skip sync check when `PSM_CONFIG_NOCHECKSYNC` is set

In psmprobe(), we set the initial `syncmask` to the vendor default value
if the `PSM_CONFIG_NOCHECKSYNC` bit is unset. However, we currently only
set it for the Elantech touchpad later in psmattach(), thus `syncmask`
is always configured.

Now, we check `PSM_CONFIG_NOCHECKSYNC` and skip sync check if it is set.
This fixes Elantech touchpad support for units which have `hascrc` set.

To clarify that, when we log the `syncmask` and `syncbits` fields, also
mention if they are actually used.

Finally, when we set `PSM_CONFIG_NOCHECKSYNC`, clear `PSM_NEED_SYNCBITS`
flag.

PR: 225338
MFC of: r328190

6 years agoMFC r328055: Import tzdata 2018a
philip [Sat, 27 Jan 2018 13:29:55 +0000 (13:29 +0000)]
MFC r328055: Import tzdata 2018a
MFC r328318: Import tzdata 2018c

6 years agoMFC r328192:
kib [Sat, 27 Jan 2018 11:40:46 +0000 (11:40 +0000)]
MFC r328192:
Assign map->header values to avoid boundary checks.

6 years agoMFC r320930,r324286: Add tests for hexdump(1)
kevans [Sat, 27 Jan 2018 06:31:14 +0000 (06:31 +0000)]
MFC r320930,r324286: Add tests for hexdump(1)

MFC r320930:
Add some basic tests for hexdump(1)'s various output flags. Formatting
tests are omitted for this initial run as there are still some bugs to work
out there.

This covers -s flag testing on devices and non-devices that would have
caught breakage found in PR 219173 as well as other subtle breakage caused
locally.

MFC r324286: hexdump: Remove expected test failures for now succeeding tests

r323990 fixed the -s flag breakage reported by PR 219173. Mark the
corresponding hexdump tests accordingly, since they should now both succeed.

PR: 222781

6 years agoMFC r327826: patch(1): Don't check for NUL bytes in Plan A
kevans [Sat, 27 Jan 2018 06:20:27 +0000 (06:20 +0000)]
MFC r327826: patch(1): Don't check for NUL bytes in Plan A

Plan A mmap()'s the entire input file and operates on it in memory. The
map(2) call succeeded, so we shouldn't need to bother checking for the NUL
byte as long as we're within our buffer space.

This was clearly intentional to match "the behavior of the original code",
but it creates a discrepancy between Plan A and Plan B that doesn't seem
sensible and it's not inherently wrong to allow a NUL byte.

This change was motivated by the gemspec in net/rubygem-grpc failing to
patch, despite the patch being generated with diff, because a NUL byte was
used as a delimiter in the header briefly in an otherwise text file.

An alternative was considered: to fallback to plan B if plan A won't process
the entire file due to a NUL byte, but I deemed this to be the better option
since plan A isn't failing due to memory limitations and will fail later on
if it's really dealing with a file it shouldn't be.

6 years agoMFC r326483: grep test: Fix copyright notice
kevans [Sat, 27 Jan 2018 06:15:24 +0000 (06:15 +0000)]
MFC r326483: grep test: Fix copyright notice

The copyright notice was erroneously introduced as one from the NetBSD
foundation due to it being copied from a file in the NetBSD test suite, but
this file itself is not derived from or supplied with the NetBSD test suite.

6 years agoMFC r314467,r328027: Add hw.usb.wsp.enable_single_tap_clicks sysctl
kevans [Sat, 27 Jan 2018 06:10:20 +0000 (06:10 +0000)]
MFC r314467,r328027: Add hw.usb.wsp.enable_single_tap_clicks sysctl

MFC r314467 (imp): Make wsp process a single touchpad tap and interpret it
as a left-click event.  It can be disabled by setting the new
hw.usb.wsp.enable_single_tap_clicks sysctl to 0.

MFC r328027: wsp(4): Update to reflect new sysctl from r314467

r314467 introduced hw.usb.wsp.enable_single_tap_clicks to enable/disable
single-tap left click behavior. Update the man page to reflect the new
sysctl.

PR: 196624

6 years agoMFC (conceptually) r328106: libfdt: Update to 1.4.6, use libfdt for overlays
kevans [Sat, 27 Jan 2018 05:56:16 +0000 (05:56 +0000)]
MFC (conceptually) r328106: libfdt: Update to 1.4.6, use libfdt for overlays

This is a direct commit to stable/11 due to path changes in HEAD. Diffs have
been applied on top of their previous locations, with one minor adjustment
as per the "MFC" note below: a <stdlib.h> include in libfdt_env.h h as been
wrapped in an `#ifndef _STANDALONE` block to prevent build failures when
built in the bootloader context. These issues are not present in HEAD, thus
this differs from HEAD.

libfdt highlights since 1.4.3:

- fdt_property_placeholder added to create a property without specifying its
value at creation time
- stringlist helper functions added to libfdt
- Improved overlay support
- Various internal cleanup

Also switch stand/fdt over to using libfdt for overlay support with this
update. Our current overlay implementation works only for limited use cases
with overlays generated only by some specific versions of our dtc(1). Swap
it out for the libfdt implementation, which supports any properly generated
overlay being applied to a properly generated base.

This will be followed up fairly soon with an update to dtc(1) in tree to
properly generate overlays.

MFC note: the <stdlib.h> include this update introduces in libfdt_env.h is
apparently not necessary in the context we use this in. It's not immediately
clear to me the motivation for it being introduced, but it came in with
overlay support. I've left it in for the sake of accuracy and because it's
not harmful here on HEAD, but MFC'ing this to stable/11 will require
wrapping the #include in an `#ifndef _STANDALONE` block or else it will
cause build failures.

6 years agoMFC r327925: Add IDs for Nuvoton NCT6793/NCT6795.
mav [Sat, 27 Jan 2018 05:08:44 +0000 (05:08 +0000)]
MFC r327925: Add IDs for Nuvoton NCT6793/NCT6795.

6 years agoMFC 326184: Decode kevent structures logged via ktrace(2) in kdump.
jhb [Fri, 26 Jan 2018 23:49:31 +0000 (23:49 +0000)]
MFC 326184: Decode kevent structures logged via ktrace(2) in kdump.

- Add a new KTR_STRUCT_ARRAY ktrace record type which dumps an array of
  structures.

  The structure name in the record payload is preceded by a size_t
  containing the size of the individual structures.  Use this to
  replace the previous code that dumped the kevent arrays dumped for
  kevent().  kdump is now able to decode the kevent structures rather
  than dumping their contents via a hexdump.

  One change from before is that the 'changes' and 'events' arrays are
  not marked with separate 'read' and 'write' annotations in kdump
  output.  Instead, the first array is the 'changes' array, and the
  second array (only present if kevent doesn't fail with an error) is
  the 'events' array.  For kevent(), empty arrays are denoted by an
  entry with an array containing zero entries rather than no record.

- Move kevent decoding tables from truss to libsysdecode.

  This adds three new functions to decode members of struct kevent:
  sysdecode_kevent_filter, sysdecode_kevent_flags, and
  sysdecode_kevent_fflags.

  kdump uses these helper functions to pretty-print kevent fields.

- Move structure definitions for freebsd11 and freebsd32 kevent
  structures to <sys/event.h> so that they can be shared with userland.
  The 32-bit structures are only exposed if _WANT_KEVENT32 is defined.
  The freebsd11 structures are only exposed if _WANT_FREEBSD11_KEVENT is
  defined.  The 32-bit freebsd11 structure requires both.

- Decode freebsd11 kevent structures in truss for the compat11.kevent()
  system call.

- Log 32-bit kevent structures via ktrace for 32-bit compat kevent()
  system calls.

- While here, constify the 'void *data' argument to ktrstruct().

Note that this version of the change for 11.x does not include freebsd11
kevent structures or _WANT_FREEBSD11_KEVENT.  It also does not include
the change to decode the compat11.kevent system call in truss.

6 years agoMFC (conceptually) r327991, r328009: Don't clobber FDT enroute to the kernel
kevans [Fri, 26 Jan 2018 22:23:24 +0000 (22:23 +0000)]
MFC (conceptually) r327991, r328009: Don't clobber FDT enroute to the kernel

This is a direct commit to stable/11 due to path changes that have occured
in HEAD. The diffs remain the same, but rebased against their old locations.

MFC r327991: stand/fdt: don't send clobbered FDT to the kernel

If fdt_overlay_apply fails at some stage to apply the overlay to the base,
both the base and overlay may be in an inconsistent state (some fixups
applied, some phandles adjusted, some symbols merged). These can be bad for
a number of reasons, to include user frustration if some fixups applied and
not others. Fail a little safer by making a clean copy of the base FDT for
every overlay that we can simply discard if things go awry.

This also allows us the luxury of simply discarding overlays if we hit some
kind of memory limit or if they're malformed and extremely large for some
reason. We'll now leave a nice error message indicating that some overlays
could not be applied due to size restrictions and we apply what we can.

I note that our overlay implementation has some flaws that might still leave
your system in an unbootable state even if an overlay applies correctly;
please exercise caution in using overlays until we can swap it out for
libfdt's implementation.

MFC r328009: stand/fdt: Don't leak next_fdtp if we fail to open overlay

6 years agoMFC r328283, r328284:
gjb [Fri, 26 Jan 2018 04:32:31 +0000 (04:32 +0000)]
MFC r328283, r328284:

 r328283:
  When CHROOTBUILD_SKIP is set, evaluate the existence of /bin/sh
  within the CHROOTDIR.  If it does not exist, unset CHROOTBUILD_SKIP
  to prevent build failures.

 r328284:
  Bump Copyright year.

Sponsored by: The FreeBSD Foundation

6 years agoMFC r328297:
brooks [Fri, 26 Jan 2018 00:34:33 +0000 (00:34 +0000)]
MFC r328297:

Don't escape '?'s in protocol output.

This isn't required by mandoc and is nonfunctional in groff.

PR: 224632
Reported by: w.schwarzenfeld@utanet.at
Differential Revision: https://reviews.freebsd.org/D13779

6 years agoMFC r327820:
kib [Thu, 25 Jan 2018 15:28:43 +0000 (15:28 +0000)]
MFC r327820:
Remove redundand CLD instructions.

6 years agoMFC of r305169:
pkelsey [Thu, 25 Jan 2018 07:27:03 +0000 (07:27 +0000)]
MFC of r305169:

_taskqueue_start_threads() now fails if it doesn't actually start any threads.

Reviewed by: jhb
Differential Revision: https://reviews.freebsd.org/D7701

6 years agoMFC of r316630, r316631, r316632, r316633, r316634
pkelsey [Thu, 25 Jan 2018 07:19:07 +0000 (07:19 +0000)]
MFC of r316630, r316631, r316632, r316633, r316634

Fixed various typos.

6 years agoMFC r316648:
pkelsey [Thu, 25 Jan 2018 02:45:21 +0000 (02:45 +0000)]
MFC r316648:

Corrected misspelled versions of rendezvous.

The MFC maintains smp_no_rendevous_barrier() as a symbol alias of
smp_no_rendezvous_barrier().

__FreeBSD_version bumped to indicate presence of the new name
smp_no_rendezvous_barrier().

Reviewed by: gnn, jhb (email), kib
Differential Revision: https://reviews.freebsd.org/D10313

6 years agoMFC 312534: ANSYfy kern_ktrace.c and remove archaic register keyword
jhb [Thu, 25 Jan 2018 00:09:44 +0000 (00:09 +0000)]
MFC 312534: ANSYfy kern_ktrace.c and remove archaic register keyword

6 years agoMFC 325028,328344: Discard the correct thread event reported for a ptrace stop.
jhb [Wed, 24 Jan 2018 21:48:39 +0000 (21:48 +0000)]
MFC 325028,328344: Discard the correct thread event reported for a ptrace stop.

325028:
Discard the correct thread event reported for a ptrace stop.

When multiple threads wish to report a tracing event to a debugger,
both threads call ptracestop() and one thread will win the race to be
the reporting thread (p->p_xthread).  The debugger uses PT_LWPINFO
with the process ID to determine which thread / LWP is reporting an
event and the details of that event.  This event is cleared as a side
effect of the subsequent ptrace event that resumed the process
(PT_CONTINUE, PT_STEP, etc.).  However, ptrace() was clearing the
event identified by the LWP ID passed to the resume request even if
that wasn't the 'p_xthread'.  This could result in clearing an event
that had not yet been observed by the debugger and leaving the
existing event for 'p_thread' pending so that it was reported a second
time.

Specifically, if the debugger stopped due to a software breakpoint in
one thread, but then switched to another thread that was used to
resume (e.g. if the user switched to a different thread and issued a
step), the resume request (PT_STEP) cleared a pending event (if any)
for the thread being stepped.  However, the process immediately
stopped and the first thread reported it's breakpoint event a second
time.  The debugger decremented the PC for "both" breakpoint events
which resulted in the PC now pointing into the middle of an
instruction (on x86) and a SIGILL fault when the process was resumed a
second time.

To fix, always clear the pending event for 'p_xthread' when resuming a
process.  ptrace() still honors the requested LWP ID when enabling
single-stepping (PT_STEP) or setting a different PC (PT_CONTINUE).

328344:
Mark the unused argument to continue_thread() as such.

clang in HEAD and 11 does not warn about this, but clang in 10 does.

6 years agoMFC r327779, r327780:
markj [Wed, 24 Jan 2018 15:16:17 +0000 (15:16 +0000)]
MFC r327779, r327780:
Fix handling of read errors during synchronization.

6 years agoMFC r327496, r327760:
markj [Wed, 24 Jan 2018 15:15:18 +0000 (15:15 +0000)]
MFC r327496, r327760:
Fix some I/O ordering issues in gmirror.

6 years agoMFC r314502:
hselasky [Wed, 24 Jan 2018 13:12:21 +0000 (13:12 +0000)]
MFC r314502:
Make gtaskqueue compatible with drm-next such that they can be used with the
linuxkpi tasklets.

Submitted by: mmacy@nextbsd.org
Reported by: hselasky (hps)

6 years agoMFC r322596:
hselasky [Wed, 24 Jan 2018 12:51:13 +0000 (12:51 +0000)]
MFC r322596:
Add SI_SUB_TASKQ after SI_SUB_INTR and move taskqueue initialization there for EARLY_AP_STARTUP

This fixes a regression accidentally introduced in r322588, due to an
interaction with EARLY_AP_STARTUP.

Discussed with: cem@
Reviewed by: bdrewery@, jhb@
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D12053

6 years agoMFC r328082:
kib [Wed, 24 Jan 2018 10:50:21 +0000 (10:50 +0000)]
MFC r328082:
Amd64 user_ldt_deref() is not used outside sys_machdep.c.  Mark it as
static.

6 years agoMFC r327770: lld: introduce basic man page
emaste [Wed, 24 Jan 2018 00:52:25 +0000 (00:52 +0000)]
MFC r327770: lld: introduce basic man page

Upstream lld has no man page. Introduce a basic one for FreeBSD based on
ld.lld --help, with a brief introduction and additional detail for some
options.

We'll continue refining this in FreeBSD, and then submit it upstream once
the first round of edits are complete.

Submitted by: krion, Arshan Khanifar, emaste, bjk
Sponsored by: The FreeBSD Foundation

6 years agoMFC 326953:
jhb [Wed, 24 Jan 2018 00:32:02 +0000 (00:32 +0000)]
MFC 326953:
Catch up to r325719 which makes the kern.proc.pid sysctl "work" for zombies.

Some of the ptrace tests need to wait for a child process to become a
zombie before preceding.  The parent process polls the child process
via the kern.proc.pid sysctl to wait for it to become a zombie.
Previously the code polled until the sysctl failed with ESRCH.  Now it
will poll until either the sysctl fails with ESRCH (for compatiblity
with older kernels) or returns a kinfo_proc structure with the ki_stat
field set to SZOMB.

6 years agoMFC r328221:
pfg [Wed, 24 Jan 2018 00:11:46 +0000 (00:11 +0000)]
MFC r328221:

Define a new __alloc_size2 attribute to complement the existing support.

At least on GCC7, calling __alloc_size(x) twice is not equivalent to
calling using the attribute once with two arguments. The later is the
documented use in GCC documentation so add a new alloc_size(n, x)
alternative to cover for the few places where it is used: basically:
calloc(3), reallocarray(3) and  mallocarray(9).

Submitted by: Mark Millard

6 years agoMFC 320900,323882,324224,324226,324228,326986,326988,326989,326990,326993,
jhb [Tue, 23 Jan 2018 20:08:25 +0000 (20:08 +0000)]
MFC 320900,323882,324224,324226,324228,326986,326988,326989,326990,326993,
326994,326995,327004: Various fixes for pathconf(2).

The original change to use vop_stdpathconf() more widely was motivated
by a panic due to recent AIO-related changes.  However, bde@ reported
that vop_stdpathconf() contained too many settings that were not
filesystem-independent.  The end result of this set of patches is to
fix the AIO-related panic via use of a trimmed-down vop_stdpathconf()
while also adding support for missing pathconf variables in various
filesystems (and removing a few settings incorrectly reported as
supported).

320900:
Consistently use vop_stdpathconf() for default pathconf values.

Update filesystems not currently using vop_stdpathconf() in pathconf
VOPs to use vop_stdpathconf() for any configuration variables that do
not have filesystem-specific values.  vop_stdpathconf() is used for
variables that have system-wide settings as well as providing default
values for some values based on system limits.  Filesystems can still
explicitly override individual settings.

323882:
Only handle _PC_MAX_CANON, _PC_MAX_INPUT, and _PC_VDISABLE for TTY devices.

Move handling of these three pathconf() variables out of vop_stdpathconf()
and into devfs_pathconf() as TTY devices can only be devfs files.  In
addition, only return settings for these three variables for devfs devices
whose device switch has the D_TTY flag set.

324224:
Handle _PC_FILESIZEBITS and _PC_SYMLINK_MAX pathconf() requests in cd9660.

cd9660 only supports symlinks with Rock Ridge extensions, so
_PC_SYMLINK_MAX is conditional on Rock Ridge.

324226:
Return 64 for pathconf(_PC_FILESIZEBITS) on tmpfs.

324228:
Flesh out pathconf() on UDF.

- Return 64 bits for _PC_FILESIZEBITS.
- Handle _PC_SYMLINK_MAX.
- Defer _PC_PATH_MAX to vop_stdpathconf().

326986:
Add a custom VOP_PATHCONF method for fdescfs.

The method handles NAME_MAX and LINK_MAX explicitly.  For all other
pathconf variables, the method passes the request down to the underlying
file descriptor.  This requires splitting a kern_fpathconf() syscallsubr
routine out of sys_fpathconf().  Also, to avoid lock order reversals with
vnode locks, the fdescfs vnode is unlocked around the call to
kern_fpathconf(), but with the usecount of the vnode bumped.

326988:
Add a custom VOP_PATHCONF method for fuse.

This method handles _PC_FILESIZEBITS, _PC_SYMLINK_MAX, and _PC_NO_TRUNC.
For other values it defers to vop_stdpathconf().

326989:
Support _PC_FILESIZEBITS in msdosfs' VOP_PATHCONF().

326990:
Handle _PC_FILESIZEBITS and _PC_NO_TRUNC for smbfs' VOP_PATHCONF().

326993:
Move NAME_MAX, LINK_MAX, and CHOWN_RESTRICTED out of vop_stdpathconf().

Having all filesystems fall through to default values isn't always correct
and these values can vary for different filesystem implementations.  Most
of these changes just use the existing default values with a few exceptions:
- Don't report CHOWN_RESTRICTED for ZFS since it doesn't do the exact
  permissions check this claims for chown().
- Use NANDFS_NAME_LEN for NAME_MAX for nandfs.
- Don't report a LINK_MAX of 0 on smbfs.  Now fail with EINVAL to
  indicate hard links aren't supported.

326994:
Handle _PC_FILESIZEBITS and _PC_SYMLINK_MAX for devfs' VOP_PATHCONF().

326995:
Use FUSE_LINK_MAX for LINK_MAX in fuse' VOP_PATHCONF().

Should have included this in r326993.

327004:
Rework pathconf handling for FIFOs.

On the one hand, FIFOs should respect other variables not supported by
the fifofs vnode operation (such as _PC_NAME_MAX, _PC_LINK_MAX, etc.).
These values are fs-specific and must come from a fs-specific method.
On the other hand, filesystems that support FIFOs are required to
support _PC_PIPE_BUF on directory vnodes that can contain FIFOs.
Given this latter requirement, once the fs-specific VOP_PATHCONF
method supports _PC_PIPE_BUF for directories, it is also suitable for
FIFOs permitting a single VOP_PATHCONF method to be used for both
FIFOs and non-FIFOs.

To that end, retire all of the FIFO-specific pathconf methods from
filesystems and change FIFO-specific vnode operation switches to use
the existing fs-specific VOP_PATHCONF method.  For fifofs, set it's
VOP_PATHCONF to VOP_PANIC since it should no longer be used.

While here, move _PC_PIPE_BUF handling out of vop_stdpathconf() so that
only filesystems supporting FIFOs will report a value.  In addition,
only report a valid _PC_PIPE_BUF for directories and FIFOs.

PR: 219851
Sponsored by: Chelsio Communications

6 years agoMFC 323993: Use tmpfs_print for tmpfs FIFOs.
jhb [Tue, 23 Jan 2018 19:00:13 +0000 (19:00 +0000)]
MFC 323993: Use tmpfs_print for tmpfs FIFOs.

6 years agoMFC 325835: Use #if instead of #ifdef for __BSD_VISIBLE tests.
jhb [Tue, 23 Jan 2018 18:22:41 +0000 (18:22 +0000)]
MFC 325835: Use #if instead of #ifdef for __BSD_VISIBLE tests.

__BSD_VISIBLE is always defined and it's value instead needs to be
tested via #if to determine if FreeBSD-specific APIs should be
exposed.

PR: 196226

6 years agoMFC r327675
kp [Tue, 23 Jan 2018 04:30:46 +0000 (04:30 +0000)]
MFC r327675

pf: Avoid integer overflow issues by using mallocarray() iso. malloc()

pfioctl() handles several ioctl that takes variable length input, these
include:
- DIOCRADDTABLES
- DIOCRDELTABLES
- DIOCRGETTABLES
- DIOCRGETTSTATS
- DIOCRCLRTSTATS
- DIOCRSETTFLAGS

All of them take a pfioc_table struct as input from userland. One of
its elements (pfrio_size) is used in a buffer length calculation.
The calculation contains an integer overflow which if triggered can lead
to out of bound reads and writes later on.

Reported by: Ilja Van Sprundel <ivansprundel@ioactive.com>

6 years agoMFC r327718:
cy [Tue, 23 Jan 2018 04:01:48 +0000 (04:01 +0000)]
MFC r327718:

When growing the state, also grow the seed array. Otherwise memory
that was not allocated will be accessed.

This necessitated refactoring state seed allocation from
ipf_state_soft_init() into a new common ipf_state_seed_alloc() function
as it is now also used by ipf_state_rehash() when changing the size of
the state hash table in addition to by ipf_state_soft_init() during
initialization.

According to Christos Zoulas <christos@NetBSD.org>:

The bug was encountered by a NetBSD vendor who's customer machines had
large ipfilter states. The bug was reliably triggered by resizing the
state variables using "ipf -T".

Submitted by: Christos Zoulas <christos@NetBSD.org>
Reviewed by: delphij, rgrimes
Obtained from: NetBSD ip_state.c CVS revs r1.9 and r1.10
Differential Revision: https://reviews.freebsd.org/D13755

6 years agoMFC r328008:
eadler [Mon, 22 Jan 2018 04:15:12 +0000 (04:15 +0000)]
MFC r328008:

units(1) free savescr in error condition too

CID:          978392

6 years agoMFC r322245: MFV r322242: 8373 TXG_WAIT in ZIL commit path
mav [Mon, 22 Jan 2018 00:19:50 +0000 (00:19 +0000)]
MFC r322245: MFV r322242: 8373 TXG_WAIT in ZIL commit path

illumos/illumos-gate@d28671a3b094af696bea87f52272d4c4d89321c7
https://github.com/illumos/illumos-gate/commit/d28671a3b094af696bea87f52272d4c4d89321c7

https://www.illumos.org/issues/8373
  The code that writes ZIL blocks uses dmu_tx_assign(TXG_WAIT) to assign
  a transaction to a transaction group.  That seems to be logically
  incorrect as writing of the ZIL block does not introduce any new dirty
  data.  Also, when there is a lot of dirty data, the call can introduce
  significant delays into the ZIL commit path, thus affecting all
  synchronous writes. Additionally, ARC throttling may affect the ZIL
  writing.

Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Prakash Surya <prakash.surya@delphix.com>
Approved by: Dan McDonald <danmcd@joyent.com>
Author: Andriy Gapon <avg@FreeBSD.org>

6 years agoMFC r327965:
kib [Sun, 21 Jan 2018 10:43:01 +0000 (10:43 +0000)]
MFC r327965:
Add STAC and CLAC instructions wrappers.

6 years agoMFC r327964:
kib [Sun, 21 Jan 2018 10:39:57 +0000 (10:39 +0000)]
MFC r327964:
Enumerate and print Intel CPU features for Speculative Execution Side
Channel Mitigations.

6 years agoMFC r323822 (by cem):
kib [Sun, 21 Jan 2018 10:38:38 +0000 (10:38 +0000)]
MFC r323822 (by cem):
x86: Decode AMD "Extended Feature Extensions ID EBX" bits.

6 years agoMFC r327963:
kib [Sun, 21 Jan 2018 10:35:17 +0000 (10:35 +0000)]
MFC r327963:
When re-evaluating cpu_features, also re-print CPU identification.

6 years agoMFC r327674, r327796
kp [Sat, 20 Jan 2018 23:46:03 +0000 (23:46 +0000)]
MFC r327674, r327796

Introduce mallocarray() in the kernel

Similar to calloc() the mallocarray() function checks for integer
overflows before allocating memory.
It does not zero memory, unless the M_ZERO flag is set.

Additionally, move the overflow check logic out to WOULD_OVERFLOW() for
consumers to have a common means of testing for overflowing allocations.
WOULD_OVERFLOW() should be a secondary check -- on 64-bit platforms, just
because an allocation won't overflow size_t does not mean it is a sane size
to request.  Callers should be imposing reasonable allocation limits far,
far, below overflow.

Obtained from: OpenBSD

6 years agoMFC r327913:
cy [Sat, 20 Jan 2018 18:04:08 +0000 (18:04 +0000)]
MFC r327913:

Remove redundant variable.

6 years agoMFC r327912:
cy [Sat, 20 Jan 2018 18:00:42 +0000 (18:00 +0000)]
MFC r327912:

Though this block of code is not used by FreeBSD, correct a call to
sprintf() with a macro call to SNPRINTF similar to other calls to
SNPRINTF within this same block.

6 years agoMFC r327917:
kib [Sat, 20 Jan 2018 12:31:21 +0000 (12:31 +0000)]
MFC r327917:
Add sysctl debug.kdb.stack_overflow.

6 years agoMFC r327946 r327947:
eadler [Sat, 20 Jan 2018 01:01:28 +0000 (01:01 +0000)]
MFC r327946 r327947:

limits(1): fix grammar

PR:           225147

6 years agoMFC r323317 (by scottl): Move the intrhook release to later in the function
mav [Fri, 19 Jan 2018 16:06:52 +0000 (16:06 +0000)]
MFC r323317 (by scottl): Move the intrhook release to later in the function
so that GEOM knows to wait longer for possible root devices to come online.
This fixes a race that seems to be triggered by EARLY_AP_STARTUP.

Submitted by: cgull@glup.org

6 years agoMFC r322288: regex(3): Refactor fast/slow stepping bits in matching engine
kevans [Thu, 18 Jan 2018 22:13:31 +0000 (22:13 +0000)]
MFC r322288: regex(3): Refactor fast/slow stepping bits in matching engine

Adding features for matching is fairly straightforward, but this requires
some duplication because of this fast/slow setup. They can be fairly
trivially combined into a single walk(), so do it to make future additions
less error prone.

6 years agoMFC r320742, r320750, r320796: Refactor regex(3) for maintainability
kevans [Thu, 18 Jan 2018 22:10:00 +0000 (22:10 +0000)]
MFC r320742, r320750, r320796: Refactor regex(3) for maintainability

MFC r320742:
The impending libregex will implement GNU extensions to bring BREs and
EREs closer together. Prepare for this and reduce the diff of libregex
changes by refactoring and combining the top-level parsers for EREs/BREs
ahead of time.

Branching functionality has been split out to make it easier to follow the
combined version of the top-level parser. It may also be enabled in the
parsing context to make it easier when libregex enables branching for BREs.

A branching context was also added for the various branching functions and
so that BREs, for instance, can determine if they're the first expression in
a chain of expressions within the current branch and treat '*' as ordinary
if so.

This should have no functional impact and negligible performance impact.

MFC r320750: Fix sparc64 libc build after r320742.

p_branch_empty was declared but never used due to an oversight. Use it as
designed, further comment on its return value.

MFC r320796:
Correctly ignore branch operators in the top-level parser when applicable.

An oversight in r320742 caused BREs to become sensitive to the branching
operator prematurely, which caused breakage in some limited situations --
namely, those that tried to use branching in a BRE. Most of these scenarios
had already been corrected beforehand to properly use gsed or grep for GNU
extensions, so the damage is slightly mitigated.

6 years agoMFC r327567: hexdump(1): Speed up -s flag on devices
kevans [Thu, 18 Jan 2018 21:59:13 +0000 (21:59 +0000)]
MFC r327567: hexdump(1): Speed up -s flag on devices

Using the -s flag on devices is extraordinarily slow due to using fseek(3) a
little too conservatively. Address this by using fseek on character/block
devices as well, falling back to getchar(3) only if we fail to seek or we're
operating on tape drives, where fseek may succeed while not actually being
supported.

PR: 86485

6 years agoMFC r326084: patch(1): don't assume match if we run out of context to check
kevans [Thu, 18 Jan 2018 21:53:07 +0000 (21:53 +0000)]
MFC r326084: patch(1): don't assume match if we run out of context to check

Patches with very little context (-U0 and -U1) could get misapplied if
the file to be patched changes and a hunk is no longer applicable. Matching
with fuzz would be attempted and default to a match when we unexpectedly ran
out of context.

This also affected patches with higher levels of context but had limited
actual context due to the hunk being located near the beginning/end of file.

PR: 74127

6 years agoMFC r324431: patch(1): Don't overrun line buffer in some cases
kevans [Thu, 18 Jan 2018 21:46:42 +0000 (21:46 +0000)]
MFC r324431: patch(1): Don't overrun line buffer in some cases

Patches like file.txt attached to PR 190195 with a final line formed
like ">(EOL)" could cause a copy past the end of the current line buffer. In
the case of PR 191641, this caused a duplicate line to be copied into the
resulting file.

Instead of running past the end, treat it as if it were a blank line.

PR: 191641

6 years agoMFC r322322: Expose device caps as libusb_bos_descriptor::dev_capability
kevans [Thu, 18 Jan 2018 21:39:03 +0000 (21:39 +0000)]
MFC r322322: Expose device caps as libusb_bos_descriptor::dev_capability

Some libusb consumers in Linux-land (in this case, libusb4java) expect a
dev_capability member that they can use to enumerate the device
capabilities.

No particular layout is expected of this, just that it can be traversed
using the bLength member until bNumDeviceCapabilities are read and that the
consumer may then use one of the libusb_get_*_descriptor methods to extract
specific (usb 2.0 vs. ss) capability information.

6 years agoMFC r322293: df(1): Add --si as an alias for -H
kevans [Thu, 18 Jan 2018 21:35:18 +0000 (21:35 +0000)]
MFC r322293: df(1): Add --si as an alias for -H

6 years agoMFC r322291: du(1): Add --si option to display in terms of powers of 1000
kevans [Thu, 18 Jan 2018 21:32:50 +0000 (21:32 +0000)]
MFC r322291: du(1): Add --si option to display in terms of powers of 1000

6 years agoMFC r322177: Respect SIMPLE_BACKUP_SUFFIX environment variable in indent(1)
kevans [Thu, 18 Jan 2018 21:29:46 +0000 (21:29 +0000)]
MFC r322177: Respect SIMPLE_BACKUP_SUFFIX environment variable in indent(1)

Instead of using a non-configurable ".BAK" suffix, respect the
SIMPLE_BACKUP_SUFFIX environment variable also used by patch(1). This
simplifies cleanup operations in some patch/indent workflows.

6 years agoMFC r327560:
ed [Thu, 18 Jan 2018 13:43:09 +0000 (13:43 +0000)]
MFC r327560:

  Allow timed waits with relative timeouts on locks and condvars.

  Even though pthreads doesn't support this, there are various alternative
  APIs that use this. For example, uv_cond_timedwait() accepts a relative
  timeout. So does Rust's std::sync::Condvar::wait_timeout().

  Though I personally think that relative timeouts are bad (due to
  imprecision for repeated operations), it does seem that people want
  this. Extend the existing futex functions to keep track of whether an
  absolute timeout is used in a boolean flag.

6 years agoMFC r327822:
kib [Thu, 18 Jan 2018 12:14:24 +0000 (12:14 +0000)]
MFC r327822:
Skip IRELATIVE relocations when loader processes ELF files.

6 years agoMFC r327819:
kib [Thu, 18 Jan 2018 12:08:52 +0000 (12:08 +0000)]
MFC r327819:
Do not redundantly clear %RFLAGS.DF on fast syscall entry.

6 years agoMFC r327818:
kib [Thu, 18 Jan 2018 12:07:37 +0000 (12:07 +0000)]
MFC r327818:
Move the hardware setup for fast syscalls into a common function.

6 years agoMFC r327555:
kib [Thu, 18 Jan 2018 12:06:01 +0000 (12:06 +0000)]
MFC r327555:
Restructure swapout tests after vm map locking was removed.

6 years agoMFC r327450 (by alc):
kib [Thu, 18 Jan 2018 12:04:45 +0000 (12:04 +0000)]
MFC r327450 (by alc):
Eliminate "minslptime".

6 years agoMFC r327768:
markj [Wed, 17 Jan 2018 15:12:52 +0000 (15:12 +0000)]
MFC r327768:
Clarify the use of the gmirror flag mask constants.

6 years agoMFC r327724: usbdevs: add ASMedia vendor ID
avg [Tue, 16 Jan 2018 11:23:21 +0000 (11:23 +0000)]
MFC r327724: usbdevs: add ASMedia vendor ID

6 years agoMFC r327725: zfs_mount: restore a bit of ifdef-out illumos code
avg [Tue, 16 Jan 2018 11:22:08 +0000 (11:22 +0000)]
MFC r327725: zfs_mount: restore a bit of ifdef-out illumos code