hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/kernel/time/posix-timers.c
....@@ -1,34 +1,13 @@
1
+// SPDX-License-Identifier: GPL-2.0+
12 /*
2
- * linux/kernel/posix-timers.c
3
- *
4
- *
53 * 2002-10-15 Posix Clocks & timers
64 * by George Anzinger george@mvista.com
7
- *
85 * Copyright (C) 2002 2003 by MontaVista Software.
96 *
107 * 2004-06-01 Fix CLOCK_REALTIME clock/timer TIMER_ABSTIME bug.
118 * Copyright (C) 2004 Boris Hu
129 *
13
- * This program is free software; you can redistribute it and/or modify
14
- * it under the terms of the GNU General Public License as published by
15
- * the Free Software Foundation; either version 2 of the License, or (at
16
- * your option) any later version.
17
- *
18
- * This program is distributed in the hope that it will be useful, but
19
- * WITHOUT ANY WARRANTY; without even the implied warranty of
20
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21
- * General Public License for more details.
22
-
23
- * You should have received a copy of the GNU General Public License
24
- * along with this program; if not, write to the Free Software
25
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26
- *
27
- * MontaVista Software | 1237 East Arques Avenue | Sunnyvale | CA 94085 | USA
28
- */
29
-
30
-/* These are all the functions necessary to implement
31
- * POSIX clocks & timers
10
+ * These are all the functions necessary to implement POSIX clocks & timers
3211 */
3312 #include <linux/mm.h>
3413 #include <linux/interrupt.h>
....@@ -51,6 +30,7 @@
5130 #include <linux/hashtable.h>
5231 #include <linux/compat.h>
5332 #include <linux/nospec.h>
33
+#include <linux/time_namespace.h>
5434
5535 #include "timekeeping.h"
5636 #include "posix-timers.h"
....@@ -141,7 +121,8 @@
141121 {
142122 struct k_itimer *timer;
143123
144
- hlist_for_each_entry_rcu(timer, head, t_hash) {
124
+ hlist_for_each_entry_rcu(timer, head, t_hash,
125
+ lockdep_is_held(&hash_lock)) {
145126 if ((timer->it_signal == sig) && (timer->it_id == id))
146127 return timer;
147128 }
....@@ -186,10 +167,15 @@
186167 }
187168
188169 /* Get clock_realtime */
189
-static int posix_clock_realtime_get(clockid_t which_clock, struct timespec64 *tp)
170
+static int posix_get_realtime_timespec(clockid_t which_clock, struct timespec64 *tp)
190171 {
191172 ktime_get_real_ts64(tp);
192173 return 0;
174
+}
175
+
176
+static ktime_t posix_get_realtime_ktime(clockid_t which_clock)
177
+{
178
+ return ktime_get_real();
193179 }
194180
195181 /* Set clock_realtime */
....@@ -200,7 +186,7 @@
200186 }
201187
202188 static int posix_clock_realtime_adj(const clockid_t which_clock,
203
- struct timex *t)
189
+ struct __kernel_timex *t)
204190 {
205191 return do_adjtimex(t);
206192 }
....@@ -208,10 +194,16 @@
208194 /*
209195 * Get monotonic time for posix timers
210196 */
211
-static int posix_ktime_get_ts(clockid_t which_clock, struct timespec64 *tp)
197
+static int posix_get_monotonic_timespec(clockid_t which_clock, struct timespec64 *tp)
212198 {
213199 ktime_get_ts64(tp);
200
+ timens_add_monotonic(tp);
214201 return 0;
202
+}
203
+
204
+static ktime_t posix_get_monotonic_ktime(clockid_t which_clock)
205
+{
206
+ return ktime_get();
215207 }
216208
217209 /*
....@@ -220,6 +212,7 @@
220212 static int posix_get_monotonic_raw(clockid_t which_clock, struct timespec64 *tp)
221213 {
222214 ktime_get_raw_ts64(tp);
215
+ timens_add_monotonic(tp);
223216 return 0;
224217 }
225218
....@@ -234,6 +227,7 @@
234227 struct timespec64 *tp)
235228 {
236229 ktime_get_coarse_ts64(tp);
230
+ timens_add_monotonic(tp);
237231 return 0;
238232 }
239233
....@@ -243,16 +237,27 @@
243237 return 0;
244238 }
245239
246
-static int posix_get_boottime(const clockid_t which_clock, struct timespec64 *tp)
240
+static int posix_get_boottime_timespec(const clockid_t which_clock, struct timespec64 *tp)
247241 {
248242 ktime_get_boottime_ts64(tp);
243
+ timens_add_boottime(tp);
249244 return 0;
250245 }
251246
252
-static int posix_get_tai(clockid_t which_clock, struct timespec64 *tp)
247
+static ktime_t posix_get_boottime_ktime(const clockid_t which_clock)
248
+{
249
+ return ktime_get_boottime();
250
+}
251
+
252
+static int posix_get_tai_timespec(clockid_t which_clock, struct timespec64 *tp)
253253 {
254254 ktime_get_clocktai_ts64(tp);
255255 return 0;
256
+}
257
+
258
+static ktime_t posix_get_tai_ktime(clockid_t which_clock)
259
+{
260
+ return ktime_get_clocktai();
256261 }
257262
258263 static int posix_get_hrtimer_res(clockid_t which_clock, struct timespec64 *tp)
....@@ -305,7 +310,7 @@
305310 * To protect against the timer going away while the interrupt is queued,
306311 * we require that the it_requeue_pending flag be set.
307312 */
308
-void posixtimer_rearm(struct siginfo *info)
313
+void posixtimer_rearm(struct kernel_siginfo *info)
309314 {
310315 struct k_itimer *timr;
311316 unsigned long flags;
....@@ -434,12 +439,12 @@
434439 rtn = pid_task(pid, PIDTYPE_PID);
435440 if (!rtn || !same_thread_group(rtn, current))
436441 return NULL;
437
- /* FALLTHRU */
442
+ fallthrough;
438443 case SIGEV_SIGNAL:
439444 case SIGEV_THREAD:
440445 if (event->sigev_signo <= 0 || event->sigev_signo > SIGRTMAX)
441446 return NULL;
442
- /* FALLTHRU */
447
+ fallthrough;
443448 case SIGEV_NONE:
444449 return pid;
445450 default:
....@@ -463,7 +468,7 @@
463468
464469 static void k_itimer_rcu_free(struct rcu_head *head)
465470 {
466
- struct k_itimer *tmr = container_of(head, struct k_itimer, it.rcu);
471
+ struct k_itimer *tmr = container_of(head, struct k_itimer, rcu);
467472
468473 kmem_cache_free(posix_timers_cache, tmr);
469474 }
....@@ -480,7 +485,7 @@
480485 }
481486 put_pid(tmr->it_pid);
482487 sigqueue_free(tmr->sigq);
483
- call_rcu(&tmr->it.rcu, k_itimer_rcu_free);
488
+ call_rcu(&tmr->rcu, k_itimer_rcu_free);
484489 }
485490
486491 static int common_timer_create(struct k_itimer *new_timer)
....@@ -666,7 +671,6 @@
666671 {
667672 const struct k_clock *kc = timr->kclock;
668673 ktime_t now, remaining, iv;
669
- struct timespec64 ts64;
670674 bool sig_none;
671675
672676 sig_none = timr->it_sigev_notify == SIGEV_NONE;
....@@ -684,12 +688,7 @@
684688 return;
685689 }
686690
687
- /*
688
- * The timespec64 based conversion is suboptimal, but it's not
689
- * worth to implement yet another callback.
690
- */
691
- kc->clock_get(timr->it_clock, &ts64);
692
- now = timespec64_to_ktime(ts64);
691
+ now = kc->clock_get_ktime(timr->it_clock);
693692
694693 /*
695694 * When a requeue is pending or this is a SIGEV_NONE timer move the
....@@ -751,14 +750,14 @@
751750
752751 #ifdef CONFIG_COMPAT_32BIT_TIME
753752
754
-COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
755
- struct compat_itimerspec __user *, setting)
753
+SYSCALL_DEFINE2(timer_gettime32, timer_t, timer_id,
754
+ struct old_itimerspec32 __user *, setting)
756755 {
757756 struct itimerspec64 cur_setting;
758757
759758 int ret = do_timer_gettime(timer_id, &cur_setting);
760759 if (!ret) {
761
- if (put_compat_itimerspec64(&cur_setting, setting))
760
+ if (put_old_itimerspec32(&cur_setting, setting))
762761 ret = -EFAULT;
763762 }
764763 return ret;
....@@ -802,7 +801,7 @@
802801 * Posix magic: Relative CLOCK_REALTIME timers are not affected by
803802 * clock modifications, so they become CLOCK_MONOTONIC based under the
804803 * hood. See hrtimer_init(). Update timr->kclock, so the generic
805
- * functions which use timr->kclock->clock_get() work.
804
+ * functions which use timr->kclock->clock_get_*() work.
806805 *
807806 * Note: it_clock stays unmodified, because the next timer_set() might
808807 * use ABSTIME, so it needs to switch back.
....@@ -824,6 +823,39 @@
824823 static int common_hrtimer_try_to_cancel(struct k_itimer *timr)
825824 {
826825 return hrtimer_try_to_cancel(&timr->it.real.timer);
826
+}
827
+
828
+static void common_timer_wait_running(struct k_itimer *timer)
829
+{
830
+ hrtimer_cancel_wait_running(&timer->it.real.timer);
831
+}
832
+
833
+/*
834
+ * On PREEMPT_RT this prevent priority inversion against softirq kthread in
835
+ * case it gets preempted while executing a timer callback. See comments in
836
+ * hrtimer_cancel_wait_running. For PREEMPT_RT=n this just results in a
837
+ * cpu_relax().
838
+ */
839
+static struct k_itimer *timer_wait_running(struct k_itimer *timer,
840
+ unsigned long *flags)
841
+{
842
+ const struct k_clock *kc = READ_ONCE(timer->kclock);
843
+ timer_t timer_id = READ_ONCE(timer->it_id);
844
+
845
+ /* Prevent kfree(timer) after dropping the lock */
846
+ rcu_read_lock();
847
+ unlock_timer(timer, *flags);
848
+
849
+ /*
850
+ * kc->timer_wait_running() might drop RCU lock. So @timer
851
+ * cannot be touched anymore after the function returns!
852
+ */
853
+ if (!WARN_ON_ONCE(!kc->timer_wait_running))
854
+ kc->timer_wait_running(timer);
855
+
856
+ rcu_read_unlock();
857
+ /* Relock the timer. It might be not longer hashed. */
858
+ return lock_timer(timer_id, flags);
827859 }
828860
829861 /* Set a POSIX.1b interval timer. */
....@@ -858,6 +890,8 @@
858890
859891 timr->it_interval = timespec64_to_ktime(new_setting->it_interval);
860892 expires = timespec64_to_ktime(new_setting->it_value);
893
+ if (flags & TIMER_ABSTIME)
894
+ expires = timens_ktime_to_host(timr->it_clock, expires);
861895 sigev_none = timr->it_sigev_notify == SIGEV_NONE;
862896
863897 kc->timer_arm(timr, expires, flags & TIMER_ABSTIME, sigev_none);
....@@ -865,13 +899,13 @@
865899 return 0;
866900 }
867901
868
-static int do_timer_settime(timer_t timer_id, int flags,
902
+static int do_timer_settime(timer_t timer_id, int tmr_flags,
869903 struct itimerspec64 *new_spec64,
870904 struct itimerspec64 *old_spec64)
871905 {
872906 const struct k_clock *kc;
873907 struct k_itimer *timr;
874
- unsigned long flag;
908
+ unsigned long flags;
875909 int error = 0;
876910
877911 if (!timespec64_valid(&new_spec64->it_interval) ||
....@@ -880,8 +914,9 @@
880914
881915 if (old_spec64)
882916 memset(old_spec64, 0, sizeof(*old_spec64));
917
+
918
+ timr = lock_timer(timer_id, &flags);
883919 retry:
884
- timr = lock_timer(timer_id, &flag);
885920 if (!timr)
886921 return -EINVAL;
887922
....@@ -889,13 +924,16 @@
889924 if (WARN_ON_ONCE(!kc || !kc->timer_set))
890925 error = -EINVAL;
891926 else
892
- error = kc->timer_set(timr, flags, new_spec64, old_spec64);
927
+ error = kc->timer_set(timr, tmr_flags, new_spec64, old_spec64);
893928
894
- unlock_timer(timr, flag);
895929 if (error == TIMER_RETRY) {
896
- old_spec64 = NULL; // We already got the old time...
930
+ // We already got the old time...
931
+ old_spec64 = NULL;
932
+ /* Unlocks and relocks the timer if it still exists */
933
+ timr = timer_wait_running(timr, &flags);
897934 goto retry;
898935 }
936
+ unlock_timer(timr, flags);
899937
900938 return error;
901939 }
....@@ -924,9 +962,9 @@
924962 }
925963
926964 #ifdef CONFIG_COMPAT_32BIT_TIME
927
-COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
928
- struct compat_itimerspec __user *, new,
929
- struct compat_itimerspec __user *, old)
965
+SYSCALL_DEFINE4(timer_settime32, timer_t, timer_id, int, flags,
966
+ struct old_itimerspec32 __user *, new,
967
+ struct old_itimerspec32 __user *, old)
930968 {
931969 struct itimerspec64 new_spec, old_spec;
932970 struct itimerspec64 *rtn = old ? &old_spec : NULL;
....@@ -934,12 +972,12 @@
934972
935973 if (!new)
936974 return -EINVAL;
937
- if (get_compat_itimerspec64(&new_spec, new))
975
+ if (get_old_itimerspec32(&new_spec, new))
938976 return -EFAULT;
939977
940978 error = do_timer_settime(timer_id, flags, &new_spec, rtn);
941979 if (!error && old) {
942
- if (put_compat_itimerspec64(&old_spec, old))
980
+ if (put_old_itimerspec32(&old_spec, old))
943981 error = -EFAULT;
944982 }
945983 return error;
....@@ -972,13 +1010,15 @@
9721010 struct k_itimer *timer;
9731011 unsigned long flags;
9741012
975
-retry_delete:
9761013 timer = lock_timer(timer_id, &flags);
1014
+
1015
+retry_delete:
9771016 if (!timer)
9781017 return -EINVAL;
9791018
980
- if (timer_delete_hook(timer) == TIMER_RETRY) {
981
- unlock_timer(timer, flags);
1019
+ if (unlikely(timer_delete_hook(timer) == TIMER_RETRY)) {
1020
+ /* Unlocks and relocks the timer if it still exists */
1021
+ timer = timer_wait_running(timer, &flags);
9821022 goto retry_delete;
9831023 }
9841024
....@@ -997,40 +1037,69 @@
9971037 }
9981038
9991039 /*
1000
- * return timer owned by the process, used by exit_itimers
1040
+ * Delete a timer if it is armed, remove it from the hash and schedule it
1041
+ * for RCU freeing.
10011042 */
10021043 static void itimer_delete(struct k_itimer *timer)
10031044 {
10041045 unsigned long flags;
10051046
1006
-retry_delete:
1047
+ /*
1048
+ * irqsave is required to make timer_wait_running() work.
1049
+ */
10071050 spin_lock_irqsave(&timer->it_lock, flags);
10081051
1052
+retry_delete:
1053
+ /*
1054
+ * Even if the timer is not longer accessible from other tasks
1055
+ * it still might be armed and queued in the underlying timer
1056
+ * mechanism. Worse, that timer mechanism might run the expiry
1057
+ * function concurrently.
1058
+ */
10091059 if (timer_delete_hook(timer) == TIMER_RETRY) {
1010
- unlock_timer(timer, flags);
1060
+ /*
1061
+ * Timer is expired concurrently, prevent livelocks
1062
+ * and pointless spinning on RT.
1063
+ *
1064
+ * timer_wait_running() drops timer::it_lock, which opens
1065
+ * the possibility for another task to delete the timer.
1066
+ *
1067
+ * That's not possible here because this is invoked from
1068
+ * do_exit() only for the last thread of the thread group.
1069
+ * So no other task can access and delete that timer.
1070
+ */
1071
+ if (WARN_ON_ONCE(timer_wait_running(timer, &flags) != timer))
1072
+ return;
1073
+
10111074 goto retry_delete;
10121075 }
10131076 list_del(&timer->list);
1014
- /*
1015
- * This keeps any tasks waiting on the spin lock from thinking
1016
- * they got something (see the lock code above).
1017
- */
1018
- timer->it_signal = NULL;
10191077
1020
- unlock_timer(timer, flags);
1078
+ spin_unlock_irqrestore(&timer->it_lock, flags);
10211079 release_posix_timer(timer, IT_ID_SET);
10221080 }
10231081
10241082 /*
1025
- * This is called by do_exit or de_thread, only when there are no more
1026
- * references to the shared signal_struct.
1083
+ * Invoked from do_exit() when the last thread of a thread group exits.
1084
+ * At that point no other task can access the timers of the dying
1085
+ * task anymore.
10271086 */
1028
-void exit_itimers(struct signal_struct *sig)
1087
+void exit_itimers(struct task_struct *tsk)
10291088 {
1089
+ struct list_head timers;
10301090 struct k_itimer *tmr;
10311091
1032
- while (!list_empty(&sig->posix_timers)) {
1033
- tmr = list_entry(sig->posix_timers.next, struct k_itimer, list);
1092
+ if (list_empty(&tsk->signal->posix_timers))
1093
+ return;
1094
+
1095
+ /* Protect against concurrent read via /proc/$PID/timers */
1096
+ spin_lock_irq(&tsk->sighand->siglock);
1097
+ list_replace_init(&tsk->signal->posix_timers, &timers);
1098
+ spin_unlock_irq(&tsk->sighand->siglock);
1099
+
1100
+ /* The timers are not longer accessible via tsk::signal */
1101
+ while (!list_empty(&timers)) {
1102
+ tmr = list_first_entry(&timers, struct k_itimer, list);
10341103 itimer_delete(tmr);
10351104 }
10361105 }
....@@ -1060,7 +1129,7 @@
10601129 if (!kc)
10611130 return -EINVAL;
10621131
1063
- error = kc->clock_get(which_clock, &kernel_tp);
1132
+ error = kc->clock_get_timespec(which_clock, &kernel_tp);
10641133
10651134 if (!error && put_timespec64(&kernel_tp, tp))
10661135 error = -EFAULT;
....@@ -1068,22 +1137,28 @@
10681137 return error;
10691138 }
10701139
1071
-SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock,
1072
- struct timex __user *, utx)
1140
+int do_clock_adjtime(const clockid_t which_clock, struct __kernel_timex * ktx)
10731141 {
10741142 const struct k_clock *kc = clockid_to_kclock(which_clock);
1075
- struct timex ktx;
1076
- int err;
10771143
10781144 if (!kc)
10791145 return -EINVAL;
10801146 if (!kc->clock_adj)
10811147 return -EOPNOTSUPP;
10821148
1149
+ return kc->clock_adj(which_clock, ktx);
1150
+}
1151
+
1152
+SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock,
1153
+ struct __kernel_timex __user *, utx)
1154
+{
1155
+ struct __kernel_timex ktx;
1156
+ int err;
1157
+
10831158 if (copy_from_user(&ktx, utx, sizeof(ktx)))
10841159 return -EFAULT;
10851160
1086
- err = kc->clock_adj(which_clock, &ktx);
1161
+ err = do_clock_adjtime(which_clock, &ktx);
10871162
10881163 if (err >= 0 && copy_to_user(utx, &ktx, sizeof(ktx)))
10891164 return -EFAULT;
....@@ -1111,8 +1186,8 @@
11111186
11121187 #ifdef CONFIG_COMPAT_32BIT_TIME
11131188
1114
-COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock,
1115
- struct compat_timespec __user *, tp)
1189
+SYSCALL_DEFINE2(clock_settime32, clockid_t, which_clock,
1190
+ struct old_timespec32 __user *, tp)
11161191 {
11171192 const struct k_clock *kc = clockid_to_kclock(which_clock);
11181193 struct timespec64 ts;
....@@ -1120,14 +1195,14 @@
11201195 if (!kc || !kc->clock_set)
11211196 return -EINVAL;
11221197
1123
- if (compat_get_timespec64(&ts, tp))
1198
+ if (get_old_timespec32(&ts, tp))
11241199 return -EFAULT;
11251200
11261201 return kc->clock_set(which_clock, &ts);
11271202 }
11281203
1129
-COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
1130
- struct compat_timespec __user *, tp)
1204
+SYSCALL_DEFINE2(clock_gettime32, clockid_t, which_clock,
1205
+ struct old_timespec32 __user *, tp)
11311206 {
11321207 const struct k_clock *kc = clockid_to_kclock(which_clock);
11331208 struct timespec64 ts;
....@@ -1136,48 +1211,34 @@
11361211 if (!kc)
11371212 return -EINVAL;
11381213
1139
- err = kc->clock_get(which_clock, &ts);
1214
+ err = kc->clock_get_timespec(which_clock, &ts);
11401215
1141
- if (!err && compat_put_timespec64(&ts, tp))
1216
+ if (!err && put_old_timespec32(&ts, tp))
11421217 err = -EFAULT;
11431218
11441219 return err;
11451220 }
11461221
1147
-#endif
1148
-
1149
-#ifdef CONFIG_COMPAT
1150
-
1151
-COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock,
1152
- struct compat_timex __user *, utp)
1222
+SYSCALL_DEFINE2(clock_adjtime32, clockid_t, which_clock,
1223
+ struct old_timex32 __user *, utp)
11531224 {
1154
- const struct k_clock *kc = clockid_to_kclock(which_clock);
1155
- struct timex ktx;
1225
+ struct __kernel_timex ktx;
11561226 int err;
11571227
1158
- if (!kc)
1159
- return -EINVAL;
1160
- if (!kc->clock_adj)
1161
- return -EOPNOTSUPP;
1162
-
1163
- err = compat_get_timex(&ktx, utp);
1228
+ err = get_old_timex32(&ktx, utp);
11641229 if (err)
11651230 return err;
11661231
1167
- err = kc->clock_adj(which_clock, &ktx);
1232
+ err = do_clock_adjtime(which_clock, &ktx);
11681233
1169
- if (err >= 0 && compat_put_timex(utp, &ktx))
1234
+ if (err >= 0 && put_old_timex32(utp, &ktx))
11701235 return -EFAULT;
11711236
11721237 return err;
11731238 }
11741239
1175
-#endif
1176
-
1177
-#ifdef CONFIG_COMPAT_32BIT_TIME
1178
-
1179
-COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
1180
- struct compat_timespec __user *, tp)
1240
+SYSCALL_DEFINE2(clock_getres_time32, clockid_t, which_clock,
1241
+ struct old_timespec32 __user *, tp)
11811242 {
11821243 const struct k_clock *kc = clockid_to_kclock(which_clock);
11831244 struct timespec64 ts;
....@@ -1187,7 +1248,7 @@
11871248 return -EINVAL;
11881249
11891250 err = kc->clock_getres(which_clock, &ts);
1190
- if (!err && tp && compat_put_timespec64(&ts, tp))
1251
+ if (!err && tp && put_old_timespec32(&ts, tp))
11911252 return -EFAULT;
11921253
11931254 return err;
....@@ -1201,7 +1262,22 @@
12011262 static int common_nsleep(const clockid_t which_clock, int flags,
12021263 const struct timespec64 *rqtp)
12031264 {
1204
- return hrtimer_nanosleep(rqtp, flags & TIMER_ABSTIME ?
1265
+ ktime_t texp = timespec64_to_ktime(*rqtp);
1266
+
1267
+ return hrtimer_nanosleep(texp, flags & TIMER_ABSTIME ?
1268
+ HRTIMER_MODE_ABS : HRTIMER_MODE_REL,
1269
+ which_clock);
1270
+}
1271
+
1272
+static int common_nsleep_timens(const clockid_t which_clock, int flags,
1273
+ const struct timespec64 *rqtp)
1274
+{
1275
+ ktime_t texp = timespec64_to_ktime(*rqtp);
1276
+
1277
+ if (flags & TIMER_ABSTIME)
1278
+ texp = timens_ktime_to_host(which_clock, texp);
1279
+
1280
+ return hrtimer_nanosleep(texp, flags & TIMER_ABSTIME ?
12051281 HRTIMER_MODE_ABS : HRTIMER_MODE_REL,
12061282 which_clock);
12071283 }
....@@ -1225,6 +1301,7 @@
12251301 return -EINVAL;
12261302 if (flags & TIMER_ABSTIME)
12271303 rmtp = NULL;
1304
+ current->restart_block.fn = do_no_restart_syscall;
12281305 current->restart_block.nanosleep.type = rmtp ? TT_NATIVE : TT_NONE;
12291306 current->restart_block.nanosleep.rmtp = rmtp;
12301307
....@@ -1233,9 +1310,9 @@
12331310
12341311 #ifdef CONFIG_COMPAT_32BIT_TIME
12351312
1236
-COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
1237
- struct compat_timespec __user *, rqtp,
1238
- struct compat_timespec __user *, rmtp)
1313
+SYSCALL_DEFINE4(clock_nanosleep_time32, clockid_t, which_clock, int, flags,
1314
+ struct old_timespec32 __user *, rqtp,
1315
+ struct old_timespec32 __user *, rmtp)
12391316 {
12401317 const struct k_clock *kc = clockid_to_kclock(which_clock);
12411318 struct timespec64 t;
....@@ -1245,13 +1322,14 @@
12451322 if (!kc->nsleep)
12461323 return -EOPNOTSUPP;
12471324
1248
- if (compat_get_timespec64(&t, rqtp))
1325
+ if (get_old_timespec32(&t, rqtp))
12491326 return -EFAULT;
12501327
12511328 if (!timespec64_valid(&t))
12521329 return -EINVAL;
12531330 if (flags & TIMER_ABSTIME)
12541331 rmtp = NULL;
1332
+ current->restart_block.fn = do_no_restart_syscall;
12551333 current->restart_block.nanosleep.type = rmtp ? TT_COMPAT : TT_NONE;
12561334 current->restart_block.nanosleep.compat_rmtp = rmtp;
12571335
....@@ -1262,7 +1340,8 @@
12621340
12631341 static const struct k_clock clock_realtime = {
12641342 .clock_getres = posix_get_hrtimer_res,
1265
- .clock_get = posix_clock_realtime_get,
1343
+ .clock_get_timespec = posix_get_realtime_timespec,
1344
+ .clock_get_ktime = posix_get_realtime_ktime,
12661345 .clock_set = posix_clock_realtime_set,
12671346 .clock_adj = posix_clock_realtime_adj,
12681347 .nsleep = common_nsleep,
....@@ -1274,13 +1353,15 @@
12741353 .timer_forward = common_hrtimer_forward,
12751354 .timer_remaining = common_hrtimer_remaining,
12761355 .timer_try_to_cancel = common_hrtimer_try_to_cancel,
1356
+ .timer_wait_running = common_timer_wait_running,
12771357 .timer_arm = common_hrtimer_arm,
12781358 };
12791359
12801360 static const struct k_clock clock_monotonic = {
12811361 .clock_getres = posix_get_hrtimer_res,
1282
- .clock_get = posix_ktime_get_ts,
1283
- .nsleep = common_nsleep,
1362
+ .clock_get_timespec = posix_get_monotonic_timespec,
1363
+ .clock_get_ktime = posix_get_monotonic_ktime,
1364
+ .nsleep = common_nsleep_timens,
12841365 .timer_create = common_timer_create,
12851366 .timer_set = common_timer_set,
12861367 .timer_get = common_timer_get,
....@@ -1289,27 +1370,29 @@
12891370 .timer_forward = common_hrtimer_forward,
12901371 .timer_remaining = common_hrtimer_remaining,
12911372 .timer_try_to_cancel = common_hrtimer_try_to_cancel,
1373
+ .timer_wait_running = common_timer_wait_running,
12921374 .timer_arm = common_hrtimer_arm,
12931375 };
12941376
12951377 static const struct k_clock clock_monotonic_raw = {
12961378 .clock_getres = posix_get_hrtimer_res,
1297
- .clock_get = posix_get_monotonic_raw,
1379
+ .clock_get_timespec = posix_get_monotonic_raw,
12981380 };
12991381
13001382 static const struct k_clock clock_realtime_coarse = {
13011383 .clock_getres = posix_get_coarse_res,
1302
- .clock_get = posix_get_realtime_coarse,
1384
+ .clock_get_timespec = posix_get_realtime_coarse,
13031385 };
13041386
13051387 static const struct k_clock clock_monotonic_coarse = {
13061388 .clock_getres = posix_get_coarse_res,
1307
- .clock_get = posix_get_monotonic_coarse,
1389
+ .clock_get_timespec = posix_get_monotonic_coarse,
13081390 };
13091391
13101392 static const struct k_clock clock_tai = {
13111393 .clock_getres = posix_get_hrtimer_res,
1312
- .clock_get = posix_get_tai,
1394
+ .clock_get_ktime = posix_get_tai_ktime,
1395
+ .clock_get_timespec = posix_get_tai_timespec,
13131396 .nsleep = common_nsleep,
13141397 .timer_create = common_timer_create,
13151398 .timer_set = common_timer_set,
....@@ -1319,13 +1402,15 @@
13191402 .timer_forward = common_hrtimer_forward,
13201403 .timer_remaining = common_hrtimer_remaining,
13211404 .timer_try_to_cancel = common_hrtimer_try_to_cancel,
1405
+ .timer_wait_running = common_timer_wait_running,
13221406 .timer_arm = common_hrtimer_arm,
13231407 };
13241408
13251409 static const struct k_clock clock_boottime = {
13261410 .clock_getres = posix_get_hrtimer_res,
1327
- .clock_get = posix_get_boottime,
1328
- .nsleep = common_nsleep,
1411
+ .clock_get_ktime = posix_get_boottime_ktime,
1412
+ .clock_get_timespec = posix_get_boottime_timespec,
1413
+ .nsleep = common_nsleep_timens,
13291414 .timer_create = common_timer_create,
13301415 .timer_set = common_timer_set,
13311416 .timer_get = common_timer_get,
....@@ -1334,6 +1419,7 @@
13341419 .timer_forward = common_hrtimer_forward,
13351420 .timer_remaining = common_hrtimer_remaining,
13361421 .timer_try_to_cancel = common_hrtimer_try_to_cancel,
1422
+ .timer_wait_running = common_timer_wait_running,
13371423 .timer_arm = common_hrtimer_arm,
13381424 };
13391425