From patchwork Tue Oct 8 16:33:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 60707 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A8C361D427; Tue, 8 Oct 2019 18:34:04 +0200 (CEST) Received: from mail-pl1-f196.google.com (mail-pl1-f196.google.com [209.85.214.196]) by dpdk.org (Postfix) with ESMTP id B6ED81C1C3 for ; Tue, 8 Oct 2019 18:33:59 +0200 (CEST) Received: by mail-pl1-f196.google.com with SMTP id w8so8678967plq.5 for ; Tue, 08 Oct 2019 09:33:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PefKtuj67XVP00td27XmXktyYTet80qgSY8DUi9zOoc=; b=nMeL/LB3RLA4gA89X3od3ZfbQgyS23xhrKJv/pBjlGFwT2gzQdxbBQgmjH5zE/spfL u4Hu70rJXoHOUr0EdJD/L4TR10GLudgQXx63OJ+kaI2JlQ7fHXspkdAVXAUbgje5urOg VTnJX9U+PyNiZgkD5RYtevGHVrCHoC2hkQIqBnrXcXRrSlmlxASx8c0xcE06qKe90Eca FYGUan8TR3e6cVC9tYANQ41FUGXQYiwXHk20n3HSsWQwN21nUI/eCxKt1kTbrFJAp2nZ OwIxerR2z3elml2S2wYNANqknn9V5YNSZR2wr+7/DOsAC2s1AM0395QTBY2igjzzJ3FO ucxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PefKtuj67XVP00td27XmXktyYTet80qgSY8DUi9zOoc=; b=GY3g2BrB9EZctXNpc+vI2Pysbqlq+3+ysJMM13ObstnYgE8P1m8qzfVSzqRu1oQyGq Panq9HkEXZ/ZvQL+blwjStzEL4ZaA9QdeNs8RL6vyuyxisoBZoK3xln51QTMYODrIw7O wci5zE4SIrGtWHT9br7fQGBSnRpCeuwvwWMMdugnyrxqYQHR9IWj3Eu2HycQCfWWkFpX T461jQzcOa7p9Bi+kQjG4MH8UjBBwQoWbWWkrsv9TGvl23UzOPfzsevOHL3XyoF8iqSG j03vdy4aaRM9wewX5INluWTgpZLyxRAVwKBLcYIxqTcMA/UWG0+nKdgYOblzi3oMfywR ef3A== X-Gm-Message-State: APjAAAVNjIncZ1dao96e6WmBVOZOjiURlweB8ZJu6qQUrk0EMOKaQOM+ PQTRIKNTrEst4vnFsqOT6lbccsnFBGoR5A== X-Google-Smtp-Source: APXvYqxvPDYKwcRlSE8uMRfzbJYhuLUCG9xfK1Lg4CF/ONpC2mSip+TWIYC73aBQZOxnGl8Vh7aEUg== X-Received: by 2002:a17:902:7782:: with SMTP id o2mr6691401pll.165.1570552438283; Tue, 08 Oct 2019 09:33:58 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id 18sm17702551pfp.100.2019.10.08.09.33.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2019 09:33:57 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Olivier Matz Date: Tue, 8 Oct 2019 09:33:46 -0700 Message-Id: <20191008163350.20779-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191008163350.20779-1-stephen@networkplumber.org> References: <20190928003758.18489-1-stephen@networkplumber.org> <20191008163350.20779-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v6 1/5] mbuf: don't generate invalid mbuf in clone test 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" The test for cloning changed mbuf would generate an mbuf whose length and segments were invalid. This would cause a crash if test was run with mbuf debugging enabled. Fixes: f1022aba76a5 ("app/test: rename mbuf variable") Signed-off-by: Stephen Hemminger Acked-by: Olivier Matz --- app/test/test_mbuf.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/test/test_mbuf.c b/app/test/test_mbuf.c index 2a97afe2044a..aafad0cf6206 100644 --- a/app/test/test_mbuf.c +++ b/app/test/test_mbuf.c @@ -332,8 +332,11 @@ testclone_testupdate_testdetach(struct rte_mempool *pktmbuf_pool) m->next = rte_pktmbuf_alloc(pktmbuf_pool); if (m->next == NULL) GOTO_FAIL("Next Pkt Null\n"); + m->nb_segs = 2; rte_pktmbuf_append(m->next, sizeof(uint32_t)); + m->pkt_len = 2 * sizeof(uint32_t); + data = rte_pktmbuf_mtod(m->next, unaligned_uint32_t *); *data = MAGIC_DATA; From patchwork Tue Oct 8 16:33:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 60708 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6742C1D454; Tue, 8 Oct 2019 18:34:07 +0200 (CEST) Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by dpdk.org (Postfix) with ESMTP id 4D50B1D176 for ; Tue, 8 Oct 2019 18:34:01 +0200 (CEST) Received: by mail-pg1-f194.google.com with SMTP id t3so4697572pga.8 for ; Tue, 08 Oct 2019 09:34:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yQh5p5nD1cVmY52VYrUOKE5OPsSsIwvktFX/RNjf88c=; b=peazpEMQ1Na5ZsoDlayFDr9w0z3KUge8hYOsS0188jYXxQJlTf/JHWuyDJUVlZMasC Hmnxc5uxIeCVU87Ke4s1fclFgfuySe+Bs3MxoqegItEKmYlSfBE3A62osJS5clo/ZwB1 /5ktBiWPM1tz+BbvzHk1VJ5Pt7j+kuA5s61NTWqXYLqdA81ZEoUvmb0ZVXeX+X/hu+UM MGWCxh87plc0VMAdvidaIVDgngCZqhUsFdXJBSRNtKn/D7o2nCnnyiLQF0LgyATVSCPB 8QuskOtckoPuN1YYHvO33BwHGVDzXCnPE2mGMFBl8Nt/0E7QTVEBO1LLAsRJU/Y6Ap81 RnQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yQh5p5nD1cVmY52VYrUOKE5OPsSsIwvktFX/RNjf88c=; b=odN2SrzTgTfjvboM0DLg/J1IhKYcZpJz9ydzeD8M/sBtEP/yBmlnwX+ocRVV0D8aDN TLXeltE1ITRKZrMtAjykNY5pLxeFw+jAF/n4+wxmSKTyqkNSDUauRQCZCGP7kV/QjAXx e+WhRZmEzKt99wla/PfqAew4VwT7F7LGv1SgWc4WVAy8TEWXTiUCXiUf5PwYC4f9AXg8 NQVjXSyVaV+dhTaeNEmZSIAnmtsoYQV8gTmmIdPxfmYXgza7/DY0y5EI2H9KFe7tJGqS XGGobzXPyDE9Hov/v95MFBmE0Huf7TOfd8vOKULlq5QL9yU7seLKBFgi108yaIUT0XjL amUQ== X-Gm-Message-State: APjAAAWNbsuCQm0pJJ44FTmJzjOKv/UERk8b6UMFp2XJgl5gRTnKuFoF SJN8/cJ9pyjbu3AvnUWjuGpC6Ftd4Ev84Q== X-Google-Smtp-Source: APXvYqzGVC6mhXaEkbVU9L/B8rH0keT04ag/Fgv57zkHeKCnYeOWYJdV99DS4Jpn/PTYDAnwlIbJBg== X-Received: by 2002:a17:90a:bc49:: with SMTP id t9mr6739197pjv.93.1570552439671; Tue, 08 Oct 2019 09:33:59 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id 18sm17702551pfp.100.2019.10.08.09.33.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2019 09:33:58 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Andrew Rybchenko , Olivier Matz Date: Tue, 8 Oct 2019 09:33:47 -0700 Message-Id: <20191008163350.20779-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191008163350.20779-1-stephen@networkplumber.org> References: <20190928003758.18489-1-stephen@networkplumber.org> <20191008163350.20779-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v6 2/5] mbuf: delinline rte_pktmbuf_linearize 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" This copy part of this function is too big to be put inline. The places it is used are only in special exception paths where a highly fragmented mbuf arrives at a device that can't handle it. Signed-off-by: Stephen Hemminger Acked-by: Andrew Rybchenko Acked-by: Olivier Matz --- lib/librte_mbuf/rte_mbuf.c | 37 +++++++++++++++++++++++++++ lib/librte_mbuf/rte_mbuf.h | 38 +++++----------------------- lib/librte_mbuf/rte_mbuf_version.map | 6 +++++ 3 files changed, 49 insertions(+), 32 deletions(-) diff --git a/lib/librte_mbuf/rte_mbuf.c b/lib/librte_mbuf/rte_mbuf.c index 37718d49c148..e2c661c97522 100644 --- a/lib/librte_mbuf/rte_mbuf.c +++ b/lib/librte_mbuf/rte_mbuf.c @@ -245,6 +245,43 @@ int rte_mbuf_check(const struct rte_mbuf *m, int is_header, return 0; } +/* convert multi-segment mbuf to single mbuf */ +int +__rte_pktmbuf_linearize(struct rte_mbuf *mbuf) +{ + size_t seg_len, copy_len; + struct rte_mbuf *m; + struct rte_mbuf *m_next; + char *buffer; + + /* Extend first segment to the total packet length */ + copy_len = rte_pktmbuf_pkt_len(mbuf) - rte_pktmbuf_data_len(mbuf); + + if (unlikely(copy_len > rte_pktmbuf_tailroom(mbuf))) + return -1; + + buffer = rte_pktmbuf_mtod_offset(mbuf, char *, mbuf->data_len); + mbuf->data_len = (uint16_t)(mbuf->pkt_len); + + /* Append data from next segments to the first one */ + m = mbuf->next; + while (m != NULL) { + m_next = m->next; + + seg_len = rte_pktmbuf_data_len(m); + rte_memcpy(buffer, rte_pktmbuf_mtod(m, char *), seg_len); + buffer += seg_len; + + rte_pktmbuf_free_seg(m); + m = m_next; + } + + mbuf->next = NULL; + mbuf->nb_segs = 1; + + return 0; +} + /* dump a mbuf on console */ void rte_pktmbuf_dump(FILE *f, const struct rte_mbuf *m, unsigned dump_len) diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index 98225ec80bf1..bffda1c81fbd 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -2400,6 +2400,11 @@ rte_validate_tx_offload(const struct rte_mbuf *m) return 0; } +/** + * @internal used by rte_pktmbuf_linearize(). + */ +int __rte_pktmbuf_linearize(struct rte_mbuf *mbuf); + /** * Linearize data in mbuf. * @@ -2415,40 +2420,9 @@ rte_validate_tx_offload(const struct rte_mbuf *m) static inline int rte_pktmbuf_linearize(struct rte_mbuf *mbuf) { - size_t seg_len, copy_len; - struct rte_mbuf *m; - struct rte_mbuf *m_next; - char *buffer; - if (rte_pktmbuf_is_contiguous(mbuf)) return 0; - - /* Extend first segment to the total packet length */ - copy_len = rte_pktmbuf_pkt_len(mbuf) - rte_pktmbuf_data_len(mbuf); - - if (unlikely(copy_len > rte_pktmbuf_tailroom(mbuf))) - return -1; - - buffer = rte_pktmbuf_mtod_offset(mbuf, char *, mbuf->data_len); - mbuf->data_len = (uint16_t)(mbuf->pkt_len); - - /* Append data from next segments to the first one */ - m = mbuf->next; - while (m != NULL) { - m_next = m->next; - - seg_len = rte_pktmbuf_data_len(m); - rte_memcpy(buffer, rte_pktmbuf_mtod(m, char *), seg_len); - buffer += seg_len; - - rte_pktmbuf_free_seg(m); - m = m_next; - } - - mbuf->next = NULL; - mbuf->nb_segs = 1; - - return 0; + return __rte_pktmbuf_linearize(mbuf); } /** diff --git a/lib/librte_mbuf/rte_mbuf_version.map b/lib/librte_mbuf/rte_mbuf_version.map index 2662a37bf674..4d0bc9772769 100644 --- a/lib/librte_mbuf/rte_mbuf_version.map +++ b/lib/librte_mbuf/rte_mbuf_version.map @@ -46,6 +46,12 @@ DPDK_18.08 { rte_pktmbuf_pool_create_by_ops; } DPDK_16.11; +DPDK_19.11 { + global: + + __rte_pktmbuf_linearize; +} DPDK_18.08; + EXPERIMENTAL { global: From patchwork Tue Oct 8 16:33:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 60709 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 0D4231D50C; Tue, 8 Oct 2019 18:34:09 +0200 (CEST) Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) by dpdk.org (Postfix) with ESMTP id E97531D412 for ; Tue, 8 Oct 2019 18:34:01 +0200 (CEST) Received: by mail-pl1-f194.google.com with SMTP id d22so8704331pls.0 for ; Tue, 08 Oct 2019 09:34:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HIvhTcCefGzrscLW8jcFtSXJiWq/6kU5A7DNPu7eb3E=; b=JLZMbp9XDnJhhouLa039NM3SoM7auKc+SbFn2MUrWsNKL38Z/WP/Ko/m7stdBuvinQ uNmn5VAcR9rnEw2XaorjKbya7soRtDvFnxwVBPfn+4VOQ5z8x5lpLxNLTIW7/MvSP6QT wdzHGZ8YYX3l7vqLgxMJeDUwgahRVTzI/A9YulapxA5SueE1U1nZBHbRw2qpFwjHz9mZ XA/M4Q6hapEMTZTcAxwAQzF2nGU1+f0pgy6JKfEeOc1fZ29M02UfKTTKrage+SnX78Hr ypQFYPbgPvzgK1JDQyfnuUO97k7Fcxkr8hBFDUFyWbezJUTw4lomZkMkenN2tPXtTFw2 2x8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HIvhTcCefGzrscLW8jcFtSXJiWq/6kU5A7DNPu7eb3E=; b=ZZYMr/3OsQH2lr33oOUsuBPkj4uuXfiiJOSM57tufgCqcm0As90Gj/o4k7hD1m/Zbo 8Ho663+JZ7pPeQMGmrwf3U5uekhpYjdtHogGFqyOCllMrCc3AhJd2gU51o5CAFq67nhJ ZpvZK3LQZklWuX3y8uFqvFvMkYqH9ZuMoxmj637Ky7ad8epH9i4sKCdZJv17oNhJxl0i TSDiOyydw6K+eSyqZdzGLC+qGMZl+pTpNJLwd9lT/soXZ+0mewjF16EDqkfJmEWL/Sl+ jbLczl54r5WzK03Ktz2utyrDgVxv3A9jJbyspTeeHq9PIBfeqRPcyQupssaGJdWDm6aE y8pw== X-Gm-Message-State: APjAAAU2XxVzohfyYWfUAvhtD69D7L2jlPlRTN6l4I2ao/6OUirOhiDU ezY240kB1yat/Th7Iq6ObtQKEgu+XELabw== X-Google-Smtp-Source: APXvYqwLSrAspG11GjGcQgdhSkOrhTTQQQBvIkNlg4Q1zhi/Vj51J9nXZhWTnmIeThbunwQymK3Ptg== X-Received: by 2002:a17:902:6941:: with SMTP id k1mr33676038plt.252.1570552440528; Tue, 08 Oct 2019 09:34:00 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id 18sm17702551pfp.100.2019.10.08.09.33.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2019 09:33:59 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Andrew Rybchenko , Olivier Matz Date: Tue, 8 Oct 2019 09:33:48 -0700 Message-Id: <20191008163350.20779-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191008163350.20779-1-stephen@networkplumber.org> References: <20190928003758.18489-1-stephen@networkplumber.org> <20191008163350.20779-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v6 3/5] mbuf: deinline rte_pktmbuf_clone 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" Cloning mbufs requires allocations and iteration and therefore should not be an inline. Signed-off-by: Stephen Hemminger Acked-by: Andrew Rybchenko Acked-by: Olivier Matz --- lib/librte_mbuf/rte_mbuf.c | 39 ++++++++++++++++++++++++++++ lib/librte_mbuf/rte_mbuf.h | 38 ++------------------------- lib/librte_mbuf/rte_mbuf_version.map | 1 + 3 files changed, 42 insertions(+), 36 deletions(-) diff --git a/lib/librte_mbuf/rte_mbuf.c b/lib/librte_mbuf/rte_mbuf.c index e2c661c97522..9a1a1b5f9468 100644 --- a/lib/librte_mbuf/rte_mbuf.c +++ b/lib/librte_mbuf/rte_mbuf.c @@ -245,6 +245,45 @@ int rte_mbuf_check(const struct rte_mbuf *m, int is_header, return 0; } +/* Creates a shallow copy of mbuf */ +struct rte_mbuf * +rte_pktmbuf_clone(struct rte_mbuf *md, struct rte_mempool *mp) +{ + struct rte_mbuf *mc, *mi, **prev; + uint32_t pktlen; + uint16_t nseg; + + mc = rte_pktmbuf_alloc(mp); + if (unlikely(mc == NULL)) + return NULL; + + mi = mc; + prev = &mi->next; + pktlen = md->pkt_len; + nseg = 0; + + do { + nseg++; + rte_pktmbuf_attach(mi, md); + *prev = mi; + prev = &mi->next; + } while ((md = md->next) != NULL && + (mi = rte_pktmbuf_alloc(mp)) != NULL); + + *prev = NULL; + mc->nb_segs = nseg; + mc->pkt_len = pktlen; + + /* Allocation of new indirect segment failed */ + if (unlikely(mi == NULL)) { + rte_pktmbuf_free(mc); + return NULL; + } + + __rte_mbuf_sanity_check(mc, 1); + return mc; +} + /* convert multi-segment mbuf to single mbuf */ int __rte_pktmbuf_linearize(struct rte_mbuf *mbuf) diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index bffda1c81fbd..6133f12172ae 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -1924,42 +1924,8 @@ static inline void rte_pktmbuf_free(struct rte_mbuf *m) * - The pointer to the new "clone" mbuf on success. * - NULL if allocation fails. */ -static inline struct rte_mbuf *rte_pktmbuf_clone(struct rte_mbuf *md, - struct rte_mempool *mp) -{ - struct rte_mbuf *mc, *mi, **prev; - uint32_t pktlen; - uint16_t nseg; - - if (unlikely ((mc = rte_pktmbuf_alloc(mp)) == NULL)) - return NULL; - - mi = mc; - prev = &mi->next; - pktlen = md->pkt_len; - nseg = 0; - - do { - nseg++; - rte_pktmbuf_attach(mi, md); - *prev = mi; - prev = &mi->next; - } while ((md = md->next) != NULL && - (mi = rte_pktmbuf_alloc(mp)) != NULL); - - *prev = NULL; - mc->nb_segs = nseg; - mc->pkt_len = pktlen; - - /* Allocation of new indirect segment failed */ - if (unlikely (mi == NULL)) { - rte_pktmbuf_free(mc); - return NULL; - } - - __rte_mbuf_sanity_check(mc, 1); - return mc; -} +struct rte_mbuf * +rte_pktmbuf_clone(struct rte_mbuf *md, struct rte_mempool *mp); /** * Adds given value to the refcnt of all packet mbuf segments. diff --git a/lib/librte_mbuf/rte_mbuf_version.map b/lib/librte_mbuf/rte_mbuf_version.map index 4d0bc9772769..ff5c18a5559b 100644 --- a/lib/librte_mbuf/rte_mbuf_version.map +++ b/lib/librte_mbuf/rte_mbuf_version.map @@ -50,6 +50,7 @@ DPDK_19.11 { global: __rte_pktmbuf_linearize; + rte_pktmbuf_clone; } DPDK_18.08; EXPERIMENTAL { From patchwork Tue Oct 8 16:33:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 60710 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id C9D8B1DF96; Tue, 8 Oct 2019 18:34:10 +0200 (CEST) Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by dpdk.org (Postfix) with ESMTP id 8AAB41D41D for ; Tue, 8 Oct 2019 18:34:03 +0200 (CEST) Received: by mail-pg1-f193.google.com with SMTP id i32so3223809pgl.10 for ; Tue, 08 Oct 2019 09:34:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=41c2SjNfIBxEKwX/NOAGZPs8cbfMgVJcdrvMw4C4nC8=; b=eiufd2ezm0rXouDxDC/Vt0EXx3C3az3ZiCMr+XQzo+rOaV3AQlAOcIA0RL8HocgKIm Wte+G6lSY+4KY8e5BIlBMIf+oVUd8vilTjNm8EBtcOI8dzC1/kGbqEV495Ez3Kdsgtnv YnPAArFESiBzWEqO0uJDQndNKDVea9LdnumWmKAd+jH5QZx7IyNXqiSemTDGReX3yeGB HdHc0cGK0IwRoOFgSFFZIjqTXwoh/bArRShf32zP9ZnXiQu8EeoLuPfzfkjg7WhghSfc a14LTLyP8ivRHqqnRlNWXctRe8o0Qap2LvQHTqO4vLrfn6UsUAP7x3Xn5kgGUxTAwmRB ZO0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=41c2SjNfIBxEKwX/NOAGZPs8cbfMgVJcdrvMw4C4nC8=; b=I1ezu8e93dPXS90QlTxWTnsdvJlO2tlcn8gCovVoDGsKYK87UjNgrqW5HTY+4uuEm4 OwOlENswO3iTBC+hbcQTvDbUtJ72ebO2EijxmZUZaUL9ubDPSVeLh6Nx0KN4c7HNIa5Z 4q29zwjS2iUBDl4FzsvTV3WOwpEa8N3ge0XjuN9ZknAd6uX/BUS6dQgHaoA8L+lI1Dm8 cl7xJabiJWJ8tYFCo8nR+BoaaBWzVH723lGuL3luUQ4hQfHEQutmUz04VZMNb9ODqXU1 gANQ42lek63Ck54D+2dYFc7HeaAPScgVB/2FP0bOVuOP7+O6n8tnPMGz4wMz8+if5XT5 HiIA== X-Gm-Message-State: APjAAAX+ITCjFV0CvYQ27IKRw00/GLEAbADH6n/TmvBRsSd258XPOsTd pW1zp1Hp1hYpuoTFS/i64JsKNsCDvphv9A== X-Google-Smtp-Source: APXvYqyiO8ocG7raRZhNazDpt0Dd9geRpMUQohjqyFmmVVyVAzKfDpSUIhJ8Scuu2VaUF5qmQo+dkQ== X-Received: by 2002:a63:2f45:: with SMTP id v66mr38263141pgv.263.1570552442104; Tue, 08 Oct 2019 09:34:02 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id 18sm17702551pfp.100.2019.10.08.09.34.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2019 09:34:00 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Tue, 8 Oct 2019 09:33:49 -0700 Message-Id: <20191008163350.20779-5-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191008163350.20779-1-stephen@networkplumber.org> References: <20190928003758.18489-1-stephen@networkplumber.org> <20191008163350.20779-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v6 4/5] mbuf: add a pktmbuf copy routine 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" This is a commonly used operation that surprisingly the DPDK has not supported. The new rte_pktmbuf_copy does a deep copy of packet. This is a complete copy including meta-data. It handles the case where the source mbuf comes from a pool with larger data area than the destination pool. The routine also has options for skipping data, or truncating at a fixed length. This patch also introduces internal inline to copy the metadata fields of mbuf. Signed-off-by: Stephen Hemminger Acked-by: Olivier Matz --- lib/librte_mbuf/rte_mbuf.c | 77 ++++++++++++++++++++++++++++ lib/librte_mbuf/rte_mbuf.h | 55 ++++++++++++++++---- lib/librte_mbuf/rte_mbuf_version.map | 1 + 3 files changed, 122 insertions(+), 11 deletions(-) diff --git a/lib/librte_mbuf/rte_mbuf.c b/lib/librte_mbuf/rte_mbuf.c index 9a1a1b5f9468..0236fba76bbc 100644 --- a/lib/librte_mbuf/rte_mbuf.c +++ b/lib/librte_mbuf/rte_mbuf.c @@ -321,6 +321,83 @@ __rte_pktmbuf_linearize(struct rte_mbuf *mbuf) return 0; } +/* Create a deep copy of mbuf */ +struct rte_mbuf * +rte_pktmbuf_copy(const struct rte_mbuf *m, struct rte_mempool *mp, + uint32_t off, uint32_t len) +{ + const struct rte_mbuf *seg = m; + struct rte_mbuf *mc, *m_last, **prev; + + /* garbage in check */ + __rte_mbuf_sanity_check(m, 1); + + /* check for request to copy at offset past end of mbuf */ + if (unlikely(off >= m->pkt_len)) + return NULL; + + mc = rte_pktmbuf_alloc(mp); + if (unlikely(mc == NULL)) + return NULL; + + /* truncate requested length to available data */ + if (len > m->pkt_len - off) + len = m->pkt_len - off; + + __rte_pktmbuf_copy_hdr(mc, m); + + /* copied mbuf is not indirect or external */ + mc->ol_flags = m->ol_flags & ~(IND_ATTACHED_MBUF|EXT_ATTACHED_MBUF); + + prev = &mc->next; + m_last = mc; + while (len > 0) { + uint32_t copy_len; + + /* skip leading mbuf segments */ + while (off >= seg->data_len) { + off -= seg->data_len; + seg = seg->next; + } + + /* current buffer is full, chain a new one */ + if (rte_pktmbuf_tailroom(m_last) == 0) { + m_last = rte_pktmbuf_alloc(mp); + if (unlikely(m_last == NULL)) { + rte_pktmbuf_free(mc); + return NULL; + } + ++mc->nb_segs; + *prev = m_last; + prev = &m_last->next; + } + + /* + * copy the min of data in input segment (seg) + * vs space available in output (m_last) + */ + copy_len = RTE_MIN(seg->data_len - off, len); + if (copy_len > rte_pktmbuf_tailroom(m_last)) + copy_len = rte_pktmbuf_tailroom(m_last); + + /* append from seg to m_last */ + rte_memcpy(rte_pktmbuf_mtod_offset(m_last, char *, + m_last->data_len), + rte_pktmbuf_mtod_offset(seg, char *, off), + copy_len); + + /* update offsets and lengths */ + m_last->data_len += copy_len; + mc->pkt_len += copy_len; + off += copy_len; + len -= copy_len; + } + + /* garbage out check */ + __rte_mbuf_sanity_check(mc, 1); + return mc; +} + /* dump a mbuf on console */ void rte_pktmbuf_dump(FILE *f, const struct rte_mbuf *m, unsigned dump_len) diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index 6133f12172ae..fb0849ac1473 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -1684,6 +1684,19 @@ rte_pktmbuf_attach_extbuf(struct rte_mbuf *m, void *buf_addr, */ #define rte_pktmbuf_detach_extbuf(m) rte_pktmbuf_detach(m) +/* internal */ +static inline void +__rte_pktmbuf_copy_hdr(struct rte_mbuf *mdst, const struct rte_mbuf *msrc) +{ + mdst->port = msrc->port; + mdst->vlan_tci = msrc->vlan_tci; + mdst->vlan_tci_outer = msrc->vlan_tci_outer; + mdst->tx_offload = msrc->tx_offload; + mdst->hash = msrc->hash; + mdst->packet_type = msrc->packet_type; + mdst->timestamp = msrc->timestamp; +} + /** * Attach packet mbuf to another packet mbuf. * @@ -1721,23 +1734,17 @@ static inline void rte_pktmbuf_attach(struct rte_mbuf *mi, struct rte_mbuf *m) mi->ol_flags = m->ol_flags | IND_ATTACHED_MBUF; } - mi->buf_iova = m->buf_iova; - mi->buf_addr = m->buf_addr; - mi->buf_len = m->buf_len; + __rte_pktmbuf_copy_hdr(mi, m); mi->data_off = m->data_off; mi->data_len = m->data_len; - mi->port = m->port; - mi->vlan_tci = m->vlan_tci; - mi->vlan_tci_outer = m->vlan_tci_outer; - mi->tx_offload = m->tx_offload; - mi->hash = m->hash; + mi->buf_iova = m->buf_iova; + mi->buf_addr = m->buf_addr; + mi->buf_len = m->buf_len; mi->next = NULL; mi->pkt_len = mi->data_len; mi->nb_segs = 1; - mi->packet_type = m->packet_type; - mi->timestamp = m->timestamp; __rte_mbuf_sanity_check(mi, 1); __rte_mbuf_sanity_check(m, 0); @@ -1908,7 +1915,7 @@ static inline void rte_pktmbuf_free(struct rte_mbuf *m) } /** - * Creates a "clone" of the given packet mbuf. + * Create a "clone" of the given packet mbuf. * * Walks through all segments of the given packet mbuf, and for each of them: * - Creates a new packet mbuf from the given pool. @@ -1927,6 +1934,32 @@ static inline void rte_pktmbuf_free(struct rte_mbuf *m) struct rte_mbuf * rte_pktmbuf_clone(struct rte_mbuf *md, struct rte_mempool *mp); +/** + * Create a full copy of a given packet mbuf. + * + * Copies all the data from a given packet mbuf to a newly allocated + * set of mbufs. The private data are is not copied. + * + * @param m + * The packet mbuf to be copiedd. + * @param mp + * The mempool from which the "clone" mbufs are allocated. + * @param offset + * The number of bytes to skip before copying. + * If the mbuf does not have that many bytes, it is an error + * and NULL is returned. + * @param length + * The upper limit on bytes to copy. Passing UINT32_MAX + * means all data (after offset). + * @return + * - The pointer to the new "clone" mbuf on success. + * - NULL if allocation fails. + */ +__rte_experimental +struct rte_mbuf * +rte_pktmbuf_copy(const struct rte_mbuf *m, struct rte_mempool *mp, + uint32_t offset, uint32_t length); + /** * Adds given value to the refcnt of all packet mbuf segments. * diff --git a/lib/librte_mbuf/rte_mbuf_version.map b/lib/librte_mbuf/rte_mbuf_version.map index ff5c18a5559b..a50dcb6db9ec 100644 --- a/lib/librte_mbuf/rte_mbuf_version.map +++ b/lib/librte_mbuf/rte_mbuf_version.map @@ -57,4 +57,5 @@ EXPERIMENTAL { global: rte_mbuf_check; + rte_pktmbuf_copy; } DPDK_18.08; From patchwork Tue Oct 8 16:33:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 60711 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 4D7181DFE3; Tue, 8 Oct 2019 18:34:12 +0200 (CEST) Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) by dpdk.org (Postfix) with ESMTP id 12B831D42B for ; Tue, 8 Oct 2019 18:34:05 +0200 (CEST) Received: by mail-pf1-f194.google.com with SMTP id x127so11066677pfb.7 for ; Tue, 08 Oct 2019 09:34:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LYiypZaEWrK3SD786cwpvQB7zDQwprOL/UnAs+oU7Sc=; b=lZM+K/VHFXuj/+XC2y315Utc9lhl3H0IVnzp8qsqkiBXWT3sAXXpkPShVpxuy3ajjs ikUZ5JUzLZ7y6QuGpJjdGAlpcMrKKZdBlkPyV3p+ivMQgxMJIxWTUiohpiEoINThnWvU t26o3zqOCbPoWy6jlzZHX5DcS1cPRsWa0Z/pxU4mOJ+UGqUcw6gOOAeRNv/qgURxODxo aa2i7gQir5g9rCDpD+ysU0gPWsmiV+V4AAQrUh/Iw3vJhWpRJden7nSekllvGTxBkJcv hcS4toFtHrea9mbu8io4SKU7M/LT6pi9ehQZc0sR6Mpre9lq3tlfZtj92vm17JqojzIc VavQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LYiypZaEWrK3SD786cwpvQB7zDQwprOL/UnAs+oU7Sc=; b=t2Vl9bKQ1aPQT9FaJFD9e54h3QFXFpznjpzsao5lsIfr63jmwG32X6PcyFU/Uzcl25 u7/XEQUyJWZJxUM5rsTORo69HRJTa2Gj09j49eMSE7Bf5TBBG8JiGBU0xi828bhoDTdv Iy9fQcFzCZPuT4IHnc/zLPK/bIrnkeXT1UTYwOQTzq/u6OmYdk5TtqQK+qh5FgwlwTmt d44i72kUZ7NIUQrPqfCcsE0EDPwoqud3FAiUOPTh0lGOwuk5x/EQ9z4DzcvTLvIOv6+x r0DcLSTdgPErs37o4xdsep3pcxXPjjrG0TwPGsRGuCiaQQ7F4fd4RoHjmrxpbpcNo/92 hlyg== X-Gm-Message-State: APjAAAVYjH+FPwEoliwd9T90YDOaYQ2wPuibjg4m1UQIN/DKx5zgeau/ +GZr6zmaZb0LO/eVRXhgtr6kGVt9pLzQSQ== X-Google-Smtp-Source: APXvYqxWvNHd+nBMYOx3/dtoIBBIba0t+iGaHNUzOBesxY+mpdVltA3AjcEExyZ4xZypmq9WaYegFw== X-Received: by 2002:a63:e14:: with SMTP id d20mr36901303pgl.33.1570552443745; Tue, 08 Oct 2019 09:34:03 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id 18sm17702551pfp.100.2019.10.08.09.34.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2019 09:34:02 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Olivier Matz Date: Tue, 8 Oct 2019 09:33:50 -0700 Message-Id: <20191008163350.20779-6-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191008163350.20779-1-stephen@networkplumber.org> References: <20190928003758.18489-1-stephen@networkplumber.org> <20191008163350.20779-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v6 5/5] mbuf: add pktmbuf copy test 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" New test for rte_pktmbuf_copy based of the clone tests. Signed-off-by: Stephen Hemminger Acked-by: Olivier Matz --- app/test/test_mbuf.c | 157 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) diff --git a/app/test/test_mbuf.c b/app/test/test_mbuf.c index aafad0cf6206..0df6b0e12a39 100644 --- a/app/test/test_mbuf.c +++ b/app/test/test_mbuf.c @@ -399,6 +399,158 @@ testclone_testupdate_testdetach(struct rte_mempool *pktmbuf_pool) return -1; } +static int +test_pktmbuf_copy(struct rte_mempool *pktmbuf_pool) +{ + struct rte_mbuf *m = NULL; + struct rte_mbuf *copy = NULL; + struct rte_mbuf *copy2 = NULL; + struct rte_mbuf *clone = NULL; + unaligned_uint32_t *data; + + /* alloc a mbuf */ + m = rte_pktmbuf_alloc(pktmbuf_pool); + if (m == NULL) + GOTO_FAIL("ooops not allocating mbuf"); + + if (rte_pktmbuf_pkt_len(m) != 0) + GOTO_FAIL("Bad length"); + + rte_pktmbuf_append(m, sizeof(uint32_t)); + data = rte_pktmbuf_mtod(m, unaligned_uint32_t *); + *data = MAGIC_DATA; + + /* copy the allocated mbuf */ + copy = rte_pktmbuf_copy(m, pktmbuf_pool, 0, UINT32_MAX); + if (copy == NULL) + GOTO_FAIL("cannot copy data\n"); + + if (rte_pktmbuf_pkt_len(copy) != sizeof(uint32_t)) + GOTO_FAIL("copy length incorrect\n"); + + if (rte_pktmbuf_data_len(copy) != sizeof(uint32_t)) + GOTO_FAIL("copy data length incorrect\n"); + + data = rte_pktmbuf_mtod(copy, unaligned_uint32_t *); + if (*data != MAGIC_DATA) + GOTO_FAIL("invalid data in copy\n"); + + /* free the copy */ + rte_pktmbuf_free(copy); + copy = NULL; + + /* same test with a cloned mbuf */ + clone = rte_pktmbuf_clone(m, pktmbuf_pool); + if (clone == NULL) + GOTO_FAIL("cannot clone data\n"); + + if (!RTE_MBUF_CLONED(clone)) + GOTO_FAIL("clone did not give a cloned mbuf\n"); + + copy = rte_pktmbuf_copy(clone, pktmbuf_pool, 0, UINT32_MAX); + if (copy == NULL) + GOTO_FAIL("cannot copy cloned mbuf\n"); + + if (RTE_MBUF_CLONED(copy)) + GOTO_FAIL("copy of clone is cloned?\n"); + + if (rte_pktmbuf_pkt_len(copy) != sizeof(uint32_t)) + GOTO_FAIL("copy clone length incorrect\n"); + + if (rte_pktmbuf_data_len(copy) != sizeof(uint32_t)) + GOTO_FAIL("copy clone data length incorrect\n"); + + data = rte_pktmbuf_mtod(copy, unaligned_uint32_t *); + if (*data != MAGIC_DATA) + GOTO_FAIL("invalid data in clone copy\n"); + rte_pktmbuf_free(clone); + rte_pktmbuf_free(copy); + copy = NULL; + clone = NULL; + + + /* same test with a chained mbuf */ + m->next = rte_pktmbuf_alloc(pktmbuf_pool); + if (m->next == NULL) + GOTO_FAIL("Next Pkt Null\n"); + m->nb_segs = 2; + + rte_pktmbuf_append(m->next, sizeof(uint32_t)); + m->pkt_len = 2 * sizeof(uint32_t); + data = rte_pktmbuf_mtod(m->next, unaligned_uint32_t *); + *data = MAGIC_DATA + 1; + + copy = rte_pktmbuf_copy(m, pktmbuf_pool, 0, UINT32_MAX); + if (copy == NULL) + GOTO_FAIL("cannot copy data\n"); + + if (rte_pktmbuf_pkt_len(copy) != 2 * sizeof(uint32_t)) + GOTO_FAIL("chain copy length incorrect\n"); + + if (rte_pktmbuf_data_len(copy) != 2 * sizeof(uint32_t)) + GOTO_FAIL("chain copy data length incorrect\n"); + + data = rte_pktmbuf_mtod(copy, unaligned_uint32_t *); + if (data[0] != MAGIC_DATA || data[1] != MAGIC_DATA + 1) + GOTO_FAIL("invalid data in copy\n"); + + rte_pktmbuf_free(copy2); + + /* test offset copy */ + copy2 = rte_pktmbuf_copy(copy, pktmbuf_pool, + sizeof(uint32_t), UINT32_MAX); + if (copy2 == NULL) + GOTO_FAIL("cannot copy the copy\n"); + + if (rte_pktmbuf_pkt_len(copy2) != sizeof(uint32_t)) + GOTO_FAIL("copy with offset, length incorrect\n"); + + if (rte_pktmbuf_data_len(copy2) != sizeof(uint32_t)) + GOTO_FAIL("copy with offset, data length incorrect\n"); + + data = rte_pktmbuf_mtod(copy2, unaligned_uint32_t *); + if (data[0] != MAGIC_DATA + 1) + GOTO_FAIL("copy with offset, invalid data\n"); + + rte_pktmbuf_free(copy2); + + /* test truncation copy */ + copy2 = rte_pktmbuf_copy(copy, pktmbuf_pool, + 0, sizeof(uint32_t)); + if (copy2 == NULL) + GOTO_FAIL("cannot copy the copy\n"); + + if (rte_pktmbuf_pkt_len(copy2) != sizeof(uint32_t)) + GOTO_FAIL("copy with truncate, length incorrect\n"); + + if (rte_pktmbuf_data_len(copy2) != sizeof(uint32_t)) + GOTO_FAIL("copy with truncate, data length incorrect\n"); + + data = rte_pktmbuf_mtod(copy2, unaligned_uint32_t *); + if (data[0] != MAGIC_DATA) + GOTO_FAIL("copy with truncate, invalid data\n"); + + /* free mbuf */ + rte_pktmbuf_free(m); + rte_pktmbuf_free(copy); + rte_pktmbuf_free(copy2); + + m = NULL; + copy = NULL; + copy2 = NULL; + printf("%s ok\n", __func__); + return 0; + +fail: + if (m) + rte_pktmbuf_free(m); + if (copy) + rte_pktmbuf_free(copy); + if (copy2) + rte_pktmbuf_free(copy2); + return -1; +} + static int test_attach_from_different_pool(struct rte_mempool *pktmbuf_pool, struct rte_mempool *pktmbuf_pool2) @@ -1203,6 +1355,11 @@ test_mbuf(void) goto err; } + if (test_pktmbuf_copy(pktmbuf_pool) < 0) { + printf("test_pktmbuf_copy() failed.\n"); + goto err; + } + if (test_attach_from_different_pool(pktmbuf_pool, pktmbuf_pool2) < 0) { printf("test_attach_from_different_pool() failed\n"); goto err;