From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D7B3C4360C for ; Fri, 11 Oct 2019 01:24:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2BCC9214E0 for ; Fri, 11 Oct 2019 01:24:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=arista.com header.i=@arista.com header.b="LbSg4PoU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728099AbfJKBYC (ORCPT ); Thu, 10 Oct 2019 21:24:02 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:43018 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728052AbfJKBX6 (ORCPT ); Thu, 10 Oct 2019 21:23:58 -0400 Received: by mail-wr1-f68.google.com with SMTP id j18so9938718wrq.10 for ; Thu, 10 Oct 2019 18:23:55 -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=fFQTdTjOCYTB2jTtP3oKDu+vJj96IWOcHQXllMBxd3E=; b=LbSg4PoUGLS//wBy1BrCYZVaJQ2XsJ0XHO1iDR7hykN8ueLKs/FASph5UthTKFSCld O51fToVlj1CnM1kIHBNMOiQAk1AaitCrMmN9oJJMl2gWUhNzwjWqb3H5qkn0EaewjGOG 42r0YLGgU3QZ7XbFHgFQcBxJ8PbZxSNDO+d0I+HMzvi7NzLu6YwnGU4IzEs+p6pu+stD vcsnsYYUX3vO2I7MF2shRA5vJGV/r+SrznM7vLRc08PWK1dzeT90yW5s32bWzm9uFdEy qhoTHTJmwvhJsD28D7duhFClwnSkkvZzT1hpBi/oZgO8yA/2sgxlSCt2uM3189RpQbOV uZhw== 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=fFQTdTjOCYTB2jTtP3oKDu+vJj96IWOcHQXllMBxd3E=; b=kppedo0Va4/yqlD1b4il1txencDyAMWYNhfaZGzFAdE/ikCKaBNfwzPteaWt5JjJqR sG6cBY79TGETjHz8+Plp6SM1u5dvrK5kYH73bRYGFcfXk6RoqCfoNc10mYSmwscdS6nW BBrrGSLC9kVL7IMqkKjBpHzZefbfgwndd08bwzRiLv3daW5cb5J+UimerFQZOImK0nGy WjhwgDWmNDI0KE0nwsFoSDLP1gbvBpLsTNEMH3htvXCQ2x/P1bTaJ3t0Eu9gE6sw2wUi xcOaK5sRYnM4RnyrxdPZtSM/FprTVdW0WYjxhDeMSr7JjVR4JhZOHkbxJVt/sopE/JM8 I+rA== X-Gm-Message-State: APjAAAV4BlUUJxT8EaZ3i6nHP7fIEN+crcBqwyEqvXBqeW4PpNUD1S+t SSe4yqaUCBzY+t3mlofne/FKNOvBdqE= X-Google-Smtp-Source: APXvYqyXWFpjw7CccP10Mvd9aqwdjuBO9S0LnpCx8VsHwnOo9bBD03qkJ5HmxSwbJa4bgtuKUXS8yw== X-Received: by 2002:adf:f5cf:: with SMTP id k15mr10737112wrp.315.1570757034452; Thu, 10 Oct 2019 18:23:54 -0700 (PDT) Received: from localhost.localdomain ([2a02:8084:ea2:c100:228:f8ff:fe6f:83a8]) by smtp.gmail.com with ESMTPSA id l13sm7699795wmj.25.2019.10.10.18.23.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 18:23:53 -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: [PATCHv7 06/33] alarmtimer: Provide get_timespec() callback Date: Fri, 11 Oct 2019 02:23:14 +0100 Message-Id: <20191011012341.846266-7-dima@arista.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191011012341.846266-1-dima@arista.com> References: <20191011012341.846266-1-dima@arista.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrei Vagin The upcoming support for time namespaces requires to have access to: - The time in a task's time namespace for sys_clock_gettime() - The time in the root name space for common_timer_get() Wire up alarm bases with get_timespec(). Suggested-by: Thomas Gleixner Signed-off-by: Andrei Vagin Co-developed-by: Dmitry Safonov Signed-off-by: Dmitry Safonov --- include/linux/posix-timers.h | 3 +++ kernel/time/alarmtimer.c | 8 ++++++-- kernel/time/posix-timers.c | 4 ++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h index 3d10c84a97a9..d535d52eb3ca 100644 --- a/include/linux/posix-timers.h +++ b/include/linux/posix-timers.h @@ -230,4 +230,7 @@ void set_process_cpu_timer(struct task_struct *task, unsigned int clock_idx, void update_rlimit_cpu(struct task_struct *task, unsigned long rlim_new); void posixtimer_rearm(struct kernel_siginfo *info); + +int posix_get_realtime_timespec(clockid_t which_clock, struct timespec64 *tp); +int posix_get_boottime_timespec(const clockid_t which_clock, struct timespec64 *tp); #endif diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c index 22b6f9b133b2..73a5458194c7 100644 --- a/kernel/time/alarmtimer.c +++ b/kernel/time/alarmtimer.c @@ -37,12 +37,15 @@ * @lock: Lock for syncrhonized access to the base * @timerqueue: Timerqueue head managing the list of events * @get_ktime: Function to read the time correlating to the base + * @get_timespec: Function to read the namespace time correlating to the base * @base_clockid: clockid for the base */ static struct alarm_base { spinlock_t lock; struct timerqueue_head timerqueue; ktime_t (*get_ktime)(void); + int (*get_timespec)(const clockid_t which_clock, + struct timespec64 *tp); clockid_t base_clockid; } alarm_bases[ALARM_NUMTYPE]; @@ -670,8 +673,7 @@ static int alarm_clock_get_timespec(clockid_t which_clock, struct timespec64 *tp if (!alarmtimer_get_rtcdev()) return -EINVAL; - *tp = ktime_to_timespec64(base->get_ktime()); - return 0; + return base->get_timespec(base->base_clockid, tp); } /** @@ -883,8 +885,10 @@ static int __init alarmtimer_init(void) /* Initialize alarm bases */ alarm_bases[ALARM_REALTIME].base_clockid = CLOCK_REALTIME; alarm_bases[ALARM_REALTIME].get_ktime = &ktime_get_real; + alarm_bases[ALARM_REALTIME].get_timespec = posix_get_realtime_timespec, alarm_bases[ALARM_BOOTTIME].base_clockid = CLOCK_BOOTTIME; alarm_bases[ALARM_BOOTTIME].get_ktime = &ktime_get_boottime; + alarm_bases[ALARM_BOOTTIME].get_timespec = posix_get_boottime_timespec; for (i = 0; i < ALARM_NUMTYPE; i++) { timerqueue_init_head(&alarm_bases[i].timerqueue); spin_lock_init(&alarm_bases[i].lock); diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c index 68d4690cc225..e65241a46038 100644 --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -165,7 +165,7 @@ static inline void unlock_timer(struct k_itimer *timr, unsigned long flags) } /* Get clock_realtime */ -static int posix_get_realtime_timespec(clockid_t which_clock, struct timespec64 *tp) +int posix_get_realtime_timespec(clockid_t which_clock, struct timespec64 *tp) { ktime_get_real_ts64(tp); return 0; @@ -222,7 +222,7 @@ static int posix_get_coarse_res(const clockid_t which_clock, struct timespec64 * return 0; } -static int posix_get_boottime_timespec(const clockid_t which_clock, struct timespec64 *tp) +int posix_get_boottime_timespec(const clockid_t which_clock, struct timespec64 *tp) { ktime_get_boottime_ts64(tp); return 0; -- 2.23.0