History log of /freebsd-current/sys/compat/linux/linux_futex.c
Revision Date Author Comments
# 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/


# 48645905 10-Jun-2023 Dmitry Chagin <dchagin@FreeBSD.org>

Revert "linux(4): The futex_wait operation should restart."

This reverts commit 5eec19c8eb0e1afafd7290325c61611c9a13b621 due to its
wrong. Linux interrupts futex syscall on signal and return EINTR.


# 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


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

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


# 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


# 9f7bf94e 08-Nov-2022 Alex S <iwtcex@gmail.com>

linux(4): Fix get_robust_list() syscall return value.

The system call returns the head of the robust futex list. The list head is stored
in the location pointed to by the head argument. When copying data between address
spaces use proper head storage size as it depends on an emulated ABI.

PR: 267616
MFC after: 3 days


# b04f5d18 19-May-2022 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): To improve readability use FUTEX_UNOWNED instead of 0

MFC after: 2 weeks


# 2cd66206 19-May-2022 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Handle cas failure on ll/sc operations

Follow the 11a6ecd4. Check and handle the case when the ll/sc casu fails
even when the compare succeeds.

For more details PR/263825, https://reviews.freebsd.org/D35150.

Obtained from: Andrew@
MFC after: 2 weeks


# 109c2bd2 09-May-2022 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4); Style.

MFC after: 2 weeks


# 07d10893 09-May-2022 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Return native error from futex_atomic_op to avoid conversion by the caller.

MFC after: 2 weeks


# 5eec19c8 09-May-2022 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): The futex_wait operation should restart.

It's ok from the futex_wait perspective as umtxq_sleep method uses
absolute sleep timeout.

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


# d4da6928 13-Aug-2021 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Improve comment.

Reported by: pfg
MFC after: 2 weeks


# 6e31bed6 12-Aug-2021 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Fix futex copyrights.

As no more NetBSD code in futexes exists replace NetBSD copyrights by
standard FreeBSD 2 clause license.
Add Roman Divacky's copyrights as an author of the robust futexes.

Differential revision: https://reviews.freebsd.org/D31347
MFC after: 2 weeks


# 2411ac0b 28-Jul-2021 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Eliminate a now unused includes after futexes refactoring.

MFC after: 2 weeks


# d90df8ac 28-Jul-2021 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Add a comment about wait/requeue pi operations.

MFC after: 2 weeks


# 626cbd46 28-Jul-2021 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Handle incorrect FUTEX_CLOCK_REALTIME option bit.

Return ENOSYS if the FUTEX_CLOCK_REALTIME option bit is specified for an
inappropriate futex operation.

MFC after: 2 weeks


# a9bb1b1c 28-Jul-2021 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Handle FUTEX_LOCK_PI2 oeration.

FUTEX_LOCK_PI2 was added to support clock selection as FUTEX_LOCK_PI uses a
CLOCK_REALTIME based absolute value since it was implemented, but it does not
require that the FUTEX_CLOCK_REALTIME bit is set, because that was introduced
later.

MFC after: 2 weeks


# bd25bf09 28-Jul-2021 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Use variable name not type for sizeof() to calculate storage size.

MFC after: 2 weeks


# 49a5c040 28-Jul-2021 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Move len variable initialization to the appropriate place.

MFC after: 2 weeks


# c8e9d2b7 28-Jul-2021 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Use linux_tdfind() in get_robust_list.

In the Linux emulation layer linux_tdfind() has a special purpose to
handle glibc specific TID mangling and we should use it instead of tdfind().

MFC after: 2 weeks


# f88d3c52 28-Jul-2021 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Eliminate unnecessary error initialization.

MFC after: 2 weeks


# 6b68e8af 28-Jul-2021 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Eliminate unnecessary head initialization.

MFC after: 2 weeks


# 971b53fa 28-Jul-2021 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): style, wrap too long line.

MFC after: 2 weeks


# edd44176 28-Jul-2021 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Eliminating remnants of futex sdt.

MFC after: 2 weeks


# b59cf25e 28-Jul-2021 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Handle special case for regular futex in handle_futex_death().

Handle some races in handle_futex_death() which can prevents a wakeup of
potential waiters which can cause these waiters to block forever.

Differential Revision: https://reviews.freebsd.org/D31280
MFC after: 2 weeks


# dad10770 28-Jul-2021 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Futex address must be 32-bit aligned.

Linux futex documentation explicitly states that EINVAL is returned if
the futex is not 4-byte aligned. Check futex alignment as a Linux do
and return EINVAL.

Differential Revision: https://reviews.freebsd.org/D31279
MFC after: 2 weeks


# b33e4690 28-Jul-2021 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Finish cf8d74e3fe63.

Add forgotten val3_compare initialization in case of time64 futex.

MFC after: 2 weeks


# 4f34dc64 28-Jul-2021 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Replace casuword32 by casueword32.

Follow the r349951 (30b3018d), add check to react to stops and requests
to terminate between retries.

Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D31254
MFC after: 2 weeks


# 7a718f29 28-Jul-2021 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Implement pi futexes using umtx.

Differential Revision: https://reviews.freebsd.org/D31240
MFC after: 2 weeks


# cb01cc4a 28-Jul-2021 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Replace copyin() by fueword32() in handle_futex_death().

According to fetch(9) fueword facility designed to fetch atomically
small amount of data from user space.

Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D31239
MFC after: 2 weeks


# 0dc38e33 28-Jul-2021 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Reimplement futexes using umtx.

Differential Revision: https://reviews.freebsd.org/D31236
MFC after: 2 weeks


# af29f399 28-Jul-2021 Dmitry Chagin <dchagin@FreeBSD.org>

umtx: Split umtx.h on two counterparts.

To prevent umtx.h polluting by future changes split it on two headers:
umtx.h - ABI header for userspace;
umtxvar.h - the kernel staff.

While here fix umtx_key_match style.

Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D31248
MFC after: 2 weeks


# 75cb2382 20-Jul-2021 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Factor out the futex_wait() op into linux_futex_wait().

MFC after: 2 weeks


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

linux(4): Prevent an endless loop.

In the futex_atomic_op() the encoded_op is a user-supplied parameter.
If the user specifies an incorrect value for this parameter paired with a valid
*uaddr parameter the caller will go into the endless loop. To prevent this check
futex_atomic_op() result and break the loop in case of ENOSYS.

MFC after: 2 weeks


# 80b8d6b1 20-Jul-2021 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Eliminate bogus comment.

For the caller is no need for access checking here, as the caller must take care
of EFAULT handling. Moreover, this check would be superfluous, since EFAULT is
extremily rare, and we prefer the fast path.

MFC after: 2 weeks


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

linux(4): Allow musl brand to use FUTEX_REQUEUE op.

Initial patch from submitter was adapted by me to prevent unconditional
FUTEX_REQUEUE use.

PR: 255947
Submitted by: Philippe Michaud-Boudreault
Differential Revision: https://reviews.freebsd.org/D30332


# 4c361d7a 20-Jul-2021 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Factor out the FUTEX_WAKE_OP op into linux_futex_wakeop().

MFC after: 2 weeks


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

linux(4): Factor out the FUTEX_CMP_REQUEUE op into linux_futex_requeue().

MFC after: 2 weeks


# 19f7e2c2 20-Jul-2021 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Factor out the FUTEX_WAKE op into linux_futex_wake().

MFC after: 2 weeks


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

linux(4): Factor out the FUTEX_WAIT op into linux_futex_wait().

MFC after: 2 weeks


# 1866eef4 20-Jul-2021 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Refactor the struct linux_futex_args.

Move flags and rtclock to the struct linux_futex_args. This will be used when
I split linux_futex() into separate futex op functions.

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


# 2e46d0c3 10-Jun-2021 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Implement futex_time64 system call.

MFC after: 2 weeks


# 25b09d6f 10-Jun-2021 Dmitry Chagin <dchagin@FreeBSD.org>

linux(4): Prevent integer overflow in futex_requeue.

To prevent a signed integer overflow in futex_requeue add a sanity check
to catch negative values of nrwake or nrrequeue.

MFC after: 2 weeks


# 5e8caee2 05-May-2021 Edward Tomasz Napierala <trasz@FreeBSD.org>

linux: remove redundant SDT tracepoints

Remove all the 'entry' and 'return' probes; they clutter up the source
and are redundant to FBT.

Reviewed By: dchagin
Sponsored By: EPSRC
Differential Revision: https://reviews.freebsd.org/D30040


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

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


# 74a796e0 17-Aug-2020 Mark Johnston <markj@FreeBSD.org>

Fix a lock leak when emulating futex(FUTEX_WAIT_BITSET).

Reported by: syzkaller
MFC after: 1 week
Sponsored by: The FreeBSD Foundation


# 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


# 433d61a5 10-Jun-2020 Edward Tomasz Napierala <trasz@FreeBSD.org>

Improve the warnings.

MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation


# 8e3d7cae 07-Feb-2020 Konstantin Belousov <kib@FreeBSD.org>

linux futex_put(): do not touch futex after dropping our reference.

Reported and tested by: Steve Roome <me@stephenroome.com>
Sponsored by: The FreeBSD Foundation
MFC after: 1 week


# a161fba9 17-Oct-2019 Yuri Pankov <yuripv@FreeBSD.org>

linux: futex_mtx should follow futex_list

Move futex_mtx to linux_common.ko for amd64 and aarch64 along
with respective list/mutex init/destroy.

PR: 240989
Reported by: Alex S <iwtcex@gmail.com>


# b9d3556a 18-Oct-2019 Yuri Pankov <yuripv@FreeBSD.org>

linux: provide just one instance of futex_list

Move futex_list definition to linux.c which is included once
in linux.ko (i386) and in linux_common.ko (amd64 and aarch64)
allowing 32/64 bit linux programs to access the same futexes
in the latter case.

PR: 240989
Reviewed by: dchagin
Differential Revision: https://reviews.freebsd.org/D22073


# 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


# 0cde66af 23-Apr-2018 Konstantin Belousov <kib@FreeBSD.org>

Fix futexes on i386 after the 4/4G split.

Use proper method to access userspace. For now, only the slow copyout
path is implemented.

Reported and tested by: tijl (previous version)
Sponsored by: The FreeBSD Foundation


# 7f2d13d6 27-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

sys/compat: further adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.


# 2ca5d34d 30-Apr-2017 Dmitry Chagin <dchagin@FreeBSD.org>

Fix NULL pointer dereference in futex_wake_op() in case when the same
address specified for arguments uaddr and uaddr2.

PR: 218987
Reported by: luke.tw gmail
MFC after: 1 week


# 0aecedaa 02-Apr-2017 Dmitry Chagin <dchagin@FreeBSD.org>

Remove excess tv_nsec test as this is done by linux_to_native_timespec().

MFC after: 1 week


# f8d72f53 21-May-2016 Dmitry Chagin <dchagin@FreeBSD.org>

For future use move futex timeout code to the separate function and
switch to the high resolution sbintime_t.

MFC after: 1 week


# a03566dd 21-May-2016 Dmitry Chagin <dchagin@FreeBSD.org>

Due to lack the priority propagation feature replace sx by mutex. WIth this
commit NPTL tests are ends in 1 minute faster.

MFC after: 1 week


# ea53658e 21-May-2016 Dmitry Chagin <dchagin@FreeBSD.org>

Add my copyright as I rewrote most of the futex code. Minor style(9) cleanup
while here.

MFC after: 1 week


# 037f7508 14-Jan-2016 Gleb Smirnoff <glebius@FreeBSD.org>

Change linux get_robust_list system call to match actual linux one.

The set_robust_list system call request the kernel to record the head
of the list of robust futexes owned by the calling thread. The head
argument is the list head to record.
The get_robust_list system call should return the head of the robust
list of the thread whose thread id is specified in pid argument.
The list head should be stored in the location pointed to by head
argument.

In contrast, our implemenattion of get_robust_list system call copies
the known portion of memory pointed by recorded in set_robust_list
system call pointer to the head of the robust list to the location
pointed by head argument.

So, it is possible for a local attacker to read portions of kernel
memory, which may result in a privilege escalation.

Submitted by: mjg
Security: SA-16:03.linux


# 6437b8e7 10-Jan-2016 Dmitry Chagin <dchagin@FreeBSD.org>

Unlock process lock when return error from getrobustlist call and add
an forgotten dtrace probe when return the same error.

MFC after: 3 days
XMFC with: r292743


# 6e554971 26-Dec-2015 Dmitry Chagin <dchagin@FreeBSD.org>

Do not allow access to emuldata for non Linux processes.

Pointed out by: mjg@
Security: https://admbugs.freebsd.org/show_bug.cgi?id=679


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

Do not use struct l_timespec without conversion. While here move
args->timeout handling before acquiring the futex key at FUTEX_WAIT path.

Differential Revision: https://reviews.freebsd.org/D1520
Reviewed by: trasz


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

Add prototypes for static futex functions.

Differential Revision: https://reviews.freebsd.org/D1519
Reviewed by: trasz


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

Print out unsupported futex operation message only once for the process.

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


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

Where possible we will use M_LINUX malloc(9) type.
Move M_FUTEX defines to the linux_common.ko.

Differential Revision: https://reviews.freebsd.org/D1077
Reviewed by: emaste


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

Refund the proc emuldata struct for future use. For now move flags from
thread emuldata to proc emuldata as it was originally intended.

As we can have both 64 & 32 bit Linuxulator running any eventhandler
can be called twice for us. To prevent this move eventhandlers code
from linux_emul.c to the linux_common.ko module.

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


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

Switch linuxulator to use the native 1:1 threads.

The reasons:
1. Get rid of the stubs/quirks with process dethreading,
process reparent when the process group leader exits and close
to this problems on wait(), waitpid(), etc.
2. Reuse our kernel code instead of writing excessive thread
managment routines in Linuxulator.

Implementation details:

1. The thread is created via kern_thr_new() in the clone() call with
the CLONE_THREAD parameter. Thus, everything else is a process.
2. The test that the process has a threads is done via P_HADTHREADS
bit p_flag of struct proc.
3. Per thread emulator state data structure is now located in the
struct thread and freed in the thread_dtor() hook.
Mandatory holdig of the p_mtx required when referencing emuldata
from the other threads.
4. PID mangling has changed. Now Linux pid is the native tid
and Linux tgid is the native pid, with the exception of the first
thread in the process where tid and pid are one and the same.

Ugliness:

In case when the Linux thread is the initial thread in the thread
group thread id is equal to the process id. Glibc depends on this
magic (assert in pthread_getattr_np.c). So for system calls that
take thread id as a parameter we should use the special method
to reference struct thread.

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


# 5072ad67 01-Jan-2015 Dmitry Chagin <dchagin@FreeBSD.org>

Fix Clang warning: passing 'unsigned int *' to parameter of type 'int *' converts between pointers to integer types with different sign.

MFC after: 1 week


# fb6bf8bb 31-May-2014 Dmitry Chagin <dchagin@FreeBSD.org>

Glibc was switched to the FUTEX_WAIT_BITSET op and CLOCK_REALTIME
flag has been added instead of FUTEX_WAIT to replace the FUTEX_WAIT
logic which needs to do gettimeofday() calls before the futex syscall
to convert the absolute timeout to a relative timeout.
Before this the CLOCK_MONOTONIC used by the FUTEX_WAIT_BITSET op.

When the FUTEX_CLOCK_REALTIME is specified the timeout is an absolute
time, not a relative time. Rework futex_wait to handle this.
On the side fix the futex leak in error case and remove useless
parentheses.

Properly calculate the timeout for the CLOCK_MONOTONIC case.

MFC after: 3 days


# 32fd4465 27-May-2014 Dmitry Chagin <dchagin@FreeBSD.org>

In r218101 I have not changed properly the futex syscall definition.
Some Linux futex ops atomically verifies that the futex address uaddr
(uval) contains the value val. Comparing signed uval and unsigned val
may lead to an unexpected result, mostly to a deadlock.

So copyin uaddr to an unsigned int to compare the parameters correctly.

While here change ktr records to print parameters in more readable format.

Tested by eadler@

MFC after: 3 days


# 54366c0b 25-Nov-2013 Attilio Rao <attilio@FreeBSD.org>

- For kernel compiled only with KDTRACE_HOOKS and not any lock debugging
option, unbreak the lock tracing release semantic by embedding
calls to LOCKSTAT_PROFILE_RELEASE_LOCK() direclty in the inlined
version of the releasing functions for mutex, rwlock and sxlock.
Failing to do so skips the lockstat_probe_func invokation for
unlocking.
- As part of the LOCKSTAT support is inlined in mutex operation, for
kernel compiled without lock debugging options, potentially every
consumer must be compiled including opt_kdtrace.h.
Fix this by moving KDTRACE_HOOKS into opt_global.h and remove the
dependency by opt_kdtrace.h for all files, as now only KDTRACE_FRAMES
is linked there and it is only used as a compile-time stub [0].

[0] immediately shows some new bug as DTRACE-derived support for debug
in sfxge is broken and it was never really tested. As it was not
including correctly opt_kdtrace.h before it was never enabled so it
was kept broken for a while. Fix this by using a protection stub,
leaving sfxge driver authors the responsibility for fixing it
appropriately [1].

Sponsored by: EMC / Isilon storage division
Discussed with: rstone
[0] Reported by: rstone
[1] Discussed with: philip


# 92c6196c 01-Oct-2013 Mark Johnston <markj@FreeBSD.org>

Fix some typos that were causing probe argument types to show up as unknown.

Reviewed by: rwatson (mac provider)
Approved by: re (glebius)
MFC after: 1 week


# 4d04cf1d 25-Jan-2013 Dmitry Chagin <dchagin@FreeBSD.org>

Arithmetic on pointers takes into account the size of the type. Properly cast the pointer to avoid incorrect pointer scaling.

MFC after: 1 Week


# 19e252ba 05-May-2012 Alexander Leidinger <netchild@FreeBSD.org>

- >500 static DTrace probes for the linuxulator
- DTrace scripts to check for errors, performance, ...
they serve mostly as examples of what you can do with the static probe;s
with moderate load the scripts may be overwhelmed, excessive lock-tracing
may influence program behavior (see the last design decission)

Design decissions:
- use "linuxulator" as the provider for the native bitsize; add the
bitsize for the non-native emulation (e.g. "linuxuator32" on amd64)
- Add probes only for locks which are acquired in one function and released
in another function. Locks which are aquired and released in the same
function should be easy to pair in the code, inter-function
locking is more easy to verify in DTrace.
- Probes for locks should be fired after locking and before releasing to
prevent races (to provide data/function stability in DTrace, see the
man-page of "dtrace -v ..." and the corresponding DTrace docs).


# d745c852 06-Nov-2011 Ed Schouten <ed@FreeBSD.org>

Mark MALLOC_DEFINEs static that have no corresponding MALLOC_DECLAREs.

This means that their use is restricted to a single C file.


# c28a98e9 10-Mar-2011 John Baldwin <jhb@FreeBSD.org>

Remove now-obsolete comment.

Submitted by: netchild
MFC after: 1 week


# 3a4bc256 03-Mar-2011 Dmitry Chagin <dchagin@FreeBSD.org>

Print out shared flag for debug purpose.

MFC after: 1 Week


# 815cb72a 03-Mar-2011 Dmitry Chagin <dchagin@FreeBSD.org>

Switch PROCESS_SHARE to AUTO_SHARE (as umtx do). Even for SHARED,
if page mapped MAP_ANON linux uses private algorithm too.

Disscussed with: jhb

MFC after: 3 Days


# 21f8f506 23-Feb-2011 John Baldwin <jhb@FreeBSD.org>

Use umtx_key objects to uniquely identify futexes. Private futexes in
different processes that happen to use the same user address in the
separate processes will now be treated as distinct futexes rather than the
same futex. We can now honor shared futexes properly by mapping them to a
PROCESS_SHARED umtx_key. Private futexes use THREAD_SHARED umtx_key
objects.

In conjunction with: dchagin
Reviewed by: kib
MFC after: 1 week


# e2ef00a4 14-Feb-2011 Dmitry Chagin <dchagin@FreeBSD.org>

Style(9) fix. Do not initialize variables in the declarations.


# 49fa1a74 13-Feb-2011 Dmitry Chagin <dchagin@FreeBSD.org>

Sort include files in the alphabetical order.


# 4ca49f41 13-Feb-2011 Dmitry Chagin <dchagin@FreeBSD.org>

Remove comment about 'ftlk' LOR.


# 890c582f 13-Feb-2011 Dmitry Chagin <dchagin@FreeBSD.org>

Stop printing the LOR, as this is expected behavior.


# 7c3b05b9 13-Feb-2011 Dmitry Chagin <dchagin@FreeBSD.org>

The bitset field of freshly created futex should be initialized explicity.
Otherwise, REQUEUE operations fails.


# d14cc07d 12-Feb-2011 Dmitry Chagin <dchagin@FreeBSD.org>

Rename used_requeue and use it as bitwise field to store more flags.
Reimplement used_requeue logic with LINUX_XDEPR_REQUEUEOP flag.


# 78ec1867 30-Jan-2011 Dmitry Chagin <dchagin@FreeBSD.org>

Yet another unimplemented futex operation, print out about.

Submitted by: arundel
MFC after: 1 month.


# 51637623 30-Jan-2011 Dmitry Chagin <dchagin@FreeBSD.org>

Implement a futex BITSET op.

Submitted by: arundel
MFC after: 1 month.


# 5706ce8b 22-Nov-2010 Alexander Leidinger <netchild@FreeBSD.org>

Remove trailing dot from the unimplemented futex messages to make
them consistent with the syscall and ipc messages.

Submitted by: arundel
MFC after: 3 days


# 809290db 15-Nov-2010 Alexander Leidinger <netchild@FreeBSD.org>

Some style(9) fixes.

Submitted by: arundel
MFC after: 1 week


# be44a97c 15-Nov-2010 Alexander Leidinger <netchild@FreeBSD.org>

- print out the PID and program name of the program trying to use an
unsupported futex operation
- for those futex operations which are known to be not supported,
print out which futex operation it is
- shortcut the error return of the unsupported FUTEX_CLOCK_REALTIME in
some cases:
FUTEX_CLOCK_REALTIME can be used to tell linux to use
CLOCK_REALTIME instead of CLOCK_MONOTONIC. FUTEX_CLOCK_REALTIME
however must only be set, if either FUTEX_WAIT_BITSET or
FUTEX_WAIT_REQUEUE_PI are set too. If that's not the case
we can die with ENOSYS right at the beginning.

Submitted by: arundel
Reviewed by: rdivacky (earlier iteration of the patch)
MFC after: 1 week


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# 2a947939 06-Oct-2010 Jung-uk Kim <jkim@FreeBSD.org>

Simplify timeout check in futex_wait() using itimerfix() and return error
if the given timeout is invalid. Consistently use int type for timeout and
correct a format string in futex_sleep().


# 5e82f12a 06-Oct-2010 Alexander Leidinger <netchild@FreeBSD.org>

Fix a comparision of an uninitialised pointer.

Submitted by: arundel
Found by: clang analysis (automatic service by uqs@)
Reviewed by: rdivacky


# 7733cf8f 11-Feb-2010 Matt Jacob <mjacob@FreeBSD.org>

MFC a number of changes from head for ISP (203478,203463,203444,202418,201758,
201408,201325,200089,198822,197373,197372,197214,196162). Since one of those
changes was a semicolon cleanup from somebody else, this touches a lot more.


# c2ede4b3 07-Jan-2010 Martin Blapp <mbr@FreeBSD.org>

Remove extraneous semicolons, no functional changes.

Submitted by: Marc Balmer <marc@msys.ch>
MFC after: 1 week


# 0046fd5d 14-Jun-2009 Dmitry Chagin <dchagin@FreeBSD.org>

Unlock process lock when return error from getrobustlist call.

Tested by: Alexander Best <alexbestms at math uni-muenster de>
Approved by: kib (mentor)
MFC after: 3 days


# ca8c3e7b 07-May-2009 Dmitry Chagin <dchagin@FreeBSD.org>

Add KTR(9) tracing for futex emulation.

Approved by: kib (mentor)
MFC after: 1 month


# d789bfd5 02-May-2009 Dmitry Chagin <dchagin@FreeBSD.org>

Move extern variable definitions to the header file.

Approved by: kib (mentor)
MFC after: 1 month


# 79262bf1 01-May-2009 Dmitry Chagin <dchagin@FreeBSD.org>

Reimplement futexes.
Old implemention used Giant to protect the kernel data structures,
but at the same time called malloc(M_WAITOK), that could cause the
calling thread to sleep and lost Giant protection. User-visible
result was the missed wakeup.

New implementation uses one sx lock per futex. The sx protects
the futex structures and allows to sleep while copyin or copyout
are performed.

Unlike linux, we return EINVAL when FUTEX_CMP_REQUEUE operation
is requested and either caller specified futexes are equial or
second futex already exists. This is acceptable since the situation
can only occur from the application error, and glibc falls back to
old FUTEX_WAKE operation when FUTEX_CMP_REQUEUE returns an error.

Approved by: kib (mentor)
MFC after: 1 month


# b1121623 19-Apr-2009 Dmitry Chagin <dchagin@FreeBSD.org>

Remove support for FUTEX_REQUEUE operation.
Glibc does not use this operation since 2.3.3 version (Jun 2004),
as it is racy and replaced by FUTEX_CMP_REQUEUE operation.
Glibc versions prior to 2.3.3 fall back to FUTEX_WAKE when
FUTEX_REQUEUE returned EINVAL.

Any application directly using FUTEX_REQUEUE without return
value checking are definitely broken.

Limit quantity of messages per process about unsupported
operation.

Approved by: kib (mentor)
MFC after: 1 month


# 731aded8 15-Mar-2009 Dmitry Chagin <dchagin@FreeBSD.org>

Sort include files in the alphabetical order.

Approved by: kib (mentor)
MFC after: 2 weeks


# b41a7787 15-Mar-2009 Dmitry Chagin <dchagin@FreeBSD.org>

Ignore FUTEX_FD op, as it is done by linux.

Approved by: kib (mentor)
MFC after: 2 weeks


# 3b8cbbde 15-Mar-2009 Dmitry Chagin <dchagin@FreeBSD.org>

Include linux_futex.h before linux_emul.h

Approved by: kib (mentor)
MFC after: 6 days


# 62162dfc 16-Nov-2008 Konstantin Belousov <kib@FreeBSD.org>

In the robust futexes list head, futex_offset shall be signed,
and glibc actually supplies negative offsets. Change l_ulong to l_long.

Submitted by: dchagin


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 175c6c31 14-Oct-2008 Konstantin Belousov <kib@FreeBSD.org>

Make robust futexes work on linux32/amd64. Use PTRIN to read
user-mode pointers. Change types used in the structures definitions to
properly-sized architecture-specific types.

Submitted by: dchagin
MFC after: 1 week


# 4732e446 13-May-2008 Roman Divacky <rdivacky@FreeBSD.org>

Implement robust futexes. Most of the code is modelled after
what Linux does. This is because robust futexes are mostly
userspace thing which we cannot alter. Two syscalls maintain
pointer to userspace list and when process exits a routine
walks this list waking up processes sleeping on futexes
from that list.

Reviewed by: kib (mentor)
MFC after: 1 month


# 6af82123 20-Mar-2008 Roman Divacky <rdivacky@FreeBSD.org>

o Add stub support for some new futex operations,
so the annoying message is not printed.

o Don't warn about FUTEX_FD not being implemented
and return ENOSYS instead of 0 (eg. success).

o Clear FUTEX_PRIVATE_FLAG as we actually implement
only private futexes so there is no reason to
return ENOSYS when app asks for a private futex.
We don't reject shared futexes because they worked
just fine with our implementation so far.

Approved by: kib (mentor)
Tested by: bsam
MFC after: 1 week


# a0b0d286 02-Mar-2008 Konstantin Belousov <kib@FreeBSD.org>

Return ENOSYS instead of 0 for the unknown futex operations.

Submitted by: rdivacky
Reported and tested by: Gary Stanley <gary velocity-servers net>


# 1c182de9 23-May-2007 Konstantin Belousov <kib@FreeBSD.org>

Move futex support code from <arch>/support.s into linux compat directory.
Implement all futex atomic operations in assembler to not depend on the
fuword() that does not allow to distinguish between -1 and failure return.
Correctly return 0 from atomic operations on success.

In collaboration with: rdivacky
Tested by: Scot Hetzel <swhetzel gmail com>, Milos Vyletel <mvyletel mzm cz>
Sponsored by: Google SoC 2007


# a328699b 29-Mar-2007 Jung-uk Kim <jkim@FreeBSD.org>

MFP4: Linux futex support for amd64.

Initial patch was submitted by kib and additional work was done
by Divacky Roman.

Tested by: emulation


# 8cf5ee2e 24-Feb-2007 Alexander Leidinger <netchild@FreeBSD.org>

MFp4 (110541):
Sync with rev 1.7 in NetBSD.

Obtained from: NetBSD


# f9dac961 24-Feb-2007 Alexander Leidinger <netchild@FreeBSD.org>

MFp4 (110523, parts which apply cleanly):
semi-automatic style(9)

The futex stuff already differs a lot (only a small part does not differ)
from NetBSD, so we are already way off and can't apply changes from NetBSD
automatically. As we need to merge everything by hand already, we can even
make the files comply to our world order.


# bb59e63f 09-Sep-2006 Alexander Leidinger <netchild@FreeBSD.org>

Change futex lock from mutex to sx. Make futex_get atomic (protected by the
futex lock).

Sponsored by: Google SoC 2006
Submitted by: rdivacky
Suggested by: jhb


# c19ddeda 09-Sep-2006 Alexander Leidinger <netchild@FreeBSD.org>

- don't wake every sleeper just the first one [1]
- remove debuging printf [2]

Submitted by: intron <mag@intron.ac> [1], rdivacky [2]


# 84ed9f91 26-Aug-2006 Alexander Leidinger <netchild@FreeBSD.org>

Correct the number of retries in a futex_wake() call.

Sponsored by: Google SoC 2006
Submitted by: rdivacky


# b273d5aa 19-Aug-2006 Suleiman Souhlal <ssouhlal@FreeBSD.org>

ifdef DEBUG a printf

Submitted by: rdivacky


# 9b0bcbfb 17-Aug-2006 Alexander Leidinger <netchild@FreeBSD.org>

Fix the DEBUG build:
- linux_emul.c [1]
- linux_futex.c [2]

Sponsored by: Google SoC 2006 [1]
Submitted by: rdivacky [1]
netchild [2]


# ad2056f2 14-Aug-2006 Alexander Leidinger <netchild@FreeBSD.org>

Add some new files needed for linux 2.6.x compatibility.

Please don't style(9) the NetBSD code, we want to stay in sync. Not imported
on a vendor branch since we need local changes.

Sponsored by: Google SoC 2006
Submitted by: rdivacky
With help from: manu@NetBSD.org
Obtained from: NetBSD (linux_{futex,time}.*)