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 B1AC2A00C2; Mon, 23 May 2022 15:00:40 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 54E914014F; Mon, 23 May 2022 15:00:40 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 2579340141 for ; Mon, 23 May 2022 15:00:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653310837; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ArI+t6GijivWexl57CENs0KEnvZXIn6ISMdmqtUxVAk=; b=JK49P8ARsIbaTYKCyZLHfVrg9tPWk37aHxwnhJUO63OyhCEqBlMmEZjIq2seJLrHw1jSwY azUCphvEFUsp5ORYd5Jc8eP96yFLi6bpusZ5bfSJOPC8dOlEtlmADewoccedLWHzRbFOEc xvW9FEFI5fkT3LTryrCzkeiEWUCEdTA= Received: from mail-lj1-f200.google.com (mail-lj1-f200.google.com [209.85.208.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-654-AMuzvgsePxWWOfH1NttG7A-1; Mon, 23 May 2022 09:00:28 -0400 X-MC-Unique: AMuzvgsePxWWOfH1NttG7A-1 Received: by mail-lj1-f200.google.com with SMTP id h14-20020a2eb0ee000000b00253ca8c5c87so2805185ljl.9 for ; Mon, 23 May 2022 06:00:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=ArI+t6GijivWexl57CENs0KEnvZXIn6ISMdmqtUxVAk=; b=nP6dY5AxAnQWMYsiq6bbP+AbxjDZeYLBHDX3cXLzbr8O6oZ4Sp5CmHYOV2HnTCunF7 FSaOzjopMJjyGrlxSyzcFZ8Hcp6mleL+xe3OoeSSFORT4RHQq6brptr0PEGU/yDsoY7I gh8XrWWrv+XWkuOCTgOiq2cRzn7MxfDH84ZWzgkwJw+3h7SAvFVBxr5eqVI94RXBEQ69 gB+BkVYcNZiNbBExguSm80pNf1xris9Xbqjv+HN3hPVgDN+S3l0m5rIRsPfg6DvysAtq PKV8AN44dEcEbf1q92JUS/Ie59SLLN2mNQ2dll4UIRp7JRioGWEJrF7SzTY9vzHq8POD NzzQ== X-Gm-Message-State: AOAM5320dKgcJSAIUfj/Y9mVR/Ae+W0WktE4R7EuMAxyX3uAeOeRhG9i mEXjD4vxwifvivUUssRYCsfqhpQntxnXckGkfgmHJ1+++YUjdCa/aDEztYvsqW4W0nbErW9VJ2h /mpN1nJvNMqGpvX6ZrVE= X-Received: by 2002:a2e:3e1a:0:b0:253:ed91:bd3b with SMTP id l26-20020a2e3e1a000000b00253ed91bd3bmr2225778lja.55.1653310825474; Mon, 23 May 2022 06:00:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9x/a5iSwD6fkMTYSd0V9WH+hTOnBpI2wYKNx6CUO4mdJxp81KXTmINYBu2iGGEhrIZuHRmKbuhOTCX+tya18= X-Received: by 2002:a2e:3e1a:0:b0:253:ed91:bd3b with SMTP id l26-20020a2e3e1a000000b00253ed91bd3bmr2225716lja.55.1653310823801; Mon, 23 May 2022 06:00:23 -0700 (PDT) MIME-Version: 1.0 References: <20220517160444.413819-1-zhichaox.zeng@intel.com> <20220523111642.10406-1-zhichaox.zeng@intel.com> In-Reply-To: From: David Marchand Date: Mon, 23 May 2022 15:00:12 +0200 Message-ID: Subject: Re: [PATCH v2] lib/eal: fix segfaults due to thread exit order To: "Zeng, ZhichaoX" , Bruce Richardson , Aaron Conole , Olivier Matz Cc: dev , Qiming Yang , Harman Kalra , Thomas Monjalon Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dmarchan@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 On Mon, May 23, 2022 at 2:10 PM David Marchand wrote: > > On Mon, May 23, 2022 at 5:17 AM wrote: > > > > From: Zhichao Zeng > > > > The eal-intr-thread is not closed before memory cleanup in the > > process of exiting. There is a small probability that when the > > eal-intr-thread is about to use some pointers, the memory were > > just cleaned, which cause the segment fault error caught by ASan. > > > > This patch close the eal-intr-thread before memory cleanup when > > exiting to avoid segment fault. > > This breaks the debug_autotest unit test. > It results in a segfault in a forked process executing > rte_exit()/rte_eal_cleanup(). > > That's probably because intr_thread thread does not exist in the forked p= rocess. Reading fork() manual: * The child process is created with a single thread=E2=80=94the o= ne that called fork(). The entire virtual address space of the parent is replicated in the child, including the states of mutexes, condi=E2=80=90 tion variables, and other pthreads objects; the use of pthread_atfork(3) may be helpful for dealing with problems that this can cause. We may need a check like diff below. But then, debug_autotest code seems dangerous, because it does exactly what the added check wants to warn about. Opinions? diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index 1ef263434a..1e6fd01d5d 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -857,12 +857,25 @@ is_iommu_enabled(void) return n > 2; } +static uint32_t run_once; + +static void warn_parent(void) +{ + RTE_LOG(WARNING, EAL, "fork() was called, DPDK won't work in the ch= ild " + "process unless it calls rte_eal_init()\n"); +} + +static void scratch_child(void) +{ + /* Scratch run_once so that a call to rte_eal_cleanup won't crash..= . */ + __atomic_store_n(&run_once, 0, __ATOMIC_RELAXED); +} + /* Launch threads, called at application init(). */ int rte_eal_init(int argc, char **argv) { int i, fctret, ret; - static uint32_t run_once; uint32_t has_run =3D 0; const char *p; static char logid[PATH_MAX]; @@ -1228,6 +1241,8 @@ rte_eal_init(int argc, char **argv) eal_mcfg_complete(); + pthread_atfork(NULL, warn_parent, scratch_child); + return fctret; } @@ -1257,6 +1272,9 @@ rte_eal_cleanup(void) struct internal_config *internal_conf =3D eal_get_internal_configuration(); + if (__atomic_load_n(&run_once, __ATOMIC_RELAXED) =3D=3D 0) + return 0; + if (rte_eal_process_type() =3D=3D RTE_PROC_PRIMARY && internal_conf->hugepage_file.unlink_existing) rte_memseg_walk(mark_freeable, NULL); --=20 David Marchand