Commit Graph

4332 Commits

Author SHA1 Message Date
Dmitry Chagin
7a7cee5585 linux(4): Refactor SIGPWR mapping
Map Linux RT signals to the native RT signals starting from SIGRTMIN,
and Linux SIGPWR signal map to after the last RT signal.

MFC after:		2 weeks
2022-05-30 19:55:49 +03:00
Dmitry Chagin
669516a1a1 linux(4): Fix the type of a constant in the signal mask macro
Since l_sigset_t is 64-bit unsigned on all Linuxulators, fix the type
of a constant in the signal mask manipulation macro.
The suffix L indicates type long which is 32-bit on i386, therefore,
bitwise operations between a 32-bit constant and 64-bit signal mask
lead to the wrong result.

Pointy hat to:		dchagin
MFC after:		2 weeks
2022-05-30 19:53:52 +03:00
Dmitry Chagin
2ca34847e7 linux(4): Reduce duplication between MD parts of the Linuxulator
Move sigprocmask actions defines under compat/linux,
they are identical across all Linux architectures.

MFC after:		2 weeks
2022-05-30 19:47:26 +03:00
Dmitry Chagin
3735f9cff1 linux(4): Handle multiple mbufs in a control message chain in recvmsg
PR:		230274
MFC after:	2 weeks
2022-05-28 23:48:45 +03:00
Dmitry Chagin
31d7f3e9ce linux(4): Ratelimit message about unupported cmsg
MFC after:		2 weeks
2022-05-28 23:48:16 +03:00
Dmitry Chagin
f8a6615064 linux(4): Handle IP_ORIGDSTADDR socket option for IPPROTO_IP protocol level
MFC after:		2 weeks
2022-05-28 23:47:40 +03:00
Dmitry Chagin
4f02a4f48c linux(4): Add LINUX_RATELIMIT_MSG_OPT2 for future use
MFC after:		2 weeks
2022-05-28 23:47:23 +03:00
Dmitry Chagin
53494b918d linux(4): Overwrite SO_TIMESTAMP counterpart
A socket cannot mix SO_TIMESTAMP and SO_TIMESTAMPNS: the two modes
are mutually exclusive.

MFC after:		2 weeks
2022-05-28 23:46:38 +03:00
Dmitry Chagin
0eda2ceab7 linux(4): Refactor linux_common_recvmsg()
To improve readability lower nesting level, better naming for variables.
No functional changes.

MFC after:		2 weeks
2022-05-28 23:46:22 +03:00
Dmitry Chagin
71bc8bcf66 linux(4): Handle SO_TIMESTAMPNS socket option
The SO_TIMESTAMPNS enables or disables the receiving of the SCM_TIMESTAMPNS
control message. The cmsg_data field is a struct timespec.
To distinguish between SO_TIMESTAMP and SO_TIMESTAMPNS in the recvmsg()
map the last one to the SO_BINTIME and convert bintime to the timespec.
In the rest, implementation is identical to the SO_TIMESTAMP.

MFC after:		2 weeks
2022-05-28 23:46:05 +03:00
Dmitry Chagin
0e26e54bdf linux(4): Handle 64-bit SO_TIMESTAMP for 32-bit binaries
To solve y2k38 problem in the recvmsg syscall the new SO_TIMESTAMP
constant were added on v5.1 Linux kernel. So, old 32-bit binaries
that knows only 32-bit time_t uses the old value of the constant,
and binaries that knows 64-bit time_t uses the new constant.

To determine what size of time_t type is expected by the user-space,
store requested value (SO_TIMESTAMP) in the process emuldata structure.

MFC after:		2 weeks
2022-05-28 23:45:39 +03:00
Dmitry Chagin
6335583990 linux(4): For future use replace malloc type for l_sockaddr by M_LINUX
MFC after:		2 weeks
2022-05-28 23:44:48 +03:00
Dmitry Chagin
b408788d6b linux(4): Improve recvmsg() readability
To improve recvmsg() readability SCM_ handlers moved to a separate
functions.

MFC after:		2 weeks
2022-05-28 23:44:02 +03:00
Dmitry Chagin
f409a7c538 linux(4): For future use move SCM definitions below socket options
MFC after:		2 weeks
2022-05-28 23:42:23 +03:00
Dmitry Chagin
db48fa8319 linux(4): Avoid EISCONN if addr is specified for sendto()
If the socket is in a connected state, the target address should be
ignored.

MFC after:		2 weeks
2022-05-28 23:42:09 +03:00
Dmitry Chagin
e8d9d8082b linux(4): Fix SO_LINGER l_onoff value
On Linux l_onoff should be 1 when linger is used.

MFC after:		2 weeks
2022-05-28 23:31:06 +03:00
Dmitry Chagin
e92b9a9eaa linux(4): Add a helper to copyout getsockopt value
For getsockopt(), optlen is a value-result argument, which is modified
on return to indicate the actual size of the value returned.
For some cases this was missed, fixed.

MFC after:		2 weeks
2022-05-28 23:30:22 +03:00
Dmitry Chagin
3a99aac66f linux(4): Check the socket before any others sanity checks
Strictly speaking, this check is performed by the kern_recvit(), but in
the Linux emulation layer before calling the kernel we do other sanity
checks and conversions from Linux types to the native types. This changes
an order of the error returning that is critical for some buggy Linux
applications.

For recvmmsg() syscall this fixes a panic in case when the user-supplied
vlen value is 0, then error is not initialized and garbage passed to the
bsd_to_linux_errno().

MFC after:		2 weeks
2022-05-28 23:29:12 +03:00
Dmitry Chagin
d46174cd88 Finish cpuset_getaffinity() after f35093f8
Split cpuset_getaffinity() into a two counterparts, where the
user_cpuset_getaffinity() is intended to operate on the cpuset_t from
user va, while kern_cpuset_getaffinity() expects the cpuset from kernel
va.
Accordingly, the code that clears the high bits is moved to the
user_cpuset_getaffinity(). Linux sched_getaffinity() syscall returns
the size of set copied to the user-space and then glibc wrapper clears
the high bits.

MFC after:		2 weeks
2022-05-28 20:53:08 +03:00
Dmitry Chagin
31d1b816fe sysent: Get rid of bogus sys/sysent.h include.
Where appropriate hide sysent.h under proper condition.

MFC after:	2 weeks
2022-05-28 20:52:17 +03:00
Emmanuel Vadot
25d21a8452 linuxkpi: Rework detach function
We need to detach the matching i2c adapter so look for the right one.
While here add some locks to protect multiple add/del at the same time.

Fixes:	1961a14a47 ("linuxkpi: Add i2c support")
Sponsored by:	Beckhoff Automation GmbH & Co. KG
2022-05-25 09:57:10 +02:00
Dmitry Chagin
1bb3faed29 linux(4): Fix unlinkat() after a125ed50
MFC after:		2 weeks
2022-05-23 13:19:34 +03:00
Dmitry Chagin
26700ac0c4 linux(4): Deduplicate execve
As linux_execve is common across archs, except amd64 32-bit Linuxulator,
move it under compat/linux.

Noted by:		andrew@
MFC after:		2 weeks
2022-05-23 13:18:41 +03:00
Dmitry Chagin
e0aef0d62d linux(4): Fix unlink() after a125ed50
MFC after:		2 weeks
2022-05-23 13:18:07 +03:00
Bjoern A. Zeeb
6cf748ad94 LinuxKPI 802.11 / iwlwifi / rtw88 : re-factor ieee802211_sta for MLO
Working on an update for rtw88 baed on wireless-testing I ran into
a build issue with struct ieee802211_sta.  Some fields were factored
out into their own struct apparently preparing for MLO (Multi Link
Operation).

In order to be able to update one driver we have to adjust both
rtw88 and iwlwifi (and the ones still out-of-tree) now.

This is mostly a sed-replace job and no functional changes are
intended.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-05-20 18:45:18 +00:00
Mark Johnston
4a3e51335e cpuset: Fix the KASAN and KMSAN builds
Rename the "copyin" and "copyout" fields of struct cpuset_copy_cb to
something less generic, since sanitizers define interceptors for
copyin() and copyout() using #define.

Reported by:	syzbot+2db5d644097fc698fb6f@syzkaller.appspotmail.com
Fixes:	47a57144af ("cpuset: Byte swap cpuset for compat32 on big endian architectures")
Sponsored by:	The FreeBSD Foundation
2022-05-20 10:34:25 -04:00
Dmitry Chagin
eca368ecb6 Retire sv_transtrap
Call translate_traps directly from sendsig().

MFC after:		2 weeks
2022-05-20 14:54:03 +03:00
Bjoern A. Zeeb
d296b65d89 LinuxKPI: 802.11 updates
Add more values to the ieee80211_min_mpdu_start_spacing enum with
two missing given we do not know how they are called.  Also update
the reference while here.

Add struct ieee80211_hdr_3addr and correct the comment on the
ieee80211_hdr to match the one in net80211 to avoid future confusion.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-05-20 01:11:22 +00:00
Bjoern A. Zeeb
85eb99f9a4 LinuxKPI: implement pcie_capability_set_word()
Implement pcie_capability_set_word() using the already available
read/write functions.
Also define the completion timeout disable value to our PCI one.
Both needed by a driver update.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Reviewed by:	manu, hselasky
Differential Revision: https://reviews.freebsd.org/D35250
2022-05-20 01:09:08 +00:00
Dmitry Chagin
b04f5d18b5 linux(4): To improve readability use FUTEX_UNOWNED instead of 0
MFC after:		2 weeks
2022-05-19 21:42:38 +03:00
Dmitry Chagin
89737eb829 Fix the build after 47a57144 2022-05-19 21:40:59 +03:00
Dmitry Chagin
a6f85b12bb linux(4): Convert the native kernel signal codes into the Linux codes
MFC after:		2 weeks
2022-05-19 19:56:50 +03:00
Dmitry Chagin
3030197563 linux(4): Add kernel signal code definitions
In the next commit I'll convert the native signal codes into the Linux codes,
since they are not 1:1 mapped.

MFC after:		2 weeks
2022-05-19 19:55:56 +03:00
Dmitry Chagin
9386e18b39 linux(4): Move signal codes definitions to the appropriate header
In the Linux the struct siginfo related bits are placed into the siginfo.h
header.

MFC after:		2 weeks
2022-05-19 19:55:20 +03:00
Dmitry Chagin
2cd662064a linux(4): Handle cas failure on ll/sc operations
Follow the 11a6ecd4. Check and handle the case when the ll/sc casu fails
even when the compare succeeds.

For more details PR/263825, https://reviews.freebsd.org/D35150.

Obtained from:		Andrew@
MFC after:		2 weeks
2022-05-19 19:52:18 +03:00
Justin Hibbits
47a57144af cpuset: Byte swap cpuset for compat32 on big endian architectures
Summary:
BITSET uses long as its basic underlying type, which is dependent on the
compile type, meaning on 32-bit builds the basic type is 32 bits, but on
64-bit builds it's 64 bits.  On little endian architectures this doesn't
matter, because the LSB is always at the low bit, so the words get
effectively concatenated moving between 32-bit and 64-bit, but on
big-endian architectures it throws a wrench in, as setting bit 0 in
32-bit mode is equivalent to setting bit 32 in 64-bit mode.  To
demonstrate:

32-bit mode:

BIT_SET(foo, 0):        0x00000001

64-bit sees: 0x0000000100000000

cpuset is the only system interface that uses bitsets, so solve this
by swapping the integer sub-components at the copyin/copyout points.

Reviewed by:	kib
MFC after:	3 days
Sponsored by:	Juniper Networks, Inc.
Differential Revision:	https://reviews.freebsd.org/D35225
2022-05-19 10:49:55 -05:00
Vladimir Kondratyev
71fe907dfb LinuxKPI: Switch irq_work implementation back to standard taskqueue
from fast one as dmabuf does not run callbacks from critical sections
since drm-kmod 5.7.
Consumers which requires fair irq_work like drm-kmod 5.4 must #define
LKPI_IRQ_WORK_USE_FAST_TQ somewhere in source file before linux/irq_work.h
inclusion to enable old behavior.

MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D35052
2022-05-17 15:10:20 +03:00
Vladimir Kondratyev
bec4576e4c LinuxKPI: Do not use forward declaration for struct llist_node
in linux/irq_work.h as irq_work structure contains full version of
llist_node rather than reference to it.

MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D35052
2022-05-17 15:10:20 +03:00
Vladimir Kondratyev
fa30bff5da LinuxKPI: IRQ work add TASKQUEUE_FAIL_IF_PENDING flag to taskqueue_enqueue
call to match Linux.

MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D35052
2022-05-17 15:10:20 +03:00
Vladimir Kondratyev
b6f87b78b5 LinuxKPI: Implement kthread_worker related functions
Kthread worker is a single thread workqueue which can be used in cases
where specific kthread association is necessary, for example, when it
should have RT priority or be assigned to certain cgroup.

This change implements Linux v4.9 interface which mostly hides kthread
internals from users thus allowing to use ordinary taskqueue(9) KPI.
As kthread worker prohibits enqueueing of already pending or canceling
tasks some minimal changes to taskqueue(9) were done.
taskqueue_enqueue_flags() was added to taskqueue KPI which accepts extra
flags parameter. It contains one or more of the following flags:

TASKQUEUE_FAIL_IF_PENDING - taskqueue_enqueue_flags() fails if the task
    is already scheduled to execution. EEXIST is returned and the
    ta_pending counter value remains unchanged.
TASKQUEUE_FAIL_IF_CANCELING - taskqueue_enqueue_flags() fails if the
    task is in the canceling state and ECANCELED is returned.

Required by:	drm-kmod 5.10

MFC after:	1 week
Reviewed by:	hselasky, Pau Amma (docs)
Differential Revision:	https://reviews.freebsd.org/D35051
2022-05-17 15:10:20 +03:00
Vladimir Kondratyev
0093bc3cd1 LinuxKPI: Implement sched_set_fifo(_low) functions
Required by:	drm-kmod

MFC after:	1 week
Reviewed by:	hselasky, manu
Differential Revision:	https://reviews.freebsd.org/D35050
2022-05-17 15:10:20 +03:00
Vladimir Kondratyev
1ebd7aeeca LinuxKPI: Add some pollution required by drm-kmod to linux/sched.h
MFC after:	1 week
Reviewed by:	hselasky, manu
Differential Revision:	https://reviews.freebsd.org/D35050
2022-05-17 15:10:20 +03:00
Vladimir Kondratyev
6bcd132222 LinuxKPI: Add cpu_latency_qos_request_active stub to linux/pm_qos.h
Required by:	drm-kmod 5.10

MFC after:	1 week
Reviewers:	hselasky, manu
Differential Revision:	https://reviews.freebsd.org/D35049
2022-05-17 15:10:20 +03:00
Vladimir Kondratyev
41559beb00 LinuxKPI: Fix typo in cond_resched_lock
Lock must be released rather than acquired around mi_switch call.

MFC after:	1 week
Reviewed by:	hselasky, manu
Differential Revision:	https://reviews.freebsd.org/D35048
2022-05-17 15:10:20 +03:00
Vladimir Kondratyev
29d5f0c148 LinuxKPI: Convert lkpi-shrinker lock to sx.
This fixes "might_sleep() with the following non-sleepable locks held:
exclusive sleep mutex lkpi-shrinker" warnings.

MFC after:	1 week
Reviewed by:	hselasky, manu
Differential Revision:	https://reviews.freebsd.org/D35047
2022-05-17 15:10:20 +03:00
Vladimir Kondratyev
f49cddbda6 LinuxKPI: Allow lkpi_iic driver to be a child of drm device.
i915kms exposes "AUX #/port #" I2C adapters as drm children

MFC after:	1 week
Reviewed by:	hselasky, manu
Differential Revision:	https://reviews.freebsd.org/D35046
2022-05-17 15:10:19 +03:00
Bjoern A. Zeeb
05d6f4d696 LinuxKPI: 802.11 add rfkill_soft_blocked()
Add rfkill_soft_blocked() to the list of things to implement in
preparation for an iwlwifi update.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-05-16 15:38:31 +00:00
Dmitry Chagin
390c9ea029 linux(4): Add AT_MINSIGSTKSZ to arm64 port
MFC after:	2 weeks
2022-05-15 21:12:03 +03:00
Dmitry Chagin
af557e649c linux(4): Rework the definition of struct siginfo to match Linux actual one
Rework the defintion of struct siginfo so that the array padding
struct siginfo to SI_MAX_SIZE can be placed in a union along side of the
rest of the struct siginfo members.  The result is that we no longer need
the __ARCH_SI_PREAMBLE_SIZE or SI_PAD_SIZE definitions.

Move struct siginfo definition under /compat/linux to reduce MD part.
To avoid headers polution include linux_siginfo.h in the MD linux.h

MFC after:		2 weeks
2022-05-15 21:05:01 +03:00
Hans Petter Selasky
f9e90c2473 LinuxKPI: Implement linux/hashtable.h for FreeBSD.
This implementation uses the concurrency kit, CK, API directly which is
suitable for use with EPOCH(9) and RCU under FreeBSD.

No functional change intended.

The initial "linux/hash.h" code was obtained from DragonFlyBSD via
FreeBSD's drm-kmod in ports.

Differential Revision:	https://reviews.freebsd.org/D35162
Reviewed by:	bz@ and markj@
MFC after:	1 week
Sponsored by:	NVIDIA Networking
2022-05-12 16:32:47 +02:00