From patchwork Wed Sep 11 13:29:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Obrembski X-Patchwork-Id: 1160980 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=intel.com Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46T2vX4WMFz9s00 for ; Wed, 11 Sep 2019 23:35:02 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id C466C13FF; Wed, 11 Sep 2019 13:31:27 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id B364013F5 for ; Wed, 11 Sep 2019 13:31:25 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 1D8D189C for ; Wed, 11 Sep 2019 13:31:25 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Sep 2019 06:31:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,493,1559545200"; d="scan'208";a="214684336" Received: from mobrembx-mobl.ger.corp.intel.com ([10.103.104.26]) by fmsmga002.fm.intel.com with ESMTP; 11 Sep 2019 06:31:23 -0700 From: Michal Obrembski To: dev@openvswitch.org Date: Wed, 11 Sep 2019 15:29:54 +0200 Message-Id: <20190911133003.720-6-michalx.obrembski@intel.com> X-Mailer: git-send-email 2.23.0.windows.1 In-Reply-To: <20190911133003.720-1-michalx.obrembski@intel.com> References: <20190911133003.720-1-michalx.obrembski@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Michael Qiu Subject: [ovs-dev] [PATCH v16 05/14] dp-packet: copy data from multi-seg. DPDK mbuf X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org From: Michael Qiu When doing packet clone, if packet source is from DPDK driver, multi-segment must be considered, and copy the segment's data one by one. Also, lots of DPDK mbuf's info is missed during a copy, like packet type, ol_flags, etc. That information is very important for DPDK to do packets processing. Co-authored-by: Mark Kavanagh Co-authored-by: Tiago Lam Signed-off-by: Michael Qiu Signed-off-by: Mark Kavanagh Signed-off-by: Tiago Lam Acked-by: Eelco Chaudron --- lib/dp-packet.c | 40 ++++++++++++++++++++++++++++++++++++---- lib/dp-packet.h | 29 +++++++++++++++++++++++++++++ lib/netdev-dpdk.c | 1 + 3 files changed, 66 insertions(+), 4 deletions(-) diff --git a/lib/dp-packet.c b/lib/dp-packet.c index c7675fd..0707bb4 100644 --- a/lib/dp-packet.c +++ b/lib/dp-packet.c @@ -179,6 +179,41 @@ dp_packet_clone(const struct dp_packet *buffer) return dp_packet_clone_with_headroom(buffer, 0); } +#ifdef DPDK_NETDEV +struct dp_packet * +dp_packet_clone_with_headroom(const struct dp_packet *b, size_t headroom) { + struct dp_packet *new_buffer; + uint32_t pkt_len = dp_packet_size(b); + + /* Copy multi-seg data. */ + if (b->source == DPBUF_DPDK && !rte_pktmbuf_is_contiguous(&b->mbuf)) { + void *dst = NULL; + struct rte_mbuf *mbuf = CONST_CAST(struct rte_mbuf *, &b->mbuf); + + new_buffer = dp_packet_new_with_headroom(pkt_len, headroom); + dst = dp_packet_data(new_buffer); + dp_packet_set_size(new_buffer, pkt_len); + + if (!rte_pktmbuf_read(mbuf, 0, pkt_len, dst)) { + dp_packet_delete(new_buffer); + return NULL; + } + } else { + new_buffer = dp_packet_clone_data_with_headroom(dp_packet_data(b), + dp_packet_size(b), + headroom); + } + + dp_packet_copy_common_members(new_buffer, b); + + dp_packet_copy_mbuf_flags(new_buffer, b); + if (dp_packet_rss_valid(new_buffer)) { + new_buffer->mbuf.hash.rss = b->mbuf.hash.rss; + } + + return new_buffer; +} +#else /* Creates and returns a new dp_packet whose data are copied from 'buffer'. * The returned dp_packet will additionally have 'headroom' bytes of * headroom. */ @@ -197,10 +232,6 @@ dp_packet_clone_with_headroom(const struct dp_packet *buffer, size_t headroom) sizeof(struct dp_packet) - offsetof(struct dp_packet, l2_pad_size)); -#ifdef DPDK_NETDEV - new_buffer->mbuf.ol_flags = buffer->mbuf.ol_flags; -#endif - if (dp_packet_rss_valid(buffer)) { dp_packet_set_rss_hash(new_buffer, dp_packet_get_rss_hash(buffer)); } @@ -210,6 +241,7 @@ dp_packet_clone_with_headroom(const struct dp_packet *buffer, size_t headroom) return new_buffer; } +#endif /* Creates and returns a new dp_packet that initially contains a copy of the * 'size' bytes of data starting at 'data' with no headroom or tailroom. */ diff --git a/lib/dp-packet.h b/lib/dp-packet.h index 7b2c4a0..3efa9d6 100644 --- a/lib/dp-packet.h +++ b/lib/dp-packet.h @@ -149,6 +149,10 @@ struct dp_packet *dp_packet_clone_data_with_headroom(const void *, size_t, size_t headroom); static inline void dp_packet_delete(struct dp_packet *); +static inline void +dp_packet_copy_common_members(struct dp_packet *new_b, + const struct dp_packet *b); + static inline void *dp_packet_at(const struct dp_packet *, size_t offset, size_t size); static inline void *dp_packet_at_assert(const struct dp_packet *, @@ -159,6 +163,8 @@ dp_packet_mbuf_from_offset(const struct dp_packet *b, size_t *offset); void dp_packet_mbuf_write(struct rte_mbuf *mbuf, int16_t ofs, uint32_t len, const void *data); +static inline void +dp_packet_copy_mbuf_flags(struct dp_packet *dst, const struct dp_packet *src); #endif static inline void *dp_packet_tail(const struct dp_packet *); static inline void *dp_packet_end(const struct dp_packet *); @@ -212,6 +218,17 @@ dp_packet_delete(struct dp_packet *b) } } +/* Copies the following fields into the 'new_b', which represent the common + * fields between DPDK and non-DPDK packets: l2_pad_size, l2_5_ofs, l3_ofs, + * l4_ofs, cutlen, packet_type and md. */ +static inline void +dp_packet_copy_common_members(struct dp_packet *new_b, + const struct dp_packet *b) { + memcpy(&new_b->l2_pad_size, &b->l2_pad_size, + sizeof(struct dp_packet) - + offsetof(struct dp_packet, l2_pad_size)); +} + /* If 'b' contains at least 'offset + size' bytes of data, returns a pointer to * byte 'offset'. Otherwise, returns a null pointer. For DPDK packets, this * means the 'offset' + 'size' must fall within the same mbuf (not necessarily @@ -715,6 +732,18 @@ dp_packet_set_allocated(struct dp_packet *b, uint16_t s) b->mbuf.buf_len = s; } +static inline void +dp_packet_copy_mbuf_flags(struct dp_packet *dst, const struct dp_packet *src) +{ + ovs_assert(dst != NULL && src != NULL); + struct rte_mbuf *buf_dst = &dst->mbuf; + const struct rte_mbuf *buf_src = &src->mbuf; + + buf_dst->ol_flags = buf_src->ol_flags; + buf_dst->packet_type = buf_src->packet_type; + buf_dst->tx_offload = buf_src->tx_offload; +} + /* Returns the RSS hash of the packet 'p'. Note that the returned value is * correct only if 'dp_packet_rss_valid(p)' returns true */ static inline uint32_t diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c index 09fd72d..6fef910 100644 --- a/lib/netdev-dpdk.c +++ b/lib/netdev-dpdk.c @@ -2472,6 +2472,7 @@ dpdk_do_tx_copy(struct netdev *netdev, int qid, struct dp_packet_batch *batch) memcpy(rte_pktmbuf_mtod(pkts[txcnt], void *), dp_packet_data(packet), size); dp_packet_set_size((struct dp_packet *)pkts[txcnt], size); + dp_packet_copy_mbuf_flags((struct dp_packet *)pkts[txcnt], packet); txcnt++; }