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=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, 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 82931C31E4B for ; Fri, 14 Jun 2019 13:59:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 43E472168B for ; Fri, 14 Jun 2019 13:59:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728767AbfFNN7M (ORCPT ); Fri, 14 Jun 2019 09:59:12 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:38196 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728300AbfFNN7M (ORCPT ); Fri, 14 Jun 2019 09:59:12 -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 1hbmj6-0006Yh-J4; Fri, 14 Jun 2019 15:58:44 +0200 Date: Fri, 14 Jun 2019 15:58:43 +0200 (CEST) From: Thomas Gleixner To: Dmitry Safonov cc: linux-kernel@vger.kernel.org, Andrei Vagin , Adrian Reber , 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, Andrei Vagin Subject: Re: [PATCHv4 15/28] x86/vdso: Add offsets page in vvar In-Reply-To: <20190612192628.23797-16-dima@arista.com> Message-ID: References: <20190612192628.23797-1-dima@arista.com> <20190612192628.23797-16-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: > > +#ifdef CONFIG_TIME_NS > +notrace static __always_inline void clk_to_ns(clockid_t clk, struct timespec *ts) > +{ > + struct timens_offsets *timens = (struct timens_offsets *) &timens_page; > + struct timespec64 *offset64; > + > + switch (clk) { > + case CLOCK_MONOTONIC: > + case CLOCK_MONOTONIC_COARSE: > + case CLOCK_MONOTONIC_RAW: > + offset64 = &timens->monotonic; > + break; > + case CLOCK_BOOTTIME: > + offset64 = &timens->boottime; > + default: > + return; > + } > + > + ts->tv_nsec += offset64->tv_nsec; > + ts->tv_sec += offset64->tv_sec; > + if (ts->tv_nsec >= NSEC_PER_SEC) { > + ts->tv_nsec -= NSEC_PER_SEC; > + ts->tv_sec++; > + } > + if (ts->tv_nsec < 0) { > + ts->tv_nsec += NSEC_PER_SEC; > + ts->tv_sec--; > + } I had to think twice why adding the offset (which can be negative) can never result in negative time being returned. A comment explaining this would be appreciated. As I'm planning to merge Vincezos VDSO consolidation into 5.3, can you please start to work on top of his series, which should be available as final v7 next week hopefully. Thanks, tglx