Received: by 2002:a05:7412:1492:b0:e2:908c:2ebd with SMTP id s18csp232239rdh; Mon, 21 Aug 2023 13:20:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEE2dY/b+48iwUPUBzJWQM0vaW1B1lnRpe6A4r7+4g+3W3ewuuCeO/V0GhWYhnGkBhu3WLO X-Received: by 2002:a17:903:1212:b0:1bd:b8c0:b58f with SMTP id l18-20020a170903121200b001bdb8c0b58fmr6997558plh.50.1692649240739; Mon, 21 Aug 2023 13:20:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692649240; cv=none; d=google.com; s=arc-20160816; b=lI7xpTEV2wVbVDjHcqUY7RvVDAQx4Xe3mNX5qgHiDNkr5kus8JRlELpNRRANVT6iQ/ cJNskxLXW/fDCf7IAQf6P04Jrk4ZoomIaU8kkChJO1FiLijEOawdK5lrQYrhTciyUeOc sQvFV+RkOnUjDKKRXYT4CJ2mo6ZrNYtKSik3/tHzOmS1sXheKLxUp9DGaMPCI/oc8eos TyT59rRGk0+1iA8D1sF3//Vbku5WTpLybSDobouN7ozVCVIjt8QhZPQ+VQZfsEiOXbiP oQXGgjoMfTrb4CvJmcho9lTVuXZKW7ckG3FbgK4aPqGqJWgo4l+51Av3U1jUKyoivlty iY3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:subject:cc:to:from:date; bh=Pvgkt1UxMn5ZQqUdCeCWIQE1QtAoX1en5Es6rc/sF4w=; fh=boN+c/w6Q69kGm+ZEb+ItfotTU4i+QZARjAYOfYUf1k=; b=EfbaHXtALLGZF53ZDOi+wEd2fb0VWePUegNA1rvvluQxUx0WnTHTeOd4yxQGn8n050 jcYXTKJGHhWFZ9FCZEV74o1VmSs6C7Tx3xaPswBpr9BIQg3aISsTLrHmf5+pX0zWPFx5 FaSHfIAUL0VNnaRfytFNNh0relzRkj1cY4XGkAYwy0utmoP2hrtBtOyGA0WjnUEEseWG TE0PgMIssBlz71y6iB5mnWuB1hqiKvVl0O0AJR2JU7PO1BCSfNdAVOtK0/PYkEwkz1Ca lbnrrg/tYk591mGsnL9vGErhKqLlyyYUzV2jGK22oOmeICO9fvsAmzzT7hbiYnEGG+9v 1fdA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q5-20020a17090311c500b001bf223c315bsi8321377plh.60.2023.08.21.13.20.27; Mon, 21 Aug 2023 13:20:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230228AbjHUUFI (ORCPT + 99 others); Mon, 21 Aug 2023 16:05:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230229AbjHUUFH (ORCPT ); Mon, 21 Aug 2023 16:05:07 -0400 Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72A00129 for ; Mon, 21 Aug 2023 13:05:04 -0700 (PDT) Received: from [2601:18c:8180:ac39:6e0b:84ff:fee2:98bb] (helo=imladris.surriel.com) by shelob.surriel.com with esmtpsa (TLS1.2) tls TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1qYB8H-0005n1-1a; Mon, 21 Aug 2023 16:04:13 -0400 Date: Mon, 21 Aug 2023 16:04:09 -0400 From: Rik van Riel To: linux-kernel@vger.kernel.org Cc: kernel-team@meta.com, Peter Zijlstra , "Paul E. McKenney" , Valentin Schneider , Juergen Gross Subject: [PATCH,RFC] smp,csd: throw an error if a CSD lock is stuck for too long Message-ID: <20230821160409.663b8ba9@imladris.surriel.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: riel@surriel.com X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The CSD lock seems to get stuck in 2 "modes". When it gets stuck temporarily, it usually gets released in a few seconds, and sometimes up to one or two minutes. If the CSD lock stays stuck for more than several minutes, it never seems to get unstuck, and gradually more and more things in the system end up also getting stuck. In the latter case, we should just give up, so the system can dump out a little more information about what went wrong, and, with panic_on_oops and a kdump kernel loaded, dump a whole bunch more information about what might have gone wrong. Question: should this have its own panic_on_ipistall switch in /proc/sys/kernel, or maybe piggyback on panic_on_oops in a different way than via BUG_ON? Signed-off-by: Rik van Riel --- kernel/smp.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/kernel/smp.c b/kernel/smp.c index 385179dae360..8b808bff15e6 100644 --- a/kernel/smp.c +++ b/kernel/smp.c @@ -228,6 +228,7 @@ static bool csd_lock_wait_toolong(struct __call_single_data *csd, u64 ts0, u64 * } ts2 = sched_clock(); + /* How long since we last checked for a stuck CSD lock.*/ ts_delta = ts2 - *ts1; if (likely(ts_delta <= csd_lock_timeout_ns || csd_lock_timeout_ns == 0)) return false; @@ -241,9 +242,17 @@ static bool csd_lock_wait_toolong(struct __call_single_data *csd, u64 ts0, u64 * else cpux = cpu; cpu_cur_csd = smp_load_acquire(&per_cpu(cur_csd, cpux)); /* Before func and info. */ + /* How long since this CSD lock was stuck. */ + ts_delta = ts2 - ts0; pr_alert("csd: %s non-responsive CSD lock (#%d) on CPU#%d, waiting %llu ns for CPU#%02d %pS(%ps).\n", - firsttime ? "Detected" : "Continued", *bug_id, raw_smp_processor_id(), ts2 - ts0, + firsttime ? "Detected" : "Continued", *bug_id, raw_smp_processor_id(), ts_delta, cpu, csd->func, csd->info); + /* + * If the CSD lock is still stuck after 5 minutes, it is unlikely + * to become unstuck. Use a signed comparison to avoid triggering + * on underflows when the TSC is out of sync between sockets. + */ + BUG_ON((s64)ts_delta > 300000000000LL); if (cpu_cur_csd && csd != cpu_cur_csd) { pr_alert("\tcsd: CSD lock (#%d) handling prior %pS(%ps) request.\n", *bug_id, READ_ONCE(per_cpu(cur_csd_func, cpux)), -- 2.41.0