Commit Graph

4425 Commits

Author SHA1 Message Date
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