]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
timens: additional helper functions for boottime offset handling
authorMichael Weiß <michael.weiss@aisec.fraunhofer.de>
Tue, 27 Oct 2020 20:42:56 +0000 (21:42 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 3 Nov 2020 10:05:39 +0000 (11:05 +0100)
Provide functions for time_namespace to subtract the boottime offset
from a timespec64 as well as to apply the boottime offset to u64 types in
nanoseconds.

Signed-off-by: Michael Weiß <michael.weiss@aisec.fraunhofer.de>
Reviewed-by: Andrei Vagin <avagin@gmail.com>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
Link: https://lore.kernel.org/r/20201027204258.7869-2-michael.weiss@aisec.fraunhofer.de
include/linux/time_namespace.h

index 5b6031385db05f8c79dbbddc7e35ad212cd2dc9b..68770ac9ba8979116a2edc20e45870fc6435c95e 100644 (file)
@@ -77,6 +77,20 @@ static inline void timens_add_boottime(struct timespec64 *ts)
        *ts = timespec64_add(*ts, ns_offsets->boottime);
 }
 
+static inline u64 timens_add_boottime_ns(u64 nsec)
+{
+       struct timens_offsets *ns_offsets = &current->nsproxy->time_ns->offsets;
+
+       return nsec + timespec64_to_ns(&ns_offsets->boottime);
+}
+
+static inline void timens_sub_boottime(struct timespec64 *ts)
+{
+       struct timens_offsets *ns_offsets = &current->nsproxy->time_ns->offsets;
+
+       *ts = timespec64_sub(*ts, ns_offsets->boottime);
+}
+
 ktime_t do_timens_ktime_to_host(clockid_t clockid, ktime_t tim,
                                struct timens_offsets *offsets);
 
@@ -130,6 +144,14 @@ static inline int timens_on_fork(struct nsproxy *nsproxy,
 
 static inline void timens_add_monotonic(struct timespec64 *ts) { }
 static inline void timens_add_boottime(struct timespec64 *ts) { }
+
+static inline u64 timens_add_boottime_ns(u64 nsec)
+{
+       return nsec;
+}
+
+static inline void timens_sub_boottime(struct timespec64 *ts) { }
+
 static inline ktime_t timens_ktime_to_host(clockid_t clockid, ktime_t tim)
 {
        return tim;