Commit Graph

4686 Commits

Author SHA1 Message Date
Dmitry Chagin
8243e17463 linux(4): Fixup 5c32488de0 mis-merge 2023-03-04 12:42:04 +03:00
Dmitry Chagin
5c32488de0 linux(4): Add a counterpart to linux_ifflags
For further use in linux_ioctl_socket add bsd_to_linux_ifflags() which
accepts FreeBSD interface flags and translate it to Linux if flags.

Reviewed by:		melifaro
Differential Revision:	https://reviews.freebsd.org/D38873
2023-03-04 12:26:48 +03:00
Dmitry Chagin
945a7f0d21 linux(4): Assert that the FreeBSD size of struct sockaddr is equal to Linux
Our code depends on the fact that the size of struct sockaddr and
the size of sa_data is equal between FreeBSD and Linux.
2023-03-04 12:11:39 +03:00
Dmitry Chagin
9883961ed5 linux(4): Drop excess assert that Linux IFNAMSIZ is equal to FreeBSD
While here use _Static_assert() instead of the older CTASSERT().
2023-03-04 12:11:39 +03:00
Dmitry Chagin
d447088d99 linux(4): Improve linux_ifconf readability
Initialize max_len and full variables in a code block where
they are used.
2023-03-04 12:11:39 +03:00
Dmitry Chagin
96a8c6aa37 linux(4): Fixup of the pointer cast when comparing to an integer 2023-03-04 12:11:39 +03:00
Dmitry Chagin
8d6dd96d50 linux(4): Add net epoch assert to the linux_ifhwaddr, linux_ifflags
Now this functions are intended to use in the net epoch.

Reviewed by:		emaste, melifaro
Differential Revision:	https://reviews.freebsd.org/D38795
2023-03-04 12:11:38 +03:00
Dmitry Chagin
f9b0675b01 linux(4): Refactor socket ioctl path to avoid referencing an unstable interfaces
Split the linux_ioctl_socket() function on two counterparts, where
the linux_ioctl_socket_ifreq() intended to use in a code path which
requires the struct ifreq manipulation, i.e., translating in/out
values of the struct, while the linux_ioctl_socket() function is left
as is, it calls sys_ioctl() without touching in/out values.

Due to structures ifreq, sockaddr difference between FreeBSD and Linux
the linux_ioctl_socket_ifreq() calls kern_ioctl() directly, converting
in and out values to FreeBSD and to Linux accordingly.

Finally, modify the ifname_linux_to_bsd() to return error code, not
an unstable reference to the interface.

Reviewed by:		melifaro
Differential Revision:	https://reviews.freebsd.org/D38794
2023-03-04 12:11:38 +03:00
Dmitry Chagin
a927409ce8 linux(4): Rename struct l_ifreq members names to avoid conflicts with FreeBSD
For now we are using mixed names to access struct ifreq members, some
of Linux (ifr_name, ifr_ifindex), others of FreeBSD. To avoid conflicts
switch to use FreeBSD names.

Reviewed by:		jhibbits
Differential Revision:	https://reviews.freebsd.org/D38792
2023-03-04 12:11:38 +03:00
Dmitry Chagin
cabbfb60d0 linux(4): Reduce code duplication between MD files
Move struct ifnet definitions under compat/linux.

Reviewed by:		emaste
Differential Revision:	https://reviews.freebsd.org/D38791
2023-03-04 12:11:38 +03:00
Dmitry Chagin
5d5b633dde linsysfs(4): Refactor to avoid referencing an unstable interfaces
Enter the net epoch when traversing a list of interfaces. For that
split the ifname_linux_to_bsd() function on two counterparts, where
the ifname_linux_to_ifp() intended to use in epoch, while the
ifname_linux_to_bsd() intended to be a self-contained.
Until the linux_ioctl_coket() function is refactored, the
ifname_linux_to_bsd() temporarily returns interface outside
of the net epoch.

Reviewed by:		melifaro
Differential Revision:	https://reviews.freebsd.org/D38790
2023-03-04 12:11:38 +03:00
Dmitry Chagin
130383f2f1 linux(4): Make linux_ifflags return a value
To simplify the use of the function in the printf-like statements.

Differential Revision:	https://reviews.freebsd.org/D38830
2023-03-04 12:11:38 +03:00
Dmitry Chagin
6c5786fd37 linux(4): Migrate to IfAPI
Migrate linux and linprocfs to use the IfAPI interfaces instead of
direct ifnet accesses.
The code initially writed by jhibbits@, and adapted by me to 3ab3c9c2.

Reviewed by:		jhibbits
Differential Revision:  https://reviews.freebsd.org/D38735
2023-03-04 12:11:38 +03:00
Dmitry Chagin
a55b5a9aed linprocfs(4): Fixup process size in the /proc/pid/stat file
According to the Linux sources the kernel exposes a proces virtual
memory size via proc filesystem into the three files - stat, status
and statm. This is the struct mm->total_vm value adjusted to the
corresponding units - bytes, kilobytes and pages.

The fix is based on a fernape@ analysis.

PR:		265937
Reported by:	Ray Bellis
MFC after:	3 days
2023-02-26 16:42:22 +03:00
Dmitry Chagin
e55e4a6ba3 linux(4): Fixup the interface name translation in netlink
Netlink should translate a FreeBSD interface name to a Linux
interface name.

Reviewed by:		melifaro
Differential Revision:	https://reviews.freebsd.org/D38715
MFC after:		3 days
2023-02-23 11:01:18 +03:00
Dmitry Chagin
3ab3c9c29c linux(4): Consolidate a FreeBSD interface names translation code
We have some amount of interface names translation functions which are
differs by bugs implementation. Consolidates it in a one place.

Fixup loopback interface names translation and use ifnet methods and
accessors, where possible.

Reviewed by:		melifaro
Differential Revision:	https://reviews.freebsd.org/D38714
MFC after:		3 days
X-MFC with:		32fdc75fe7
2023-02-23 11:00:29 +03:00
Dmitry Chagin
200fe6e3a0 linux(4): Use predefined constant instead of hardcoded value
Reviewed by:		melifaro
Differential Revision:	https://reviews.freebsd.org/D38713
MFC after:		3 days
2023-02-23 10:59:34 +03:00
Justin Hibbits
19850ee073 Revert "linprocfs: Migrate to IfAPI"
This reverts commit 5243598927.

Requested by:	dchagin
2023-02-21 18:17:26 -05:00
Justin Hibbits
e9e637bf24 Revert "Port Linuxulator to IfAPI"
Revert pending netlink fixes, and further fixes to this.

This reverts commit 52d984831d.

Requested by:	dchagin
2023-02-21 12:20:24 -05:00
Emmanuel Vadot
a0fdaf9a7b linuxkpi: Add more suspend defines
Needed by drm 5.15-lts

Sponsored by:	Beckhoff Automation GmbH & Co. KG
2023-02-17 14:50:58 +01:00
Jean-Sébastien Pédron
b1a9e570fe
linuxkpi: Add strscpy_pad() to <linux/string.h>
It's the same as `strscpy()` except that it fills the rest of the
destination buffer with zeroes if the source buffer is shorter.

Reviewed by:	manu
Approved by:	manu
2023-02-15 23:19:41 +01:00
Jean-Sébastien Pédron
4dac88cd15
linuxkpi: Define debugfs_initialized()
It always return true on FreeBSD, at least for now, because all DRM
drivers using it depend on lindebugfs.

Reviewed by:	manu
Approved by:	manu
2023-02-15 23:19:41 +01:00
Jean-Sébastien Pédron
4b0552d5f4
linuxkpi: Move IS_ENABLED() and friends to <linux/kconfig.h>
The header is included in <linux/xarray.h> like it is on Linux. Some DRM
code depends on this header "pollution".

Reviewed by:	bz
Approved by:	bz
Differential Revision:	https://reviews.freebsd.org/D38567
2023-02-15 00:06:32 +01:00
Jean-Sébastien Pédron
96e16cf368
linuxkpi: Add <linux/cc_platform.h>
It defines the `cc_platform_has()` function.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38596
2023-02-14 23:07:19 +01:00
Jean-Sébastien Pédron
e6f7fe74a9
linuxkpi: Update ww_mutex_trylock() API for Linux 5.16
It gains new `struct ww_acquire_ctx *` argument we don't use currently.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38568
2023-02-14 23:01:07 +01:00
Jean-Sébastien Pédron
7d03acf065
linuxkpi: Declare struct fwnode_handle in <linux/fwnode.h>
Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38566
2023-02-14 23:01:06 +01:00
Jean-Sébastien Pédron
8363672729
linuxkpi: Add synchronize_shrinkers()
It takes the lock and release it immediately to make sure no shrinkers
are running in parallel.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38565
2023-02-14 23:01:06 +01:00
Jean-Sébastien Pédron
53da54b936
linuxkpi: Define totalram_pages()
It returns `physmem`.

`__FreeBSD_version` is bumped to 1400080. We need that to remove a copy
of this function in the i915 DRM driver, maintained outside of base.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38531
2023-02-14 23:01:06 +01:00
Jean-Sébastien Pédron
3102ea3b15
linuxkpi: Accept NULL as a value in linux_xarray
Linux' XArray allows to store a NULL pointer as a value. `xa_load()`
would return NULL for both an unused index and an index set to NULL. But
it impacts `xa_alloc()` which needs to find the next available index.

However, our implementation relies on a radix tree (see `linux_radix.c`)
which does not accept NULL pointers as values. I'm not sure if this is a
limitation or a feature, so to work around this, a NULL value is
replaced by `NULL_VALUE`, an unlikely address, when we pass it to
linux_radix.

Reviewed by:	emaste, manu
Approved by:	emaste, manu
Differential Revision:	https://reviews.freebsd.org/D38543
2023-02-14 23:01:02 +01:00
Justin Hibbits
52d984831d Port Linuxulator to IfAPI
Reviewed by:	dchagin
Sponsored by:	Juniper Networks, Inc.
Differential Revision: https://reviews.freebsd.org/D38349
2023-02-14 10:28:44 -05:00
Dmitry Chagin
c8a79231a5 linux(4): Rename linux_timer.h to linux_time.h
To avoid confusing people, rename linux_timer.h to linux_time.h,
as linux_timer.c is the implementation of timer syscalls only,
while linux_time.c contains implementation of all stuff declared
in linux_time.h.

MFC after:		2 weeks
2023-02-14 17:46:33 +03:00
Dmitry Chagin
d8e53d94fa linux(4): Cleanup includes under compat/linux
Cleanup unneeded includes, sort the rest according to style(9).
No functional changes.

MFC after:		2 weeks
2023-02-14 17:46:32 +03:00
Dmitry Chagin
e2028292e5 linux(4): Cleanup sys/sysctl.h from linux_misc.h
Leftover after c5156c77 (r374538).

MFC after:		2 weeks
2023-02-14 17:46:32 +03:00
Dmitry Chagin
77f66834b0 linux(4): Fix brackets of local include opt_inet6
MFC after:		2 weeks
2023-02-14 17:46:32 +03:00
Dmitry Chagin
32fdc75fe7 linux(4): Move use_real_names knob to the linux.c
MI linux.[c|h] are the module independent in terms of the Linux emulation
layer (ie, intended for both ISA - 32 & 64 bit), analogue of MD linux.h.
There must be a code here that cannot be placed into the corresponding by
common sense MI source and header files, i.e., code is machine independent,
but ISA dependent.
For the use_real_names knob, the code must be placed into the
linux_socket.[c|h], however linux_socket is ISA dependent.

MFC after:		2 weeks
2023-02-14 17:46:32 +03:00
Dmitry Chagin
acbbd5c039 linux(4): Cleanup sys/uio.h where linux_uitl.h is included
MFC after:		2 weeks
2023-02-14 17:46:31 +03:00
Dmitry Chagin
50c85a32d9 linux(4): Move uselib() to i386
This obsolete system call is not supported by glibc. In ancient libc
versions (before glibc 2.0), uselib() was used to load the shared
libraries with names found in an array of names in the binary.
On Linux, since 3.15, this system call is available only when
the kernel is configured with the CONFIG_USELIB option.

It doesn't look like anyone needs this syscall for others Linuxulators,
so move it to the corresponding MD Linuxulator.

MFC after:		2 weeks
2023-02-14 17:46:31 +03:00
Dmitry Chagin
86f9efef2c linux(4): Cleanup abi_compat.h include from linux_timer.h
Leftover after timespec copyin/copyout routines was implemented.

MFC after:		2 weeks
2023-02-14 17:46:31 +03:00
Dmitry Chagin
007986714c linux(4): Cleanup sys/queue.h from linux.h
Leftover after converting futexes to the umtx API.

NFC after:		2 weeks
2023-02-14 17:46:31 +03:00
Dmitry Chagin
513eb69edf linux(4): Cleanup sys/sysent.h from linux_util
Include sys/sysent.h directly where it needed. The linux_util.h included
in a most source files of the Linuxulator, avoid collecting a rarely used
includes here.

MFC after:		2 weeks
2023-02-14 17:46:31 +03:00
Dmitry Chagin
31e938c531 linux(4): Cleanup vm includes from linux_util.h
Include vm headers directly where they needed. The linux_util.h included
in a most source files of the Linuxulator, avoid collecting a rarely used
includes here.

MFC after:		2 weeks
2023-02-14 17:46:30 +03:00
Dmitry Chagin
81e7a80055 linux(4): Cleanup unneeded includes from linux_util.h
MFC after:		2 weeks
2023-02-14 17:46:30 +03:00
Jean-Sébastien Pédron
a27902c183
linuxkpi: Define cpu_data(cpu)
`cpu_data(cpu)` evaluates to a `struct cpuinfo_x86` filled with
attributes of the given CPU number. The CPU number is an index in the
`__cpu_data[]` array with MAXCPU entries. On FreeBSD, we simply
initialize all of them like we do with `boot_cpu_data`.

While here, we add the `x86_model` field to the `struct cpuinfo_x86`. We
use `CPUID_TO_MODEL()` to set it.

At the same time, we fix the value of `x86` which should have been set
to the CPU family. It was using the same implementation as
`CPUID_TO_MODEL()` before. It now uses `CPUID_TO_FAMILY()`.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38542
2023-02-13 22:09:32 +01:00
Jean-Sébastien Pédron
f3490083b7
linuxkpi: Add sg_alloc_table_from_pages_segment()
Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38541
2023-02-13 22:09:32 +01:00
Jean-Sébastien Pédron
d91cf06020
linuxkpi: Add <linux/stdarg.h> + include it from <linux/string.h>
The <stdarg.h> header was moved in Linux 5.15.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38540
2023-02-13 22:09:32 +01:00
Jean-Sébastien Pédron
210e756d4b
linuxkpi: Define IRQ_NOTCONNECTED
Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38539
2023-02-13 22:09:32 +01:00
Jean-Sébastien Pédron
b82bcfb66f
linuxkpi: Define lockdep_assert{,_once}()
Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38538
2023-02-13 22:09:32 +01:00
Jean-Sébastien Pédron
54606590df
linuxkpi: Move definition of struct list_head to <linux/types.h>
This is the case on Linux.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38537
2023-02-13 22:09:31 +01:00
Jean-Sébastien Pédron
bf6f665081
linuxkpi: Define FIELD_FIT()
Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38536
2023-02-13 22:09:31 +01:00
Jean-Sébastien Pédron
83276e1f95
linuxkpi: Add i2c_adapter_quirks support
While here, also declare `I2C_CLASS_HWMON`.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38535
2023-02-13 22:09:31 +01:00