hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/fs/timerfd.c
....@@ -26,6 +26,9 @@
2626 #include <linux/syscalls.h>
2727 #include <linux/compat.h>
2828 #include <linux/rcupdate.h>
29
+#include <linux/time_namespace.h>
30
+
31
+#include <trace/hooks/fs.h>
2932
3033 struct timerfd_ctx {
3134 union {
....@@ -196,6 +199,8 @@
196199 }
197200
198201 if (texp != 0) {
202
+ if (flags & TFD_TIMER_ABSTIME)
203
+ texp = timens_ktime_to_host(clockid, texp);
199204 if (isalarm(ctx)) {
200205 if (flags & TFD_TIMER_ABSTIME)
201206 alarm_start(&ctx->t.alarm, texp);
....@@ -302,11 +307,11 @@
302307 static void timerfd_show(struct seq_file *m, struct file *file)
303308 {
304309 struct timerfd_ctx *ctx = file->private_data;
305
- struct itimerspec t;
310
+ struct timespec64 value, interval;
306311
307312 spin_lock_irq(&ctx->wqh.lock);
308
- t.it_value = ktime_to_timespec(timerfd_get_remaining(ctx));
309
- t.it_interval = ktime_to_timespec(ctx->tintv);
313
+ value = ktime_to_timespec64(timerfd_get_remaining(ctx));
314
+ interval = ktime_to_timespec64(ctx->tintv);
310315 spin_unlock_irq(&ctx->wqh.lock);
311316
312317 seq_printf(m,
....@@ -318,10 +323,10 @@
318323 ctx->clockid,
319324 (unsigned long long)ctx->ticks,
320325 ctx->settime_flags,
321
- (unsigned long long)t.it_value.tv_sec,
322
- (unsigned long long)t.it_value.tv_nsec,
323
- (unsigned long long)t.it_interval.tv_sec,
324
- (unsigned long long)t.it_interval.tv_nsec);
326
+ (unsigned long long)value.tv_sec,
327
+ (unsigned long long)value.tv_nsec,
328
+ (unsigned long long)interval.tv_sec,
329
+ (unsigned long long)interval.tv_nsec);
325330 }
326331 #else
327332 #define timerfd_show NULL
....@@ -388,6 +393,7 @@
388393 {
389394 int ufd;
390395 struct timerfd_ctx *ctx;
396
+ char file_name_buf[32];
391397
392398 /* Check the TFD_* constants for consistency. */
393399 BUILD_BUG_ON(TFD_CLOEXEC != O_CLOEXEC);
....@@ -424,7 +430,9 @@
424430
425431 ctx->moffs = ktime_mono_to_real(0);
426432
427
- ufd = anon_inode_getfd("[timerfd]", &timerfd_fops, ctx,
433
+ strlcpy(file_name_buf, "[timerfd]", sizeof(file_name_buf));
434
+ trace_android_vh_timerfd_create(file_name_buf, sizeof(file_name_buf));
435
+ ufd = anon_inode_getfd(file_name_buf, &timerfd_fops, ctx,
428436 O_RDWR | (flags & TFD_SHARED_FCNTL_FLAGS));
429437 if (ufd < 0)
430438 kfree(ctx);
....@@ -432,7 +440,7 @@
432440 return ufd;
433441 }
434442
435
-static int do_timerfd_settime(int ufd, int flags,
443
+static int do_timerfd_settime(int ufd, int flags,
436444 const struct itimerspec64 *new,
437445 struct itimerspec64 *old)
438446 {
....@@ -471,7 +479,11 @@
471479 break;
472480 }
473481 spin_unlock_irq(&ctx->wqh.lock);
474
- cpu_relax();
482
+
483
+ if (isalarm(ctx))
484
+ hrtimer_cancel_wait_running(&ctx->t.alarm.timer);
485
+ else
486
+ hrtimer_cancel_wait_running(&ctx->t.tmr);
475487 }
476488
477489 /*
....@@ -560,30 +572,30 @@
560572 }
561573
562574 #ifdef CONFIG_COMPAT_32BIT_TIME
563
-COMPAT_SYSCALL_DEFINE4(timerfd_settime, int, ufd, int, flags,
564
- const struct compat_itimerspec __user *, utmr,
565
- struct compat_itimerspec __user *, otmr)
575
+SYSCALL_DEFINE4(timerfd_settime32, int, ufd, int, flags,
576
+ const struct old_itimerspec32 __user *, utmr,
577
+ struct old_itimerspec32 __user *, otmr)
566578 {
567579 struct itimerspec64 new, old;
568580 int ret;
569581
570
- if (get_compat_itimerspec64(&new, utmr))
582
+ if (get_old_itimerspec32(&new, utmr))
571583 return -EFAULT;
572584 ret = do_timerfd_settime(ufd, flags, &new, &old);
573585 if (ret)
574586 return ret;
575
- if (otmr && put_compat_itimerspec64(&old, otmr))
587
+ if (otmr && put_old_itimerspec32(&old, otmr))
576588 return -EFAULT;
577589 return ret;
578590 }
579591
580
-COMPAT_SYSCALL_DEFINE2(timerfd_gettime, int, ufd,
581
- struct compat_itimerspec __user *, otmr)
592
+SYSCALL_DEFINE2(timerfd_gettime32, int, ufd,
593
+ struct old_itimerspec32 __user *, otmr)
582594 {
583595 struct itimerspec64 kotmr;
584596 int ret = do_timerfd_gettime(ufd, &kotmr);
585597 if (ret)
586598 return ret;
587
- return put_compat_itimerspec64(&kotmr, otmr) ? -EFAULT : 0;
599
+ return put_old_itimerspec32(&kotmr, otmr) ? -EFAULT : 0;
588600 }
589601 #endif