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 AE2BA42F42 for ; Tue, 25 Jul 2023 10:53:56 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A7BC040A7F; Tue, 25 Jul 2023 10:53:56 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mails.dpdk.org (Postfix) with ESMTP id E2A1740697 for ; Tue, 25 Jul 2023 10:53:54 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9B57315BF; Tue, 25 Jul 2023 01:54:37 -0700 (PDT) Received: from net-arm-n1amp-02.shanghai.arm.com (net-arm-n1amp-02.shanghai.arm.com [10.169.210.108]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E3AA93F6C4; Tue, 25 Jul 2023 01:53:51 -0700 (PDT) From: Ruifeng Wang To: stable@dpdk.org Cc: ktraynor@redhat.com, nd@arm.com, Ruifeng Wang , Jia He , Anatoly Burakov Subject: [PATCH 21.11] test/mbuf: fix crash in a forked process Date: Tue, 25 Jul 2023 16:53:24 +0800 Message-Id: <20230725085324.53061-1-ruifeng.wang@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org [ upstream commit b6c419dde10e9f5dec7a02098c48060a7493420c ] test/mbuf: fix crash in a forked process Access of any memory in the hugepage shared file-backed area will trigger an unexpected forked child process segment fault. The root cause is DPDK doesn't support fork model [1] (calling rte_eal_init() before fork()). Forked child process can't be treated as a secondary process. Hence fix it by avoiding fork and doing verification in the main process. [1] https://mails.dpdk.org/archives/dev/2018-July/108106.html Fixes: af75078fece3 ("first public release") Signed-off-by: Jia He Signed-off-by: Ruifeng Wang Acked-by: Anatoly Burakov --- app/test/test_mbuf.c | 49 +++++++++++++------------------------------- 1 file changed, 14 insertions(+), 35 deletions(-) diff --git a/app/test/test_mbuf.c b/app/test/test_mbuf.c index 2287bce2f9..9c0ac63f92 100644 --- a/app/test/test_mbuf.c +++ b/app/test/test_mbuf.c @@ -1172,37 +1172,16 @@ test_refcnt_mbuf(void) #endif } -#include -#include -#include -#include - -/* use fork() to test mbuf errors panic */ -static int -verify_mbuf_check_panics(struct rte_mbuf *buf) +/* Verify if mbuf can pass the check */ +static bool +mbuf_check_pass(struct rte_mbuf *buf) { - int pid; - int status; - - pid = fork(); - - if (pid == 0) { - struct rlimit rl; + const char *reason; - /* No need to generate a coredump when panicking. */ - rl.rlim_cur = rl.rlim_max = 0; - setrlimit(RLIMIT_CORE, &rl); - rte_mbuf_sanity_check(buf, 1); /* should panic */ - exit(0); /* return normally if it doesn't panic */ - } else if (pid < 0) { - printf("Fork Failed\n"); - return -1; - } - wait(&status); - if(status == 0) - return -1; + if (rte_mbuf_check(buf, 1, &reason) == 0) + return true; - return 0; + return false; } static int @@ -1219,47 +1198,47 @@ test_failing_mbuf_sanity_check(struct rte_mempool *pktmbuf_pool) return -1; printf("Checking good mbuf initially\n"); - if (verify_mbuf_check_panics(buf) != -1) + if (!mbuf_check_pass(buf)) return -1; printf("Now checking for error conditions\n"); - if (verify_mbuf_check_panics(NULL)) { + if (mbuf_check_pass(NULL)) { printf("Error with NULL mbuf test\n"); return -1; } badbuf = *buf; badbuf.pool = NULL; - if (verify_mbuf_check_panics(&badbuf)) { + if (mbuf_check_pass(&badbuf)) { printf("Error with bad-pool mbuf test\n"); return -1; } badbuf = *buf; badbuf.buf_iova = 0; - if (verify_mbuf_check_panics(&badbuf)) { + if (mbuf_check_pass(&badbuf)) { printf("Error with bad-physaddr mbuf test\n"); return -1; } badbuf = *buf; badbuf.buf_addr = NULL; - if (verify_mbuf_check_panics(&badbuf)) { + if (mbuf_check_pass(&badbuf)) { printf("Error with bad-addr mbuf test\n"); return -1; } badbuf = *buf; badbuf.refcnt = 0; - if (verify_mbuf_check_panics(&badbuf)) { + if (mbuf_check_pass(&badbuf)) { printf("Error with bad-refcnt(0) mbuf test\n"); return -1; } badbuf = *buf; badbuf.refcnt = UINT16_MAX; - if (verify_mbuf_check_panics(&badbuf)) { + if (mbuf_check_pass(&badbuf)) { printf("Error with bad-refcnt(MAX) mbuf test\n"); return -1; } -- 2.25.1