From nobody Fri Dec 19 21:10:01 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 534361667F7 for ; Tue, 28 May 2024 12:21:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716898918; cv=none; b=br+Ljpwm6uZ5NDvWfzbNImdA5+u0fLw/QYNimIrtIP2g5FkSK5VERwk5DnVO3KWScx/c6siypr158r1uHy15dhoGDETP5/GzFRGsChxFaDULFJDDL4KFV2e6aSwYba/jyx2d2FutF8jd6h+dYUNy6rGhdMcbJzaoqBCnFZbJyNs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716898918; c=relaxed/simple; bh=elNuCq8QtdmOU0EzT0lu07QKF5Eq5srUhF1AcdcGzqw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=W1wAF54yhacG9oeVJU6SemWAjA/qa4TfRU3vVBvcs2JubYDHs72VvaylPCq7rFiudSRfXfpEzU3Joc+Rg3JCm5iNXamdyWkIcdCiJ2A4EwZgLQSX9iKzcyL7fKoixCel50b2Yk5j8SdGlHP8O5U2VeYWzJhzvV/RvmukRyylXmE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=IgXvxGmx; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="IgXvxGmx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716898916; 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=uCh1gYJFIP639OlFNyHDb4Yot7+nKefxsAYABdFfySA=; b=IgXvxGmx9pZ8MIPeDS5uh2JivqO7q6fA3kWQVyQBxOdrHZaxY/fLmbLzRPWxUeBTIB3nHx lO3ll8icDOWbLawi/UbM6PKfDj5Y+Y5IIcF99dh5y+C4n1aGepylKzd3nken9WV3qFUfzi yiS0Lb9Ggv0MVDFecRfbA7ca4aBnMfo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-445-WBexFJXmMpWh_TmmG5EyUA-1; Tue, 28 May 2024 08:21:50 -0400 X-MC-Unique: WBexFJXmMpWh_TmmG5EyUA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B01C585A58C; Tue, 28 May 2024 12:21:49 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.226.131]) by smtp.corp.redhat.com (Postfix) with SMTP id 3B451C15BB1; Tue, 28 May 2024 12:21:48 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Tue, 28 May 2024 14:20:21 +0200 (CEST) Date: Tue, 28 May 2024 14:20:19 +0200 From: Oleg Nesterov To: Frederic Weisbecker , Ingo Molnar , Nicholas Piggin , Peter Zijlstra , Phil Auld , Thomas Gleixner Cc: Chris von Recklinghausen , linux-kernel@vger.kernel.org Subject: [PATCH] tick/nohz_full: don't abuse smp_call_function_single() in tick_setup_device() Message-ID: <20240528122019.GA28794@redhat.com> References: <20240522151742.GA10400@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240522151742.GA10400@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" After the recent commit 5097cbcb38e6 ("sched/isolation: Prevent boot crash when the boot CPU is nohz_full") the kernel no longer crashes, but there is another problem. In this case tick_setup_device() calls tick_take_do_timer_from_boot() to update tick_do_timer_cpu and this triggers the WARN_ON_ONCE(irqs_disabled) in smp_call_function_single(). Kill tick_take_do_timer_from_boot() and just use WRITE_ONCE(), the new comment tries to explain why this is safe (thanks Thomas!). Fixes: 08ae95f4fd3b ("nohz_full: Allow the boot CPU to be nohz_full") Link: https://lore.kernel.org/all/20240522151742.GA10400@redhat.com Signed-off-by: Oleg Nesterov --- kernel/time/tick-common.c | 39 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/kernel/time/tick-common.c b/kernel/time/tick-common.c index d88b13076b79..27d0018c8b05 100644 --- a/kernel/time/tick-common.c +++ b/kernel/time/tick-common.c @@ -178,26 +178,6 @@ void tick_setup_periodic(struct clock_event_device *de= v, int broadcast) } } =20 -#ifdef CONFIG_NO_HZ_FULL -static void giveup_do_timer(void *info) -{ - int cpu =3D *(unsigned int *)info; - - WARN_ON(tick_do_timer_cpu !=3D smp_processor_id()); - - tick_do_timer_cpu =3D cpu; -} - -static void tick_take_do_timer_from_boot(void) -{ - int cpu =3D smp_processor_id(); - int from =3D tick_do_timer_boot_cpu; - - if (from >=3D 0 && from !=3D cpu) - smp_call_function_single(from, giveup_do_timer, &cpu, 1); -} -#endif - /* * Setup the tick device */ @@ -221,19 +201,26 @@ static void tick_setup_device(struct tick_device *td, tick_next_period =3D ktime_get(); #ifdef CONFIG_NO_HZ_FULL /* - * The boot CPU may be nohz_full, in which case set - * tick_do_timer_boot_cpu so the first housekeeping - * secondary that comes up will take do_timer from - * us. + * The boot CPU may be nohz_full, in which case the + * first housekeeping secondary will take do_timer() + * from us. */ if (tick_nohz_full_cpu(cpu)) tick_do_timer_boot_cpu =3D cpu; =20 } else if (tick_do_timer_boot_cpu !=3D -1 && !tick_nohz_full_cpu(cpu)) { - tick_take_do_timer_from_boot(); tick_do_timer_boot_cpu =3D -1; - WARN_ON(READ_ONCE(tick_do_timer_cpu) !=3D cpu); + /* + * The boot CPU will stay in periodic (NOHZ disabled) + * mode until clocksource_done_booting() called after + * smp_init() selects a high resolution clocksource and + * timekeeping_notify() kicks the NOHZ stuff alive. + * + * So this WRITE_ONCE can only race with the READ_ONCE + * check in tick_periodic() but this race is harmless. + */ + WRITE_ONCE(tick_do_timer_cpu, cpu); #endif } =20 --=20 2.25.1.362.g51ebf55