Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1352988rwd; Thu, 15 Jun 2023 09:22:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4W3IDUzIdkOAv5SnW6/Z15gw9Jecfos+CBGkGNHdPhL5u6OGczhOIqNtZW2ciOg06FGUf9 X-Received: by 2002:aa7:df0e:0:b0:514:bbf9:2dc0 with SMTP id c14-20020aa7df0e000000b00514bbf92dc0mr11831941edy.31.1686846160757; Thu, 15 Jun 2023 09:22:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686846160; cv=none; d=google.com; s=arc-20160816; b=OtXSplov/IoEe/QjPkk99iZOtJ62oehXVZUBIm9jSsr/2AzVtMRi6g8pZah5gltewG /rGpWaNcLx0wgZL3aCOWzcRU0cbhRtU9/3xamf9NmbVk6PkUNVPZTFCbwzNiS258aEr6 3Fge5/HtVpves1UUYFQSRYOSAU6Bg2k8mNPDFheoRstKLA4Xaz3ZueIl3CTO0VUzbPTv gsSwldNmmvIO6M4rEHYZUNhG+ZejWRqFcdLCnIVxucHtERsDhk2ivg3TcfGIWuuiLsZj aRA4UVYFmdxFRj1vkn4XhgK8zdv1pzaYHMXk0ZxTT7CFde9DgMxu4hdbmd4ASCKvZTRq WcHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=JavcXrjGn4mHCXMrWheJSZoCVuwJFmCp90APvt1u644=; b=Lrvu7PwUU2xJ3xD3lh/mkwRBBr9BIFiHQl8usDQ0GYcP+Ui/L2jjwf8JWkEdfZbcY+ j5Ee8XtUKugrJK8ihO9U1L8IebHP4BUty/YTKVCcoKZzu3AS7a2Im3x0BWSJtL8Qt4JG S4sLqW7dSmon2myLOQSSkp3KU75ECyz6Et3bmLnOkZDUj6ij6YZFI1AkN/76y+rDsvUp LlLFZmH43GDlBDkzxWhaDUNGVUSkbjc1+v3zjc3p3J2TrZSle7fDKU+0FlfY19Os7llq 2wY7gIzk7PTid3ssVigr0dS51bAyXPqOri2kRAvB6YekTIB9HZ2UmmWDjCa+DPdIqfbh hFYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SV5IxU0d; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r10-20020aa7cb8a000000b005149e0f8897si9763242edt.331.2023.06.15.09.22.14; Thu, 15 Jun 2023 09:22:40 -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=@kernel.org header.s=k20201202 header.b=SV5IxU0d; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241215AbjFOQAz (ORCPT + 99 others); Thu, 15 Jun 2023 12:00:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241465AbjFOQAx (ORCPT ); Thu, 15 Jun 2023 12:00:53 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F9D2294E; Thu, 15 Jun 2023 09:00:52 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1D8C462118; Thu, 15 Jun 2023 16:00:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 735A0C433C0; Thu, 15 Jun 2023 16:00:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686844851; bh=h/6t7DwDjA3p+BAZ2sQtK/aU1fbTz3A8IeHUPH5Jep4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SV5IxU0dpgPZ7fXfIUCGRNy7QrQkryzp/8BbBqvMIrsaB6UqwdNi1tCY+eV/ZilK7 LyxrHXlChvx/Bn/IFU/3i9h7T5GagC73RoCt0mnCE0Xr76fzaQ+voFdSFVsl++5rgr +mnTYUkzTy9tnhmagAS65d8WaEodJ6Y+w6cPTUaJISRGYzSkiHwPwxRA0Y8RAnpoMA o1ePrQbpfKbXCuLTT9H+eCBJ5g3vyLuxGNLEWAkb8uNmgvy3rA8ddHKNNXmCKSnNDr GNW8J7ICGJpIRQreTm4WI84n1WIyv76HWQB9bZB0QYnUwIx/yonXeallCa8uVyPgef WZ7sv0G19K/8A== From: SeongJae Park To: Sebastian Andrzej Siewior Cc: Mathias Krause , Luiz Capitulino , Sven-Haegar Koch , "gregkh@linuxfoundation.org" , "Bhatnagar, Rishabh" , "linux-kernel@vger.kernel.org" , "tglx@linutronix.de" , "sashal@kernel.org" , abuehaze@amazon.com, "stable@vger.kernel.org" , Frederic Weisbecker , Ingo Molnar , SeongJae Park Subject: Re: [PATCH] tick/common: Align tick period during sched_timer setup. Date: Thu, 15 Jun 2023 16:00:48 +0000 Message-Id: <20230615160048.84518-1-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230615091830.RxMV2xf_@linutronix.de> References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 Thu, 15 Jun 2023 11:18:30 +0200 Sebastian Andrzej Siewior wrote: > From: Thomas Gleixner > > The tick period is aligned very early while the first clock_event_device > is registered. The system runs in periodic mode and switches later to > one-shot mode if possible. > > The next wake-up event is programmed based on aligned value > (tick_next_period) but the delta value, that is used to program the > clock_event_device, is computed based on ktime_get(). > > With the subtracted offset, the devices fires in less than the exacted > time frame. With a large enough offset the system programs the timer for > the next wake-up and the remaining time left is too little to make any > boot progress. The system hangs. > > Move the alignment later to the setup of tick_sched timer. At this point > the system switches to oneshot mode and a highres clocksource is > available. It safe to update tick_next_period ktime_get() will now > return accurate (not jiffies based) time. > > [bigeasy: Patch description + testing]. > > Reported-by: Mathias Krause > Reported-by: "Bhatnagar, Rishabh" > Fixes: e9523a0d81899 ("tick/common: Align tick period with the HZ tick.") > Signed-off-by: Thomas Gleixner > Signed-off-by: Sebastian Andrzej Siewior > Link: https://lore.kernel.org/5a56290d-806e-b9a5-f37c-f21958b5a8c0@grsecurity.net > Link: https://lore.kernel.org/12c6f9a3-d087-b824-0d05-0d18c9bc1bf3@amazon.com I guess adding 'Cc: stable@' might further help stable maintainers? I also left one very tirival cosmetic comment below, but I dont think those could be blockers. Acked-by: SeongJae Park Thanks, SJ > --- > kernel/time/tick-common.c | 11 +---------- > kernel/time/tick-sched.c | 13 ++++++++++++- > 2 files changed, 13 insertions(+), 11 deletions(-) > > diff --git a/kernel/time/tick-common.c b/kernel/time/tick-common.c > index 65b8658da829e..b85f2f9c32426 100644 > --- a/kernel/time/tick-common.c > +++ b/kernel/time/tick-common.c > @@ -218,19 +218,10 @@ static void tick_setup_device(struct tick_device *td, > * this cpu: > */ > if (tick_do_timer_cpu == TICK_DO_TIMER_BOOT) { > - ktime_t next_p; > - u32 rem; > Nit: I guess we'd like to remove above one blank line together? > tick_do_timer_cpu = cpu; > > - next_p = ktime_get(); > - div_u64_rem(next_p, TICK_NSEC, &rem); > - if (rem) { > - next_p -= rem; > - next_p += TICK_NSEC; > - } > - > - tick_next_period = next_p; > + tick_next_period = ktime_get(); > #ifdef CONFIG_NO_HZ_FULL > /* > * The boot CPU may be nohz_full, in which case set > diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c > index 52254679ec489..42c0be3080bde 100644 > --- a/kernel/time/tick-sched.c > +++ b/kernel/time/tick-sched.c > @@ -161,8 +161,19 @@ static ktime_t tick_init_jiffy_update(void) > raw_spin_lock(&jiffies_lock); > write_seqcount_begin(&jiffies_seq); > /* Did we start the jiffies update yet ? */ > - if (last_jiffies_update == 0) > + if (last_jiffies_update == 0) { > + u32 rem; > + > + /* > + * Ensure that the tick is aligned to a multiple of > + * TICK_NSEC. > + */ > + div_u64_rem(tick_next_period, TICK_NSEC, &rem); > + if (rem) > + tick_next_period += TICK_NSEC - rem; > + > last_jiffies_update = tick_next_period; > + } > period = last_jiffies_update; > write_seqcount_end(&jiffies_seq); > raw_spin_unlock(&jiffies_lock); > -- > 2.40.1