Commit Graph

184 Commits

Author SHA1 Message Date
Olivier Houchard
7e8cd4e1af Import CK as of commit 6b141c0bdd21ce8b3e14147af8f87f22b20ecf32
This brings us changes we needed in ck_epoch.
2017-04-09 21:02:05 +00:00
Hans Petter Selasky
76fe8c9330 Fix compilation of LinuxKPI for PowerPC.
Found by:		emaste @
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-04-09 14:31:41 +00:00
Hans Petter Selasky
22cbd6ef2e Create the LinuxKPI current task structure on the fly if it doesn't
exist when the current macro is used.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-04-07 14:43:28 +00:00
Hans Petter Selasky
99e690772a The __stringify() macro in the LinuxKPI should expand any macros
before stringifying.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-04-07 12:27:49 +00:00
Hans Petter Selasky
c9dd0b48c9 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)

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-04-06 13:30:31 +00:00
Hans Petter Selasky
480e2fd3d5 Define VM_READ, VM_WRITE and VM_EXEC in the LinuxKPI.
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-04-06 10:52:52 +00:00
Hans Petter Selasky
fc51649e31 Implement need_resched() in the LinuxKPI.
Obtained from:		kmacy @
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-04-06 10:29:54 +00:00
Hans Petter Selasky
8402f058ad 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.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-04-06 10:26:03 +00:00
Hans Petter Selasky
1ea4c85781 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 @
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-04-06 09:34:54 +00:00
Hans Petter Selasky
e54b103e70 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.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-04-06 09:07:01 +00:00
Hans Petter Selasky
6e3e654490 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.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-04-05 12:48:24 +00:00
Hans Petter Selasky
0bd68b774d Implement down_write_killable() in the LinuxKPI.
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-04-05 12:10:02 +00:00
Hans Petter Selasky
0a475c59a9 Implement vmalloc_32() in the LinuxKPI.
Obtained from:		kmacy @
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-27 17:18:04 +00:00
Hans Petter Selasky
0791730913 Add more platforms supporting the direct map feature in the LinuxKPI.
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-27 17:09:11 +00:00
Hans Petter Selasky
8186b52744 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 @
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-27 17:04:11 +00:00
Hans Petter Selasky
8f7eee5a63 Use ppsratecheck() for ratelimiting in the LinuxKPI.
Suggested by:		cem @
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-23 16:23:55 +00:00
Hans Petter Selasky
d2f312e0e7 Add proper error checking for the string to number conversion
functions in the LinuxKPI.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-23 16:01:51 +00:00
Hans Petter Selasky
8293738e64 Function macros are preferred in the LinuxKPI.
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-23 13:28:16 +00:00
Hans Petter Selasky
e9db3df254 Add support for ratelimited printouts in the LinuxKPI.
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-23 10:48:10 +00:00
Mark Johnston
e5fe3ae2b4 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 after:	2 weeks
2017-03-22 17:33:57 +00:00
Hans Petter Selasky
82d0140707 Add full VNET support to the inet_get_local_port_range() function in
the LinuxKPI.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-22 15:46:31 +00:00
Hans Petter Selasky
303bd80ad5 Add support for more IPv4 and IPv6 related macros in the LinuxKPI.
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-22 15:44:00 +00:00
Hans Petter Selasky
a0699ebf77 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 @
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-17 15:40:24 +00:00
Hans Petter Selasky
05d4f501dc 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 @
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-17 10:30:06 +00:00
Hans Petter Selasky
0a2f4606bb Add comment describing the use of pagefault_disable() and
pagefault_enable() in the LinuxKPI.

Suggested by:  		rpokala@
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-17 08:02:46 +00:00
Hans Petter Selasky
3803a97f84 Use __LP64__ to detect presence of suword64() to fix linking and
loading of the LinuxKPI on 32-bit platforms.

Reported by:		lwhsu @
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-16 20:39:31 +00:00
Hans Petter Selasky
810ea5b270 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 @
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-16 16:53:22 +00:00
Hans Petter Selasky
0e05589b39 Implement more userspace memory access functions in the LinuxKPI.
Obtained from:		kmacy @
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-16 16:49:27 +00:00
Hans Petter Selasky
b8a8ed7c96 Define some more LinuxKPI task related macros.
Obtained from:		kmacy @
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-16 12:33:34 +00:00
Hans Petter Selasky
8300fb13dd Add helper function similar to ip_dev_find() to the LinuxKPI to lookup
a network device by its IPv6 address in the given VNET.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-16 10:02:45 +00:00
Hans Petter Selasky
404027276b Add basic support for VIMAGE to the LinuxKPI and ibcore.
Support is implemented by mapping Linux's "struct net" into FreeBSD's
"struct vnet". Currently only vnet0 is supported by ibcore.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-16 09:59:35 +00:00
Hans Petter Selasky
5f50a414ba Set "current" pointer for LinuxKPI interrupts and timer callbacks.
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-14 14:02:47 +00:00
Hans Petter Selasky
f73286645f Fix implementation of the DECLARE_WORK() macro in the LinuxKPI to fully
initialize the declared work structure and not only the function callback
pointer.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-09 18:37:17 +00:00
Hans Petter Selasky
9760ac0a3e 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 .

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-09 18:33:40 +00:00
Hans Petter Selasky
4f688d19fb 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.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-09 17:01:00 +00:00
Hans Petter Selasky
c23b6e238f 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>
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-09 09:17:43 +00:00
Hans Petter Selasky
43ee32f7df 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 @
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-08 21:28:53 +00:00
Hans Petter Selasky
14c5024db8 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().

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-08 11:09:27 +00:00
Hans Petter Selasky
0e3bbe9197 Implement eth_zero_addr() in the LinuxKPI.
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-08 09:53:20 +00:00
Hans Petter Selasky
a767c1883d Add support for constant pointer constructs to READ_ONCE() in the
LinuxKPI. When the type of the argument is constant the temporary
variable cannot be assigned after the barrier. Instead assign the
temporary variable by initialization.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-07 20:24:34 +00:00
Hans Petter Selasky
249a42207b Implement time_is_after_eq_jiffies() function in the LinuxKPI.
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-07 15:37:51 +00:00
Hans Petter Selasky
661a318c83 Fix implementation of the DECLARE_RWSEM() macro in the LinuxKPI.
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-07 15:34:49 +00:00
Hans Petter Selasky
dc0d19dd4a Make sure jiffies value is cast to an integer in the LinuxKPI before
doing millisecond conversion. Under FreeBSD jiffies are 32-bit.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-07 15:33:38 +00:00
Hans Petter Selasky
4cd34a41c9 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.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-07 13:51:14 +00:00
Hans Petter Selasky
ca2ad6bd77 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.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-07 12:09:14 +00:00
Hans Petter Selasky
def277d3ef Implement add_timer_on() function in the LinuxKPI.
Obtained from:		kmacy @
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-06 14:56:57 +00:00
Hans Petter Selasky
19bf8ef562 Implement DECLARE_RWSEM() macro in the LinuxKPI to initialize a
Read-Write semaphore during module init time.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-06 12:22:05 +00:00
Hans Petter Selasky
684bcfec89 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.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-06 12:20:56 +00:00
Hans Petter Selasky
e0db0ddb39 Remove duplicate prototype in the LinuxKPI to fix compilation warning.
Reported by:		emaste @
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-04 20:06:47 +00:00
Hans Petter Selasky
1f827dab9e 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.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-03-03 16:28:03 +00:00