From patchwork Mon Sep 18 15:00:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 112929 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp3766045qgf; Mon, 18 Sep 2017 08:02:07 -0700 (PDT) X-Google-Smtp-Source: ADKCNb54I/EeFSKWRtrATHD2j1OEnPcCoi/B/tkaAwytAqh2JQ+qyyLAtMX5v56axwC2nhBlE/ao X-Received: by 10.13.213.149 with SMTP id x143mr29840335ywd.123.1505746927144; Mon, 18 Sep 2017 08:02:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505746927; cv=none; d=google.com; s=arc-20160816; b=u7nOanAit3tLXkW60kLuKhGIpxlHPiVmR5eY1civS6W0+ZQu4M0AeObYBgpB1StK1k UlOxpMOD/cwqCEb1JQPQv2cLpBEMDn4teJ+pqCspImBZUNlX3/yZegHHVGiSLrskFubx twhQuBGlftxSkv6sWDfq9FD12EQuDUbVx/jrCgkZeaaCWC3CYsmzhjYz9cWkywu80Vnw FeGwzrljMZyjRqaWoXgPmRIv0UPpfmnqDYTpC7WHsKYj5ujmI4dt3KBUU37cSb2gTx8y 2tidCcS0+yvwAnqovTz7OH7JLTfQGpU6pKfreITAy5GWMiZOgfTV+34zOfH74eLtoEuH cnQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=KFWZcbU4ak5xbczz6gjFHwSfHwaJnrbIHuee4NNoioM=; b=JhVw3hzEi73Ux2dqwZdYMdqMdEJYNrix9gwU+zPZIpImBQ6chqJs1xjFeI75gaBNTI MinkJkDj2ebC6VgQ3p91yuccqHME8smVon9YsMfZToHDbfjF/WUCi6Awo+kWauAqwn1l efeL2pRm8p9ebhGCgo65/VG/pkfNT9mgeh2jUvMUx2NdtDL2szer3FozMh6wnuQTkcCs KdPP1QhzLoGkQeh3Y1h4aHUoVmNTYiirWLOOI5E+A2X8uZoYefeQwmCZTFchSyWe6hWr s5OHd1NPTJfahMwDG3SF+D6QLWilqGf01CO3+uAsBvo/+wCuJp3FzHx5JLI2HUrT3XDT q8qQ== ARC-Authentication-Results: i=1; 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=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 69si4671436oie.301.2017.09.18.08.02.06; Mon, 18 Sep 2017 08:02:07 -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=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 2AA7460F34; Mon, 18 Sep 2017 15:02:06 +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=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 26F0160D8D; Mon, 18 Sep 2017 15:00:32 +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 A738D60D6B; Mon, 18 Sep 2017 15:00:27 +0000 (UTC) Received: from forward106j.mail.yandex.net (forward106j.mail.yandex.net [5.45.198.249]) by lists.linaro.org (Postfix) with ESMTPS id 882A560D6B for ; Mon, 18 Sep 2017 15:00:23 +0000 (UTC) Received: from mxback15g.mail.yandex.net (mxback15g.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b7:94]) by forward106j.mail.yandex.net (Yandex) with ESMTP id 2FDA11802275 for ; Mon, 18 Sep 2017 18:00:22 +0300 (MSK) Received: from smtp2o.mail.yandex.net (smtp2o.mail.yandex.net [2a02:6b8:0:1a2d::26]) by mxback15g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id 3Opuosj4tP-0Fd8gE5S; Mon, 18 Sep 2017 18:00:15 +0300 Received: by smtp2o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id I83pQYHSx8-0FYC6GPL; Mon, 18 Sep 2017 18:00:15 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Mon, 18 Sep 2017 18:00:08 +0300 Message-Id: <1505746808-26297-3-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505746808-26297-1-git-send-email-odpbot@yandex.ru> References: <1505746808-26297-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 180 Subject: [lng-odp] [PATCH v2 2/2] linux-generic: packet: add debugging asserts in packet code 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: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Bill Fischofer Restore the ODP_ASSERTS() that assist application debugging that were lost in the recent packet reference rework. When using --enable-debug insert guards to detect duplicate packet frees as well as attempts to modify the shared data sections of packet references. Signed-off-by: Bill Fischofer --- /** Email created from pull request 180 (Bill-Fischofer-Linaro:pkt-debug) ** https://github.com/Linaro/odp/pull/180 ** Patch: https://github.com/Linaro/odp/pull/180.patch ** Base sha: e1c46f8e296a730ed27141a33189185bb7dfd1b1 ** Merge commit sha: 8f6cbdeb075be6d397a255d8791d88a492b9d2db **/ platform/linux-generic/odp_packet.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index a3fd0559f..4cd0a108c 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -354,6 +354,8 @@ static inline void link_segments(odp_packet_hdr_t *pkt_hdr[], int num) hdr->buf_hdr.seg[i].hdr = buf_hdr; hdr->buf_hdr.seg[i].data = buf_hdr->base_data; hdr->buf_hdr.seg[i].len = BASE_LEN; + ODP_ASSERT((odp_atomic_store_u32(&hdr->buf_hdr.ref_cnt, + 1), 1)); cur++; if (cur == num) { @@ -388,6 +390,7 @@ static inline void init_segments(odp_packet_hdr_t *pkt_hdr[], int num) hdr->buf_hdr.num_seg = 1; hdr->buf_hdr.next_seg = NULL; hdr->buf_hdr.last_seg = &hdr->buf_hdr; + ODP_ASSERT((odp_atomic_store_u32(&hdr->buf_hdr.ref_cnt, 1), 1)); if (odp_unlikely(num > 1)) link_segments(pkt_hdr, num); @@ -848,6 +851,8 @@ void odp_packet_free(odp_packet_t pkt) odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); int num_seg = pkt_hdr->buf_hdr.segcount; + ODP_ASSERT(buffer_ref(&pkt_hdr->buf_hdr) >= 1); + if (odp_likely(CONFIG_PACKET_MAX_SEGS == 1 || num_seg == 1)) { odp_buffer_hdr_t *buf_hdr[2]; int num = 1; @@ -877,6 +882,8 @@ void odp_packet_free_multi(const odp_packet_t pkt[], int num) odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt[i]); int num_seg = pkt_hdr->buf_hdr.segcount; + ODP_ASSERT(buffer_ref(&pkt_hdr->buf_hdr) >= 1); + if (odp_unlikely(num_seg > 1)) { free_all_segments(pkt_hdr, num_seg); num_freed++; @@ -1010,6 +1017,8 @@ void *odp_packet_pull_head(odp_packet_t pkt, uint32_t len) if (len > pkt_hdr->frame_len) return NULL; + ODP_ASSERT(len <= odp_packet_unshared_len(pkt)); + pull_head(pkt_hdr, len); return packet_data(pkt_hdr); } @@ -1023,6 +1032,8 @@ int odp_packet_trunc_head(odp_packet_t *pkt, uint32_t len, if (len > pkt_hdr->frame_len) return -1; + ODP_ASSERT(len <= odp_packet_unshared_len(*pkt)); + if (len < seg_len) { pull_head(pkt_hdr, len); } else if (CONFIG_PACKET_MAX_SEGS != 1) { @@ -1057,6 +1068,8 @@ void *odp_packet_push_tail(odp_packet_t pkt, uint32_t len) if (len > pkt_hdr->tailroom) return NULL; + ODP_ASSERT(odp_packet_has_ref(pkt) == 0); + old_tail = packet_tail(pkt_hdr); push_tail(pkt_hdr, len); @@ -1072,6 +1085,8 @@ int odp_packet_extend_tail(odp_packet_t *pkt, uint32_t len, uint32_t tail_off = frame_len; int ret = 0; + ODP_ASSERT(odp_packet_has_ref(*pkt) == 0); + if (len > tailroom) { pool_t *pool = pkt_hdr->buf_hdr.pool_ptr; int num; @@ -1104,6 +1119,8 @@ void *odp_packet_pull_tail(odp_packet_t pkt, uint32_t len) odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); seg_entry_t *last_seg = seg_entry_last(pkt_hdr); + ODP_ASSERT(odp_packet_has_ref(pkt) == 0); + if (len > last_seg->len) return NULL; @@ -1123,6 +1140,8 @@ int odp_packet_trunc_tail(odp_packet_t *pkt, uint32_t len, if (len > pkt_hdr->frame_len) return -1; + ODP_ASSERT(odp_packet_has_ref(*pkt) == 0); + last = packet_last_seg(pkt_hdr); last_seg = seg_entry_last(pkt_hdr); seg_len = last_seg->len; @@ -1386,6 +1405,8 @@ int odp_packet_align(odp_packet_t *pkt, uint32_t offset, uint32_t len, if (align > ODP_CACHE_LINE_SIZE) return -1; + ODP_ASSERT(odp_packet_has_ref(*pkt) == 0); + if (seglen >= len) { misalign = align <= 1 ? 0 : ROUNDUP_ALIGN(uaddr, align) - uaddr; @@ -1423,6 +1444,8 @@ int odp_packet_concat(odp_packet_t *dst, odp_packet_t src) uint32_t dst_len = dst_hdr->frame_len; uint32_t src_len = src_hdr->frame_len; + ODP_ASSERT(odp_packet_has_ref(*dst) == 0); + /* Do a copy if packets are from different pools. */ if (odp_unlikely(dst_pool != src_pool)) { if (odp_packet_extend_tail(dst, src_len, NULL, NULL) >= 0) { @@ -1453,6 +1476,8 @@ int odp_packet_split(odp_packet_t *pkt, uint32_t len, odp_packet_t *tail) if (len >= pktlen || tail == NULL) return -1; + ODP_ASSERT(odp_packet_has_ref(*pkt) == 0); + *tail = odp_packet_copy_part(*pkt, len, pktlen - len, odp_packet_pool(*pkt)); @@ -1538,6 +1563,8 @@ int odp_packet_copy_from_mem(odp_packet_t pkt, uint32_t offset, if (offset + len > pkt_hdr->frame_len) return -1; + ODP_ASSERT(offset + len <= odp_packet_unshared_len(pkt)); + while (len > 0) { mapaddr = packet_map(pkt_hdr, offset, &seglen, NULL); cpylen = len > seglen ? seglen : len; @@ -1567,6 +1594,8 @@ int odp_packet_copy_from_pkt(odp_packet_t dst, uint32_t dst_offset, src_offset + len > src_hdr->frame_len) return -1; + ODP_ASSERT(dst_offset + len <= odp_packet_unshared_len(dst)); + overlap = (dst_hdr == src_hdr && ((dst_offset <= src_offset && dst_offset + len >= src_offset) || @@ -1607,6 +1636,8 @@ int odp_packet_copy_from_pkt(odp_packet_t dst, uint32_t dst_offset, int odp_packet_copy_data(odp_packet_t pkt, uint32_t dst_offset, uint32_t src_offset, uint32_t len) { + ODP_ASSERT(dst_offset + len <= odp_packet_unshared_len(pkt)); + return odp_packet_copy_from_pkt(pkt, dst_offset, pkt, src_offset, len); } @@ -1614,6 +1645,8 @@ int odp_packet_copy_data(odp_packet_t pkt, uint32_t dst_offset, int odp_packet_move_data(odp_packet_t pkt, uint32_t dst_offset, uint32_t src_offset, uint32_t len) { + ODP_ASSERT(dst_offset + len <= odp_packet_unshared_len(pkt)); + return odp_packet_copy_from_pkt(pkt, dst_offset, pkt, src_offset, len); } @@ -1629,6 +1662,8 @@ int _odp_packet_set_data(odp_packet_t pkt, uint32_t offset, if (offset + len > pkt_hdr->frame_len) return -1; + ODP_ASSERT(offset + len <= odp_packet_unshared_len(pkt)); + while (len > 0) { mapaddr = packet_map(pkt_hdr, offset, &seglen, NULL); setlen = len > seglen ? seglen : len;