From patchwork Tue Aug 17 03:27:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerin Jacob Kollanukkaran X-Patchwork-Id: 96959 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A6F62A0548; Tue, 17 Aug 2021 05:30:03 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8DF9B4115D; Tue, 17 Aug 2021 05:30:03 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 08B714014E for ; Tue, 17 Aug 2021 05:30:01 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.1.2/8.16.0.43) with SMTP id 17H2lc0h006745; Mon, 16 Aug 2021 20:29:55 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=ZPwb3P4irC5JFR8lS+TqMid+yDeG5AdkBsAeVbdmSf4=; b=Q11MenoiO7zfC+72A7y9WFuUShzO6QjWSmLp+mMaKHyhQvgwg/tm/Rpv+/iI01NK1Cy/ RT69c2q+TEFGjv4CkFPvyGf9QCOLz52TJRKeVH5X7OSzOB8XoVsIpneHECnkLjhIoZgu UGjTnNRhQnXfmhZ/7jca3WBpdtQmsAD/NYG9wNw2BktjNE8bBzjeu1u0MQ6wdSt5cnIx HKJqD8IKTyhluSEWE60/tdujk/kPpTUKNenfEogfioxSwvKq4r7VcGYPzNS/7vTY514Q snXeYpGlpqKWu9hv55J873czLtb51pDAtrKcNIJIe2jTTayd0PPU22p0mi5zHT428pms Fw== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com with ESMTP id 3ag4n0r3t0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 16 Aug 2021 20:29:55 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 16 Aug 2021 20:29:54 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Mon, 16 Aug 2021 20:29:54 -0700 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id B7BB43F70A2; Mon, 16 Aug 2021 20:29:49 -0700 (PDT) From: To: , Bruce Richardson , "Ray Kinsella" CC: , , , , , , , , , , Jerin Jacob Date: Tue, 17 Aug 2021 08:57:18 +0530 Message-ID: <20210817032723.3997054-2-jerinj@marvell.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210817032723.3997054-1-jerinj@marvell.com> References: <20210730084938.2426128-2-jerinj@marvell.com> <20210817032723.3997054-1-jerinj@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: 7jVWJ-weDPWKQ7PZj3pkESJIn-R_4QJ5 X-Proofpoint-ORIG-GUID: 7jVWJ-weDPWKQ7PZj3pkESJIn-R_4QJ5 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.391,FMLib:17.0.607.475 definitions=2021-08-17_01,2021-08-16_02,2020-04-07_01 Subject: [dpdk-dev] [PATCH v2 1/6] eal: introduce oops handling API X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Jerin Jacob Introducing oops handling API with following specification and enable stub implementation for Linux and FreeBSD. On rte_eal_init() invocation, the EAL library installs the oops handler for the essential signals. The rte_oops_signals_enabled() API provides the list of signals the library installed by the EAL. The default EAL oops handler decodes the oops message using rte_oops_decode() and then calls the signal handler installed by the application before invoking the rte_eal_init(). This scheme will also enable the use of the default coredump handler(for gdb etc.) provided by OS if the application does not install any specific signal handler. The second case where the application installs the signal handler after the rte_eal_init() invocation, rte_oops_decode() provides the means of decoding the oops message in the application's fault handler. Signed-off-by: Jerin Jacob --- doc/api/doxy-api-index.md | 3 +- lib/eal/common/eal_private.h | 3 ++ lib/eal/freebsd/eal.c | 6 +++ lib/eal/include/meson.build | 1 + lib/eal/include/rte_oops.h | 100 +++++++++++++++++++++++++++++++++++ lib/eal/linux/eal.c | 6 +++ lib/eal/unix/eal_oops.c | 36 +++++++++++++ lib/eal/unix/meson.build | 1 + lib/eal/version.map | 4 ++ 9 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 lib/eal/include/rte_oops.h create mode 100644 lib/eal/unix/eal_oops.c diff --git a/doc/api/doxy-api-index.md b/doc/api/doxy-api-index.md index 1992107a03..0d0da35205 100644 --- a/doc/api/doxy-api-index.md +++ b/doc/api/doxy-api-index.md @@ -215,7 +215,8 @@ The public API headers are grouped by topics: [log] (@ref rte_log.h), [errno] (@ref rte_errno.h), [trace] (@ref rte_trace.h), - [trace_point] (@ref rte_trace_point.h) + [trace_point] (@ref rte_trace_point.h), + [oops] (@ref rte_oops.h) - **misc**: [EAL config] (@ref rte_eal.h), diff --git a/lib/eal/common/eal_private.h b/lib/eal/common/eal_private.h index 64cf4e81c8..c3a490d803 100644 --- a/lib/eal/common/eal_private.h +++ b/lib/eal/common/eal_private.h @@ -716,6 +716,9 @@ void __rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset); */ void __rte_thread_uninit(void); +int eal_oops_init(void); +void eal_oops_fini(void); + /** * asprintf(3) replacement for Windows. */ diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index 6cee5ae369..3c098708c6 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -692,6 +692,11 @@ rte_eal_init(int argc, char **argv) return -1; } + if (eal_oops_init()) { + rte_eal_init_alert("oops init failed."); + rte_errno = ENOENT; + } + thread_id = pthread_self(); eal_reset_internal_config(internal_conf); @@ -974,6 +979,7 @@ rte_eal_cleanup(void) rte_trace_save(); eal_trace_fini(); eal_cleanup_config(internal_conf); + eal_oops_fini(); return 0; } diff --git a/lib/eal/include/meson.build b/lib/eal/include/meson.build index 88a9eba12f..6c74bdb7b5 100644 --- a/lib/eal/include/meson.build +++ b/lib/eal/include/meson.build @@ -30,6 +30,7 @@ headers += files( 'rte_malloc.h', 'rte_memory.h', 'rte_memzone.h', + 'rte_oops.h', 'rte_pci_dev_feature_defs.h', 'rte_pci_dev_features.h', 'rte_per_lcore.h', diff --git a/lib/eal/include/rte_oops.h b/lib/eal/include/rte_oops.h new file mode 100644 index 0000000000..ff82c409ec --- /dev/null +++ b/lib/eal/include/rte_oops.h @@ -0,0 +1,100 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2020 Marvell. + */ + +#ifndef _RTE_OOPS_H_ +#define _RTE_OOPS_H_ + +#include +#include +#include + +/** + * @file + * + * RTE oops API + * + * This file provides the oops handling APIs to RTE applications. + * + * On rte_eal_init() invocation, the EAL library installs the oops handler for + * the essential signals. The rte_oops_signals_enabled() API provides the list + * of signals the library installed by the EAL. + * + * The default EAL oops handler decodes the oops message using rte_oops_decode() + * and then calls the signal handler installed by the application before + * invoking the rte_eal_init(). This scheme will also enable the use of + * the default coredump handler(for gdb etc.) provided by OS if the application + * does not install any specific signal handler. + * + * The second case where the application installs the signal handler after + * the rte_eal_init() invocation, rte_oops_decode() provides the means of + * decoding the oops message in the application's fault handler. + * + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Maximum number of oops signals enabled in EAL. + * @see rte_oops_signals_enabled() + */ +#define RTE_OOPS_SIGNALS_MAX 32 + +/** + * Get the list of enabled oops signals installed by EAL. + * + * @param [out] signals + * A pointer to store the enabled signals. + * Value NULL is allowed. if not NULL, then the size of this array must be + * at least RTE_OOPS_SIGNALS_MAX. + * + * @return + * Number of enabled oops signals. + */ +__rte_experimental +int rte_oops_signals_enabled(int *signals); + +#if defined(RTE_EXEC_ENV_LINUX) || defined(RTE_EXEC_ENV_FREEBSD) +#include +#include + +/** + * Decode an oops + * + * This prototype is same as sa_sigaction defined in signal.h. + * Application must register signal handler using sigaction() with + * sa_flag as SA_SIGINFO flag to get this information from unix OS. + * + * @param sig + * Signal number + * @param info + * Signal info provided by sa_sigaction. Value NULL is allowed. + * @param uc + * ucontext_t provided when signal installed with SA_SIGINFO flag. + * Value NULL is allowed. + * + */ +__rte_experimental +void rte_oops_decode(int sig, siginfo_t *info, ucontext_t *uc); +#else + +/** + * Decode an oops + * + * @param sig + * Signal number + */ +__rte_experimental +void rte_oops_decode(int sig); + +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_OOPS_H_ */ diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index 3577eaeaa4..3438a96b75 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -991,6 +991,11 @@ rte_eal_init(int argc, char **argv) return -1; } + if (eal_oops_init()) { + rte_eal_init_alert("oops init failed."); + rte_errno = ENOENT; + } + p = strrchr(argv[0], '/'); strlcpy(logid, p ? p + 1 : argv[0], sizeof(logid)); thread_id = pthread_self(); @@ -1371,6 +1376,7 @@ rte_eal_cleanup(void) rte_trace_save(); eal_trace_fini(); eal_cleanup_config(internal_conf); + eal_oops_fini(); return 0; } diff --git a/lib/eal/unix/eal_oops.c b/lib/eal/unix/eal_oops.c new file mode 100644 index 0000000000..53b580f733 --- /dev/null +++ b/lib/eal/unix/eal_oops.c @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2021 Marvell. + */ + + +#include + +#include "eal_private.h" + +void +rte_oops_decode(int sig, siginfo_t *info, ucontext_t *uc) +{ + RTE_SET_USED(sig); + RTE_SET_USED(info); + RTE_SET_USED(uc); + +} + +int +rte_oops_signals_enabled(int *signals) +{ + RTE_SET_USED(signals); + + return 0; +} + +int +eal_oops_init(void) +{ + return 0; +} + +void +eal_oops_fini(void) +{ +} diff --git a/lib/eal/unix/meson.build b/lib/eal/unix/meson.build index e3ecd3e956..cdd3320669 100644 --- a/lib/eal/unix/meson.build +++ b/lib/eal/unix/meson.build @@ -6,5 +6,6 @@ sources += files( 'eal_unix_memory.c', 'eal_unix_timer.c', 'eal_firmware.c', + 'eal_oops.c', 'rte_thread.c', ) diff --git a/lib/eal/version.map b/lib/eal/version.map index 887012d02a..f2841d09fd 100644 --- a/lib/eal/version.map +++ b/lib/eal/version.map @@ -426,6 +426,10 @@ EXPERIMENTAL { # added in 21.08 rte_power_monitor_multi; # WINDOWS_NO_EXPORT + + # added in 21.11 + rte_oops_signals_enabled; # WINDOWS_NO_EXPORT + rte_oops_decode; # WINDOWS_NO_EXPORT }; INTERNAL { From patchwork Tue Aug 17 03:27:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerin Jacob Kollanukkaran X-Patchwork-Id: 96960 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7547EA0548; Tue, 17 Aug 2021 05:30:08 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A95D54116F; Tue, 17 Aug 2021 05:30:06 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 15C214116D for ; Tue, 17 Aug 2021 05:30:04 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.1.2/8.16.0.43) with SMTP id 17H2lc0j006745; Mon, 16 Aug 2021 20:30:01 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=5RpELlI32r1Pi0dH3d3A14asnRfqhUepn/PBA9xuMfA=; b=LPdAymZlUmSdP2u79TU7uYBWI6KCthR8zIo8hihP+vl1XStucM9TQ25S81s/wY3fUiZh NFnU3V6CAU4Lidz1tywZLgE/amwRv8HHS4/rigGxZOEhZMHOpoQ9kFg6MFLfrqyscNsK rorTVRqbZI42OaTyfUVOyAwpvOkvwoozHS+EVRhxyAT2AsANwMmsMXkYE58AVvI1Ycl8 oJPqKkq9BbkYqglMQdmS4N1gOv7KU9HwMbvuiygQg6n3MzlV2ljdu1lU3X+r/HUbEov0 KbGEGTWIOeEWaVwhgaY5rJeunctXddcZR1NQsaIkbo25FsT6DmyYcjM8qROX+L2qX63v AA== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com with ESMTP id 3ag4n0r3tj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 16 Aug 2021 20:30:01 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 16 Aug 2021 20:29:59 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Mon, 16 Aug 2021 20:29:59 -0700 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id B19323F707C; Mon, 16 Aug 2021 20:29:55 -0700 (PDT) From: To: CC: , , , , , , , , , , , Jerin Jacob Date: Tue, 17 Aug 2021 08:57:19 +0530 Message-ID: <20210817032723.3997054-3-jerinj@marvell.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210817032723.3997054-1-jerinj@marvell.com> References: <20210730084938.2426128-2-jerinj@marvell.com> <20210817032723.3997054-1-jerinj@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: DU0Gl0EwgOeE9UgfwOgUXbXRw9glZNkb X-Proofpoint-ORIG-GUID: DU0Gl0EwgOeE9UgfwOgUXbXRw9glZNkb X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.391,FMLib:17.0.607.475 definitions=2021-08-17_01,2021-08-16_02,2020-04-07_01 Subject: [dpdk-dev] [PATCH v2 2/6] eal: oops handling API implementation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Jerin Jacob Implement the base oops handling APIs. Signed-off-by: Jerin Jacob --- lib/eal/unix/eal_oops.c | 176 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 169 insertions(+), 7 deletions(-) diff --git a/lib/eal/unix/eal_oops.c b/lib/eal/unix/eal_oops.c index 53b580f733..7b12cfd5f5 100644 --- a/lib/eal/unix/eal_oops.c +++ b/lib/eal/unix/eal_oops.c @@ -2,35 +2,197 @@ * Copyright(C) 2021 Marvell. */ +#include +#include +#include +#include +#include +#include +#include #include #include "eal_private.h" -void -rte_oops_decode(int sig, siginfo_t *info, ucontext_t *uc) +#define oops_print(...) rte_log(RTE_LOG_ERR, RTE_LOGTYPE_EAL, __VA_ARGS__) + +static int oops_signals[] = {SIGSEGV, SIGBUS, SIGILL, SIGABRT, SIGFPE, SIGSYS}; + +struct oops_signal { + int sig; + bool enabled; + struct sigaction sa; +}; + +static struct oops_signal signals_db[RTE_DIM(oops_signals)]; + +static void +back_trace_dump(ucontext_t *context) +{ + RTE_SET_USED(context); + + rte_dump_stack(); +} +static void +siginfo_dump(int sig, siginfo_t *info) +{ + oops_print("PID: %" PRIdMAX "\n", (intmax_t)getpid()); + + if (info == NULL) + return; + if (sig != info->si_signo) + oops_print("Invalid signal info\n"); + + oops_print("Signal number: %d\n", info->si_signo); + oops_print("Fault address: %p\n", info->si_addr); +} + +static void +mem32_dump(void *ptr) +{ + uint32_t *p = ptr; + int i; + + for (i = 0; i < 16; i++) + oops_print("%p: 0x%x\n", p + i, rte_be_to_cpu_32(p[i])); +} + +static void +stack_dump_header(void) +{ + oops_print("Stack dump:\n"); + oops_print("----------\n"); +} + +static void +code_dump_header(void) +{ + oops_print("Code dump:\n"); + oops_print("----------\n"); +} + +static void +stack_code_dump(void *stack, void *code) +{ + if (stack == NULL || code == NULL) + return; + + oops_print("\n"); + stack_dump_header(); + mem32_dump(stack); + oops_print("\n"); + + code_dump_header(); + mem32_dump(code); + oops_print("\n"); +} +static void +archinfo_dump(ucontext_t *uc) { - RTE_SET_USED(sig); - RTE_SET_USED(info); RTE_SET_USED(uc); + stack_code_dump(NULL, NULL); +} + +static void +default_signal_handler_invoke(int sig) +{ + unsigned int idx; + + for (idx = 0; idx < RTE_DIM(oops_signals); idx++) { + /* Skip disabled signals */ + if (signals_db[idx].sig != sig) + continue; + if (!signals_db[idx].enabled) + continue; + /* Replace with stored handler */ + sigaction(sig, &signals_db[idx].sa, NULL); + kill(getpid(), sig); + } +} + +void +rte_oops_decode(int sig, siginfo_t *info, ucontext_t *uc) +{ + oops_print("Signal info:\n"); + oops_print("------------\n"); + siginfo_dump(sig, info); + oops_print("\n"); + + oops_print("Backtrace:\n"); + oops_print("----------\n"); + back_trace_dump(uc); + oops_print("\n"); + + oops_print("Arch info:\n"); + oops_print("----------\n"); + if (uc) + archinfo_dump(uc); +} + +static void +eal_oops_handler(int sig, siginfo_t *info, void *ctx) +{ + ucontext_t *uc = ctx; + + rte_oops_decode(sig, info, uc); + default_signal_handler_invoke(sig); } int rte_oops_signals_enabled(int *signals) { - RTE_SET_USED(signals); + int count = 0, sig[RTE_OOPS_SIGNALS_MAX]; + unsigned int idx = 0; - return 0; + for (idx = 0; idx < RTE_DIM(oops_signals); idx++) { + if (signals_db[idx].enabled) { + sig[count] = signals_db[idx].sig; + count++; + } + } + if (signals) + memcpy(signals, sig, sizeof(*signals) * count); + + return count; } int eal_oops_init(void) { - return 0; + unsigned int idx, rc = 0; + struct sigaction sa; + + RTE_BUILD_BUG_ON(RTE_DIM(oops_signals) > RTE_OOPS_SIGNALS_MAX); + + sigemptyset(&sa.sa_mask); + sa.sa_sigaction = &eal_oops_handler; + sa.sa_flags = SA_RESTART | SA_SIGINFO | SA_ONSTACK; + + for (idx = 0; idx < RTE_DIM(oops_signals); idx++) { + signals_db[idx].sig = oops_signals[idx]; + /* Get exiting sigaction */ + rc = sigaction(signals_db[idx].sig, NULL, &signals_db[idx].sa); + if (rc) + continue; + /* Replace with oops handler */ + rc = sigaction(signals_db[idx].sig, &sa, NULL); + if (rc) + continue; + signals_db[idx].enabled = true; + } + return rc; } void eal_oops_fini(void) { + unsigned int idx; + + for (idx = 0; idx < RTE_DIM(oops_signals); idx++) { + if (!signals_db[idx].enabled) + continue; + /* Replace with stored handler */ + sigaction(signals_db[idx].sig, &signals_db[idx].sa, NULL); + } } From patchwork Tue Aug 17 03:27:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerin Jacob Kollanukkaran X-Patchwork-Id: 96961 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id E1E1AA0548; Tue, 17 Aug 2021 05:30:13 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CECAF41179; Tue, 17 Aug 2021 05:30:12 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id A224741173 for ; Tue, 17 Aug 2021 05:30:11 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.1.2/8.16.0.43) with SMTP id 17H2m146006952; Mon, 16 Aug 2021 20:30:08 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=EAgptWyKHT4v6Ze/bE48WNBxLpUk69lCXPDlMiIKirQ=; b=j8NLK7+XHA3OSbzfHR9rxLNeaNa5vwnbNTlA+XlIn6Wn6H4zphqeGpfZElfTdafZtrTx lyvIlneRQtsn8RTJ2n8wgoQyRdJDZo0Gvz24AkfxAlqYV2k6nQ33hS7vuBC8LrCK0FYT 1JJxqBmy1Pz5U7F/N13mgpMEWcMautIGNN2OyFRaQbS/s2Dr/DQhzpNTOYauBRVwYseH 6pT2lrlZAiZPbxAqismJfufzWgKH/HSxwEQKEwx/xeqpYCLkn8fKKtSXKs5J5rKHPYeu pp8e80OuUrDl4bFZxnGpsdrxCGm65z6tyqWYQ1/4ieqQ7N0ez4h0DNCt6W5C0nquZef+ wg== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com with ESMTP id 3ag4n0r3ua-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 16 Aug 2021 20:30:08 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 16 Aug 2021 20:30:07 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Mon, 16 Aug 2021 20:30:06 -0700 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id 600873F70C1; Mon, 16 Aug 2021 20:30:01 -0700 (PDT) From: To: , Aaron Conole , Michael Santana , Bruce Richardson CC: , , , , , , , , , , Jerin Jacob Date: Tue, 17 Aug 2021 08:57:20 +0530 Message-ID: <20210817032723.3997054-4-jerinj@marvell.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210817032723.3997054-1-jerinj@marvell.com> References: <20210730084938.2426128-2-jerinj@marvell.com> <20210817032723.3997054-1-jerinj@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: 5-ldC3d7udj6QKMny1Bjtj-HxQFS63WE X-Proofpoint-ORIG-GUID: 5-ldC3d7udj6QKMny1Bjtj-HxQFS63WE X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.391,FMLib:17.0.607.475 definitions=2021-08-17_01,2021-08-16_02,2020-04-07_01 Subject: [dpdk-dev] [PATCH v2 3/6] eal: support libunwind based backtrace X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Jerin Jacob adding optional libwind library dependency to DPDK for enhanced backtrace based on ucontext. Signed-off-by: Jerin Jacob --- .github/workflows/build.yml | 2 +- .travis.yml | 2 +- config/meson.build | 8 +++++++ lib/eal/unix/eal_oops.c | 47 +++++++++++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7dac20ddeb..caaca207a6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -93,7 +93,7 @@ jobs: run: sudo apt install -y ccache libnuma-dev python3-setuptools python3-wheel python3-pip python3-pyelftools ninja-build libbsd-dev libpcap-dev libibverbs-dev libcrypto++-dev libfdt-dev libjansson-dev - libarchive-dev + libarchive-dev libunwind-dev - name: Install libabigail build dependencies if no cache is available if: env.ABI_CHECKS == 'true' && steps.libabigail-cache.outputs.cache-hit != 'true' run: sudo apt install -y autoconf automake libtool pkg-config libxml2-dev diff --git a/.travis.yml b/.travis.yml index 23067d9e3c..e72b156014 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ addons: packages: &required_packages - [libnuma-dev, python3-setuptools, python3-wheel, python3-pip, python3-pyelftools, ninja-build] - [libbsd-dev, libpcap-dev, libibverbs-dev, libcrypto++-dev, libfdt-dev, libjansson-dev] - - [libarchive-dev] + - [libarchive-dev, libunwind-dev] _aarch64_packages: &aarch64_packages - *required_packages diff --git a/config/meson.build b/config/meson.build index e80421003b..26a85dab6b 100644 --- a/config/meson.build +++ b/config/meson.build @@ -236,6 +236,14 @@ if cc.get_id() == 'clang' and dpdk_conf.get('RTE_ARCH_64') == false dpdk_extra_ldflags += '-latomic' endif +# check for libunwind +unwind_dep = dependency('libunwind', required: false, method: 'pkg-config') +if unwind_dep.found() and cc.has_header('libunwind.h', dependencies: unwind_dep) + dpdk_conf.set('RTE_USE_LIBUNWIND', 1) + add_project_link_arguments('-lunwind', language: 'c') + dpdk_extra_ldflags += '-lunwind' +endif + # add -include rte_config to cflags add_project_arguments('-include', 'rte_config.h', language: 'c') diff --git a/lib/eal/unix/eal_oops.c b/lib/eal/unix/eal_oops.c index 7b12cfd5f5..a7f00ecd4e 100644 --- a/lib/eal/unix/eal_oops.c +++ b/lib/eal/unix/eal_oops.c @@ -26,6 +26,50 @@ struct oops_signal { static struct oops_signal signals_db[RTE_DIM(oops_signals)]; +#if defined(RTE_USE_LIBUNWIND) + +#define BACKTRACE_DEPTH 256 +#define UNW_LOCAL_ONLY +#include + +static void +back_trace_dump(ucontext_t *context) +{ + unw_cursor_t cursor; + unw_word_t ip, off; + int rc, level = 0; + char name[256]; + + if (context == NULL) { + rte_dump_stack(); + return; + } + + rc = unw_init_local(&cursor, (unw_context_t *)context); + if (rc < 0) + goto fail; + + for (;;) { + rc = unw_get_reg(&cursor, UNW_REG_IP, &ip); + if (rc < 0) + goto fail; + rc = unw_get_proc_name(&cursor, name, sizeof(name), &off); + if (rc == 0) + oops_print("[%16p]: %s()+0x%" PRIx64 "\n", (void *)ip, + name, (uint64_t)off); + else + oops_print("[%16p]: \n", (void *)ip); + rc = unw_step(&cursor); + if (rc <= 0 || ++level >= BACKTRACE_DEPTH) + break; + } + return; +fail: + oops_print("libunwind call failed %s\n", unw_strerror(rc)); +} + +#else + static void back_trace_dump(ucontext_t *context) { @@ -33,6 +77,9 @@ back_trace_dump(ucontext_t *context) rte_dump_stack(); } + +#endif + static void siginfo_dump(int sig, siginfo_t *info) { From patchwork Tue Aug 17 03:27:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerin Jacob Kollanukkaran X-Patchwork-Id: 96962 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 67690A0548; Tue, 17 Aug 2021 05:30:21 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6170C4116A; Tue, 17 Aug 2021 05:30:18 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 514DA4115A for ; Tue, 17 Aug 2021 05:30:16 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.1.2/8.16.0.43) with SMTP id 17H2ldY3006756; Mon, 16 Aug 2021 20:30:13 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=jTGUqPpmoGwZZ0VMh3tX/lq5ypWSZczv7Dz2uwoXQTA=; b=RUvrmso+ebvVo8Al71GRDfqmwlfo8Y/6d9934MeyMnoTraqh/BywUnSzQWW8MwL2S9r5 TfkZwDIgvt1/QEz92XThC9Kg0XdUkWaH1A18Bf0gZiwO2Gly6dc0x4aEkCIwTiWF1Yuy UfrZFlLLppcKUJcfG672DcZYlOnJv4IX8IzzXa1t8G/tvNDKUJMDoMS6VwbzrPUPOVTc j/HqH8CzFYEAJN7sMKiUN6No0KDPEat4aAI6CaK4BOsCH4iP5TKUeUxN7s+GA/6IJgeZ sO+2BFBUHCr041pzffuAsOnUHFH5gTQow2BOuiO9arlNv9Wbm55zar7xuMfbVdubwbsK 0Q== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com with ESMTP id 3ag4n0r3ur-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 16 Aug 2021 20:30:13 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 16 Aug 2021 20:30:11 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Mon, 16 Aug 2021 20:30:11 -0700 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id 996613F70A4; Mon, 16 Aug 2021 20:30:07 -0700 (PDT) From: To: CC: , , , , , , , , , , , Jerin Jacob Date: Tue, 17 Aug 2021 08:57:21 +0530 Message-ID: <20210817032723.3997054-5-jerinj@marvell.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210817032723.3997054-1-jerinj@marvell.com> References: <20210730084938.2426128-2-jerinj@marvell.com> <20210817032723.3997054-1-jerinj@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: sdS02fFVduN5t-kt42A87AraUO6cjdhj X-Proofpoint-ORIG-GUID: sdS02fFVduN5t-kt42A87AraUO6cjdhj X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.391,FMLib:17.0.607.475 definitions=2021-08-17_01,2021-08-16_02,2020-04-07_01 Subject: [dpdk-dev] [PATCH v2 4/6] eal/x86: support register dump for oops X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Jerin Jacob Dump the x86 arch state register in oops handling routine. Signed-off-by: Jerin Jacob --- lib/eal/unix/eal_oops.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/lib/eal/unix/eal_oops.c b/lib/eal/unix/eal_oops.c index a7f00ecd4e..a0f9526d96 100644 --- a/lib/eal/unix/eal_oops.c +++ b/lib/eal/unix/eal_oops.c @@ -133,6 +133,38 @@ stack_code_dump(void *stack, void *code) mem32_dump(code); oops_print("\n"); } + +#if defined(RTE_ARCH_X86_64) && defined(RTE_EXEC_ENV_LINUX) +static void +archinfo_dump(ucontext_t *uc) +{ + + mcontext_t *mc = &uc->uc_mcontext; + + oops_print("R8 : 0x%.16llx ", mc->gregs[REG_R8]); + oops_print("R9 : 0x%.16llx\n", mc->gregs[REG_R9]); + oops_print("R10: 0x%.16llx ", mc->gregs[REG_R10]); + oops_print("R11: 0x%.16llx\n", mc->gregs[REG_R11]); + oops_print("R12: 0x%.16llx ", mc->gregs[REG_R12]); + oops_print("R13: 0x%.16llx\n", mc->gregs[REG_R13]); + oops_print("R14: 0x%.16llx ", mc->gregs[REG_R14]); + oops_print("R15: 0x%.16llx\n", mc->gregs[REG_R15]); + oops_print("RAX: 0x%.16llx ", mc->gregs[REG_RAX]); + oops_print("RBX: 0x%.16llx\n", mc->gregs[REG_RBX]); + oops_print("RCX: 0x%.16llx ", mc->gregs[REG_RCX]); + oops_print("RDX: 0x%.16llx\n", mc->gregs[REG_RDX]); + oops_print("RBP: 0x%.16llx ", mc->gregs[REG_RBP]); + oops_print("RSP: 0x%.16llx\n", mc->gregs[REG_RSP]); + oops_print("RSI: 0x%.16llx ", mc->gregs[REG_RSI]); + oops_print("RDI: 0x%.16llx\n", mc->gregs[REG_RDI]); + oops_print("RIP: 0x%.16llx ", mc->gregs[REG_RIP]); + oops_print("EFL: 0x%.16llx\n", mc->gregs[REG_EFL]); + + stack_code_dump((void *)mc->gregs[REG_RSP], (void *)mc->gregs[REG_RIP]); +} + +#else + static void archinfo_dump(ucontext_t *uc) { @@ -141,6 +173,8 @@ archinfo_dump(ucontext_t *uc) stack_code_dump(NULL, NULL); } +#endif + static void default_signal_handler_invoke(int sig) { From patchwork Tue Aug 17 03:27:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerin Jacob Kollanukkaran X-Patchwork-Id: 96963 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0EDB2A0548; Tue, 17 Aug 2021 05:30:27 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8CB2941186; Tue, 17 Aug 2021 05:30:24 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 23F9041186 for ; Tue, 17 Aug 2021 05:30:21 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.1.2/8.16.0.43) with SMTP id 17H2m149006952; Mon, 16 Aug 2021 20:30:18 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=rsWSsBOdIe5P2rXJ6ZZ5OR0IaScgbXz/Gch7/JTZZno=; b=ZS/Q3cvPg7tg9rDHXQcaef1grPbpmn+Fi5kBeHwZutKJlaco8q734Ky0F/hoqfvFgUNf nujyk/cJ2taW3Brp83+m3d2Q8cOPtqFHEPkJ/ikAuZqC8idocHoxpIS3Az8i5Kri67xT 2auv/o/prEqMKfdEm796Jthr0jp1deDVY9ujUoDD1g+gA+g9VzhW7O3f04IyquC1jDdh +6vSff5BMkoU6zm8pr6ENbH0RdLzCx05iRiROLNb7ol+5IsYcGWRDDW0snHvdmsxxk8c j50YLvHWJmcfyLKnHYpA0FQTayfFB9Cd5ofhrOES1PWM82G2wRcMDRcShYXO1hGHS/ba Ew== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com with ESMTP id 3ag4n0r3v7-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 16 Aug 2021 20:30:18 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 16 Aug 2021 20:30:17 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Mon, 16 Aug 2021 20:30:17 -0700 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id 55CA53F70AB; Mon, 16 Aug 2021 20:30:13 -0700 (PDT) From: To: CC: , , , , , , , , , , , Jerin Jacob Date: Tue, 17 Aug 2021 08:57:22 +0530 Message-ID: <20210817032723.3997054-6-jerinj@marvell.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210817032723.3997054-1-jerinj@marvell.com> References: <20210730084938.2426128-2-jerinj@marvell.com> <20210817032723.3997054-1-jerinj@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: ioye7l-z1tYs_LFDhflvmMX6nxAMKkow X-Proofpoint-ORIG-GUID: ioye7l-z1tYs_LFDhflvmMX6nxAMKkow X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.391,FMLib:17.0.607.475 definitions=2021-08-17_01,2021-08-16_02,2020-04-07_01 Subject: [dpdk-dev] [PATCH v2 5/6] eal/arm64: support register dump for oops X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Jerin Jacob Dump the arm64 arch state register in oops handling routine. Signed-off-by: Jerin Jacob --- lib/eal/unix/eal_oops.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/eal/unix/eal_oops.c b/lib/eal/unix/eal_oops.c index a0f9526d96..9c783f936a 100644 --- a/lib/eal/unix/eal_oops.c +++ b/lib/eal/unix/eal_oops.c @@ -163,6 +163,25 @@ archinfo_dump(ucontext_t *uc) stack_code_dump((void *)mc->gregs[REG_RSP], (void *)mc->gregs[REG_RIP]); } +#elif defined(RTE_ARCH_ARM64) && defined(RTE_EXEC_ENV_LINUX) + +static void +archinfo_dump(ucontext_t *uc) +{ + mcontext_t *mc = &uc->uc_mcontext; + int i; + + oops_print("PC : 0x%.16llx ", mc->pc); + oops_print("SP : 0x%.16llx\n", mc->sp); + for (i = 0; i < 31; i++) + oops_print("X%.2d: 0x%.16llx%s", i, mc->regs[i], + i & 0x1 ? "\n" : " "); + + oops_print("PSTATE: 0x%.16llx\n", mc->pstate); + + stack_code_dump((void *)mc->sp, (void *)mc->pc); +} + #else static void From patchwork Tue Aug 17 03:27:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerin Jacob Kollanukkaran X-Patchwork-Id: 96964 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 67EE5A0548; Tue, 17 Aug 2021 05:30:32 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A035141183; Tue, 17 Aug 2021 05:30:30 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 8448441183 for ; Tue, 17 Aug 2021 05:30:28 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.1.2/8.16.0.43) with SMTP id 17H2ldqW006753; Mon, 16 Aug 2021 20:30:24 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=+0R8VA+/m87ziXmnSG3F+7vKnk60Jn58q3DUijI7iHM=; b=LHYb/0vf8Lvhx0bMFTiDSAkEnOMpMT71V1xLly0idl4PV7Pg8i8FYPTO8mBTxnvVy2/f joNw06OESFEqJaHuJKKNWcRmLDGWIA7Hb2OHFrJij+VHl8pGhnduuOboc1tsL9DmotCw P25VSxSSvsChzGc5HdLvRQoqFVo+/znJ2PlzMPuoF7+n+M/G7Nrs5BW4vfOzWLwPxtEp VubP4KC3l5FSET/HXfRutHM99BXMzgBbQCcrUta7UVQy8BZ+SVBN/DGzEIqpq6tstbAZ 8LSwXUk1F2nBv+OrESIjKJhj+T01LlZJH7NamtCjjObsgNtYTfLbv2wu1a0QVDKH8nHs nw== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com with ESMTP id 3ag4n0r3vw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 16 Aug 2021 20:30:24 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 16 Aug 2021 20:30:23 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Mon, 16 Aug 2021 20:30:23 -0700 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id 1E2D03F70AC; Mon, 16 Aug 2021 20:30:18 -0700 (PDT) From: To: CC: , , , , , , , , , , , Jerin Jacob Date: Tue, 17 Aug 2021 08:57:23 +0530 Message-ID: <20210817032723.3997054-7-jerinj@marvell.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210817032723.3997054-1-jerinj@marvell.com> References: <20210730084938.2426128-2-jerinj@marvell.com> <20210817032723.3997054-1-jerinj@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: buJzccEWNr1E85oC_smlpSw4ibvdB6Ne X-Proofpoint-ORIG-GUID: buJzccEWNr1E85oC_smlpSw4ibvdB6Ne X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.391,FMLib:17.0.607.475 definitions=2021-08-17_01,2021-08-16_02,2020-04-07_01 Subject: [dpdk-dev] [PATCH v2 6/6] test/oops: support unit test case for oops handling APIs X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Jerin Jacob Added unit test cases for all the oops handling APIs. Signed-off-by: Jerin Jacob --- app/test/meson.build | 2 + app/test/test_oops.c | 121 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 app/test/test_oops.c diff --git a/app/test/meson.build b/app/test/meson.build index a7611686ad..1e471ab351 100644 --- a/app/test/meson.build +++ b/app/test/meson.build @@ -97,6 +97,7 @@ test_sources = files( 'test_metrics.c', 'test_mcslock.c', 'test_mp_secondary.c', + 'test_oops.c', 'test_per_lcore.c', 'test_pflock.c', 'test_pmd_perf.c', @@ -236,6 +237,7 @@ fast_tests = [ ['memzone_autotest', false], ['meter_autotest', true], ['multiprocess_autotest', false], + ['oops_autotest', true], ['per_lcore_autotest', true], ['pflock_autotest', true], ['prefetch_autotest', true], diff --git a/app/test/test_oops.c b/app/test/test_oops.c new file mode 100644 index 0000000000..60a7f259c7 --- /dev/null +++ b/app/test/test_oops.c @@ -0,0 +1,121 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2021 Marvell + */ + +#include +#include + +#include +#include + +#include "test.h" + +static jmp_buf pc; +static bool detected_segfault; + +static void +segv_handler(int sig, siginfo_t *info, void *ctx) +{ + detected_segfault = true; + rte_oops_decode(sig, info, (ucontext_t *)ctx); + longjmp(pc, 1); +} + +/* OS specific way install the signal segfault handler*/ +static int +segv_handler_install(void) +{ + struct sigaction sa; + + sigemptyset(&sa.sa_mask); + sa.sa_sigaction = &segv_handler; + sa.sa_flags = SA_SIGINFO; + + return sigaction(SIGSEGV, &sa, NULL); +} + +static int +test_oops_generate(void) +{ + int rc; + + rc = segv_handler_install(); + TEST_ASSERT_EQUAL(rc, 0, "rc=%d\n", rc); + + detected_segfault = false; + rc = setjmp(pc); /* Save the execution state */ + if (rc == 0) { + /* Generate a segfault */ + *(volatile int *)0x05 = 0; + } else { /* logjump from segv_handler */ + if (detected_segfault) + return TEST_SUCCESS; + + } + return TEST_FAILED; +} + +static int +test_signal_handler_installed(int count, int *signals) +{ + int i, rc, verified = 0; + struct sigaction sa; + + for (i = 0; i < count; i++) { + rc = sigaction(signals[i], NULL, &sa); + if (rc) { + printf("Failed to get sigaction for %d", signals[i]); + continue; + } + if (sa.sa_handler != SIG_DFL) + verified++; + } + TEST_ASSERT_EQUAL(count, verified, "count=%d verified=%d\n", count, + verified); + return TEST_SUCCESS; +} + +static int +test_oops_signals_enabled(void) +{ + int *signals = NULL; + int i, rc; + + rc = rte_oops_signals_enabled(signals); + TEST_ASSERT_NOT_EQUAL(rc, 0, "rc=%d\n", rc); + + signals = malloc(sizeof(int) * rc); + rc = rte_oops_signals_enabled(signals); + TEST_ASSERT_NOT_EQUAL(rc, 0, "rc=%d\n", rc); + free(signals); + + signals = malloc(sizeof(int) * RTE_OOPS_SIGNALS_MAX); + rc = rte_oops_signals_enabled(signals); + TEST_ASSERT_NOT_EQUAL(rc, 0, "rc=%d\n", rc); + + for (i = 0; i < rc; i++) + TEST_ASSERT_NOT_EQUAL(signals[i], 0, "idx=%d val=%d\n", i, + signals[i]); + + rc = test_signal_handler_installed(rc, signals); + free(signals); + + return rc; +} + +static struct unit_test_suite oops_tests = { + .suite_name = "oops autotest", + .setup = NULL, + .teardown = NULL, + .unit_test_cases = { + TEST_CASE(test_oops_signals_enabled), + TEST_CASE(test_oops_generate), + TEST_CASES_END()}}; + +static int +test_oops(void) +{ + return unit_test_suite_runner(&oops_tests); +} + +REGISTER_TEST_COMMAND(oops_autotest, test_oops);