Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1195109imm; Wed, 19 Sep 2018 13:53:37 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZ+BdYgzC+qQAEoL2yxcAfFl8nTjCApiNFG9QOgNaIU6ZjjNJt5lNK/9phsrbfC2QQsESLJ X-Received: by 2002:a17:902:e85:: with SMTP id 5-v6mr35098785plx.73.1537390417531; Wed, 19 Sep 2018 13:53:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537390417; cv=none; d=google.com; s=arc-20160816; b=Qvc55JWPnXMSeSW8YAQ6b4NRX87Ms8d2BAHiniMl/nUHNTt29bhHj7n/+aTDVoJ5Tu JRgVOE61TZPzRjMmv2jT1MCM19dExCKwfJRMPfjuLuVpg/K0sHsJCSxS3Gr0UU0hrEWi qmxraR4rLF3rBU1xQlKjYgeBMCLY0jAVhxWRuWdtf0/Gvd4iHRzyQbdecAqJGJ82I5Fb DDa50Yw6nspsTGbsXZCyBKz27/L5eArwC5JCcPp5ARPvOe2E+rUdDSmQGfQ8iBTbtKQt sC3pF+/7wS5Pp7IqOo04NZcXbgBqdVk3UemnJ1Rk2fNXnficvKjC6CoYI02wXBGMCjqh sT+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=bP6x72afHhqDJ7ddcE8DNcBh4tk+zD9yWPVM9lT5xD8=; b=nNyfQICoxca+MOmyZNIQz7MjlfwWH1i+7S9gIKW06CXPFxkOB0Z8c47IuazZGdBGuj OkYAhMCfwexcwpzuwS1OjZRkB8XMgnxrOj+dP80VzZ+QZIHO+E5cdLMqfG1KlLdzLvNJ FOwgp7RxxBY23DBxBme1CAQUwn3s4kmrpfINgwwEdpttAFXtwE5z6Q+6kCU4XKtq7+Lz +O3n2na4CtvYRNEGrunycBimrsiUjbfBlKRj3SjHGVdH+5/ro9P1KG3J05xVNJRDJK1o 9azhmwUScaGwn8owKkLG+c3lN28r5Lx5gkRiWDeJtg7/pjlj4kKlffP5kOAR8AkhXVZ+ J+GQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=googlenew header.b=Vum7eVmU; 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 o21-v6si22120618pgk.337.2018.09.19.13.53.22; Wed, 19 Sep 2018 13:53:37 -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=Vum7eVmU; 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 S1732576AbeITCa1 (ORCPT + 99 others); Wed, 19 Sep 2018 22:30:27 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:33439 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732336AbeITCa0 (ORCPT ); Wed, 19 Sep 2018 22:30:26 -0400 Received: by mail-ed1-f68.google.com with SMTP id d8-v6so6063901edv.0 for ; Wed, 19 Sep 2018 13:50:46 -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; bh=bP6x72afHhqDJ7ddcE8DNcBh4tk+zD9yWPVM9lT5xD8=; b=Vum7eVmU+8KkpZOqjqgsLPRxNn/ZFXt/4P3gwZ0Rpe/jMT1GjJqaEMwDdikL7aTHDx PXNzNbSYPKejyf5RBQ0qfKl9u9Gs5dVAQFeSOK2fkUthFOAPSBMVBUATrtviGwmbugo4 jecWAPrnnWVHrh/XK+NcMq8TX4jrHSRxB4uGrgVvp8LoiUKiBeXz4JeeKXKczH3brbdQ n6p+EhuXt1pEAh09pCu8/xEPkCjGwfFIU9u1AiGx/g68pWsZ8ENHriREpQxJuk39f/Cg M5ybJhAP9IElcF6jTRqxNycNMcK7TIywG6G4Fe0Nlk8BHkDIIRMrvnVrC+mR677eQOVB aEdA== 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; bh=bP6x72afHhqDJ7ddcE8DNcBh4tk+zD9yWPVM9lT5xD8=; b=Aog2ZxETwxW4Dl1EL4G5Ik9q9SZWxkctZ3Vc2OxfRJurqEDv0hdW+NYJucrFWJoKaE F7Uy8iseyB/xoK5/hXWl4KZWvK8PbZnBwOE61xVAl7Yjc4vku0rTL+SFIasf0EPZn2hV RIE8MbYNGInWb3ZPkzCFEicq5rQHWSqYE1YnRYorLBSrVviUCh+sILO3w35xyitNYuV8 ROndBBb5UhfFi05fyqA7ZwLxFwcIH5XZjXTnfGhJ8kVQCOv/+j0H7iC+ZJ3jFSqMGjgP 6n+/v+KEoo63+wXN4H6G8vsmEr6ihsVbFHHWzq7lmVoSWgJ9Q1fKK3zjn+szMm9fQwf+ AKGQ== X-Gm-Message-State: APzg51Bxc0uKTg7st8LNDJsOVcTM56lFa769b+zeMccNfhMlU/eBFoo7 20vXiG0FywpLNUI+8M16bjpK5C14KsE= X-Received: by 2002:a50:eb96:: with SMTP id y22-v6mr59897039edr.38.1537390245276; Wed, 19 Sep 2018 13:50:45 -0700 (PDT) Received: from dhcp.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id t17-v6sm1747729edb.27.2018.09.19.13.50.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Sep 2018 13:50:44 -0700 (PDT) From: Dmitry Safonov To: linux-kernel@vger.kernel.org Cc: Dmitry Safonov <0x7f454c46@gmail.com>, Andrei Vagin , Dmitry Safonov , Adrian Reber , Andy Lutomirski , Christian Brauner , Cyrill Gorcunov , "Eric W. Biederman" , "H. Peter Anvin" , Ingo Molnar , Jeff Dike , Oleg Nesterov , Pavel Emelyanov , Shuah Khan , Thomas Gleixner , containers@lists.linux-foundation.org, criu@openvz.org, linux-api@vger.kernel.org, x86@kernel.org Subject: [RFC 04/20] timens: Introduce CLOCK_BOOTTIME offset Date: Wed, 19 Sep 2018 21:50:21 +0100 Message-Id: <20180919205037.9574-5-dima@arista.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180919205037.9574-1-dima@arista.com> References: <20180919205037.9574-1-dima@arista.com> 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. Provide clock_set() API to set boottime clock inside ns. Signed-off-by: Andrei Vagin Signed-off-by: Dmitry Safonov --- include/linux/timens_offsets.h | 1 + kernel/time/posix-timers.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/linux/timens_offsets.h b/include/linux/timens_offsets.h index 248b0c0bb92a..777530c46852 100644 --- a/include/linux/timens_offsets.h +++ b/include/linux/timens_offsets.h @@ -4,6 +4,7 @@ struct timens_offsets { struct timespec64 monotonic_time_offset; + struct timespec64 monotonic_boottime_offset; }; #endif diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c index 3c1f98760dec..d38835a21c5d 100644 --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -276,7 +276,32 @@ static int posix_get_coarse_res(const clockid_t which_clock, struct timespec64 * static int posix_get_boottime(const clockid_t which_clock, struct timespec64 *tp) { + struct timens_offsets *ns_offsets = current->nsproxy->time_ns->offsets; + ktime_get_boottime_ts64(tp); + + if (!ns_offsets) + return 0; + + *tp = timespec64_add(*tp, ns_offsets->monotonic_boottime_offset); + + return 0; +} + +static int posix_set_boottime(clockid_t which_clock, const struct timespec64 *tp) +{ + struct timens_offsets *ns_offsets = current->nsproxy->time_ns->offsets; + struct timespec64 ktp; + + if (!ns_capable(current->nsproxy->time_ns->user_ns, CAP_SYS_TIME)) + return -EPERM; + + ktime_get_boottime_ts64(&ktp); + + if (ns_offsets) + ns_offsets->monotonic_boottime_offset = timespec64_sub(*tp, ktp); + else + return -EINVAL; return 0; } @@ -1362,6 +1387,7 @@ static const struct k_clock clock_tai = { static const struct k_clock clock_boottime = { .clock_getres = posix_get_hrtimer_res, .clock_get = posix_get_boottime, + .clock_set = posix_set_boottime, .nsleep = common_nsleep, .timer_create = common_timer_create, .timer_set = common_timer_set, -- 2.13.6