Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp897976ybb; Wed, 1 Apr 2020 11:40:10 -0700 (PDT) X-Google-Smtp-Source: APiQypLx/OsIdHyCf9Swv85RSNeWAsU5/Bm5NiIT9QUCQFwkkBflS8DouCoJMVW3QQ/SsQcANbas X-Received: by 2002:aca:47c8:: with SMTP id u191mr3945449oia.17.1585766410050; Wed, 01 Apr 2020 11:40:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585766410; cv=none; d=google.com; s=arc-20160816; b=ruYeQEv1JT68zoPMN0+Fng/oRkUG83XLLTo1iUWLLGlCqDEwra9dFlv5F3vutjSoeJ V/tFwwnr53omMs7RY7k2tK/U156EI+F6G4iHa1H5aVvI7ABbudrFJdkF0kzWDfKI/8qL ZXWdY7kBDdfOVbALlIqZsUl2IVp/F6z4b1nsyIC2yzBqKR42qQ2bb3R5WPVEcxINGx/M NnJUfRe1VesOfZ2lUHEFYwGjB488sa/22sWLl0EOV+4dNM5g+2kvjvqKx1No4+Eop9XW uxMB6sC6mt6bmzeSfegYSpJvEVa0I/9EOYqdwmmSDn8G5hV77T1fkHshibNp0HYill5h wqjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:in-reply-to :subject:cc:to:from; bh=XLCaX0H/Qra/joH5lLCnpiygZDzNXNbTsiMLOSuRd7M=; b=Q7DqSvMYT2kfe+lOzdYEF+bxo3Q2vtQ66OILWOeppt7bb16ziNix9Xdyhc0/ZNAC+V 7DKf06f422uENCqXHMnBREmvjGKxQdYEe9pFmhc6q3nM21GQk7P27a/dqZ7gbHgr8c6i 3kgY2UQFIKHTidR5hV1iXrLvTlSce73mkaM70NOw6Y2deiK8KHXH8+Ae6YYX8S/mPHTD gQb3FYQZxP8UM0XPyx5pvn3M94HxlWPzf2HU7zAuAigoN5zvXqigNWK85fqLsT2VRZ26 +xgDQmzxwlaibxtNiWli20Bf5GPlhx3FMeOb08/SHOYogDD1k12mlI75WHwItQv66u6V byoA== 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 w16si1104491oti.167.2020.04.01.11.39.56; Wed, 01 Apr 2020 11:40:09 -0700 (PDT) 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 S1732537AbgDARmq (ORCPT + 99 others); Wed, 1 Apr 2020 13:42:46 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:35565 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732196AbgDARmq (ORCPT ); Wed, 1 Apr 2020 13:42:46 -0400 Received: from p5de0bf0b.dip0.t-ipconnect.de ([93.224.191.11] 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 1jJhNy-0007ix-O2; Wed, 01 Apr 2020 19:42:42 +0200 Received: by nanos.tec.linutronix.de (Postfix, from userid 1000) id 19A9A103A01; Wed, 1 Apr 2020 19:42:42 +0200 (CEST) From: Thomas Gleixner To: "Michael Kerrisk \(man-pages\)" Cc: Michael Kerrisk , linux-man , lkml , arul.jeniston@gmail.com, "devi R.K" , Marc Lehmann , John Stultz , Andrei Vagin , Cyrill Gorcunov Subject: Re: timer_settime() and ECANCELED In-Reply-To: Date: Wed, 01 Apr 2020 19:42:42 +0200 Message-ID: <87pncrf6gd.fsf@nanos.tec.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain 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 Michael, "Michael Kerrisk (man-pages)" writes: > Following on from our discussion of read() on a timerfd [1], I > happened to remember a Debian bug report [2] that points out that > timer_settime() can fail with the error ECANCELED, which is both > surprising and odd (because despite the error, the timer does get > updated). ... > (1) If the wall-clock is changed before the first timerfd_settime() > call, the call succeeds. This is of course expected. > (2) If the wall-clock is changed after a timerfd_settime() call, then > the next timerfd_settime() call fails with ECANCELED. > (3) Even if the timerfd_settime() call fails, the timer is still updated(!). > > Some questions: > (a) What is the rationale for timerfd_settime() failing with ECANCELED > in this case? (Currently, the manual page says nothing about this.) > (b) It seems at the least surprising, but more likely a bug, that > timerfd_settime() fails with ECANCELED while at the same time > successfully updating the timer value. Really good question and TBH I can't remember why this is implemented in the way it is, but I have a faint memory that at least (a) is intentional. After staring at the code for a while I came up with the following answers: (a): If the clock was set event ("date -s ...") which triggered the cancel was not yet consumed by user space via read(), then that information would get lost because arming the timer to the new value has to reset the state. (b): Arming the timer in that case is indeed very questionable, but it could be argued that because the clock was set event happened with the old expiry value that the new expiry value is not affected. I'd be happy to change that and not arm the timer in the case of a pending cancel, but I fear that some user space already depends on that behaviour. Thanks, tglx