From patchwork Fri Aug 4 14:00:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 131216 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:44a:b0:3f2:4152:657d with SMTP id ez10csp325350vqb; Fri, 4 Aug 2023 08:06:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE6Rg0W+Ta35tqC/aAFNlPXOjyP0ujnP9yAM3Mia6tiAZQbVWAY74Mn5prSQ7dCXvXN91R6 X-Received: by 2002:a05:6a20:4308:b0:13f:d171:fd6d with SMTP id h8-20020a056a20430800b0013fd171fd6dmr2645972pzk.51.1691161618879; Fri, 04 Aug 2023 08:06:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691161618; cv=none; d=google.com; s=arc-20160816; b=iA5/AjNdL9i8tiFiVMhkWJpgy0j1z5JY0fRfocC3xAQMzrabyv+OWz89+ytA+KVUxY I2+oD/E6+ly7gxgMUhqJnTYd0PoBs3ts5tBBfrIzgjUprbICOlVAEg/5wmhUeu45D+Nb ZQwdTsH/K+I9bFFjx+ZaaO6/awvMeQpX1OFE8t4cOY1oAtWbt5i8GsmO4mPLGudQ0SAY Wypcd3v8XPygzpHYxusNXgjK/JCJ+35rAzbCdinIWH0ZDOo+IIMub0a72VobJ18pt+BU V/+MI3HLt6VW+CBL82zn5KXrXdmu6EdrCPVMgxlPwuN4yUlzE8fUKvahk+0UypdvBfRn 516g== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=f39QpJHkK3FDjMGNWGLjQE1kQtnElDb2bSgZWnyAPYg=; fh=SkV4WIZ/kO3rGeSx4T6/01fodnID+WR4rjybrs3KpPk=; b=LJgTPO/PxiEzatGvxfe9VHjC+q/CzJuxQSdodyLPbgpCfqGnvrF9qbOP5cNVBg1Eiv F+eMbk/YyPeOfE75JYms/wxTpFbXCtDHHQCiqMiZuHLebiTMoogsXcvrqNYRYHCtgT46 h/KsD1sC4ZlEfcyoW9PGOCaP/uOczFmv+7Gp7yVqCsjRQg3M0poKyHQ5IiWUt3Yvh8oC a3K98C9QPFVQiBnurE+6utabaq3Mfbw3Y+RyvVcBzgf7C2HzWYLdT5lcDCdYrLd9q083 se/T5Ag4OZAHz3fdzX3MoMRk3ZYidLw8T6OliTfnX2QD2U7M/gMUMx/ibUZPz3NSRmjD CZtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=X3lAEI69; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v15-20020a63f20f000000b0056499cf2149si2035268pgh.65.2023.08.04.08.06.19; Fri, 04 Aug 2023 08:06:58 -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; dkim=pass header.i=@chromium.org header.s=google header.b=X3lAEI69; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231487AbjHDOB3 (ORCPT + 99 others); Fri, 4 Aug 2023 10:01:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231459AbjHDOBT (ORCPT ); Fri, 4 Aug 2023 10:01:19 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9564F1994 for ; Fri, 4 Aug 2023 07:01:14 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1bbf8cb694aso18031795ad.3 for ; Fri, 04 Aug 2023 07:01:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1691157674; x=1691762474; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=f39QpJHkK3FDjMGNWGLjQE1kQtnElDb2bSgZWnyAPYg=; b=X3lAEI693n80r5mFKYlfIDlyQhhjUlZsA9aQBj3n6FhGBaDvncTyaIKlIxeHmxb3oW aYXtgWmejUHWn1RqoAkoQcSdejArts+GCCmu7wZj9L4TMrrIP56KM4TiETSJip99sg0k 3LxhNBgv4/ZyabndXgou0bVDwJapRc3DbP9kk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691157674; x=1691762474; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=f39QpJHkK3FDjMGNWGLjQE1kQtnElDb2bSgZWnyAPYg=; b=Re3oCjielGYS60H7ZDgNxXoAFKV3Pvt7LRQiakluvgGtRGLkf27VwyW/f72/qlzxB/ Ywy9jUuliXaNCJfl/YtkYM5BsNYTZAUvpFLilEsCpVxDIPsC4eatKeSZq4/EeaN5o6kG /M7SQ0YDD+nxHKCqC2V1tjStaXIExh8DKc8fau59hrt5yrdnT5vsqIzglO2FjxPOa9Hv C491n5fTE8mUVV2EdnTJmSnazzvEUx9R7ye/nzFjFPpjeEsYXy/rq0f8kOpLCIIBNkJz tMRHtWczDORQEGb0zj4FR94Os+9r2uKCRF+XTCu1hSZemLvm6jnEBZ54Z+UvMMiCocAT /mhA== X-Gm-Message-State: AOJu0YzLT6Qf0yC5oD6MgiEulIh34DRYKF/PW24HoW9Z0PtyrKGmWW6q MjnxQc0Ce71wJRhuYBOsRaa4Rg== X-Received: by 2002:a17:902:d5cb:b0:1b8:33d4:77f8 with SMTP id g11-20020a170902d5cb00b001b833d477f8mr1954462plh.23.1691157673658; Fri, 04 Aug 2023 07:01:13 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:7e35:e6d0:7bbf:64]) by smtp.gmail.com with ESMTPSA id g5-20020a170902c38500b001b89536974bsm1792291plg.202.2023.08.04.07.01.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 07:01:12 -0700 (PDT) From: Douglas Anderson To: Andrew Morton Cc: Petr Mladek , Michal Hocko , Douglas Anderson , Arnd Bergmann , Borislav Petkov , Christophe Leroy , "Darrick J. Wong" , Dave Hansen , "David S. Miller" , Frederic Weisbecker , Gaosheng Cui , Greg Kroah-Hartman , "Guilherme G. Piccoli" , "H. Peter Anvin" , Huacai Chen , Ingo Molnar , "Jason A. Donenfeld" , Jianmin Lv , Jinyang He , Josh Poimboeuf , Kees Cook , Lecopzer Chen , Marc Zyngier , Mark Rutland , Michael Ellerman , Nicholas Piggin , "Paul E. McKenney" , Peter Zijlstra , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Pingfan Liu , Qing Zhang , "Russell King (Oracle)" , Russell King , Stephen Rothwell , Thomas Bogendoerfer , Thomas Gleixner , Tom Rix , Ulf Hansson , Valentin Schneider , WANG Xuerui , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, loongarch@lists.linux.dev, sparclinux@vger.kernel.org, x86@kernel.org Subject: [PATCH v4 1/2] nmi_backtrace: Allow excluding an arbitrary CPU Date: Fri, 4 Aug 2023 07:00:42 -0700 Message-ID: <20230804065935.v4.1.Ia35521b91fc781368945161d7b28538f9996c182@changeid> X-Mailer: git-send-email 2.41.0.585.gd2178a4bd4-goog MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773260268515232651 X-GMAIL-MSGID: 1773311485594719850 The APIs that allow backtracing across CPUs have always had a way to exclude the current CPU. This convenience means callers didn't need to find a place to allocate a CPU mask just to handle the common case. Let's extend the API to take a CPU ID to exclude instead of just a boolean. This isn't any more complex for the API to handle and allows the hardlockup detector to exclude a different CPU (the one it already did a trace for) without needing to find space for a CPU mask. Arguably, this new API also encourages safer behavior. Specifically if the caller wants to avoid tracing the current CPU (maybe because they already traced the current CPU) this makes it more obvious to the caller that they need to make sure that the current CPU ID can't change. Acked-by: Michal Hocko Signed-off-by: Douglas Anderson --- Changes in v4: - Renamed trigger_allbutself_cpu_backtrace() for when trigger is unsupported. Changes in v3: - ("nmi_backtrace: Allow excluding an arbitrary CPU") new for v3. arch/arm/include/asm/irq.h | 2 +- arch/arm/kernel/smp.c | 4 ++-- arch/loongarch/include/asm/irq.h | 2 +- arch/loongarch/kernel/process.c | 4 ++-- arch/mips/include/asm/irq.h | 2 +- arch/mips/kernel/process.c | 4 ++-- arch/powerpc/include/asm/irq.h | 2 +- arch/powerpc/kernel/stacktrace.c | 4 ++-- arch/powerpc/kernel/watchdog.c | 4 ++-- arch/sparc/include/asm/irq_64.h | 2 +- arch/sparc/kernel/process_64.c | 6 +++--- arch/x86/include/asm/irq.h | 2 +- arch/x86/kernel/apic/hw_nmi.c | 4 ++-- include/linux/nmi.h | 14 +++++++------- kernel/watchdog.c | 2 +- lib/nmi_backtrace.c | 6 +++--- 16 files changed, 32 insertions(+), 32 deletions(-) diff --git a/arch/arm/include/asm/irq.h b/arch/arm/include/asm/irq.h index 18605f1b3580..26c1d2ced4ce 100644 --- a/arch/arm/include/asm/irq.h +++ b/arch/arm/include/asm/irq.h @@ -32,7 +32,7 @@ void handle_IRQ(unsigned int, struct pt_regs *); #include extern void arch_trigger_cpumask_backtrace(const cpumask_t *mask, - bool exclude_self); + int exclude_cpu); #define arch_trigger_cpumask_backtrace arch_trigger_cpumask_backtrace #endif diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c index 6756203e45f3..3431c0553f45 100644 --- a/arch/arm/kernel/smp.c +++ b/arch/arm/kernel/smp.c @@ -846,7 +846,7 @@ static void raise_nmi(cpumask_t *mask) __ipi_send_mask(ipi_desc[IPI_CPU_BACKTRACE], mask); } -void arch_trigger_cpumask_backtrace(const cpumask_t *mask, bool exclude_self) +void arch_trigger_cpumask_backtrace(const cpumask_t *mask, int exclude_cpu) { - nmi_trigger_cpumask_backtrace(mask, exclude_self, raise_nmi); + nmi_trigger_cpumask_backtrace(mask, exclude_cpu, raise_nmi); } diff --git a/arch/loongarch/include/asm/irq.h b/arch/loongarch/include/asm/irq.h index a115e8999c69..218b4da0ea90 100644 --- a/arch/loongarch/include/asm/irq.h +++ b/arch/loongarch/include/asm/irq.h @@ -40,7 +40,7 @@ void spurious_interrupt(void); #define NR_IRQS_LEGACY 16 #define arch_trigger_cpumask_backtrace arch_trigger_cpumask_backtrace -void arch_trigger_cpumask_backtrace(const struct cpumask *mask, bool exclude_self); +void arch_trigger_cpumask_backtrace(const struct cpumask *mask, int exclude_cpu); #define MAX_IO_PICS 2 #define NR_IRQS (64 + (256 * MAX_IO_PICS)) diff --git a/arch/loongarch/kernel/process.c b/arch/loongarch/kernel/process.c index 2e04eb07abb6..778e8d09953e 100644 --- a/arch/loongarch/kernel/process.c +++ b/arch/loongarch/kernel/process.c @@ -345,9 +345,9 @@ static void raise_backtrace(cpumask_t *mask) } } -void arch_trigger_cpumask_backtrace(const cpumask_t *mask, bool exclude_self) +void arch_trigger_cpumask_backtrace(const cpumask_t *mask, int exclude_cpu) { - nmi_trigger_cpumask_backtrace(mask, exclude_self, raise_backtrace); + nmi_trigger_cpumask_backtrace(mask, exclude_cpu, raise_backtrace); } #ifdef CONFIG_64BIT diff --git a/arch/mips/include/asm/irq.h b/arch/mips/include/asm/irq.h index 75abfa834ab7..3a848e7e69f7 100644 --- a/arch/mips/include/asm/irq.h +++ b/arch/mips/include/asm/irq.h @@ -77,7 +77,7 @@ extern int cp0_fdc_irq; extern int get_c0_fdc_int(void); void arch_trigger_cpumask_backtrace(const struct cpumask *mask, - bool exclude_self); + int exclude_cpu); #define arch_trigger_cpumask_backtrace arch_trigger_cpumask_backtrace #endif /* _ASM_IRQ_H */ diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c index a3225912c862..5387ed0a5186 100644 --- a/arch/mips/kernel/process.c +++ b/arch/mips/kernel/process.c @@ -750,9 +750,9 @@ static void raise_backtrace(cpumask_t *mask) } } -void arch_trigger_cpumask_backtrace(const cpumask_t *mask, bool exclude_self) +void arch_trigger_cpumask_backtrace(const cpumask_t *mask, int exclude_cpu) { - nmi_trigger_cpumask_backtrace(mask, exclude_self, raise_backtrace); + nmi_trigger_cpumask_backtrace(mask, exclude_cpu, raise_backtrace); } int mips_get_process_fp_mode(struct task_struct *task) diff --git a/arch/powerpc/include/asm/irq.h b/arch/powerpc/include/asm/irq.h index f257cacb49a9..ba1a5974e714 100644 --- a/arch/powerpc/include/asm/irq.h +++ b/arch/powerpc/include/asm/irq.h @@ -55,7 +55,7 @@ int irq_choose_cpu(const struct cpumask *mask); #if defined(CONFIG_PPC_BOOK3S_64) && defined(CONFIG_NMI_IPI) extern void arch_trigger_cpumask_backtrace(const cpumask_t *mask, - bool exclude_self); + int exclude_cpu); #define arch_trigger_cpumask_backtrace arch_trigger_cpumask_backtrace #endif diff --git a/arch/powerpc/kernel/stacktrace.c b/arch/powerpc/kernel/stacktrace.c index 5de8597eaab8..b15f15dcacb5 100644 --- a/arch/powerpc/kernel/stacktrace.c +++ b/arch/powerpc/kernel/stacktrace.c @@ -221,8 +221,8 @@ static void raise_backtrace_ipi(cpumask_t *mask) } } -void arch_trigger_cpumask_backtrace(const cpumask_t *mask, bool exclude_self) +void arch_trigger_cpumask_backtrace(const cpumask_t *mask, int exclude_cpu) { - nmi_trigger_cpumask_backtrace(mask, exclude_self, raise_backtrace_ipi); + nmi_trigger_cpumask_backtrace(mask, exclude_cpu, raise_backtrace_ipi); } #endif /* defined(CONFIG_PPC_BOOK3S_64) && defined(CONFIG_NMI_IPI) */ diff --git a/arch/powerpc/kernel/watchdog.c b/arch/powerpc/kernel/watchdog.c index edb2dd1f53eb..8c464a5d8246 100644 --- a/arch/powerpc/kernel/watchdog.c +++ b/arch/powerpc/kernel/watchdog.c @@ -245,7 +245,7 @@ static void watchdog_smp_panic(int cpu) __cpumask_clear_cpu(c, &wd_smp_cpus_ipi); } } else { - trigger_allbutself_cpu_backtrace(); + trigger_allbutcpu_cpu_backtrace(cpu); cpumask_clear(&wd_smp_cpus_ipi); } @@ -416,7 +416,7 @@ DEFINE_INTERRUPT_HANDLER_NMI(soft_nmi_interrupt) xchg(&__wd_nmi_output, 1); // see wd_lockup_ipi if (sysctl_hardlockup_all_cpu_backtrace) - trigger_allbutself_cpu_backtrace(); + trigger_allbutcpu_cpu_backtrace(cpu); if (hardlockup_panic) nmi_panic(regs, "Hard LOCKUP"); diff --git a/arch/sparc/include/asm/irq_64.h b/arch/sparc/include/asm/irq_64.h index b436029f1ced..8c4c0c87f998 100644 --- a/arch/sparc/include/asm/irq_64.h +++ b/arch/sparc/include/asm/irq_64.h @@ -87,7 +87,7 @@ static inline unsigned long get_softint(void) } void arch_trigger_cpumask_backtrace(const struct cpumask *mask, - bool exclude_self); + int exclude_cpu); #define arch_trigger_cpumask_backtrace arch_trigger_cpumask_backtrace extern void *hardirq_stack[NR_CPUS]; diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c index b51d8fb0ecdc..1ea3f37fa985 100644 --- a/arch/sparc/kernel/process_64.c +++ b/arch/sparc/kernel/process_64.c @@ -236,7 +236,7 @@ static void __global_reg_poll(struct global_reg_snapshot *gp) } } -void arch_trigger_cpumask_backtrace(const cpumask_t *mask, bool exclude_self) +void arch_trigger_cpumask_backtrace(const cpumask_t *mask, int exclude_cpu) { struct thread_info *tp = current_thread_info(); struct pt_regs *regs = get_irq_regs(); @@ -252,7 +252,7 @@ void arch_trigger_cpumask_backtrace(const cpumask_t *mask, bool exclude_self) memset(global_cpu_snapshot, 0, sizeof(global_cpu_snapshot)); - if (cpumask_test_cpu(this_cpu, mask) && !exclude_self) + if (cpumask_test_cpu(this_cpu, mask) && this_cpu != exclude_cpu) __global_reg_self(tp, regs, this_cpu); smp_fetch_global_regs(); @@ -260,7 +260,7 @@ void arch_trigger_cpumask_backtrace(const cpumask_t *mask, bool exclude_self) for_each_cpu(cpu, mask) { struct global_reg_snapshot *gp; - if (exclude_self && cpu == this_cpu) + if (cpu == exclude_cpu) continue; gp = &global_cpu_snapshot[cpu].reg; diff --git a/arch/x86/include/asm/irq.h b/arch/x86/include/asm/irq.h index 29e083b92813..836c170d3087 100644 --- a/arch/x86/include/asm/irq.h +++ b/arch/x86/include/asm/irq.h @@ -42,7 +42,7 @@ extern void init_ISA_irqs(void); #ifdef CONFIG_X86_LOCAL_APIC void arch_trigger_cpumask_backtrace(const struct cpumask *mask, - bool exclude_self); + int exclude_cpu); #define arch_trigger_cpumask_backtrace arch_trigger_cpumask_backtrace #endif diff --git a/arch/x86/kernel/apic/hw_nmi.c b/arch/x86/kernel/apic/hw_nmi.c index 34a992e275ef..d6e01f924299 100644 --- a/arch/x86/kernel/apic/hw_nmi.c +++ b/arch/x86/kernel/apic/hw_nmi.c @@ -34,9 +34,9 @@ static void nmi_raise_cpu_backtrace(cpumask_t *mask) apic->send_IPI_mask(mask, NMI_VECTOR); } -void arch_trigger_cpumask_backtrace(const cpumask_t *mask, bool exclude_self) +void arch_trigger_cpumask_backtrace(const cpumask_t *mask, int exclude_cpu) { - nmi_trigger_cpumask_backtrace(mask, exclude_self, + nmi_trigger_cpumask_backtrace(mask, exclude_cpu, nmi_raise_cpu_backtrace); } diff --git a/include/linux/nmi.h b/include/linux/nmi.h index e3e6a64b98e0..7cf7801856a1 100644 --- a/include/linux/nmi.h +++ b/include/linux/nmi.h @@ -157,31 +157,31 @@ static inline void touch_nmi_watchdog(void) #ifdef arch_trigger_cpumask_backtrace static inline bool trigger_all_cpu_backtrace(void) { - arch_trigger_cpumask_backtrace(cpu_online_mask, false); + arch_trigger_cpumask_backtrace(cpu_online_mask, -1); return true; } -static inline bool trigger_allbutself_cpu_backtrace(void) +static inline bool trigger_allbutcpu_cpu_backtrace(int exclude_cpu) { - arch_trigger_cpumask_backtrace(cpu_online_mask, true); + arch_trigger_cpumask_backtrace(cpu_online_mask, exclude_cpu); return true; } static inline bool trigger_cpumask_backtrace(struct cpumask *mask) { - arch_trigger_cpumask_backtrace(mask, false); + arch_trigger_cpumask_backtrace(mask, -1); return true; } static inline bool trigger_single_cpu_backtrace(int cpu) { - arch_trigger_cpumask_backtrace(cpumask_of(cpu), false); + arch_trigger_cpumask_backtrace(cpumask_of(cpu), -1); return true; } /* generic implementation */ void nmi_trigger_cpumask_backtrace(const cpumask_t *mask, - bool exclude_self, + int exclude_cpu, void (*raise)(cpumask_t *mask)); bool nmi_cpu_backtrace(struct pt_regs *regs); @@ -190,7 +190,7 @@ static inline bool trigger_all_cpu_backtrace(void) { return false; } -static inline bool trigger_allbutself_cpu_backtrace(void) +static inline bool trigger_allbutcpu_cpu_backtrace(void) { return false; } diff --git a/kernel/watchdog.c b/kernel/watchdog.c index be38276a365f..085d7a78f62f 100644 --- a/kernel/watchdog.c +++ b/kernel/watchdog.c @@ -523,7 +523,7 @@ static enum hrtimer_restart watchdog_timer_fn(struct hrtimer *hrtimer) dump_stack(); if (softlockup_all_cpu_backtrace) { - trigger_allbutself_cpu_backtrace(); + trigger_allbutcpu_cpu_backtrace(smp_processor_id()); clear_bit_unlock(0, &soft_lockup_nmi_warn); } diff --git a/lib/nmi_backtrace.c b/lib/nmi_backtrace.c index 5274bbb026d7..33c154264bfe 100644 --- a/lib/nmi_backtrace.c +++ b/lib/nmi_backtrace.c @@ -34,7 +34,7 @@ static unsigned long backtrace_flag; * they are passed being updated as a side effect of this call. */ void nmi_trigger_cpumask_backtrace(const cpumask_t *mask, - bool exclude_self, + int exclude_cpu, void (*raise)(cpumask_t *mask)) { int i, this_cpu = get_cpu(); @@ -49,8 +49,8 @@ void nmi_trigger_cpumask_backtrace(const cpumask_t *mask, } cpumask_copy(to_cpumask(backtrace_mask), mask); - if (exclude_self) - cpumask_clear_cpu(this_cpu, to_cpumask(backtrace_mask)); + if (exclude_cpu != -1) + cpumask_clear_cpu(exclude_cpu, to_cpumask(backtrace_mask)); /* * Don't try to send an NMI to this cpu; it may work on some From patchwork Fri Aug 4 14:00:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 131206 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:44a:b0:3f2:4152:657d with SMTP id ez10csp311676vqb; Fri, 4 Aug 2023 07:45:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHWeDUfEOYAWo/TNc3KQU1gWxWuqPmnANpacCcXhIu/huFvCyDFihnxKFrM4aQgWmju7ULk X-Received: by 2002:a19:384d:0:b0:4fd:f85d:f67a with SMTP id d13-20020a19384d000000b004fdf85df67amr1192074lfj.61.1691160332967; Fri, 04 Aug 2023 07:45:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691160332; cv=none; d=google.com; s=arc-20160816; b=OnTdsDhwkeXdIvC3ZRYAmBdc1G9rghxxId9f0e34L8OifBSrOy9PVaBBZwUCymuLws FAkC/0JdogJIyqRpONf2R3wbnB1C2aiY1jf/Tp1MXnzFzVTTU+/ttUWPjl7e/Dxp7iVe 1bMtS7XK6SrJWa7xJp2vuoL4BjBOEkaVMMmwjy3mrRCqhVIN+GshVVRC56SPaEf1DRtX 5oO/ihlqQrv9+GO5FukKz3l+kBEBNlOvjMf6xPVmNFr8Okv/EMZzUsdN3h/ekwlFY9AB b6lO3WP3px+56j+X9D/3eMkQF7SmpsYB3qDqwS1OyW3lDh4Bv3mmw8OrsIFDzj3T7rya hatA== 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:date:subject:cc:to:from :dkim-signature; bh=/ubpHUCUhhdAc9BVTuBszAKxHoy82Y2oolLi025KUkk=; fh=avs7fZ6pz8AoZpPPmikAp2BXzqt3vVG0t7rbESvlVlk=; b=diRR5Chn2Hqfq1719sbntT8TquOCbDZMyw49eB9ZhjjyLhqCNS32nRkJ21LIXdYRXd TyV59Sa22drr8bPJZHQGJCTslC6hoJF9JqAJ+5hKI25tMY/5AYDKvWprM5/BV2NT8zvz eD+7WZoGv5T6jQX7Tii8rls+zaO6plTuJIF2EjONROaDbTdw7ZB0q8vLc6mEnadW17lC MeW9+MkRjHVZRgUoLeBDqztYdHVpK9T4/viuCgcBxjNj07rZpjAVwnKgMnG2aFslbyal t5vCoQRdu4xD7zN0axlK7WQEDWk2pvuK1tEETRYNsP0AzLX+Y4G6WIQzmK22kxCAJidv Kung== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=lM7VVMYB; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s10-20020a056402164a00b00522472b99f5si1614643edx.285.2023.08.04.07.45.07; Fri, 04 Aug 2023 07:45:32 -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; dkim=pass header.i=@chromium.org header.s=google header.b=lM7VVMYB; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231424AbjHDOBb (ORCPT + 99 others); Fri, 4 Aug 2023 10:01:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231462AbjHDOBU (ORCPT ); Fri, 4 Aug 2023 10:01:20 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 113FC19AA for ; Fri, 4 Aug 2023 07:01:17 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1bc02bd4eafso18107875ad.1 for ; Fri, 04 Aug 2023 07:01:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1691157676; x=1691762476; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/ubpHUCUhhdAc9BVTuBszAKxHoy82Y2oolLi025KUkk=; b=lM7VVMYBqLq1WWaKyoy1S9d9QHqyvdoAXmQKdUq1F1mGa1KKnkys7Y3zb0ObUNTO/8 D6/0MKl7nUQQi1/P2oo6KBdOlRmoYlfhATagj8O3Gy9Ejq7iU1iRTCueBRDQc5+jkufs Yg6z7jRxvZTeC6ywXmtCoJEaRAjiFYESD7IkU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691157676; x=1691762476; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/ubpHUCUhhdAc9BVTuBszAKxHoy82Y2oolLi025KUkk=; b=AFjF1PhYDqrRqzb4gNavo2MGyzkvIePpBJYvAyD5dErBhroZDn058czly6ykgW42Ty XzvIrcCfny/OAf43WwCiKNCjKDKnfi5rPU+gZrSDGK4ElB5Sh8Khk5a0K+9Vo58y3Qox H0sc50m8SDOtzzN2SGlKUxhGfSd56OByeAEkD4qzkwDBdhaXXY5UzPWRXUoUap/q77dT vnHy7FZ9HdcFnNLMO/VHtqadtU+GPccXBKzcr864ZxrTksVAzHV29ZcLNFksSLbybMTr iazwtSt4to57ud5+AYppzGtUu5NSFZbKlDq625iEQJsfbLATiqLUI5tZ5HvoCChc7d24 wLPA== X-Gm-Message-State: AOJu0Yz9ldFQrDyez6gSNzLJsTM4tWLTi4ngP6YYAQKcJlti87KOS0iN pXXHSSYQnV27jiYsMO2I8z5zCw== X-Received: by 2002:a17:902:b68c:b0:1bc:2036:5338 with SMTP id c12-20020a170902b68c00b001bc20365338mr1611384pls.28.1691157676198; Fri, 04 Aug 2023 07:01:16 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:7e35:e6d0:7bbf:64]) by smtp.gmail.com with ESMTPSA id g5-20020a170902c38500b001b89536974bsm1792291plg.202.2023.08.04.07.01.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 07:01:14 -0700 (PDT) From: Douglas Anderson To: Andrew Morton Cc: Petr Mladek , Michal Hocko , Douglas Anderson , kernel test robot , Lecopzer Chen , Pingfan Liu , linux-kernel@vger.kernel.org Subject: [PATCH v4 2/2] watchdog/hardlockup: Avoid large stack frames in watchdog_hardlockup_check() Date: Fri, 4 Aug 2023 07:00:43 -0700 Message-ID: <20230804065935.v4.2.I501ab68cb926ee33a7c87e063d207abf09b9943c@changeid> X-Mailer: git-send-email 2.41.0.585.gd2178a4bd4-goog In-Reply-To: <20230804065935.v4.1.Ia35521b91fc781368945161d7b28538f9996c182@changeid> References: <20230804065935.v4.1.Ia35521b91fc781368945161d7b28538f9996c182@changeid> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773310137592900551 X-GMAIL-MSGID: 1773310137592900551 After commit 77c12fc95980 ("watchdog/hardlockup: add a "cpu" param to watchdog_hardlockup_check()") we started storing a `struct cpumask` on the stack in watchdog_hardlockup_check(). On systems with CONFIG_NR_CPUS set to 8192 this takes up 1K on the stack. That triggers warnings with `CONFIG_FRAME_WARN` set to 1024. We'll use the new trigger_allbutcpu_cpu_backtrace() to avoid needing to use a CPU mask at all. Fixes: 77c12fc95980 ("watchdog/hardlockup: add a "cpu" param to watchdog_hardlockup_check()") Reported-by: kernel test robot Closes: https://lore.kernel.org/r/202307310955.pLZDhpnl-lkp@intel.com Acked-by: Michal Hocko Signed-off-by: Douglas Anderson Reviewed-by: Petr Mladek --- (no changes since v3) Changes in v3: - Rebase on change introducing trigger_allbutcpu_cpu_backtrace(). Changes in v2: - Allocate space when userspace requests all cpus be backtraced. kernel/watchdog.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/kernel/watchdog.c b/kernel/watchdog.c index 085d7a78f62f..d145305d95fe 100644 --- a/kernel/watchdog.c +++ b/kernel/watchdog.c @@ -151,9 +151,6 @@ void watchdog_hardlockup_check(unsigned int cpu, struct pt_regs *regs) */ if (is_hardlockup(cpu)) { unsigned int this_cpu = smp_processor_id(); - struct cpumask backtrace_mask; - - cpumask_copy(&backtrace_mask, cpu_online_mask); /* Only print hardlockups once. */ if (per_cpu(watchdog_hardlockup_warned, cpu)) @@ -167,10 +164,8 @@ void watchdog_hardlockup_check(unsigned int cpu, struct pt_regs *regs) show_regs(regs); else dump_stack(); - cpumask_clear_cpu(cpu, &backtrace_mask); } else { - if (trigger_single_cpu_backtrace(cpu)) - cpumask_clear_cpu(cpu, &backtrace_mask); + trigger_single_cpu_backtrace(cpu); } /* @@ -179,7 +174,7 @@ void watchdog_hardlockup_check(unsigned int cpu, struct pt_regs *regs) */ if (sysctl_hardlockup_all_cpu_backtrace && !test_and_set_bit(0, &watchdog_hardlockup_all_cpu_dumped)) - trigger_cpumask_backtrace(&backtrace_mask); + trigger_allbutcpu_cpu_backtrace(cpu); if (hardlockup_panic) nmi_panic(regs, "Hard LOCKUP");