From patchwork Sat Feb 12 18:44:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 107406 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 324C6A00C2; Sat, 12 Feb 2022 19:44:46 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E7D11410D5; Sat, 12 Feb 2022 19:44:40 +0100 (CET) Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by mails.dpdk.org (Postfix) with ESMTP id 02ADB40140 for ; Sat, 12 Feb 2022 19:44:39 +0100 (CET) Received: by mail-pf1-f176.google.com with SMTP id d187so21979434pfa.10 for ; Sat, 12 Feb 2022 10:44:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pyR6ZtjSewF3D/9tYzAWSC3Avs5WomenBqmqcQMPNNw=; b=nZPeH96wj2uAgsiT9HEOtmPYd02mpCLnVFD96cplNcFb7QmlUVNd1J1bbJVooYpudL QAL4bnumIlE3ULPfNlkOKUh3ZKZlLmzr7R4AY9bSTceW3e58k/Ab94Te1Q3D67GD4vDL TphuPkt9/UK9H2DVpr09Xp0VRWFNVb5paDsp2pC/OSAEDC4dx7Pk6Ro7dDdfC4xlTh/z 20SVoKyV9kjTRzxj8qumutXeVQvLTHkLFd9zgL8k1spabiOqAHO4d/BJeYQJuh2IYkxD fn0WhO1aadoIzOpIEeYuwk6MDivTeydpeFz6YbwYAJ0Hv57gmQJxpzYBWuc0BuAvUuzh ga+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pyR6ZtjSewF3D/9tYzAWSC3Avs5WomenBqmqcQMPNNw=; b=iwG1dboapH55OtsS1BuVI1RKLjUQi7ST1331ynUfN+WesX2BPlEq0TsB7F/f6H9ShL zLIEtWuA3bLV4IagPK4FKHwdYCSQv0sHZ7ydM2tRR6QffW30tISg6Yy/VBGXW8vq3XDa rMjgqlJegOMLVlunfn92YVUXTqse4XngGH2UDJq2r7Fd7Kgsq47mActyoztLPL76q7F3 BW0tKt+LO1oCRnVn8gbyNCcYlGfn4JIGnJJrrXg3JZLzGOO1NVcpzlIP4d41MZXLqdmM V7gR8ZXNBwjp80c6vaf8vB4hJBAGYz+A2BlD4YCUfr+Lk/Y4AaPsQM2xc6LHlsQghEq6 qhOQ== X-Gm-Message-State: AOAM5324MJtg21jjOAHcmljhVq9X6oas29ebuDtRsfb9F6PHZw7NbEb8 3KjkeNWGJrQrfxv4YeT/eCROIM9ZTQ/vD8gt X-Google-Smtp-Source: ABdhPJxEK4sX9MVGbUf/ga4E1eI311r5GPXy5qMX1BwWnz9+0+Nj6c0NHCF4Cr16MAZiIKAa3BlaOQ== X-Received: by 2002:a63:945:: with SMTP id 66mr5836744pgj.432.1644691478721; Sat, 12 Feb 2022 10:44:38 -0800 (PST) Received: from hermes.local (204-195-112-199.wavecable.com. [204.195.112.199]) by smtp.gmail.com with ESMTPSA id 16sm20105141pfm.200.2022.02.12.10.44.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Feb 2022 10:44:38 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v2 1/2] eal_debug: do not use malloc in rte_dump_stack Date: Sat, 12 Feb 2022 10:44:32 -0800 Message-Id: <20220212184433.66791-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220212184433.66791-1-stephen@networkplumber.org> References: <20220129011039.264377-1-stephen@networkplumber.org> <20220212184433.66791-1-stephen@networkplumber.org> MIME-Version: 1.0 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 The glibc backtrace_symbols() calls malloc which makes it dangerous to use rte_dump_stack() in a signal handler that is handling errors that maybe due to memory corruption. Instead, use dladdr() to lookup up symbols incrementally. The format of the messages is based on what X org server has been doing for many years. It changes from bottom up to top down order. Signed-off-by: Stephen Hemminger --- lib/eal/linux/eal_debug.c | 46 +++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/lib/eal/linux/eal_debug.c b/lib/eal/linux/eal_debug.c index 64dab4e0da24..51f24e3cccdf 100644 --- a/lib/eal/linux/eal_debug.c +++ b/lib/eal/linux/eal_debug.c @@ -4,6 +4,7 @@ #ifdef RTE_BACKTRACE #include +#include #endif #include #include @@ -18,26 +19,47 @@ #define BACKTRACE_SIZE 256 -/* dump the stack of the calling core */ +/* Dump the stack of the calling core + * + * Note: this requires limiting what functions are used in this code to stay safe + * when called from a signal handler and malloc pool maybe corrupt. + */ void rte_dump_stack(void) { #ifdef RTE_BACKTRACE void *func[BACKTRACE_SIZE]; - char **symb = NULL; - int size; + int i, size; size = backtrace(func, BACKTRACE_SIZE); - symb = backtrace_symbols(func, size); - if (symb == NULL) - return; + for (i = 0; i < size; i++) { + void *pc = func[i]; + const char *fname; + Dl_info info; - while (size > 0) { - rte_log(RTE_LOG_ERR, RTE_LOGTYPE_EAL, - "%d: [%s]\n", size, symb[size - 1]); - size --; - } + if (dladdr(pc, &info) == 0) { + /* If symbol information not found print in hex */ + rte_log(RTE_LOG_ERR, RTE_LOGTYPE_EAL, + "%d: ?? [%p]\n", i, pc); + continue; + } - free(symb); + /* Is file name known? */ + fname = (info.dli_fname && *info.dli_fname) ? info.dli_fname : "(vdso)"; + + /* Is symbol name known? */ + if (info.dli_sname != NULL) + rte_log(RTE_LOG_ERR, RTE_LOGTYPE_EAL, + "%d: %s (%s+%#tx) [%p]\n", + i, fname, info.dli_sname, + (ptrdiff_t)((uintptr_t)pc - (uintptr_t)info.dli_saddr), + pc); + else + rte_log(RTE_LOG_ERR, RTE_LOGTYPE_EAL, + "%d: %s (%p+%#tx) [%p]\n", + i, fname, info.dli_fbase, + (ptrdiff_t)((uintptr_t)pc - (uintptr_t)info.dli_fbase), + pc); + } #endif /* RTE_BACKTRACE */ } From patchwork Sat Feb 12 18:44:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 107407 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 843ADA00C2; Sat, 12 Feb 2022 19:44:51 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C0D10410F0; Sat, 12 Feb 2022 19:44:42 +0100 (CET) Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by mails.dpdk.org (Postfix) with ESMTP id C3A364069D for ; Sat, 12 Feb 2022 19:44:40 +0100 (CET) Received: by mail-pl1-f169.google.com with SMTP id x12so184019pln.2 for ; Sat, 12 Feb 2022 10:44:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CeciaiVxaCiSR7MRPGLw8IZcpib50Ze4mrpeOEU72w4=; b=D3/0skKXS0AtV8F+Wrtn4aw5yL2hrt1H15igQd1XTwpIe5ywWQ8LW7D+1h4keIpt2G WW3r9EhYf/7U3o2fNj2PipYhfxvR0+9TCHmRkCkrS037zL7zR8ZO6lMrwWivDFPYaKHP QtwR30xeSBTCF8gxpeywwyxD08AGgfZWXhuNY/BH6wyuBkI3FJ1T8/bfemrRNfNo3GXR 7Yx/NW74VnB4KIcehU0KtIh43jXoOAWuPDP8YcBESOxzlzHhrUSXaddN03fJzsIXVh95 ebnwYGBxP+NNxmP0QBj62DrASIjLiOqKHuWNL8mBiYwmqV3xrUNuhGIdEOzKuc4qy/Je 9pDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CeciaiVxaCiSR7MRPGLw8IZcpib50Ze4mrpeOEU72w4=; b=1BZiA5b3k/TMECyDWK9+ztgXWzUS4JdHaBiFyv9CXHAblR4pd7zZ0l6QEJXuupI/S+ veG8dirOYbrsT+jfmmhBsGxufDW0xfUuZxpFUflmOTVSSUdvPudQd+JexF+znZe4IoV5 dB9kfNeg7/v1NPDTOP3h41GhifcyITS7/NoAA4Ic60OgfP7dhgULRGrmag7QypOW9MV9 M9uvovZehnlIINltwTufShy4GfSVkI4MIXrm1lIIgpy+qkPqK/K4wpYW4cRsSzWJ2s3H 0epjYm4mU4ad8N9nX8h6nBRNJkAR1Ffz7jPmduPgZN7BQ3Jxc8DwDt16FSkXETuIZJ46 IC+w== X-Gm-Message-State: AOAM533CeCYLihEfJaKw2l2EdXrfllbt+rDXg4CB8tcMmUoEx6J+ukZ9 AgZmrScbH5/POcNt+ANvn8nvjVLwbuyjarjp X-Google-Smtp-Source: ABdhPJwBI5vuqc6CfKH7DJ0Wh5VKxf2ns/3UdSvHIqVl2CX6XY2QzlclbFSaOqtpXCb/hc0Cl2mAhg== X-Received: by 2002:a17:90b:33cd:: with SMTP id lk13mr6319996pjb.91.1644691479676; Sat, 12 Feb 2022 10:44:39 -0800 (PST) Received: from hermes.local (204-195-112-199.wavecable.com. [204.195.112.199]) by smtp.gmail.com with ESMTPSA id 16sm20105141pfm.200.2022.02.12.10.44.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Feb 2022 10:44:39 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v2 2/2] eal: common rte_dump_stack for both Linux and FreeBSD Date: Sat, 12 Feb 2022 10:44:33 -0800 Message-Id: <20220212184433.66791-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220212184433.66791-1-stephen@networkplumber.org> References: <20220129011039.264377-1-stephen@networkplumber.org> <20220212184433.66791-1-stephen@networkplumber.org> MIME-Version: 1.0 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 The core functions used by rte_dump_stack() are backtrace_symbols and dladdr. Both of those functions are the same in Linux and FreeBSD so the code for decoding stack should be common. Also, the filenames unix/meson.build are now resorted. Signed-off-by: Stephen Hemminger --- lib/eal/freebsd/eal_debug.c | 43 ----------------------------- lib/eal/freebsd/meson.build | 1 - lib/eal/linux/meson.build | 1 - lib/eal/{linux => unix}/eal_debug.c | 0 lib/eal/unix/meson.build | 5 ++-- 5 files changed, 3 insertions(+), 47 deletions(-) delete mode 100644 lib/eal/freebsd/eal_debug.c rename lib/eal/{linux => unix}/eal_debug.c (100%) diff --git a/lib/eal/freebsd/eal_debug.c b/lib/eal/freebsd/eal_debug.c deleted file mode 100644 index 64dab4e0da24..000000000000 --- a/lib/eal/freebsd/eal_debug.c +++ /dev/null @@ -1,43 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * Copyright(c) 2010-2014 Intel Corporation - */ - -#ifdef RTE_BACKTRACE -#include -#endif -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#define BACKTRACE_SIZE 256 - -/* dump the stack of the calling core */ -void rte_dump_stack(void) -{ -#ifdef RTE_BACKTRACE - void *func[BACKTRACE_SIZE]; - char **symb = NULL; - int size; - - size = backtrace(func, BACKTRACE_SIZE); - symb = backtrace_symbols(func, size); - - if (symb == NULL) - return; - - while (size > 0) { - rte_log(RTE_LOG_ERR, RTE_LOGTYPE_EAL, - "%d: [%s]\n", size, symb[size - 1]); - size --; - } - - free(symb); -#endif /* RTE_BACKTRACE */ -} diff --git a/lib/eal/freebsd/meson.build b/lib/eal/freebsd/meson.build index 398ceab71d03..85cca5a096ca 100644 --- a/lib/eal/freebsd/meson.build +++ b/lib/eal/freebsd/meson.build @@ -7,7 +7,6 @@ sources += files( 'eal.c', 'eal_alarm.c', 'eal_cpuflags.c', - 'eal_debug.c', 'eal_dev.c', 'eal_hugepage_info.c', 'eal_interrupts.c', diff --git a/lib/eal/linux/meson.build b/lib/eal/linux/meson.build index 65f2ac6b4798..3cccfa36c0a4 100644 --- a/lib/eal/linux/meson.build +++ b/lib/eal/linux/meson.build @@ -7,7 +7,6 @@ sources += files( 'eal.c', 'eal_alarm.c', 'eal_cpuflags.c', - 'eal_debug.c', 'eal_dev.c', 'eal_hugepage_info.c', 'eal_interrupts.c', diff --git a/lib/eal/linux/eal_debug.c b/lib/eal/unix/eal_debug.c similarity index 100% rename from lib/eal/linux/eal_debug.c rename to lib/eal/unix/eal_debug.c diff --git a/lib/eal/unix/meson.build b/lib/eal/unix/meson.build index a22ea7cabc46..9f724bfd5d7a 100644 --- a/lib/eal/unix/meson.build +++ b/lib/eal/unix/meson.build @@ -2,10 +2,11 @@ # Copyright(c) 2020 Dmitry Kozlyuk sources += files( + 'eal_debug.c', 'eal_file.c', + 'eal_filesystem.c', + 'eal_firmware.c', 'eal_unix_memory.c', 'eal_unix_timer.c', - 'eal_firmware.c', - 'eal_filesystem.c', 'rte_thread.c', )