Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3276109pxu; Sat, 19 Dec 2020 19:46:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJyF+YUy+RZMzAbFyfM4VwPKFO+dROhN0LkbQpeLqHvh04qdtqqyWxF8hG7avYNtDWlCIy+y X-Received: by 2002:a50:e0ce:: with SMTP id j14mr11159132edl.18.1608435994336; Sat, 19 Dec 2020 19:46:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608435994; cv=none; d=google.com; s=arc-20160816; b=POiGVn0+cKKBn+GsLOg3X3IxnoQKcfrIMY+AGClsLS7hAw9n/8xQIQ3HCVYYLUGoGL u4qKhzfcTTVniwrvuksE8a0UR7+gewKygpmu2h23CwQtvBYry+AolPDDRHFZ+QMJCAYA gJw+0i2LhPUF1oSfSRcXa2xKmMMIj6/UH7kitfbo6L7oCJHW+vEndSaTyCLXSm6FlnXv IitMUsodShFWlzIJn1q4pnaZa1UjSnVbGFTquznXMOySWb39/h0NVEfzXk1JvOyq9oiS lS7hUm1bLDwuoplkjFbjIC1IpTNJhdaHEw9cUvwjQiD9ZLf+PEntcb03clule3/R52cX 1XlQ== 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; bh=uSpOmpfYMFNcsPD1azqQFeGrfOrMG39oMZ1JT86sonY=; b=Gbcx6GtUoF6D6aTiYtEJxgf72gEMflUNj0SECl4QxWH21RR3VvlnoCsLne7MBNN0YU zLJInnU4EykBhbG5JAQGXUuE3yuVEje/p7kNZRtLsVjpxANh5lZNTHNMhUX2zvrGpme2 +FISaMupZ7iuWyhZJfs/cHQGD0+qsYcWbMCYRcg80hhYHleLCzqvDOVg7DAVZvKsSroy VFyKSvVXQAtV0oFnUbvxqRtb1DB1OUJYWo4YRSIxOU2mjRkf8RwPz7AVqGXheFXuindm thnNcyVUrhSyi0ShBaUOtT/TeSN3p4dO+8OVZnjF+qzLSVAWITJVz6xR8lbGm5wL2//3 YzFw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g25si7098838ejp.67.2020.12.19.19.46.12; Sat, 19 Dec 2020 19:46:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727286AbgLTDp5 (ORCPT + 99 others); Sat, 19 Dec 2020 22:45:57 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:10052 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726923AbgLTDp4 (ORCPT ); Sat, 19 Dec 2020 22:45:56 -0500 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4Cz7ks2h6JzM6xk; Sun, 20 Dec 2020 11:44:21 +0800 (CST) Received: from use12-sp2.huawei.com (10.67.189.174) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.498.0; Sun, 20 Dec 2020 11:45:07 +0800 From: Xiaoming Ni To: , , , , , , , , CC: , Subject: [PATCH v2 1/4] panic: Add new API in_panic_state() Date: Sun, 20 Dec 2020 11:45:02 +0800 Message-ID: <20201220034505.113118-2-nixiaoming@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201220034505.113118-1-nixiaoming@huawei.com> References: <20201220034505.113118-1-nixiaoming@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.189.174] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For some features (such as hang_task, ledtrig-activity, ledtrig-heartbeat) different processing logics need to be performed based on whether the current system is in panic state: 1: Register hook for panic_notifier_list. 2. Assign a value to the global variable in the hook function. 3. Determine whether the system is in panic state based on the global variable and perform different processing. Duplicate code snippets exist, and the timing judgment is relatively lag. Therefore, consider extracting the new API: bool in_panic_state(void). Signed-off-by: Xiaoming Ni --- include/linux/kernel.h | 1 + kernel/panic.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/include/linux/kernel.h b/include/linux/kernel.h index f7902d8c1048..c9a9078157b6 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -167,6 +167,7 @@ void __might_fault(const char *file, int line); static inline void might_fault(void) { } #endif +extern bool in_panic_state(void); extern struct atomic_notifier_head panic_notifier_list; extern long (*panic_blink)(int state); __printf(1, 2) diff --git a/kernel/panic.c b/kernel/panic.c index 332736a72a58..351627883a04 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -125,6 +125,12 @@ void __weak crash_smp_send_stop(void) atomic_t panic_cpu = ATOMIC_INIT(PANIC_CPU_INVALID); +bool in_panic_state(void) +{ + return (atomic_read(&panic_cpu) != PANIC_CPU_INVALID); +} +EXPORT_SYMBOL(in_panic_state); + /* * A variant of panic() called from NMI context. We return if we've already * panicked on this CPU. If another CPU already panicked, loop in -- 2.27.0