From patchwork Tue Oct 24 01:00:15 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: 116885 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp5243449qgn; Mon, 23 Oct 2017 18:01:06 -0700 (PDT) X-Google-Smtp-Source: ABhQp+SaBAQ29hM0Asaj0Alc3p05eVBRlxaybQah8JyxiW59idNWbkKF+crxpLfBOJ+IXir6lOkh X-Received: by 10.237.37.8 with SMTP id v8mr23600766qtc.275.1508806866498; Mon, 23 Oct 2017 18:01:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508806866; cv=none; d=google.com; s=arc-20160816; b=V5qLTo/MuTItKYL5jGdzELtMV7vPX6L8+HiHDgJvUrAFJ3/jMv4DjtWAAe+kXbRp7i pgAUvA5eflztK/4ocS8Xq508NjmSG0K1znZLD3/sbvE5ZHjhChT+2XdG8faLdFMDrl4l POdsBdQsXExh56YqsQ5V2gFfVNhsxncOsaT/ERCJIlZ6aICCyW55QquFJeIf17srpuV2 AArKn9KQzatNqlC8SUDjTm7ZCHJvziANq43Apy9QFE4QvH12gQJ/t0YX4uwJqj+x+xt9 bSHuiVSdjfaUSFHOVGcGyjqrRQj8MG3lrJV//pXlPZGhcuWLJAIL9I8yMR/Rc0wpwlrn AczA== 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=OEiJ4kXIE9i36eTrO0qnbEckpDfDAfMNWYvz+U66qyc=; b=0LzUkbhpqvbchPDEB0vzOj/b35jSEjdtOUnpY4zuYx/VSA1sCNhq5O9SsBLqkALKU9 6bvpsugblstfXJCzrBsSGPb4SZWLUMTEnoSdzjgEfVWwSSZnuGupUShKPPm2X0R8zVHw ZW5SLyO4IHrzzu6dagN2rdxCwO1uLKoVfJaH+fW/NpYaYII9aw2PF0hCcc5Y/BjMbnu+ PNS2khDmchszfquyI2rpCaS17DmyNTKsRl+2JujwXkIQeYqjMYMLWtwoR+eQ2/fIhMBy wGqqpnp/55xMBd2vmGQUCbxMU8H9Ejo1hDCv4XlYkgF/fFufQLnwB5a9B3wQ8x/3Dclm bLzg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 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 (ec2-54-197-127-237.compute-1.amazonaws.com. [54.197.127.237]) by mx.google.com with ESMTP id q25si45154qkl.266.2017.10.23.18.01.06; Mon, 23 Oct 2017 18:01:06 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) client-ip=54.197.127.237; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 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 38DE0622A0; Tue, 24 Oct 2017 01:01: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=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, 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 9C576622A2; Tue, 24 Oct 2017 01:00:39 +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 4CCDE6229D; Tue, 24 Oct 2017 01:00:36 +0000 (UTC) Received: from forward106o.mail.yandex.net (forward106o.mail.yandex.net [37.140.190.187]) by lists.linaro.org (Postfix) with ESMTPS id B2AC061D19 for ; Tue, 24 Oct 2017 01:00:34 +0000 (UTC) Received: from mxback18j.mail.yandex.net (mxback18j.mail.yandex.net [IPv6:2a02:6b8:0:1619::94]) by forward106o.mail.yandex.net (Yandex) with ESMTP id 0545F782B78 for ; Tue, 24 Oct 2017 04:00:33 +0300 (MSK) Received: from smtp2p.mail.yandex.net (smtp2p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:7]) by mxback18j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id m4P9E9qujK-0WXa5jUB; Tue, 24 Oct 2017 04:00:32 +0300 Received: by smtp2p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id 3auJzRIbtl-0WhWNwDj; Tue, 24 Oct 2017 04:00:32 +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: Tue, 24 Oct 2017 04:00:15 +0300 Message-Id: <1508806815-13010-2-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1508806815-13010-1-git-send-email-odpbot@yandex.ru> References: <1508806815-13010-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 180 Subject: [lng-odp] [PATCH v6 1/1] 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 known 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: f5120355753ae3d69f81010cb9131abffdfb03fc ** Merge commit sha: 998cf29c03c5a09555111d05446b15191cab2877 **/ 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 94aa01deb..89bae3625 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -352,6 +352,16 @@ 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 = seg_len; + + /* init_segments() handles first seg ref_cnt init */ + if (ODP_DEBUG == 1 && cur > 0) { + uint32_t prev_ref = + odp_atomic_fetch_inc_u32( + &pkt_hdr[cur]->buf_hdr.ref_cnt); + + ODP_ASSERT(prev_ref == 0); + } + cur++; if (cur == num) { @@ -381,6 +391,13 @@ static inline void init_segments(odp_packet_hdr_t *pkt_hdr[], int num) hdr->buf_hdr.seg[0].data = hdr->buf_hdr.base_data; hdr->buf_hdr.seg[0].len = seg_len; + if (ODP_DEBUG == 1) { + uint32_t prev_ref = + odp_atomic_fetch_inc_u32(&hdr->buf_hdr.ref_cnt); + + ODP_ASSERT(prev_ref == 0); + } + if (!CONFIG_PACKET_SEG_DISABLED) { hdr->buf_hdr.segcount = num; hdr->buf_hdr.num_seg = 1; @@ -846,6 +863,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) > 0); + if (odp_likely(CONFIG_PACKET_SEG_DISABLED || num_seg == 1)) { odp_buffer_hdr_t *buf_hdr[2]; int num = 1; @@ -875,6 +894,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) > 0); + if (odp_unlikely(num_seg > 1)) { free_all_segments(pkt_hdr, num_seg); num_freed++; @@ -1055,6 +1076,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); @@ -1070,6 +1093,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; @@ -1102,6 +1127,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; @@ -1121,6 +1148,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; @@ -1384,6 +1413,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; @@ -1421,6 +1452,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) { @@ -1451,6 +1484,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));