Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2616492lqb; Tue, 28 May 2024 05:47:07 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXikrh4V8kgYqUEfQ/XJx44tyjE0jte1OnyeA+3UrWJS7OmPS0giVKHxmCU1JV/w3uDgOPJdJhFB3JausqpyrWTlytnZcbZO7U3QXK1dw== X-Google-Smtp-Source: AGHT+IFsCLUS5lIpnYvdGNK5O0WPa2gZmd4kcDwRFyWGFCVOhtH2Ed8iiC/NEyZp0o6owBYjxNt2 X-Received: by 2002:a17:902:ea04:b0:1f4:5d87:ffb3 with SMTP id d9443c01a7336-1f45d8807d6mr108825115ad.17.1716900426641; Tue, 28 May 2024 05:47:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716900426; cv=pass; d=google.com; s=arc-20160816; b=QFYsPI96TbOiyEGKT8wbYToVBwPtSEVC6zlHIYAD+w3RtLX1xoVL19scATGP6hr6B8 vVYAXCzulCyd8XxGUwfswicVIgxeuzTLRZU57YSon8JBI0eKIEt1zFHN9BbWc3D9XlLY m/Wom/1M/tL+9qLzZfw2ee99+qexh9h2gqBWE9EcLiHMintp0NNm7coHpPbbcMdkLOl0 OKiQ+QCpMQRoYmKvRjehpvHGIC4hA4Z+WCGb8ra3Zz14yLNhs7gReKFPTKulRylCC6to njvh69B6JHSnClId6K3Orvl6q8CsH0BD3tDXi4W1hXpd3THTaGcwK+ePYrj2vymmt1LP 39QA== 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=U5hXCAyCRLskJTU1cugcsSNJSbjQozoJ0z0zbajvdQU=; fh=DrnLVe9OaK7N4pqdHtGyBKWYB6W1LPA6jrokFQtXADY=; b=NkVN1B4PIA6gt6NK4AZgRWQPp0/cVwah27SQkL576jaMruYXN8Dvn5avKdZJzd/1b4 WpLkt0gi1Ll3zR7XmUWK0utHholDKi2SqDU3zeIRVC7GyTegj+6S5leylX9yDZYngfCK 8QqQK5N/ePE8YObpRnoSQlqv/LzJKbWVNmIwtcl3hNyQLk+Da4mfNkDZ9rC3OjI2bOJV kVtdJ6QRmvHk65+4mufOgT7yl682MDLxrgdh/wtT3v/Cw5twDwyVl5VosLrKvDndkhH2 oxxmbOhRyrd6sLxezAW2htiaJ5WSTKMpkoFUef5r3bQ2m46lSntSbZ6Qv8otc633CAEI Ud8w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MrVEGPT3; 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-192289-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192289-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id d9443c01a7336-1f47f3aa86dsi48779805ad.459.2024.05.28.05.47.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 05:47:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-192289-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MrVEGPT3; 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-192289-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192289-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 252D3B25B98 for ; Tue, 28 May 2024 12:24:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 96B4016DED8; Tue, 28 May 2024 12:24:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="MrVEGPT3" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 2FD7F16D4ED for ; Tue, 28 May 2024 12:24:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716899050; cv=none; b=fVC1FF8/SNaXspWLNDYLUpoFHup/Dz2X9Yrb86T7akxk40Tp3Av9ZhLKEHMvYeUV86EQyMrOY5SIr4woGXwixHN5io05LSdVfTlMLjirqfUbH8fyVyPRlH93pBiaR2SvU2bJHtFgwcOsm41tEfhXoF4ggfUVFMoN/FDe6cU++pU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716899050; c=relaxed/simple; bh=/MJqfAee7OGT7xTNKJA57WCoB+d01NTLAU8YZ2IFO0k=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WmIqeXw7tIpfYNoyFR3AkLoEKKfuzUp/WWV09Pihp2bXSgDC5vDIBzfIgXpEOIP4IzyFNbpCtAbFdexNEWvl+7p2JhNGH7k1BnSiwAKwPlqdTMdR2XnJ9HZruYU315SGjDeEOTV+mY7QXImKV4lAioADvCnaMoRwMXraOHMiWxM= 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=MrVEGPT3; arc=none smtp.client-ip=170.10.133.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=1716899048; 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=U5hXCAyCRLskJTU1cugcsSNJSbjQozoJ0z0zbajvdQU=; b=MrVEGPT3pfJ1foCpVG3EjG9ueXkHp+0WKjlkaSNOdt2UHA0ZAXBDWf/bVSUHSAA/+7QLy/ 9dsKUTWcBymVDerW1EMF7NQiYGxFjEZk/CT73QL79ugCpeGyCxqYdlexm3JCpXcRdvspMh 1G2WessU1hZ8rHJZHE/tynzVUrp+QkY= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-414-7AT-4PBFNam1O4vlP9KA1A-1; Tue, 28 May 2024 08:24:05 -0400 X-MC-Unique: 7AT-4PBFNam1O4vlP9KA1A-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (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 A936A29AA382; Tue, 28 May 2024 12:24:04 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.226.131]) by smtp.corp.redhat.com (Postfix) with SMTP id 4E2C02026D68; Tue, 28 May 2024 12:24:02 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Tue, 28 May 2024 14:22:36 +0200 (CEST) Date: Tue, 28 May 2024 14:22:33 +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: Re: [PATCH] tick/nohz_full: don't abuse smp_call_function_single() in tick_setup_device() Message-ID: <20240528122233.GB28794@redhat.com> References: <20240522151742.GA10400@redhat.com> <20240528122019.GA28794@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: <20240528122019.GA28794@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 If this patch/changelog/comment is fine, I'll send another trivial one which turns tick_do_timer_boot_cpu into "bool boot_cpu_is_nohz_full". On 05/28, Oleg Nesterov wrote: > > 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 >