From patchwork Sat Feb 18 12:52:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 94174 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp588719qgi; Sat, 18 Feb 2017 04:52:40 -0800 (PST) X-Received: by 10.200.41.3 with SMTP id y3mr11251997qty.205.1487422359952; Sat, 18 Feb 2017 04:52:39 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id q33si9459594qtd.32.2017.02.18.04.52.39; Sat, 18 Feb 2017 04:52:39 -0800 (PST) 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 sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 3137562ECE; Sat, 18 Feb 2017 12:52:39 +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, RCVD_IN_DNSWL_NONE, 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 2BB7F60A1A; Sat, 18 Feb 2017 12:52:33 +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 7A6E460CBA; Sat, 18 Feb 2017 12:52:31 +0000 (UTC) Received: from mail-ot0-f182.google.com (mail-ot0-f182.google.com [74.125.82.182]) by lists.linaro.org (Postfix) with ESMTPS id 5A3E960997 for ; Sat, 18 Feb 2017 12:52:30 +0000 (UTC) Received: by mail-ot0-f182.google.com with SMTP id 45so46387572otd.2 for ; Sat, 18 Feb 2017 04:52:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=jdTxv8JbKnE0E9eStqQ26tXq0uoMxrrS75W6p/S52Ec=; b=B42x4wMwSWZsNNXgmH3iB6xhpMNSsVg+hkgoOAsVTlE8QAJDdRPWAcuvfTF4Ga601b tccr4KH5T1b+6Ui0NQqOr2c3dZGzaCdN/gczhT41TNYXWUtLARE4pm1vtW8GV/+JoG+a 2eAHa8quUNTj6JqPJXYXIadXwll9X3Kr2+iY5InlpirydWz06OZySCoI6rjE4ryi73Tz 1u+MME32xPdO4Ts1JkdFz+HM9KgKJfMGItO5D8vA8ue/+oBgIcIPFYH3OuB7YCSSdTM/ rNOL3ipk25pP4OR5QsxiAuM6shHULIIFV507gcu4tZI7Hlbulp/7YbZVKT6tb6mIVlCP Qn5Q== X-Gm-Message-State: AMke39mTZ623vVZn7i4OhTnG2N8do08tzU1nDzXohJSdt3sKfMRtgbhHStlZ2QJBC/rtJUKStYQ= X-Received: by 10.157.37.171 with SMTP id q40mr6839494ota.255.1487422349716; Sat, 18 Feb 2017 04:52:29 -0800 (PST) Received: from localhost.localdomain (cpe-70-121-83-241.austin.res.rr.com. [70.121.83.241]) by smtp.gmail.com with ESMTPSA id n45sm4272443otb.52.2017.02.18.04.52.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 18 Feb 2017 04:52:28 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Sat, 18 Feb 2017 06:52:25 -0600 Message-Id: <20170218125225.26824-1-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.12.0.rc1 Subject: [lng-odp] [API-NEXT PATCHv2] linux-generic: packet: avoid race condition in packet_free processing 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" Resolve bug https://bugs.linaro.org/show_bug.cgi?id=2892 by setting unshared_len prior to potentially freeing segments. Reported-by: Janne Peltonen Signed-off-by: Bill Fischofer --- platform/linux-generic/odp_packet.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) -- 2.12.0.rc1 diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index 81bbcedd..b18b69a9 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -658,6 +658,9 @@ static inline odp_packet_hdr_t *packet_free_to_list(odp_packet_hdr_t *pkt_hdr, if (*nfree + num_seg >= nbufs) break; + if (ref_count == 2) + pkt_hdr->unshared_len = pkt_hdr->frame_len; + for (i = 0; i < num_seg; i++) { odp_packet_hdr_t *hdr = pkt_hdr->buf_hdr.seg[i].hdr; @@ -666,9 +669,6 @@ static inline odp_packet_hdr_t *packet_free_to_list(odp_packet_hdr_t *pkt_hdr, packet_ref_dec(hdr) == 1) buf[(*nfree)++] = buffer_handle(hdr); } - - if (ref_count == 2) - pkt_hdr->unshared_len = pkt_hdr->frame_len; } pkt_hdr = ref_hdr; @@ -693,10 +693,10 @@ static inline void packet_free(odp_packet_hdr_t *pkt_hdr) buffer_free_multi((odp_buffer_t *) &pkt_hdr->buf_hdr.handle.handle, 1); } else { - free_bufs(pkt_hdr, 0, num_seg); - if (ref_count == 2) pkt_hdr->unshared_len = pkt_hdr->frame_len; + + free_bufs(pkt_hdr, 0, num_seg); } pkt_hdr = ref_hdr;