Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1142683pxu; Fri, 27 Nov 2020 00:16:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJx6JKizf58ZN+OxG0RZ0hZyq1ifgYrYgJ2PVxMDXWHW9JyrzJlbFBzrCw0KPFFGUQjH+XSo X-Received: by 2002:a17:906:6dc3:: with SMTP id j3mr6773478ejt.320.1606464994747; Fri, 27 Nov 2020 00:16:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606464994; cv=none; d=google.com; s=arc-20160816; b=pS6HE+LBEfXGt+OjlX79WkvV+naywnf1S6l3ELv+yJ6gFO5auARAXAsUiIUQzU7PFe 1twlaP4Ws4Vz7UKvAEl3Mht40QGKDhozxjBl1nBQ7/EJLACbqmQvPdmL2tS3FkKRUtHC iS4Euoq2KEXTqYCBirnTSGKWeeKuKkdObvigB0+s2rZUqaUVI28kpgJutGPex0lNxBhI 0yfIIop3jP2RY6BI7EaCy+JTNh/oP7zEV++oSMErg2gSR8xtMR2DuvMJphOMXF5/12jY jL9T869qa6b2oeKbS0WwVhXlAp1wBL6/16DN3bUG9trgJhP86cIqj6L15jggqY/ar7X+ 2DGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=ixj0rX9Bs+g4dJIAp3UVgg6X4W9ifQ/hF6Ln6sqBooY=; b=iHAF8R5TrWyUMMVtSEbMS20bjnQh9OmkzQzHy1IqyK+0BbevC7F2lwKBF5xj5bh6fx ERQLCTYKdKue1B9xHsKYsszntwvmp4VkuHpsthgTELjK1CMtc9PMgdevClwfpe9fm7gR 2a+MEV90HkcjdygdJgYo/1ScX2RzOotoPWTCNO6FxeuexTcaLkUIkxh/owE5iwsWQ/Ao Lp4jV2VgkvyTb0b5rpLRqITPCtI4+K4j+ZghumtuTo5JYALFLCUCOp1OIFpRt3QTblYi QlnXPL/nMv3qkE7W8pOw3tN9VRvM2aR3WWHOV59NR714ej2oxslO0yxtRFgxksItblb3 4NWw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rn17si5376597ejb.292.2020.11.27.00.16.10; Fri, 27 Nov 2020 00:16:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389256AbgKZLdp (ORCPT + 99 others); Thu, 26 Nov 2020 06:33:45 -0500 Received: from foss.arm.com ([217.140.110.172]:57076 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389236AbgKZLdo (ORCPT ); Thu, 26 Nov 2020 06:33:44 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BE0641478; Thu, 26 Nov 2020 03:33:43 -0800 (PST) Received: from [10.37.12.45] (unknown [10.37.12.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C824B3F71F; Thu, 26 Nov 2020 03:33:41 -0800 (PST) Subject: Re: [PATCH 1/2] syscalls: avoid time() using __cvdso_gettimeofday in use-level's VDSO To: Thomas Gleixner , Cyril Hrubis , Li Wang Cc: ltp@lists.linux.it, Chunyu Hu , LKML , Peter Zijlstra , John Stultz , Arnd Bergmann , Andy Lutomirski , "Michael Kerrisk (man-pages)" , Carlos O'Donell References: <20201123083137.11575-1-liwang@redhat.com> <20201124153837.GA24470@yuki.lan> <875z5tllih.fsf@nanos.tec.linutronix.de> From: Vincenzo Frascino Message-ID: Date: Thu, 26 Nov 2020 11:36:54 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <875z5tllih.fsf@nanos.tec.linutronix.de> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Thomas. On 11/25/20 11:32 AM, Thomas Gleixner wrote: [...] >>> Here we propose to use '__NR_time' to invoke syscall directly that makes >>> test all get real seconds via ktime_get_real_second. > > This is a general problem and not really just for this particular test > case. > > Due to the internal implementation of ktime_get_real_seconds(), which is > a 2038 safe replacement for the former get_seconds() function, this > accumulation issue can be observed. (time(2) via syscall and newer > versions of VDSO use the same mechanism). > > clock_gettime(CLOCK_REALTIME, &ts); > sec = time(); > assert(sec >= ts.tv_sec); > > That assert can trigger for two reasons: > > 1) Clock was set between the clock_gettime() and time(). > > 2) The clock has advanced far enough that: > > timekeeper.tv_nsec + (clock_now_ns() - last_update_ns) > NSEC_PER_SEC > > #1 is just a property of clock REALTIME. There is nothing we can do > about that. > > #2 is due to the optimized get_seconds()/time() access which avoids to > read the clock. This can happen on bare metal as well, but is far > more likely to be exposed on virt. > > The same problem exists for CLOCK_XXX vs. CLOCK_XXX_COARSE > > clock_gettime(CLOCK_XXX, &ts); > clock_gettime(CLOCK_XXX_COARSE, &tc); > assert(tc.tv_sec >= ts.tv_sec); > > The _COARSE variants return their associated timekeeper.tv_sec,tv_nsec > pair without reading the clock. Same as #2 above just extended to clock > MONOTONIC. > > There is no way to fix this except giving up on the fast accessors and > make everything take the slow path and read the clock, which might make > a lot of people unhappy. > > For clock REALTIME #1 is anyway an issue, so I think documenting this > proper is the right thing to do. > > Thoughts? > I completely agree with your analysis and the fact that we should document this information. My proposal would be to use either the vDSO document present in the kernel [1] or the man pages for time(2) and clock_gettime(2). Probably the second would be more accessible to user space developers. [1] Documentation/ABI/stable/vdso > Thanks, > > tglx > -- Regards, Vincenzo