Commit graph

27 commits

Author SHA1 Message Date
Warner Losh 71625ec9ad sys: Remove $FreeBSD$: one-line .c comment pattern
Remove /^/[*/]\s*\$FreeBSD\$.*\n/
2023-08-16 11:54:24 -06:00
Hans Petter Selasky 2ae0861242 cuse(3): Cosmetic change about testing boolean values.
No functional change intended.

Differential Revision:	https://reviews.freebsd.org/D36633
Suggested by:	jrtc27@ and avg@
MFC after:	1 week
Sponsored by:	NVIDIA Networking
2022-10-04 13:51:06 +02:00
Hans Petter Selasky 5e59b2734f cuse(3): Optimise small reads and writes.
When doing small reads and writes use an intermediate buffer to store the
data to save locking the remote process to access data.

Reviewed by:	imp @
Differential Revision:	https://reviews.freebsd.org/D36633
MFC after:	1 week
Sponsored by:	NVIDIA Networking
2022-10-03 17:35:14 +02:00
Hans Petter Selasky 8f0a3c9c35 cuse(3): Use bool type for boolean value instead of int type.
No functional change intended.

Reviewed by:	imp @
Differential Revision:	https://reviews.freebsd.org/D36633
MFC after:	1 week
Sponsored by:	NVIDIA Networking
2022-10-03 17:35:14 +02:00
Hans Petter Selasky d14b53ee31 cuse(3): Allow shared memory allocations up to, but excluding 2 GBytes.
Currently the cuse(3) mmap(2) offset is split into 128 banks of 16 Mbytes.
Allow cuse(3) to make allocations that span multiple banks at the expense
of any fragmentation issues that may arise. Typically mmap(2) buffers are
well below 16 Mbytes. This allows 8K video resolution to work using webcamd.

Reviewed by:	markj @
Differential Revision:	https://reviews.freebsd.org/D35830
MFC after:	1 week
Sponsored by:	NVIDIA Networking
2022-07-20 10:41:11 +02:00
Hans Petter Selasky 0996dd7df6 cuse(3): Fix an off-by-one.
The page allocation limit is inclusive and not exclusive.

MFC after:	1 week
Sponsored by:	NVIDIA Networking
2022-07-20 10:41:11 +02:00
Hans Petter Selasky 2c28cd09d9 cuse(3): Remove PAGE_SIZE from libcuse.
To allow for a dynamic page size on arm64 remove the static value from libcuse.

Differential Revision:	https://reviews.freebsd.org/D35585
MFC after:	1 week
Sponsored by:	NVIDIA Networking
2022-06-25 12:01:59 +02:00
Hans Petter Selasky a71074e0af Fix for loading cuse.ko via rc.d . Make sure we declare the cuse(3)
module by name and not only by the version information, so that
"kldstat -q -m cuse" works.

Found by:		Goran Mekic <meka@tilda.center>
MFC after:		1 week
Sponsored by:		Mellanox Technologies // NVIDIA Networking
2020-10-23 08:44:53 +00:00
Mateusz Guzik 586ee69f09 fs: clean up empty lines in .c and .h files 2020-09-01 21:18:40 +00:00
Mark Johnston cbef26ed16 cuse: Stop checking for failures from malloc(M_WAITOK).
PR:		240545
Submitted by:	Andrew Reiter <arr@watson.org>
Reviewed by:	hselasky
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D25765
2020-07-23 14:03:37 +00:00
Hans Petter Selasky 98029019b6 Fine grain locking inside the cuse(3) kernel module.
Implement one mutex per cuse(3) server instance which also cover the
clients belonging to the given server instance.

This should significantly reduce the mutex congestion inside the
cuse(3) kernel module when multiple servers are in use.

MFC after:	1 week
Sponsored by:	Mellanox Technologies
2020-03-30 18:25:43 +00:00
Hans Petter Selasky 43a9329e1b Free all allocated unit IDs in cuse(3) after the client character
devices have been destroyed to avoid creating character devices with
identical name.

MFC after:	1 week
Sponsored by:	Mellanox Technologies
2019-06-25 11:46:01 +00:00
Hans Petter Selasky c7ffaed92e Fix for deadlock situation in cuse(3)
The final server unref should be done by the server thread to prevent
deadlock in the client cdevpriv destructor, which cannot destroy
itself.

MFC after:	1 week
Sponsored by:	Mellanox Technologies
2019-06-25 11:42:53 +00:00
Hans Petter Selasky db92a6cd51 Implement flag for telling cuse(3) clients if the peer is running in 32-bit
compat mode or not. This is useful when implementing compatibility ioctl(2)
handlers in userspace.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
2019-04-18 19:04:07 +00:00
Ed Maste 891cf3ed44 Use NULL for SYSINIT's last arg, which is a pointer type
Sponsored by:	The FreeBSD Foundation
2018-05-18 17:58:09 +00:00
Brooks Davis 6469bdcdb6 Move most of the contents of opt_compat.h to opt_global.h.
opt_compat.h is mentioned in nearly 180 files. In-progress network
driver compabibility improvements may add over 100 more so this is
closer to "just about everywhere" than "only some files" per the
guidance in sys/conf/options.

Keep COMPAT_LINUX32 in opt_compat.h as it is confined to a subset of
sys/compat/linux/*.c.  A fake _COMPAT_LINUX option ensure opt_compat.h
is created on all architectures.

Move COMPAT_LINUXKPI to opt_dontuse.h as it is only used to control the
set of compiled files.

Reviewed by:	kib, cem, jhb, jtl
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D14941
2018-04-06 17:35:35 +00:00
Hans Petter Selasky 56c49c63e7 Allow CUSE(3) to free all memory mapped memory by using regular SWAP objects
instead of malloc(). The SWAP objects are automagically freed when there are no
more consumers. This greatly simplifies the mmap logic inside CUSE(3) in the
kernel. This change fixes an issue where mmapped memory can accumulate and never
get freed, if many different mmap sizes are needed over time. Further this
change fixes memory leaks when the CUSE(3) kernel module is unloaded.

While at it make sure the CUSE_ALLOC_PAGES_MAX limit is treated as an exclusive
limit. CUSE(3) memory maps must be less than CUSE_ALLOC_PAGES_MAX number of pages.

Reviewed by:		kib @
Differential Revision:	https://reviews.freebsd.org/D11392
Sponsored by:		Mellanox Technologies
MFC after:		1 week
2017-11-03 14:10:57 +00:00
Hans Petter Selasky 9f16d9c95b Add support for new cuse(3) error code, CUSE_ERR_NO_DEVICE.
This error code is useful when emulating Linux input event
devices from userspace.

PR:			218626
Submitted by:		jan.kokemueller@gmail.com
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2017-10-05 16:42:02 +00:00
Hans Petter Selasky 9a83b0971e Minor code optimisation.
Avoid locking the global CUSE lock when the polling flags are zero.

MFC after:	1 week
2017-05-31 21:05:24 +00:00
Hans Petter Selasky 19f1b6fb7b Prevent cuse4bsd.ko and cuse.ko from loading at the same time by
declaring support for the cuse4bsd interface in cuse.ko.

Found by:	Sergey V. Dyatko <sergey.dyatko@gmail.com>
MFC after:	1 week
2016-09-23 07:41:23 +00:00
Hans Petter Selasky 010638ab22 Handle IOC_VOID special case of passing an integer IOCTL argument through CUSE.
Submitted by:	Vladimir Kondratyev <wulf@cicgroup.ru>
Approved by:	re (gjb)
2016-07-06 22:21:22 +00:00
Hans Petter Selasky beebd9aac8 Make CUSE usable with platforms where the size of "unsigned long" is
different from the size of a pointer.
2015-12-22 09:55:44 +00:00
Hans Petter Selasky 9fb69c9d9d Make CUSE usable with platforms where the size of "unsigned long" is
different from the size of a pointer.
2015-12-22 09:41:33 +00:00
Hans Petter Selasky ac60e80129 Guard against the same process being both CUSE server and client at
the same time. This can easily lead to a deadlock when destroying the
character devices nodes.
2015-12-22 09:26:24 +00:00
Hans Petter Selasky 9570004318 Don't use POLLNVAL as a return value from the client side poll
function. Many existing clients don't understand POLLNVAL and instead
relies on an error code from the read(), write() or ioctl() system
call. Also make sure we wakeup any client pollers before the cuse
server is closing, so they don't wait forever for an event.
2015-01-13 13:32:18 +00:00
Hans Petter Selasky 5928e3b9f4 Use existing PHOLD() and PRELE() macros.
Submitted by:	kib @
2014-06-24 18:25:43 +00:00
Hans Petter Selasky fa0f6e62c6 Initial import of character device in userspace support for FreeBSD.
The CUSE library is a wrapper for the devfs kernel functionality which
is exposed through /dev/cuse . In order to function the CUSE kernel
code must either be enabled in the kernel configuration file or loaded
separately as a module. Currently none of the committed items are
connected to the default builds, except for installing the needed
header files. The CUSE code will be connected to the default world and
kernel builds in a follow-up commit.

The CUSE module was written by Hans Petter Selasky, somewhat inspired
by similar functionality found in FUSE. The CUSE library can be used
for many purposes. Currently CUSE is used when running Linux kernel
drivers in user-space, which need to create a character device node to
communicate with its applications. CUSE has full support for almost
all devfs functionality found in the kernel:
 - kevents
 - read
 - write
 - ioctl
 - poll
 - open
 - close
 - mmap
 - private per file handle data

Requested by several people. Also see "multimedia/cuse4bsd-kmod" in
ports.
2014-05-23 08:46:28 +00:00