Commit Graph

155 Commits

Author SHA1 Message Date
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
Hans Petter Selasky
3cfeca84b4 Implement more bit operation functions in the LinuxKPI.
Some minor whitespace nits while at it.

Obtained from:		kmacy @
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-02-27 14:38:17 +00:00
Hans Petter Selasky
522f4b2c75 Define __sum16 type in the LinuxKPI.
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-02-27 13:59:02 +00:00
Hans Petter Selasky
0f32531a56 Implement more string functions in the LinuxKPI.
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-02-24 17:36:55 +00:00
Hans Petter Selasky
5a5a8c8a17 Prototype device structure to ensure LinuxKPI header file can be
included standalone.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-02-24 17:03:14 +00:00
Hans Petter Selasky
959d6165a2 Implement srcu_dereference() macro in the LinuxKPI.
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-02-24 14:40:15 +00:00
Hans Petter Selasky
797046eebb Implement BIT_ULL() macro in the LinuxKPI.
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-02-24 14:23:46 +00:00
Hans Petter Selasky
cffaf933d7 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.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-02-23 09:53:54 +00:00
Hans Petter Selasky
72ebbe00b3 Convert magic values into macros in the LinuxKPI scatterlist
implementation.

Suggested by:		cem @
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-02-22 20:24:09 +00:00
Hans Petter Selasky
1cdefd084d 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 @
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-02-22 19:39:54 +00:00
Hans Petter Selasky
8306998f5b 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 @
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-02-22 19:31:02 +00:00
Hans Petter Selasky
1a01b4e566 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 @
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-02-21 18:04:21 +00:00
Hans Petter Selasky
e560eab72c 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().

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-02-21 14:22:14 +00:00
Hans Petter Selasky
ef23481a79 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.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-02-21 13:23:53 +00:00
Hans Petter Selasky
1e3db1de0c 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.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-02-21 12:43:02 +00:00
Hans Petter Selasky
269d8c86e9 Implement GFP_DMA32 flag in the LinuxKPI.
Define all FreeBSD native GFP bits as GFP_NATIVE_MASK.

Obtained from:		kmacy @
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-02-17 13:31:11 +00:00
Hans Petter Selasky
ddad2785bc Allow container_of() to be used with constant data pointers.
Obtained from:		kmacy @
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-02-16 14:13:36 +00:00
Hans Petter Selasky
622f2291e8 Implement more LinuxKPI atomic functions and macros.
Obtained from:		kmacy @
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-02-16 12:56:10 +00:00
Hans Petter Selasky
28a04a26b2 Allow passing a constant atomic_t to atomic_read().
Obtained from:		kmacy @
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-02-16 12:20:57 +00:00
Hans Petter Selasky
13459eb4a3 Whitespace fix.
Obtained from:		kmacy @
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-02-16 12:08:52 +00:00
Baptiste Daroussin
b4b4b5304b Revert crap accidentally committed 2017-01-28 16:31:23 +00:00
Baptiste Daroussin
814aaaa7da Revert r312923 a better approach will be taken later 2017-01-28 16:30:14 +00:00
Mateusz Guzik
21b737495b Introduce __read_mostly and __exclusive_cache_line macros.
The intended use is to annotate frequently used globals which either rarely
change (and thus can be grouped in the same cacheline) or are an atomic counter
(which means it may benefit from being the only variable in the cacheline).

Linker script support is provided only for amd64. Architectures without it risk
having other variables put in, i.e. as if they were not annotated. This is
harmless from correctness point of view.

Reviewed by:	bde (previous version)
MFC after:	1 month
2017-01-27 14:53:09 +00:00
Hans Petter Selasky
a11bac7379 Implement more list header file functions.
Add definition guard for the list_head structure.

Obtained from:	kmacy @
MFC after:	1 week
Sponsored by:	Mellanox Technologies
2016-12-26 10:41:51 +00:00
Hans Petter Selasky
70a3cc597a Fix LINT build.
Found by:	mmel @
MFC after:	1 week
Sponsored by:	Mellanox Technologies
2016-12-26 10:03:33 +00:00
Hans Petter Selasky
1125dbc049 Implement register and unregister chrdev in the LinuxKPI.
Obtained from:	kmacy @
MFC after:	1 week
Sponsored by:	Mellanox Technologies
2016-12-26 01:18:07 +00:00
Hans Petter Selasky
a1410999f4 Use correct integer type when computing the maximum physical address
for kmem_alloc_contig().

Obtained from:	kmacy @
MFC after:	1 week
Sponsored by:	Mellanox Technologies
2016-12-25 21:41:40 +00:00
Hans Petter Selasky
03adb29e0d Improve LinuxKPI device support. Only delete own BSD devices and not
the ones obtained through devclass_get_device(). Some minor code
cleanups while at it.

Obtained from:	kmacy @
MFC after:	1 week
Sponsored by:	Mellanox Technologies
2016-12-25 19:49:09 +00:00
Conrad Meyer
2f02a9e15a 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
2016-12-13 19:58:21 +00:00
Ed Schouten
d6d7df8aa0 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.
2016-12-13 07:58:30 +00:00