Skip to content

Commit e4e28fd

Browse files
KAGA-KOKOingomolnar
authored andcommitted
futex: Convert to get/put_user_inline()
Replace the open coded implementation with the new get/put_user_inline() helpers. This might be replaced by a regular get/put_user(), but that needs a proper performance evaluation. No functional change intended. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Link: https://patch.msgid.link/20251027083745.736737934@linutronix.de
1 parent b2cfc0c commit e4e28fd

2 files changed

Lines changed: 5 additions & 57 deletions

File tree

kernel/futex/core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ int get_futex_key(u32 __user *uaddr, unsigned int flags, union futex_key *key,
581581
if (flags & FLAGS_NUMA) {
582582
u32 __user *naddr = (void *)uaddr + size / 2;
583583

584-
if (futex_get_value(&node, naddr))
584+
if (get_user_inline(node, naddr))
585585
return -EFAULT;
586586

587587
if ((node != FUTEX_NO_NODE) &&
@@ -601,7 +601,7 @@ int get_futex_key(u32 __user *uaddr, unsigned int flags, union futex_key *key,
601601
node = numa_node_id();
602602
node_updated = true;
603603
}
604-
if (node_updated && futex_put_value(node, naddr))
604+
if (node_updated && put_user_inline(node, naddr))
605605
return -EFAULT;
606606
}
607607

kernel/futex/futex.h

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -281,63 +281,11 @@ static inline int futex_cmpxchg_value_locked(u32 *curval, u32 __user *uaddr, u32
281281
return ret;
282282
}
283283

284-
/*
285-
* This does a plain atomic user space read, and the user pointer has
286-
* already been verified earlier by get_futex_key() to be both aligned
287-
* and actually in user space, just like futex_atomic_cmpxchg_inatomic().
288-
*
289-
* We still want to avoid any speculation, and while __get_user() is
290-
* the traditional model for this, it's actually slower than doing
291-
* this manually these days.
292-
*
293-
* We could just have a per-architecture special function for it,
294-
* the same way we do futex_atomic_cmpxchg_inatomic(), but rather
295-
* than force everybody to do that, write it out long-hand using
296-
* the low-level user-access infrastructure.
297-
*
298-
* This looks a bit overkill, but generally just results in a couple
299-
* of instructions.
300-
*/
301-
static __always_inline int futex_get_value(u32 *dest, u32 __user *from)
302-
{
303-
u32 val;
304-
305-
if (can_do_masked_user_access())
306-
from = masked_user_access_begin(from);
307-
else if (!user_read_access_begin(from, sizeof(*from)))
308-
return -EFAULT;
309-
unsafe_get_user(val, from, Efault);
310-
user_read_access_end();
311-
*dest = val;
312-
return 0;
313-
Efault:
314-
user_read_access_end();
315-
return -EFAULT;
316-
}
317-
318-
static __always_inline int futex_put_value(u32 val, u32 __user *to)
319-
{
320-
if (can_do_masked_user_access())
321-
to = masked_user_access_begin(to);
322-
else if (!user_write_access_begin(to, sizeof(*to)))
323-
return -EFAULT;
324-
unsafe_put_user(val, to, Efault);
325-
user_write_access_end();
326-
return 0;
327-
Efault:
328-
user_write_access_end();
329-
return -EFAULT;
330-
}
331-
284+
/* Read from user memory with pagefaults disabled */
332285
static inline int futex_get_value_locked(u32 *dest, u32 __user *from)
333286
{
334-
int ret;
335-
336-
pagefault_disable();
337-
ret = futex_get_value(dest, from);
338-
pagefault_enable();
339-
340-
return ret;
287+
guard(pagefault)();
288+
return get_user_inline(*dest, from);
341289
}
342290

343291
extern void __futex_unqueue(struct futex_q *q);

0 commit comments

Comments
 (0)