Received: by 2002:ab2:1347:0:b0:1f4:ac9d:b246 with SMTP id g7csp64975lqg; Wed, 10 Apr 2024 15:48:21 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXD9PEzjDePH/gSjrAe8ph1hAKrpNoX4Vaj5i3fsqNwHxRCYSgEwuN3IdIZ77HGJGHDSaKtZw6W+2cQxKlEImJ+iMtZ05+cgjJ7VfWmKA== X-Google-Smtp-Source: AGHT+IFDpC3FD2L/9LcyuSD+O+aLOhQKxSbSkh8HyuPqqzk3RYrM6YLWn/RKWOjAWb4kvz/4DvoR X-Received: by 2002:a05:6a00:9392:b0:6ea:9b37:c288 with SMTP id ka18-20020a056a00939200b006ea9b37c288mr1184449pfb.15.1712789300963; Wed, 10 Apr 2024 15:48:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712789300; cv=pass; d=google.com; s=arc-20160816; b=MrnnzMbw6EvI82nutVoOhUqDC0YUBrTUC/Rr1Foa1C6r060yZ0VA5pajHeRMcXCKJM u6hBfxJwFC7oRsp75Bd2d3/DHSRTiVpJK/N2MgqZAXR7M0wIP4LSlEPVVINH1VM3qLng 4NBH12LWm0AxQ+7n6BU5BnygKHUppAS+jl1lO2D0wX79suSaRimz92QOtyVn7YoQ0/r/ cHYVg5hHijusrH5Dv8Cr6tBcOvSZcLOkHddGMEcT2NGnuD2f3YirMWoyHa6jjHEOIYJ+ uCBGCnJ4uMfXoOrQY3FAshCUXcfuEUyl0f9+1ANgFNvzRwKbSl1fQHeV6svlAWj/Su/g mv4Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:subject:cc:to:from:dkim-signature :dkim-signature:message-id; bh=bZ0w/TM6AE9SMRNm3Xm9JEw2iNfzEaEbkpBswlSbBEk=; fh=joBs/8L+orz77ylyCy6wqNwwi35f7sYhLR+/TQjQjhI=; b=DymigdRdKuPSlMDKq/Pe+jlOqMIAkRSJdyw2ipg9nRcpoPBc3AGnRXRDD+nmf1vuUm 9qTG5iMvw9Nii/BzG1Bh/Qr1Fns6a+CaZ5rg+WhFcAQ4+kbu1fAd9zwL6K/A5E5mxL/6 pxgwBenxD/5SWhodMoMpfCpMJPyLvDERLd7/fwKydCl+Ai5FBYkT1kiqp70IpFvETJdH 8f9kB7o95qSh3hyy3X7oGnwJbMn/jrEMATS82fnaLxtElZLaaLqTvZG/6VEhHHwbwy3l RkvWI/dYzNdJVV8Yo0/Hj64DekLNmdh5/bwzBDbs/KXRInOp0wSHEakrRxKdIRToUyok i0ig==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=JwBgcegB; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-139462-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139462-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id t14-20020a63b70e000000b005cee039f233si89146pgf.425.2024.04.10.15.48.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 15:48:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-139462-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=JwBgcegB; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-139462-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139462-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id A33C9283E97 for ; Wed, 10 Apr 2024 22:48:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8FD6846556; Wed, 10 Apr 2024 22:46:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="JwBgcegB"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Hac/vYtR" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3AD3044C9C for ; Wed, 10 Apr 2024 22:46:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712789191; cv=none; b=aQFlX81kRmqZz404qNcanW31lroif72hKAy+EkrRX1lC4HROzRdk8dGvWtsocVwft54JdDZvjlD9qagqZz1xght2yZpmy5BbH4p0nYyzHl1osPcBEVqooiRv8Mb+7R9mmyji/2eYH03wRLOFfsR3ylgIF6CicxbqPV1n+CKQ2ng= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712789191; c=relaxed/simple; bh=tBM7wjzipNsnWNbyoaSXjOxN31IJ8Anu9Imn8eeRuXc=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=l2Ct9sEl3OouNQMPxyc+RTyyL/dlRckxp2XR35Go6otqVqPXo1ongsjjLSuMOha8soe2mKc0maRQi2rqt3sEjfHUCyUlPBc0/ObliIZMAB85vKb7GBO/kgJMwJftwCo01bVTIK5hKYGVu0bxOIFBmQGnmnp+drS3AGTeNwJgLZU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=JwBgcegB; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Hac/vYtR; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Message-ID: <20240410165551.507566619@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1712789188; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=bZ0w/TM6AE9SMRNm3Xm9JEw2iNfzEaEbkpBswlSbBEk=; b=JwBgcegBSK9F8S1rCnEh4K9h4RRWM/Kw2wiHMj1/nDmTravpXYCT/k0L0Pm0e4ljUM/IHn G8/RW6PDW88uQQ3R2Iy9go6jmBxoShjXpcmYMtG1IM7GepGCGWNJzBk5CJRN7zZdVDKGrH mTAniro9eIsm9A4r0N/4eB9VgpaiK0zxPURA2Pp9XRsIqNjHBSiEuZ/14cuvL4f/OV5zoF vFOOZ/Lk91Fw57CCZPcQvi0WeEDvAKyRKoonTr/Q3zaEYjfTvJhwU5hq/qmt8r97zJmTAz ZtNmVeomMpz07L3NteXi1YslIGNDkV1b6gT60sl/GDr8KLikZbHjD2H5FDc4sA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1712789188; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=bZ0w/TM6AE9SMRNm3Xm9JEw2iNfzEaEbkpBswlSbBEk=; b=Hac/vYtRiZ/v2yf/qhXTlwR+4llBiC0FbGcSvaa+/fVJuqyZlm+bBGIdylWhZIkZrjElwO xMF2/1wiZ6JXOaCA== From: Thomas Gleixner To: LKML Cc: Anna-Maria Behnsen , Frederic Weisbecker , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch V2 09/50] posix-cpu-timers: Handle interval timers correctly in timer_get() References: <20240410164558.316665885@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Thu, 11 Apr 2024 00:46:27 +0200 (CEST) timer_gettime() must return the remaining time to the next expiry of a timer or 0 if the timer is not armed and no signal pending, but posix CPU timers fail to forward a timer which is already expired. Add the required logic to address that. Signed-off-by: Thomas Gleixner --- V2: Split out into new patch to make review simpler - Frederic --- kernel/time/posix-cpu-timers.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) --- a/kernel/time/posix-cpu-timers.c +++ b/kernel/time/posix-cpu-timers.c @@ -787,8 +787,24 @@ static int posix_cpu_timer_set(struct k_ static void __posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec64 *itp, u64 now) { - u64 expires = cpu_timer_getexpires(&timer->it.cpu); + u64 expires, iv = timer->it_interval; + /* + * Make sure that interval timers are moved forward for the + * following cases: + * - Timers which expired, but the signal has not yet been + * delivered + */ + if (iv && (timer->it_requeue_pending & REQUEUE_PENDING)) + expires = bump_cpu_timer(timer, now); + else + expires = cpu_timer_getexpires(&timer->it.cpu); + + /* + * Expired interval timers cannot have a remaining time <= 0. + * The kernel has to move them forward so that the next + * timer expiry is > @now. + */ if (now < expires) { itp->it_value = ns_to_timespec64(expires - now); } else {