Commit graph

5103 commits

Author SHA1 Message Date
Bjoern A. Zeeb 63a327b954 LinuxKPI: 802.11: use net80211 IEEE80211_HTCAP_* definitions
Rather than using the values and leaving net80211 names in a comment
define the LinuxKPI IEEE80211_HT_CAP_* to the net80211 IEEE80211_HTCAP_*
names.  That way errors like the one fixed in 3e0915b7b6 are less
likely to happen.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2024-06-07 23:57:04 +00:00
Bjoern A. Zeeb 3753988c5d LinuxKPI: pm: add SET_SYSTEM_SLEEP_PM_OPS() and device_can_wakeup()
Add the SET_SYSTEM_SLEEP_PM_OPS() by factoring some other macro code
out in order to set the suspend/resume functions when the struct is
already given.  Such is the case in iwlwifi d3.

Also add an initial implementation of device_can_wakeup().  Though
this is likely all we need we have no way of setting the flag for it
yet so leave a pr_debug() and a comment there as well.  Until we want
to support WoWLAN this is likely not needed for wireless.
Doing it the proper way checking a bool in 'struct dev_pm_info' would
change 'struct device' and with that 'struct pci_dev' and break the
KBI.  In favour of mergeability this version does not implement the
full functionality yet.

Both help to make an updated iwlwifi d3 compile.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Differential Revision: https://reviews.freebsd.org/D45358
2024-06-07 22:57:04 +00:00
Bjoern A. Zeeb 8866534929 LinuxKPI: 802.11: make sure we can send DISASSOC or DEAUTH frames
The "Invalid TXQ" error from iwlwifi seems to be triggered by a
frame being sent for a sta which is no longer known to the driver/fw.

While we make sure to trigger the sending of the frame in net80211
early enough (by calling (*iv_newstate)() early on rather than at
the end), TX in LinuxKPI is run in a deferred task.  When we drop the
net80211 ic lock again and re-acquire the LHW lock the packet may not
yet have made it to the driver.
Work around this between the (ic and lhw) locks by making sure
(a) no new packets get queued after we return from (*iv_newstate)(),
and (b) the TX task has run or gets cancelled and we manually push
any remaining packets out (or let lsta_free() clean them up).
The disabled packet queuing now also needs to be re-enabled in
scan_to_auth() in case an lsta is staying in service or gets re-used.

Also make sure that any following lkpi_wake_tx_queues() calls no
longer ignore queues which have not seen a prior dequeue.
This former workaround "feature" (ltxq->seen_dequeue) should be
fully garbage collected in a later change on its own.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
PR:		274382
Tested by:	emaste, lwhsu, thj, rkoberman at gmail.com
Accepted by:	adrian
Differential Revision: https://reviews.freebsd.org/D45508
2024-06-07 21:47:42 +00:00
Bjoern A. Zeeb 105b9df26e LinuxKPI: 802.11: close race lkpi_sta_scan_to_auth()/(*iv_update_bss)()
We have to unlock the net80211 ic lock in order to be able to call
sleepable downcalls to the driver/firmware; a 2nd thread may go through
net80211::join1() and (*iv_update_bss)() after we checked and unlocked.
Re-check status at the end of the function under the ic lock so that we
do not accidentally set lvif_bss_synched to true again despite it no
longer being true.

This should fix a race where we lost the (*iv_update_bss)() state
during startup where one SCAN->AUTH is followed by a (then) AUTH->AUTH
and lkpi_sta_a_to_a() did the wrong thing.

Once we re-consider net80211 state and allowing a second join
on a different node or iv_bss update without previously tearing down
the older node we can likely undo a lot of these extra checks and
workarounds.

Sponsored by:	The FreeBSD Foundation (updated version)
Tested by:	emaste (on and off)
MFC after:	3 days
Reviewd by:	cc
Differential Revision: https://reviews.freebsd.org/D43967
2024-06-07 21:40:32 +00:00
Bjoern A. Zeeb 3e0915b7b6 LinuxKPI: 802.11: Fix definition of IEEE80211_HT_CAP_RX_STBC
IEEE80211_HT_CAP_RX_STBC was set to 0x100 instead of 0x300.
Correct to get the expected behavior.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Fixes:		b0f7376822 LinuxKPI: 802.11 header updates
Reviewed by:	adrian
Differential Revision: https://reviews.freebsd.org/D45506
2024-06-07 21:16:49 +00:00
Bjoern A. Zeeb 582469016a LinuxKPI: 802.11: initalize lsta to NULL in linuxkpi_ieee80211_rx()
The logic following this new assignment in some cases may not set lsta
but the later tracing is checking for it to be != NULL.
With lsta not initialized that check may not hold up and later we would
dereference lsta->state and possibly panic.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D45507
2024-06-07 21:06:31 +00:00
Vladimir Kondratyev db42bd1f71 LinuxKPI: Convert Linux integer types to ISO C99 in linux/kstrtox.h
Sponsored by:	Serenity Cyber Security, LLC
MFC after:	1 week
Reviewed by:	bz, emaste
Differential Revision:	https://reviews.freebsd.org/D45465
2024-06-06 23:42:07 +03:00
Vladimir Kondratyev d207a2dee3 LinuxKPI: Add kstrtoll to linux/kstrtox.h
kstrtoll converts a string to a long long.

Sponsored by:	Serenity Cyber Security, LLC
MFC after:	1 week
Reviewed by:	bz, emaste
Differential Revision:	https://reviews.freebsd.org/D45455
2024-06-06 23:42:07 +03:00
Vladimir Kondratyev a97f3a9ec9 LinuxKPI: Move kstrto* functions to linux/kstrtox.h
from linux/kernel.h to match Linux and
allow direct linux/kstrtox.h inclusion.

Sponsored by:	Serenity Cyber Security, LLC
MFC after:	1 week
Reviewed by:	bz
Differential Revision:	https://reviews.freebsd.org/D45454
2024-06-06 23:42:07 +03:00
Vladimir Kondratyev afc450fac9 LinuxKPI: Add abs_diff to linux/math.h
It returns absolute value of the difference between the arguments.

Add LinuxKPI version check as the macro was moved from drm-kmod to
linux/math.h in Linux kernel commit 46f12960aad (6.6 timeframe).

Sponsored by:	Serenity Cyber Security, LLC
MFC after:	1 week
Reviewed by:	bz, emaste
Differential Revision:	https://reviews.freebsd.org/D45453
2024-06-06 23:42:07 +03:00
Vladimir Kondratyev 588064e658 LinuxKPI: Move linux/math.h content out of linux/kernel.h
To match Linux and allow direct linux/math.h inclusion.

Sponsored by:	Serenity Cyber Security, LLC
MFC after:	1 week
Reviewed by:	bz
Differential Revision:	https://reviews.freebsd.org/D45452
2024-06-06 23:42:07 +03:00
Vladimir Kondratyev 07c7c41ca1 LinuxKPI: Add min_not_zero() to linux/minmax.h
It returns the minimum that is not zero, except both equals to zero.

Sponsored by:	Serenity Cyber Security, LLC
MFC after:	1 week
Reviewed by:	bz, emaste, ssaxena
Differential Revision:	https://reviews.freebsd.org/D45450
Differential Revision:	https://reviews.freebsd.org/D45451
2024-06-06 23:42:06 +03:00
Vladimir Kondratyev f79474c4e3 LinuxKPI: Move linux/minmax.h content out of linux/kernel.h
To match Linux and allow direct linux/minmax.h inclusion.

Sponsored by:	Serenity Cyber Security, LLC
MFC after:	1 week
Reviewed by:	bz
Differential Revision:	https://reviews.freebsd.org/D45449
2024-06-06 23:42:06 +03:00
Vladimir Kondratyev cb8bfc4db8 LinuxKPI: Move page_address definition from linux/gfp.h to linux/mm.h
To match Linux. Some future changes may depend on proper location.

Sponsored by:	Serenity Cyber Security, LLC
MFC after:	1 week
Reviewed by:	bz, emaste
Differential Revision:	https://reviews.freebsd.org/D45448
2024-06-06 23:42:06 +03:00
Austin Shafer 613723bac2 linuxkpi: Allow ida_destroy and idr_destroy to be called multiple times
This fixes some weird behavior triggered by nvidia-drm.ko: some DRM
cleanup functions will be called multiple times, leading to a double
free. drm_mode_config_cleanup will be called twice, causing ida_destroy
to be called twice. Although calling the cleanup twice doesn't seem
very clean, on Linux this seems to be permissable as it handles it
just fine. Not doing these checks causes mutex panics and double frees.

In order to preserve this behavior this change checks if the objects
have already been destroyed and bails if so. This fixes the panic seen
when unloading the nvidia-drm driver.

MFC after:	1 week
Reviewed by:	bz, manu
Differential revision:	https://reviews.freebsd.org/D44865
2024-06-06 23:42:06 +03:00
Alvin Chen 21f4cf5ccf LinuxKPI: lockdep_assert: wrong 'cond' used in WARN_ON MACRO
'cond' in WARN_ON need be bracketed,
otherwise it is wrong for multiple conditions.

Reviewed by:	wulf
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D44604
2024-06-06 23:42:06 +03:00
Andrew Turner ec69d23093 linux: Allows writing to the vdso from the kernel
We need to write to the vdso in the kernel to perform fixups. Move it
from .rodata to .data so these can be run.

Reported by:	cy
Sponsored by:	Arm Ltd
2024-06-06 09:07:49 +00:00
Andrew Turner bed65d85c6 linux64: Fix the build on arm64 with bti checking
When we enable checking for BTI on arm64 we need to include an ELF
note in all object files linked into a module.

As using objcopy from a binary to an ELF object file doesn't add the
note switch to using .incbin from an assembly file. This allows us to
add the needed note without affecting the included object.

Reviewed by:	imp, kib, emaste
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D45468
2024-06-05 09:23:40 +00:00
Doug Moore b0056b31e9 libkern: add ilog2 macro
The kernel source contains several definitions of an ilog2 function;
some are slower than necessary, and one of them is incorrect.
Elimininate them all and define an ilog2 macro in libkern to replace
them, in a way that is fast, correct for all argument types, and, in a
GENERIC kernel, includes a check for an invalid zero parameter.

Folks at Microsoft have verified that having a correct ilog2
definition for their MANA driver doesn't break it.

Reviewed by:	alc, markj, mhorne (older version), jhibbits (older version)
Differential Revision:	https://reviews.freebsd.org/D45170
Differential Revision:	https://reviews.freebsd.org/D45235
2024-06-03 11:37:55 -05:00
Val Packett 108de78451 Redefine CLOCK_BOOTTIME to alias CLOCK_MONOTONIC, not CLOCK_UPTIME
The suspend-awareness situation with monotonic clocks across platforms
is kind of a mess, let's try not making it worse.

On Linux, CLOCK_MONOTONIC does NOT count suspended time, and
CLOCK_BOOTTIME was introduced to INCLUDE suspended time.

On OpenBSD, CLOCK_MONOTONIC DOES count suspended time, and CLOCK_UPTIME
was introduced to EXCLUDE suspended time.

On macOS, it's the same as OpenBSD, but with CLOCK_UPTIME_RAW.

Right now, we do not have a monotonic clock that counts suspended time.
We have CLOCK_UPTIME as a distinct ID alias, and CLOCK_BOOTTIME as a
preprocessor alias, both being effectively `CLOCK_MONOTONIC` for now.

When we introduce a suspend-aware clock in the future, it would make a
lot more sense to do it the OpenBSD/macOS way, i.e. to make
CLOCK_MONOTONIC include suspended time and make CLOCK_UPTIME exclude it,
because that's what the name CLOCK_UPTIME implies: a deviation from the
default intended for the uptime command to allow it to only show the
time the system was actually up and not suspended.

Let's change the define right now to make sure software using the define
would not end up using the ID of the wrong clock in the future, and fix
the IDs in the Linux compat code to match the expected changes too.

See https://bugzilla.mozilla.org/show_bug.cgi?id=1824084
for more discussion.

Fixes:		155f15118a ("clock_gettime: Add Linux aliases for CLOCK_*")
Fixes:		25ada63736 ("Map Linux CLOCK_BOOTTIME to native CLOCK_UPTIME.")
Sponsored by:	https://www.patreon.com/valpackett
Reviewed by:	kib, imp
Differential Revision:	https://reviews.freebsd.org/D39270
2024-05-31 08:45:02 -06:00
Bjoern A. Zeeb ecd1d1f1da LinuxKPI: remove extern from function declarations
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Reviewed by:	emaste (earlier version, found another two)
Differential Revision: https://reviews.freebsd.org/D45386
2024-05-30 21:01:57 +00:00
Warner Losh c48820a448 minor style tweak.
checkstyle9 doesn't check for this construct...

Fixes: 6d849754b9
2024-05-29 09:53:20 -06:00
Son Phan Trung 6d849754b9 linux: implement PR_CHILD_SET_SUBREAPER
Reviewed by: imp, dchagin
Pull Request: https://github.com/freebsd/freebsd-src/pull/1260
2024-05-29 07:56:23 -06:00
Gleb Smirnoff 2780e5f43d linux: allow RTM_GETADDR without full ifaddrmsg argument
Even modern glibc uses truncated argument for RTM_GETADDR when it wants to
list all addresses in a system.  See
sysdeps/unix/sysv/linux/ifaddrs.c:__netlink_sendreq().  It sends a one
char payload.  Linux kernel allows that as long as given socket is not
marked as a 'strict'.  We have a similar flag in the general netlink code
and it is checked in
sys/netlink/netlink_message_parser.h:nl_parse_header().  If the flag is
not present, parser will allocate a temporary zeroed buffer to make the
message correct.  The checks added in b977dd1ea5 blocked such message
before the parser.  My reading of glibc says that there are two types of
messages that are sent with __netlink_sendreq() - RTM_GETLINK and
RTM_GETADDR.  The RTM_GETLINK is binary compatible between Linux and
FreeBSD and thus doesn't need any ABI handler.

PR:		279012
Fixes:		b977dd1ea5
2024-05-28 13:13:08 -07:00
Bjoern A. Zeeb 45bce6fa30 LinuxKPI: 802.11: lock MO tx/wake_tx_queue() downcalls
Lock the two TX MO downcalls into driver/firmware in
lkpi_80211_txq_tx_one() to make sure they cannot happen in the
middle of other (net80211 triggered) updates calling down into
the driver/firmware.

Sponsored by:	The FreeBSD Foundation (commit)
MFC after:	3 days
Reviewed by:	cc
Differential Revision: https://reviews.freebsd.org/D43966
2024-05-23 23:43:29 +00:00
Ricardo Branco 9a9677ec1c linux: Update linux manpage to mention mqueuefs
Reviewed by: imp, kib
Pull Request: https://github.com/freebsd/freebsd-src/pull/1248
2024-05-23 13:40:47 -06:00
Ricardo Branco 97add684f5 linux: Support POSIX message queues
Reviewed by: imp, kib
Pull Request: https://github.com/freebsd/freebsd-src/pull/1248
2024-05-23 13:40:46 -06:00
Ricardo Branco 86e43b5def linux: Export linux_convert_l_sigevent
Reviewed by: imp, kib
Pull Request: https://github.com/freebsd/freebsd-src/pull/1248
2024-05-23 13:40:46 -06:00
Ricardo Branco 9c7b1bf271 linux: Export linux_common_openflags()
Reviewed by: imp, kib
Pull Request: https://github.com/freebsd/freebsd-src/pull/1248
2024-05-23 13:40:46 -06:00
Ricardo Branco 04d3f8e539 linprocfs: Add support for proc/sys/fs/mqueue/*
Reviewed by: imp, kib
Pull Request: https://github.com/freebsd/freebsd-src/pull/1248
2024-05-23 13:40:45 -06:00
Bjoern A. Zeeb d1af434d99 LinuxKPI: 802.11: rename chanctx_conf for consistency
We used to call the struct ieee80211_chanctx_conf variable "conf"
in some places but that becomes confusing with bss_conf and other
"conf" bits.  On the vif it is already called chanctx_conf thus also
rename it on the internal struct lkpi_chanctx and for our variables
in the implementation.

This should not have any external visibility.
No functional changes intended.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Differential Revision: https://reviews.freebsd.org/D45185
2024-05-22 21:08:55 +00:00
Bjoern A. Zeeb 5a4d24610f LinuxKPI: 802.11: change teardown order to avoid iwlwifi firmware crashes
While the previous order worked well for iwlwifi 22000 and later chipsets
(AXxxx, BE200), earlier chipsets had trouble and ran into firmware crashes.
Change the teardown order to avoid these problems.  The inline comments
in lkpi_sta_run_to_init() (and lkpi_disassoc()) try to document the new
order and also the old problems we were seeing (too early sta removal or
silent non-removal) leading to follow-up problems.

There is a possible further problem still lingering but a lot harder to
trigger (see comment in review) and likely related to some other doings
so we'll track it separately.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
PR:		275255
Tested with:	AX210, 8265 (bz); 9260 (Bakul Shah)
Differential Revision: https://reviews.freebsd.org/D45293
2024-05-22 21:04:19 +00:00
Warner Losh 208f11e806 linprocfs: use %z for size_t arguments
64-bit doesn't care or give a warning, but i386 compile complains
(rightly) that these are size_t and need a %z modifier.

Fixes: 25a04527b7
Sponsored by:		Netflix
2024-05-21 20:03:08 -06:00
Ricardo Branco 25a04527b7 linprocfs: Add support for proc/sysvipc/{msg,sem,shm}
Reviewed by: imp,kib
Pull Request: https://github.com/freebsd/freebsd-src/pull/1232
2024-05-21 17:58:28 -06:00
Bjoern A. Zeeb bb025df257 LinuxKPI: add FIELD_PREP_CONST()
Add FIELD_PREP_CONST() like FIELD_PREP() without any extra checks likely
expected on this version in Linux.  This is called by an updated wireless
driver.

Sposnored by:	The FreeBSD Foundation
MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D45180
2024-05-21 23:27:10 +00:00
Bjoern A. Zeeb 8e4b8e9d80 LinuxKPI: add kvmemdup()
Add kvmemdup() as a variant of kmemdup().  While currently it could
just call kmemdup() we duplicate the code and use kvmalloc() in case
someone will change the implementation of kvmalloc/kvfree in slab.h.
This is used by an updated wireless driver.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D45181
2024-05-21 22:14:50 +00:00
Bjoern A. Zeeb 69b6c4a6ec LinuxKPI: 802.11: fix for_each_sta_active_link()
Likely a c&p error from for_each_vif_active_link() to
for_each_sta_active_link().
We are checking the nitems on the vif instead of the sta in this macro.
Function wise there is no difference as the arrays are the same size
but for correctness fix this.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2024-05-21 22:12:00 +00:00
Mariusz Zaborski 408957613b Regen 2024-05-21 22:03:20 +02:00
Zhenlei Huang 68c890b443 linux(4): Add const qualifier to the value parameter of function handle_string()
The content that `value` point to is not going to be altered by function
handle_string().

MFC after:	1 week
2024-05-20 12:02:33 +08:00
Emmanuel Vadot a7b222db12 linuxkpi: rwlock: Fix rwlock_init
Some linux code re-init some spinlock so add MTX_NEW to mtx_init.

Reported by:    rlibby
Fixes:          5c0a192348 ("linuxkpi: rwlock: Simplify code")
2024-05-17 07:59:02 +02:00
Emmanuel Vadot cff79fd026 linuxkpi: Fix spin_lock_init
Some linux code re-init some spinlock so add MTX_NEW to mtx_init.

Reported by:	David Wolfskill <david@catwhisker.org>
Fixes:		ae38a1a1bf ("linuxkpi: spinlock: Simplify code")
2024-05-17 07:58:59 +02:00
Austin Shafer 28a59100b5 linuxkpi: Provide a non-NULL value for THIS_MODULE
THIS_MODULE is used to differentiate modules on Linux. We currently
completely stub out any Linux struct module usage, but THIS_MODULE
is still used to populate the "owner" fields of various drivers.
Even though we don't actually dereference these "owner" fields they
are still used by drivers to check if devices/dmabufs/etc come
from different modules. For example, during DRM GEM import some
drivers check if the dmabuf's owner matches the dev's owner. If
they match because they are both NULL drivers may incorrectly think
two resources come from the same module.

This adds a general purpose __this_linker_file which will point to
the linker file of the module that uses it. We can then use that
pointer to have a valid value for THIS_MODULE.

Reviewed by:	bz, jhb
Differential Revision:	https://reviews.freebsd.org/D44306
2024-05-16 10:36:36 -07:00
Emmanuel Vadot abb1a1340e linuxkpi: refcount: Use atomic_t directly
Simply use a typedef for refcount_t on atomic_t, this allow us
to use a nativ type and also changing struct kref to directly use
a refcount_t like Linux.

Reviewed by:		bz
Sponsored by:		Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D45207
2024-05-16 09:40:46 +02:00
Emmanuel Vadot 5c0a192348 linuxkpi: rwlock: Simplify code
Just use a typedef for rwlock_t, no need to create a useless
structure.

Reviewed by:		bz
Sponsored by:		Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D45206
2024-05-16 09:40:03 +02:00
Emmanuel Vadot ae38a1a1bf linuxkpi: spinlock: Simplify code
Just use a typedef for spinlock_t, no need to create a useless
structure.

Reviewed by:		bz, emaste
Sponsored by:		Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D45205
2024-05-16 09:39:36 +02:00
Mariusz Zaborski e90259af59 regen
Pointed out by:	brooks
2024-05-13 20:37:20 +02:00
Warner Losh 71ffda4130 Revert linprocfs commits
There's a race in these that I missed in my review that needs
to be resolved.

This reverts commit ee2e36686e.
This reverts commit 02f481a30b.
This reverts commit 099a81a417.
2024-05-12 09:09:03 -06:00
Warner Losh ee2e36686e linprocfs: Really fix time_t type issue
The cast to (long) is wrong on all the other 32-bit platforms. (long
long) is the correct type on all platforms. Also, use a z modifier for
size_t which also fails on 32-bit platforms.

Fixes: 02f481a30b
Sponsored by: Netflix
2024-05-11 22:53:15 -06:00
Warner Losh 02f481a30b linprocfs: Fix i386 time type
Cast the time type to (long). This is correct on all architectures. On
i386, this promotes the int time_t to a long (which is also 32-bit). On
64-bit architectures, this promotes the 64-bit signed time_t to a 64-bit
signed int type.

Sponsored by:		Netflix
2024-05-11 18:38:17 -06:00
Ricardo Branco 099a81a417 linprocfs: Add support for proc/sysvipc/{msg,sem,shm}
Signed-off-by: Ricardo Branco <rbranco@suse.de>
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1218
2024-05-11 13:37:47 -06:00