Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp335962pxu; Wed, 25 Nov 2020 04:37:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJydJ5wKymbLZZuzl7sRICPk/EyDvVYBRxS4/S0ATAlulWKjkucdPRwkbb6SOirdaX8g8p4r X-Received: by 2002:a05:6402:22c9:: with SMTP id dm9mr3181006edb.96.1606307828107; Wed, 25 Nov 2020 04:37:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606307828; cv=none; d=google.com; s=arc-20160816; b=EGsMUio2yJTkur7bn1V6P3my7YJzB5SqWss9H0x/SOGMDchK0UefU419+cP196ewlV v5szgCYNtQGB37NVvHCJqgXBufLAOI5iqFQOT16unVqJAfqlsW7W83GerBH+AW9DMdse Bucq2R/SFESj1uJlhrlTLGtpFLIwZKXdF/piePG8izh53Pc+hPfRKil7vyqYiVxYX793 FWZvbHzfRojwKBeqzVddQ00knPAwQlNC9FKEsbbR2d1BEMoGDcOD5xEcuX580apXh/tN byuDVIfGW+AbIs18GMN075ghITXHgmRFx24snqwpU85IJ2DFlD5GYG2GLoxU+RzCeimp /Ldw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=LZIUa5WVKtH+IPuQCk5Fd8DnUmUp5sXKt8pVRFr2E/c=; b=lfvmqHGVaFO3xYGDt7wQ70+Bw1c6njZg6u/rCOPcFhk82hfkZrClgFnYbzA8y7mmop JWJAQ8y80lm9uTRuT6aSQnwdjYlctxVvVkYpfuiTIppGqBXT7lo7AA9zoUUU33ykw927 GlpIx0DVn+KCo8qPyjSpVeMCT1lL4Mbs5VMrqOFqoaoMkSHJ112/xRBmTaJSa3sUDAly WctHHzouQ2fpN2GJUivDyADuL6lUAYs1YGDZv14/mwHhKCMF0AF28PXbTn5yEMXZJz85 0/b5Rn4x9Qwu29ZZMx7CfZbJ5+L3ZSqbqazBR0lbdTrBP+tdwgJ4xcUQ66aJVut95+H7 qHJw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r2si1094062ejb.548.2020.11.25.04.36.43; Wed, 25 Nov 2020 04:37:08 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729424AbgKYMep (ORCPT + 99 others); Wed, 25 Nov 2020 07:34:45 -0500 Received: from mx2.suse.de ([195.135.220.15]:40226 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726162AbgKYMeo (ORCPT ); Wed, 25 Nov 2020 07:34:44 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 576F3AC2F; Wed, 25 Nov 2020 12:34:43 +0000 (UTC) Date: Wed, 25 Nov 2020 13:35:34 +0100 From: Cyril Hrubis To: Thomas Gleixner Cc: Li Wang , ltp@lists.linux.it, Chunyu Hu , LKML , Peter Zijlstra , John Stultz , Arnd Bergmann , Vincenzo Frascino , Andy Lutomirski , "Michael Kerrisk (man-pages)" , Carlos O'Donell Subject: Re: [PATCH 1/2] syscalls: avoid time() using __cvdso_gettimeofday in use-level's VDSO Message-ID: <20201125123534.GA28684@yuki.lan> References: <20201123083137.11575-1-liwang@redhat.com> <20201124153837.GA24470@yuki.lan> <875z5tllih.fsf@nanos.tec.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <875z5tllih.fsf@nanos.tec.linutronix.de> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi! > 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. Good hint, I guess that easiest fix would be to switch to coarse timers for these tests. > 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. That's understandable and reasonable. Thanks a lot for the confirmation. > For clock REALTIME #1 is anyway an issue, so I think documenting this > proper is the right thing to do. > > Thoughts? I guess that ideally BUGS section for time(2) and clock_gettime(2) should be updated with this explanation. -- Cyril Hrubis chrubis@suse.cz