From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from g2t2353.austin.hpe.com (g2t2353.austin.hpe.com [15.233.44.26]) by dpdk.org (Postfix) with ESMTP id 3BA7AD4FC for ; Fri, 11 Nov 2016 00:25:45 +0100 (CET) Received: from g2t2360.austin.hpecorp.net (g2t2360.austin.hpecorp.net [16.196.225.135]) by g2t2353.austin.hpe.com (Postfix) with ESMTP id 3655B49; Thu, 10 Nov 2016 23:25:44 +0000 (UTC) Received: from postal.labs.hpecorp.net (postal.labs.hpe.com [16.111.35.25]) by g2t2360.austin.hpecorp.net (Postfix) with ESMTP id DA7A039; Thu, 10 Nov 2016 23:25:43 +0000 (UTC) Received: from bougret.labs.hpecorp.net (bougret.labs.hpecorp.net [16.111.8.16]) by postal.labs.hpecorp.net (8.14.4/8.14.4/HPL-PA Hub) with ESMTP id uAANPek2002005 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Thu, 10 Nov 2016 15:25:42 -0800 Received: from jt by bougret.labs.hpecorp.net with local (Exim 4.84_2) (envelope-from ) id 1c4yiy-00058R-R3; Thu, 10 Nov 2016 15:25:40 -0800 Date: Thu, 10 Nov 2016 15:25:40 -0800 From: Jean Tourrilhes To: dev@dpdk.org, Thomas Monjalon , David Marchand , Sergio Gonzalez Monroy Message-ID: <20161110232540.GA18054@labs.hpe.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Organisation: HP Labs Palo Alto Address: HP Labs, MS1184, 1501 Page Mill road, Palo Alto, CA 94304, USA. E-mail: jean.tourrilhes@hpe.com User-Agent: Mutt/1.5.23 (2014-03-12) Subject: [dpdk-dev] [PATCH v3] mempool: Add sanity check when secondary link-in less mempools than primary X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: jean.tourrilhes@hpe.com List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Nov 2016 23:25:45 -0000 If the mempool ops the caller wants to use is not registered, the library will segfault in an obscure way when trying to use that mempool. It's better to catch it early and warn the user. If the primary and secondary process were build using different build systems, the list of constructors included by the linker in each binary might be different. Mempools are registered via constructors, so the linker magic will directly impact which mempools are registered with the primary and the secondary. DPDK currently assumes that the secondary has a superset of the mempools registered at the primary, and they are in the same order (same index in primary and secondary). In some build scenario, the secondary might not initialise any mempools at all. This would also catch cases where there is a bug in the mempool registration, or some memory corruptions, but this has not been observed. Signed-off-by: Jean Tourrilhes --- lib/librte_mempool/rte_mempool.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c index e94e56f..bbb6723 100644 --- a/lib/librte_mempool/rte_mempool.c +++ b/lib/librte_mempool/rte_mempool.c @@ -1273,6 +1273,29 @@ rte_mempool_lookup(const char *name) return NULL; } + /* Sanity check : secondary may have initialised less mempools + * than primary due to linker and constructor magic. Or maybe + * there is a mempool corruption or bug. In any case, we can't + * go on, we will segfault in an obscure way. + * This does not detect the cases where the constructor order + * is different between primary and secondary or where the + * index points to the wrong ops. This would require more + * extensive changes, and is much less likely. Jean II */ + if (mp->ops_index >= (int32_t) rte_mempool_ops_table.num_ops) { + unsigned i; + /* Dump list of mempool ops for further investigation. + * In most cases, list is empty... */ + for (i = 0; i < rte_mempool_ops_table.num_ops; i++) { + RTE_LOG(ERR, EAL, "Registered mempool[%d] is %s\n", + i, rte_mempool_ops_table.ops[i].name); + } + /* Do not dump mempool list itself, it will segfault. */ + rte_panic("Cannot find ops for mempool, ops_index %d, " + "num_ops %d - maybe due to build process or " + "linker configuration\n", + mp->ops_index, rte_mempool_ops_table.num_ops); + } + return mp; }