History log of /freebsd-current/sys/compat/linux/linux_event.c
Revision Date Author Comments
# aadc14bc 05-Sep-2023 Vico Chen <vico.chern_qq.com>

linux(4): Convert flags in timerfd_create

The timerfd is introduced in FreeBSD 14, and the Linux ABI timerfd is
also moved to FreeBSD native timerfd, but it can't work well as Linux
TFD_CLOEXEC and TFD_NONBLOCK haven't been converted to FreeBSD
TFD_CLOEXEC and TFD_NONBLOCK.

Reviewed by: dchagin, jfree
Differential revision: https://reviews.freebsd.org/D41708
MFC after: 1 week


# af93fea7 23-Aug-2023 Jake Freeland <jfree@freebsd.org>

timerfd: Move implementation from linux compat to sys/kern

Move the timerfd impelemntation from linux compat code to sys/kern. Use
it to implement the new system calls for timerfd. Add a hook to kern_tc
to allow timerfd to know when the system time has stepped. Add kqueue
support to timerfd. Adjust a few names to be less Linux centric.

RelNotes: YES
Reviewed by: markj (on irc), imp, kib (with reservations), jhb (slack)
Differential Revision: https://reviews.freebsd.org/D38459


# 3460fab5 18-Aug-2023 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Remove sys/cdefs.h inclusion where it's not needed due to 685dc743


# 685dc743 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

sys: Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 4d846d26 10-May-2023 Warner Losh <imp@FreeBSD.org>

spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD

The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with: pfg
MFC After: 3 days
Sponsored by: Netflix


# c8a79231 14-Feb-2023 Dmitry Chagin <dchagin@FreeBSD.org>

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


# d8e53d94 14-Feb-2023 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Cleanup includes under compat/linux

Cleanup unneeded includes, sort the rest according to style(9).
No functional changes.

MFC after: 2 weeks


# 10d16789 12-Feb-2023 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Get rid of the opt_compat.h include.

Since e013e369 COMPAT_LINUX, COMPAT_LINUX32 build options are removed,
so include of opt_compat.h is no more needed.

MFC after: 2 weeks


# c6d31b83 18-Jul-2022 Konstantin Belousov <kib@FreeBSD.org>

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


# 93107373 22-Jun-2022 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Trace Linux l_sigset_t.

MFC after: 2 weeks


# 707e567a 08-May-2022 Dmitry Chagin <dchagin@FreeBSD.org>

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


# ce9f8d6a 04-May-2022 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Implement timerfd_gettime64 syscall.

MFC after: 2 weeks


# b1f0b08d 04-May-2022 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Implement timerfd_settime64 syscall.

MFC after: 2weeks


# e00aad10 26-Apr-2022 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Add epoll_pwai2 syscall.

MFC after: 2 weeks


# 3923e632 26-Apr-2022 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Add copyin_sigset() helper.

MFC after: 2 weeks


# 27a25179 26-Apr-2022 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Add linux_epoll_pwait_ts() helper for future use.

MFC after: 2 weeks


# 74a0e24f 24-Nov-2021 Mateusz Guzik <mjg@FreeBSD.org>

linux: plug set-but-not-unused vars

Sponsored by: Rubicon Communications, LLC ("Netgate")


# 2b68eb8e 01-Oct-2021 Mateusz Guzik <mjg@FreeBSD.org>

vfs: remove thread argument from VOP_STAT

and fo_stat.


# 2b381863 20-Jul-2021 Dmitry Chagin <dchagin@FreeBSD.org>

Drop rdivacky@ "All rights reserved" from linux_event.

I got explicit permission from Roman.

Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D30913
MFC after: 2 weeks


# 1ca6b15b 20-Jul-2021 Dmitry Chagin <dchagin@FreeBSD.org>

Drop "All rights reserved" from my copyright statements.

Add email and fixup years while here.

Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D30912
MFC after: 2 weeks


# b3c6fe66 07-Feb-2021 Vladimir Kondratyev <wulf@FreeBSD.org>

epoll: Store epoll_event udata member in ext member of kevent.

Current epoll implementation stores udata fields of epoll_event
structure in special dynamically-sized table rather than in udata field
of backing kevent structure because of 2 reasons:
1. Kevent's udata size is smaller than epoll's on 32-bit archs.
2. Kevent's udata can be clobbered on execution EPOLL_CTL_ADD as kqueue
modifies existing event while epoll returns error in this case.

After r320043 has introduced four new 64bit user data members (ext[]),
we can store epoll udata in one of them and drop aforementioned table.
According to kqueue_register() source code ext members are not updated
when existing kevent is modified that fixes p.2.

As a side effect the patch fixes PR/252582.

Reviewed by: trasz
MFC after: 1 month
Differential revision: https://reviews.freebsd.org/D28169


# 14c40d2c 03-Feb-2021 shu <ankohuu@outlook.com>

linux: remove locks around callout_drain in timerfd_close()

The lock around callout_drain() is unnecessary and may cause
deadlock when one closes a timer descriptor during timer execution.

Reviewed By: delphij
Submitted By: ankohuu_outlook.com (Shunchao Hu)
Differential Revision: https://reviews.freebsd.org/D28148


# ae71b794 03-Feb-2021 shu <ankohuu@outlook.com>

linux: make timerfd_settime(2) set expirations count to zero

On Linux, read(2) from a timerfd file descriptor returns an unsigned
8-byte integer (uint64_t) containing the number of expirations
that have occurred, if the timer has already expired one or more
times since its settings were last modified using timerfd_settime(),
or since the last successful read(2). That's to say, once we do
a read or call timerfd_settime(), timer fd's expiration count should
be zero. Some Linux applications create timerfd and add it to epoll
with LT mode, when event comes, they do timerfd_settime instead
of read to stop event source from trigger. On FreeBSD,
timerfd_settime(2) didn't set the count to zero, which caused high
CPU utilization.

Submitted by: ankohuu_outlook.com (Shunchao Hu)
Differential Revision: https://reviews.freebsd.org/D28231


# 6b3a9a0f 11-Jan-2021 Mateusz Guzik <mjg@FreeBSD.org>

Convert remaining cap_rights_init users to cap_rights_init_one

semantic patch:

@@

expression rights, r;

@@

- cap_rights_init(&rights, r)
+ cap_rights_init_one(&rights, r)


# 7a202823 23-Dec-2020 Konstantin Belousov <kib@FreeBSD.org>

Expose eventfd in the native API/ABI using a new __specialfd syscall

eventfd is a Linux system call that produces special file descriptors
for event notification. When porting Linux software, it is currently
usually emulated by epoll-shim on top of kqueues. Unfortunately, kqueues
are not passable between processes. And, as noted by the author of
epoll-shim, even if they were, the library state would also have to be
passed somehow. This came up when debugging strange HW video decode
failures in Firefox. A native implementation would avoid these problems
and help with porting Linux software.

Since we now already have an eventfd implementation in the kernel (for
the Linuxulator), it's pretty easy to expose it natively, which is what
this patch does.

Submitted by: greg@unrelenting.technology
Reviewed by: markj (previous version)
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D26668


# 7cb901bf 23-Dec-2020 Konstantin Belousov <kib@FreeBSD.org>

Remove useless ARGUSED annotations.

Submitted by: greg@unrelenting.technology


# 11c9f2ff 23-Dec-2020 Konstantin Belousov <kib@FreeBSD.org>

Add SPDX tag.

Submitted by: greg@unrelenting.technology


# 1a180032 01-Sep-2020 Mateusz Guzik <mjg@FreeBSD.org>

compat: clean up empty lines in .c and .h files


# 86e794eb 11-Jun-2020 Edward Tomasz Napierala <trasz@FreeBSD.org>

Don't use newlines with linux_msg(). No functional changes.

MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation


# 71b8e362 24-Nov-2019 Vladimir Kondratyev <wulf@FreeBSD.org>

Linux epoll: Allow passing of any negative timeout value to epoll_wait

Linux epoll allow passing of any negative timeout value to epoll_wait()
to cause unbound blocking

Reviewed by: emaste
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D22517


# 335fe0af 24-Nov-2019 Vladimir Kondratyev <wulf@FreeBSD.org>

Linux epoll: Register events with zero event mask

Such an events are legal and should be interpreted as EPOLLERR | EPOLLHUP.
Register a disabled kqueue event in that case as we do not support EPOLLHUP yet.

Required by Linux Steam client.

PR: 240590
Reported by: Alex S <iwtcex@gmail.com>
Reviewed by: emaste
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D22516


# 461120b8 24-Nov-2019 Vladimir Kondratyev <wulf@FreeBSD.org>

Linux epoll: Check both read and write kqueue events existence in EPOLL_CTL_ADD

Linux epoll EPOLL_CTL_ADD op handler should always check registration
of both EVFILT_READ and EVFILT_WRITE kevents to deceide if supplied
file descriptor fd is already registered with epoll instance.

Reviewed by: emaste
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D22515


# 896a4c27 24-Nov-2019 Vladimir Kondratyev <wulf@FreeBSD.org>

Linux epoll: Don't deregister file descriptor after EPOLLONESHOT is fired

Linux epoll does not remove descriptor after one-shot event has been triggered.
Set EV_DISPATCH kqueue flag rather then EV_ONESHOT to get the same behavior.

Required by Linux Steam client.

PR: 240590
Reported by: Alex S <iwtcex@gmail.com>
Reviewed by: emaste, imp
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D22513


# 792843c3 24-Nov-2018 Mark Johnston <markj@FreeBSD.org>

Pass malloc flags directly through kevent(2) subroutines.

Some kevent functions have a boolean "waitok" parameter for use when
calling malloc(9). Replace them with the corresponding malloc() flags:
the desired behaviour is known at compile-time, so this eliminates a
couple of conditional branches, and makes the code easier to read.

No functional change intended.

Reviewed by: kib
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D18318


# 6040822c 30-Jul-2018 Alan Somers <asomers@FreeBSD.org>

Make timespecadd(3) and friends public

The timespecadd(3) family of macros were imported from NetBSD back in
r35029. However, they were initially guarded by #ifdef _KERNEL. In the
meantime, we have grown at least 28 syscalls that use timespecs in some
way, leading many programs both inside and outside of the base system to
redefine those macros. It's better just to make the definitions public.

Our kernel currently defines two-argument versions of timespecadd and
timespecsub. NetBSD, OpenBSD, and FreeDesktop.org's libbsd, however, define
three-argument versions. Solaris also defines a three-argument version, but
only in its kernel. This revision changes our definition to match the
common three-argument version.

Bump _FreeBSD_version due to the breaking KPI change.

Discussed with: cem, jilles, ian, bde
Differential Revision: https://reviews.freebsd.org/D14725


# 931e2a1a 15-Jun-2018 Ed Maste <emaste@FreeBSD.org>

linuxulator: do not include legacy syscalls on arm64

Existing linuxulator platforms (i386, amd64) support legacy syscalls,
such as non-*at ones like open, but arm64 and other new platforms do
not.

Wrap these in #ifdef LINUX_LEGACY_SYSCALLS, #defined in the MD linux.h
files. We may need finer grained control in the future but this is
sufficient for now.

Reviewed by: andrew
Sponsored by: Turing Robotic Industries
Differential Revision: https://reviews.freebsd.org/D15237


# cbd92ce6 09-May-2018 Matt Macy <mmacy@FreeBSD.org>

Eliminate the overhead of gratuitous repeated reinitialization of cap_rights

- Add macros to allow preinitialization of cap_rights_t.

- Convert most commonly used code paths to use preinitialized cap_rights_t.
A 3.6% speedup in fstat was measured with this change.

Reported by: mjg
Reviewed by: oshogbo
Approved by: sbruno
MFC after: 1 month


# 132f90c6 05-Feb-2018 Ed Maste <emaste@FreeBSD.org>

Linuxolator whitespace cleanup

A version of each of the MD files by necessity exists for each CPU
architecture supported by the Linuxolator. Clean these up so that new
architectures do not inherit whitespace issues.

Clean up shared Linuxolator files while here.

Sponsored by: Turing Robotic Industries Inc.


# 0633df29 28-Feb-2017 Dmitry Chagin <dchagin@FreeBSD.org>

Linux epoll return EEXIST on case when op is EPOLL_CTL_ADD, and the supplied
file descriptor fd is already registered with this epoll instance.

MFC after: 1 month


# 8bc4edfd 28-Feb-2017 Dmitry Chagin <dchagin@FreeBSD.org>

Linux epoll return ENOENT error in case when op is EPOLL_CTL_MOD or
EPOLL_CTL_DEL, and fd is not registered with this epoll instance.

MFC after: 1 month


# 29b1ecbe 28-Feb-2017 Dmitry Chagin <dchagin@FreeBSD.org>

FreeBSD does not have analgue for epill EPOLLPRI event type.
So, do not set EPOLLPRI event acidently.
Also, do not set EPOLLWRNORM and EPOLLRDNORM events as epoll
do not set this events.

MFC after: 1 month


# 281afc59 27-Feb-2017 Dmitry Chagin <dchagin@FreeBSD.org>

Return EINVAL when an invalid file descriptor specified.

MFC after: 1 month


# ed211c40 27-Feb-2017 Dmitry Chagin <dchagin@FreeBSD.org>

Unify eventfd ioctl method and use it for other similar interfaces.

MFC after: 1 month


# 2fa6d2fe 26-Feb-2017 Dmitry Chagin <dchagin@FreeBSD.org>

Return EINVAL in case when an invalid size of signal mask specified.

MFC after: 1 month


# 80c7315d 26-Feb-2017 Dmitry Chagin <dchagin@FreeBSD.org>

Restore signal mask in epoll_pwait.

MFC after: 1 month


# e0a254f6 26-Feb-2017 Dmitry Chagin <dchagin@FreeBSD.org>

Return EINVAL when an invalid file descriptor is specified.

MFC after: 1 month


# dd93b628 26-Feb-2017 Dmitry Chagin <dchagin@FreeBSD.org>

Implement timerfd family syscalls.

MFC after: 1 month


# 01d4a346 26-Feb-2017 Dmitry Chagin <dchagin@FreeBSD.org>

Nostly style(9) changes, replace unused eventfd_truncate()
by default invfo_truncate() method.

MFC after: 1 month


# df4336dd 19-Sep-2016 Ed Maste <emaste@FreeBSD.org>

Catch up to sys/capability.h rename to sys/capsicum.h in r263232

MFC after: 1 month
Sponsored by: The FreeBSD Foundation


# 09806d8e 26-Mar-2016 Dmitry Chagin <dchagin@FreeBSD.org>

When write(2) on eventfd object fails with the error EAGAIN do not return
the number of bytes written.

MFC after: 1 week


# 2bb14e75 26-Mar-2016 Dmitry Chagin <dchagin@FreeBSD.org>

Implement O_NONBLOCK flag via fcntl(F_SETFL) for eventfd object.

MFC after: 1 week


# a2034cc9 05-Aug-2015 Ed Schouten <ed@FreeBSD.org>

Allow the creation of kqueues with a restricted set of Capsicum rights.

On CloudABI we want to create file descriptors with just the minimal set
of Capsicum rights in place. The reason for this is that it makes it
easier to obtain uniform behaviour across different operating systems.

By explicitly whitelisting the operations, we can return consistent
error codes, but also prevent applications from depending OS-specific
behaviour.

Extend kern_kqueue() to take an additional struct filecaps that is
passed on to falloc_caps(). Update the existing consumers to pass in
NULL.

Differential Revision: https://reviews.freebsd.org/D3259


# 3c91646b 19-Jun-2015 Dmitry Chagin <dchagin@FreeBSD.org>

Add EPOLLRDHUP support.

Tested by: abi at abinet dot ru


# 6e4c8004 24-May-2015 Dmitry Chagin <dchagin@FreeBSD.org>

Implement epoll_pwait() system call.


# 76672e11 24-May-2015 Dmitry Chagin <dchagin@FreeBSD.org>

Add EPOLLERR flag handling to epoll.

Tested by: abi at abinet dot ru


# e2ff4b98 24-May-2015 Dmitry Chagin <dchagin@FreeBSD.org>

As fo_fill_kinfo() does not check fo_fill_kinfo to NULL
add a fo_fill_kinfo op to eventfdops.

Reported by: trinity


# a31d7686 24-May-2015 Dmitry Chagin <dchagin@FreeBSD.org>

Implement eventfd system call.

Differential Revision: https://reviews.freebsd.org/D1094
In collaboration with: Jilles Tjoelker


# e16fe1c7 24-May-2015 Dmitry Chagin <dchagin@FreeBSD.org>

Implement epoll family system calls. This is a tiny wrapper
around kqueue() to implement epoll subset of functionality.
The kqueue user data are 32bit on i386 which is not enough for
epoll user data, so we keep user data in the proc emuldata.

Initial patch developed by rdivacky@ in 2007, then extended
by Yuri Victorovich @ r255672 and finished by me
in collaboration with mjg@ and jillies@.

Differential Revision: https://reviews.freebsd.org/D1092