Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp1832676ybn; Thu, 26 Sep 2019 02:56:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqxddD7CgFLZ/r/87Tf/ztuo1dN7LFQiKyFbMnLfn/Bn8e08uSGm6lvIQLL1tlVou2jNKoEY X-Received: by 2002:a50:a939:: with SMTP id l54mr2555864edc.214.1569491784750; Thu, 26 Sep 2019 02:56:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569491784; cv=none; d=google.com; s=arc-20160816; b=uzGBDliP1AW4C6VxQ62PAl1ntFvRGXAzrcvehZVAnNTMrNcK+T+Km/YXb8MV/jQNeq GMbgYCYftY5+pqJUY0KuzFkGSMGgl/oj/M/+zRUtwx6rEAgGAQrRKGz0D5GNokJMn9uM D/Ys0Hf743S8imyusEce9AF/qvQ0tjxmS3D+EsW/5A4Gah+N/3vQYxUGl1EbK3Uwy6cA iul0fuZZUZGdZsXO2OGoufMWTZPkLvcB7pTy6mp+uQUTfxM8FWg90HOJOmZBhxykQent UAMjiGPbMbob1LmEiJ0tlCycztZym3Y3yeGeyMi0jfqguz3GR/EZb2v0PKc0sWkEKgAS FssQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CQLYUORcfotgaKqy5gkXc5kVZJb5dGrYga+46jw612E=; b=G7Ge/C7WBPQKM3tTZ7DCQtk67fvg6oeyHfWMX4pswM1PtPLbOZccJTjWOi6jxLFBUf jWvghedcrs+2WGdKDtTmXHLWk6DENncnO8LK7N5WOBCmWARuaTstFiN9ail/nhD7WloN PTrF/bvbDvvxTQnstJZIttTN1bhE61G94H0j5ZhApjK7QjIgfZAGcjE2CkOKdpZNpPfw h9IkW0KxB7Fa+Zf0tS9BaTAXrjiJNAbZCymNRbggkM+lGwXkxuEzFR3fG82PUV6JDw/K 38X6U+PfTw54+gWAnduvQdn2OXGUo6ZFR/FzUNHYIzlAoLgMrUJCRY3YO1MDSwFDKL5o cuKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=BBRlV88b; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t49si986089edd.198.2019.09.26.02.56.01; Thu, 26 Sep 2019 02:56:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=BBRlV88b; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392704AbfIYUC6 (ORCPT + 99 others); Wed, 25 Sep 2019 16:02:58 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:41662 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2440130AbfIYUCw (ORCPT ); Wed, 25 Sep 2019 16:02:52 -0400 Received: by mail-pg1-f196.google.com with SMTP id s1so542615pgv.8 for ; Wed, 25 Sep 2019 13:02:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CQLYUORcfotgaKqy5gkXc5kVZJb5dGrYga+46jw612E=; b=BBRlV88bVISU676nmRF0kHVZdbXHig0dn9rIjsZ8a0RiJ8C7mEzWYP6UYHuj4l6KeY M8EMwHVLwnCKr6L4uqSHsH4P7cYEucUlq4v1CPfV7QjSl0nBvxmnM5Hr3knERGUN+v+T iDStwC0hgjriwDEOj/1GoS+dVq0GqUviNbZq8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CQLYUORcfotgaKqy5gkXc5kVZJb5dGrYga+46jw612E=; b=Y2ME0yMJ5Yy1cZBd1pfyRy4KQGp0D0KXnYaXFWauNggZuLgud+BK1J6WUg3KjxC2mh DRn2l2rdt1Oybcoo/6iljVuNLWsUJT0iaZL09ftApOkiyNO3PZ/IeiJlbchQA1dbcyyd XoxWno7giB5IDHKBePUfJGpbDnfNCOr9ROZMtdbLYpuONtDLrTmHguvIrfRcRQZunapm 61jJK+TwJBIzYzRYKQVyJDM9frhGeHTymJUMIkAWz4m9q1IWR42XX29qAvUd0IcHDNDu hMJTA3vpo5mgoUKNxVoKP44Mkd/hg+PUqh9LgLRIWzHNtBcy05amiV6jpMbKVocOG3XC KHng== X-Gm-Message-State: APjAAAXD3p0fq+1lIriwH6mIyXiGKAe+wjUduZNYzUQSuSqxnYYoHiEy HqfKaakNQKFPBn4+M2RBtpgxhg== X-Received: by 2002:a62:3c1:: with SMTP id 184mr317726pfd.209.1569441771927; Wed, 25 Sep 2019 13:02:51 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:1:24fa:e766:52c9:e3b2]) by smtp.gmail.com with ESMTPSA id d76sm458113pga.80.2019.09.25.13.02.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2019 13:02:51 -0700 (PDT) From: Douglas Anderson To: Catalin Marinas , Will Deacon , Jason Wessel , Daniel Thompson Cc: kgdb-bugreport@lists.sourceforge.net, Douglas Anderson , Christophe Leroy , linux-kernel@vger.kernel.org Subject: [PATCH v3 3/4] kdb: Fix "btc " crash if the CPU didn't round up Date: Wed, 25 Sep 2019 13:02:19 -0700 Message-Id: <20190925125811.v3.3.Id33c06cbd1516b49820faccd80da01c7c4bf15c7@changeid> X-Mailer: git-send-email 2.23.0.351.gc4317032e6-goog In-Reply-To: <20190925200220.157670-1-dianders@chromium.org> References: <20190925200220.157670-1-dianders@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I noticed that when I did "btc " and the CPU I passed in hadn't rounded up that I'd crash. I was going to copy the same fix from commit 162bc7f5afd7 ("kdb: Don't back trace on a cpu that didn't round up") into the "not all the CPUs" case, but decided it'd be better to clean things up a little bit. This consolidates the two code paths. It is _slightly_ wasteful in in that the checks for "cpu" being too small or being offline isn't really needed when we're iterating over all online CPUs, but that really shouldn't hurt. Better to have the same code path. While at it, eliminate at least one slightly ugly (and totally needless) recursive use of kdb_parse(). Signed-off-by: Douglas Anderson --- Changes in v3: - Patch ("kdb: Fix "btc " crash if the CPU...") new for v3. Changes in v2: None kernel/debug/kdb/kdb_bt.c | 61 ++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/kernel/debug/kdb/kdb_bt.c b/kernel/debug/kdb/kdb_bt.c index 120fc686c919..d9af139f9a31 100644 --- a/kernel/debug/kdb/kdb_bt.c +++ b/kernel/debug/kdb/kdb_bt.c @@ -101,6 +101,27 @@ kdb_bt1(struct task_struct *p, unsigned long mask, bool btaprompt) return 0; } +static void +kdb_bt_cpu(unsigned long cpu) +{ + struct task_struct *kdb_tsk; + + if (cpu >= num_possible_cpus() || !cpu_online(cpu)) { + kdb_printf("WARNING: no process for cpu %ld\n", cpu); + return; + } + + /* If a CPU failed to round up we could be here */ + kdb_tsk = KDB_TSK(cpu); + if (!kdb_tsk) { + kdb_printf("WARNING: no task for cpu %ld\n", cpu); + return; + } + + kdb_set_current_task(kdb_tsk); + kdb_bt1(kdb_tsk, ~0UL, false); +} + int kdb_bt(int argc, const char **argv) { @@ -161,7 +182,6 @@ kdb_bt(int argc, const char **argv) } else if (strcmp(argv[0], "btc") == 0) { unsigned long cpu = ~0; struct task_struct *save_current_task = kdb_current_task; - char buf[80]; if (argc > 1) return KDB_ARGCOUNT; if (argc == 1) { @@ -169,35 +189,22 @@ kdb_bt(int argc, const char **argv) if (diag) return diag; } - /* Recursive use of kdb_parse, do not use argv after - * this point */ - argv = NULL; if (cpu != ~0) { - if (cpu >= num_possible_cpus() || !cpu_online(cpu)) { - kdb_printf("no process for cpu %ld\n", cpu); - return 0; - } - sprintf(buf, "btt 0x%px\n", KDB_TSK(cpu)); - kdb_parse(buf); - return 0; - } - kdb_printf("btc: cpu status: "); - kdb_parse("cpu\n"); - for_each_online_cpu(cpu) { - void *kdb_tsk = KDB_TSK(cpu); - - /* If a CPU failed to round up we could be here */ - if (!kdb_tsk) { - kdb_printf("WARNING: no task for cpu %ld\n", - cpu); - continue; + kdb_bt_cpu(cpu); + } else { + /* + * Recursive use of kdb_parse, do not use argv after + * this point. + */ + argv = NULL; + kdb_printf("btc: cpu status: "); + kdb_parse("cpu\n"); + for_each_online_cpu(cpu) { + kdb_bt_cpu(cpu); + touch_nmi_watchdog(); } - - sprintf(buf, "btt 0x%px\n", kdb_tsk); - kdb_parse(buf); - touch_nmi_watchdog(); + kdb_set_current_task(save_current_task); } - kdb_set_current_task(save_current_task); return 0; } else { if (argc) { -- 2.23.0.351.gc4317032e6-goog