Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4401136ybi; Tue, 30 Jul 2019 01:21:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqybpZjYAPjmbR0VSJrSgAlqUy0CkZn8FNmyFIFp2EbvFVdDHi/uCdjn+v3ofnEedoS6SBGr X-Received: by 2002:a62:ce07:: with SMTP id y7mr39197386pfg.12.1564474900950; Tue, 30 Jul 2019 01:21:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564474900; cv=none; d=google.com; s=arc-20160816; b=N6+TyiwZdGRLH8/gMwhEM3AXiGbEJ2FvEDqNGmt7Dr//vJWWyX6uOjCUnPuzfYZmvS iC1nzNL+NS48aYTtGqsJIk+4tKLgVf2eLJlbmh9OPaJzMgQrR08iEhuYFQmJu8bRCE5S 4DMFolGoalRw30bK46pTxosxBeDyftKr5hNAPJtkj+SkIJrajcXpytVq+8Jot4lR93LW pj3diad7N89I2Zt/bApTcVtLHpy4dKykra89xNAC6ajFJti2ADqCwCJRlVgvoBHkIw+P Cv+LKrw1F74vXFFsZTxoOoNxkEvBjpmZw/p49trrXyqPjdz2dDGK4fA7FGd5cLz9I1Bg st1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Ka7x1gX+cc0hv8MDuwO2Malh6j1ZrZUM3jDIBgobxjI=; b=mAgSQzNlekqMNKW7mT3ZjPgChaD1TBPXMwuCMUDvL4a4yux73EZFB0Cbj187lFMFSy BZNNNTjHQ5ax8nbBh4QpZvcelCgwb2lx9G2sL6xsEffz+1FIlMwHNQmsJJ9S2GZ4iEO9 kBNbeg67AjpAhbqkAT5Xysu0cc8GUNLfe6o+d0o3BBME2rxiVgZW23OADmL+EPS0hATG ImCyBlnp8Oct+NAjtbEyQ9YPJs/2z5/ZnXd4yFk8YpVQ545+0zsMGeGbqvyYVz/RAbfV Et+HdPZs2qmAunPSyaNzzECcKitjUP/Rk1G2q9gXPiCf0osb8jsqSyLeBuKCmDQXXiB2 P4zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=googlenew header.b=Xvj7FXGO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=REJECT dis=NONE) header.from=arista.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k13si30446004pfa.17.2019.07.30.01.21.25; Tue, 30 Jul 2019 01:21:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@arista.com header.s=googlenew header.b=Xvj7FXGO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=REJECT dis=NONE) header.from=arista.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728294AbfG2V6T (ORCPT + 99 others); Mon, 29 Jul 2019 17:58:19 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:54226 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389231AbfG2V6Q (ORCPT ); Mon, 29 Jul 2019 17:58:16 -0400 Received: by mail-wm1-f68.google.com with SMTP id x15so55202772wmj.3 for ; Mon, 29 Jul 2019 14:58:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=googlenew; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ka7x1gX+cc0hv8MDuwO2Malh6j1ZrZUM3jDIBgobxjI=; b=Xvj7FXGOcZc8glBEOSMlCCRea94AmWoUVCJMP4wuIQXao27FvB4hBx1k92QxTkajh1 WY9QHbdeRtE5Z6xDWbgfQ9X7s5m4rKiPEIG3HvXUoVr/LuauNb2sAkNkZoNYLVQWV0j8 PRoFX4kbJW1IMVapY3ml5xDK0ckUVqvxR3mc/ly8Rhj7LVik0gw9BEUFvWNKPpPyPd6b rgcPv4NoHwaotea3sOn3POMM8cMkmKuimIZtGpdPxIZqB296MQkqX1o2x+13ce2N/NUr NyapX0AJFU6J35F/tgLrdWswAZ8FWI0O3VPDnRtZx8BFbK5ftShXT2EX6u1+Vpj5+7fS K9Nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ka7x1gX+cc0hv8MDuwO2Malh6j1ZrZUM3jDIBgobxjI=; b=qX8mi6Bn88f5c9iR1MoUmPhagj4VGvmS1028VCRkBt7W0MFKcel9tgLX4zA/GaoEaj +V7fOslSH1Akia2Qze84cZZTQwZ9NcScqCyTxCFS6joZIP2GvK4z79uDwRywOneqqWl0 JDoTLz350LtRxwjn4OeLz0Lx+64SMOshxvcZ5ycG85bVB9d+GCv1l3hqjAZKLzNiMOKV 4+Cmvz8mA3tk2+v1R+ImM5qJAYkfiiylaQBlmHcsq2eV7amImTCMTTpnzjt2NJq223Cy n3lVHkTEJOJESKegl3wN871aO80jcxrYXWGlkdxbADy28K/34l9eND+amXLfxDOeXYki w+3g== X-Gm-Message-State: APjAAAUpyTeIYyXQB/V1WS/bvuO9od63ls/1hh+44huo/9WQCg3o/j7f y7nr4A01PzAELdWVk9GufnTMTozdpAXtrfm3d3Dy+LFENAGGJJnMiqH/I9gn1V+/DNCcO/krelV mmWjaU/eKOfB0WD/TsS69xwFVlVh034JtPUGzzkrRm+UzRkJrQiYaSUJqd3+KfHF5Wur/955HbW +ozVa2q4kHaVfFFA9JpIyghNBFu/AJqfx3hx6Hzf8= X-Received: by 2002:a1c:c545:: with SMTP id v66mr103549986wmf.51.1564437494027; Mon, 29 Jul 2019 14:58:14 -0700 (PDT) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id x20sm49230728wmc.1.2019.07.29.14.58.12 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 29 Jul 2019 14:58:13 -0700 (PDT) From: Dmitry Safonov To: linux-kernel@vger.kernel.org Cc: Dmitry Safonov <0x7f454c46@gmail.com>, Andrei Vagin , Dmitry Safonov , Adrian Reber , Andrei Vagin , Andy Lutomirski , Arnd Bergmann , Christian Brauner , Cyrill Gorcunov , "Eric W. Biederman" , "H. Peter Anvin" , Ingo Molnar , Jann Horn , Jeff Dike , Oleg Nesterov , Pavel Emelyanov , Shuah Khan , Thomas Gleixner , Vincenzo Frascino , containers@lists.linux-foundation.org, criu@openvz.org, linux-api@vger.kernel.org, x86@kernel.org Subject: [PATCHv5 10/37] posix-clocks: Introduce CLOCK_BOOTTIME time namespace offset Date: Mon, 29 Jul 2019 22:56:52 +0100 Message-Id: <20190729215758.28405-11-dima@arista.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729215758.28405-1-dima@arista.com> References: <20190729215758.28405-1-dima@arista.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CLOUD-SEC-AV-Info: arista,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrei Vagin Adds boottime virtualisation for time namespace. Introduce timespec for boottime clock into timens offsets and wire clock_gettime() syscall. Signed-off-by: Andrei Vagin Co-developed-by: Dmitry Safonov Signed-off-by: Dmitry Safonov --- include/linux/time_namespace.h | 9 +++++++++ include/linux/timens_offsets.h | 1 + kernel/time/alarmtimer.c | 1 + kernel/time/posix-stubs.c | 1 + kernel/time/posix-timers.c | 1 + 5 files changed, 13 insertions(+) diff --git a/include/linux/time_namespace.h b/include/linux/time_namespace.h index 186c134fe222..334c1a1c6607 100644 --- a/include/linux/time_namespace.h +++ b/include/linux/time_namespace.h @@ -48,6 +48,14 @@ static inline void timens_add_monotonic(struct timespec64 *ts) *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; + + if (ns_offsets) + *ts = timespec64_add(*ts, ns_offsets->boottime); +} + #else static inline struct time_namespace *get_time_ns(struct time_namespace *ns) { @@ -73,6 +81,7 @@ static inline int timens_on_fork(struct nsproxy *nsproxy, struct task_struct *ts } static inline void timens_add_monotonic(struct timespec64 *ts) {} +static inline void timens_add_boottime(struct timespec64 *ts) {} #endif #endif /* _LINUX_TIMENS_H */ diff --git a/include/linux/timens_offsets.h b/include/linux/timens_offsets.h index eaac2c82be5c..e93aabaa5e45 100644 --- a/include/linux/timens_offsets.h +++ b/include/linux/timens_offsets.h @@ -4,6 +4,7 @@ struct timens_offsets { struct timespec64 monotonic; + struct timespec64 boottime; }; #endif diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c index 55cb6e78d082..b1e82bb6cc6b 100644 --- a/kernel/time/alarmtimer.c +++ b/kernel/time/alarmtimer.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "posix-timers.h" diff --git a/kernel/time/posix-stubs.c b/kernel/time/posix-stubs.c index 17c67e0aecd8..edaf075d1ee4 100644 --- a/kernel/time/posix-stubs.c +++ b/kernel/time/posix-stubs.c @@ -82,6 +82,7 @@ int do_clock_gettime(clockid_t which_clock, struct timespec64 *tp) break; case CLOCK_BOOTTIME: ktime_get_boottime_ts64(tp); + timens_add_boottime(tp); break; default: return -EINVAL; diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c index cfeb0477d1f9..265fbc816520 100644 --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -240,6 +240,7 @@ static int posix_get_coarse_res(const clockid_t which_clock, struct timespec64 * int posix_get_boottime_timespec(const clockid_t which_clock, struct timespec64 *tp) { ktime_get_boottime_ts64(tp); + timens_add_boottime(tp); return 0; } -- 2.22.0