Skip to content

Commit 5abbe51

Browse files
oleg-nesterovKAGA-KOKO
authored andcommitted
kernel, fs: Introduce and use set_restart_fn() and arch_set_restart_data()
Preparation for fixing get_nr_restart_syscall() on X86 for COMPAT. Add a new helper which sets restart_block->fn and calls a dummy arch_set_restart_data() helper. Fixes: 609c19a ("x86/ptrace: Stop setting TS_COMPAT in ptrace code") Signed-off-by: Oleg Nesterov <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected]
1 parent 1e28eed commit 5abbe51

File tree

6 files changed

+21
-11
lines changed

6 files changed

+21
-11
lines changed

fs/select.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,10 +1055,9 @@ static long do_restart_poll(struct restart_block *restart_block)
10551055

10561056
ret = do_sys_poll(ufds, nfds, to);
10571057

1058-
if (ret == -ERESTARTNOHAND) {
1059-
restart_block->fn = do_restart_poll;
1060-
ret = -ERESTART_RESTARTBLOCK;
1061-
}
1058+
if (ret == -ERESTARTNOHAND)
1059+
ret = set_restart_fn(restart_block, do_restart_poll);
1060+
10621061
return ret;
10631062
}
10641063

@@ -1080,7 +1079,6 @@ SYSCALL_DEFINE3(poll, struct pollfd __user *, ufds, unsigned int, nfds,
10801079
struct restart_block *restart_block;
10811080

10821081
restart_block = &current->restart_block;
1083-
restart_block->fn = do_restart_poll;
10841082
restart_block->poll.ufds = ufds;
10851083
restart_block->poll.nfds = nfds;
10861084

@@ -1091,7 +1089,7 @@ SYSCALL_DEFINE3(poll, struct pollfd __user *, ufds, unsigned int, nfds,
10911089
} else
10921090
restart_block->poll.has_timeout = 0;
10931091

1094-
ret = -ERESTART_RESTARTBLOCK;
1092+
ret = set_restart_fn(restart_block, do_restart_poll);
10951093
}
10961094
return ret;
10971095
}

include/linux/thread_info.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/types.h>
1212
#include <linux/bug.h>
1313
#include <linux/restart_block.h>
14+
#include <linux/errno.h>
1415

1516
#ifdef CONFIG_THREAD_INFO_IN_TASK
1617
/*
@@ -59,6 +60,18 @@ enum syscall_work_bit {
5960

6061
#ifdef __KERNEL__
6162

63+
#ifndef arch_set_restart_data
64+
#define arch_set_restart_data(restart) do { } while (0)
65+
#endif
66+
67+
static inline long set_restart_fn(struct restart_block *restart,
68+
long (*fn)(struct restart_block *))
69+
{
70+
restart->fn = fn;
71+
arch_set_restart_data(restart);
72+
return -ERESTART_RESTARTBLOCK;
73+
}
74+
6275
#ifndef THREAD_ALIGN
6376
#define THREAD_ALIGN THREAD_SIZE
6477
#endif

kernel/futex.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2728,14 +2728,13 @@ static int futex_wait(u32 __user *uaddr, unsigned int flags, u32 val,
27282728
goto out;
27292729

27302730
restart = &current->restart_block;
2731-
restart->fn = futex_wait_restart;
27322731
restart->futex.uaddr = uaddr;
27332732
restart->futex.val = val;
27342733
restart->futex.time = *abs_time;
27352734
restart->futex.bitset = bitset;
27362735
restart->futex.flags = flags | FLAGS_HAS_TIMEOUT;
27372736

2738-
ret = -ERESTART_RESTARTBLOCK;
2737+
ret = set_restart_fn(restart, futex_wait_restart);
27392738

27402739
out:
27412740
if (to) {

kernel/time/alarmtimer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,9 +854,9 @@ static int alarm_timer_nsleep(const clockid_t which_clock, int flags,
854854
if (flags == TIMER_ABSTIME)
855855
return -ERESTARTNOHAND;
856856

857-
restart->fn = alarm_timer_nsleep_restart;
858857
restart->nanosleep.clockid = type;
859858
restart->nanosleep.expires = exp;
859+
set_restart_fn(restart, alarm_timer_nsleep_restart);
860860
return ret;
861861
}
862862

kernel/time/hrtimer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1957,9 +1957,9 @@ long hrtimer_nanosleep(ktime_t rqtp, const enum hrtimer_mode mode,
19571957
}
19581958

19591959
restart = &current->restart_block;
1960-
restart->fn = hrtimer_nanosleep_restart;
19611960
restart->nanosleep.clockid = t.timer.base->clockid;
19621961
restart->nanosleep.expires = hrtimer_get_expires_tv64(&t.timer);
1962+
set_restart_fn(restart, hrtimer_nanosleep_restart);
19631963
out:
19641964
destroy_hrtimer_on_stack(&t.timer);
19651965
return ret;

kernel/time/posix-cpu-timers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1480,8 +1480,8 @@ static int posix_cpu_nsleep(const clockid_t which_clock, int flags,
14801480
if (flags & TIMER_ABSTIME)
14811481
return -ERESTARTNOHAND;
14821482

1483-
restart_block->fn = posix_cpu_nsleep_restart;
14841483
restart_block->nanosleep.clockid = which_clock;
1484+
set_restart_fn(restart_block, posix_cpu_nsleep_restart);
14851485
}
14861486
return error;
14871487
}

0 commit comments

Comments
 (0)