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=-3.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 405B6C31E4B for ; Fri, 14 Jun 2019 13:38:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1E9E820866 for ; Fri, 14 Jun 2019 13:38:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728294AbfFNNiW (ORCPT ); Fri, 14 Jun 2019 09:38:22 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:38041 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727808AbfFNNiW (ORCPT ); Fri, 14 Jun 2019 09:38:22 -0400 Received: from [5.158.153.52] (helo=nanos.tec.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1hbmOy-0005NV-SL; Fri, 14 Jun 2019 15:37:57 +0200 Date: Fri, 14 Jun 2019 15:37:56 +0200 (CEST) From: Thomas Gleixner To: Dmitry Safonov cc: linux-kernel@vger.kernel.org, Andrei Vagin , Adrian Reber , Andrei Vagin , Andy Lutomirski , Arnd Bergmann , Christian Brauner , Cyrill Gorcunov , Dmitry Safonov <0x7f454c46@gmail.com>, "Eric W. Biederman" , "H. Peter Anvin" , Ingo Molnar , Jann Horn , Jeff Dike , Oleg Nesterov , Pavel Emelyanov , Shuah Khan , Vincenzo Frascino , containers@lists.linux-foundation.org, criu@openvz.org, linux-api@vger.kernel.org, x86@kernel.org Subject: Re: [PATCHv4 06/28] timerfd/timens: Take into account ns clock offsets In-Reply-To: <20190612192628.23797-7-dima@arista.com> Message-ID: References: <20190612192628.23797-1-dima@arista.com> <20190612192628.23797-7-dima@arista.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 12 Jun 2019, Dmitry Safonov wrote: > --- > fs/timerfd.c | 3 +++ > include/linux/time_namespace.h | 18 ++++++++++++++++++ > kernel/time_namespace.c | 27 +++++++++++++++++++++++++++ > 3 files changed, 48 insertions(+) Again, please split that into: 1) Introduce the new function 2) Make use of it > diff --git a/fs/timerfd.c b/fs/timerfd.c > index 6a6fc8aa1de7..9b0c2f65e7e8 100644 > --- a/fs/timerfd.c > +++ b/fs/timerfd.c > @@ -26,6 +26,7 @@ > #include > #include > #include > +#include > > struct timerfd_ctx { > union { > @@ -196,6 +197,8 @@ static int timerfd_setup(struct timerfd_ctx *ctx, int flags, > } > > if (texp != 0) { > + if (flags & TFD_TIMER_ABSTIME) > + texp = timens_ktime_to_host(clockid, texp); > if (isalarm(ctx)) { > if (flags & TFD_TIMER_ABSTIME) > alarm_start(&ctx->t.alarm, texp); > diff --git a/include/linux/time_namespace.h b/include/linux/time_namespace.h > index 1dda8af6b9fe..d32b55fad953 100644 > --- a/include/linux/time_namespace.h > +++ b/include/linux/time_namespace.h > @@ -56,6 +56,19 @@ static inline void timens_add_boottime(struct timespec64 *ts) > *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 timens_offsets *offsets = current->nsproxy->time_ns->offsets; > + > + if (!offsets) /* fast-path for the root time namespace */ Can you please avoid tail comments. They break the reading flow. Aside of that I don't see the value of documenting the obvious. > +ktime_t do_timens_ktime_to_host(clockid_t clockid, ktime_t tim, struct timens_offsets *ns_offsets) Please line break the arguments ktime_t do_timens_ktime_to_host(clockid_t clockid, ktime_t tim, struct timens_offsets *ns_offsets) > +{ > + ktime_t koff; > + > + switch (clockid) { > + case CLOCK_MONOTONIC: > + koff = timespec64_to_ktime(ns_offsets->monotonic); > + break; > + case CLOCK_BOOTTIME: > + case CLOCK_BOOTTIME_ALARM: > + koff = timespec64_to_ktime(ns_offsets->boottime); > + break; > + default: > + return tim; > + } > + > + /* tim - off has to be in [0, KTIME_MAX) */ Please be more elaborate why the below conditions can happen at all. > + if (tim < koff) > + tim = 0; > + else if (KTIME_MAX - tim < -koff) > + tim = KTIME_MAX; > + else > + tim = ktime_sub(tim, koff); Thanks, tglx