From patchwork Thu May 5 15:35:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zoltan Kiss X-Patchwork-Id: 67209 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp815535qge; Thu, 5 May 2016 08:36:26 -0700 (PDT) X-Received: by 10.107.51.206 with SMTP id z197mr19278605ioz.107.1462462586366; Thu, 05 May 2016 08:36:26 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id s9si4137044iga.71.2016.05.05.08.36.25; Thu, 05 May 2016 08:36:26 -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 3053A615E8; Thu, 5 May 2016 15:36:25 +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_H3, RCVD_IN_MSPIKE_WL, 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 77118615F3; Thu, 5 May 2016 15:35:58 +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 DD294615E3; Thu, 5 May 2016 15:35:48 +0000 (UTC) Received: from mail-wm0-f41.google.com (mail-wm0-f41.google.com [74.125.82.41]) by lists.linaro.org (Postfix) with ESMTPS id 775B76158A for ; Thu, 5 May 2016 15:35:47 +0000 (UTC) Received: by mail-wm0-f41.google.com with SMTP id g17so34139860wme.1 for ; Thu, 05 May 2016 08:35:47 -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:in-reply-to :references; bh=zN6hjC2Kv6JbuKiY06hRmoDqEw9VhCmjTJwQLSazays=; b=Gl2UFCs7s5dE0hGEb1LC1rrq+asTD2b0sCThTXwsJWp+T45bmXrgrgxaVjBoDoB0Im t8WB6jPrDjt2zfqX5yLFdJ5857XBxSdRfWbqRJfT5mTC96aM/kGc2oZ0j0MfLaIqYJ+C KI6PBvm9tHVyqaLMC2jMVMnl7WxXMIUwhzJOFVimRiVeZkQ0HtyD3ToCc8pdTtkorQj/ msb1SZkoXxFS1cCkgAc/c/pTrnaPGey+8ahgKzW0/mnhf/MfV9EqLsfyNGNm8VIkXD27 ooSUs75J2YLmlyWL9TminAmRiYHLTc89Wi6HkMLO2WK3UFsf6mJf/qVkgXY6KQVHBTdz Uz1A== X-Gm-Message-State: AOPr4FU+N0iGA7rpEsF1X6MOSkmC3USG5lLFHA1IW50p3sNgeRYPwsib4ZXHZyyn9azR8nq96SY= X-Received: by 10.194.82.168 with SMTP id j8mr16704654wjy.37.1462462546653; Thu, 05 May 2016 08:35:46 -0700 (PDT) Received: from localhost.localdomain ([195.11.233.227]) by smtp.googlemail.com with ESMTPSA id f8sm10302731wjm.13.2016.05.05.08.35.45 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 05 May 2016 08:35:46 -0700 (PDT) From: Zoltan Kiss To: lng-odp@lists.linaro.org Date: Thu, 5 May 2016 16:35:07 +0100 Message-Id: <1462462509-13337-2-git-send-email-zoltan.kiss@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1462462509-13337-1-git-send-email-zoltan.kiss@linaro.org> References: <1462462509-13337-1-git-send-email-zoltan.kiss@linaro.org> X-Topics: Classification patch Cc: petri.savolainen@nokia.com Subject: [lng-odp] [PATCH v2 1/3] linux-generic: classification: release the packet as soon as an error happens 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" Move release to _odp_packet_classifier(), because caller has no way to know if new_pkt were allocated. In that case there would be a double free on pkt, and new_pkt would be leaked. The only exception is when cos == NULL or odp_packet_copy() fails, in that case the packet is reenqued. Signed-off-by: Zoltan Kiss --- v2: - add comment for this function - use errno.h values - let caller handle EINVAL and ENOMEM - loopback reenques them - fix in stats that CoS drop means actually discard platform/linux-generic/odp_classification.c | 41 ++++++++++++++++++++++------- platform/linux-generic/pktio/loop.c | 16 ++++++++--- 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/platform/linux-generic/odp_classification.c b/platform/linux-generic/odp_classification.c index 25e1c2c..a3fe545 100644 --- a/platform/linux-generic/odp_classification.c +++ b/platform/linux-generic/odp_classification.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #define LOCK(a) odp_spinlock_lock(a) @@ -746,6 +747,20 @@ int pktio_classifier_init(pktio_entry_t *entry) return 0; } +/** + * Classify packet and enqueue to the right queue + * + * entry pktio where it arrived + * pkt packet handle + * + * Return values: + * 0 on success, packet is consumed + * -ENOENT CoS dropped the packet + * -EFAULT Bug, packet is released + * -EINVAL Config error, packet is NOT released + * -ENOMEM Target CoS pool exhausted, packet is NOT released + */ + int _odp_packet_classifier(pktio_entry_t *entry, odp_packet_t pkt) { queue_entry_t *queue; @@ -754,8 +769,10 @@ int _odp_packet_classifier(pktio_entry_t *entry, odp_packet_t pkt) odp_packet_t new_pkt; uint8_t *pkt_addr; - if (entry == NULL) - return -1; + if (entry == NULL) { + odp_packet_free(pkt); + return -EFAULT; + } pkt_hdr = odp_packet_hdr(pkt); pkt_addr = odp_packet_data(pkt); @@ -763,18 +780,17 @@ int _odp_packet_classifier(pktio_entry_t *entry, odp_packet_t pkt) /* Matching PMR and selecting the CoS for the packet*/ cos = pktio_select_cos(entry, pkt_addr, pkt_hdr); if (cos == NULL) - return -1; + return -EINVAL; - if (cos->s.pool == NULL) - return -1; - - if (cos->s.queue == NULL) - return -1; + if (cos->s.queue == NULL || cos->s.pool == NULL) { + odp_packet_free(pkt); + return -ENOENT; + } if (odp_packet_pool(pkt) != cos->s.pool->s.pool_hdl) { new_pkt = odp_packet_copy(pkt, cos->s.pool->s.pool_hdl); if (new_pkt == ODP_PACKET_INVALID) - return -1; + return -ENOMEM; odp_packet_free(pkt); } else { new_pkt = pkt; @@ -782,7 +798,12 @@ int _odp_packet_classifier(pktio_entry_t *entry, odp_packet_t pkt) /* Enqueuing the Packet based on the CoS */ queue = cos->s.queue; - return queue_enq(queue, odp_buf_to_hdr((odp_buffer_t)new_pkt), 0); + if (queue_enq(queue, odp_buf_to_hdr((odp_buffer_t)new_pkt), 0)) { + odp_packet_free(new_pkt); + return -EFAULT; + } else { + return 0; + } } cos_t *pktio_select_cos(pktio_entry_t *entry, const uint8_t *pkt_addr, diff --git a/platform/linux-generic/pktio/loop.c b/platform/linux-generic/pktio/loop.c index 5819e66..f7ccbd9 100644 --- a/platform/linux-generic/pktio/loop.c +++ b/platform/linux-generic/pktio/loop.c @@ -73,19 +73,29 @@ static int loopback_recv(pktio_entry_t *pktio_entry, odp_packet_t pkts[], if (pktio_cls_enabled(pktio_entry)) { for (i = 0, j = 0; i < nbr; i++) { + int ret; pkt = _odp_packet_from_buffer(odp_hdr_to_buf (hdr_tbl[i])); pkt_hdr = odp_packet_hdr(pkt); packet_parse_reset(pkt_hdr); packet_parse_l2(pkt_hdr); - if (!_odp_packet_classifier(pktio_entry, pkt)) { + ret = _odp_packet_classifier(pktio_entry, pkt); + switch (ret) { + case 0: packet_set_ts(pkt_hdr, ts); pktio_entry->s.stats.in_octets += odp_packet_len(pkt); - } else { + break; + case -ENOENT: + pktio_entry->s.stats.in_discards += + odp_packet_len(pkt); + break; + case -EFAULT: pktio_entry->s.stats.in_errors += odp_packet_len(pkt); - odp_packet_free(pkt); + break; + default: + ret = queue_enq(qentry, hdr_tbl[i], 0); } } nbr = j;