Commit graph

3820 commits

Author SHA1 Message Date
Bjoern A. Zeeb
111619ff70 LinuxKPI: add bcd.h
Add bcd2bin() in bcd.h.

Libkern does provide a bcd2bin() which cannot be used cirectly leaving
us with a conflict (see comment in file).
Rather than having code to re-define bcd2bin() for the LinuxKPI
make sure libkern.h is always included before the LinuxKPI version.
Then only re-define our local LinuxKPI implementation.  [1]
From the argument truncating wrapper call the libkern version.
If we change our libkern implementation in the future we can save
us the remainder of the hassle. [2].

Suggested by:	Johannes Berg (johannes sipsolutions.net) [1]
Suggested by:	ian [2]
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 548ada00e5)
(cherry picked from commit ae2268efd5)
2021-11-21 18:15:58 +00:00
Bjoern A. Zeeb
9d2d8a27d0 LinuxKPI: add strreplace() to string.h
Add strreplace() needed by a driver.

(cherry picked from commit a5e2a27dca)
2021-11-19 00:01:26 +00:00
Bjoern A. Zeeb
4459c16279 LinuxKPI: add kstrtou8() and kstrtou8_from_user() to kernel.h
Analogous to the other sized version of kstrto[u]<type>() and
kstrtobool_from_user() add the "u8" versions needed by a driver.

(cherry picked from commit b382b78503)
2021-11-19 00:01:26 +00:00
Bjoern A. Zeeb
a6a1ab040f LinuxKPI: add simple_open() to fs.h
Add a dummy simple_open() to fs.h as we have for other
(unsupported) functions.
This is needed by a wireless driver.

(cherry picked from commit 41dee251ee)
2021-11-19 00:01:26 +00:00
Bjoern A. Zeeb
009e6b6e71 LinuxKPI: module.h add MODULE_SUPPORTED_DEVICE()
Add a dummy MODULE_SUPPORTED_DEVICE define as we do for other
MODULE_* macros.  This is needed by a wireless driver.

(cherry picked from commit c5eec7b57c)
2021-11-19 00:01:26 +00:00
Bjoern A. Zeeb
c7fc9ca779 LinuxKPI: pci.h make pci_dev argument const for pci_{read,write}_config*()
Make the struct pci_dev argument to the pci_{read,write}_config*()
functions "const" to match the Linux definition as some drivers
try to pass in a const argument which we currently fail to honor.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit ed5600f532)
2021-11-19 00:01:26 +00:00
Bjoern A. Zeeb
dc70c937b1 LinuxKPI: pci.h / linux_pci.c rename pci_driver field
Rename the struct pci_driver {} field to the list_head from links
to node as a driver is actually initialsing this to {} which seems
questionable but it will at least make us match the Linux structure
field name.

Reviewed by:	manu, hselasky

(cherry picked from commit cf89934842)
2021-11-19 00:01:26 +00:00
Bjoern A. Zeeb
aaf3364151 LinuxKPI: add netdev_features.h
Add netdev_features.h as a spearate file from the future netdevice.h
implementation to avoid include problems with a future skbuff.h.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 490f9d8f0e)
2021-11-19 00:01:25 +00:00
Bjoern A. Zeeb
37b2cf4e6a LinuxKPI: implement dma_set_coherent_mask()
Coherent is lower 32bit only by default in Linux and our only default
dma mask is 64bit currently which violates expectations unless
dma_set_coherent_mask() was called explicitly with a different mask.

Implement coherent by creating a second tag, and storing the tags in the
objects and use the tag from the object wherever possible.
This currently does not update the scatterlist or pool (both could be
converted but S/G cannot be MFCed as easily).

There is a 2nd change embedded in the updated logic of
linux_dma_alloc_coherent() to always zero the allocation as
otherwise some drivers get cranky on uninialised garbage.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit c39eefe715)
(cherry picked from commit 1269873159)
2021-11-19 00:01:24 +00:00
Bjoern A. Zeeb
d005c4c6de LinuxKPI: dma-mapping.h unify "mask" and "dma_mask"
In some places we are using "mask" and others "dma_mask" for the
same thing.  Harmonize the various places to "dma_mask" as used in
linux_pci.c.  For the declaration remove the argument names to
avoid the entire problem.

This is in preparation for an upcoming change.
No functional changes intended.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 72c89ce97b)
2021-11-19 00:01:24 +00:00
Bjoern A. Zeeb
870e31d839 LinuxKPI: disable device_release_driver()
As reported by multiple people testing iwlwifi, device_release_driver()
can lead to a panic on secondary errors (usually during attach).
Disable device_release_driver() for the short-term to prevent the panic
but leave it in place so it can be re-worked and fixed properly for
the long-term more easily.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 93b14194ac)
2021-11-19 00:01:24 +00:00
Bjoern A. Zeeb
20c9dcd2ed LinuxKPI: add fsleep()
Add fsleep() function now required by rtw88.  This seems to be
making a decision depending on time to sleep on how to sleep.
Given our compat framework already is lenient on how long to sleep,
this is a cut down version.

(cherry picked from commit cc2723370b)
2021-11-19 00:01:23 +00:00
Bjoern A. Zeeb
9342ec5077 LinuxKPI: add read_poll_timeout()
Add an implementation of read_poll_timeout() and the atomic variant
which I did at some point last year for rtw88 and now updated based
on feedback.

(cherry picked from commit fed248a6ac)
2021-11-19 00:01:23 +00:00
Bjoern A. Zeeb
4c8e296374 LinuxKPI: add module_pci_driver() and pci_alloc_irq_vectors()
Add the two new functions needed by rtw88 to register the driver and
handle the module bits as well as a version of pci_alloc_irq_vectors()
for what is needed.

(cherry picked from commit 366d68f283)
2021-11-19 00:01:23 +00:00
Bjoern A. Zeeb
034475d66c LinuxKPI: add sign_extend32()
Add sign_extend32() replicating the 64 version.  This is needed by
the rtw88 driver.

(cherry picked from commit ea4dea8394)
2021-11-19 00:01:23 +00:00
Bjoern A. Zeeb
3ce981ee8e LinuxKPI: fix bug in le32p_replace_bits()
Fix a bug that slipped in in 90707c4e44
using the correct field in le32p_replace_bits().

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 22e20d852f)
2021-11-19 00:01:23 +00:00
Bjoern A. Zeeb
2314243b4a LinuxKPI: bitfield.h cleanup
Add a missing tab and remove an unnecessary return.
No functional changes.

(cherry picked from commit 4c8af633d1)
2021-11-19 00:01:23 +00:00
Bjoern A. Zeeb
e41baaefc4 LinuxKPI: dmi.h do not rely on implicit includes
Add sys/types.h to dmi.h and do not rely on other files to include
all needed headers in Linux land.  I ran into compile problems with
rtw88 otherwise.

(cherry picked from commit ac134e762e)
2021-11-19 00:01:22 +00:00
Bjoern A. Zeeb
79bc96d1fb LinuxKPI: add nexthdr definitions for IPv6
Add the nexthdr definitions for IPv6 which are used by wireless
drivers and were previously placed in an 80211 header file by
accident.

Obtained from:	bz_iwlwifi
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit b9d984e2c5)
2021-11-19 00:01:22 +00:00
Hans Petter Selasky
8ababf739a LinuxKPI: Add sysctl(8) knob to control verbosity of WARN_ON's.
The purpose of this change is to reduce the amount of dmesg(8) noise when
VT switching after a panic.

Submitted by:	Greg V <greg@unrelenting.technology>
Differential Revision:	https://reviews.freebsd.org/D30174
Sponsored by:	NVIDIA Networking

(cherry picked from commit 2390a1441e)
2021-11-12 15:31:24 +01:00
Mark Johnston
f86bda068c Convert consumers to vm_page_alloc_noobj_contig()
Remove now-unneeded page zeroing.  No functional change intended.

Reviewed by:	alc, hselasky, kib
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 84c3922243)
2021-11-03 13:41:40 -04:00
Mark Johnston
66cb1858f4 Convert vm_page_alloc() callers to use vm_page_alloc_noobj().
Remove page zeroing code from consumers and stop specifying
VM_ALLOC_NOOBJ.  In a few places, also convert an allocation loop to
simply use VM_ALLOC_WAITOK.

Similarly, convert vm_page_alloc_domain() callers.

Note that callers are now responsible for assigning the pindex.

Reviewed by:	alc, hselasky, kib
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit a4667e09e6)
2021-11-03 13:39:36 -04:00
Jessica Clarke
fa82e6a103 LinuxKPI: Support lazy BAR allocation
Linux KPIs like pci_resource_start/len assume that BARs have been
allocated, but FreeBSD lazily allocates BARs if it cannot allocate the
firmware-allocated BARs. Thus using the Linux KPIs must force allocation
of the BARs rather than returning 0 for the start and length, which can
crash drm-kmod drivers that assume the BARs are valid. This is needed
for the AMDGPU driver to be able to attach on SiFive's HiFive Unmatched.

Reviewed by:	hselasky, jhb, mav
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D32447

(cherry picked from commit 82098c8bb5)
2021-10-24 19:51:15 +01:00
Jessica Clarke
feb3031f0a LinuxKPI: Implement _ioremap_attr for riscv
Now that riscv implements pmap_mapdev_attr we can enable the non-stub
implementation for riscv, which is needed for drm-kmod to not fail at
run time for drivers that need to map I/O regions.

Reviewed by:	hselasky, bz
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D32446

(cherry picked from commit 60d962e041)
2021-10-24 19:51:12 +01:00
Vladimir Kondratyev
e1f5bed753 LinuxKPI: Import linux_page.c and some dependent code from drm-kmod
No functional changes intended

Reviewed by:	hselasky, manu, markj
Differential revision:  https://reviews.freebsd.org/D32167

(cherry picked from commit c072f6e856)
2021-10-13 12:07:53 +03:00
Vladimir Kondratyev
c6fb23b292 LinuxKPI: Update pte_fn_t definition to match Linux 5.3
Reviewed by:	emaste, hselasky, manu
Differential revision:	https://reviews.freebsd.org/D32166

(cherry picked from commit 88531adbfb)
2021-10-13 12:07:24 +03:00
Vladimir Kondratyev
9441d948aa LinuxKPI: Implement backlight_enable and backlight_disable functions
For now, disable backlight if brightness level is set to 0.
In the future we may implement separate knob in backlight(8).

Required by drm-kmod v5.6

Reviewed by:	hselasky, manu
Differential revision:	https://reviews.freebsd.org/D32165

(cherry picked from commit b52e363840)
2021-10-13 12:06:51 +03:00
Vladimir Kondratyev
f2a3116ab4 LinuxKPI: Add dummy pgprot_decrypted() implementation
to reduce number of #ifdefs in drm-kmod

Reviewed by:	hselasky
Differential revision:	https://reviews.freebsd.org/D32094

(cherry picked from commit 3d86f8f1d7)
2021-10-13 12:05:38 +03:00
Vladimir Kondratyev
8cf87dd59f LinuxKPI: Cast offset_in_page() parameter to unsigned long
to reduce number of patches in drm-kmod

Reviewed by:	hselasky
Differential revision:	https://reviews.freebsd.org/D32093

(cherry picked from commit 37eba5b77a)
2021-10-13 12:04:58 +03:00
Vladimir Kondratyev
0ed3a19a38 LinuxKPI: Import linux/poison.h header
Required by drm-kmod 5.6

Reviewed by:	hselasky, imp, manu
Obtained from:	OpenBSD
Differential revision:	https://reviews.freebsd.org/D32092

(cherry picked from commit 6efabdeede)
2021-10-13 12:04:11 +03:00
Vladimir Kondratyev
7db428f0bb LinuxKPI: Add helper functions to store integers to linux/xarray.h
Required by drm-kmod.

Reviewed by:	hselasky
Differential revision:	https://reviews.freebsd.org/D32091

(cherry picked from commit b59ffedae8)
2021-10-13 12:03:29 +03:00
Vladimir Kondratyev
767e3ba2e6 LinuxKPI: Allow cdev_pager prefault handler to steal pages
from other vm_objects. This workarounds "Page already inserted" panic
in vm_page_insert routine triggered on attempt to mmap file created
with shmem_file_setup call. After introduction of "GTT mmap
interface v4" a.k.a. MMAP_OFFSET, vm_objects allocated by these calls
may try to own intersected sets of pages that leads to the assertion.

Reviewed by:	kib
Differential revision:	https://reviews.freebsd.org/D32090

(cherry picked from commit 62ff0566c9)
2021-10-13 12:02:49 +03:00
Vladimir Kondratyev
4fba1853b5 LinuxKPI: stub anon_inode_getfile
Although drm-kmod contains better implementation which is able to
allocate real entries on pseudofs, this feature has never been used.

Starting from drm-kmod v5.6 old implementation began to leak entries
on each drm device close(). Now just drop pseudofs support instead of
fixing it in drm-kmod and provide stub in base.

Reviewed by:	hselasky, manu
Differential revision:	https://reviews.freebsd.org/D32069

(cherry picked from commit bd6d55adb4)
2021-10-13 12:02:17 +03:00
Vladimir Kondratyev
847ffc18dd LinuxKPI: Factor out vmf_insert_pfn_prot() routine
from GEM and TTM page fault handlers and move it in to base system. This
code is tightly integrated with LKPI mmap support to belong to drm-kmod.

As this routine requires associated vm_object to be locked, it got
additional _locked suffix.

Reviewed by:	hselasky, markj
Differential revision:	https://reviews.freebsd.org/D32068

(cherry picked from commit f6823dac8f)
2021-10-13 12:01:32 +03:00
Vladimir Kondratyev
cdae9b8e43 LinuxKPI: Invoke release handler when file is destroyed by fput()
Required by drm_kmod 5.6

Reviewed by:	hselasky, manu
MFC after:	2 weeks
Differential revision:	https://reviews.freebsd.org/D32067

(cherry picked from commit 7d92d48358)
2021-10-13 12:01:06 +03:00
Vladimir Kondratyev
c1daa6fa4c LinuxKPI: allocate current before taking shrinkers lock
This fixes following warnings when shrinkers are invoked first time:

uma_zalloc_debug: zone "lkpicurr" with the following non-sleepable
locks held: exclusive sleep mutex lkpi-shrinker (lkpi-shrinker)

uma_zalloc_debug: zone "lkpimm" with the following non-sleepable locks
held: exclusive sleep mutex lkpi-shrinker (lkpi-shrinker)

Reviewed by:	hselasky, manu
Differential revision:	https://reviews.freebsd.org/D32066

(cherry picked from commit 2fe9ea5d3a)
2021-10-13 12:00:17 +03:00
Vladimir Kondratyev
2c26756366 LinuxKPI: implement _IOC_TYPE and _IOC_NR macros in linux/ioctl.h
They are used by drm-kmod

Reviewed by:	emaste, hselasky, manu
Differential revision:	https://reviews.freebsd.org/D31674

(cherry picked from commit b58c916f11)
2021-10-13 11:59:25 +03:00
Vladimir Kondratyev
fd6adf784e LinuxKPI: Remove FreeBSD struct resource from all LKPI headers
except linux/pci.h to avoid conflicts with Linux version.
This allows to #define resource in drm-kmod globally and strip some #ifdef-s

Reviewed by:	hselasky, manu
Differential revision:	https://reviews.freebsd.org/D31673

(cherry picked from commit 66ea390652)
2021-10-13 11:58:39 +03:00
Vladimir Kondratyev
a029968046 LinuxKPI: Implement get_file_rcu()
get_file_rcu() grabs a file if the file->f_count is not zero.

Required by drm-kmod 5.6

Reviewed by:	hselasky, manu (previous version)
Differential revision:	https://reviews.freebsd.org/D31672

(cherry picked from commit a81b36c6d3)
2021-10-13 11:57:46 +03:00
Mark Johnston
e49d57eecc linuxkpi: Handle a NULL cache pointer in kmem_cache_destroy()
This is compatible with Linux, and some driver error paths depend on it.

Reviewed by:	bz, emaste
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit a76de17715)
2021-10-12 20:36:18 -04:00
Mateusz Guzik
cda5e344e2 linprocfs: find cwd and root handling
The code would incorrectly use curthread instead of the target proc to
resolve vnodes.

Fixes:	8d03b99b9d ("fd: move vnodes out of filedesc into a dedicated structure")
PR:	258729
Noted by:	 Damjan Jovanovic <damjan.jov@gmail.com>

(cherry picked from commit 69ab528386)
2021-10-11 09:13:29 +00:00
Jessica Clarke
e79989d823 LinuxKPI: Add more #ifdef VM_MEMATTR_WRITE_COMBINING guards
One of the three uses is already guarded; this guards the remaining ones
to support architectures like riscv that do not provide write-combining,
and is needed to build drm-kmod on riscv.

Reviewed by:	hselasky, manu
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D31999

(cherry picked from commit 8167c92f65)
2021-10-10 14:36:53 +01:00
Mark Johnston
bcff2fdf8e freebsd32: Fix a double copyin in sendmsg() and recvmsg()
freebsd32_sendmsg() and freebsd32_recvmsg() both copyin the message
header twice, once directly and once in freebsd32_copyinmsghdr().  The
iovec length from the former is used when copying in msg_iov, but the
rest of the kernel uses the iovec length from the latter.  When
kern_sendit() and kern_recvit() iterate over the iovec to compute the
residual for I/O, they can therefore end up walking past the end of the
copied in iovec, either resulting in a system call error, userspace
memory corruption from uiomove() with invalid iovecs, or a kernel page
fault if the copied-in iovec is followed by an unmapped KVA region.

Reported by:	syzbot+7cc64cd0c49605acd421@syzkaller.appspotmail.com
Reviewed by:	kib, emaste
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit fea1a98ead)
2021-09-26 11:55:05 -04:00
Mark Johnston
8694d0b744 freebsd32: Provide an ANSI definition for freebsd32_recvmsg()
Fix style in the freebsd32_sendmsg() definition.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 4bda16ff18)
2021-09-26 11:55:01 -04:00
Konstantin Belousov
d4a478c270 procctl(2): Add PROC_WXMAP_CTL/STATUS
(cherry picked from commit 796a8e1ad1)
2021-09-24 03:26:59 +03:00
Edward Tomasz Napierala
e79a18dadf procctl(2): add PROC_NO_NEW_PRIVS_CTL, PROC_NO_NEW_PRIVS_STATUS
(cherry picked from commit db8d680ebe)
2021-09-24 03:26:59 +03:00
Warner Losh
0437d10e35 direct commit: fix KBI for pci_dev
Move all the new elemenets to the end of the structure for 13. We
allocate this inside the linuxkpi code, so the size isn't enccoded in
client modules. However, the offsets to the different fields are
encoded. Tihs modifies 04456f7118, 40a215e38a, and 3a606aadf2
and will likely create merge conflicts there (and that's a good thing
since the elements need to be moved to the end of the structure when
merging).

Tweak irq_ent to be binary compatible. Since this is inlined into the
clients, all clients have to agree on the irq_ent offsets.

Restore visibility to linux_kmem_cache_free_rcu
linux_kmem_cache_free_rcu was made static in 10235ad056, however
client drivers depended on calling it directly. Make it visible again to
restore the 13.0-Release KBI for linuxkpi.

Bump FreeBSD_version to 1300515 for restoration of 13.0 KBI. Since this
commmit changes the linuxkpi KBI (this time back to 13.0 release to
restore the status quo of), you'll need to recompile everything that
uses it (you needed to earlier as well, but those were silent
recompilation events). The plus side is that our packages (built using
13.0) for drm-kmod 5.4 work again on -stable systems.

Reviewed by:		bz, wulf
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D31363
2021-09-22 09:00:16 -06:00
Konstantin Belousov
130f41810e linuxkpi: remove global atomic counter of the task allocations
(cherry picked from commit d96f55bc71)
2021-08-03 12:56:02 +03:00
Hans Petter Selasky
3a83634c0f Wait for all task_struct allocations to be returned before freeing the UMA zone in the LinuxKPI
(cherry picked from commit b764a42653)
2021-08-03 12:55:12 +03:00
Konstantin Belousov
fb29b54a91 Regen 2021-08-03 12:52:36 +03:00