From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4D114A052E; Mon, 9 Mar 2020 04:02:05 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 89FF72BE6; Mon, 9 Mar 2020 04:02:04 +0100 (CET) Received: from mail-qv1-f65.google.com (mail-qv1-f65.google.com [209.85.219.65]) by dpdk.org (Postfix) with ESMTP id D59BEFEB for ; Mon, 9 Mar 2020 04:02:02 +0100 (CET) Received: by mail-qv1-f65.google.com with SMTP id cz10so321270qvb.0 for ; Sun, 08 Mar 2020 20:02:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=cen4zTx+4MEdBJp8NuhuGFJk0ZR1o4QuBRkpv98tRGk=; b=Od+3ZRYXjJdty7qvT+GfiJ4uolsaGPdUYDPfeK8gR2nM+kLidzPPRSu1yS956JY3VW B0V4y7gQVLIz4YHpxypTG80iLxRqVpdtSUHhYX4avI7yrVTsBn5af+78pfYq1aFUuRB+ WhfQGogzE1v76IJeYKG+e0Hmf464KI6FsRQLTgZTSWjteSL2PRsKYKGsLJ+yImgYYgX2 MMblrd5zRPY/GyiobM3812VDSkwOT9r16ThkmJUrtu/9XsXuj3DoLkDgp8LqAb35zzMF xrgoLhs0YNFh+7qLi0WeIze39ss8EEW8qpK8eToJiMa1eEEsKz42riJnqyc6EY69jrHA mmtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=cen4zTx+4MEdBJp8NuhuGFJk0ZR1o4QuBRkpv98tRGk=; b=q51TX9RVSSSgt/jjBlf34GQMoQlZJctbXulgQEd0He3ldNUFRhmeGJHHZk+GiWZDQB 2h1mXbzfbLYOl0r1XKMNdlsw9KaX3q9wUdOV2WeCF411nL1cj0IV1TlX3ANLQQWMZ3Xr lWScg8bj62FkKs+3Y9O2p8Wv4p6j84j3e2Fcf3cLbhpA9ssfCPJq6EhfiXZAoKjCob80 3lBgSlUKPZHJ9UqZoC5hBccfv+K3D41sj92cU0NSMZ+UOsOoVOfEr/HyTbTLxIxX2Cww hhZBIYa26ZlhKNy0Acti9OH2ZjMgnwXDYh1km6YZ3tOut+vWC4gn/+g1IPPD9Lxg6PmO n+dA== X-Gm-Message-State: ANhLgQ1mrxW1zPUBz/jvc2JtQY75Vz4br2v9Qs+y8G+lkMuq8XSvHp+H mpOM+cCfTn9RzhVaOlA2sjP0ZB0/5Nd9cvgjT5w= X-Google-Smtp-Source: ADFU+vvh6muDzqJYxkMJ1SXNsm+aHB6eenothpEy42RpzmH2cYfqu4xjS63cWtvUh9Z9uFRafaKCyKjSXDFQzfrbEqc= X-Received: by 2002:ad4:49c6:: with SMTP id j6mr1119221qvy.68.1583722922068; Sun, 08 Mar 2020 20:02:02 -0700 (PDT) MIME-Version: 1.0 References: <1583114253-15345-1-git-send-email-xiangxia.m.yue@gmail.com> <1583501776-9958-1-git-send-email-xiangxia.m.yue@gmail.com> <7420c590-4906-34e2-b0b8-d412df9005c8@solarflare.com> In-Reply-To: From: Tonghao Zhang Date: Mon, 9 Mar 2020 11:01:25 +0800 Message-ID: To: Andrew Rybchenko Cc: Jerin Jacob , dpdk-dev , Olivier Matz , Gage Eads , "Artem V. Andreev" , Jerin Jacob , Nithin Dabilpuram , Vamsi Attunuru , Hemant Agrawal Content-Type: text/plain; charset="UTF-8" Subject: Re: [dpdk-dev] [PATCH dpdk-dev v3] mempool: sort the rte_mempool_ops by name X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 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" On Sat, Mar 7, 2020 at 8:54 PM Andrew Rybchenko wrote: > > On 3/7/20 3:51 PM, Andrew Rybchenko wrote: > > On 3/6/20 4:37 PM, Jerin Jacob wrote: > >> On Fri, Mar 6, 2020 at 7:06 PM wrote: > >>> From: Tonghao Zhang > >>> > >>> The order of mempool initiation affects mempool index in the > >>> rte_mempool_ops_table. For example, when building APPs with: > >>> > >>> $ gcc -lrte_mempool_bucket -lrte_mempool_ring ... > >>> > >>> The "bucket" mempool will be registered firstly, and its index > >>> in table is 0 while the index of "ring" mempool is 1. DPDK > >>> uses the mk/rte.app.mk to build APPs, and others, for example, > >>> Open vSwitch, use the libdpdk.a or libdpdk.so to build it. > >>> The mempool lib linked in dpdk and Open vSwitch is different. > >>> > >>> The mempool can be used between primary and secondary process, > >>> such as dpdk-pdump and pdump-pmd/Open vSwitch(pdump enabled). > >>> There will be a crash because dpdk-pdump creates the "ring_mp_mc" > >>> ring which index in table is 0, but the index of "bucket" ring > >>> is 0 in Open vSwitch. If Open vSwitch use the index 0 to get > >>> mempool ops and malloc memory from mempool. The crash will occur: > >>> > >>> bucket_dequeue (access null and crash) > >>> rte_mempool_get_ops (should get "ring_mp_mc", > >>> but get "bucket" mempool) > >>> rte_mempool_ops_dequeue_bulk > >>> ... > >>> rte_pktmbuf_alloc > >>> rte_pktmbuf_copy > >>> pdump_copy > >>> pdump_rx > >>> rte_eth_rx_burst > >>> > >>> To avoid the crash, there are some solution: > >>> * constructor priority: Different mempool uses different > >>> priority in RTE_INIT, but it's not easy to maintain. > >>> > >>> * change mk/rte.app.mk: Change the order in mk/rte.app.mk to > >>> be same as libdpdk.a/libdpdk.so, but when adding a new mempool > >>> driver in future, we must make sure the order. > >>> > >>> * register mempool orderly: Sort the mempool when registering, > >>> so the lib linked will not affect the index in mempool table. > >>> > >>> Signed-off-by: Tonghao Zhang > >>> Acked-by: Olivier Matz > >> Acked-by: Jerin Jacob > > > > The patch is OK, but the fact that ops index changes during > > mempool driver lifetime is frightening. In fact it breaks > > rte_mempool_register_ops() return value semantics (read > > as API break). The return value is not used in DPDK, but it > > is a public function. If I'm not mistaken it should be taken > > into account. Yes, should update the doc: how about this: diff --git a/lib/librte_mempool/rte_mempool.h b/lib/librte_mempool/rte_mempool.h index c90cf31..5a9c8a7 100644 --- a/lib/librte_mempool/rte_mempool.h +++ b/lib/librte_mempool/rte_mempool.h @@ -904,7 +904,9 @@ int rte_mempool_ops_get_info(const struct rte_mempool *mp, * @param ops * Pointer to an ops structure to register. * @return - * - >=0: Success; return the index of the ops struct in the table. + * - >=0: Success; return the index of the last ops struct in the table. + * The number of the ops struct registered is equal to index + * returned + 1. * - -EINVAL - some missing callbacks while registering ops struct. * - -ENOSPC - the maximum number of ops structs has been reached. */ diff --git a/lib/librte_mempool/rte_mempool_ops.c b/lib/librte_mempool/rte_mempool_ops.c index b0da096..053f340 100644 --- a/lib/librte_mempool/rte_mempool_ops.c +++ b/lib/librte_mempool/rte_mempool_ops.c @@ -26,7 +26,11 @@ struct rte_mempool_ops_table rte_mempool_ops_table = { return strcmp(m_a->name, m_b->name); } -/* add a new ops struct in rte_mempool_ops_table, return its index. */ +/* + * add a new ops struct in rte_mempool_ops_table. + * on success, return the index of the last ops + * struct in the table. + */ int rte_mempool_register_ops(const struct rte_mempool_ops *h) { > > Also I remember patches which warn about above behaviour > > in documentation. If behaviour changes, corresponding > > documentation must be updated. > > One more point. If the patch is finally accepted it definitely > deserves few lines in release notes. OK, a separate patch should be sent before DPDK 20.05 release ? > -- Thanks, Tonghao