Commit Graph

4752 Commits

Author SHA1 Message Date
Jean-Sébastien Pédron
1ad6b2b1da
linuxkpi: Add krealloc_array()
In FreeBSD, this is a wrapper on top of `realloc()`.

V2: Check if `n * size` would overflow and return `NULL` if that's the
    case. Suggested by hselasky@ and emaste@.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D36959
2022-11-11 18:37:34 +01:00
Jean-Sébastien Pédron
0b8a423d07
linuxkpi: Introduce module_param() of type hexint
In Linux, this affects how the value is formatted. In FreeBSD, this
remains an unsigned integer.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D36958
2022-11-11 18:36:46 +01:00
Jean-Sébastien Pédron
c72dd0aabe
linuxkpi: Introduce vma_set_file()
This code was moved from the i915 driver in Linux 5.11.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D36957
2022-11-11 18:36:00 +01:00
Jean-Sébastien Pédron
415ca4d27d
linuxkpi: Include <linux/shinker.h> in <linux/mm.h>
This is done like this in Linux.

Reviewed by:	emaste manu
Approved by:	emaste manu
Differential Revision:	https://reviews.freebsd.org/D36956
2022-11-11 18:34:19 +01:00
Jean-Sébastien Pédron
f021c5c4a1
linuxkpi: Update struct irq_work
The previous `llnode` field is moved inside another field `node`.

This `node` field is a `struct __call_single_node` in Linux. Here, we
simply add an anonymous struct with the `llnode` field inside. That
field's new name is `llist` now.

V2: Use an anonymous union to keep the structure backward compatible
    with drivers using the previous `llnode` field. This was suggested
    by wufl@ and hselasky@. Thank you!

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D36955
2022-11-11 18:32:58 +01:00
Jean-Sébastien Pédron
bfe6bfd79e
linuxkpi: Add __GFP_NOMEMALLOC kmalloc flag
Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D36954
2022-11-11 18:30:31 +01:00
Emmanuel Vadot
ee247fc1e9 linuxkpi: Move cpu_relax out of ifdef for x86
It's needed by drm-kmod and this allow building on arm64 and powerpc.

Reported by:	jhibbits
Sponsored by:	Beckhoff Automation GmbH & Co. KG
2022-11-10 12:50:51 +01:00
Alex S
9f7bf94ee2 linux(4): Fix get_robust_list() syscall return value.
The system call returns the head of the robust futex list. The list head is stored
in the location pointed to by the head argument. When copying data between address
spaces use proper head storage size as it depends on an emulated ABI.

PR:		267616
MFC after:	3 days
2022-11-09 00:17:17 +03:00
Bjoern A. Zeeb
b5c3819c7b LinuxKPI: add virt_to_phys()
Add virt_to_phys() as a define to vtophys().
This is used by a wireless driver for dma related work; sigh.

MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D37301
2022-11-08 18:18:01 +00:00
Bjoern A. Zeeb
f2978460c7 LinuxKPI: tasklet add (*callback) support
In addition to (*func) tasklet also seems to have a (*callback) with
a different argument.  Add support for this and add tasklet_setup()
as well for support in more drivers.

The from_tasklet() definition is duplicated in the tree; hide it there
under #ifndef to avoid a re-definition.  People should generally add
LinuxKPI bits to linuxkpi rather than private files if they also rely
on other LinuxKPI bits.

X-MFC:		DO NOT MFC, space allocated by drivers not us.
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D37216
2022-11-08 18:14:17 +00:00
Bjoern A. Zeeb
e2361e04b0 LinuxKPI: implement cpumask_of()
Add a static set of cpumasks for all (possible) cpus with only the one
indexed cpu enabled in each set.
This is needed for cpumask_of(_cpuid) which returns a cpumask (cpuset)
with only cpu _cpuid enabled and is used by one wireless driver at least.

MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D37223
2022-11-08 18:11:55 +00:00
Bjoern A. Zeeb
a62d5ff5b0 LinuxKPI: add linux/leds.h
This is just a dummy enum and struct in order to make drivers compile
more happily as some parts are simply not hidden behind #ifdefs and
this avoids a longer-term maintenance problem.

MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D37215
2022-11-07 12:52:41 +00:00
Bjoern A. Zeeb
6e8d676131 LinuxKPI: add devm_request_irq()
Add devm_request_irq() needed by a driver.  Turns out all we need
is a wrapper with the right arguments to lkpi_request_irq().

MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D37217
2022-11-07 12:51:01 +00:00
Bjoern A. Zeeb
6a647ae514 LinuxKPI: string.h implement memcpy_and_pad()
Add a memcpy variant which takes length of source and destination
buffers and a padding character in case there is free space in the
destination.  This is used by a wireless driver.

MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D37226
2022-11-07 12:49:01 +00:00
Bjoern A. Zeeb
4a67f1df8b LinuxKPI: 802.11: enable WME support
Most of the WME code has been there disabled for months.  One of the
reasons was that it lead to crashes early on.  It is now understood
that the crashes are independent event and we can enable WME.
Update the code and deal with the calls from net80211 and adjust the
updates to when mac80211 drivers expect them, coherently put it under
LKPI_80211_WME and enable the define locally.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-11-07 12:39:46 +00:00
Elliott Mitchell
21cc0918c7 sys: Nuke double-semicolons
A distinct number of double-semicolons have ended up in FreeBSD.  Take a
pass at getting rid of many of these harmless typos.

Reviewed by: emaste, rrs
Pull Request: https://github.com/freebsd/freebsd-src/pull/609
Differential Revision: https://reviews.freebsd.org/D31716
2022-11-02 09:34:20 -06:00
Bjoern A. Zeeb
e7fe037310 LinuxKPI: 802.11: pass internal variable to lkpi_80211_mo_sta_state()
With mac80211 operations (MO) tracing on we have seen some ill-ordered
executions of MO functions.  In order to limit visibility of the mac80211
sta, pass the internal version into lkpi_80211_mo_sta_state() and only
there convert to the argument needed.  This mostly eases tracing and
debugging.

Sposnored by:	The FreeBSD Foundation
MFC after:	3 days
2022-11-01 00:00:18 +00:00
Bjoern A. Zeeb
05e640dc9e LinuxKPI: 802.11: update struct member types
Update struct member types for ongoing work towards HT support.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-10-31 22:24:08 +00:00
Bjoern A. Zeeb
1d70218e9e LinuxKPI: 802.11 update header files
Adjust struct members, add more (for HE dummy) defines, add more
(wrapper) functions in order to acoomodate another driver.

MFC after:	3 days
2022-10-31 22:09:25 +00:00
Bjoern A. Zeeb
cca40d7cc7 LinuxKPI: add timekeeping.h, another dummy (empty) header file
The file is included by a driver but it seems we don't need to implement
anything here.

MFC after:	3 days
2022-10-30 17:35:24 +00:00
Ed Maste
43d0c2ddd2 netlink: use (void) for function definitions with no arguments
For some of these Clang produced a warning that "a function declaration
without a prototype is deprecated in all versions of C".  In other cases
the function defintion used () which did not match the header
declaration, which used (void).

Sponsored by:	The FreeBSD Foundation
2022-10-27 11:14:00 -04:00
Bjoern A. Zeeb
b5a8107590 LinuxKPI: seq_file add "private" versions.
Add __seq_open_private() and seq_release_private() needed by iwlwifi
debugfs support.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D37089
2022-10-24 21:39:48 +00:00
Bjoern A. Zeeb
d3975204e4 LinuxKPI: add MSEC_PER_SEC
Sponsored by:	The FreeBSD Foundation
Reviewed by:	imp, emaste
MFC after:	3 days
Differential Revision: https://reviews.freebsd.org/D37087
2022-10-23 21:54:36 +00:00
Bjoern A. Zeeb
64d3da0063 LinuxKPI: 802.11: add MO tracing
Add a macro to each implemented mac80211 operation.  This currently
turns into a printf if LINUXKPI_80211_DEBUG is defined but in the
future could become a different probe as well.
This is helpful for quick analysis and boot-time problem debugging
when DTrace and other frameworks may be harder to use.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-10-23 21:48:22 +00:00
Bjoern A. Zeeb
0080f30ff1 LinuxKPI: 802.11: add changes to support debugfs in iwlwifi
Add new fields (also have to move a struct up, no changes there)
in order to make iwlwifi debugfs support compile.

Sposnored by:	The FreeBSD Foundation
MFC after:	3 days
2022-10-22 20:42:35 +00:00
John Grafton
4c9db9566e linprocfs: Add net/route.
PR:			266482
Reviewed by:		melifaro, me
Differential revision:	https://reviews.freebsd.org/D36949
MFC after:		1 week
2022-10-22 13:52:58 +03:00
Ed Maste
9f6097d6a6 linuxkpi: retire now-unused MIPS support
Reviewed by:	bz, manu
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D37023
2022-10-17 16:31:20 -04:00
Jake Freeland
4cb3cb2de2 LinuxKPI: Add pci_power querying for drm-kmod
Adds a few struct members and a function to get i915_runtime_pm_status()
to compile in drm-kmod.

Differential Revision:	https://reviews.freebsd.org/D36749
Sponsored by:   Google, Inc. (GSoC 2022)
2022-10-06 10:15:41 +02:00
Alexander V. Chernikov
7c40e2d5f6 linuxolator: add netlink support
Add the glue code to support netlink in Linuxolator.
linux_common(4) now depends on netlink(4).

All netlink protocol constants are consistent with the Linux version.
However, certain OS-specific constants such as AF_INET6, interface
flags or default routing table id, are different between FreeBSD and
Linux. Thus, it may be needed to rewrite some message parts or even
rewrite the whole message, adding or removing some TLVs. The core
netlink implementation code provides efficient rewriting callbacks
 which Linuxolator now uses.

Reviewed by:	dchagin
Differential Revision: https://reviews.freebsd.org/D36361
MFC after:	2 months
2022-10-01 14:16:45 +00:00
Ed Schouten
af3c78886f Alter the prototype of qsort_r(3) to match POSIX, which adopted the
glibc-based interface.

Unfortunately, the glibc maintainers, despite knowing the existence
of the FreeBSD qsort_r(3) interface in 2004 and refused to add the
same interface to glibc based on grounds of the lack of standardization
and portability concerns, has decided it was a good idea to introduce
their own qsort_r(3) interface in 2007 as a GNU extension with a
slightly different and incompatible interface.

With the adoption of their interface as POSIX standard, let's switch
to the same prototype, there is no need to remain incompatible.

C++ and C applications written for the historical FreeBSD interface
get source level compatibility when building in C++ mode, or when
building with a C compiler with C11 generics support, provided that
the caller passes a fifth parameter of qsort_r() that exactly matches
the historical FreeBSD comparator function pointer type and does not
redefine the historical qsort_r(3) prototype in their source code.

Symbol versioning is used to keep old binaries working.

MFC:			never
Relnotes:		yes
Reviewed by:		cem, imp, hps, pauamma
Differential revision:	https://reviews.freebsd.org/D17083
2022-09-30 15:26:30 -07:00
Hans Petter Selasky
dd6bb9abf0 LinuxKPI: Use SYSCTL_FOREACH()
Differential Revision:  https://reviews.freebsd.org/D36748
MFC after:	1 week
Sponsored by:	NVIDIA Networking
2022-09-28 13:59:55 +02:00
Alan Somers
d3f96f6610 Fix O(n^2) behavior in sysctl
Sysctl OIDs were internally stored in linked lists, triggering O(n^2)
behavior when userland iterates over many of them.  The slowdown is
noticeable for MIBs that have > 100 children (for example, vm.uma).  But
it's unignorable for kstat.zfs when a pool has > 1000 datasets.

Convert the linked lists into RB trees.  This produces a ~25x speedup
for listing kstat.zfs with 4100 datasets, and no measurable penalty for
small dataset counts.

Bump __FreeBSD_version for the KPI change.

Sponsored by:	Axcient
Reviewed by:	mjg
Differential Revision: https://reviews.freebsd.org/D36500
2022-09-26 18:03:34 -06:00
Bjoern A. Zeeb
0b9bc97342 LinuxKPI: add DMA_MAPPING_ERROR
While we deal with 0 returned, some drivers directly use and check for
DMA_MAPPING_ERROR.  Add the case and check for both in dma_mapping_error().

MFC after:	1 week
Reviewed by:	hselasky
Differential Revision: https://reviews.freebsd.org/D36686
2022-09-26 19:42:02 +00:00
Bjoern A. Zeeb
f486b35247 LinuxKPI: add struct dmi_header and unsupported dmi_walk()
Add a structure definition as well as a dummy dmi_walk for now
which returns an error as not supported.  Our current dmi implementation
is special but does not give access to all details but rather only
information from kenv which does not suffice all use cases.

MFC after:	1 week
Reviewed by:	hselasky
Differential Revision: https://reviews.freebsd.org/D36687
2022-09-26 19:40:49 +00:00
John Baldwin
f49fd63a6a kmem_malloc/free: Use void * instead of vm_offset_t for kernel pointers.
Reviewed by:	kib, markj
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D36549
2022-09-22 15:09:19 -07:00
John Baldwin
7ae99f80b6 pmap_unmapdev/bios: Accept a pointer instead of a vm_offset_t.
This matches the return type of pmap_mapdev/bios.

Reviewed by:	kib, markj
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D36548
2022-09-22 15:08:52 -07:00
Bjoern A. Zeeb
f7c0c1590e LinuxKPI: cache.h add L1_CACHE_ALIGN()
Sponsored by:	The FreeBSD Foundation
MFC after:	7 days
Reviewed by:	hselasky
Differential Revision: https://reviews.freebsd.org/D36655
2022-09-22 15:10:04 +00:00
Bjoern A. Zeeb
30048f6142 LinuxKPI: pci.h split up pcim_iomap_regions_request_all()
Factor out parts of pcim_iomap_regions_request_all() into
pcim_iomap_regions() now needed for a driver.

Sponsored by:	The FreeBSD Foundation
MFC after:	7 days
Reviewed by:	hselasky
Differential Revision: https://reviews.freebsd.org/D36654
2022-09-22 15:10:04 +00:00
Bjoern A. Zeeb
8e30f49256 LinuxKPI: if_ether.h add more constants
In addition to the ones added last year add more found in modern
drivers.

Sponsored by:	The FreeBSD Foundation
MFC after:	7 days
Reviewed by:	hselasky
Differential Revision: https://reviews.freebsd.org/D36656
2022-09-22 15:10:04 +00:00
Bjoern A. Zeeb
046b82842c LinuxKPI: io.h constify arguments and add more functions
Constify "*from" arguments and add __ioread32_copy() and
__ioread64_copy() based on the already existing implementations.

Sponsored by:	The FreeBSD Foundation
MFC after:	7 days
Reviewed by:	hselasky
Differential Revision: https://reviews.freebsd.org/D36657
2022-09-22 15:10:04 +00:00
Bjoern A. Zeeb
7105f0d967 LinuxKPI: dma-mapping: add dmam_alloc_coherent()
Add the devres version dmam_alloc_coherent() of dma_alloc_coherent()
along with the ancillary free function.

Sponsored by:	The FreeBSD Foundation
MFC after:	7 days
Reviewed by:	hselasky
Differential Revision: https://reviews.freebsd.org/D36661
2022-09-22 15:10:03 +00:00
Bjoern A. Zeeb
f9f4988dc4 LinuxKPI: tracepoint.h add more defines
Add some more defines used in drivers to make it easier to compile.

MFC after:	7 days
Reviewed by:	hselasky, emaste
Differential Revision: https://reviews.freebsd.org/D36660
2022-09-22 15:10:03 +00:00
Bjoern A. Zeeb
fdc7ef3c98 LinuxKPI: pci_ids.h Add more Vendor IDs.
Add PCI vendor IDs found in ath and mt76 drivers.  This should make it
easier for me and others not having to re-define them locally.

MFC after:	7 days
Reviewed by:	hselasky, emaste
Differential Revision: https://reviews.freebsd.org/D36659
2022-09-22 15:10:03 +00:00
Bjoern A. Zeeb
b27c3aa800 LinuxKPI: lockdep.h add lockdep_{,un}register_key()
Add NOPs for lockdep_{,un}register_key().

Sponsored by:	The FreeBSD Foundation
MFC after:	7 days
Reviewed by:	hselasky, emaste
Differential Revision: https://reviews.freebsd.org/D36658
2022-09-22 15:10:03 +00:00
Bjoern A. Zeeb
c41d83548b LinuxKPI: pci.h add more defines and functions
Add #defines for PCI_DEVICE_ID and repoint the PCI_VENDOR_ID one.
Add dev_is_pci().
Add pcie_capability_clear_word() according to similar implementations.

Sponsored by:	The FreeBSD Foundation
MFC after:	7 days
Reviewed by:	hselasky, emaste
Differential Revision: https://reviews.freebsd.org/D36653
2022-09-22 15:10:03 +00:00
Bjoern A. Zeeb
e999fbf077 LinuxKPI: device.h add devm_kmemdup()
Add devm_kmemdup() as needed by a networking driver.

Sponsored by:	The FreeBSD Foundation
MFC after:	7 days
eviewed by: 	hselasky, emaste
Differential Revision: https://reviews.freebsd.org/D36652
2022-09-22 15:09:26 +00:00
Bjoern A. Zeeb
8ea48fc59e LinuxKPI: device.h remove duplicate #include
linux/types.h is included twice; reduce to the first.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-09-21 17:25:34 +00:00
Bjoern A. Zeeb
f02e21159b LinuxKPI: 802.11: add more header compat bits
First part adding more bits in order to synch up drivers to the same
level and enable a new ones.

MFC after:	3 days
2022-09-21 17:12:48 +00:00
Hans Petter Selasky
cbda8bed15 linuxkpi: Resolve duplicate global symbol name to fix LINT kernel build.
seq_printf() is defined in both spl_procfs_list.c and linux_seq_file.c .
Fix this by renaming the LinuxKPI ones and use macros to invoke the
correct function.

Reported by:	jfree@
Differential Revision:  https://reviews.freebsd.org/D35883
MFC after:	1 week
Sponsored by:	NVIDIA Networking
2022-09-20 22:37:15 +02:00
Jake Freeland
f697b9432d linuxkpi: drm-kmod debugfs support
This diff extends LinuxKPI to support simple attribute files in debugfs.
These simple attributes are an essential component for compiling drm-kmod
with CONFIG_DEBUG_FS enabled.
This will allow for easier graphics driver debugging using
Intel's igt-gpu-tools.

Reviewed by:	hselasky
Differential Revision:	https://reviews.freebsd.org/D35883
Sponsored by:	Google, Inc. (GSoC 2022)
2022-09-20 19:41:10 +02:00
Jake Freeland
a11195df34 linuxkpi: Add strndup_user
Reviewed by:	hselasky, markj
Differential Revision:	https://reviews.freebsd.org/D36350
Sponsored by:	Google, Inc. (GSoC 2022)
2022-09-20 19:40:05 +02:00
Jake Freeland
a06eeeaa1d linuxkpi: Add EPOLL aliases
Reviewed by:	hselasky
Differential Revision:	https://reviews.freebsd.org/D36527
Sponsored by:	Google, Inc. (GSoC 2022)
2022-09-20 19:39:52 +02:00
Jake Freeland
f0b0f28f35 linuxkpi: Add down_read_killable()
Reviewed by:	hselasky
Differential Revision:	https://reviews.freebsd.org/D36528
Sponsored by:	Google, Inc. (GSoC 2022)
2022-09-20 19:39:32 +02:00
Mateusz Guzik
c3707bd3d6 linuxkpi: use SI_SUB_EVENTHANDLER + 1, like other consumers
Otherwise it may try to initialize before eventhandler subsystem.
2022-09-17 23:52:23 +00:00
Jessica Clarke
7b673a2c73 freebsd32: Make sendmsg match native ABI for unpadded final control message
The API says that CMSG_SPACE should be used for msg_controllen, but in
practice the native ABI allows you to only use CMSG_LEN for the final
(typically only) control message, and real-world software does this,
including Wayland. For freebsd32, this is in practice mostly harmless,
since control messages are generally used to carry file descriptors,
which are already 4 bytes in size and thus no padding is needed, but
they can carry other quantities that may not result in an aligned
length. This was discovered after CheriBSD's freebsd64 equivalent was
updated to match the freebsd32 implementation, as that uses 8 byte
alignment which does break the file descriptor use case, and thus
Wayland.

This used to be addressed by aligning buflen before the first iteration,
but that allowed unwanted invalid inputs and was lost in 1b1428dcc8,
with no safer equivalent put in its place.

Reviewed by:	brooks, kib, markj
Obtained from:	CheriBSD
Fixes:		1b1428dcc8 ("Fix a TOCTOU vulnerability in freebsd32_copyin_control().")
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D36554
2022-09-15 17:16:22 +01:00
Doug Moore
4893472c9a rb_tree: pass parent to RB_INSERT_COLOR
Change RB_COLOR_INSERT to take a parent parameter, to avoid looking up
a value already available. Make adjustments to a linux rbtree header,
which invokes it.

Reviewed by:	alc, hselasky
Differential Revision:	https://reviews.freebsd.org/D36114
2022-09-13 01:11:47 -05:00
Mateusz Guzik
3212ad15ab Add getsock
All but one consumers of getsock_cap only pass 4 arguments.
Take advantage of it.
2022-09-10 19:47:47 +00:00
Bjoern A. Zeeb
800aa9cd3d LinuxKPI: 80211 (+net80211): update and cleanup headers
Fix types for various struct fields (initially added as int).

Move structs and inline functions logically together, e.g., for wowlan.
Add more skeleton functions and #defines needed for iwlwifi d3.c
in the future.

Add struct ieee80211_vht_cap (without "_ie") to net80211 and remove
duplicate definitions in LinuxKPI headers now using net80211 structs.
For now leave ieee80211_ie_vhtcap in net80211.  I am not sure yet if we
actually need it as such.  That'll be cleaned up with more VHT updates
in net80211 in the future.

No functional changes in currently compiled code intended.

Try to implement ieee80211_action_contains_tpc() as I ran into it with
an older iwlwifi chipset.  This depends on c994352a88.

Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
2022-09-09 18:40:23 +00:00
Bjoern A. Zeeb
d6d687daaa LinuxKPI: 80211: add ieee80211_stop_tx_ba_session()
rtw89 needs ieee80211_stop_tx_ba_session().
Add the skeleton function for now so we can implement BA functions all
together.

MFC after:	3 days
2022-09-09 16:30:00 +00:00
Felix Palmen
600f161295 linuxkpi: Add non-atomic readq()/writeq()
The non-atomic versions are required by drm-510-kmod to build on 32-bit
architectures.

Approved by:		hselasky, manu, tcberner (mentor)
Differential Revision:	https://reviews.freebsd.org/D36507
2022-09-09 16:59:41 +02:00
Doug Moore
d0354fa7b6 rb_tree: reduce duplication in balancing code
Change RB_INSERT_COLOR and RB_REMOVE_COLOR so that the blocks of code
that are identical except for left and right being exchanged are made
only one block with a variable to indicate left- or right-handedness.

Rename RB macros so that those not intended for external use begin
with an underscore.

Add comments to the balancing code so that another might understand it.

Reviewed by:	alc, kib
MFC after:	3 weeks
Differential Revision:	https://reviews.freebsd.org/D36393
2022-09-07 23:46:19 -05:00
Bjoern A. Zeeb
549198b1ab LinuxKPI, dev: 80211 update mac80211 KPI
Update the mac80211 ops KPI for (*conf_tx), (*assign_vif_chanctx),
(*unassign_vif_chanctx), (*start_ap), and (*stop_ap), as well as
ieee80211_beacon_get_tim() and ieee80211_beacon_get_template().

Update in-tree drivers iwlwifi and rtw88 accordingly based on upstream
changes (as well as out-of-tree ones).  This was triggered by trying to
synchronize more drivers to a common state.

MFC after:	1 week
2022-09-07 23:38:54 +00:00
Bjoern A. Zeeb
ac07a3b8b6 LinuxKPI: netdev: expose napi state
There are drivers directly accessing napi->state testing for bits
(NAPI_STATE_SCHED encountered so far).  Rename the internal _flags
struct field to state and expose our internal state flag bits along
with the one official aliased.

As I left in a comment, I wished Linux would hide these accesses
behind inline functions or by other means and not public expose
the implementation details.

MFC after:	1 week
2022-09-07 23:35:41 +00:00
Bjoern A. Zeeb
fb3c549738 LinuxKPI: firmware: add request_partial_firmware_into_buf()
A (so far out-of-tree) driver update needs
request_partial_firmware_into_buf().  Given we load the full .ko file
using firmware(9) just do that and copy the requeste data into the
buffer (rather than poissibly only reading portions of the firmware
file).

MFC after:	1 week
2022-09-07 23:33:45 +00:00
Bjoern A. Zeeb
e3a0b1202b LinuxKPI: 80211 / iwlwifi: improve queue management
For one initialise vif->hw_queues later set in lkpi_80211_txq_tx_one()
for drivers using them.  This may still need slightly more cleanup once
we get QUEUE_CONTROL-supporting drivers into the tree.

For the other rework and improve how we deal with tid/ac/txq in
lkpi_80211_txq_tx_one() and cleanup old comments and unused code.
This seems to reduce (remove) "Invalid TXQ id" reports from iwlwifi.
(The assumption is that the frame(s) triggering this WARN_ONCE or the
added FreeBSD specific logging were sent with lkpi_80211_mo_tx()).

Adjust the one logging from e674ddec0b
to IWL_DEBUG_TX so that now this is fixed it is also not always logged
anymore but leave it in case we need to further debug queues in the
future.

Tested by:	pstef, Kevin Oberman (rkoberman gmail.com)
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-09-05 21:03:03 +00:00
Bjoern A. Zeeb
ec190d9150 LinuxKPI: 80211: improve linuxkpi_ieee80211_get_tid()
Continue what was started in 26a3694833
in iwlwifi and extend out internal implementation of
linuxkpi_ieee80211_get_tid() by an argument as to whether "no-QoS"
answers are acceptable.  For the LinuxKPI ieee80211_get_tid() set
this to false as the Linux derived drivers seem to do extra checks
for the QoS-Data frame before acquiring the tid.
Add KASSERTs to enforce the extra argument.
This allows us to use the net80211 variant in LinuxKPI for other
means explicitly documenting that we do accept a IEEE80211_NONQOS_TID.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-09-05 20:57:17 +00:00
Bjoern A. Zeeb
a486fbbd78 LinuxKPI: 80211: scanning code updates
For consistency rename LKPI_SCAN_RUNNING adding a LHW_ prefix.
Add a local flag LKPI_LHW_SCAN_HW mirroring the net80211
IEEE80211_FEXT_SCAN_OFFLOAD flag.
Slightly simplify the code.
Overload (*ic_scan_curchan) and (*ic_scan_mindwell) so that we can
call the net80211 implementation in case of software scan but skip it
in case of full-offload scans.
Also add a bandaid to our (*ic_set_channel) implementation to not siwtch
channels if we have an active hw_scan running.

Obtained from:	bz/wireless-dev
Sponsored by:	The FreeBSD Foundation (partially)
MFC after:	4 days
2022-09-03 23:40:51 +00:00
Bjoern A. Zeeb
527687a9e3 LinuxKPI: 80211: implement (*get_antenna) and set ic_[rt]xstream
Implement the mac80211 (*get_antenna) call and after checking any
antenna information present query the current configuration on startup
(both informations should be identical at this point in theory).
Both the wiphy variables and function call report a bitmask not a count.
Count the bits for net80211 for as long as we get away with just a
number in ic_[rt]xstream.

Sponsored by:	The FreeBSD Foundation
MFC after:	4 days
2022-09-03 23:11:05 +00:00
Bjoern A. Zeeb
b35f6cd066 LinuxKPI: 80211: make HW_CRYPTO compileable again
Rename TRY_HW_CRYPTO to LKPI_80211_HW_CRYPTO for consitency and make
it compileable again in case someone wants to sit down and make it
work.  It's probably not too much to do.  Otherwise I might eventually
get around to it.

Obtained from:	bz/wireless-dev
Sponsored by:	The FreeBSD Foundation
MFC after:	4 days
2022-09-03 22:51:16 +00:00
Bjoern A. Zeeb
c9b7e9df18 net80211 / drivers: rename to IEEE80211_FC0_SUBTYPE_QOS_DATA
Going through the Frame (Sub)types the "QOS Data" being called "QOS"
scheme leads to a naming conflict for QOS_CFPOLL and QOS_CFACKPOLL
(if added).   Rename QOS* to QOS_DATA* to avoid the conflict and
to also better match the standards name.

No functional changes intended.

Sponsored by:	The FreeBSD Foundation
MFC after:	5 days
Reviewed by:	hselasky
Differential Revision: https://reviews.freebsd.org/D36409
2022-09-03 21:04:13 +00:00
Tijl Coosemans
fdc1894795 linuxkpi: on i386 only use first_msi_irq if apic is in kernel config 2022-09-01 14:08:15 +02:00
Bjoern A. Zeeb
caaa79c3f8 LinuxKPI 802.11: change type of bssid in struct ieee80211_bss_conf
Enabling other driver code found that the bssid in
struct ieee80211_bss_conf is not an array but expected to be
a const pointer (const, != NULL checks).
Adjust accordingly in the header and in the LinuxKPI compat code.
There initialization now needs to be a static array always present
as we need a value before we will have a BSS (node in scan_to_auth)
as the mac80211 driver (*handlers) are expecting the pointer to be
not NULL (copying without checks).
This is a pre-req to enable d3 (CONFIG_PM[_SLEEP]) in the future.

Tested by:	Tomoaki AOKI (junchoon dec.sakura.ne.jp)
Tested by:	Berislav Purgar (bpurgar gmail.com)
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-08-27 14:54:02 +00:00
Brooks Davis
c46697b9cb freebsd32_sendmsg: fix control message ABI
When a freebsd32 caller uses all or most allowed space for control
messages (MCLBYTES == 2K) then the message may no longer fit when
the messages are padded for 64-bit alignment.  Historically we've just
shrugged and said there is no ABI guarantee.  We ran into this on
CheriBSD where a capsicumized 64-bit nm would fail when called with more
than 64 files.

Fix this by not gratutiously capping size of mbuf data we'll allocate
to MCLBYTES and let m_get2 allocate up to MJUMPAGESIZE (4K or larger).
Instead of hard-coding a length check, let m_get2 do it and check for a
NULL return.

Reviewed by:	markj, jhb, emaste
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D36322
2022-08-24 18:34:39 +01:00
Emmanuel Vadot
6364180582 linuxkpi: unbreak linux_i2cbb
This is a joint work with manu.

- fixed conditions in do_i2c_transfer and i2c_transfer as linux_i2cbb
  does not set adapter->algo->master_xfer but does set
  adapter->algo_data;
- fixed parent bus specification for linux_i2cbb driver module;
- actually implemented iicbb_transfer method;
- added iicbb_pre_xfer and iicbb_post_xfer methods;
- removed unnecessary and harmful delays (and other extra logic) from
  iicbb methods as iicbb driver already has them;
- added setting of iicbb speed based on algo_data->udelay, so that iicbb
  uses correct delays;

PR:		265920
Fixes:		1961a14a47 linuxkpi: Add i2c support
MFC after:	2 weeks
Sponsored by:	Beckhoff Automation GmbH & Co. KG (manu's work)
2022-08-24 16:23:37 +03:00
Doug Moore
02d0c43c9e rb_tree: speed-up double rotation
RB_ROTATE_LEFT (and it symmetric twin) modify the rb-tree, adjusting
pointers so that what started as a proper tree ends up a proper
tree. When two consecutive rotations move the same node up the tree,
some of the pointers changed in the first rotation are immediately
changed again in the second - namely, the pointer from the rising node
to its new parent, and the pointer from that parent back to the rising
node. This change removes from RB_ROTATE macros the responsibility for
managing those two pointers, and leaves it to the code that calls for
rotations to fix up those pointers afterward. That drops a comparison
and a pair of assignments from every INSERT_COLOR or REMOVE_COLOR call
that ends in a double rotation.

A side-effect of this change is that the SWAP_CHILD macro must take as
a parameter a pointer to the node that is changing children, where it
is now computed from the old child. Since this macro is called in a
couple of places besides the RB_ROTATE macros, those calls are also
affected.

Reviewed by:	alc
MFC after:	3 weeks
Differential Revision:	https://reviews.freebsd.org/D36266
2022-08-19 18:11:29 -05:00
Emmanuel Vadot
319a4bddb0 linuxkpi: i2c: Fix 7bit/8bit addressing
Linux is using 7 bit addressing while FreeBSD uses 8 bit addresses
internally, but i2c(8) uses 7 bit address.
This confused me when originally doing the code and I thought that
0x50 was the 8bit EDID address while it's the 7bit address and since
I did all my testing using this I didn't noticed the problem.

Reported by:	avg
PR:		265920 (somewhat)
2022-08-19 14:39:16 +02:00
Bjoern A. Zeeb
8d37116489 net80211: LinuxKPI 802.11: harmonize IEEE80211_VHT_MCS_*
Rather than defining the same values in two places and having to do
conflict resulution on the name in LKPI, change the defines to an
enum in net80211.  In addition to de-duplication this also gives us
value checks in certain cases.

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Reviewed by:	adrian
Differential Revision: https://reviews.freebsd.org/D36250
2022-08-18 20:34:30 +00:00
Bjoern A. Zeeb
4a7e8c7bd4 LinuxKPI: extend kfifo to be usable
Implement some basic kfifo pieces as needed by drivers.

MFC after:	2 weeks
Reviewed by:	wulf, hselasky
Differential Revision: https://reviews.freebsd.org/D35829
2022-08-18 20:26:20 +00:00
Emmanuel Vadot
7bf65b00c6 linuxkpi: Add I2C_NAME_SIZE and I2C_MODULE_PREFIX defines
Both are needed by drm-kmod

Obtained from:	drm-kmod
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	//reviews.freebsd.org/D36212
2022-08-18 09:47:19 +02:00
Emmanuel Vadot
4b4ab8c310 linuxkpi: Add linux/vgaarb.h
Needed by drm-kmod.

Reviewed by:	bz
Obtained from:	Linux
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36104
2022-08-18 09:47:15 +02:00
Emmanuel Vadot
73e342328b linuxkpi: Add video/mipi_display.h
Needed by drm-kmod.

Reviewed by:	bz
Obtained from:	OpenBSD
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36103
2022-08-18 09:47:12 +02:00
Emmanuel Vadot
afe53d7f7a linuxkpi: acpi/video.h: Add stubs acpi_video_{register,unregister}
Needed by i915.

Reviewed by:	bz
Obtained from:	drm-kmod
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36102
2022-08-18 09:47:07 +02:00
Emmanuel Vadot
76d93395c5 linuxkpi: Add __copy_to_user_inatomic and __copy_from_user_inatomic
Reviewed by:	bz
Obtained from:	drm-kmod
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36113
2022-08-18 09:47:04 +02:00
Emmanuel Vadot
bf27839aa9 linuxkpi: Add add_taint stub
Needed by drm-kmod.

Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36112
2022-08-18 09:47:00 +02:00
Emmanuel Vadot
4b2cb13e91 linuxkpi: Add few more include in linux/kernel.h
Those are needed and also included in linux (via polution).

Reviewed by:	bz
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36111
2022-08-18 09:46:57 +02:00
Emmanuel Vadot
d4eeb02986 linuxkpi: Add a bunch of dummy include
All those are needed for drm-kmod.
Add them to base in another directory that will be append in the CFLAGS.

Reviewed by:	bz
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36110
2022-08-18 09:46:54 +02:00
Emmanuel Vadot
6d3d565316 linuxkpi: swap.h: Fix include
Add needed includes so we can use it.

Reviewed by:	bz
Fixes:	c3f4f28c63 ("linuxkpi: Add some basic swap functions")
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36109
2022-08-18 09:46:50 +02:00
Emmanuel Vadot
35b7625ed0 linuxkpi: Add stub kmem_cache_shrink
Needed by drm-kmod.

Reviewed by:	bz
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36108
2022-08-18 09:46:47 +02:00
Emmanuel Vadot
b2c860060c linuxkpi: Add asm/processor.h
Also fill the boot_cpu_data struct as drm needs it.

Reviewed by:	bz
Obtained from:	drm-kmod
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36107
2022-08-18 09:46:43 +02:00
Emmanuel Vadot
9202c95f47 linuxkpi: Add dma_{un,}map_sgtable
Variant of dma_{un,}map_sg_attrs for struct sg_table.

Reviewed by:	bz
Obtained from:	drm-kmod
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36106
2022-08-18 09:46:40 +02:00
Emmanuel Vadot
b1c82bd402 linuxkpi: Add linux/stackdepot.h
With a typedef needed by drm-kmod.

Reviewed by:	bz
Obtained from:	drm-kmod
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36105
2022-08-18 09:46:36 +02:00
Emmanuel Vadot
fd62b3fa1e linuxkpi: pgtable: Add more defines
Needed by drm-kmod

Reviewed by:	bz
Obtained from:	drm-kmod
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36101
2022-08-18 09:46:33 +02:00
Emmanuel Vadot
8828ebd6fc linuxkpi: Add sched/mm.h
With stubs needed by drm-kmod.

Obtained from:	drm-kmod
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36100
2022-08-18 09:46:29 +02:00
Emmanuel Vadot
1a6874e3a4 linuxkpi: Add refcount_dec_and_test
In Linux this takes a refcount_t argument but in linuxkpi struct kref
uses an atomic_t for the refcount and code in drm directly uses this
function with a kref so use an atomic_t here.

Reviewed by:	bz
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36099
2022-08-18 09:46:25 +02:00
Emmanuel Vadot
4370e9f1cf linuxkpi: Add for_each_sgtable_{sg,page}
Needed by drm-kmod.

Reviewed by:	bz
Obtained from:	drm-kmod
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36098
2022-08-18 09:46:22 +02:00
Gleb Smirnoff
e7d02be19d protosw: refactor protosw and domain static declaration and load
o Assert that every protosw has pr_attach.  Now this structure is
  only for socket protocols declarations and nothing else.
o Merge struct pr_usrreqs into struct protosw.  This was suggested
  in 1996 by wollman@ (see 7b187005d1), and later reiterated
  in 2006 by rwatson@ (see 6fbb9cf860).
o Make struct domain hold a variable sized array of protosw pointers.
  For most protocols these pointers are initialized statically.
  Those domains that may have loadable protocols have spacers. IPv4
  and IPv6 have 8 spacers each (andre@ dff3237ee5).
o For inetsw and inet6sw leave a comment noting that many protosw
  entries very likely are dead code.
o Refactor pf_proto_[un]register() into protosw_[un]register().
o Isolate pr_*_notsupp() methods into uipc_domain.c

Reviewed by:		melifaro
Differential revision:	https://reviews.freebsd.org/D36232
2022-08-17 11:50:32 -07:00
Konstantin Belousov
00d17cf342 elf_note_prpsinfo: handle more failures from proc_getargv()
Resulting sbuf_len() from proc_getargv() might return 0 if user mangled
ps_strings enough. Also, sbuf_len() API contract is to return -1 if the
buffer overflowed. The later should not occur because get_ps_strings()
checks for catenated length, but check for this subtle detail explicitly
as well to be more resilent.

The end result is that p_comm is used in this situations.

Approved by:	so
Security:	FreeBSD-SA-22:09.elf
Reported by:	Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
Reviewed by:	delphij, markj
admbugs:	988
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D35391
2022-08-09 15:44:45 -04:00
Emmanuel Vadot
521abc32e2 linuxkpi: io.h: Only exclude armv6 and armv7 for asm/set_memory.h
Other arches like powerpc* needs it.

Fixes:  d387a1b4b1 ("linuxkpi: io.h: Do not include asm/set_memory.h for armv6 and armv7")
Fixes:  789dbdbb48 ("linuxkpi: Add arch_io_{reserve,free}_memtype_wc")
Sponsored by:	Beckhoff Automation GmbH & Co. KG
2022-08-08 20:22:44 +02:00
Emmanuel Vadot
d387a1b4b1 linuxkpi: io.h: Do not include asm/set_memory.h for armv6 and armv7
They do not have the same pmap api and this cannot work for those arch.

Fixes:	789dbdbb48 ("linuxkpi: Add arch_io_{reserve,free}_memtype_wc")
Sponsored by:	Beckhoff Automation GmbH & Co. KG
2022-08-08 18:55:58 +02:00
Konstantin Belousov
1b0a4974c5 thread_create(): call cpu_copy_thread() after td_pflags is zeroed
By calling the function too early we might still have the td_pflags
value cached from the previous struct thread use. cpu_copy_thread()
depends on correct value for TDP_KTHREAD at least on x86.

Reported, bisected, and tested by:	pho
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D36069
2022-08-08 19:44:17 +03:00
Emmanuel Vadot
2ff0f05149 linuxkpi: pm: Add more defines and includes
Needed by drm-kmod.

Reviewed By:	emaste, hselasky
Obtained from:	drm-kmod
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36024
2022-08-08 15:22:36 +02:00
Emmanuel Vadot
b829f450a7 linuxkpi: Include highmem.h in pagemap.h
Linux does the same.

Reviewed by:	bz, emaste, hselasky
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36023
2022-08-08 15:22:36 +02:00
Emmanuel Vadot
789dbdbb48 linuxkpi: Add arch_io_{reserve,free}_memtype_wc
Reviewed by:	hselasky
Obtained from:	drm-kmod
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36022
2022-08-08 15:22:36 +02:00
Emmanuel Vadot
a7727e1a6d linuxkpi: Add dev_info_once
Obtained from:	drm-kmod
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36021
2022-08-08 15:22:36 +02:00
Emmanuel Vadot
eca2f0f380 linuxkpi: Add smp_mb__before/after_atomic
Reviewed by:	hselasky
Obtained from:	drm-kmod
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36020
2022-08-08 15:22:35 +02:00
Emmanuel Vadot
d1c3cfd79d linuxkpi: Add trylock_page and unlock_page
Simple wrapper around vm_page_trylock and vm_page_unlock.

Reviewed by:	hselasky
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36019
2022-08-08 15:22:35 +02:00
Emmanuel Vadot
7d2702a198 linuxkpi: Add more notifier defines
Needded by drm-kmod.

Reviewed by:	bz, emaste, hselasky
Obtained from:	drm-kmod
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36018
2022-08-08 15:22:35 +02:00
Emmanuel Vadot
2d4b17685f linuxkpi: errno: Add EHWPOISON
Needed by drm-kmod.

Reviewed by:	bz, hselasky
Obtained from:	drm-kmod
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36017
2022-08-08 15:22:35 +02:00
Emmanuel Vadot
37cda2837c linuxkpi: Add compat_ptr and ptr_to_compat
Needed by drm-kmod.

Obtained from:	drm-kmod
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36016
2022-08-08 15:22:35 +02:00
Emmanuel Vadot
39da3678b1 linuxkpi: Add try_cmpxchg and atomic_try_cmpxchg
Needed by drm-kmod

Obtain from:	drm-kmod
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36015
2022-08-08 15:22:35 +02:00
Emmanuel Vadot
fa1f02baaf linuxkpi: Add some memset functions
Needed by drm-kmod

Obtained from:	OpenBSD
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D35943
2022-08-08 15:22:35 +02:00
Emmanuel Vadot
96b917bfcf linuxkpi: Add io.h
out* arguments are different on Linux and the i915 driver uses them.

Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D35942
2022-08-08 15:22:35 +02:00
Emmanuel Vadot
a0c171328f linuxkpi: Add pagevec implementation
Needed by drm-kmod.

Reviewed by:	hselasky
Obtained from:	OpenBSD
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D35941
2022-08-08 15:22:35 +02:00
Emmanuel Vadot
aec6a64c68 linuxkpi: Add linux/nospec.h
Needed by drm-kmod.

Reviewed by:	hselasky
Obtained from:	OpenBSD
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D35940
2022-08-08 15:22:35 +02:00
Emmanuel Vadot
4aa82e4358 linuxkpi: Add mapping_clear_unevictable stub
Reviewed by:	hselasky
Obtained from:	drm-kmod
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D35939
2022-08-08 15:22:34 +02:00
Emmanuel Vadot
6890e327a8 linuxkpi: pci: Add more functions needed by drm
Mostly stubs to satisfy building

Reviewed by:	hselasky
Obtained from:	drm-kmod
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D35938
2022-08-08 15:22:34 +02:00
Emmanuel Vadot
885ab0dba2 linuxkpi: math.h: Add mul_u64_u32_div and mul_u64_u32_shr
Needed by drm-kmod.

Reviewed by:	hselasky
Obtained from:	OpenBSD
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D35937
2022-08-08 15:22:34 +02:00
Emmanuel Vadot
6be89cc88d linuxkpi: atomic: Add atomic_fetch_inc
Reviewed by:	hselasky
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D35936
2022-08-08 15:22:34 +02:00
Konstantin Belousov
f04f3afbf5 linuxkpi: more precise need_resched() definition
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D35888
2022-08-02 21:11:10 +03:00
Konstantin Belousov
c6d31b8306 AST: rework
Make most AST handlers dynamically registered.  This allows to have
subsystem-specific handler source located in the subsystem files,
instead of making subr_trap.c aware of it.  For instance, signal
delivery code on return to userspace is now moved to kern_sig.c.

Also, it allows to have some handlers designated as the cleanup (kclear)
type, which are called both at AST and on thread/process exit.  For
instance, ast(), exit1(), and NFS server no longer need to be aware
about UFS softdep processing.

The dynamic registration also allows third-party modules to register AST
handlers if needed.  There is one caveat with loadable modules: the
code does not make any effort to ensure that the module is not unloaded
before all threads processed through AST handler in it.  In fact, this
is already present behavior for hwpmc.ko and ufs.ko.  I do not think it
is worth the efforts and the runtime overhead to try to fix it.

Reviewed by:	markj
Tested by:	emaste (arm64), pho
Discussed with:	jhb
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D35888
2022-08-02 21:11:09 +03:00
Bjoern A. Zeeb
d8dd6b329e LinuxKPI: 802.11: add missing linuxkpi_cfg80211_bss_flush()
Add the missing implementation of linuxkpi_cfg80211_bss_flush().
without this we get unresolved symbols and drivers won't load.

Reported by:	eduardo, Berislav Purgar (bpurgar gmail.com)
MFC after:	3 days
X-MFC-Squash:	b0f7376822
2022-07-30 14:23:14 +00:00
Bjoern A. Zeeb
b0f7376822 LinuxKPI: 802.11 header updates
While working on new and updates to drivers more structs, fields,
functions, .. were found, had to be shuffled around, ..
Some of these are (so far still dummy) functions or not properly
typed fields.  The IEEE80211_HE_ constants are all still dummy.
This was msotly as a start to make new (out-of-tree) things compile.

Sponsored by:	The FreeBSD Foundation (minor VHT/chan width bits)
MFC after:	1 week
2022-07-29 15:23:49 +00:00
Bjoern A. Zeeb
89c32dafa5 LinuxKPI: skbuff: sort list header and add new (dummy) functions
While working on new and updates to drivers more skbuff changes
came up.  Sort out the list/prev/next header problem and add more
(so far dummy) functions needed.

MFC after:	1 week
2022-07-29 15:21:48 +00:00
Bjoern A. Zeeb
467d3e2e8a LinuxKPI 802.11/iwlwifi/rtw88: update KPI
Upgrade the argument of (*bss_info_changed) mac80211 ops function call
from 32 to 64 bit.
Add an extra argument to ieee80211_beacon_get_template().

Both changes are needed in order to keep other out-of-tree drivers in
synch and to move forward.

The driver changes were extracted from Linux wireless-testing
7b7090b4c6a906cc7c3e2a460335f705b93f4506 and
6e8912a503759bb8f1f01c5b761d0d45815fa6de.

Sponsored by:	The FreBSD Foundation
MFC after:	1 week
2022-07-28 23:39:03 +00:00
Dimitry Andric
e90d1b5748 Adjust linux_get_char_devices() definition to avoid clang 15 warning
With clang 15, the following -Werror warning is produced:

    sys/compat/linux/linux_util.c:243:23: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    linux_get_char_devices()
                          ^
                           void

This is because linux_get_char_devices() is declared with a (void)
argument list, but defined with an empty argument list. Make the
definition match the declaration.

MFC after:	3 days
2022-07-25 00:40:13 +02:00
Kornel Dulęba
939f0b6323 Implement shared page address randomization
It used to be mapped at the top of the UVA.
If the randomization is enabled any address above .data section will be
randomly chosen and a guard page will be inserted in the shared page
default location.
The shared page is now mapped in exec_map_stack, instead of
exec_new_vmspace. The latter function is called before image activator
has a chance to parse ASLR related flags.
The KERN_PROC_VM_LAYOUT sysctl was extended to provide shared page
address.
The feature is enabled by default for 64 bit applications on all
architectures.
It can be toggled kern.elf64.aslr.shared_page sysctl.

Approved by:	mw(mentor)
Sponsored by:	Stormshield
Obtained from:	Semihalf
Reviewed by:	kib
Differential Revision: https://reviews.freebsd.org/D35349
2022-07-18 16:27:37 +02:00
Kornel Dulęba
361971fbca Rework how shared page related data is stored
Store the shared page address in struct vmspace.
Also instead of storing absolute addresses of various shared page
segments save their offsets with respect to the shared page address.
This will be more useful when the shared page address is randomized.

Approved by:	mw(mentor)
Sponsored by:	Stormshield
Obtained from:	Semihalf
Reviewed by:	kib
Differential Revision: https://reviews.freebsd.org/D35393
2022-07-18 16:27:32 +02:00
Gordon Bergling
d3d3b76c1b linux(4): Fix a typo in a source code comment
- s/alredy/already/

MFC after:	3 days
2022-07-16 13:39:17 +02:00
Mark Johnston
6b38974085 vm_object: Modify various drivers to allocate OBJT_SWAP objects
This is in preparation for removal of OBJT_DEFAULT.  In particular, it
is now cheap to check whether an OBJT_SWAP object has any swap blocks
allocated, so the benefit of having a separate OBJT_DEFAULT type is
quite marginal, and the OBJT_DEFAULT->SWAP transition is a source of
bugs.

Reviewed by:	alc, hselasky, kib
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D35779
2022-07-12 09:10:15 -04:00
Dmitry Chagin
42317e6426 linux(4): Implement __vdso_time
PR:		240769
MFC after:	3 days
2022-07-04 23:41:32 +03:00
Emmanuel Vadot
2b743f65f1 linuxkpi: Add pwm.h
Provide dummy functions needed for drm-kmod.

Reviewed by:	bz
MFC after:      1 week
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D35572
2022-06-29 09:55:26 +02:00
Emmanuel Vadot
0e45856f9a linuxkpi: Add asm/set_memory.h
Provide functions needed for drm-kmod.

MFC after:      1 week
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D35571
2022-06-29 09:55:23 +02:00
Emmanuel Vadot
137e91dbf6 linuxkpi: Add asm/iosfmbi.h
Provide dummy functions needed for drm-kmod.

Obtain from:	OpenBSD (via drm-kmod)
MFC after:      1 week
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D35570
2022-06-29 09:55:19 +02:00
Emmanuel Vadot
631bf94fe9 linuxkpi: Add typecheck.h
typecheck macro check if the type of a variable matches a type.

MFC after:      1 week
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D35569
2022-06-29 09:55:15 +02:00
Emmanuel Vadot
456a92d5d3 linuxkpi: Add pm_runtime.h
Provide dummy functions needed for drm-kmod.

Obtain from:	OpenBSD (via drm-kmod)
MFC after:      1 week
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D35568
2022-06-29 09:55:12 +02:00
Emmanuel Vadot
cfe72b9f09 linuxkpi: Add mmu_notifier.h
Provide dummy structure needed for drm-kmod.

MFC after:      1 week
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D35567
2022-06-29 09:55:08 +02:00
Emmanuel Vadot
a95f28800a linuxkpi: Add mmu_context.h
Provide dummy functions needed for drm-kmod.

Reviewed by:	bz
MFC after:      1 week
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D35566
2022-06-29 09:55:04 +02:00
Emmanuel Vadot
7e4f9ebeaa linuxkpi: Add media-bus-format.h
Provide macros needed for drm-kmod.

Obtain from:	OpenBSD (via drm-kmod)
MFC after:      1 week
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D35565
2022-06-29 09:55:00 +02:00
Emmanuel Vadot
8730ba418e linuxkpi: Add kmemleak.h
Provide macros needed for drm-kmod.

Obtain from:	OpenBSD (via drm-kmod)
MFC after:      1 week
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D35564
2022-06-29 09:54:57 +02:00
Emmanuel Vadot
088b746cbd linuxkpi: Add kfifo.h
Provide macros needed for drm-kmod.

Reviewed by:	bz
MFC after:      1 week
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D35563
2022-06-29 09:54:53 +02:00
Emmanuel Vadot
57c9ec539c linuxkpi: Add console.h
Provide dummy functions needed for drm-kmod.

Reviewed By:	bz
MFC after:      1 week
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D35562
2022-06-29 09:54:49 +02:00
Emmanuel Vadot
7674baeb37 linuxkpi: Add circ_buf.h
Provide macros needed for drm-kmod.

Reviewed by:	bz
MFC after:	1 week
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D35561
2022-06-29 09:54:45 +02:00
Dmitry Chagin
c8e7070ce3 linprocfs: Decode SGX CPU feature in cpuinfo
MFC after:		2 weeks
2022-06-29 10:37:52 +03:00
Dmitry Chagin
7ab03740ae linprocfs: Decode more CPU flags in cpuinfo
Differential revision:	https://reviews.freebsd.org/D35556
MFC after:		2 weeks
2022-06-29 10:37:30 +03:00
Dmitry Chagin
8da00a514e linprocfs: Decode constant_tsc CPU feature
Differential revision:	https://reviews.freebsd.org/D35554
MFC after:		2 weeks
2022-06-29 10:34:04 +03:00
Bjoern A. Zeeb
841719c08f LinuxKPI: 802.11: remove an early bandaid to make sure queues are allocated
iwlwifi allocates queues on first wakeup.  This takes a lot longer on
FreeBSD's work implementation that it seems to on Linux based on some
discussion.  That meant that we couldn't get non-data frames out quickly
enough initially and failed to associate.
d0d2911035 should have solved most of this
for us with iwlwifi.  None of the other drivers ported to LinuxKPI/802.11
up to today will call a dequeue so we get notified when the queus are
allocated or even need to do so.
Remove the bandaid initilly put in for iwlwifi now and speed up the
overall process of getting us associated.

MFC after:	3 days
2022-06-26 19:17:04 +00:00
Bjoern A. Zeeb
e24e8103e0 LinuxKPI: 802.11: cleanup lsta better
This changes cleans up lsta from the VIF station list as well as
deals with freeing the lsta itself so it is not leaked.

lkpi_iv_update_bss() makes this more complicated than it should be
as we ties more sta state (incl. drv/fw) to the node that net80211
does not know about.  There is more work to be done detangling this
now that is better understood.

MFC after:	3 days
2022-06-26 19:13:00 +00:00
Bjoern A. Zeeb
ed3ef56b29 LinuxKPI: 802.11: sync sta->addr in lkpi_iv_update_bss()
In lkpi_iv_update_bss() introduced in d9f59799fc we swap lsta and
along with that sta and drv state if ni gets reused and swapped under
us by net80211.  What we did not do was to sync sta->addr which later
(usually in lkpi_sta_assoc_to_run) during a bss_info update cause
problems in drivers (or firmware) as the BSSID and the station address
were not aligned.

If this proves to hold up to fix iwlwifi issues seem on firmware
for older chipsets, multi-assoc runs, and rtw89 (which this fixes)
we should add asserts that lkpi_iv_update_bss() can only happen in
pre-auth stages and/or make sure we factor out synching more state
fields.

Found debugging:	rtw89
MFC after:		3 days
2022-06-26 19:04:16 +00:00
Bjoern A. Zeeb
9597f7cb99 Revert "LinuxKPI: 802.11: fix iwlwifi fw assert with older chipsets"
This reverts commit 013e516dc9.
2022-06-26 18:50:36 +00:00
Dmitry Chagin
ef1976ccf5 linprocfs: Skip printing of the guard page in the /proc/self/maps
To calculate the base (lowest addressable) address of the stack of the
initial thread glibc parses /proc/self/maps.
In fact, the base address is calculated as 'to' value of stack entry of the
/proc/self/maps - stack size limit (if the stack grows down).
The base address should fit in between preceding entry and stack entry of
the /proc/self/maps.
In FreeBSD, since 19bd0d9 (Implement address space guards), we actually
have two mappings for the stack region. The first one is the no-access
mapping for the region the stack can grow into (guard page), and the
second - initial stack region with size sgrowsiz.
The first mapping confuses Glibc, in the end which is improperly
calculate stack size and the base address.

PR:			253337
Reviewed by:		kib
Differential revision:	https://reviews.freebsd.org/D35537
MFC after:		2 week
2022-06-22 14:49:40 +03:00
Dmitry Chagin
9310737333 linux(4): Trace Linux l_sigset_t.
MFC after:		2 weeks
2022-06-22 14:09:54 +03:00
Greg V
8870cb573f LinuxKPI: add asm/neon.h
This is equivalent to asm/fpu/api.h, but is included by drm on aarch64.

Reviewed by:	bz, imp, hselasky
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D35512
2022-06-21 19:10:43 +02:00
Bjoern A. Zeeb
4c3684ef5c net80211 / LinuxKPI: 802.11: add Control Trigger Subframe information
Add definitions related to 802.11ax Control Trigger frame format
needed for rtw89.

MFC after:	3 days
2022-06-17 22:55:13 +00:00
Bjoern A. Zeeb
799051e2ca LinuxKPI: 802.11: ieee80211_start_tx_ba_session()
For as long as we do not implement the compat code for tx aggregation
return -EINVAL in ieee80211_start_tx_ba_session() as both rtw88 and
rtw89 check for this value and only then disable further attempts.

MFC after:	3 days
2022-06-15 21:05:33 +00:00
Emmanuel Vadot
d87fad3633 linuxkpi: Acquire giant when adding/removing i2c adapters
We need Giant as we run in a taskqueue_thread via linux_work.
This fix detaching amdgpu and i915kms.

Reviewed by:	bz, hselasky, imp
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D35478
2022-06-15 13:37:43 +02:00
Bjoern A. Zeeb
fb6eaf74e9 LinuxKPI: 802.11: fix compiling with DEBUG
Fix a build with DEBUG after d0d2911035
which lost the __func__, __LINE__ argument in an updated tracing line.

Reported by:	Tomoaki AOKI (junchoon dec.sakura.ne.jp)
MFC after:	2 days
X-MFC with:	d0d2911035
2022-06-11 16:38:00 +00:00
Bjoern A. Zeeb
013e516dc9 LinuxKPI: 802.11: fix iwlwifi fw assert with older chipsets
A problem which showed up on 13.1 between BETA3 and RC1 was that on older
chipsets the fw would crash.  While some 0x18 ADD_STA problems were seen
before, d9f59799fc was the actual trigger for this problem
(in 0x28 MAC_CONTEXT command) in a squashed merge to the releng branch.
Strangely there were no changes to assoc_to_run in that revision so other
circumstances may be the actual cause but swapping the bss_info update and
the sta_state in that function seem to make my 8265 happy while AX200 and
AX210 stay good.

Thanks to everyone who helped debug this.

Sponsored by:	The FreeBSD Foundation (partially)
MFC after:	3 days
2022-06-11 12:49:40 +00:00
Bjoern A. Zeeb
d0d2911035 LinuxKPI: 802.11: rework handling of the special IEEE80211_NUM_TIDS queue
Rework the way we are dealing with the last queue.  If the driver
opts in to STA_MMPDU_TXQ then preferably send all non-data frames
via the last (IEEE80211_NUM_TIDS) queue which otherwise is not used
in station mode.
If we do not have that queue we do individual tx() calls for non-data
frames now.
Everything else goes via the selected queue if possible for as long as
we have a ni (sta) and otherwise resorts to direct tx.

Tested on:	Intel AX200 and AX210
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-06-10 14:18:57 +00:00
Bjoern A. Zeeb
0e981d79b1 LinuxKPI: move pm_message_t from kernel.h to pm.h
Move pm_message_t from kernel.h to pm.h and remove a private define
in usb.h as well as adjust the implementation in linux_usb.c.
This cleans up what I believe to be a historic shortcut and is
needed for future wireless driver updates.

Leave a note in UPDATING that drm-kmod users need to update to the
latest version before re-compiling a new kernel to avoid errors
(see PR).

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
PR:		264449 (drm-kmod port update, thanks wulf)
Obtained from:	bz_git_iwlwifi (Dec 2020) (partly)
Reviewed by:	hselasky, imp
Differential Revision: https://reviews.freebsd.org/D35276
2022-06-10 14:05:12 +00:00
Hans Petter Selasky
85d7875d42 LinuxKPI: Fix dmi_matches() function
Make sure to check for NULL pointers and also check all search criterias,
not only the first one!

Bump the FreeBSD version.

Reviewed by:	manu@
Differential Revision:	https://reviews.freebsd.org/D35403
MFC after:	1 week
Sponsored by:	NVIDIA Networking
2022-06-06 10:31:34 +02:00
Bjoern A. Zeeb
71df58aefc LinuxKPI: 802.11: plug a ni leak in lkpi_sta_assoc_to_run()
In lkpi_sta_assoc_to_run() we are going through some code segments
twice (auth->assoc, assoc->authorized).  The 2nd time we shall not
re-gain a reference on the net80211 node as otherwise it'll leak.
Likewise we do not have to re-set lsta and sta.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-06-05 21:12:55 +00:00
Bjoern A. Zeeb
dbc06dd98a LinuxKPI: 802.11 plug mbuf leak in error cases
Manually free the mbuf in certain error cases from net80211 to not
leak it.
Note that the differences between ieee80211_input_mimo() and
ieee80211_input_mimo_all(), the former not consuming the mbuf while
the later does, is confusing.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-06-05 18:10:24 +00:00
Gordon Bergling
8cf0d09462 linux(4): Fix a typo in a source code comment
- s/accross/across/

MFC after:	3 days
2022-06-04 11:27:19 +02:00
Corvin Köhne
99902b1c52 linuxkpi/dmi: don't match exactly on DMI_MATCH
Linux has two defines to check dmi data. DMI_MATCH checks if the dmi
string includes substr. DMI_EXACT_MATCH checks if the dmi string exactly
matches substr. Compat layer should have the same behaviour.

The new definition of dmi_strmatch shouldn't break any driver. A driver
would break if it uses the highest bit of the slot field. Nevertheless,
linux uses the same definition and FreeBSD uses dmi_field values as slot
which are lower than 128.

Sponsored by:		Beckhoff Automation GmbH & Co. KG
MFC after:		1 week
Differential Revision:	https://reviews.freebsd.org/D35395
2022-06-03 16:20:45 +02:00
Dmitry Chagin
539fadb493 linux(4): Return EINVAL when the clockid has invalid bits are set
Linux forbids PERTHREAD bit set for CLOCKFD clock.

MFC after:		2 weeks
2022-05-31 11:46:15 +03:00
Dmitry Chagin
452f4636c3 linux(4): Return ENOTSUP for unsupported clockid
It's much better from the user perspective to get a sane error code.

MFC after:		2 weeks
2022-05-31 11:43:00 +03:00
Dmitry Chagin
7e2a451119 linprocfs: Add /proc/vm/max_map_count
On Linux this limits the number of maps per mm struct.
We don't limit mappings, return a suitable large value.

Reviewed by:		emaste
Differential revision:	https://reviews.freebsd.org/D35351
MFC after:		2 weeks
2022-05-31 11:42:06 +03:00
Dmitry Chagin
2722e515ac linux(4): Prefer sizeof(object) vs sizeof(type)
MFC after:		2 weeks
2022-05-30 20:03:14 +03:00
Dmitry Chagin
5573143777 linux(4): Error is not a bool, use proper comparison
MFC afer:		2 weeks
2022-05-30 20:00:30 +03:00
Dmitry Chagin
5e872c279a linux(4): Use the copyin_sigset() in the remaining places
MFC after:		2 weeks
2022-05-30 19:59:45 +03:00
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
Dmitry Chagin
5326ebfd05 linux(4): Revert c7ef7c3 as it's wrong at all.
Reported by:		trasz
2022-05-11 21:00:54 +03:00
Dmitry Chagin
f35093f8d6 Use Linux semantics for the thread affinity syscalls.
Linux has more tolerant checks of the user supplied cpuset_t's.

Minimum cpuset_t size that the Linux kernel permits in case of
getaffinity() is the maximum CPU id, present in the system / NBBY,
the maximum size is not limited.
For setaffinity(), Linux does not limit the size of the user-provided
cpuset_t, internally using only the meaningful part of the set, where
the upper bound is the maximum CPU id, present in the system, no larger
than the size of the kernel cpuset_t.
Unlike FreeBSD, Linux ignores high bits if set in the setaffinity(),
so clear it in the sched_setaffinity() and Linuxulator itself.

Reviewed by:		Pau Amma (man pages)
In collaboration with:	jhb
Differential revision:	https://reviews.freebsd.org/D34849
MFC after:		2 weeks
2022-05-11 10:36:01 +03:00
Dmitry Chagin
109c2bd212 linux(4); Style.
MFC after:		2 weeks
2022-05-09 21:16:48 +03:00
Dmitry Chagin
07d108932a linux(4): Return native error from futex_atomic_op to avoid conversion by the caller.
MFC after:		2 weeks
2022-05-09 21:16:31 +03:00
Dmitry Chagin
b17446281d linux(4): Fixed offset miscalculation in the preadv/pwritev syscalls.
MFC after:		2 weeks
2022-05-09 21:11:37 +03:00
Dmitry Chagin
5eec19c8eb linux(4): The futex_wait operation should restart.
It's ok from the futex_wait perspective as umtxq_sleep method uses
absolute sleep timeout.

MFC after:		2 weeks
2022-05-09 21:08:59 +03:00
Dmitry Chagin
c6df217603 linux(4): Use the right function to get the bit index in vdso binuptime.
This is modeled after a1f93266 (by kib@).

MFC after:		2 weeks
2022-05-08 17:20:52 +03:00
Dmitry Chagin
5a6a4fb284 linux(4): Implement vdso getcpu for x86.
This is modeled after f2395455 (by kib@).

MFC after:		2 weeks
2022-05-08 17:20:52 +03:00
Dmitry Chagin
707e567a40 linux(4): Add a helper intended for copying timespec's from the userspace.
There are many places where we copyin Linux timespec from the userspace
and then convert it to the kernel timespec. To avoid code duplication
add a tiny halper for doing this.

MFC after:		2 weeks
2022-05-08 16:16:47 +03:00
Dmitry Chagin
3dc2a06752 linux(4): Prevent time_t overflows on i386.
As native i386 time_t is still 32-bit, check that the user-provided 64-bit
tv_sec value fits to the kernel time_t, return EOVERFLOW if not.

MFC after:		2 weeks
2022-05-08 15:39:09 +03:00
Dmitry Chagin
1579b320f1 linux(4): Zero out high order bits of nanoseconds in the compat mode.
Assuming the kernel would use random data, the 64-bit Linux kernel ignores
upper 32 bits of tv_nsec of struct timespec64 for 32-bit binaries.

MFC after:		2 weeks
2022-05-08 15:38:19 +03:00
Dmitry Chagin
9a9482f874 linux(4): Add a helper intended for copying timespec's to the userspace.
There are many places where we convert natvie timespec and copyout it to
the userspace. To avoid code duplication add a tiny halper for doing this.

MFC after:		2 weeks
2022-05-08 15:37:27 +03:00
John Baldwin
a65d077437 linuxkpi: Remove unused devclass arguments to DRIVER_MODULE. 2022-05-06 15:46:58 -07:00
John Baldwin
676ea8e177 Remove unused iicbus_devclass. 2022-05-06 15:39:30 -07:00
John Baldwin
8c13dd83a3 Remove unused iicbb_devclass. 2022-05-06 15:39:30 -07:00
Dmitry Chagin
3245a2ecea linux(4): Implement semtimedop syscalls.
On i386 are two semtimedop. The old one is called via multiplexor and
uses 32-bit timespec, and new semtimedop_tim64, which is uses 64-bit
timespec.

MFC after:		2 weeks
2022-05-06 20:02:59 +03:00
Dmitry Chagin
f48a68874b linux(4): Retire linux_semop implementation.
In i386 Linux semop called via ipc() multiplexor, so use kern_semop
directly from multiplexor.

MFC after:		2 weeks
2022-05-06 20:00:13 +03:00
Bjoern A. Zeeb
6a50157090 LinuxKPI: skbuff: add memlimit tunable for 64bit systems
Some drivers, such as Realtek's rtw88, require 32bit DMA in
a single segment.  busdma(9) has a hard time providing this
currently for 3-ish pages at large quantities
(see lkpi_pci_nseg1_fail in linux_pci.c e86707418c).
Work around this for now by allowing a tunable to enforce
physical addresses allocation limits on 64bit platforms (ignoring PAE)
using "old-school" contigmalloc(9) to avoid bouncing.

A patch needing a custom kernel compiled was tested in the last weeks
by rtw88 users providing the 32bit limit only hardcoded.  The 36bit
limit can be found in iwlwifi so is added as a testing option along.

This is put in as a bandaid for now, so people no longer need to patch
and compile their own kernels to use rtw88 and to allow us to MFC the
driver as well before the amounts of commits to track increases by
much more.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-05-05 20:54:44 +00:00
Dmitry Chagin
1744f14e26 linux(4): Implement recvmmsg_time64 syscall.
MFC after:		2 weeks
2022-05-04 13:06:53 +03:00
Dmitry Chagin
ce9f8d6ab0 linux(4): Implement timerfd_gettime64 syscall.
MFC after:		2 weeks
2022-05-04 13:06:52 +03:00
Dmitry Chagin
b1f0b08d93 linux(4): Implement timerfd_settime64 syscall.
MFC after:		2weeks
2022-05-04 13:06:50 +03:00
Dmitry Chagin
a1fd2911dd linux(4): Implement timer_settime64 syscall.
MFC after:		2 weeks
2022-05-04 13:06:49 +03:00
Dmitry Chagin
783c1bd8cb linux(4): Implement timer_gettime64 syscall.
MFC after:		2 weeks
2022-05-04 13:06:48 +03:00
Dmitry Chagin
8c84ca657b linux(4): Implement sched_rr_get_interval_time64 syscall.
MFC after:		2 weeks
2022-05-04 13:06:47 +03:00
Bjoern A. Zeeb
00614c9c2d LinuxKPI: 802.11: fill in two more TODOs
Implement ieee80211_is_data_present() and a subset of
ieee80211_is_bufferable_mmpdu() which hopefully is good enough in
the compat code for now.
This is partly in preparation for some TXQ changes coming up soon.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-04-30 08:00:04 +00:00
Bjoern A. Zeeb
3540911bfd LinuxKPI: 802.11: use ieee80211_beacon_miss()
In ieee80211_beacon_loss() call into net80211::ieee80211_beacon_miss()
rather than manually bouncing our state.  That should give us the
ability to send a probereq and see if the AP is till there rather than
right away going to scan.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-04-30 07:57:34 +00:00
Dmitry Chagin
e00aad1042 linux(4): Add epoll_pwai2 syscall.
MFC after:	2 weeks
2022-04-26 19:35:59 +03:00
Dmitry Chagin
3923e63209 linux(4): Add copyin_sigset() helper.
MFC after:	2 weeks
2022-04-26 19:35:57 +03:00
Dmitry Chagin
27a25179c8 linux(4): Add linux_epoll_pwait_ts() helper for future use.
MFC after:	2 weeks
2022-04-26 19:35:56 +03:00
Dmitry Chagin
5171ed79f6 linux(4): Copyout pselect timeout.
According to pselect6 manual, on error timeout becomes undefined, by fact
Linux modifies the timeout and ignore EFAULT error if so.

MFC after:	2 weeks
2022-04-26 19:35:56 +03:00
Dmitry Chagin
ee55d560e8 linux(4): Add a simple rseq syscall implementation.
To avoid annoyng messages from glibc-2.35 test suite add the simple
implementation of rseq syscall which is do nothing for now.

I plan to implement it if and when the API stabilizes.

MFC after:	2 weeks
2022-04-26 19:35:56 +03:00
Mark Johnston
efb8f0b8db linuxkpi: Mitigate a seqlock livelock
Disable preemption in seqlock write sections when using the _irqsave
variant.  This ensures that a writer can't be preempted and subsequently
starved by a reader running in a callout handler on the same CPU.

This fixes occasional display hangs seen when using the i915 driver.

Tested by:	emaste, wulf
Reviewed by:	wulf, hselasky
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D35021
2022-04-25 09:13:03 -04:00
Bjoern A. Zeeb
b3e7f403a5 LinuxKPI: 802.11 ieee80211_sn_sub() fix
In ieee80211_sn_sub() we need to shift the mask before applying it.
This fixes the logic from 978f25e840.

Reported by:	J.R. Oldroyd (fbsd opal.com)
MFC after:	3 days
Sponsored by:	The FreeBSD Foundation
2022-04-25 11:35:57 +00:00
Dmitry Chagin
6201a50d0d linux(4): Refactor signal send methods.
Created a couple of helpers to send signals to the specific thread or to
the whole process. Use helpers in the corresponding syscalls.
This fixes the confusion where a signal destined for a whole process
was sent to a specific thread and vice versa.
There is an exclusion for the linux_kill() syscall that takes a pid
argument and should send a signal to the whole process, but I know
at least one example where kill() takes tid.

MFC after:		2 weeks
2022-04-25 10:22:51 +03:00
Dmitry Chagin
fe894a3705 linux(4): Check that the thread tid in the thread group pid in linux_tdfind().
MFC after:		2 weeks
2022-04-25 10:21:51 +03:00
Dmitry Chagin
bbddd5881d linux(4): Microoptimize bsd_to_linux_sockaddr().
Differential Revision:	https://reviews.freebsd.org/D34725
MFC after:		2 weeks
2022-04-25 10:21:20 +03:00
Dmitry Chagin
91e7bdcdcf Add timespecvalid_interval macro and use it.
Reviewed by:		jhb, imp (early rev)
Differential revision:	https://reviews.freebsd.org/D34848
MFC after:		2 weeks
2022-04-25 10:20:54 +03:00
Mateusz Guzik
93494e425b linux: plug a set-but-not-used var
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2022-04-19 12:45:57 +00:00
John Baldwin
e2c5ab094b linuxkpi_ieee80211_tx_status: Mark ridx as unused.
__diagused only squelches warnings for variables used under
INVARIANTS, it does not apply to custom debug knobs like
LINUXKPI_DEBUG_80211.  Use __unused instead.
2022-04-18 12:29:47 -07:00
Bjoern A. Zeeb
d9945d7821 LinuxKPI: 802.11: improve hw_scan
Initially we were using the IEs from ieee80211_probereq_ie() of net80211
and put them into the common_ies field.  Start by manually building the
per-band and common IE parts as drivers put them back together.
This also involves allocating the req.ie as one buffer for all IEs over
all bands and setting req.ie_len correctly based on how many bytes we
put in.

Manually building per-band scan IEs we still use the net80211 routines
to add IEs to the buffer (mostly).

This is needed by Realtek drivers but will equally used by others.
Realtek would simply panic due to skbs being allocated with the wrong
length.

Longer-term this will help us, e.g., when not supporting VHT on 2Ghz
and we would have to do this anyway.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-04-15 15:54:03 +00:00
Bjoern A. Zeeb
8891c45563 LinuxKPI: 802.11: use an sx lock to protect the list of vifs
Use an sx lock to protect the list of vifs.  We could use the
linux mutex compat for this but our current implementation may
re-acquire the lock recursively so allow this.  The change is
mainly motivated by the fact that some callers may sleep in the
interator function called.  Recursiveness is needed because we
see find_sta_by_ifaddr() being called from an iterator function
from iterate_interfaces().

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-04-15 15:54:03 +00:00
Bjoern A. Zeeb
383b3e8f50 LinuxKPI: 802.11: start adding rate control to ieee80211_tx_status()
Start adding rate control feedback in ieee80211_tx_status() in order
for net80211 to be able to report something back (which may not
yet be the view of the firmware).  iwlwifi is reporting back an MSC 0
even with HT disabled (to be investigated) so we cannot (yet) use
the firmware/driver rate feedback directly.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-04-15 15:54:03 +00:00
Bjoern A. Zeeb
ade774b19f LinuxKPI: 802.11: implement ieee80211_probereq_get()
Implement ieee80211_probereq_get() needed by Realtek drivers.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-04-15 15:54:03 +00:00
Bjoern A. Zeeb
349b042b90 LinuxKPI: skbuff: start implementing skb_copy()
Implement skb_copy() with omissions of fragments and possibly other fields
for now.  Should we hit frags at any point a log message will let us know.
For the few cases we need this currently this is enough.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-04-15 15:54:03 +00:00
Bjoern A. Zeeb
952643ea45 LinuxKPI: skbuff: dev_kfree_skb_irq() and improvements
While it is currently unclear if we will have to defer work in
dev_kfree_skb_irq() to call dev_kfree_skb().
We only have one caller which seems to be fine on FreeBSD by calling
it directly for now.

While here shortcut skb_put()/skb_put_data() saving us work if there
are no adjustments to do.
Also adjust the logging in skb_is_gso() to avoid getting spammed by it.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-04-15 15:54:03 +00:00
Ed Maste
f99cc5a389 sysent: regen after 52a1d90c8b, posix_fadvise in capmode 2022-04-14 15:17:36 -04:00
John Baldwin
34dae08e6c linuxkpi: Use an inline function for the _ioremap_attr stub.
This "consumes" variables passed to ioremap*() avoiding set but unused
warnings.
2022-04-13 16:08:22 -07:00
Dmitry Chagin
673bce11ce linux(4): Copyout actual size of addr to the user space in accept().
Differential Revision:	https://reviews.freebsd.org/D34727
2022-04-11 23:33:27 +03:00
Dmitry Chagin
bb0f644cd6 linux(4): Limit user-supplied sockaddr length in recvfrom().
Differential Revision:	https://reviews.freebsd.org/D34726
2022-04-11 23:32:28 +03:00
Dmitry Chagin
68bfaefb3d linux(4): Remove unnecessary PTRIN(). 2022-04-11 23:32:02 +03:00
Dmitry Chagin
cf312f799a linux(4): Handle SO_DOMAIN in getsockopt syscall.
Differential revision:	https://reviews.freebsd.org/D34714
2022-04-11 23:31:28 +03:00
Dmitry Chagin
bb46e9b510 linux(4): Prevent an attempt to copy an uninitialized source address.
PR:			259380
MFC after:		3 days
2022-04-11 23:29:45 +03:00
Fernando Apesteguía
0f2041a5b0 [linprocfs] add sys/kernel/random/boot_id
This file holds a UUID that is invariant for every boot. In our case, it is
invariant per mount.

PR:	262369
Reported by:	sodynet1@gmail.com
Approved by:	dchagin@
Differential Revision:	https://reviews.freebsd.org/D34860
2022-04-11 18:23:28 +02:00
Bjoern A. Zeeb
978f25e840 LinuxKPI: 802.11: add ieee80211_beacon_get_tim(), ieee80211_sn_sub()
Add a dummy implementation for ieee80211_beacon_get_tim().
Add the implementation for ieee80211_sn_sub().

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-04-08 21:05:06 +00:00
Bjoern A. Zeeb
97f2e93a66 LinuxKPI: add ALIGN_DOWN()
Add ALIGN_DOWN as rounddown2() along ALIGN() which is implemented as
roundup2().

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Reviewed by:	manu, hselasky (now with less ())
Differential Revision: https://reviews.freebsd.org/D34844
2022-04-08 18:27:49 +00:00
Bjoern A. Zeeb
170acccf1e LinuxKPI: 802.11: further fix RSSI calculations
60970a328e did one half of the job
of making rssi relative to nf and numbers for radiotap were fine.
net80211 internally works with .5 dBm units thus we need to apply a
* 2 to the value we pass in to c_rssi;  leave a comment explaining.

Note: it is only ifconfig in user space which re-adjust it for printing
or contrib/wpa for calculations.  Other applications getting values
from kernel also have to apply the maths.

In collaboration with:	J.R. Oldroyd (fbsd opal.com)
Sponsored by:		The FreeBSD Foundation
MFC after:		3 days
2022-04-08 11:06:58 +00:00
Bjoern A. Zeeb
9df5f29caf LinuxKPI: skbuff: handle dev_alloc_skb() correctly
dev_alloc_skb() comapred to alloc_skb() reserves some headroom
at the beginning of the skb which is used by drivers.
Split the code for the two cases and reserve NET_SKB_PAD space,
which should at least be 32 octets.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-04-07 20:55:53 +00:00
Dmitry Chagin
0938d04a2c linux(4): Fix a typo in itimerspec conversion routine.
MFC after:	3 days
2022-04-06 17:40:00 +03:00
Warner Losh
132b00f906 linuxkpi: move io_mapping_create_wc to .c
Move io_mapping_create_wc to .c because it encodes the size of struct
io_mapping so we move this from the client module to the linuxkpi
module.

Sponsored by:		Netflix
Reviewed by:		hselasky, emaste
Differential Revision:	https://reviews.freebsd.org/D34776
2022-04-04 23:06:37 -06:00
Warner Losh
2bf3361d56 linuxkpi: Move lkpi_pcim_iomap_devres_find to .c file
lkpi_pcim_iomap_devres_find encodes the size of struct pcim_iomap_devres
in the code, so move from .h to .c to move from client driver to
linuxkpi module.

Sponsored by:		Netflix
Reviewed by:		hselasky
Differential Revision:	https://reviews.freebsd.org/D34775
2022-04-04 23:06:29 -06:00
Warner Losh
36b5c44002 linuxkpi: Move pci_alloc_irq_vectors to .c file
pci_alloc_irq_vectors encodes the size of struct msix_entry
into its code. Move from .h to .c to move this knowledge from
client modules to linuxkpi module.

Sponsored by:		Netflix
Reviewed by:		hselasky
Differential Revision:	https://reviews.freebsd.org/D34774
2022-04-04 23:06:21 -06:00
Warner Losh
1cdb25340f linuxkpi: Move pci_request_region and _lkpi_pci_iomap into .c
Both pci_request_region and _lkpi_pci_iomap encode the size of struct
pci_mmio_region into their code. Move from .h to .c files to move that
knowledge from the client drivers into the linuxkpi module.

Sponsored by:		Netflix
Reviewed by:		hselasky
Differential Revision:	https://reviews.freebsd.org/D34773
2022-04-04 23:06:14 -06:00
Warner Losh
3ea682e21e linuxkpi: Move lkpi_pci_devres_get_alloc into .c file
lkpi_pci_devres_get_alloc encodes the struct pci_devres into its
code. Move from .h file to .c file to move this knowledge into linuxkpi
module.

Sponsored by:		Netflix
Reviewed by:		hselasky, emaste
Differential Revision:	https://reviews.freebsd.org/D34772
2022-04-04 23:06:06 -06:00
Warner Losh
aca0bcbca3 linuxkpi: Move cdev_alloc into .c file
Move cdev_alloc into linux_compat.c since it encodes the size of struct
linux_cdev into the client modules otherwise.

Sponsored by:		Netflix
Reviewed by:		hselasky, emaste
Differential Revision:	https://reviews.freebsd.org/D34771
2022-04-04 23:05:59 -06:00
Warner Losh
58e6719ca0 linuxkpi: Remove write only variable from lkpi_iicbb_reset
Sponsored by:		Netflix
Reviewed by:		hselasky
Differential Revision:	https://reviews.freebsd.org/D34770
2022-04-04 23:05:52 -06:00
Warner Losh
1341ac9f9c linuxkpi: Move class_create to .c file
class_create encodes the size of struct class into the generated
code. Move from .h file to .c file to move this knowledge from the
client modules that call this into the linuxkpi module.

Sponsored by:		Netflix
Reviewed by:		hselasky, emaste
Differential Revision:	https://reviews.freebsd.org/D34769
2022-04-04 23:05:43 -06:00
Warner Losh
702b687503 linuxkpi: Move device_create_groups_vargs to linux_compat.c
device_create_groups_vargs encodes the size of struct device. Move
definition from .h to .c to move this size into the linuxkpi module
rather than encoding it in all client driver modules.

Sponsored by:		Netflix
Reviewed by:		hselasky, emaste
Differential Revision:	https://reviews.freebsd.org/D34768
2022-04-04 23:05:36 -06:00
Warner Losh
36929b5584 linuxkpi: move kobject_create to .c file
kobject_create knows the size of struct kobject. Move it to
linux_compat.c so this knowledge is confined to the loadable module and
not the clients.

Sponsored by:		Netflix
Reviewed by:		hselasky, emaste
Differential Revision:	https://reviews.freebsd.org/D34767
2022-04-04 23:05:26 -06:00
Bjoern A. Zeeb
e86707418c LinuxKPI: PCI: add counter for linux_dma_map_phys_common() errors
LinuxKPI is asking for single-segment mappings.  Some (wireless) drivers
are using this to map multi-pages and our busdma framework is not very
friendly to that as single-segments [D31823].  Add a counter so we can
track when this happens to gather more information.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	hselasky
MFC after:	3 days
Differential Revision: https://reviews.freebsd.org/D34715
2022-04-03 23:05:47 +00:00
Bjoern A. Zeeb
60970a328e LinuxKPI: 802.11: fix RSSI (and NF)
As in 4a22cd6c4e nf and rss should be
signed and not unsigned.  Change the types in the header and while
here change a magic number to a define as done elsewhere (value does
not change).

When calculating c_rssi we need to make it relative so subtract nf.
And while here improve the debug output.

This will hopefully fix ifconfig wlanN list scan S:N output which
tools use to chose a BSSID and help net80211 internal calculations.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-04-01 22:31:23 +00:00
Dmitry Chagin
bafe3b8804 linsysfs: plug set-but-not-used vars.
MFC after:	2 weeks
2022-03-31 23:49:26 +03:00
Dmitry Chagin
09d60bfae5 linux(4): Cleanup empty lines.
MFC after:		2 weeks
2022-03-31 21:23:12 +03:00
Dmitry Chagin
4e1e83461b linux(4): Fix KASSERT message.
MFC after:		2 weeks
2022-03-31 21:22:31 +03:00
Dmitry Chagin
d6ccce0aa2 linux(4): readlink should fail if bufzis <= 0.
MFC after:		2 weeks
2022-03-31 21:21:41 +03:00
Dmitry Chagin
b7df7b987e linprocfs: Add /proc/self/oom_score_adj.
To avoid annoyng messages from LTP test suites add the simple
implementation of /proc/self/oom_score_adj which is do nothing.

Reviewed by:		emaste
Differential revision:  https://reviews.freebsd.org/D34710
MFC after:		2 weeks
2022-03-31 21:04:44 +03:00
Dmitry Chagin
d5dc757e84 linux(4): Add compat.linux32.emulate_i386 knob.
Historically 32-bit Linuxulator under amd64 emulated the real i386
behavior. Since 3d8dd983 the old i386 Linux world can't be used under
amd64 Linuxulator as it don't know anything about amd64 machine (which
is returned now by newuname() syscall). So, add a knob to allow to swith
the behavior and use i386 Linux binaries on amd64.
Set knob to the new behavior as I think this is common to the modern
Linux distros.

Reviewed by:		Pau Amma (doc), emaste
Differential revision:	https://reviews.freebsd.org/D34708
MFC after:		2 weeks
2022-03-31 21:01:09 +03:00
Dmitry Chagin
099fa2feb3 linux(4): Fixup miscalculation of d_off of struct dirent in getdents() syscalls.
Avoid calculating d_off value as it is specific to the underlying filesystem
and can be used by others API, like lseek(), seekdir() as input offset.

Differential revision:  https://reviews.freebsd.org/D31551
MFC after:		2 weeks
2022-03-31 20:50:09 +03:00
Dmitry Chagin
9103c5582a linux(4): wait4() returns ESRCH if pid is INT_MIN.
Weird and undocumented patch was added to the Linux kernel in 2017,
fixes wait403 LTP test.

MFC after:	2 weeks
2022-03-31 20:49:39 +03:00
Dmitry Chagin
5bcf0f7cd7 linux(4): Rid unused defines from linux_mib.
Reviewed by:		trasz
Differential revision:  https://reviews.freebsd.org/D31591
MFC after:		2 weeks
2022-03-31 20:45:12 +03:00
Dmitry Chagin
4e3aefb923 linux(4): Fixup waitid handling P_PGID idtype.
Since Linux 5.4, if id is zero, then wait for any child that is in the same
process grop as the caller's process group.

Differential revision:  https://reviews.freebsd.org/D31567
MFC after:		2 weeks
2022-03-31 20:44:00 +03:00