linux-user/syscall.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
For PI futexes, the futex word is expected to contain the thread id in native
byte order. And failing to emulate that leads to issues as e.g. glibc does
not expect `ESRCH` to be returned from a `FUTEX_LOCK_PI` operation.
If the mutex is set to be "robust", then this is detected as unrecoverable
failure and glibc aborts (since a robust mutex should've been unlocked by
the kernel when the owner dies):
Fatal glibc error: pthread_mutex_lock.c:450 (__pthread_mutex_lock_full): assertion failed: e != ESRCH || !robust
qemu: uncaught target signal 6 (Aborted) - core dumped
Aborted (core dumped)
Since `FUTEX_LOCK_PI{,2}` cannot be easily emulated when the host and target
endianness differs, do not handle them, and return `ENOSYS`. This allows
e.g. glibc to detect that they do not work and handle things accordingly.
Link: https://gitlab.com/qemu-project/qemu/-/work_items/4911
Cc: qemu-stable@nongnu.org
Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
---
linux-user/syscall.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 2fc61b3eab..c5fbd30e28 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -8243,6 +8243,7 @@ static int do_futex(CPUState *cpu, bool time64, target_ulong uaddr,
case FUTEX_WAIT_BITSET:
val = tswap32(val);
break;
+#if HOST_BIG_ENDIAN == TARGET_BIG_ENDIAN
case FUTEX_WAIT_REQUEUE_PI:
val = tswap32(val);
haddr2 = g2h(cpu, uaddr2);
@@ -8250,10 +8251,11 @@ static int do_futex(CPUState *cpu, bool time64, target_ulong uaddr,
case FUTEX_LOCK_PI:
case FUTEX_LOCK_PI2:
break;
- case FUTEX_WAKE:
- case FUTEX_WAKE_BITSET:
case FUTEX_TRYLOCK_PI:
case FUTEX_UNLOCK_PI:
+#endif
+ case FUTEX_WAKE:
+ case FUTEX_WAKE_BITSET:
timeout = 0;
break;
case FUTEX_FD:
@@ -8261,7 +8263,9 @@ static int do_futex(CPUState *cpu, bool time64, target_ulong uaddr,
timeout = 0;
break;
case FUTEX_CMP_REQUEUE:
+#if HOST_BIG_ENDIAN == TARGET_BIG_ENDIAN
case FUTEX_CMP_REQUEUE_PI:
+#endif
val3 = tswap32(val3);
/* fall through */
case FUTEX_REQUEUE:
--
2.56.1
On 11/19/26 20:12, Barnabás Pőcze wrote:
> For PI futexes, the futex word is expected to contain the thread id in native
> byte order. And failing to emulate that leads to issues as e.g. glibc does
> not expect `ESRCH` to be returned from a `FUTEX_LOCK_PI` operation.
>
> If the mutex is set to be "robust", then this is detected as unrecoverable
> failure and glibc aborts (since a robust mutex should've been unlocked by
> the kernel when the owner dies):
>
> Fatal glibc error: pthread_mutex_lock.c:450 (__pthread_mutex_lock_full): assertion failed: e != ESRCH || !robust
> qemu: uncaught target signal 6 (Aborted) - core dumped
> Aborted (core dumped)
>
> Since `FUTEX_LOCK_PI{,2}` cannot be easily emulated when the host and target
> endianness differs, do not handle them, and return `ENOSYS`. This allows
> e.g. glibc to detect that they do not work and handle things accordingly.
>
> Link: https://gitlab.com/qemu-project/qemu/-/work_items/4911
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
> ---
> linux-user/syscall.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
Reviewed-by: Helge Deller <deller@gmx.de>
Tested-by: Helge Deller <deller@gmx.de> # on big-endian hppa guest
I've applied this patch to the linux-user-next git tree.
Thanks!
Helge
On 11/19/26 20:12, Barnabás Pőcze wrote:
> For PI futexes, the futex word is expected to contain the thread id in native
> byte order. And failing to emulate that leads to issues as e.g. glibc does
> not expect `ESRCH` to be returned from a `FUTEX_LOCK_PI` operation.
>
> If the mutex is set to be "robust", then this is detected as unrecoverable
> failure and glibc aborts (since a robust mutex should've been unlocked by
> the kernel when the owner dies):
>
> Fatal glibc error: pthread_mutex_lock.c:450 (__pthread_mutex_lock_full): assertion failed: e != ESRCH || !robust
> qemu: uncaught target signal 6 (Aborted) - core dumped
> Aborted (core dumped)
>
> Since `FUTEX_LOCK_PI{,2}` cannot be easily emulated when the host and target
> endianness differs, do not handle them, and return `ENOSYS`.
Your patch seems correct, but that makes me wonder if it makes sense to
propose a kernel patch (and additional qemu patch) for
FUTEX_LOCK_PI3
and
FUTEX_CMP_REQUEUE_PI3:
where the thread id is always stored in little endian format?
That way emulation is possible (I think so), and little endian format
since nowadays all major architectures run little endian. That way only
the big endian arches suffer a little, but have the benefit to be able
to be emulated on any arch.
Thoughts?
Helge
> This allows
> e.g. glibc to detect that they do not work and handle things accordingly.
>
> Link: https://gitlab.com/qemu-project/qemu/-/work_items/4911
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
> ---
> linux-user/syscall.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 2fc61b3eab..c5fbd30e28 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -8243,6 +8243,7 @@ static int do_futex(CPUState *cpu, bool time64, target_ulong uaddr,
> case FUTEX_WAIT_BITSET:
> val = tswap32(val);
> break;
> +#if HOST_BIG_ENDIAN == TARGET_BIG_ENDIAN
> case FUTEX_WAIT_REQUEUE_PI:
> val = tswap32(val);
> haddr2 = g2h(cpu, uaddr2);
> @@ -8250,10 +8251,11 @@ static int do_futex(CPUState *cpu, bool time64, target_ulong uaddr,
> case FUTEX_LOCK_PI:
> case FUTEX_LOCK_PI2:
> break;
> - case FUTEX_WAKE:
> - case FUTEX_WAKE_BITSET:
> case FUTEX_TRYLOCK_PI:
> case FUTEX_UNLOCK_PI:
> +#endif
> + case FUTEX_WAKE:
> + case FUTEX_WAKE_BITSET:
> timeout = 0;
> break;
> case FUTEX_FD:
> @@ -8261,7 +8263,9 @@ static int do_futex(CPUState *cpu, bool time64, target_ulong uaddr,
> timeout = 0;
> break;
> case FUTEX_CMP_REQUEUE:
> +#if HOST_BIG_ENDIAN == TARGET_BIG_ENDIAN
> case FUTEX_CMP_REQUEUE_PI:
> +#endif
> val3 = tswap32(val3);
> /* fall through */
> case FUTEX_REQUEUE:
Hi
2026. 11. 21. 0:41 keltezéssel, Helge Deller írta:
> On 11/19/26 20:12, Barnabás Pőcze wrote:
>> For PI futexes, the futex word is expected to contain the thread id in native
>> byte order. And failing to emulate that leads to issues as e.g. glibc does
>> not expect `ESRCH` to be returned from a `FUTEX_LOCK_PI` operation.
>>
>> If the mutex is set to be "robust", then this is detected as unrecoverable
>> failure and glibc aborts (since a robust mutex should've been unlocked by
>> the kernel when the owner dies):
>>
>> Fatal glibc error: pthread_mutex_lock.c:450 (__pthread_mutex_lock_full): assertion failed: e != ESRCH || !robust
>> qemu: uncaught target signal 6 (Aborted) - core dumped
>> Aborted (core dumped)
>>
>> Since `FUTEX_LOCK_PI{,2}` cannot be easily emulated when the host and target
>> endianness differs, do not handle them, and return `ENOSYS`.
>
> Your patch seems correct, but that makes me wonder if it makes sense to
> propose a kernel patch (and additional qemu patch) for
> FUTEX_LOCK_PI3
> and
> FUTEX_CMP_REQUEUE_PI3:
> where the thread id is always stored in little endian format?
> That way emulation is possible (I think so), and little endian format
> since nowadays all major architectures run little endian. That way only
> the big endian arches suffer a little, but have the benefit to be able
> to be emulated on any arch.
>
> Thoughts?
I have a feeling that such an api would not be welcome by the kernel since it arguably
degrades the performance on big endian, and is only there to help with the (arguably niche)
use case of qemu user emulation.
>
> Helge
>
>> This allows
>> e.g. glibc to detect that they do not work and handle things accordingly.
>>
>> Link: https://gitlab.com/qemu-project/qemu/-/work_items/4911
>> Cc: qemu-stable@nongnu.org
>> Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
>> ---
>> linux-user/syscall.c | 8 ++++++--
>> 1 file changed, 6 insertions(+), 2 deletions(-)
>>
>> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
>> index 2fc61b3eab..c5fbd30e28 100644
>> --- a/linux-user/syscall.c
>> +++ b/linux-user/syscall.c
>> @@ -8243,6 +8243,7 @@ static int do_futex(CPUState *cpu, bool time64, target_ulong uaddr,
>> case FUTEX_WAIT_BITSET:
>> val = tswap32(val);
>> break;
>> +#if HOST_BIG_ENDIAN == TARGET_BIG_ENDIAN
>> case FUTEX_WAIT_REQUEUE_PI:
>> val = tswap32(val);
>> haddr2 = g2h(cpu, uaddr2);
>> @@ -8250,10 +8251,11 @@ static int do_futex(CPUState *cpu, bool time64, target_ulong uaddr,
>> case FUTEX_LOCK_PI:
>> case FUTEX_LOCK_PI2:
>> break;
>> - case FUTEX_WAKE:
>> - case FUTEX_WAKE_BITSET:
>> case FUTEX_TRYLOCK_PI:
>> case FUTEX_UNLOCK_PI:
>> +#endif
>> + case FUTEX_WAKE:
>> + case FUTEX_WAKE_BITSET:
>> timeout = 0;
>> break;
>> case FUTEX_FD:
>> @@ -8261,7 +8263,9 @@ static int do_futex(CPUState *cpu, bool time64, target_ulong uaddr,
>> timeout = 0;
>> break;
>> case FUTEX_CMP_REQUEUE:
>> +#if HOST_BIG_ENDIAN == TARGET_BIG_ENDIAN
>> case FUTEX_CMP_REQUEUE_PI:
>> +#endif
>> val3 = tswap32(val3);
>> /* fall through */
>> case FUTEX_REQUEUE:
>
© 2016 - 2026 Red Hat, Inc.