Bug 506816 - futex2, futex_waitv WARNING: unhandled amd64-linux syscall: 449
Summary: futex2, futex_waitv WARNING: unhandled amd64-linux syscall: 449
Status: RESOLVED FIXED
Alias: None
Product: valgrind
Classification: Developer tools
Component: general (other bugs)
Version First Reported In: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: mcermak
URL:
Keywords:
Depends on:
Blocks: 506971
  Show dependency treegraph
 
Reported: 2025-07-09 17:08 UTC by Mark Wielaard
Modified: 2025-09-12 11:40 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments
proposed patch (16.57 KB, patch)
2025-09-10 14:39 UTC, mcermak
Details
updated patch (15.29 KB, patch)
2025-09-12 06:23 UTC, mcermak
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Wielaard 2025-07-09 17:08:27 UTC
There are a couple of LTP testcases for this:
kernel/syscalls/futex/futex_waitv0{1,2,3}

Full documentation at:
https://docs.kernel.org/userspace-api/futex2.html
Comment 1 mcermak 2025-09-10 14:39:03 UTC
Created attachment 184869 [details]
proposed patch
Comment 2 Mark Wielaard 2025-09-11 10:56:13 UTC
(In reply to mcermak from comment #1)
> Created attachment 184869 [details]
> proposed patch

+PRE(sys_futex_waitv)
+{
+    /* asmlinkage long sys_futex_waitv(struct futex_waitv __user *waiters,
+     *                                 unsigned int nr_futexes, unsigned int flags,
+     *                                 struct __kernel_timespec __user *timeout, clockid_t clockid); */
+
+    PRINT("sys_futex_waitv ( %#" FMT_REGWORD "x, %ld, %ld, %#" FMT_REGWORD "x, %d )",
+          ARG1, SARG2, SARG3, ARG4, ARG5);
+    PRE_MEM_READ("sys_futex_waitv(waiters)", ARG1, sizeof(struct vki_futex_waitv));

Shouldn't that be sizeof(struct vki_futex_waitv) * ARG2?

+    PRE_MEM_READ("sys_futex_waitv(timeout)", ARG4, sizeof(struct vki__kernel_timespec));
+}

Looks good otherwise. Do all LTP futex_waitv tests pass with this?
Comment 3 mcermak 2025-09-11 11:08:30 UTC
(In reply to Mark Wielaard from comment #2)
> (In reply to mcermak from comment #1)
> > Created attachment 184869 [details]
> > proposed patch
> 
> +PRE(sys_futex_waitv)
> +{
> +    /* asmlinkage long sys_futex_waitv(struct futex_waitv __user *waiters,
> +     *                                 unsigned int nr_futexes, unsigned
> int flags,
> +     *                                 struct __kernel_timespec __user
> *timeout, clockid_t clockid); */
> +
> +    PRINT("sys_futex_waitv ( %#" FMT_REGWORD "x, %ld, %ld, %#" FMT_REGWORD
> "x, %d )",
> +          ARG1, SARG2, SARG3, ARG4, ARG5);
> +    PRE_MEM_READ("sys_futex_waitv(waiters)", ARG1, sizeof(struct
> vki_futex_waitv));
> 
> Shouldn't that be sizeof(struct vki_futex_waitv) * ARG2?

https://docs.kernel.org/userspace-api/futex2.html reads: The pointer for the first item of the array is passed as waiters.  So I assume the following structs are referenced one from another.

> 
> +    PRE_MEM_READ("sys_futex_waitv(timeout)", ARG4, sizeof(struct
> vki__kernel_timespec));
> +}
> 
> Looks good otherwise. Do all LTP futex_waitv tests pass with this?

Yep, both regtest and ltp tests seem to test fine.
Comment 4 mcermak 2025-09-11 11:20:25 UTC
(In reply to mcermak from comment #3)
> (In reply to Mark Wielaard from comment #2)
> > (In reply to mcermak from comment #1)
> > > Created attachment 184869 [details]
> > > proposed patch
> > 
> > +PRE(sys_futex_waitv)
> > +{
> > +    /* asmlinkage long sys_futex_waitv(struct futex_waitv __user *waiters,
> > +     *                                 unsigned int nr_futexes, unsigned
> > int flags,
> > +     *                                 struct __kernel_timespec __user
> > *timeout, clockid_t clockid); */
> > +
> > +    PRINT("sys_futex_waitv ( %#" FMT_REGWORD "x, %ld, %ld, %#" FMT_REGWORD
> > "x, %d )",
> > +          ARG1, SARG2, SARG3, ARG4, ARG5);
> > +    PRE_MEM_READ("sys_futex_waitv(waiters)", ARG1, sizeof(struct
> > vki_futex_waitv));
> > 
> > Shouldn't that be sizeof(struct vki_futex_waitv) * ARG2?
> 
> https://docs.kernel.org/userspace-api/futex2.html reads: The pointer for the
> first item of the array is passed as waiters.  So I assume the following
> structs are referenced one from another.

Apologies, I mistakenly imagined a linked list.  Will fix the patch!
Comment 5 mcermak 2025-09-12 06:23:46 UTC
Created attachment 184902 [details]
updated patch
Comment 6 Paul Floyd 2025-09-12 07:29:01 UTC
(In reply to mcermak from comment #5)
> Created attachment 184902 [details]
> updated patch

LGTM
Comment 7 Mark Wielaard 2025-09-12 11:40:45 UTC
(In reply to Paul Floyd from comment #6)
> (In reply to mcermak from comment #5)
> > Created attachment 184902 [details]
> > updated patch
> 
> LGTM

Agreed. Thanks for adding the SfMayBlock.
Pushed as:

commit 4b9d06bcde9935b3eae0307ec07fc1437a76e903 (HEAD -> master)
Author: Martin Cermak <mcermak@redhat.com>
Date:   Fri Sep 12 07:52:55 2025 +0200

    Wrap the futex_waitv syscall
    
    Wrap the futex2/futex_waitv syscall:
    
    sys_futex_waitv(struct futex_waitv __user *, waiters,
                    unsigned int, nr_futexes, unsigned int, flags,
                    struct __kernel_timespec __user *, timeout, clockid_t, clockid)
    
    sys_futex_waitv - Wait on a list of futexes
    @waiters:    List of futexes to wait on
    @nr_futexes: Length of futexv
    @flags:      Flag for timeout (monotonic/realtime)
    @timeout:    Optional absolute timeout.
    @clockid:    Clock to be used for the timeout, realtime or monotonic.
    
    Given an array of `struct futex_waitv`, wait on each uaddr. The thread wakes
    if a futex_wake() is performed at any uaddr. The syscall returns immediately
    if any waiter has *uaddr != val. *timeout is an optional timeout value for
    the operation. Each waiter has individual flags. The `flags` argument for
    the syscall should be used solely for specifying the timeout as realtime, if
    needed. Flags for private futexes, sizes, etc. should be used on the
    individual flags of each waiter. Returns the array index of one of the woken
    futexes. No further information is provided.
    
    Declare a futex_waitv wrapper in priv_syswrap-linux.h
    and hook it for {amd64,arm,arm64,mips64,ppc32,ppc64,riscv64,s390x\
    ,x86}- linux using LINX_ with PRE handler in syswrap-linux.c
    
    https://bugs.kde.org/show_bug.cgi?id=506816