mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-12 13:55:32 +00:00
![Dmitry Safonov](/assets/img/avatar_default.png)
VDSO support for time namespaces needs to set up a page with the same layout as VVAR. That timens page will be placed on position of VVAR page inside namespace. That page has vdso_data->seq set to 1 to enforce the slow path and vdso_data->clock_mode set to VCLOCK_TIMENS to enforce the time namespace handling path. To prepare the time namespace page the kernel needs to know the vdso_data offset. Provide arch_get_vdso_data() helper for locating vdso_data on VVAR page. Co-developed-by: Andrei Vagin <avagin@openvz.org> Signed-off-by: Andrei Vagin <avagin@openvz.org> Signed-off-by: Dmitry Safonov <dima@arista.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/r/20191112012724.250792-22-dima@arista.com
111 lines
2.6 KiB
C
111 lines
2.6 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef _LINUX_TIMENS_H
|
|
#define _LINUX_TIMENS_H
|
|
|
|
|
|
#include <linux/sched.h>
|
|
#include <linux/kref.h>
|
|
#include <linux/nsproxy.h>
|
|
#include <linux/ns_common.h>
|
|
#include <linux/err.h>
|
|
|
|
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;
|
|
|
|
#ifdef CONFIG_TIME_NS
|
|
static inline struct time_namespace *get_time_ns(struct time_namespace *ns)
|
|
{
|
|
kref_get(&ns->kref);
|
|
return ns;
|
|
}
|
|
|
|
struct time_namespace *copy_time_ns(unsigned long flags,
|
|
struct user_namespace *user_ns,
|
|
struct time_namespace *old_ns);
|
|
void free_time_ns(struct kref *kref);
|
|
int timens_on_fork(struct nsproxy *nsproxy, struct task_struct *tsk);
|
|
struct vdso_data *arch_get_vdso_data(void *vvar_page);
|
|
|
|
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 = ¤t->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 = ¤t->nsproxy->time_ns->offsets;
|
|
|
|
*ts = timespec64_add(*ts, ns_offsets->boottime);
|
|
}
|
|
|
|
ktime_t do_timens_ktime_to_host(clockid_t clockid, ktime_t tim,
|
|
struct timens_offsets *offsets);
|
|
|
|
static inline ktime_t timens_ktime_to_host(clockid_t clockid, ktime_t tim)
|
|
{
|
|
struct time_namespace *ns = current->nsproxy->time_ns;
|
|
|
|
if (likely(ns == &init_time_ns))
|
|
return tim;
|
|
|
|
return do_timens_ktime_to_host(clockid, tim, &ns->offsets);
|
|
}
|
|
|
|
#else
|
|
static inline struct time_namespace *get_time_ns(struct time_namespace *ns)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
static inline void put_time_ns(struct time_namespace *ns)
|
|
{
|
|
}
|
|
|
|
static inline
|
|
struct time_namespace *copy_time_ns(unsigned long flags,
|
|
struct user_namespace *user_ns,
|
|
struct time_namespace *old_ns)
|
|
{
|
|
if (flags & CLONE_NEWTIME)
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
return old_ns;
|
|
}
|
|
|
|
static inline int timens_on_fork(struct nsproxy *nsproxy,
|
|
struct task_struct *tsk)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline void timens_add_monotonic(struct timespec64 *ts) { }
|
|
static inline void timens_add_boottime(struct timespec64 *ts) { }
|
|
static inline ktime_t timens_ktime_to_host(clockid_t clockid, ktime_t tim)
|
|
{
|
|
return tim;
|
|
}
|
|
#endif
|
|
|
|
#endif /* _LINUX_TIMENS_H */
|