]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
6 years agoMFC r316105 (by ngie): Don't use K&R style prototypes; ANSIfy them
mav [Thu, 1 Feb 2018 19:45:28 +0000 (19:45 +0000)]
MFC r316105 (by ngie): Don't use K&R style prototypes; ANSIfy them

This fixes several -Wold-style-definition warnings.

6 years agoMFC r314230 (by imp):
mav [Thu, 1 Feb 2018 19:44:24 +0000 (19:44 +0000)]
MFC r314230 (by imp):
Make nvmecontrol logpage -p help list known pages.

Make -p help and -v help list all the pages we know about.
Add -v to usage.
Update the man page.

6 years agoMFC r314229 (by imp):
mav [Thu, 1 Feb 2018 19:43:51 +0000 (19:43 +0000)]
MFC r314229 (by imp):
Exit with usage if argv[1] is NULL in dispatch. This fixes core dumps
when a command has subcommands, but the user doesn't give the
parameters on the command line.

6 years agoMFC r314228 (by imp): Fix typos in output.
mav [Thu, 1 Feb 2018 19:43:18 +0000 (19:43 +0000)]
MFC r314228 (by imp): Fix typos in output.

6 years agoMFC r313259 (by imp):
mav [Thu, 1 Feb 2018 19:41:46 +0000 (19:41 +0000)]
MFC r313259 (by imp):
Use ssize_t instead of uint32_t to prevent warnings about a comparison
with different signs. Due to the promotion rules, this would only
happen on 32-bit platforms.

6 years agoMFC r313258 (by imp):
mav [Thu, 1 Feb 2018 19:40:51 +0000 (19:40 +0000)]
MFC r313258 (by imp):
Add the ability to dump log pages directly in binary to stdout.
Update man page to include this flag, and an example of dumping a
vendor-specific page while I'm here.

6 years agoMFC r313257 (by imp):
mav [Thu, 1 Feb 2018 19:39:29 +0000 (19:39 +0000)]
MFC r313257 (by imp):
Add some descriptions to the man page for the supported log pages as
well as the new wdc commands. Make wdc be an alias for hgst when
specifying the vendor to use to interpret the page.

6 years agoMFC r313252 (by imp):
mav [Thu, 1 Feb 2018 19:39:00 +0000 (19:39 +0000)]
MFC r313252 (by imp):
Fix off by one error that truncated the serial number for filenames.

6 years agoMFC r313251 (by imp):
mav [Thu, 1 Feb 2018 19:38:29 +0000 (19:38 +0000)]
MFC r313251 (by imp):
Fix a typo in usage string for unimplemented command.

6 years agoMFC r313191 (by imp):
mav [Thu, 1 Feb 2018 19:37:50 +0000 (19:37 +0000)]
MFC r313191 (by imp):
Implement 5 wdc-specific nvme control options for their HGST drives:
        wdc cap-diag            Capture diagnostic data from drive
        wdc drive-log           Capture drive history data from drive
        wdc get-crash-dump      Retrieve firmware crash dump from drive

6 years agoMFC r313190 (by imp):
mav [Thu, 1 Feb 2018 19:37:18 +0000 (19:37 +0000)]
MFC r313190 (by imp):
Move the usage and command name lookup into functions.

6 years agoMFC r313188 (by imp):
mav [Thu, 1 Feb 2018 19:36:42 +0000 (19:36 +0000)]
MFC r313188 (by imp):
Put the arguments to aligned_alloc in the right order.

6 years agoMFC r313111 (by imp):
mav [Thu, 1 Feb 2018 19:35:34 +0000 (19:35 +0000)]
MFC r313111 (by imp):
Use aligned buffer for the firmware data. Otherwise, when loading a
MAXPHYS bytes of data, the I/O would require MAXPHYS + PAGE_SIZE worth
of pages to do the I/O and we'd hit an assertion in
vm_fault_quick_hold_pages unless MAXPHYS was larger than 1M +
PAGE_SIZE.

6 years agoMFC r309777 (by imp):
mav [Thu, 1 Feb 2018 19:33:51 +0000 (19:33 +0000)]
MFC r309777 (by imp):
Implement Intel's log page 0xc1 (Read Command Latency Log) and page
0xc1 (Write Command Latency Log).

6 years agoMFC r309684 (by imp): Fix Typo
mav [Thu, 1 Feb 2018 19:33:17 +0000 (19:33 +0000)]
MFC r309684 (by imp): Fix Typo

6 years agoMFC r309413 (by imp):
mav [Thu, 1 Feb 2018 19:32:45 +0000 (19:32 +0000)]
MFC r309413 (by imp):
Flag the vendor specific pages as such. This allows different decoding
for the same page number as different vendors encode vendor specific
pages differently.

6 years agoMFC r308869 (by imp):
mav [Thu, 1 Feb 2018 19:31:39 +0000 (19:31 +0000)]
MFC r308869 (by imp):
i386 turns out to not have __uint128_t. So confusingly use 64-bit math
instead. Since we're little endian, we can get away with it. Also,
since the counters in quesitons would require billions of iops for
tens of billions of seconds to overflow, and since such data rates are
unlikely for people using i386 for a while, that's OK. The fastest
cards today can't do even a million IOPs.

6 years agoMFC r308856 (by imp):
mav [Thu, 1 Feb 2018 19:30:37 +0000 (19:30 +0000)]
MFC r308856 (by imp):
Decode the Intel-specific Additional SMART data page (0xca) and print
it in human readable form. Include a pointer to the public spec that
was followed to implement this in the code. Samsung also implements
page 0xca on some of their drives, but the format is slighly
different, so the code skips printing zero keys. Samsung's log page
has additional, unknown data after the end of Intel defined data which
isn't displayed.

6 years agoMFC r308848 (by imp):
mav [Thu, 1 Feb 2018 19:30:02 +0000 (19:30 +0000)]
MFC r308848 (by imp):
Remove check for valid log pages. Let the drive tell us which pages
are valid or not. While many pages are reserved in the standard, that
doesn't make them invalid and future versions of the standard may
define then.

6 years agoMFC r303315 (by imp): Remove some extraneous printfs.
mav [Thu, 1 Feb 2018 19:28:00 +0000 (19:28 +0000)]
MFC r303315 (by imp): Remove some extraneous printfs.

6 years agoMFC r303125 (by imp):
mav [Thu, 1 Feb 2018 19:27:10 +0000 (19:27 +0000)]
MFC r303125 (by imp):
Remove some bogus comments and printfs. Also, we can't
cam_periph_releaes_locked() at the end of nvme_probe_start because we
hit an assertion which may be bogus. Instead, leak a periph until we
sort it out. Since these devices don't arrive and depart often, so
this is the lessor of two evils.

6 years agoMFC r324632 (by imp):
mav [Thu, 1 Feb 2018 19:13:19 +0000 (19:13 +0000)]
MFC r324632 (by imp):
Be nicer on the dump stack by allocating only a ccb_nvmeio rather than
a full ccb. This saves a few hundre bytes, which might be important
during a crash dump...

6 years agoMFC r324644 (by imp):
mav [Thu, 1 Feb 2018 19:07:21 +0000 (19:07 +0000)]
MFC r324644 (by imp):
Closer examination shows that nvme and CAM both normally zero-fill
allocations (for req and ccb, which ultimately contain the
nvme_cmd). As such, we can micro-optimize these routines. Add a
comment to this effect, and bzero the ccb used to make the requests
for the nda dump rotuine so it more closely matches a ccb allocated
with xpt_get_ccb().

6 years agoMFC r324634 (by imp):
mav [Thu, 1 Feb 2018 19:06:42 +0000 (19:06 +0000)]
MFC r324634 (by imp):
Use nvme_ctrlr_poll instead of nvme_ctrlr_intx_handler since it is
more general and doesn't try to access registers that may be undefined
when the card is in MSIX mode.

This change, along with r324630, r324631, r324632, makes nda crash
dumps work again. Previously, they only worked on CPU 0 when the stack
garbage was just so.

6 years agoMFC r324633 (by imp):
mav [Thu, 1 Feb 2018 19:05:48 +0000 (19:05 +0000)]
MFC r324633 (by imp):
Create general polling function for the nvme controller. Use it when
we're doing the various pin-based interrupt modes. Adjust
nvme_ctrlr_intx_handler to use nvme_ctrlr_poll.

6 years agoMFC r324631 (by imp):
mav [Thu, 1 Feb 2018 19:04:50 +0000 (19:04 +0000)]
MFC r324631 (by imp):
Explicitly set reserved fields and 'fuse' to 0. This prevents us from
acidentally sending bogus values in these fields, which some drives
may reject with an error or worse (undefined behavior).

This is especially needed for the ndadump routine which allocates the
cmd from stack garbage....

6 years agoMFC r324075 (by imp): Tweak performance of nda completions
mav [Thu, 1 Feb 2018 19:01:06 +0000 (19:01 +0000)]
MFC r324075 (by imp): Tweak performance of nda completions

Use xpt_done_direct in preference to xpt_done when completing a
successful I/O. Continue to use xpt_done when there's an error, or for
completion of the submission of a CCB. This eliminates a context
switch to the cam_doneq thread.

6 years agoMFC r323834 (by imp): Fix queue depth for nda.
mav [Thu, 1 Feb 2018 19:00:05 +0000 (19:00 +0000)]
MFC r323834 (by imp):  Fix queue depth for nda.

1/4 of the number of queues times queue entries is too limiting. It
works up to about 4k IOPS / 3.0GB/s for hardware that can do
4.4k/3.2GB/s with nvd. 3/4 works better, though it highlights issues
in the fairness of nda's choice of TRIM vs READ. That will be fixed
separately.

6 years agoMFC r322998 (by imp):
mav [Thu, 1 Feb 2018 18:59:03 +0000 (18:59 +0000)]
MFC r322998 (by imp):
Fix a few overlooked spots where the coded uses 16-bit NSIDs. Chuck
Tuffli had submitted a more thorough patch that I was unaware of when
I did my work and this brings in the bits I missed from that patch.

6 years agoMFC r322997: Add CAM/NVMe support for CAM_DATA_SG
mav [Thu, 1 Feb 2018 18:57:10 +0000 (18:57 +0000)]
MFC r322997: Add CAM/NVMe support for CAM_DATA_SG

This adds support in pass(4) for data to be described with a
scatter-gather list (sglist) to augment the existing (single) virtual
address.

6 years agoMFC r322995 (by imp):
mav [Thu, 1 Feb 2018 16:53:08 +0000 (16:53 +0000)]
MFC r322995 (by imp):
Add new compile-time option NVME_USE_NVD that sets the default value
of the runtime hw.nvme.use_vnd tunable. We still default to nvd unless
otherwise requested.

6 years agoMFC r322994: Set the max transactions for NVMe drives better.
mav [Thu, 1 Feb 2018 16:52:03 +0000 (16:52 +0000)]
MFC r322994: Set the max transactions for NVMe drives better.

Provided a better estimate for the number of transactions that can be
pending at one time. This will be number of queues * number of
trackers / 4, as suggested by Jim Harris. This gives a better estimate
of the number of transactions that CAM should queue before applying
back pressure. This should be revisted when we have real multi-queue
support in CAM and the upper layers of the I/O stack.

6 years agoMFC r322903 (by imp):
mav [Thu, 1 Feb 2018 16:51:11 +0000 (16:51 +0000)]
MFC r322903 (by imp):
Fill in reserved areas from NVMe spec in the IDENTIFY structure
(struct nvme_controller_data) as defined in the NVM Express
specification, revsion 1.3.

6 years agoMFC r322902 (by imp):
mav [Thu, 1 Feb 2018 16:50:25 +0000 (16:50 +0000)]
MFC r322902 (by imp):
NVME Namespace ID is 32-bits, so widen interface to reflect that.

6 years agoMFC r322901 (by imp): Add feature codes from NVMe 1.3 specification:
mav [Thu, 1 Feb 2018 16:49:28 +0000 (16:49 +0000)]
MFC r322901 (by imp): Add feature codes from NVMe 1.3 specification:

o Automomous Power State Transition
o Host Memory Buffer
o Timestamp
o Keep Alive Timer
o Host Controlled Thermal Management
o Non-Operational Power State Config

Also note that feature codes 0x78-0x7f are reserved for the NVMe
Management Interface.

6 years agoMFC r322874, r322875 (by imp): Sanity check sizes
mav [Thu, 1 Feb 2018 16:48:40 +0000 (16:48 +0000)]
MFC r322874, r322875 (by imp): Sanity check sizes

Add compile time sanity checks to make sure that packed structures are
the proper size, typically as defined in the NVMe standard.

6 years agoMFC r322872 (by imp):
mav [Thu, 1 Feb 2018 16:45:44 +0000 (16:45 +0000)]
MFC r322872 (by imp):
Enable bus mastering on the device before resetting the device. The
card has to do PCIe transactions to complete the reset process, but
can't do them, per the PCIe spec, unless bus mastering is enabled.

6 years agoMFC r322443 (by nwhitehorn):
mav [Thu, 1 Feb 2018 16:45:08 +0000 (16:45 +0000)]
MFC r322443 (by nwhitehorn):
Move NVME controller shutdown from being called as part of module unloading
to being called through the newbus DEVICE_SHUTDOWN() path. This ensures that
the NVME controller gets shut down before the device and bus disappear
and prevents data corruption on shutdown on at least Samsung EVO 960 SSDs.

PR: kern/211852

6 years agoMFC r322257 (by imp): Use the correct queue depth for nda devices.
mav [Thu, 1 Feb 2018 16:44:19 +0000 (16:44 +0000)]
MFC r322257 (by imp): Use the correct queue depth for nda devices.

6 years agoMFC r322036 (by imp):
mav [Thu, 1 Feb 2018 16:40:37 +0000 (16:40 +0000)]
MFC r322036 (by imp):
Make nvd vs nda choice boot-time rather than build-time

Introduce hw.nvme.use_nvd tunable. This tunable allows both nvd and
nda to be installed in the kernel, while allowing only one of them to
create devices. This is an all-or-nothing setting, and you can't
change it after boot-time. However, it will allow easier A/B testing.

6 years agoMFC r320984 (by imp):
mav [Thu, 1 Feb 2018 16:35:40 +0000 (16:35 +0000)]
MFC r320984 (by imp):
This adds CAM pass(4) support for NVMe IO's. Applications indicate
the IO type (Admin or NVM) using XPT op-codes XPT_NVME_ADMIN or
XPT_NVME_IO.

6 years agoMFC r303123 (by imp): Fix mismerge and include the nvme support.
mav [Thu, 1 Feb 2018 16:33:15 +0000 (16:33 +0000)]
MFC r303123 (by imp): Fix mismerge and include the nvme support.
Also, print out the name of any CCB's functions that's not supported.

6 years agoMFC r320424 (by imp): Add new definitions for namespaces.
mav [Thu, 1 Feb 2018 16:27:50 +0000 (16:27 +0000)]
MFC r320424 (by imp): Add new definitions for namespaces.

6 years agoMFC r314889 (by imp):
mav [Thu, 1 Feb 2018 16:27:10 +0000 (16:27 +0000)]
MFC r314889 (by imp):
Avoid dereferencing unintialized elements in the error path.

Some drives sometimes have errors for things like setting the number
of queue entries in the submission queue. The error paths taken for
these drives ensure a panic dereferencing uninialized data.

6 years agoMFC r314884 (by imp): Make multi-namespace nvme drives more robust.
mav [Thu, 1 Feb 2018 16:26:35 +0000 (16:26 +0000)]
MFC r314884 (by imp): Make multi-namespace nvme drives more robust.

Fix assumptions about name spaces in NVME driver. First, it assumes
cdata.nn is the number of configured devices. However, it is the
number of supported name spaces. Second, it assumes that there will
never be more than 16 name spaces supported, but a certain drive I'm
testing reports 1024. It assumes that name spaces are a tightly packed
namespace, but the standard seems to indicate otherwise. Finally, it
assumes that an error would be generated when quearying an
unconfigured namespace. Instead, it succeeds but the identify data is
all zeros.

Fix these by limiting the number of name spaces we probe to 16. Remove
aborting when we find one in error. When the size of the name space is
zero, ignore it.

This is admittedly a bandaide. The long term fix will be to
participate in the enumeration and name space change protocols
definfed in the NVNe standard.

6 years agoMFC r313113 (by imp):
mav [Thu, 1 Feb 2018 16:24:03 +0000 (16:24 +0000)]
MFC r313113 (by imp):
Ensure that the passthrough request will fit in MAXPHYS bytes after it
has been rounded to full pages. This avoids a panic in
vm_fault_quick_hold_pages due to this off-by-one error passing one
page too many into vmapbuf.

6 years agoMFC r308855 (by imp):
mav [Thu, 1 Feb 2018 16:22:28 +0000 (16:22 +0000)]
MFC r308855 (by imp):
Implement HGST Log page 0xc1, as documented in the HGST SN100 and
SN150 product manuals. Subpage 0x32 is documented, but not implemented.

6 years agoMFC r308854 (by imp): Print Intel's expanded Temperature log page.
mav [Thu, 1 Feb 2018 16:21:45 +0000 (16:21 +0000)]
MFC r308854 (by imp): Print Intel's expanded Temperature log page.

6 years agoMFC r308849 (by imp):
mav [Thu, 1 Feb 2018 16:20:44 +0000 (16:20 +0000)]
MFC r308849 (by imp):
Use a table for pages we know the size of. We have a special case for
the error log since it isn't a fixed size.

6 years agoMFC r308853 (by imp):
mav [Thu, 1 Feb 2018 16:16:09 +0000 (16:16 +0000)]
MFC r308853 (by imp):
Add log pages that Intel SSDs provide. It turns out that many of these
are widely implemented beyond just Intel drives.

6 years agoMFC r308852 (by imp):
mav [Thu, 1 Feb 2018 16:15:39 +0000 (16:15 +0000)]
MFC r308852 (by imp):
Add log pages defined through NVM Express 1.2.1.

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