From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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); + } } -- 2.32.0