Commit Graph

192 Commits

Author SHA1 Message Date
Mark Johnston
c12488bbe0 Add on_each_cpu() and wbinvd_on_all_cpus().
Reviewed by:	hselasky
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D10550
2017-05-01 16:32:28 +00:00
Hans Petter Selasky
a8c348db51 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().

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-04-27 14:29:21 +00:00
Mark Johnston
b602c283b3 Drop Giant before sleeping in linux_wait_for_{timeout_,}common().
Reported and tested by:	Pete Wright <pete@nomadlogic.org>
Reviewed by:	hselasky (previous version)
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D10414
2017-04-19 16:12:02 +00:00
Hans Petter Selasky
a1be2ead3a Use __typeof() instead of typeof() in some RCU related macros in the LinuxKPI.
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-04-19 13:04:34 +00:00
Hans Petter Selasky
f3de9af633 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().

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-04-19 13:03:29 +00:00
Hans Petter Selasky
7a742c41cf 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.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-04-19 11:38:07 +00:00
Gleb Smirnoff
9ed01c32e0 All these files need sys/vmmeter.h, but now they got it implicitly
included via sys/pcpu.h.
2017-04-17 17:07:00 +00:00
Gleb Smirnoff
6286dc78d4 Remove unneeded include of vm_phys.h. 2017-04-17 16:51:04 +00:00
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