From patchwork Mon Sep 6 04:17:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jerin Jacob Kollanukkaran X-Patchwork-Id: 98023 X-Patchwork-Delegate: david.marchand@redhat.com 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 F0BB7A0C4D; Mon, 6 Sep 2021 06:19:49 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DCFC5410EF; Mon, 6 Sep 2021 06:19:49 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 3BA0F410ED for ; Mon, 6 Sep 2021 06:19:48 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 185Mv8jI015512; Sun, 5 Sep 2021 21:19:43 -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-type : content-transfer-encoding; s=pfpt0220; bh=CD5IQ6CMfZCCMBBi25a8kCJyYCCljBZZQ8OjQ9VDPD8=; b=JC3gngtfznbsyorGtNxxCHGOQfBy0PaIOmGyK59ipsB4E3kNGHnlp0bVLAIDbqK2zPjQ N1A8UJMEYFtZGEIaJrCN50f3EXi/XY9/StAwSqguU4iC385qVGO7N5Qd8gvMA+JDnuZM fbpSeOXNzQkBDehrmxJoD7C/NdP4LsBlj0U6i8GIvz6YkLLVFLpRXqkSv7K3F3b69iwN 9wacxyK9PSGmmy3kgZI9B+Cz4OM3VBm041mptbfxn7VuUL+E+PgTm3E1O3Hw/umEj/ch J4k9tepZZhWCQ7P05wag+AKmrSoST8Qk4XP98A+x2+vM8tyJnDbl0zLo/VeLN1K0uCWC 1w== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com with ESMTP id 3aw2sp13yf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sun, 05 Sep 2021 21:19:43 -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; Sun, 5 Sep 2021 21:19:40 -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; Sun, 5 Sep 2021 21:19:40 -0700 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id 5222F3F703F; Sun, 5 Sep 2021 21:19:37 -0700 (PDT) From: To: , Bruce Richardson , "Ray Kinsella" CC: , , , , , , , , , , Jerin Jacob Date: Mon, 6 Sep 2021 09:47:27 +0530 Message-ID: <20210906041732.1019743-2-jerinj@marvell.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210906041732.1019743-1-jerinj@marvell.com> References: <20210817032723.3997054-1-jerinj@marvell.com> <20210906041732.1019743-1-jerinj@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: 9P9jMhq_oJ5VuJegKD1mGzMTP3gJG_jA X-Proofpoint-ORIG-GUID: 9P9jMhq_oJ5VuJegKD1mGzMTP3gJG_jA 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-09-06_01,2021-09-03_01,2020-04-07_01 Subject: [dpdk-dev] [PATCH v3 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 and if –no-oops not provided in the EAL command line argument, then 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 +- doc/guides/linux_gsg/eal_args.include.rst | 4 + doc/guides/rel_notes/release_21_11.rst | 10 +++ lib/eal/common/eal_common_options.c | 5 ++ lib/eal/common/eal_internal_cfg.h | 1 + lib/eal/common/eal_options.h | 2 + lib/eal/common/eal_private.h | 3 + lib/eal/freebsd/eal.c | 8 ++ lib/eal/include/meson.build | 1 + lib/eal/include/rte_oops.h | 101 ++++++++++++++++++++++ lib/eal/linux/eal.c | 7 ++ lib/eal/unix/eal_oops.c | 36 ++++++++ lib/eal/unix/meson.build | 1 + lib/eal/version.map | 4 + 14 files changed, 185 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/doc/guides/linux_gsg/eal_args.include.rst b/doc/guides/linux_gsg/eal_args.include.rst index 96baa4a9b0..8db320bc07 100644 --- a/doc/guides/linux_gsg/eal_args.include.rst +++ b/doc/guides/linux_gsg/eal_args.include.rst @@ -226,3 +226,7 @@ Other options To disable use of max SIMD bitwidth limit:: --force-max-simd-bitwidth=0 + +* ``--no-oops``: + + Disable default EAL oops handler. diff --git a/doc/guides/rel_notes/release_21_11.rst b/doc/guides/rel_notes/release_21_11.rst index 675b573834..ba31a5dbed 100644 --- a/doc/guides/rel_notes/release_21_11.rst +++ b/doc/guides/rel_notes/release_21_11.rst @@ -62,6 +62,16 @@ New Features * Added bus-level parsing of the devargs syntax. * Kept compatibility with the legacy syntax as parsing fallback. +* **Added APIs for oops handling support.** + + Added support for decoding the oops fault with ``libunwind`` based backtrace, + architecture-specific register dump, instruction memory dump, and + stack memory dump. EAL installs the default oops handler if ``no-oops`` EAL + command line argument is not provided. The default EAL oops handler stores the + existing handler and invoke after decoding. It also offers ``rte_oops_decode`` + API to integrate the EAL oops decode function where the application does not + use the default EAL handler. + Removed Items ------------- diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index ff5861b5f3..b359e55485 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -107,6 +107,7 @@ eal_long_options[] = { {OPT_TELEMETRY, 0, NULL, OPT_TELEMETRY_NUM }, {OPT_NO_TELEMETRY, 0, NULL, OPT_NO_TELEMETRY_NUM }, {OPT_FORCE_MAX_SIMD_BITWIDTH, 1, NULL, OPT_FORCE_MAX_SIMD_BITWIDTH_NUM}, + {OPT_NO_OOPS, 0, NULL, OPT_NO_OOPS_NUM }, /* legacy options that will be removed in future */ {OPT_PCI_BLACKLIST, 1, NULL, OPT_PCI_BLACKLIST_NUM }, @@ -1825,6 +1826,9 @@ eal_parse_common_option(int opt, const char *optarg, return -1; } break; + case OPT_NO_OOPS_NUM: + conf->no_oops = 1; + break; /* don't know what to do, leave this to caller */ default: @@ -2128,6 +2132,7 @@ eal_common_usage(void) " --"OPT_TELEMETRY" Enable telemetry support (on by default)\n" " --"OPT_NO_TELEMETRY" Disable telemetry support\n" " --"OPT_FORCE_MAX_SIMD_BITWIDTH" Force the max SIMD bitwidth\n" + " --"OPT_NO_OOPS" Disable default oops EAL handler(on by default)\n" "\nEAL options for DEBUG use only:\n" " --"OPT_HUGE_UNLINK" Unlink hugepage files after init\n" " --"OPT_NO_HUGE" Use malloc instead of hugetlbfs\n" diff --git a/lib/eal/common/eal_internal_cfg.h b/lib/eal/common/eal_internal_cfg.h index d6c0470eb8..687aa062ea 100644 --- a/lib/eal/common/eal_internal_cfg.h +++ b/lib/eal/common/eal_internal_cfg.h @@ -94,6 +94,7 @@ struct internal_config { unsigned int no_telemetry; /**< true to disable Telemetry */ struct simd_bitwidth max_simd_bitwidth; /**< max simd bitwidth path to use */ + unsigned int no_oops; /**< true to disable oops */ }; void eal_reset_internal_config(struct internal_config *internal_cfg); diff --git a/lib/eal/common/eal_options.h b/lib/eal/common/eal_options.h index 7b348e707f..b0256d7529 100644 --- a/lib/eal/common/eal_options.h +++ b/lib/eal/common/eal_options.h @@ -93,6 +93,8 @@ enum { OPT_NO_TELEMETRY_NUM, #define OPT_FORCE_MAX_SIMD_BITWIDTH "force-max-simd-bitwidth" OPT_FORCE_MAX_SIMD_BITWIDTH_NUM, +#define OPT_NO_OOPS "no-oops" + OPT_NO_OOPS_NUM, /* legacy option that will be removed in future */ #define OPT_PCI_BLACKLIST "pci-blacklist" 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..6a48a7e95c 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -692,6 +692,7 @@ rte_eal_init(int argc, char **argv) return -1; } + thread_id = pthread_self(); eal_reset_internal_config(internal_conf); @@ -719,6 +720,11 @@ rte_eal_init(int argc, char **argv) /* FreeBSD always uses legacy memory model */ internal_conf->legacy_mem = true; + if (internal_conf->no_oops == 0 && eal_oops_init()) { + rte_eal_init_alert("oops init failed."); + rte_errno = ENOENT; + } + if (eal_plugins_init() < 0) { rte_eal_init_alert("Cannot init plugins"); rte_errno = EINVAL; @@ -973,6 +979,8 @@ rte_eal_cleanup(void) rte_eal_memory_detach(); rte_trace_save(); eal_trace_fini(); + if (internal_conf->no_oops == 0) + eal_oops_fini(); eal_cleanup_config(internal_conf); 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..0a76c3d242 --- /dev/null +++ b/lib/eal/include/rte_oops.h @@ -0,0 +1,101 @@ +/* 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 and if *--no-oops* not provided in the EAL + * command line argument, then 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..0ab43c9e74 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -1017,6 +1017,11 @@ rte_eal_init(int argc, char **argv) return -1; } + if (internal_conf->no_oops == 0 && eal_oops_init()) { + rte_eal_init_alert("oops init failed."); + rte_errno = ENOENT; + } + if (eal_plugins_init() < 0) { rte_eal_init_alert("Cannot init plugins"); rte_errno = EINVAL; @@ -1370,6 +1375,8 @@ rte_eal_cleanup(void) rte_eal_memory_detach(); rte_trace_save(); eal_trace_fini(); + if (internal_conf->no_oops == 0) + eal_oops_fini(); eal_cleanup_config(internal_conf); 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 beeb986adc..4106beb6ef 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 Mon Sep 6 04:17:28 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: 98024 X-Patchwork-Delegate: david.marchand@redhat.com 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 B37ACA0C4D; Mon, 6 Sep 2021 06:19:56 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7081041104; Mon, 6 Sep 2021 06:19:52 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 0EE7341100 for ; Mon, 6 Sep 2021 06:19:50 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1861VIP1023146; Sun, 5 Sep 2021 21:19:47 -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=gCc4tOz2pqkjl+DWq8xC8TxLqFBE7pKPE0ccZuNIoPQ=; b=cGLRrIqI0tx6xEixqWgJKrfQrbH96vsD/kzc2HZuSsn/7H5G3TfgwyHgFQm1NPHxgLIS LCAXRYJlSZ2mtoSgsAmXYzreXvcZ62SRg1ap7ehzqiCKG2Rv7+dd+fzImWXUtBuBsCBZ svaNdKoMsw4P4aX38X+oakSQdwF1Jf3AGfZ+mrg1baTgCnv2jCtPpGab+f2WZSUPNOrl SU7g7145jl3s3uJPoxJprBgOq8bw30TOVBZLIF5PSmL424YJ2wHlkv5K+IhQ4vSKNEMR CirsqhViql3ObB2YFnlteohAovhV9sd2672JhBAVScULyDuqGwjyjFvM/uX8iZh0wu73 GQ== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com with ESMTP id 3aw9d2rev8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sun, 05 Sep 2021 21:19:47 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Sun, 5 Sep 2021 21:19:46 -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; Sun, 5 Sep 2021 21:19:46 -0700 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id B30F63F703F; Sun, 5 Sep 2021 21:19:42 -0700 (PDT) From: To: CC: , , , , , , , , , , , Jerin Jacob Date: Mon, 6 Sep 2021 09:47:28 +0530 Message-ID: <20210906041732.1019743-3-jerinj@marvell.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210906041732.1019743-1-jerinj@marvell.com> References: <20210817032723.3997054-1-jerinj@marvell.com> <20210906041732.1019743-1-jerinj@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: ZJrXPIH7QETxPIMLZAbWD5D0xLqiwt_n X-Proofpoint-ORIG-GUID: ZJrXPIH7QETxPIMLZAbWD5D0xLqiwt_n 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-09-06_01,2021-09-03_01,2020-04-07_01 Subject: [dpdk-dev] [PATCH v3 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 | 173 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 166 insertions(+), 7 deletions(-) diff --git a/lib/eal/unix/eal_oops.c b/lib/eal/unix/eal_oops.c index 53b580f733..a480437f23 100644 --- a/lib/eal/unix/eal_oops.c +++ b/lib/eal/unix/eal_oops.c @@ -2,35 +2,194 @@ * Copyright(C) 2021 Marvell. */ +#include +#include +#include +#include +#include +#include #include #include "eal_private.h" -void -rte_oops_decode(int sig, siginfo_t *info, ucontext_t *uc) +/* It is not safe to call rte_log from signal handler due to the fact the + * malloc pool may be corrupted and rte_log uses malloc. + */ +#define oops_print(...) fprintf(stderr, __VA_ARGS__) + +static const int oops_signals[] = {SIGSEGV, SIGBUS, SIGILL, + SIGABRT, SIGFPE, SIGSYS}; + +struct oops_signal { + 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); +} +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(const void *ptr) +{ + const 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++) { + if (oops_signals[idx] != sig) + continue; + /* Skip disabled signals */ + 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++] = oops_signals[idx]; + } + 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++) { + /* Get exiting sigaction */ + rc = sigaction(oops_signals[idx], NULL, &signals_db[idx].sa); + if (rc) + continue; + /* Replace with oops handler */ + rc = sigaction(oops_signals[idx], &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(oops_signals[idx], &signals_db[idx].sa, NULL); + } } From patchwork Mon Sep 6 04:17:29 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: 98025 X-Patchwork-Delegate: david.marchand@redhat.com 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 7E88EA0C4D; Mon, 6 Sep 2021 06:20:02 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9F7AE410F0; Mon, 6 Sep 2021 06:19:58 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 6EA9E410EA for ; Mon, 6 Sep 2021 06:19:57 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 185Le8nD010416; Sun, 5 Sep 2021 21:19:54 -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=M+pMJhlvapl4RbnlYzIvjj/zHga3oTOjf0jjUl+f0yg=; b=c5zzPJa0LECX6kGzM5JfDQYsXOwK2uGaHpKUchoZuZrtS9aba8HUM3O3c74skf2jWd7v Av0KDToWqn9ZtJbOn9gcP9c6/I1qOBbx4Nrk0iCwEY2dtQo/gj/jxvYXAQi3jKP49sr1 xO1SemLixYx1oaRHkhMqWCI+HrAhsM6DzzqlpbzA4uWWLFyPz43LlOI0H91l6/o/Oasm aYfkRzUlfoZAGf6ECQR8Jd3Y7715H6sdVueP9e5XNRIh5GApnFKjFTNVMLFGvNQhJHaS Ia1OHjPPt5kbnHYPtK1SQLOEDgsFIBi3w0fQ2aujwhlVx71fAtznxpRl4f876emtgQM6 QQ== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com with ESMTP id 3aw2sp140a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sun, 05 Sep 2021 21:19:53 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Sun, 5 Sep 2021 21:19:51 -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; Sun, 5 Sep 2021 21:19:51 -0700 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id 80F8A3F7065; Sun, 5 Sep 2021 21:19:47 -0700 (PDT) From: To: , Aaron Conole , Michael Santana , Bruce Richardson CC: , , , , , , , , , , Jerin Jacob Date: Mon, 6 Sep 2021 09:47:29 +0530 Message-ID: <20210906041732.1019743-4-jerinj@marvell.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210906041732.1019743-1-jerinj@marvell.com> References: <20210817032723.3997054-1-jerinj@marvell.com> <20210906041732.1019743-1-jerinj@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: 5-6DAQYvl4nHP_DQ-Yuyvv005aEEx69y X-Proofpoint-ORIG-GUID: 5-6DAQYvl4nHP_DQ-Yuyvv005aEEx69y 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-09-06_01,2021-09-03_01,2020-04-07_01 Subject: [dpdk-dev] [PATCH v3 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 | 45 +++++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 151641e6fa..de985776ed 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 4bb5bf629e..cfb8931d3b 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 3b5966ec2f..7f4dd52bc5 100644 --- a/config/meson.build +++ b/config/meson.build @@ -237,6 +237,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 a480437f23..9c2d9d99d9 100644 --- a/lib/eal/unix/eal_oops.c +++ b/lib/eal/unix/eal_oops.c @@ -28,11 +28,56 @@ 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) + 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) { RTE_SET_USED(context); } + +#endif + static void siginfo_dump(int sig, siginfo_t *info) { From patchwork Mon Sep 6 04:17:30 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: 98026 X-Patchwork-Delegate: david.marchand@redhat.com 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 D7E97A0C4D; Mon, 6 Sep 2021 06:20:07 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BF43A410FE; Mon, 6 Sep 2021 06:20: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 97E79410EA for ; Mon, 6 Sep 2021 06:20: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.1.2) with SMTP id 1861VcUC023206; Sun, 5 Sep 2021 21:19:57 -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=aIP/JuVI0mTDVwhNEGiihDTFn5EXiYUjybw+WKYQgZ4=; b=j7EMxULT1WQQze3GYPYDRtGO+ec2s/qrpHMOSqOZvBWa5q2Vkym1uSbx5fle8j/1hHTw 0SWCvA5gwA7V80D4OHe5PrmE42fzLk/YZowIANNewGdSmfWrw2sugtLXzgmWnuj0QPY+ jSMosK8EvPqGZ6PMqTdeyYg4AKjwElxDprIiyaGKrrsmjOn9GCYFQoNbq/XDGcH+3aMz 6nqlnd+GOp0hl8jOCvyguZhTJypmU7JFWjqVH00IYTrC6GMrYxPu0ogS7qvF/C2iPzYM p2fMdsna2wv04IToyfxfed6wpKiGowVBX0ze71GGQGy1wOtz+RF2zNZqmcyWQXa/hR2f DQ== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com with ESMTP id 3aw9d2revn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sun, 05 Sep 2021 21:19:57 -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; Sun, 5 Sep 2021 21:19:56 -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; Sun, 5 Sep 2021 21:19:56 -0700 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id CEEF73F703F; Sun, 5 Sep 2021 21:19:52 -0700 (PDT) From: To: CC: , , , , , , , , , , , Jerin Jacob Date: Mon, 6 Sep 2021 09:47:30 +0530 Message-ID: <20210906041732.1019743-5-jerinj@marvell.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210906041732.1019743-1-jerinj@marvell.com> References: <20210817032723.3997054-1-jerinj@marvell.com> <20210906041732.1019743-1-jerinj@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: U3uMzU8Ph-FCP1e3SSoDjgk5XiqJqMXi X-Proofpoint-ORIG-GUID: U3uMzU8Ph-FCP1e3SSoDjgk5XiqJqMXi 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-09-06_01,2021-09-03_01,2020-04-07_01 Subject: [dpdk-dev] [PATCH v3 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 9c2d9d99d9..a9c22cbe70 100644 --- a/lib/eal/unix/eal_oops.c +++ b/lib/eal/unix/eal_oops.c @@ -131,6 +131,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) { @@ -139,6 +171,8 @@ archinfo_dump(ucontext_t *uc) stack_code_dump(NULL, NULL); } +#endif + static void default_signal_handler_invoke(int sig) { From patchwork Mon Sep 6 04:17:31 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: 98027 X-Patchwork-Delegate: david.marchand@redhat.com 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 AB590A0C4D; Mon, 6 Sep 2021 06:20:12 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C8F5C410FC; Mon, 6 Sep 2021 06:20:11 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 36869410E9 for ; Mon, 6 Sep 2021 06:20:10 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 185LevLP011779; Sun, 5 Sep 2021 21:20:07 -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=hI+cMDqv+rLQ8aLmZ3M4LZxpJZ2CvSwWoT5jDByR5qQ=; b=UhrorxuC0CG6JhlaLBglc208CGdGo0HbqJBr/O1G3ai7o3OG8A1FD5HnB2s8Hr162jL1 SU/gaxMT/jvAk3l07XpIHNfwjG0TCCOAFiIl851I07gyDs2Jsmo/XPVPuwxDs6bHa8o3 A4+1REcTHq44MDXBdEb/nBhBk9IzvmXNsJxDUsQrkIxaOxkBXhJuUKRhOkD5LI0Pl5C6 Y79OKKHA1e/Y4IwT6xwFQsA0rYFhVqDIDV6RT/P8vInLGM9PYgl5hNfb/cx1CXq4OyEW 388svgEOHabvbiHQsVCfa1FUaRVOz8TBGT5tQO30V2n24XRkc087hePWADageczbZo4p RQ== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com with ESMTP id 3aw2sp140r-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sun, 05 Sep 2021 21:20:07 -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; Sun, 5 Sep 2021 21:20:01 -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; Sun, 5 Sep 2021 21:20:01 -0700 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id 9F9223F703F; Sun, 5 Sep 2021 21:19:57 -0700 (PDT) From: To: CC: , , , , , , , , , , , Jerin Jacob Date: Mon, 6 Sep 2021 09:47:31 +0530 Message-ID: <20210906041732.1019743-6-jerinj@marvell.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210906041732.1019743-1-jerinj@marvell.com> References: <20210817032723.3997054-1-jerinj@marvell.com> <20210906041732.1019743-1-jerinj@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: vm5I-QJ1JOezfDDrbkMqMWIBsgxKXZsw X-Proofpoint-ORIG-GUID: vm5I-QJ1JOezfDDrbkMqMWIBsgxKXZsw 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-09-06_01,2021-09-03_01,2020-04-07_01 Subject: [dpdk-dev] [PATCH v3 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 a9c22cbe70..6793497bee 100644 --- a/lib/eal/unix/eal_oops.c +++ b/lib/eal/unix/eal_oops.c @@ -161,6 +161,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 Mon Sep 6 04:17:32 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: 98028 X-Patchwork-Delegate: david.marchand@redhat.com 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 4E7E3A0C4D; Mon, 6 Sep 2021 06:20:18 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id F1BD2410E6; Mon, 6 Sep 2021 06:20:15 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id CFF17410E9 for ; Mon, 6 Sep 2021 06:20:13 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 185LevLR011779; Sun, 5 Sep 2021 21:20:11 -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=kKiILMzk5Sfs95i/i9DPQlkzRuEQJMTgKv/BctWzuag=; b=P5/nOpJ9G22z82qQ8TowKkteKqgIWMh41NtiFToKvuLwNceMFKDPA3ezVHW0O4ZzoYx6 lJIB2cJdLWmH4Ij9ZmZFEr4u5l3Ae5npxmFaST7Yi5Fs3uTzGfOh2GA5cDC6fmIogO2L FyYp5v/zC26PgFm80fOmZPtHiz9TFaWdgbUJjf0mJ+nxOJHFTTq03TI3lOsXPlzTvdMO flJIpyhoLLD8KrYD1Eaok7PMGFm8ya5MC9AW2lWc5gEojdcwmkP43ZfPevhu9aVnoV4d PY344LQM81GglRCE1fH0Gb4vMqODsRlVwROr86tAblVPSKhFTh7DfJvb/CENV9O5iXax Zw== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com with ESMTP id 3aw2sp1422-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sun, 05 Sep 2021 21:20:10 -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; Sun, 5 Sep 2021 21:20:08 -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; Sun, 5 Sep 2021 21:20:08 -0700 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id 8DAE03F70CD; Sun, 5 Sep 2021 21:20:02 -0700 (PDT) From: To: CC: , , , , , , , , , , , Jerin Jacob Date: Mon, 6 Sep 2021 09:47:32 +0530 Message-ID: <20210906041732.1019743-7-jerinj@marvell.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210906041732.1019743-1-jerinj@marvell.com> References: <20210817032723.3997054-1-jerinj@marvell.com> <20210906041732.1019743-1-jerinj@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: aFTCt7ya8vt9NXb9xK_R1I_4R76Py0g4 X-Proofpoint-ORIG-GUID: aFTCt7ya8vt9NXb9xK_R1I_4R76Py0g4 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-09-06_01,2021-09-03_01,2020-04-07_01 Subject: [dpdk-dev] [PATCH v3 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 | 122 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 124 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..288761822c --- /dev/null +++ b/app/test/test_oops.c @@ -0,0 +1,122 @@ +/* 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); + if (rc == 0) + return TEST_SUCCESS; + + 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);