svn commit: r328653 - in stable/11/sys: compat/linuxkpi/common/include/asm compat/linuxkpi/common/include/linux compat/linuxkpi/common/include/net compat/linuxkpi/common/src conf contrib/rdma/krpin...

Hans Petter Selasky hselasky at FreeBSD.org
Thu Feb 1 13:01:46 UTC 2018


Author: hselasky
Date: Thu Feb  1 13:01:44 2018
New Revision: 328653
URL: https://svnweb.freebsd.org/changeset/base/328653

Log:
  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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at mattmacy.io>
  Differential Revision:  https://reviews.freebsd.org/D13537

Added:
  stable/11/sys/compat/linuxkpi/common/include/asm/msr.h   (contents, props changed)
  stable/11/sys/compat/linuxkpi/common/include/asm/smp.h   (contents, props changed)
  stable/11/sys/compat/linuxkpi/common/include/linux/atomic.h   (contents, props changed)
  stable/11/sys/compat/linuxkpi/common/include/linux/bitmap.h   (contents, props changed)
  stable/11/sys/compat/linuxkpi/common/include/linux/bottom_half.h   (contents, props changed)
  stable/11/sys/compat/linuxkpi/common/include/linux/hrtimer.h   (contents, props changed)
  stable/11/sys/compat/linuxkpi/common/include/linux/mm_types.h   (contents, props changed)
  stable/11/sys/compat/linuxkpi/common/include/linux/pfn.h   (contents, props changed)
  stable/11/sys/compat/linuxkpi/common/include/linux/pfn_t.h   (contents, props changed)
  stable/11/sys/compat/linuxkpi/common/include/linux/pid.h   (contents, props changed)
  stable/11/sys/compat/linuxkpi/common/include/linux/preempt.h   (contents, props changed)
  stable/11/sys/compat/linuxkpi/common/include/linux/rculist.h   (contents, props changed)
  stable/11/sys/compat/linuxkpi/common/include/linux/smp.h   (contents, props changed)
  stable/11/sys/compat/linuxkpi/common/include/linux/ww_mutex.h   (contents, props changed)
  stable/11/sys/compat/linuxkpi/common/src/linux_current.c   (contents, props changed)
  stable/11/sys/compat/linuxkpi/common/src/linux_hrtimer.c   (contents, props changed)
  stable/11/sys/compat/linuxkpi/common/src/linux_kthread.c   (contents, props changed)
  stable/11/sys/compat/linuxkpi/common/src/linux_lock.c   (contents, props changed)
  stable/11/sys/compat/linuxkpi/common/src/linux_page.c   (contents, props changed)
  stable/11/sys/compat/linuxkpi/common/src/linux_rcu.c   (contents, props changed)
  stable/11/sys/compat/linuxkpi/common/src/linux_schedule.c   (contents, props changed)
  stable/11/sys/compat/linuxkpi/common/src/linux_slab.c   (contents, props changed)
  stable/11/sys/compat/linuxkpi/common/src/linux_tasklet.c   (contents, props changed)
  stable/11/sys/compat/linuxkpi/common/src/linux_work.c   (contents, props changed)
Modified:
  stable/11/sys/compat/linuxkpi/common/include/asm/atomic-long.h
  stable/11/sys/compat/linuxkpi/common/include/asm/atomic.h
  stable/11/sys/compat/linuxkpi/common/include/asm/atomic64.h
  stable/11/sys/compat/linuxkpi/common/include/asm/pgtable.h
  stable/11/sys/compat/linuxkpi/common/include/linux/bitops.h
  stable/11/sys/compat/linuxkpi/common/include/linux/cdev.h
  stable/11/sys/compat/linuxkpi/common/include/linux/clocksource.h
  stable/11/sys/compat/linuxkpi/common/include/linux/compat.h
  stable/11/sys/compat/linuxkpi/common/include/linux/compiler.h
  stable/11/sys/compat/linuxkpi/common/include/linux/completion.h
  stable/11/sys/compat/linuxkpi/common/include/linux/device.h
  stable/11/sys/compat/linuxkpi/common/include/linux/dma-mapping.h
  stable/11/sys/compat/linuxkpi/common/include/linux/etherdevice.h
  stable/11/sys/compat/linuxkpi/common/include/linux/file.h
  stable/11/sys/compat/linuxkpi/common/include/linux/fs.h
  stable/11/sys/compat/linuxkpi/common/include/linux/gfp.h
  stable/11/sys/compat/linuxkpi/common/include/linux/idr.h
  stable/11/sys/compat/linuxkpi/common/include/linux/in.h
  stable/11/sys/compat/linuxkpi/common/include/linux/interrupt.h
  stable/11/sys/compat/linuxkpi/common/include/linux/io-mapping.h
  stable/11/sys/compat/linuxkpi/common/include/linux/io.h
  stable/11/sys/compat/linuxkpi/common/include/linux/jiffies.h
  stable/11/sys/compat/linuxkpi/common/include/linux/kdev_t.h
  stable/11/sys/compat/linuxkpi/common/include/linux/kernel.h
  stable/11/sys/compat/linuxkpi/common/include/linux/kobject.h
  stable/11/sys/compat/linuxkpi/common/include/linux/kthread.h
  stable/11/sys/compat/linuxkpi/common/include/linux/ktime.h
  stable/11/sys/compat/linuxkpi/common/include/linux/list.h
  stable/11/sys/compat/linuxkpi/common/include/linux/lockdep.h
  stable/11/sys/compat/linuxkpi/common/include/linux/math64.h
  stable/11/sys/compat/linuxkpi/common/include/linux/mm.h
  stable/11/sys/compat/linuxkpi/common/include/linux/module.h
  stable/11/sys/compat/linuxkpi/common/include/linux/mutex.h
  stable/11/sys/compat/linuxkpi/common/include/linux/page.h
  stable/11/sys/compat/linuxkpi/common/include/linux/pci.h
  stable/11/sys/compat/linuxkpi/common/include/linux/poll.h
  stable/11/sys/compat/linuxkpi/common/include/linux/printk.h
  stable/11/sys/compat/linuxkpi/common/include/linux/random.h
  stable/11/sys/compat/linuxkpi/common/include/linux/rcupdate.h
  stable/11/sys/compat/linuxkpi/common/include/linux/rwlock.h
  stable/11/sys/compat/linuxkpi/common/include/linux/rwsem.h
  stable/11/sys/compat/linuxkpi/common/include/linux/scatterlist.h
  stable/11/sys/compat/linuxkpi/common/include/linux/sched.h
  stable/11/sys/compat/linuxkpi/common/include/linux/semaphore.h
  stable/11/sys/compat/linuxkpi/common/include/linux/slab.h
  stable/11/sys/compat/linuxkpi/common/include/linux/spinlock.h
  stable/11/sys/compat/linuxkpi/common/include/linux/srcu.h
  stable/11/sys/compat/linuxkpi/common/include/linux/string.h
  stable/11/sys/compat/linuxkpi/common/include/linux/sysfs.h
  stable/11/sys/compat/linuxkpi/common/include/linux/timer.h
  stable/11/sys/compat/linuxkpi/common/include/linux/types.h
  stable/11/sys/compat/linuxkpi/common/include/linux/uaccess.h
  stable/11/sys/compat/linuxkpi/common/include/linux/wait.h
  stable/11/sys/compat/linuxkpi/common/include/linux/workqueue.h
  stable/11/sys/compat/linuxkpi/common/include/net/ip.h
  stable/11/sys/compat/linuxkpi/common/include/net/ipv6.h
  stable/11/sys/compat/linuxkpi/common/src/linux_compat.c
  stable/11/sys/compat/linuxkpi/common/src/linux_idr.c
  stable/11/sys/compat/linuxkpi/common/src/linux_pci.c
  stable/11/sys/conf/files
  stable/11/sys/conf/files.amd64
  stable/11/sys/contrib/rdma/krping/krping.c
  stable/11/sys/dev/mlx5/mlx5_core/mlx5_uar.c
  stable/11/sys/dev/qlnx/qlnxe/bcm_osal.h
  stable/11/sys/modules/linuxkpi/Makefile
  stable/11/sys/modules/qlnx/qlnxe/Makefile
  stable/11/sys/ofed/drivers/infiniband/core/cma.c
  stable/11/sys/ofed/drivers/infiniband/core/fmr_pool.c
  stable/11/sys/ofed/drivers/infiniband/core/iwcm.c
  stable/11/sys/ofed/drivers/infiniband/core/umem.c
  stable/11/sys/ofed/drivers/infiniband/hw/mthca/mthca_dev.h
  stable/11/sys/ofed/drivers/net/mlx4/pd.c
  stable/11/sys/sys/param.h
  stable/11/sys/sys/proc.h
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/compat/linuxkpi/common/include/asm/atomic-long.h
==============================================================================
--- stable/11/sys/compat/linuxkpi/common/include/asm/atomic-long.h	Thu Feb  1 07:52:06 2018	(r328652)
+++ stable/11/sys/compat/linuxkpi/common/include/asm/atomic-long.h	Thu Feb  1 13:01:44 2018	(r328653)
@@ -2,7 +2,7 @@
  * Copyright (c) 2010 Isilon Systems, Inc.
  * Copyright (c) 2010 iX Systems, Inc.
  * Copyright (c) 2010 Panasas, Inc.
- * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.
+ * Copyright (c) 2013-2017 Mellanox Technologies, Ltd.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -31,7 +31,7 @@
 #ifndef	_ATOMIC_LONG_H_
 #define	_ATOMIC_LONG_H_
 
-#include <sys/cdefs.h>
+#include <linux/compiler.h>
 #include <sys/types.h>
 #include <machine/atomic.h>
 
@@ -54,13 +54,13 @@ atomic_long_add_return(long i, atomic_long_t *v)
 static inline void
 atomic_long_set(atomic_long_t *v, long i)
 {
-	atomic_store_rel_long(&v->counter, i);
+	WRITE_ONCE(v->counter, i);
 }
 
 static inline long
 atomic_long_read(atomic_long_t *v)
 {
-	return atomic_load_acq_long(&v->counter);
+	return READ_ONCE(v->counter);
 }
 
 static inline long
@@ -73,6 +73,12 @@ static inline long
 atomic_long_dec(atomic_long_t *v)
 {
 	return atomic_fetchadd_long(&v->counter, -1) - 1;
+}
+
+static inline long
+atomic_long_xchg(atomic_long_t *v, long val)
+{
+	return atomic_swap_long(&v->counter, val);
 }
 
 static inline int

Modified: stable/11/sys/compat/linuxkpi/common/include/asm/atomic.h
==============================================================================
--- stable/11/sys/compat/linuxkpi/common/include/asm/atomic.h	Thu Feb  1 07:52:06 2018	(r328652)
+++ stable/11/sys/compat/linuxkpi/common/include/asm/atomic.h	Thu Feb  1 13:01:44 2018	(r328653)
@@ -2,7 +2,7 @@
  * Copyright (c) 2010 Isilon Systems, Inc.
  * Copyright (c) 2010 iX Systems, Inc.
  * Copyright (c) 2010 Panasas, Inc.
- * Copyright (c) 2013-2016 Mellanox Technologies, Ltd.
+ * Copyright (c) 2013-2017 Mellanox Technologies, Ltd.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -28,10 +28,11 @@
  *
  * $FreeBSD$
  */
-#ifndef	_ASM_ATOMIC_H_
+
+#ifndef _ASM_ATOMIC_H_
 #define	_ASM_ATOMIC_H_
 
-#include <sys/cdefs.h>
+#include <linux/compiler.h>
 #include <sys/types.h>
 #include <machine/atomic.h>
 
@@ -71,6 +72,12 @@ atomic_sub_return(int i, atomic_t *v)
 static inline void
 atomic_set(atomic_t *v, int i)
 {
+	WRITE_ONCE(v->counter, i);
+}
+
+static inline void
+atomic_set_release(atomic_t *v, int i)
+{
 	atomic_store_rel_int(&v->counter, i);
 }
 
@@ -81,9 +88,9 @@ atomic_set_mask(unsigned int mask, atomic_t *v)
 }
 
 static inline int
-atomic_read(atomic_t *v)
+atomic_read(const atomic_t *v)
 {
-	return atomic_load_acq_int(&v->counter);
+	return READ_ONCE(v->counter);
 }
 
 static inline int
@@ -123,12 +130,13 @@ static inline int
 atomic_xchg(atomic_t *v, int i)
 {
 #if defined(__i386__) || defined(__amd64__) || \
-    defined(__arm__) || defined(__aarch64__)
+    defined(__arm__) || defined(__aarch64__) || \
+    defined(__powerpc__)
 	return (atomic_swap_int(&v->counter, i));
 #else
 	int ret;
 	for (;;) {
-		ret = atomic_load_acq_int(&v->counter);
+		ret = READ_ONCE(v->counter);
 		if (atomic_cmpset_int(&v->counter, ret, i))
 			break;
 	}
@@ -144,7 +152,7 @@ atomic_cmpxchg(atomic_t *v, int old, int new)
 	for (;;) {
 		if (atomic_cmpset_int(&v->counter, old, new))
 			break;
-		ret = atomic_load_acq_int(&v->counter);
+		ret = READ_ONCE(v->counter);
 		if (ret != old)
 			break;
 	}
@@ -152,31 +160,47 @@ atomic_cmpxchg(atomic_t *v, int old, int new)
 }
 
 #define	cmpxchg(ptr, old, new) ({				\
-	__typeof(*(ptr)) __ret = (old);				\
-	CTASSERT(sizeof(__ret) == 4 || sizeof(__ret) == 8);	\
-	for (;;) {						\
-		if (sizeof(__ret) == 4) {			\
-			if (atomic_cmpset_int((volatile int *)	\
-			    (ptr), (old), (new)))		\
-				break;				\
-			__ret = atomic_load_acq_int(		\
-			    (volatile int *)(ptr));		\
-			if (__ret != (old))			\
-				break;				\
-		} else {					\
-			if (atomic_cmpset_64(			\
-			    (volatile int64_t *)(ptr),		\
-			    (old), (new)))			\
-				break;				\
-			__ret = atomic_load_acq_64(		\
-			    (volatile int64_t *)(ptr));		\
-			if (__ret != (old))			\
-				break;				\
-		}						\
+	__typeof(*(ptr)) __ret;					\
+								\
+	CTASSERT(sizeof(__ret) == 1 || sizeof(__ret) == 2 ||	\
+	    sizeof(__ret) == 4 || sizeof(__ret) == 8);		\
+								\
+	__ret = (old);						\
+	switch (sizeof(__ret)) {				\
+	case 1:							\
+		while (!atomic_fcmpset_8((volatile int8_t *)(ptr), \
+		    (int8_t *)&__ret, (new)) && __ret == (old))	\
+			;					\
+		break;						\
+	case 2:							\
+		while (!atomic_fcmpset_16((volatile int16_t *)(ptr), \
+		    (int16_t *)&__ret, (new)) && __ret == (old)) \
+			;					\
+		break;						\
+	case 4:							\
+		while (!atomic_fcmpset_32((volatile int32_t *)(ptr), \
+		    (int32_t *)&__ret, (new)) && __ret == (old)) \
+			;					\
+		break;						\
+	case 8:							\
+		while (!atomic_fcmpset_64((volatile int64_t *)(ptr), \
+		    (int64_t *)&__ret, (new)) && __ret == (old)) \
+			;					\
+		break;						\
 	}							\
 	__ret;							\
 })
 
+#define	cmpxchg_relaxed(...)	cmpxchg(__VA_ARGS__)
+
+#define	xchg(ptr, v) ({						\
+	__typeof(*(ptr)) __ret;					\
+								\
+	__ret = *(ptr);						\
+	*(ptr) = v;						\
+	__ret;							\
+})
+
 #define	LINUX_ATOMIC_OP(op, c_op)				\
 static inline void atomic_##op(int i, atomic_t *v)		\
 {								\
@@ -187,8 +211,26 @@ static inline void atomic_##op(int i, atomic_t *v)		\
 		c = old;					\
 }
 
+#define	LINUX_ATOMIC_FETCH_OP(op, c_op)				\
+static inline int atomic_fetch_##op(int i, atomic_t *v)		\
+{								\
+	int c, old;						\
+								\
+	c = v->counter;						\
+	while ((old = atomic_cmpxchg(v, c, c c_op i)) != c)	\
+		c = old;					\
+								\
+	return (c);						\
+}
+
 LINUX_ATOMIC_OP(or, |)
 LINUX_ATOMIC_OP(and, &)
+LINUX_ATOMIC_OP(andnot, &~)
 LINUX_ATOMIC_OP(xor, ^)
+
+LINUX_ATOMIC_FETCH_OP(or, |)
+LINUX_ATOMIC_FETCH_OP(and, &)
+LINUX_ATOMIC_FETCH_OP(andnot, &~)
+LINUX_ATOMIC_FETCH_OP(xor, ^)
 
 #endif					/* _ASM_ATOMIC_H_ */

Modified: stable/11/sys/compat/linuxkpi/common/include/asm/atomic64.h
==============================================================================
--- stable/11/sys/compat/linuxkpi/common/include/asm/atomic64.h	Thu Feb  1 07:52:06 2018	(r328652)
+++ stable/11/sys/compat/linuxkpi/common/include/asm/atomic64.h	Thu Feb  1 13:01:44 2018	(r328653)
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2016 Mellanox Technologies, Ltd.
+ * Copyright (c) 2016-2017 Mellanox Technologies, Ltd.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -28,7 +28,7 @@
 #ifndef	_ASM_ATOMIC64_H_
 #define	_ASM_ATOMIC64_H_
 
-#include <sys/cdefs.h>
+#include <linux/compiler.h>
 #include <sys/types.h>
 #include <machine/atomic.h>
 
@@ -36,6 +36,8 @@ typedef struct {
 	volatile int64_t counter;
 } atomic64_t;
 
+#define	ATOMIC64_INIT(x)	{ .counter = (x) }
+
 /*------------------------------------------------------------------------*
  *	64-bit atomic operations
  *------------------------------------------------------------------------*/
@@ -72,7 +74,7 @@ atomic64_set(atomic64_t *v, int64_t i)
 static inline int64_t
 atomic64_read(atomic64_t *v)
 {
-	return atomic_load_acq_64(&v->counter);
+	return READ_ONCE(v->counter);
 }
 
 static inline int64_t
@@ -106,12 +108,13 @@ static inline int64_t
 atomic64_xchg(atomic64_t *v, int64_t i)
 {
 #if defined(__i386__) || defined(__amd64__) || \
-    defined(__arm__) || defined(__aarch64__)
+    defined(__arm__) || defined(__aarch64__) || \
+    defined(__powerpc64__)
 	return (atomic_swap_64(&v->counter, i));
 #else
 	int64_t ret;
 	for (;;) {
-		ret = atomic_load_acq_64(&v->counter);
+		ret = READ_ONCE(v->counter);
 		if (atomic_cmpset_64(&v->counter, ret, i))
 			break;
 	}
@@ -127,7 +130,7 @@ atomic64_cmpxchg(atomic64_t *v, int64_t old, int64_t n
 	for (;;) {
 		if (atomic_cmpset_64(&v->counter, old, new))
 			break;
-		ret = atomic_load_acq_64(&v->counter);
+		ret = READ_ONCE(v->counter);
 		if (ret != old)
 			break;
 	}

Added: stable/11/sys/compat/linuxkpi/common/include/asm/msr.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/11/sys/compat/linuxkpi/common/include/asm/msr.h	Thu Feb  1 13:01:44 2018	(r328653)
@@ -0,0 +1,36 @@
+/*-
+ * Copyright (c) 2017 Mark Johnston <markj at FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _ASM_MSR_H_
+#define	_ASM_MSR_H_
+
+#include <machine/cpufunc.h>
+
+#define	rdmsrl(msr, val)	((val) = rdmsr(msr))
+
+#endif /* _ASM_MSR_H_ */

Modified: stable/11/sys/compat/linuxkpi/common/include/asm/pgtable.h
==============================================================================
--- stable/11/sys/compat/linuxkpi/common/include/asm/pgtable.h	Thu Feb  1 07:52:06 2018	(r328652)
+++ stable/11/sys/compat/linuxkpi/common/include/asm/pgtable.h	Thu Feb  1 13:01:44 2018	(r328653)
@@ -33,4 +33,11 @@
 
 #include <linux/page.h>
 
+typedef unsigned long	pteval_t;
+typedef unsigned long	pmdval_t;
+typedef unsigned long	pudval_t;
+typedef unsigned long	pgdval_t;
+typedef unsigned long	pgprotval_t;
+typedef struct page *pgtable_t;
+
 #endif	/* _ASM_PGTABLE_H_ */

Added: stable/11/sys/compat/linuxkpi/common/include/asm/smp.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/11/sys/compat/linuxkpi/common/include/asm/smp.h	Thu Feb  1 13:01:44 2018	(r328653)
@@ -0,0 +1,48 @@
+/*-
+ * Copyright (c) 2017 Mark Johnston <markj at FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _ASM_SMP_H_
+#define	_ASM_SMP_H_
+
+#if defined(__i386__) || defined(__amd64__)
+
+#define	wbinvd_on_all_cpus()	linux_wbinvd_on_all_cpus()
+
+int	linux_wbinvd_on_all_cpus(void);
+
+#endif
+
+#define	get_cpu() ({			\
+	sched_pin();			\
+	PCPU_GET(cpuid);		\
+})
+
+#define	put_cpu()			\
+	sched_unpin()
+
+#endif /* _ASM_SMP_H_ */

Added: stable/11/sys/compat/linuxkpi/common/include/linux/atomic.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/11/sys/compat/linuxkpi/common/include/linux/atomic.h	Thu Feb  1 13:01:44 2018	(r328653)
@@ -0,0 +1,35 @@
+/*-
+ * Copyright (c) 2017 Mark Johnston <markj at FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _LINUX_ATOMIC_H_
+#define	_LINUX_ATOMIC_H_
+
+#include <asm/atomic.h>
+#include <asm/atomic64.h>
+
+#endif /* _LINUX_ATOMIC_H_ */

Added: stable/11/sys/compat/linuxkpi/common/include/linux/bitmap.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/11/sys/compat/linuxkpi/common/include/linux/bitmap.h	Thu Feb  1 13:01:44 2018	(r328653)
@@ -0,0 +1,279 @@
+/*
+ * Copyright (c) 2013-2017 Mellanox Technologies, Ltd.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice unmodified, this list of conditions, and the following
+ *    disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _LINUX_BITMAP_H_
+#define	_LINUX_BITMAP_H_
+
+#include <linux/bitops.h>
+
+static inline void
+bitmap_zero(unsigned long *addr, const unsigned int size)
+{
+	memset(addr, 0, BITS_TO_LONGS(size) * sizeof(long));
+}
+
+static inline void
+bitmap_fill(unsigned long *addr, const unsigned int size)
+{
+	const unsigned int tail = size & (BITS_PER_LONG - 1);
+
+	memset(addr, 0xff, BIT_WORD(size) * sizeof(long));
+
+	if (tail)
+		addr[BIT_WORD(size)] = BITMAP_LAST_WORD_MASK(tail);
+}
+
+static inline int
+bitmap_full(unsigned long *addr, const unsigned int size)
+{
+	const unsigned int end = BIT_WORD(size);
+	const unsigned int tail = size & (BITS_PER_LONG - 1);
+	unsigned int i;
+
+	for (i = 0; i != end; i++) {
+		if (addr[i] != ~0UL)
+			return (0);
+	}
+
+	if (tail) {
+		const unsigned long mask = BITMAP_LAST_WORD_MASK(tail);
+
+		if ((addr[end] & mask) != mask)
+			return (0);
+	}
+	return (1);
+}
+
+static inline int
+bitmap_empty(unsigned long *addr, const unsigned int size)
+{
+	const unsigned int end = BIT_WORD(size);
+	const unsigned int tail = size & (BITS_PER_LONG - 1);
+	unsigned int i;
+
+	for (i = 0; i != end; i++) {
+		if (addr[i] != 0)
+			return (0);
+	}
+
+	if (tail) {
+		const unsigned long mask = BITMAP_LAST_WORD_MASK(tail);
+
+		if ((addr[end] & mask) != 0)
+			return (0);
+	}
+	return (1);
+}
+
+static inline void
+bitmap_set(unsigned long *map, unsigned int start, int nr)
+{
+	const unsigned int size = start + nr;
+	int bits_to_set = BITS_PER_LONG - (start % BITS_PER_LONG);
+	unsigned long mask_to_set = BITMAP_FIRST_WORD_MASK(start);
+
+	map += BIT_WORD(start);
+
+	while (nr - bits_to_set >= 0) {
+		*map |= mask_to_set;
+		nr -= bits_to_set;
+		bits_to_set = BITS_PER_LONG;
+		mask_to_set = ~0UL;
+		map++;
+	}
+
+	if (nr) {
+		mask_to_set &= BITMAP_LAST_WORD_MASK(size);
+		*map |= mask_to_set;
+	}
+}
+
+static inline void
+bitmap_clear(unsigned long *map, unsigned int start, int nr)
+{
+	const unsigned int size = start + nr;
+	int bits_to_clear = BITS_PER_LONG - (start % BITS_PER_LONG);
+	unsigned long mask_to_clear = BITMAP_FIRST_WORD_MASK(start);
+
+	map += BIT_WORD(start);
+
+	while (nr - bits_to_clear >= 0) {
+		*map &= ~mask_to_clear;
+		nr -= bits_to_clear;
+		bits_to_clear = BITS_PER_LONG;
+		mask_to_clear = ~0UL;
+		map++;
+	}
+
+	if (nr) {
+		mask_to_clear &= BITMAP_LAST_WORD_MASK(size);
+		*map &= ~mask_to_clear;
+	}
+}
+
+static inline unsigned int
+bitmap_find_next_zero_area_off(const unsigned long *map,
+    const unsigned int size, unsigned int start,
+    unsigned int nr, unsigned int align_mask,
+    unsigned int align_offset)
+{
+	unsigned int index;
+	unsigned int end;
+	unsigned int i;
+
+retry:
+	index = find_next_zero_bit(map, size, start);
+
+	index = (((index + align_offset) + align_mask) & ~align_mask) - align_offset;
+
+	end = index + nr;
+	if (end > size)
+		return (end);
+
+	i = find_next_bit(map, end, index);
+	if (i < end) {
+		start = i + 1;
+		goto retry;
+	}
+	return (index);
+}
+
+static inline unsigned int
+bitmap_find_next_zero_area(const unsigned long *map,
+    const unsigned int size, unsigned int start,
+    unsigned int nr, unsigned int align_mask)
+{
+	return (bitmap_find_next_zero_area_off(map, size,
+	    start, nr, align_mask, 0));
+}
+
+static inline int
+bitmap_find_free_region(unsigned long *bitmap, int bits, int order)
+{
+	int pos;
+	int end;
+
+	for (pos = 0; (end = pos + (1 << order)) <= bits; pos = end) {
+		if (!linux_reg_op(bitmap, pos, order, REG_OP_ISFREE))
+			continue;
+		linux_reg_op(bitmap, pos, order, REG_OP_ALLOC);
+		return (pos);
+	}
+	return (-ENOMEM);
+}
+
+static inline int
+bitmap_allocate_region(unsigned long *bitmap, int pos, int order)
+{
+	if (!linux_reg_op(bitmap, pos, order, REG_OP_ISFREE))
+		return (-EBUSY);
+	linux_reg_op(bitmap, pos, order, REG_OP_ALLOC);
+	return (0);
+}
+
+static inline void
+bitmap_release_region(unsigned long *bitmap, int pos, int order)
+{
+	linux_reg_op(bitmap, pos, order, REG_OP_RELEASE);
+}
+
+static inline unsigned int
+bitmap_weight(unsigned long *addr, const unsigned int size)
+{
+	const unsigned int end = BIT_WORD(size);
+	const unsigned int tail = size & (BITS_PER_LONG - 1);
+	unsigned int retval = 0;
+	unsigned int i;
+
+	for (i = 0; i != end; i++)
+		retval += hweight_long(addr[i]);
+
+	if (tail) {
+		const unsigned long mask = BITMAP_LAST_WORD_MASK(tail);
+
+		retval += hweight_long(addr[end] & mask);
+	}
+	return (retval);
+}
+
+static inline int
+bitmap_equal(const unsigned long *pa,
+    const unsigned long *pb, unsigned size)
+{
+	const unsigned int end = BIT_WORD(size);
+	const unsigned int tail = size & (BITS_PER_LONG - 1);
+	unsigned int i;
+
+	for (i = 0; i != end; i++) {
+		if (pa[i] != pb[i])
+			return (0);
+	}
+
+	if (tail) {
+		const unsigned long mask = BITMAP_LAST_WORD_MASK(tail);
+
+		if ((pa[end] ^ pb[end]) & mask)
+			return (0);
+	}
+	return (1);
+}
+
+static inline void
+bitmap_or(unsigned long *dst, const unsigned long *src1,
+    const unsigned long *src2, const unsigned int size)
+{
+	const unsigned int end = BITS_TO_LONGS(size);
+	unsigned int i;
+
+	for (i = 0; i != end; i++)
+		dst[i] = src1[i] | src2[i];
+}
+
+static inline void
+bitmap_and(unsigned long *dst, const unsigned long *src1,
+    const unsigned long *src2, const unsigned int size)
+{
+	const unsigned int end = BITS_TO_LONGS(size);
+	unsigned int i;
+
+	for (i = 0; i != end; i++)
+		dst[i] = src1[i] & src2[i];
+}
+
+static inline void
+bitmap_xor(unsigned long *dst, const unsigned long *src1,
+    const unsigned long *src2, const unsigned int size)
+{
+	const unsigned int end = BITS_TO_LONGS(size);
+	unsigned int i;
+
+	for (i = 0; i != end; i++)
+		dst[i] = src1[i] ^ src2[i];
+}
+
+#endif					/* _LINUX_BITMAP_H_ */

Modified: stable/11/sys/compat/linuxkpi/common/include/linux/bitops.h
==============================================================================
--- stable/11/sys/compat/linuxkpi/common/include/linux/bitops.h	Thu Feb  1 07:52:06 2018	(r328652)
+++ stable/11/sys/compat/linuxkpi/common/include/linux/bitops.h	Thu Feb  1 13:01:44 2018	(r328653)
@@ -2,7 +2,7 @@
  * Copyright (c) 2010 Isilon Systems, Inc.
  * Copyright (c) 2010 iX Systems, Inc.
  * Copyright (c) 2010 Panasas, Inc.
- * Copyright (c) 2013-2015 Mellanox Technologies, Ltd.
+ * Copyright (c) 2013-2017 Mellanox Technologies, Ltd.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -31,16 +31,20 @@
 #ifndef	_LINUX_BITOPS_H_
 #define	_LINUX_BITOPS_H_
 
+#include <sys/param.h>
 #include <sys/types.h>
 #include <sys/systm.h>
 #include <sys/errno.h>
+#include <sys/libkern.h>
 
 #define	BIT(nr)			(1UL << (nr))
+#define	BIT_ULL(nr)		(1ULL << (nr))
 #ifdef __LP64__
 #define	BITS_PER_LONG		64
 #else
 #define	BITS_PER_LONG		32
 #endif
+
 #define	BITMAP_FIRST_WORD_MASK(start)	(~0UL << ((start) % BITS_PER_LONG))
 #define	BITMAP_LAST_WORD_MASK(n)	(~0UL >> (BITS_PER_LONG - (n)))
 #define	BITS_TO_LONGS(n)	howmany((n), BITS_PER_LONG)
@@ -49,6 +53,12 @@
 #define	GENMASK(h, l)		(((~0UL) >> (BITS_PER_LONG - (h) - 1)) & ((~0UL) << (l)))
 #define BITS_PER_BYTE           8
 
+#define	hweight8(x)	bitcount((uint8_t)(x))
+#define	hweight16(x)	bitcount16(x)
+#define	hweight32(x)	bitcount32(x)
+#define	hweight64(x)	bitcount64(x)
+#define	hweight_long(x)	bitcountl(x)
+
 static inline int
 __ffs(int mask)
 {
@@ -73,10 +83,15 @@ __flsl(long mask)
 	return (flsl(mask) - 1);
 }
 
+static inline int
+fls64(uint64_t mask)
+{
+	return (flsll(mask));
+}
+
 static inline uint32_t
 ror32(uint32_t word, unsigned int shift)
 {
-
 	return ((word >> shift) | (word << (32 - shift)));
 }
 
@@ -241,70 +256,6 @@ find_next_zero_bit(const unsigned long *addr, unsigned
 	return (bit);
 }
 
-static inline void
-bitmap_zero(unsigned long *addr, int size)
-{
-	int len;
-
-	len = BITS_TO_LONGS(size) * sizeof(long);
-	memset(addr, 0, len);
-}
-
-static inline void
-bitmap_fill(unsigned long *addr, int size)
-{
-	int tail;
-	int len;
-
-	len = (size / BITS_PER_LONG) * sizeof(long);
-	memset(addr, 0xff, len);
-	tail = size & (BITS_PER_LONG - 1);
-	if (tail) 
-		addr[size / BITS_PER_LONG] = BITMAP_LAST_WORD_MASK(tail);
-}
-
-static inline int
-bitmap_full(unsigned long *addr, int size)
-{
-	unsigned long mask;
-	int tail;
-	int len;
-	int i;
-
-	len = size / BITS_PER_LONG;
-	for (i = 0; i < len; i++)
-		if (addr[i] != ~0UL)
-			return (0);
-	tail = size & (BITS_PER_LONG - 1);
-	if (tail) {
-		mask = BITMAP_LAST_WORD_MASK(tail);
-		if ((addr[i] & mask) != mask)
-			return (0);
-	}
-	return (1);
-}
-
-static inline int
-bitmap_empty(unsigned long *addr, int size)
-{
-	unsigned long mask;
-	int tail;
-	int len;
-	int i;
-
-	len = size / BITS_PER_LONG;
-	for (i = 0; i < len; i++)
-		if (addr[i] != 0)
-			return (0);
-	tail = size & (BITS_PER_LONG - 1);
-	if (tail) {
-		mask = BITMAP_LAST_WORD_MASK(tail);
-		if ((addr[i] & mask) != 0)
-			return (0);
-	}
-	return (1);
-}
-
 #define	__set_bit(i, a)							\
     atomic_set_long(&((volatile unsigned long *)(a))[BIT_WORD(i)], BIT_MASK(i))
 
@@ -318,8 +269,7 @@ bitmap_empty(unsigned long *addr, int size)
     atomic_clear_long(&((volatile unsigned long *)(a))[BIT_WORD(i)], BIT_MASK(i))
 
 #define	test_bit(i, a)							\
-    !!(atomic_load_acq_long(&((volatile unsigned long *)(a))[BIT_WORD(i)]) &	\
-    BIT_MASK(i))
+    !!(READ_ONCE(((volatile unsigned long *)(a))[BIT_WORD(i)]) & BIT_MASK(i))
 
 static inline int
 test_and_clear_bit(long bit, volatile unsigned long *var)
@@ -337,6 +287,21 @@ test_and_clear_bit(long bit, volatile unsigned long *v
 }
 
 static inline int
+__test_and_clear_bit(long bit, volatile unsigned long *var)
+{
+	long val;
+
+	var += BIT_WORD(bit);
+	bit %= BITS_PER_LONG;
+	bit = (1UL << bit);
+
+	val = *var;
+	*var &= ~bit;
+
+	return !!(val & bit);
+}
+
+static inline int
 test_and_set_bit(long bit, volatile unsigned long *var)
 {
 	long val;
@@ -351,46 +316,19 @@ test_and_set_bit(long bit, volatile unsigned long *var
 	return !!(val & bit);
 }
 
-static inline void
-bitmap_set(unsigned long *map, int start, int nr)
+static inline int
+__test_and_set_bit(long bit, volatile unsigned long *var)
 {
-	unsigned long *p = map + BIT_WORD(start);
-	const int size = start + nr;
-	int bits_to_set = BITS_PER_LONG - (start % BITS_PER_LONG);
-	unsigned long mask_to_set = BITMAP_FIRST_WORD_MASK(start);
+	long val;
 
-	while (nr - bits_to_set >= 0) {
-		*p |= mask_to_set;
-		nr -= bits_to_set;
-		bits_to_set = BITS_PER_LONG;
-		mask_to_set = ~0UL;
-		p++;
-	}
-	if (nr) {
-		mask_to_set &= BITMAP_LAST_WORD_MASK(size);
-		*p |= mask_to_set;
-	}
-}
+	var += BIT_WORD(bit);
+	bit %= BITS_PER_LONG;
+	bit = (1UL << bit);
 
-static inline void
-bitmap_clear(unsigned long *map, int start, int nr)
-{
-	unsigned long *p = map + BIT_WORD(start);
-	const int size = start + nr;
-	int bits_to_clear = BITS_PER_LONG - (start % BITS_PER_LONG);
-	unsigned long mask_to_clear = BITMAP_FIRST_WORD_MASK(start);
+	val = *var;
+	*var |= bit;
 
-	while (nr - bits_to_clear >= 0) {
-		*p &= ~mask_to_clear;
-		nr -= bits_to_clear;
-		bits_to_clear = BITS_PER_LONG;
-		mask_to_clear = ~0UL;
-		p++;
-	}
-	if (nr) {
-		mask_to_clear &= BITMAP_LAST_WORD_MASK(size);
-		*p &= ~mask_to_clear;
-	}
+	return !!(val & bit);
 }
 
 enum {
@@ -400,7 +338,7 @@ enum {
 };
 
 static inline int
-__reg_op(unsigned long *bitmap, int pos, int order, int reg_op)
+linux_reg_op(unsigned long *bitmap, int pos, int order, int reg_op)
 {
         int nbits_reg;
         int index;
@@ -444,70 +382,18 @@ done:
         return ret;
 }
 
-static inline int 
-bitmap_find_free_region(unsigned long *bitmap, int bits, int order)
-{
-        int pos;
-        int end;
-
-        for (pos = 0 ; (end = pos + (1 << order)) <= bits; pos = end) {
-                if (!__reg_op(bitmap, pos, order, REG_OP_ISFREE))
-                        continue;
-                __reg_op(bitmap, pos, order, REG_OP_ALLOC);
-                return pos;
-        }
-        return -ENOMEM;
-}
-
-static inline int
-bitmap_allocate_region(unsigned long *bitmap, int pos, int order)
-{
-        if (!__reg_op(bitmap, pos, order, REG_OP_ISFREE))
-                return -EBUSY;
-        __reg_op(bitmap, pos, order, REG_OP_ALLOC);
-        return 0;
-}
-
-static inline void 
-bitmap_release_region(unsigned long *bitmap, int pos, int order)
-{
-        __reg_op(bitmap, pos, order, REG_OP_RELEASE);
-}
-
 #define for_each_set_bit(bit, addr, size) \
 	for ((bit) = find_first_bit((addr), (size));		\
 	     (bit) < (size);					\
 	     (bit) = find_next_bit((addr), (size), (bit) + 1))
 
-static inline unsigned
-bitmap_weight(unsigned long *bitmap, unsigned nbits)
-{
-	unsigned bit;
-	unsigned retval = 0;
 
-	for_each_set_bit(bit, bitmap, nbits)
-		retval++;
-	return (retval);
-}
-
-static inline int
-bitmap_equal(const unsigned long *pa,
-    const unsigned long *pb, unsigned bits)
+static inline uint64_t
+sign_extend64(uint64_t value, int index)
 {
-	unsigned x;
-	unsigned y = bits / BITS_PER_LONG;
- 
-	for (x = 0; x != y; x++) {
-		if (pa[x] != pb[x])
-			return (0);
-	}
+	uint8_t shift = 63 - index;
 

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***


More information about the svn-src-all mailing list