]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - include/linux/time_namespace.h
Merge tag 'x86-urgent-2020-08-30' of git://git.kernel.org/pub/scm/linux/kernel/git...
[mirror_ubuntu-jammy-kernel.git] / include / linux / time_namespace.h
CommitLineData
769071ac
AV
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _LINUX_TIMENS_H
3#define _LINUX_TIMENS_H
4
5
6#include <linux/sched.h>
7#include <linux/kref.h>
8#include <linux/nsproxy.h>
9#include <linux/ns_common.h>
10#include <linux/err.h>
11
12struct user_namespace;
13extern struct user_namespace init_user_ns;
14
af993f58
AV
15struct timens_offsets {
16 struct timespec64 monotonic;
17 struct timespec64 boottime;
18};
19
769071ac
AV
20struct time_namespace {
21 struct kref kref;
22 struct user_namespace *user_ns;
23 struct ucounts *ucounts;
24 struct ns_common ns;
af993f58 25 struct timens_offsets offsets;
afaa7b5a
DS
26 struct page *vvar_page;
27 /* If set prevents changing offsets after any task joined namespace. */
28 bool frozen_offsets;
769071ac
AV
29} __randomize_layout;
30
31extern struct time_namespace init_time_ns;
32
33#ifdef CONFIG_TIME_NS
70ddf651
DS
34extern int vdso_join_timens(struct task_struct *task,
35 struct time_namespace *ns);
76c12881 36extern void timens_commit(struct task_struct *tsk, struct time_namespace *ns);
70ddf651 37
769071ac
AV
38static inline struct time_namespace *get_time_ns(struct time_namespace *ns)
39{
40 kref_get(&ns->kref);
41 return ns;
42}
43
44struct time_namespace *copy_time_ns(unsigned long flags,
45 struct user_namespace *user_ns,
46 struct time_namespace *old_ns);
47void free_time_ns(struct kref *kref);
48int timens_on_fork(struct nsproxy *nsproxy, struct task_struct *tsk);
64b302ab 49struct vdso_data *arch_get_vdso_data(void *vvar_page);
769071ac
AV
50
51static inline void put_time_ns(struct time_namespace *ns)
52{
53 kref_put(&ns->kref, free_time_ns);
54}
55
04a8682a
AV
56void proc_timens_show_offsets(struct task_struct *p, struct seq_file *m);
57
58struct proc_timens_offset {
59 int clockid;
60 struct timespec64 val;
61};
62
63int proc_timens_set_offset(struct file *file, struct task_struct *p,
64 struct proc_timens_offset *offsets, int n);
65
af993f58
AV
66static inline void timens_add_monotonic(struct timespec64 *ts)
67{
68 struct timens_offsets *ns_offsets = &current->nsproxy->time_ns->offsets;
69
70 *ts = timespec64_add(*ts, ns_offsets->monotonic);
71}
72
73static inline void timens_add_boottime(struct timespec64 *ts)
74{
75 struct timens_offsets *ns_offsets = &current->nsproxy->time_ns->offsets;
76
77 *ts = timespec64_add(*ts, ns_offsets->boottime);
78}
79
89dd8eec
AV
80ktime_t do_timens_ktime_to_host(clockid_t clockid, ktime_t tim,
81 struct timens_offsets *offsets);
82
83static inline ktime_t timens_ktime_to_host(clockid_t clockid, ktime_t tim)
84{
85 struct time_namespace *ns = current->nsproxy->time_ns;
86
87 if (likely(ns == &init_time_ns))
88 return tim;
89
90 return do_timens_ktime_to_host(clockid, tim, &ns->offsets);
91}
92
769071ac 93#else
70ddf651
DS
94static inline int vdso_join_timens(struct task_struct *task,
95 struct time_namespace *ns)
96{
97 return 0;
98}
99
76c12881
CB
100static inline void timens_commit(struct task_struct *tsk,
101 struct time_namespace *ns)
102{
103}
104
769071ac
AV
105static inline struct time_namespace *get_time_ns(struct time_namespace *ns)
106{
107 return NULL;
108}
109
110static inline void put_time_ns(struct time_namespace *ns)
111{
112}
113
114static inline
115struct time_namespace *copy_time_ns(unsigned long flags,
116 struct user_namespace *user_ns,
117 struct time_namespace *old_ns)
118{
119 if (flags & CLONE_NEWTIME)
120 return ERR_PTR(-EINVAL);
121
122 return old_ns;
123}
124
125static inline int timens_on_fork(struct nsproxy *nsproxy,
126 struct task_struct *tsk)
127{
128 return 0;
129}
130
af993f58
AV
131static inline void timens_add_monotonic(struct timespec64 *ts) { }
132static inline void timens_add_boottime(struct timespec64 *ts) { }
89dd8eec
AV
133static inline ktime_t timens_ktime_to_host(clockid_t clockid, ktime_t tim)
134{
135 return tim;
136}
769071ac
AV
137#endif
138
139#endif /* _LINUX_TIMENS_H */