Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp21135015rwd; Thu, 29 Jun 2023 11:25:22 -0700 (PDT) X-Google-Smtp-Source: APBJJlGbgMGE01XxEWjzpvl0tN2qVbXoAtPAs7FtYp8e3hR00rXvOZ2WWq3rsqz5m/593ZTQPfgo X-Received: by 2002:a17:90a:4cc6:b0:262:b6aa:8ab5 with SMTP id k64-20020a17090a4cc600b00262b6aa8ab5mr115617pjh.41.1688063122462; Thu, 29 Jun 2023 11:25:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688063122; cv=none; d=google.com; s=arc-20160816; b=zwz0tU6u0nsJGWYbjCI9bq5vgEkhkoPuwGe42NxEhR1NLI7DwPJugmLMoee2iw5Yh5 RVLEkTV+9WVNOfj9pSQ2VQAELZb2K4VyfBF8DLT1NuW0mc/T/674sx0l8pZ6VOsHkoSN iCwLtuwUt7YCgX1uPTvAnlZ4+Kd7y3bw6jWHT4qbvjkEu9N1sj+hQk6yaXd4jmYsAqx6 W4XQSU06AE3BQUCMBkPou1lUtJwnNaXmPVi32FeAvJwORU5bQrL1759j1UzP56L6xtJD XM9poHtPjdni4X4F+cPcj1/jIdw19YScdUPds5QiKbrvhCpZC1jqq35VhGaOAkdrfr2B txTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=9zdxRTzndBW57lfegbn1CoeTXkaZu8rXXCLefAusQhY=; fh=7+BSne7+Nsu2Q4IouaoanoIP6ArVtkXIHqdpI0+dNj0=; b=rx48QBcLNbU9i08VmPJuI6TQ92wP7J+IXSRNppslQ/XWsnkgTeeDo/BvAMltKy3lgZ p0VMEuZ+PMiud8b7tLkhBNe3wthIi+nCloz6pwuoO+ctdSps1KKzlq2435pnLcynbTjc 55mFe78por8TCwIkdLrSSBG52u95sz5xUp2VttZ/O++0MqpTNNZG3rsfuE/yIx5YbW05 wr1fQfAQ/SXr6FG2wqJ9girF9+16fIQjV9qDrBnk0aBfjSBwdEQSpjIG7ckkl6EfGhRF 3clUr/SB/9ykhrVK8kSRkXwE7TrHURT5xDdn9wpISiHzC95mKwZwUkQREvDLK2dEUdA7 FIIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=D7VKVU6G; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l184-20020a6388c1000000b0054481da6ee5si10829500pgd.418.2023.06.29.11.25.08; Thu, 29 Jun 2023 11:25:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=D7VKVU6G; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231644AbjF2SO7 (ORCPT + 99 others); Thu, 29 Jun 2023 14:14:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232022AbjF2SOx (ORCPT ); Thu, 29 Jun 2023 14:14:53 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9712D2D51 for ; Thu, 29 Jun 2023 11:14:52 -0700 (PDT) From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1688062490; 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: in-reply-to:in-reply-to:references:references; bh=9zdxRTzndBW57lfegbn1CoeTXkaZu8rXXCLefAusQhY=; b=D7VKVU6GkSOMgUAO+7DUXnenF4A0pz65mNJSBqEazLVRm5Rik2Z1+SY9zQRjrJMZeBwW60 I0YCkV1m/TZL9d+0smaCBOINH/RSlNPSYWo6Oyh/JmS6ARs34SjHxANTL4tgIO5yIYSuvx O7r0uC4DIJqppmKHjtvgzb3p7pW9iAytqd/XUTcCAYsbeyZp8CCGL2JyJwIkGl4nfkea5+ 7Nm942eLdE8+dnbzxtZAa6tkc1ifBXJEDyl9UkQ6pzaBU1SGIcPGX+Jn8++mKGK8w/rao2 d0PLrqgVSKUKN5nGPcSaWZpLZrKQsqDtLzpAYkyf0NjI+3Yh8XCbUatbcCxunw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1688062490; 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: in-reply-to:in-reply-to:references:references; bh=9zdxRTzndBW57lfegbn1CoeTXkaZu8rXXCLefAusQhY=; b=xjgHEnCfzb8hprsd4iEfT8SsJ6gGFY97u3tT+htkbdb+Nbd3bfEUn5wFRUZ3ejBLO2gRNy STl4srNTAP09UJDA== To: Frederic Weisbecker Cc: LKML , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: Re: [patch 09/45] posix-cpu-timers: Fix posix_cpu_timer_get() behaviour In-Reply-To: References: <20230606132949.068951363@linutronix.de> <20230606142031.532247561@linutronix.de> Date: Thu, 29 Jun 2023 20:14:49 +0200 Message-ID: <871qhu2l0m.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 27 2023 at 00:46, Frederic Weisbecker wrote:> On Tue, Jun 06, 2023 at 04:37:33PM +0200, Thomas Gleixner wrote: >> Aside of that posix_cpu_timer_set() pointlessly arms SIGEV_NONE timers >> which are later disarmed when the initial expiry happens. That's bogus and >> just keeping the process wide timer active for nothing. >> >> Cure this by: >> >> 1) Avoiding to arm SIGEV_NONE timers >> >> 2) Forwarding interval timers in posix_cpu_timer_get() >> >> 3) Taking SIGEV_NONE into account when a oneshot timer has expired > > This patch does too many things at once... Let me try again to split it up. I failed before ... >> -static void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec64 *itp) >> +static void __posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec64 *itp, u64 now) >> { >> - clockid_t clkid = CPUCLOCK_WHICH(timer->it_clock); >> - struct cpu_timer *ctmr = &timer->it.cpu; >> - u64 now, expires = cpu_timer_getexpires(ctmr); >> - struct task_struct *p; >> - >> - rcu_read_lock(); >> - p = cpu_timer_task_rcu(timer); >> - if (!p) >> - goto out; >> + bool sigev_none = timer->it_sigev_notify == SIGEV_NONE; >> + u64 expires; >> >> /* >> - * Easy part: convert the reload time. >> + * Make sure that interval timers are moved forward for the >> + * following cases: >> + * - SIGEV_NONE timers which are never armed >> + * - Timers which expired, but the signal has not yet been >> + * delivered >> */ >> - itp->it_interval = ktime_to_timespec64(timer->it_interval); >> - >> - if (!expires) >> - goto out; >> + expires = bump_cpu_timer(timer, now); > > What if the expiration has been reached but we arrived here before > handle_posix_cpu_timers() had a chance? In that case the call to > bump_cpu_timer() may forward the timer and artificially create an > overrun / missed event. Bah. This clearly misses some conditionals so that it actually handles the cases described in the comment above it... Thanks, tglx