Skip to content

Commit 5177c0c

Browse files
committed
futex: make futex_parse_waitv() available as a helper
To make it more generically useful, augment it with allowing the caller to pass in the wake handler and wake data. Convert the futex_waitv() syscall, passing in the default handlers. Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 8af1692 commit 5177c0c

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

kernel/futex/futex.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,11 @@ struct futex_vector {
361361
struct futex_q q;
362362
};
363363

364+
extern int futex_parse_waitv(struct futex_vector *futexv,
365+
struct futex_waitv __user *uwaitv,
366+
unsigned int nr_futexes, futex_wake_fn *wake,
367+
void *wake_data);
368+
364369
extern int futex_wait_multiple(struct futex_vector *vs, unsigned int count,
365370
struct hrtimer_sleeper *to);
366371

kernel/futex/syscalls.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,15 @@ SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val,
184184
* @futexv: Kernel side list of waiters to be filled
185185
* @uwaitv: Userspace list to be parsed
186186
* @nr_futexes: Length of futexv
187+
* @wake: Wake to call when futex is woken
188+
* @wake_data: Data for the wake handler
187189
*
188190
* Return: Error code on failure, 0 on success
189191
*/
190-
static int futex_parse_waitv(struct futex_vector *futexv,
191-
struct futex_waitv __user *uwaitv,
192-
unsigned int nr_futexes)
192+
int futex_parse_waitv(struct futex_vector *futexv,
193+
struct futex_waitv __user *uwaitv,
194+
unsigned int nr_futexes, futex_wake_fn *wake,
195+
void *wake_data)
193196
{
194197
struct futex_waitv aux;
195198
unsigned int i;
@@ -214,6 +217,8 @@ static int futex_parse_waitv(struct futex_vector *futexv,
214217
futexv[i].w.val = aux.val;
215218
futexv[i].w.uaddr = aux.uaddr;
216219
futexv[i].q = futex_q_init;
220+
futexv[i].q.wake = wake;
221+
futexv[i].q.wake_data = wake_data;
217222
}
218223

219224
return 0;
@@ -306,7 +311,8 @@ SYSCALL_DEFINE5(futex_waitv, struct futex_waitv __user *, waiters,
306311
goto destroy_timer;
307312
}
308313

309-
ret = futex_parse_waitv(futexv, waiters, nr_futexes);
314+
ret = futex_parse_waitv(futexv, waiters, nr_futexes, futex_wake_mark,
315+
NULL);
310316
if (!ret)
311317
ret = futex_wait_multiple(futexv, nr_futexes, timeout ? &to : NULL);
312318

@@ -421,7 +427,7 @@ SYSCALL_DEFINE4(futex_requeue,
421427
if (!waiters)
422428
return -EINVAL;
423429

424-
ret = futex_parse_waitv(futexes, waiters, 2);
430+
ret = futex_parse_waitv(futexes, waiters, 2, futex_wake_mark, NULL);
425431
if (ret)
426432
return ret;
427433

0 commit comments

Comments
 (0)