From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by dpdk.org (Postfix) with ESMTP id B8A831B484 for ; Tue, 26 Mar 2019 20:15:22 +0100 (CET) Received: by mail-pg1-f195.google.com with SMTP id q1so530624pgv.13 for ; Tue, 26 Mar 2019 12:15:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=qH6URklo65xDn2T+OAVWPM5iz+0F+IFz+AehosbFXAQ=; b=t5Vuk5n7/yYj1PvTq2RpW6K+9sw4ez7HGR2oM65SzYh6fSNFb16Mca1p2AJaXdJWAy 90N0u1GQCRQzobcMHvZzBXHYZvmBzfUMvv133G3ifzfsOccAgB2xH4Al9myfSt5mcYS0 WN+YgoMW22J1BCPIy3WAmGXOAQsQoBKRzHRPICMVF8FGczDY8iIPs9voL3CVjmiNAJRt DMry2oWAjCsh4syiy7GZOaYgIS4eqcdnLM5Cl/6rZ1NUJQiusNOrdlY7WSO386VK1uwb ge5XQ30bJwrBaXNEMstmq3Ubuy5rbvs7ktj2DLZseyDQisMg0un8mtjRVCKH1snxQs3O jYAA== 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=qH6URklo65xDn2T+OAVWPM5iz+0F+IFz+AehosbFXAQ=; b=cceOtH25Qb9co9x2HVaIPoLwlouICZsNGIpTftg3m0kPGkaAOih7NpvI5e3akHTpzG 4XLl3/ZtRPn2GLpZ8S20UMgDZ/hB5psQmIh022M++LLt9X36tx4Er/Yb15RgXyoSVUEC OAFtJPf+ySP0TZYzTCDWeDHwa9q86nJoN0VMKUQPFcs7KlizNhPRGRYMyzZrbpCRF0Lt /rwrZs1lDQk1K594Wv06Mcye6AK0fvsLF8eRZvepoPSTFwi0HF3CDEcnPYugA6aqKUlt bMS10QDOn0zYUXEJFd61EN9XRAFrmBWOzYCd6W8S9Ydlwf4+jQ/FhqRmCTicXm57mLnn 3F3w== X-Gm-Message-State: APjAAAVDdX1XBLYeB06iN4Yo3FZThDQRENuNgTbKhiilZ87hYlDy6hT7 IcC34ov+BNYctr27qUqV0sCmJn7ULzUMMA== X-Google-Smtp-Source: APXvYqwRRhoHhUJG1tQF+xo1EFt5JkCZlodjAfxF7jm9r67wa5VCA851Z9n1eqj/YRvG78DcXTM8Tw== X-Received: by 2002:a65:448b:: with SMTP id l11mr6884996pgq.185.1553627721619; Tue, 26 Mar 2019 12:15:21 -0700 (PDT) Received: from shemminger-XPS-13-9360.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id l187sm23972207pgl.75.2019.03.26.12.15.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 12:15:20 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Stephen Hemminger Date: Tue, 26 Mar 2019 12:15:15 -0700 Message-Id: <20190326191516.20675-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.17.1 Subject: [dpdk-dev] [PATCH] net: fix rte_vlan_insert with shared mbuf X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Mar 2019 19:15:23 -0000 If mbuf refcnt was > 1 then rte_vlan_insert() would incorrectly modify the original copy. Original code was expecting clone to make a copy (it doesn't). Better to let the caller deal with making a copy or setting up mbuf chain to allow for header to be added. Also fix docbook comment about parameters (function takes pointer to mbuf). Fixes: c974021a5949 ("ether: add soft vlan encap/decap") Signed-off-by: Stephen Hemminger --- lib/librte_net/rte_ether.h | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/lib/librte_net/rte_ether.h b/lib/librte_net/rte_ether.h index c2c5e249ffe9..bab2b198fa79 100644 --- a/lib/librte_net/rte_ether.h +++ b/lib/librte_net/rte_ether.h @@ -374,7 +374,7 @@ static inline int rte_vlan_strip(struct rte_mbuf *m) * Software version of VLAN unstripping * * @param m - * The packet mbuf. + * Pointer to the packet mbuf. * @return * - 0: On success * -EPERM: mbuf is is shared overwriting would be unsafe @@ -385,16 +385,9 @@ static inline int rte_vlan_insert(struct rte_mbuf **m) struct ether_hdr *oh, *nh; struct vlan_hdr *vh; - /* Can't insert header if mbuf is shared */ - if (rte_mbuf_refcnt_read(*m) > 1) { - struct rte_mbuf *copy; - - copy = rte_pktmbuf_clone(*m, (*m)->pool); - if (unlikely(copy == NULL)) - return -ENOMEM; - rte_pktmbuf_free(*m); - *m = copy; - } + /* Can't directly insert header if mbuf is shared */ + if (rte_mbuf_refcnt_read(*m) > 1) + return -EPERM; oh = rte_pktmbuf_mtod(*m, struct ether_hdr *); nh = (struct ether_hdr *) -- 2.17.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 50314A05D3 for ; Tue, 26 Mar 2019 20:15:25 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 75C431B485; Tue, 26 Mar 2019 20:15:24 +0100 (CET) Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by dpdk.org (Postfix) with ESMTP id B8A831B484 for ; Tue, 26 Mar 2019 20:15:22 +0100 (CET) Received: by mail-pg1-f195.google.com with SMTP id q1so530624pgv.13 for ; Tue, 26 Mar 2019 12:15:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=qH6URklo65xDn2T+OAVWPM5iz+0F+IFz+AehosbFXAQ=; b=t5Vuk5n7/yYj1PvTq2RpW6K+9sw4ez7HGR2oM65SzYh6fSNFb16Mca1p2AJaXdJWAy 90N0u1GQCRQzobcMHvZzBXHYZvmBzfUMvv133G3ifzfsOccAgB2xH4Al9myfSt5mcYS0 WN+YgoMW22J1BCPIy3WAmGXOAQsQoBKRzHRPICMVF8FGczDY8iIPs9voL3CVjmiNAJRt DMry2oWAjCsh4syiy7GZOaYgIS4eqcdnLM5Cl/6rZ1NUJQiusNOrdlY7WSO386VK1uwb ge5XQ30bJwrBaXNEMstmq3Ubuy5rbvs7ktj2DLZseyDQisMg0un8mtjRVCKH1snxQs3O jYAA== 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=qH6URklo65xDn2T+OAVWPM5iz+0F+IFz+AehosbFXAQ=; b=cceOtH25Qb9co9x2HVaIPoLwlouICZsNGIpTftg3m0kPGkaAOih7NpvI5e3akHTpzG 4XLl3/ZtRPn2GLpZ8S20UMgDZ/hB5psQmIh022M++LLt9X36tx4Er/Yb15RgXyoSVUEC OAFtJPf+ySP0TZYzTCDWeDHwa9q86nJoN0VMKUQPFcs7KlizNhPRGRYMyzZrbpCRF0Lt /rwrZs1lDQk1K594Wv06Mcye6AK0fvsLF8eRZvepoPSTFwi0HF3CDEcnPYugA6aqKUlt bMS10QDOn0zYUXEJFd61EN9XRAFrmBWOzYCd6W8S9Ydlwf4+jQ/FhqRmCTicXm57mLnn 3F3w== X-Gm-Message-State: APjAAAVDdX1XBLYeB06iN4Yo3FZThDQRENuNgTbKhiilZ87hYlDy6hT7 IcC34ov+BNYctr27qUqV0sCmJn7ULzUMMA== X-Google-Smtp-Source: APXvYqwRRhoHhUJG1tQF+xo1EFt5JkCZlodjAfxF7jm9r67wa5VCA851Z9n1eqj/YRvG78DcXTM8Tw== X-Received: by 2002:a65:448b:: with SMTP id l11mr6884996pgq.185.1553627721619; Tue, 26 Mar 2019 12:15:21 -0700 (PDT) Received: from shemminger-XPS-13-9360.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id l187sm23972207pgl.75.2019.03.26.12.15.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 12:15:20 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Stephen Hemminger Date: Tue, 26 Mar 2019 12:15:15 -0700 Message-Id: <20190326191516.20675-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.17.1 Subject: [dpdk-dev] [PATCH] net: fix rte_vlan_insert with shared mbuf X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Content-Type: text/plain; charset="UTF-8" Message-ID: <20190326191515.VICI4PBYt3TUPlFBsgcAzX5JKBsg2ltLrABRa4eVj5Y@z> If mbuf refcnt was > 1 then rte_vlan_insert() would incorrectly modify the original copy. Original code was expecting clone to make a copy (it doesn't). Better to let the caller deal with making a copy or setting up mbuf chain to allow for header to be added. Also fix docbook comment about parameters (function takes pointer to mbuf). Fixes: c974021a5949 ("ether: add soft vlan encap/decap") Signed-off-by: Stephen Hemminger --- lib/librte_net/rte_ether.h | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/lib/librte_net/rte_ether.h b/lib/librte_net/rte_ether.h index c2c5e249ffe9..bab2b198fa79 100644 --- a/lib/librte_net/rte_ether.h +++ b/lib/librte_net/rte_ether.h @@ -374,7 +374,7 @@ static inline int rte_vlan_strip(struct rte_mbuf *m) * Software version of VLAN unstripping * * @param m - * The packet mbuf. + * Pointer to the packet mbuf. * @return * - 0: On success * -EPERM: mbuf is is shared overwriting would be unsafe @@ -385,16 +385,9 @@ static inline int rte_vlan_insert(struct rte_mbuf **m) struct ether_hdr *oh, *nh; struct vlan_hdr *vh; - /* Can't insert header if mbuf is shared */ - if (rte_mbuf_refcnt_read(*m) > 1) { - struct rte_mbuf *copy; - - copy = rte_pktmbuf_clone(*m, (*m)->pool); - if (unlikely(copy == NULL)) - return -ENOMEM; - rte_pktmbuf_free(*m); - *m = copy; - } + /* Can't directly insert header if mbuf is shared */ + if (rte_mbuf_refcnt_read(*m) > 1) + return -EPERM; oh = rte_pktmbuf_mtod(*m, struct ether_hdr *); nh = (struct ether_hdr *) -- 2.17.1