Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2603573lqb; Tue, 28 May 2024 05:22:07 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXIcYny7GHREw62SmiQcPFAv2wg/eIoFW4QmRKC7SMahMIcutVo2s1+pRy7846V0vl2K/jLwvZWG0SFCWpJzHyqUa9JXYQstwfRz9MZfg== X-Google-Smtp-Source: AGHT+IGZme61B3S7oL99ZD8Yynp319SZ3hJP9LqQwL8b9ssw5T5IsExyzesKzc53wqJrSsvp//jL X-Received: by 2002:a92:cdaf:0:b0:373:8d34:4abe with SMTP id e9e14a558f8ab-3738d344ff2mr91491445ab.22.1716898927450; Tue, 28 May 2024 05:22:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716898927; cv=pass; d=google.com; s=arc-20160816; b=wbrHf2Vkza5FEZMR0hCgIVVaGYOnZjTJNt3RXvx1ga8agiMznGCfY+PQl0Z/XpLE7I aFbc4LBWRPUzVL4J4rLD/+vJH/cJX4k2eqO4iFMrD+Ed35XRbjA7TtjnfUVM3DNDqjtN 5R0FKeEY1ytN4syL7yxrdyqNq756Fi6dQHIM1kyK6YGBkXyYI5nMOItux/4LftwnTDPs Jf9ExXcsI528MBPgDTIv5Cn4K6hqQ9B5c88jVfflNej+/CiE4lQFOKbV4GwHhc1Jpm3c dqnccX8Ww+M6ki/E5Mf4juYmA8GyjNHx2zX+B4jk4S5I6LWMgDbGsKhTz4oha6JsU2k6 kA1A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :message-id:subject:cc:to:from:date:dkim-signature; bh=uCh1gYJFIP639OlFNyHDb4Yot7+nKefxsAYABdFfySA=; fh=DrnLVe9OaK7N4pqdHtGyBKWYB6W1LPA6jrokFQtXADY=; b=0XmHg+qIUuIinM2d32Q9irn2hdIX7aVp4xuMNPWteeVCjzeNlxP+ADasQ5vMVJPNmz 4ZkLRlaYkVj/pIMIjirjpjWPATDXKnrIwiEUkr9rFBd6oTdE+P3n05JjRyVfuWXg9T40 wZ7+qGqiepstjd6JZ8DI2ADBjsdqWaHBAES5eIbVqSZeeI5W5U7qeB2ngP0Q/A7FvxwQ 51ve7VWTwpjZAFfqLyX/10Fc7Zr3SQQ5MfmlYxEKvrE9Y23NxX7LD9SfW24ESe+nL78+ mbL7YmGX8hmJ6VIvMD4p4k/oCuMTjt48QjRgq+yTng6UZyKsUNQnaOQ8VJqCsbjG93HR EgEg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IgXvxGmx; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-192281-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192281-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-682275b2d8dsi7956706a12.342.2024.05.28.05.22.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 05:22:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-192281-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IgXvxGmx; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-192281-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192281-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 10C6C281EE6 for ; Tue, 28 May 2024 12:22:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8F3BE16D4CD; Tue, 28 May 2024 12:21:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="IgXvxGmx" 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 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-Type: text/plain; charset=us-ascii 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 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 *dev, int broadcast) } } -#ifdef CONFIG_NO_HZ_FULL -static void giveup_do_timer(void *info) -{ - int cpu = *(unsigned int *)info; - - WARN_ON(tick_do_timer_cpu != smp_processor_id()); - - tick_do_timer_cpu = cpu; -} - -static void tick_take_do_timer_from_boot(void) -{ - int cpu = smp_processor_id(); - int from = tick_do_timer_boot_cpu; - - if (from >= 0 && from != 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 = 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 = cpu; } else if (tick_do_timer_boot_cpu != -1 && !tick_nohz_full_cpu(cpu)) { - tick_take_do_timer_from_boot(); tick_do_timer_boot_cpu = -1; - WARN_ON(READ_ONCE(tick_do_timer_cpu) != 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 } -- 2.25.1.362.g51ebf55