Skip to content

Commit

Permalink
time: Add timens_offsets to be used for tasks in time namespace
Browse files Browse the repository at this point in the history
Introduce offsets for time namespace. They will contain an adjustment
needed to convert clocks to/from host's.

A new namespace is created with the same offsets as the time namespace
of the current process.

Co-developed-by: Dmitry Safonov <[email protected]>
Signed-off-by: Andrei Vagin <[email protected]>
Signed-off-by: Dmitry Safonov <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
  • Loading branch information
avagin authored and KAGA-KOKO committed Jan 14, 2020
1 parent 769071a commit af993f5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
22 changes: 22 additions & 0 deletions include/linux/time_namespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@
struct user_namespace;
extern struct user_namespace init_user_ns;

struct timens_offsets {
struct timespec64 monotonic;
struct timespec64 boottime;
};

struct time_namespace {
struct kref kref;
struct user_namespace *user_ns;
struct ucounts *ucounts;
struct ns_common ns;
struct timens_offsets offsets;
} __randomize_layout;

extern struct time_namespace init_time_ns;
Expand All @@ -39,6 +45,20 @@ static inline void put_time_ns(struct time_namespace *ns)
kref_put(&ns->kref, free_time_ns);
}

static inline void timens_add_monotonic(struct timespec64 *ts)
{
struct timens_offsets *ns_offsets = &current->nsproxy->time_ns->offsets;

*ts = timespec64_add(*ts, ns_offsets->monotonic);
}

static inline void timens_add_boottime(struct timespec64 *ts)
{
struct timens_offsets *ns_offsets = &current->nsproxy->time_ns->offsets;

*ts = timespec64_add(*ts, ns_offsets->boottime);
}

#else
static inline struct time_namespace *get_time_ns(struct time_namespace *ns)
{
Expand Down Expand Up @@ -66,6 +86,8 @@ static inline int timens_on_fork(struct nsproxy *nsproxy,
return 0;
}

static inline void timens_add_monotonic(struct timespec64 *ts) { }
static inline void timens_add_boottime(struct timespec64 *ts) { }
#endif

#endif /* _LINUX_TIMENS_H */
2 changes: 2 additions & 0 deletions kernel/time/namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <linux/slab.h>
#include <linux/cred.h>
#include <linux/err.h>
#include <linux/mm.h>

static struct ucounts *inc_time_namespaces(struct user_namespace *ns)
{
Expand Down Expand Up @@ -60,6 +61,7 @@ static struct time_namespace *clone_time_ns(struct user_namespace *user_ns,
ns->ucounts = ucounts;
ns->ns.ops = &timens_operations;
ns->user_ns = get_user_ns(user_ns);
ns->offsets = old_ns->offsets;
return ns;

fail_free:
Expand Down

0 comments on commit af993f5

Please sign in to comment.