Commit Graph

248 Commits

Author SHA1 Message Date
Mark Johnston
70bb2cdb04 Add some functions to math64.h in the LinuxKPI, and fix nearby style.
Reviewed by:	hselasky
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D11535
2017-07-09 23:14:51 +00:00
Mark Johnston
7a2553d9d7 Add a few functions to ktime.h in the LinuxKPI, and fix nearby style.
Reviewed by:	hselasky
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D11534
2017-07-09 23:13:08 +00:00
Mark Johnston
abf5c031bb Free existing per-thread task structs when unloading linuxkpi.ko.
They are otherwise leaked.

Reported and tested by:	ae
MFC after:		1 week
2017-07-09 22:57:00 +00:00
Mark Johnston
dac6b88a20 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 after:	1 week
2017-07-08 20:11:06 +00:00
Mark Johnston
e51dd47b08 Fix the definitions of pgprot_{noncached,writecombine} after r316562.
MFC after:	1 week
2017-07-08 19:22:29 +00:00
Mark Johnston
aa2b6b4957 Add device_is_registered() to the LinuxKPI.
MFC after:	1 week
2017-07-08 18:53:02 +00:00
Mark Johnston
8cd823ecf7 Add TASK_COMM_LEN to the LinuxKPI.
MFC after:	1 week
2017-07-08 18:52:29 +00:00
Hans Petter Selasky
611572285a 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 @
MFC after:	1 week
Sponsored by:	Mellanox Technologies
2017-07-07 13:44:14 +00:00
Hans Petter Selasky
ea16525413 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()".

MFC after:	1 week
Sponsored by:	Mellanox Technologies
2017-07-07 13:15:00 +00:00
Mark Johnston
d34188a0e1 Invoke suspend/resume methods from the driver pmops if available.
Obtained from:	kmacy (original version)
MFC after:	1 week
2017-07-04 18:44:14 +00:00
Mark Johnston
88156ba581 Add some auxiliary types for device driver support.
MFC after:	1 week
2017-07-04 01:23:36 +00:00
Mark Johnston
6373e95eb6 Add a field for the class code to struct pci_driver.
Fill out some previously uninitialized fields as well.

MFC after:	1 week
2017-07-04 01:05:20 +00:00
Mark Johnston
ecf29cf148 Add some PCI class definitions.
MFC after:	1 week
2017-07-04 00:48:50 +00:00
Mark Johnston
b38dc0a16d Rename the "driver" field to "bsddriver" to avoid a name collision.
MFC after:	1 week
2017-07-04 00:30:48 +00:00
Mark Johnston
0a930cf078 Hold the PCI device list lock when removing an element.
MFC after:	1 week
2017-07-04 00:02:06 +00:00
Mark Johnston
4600d349be 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
2017-07-03 02:01:16 +00:00
Mark Johnston
9ea3e14182 Implement parts of the hrtimer API in the LinuxKPI.
Reviewed by:	hselasky
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D11359
2017-06-26 16:28:46 +00:00
Mark Johnston
ee7c3198cd Add u64_to_user_ptr() to the LinuxKPI.
MFC after:	1 week
2017-06-25 19:30:20 +00:00
Mark Johnston
1fde37964d Add ns_to_ktime() to the LinuxKPI.
MFC after:	1 week
2017-06-25 19:28:01 +00:00
Mark Johnston
934277c59c Add a couple of macros to lockdep.h in the LinuxKPI.
MFC after:	1 week
2017-06-25 19:23:14 +00:00
Mark Johnston
0bfde0a7c7 Add the thaw_early method to struct dev_pm_ops in the LinuxKPI.
MFC after:	1 week
2017-06-25 19:21:59 +00:00
Mark Johnston
4eb1bcfc62 Add noop_lseek() to the LinuxKPI.
MFC after:	1 week
2017-06-25 19:20:12 +00:00
Mark Johnston
c73cdca2c4 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
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D11286
2017-06-21 18:20:17 +00:00
Mark Johnston
47d8a7d4d1 Add missing lock destructor invocations to the LinuxKPI unload handler.
MFC after:	1 week
2017-06-21 18:17:32 +00:00
Mark Johnston
9b6197df69 Include kmod.h from the LinuxKPI's module.h.
MFC after:	1 week
2017-06-21 18:15:47 +00:00
Mark Johnston
33baed9452 Add a lockdep macro to the LinuxKPI.
Also fix some nearby style issues.

MFC after:	1 week
2017-06-21 18:08:36 +00:00
Hans Petter Selasky
cde3f930bc 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.

MFC after:	1 week
Sponsored by:	Mellanox Technologies
2017-06-21 14:38:52 +00:00
Mark Johnston
8504aa9852 Add kthread parking support to the LinuxKPI.
Submitted by:	kmacy (original version)
Reviewed by:	hselasky
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D11264
2017-06-18 19:22:05 +00:00
Mark Johnston
4eb18346d1 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
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D11249
2017-06-18 16:43:57 +00:00
Mark Johnston
8239734079 Remove prototypes for unimplemented LinuxKPI functions.
MFC after:	1 week
2017-06-17 22:52:23 +00:00
Mark Johnston
f67b5de754 Implement pci_disable_device() in the LinuxKPI.
Submitted by:	kmacy
MFC after:	2 weeks
2017-06-09 19:57:27 +00:00
Mark Johnston
465659643b 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
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D10986
2017-06-09 19:41:12 +00:00
Justin Hibbits
864092bcaa 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
2017-06-08 02:44:34 +00:00
Justin Hibbits
287e7a861a 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
2017-06-07 18:08:11 +00:00
Hans Petter Selasky
25b3ef2c99 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.

MFC after:	1 week
Sponsored by:	Mellanox Technologies
2017-06-06 10:12:58 +00:00
Hans Petter Selasky
67e984c8f2 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.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-06-02 16:52:18 +00:00
Hans Petter Selasky
639af71ab1 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.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-06-02 16:30:40 +00:00
Hans Petter Selasky
8600ba1aa9 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.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-06-01 16:49:48 +00:00
Hans Petter Selasky
328c75d621 Translate the ERESTARTSYS error code into ERESTART in the LinuxKPI
ioctl(), read() and write() system call handlers. This error code is
internal to the kernel and should not be seen by user-space programs
according to Linux.

Submitted by:		Yanko Yankulov <yanko.yankulov@gmail.com>
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-06-01 09:53:55 +00:00
Hans Petter Selasky
a6b28ee02a 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.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-06-01 09:34:51 +00:00
Hans Petter Selasky
c2676069cb 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.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-05-31 16:24:02 +00:00
Hans Petter Selasky
427cefde27 Properly implement idr_preload() and idr_preload_end() in the
LinuxKPI.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-05-31 16:08:30 +00:00
Hans Petter Selasky
dff36e69a1 Implement in_atomic() function in the LinuxKPI.
Obtained from:		kmacy @
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-05-31 15:05:44 +00:00
Hans Petter Selasky
90b30e6560 Properly set the .d_name field in the cdevsw structure for the
LinuxKPI.

Obtained from:		kmacy @
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-05-31 13:11:06 +00:00
Hans Petter Selasky
d56f1ed887 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.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-05-31 13:07:05 +00:00
Hans Petter Selasky
cca15f28c5 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.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-05-31 13:05:54 +00:00
Hans Petter Selasky
68b9f2f00c 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 @
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-05-31 13:01:27 +00:00
Hans Petter Selasky
ea67550be0 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.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-05-31 12:08:25 +00:00
Hans Petter Selasky
f5a9867b7d 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.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-05-31 12:02:59 +00:00
Hans Petter Selasky
3f743d782a Make sure the thread's priority is restored for all three cases inside
linux_synchronize_rcu_cb() in the LinuxKPI.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-05-31 10:01:15 +00:00