From nobody Sun Feb 8 19:25:30 2026 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 D860B209F5B; Mon, 3 Feb 2025 15:31:39 +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=1738596702; cv=none; b=e1fl2CpQ6jYqhqPbZv6QGJKoeSz6q7bq5ZIoV1s7cHFOy222+uRhfT9EDvZdr7VV1Rh3Kvisz46N4LsgDWPmcVCSvhusjDHU4vvqnojbK88hy0i6P6iGlOJTLb87XwYU0VTlvXK5neXz4ZcgBiKj9hFXluC/FS89U3NzdsUbw8k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738596702; c=relaxed/simple; bh=2O3Om8Pvfs2d85QJTAZ+hT8svAOCt5hGLqwYe3KL8rg=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=Z+wPvHjqQFeInXXsLjm/pTcL13LYXhgwTs/uNJSi1kOVmnK3W9XmZzFfOE/qEeE1UN9342b8TTkcWM/VxTYmydkdjOtd+TCYAI3YiB7sjnmeK2mQEugGiBSCSMUs+Ls6kBqQutLbAIfrUxFKuPeC1Cel3Y5dcyNjEtyNLq/e70U= 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=yiAVmNre; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=QMpFeBV1; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="yiAVmNre"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="QMpFeBV1" Date: Mon, 03 Feb 2025 15:31:36 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1738596698; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EaQwflR7xkfJUS+ly/bCJZ9TcJAKXexclHLN0L8nqE8=; b=yiAVmNreFKNcFYW98ClL39M9d7Q3/fU2d22S6MqwI9hEBRw8ujkICElr/kBIgIRP1h0Gru e+mgSl3Zw6f4cgf2Ak65s7Bj9dMzVrM3szf738xMU17EEqBI84R7feMO1DylIocgdEZgF3 +yTH+YWztZVqQO68+CrISk0S2YkhNuxqMeoLmzD3C17e6+wB6hreARAfJBpT4n57K3SPJq sf2KodGLM7I6dEaYD5mtGjolxJulOXwUCmT2iJoPUrvfb6d56s+mCdk0P7FshppBEXQo6K XyPIW/ZvP+lQDOB4dKrt+TuX6aojrVgEwdbagEhtoH7OJIkSebIhLMByIrweZw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1738596698; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EaQwflR7xkfJUS+ly/bCJZ9TcJAKXexclHLN0L8nqE8=; b=QMpFeBV1Nx0qWt0+bHTg6OtiqMskUdXu/8wECxB8ikWFjm+ya1LOpGWdpCeVUQC5FzaOiu cVQUbiS9ahiRHNDw== From: "tip-bot2 for Waiman Long" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: timers/urgent] clocksource: Use migrate_disable() to avoid calling get_random_u32() in atomic context Cc: Sebastian Andrzej Siewior , Waiman Long , Thomas Gleixner , "Paul E. McKenney" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20250131173323.891943-2-longman@redhat.com> References: <20250131173323.891943-2-longman@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <173859669633.10177.1567684612873040628.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the timers/urgent branch of tip: Commit-ID: 6bb05a33337b2c842373857b63de5c9bf1ae2a09 Gitweb: https://git.kernel.org/tip/6bb05a33337b2c842373857b63de5c9bf= 1ae2a09 Author: Waiman Long AuthorDate: Fri, 31 Jan 2025 12:33:23 -05:00 Committer: Thomas Gleixner CommitterDate: Mon, 03 Feb 2025 16:18:56 +01:00 clocksource: Use migrate_disable() to avoid calling get_random_u32() in ato= mic context The following bug report happened with a PREEMPT_RT kernel: BUG: sleeping function called from invalid context at kernel/locking/spin= lock_rt.c:48 in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 2012, name: kwatch= dog preempt_count: 1, expected: 0 RCU nest depth: 0, expected: 0 get_random_u32+0x4f/0x110 clocksource_verify_choose_cpus+0xab/0x1a0 clocksource_verify_percpu.part.0+0x6b/0x330 clocksource_watchdog_kthread+0x193/0x1a0 It is due to the fact that clocksource_verify_choose_cpus() is invoked with preemption disabled. This function invokes get_random_u32() to obtain random numbers for choosing CPUs. The batched_entropy_32 local lock and/or the base_crng.lock spinlock in driver/char/random.c will be acquired during the call. In PREEMPT_RT kernel, they are both sleeping locks and so cannot be acquired in atomic context. Fix this problem by using migrate_disable() to allow smp_processor_id() to be reliably used without introducing atomic context. preempt_disable() is then called after clocksource_verify_choose_cpus() but before the clocksource measurement is being run to avoid introducing unexpected latency. Fixes: 7560c02bdffb ("clocksource: Check per-CPU clock synchronization when= marked unstable") Suggested-by: Sebastian Andrzej Siewior Signed-off-by: Waiman Long Signed-off-by: Thomas Gleixner Reviewed-by: Paul E. McKenney Reviewed-by: Sebastian Andrzej Siewior Link: https://lore.kernel.org/all/20250131173323.891943-2-longman@redhat.com --- kernel/time/clocksource.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c index 77d9566..2a7802e 100644 --- a/kernel/time/clocksource.c +++ b/kernel/time/clocksource.c @@ -373,10 +373,10 @@ void clocksource_verify_percpu(struct clocksource *cs) cpumask_clear(&cpus_ahead); cpumask_clear(&cpus_behind); cpus_read_lock(); - preempt_disable(); + migrate_disable(); clocksource_verify_choose_cpus(); if (cpumask_empty(&cpus_chosen)) { - preempt_enable(); + migrate_enable(); cpus_read_unlock(); pr_warn("Not enough CPUs to check clocksource '%s'.\n", cs->name); return; @@ -384,6 +384,7 @@ void clocksource_verify_percpu(struct clocksource *cs) testcpu =3D smp_processor_id(); pr_info("Checking clocksource %s synchronization from CPU %d to CPUs %*pb= l.\n", cs->name, testcpu, cpumask_pr_args(&cpus_chosen)); + preempt_disable(); for_each_cpu(cpu, &cpus_chosen) { if (cpu =3D=3D testcpu) continue; @@ -403,6 +404,7 @@ void clocksource_verify_percpu(struct clocksource *cs) cs_nsec_min =3D cs_nsec; } preempt_enable(); + migrate_enable(); cpus_read_unlock(); if (!cpumask_empty(&cpus_ahead)) pr_warn(" CPUs %*pbl ahead of CPU %d for clocksource %s.\n",