Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp1463868imj; Fri, 8 Feb 2019 01:48:10 -0800 (PST) X-Google-Smtp-Source: AHgI3IbxCZX8UJ5AdfUVmTf9Sqy+k01U6dsmk40wnqC91Ya6Bq6tSP8AxTUE2Zg96Dx4nCQNNu/K X-Received: by 2002:a17:902:145:: with SMTP id 63mr21767726plb.256.1549619290895; Fri, 08 Feb 2019 01:48:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549619290; cv=none; d=google.com; s=arc-20160816; b=pcRj2yj+XqaQKUfwouN1/0t1rz/O0qOX0jUaUzvNz+MZKRcBoKpNRpJSoyfMhpBJlg BJl5cMfSNtNRrt4i6rTSfbBSZQDiNtNGPtjXWsmaw8HeoO2Y4hie1Dkn5d+JRtmbL3+H ln5cX/3SP0xKB+VuPYIybi9n92XvkpUnWOy/QihPG8JqOPuDMSqd70IHcltTFnBf8q6h WH8t7Enn5iybesUAa36YbvHd3s2jthn8BqOtKB/Mp5HehPW9r3ywE1oPe+ygEYUZObsM WoMcm6WFrM/tFUIgcPqTdtIRcrE1CCUKljUJOUmQjZ7OVwSWlhn1Yrbs2rbsgawKtloY LTcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=o0TGdrR3eOxWba4KCKxTEPJyGuQYQRKbs3riQJmWvJ8=; b=knYp7xagsIH+dfKLHe2G5pjDMeY9Sq9CTTW6XxujGVsr28CzdZrGL1Z8zWfyAyvJFv 3dunyPGyDqsPQUT/S0TDhIpNSdLb9uS8oWMU4O0XfKO7SUzDVI+rU67pBvSFjG8Vdetf 8kKz1kODvNfHYUWhOacVMiMjFg5r4lbt0knChg9qpMjQXMjVXzT76hkQV9dSDCtvP/Wq a65u+TfNHgOe3IAnvzr7Y+r5qypS7FMZ+gJtXAHcNa0SRU5Ebc96Ox7OqsX7TQckv1zj 1DXR0Qls3t+Z7QIUsIxnFGsj31Cf9uj+mIj4ieuhiw7YMiJz6Y2INGwAqBD736MN6wjv vFwA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i64si1625571pge.361.2019.02.08.01.47.55; Fri, 08 Feb 2019 01:48:10 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727273AbfBHJrA (ORCPT + 99 others); Fri, 8 Feb 2019 04:47:00 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:43179 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726063AbfBHJrA (ORCPT ); Fri, 8 Feb 2019 04:47:00 -0500 Received: from p5492e0d8.dip0.t-ipconnect.de ([84.146.224.216] helo=nanos) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1gs2k0-0006Iz-E1; Fri, 08 Feb 2019 10:46:36 +0100 Date: Fri, 8 Feb 2019 10:46:35 +0100 (CET) From: Thomas Gleixner To: Dmitry Safonov cc: linux-kernel@vger.kernel.org, Andrei Vagin , Adrian Reber , Andrei Vagin , Andy Lutomirski , Andy Tucker , Arnd Bergmann , Christian Brauner , Cyrill Gorcunov , Dmitry Safonov <0x7f454c46@gmail.com>, "Eric W. Biederman" , "H. Peter Anvin" , Ingo Molnar , Jeff Dike , Oleg Nesterov , Pavel Emelyanov , Shuah Khan , containers@lists.linux-foundation.org, criu@openvz.org, linux-api@vger.kernel.org, x86@kernel.org Subject: Re: [PATCH 03/32] timens: Introduce CLOCK_MONOTONIC offsets In-Reply-To: Message-ID: References: <20190206001107.16488-1-dima@arista.com> <20190206001107.16488-4-dima@arista.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 7 Feb 2019, Thomas Gleixner wrote: > Does this really need to be an out of line call? If you stick this into the > clock_get() implementations then it boils down to: > > static inline void timens_add_monotonic(struct timespec64 *ts) > { > struct timens_offsets *ns_offsets = current->nsproxy->time_ns->offsets; > > if (ns_offsets) > *ts = timespec64_add(*ts, ns_offsets->monotonic_time_offset); And this needs to be a special variant of timespec64-add_safe(). timespec64_add_safe() is not sufficient, because it assumes that both values are positive, which is not the case here.. In timer_set() implementations you move the timespec_valid() check after the add. That's wrong because you really want to check the input value from user space. Assume that the caller supplied value is valid and the adjustment brings it out of range then how should the caller understand why it it rejected? So timespec64_add_namespace() must check for under and overflow. But doing this with timespecs is a pain. I rather suggest to rework the whole thing so hrtimer_nanosleep() takes a ktime_t expiry value and move the conversion to the call sites. Then the whole offset magic becomes: expires = timespec64_to_ktime(rqtp); if (abstime) expires = timens_to_host_mono(expires); and that function can nicely do the underflow and overflow detection and cap the values to 0 on underflow and KTIME_MAX on overflow. Hmm? Thanks, tglx