linux-user futex() and madvise() fixes
cover linux-user futex() and madvise() fixes
From: Helge Deller <[email protected]>
Three small linux-user patches. Please review.
Helge Deller (3):
linux-user: strace: Fix 5th argument of futex syscall
linux-user: val3 parameter of futex() syscall needs endianess swapping
linux-user: Fix MADV_XXX constants on hppa target
linux-user/strace.c | 7 ++++++- linux-user/syscall.c | 22 +++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-)
Signature · 1 line
2.52.0
PATCH 1/3 linux-user: strace: Fix 5th argument of futex syscall
From: Helge Deller <[email protected]>
The 5th argument isn't printed, but instead the 4th argument is shown twice. Fix this, and print the FUTEX_BITSET_MATCH_ANY string constant instead of -1 if the op is FUTEX_WAIT_BITSET or FUTEX_WAKE_BITSET.
--- linux-user/strace.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
linux-user/strace.c +6 -1
@@ -4150,7 +4150,12 @@ print_futex(CPUArchState *cpu_env, const struct syscallname *name, break; }print_pointer (arg4,0 ); -print_raw_param ("%d" , arg4,1 ); +if ((op ==FUTEX_WAIT_BITSET || (op ==FUTEX_WAKE_BITSET )) && + (arg5 ==FUTEX_BITSET_MATCH_ANY )) { +qemu_log ("FUTEX_BITSET_MATCH_ANY" ); + }else { +print_raw_param ("%#x" , arg5,1 ); + }print_syscall_epilogue (name); }#endif
Signature · 1 line
2.52.0
Re: [PATCH 1/3] linux-user: strace: Fix 5th argument of futex syscall
Quoted 20 lines · On Fri, 23 Jan 2026 at 15:16, <[email protected]> wrote:
From: Helge Deller <[email protected]>
The 5th argument isn't printed, but instead the 4th argument is shown twice. Fix this, and print the
FUTEX_BITSET_MATCH_ANYstring constant instead of -1 if the op isFUTEX_WAIT_BITSETorFUTEX_WAKE_BITSET.Signed-off-by Helge Deller <[email protected]>--- linux-user/strace.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)linux-user/strace.c +0
-0@@ -4150,7 +4150,12 @@ print_futex(CPUArchState *cpu_env, const struct syscallname *name,break ; }print_pointer (arg4,0 );
linux-user/strace.c print_futex(CPUArchState *cpu_env, const struct syscallname *name, · line 4161
Quoted 10 lines
linux-user/strace.c +6
-1-print_raw_param ("%d" , arg4,1 ); +if ((op ==FUTEX_WAIT_BITSET || (op ==FUTEX_WAKE_BITSET )) && + (arg5 ==FUTEX_BITSET_MATCH_ANY )) { +qemu_log ("FUTEX_BITSET_MATCH_ANY" ); + }else { +print_raw_param ("%#x" , arg5,1 ); + } print_syscall_epilogue(name); }#endif
thanks
-- PMM
PATCH 2/3 linux-user: val3 parameter of futex() syscall needs endianess swapping
In reply to [email protected]From: Helge Deller <[email protected]>
The FUTEX_WAIT_BITSET and FUTEX_WAKE_BITSET operations use a val3 parameter for comparism. Even if this 32-bit parameter is in most cases 0xffffffff, ensure that we do a required endianess swapping if host and guest endianess differ.
--- linux-user/syscall.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
linux-user/syscall.c +7 -1
@@ -8106,7 +8106,10 @@ static int do_futex(CPUState *cpu, bool time64, target_ulong uaddr,#endif switch (base_op) {case FUTEX_WAIT : + val =tswap32 (val); +break ;case FUTEX_WAIT_BITSET : + val3 =tswap32 (val3); val =tswap32 (val);break ;case FUTEX_WAIT_REQUEUE_PI :
@@ -8116,8 +8119,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 : + val3 =tswap32 (val3); + timeout =0 ; +break ; +case FUTEX_WAKE :case FUTEX_TRYLOCK_PI :case FUTEX_UNLOCK_PI : timeout =0 ;
Signature · 1 line
2.52.0
Re: [PATCH 2/3] linux-user: val3 parameter of futex() syscall needs endianess swapping
Quoted 18 lines · On Fri, 23 Jan 2026 at 15:11, <[email protected]> wrote:
From: Helge Deller <[email protected]>
The
FUTEX_WAIT_BITSETandFUTEX_WAKE_BITSEToperations use a val3 parameter for comparism. Even if this 32-bit parameter is in most cases0xffffffff, ensure that we do a required endianess swapping if host and guest endianess differ.Signed-off-by Helge Deller <[email protected]>--- linux-user/syscall.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)linux-user/syscall.c +0
-0
linux-user/syscall.c static int do_futex(CPUState *cpu, bool time64, target_ulong uaddr, · line 8114
Quoted 9 lines
linux-user/syscall.c +3
-0@@ -8106,7 +8106,10 @@ static int do_futex(CPUState *cpu, bool time64, target_ulong uaddr,#endif switch (base_op) {case FUTEX_WAIT : + val =tswap32 (val); +break ;case FUTEX_WAIT_BITSET : + val3 =tswap32 (val3); val =tswap32 (val);break ;
I see why we need to swap the "val" for these operations:
it is the value that the host kernel will be comparing against the in-memory value. It's currently in host order but it will be in memory in guest order, so we must swap it.
But why do we need to swap the bitmask in val3 ? That is in host order now and I would have thought the host kernel also wants it in host order.
thanks
-- PMM
Re: [PATCH 2/3] linux-user: val3 parameter of futex() syscall needs endianess swapping
Quoted 35 lines · Peter Maydell
Quoted 18 lines · On Fri, 23 Jan 2026 at 15:11, <[email protected]> wrote:
From: Helge Deller <[email protected]>
The
FUTEX_WAIT_BITSETandFUTEX_WAKE_BITSEToperations use a val3 parameter for comparism. Even if this 32-bit parameter is in most cases0xffffffff, ensure that we do a required endianess swapping if host and guest endianess differ.Signed-off-by Helge Deller <[email protected]>--- linux-user/syscall.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)linux-user/syscall.c +0
-0linux-user/syscall.c static int do_futex(CPUState *cpu, bool time64, target_ulong uaddr, · line 8114
Quoted 9 lines
linux-user/syscall.c +3
-0@@ -8106,7 +8106,10 @@ static int do_futex(CPUState *cpu, bool time64, target_ulong uaddr,#endif switch (base_op) {case FUTEX_WAIT : + val =tswap32 (val); +break ;case FUTEX_WAIT_BITSET : + val3 =tswap32 (val3); val =tswap32 (val);break ;I see why we need to swap the "val" for these operations:
it is the value that the host kernel will be comparing against the in-memory value. It's currently in host order but it will be in memory in guest order, so we must swap it.
Quoted 3 lines
But why do we need to swap the bitmask in val3 ? That is in host order now and I would have thought the host kernel also wants it in host order.
Seems it was a brain-I/O error on my side.
I'll drop that patch.
Thanks!
Helge
PATCH 3/3 linux-user: Fix MADV_XXX constants on hppa target
In reply to [email protected]From: Helge Deller <[email protected]>
Older hppa binaries may still use the old MADV_XXX constants for the madivise() syscall. Fix it up in the same manner as it's done in the Linux kernel in the parisc_madvise() function.
--- linux-user/syscall.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
linux-user/syscall.c +14 -0
@@ -12929,6 +12929,20 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,#ifdef TARGET_NR_madvisecase TARGET_NR_madvise: +#ifdef TARGET_HPPA +/* Emulate old hppa mapping of MADV_xxx constants. */ +switch (arg3) { +case 65 : arg3 =MADV_MERGEABLE ;break ; +case 66 : arg3 =MADV_UNMERGEABLE ;break ; +case 67 : arg3 =MADV_HUGEPAGE ;break ; +case 68 : arg3 =MADV_NOHUGEPAGE ;break ; +case 69 : arg3 =MADV_DONTDUMP ;break ; +case 70 : arg3 =MADV_DODUMP ;break ; +case 71 : arg3 =MADV_WIPEONFORK ;break ; +case 72 : arg3 =MADV_KEEPONFORK ;break ; +case 73 : arg3 =MADV_COLLAPSE ;break ; + } +#endif /* TARGET_HPPA */ return target_madvise (arg1, arg2, arg3);#endif #ifdef TARGET_NR_fcntl64
Signature · 1 line
2.52.0
Re: [PATCH 3/3] linux-user: Fix MADV_XXX constants on hppa target
Quoted 6 lines · On Fri, 23 Jan 2026 at 15:11, <[email protected]> wrote:
From: Helge Deller <[email protected]>
Older hppa binaries may still use the old
MADV_XXXconstants for themadivise()syscall. Fix it up in the same manner as it's done in the Linux kernel in theparisc_madvise()function.
"Remove this wrapper in year 2025" it says :-)
Quoted 1 line
Signed-off-by Helge Deller <[email protected]>
thanks
-- PMM
Re: [PATCH 3/3] linux-user: Fix MADV_XXX constants on hppa target
Quoted 9 lines · Peter Maydell
Quoted 6 lines · On Fri, 23 Jan 2026 at 15:11, <[email protected]> wrote:
From: Helge Deller <[email protected]>
Older hppa binaries may still use the old
MADV_XXXconstants for themadivise()syscall. Fix it up in the same manner as it's done in the Linux kernel in theparisc_madvise()function."Remove this wrapper in year 2025" it says :-)
Yes, I think I was too optimistic when I added that code back then. I found such programs yesterday....
Quoted 3 lines
Quoted 1 line
Signed-off-by Helge Deller <[email protected]>Reviewed-by Peter Maydell <[email protected]>
Thanks!
Helge