From patchwork Thu Jun 9 12:12:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 69706 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp293325qgf; Thu, 9 Jun 2016 05:12:53 -0700 (PDT) X-Received: by 10.140.18.197 with SMTP id 63mr9056557qgf.18.1465474373228; Thu, 09 Jun 2016 05:12:53 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id f51si3258332qga.45.2016.06.09.05.12.52; Thu, 09 Jun 2016 05:12:53 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id D25576178C; Thu, 9 Jun 2016 12:12:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 4131F61787; Thu, 9 Jun 2016 12:12:49 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 0655B61788; Thu, 9 Jun 2016 12:12:46 +0000 (UTC) Received: from mail-oi0-f48.google.com (mail-oi0-f48.google.com [209.85.218.48]) by lists.linaro.org (Postfix) with ESMTPS id 05A3461725 for ; Thu, 9 Jun 2016 12:12:45 +0000 (UTC) Received: by mail-oi0-f48.google.com with SMTP id p204so59618807oih.3 for ; Thu, 09 Jun 2016 05:12:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=+xiM+WPwr1ajxMdG5V4Bfw303P8q1vFcPOObE0MadA4=; b=I6XZRdoyQbKam7YhYuThPkyy1SI2pg+vn8K4y6VBYGYlcF5o3jiRhahXsKUad/IqyB VLTKGGJfpPu76qxdJ/Cp9okvi/i/+jNRvrA+mHWamHN5xtJQUHbB9mEk8FI6V+3sHVxj Y38/m/XWRwLV6yONGHnbpVVhoBei24R2UEqKsjTWtQ465t5z6v9usF6S50RMQBVIViu2 LTXOSp5WG4+RSAeg9SVjzWSmhXdSkaBcdipUvjqPGsk6pNmkgDG+H2W1wnuJiu2yb6gW rGW5kzN/qaJcYzbU/P2cww6OyOk14f9XxmBKy7qSJfnAEGlzAeRKlSINjPYeIqzdgYDB KXdg== X-Gm-Message-State: ALyK8tKgpU6A4XqvjNeCBJsaWI1gcFkLBcEnUiOx3VMMt3h332C8rYMlCjkZX05GkAFBw4yOaaM= X-Received: by 10.202.97.69 with SMTP id v66mr4771230oib.172.1465474364431; Thu, 09 Jun 2016 05:12:44 -0700 (PDT) Received: from localhost.localdomain (cpe-66-68-129-43.austin.res.rr.com. [66.68.129.43]) by smtp.gmail.com with ESMTPSA id e8sm2728103otb.9.2016.06.09.05.12.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 09 Jun 2016 05:12:43 -0700 (PDT) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Thu, 9 Jun 2016 07:12:40 -0500 Message-Id: <1465474361-8019-1-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.7.4 X-Topics: patch Subject: [lng-odp] [PATCHv3 1/2] linux-generic: packet: copy user area as part of odp_packet_copy() X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Resolve Bug https://bugs.linaro.org/show_bug.cgi?id=2310 by copying the user area as part of odp_packet_copy(). The copy fails if the user area size of the destination pool is not large enough to hold the source packet user area. Reported-by: Zoltan Kiss Signed-off-by: Bill Fischofer Reviewed-by: Zoltan Kiss --- v3: Resplit changes (oversight caught by Zoltan during review) v2: Zoltan review comments. Include additional metadata like ts, color, that were added more recently. .../linux-generic/include/odp_packet_internal.h | 5 ++++- platform/linux-generic/odp_packet.c | 23 +++++++++------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h index d5ace12..ab54227 100644 --- a/platform/linux-generic/include/odp_packet_internal.h +++ b/platform/linux-generic/include/odp_packet_internal.h @@ -192,6 +192,9 @@ static inline void copy_packet_parser_metadata(odp_packet_hdr_t *src_hdr, dst_hdr->l4_len = src_hdr->l4_len; dst_hdr->dst_queue = src_hdr->dst_queue; + dst_hdr->flow_hash = src_hdr->flow_hash; + dst_hdr->timestamp = src_hdr->timestamp; + dst_hdr->op_result = src_hdr->op_result; } static inline void *packet_map(odp_packet_hdr_t *pkt_hdr, @@ -294,7 +297,7 @@ static inline int packet_parse_not_complete(odp_packet_hdr_t *pkt_hdr) } /* Forward declarations */ -void _odp_packet_copy_md_to_packet(odp_packet_t srcpkt, odp_packet_t dstpkt); +int _odp_packet_copy_md_to_packet(odp_packet_t srcpkt, odp_packet_t dstpkt); odp_packet_t packet_alloc(odp_pool_t pool_hdl, uint32_t len, int parse); diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index 2868736..40549a8 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -756,22 +756,11 @@ odp_packet_t odp_packet_copy(odp_packet_t pkt, odp_pool_t pool) { odp_packet_hdr_t *srchdr = odp_packet_hdr(pkt); uint32_t pktlen = srchdr->frame_len; - uint32_t meta_offset = ODP_FIELD_SIZEOF(odp_packet_hdr_t, buf_hdr); odp_packet_t newpkt = odp_packet_alloc(pool, pktlen); if (newpkt != ODP_PACKET_INVALID) { - odp_packet_hdr_t *newhdr = odp_packet_hdr(newpkt); - uint8_t *newstart, *srcstart; - - /* Must copy metadata first, followed by packet data */ - newstart = (uint8_t *)newhdr + meta_offset; - srcstart = (uint8_t *)srchdr + meta_offset; - - memcpy(newstart, srcstart, - sizeof(odp_packet_hdr_t) - meta_offset); - - if (odp_packet_copy_from_pkt(newpkt, 0, pkt, 0, - pktlen) != 0) { + if (_odp_packet_copy_md_to_packet(pkt, newpkt) || + odp_packet_copy_from_pkt(newpkt, 0, pkt, 0, pktlen)) { odp_packet_free(newpkt); newpkt = ODP_PACKET_INVALID; } @@ -966,7 +955,7 @@ int odp_packet_is_valid(odp_packet_t pkt) * */ -void _odp_packet_copy_md_to_packet(odp_packet_t srcpkt, odp_packet_t dstpkt) +int _odp_packet_copy_md_to_packet(odp_packet_t srcpkt, odp_packet_t dstpkt) { odp_packet_hdr_t *srchdr = odp_packet_hdr(srcpkt); odp_packet_hdr_t *dsthdr = odp_packet_hdr(dstpkt); @@ -986,6 +975,12 @@ void _odp_packet_copy_md_to_packet(odp_packet_t srcpkt, odp_packet_t dstpkt) odp_atomic_load_u32( &srchdr->buf_hdr.ref_count)); copy_packet_parser_metadata(srchdr, dsthdr); + + /* Metadata copied, but return indication of whether the packet + * user area was truncated in the process. Note this can only + * happen when copying between different pools. + */ + return dsthdr->buf_hdr.uarea_size < srchdr->buf_hdr.uarea_size; } /**