From patchwork Sat Sep 28 00:37:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 60080 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 3A54C1B9B5; Sat, 28 Sep 2019 02:38:07 +0200 (CEST) Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) by dpdk.org (Postfix) with ESMTP id F40C22C4F for ; Sat, 28 Sep 2019 02:38:03 +0200 (CEST) Received: by mail-pl1-f193.google.com with SMTP id s17so1684532plp.6 for ; Fri, 27 Sep 2019 17:38: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=Q4INw0jXclEiki3qquDLRi7spTdZl6ftU0aD9i1ySi8=; b=jRiYQxjPWDwdvbmcAadyjKzeHVxUiL8r1f1b9uu6BQx87RihhSSMHNkVs1dK+fijbu suBysOFWBiMt3ikTjslfELulpdHaXCoIP3ozt8UG+HVYL9zxXYwthEUTjGF4vBYvpWZA YjQQOlK1BAK1BUPHFQ6ZQOqKa9ZZob1FEnZWUnAHuFmH3b75cmru4PyZWtYaogIJndU4 +M6rZwdHwwY7xAtwHEa9fQ+Ym8dnSZCMkWkb8ZFYESAwFptKGihDWuer/2dcX/kYcmMW CgLnNIlNbWnp4S5wlq4uEUO4fMjWUEJU6V6UeYlgOSO6u12XZBiay4IeT30plv/B3n4g L1zA== 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=Q4INw0jXclEiki3qquDLRi7spTdZl6ftU0aD9i1ySi8=; b=kyPx2vzY3nu9JCMjUPbwuGnyL4W2LzCsxPPMGCZAlNlEzTeSexNXyoo7WOjcJKXEJr xPO3g558mYI7OJQaT5oYr6L/fVwZUCnLbsBYjpyEa6VsXwq6oxREp3FxaKJmhyRr71Ft MG4K3eLfLNm0I7763UHo8/TzYIQNL6RXRIMEsICpeIoiCC8+BRjOXymNZVB2UdLJ5SAY ThgHmuTs8f6YdWzfcd9+gk+CfszM3LlMqrrUnBgKo2GekfvBRDWoSAco/MVLR7iDahiA QjbJ7JZKqoCSdAy6mFI086iAVUg3MGsRjBtQD8cwBfpgm9l9NVFZHWDBf/gsIJTKponx 8Drw== X-Gm-Message-State: APjAAAXt4DKr1n8ye24KeCdwC3WqGOx8kMhLPOJDJbHsqZ8xpSlP7pvs 3Oh2XlmHtFjbqfrGlW6PynBKP+WcxnM= X-Google-Smtp-Source: APXvYqwrVnGFXoCshKNBcioxvSoM7q+b/jPon8DcoUgOXCRyCQUd9e4NWXjoY+Mlh/WXozqnP3oqyg== X-Received: by 2002:a17:902:aa4a:: with SMTP id c10mr7556185plr.340.1569631082571; Fri, 27 Sep 2019 17:38:02 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id t13sm3494942pfh.12.2019.09.27.17.38.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Sep 2019 17:38:02 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Fri, 27 Sep 2019 17:37:54 -0700 Message-Id: <20190928003758.18489-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190928003758.18489-1-stephen@networkplumber.org> References: <20190928003758.18489-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 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 --- 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 Sat Sep 28 00:37:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 60081 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 293E31BE85; Sat, 28 Sep 2019 02:38:10 +0200 (CEST) Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by dpdk.org (Postfix) with ESMTP id 6EAF12C4F for ; Sat, 28 Sep 2019 02:38:04 +0200 (CEST) Received: by mail-pf1-f193.google.com with SMTP id q5so2414941pfg.13 for ; Fri, 27 Sep 2019 17:38: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=cSmw8GHMDLE+3FOC4N1l6sIkSxQJSZTYxYZ1VcOa21w=; b=ZesqafY2yWDOlPIvftGz6kWYsSK0jXgErr9/ERq9zKfOFlhUFEfNy9ZpfSqd8IkCFY hsTCkbQ6ZNK0sIFoonm2Y0VtiDQgIoj8n3z3089OYQ/Oz5QxviXVf4mX/TosNzI8xbPd W/cZtD6CWFhl4EzoOLqCtIzBE9EL+GPlvRGqmQ7of7QNU0Sk1E4jYrTbbYgm2zJXRhxf aWm7FL2X/ticbV/OyiGoy3KMKpRYYQTmsMqW+/xxSOw81Km8up5AFSGvwJ8UwQD67Qxe oeyG2UQ93dH7WO8zAJFg0WgmqfeLzSYB0t96TQhm7MkW1Zz4rJ8raqDE4ryKqPu7qLVQ mcPw== 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=cSmw8GHMDLE+3FOC4N1l6sIkSxQJSZTYxYZ1VcOa21w=; b=RKwGgFzWUntUfVYZ4mod0LF0YLJ2ybJ81fCe/7j+b+Y6a6ZQrzH0ySJUJosTrPvJa+ ri39XEMUvIz/uohGXYMELG/6baNVTnoEM7w6G73ySD8hBNRhogRTtqX2JvWJdbQ6uB6/ o4NmDhsTvH4mTzV8mPwrrRXWTjYNySA5W6jsUn3l02teONnWIXGkOLGmlmQOOcnxajV7 KJ+73bGW0PGjiG9pT08UYQXw2WEiEutYLcgWx8iggX6s4kZ2aSEZpUR0BOeM13MMKHqf 84KZePvWJLH1jE/K0MByJVLBuyOEjNSpTNEhapANDEV/EKbmdgKE9A+fWauuRC0QxJOq 19/A== X-Gm-Message-State: APjAAAXqprZAU7VDaojxGoE7LqANF58z3xyCOiFX0ir9h0C3K0Zhpgwm c/mWzEPmIlW/kT7X+FWYxTHaBN/mqkc= X-Google-Smtp-Source: APXvYqzC0TiCdNU2j8wpFlQEGnSIMRTvPiEHVEVZyEHyxuPmVPKYCV3yJVhgMQtBU/a2tDQrB6Ti3A== X-Received: by 2002:a62:83cb:: with SMTP id h194mr7759567pfe.66.1569631083296; Fri, 27 Sep 2019 17:38:03 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id t13sm3494942pfh.12.2019.09.27.17.38.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Sep 2019 17:38:02 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Fri, 27 Sep 2019 17:37:55 -0700 Message-Id: <20190928003758.18489-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190928003758.18489-1-stephen@networkplumber.org> References: <20190928003758.18489-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 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 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 --- lib/librte_mbuf/rte_mbuf.c | 40 ++++++++++++++++++++++++++++ lib/librte_mbuf/rte_mbuf.h | 40 ++-------------------------- lib/librte_mbuf/rte_mbuf_version.map | 6 +++++ 3 files changed, 48 insertions(+), 38 deletions(-) diff --git a/lib/librte_mbuf/rte_mbuf.c b/lib/librte_mbuf/rte_mbuf.c index 37718d49c148..922bce6f0f93 100644 --- a/lib/librte_mbuf/rte_mbuf.c +++ b/lib/librte_mbuf/rte_mbuf.c @@ -245,6 +245,46 @@ 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; + + 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; +} + /* 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..d25356b58cba 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -2412,44 +2412,8 @@ rte_validate_tx_offload(const struct rte_mbuf *m) * - 0, on success * - -1, on error */ -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; -} +int +rte_pktmbuf_linearize(struct rte_mbuf *mbuf); /** * Dump an mbuf structure to a file. diff --git a/lib/librte_mbuf/rte_mbuf_version.map b/lib/librte_mbuf/rte_mbuf_version.map index 2662a37bf674..7af410a4f687 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_18.11 { + global: + + rte_pktmbuf_linearize; +} DPDK_18.08; + EXPERIMENTAL { global: From patchwork Sat Sep 28 00:37:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 60082 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 7CF291BE92; Sat, 28 Sep 2019 02:38:12 +0200 (CEST) Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by dpdk.org (Postfix) with ESMTP id 299961B948 for ; Sat, 28 Sep 2019 02:38:05 +0200 (CEST) Received: by mail-pf1-f195.google.com with SMTP id y5so2440956pfo.4 for ; Fri, 27 Sep 2019 17:38:05 -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=90mHwihb7xMUiaegFDWqrOBXKk/uRYtwHzVS8GpuEk8=; b=Ym4JrbANbpoSR17acvpPNZQYy83yAzDSJzUtNM+LSBo/Xf0zxeFI1UvEYL6zu0hN/o XYj6l13myqzbu0z+O5nBjYmsZtS+cUmAmOGAQhaeKxc0rnODpOz9RuzgoixosFPq9wkC TwwVS7g0sf3jVmdosy5Fdzj9o7HnCGKGFlbY/wmAB2Q8YrvwHOlDkZ4yLugLWKPm1vnM p0PovZxeau7UP2BclaL9clpswDnbWuw5MSNUTG1SdCqWSvthuqvJFmTCDjG3NcBjK18j kg2ZnHOFfdpbq5d6D/WdO98JA0wzJhPmuoSfUB7FVETewquT8CGJpqbn/BelOG0/oxCq IVPQ== 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=90mHwihb7xMUiaegFDWqrOBXKk/uRYtwHzVS8GpuEk8=; b=U1/PUfGUIDMrBhrGnJPAb4FfR7SJ9a/0g3sIJFkMf9CU7zQXjYjY2ImJk9fFDIFun5 v+w+PCVHVQj6e8ujDo/yiGA0ZlagaOVNVahu4xFeDfSOnfDv/xljKCWtulpuAMyEzhhN Qr//6jYiu0MBm+lSUfWmWtToULtzpkAVRRyPKwwW1LFsSmmwjp5jU++F/ju8QGBfgJ+0 i/U+KH6atPaIEKAebh0hbUpX83K/8PneLDriZHAT/zw7msTBmmrwv11BH97QiqAvIE/V DgKbzpW8VVuS3pdQocQHvDaDGrqz1SCYZKk7lLpg8zA8NoG5PLhevCW4Tksrekr7Tcc6 ofqg== X-Gm-Message-State: APjAAAWPRwVjKMu649r9wh9/Pz9jOoraVSHnLUIk1sUVYXGH5wf4rJC8 lDjQ7Yb76LzJ+3Sziq9ZX2UbKKS+WTs= X-Google-Smtp-Source: APXvYqxH+wcVavVK5o1zp/NYIgvH2w5hRDmdhag+MypkJ6Ignzyn/JoaGMIXB28yJHIv6novN3WvDw== X-Received: by 2002:a63:ab05:: with SMTP id p5mr12264336pgf.414.1569631084781; Fri, 27 Sep 2019 17:38:04 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id t13sm3494942pfh.12.2019.09.27.17.38.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Sep 2019 17:38:03 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Fri, 27 Sep 2019 17:37:56 -0700 Message-Id: <20190928003758.18489-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190928003758.18489-1-stephen@networkplumber.org> References: <20190928003758.18489-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 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 --- 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 922bce6f0f93..12d0258a120d 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 d25356b58cba..a6e78e4ea7a6 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 7af410a4f687..9cc43e24bfa4 100644 --- a/lib/librte_mbuf/rte_mbuf_version.map +++ b/lib/librte_mbuf/rte_mbuf_version.map @@ -49,6 +49,7 @@ DPDK_18.08 { DPDK_18.11 { global: + rte_pktmbuf_clone; rte_pktmbuf_linearize; } DPDK_18.08; From patchwork Sat Sep 28 00:37:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 60083 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 2F3201BE96; Sat, 28 Sep 2019 02:38:15 +0200 (CEST) Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by dpdk.org (Postfix) with ESMTP id 04A071B948 for ; Sat, 28 Sep 2019 02:38:07 +0200 (CEST) Received: by mail-pg1-f195.google.com with SMTP id i30so4326683pgl.0 for ; Fri, 27 Sep 2019 17:38:06 -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=YGTy358oZ3HU/DV9pSNDqY3tMnkYEw+Q0RgMPLx2tFk=; b=zU15/1U9+oJVsGskyI7DMTPU0xR0wE+cA+O1+0XgoKRXiPDhrmg2P1vG1mxpVG1RqC 8u72bIgHERu7xdL3cUuBRrAz+E8964wzIE0gqB1bnZdUmy2TVRLUBajLgJfSBljee8fj XVrjFFQl4KtQ7zT55uA3cBnKs4DpXemn8l5RWXG0N6idedlhL+Py6UPaiLpv0fOF75wO QxgS9aoyi6zIom6Swu8xeh34YoLZL6UqajU+JpFgXjJ2GV59ox7haCCWf3TatFt6CoAc podvEvtbgZqAQ7/Qtd9mDl196uBbZa9DmABxbmnPLYktDe3SXSbxphv1HYkPb2ZlxwDy JCiA== 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=YGTy358oZ3HU/DV9pSNDqY3tMnkYEw+Q0RgMPLx2tFk=; b=QPLACT1g4+xx+0FQL2TgmSkkhT0Hok8ChsKd6V6/c1HnagyIORKflvYFUoOtG+ViGO fRoXk9Tdo4UR59TMzcT6TBso+drckcyuftccbQUcDwakitdaQjwzVvUoD8rR6Dz23w/M juTj1UlnfKdLGVFlG8b+2c3U/1famVlDekwTvSRx7MpTj5w+DF8VtBx8sJTiComjMcVt zFQ2X5PcKQDfFY6Zm5TazghF+BU8pWUiVKZLZKn3eLonEcWDo1CGriczzMHGaOqTZv6Z 2vl9Pteom+85kY460tPfapgzcCCGqL8Rs4tlItWQKo2488jHyp29KseVrPrvxY9IQ6hy P5Cw== X-Gm-Message-State: APjAAAUJ5KfPQTecqcIgXLvnR5qwd/PZLeoBh8jwWtUkJiR1YyasNoyE EWLi3v+/bxttjfLJoi1FUBZvzoHjqwI= X-Google-Smtp-Source: APXvYqxika6pmJghabtkb23aJLMINerAOmrhHCqKXgrSDuzuYDlzcD3X1N6AlbstU1vzhJN7R1S3ZQ== X-Received: by 2002:a62:fb06:: with SMTP id x6mr7842606pfm.186.1569631085922; Fri, 27 Sep 2019 17:38:05 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id t13sm3494942pfh.12.2019.09.27.17.38.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Sep 2019 17:38:05 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Fri, 27 Sep 2019 17:37:57 -0700 Message-Id: <20190928003758.18489-5-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190928003758.18489-1-stephen@networkplumber.org> References: <20190928003758.18489-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 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. Signed-off-by: Stephen Hemminger --- lib/librte_mbuf/rte_mbuf.c | 70 ++++++++++++++++++++++++++++ lib/librte_mbuf/rte_mbuf.h | 26 +++++++++++ lib/librte_mbuf/rte_mbuf_version.map | 1 + 3 files changed, 97 insertions(+) diff --git a/lib/librte_mbuf/rte_mbuf.c b/lib/librte_mbuf/rte_mbuf.c index 12d0258a120d..6888d6bd5dfc 100644 --- a/lib/librte_mbuf/rte_mbuf.c +++ b/lib/librte_mbuf/rte_mbuf.c @@ -324,6 +324,76 @@ 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; + + if (unlikely(off >= m->pkt_len)) + return NULL; + + mc = rte_pktmbuf_alloc(mp); + if (unlikely(mc == NULL)) + return NULL; + + if (len > m->pkt_len - off) + len = m->pkt_len - off; + + /* clone meta data from original */ + mc->port = m->port; + mc->vlan_tci = m->vlan_tci; + mc->vlan_tci_outer = m->vlan_tci_outer; + mc->tx_offload = m->tx_offload; + mc->hash = m->hash; + mc->packet_type = m->packet_type; + mc->timestamp = m->timestamp; + + prev = &mc->next; + m_last = mc; + while (len > 0) { + uint32_t copy_len; + + 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_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); + + m_last->data_len += copy_len; + mc->pkt_len += copy_len; + off += copy_len; + len -= copy_len; + } + + __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 a6e78e4ea7a6..77266a07c75b 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -1927,6 +1927,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); +/** + * Creates a full copy of a given packet mbuf. + * + * Copies all the data from a given packet mbuf to a newly allocated + * set of mbufs. + * + * @param m + * The packet mbuf to be cloned. + * @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 9cc43e24bfa4..3742ed114e7c 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 Sat Sep 28 00:37:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 60084 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 911891BEAE; Sat, 28 Sep 2019 02:38:17 +0200 (CEST) Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by dpdk.org (Postfix) with ESMTP id 6B3941B9BF for ; Sat, 28 Sep 2019 02:38:08 +0200 (CEST) Received: by mail-pf1-f193.google.com with SMTP id y5so2440980pfo.4 for ; Fri, 27 Sep 2019 17:38:08 -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=hnJVNme230AHorC9MqsxxOvVRW7V8JTUGHH+CXxU7nQ=; b=PbXUZfpoa82zQdCVAVle/pqWCVwCwa2OINPuNqvwLCJ53Y7Q+StHx/g6aCajXzLyH9 5bY0CEQ9bsu5Tpgt0GMqa41JwjBSBmKZlI3OjHeVA0Tl8icnv02Rbnw/D/pw/jJDw2+4 Q69H7NnNWdTyzZHu56u3SZPuIs0awhefSw2Y9yS3BQHT7ezN3/FWiWrxsFyrSOJihkBO UW3zKVVumo6B+VUeYnYEV9E26vIXriJ0SNJ3/GVlKFCM61nRK16AdZiQgga4hv/mq45x yaYyBDCO750d55NXXsuM3Faeb4WEHeYGZxecIbRyMcn1OjqB4giiTcG2529iaj9Tt9HX vjwA== 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=hnJVNme230AHorC9MqsxxOvVRW7V8JTUGHH+CXxU7nQ=; b=TDvkHStZYp08kK2ABJnwBStTmth7Dhoge9nl3TLbsmSp/H7luKIy+cYuIq6A4+OCom tpc+kcJA862lgmE4prOOdq1SfMMOt9z66sVqFE+hXJ3QOSqCeWyN3eLJaN+xumG4rONt fcK0k5YA4ifEWOAkc6XagiWc+DW1RkK6nW04LIRzqBWC52NOMbOqqsnHlAcc8mxZhYga 1+y07DXpJZ04I2SJaEFteL9aHPc0iizczkoXiTRSquDZ0bLd8Pw/0TQ+Rn6ZPDVuD4nm U79gigQfFki9UZzPa8lRmkQTuXC4h8PoL5o5nXPAculgsuwKVUTgDwLfBFV1GDIL93eh GJ9A== X-Gm-Message-State: APjAAAWtRBkmqOzNHBPHYBiC7We/PVs5lWM5qde/PgXXI/gOJlKXtZXX Gk8anHDOHcg5mCzH1i6e/0/NnCVUFlM= X-Google-Smtp-Source: APXvYqyJfQOQX8LA+ml+1DTRbyTmq2qICunEJvpDIFViNOvoN2YJ+DswjS/jmdRNCSprXSjgMqqMuA== X-Received: by 2002:a63:e444:: with SMTP id i4mr12381063pgk.45.1569631087061; Fri, 27 Sep 2019 17:38:07 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id t13sm3494942pfh.12.2019.09.27.17.38.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Sep 2019 17:38:06 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Fri, 27 Sep 2019 17:37:58 -0700 Message-Id: <20190928003758.18489-6-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190928003758.18489-1-stephen@networkplumber.org> References: <20190928003758.18489-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 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 --- app/test/test_mbuf.c | 126 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) diff --git a/app/test/test_mbuf.c b/app/test/test_mbuf.c index aafad0cf6206..49c3a5f7893c 100644 --- a/app/test/test_mbuf.c +++ b/app/test/test_mbuf.c @@ -399,6 +399,127 @@ 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; + 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 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 +1324,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;