[PATCH 1/4] introduce set_restart_fn()

From: Oleg Nesterov
Date: Fri Nov 29 2019 - 10:51:12 EST


---
fs/select.c | 10 ++++------
include/linux/thread_info.h | 12 ++++++++++++
kernel/futex.c | 3 +--
kernel/time/alarmtimer.c | 2 +-
kernel/time/hrtimer.c | 2 +-
kernel/time/posix-cpu-timers.c | 2 +-
6 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/fs/select.c b/fs/select.c
index 53a0c14..e517960 100644
--- a/fs/select.c
+++ b/fs/select.c
@@ -1037,10 +1037,9 @@ static long do_restart_poll(struct restart_block *re=
start_block)
=20
=09ret =3D do_sys_poll(ufds, nfds, to);
=20
-=09if (ret =3D=3D -ERESTARTNOHAND) {
-=09=09restart_block->fn =3D do_restart_poll;
-=09=09ret =3D -ERESTART_RESTARTBLOCK;
-=09}
+=09if (ret =3D=3D -ERESTARTNOHAND)
+=09=09ret =3D set_restart_fn(restart_block, do_restart_poll);
+
=09return ret;
}
=20
@@ -1062,7 +1061,6 @@ SYSCALL_DEFINE3(poll, struct pollfd __user *, ufds, u=
nsigned int, nfds,
=09=09struct restart_block *restart_block;
=20
=09=09restart_block =3D &current->restart_block;
-=09=09restart_block->fn =3D do_restart_poll;
=09=09restart_block->poll.ufds =3D ufds;
=09=09restart_block->poll.nfds =3D nfds;
=20
@@ -1073,7 +1071,7 @@ SYSCALL_DEFINE3(poll, struct pollfd __user *, ufds, u=
nsigned int, nfds,
=09=09} else
=09=09=09restart_block->poll.has_timeout =3D 0;
=20
-=09=09ret =3D -ERESTART_RESTARTBLOCK;
+=09=09ret =3D set_restart_fn(restart_block, do_restart_poll);
=09}
=09return ret;
}
diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
index 659a440..df8e3fb 100644
--- a/include/linux/thread_info.h
+++ b/include/linux/thread_info.h
@@ -39,6 +39,18 @@ enum {
=20
#ifdef __KERNEL__
=20
+#ifndef arch_set_restart_data
+#define arch_set_restart_data(restart) do { } while (0)
+#endif
+
+static inline long set_restart_fn(struct restart_block *restart,
+=09=09=09=09=09long (*fn)(struct restart_block *))
+{
+=09restart->fn =3D fn;
+=09arch_set_restart_data(restart);
+=09return -ERESTART_RESTARTBLOCK;
+}
+
#ifndef THREAD_ALIGN
#define THREAD_ALIGN=09THREAD_SIZE
#endif
diff --git a/kernel/futex.c b/kernel/futex.c
index bd18f60..f4f20e9 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -2753,14 +2753,13 @@ static int futex_wait(u32 __user *uaddr, unsigned i=
nt flags, u32 val,
=09=09goto out;
=20
=09restart =3D &current->restart_block;
-=09restart->fn =3D futex_wait_restart;
=09restart->futex.uaddr =3D uaddr;
=09restart->futex.val =3D val;
=09restart->futex.time =3D *abs_time;
=09restart->futex.bitset =3D bitset;
=09restart->futex.flags =3D flags | FLAGS_HAS_TIMEOUT;
=20
-=09ret =3D -ERESTART_RESTARTBLOCK;
+=09ret =3D set_restart_fn(restart, futex_wait_restart);
=20
out:
=09if (to) {
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index 451f9d0..a2ddf56 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -829,9 +829,9 @@ static int alarm_timer_nsleep(const clockid_t which_clo=
ck, int flags,
=09if (flags =3D=3D TIMER_ABSTIME)
=09=09return -ERESTARTNOHAND;
=20
-=09restart->fn =3D alarm_timer_nsleep_restart;
=09restart->nanosleep.clockid =3D type;
=09restart->nanosleep.expires =3D exp;
+=09set_restart_fn(restart, alarm_timer_nsleep_restart);
=09return ret;
}
=20
diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index 6560553..55f71c4 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -1932,9 +1932,9 @@ long hrtimer_nanosleep(const struct timespec64 *rqtp,
=09}
=20
=09restart =3D &current->restart_block;
-=09restart->fn =3D hrtimer_nanosleep_restart;
=09restart->nanosleep.clockid =3D t.timer.base->clockid;
=09restart->nanosleep.expires =3D hrtimer_get_expires_tv64(&t.timer);
+=09set_restart_fn(restart, hrtimer_nanosleep_restart);
out:
=09destroy_hrtimer_on_stack(&t.timer);
=09return ret;
diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.=
c
index 42d512f..eacb0ca 100644
--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -1335,8 +1335,8 @@ static int posix_cpu_nsleep(const clockid_t which_clo=
ck, int flags,
=09=09if (flags & TIMER_ABSTIME)
=09=09=09return -ERESTARTNOHAND;
=20
-=09=09restart_block->fn =3D posix_cpu_nsleep_restart;
=09=09restart_block->nanosleep.clockid =3D which_clock;
+=09=09set_restart_fn(restart_block, posix_cpu_nsleep_restart);
=09}
=09return error;
}
--=20
2.5.0