Received: by 2002:a05:7412:e79e:b0:f3:1519:9f41 with SMTP id o30csp223505rdd; Wed, 22 Nov 2023 14:06:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IFzNpm7BW9iXBIWxHfrz5wykh9X4M81T1ECRWyMgcphsyoi1zDK30yFEyZFBcYPHcb0kM4/ X-Received: by 2002:a17:902:ce90:b0:1cf:6a75:e980 with SMTP id f16-20020a170902ce9000b001cf6a75e980mr1240434plg.0.1700690807022; Wed, 22 Nov 2023 14:06:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700690807; cv=none; d=google.com; s=arc-20160816; b=EAoPaRbIbVCfR5nEousYnwvvJFl76X2HkLwrRySeLLsj0E+2tAEDoVXzdqeU20w3o2 AOFvtIu5/NsgJE3VTnoswZwrXsxXNobp6WUYOtG+plcSICKPhKO8AxP/hy/mDHJF0V/q 1iD4ZP0mwIgGx8nVoKtGdQflBc1UuFISlrZ1sW17OsOxQ72gtKGRihtuhMcDAy5t1rji z0pBlsa07QHClD6gETIS75OOZ5OEV4//WlsgUkYEikrogj8SO06KhbOMxBfv8beZP64V /fp1vxXnbQFxZSGcx2735Xg2KXAzFCTY9F/3WW9Ly3qkXx1BQlwWN+xvSUawg6CmPyD1 nf8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=2BZ74XrA5N4XOlmks/DqXWHkQTiz0TwZg8TDdsJEbXA=; fh=V18UOOBhruImUJRp8oYwTorYhwhBmHKy/BA5/v7y95A=; b=gAsKtSUTB8eIjMmkRSuvW0p+xd36xP/x6mnxNjsexdrKMWeTNH50kUd9nIH4HHfPik UKRKAom68bIgs3CfSDeHXjVHLrbXYZ7ksw76IESjZqtaddY1c1RmcLqNCXCKm6R+zLsj zBIsjBqt7fl2y8oPkZD3wNH0msFrmjpCD7IokoRTx5Q6f6rAyH664ZzNuroZz1ULH96f csPCv8hGitddP9MvE5HYcNbWE7xch85Sk8YNecaV8qixSDnxtY6S1TXXWrpFJsNfoE+8 PqUofbzsgT751f9+EAT9A3sTzu6qPaW6oUWOItxAHuJOe40jKUl0OISeU7HYDliiXlwR 1J4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=y1Hk41eg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id q2-20020a656a82000000b00577461296a9si365006pgu.338.2023.11.22.14.06.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 14:06:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=y1Hk41eg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 769B080907B1; Wed, 22 Nov 2023 14:05:44 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235181AbjKVWF1 (ORCPT + 99 others); Wed, 22 Nov 2023 17:05:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231392AbjKVWF0 (ORCPT ); Wed, 22 Nov 2023 17:05:26 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9765210C for ; Wed, 22 Nov 2023 14:05:22 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03D05C433C9; Wed, 22 Nov 2023 22:05:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1700690722; bh=6xOIEj/qsKa5m7ejSZ5W5X0UvOk1jhvFPhHiF6L75xA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=y1Hk41eg3sODEMExVfE8eRdPshbzoz1JkHYScAyrOF9UQXOkBEqF4tLDuJW/zZAs8 Gop3nqGi5IL6iTAf116t19POFywvldo5I57ilCW9TMso5lmyJD8mahO0HgeX//oGts r28xnV3VX1+qxKwiYFSYyUA4inIKEJcFXSlVlUjw= Date: Wed, 22 Nov 2023 14:05:21 -0800 From: Andrew Morton To: lizhe.67@bytedance.com Cc: dianders@chromium.org, pmladek@suse.com, lecopzer.chen@mediatek.com, kernelfans@gmail.com, linux-kernel@vger.kernel.org, lizefan.x@bytedance.com Subject: Re: [PATCH v2] softlockup: serialized softlockup's log Message-Id: <20231122140521.85c66b789625e8d270722b3c@linux-foundation.org> In-Reply-To: <20231122100212.94327-1-lizhe.67@bytedance.com> References: <20231122100212.94327-1-lizhe.67@bytedance.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 22 Nov 2023 14:05:44 -0800 (PST) On Wed, 22 Nov 2023 18:02:12 +0800 lizhe.67@bytedance.com wrote: > From: Li Zhe > > If multiple CPUs trigger softlockup at the same time with > 'softlockup_all_cpu_backtrace=0', the softlockup's logs will appear > staggeredly in dmesg, which will affect the viewing of the logs for > developer. Since the code path for outputting softlockup logs is not > a kernel hotspot and the performance requirements for the code are > not strict, locks are used to serialize the softlockup log output to > improve the readability of the logs. Seems reasonable, but... > --- a/kernel/watchdog.c > +++ b/kernel/watchdog.c > @@ -28,6 +28,8 @@ > #include > > static DEFINE_MUTEX(watchdog_mutex); > +/* This lock is used to prevent concurrent actions of softlockup output logs */ > +static DEFINE_SPINLOCK(watchdog_output_lock); It would be a little neater to reduce the scope of this - move the definition into that little code block in watchdog_timer_fn() where it is actually used. > #if defined(CONFIG_HARDLOCKUP_DETECTOR) || defined(CONFIG_HARDLOCKUP_DETECTOR_SPARC64) > # define WATCHDOG_HARDLOCKUP_DEFAULT 1 > @@ -514,6 +516,7 @@ static enum hrtimer_restart watchdog_timer_fn(struct hrtimer *hrtimer) > /* Start period for the next softlockup warning. */ > update_report_ts(); > > + spin_lock(&watchdog_output_lock); The hrtimer callout function is called from [soft]irq context, yes? Doesn't lockdep get upset when we take a spinlock in such a context? > pr_emerg("BUG: soft lockup - CPU#%d stuck for %us! [%s:%d]\n", > smp_processor_id(), duration, > current->comm, task_pid_nr(current)); > @@ -523,6 +526,7 @@ static enum hrtimer_restart watchdog_timer_fn(struct hrtimer *hrtimer) > show_regs(regs); > else > dump_stack(); > + spin_unlock(&watchdog_output_lock); > > if (softlockup_all_cpu_backtrace) { > trigger_allbutcpu_cpu_backtrace(smp_processor_id());