From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 262794315A; Mon, 23 Jun 2025 21:46:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750715181; cv=none; b=LbbTyJRA1dDl6KuZ4DmGWF24mi6F5fjkyVJR+3NBqpbYbGEDLmKuHGcWSKQFDrOkKQNljjIZl2343p2jyviiwLW0yL2L+WZOhZ8tL6wem77GZYVPfpqghew4usV8PAOTEO/PThzoVgEwNHwWhNQGfKlJFSkH7fLE/groVLjj6mg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750715181; c=relaxed/simple; bh=igpuMOLPQu2obFbmsxrkgbl+Z56s8Z1qWupDg5DCYyY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XsRmkI3Qy8CC9U3zjvvW5cHxZPgu36GF8kwrYCeODKFcmYtIA71hFw86RVT7VWc7HqaVaX1Eb/LIxF7m5a4xYh9pENlbKzGMR4zL8ckRC8FFzOKHFIeBvbnqJ7jLfEuDQ0TsBqAGMTNKqccb0gwXjREG/p7vumg+FIfLnUzMusY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=qmUHnFyJ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="qmUHnFyJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B07FEC4CEED; Mon, 23 Jun 2025 21:46:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1750715181; bh=igpuMOLPQu2obFbmsxrkgbl+Z56s8Z1qWupDg5DCYyY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qmUHnFyJTCxHbeC+OBBSyyqV+Ap4wUa4KO6cdQUJYwFgLsw03n8uQtFw1I1DC3peA I9F8BGPYW/aHvtEemHnUudDqnbQiNOVXGAelh/1Daud+MGz3Yo5kLANvmfJBTc5WUP gXBCHpVogZ3pCTCfcpHwLk9Wk4mOdx4rvgsLPzeo= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Thadeu Lima de Souza Cascardo , "Guilherme G. Piccoli" , Thomas Gleixner , "Paul E. McKenney" , Sasha Levin Subject: [PATCH 6.12 169/414] clocksource: Fix the CPUs choice in the watchdog per CPU verification Date: Mon, 23 Jun 2025 15:05:06 +0200 Message-ID: <20250623130646.255538371@linuxfoundation.org> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250623130642.015559452@linuxfoundation.org> References: <20250623130642.015559452@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Guilherme G. Piccoli [ Upstream commit 08d7becc1a6b8c936e25d827becabfe3bff72a36 ] Right now, if the clocksource watchdog detects a clocksource skew, it might perform a per CPU check, for example in the TSC case on x86. In other words: supposing TSC is detected as unstable by the clocksource watchdog running at CPU1, as part of marking TSC unstable the kernel will also run a check of TSC readings on some CPUs to be sure it is synced between them all. But that check happens only on some CPUs, not all of them; this choice is based on the parameter "verify_n_cpus" and in some random cpumask calculation. So, the watchdog runs such per CPU checks on up to "verify_n_cpus" random CPUs among all online CPUs, with the risk of repeating CPUs (that aren't double checked) in the cpumask random calculation. But if "verify_n_cpus" > num_online_cpus(), it should skip the random calculation and just go ahead and check the clocksource sync between all online CPUs, without the risk of skipping some CPUs due to duplicity in the random cpumask calculation. Tests in a 4 CPU laptop with TSC skew detected led to some cases of the per CPU verification skipping some CPU even with verify_n_cpus=8, due to the duplicity on random cpumask generation. Skipping the randomization when the number of online CPUs is smaller than verify_n_cpus, solves that. Suggested-by: Thadeu Lima de Souza Cascardo Signed-off-by: Guilherme G. Piccoli Signed-off-by: Thomas Gleixner Reviewed-by: Paul E. McKenney Link: https://lore.kernel.org/all/20250323173857.372390-1-gpiccoli@igalia.com Signed-off-by: Sasha Levin --- kernel/time/clocksource.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c index 58fb7280cabbe..ae862ad9642cb 100644 --- a/kernel/time/clocksource.c +++ b/kernel/time/clocksource.c @@ -302,7 +302,7 @@ static void clocksource_verify_choose_cpus(void) { int cpu, i, n = verify_n_cpus; - if (n < 0) { + if (n < 0 || n >= num_online_cpus()) { /* Check all of the CPUs. */ cpumask_copy(&cpus_chosen, cpu_online_mask); cpumask_clear_cpu(smp_processor_id(), &cpus_chosen); -- 2.39.5